Commits

Anonymous committed 473832e

احتمال هيكلة الدليل في الوديعة القادمة

  • Participants
  • Parent commits 4d6bc5a

Comments (0)

Files changed (18)

 /*
-    scta: Dynamic Arrays Module 
 
-    Sulaiman (seininn) Mustafa     2014-02-17
-    Version 0.1
+    scta: Generic Dynamic Array Module
+
+    Sulaiman (seininn) Mustafa     2014-02-26
     
-    This module is a part of libstc, but can be used independently.
+    This module is a part of libstc, a modular, c99/c1x-compliant, 
+    toolkit library. use stcmod to determine this module's 
+    dependencies, if any.
     
 */
 
 
 
 FILE *scta_config_debug = NULL;
-int scta_config_version[3] = {1, 0, 0};
+int scta_config_version[3] = {1, 1, 1};
 
 /*
     internal array layout
 /*
-    sctstr: A simple string module 
 
-    Sulaiman (seininn) Mustafa     2014-01-19
-    Version 0.1
+    scta: Generic Dynamic Array Module
+
+    Sulaiman (seininn) Mustafa     2014-02-26
+    
+    This module is a part of libstc, a modular, c99/c1x-compliant, 
+    toolkit library. use stcmod to determine this module's 
+    dependencies, if any.
     
-    This module is a part of libstc.
 */
 
 #ifndef SCTA_H
     scta_free
     
 SYNOPSIS
-    void scta_free(array)
+    void scta_free(type* array)
 
 DESCRIPTION    
     Takes a dynamic array and frees it.
 
 
 #define scta_length(A)                              (SCTA__EXTERN_LEN(A)[0])/*
-
 sctman:scta_length
 NAME
     scta_length
     
 SYNOPSIS
-    int scta_length(array)
+    int scta_length(type* array)
 
 DESCRIPTION    
     Returns the length of the array 
 */
 
 #define scta_set_length(A, newl)                    (scta_macro_set_length_((char **) &(A), newl))/*
+sctman:scta_set_length
+NAME
+    scta_set_length
+
+SYNOPSIS
+    bool scta_set_length(type* array, int newl)
 
 DESCRIPTION    
-    expands or collapses an array. If newl is larger than the length of the 
+    Expands or collapses an array. If newl is larger than the length of the 
     array, the array is expanded and all new elements are set to zero. If 
     newl is smaller than the length of the provided array, the array is 
     collapsed.
     
 RETURN
-    A boolian value indicating success or failure; stdbool definitions are used.
+    A boolean value indicating success or failure; stdbool definitions are used.
     
 
 */
 #define scta_insert(A, where, what)                 ((SCTA__EXTERN_INT1(A)[0]=where),\
                                                      ((A)[scta_length(A)+1]=what),\
                                                      scta_macro_insert_((char **) &(A)))/*
+sctman:scta_insert
+NAME
+    scta_insert
+
+SYNOPSIS
+    bool scta_insert(type* array, int where, type what)
                                                      
 DESCRIPTION    
-    This macro inserts variable `what' in a dynamic array `A' at index `where'.
+    This macro inserts value `what' in a dynamic array `A' at index `where'.
 
+NOTES
+    1.  `where' can be a negative value which denotes the index starting from 
+        the end of the array.
+    2.  `array' is evaluated more than once in this macro.
+    
 RETURN
-    A boolian value indicating success or failure; stdbool definitions are used.
+    A boolean value indicating success or failure; stdbool definitions are used.
 
 EXAMPLE
     int *a; // [1, 2, 3]
                                                      (SCTA__EXTERN_INT2(A)[0]=(length)),\
                                                      (SCTA__EXTERN_PTR1(A)[0]=(target)),\
                                                      scta_macro_insert_array_((char **) &(A)))
+/*
+sctman:scta_insert
+NAME
+    scta_insert_array
+
+SYNOPSIS
+    bool scta_insert(type* array, int where, type what)
+                                                     
+DESCRIPTION    
+    This macro inserts value `what' in a dynamic array `A' at index `where'.
+
+RETURN
+    A boolean value indicating success or failure; stdbool definitions are used.
+
+EXAMPLE
+    int *a; // [1, 2, 3]
+    if (!scta_insert(a, 1, 300)) {
+        puts("this macro failed");
+    }
+    a; // [1, 300, 2, 3]
+*/
                                                      
                                                                                              
 #define scta_push(A, what)                          scta_insert((A), INT_MAX, (what))
         scta_free(z);
     }
     
-    printf("scta version (%d:%d:%d) ok. (compiled on %s)\n", 
+    printf("[ok] %10s %d:%d:%d    %s\n", "scta", 
         scta_config_version[0], scta_config_version[1], 
         scta_config_version[2], __TIMESTAMP__);
     return 0;
+test: sctac.* test.c
+	gcc -o test -std=c99 -pedantic -g -Wall -Wextra -I../a ../a/scta.c sctac.c test.c
+
+memcheck: test
+	valgrind --tool=memcheck ./test
+
+clean:
+	rm test
+/*
+
+    sctac: Mutable Character Array Module
+
+    Sulaiman (seininn) Mustafa     2014-02-26
+    
+    This module is a part of libstc, a modular, c99/c1x-compliant, 
+    toolkit library. use stcmod to determine this module's 
+    dependencies, if any.
+    
+*/
+
+#include "scta.h"
+#include <string.h>
+
+FILE *sctac_config_debug = NULL;
+int sctac_config_version[3] = {1, 0, 0};
+
+char *sctac_insert_(char **string, char *appendee, int at){
+    char *s = *string;
+    int len = strlen(appendee);
+    
+    if (!scta_insert_array(s, at, appendee, len)) {
+        return NULL;
+    }
+    
+    *string = s;
+    return s;
+}
+
+char *sctac_append_(char **string, char *appendee){
+    return sctac_insert_(string, appendee, scta_length(*string));
+}
+
+
+char *sctac_delete_(char **string, int start, int length){
+    char *s = *string;
+    
+    if (!scta_delete_subset (s, start, length)) {
+        return NULL;
+    }
+    
+    *string = s;
+    return s;
+}
+
+
+char *sctac_clone_(char **string, int start, int length){
+    char *s = *string;
+    
+    if (!scta_subset (s, start, length)) {
+        return NULL;
+    }
+    
+    *string = s;
+    return s;
+}
+
+
+/*
+
+    sctac: Mutable Character Array Module
+
+    Sulaiman (seininn) Mustafa     2014-02-26
+    
+    This module is a part of libstc, a modular, c99/c1x compliant, 
+    toolkit library. use stcmod to determine this module's 
+    dependencies, if any.
+    
+*/
+
+#ifndef SCTAC_H
+#define SCTAC_H
+
+extern FILE *sctac_config_debug;
+extern int sctac_config_version[3];
+
+
+char *sctac_insert_(char **string, char *appendee, int at);
+char *sctac_append_(char **string, char *appendee);
+char *sctac_delete_(char **string, int start, int length);
+char *sctac_clone_(char **string, int start, int length);
+
+#define sctac_insert(S, A, T) sctac_insert_(&(S), (A), (T))
+#define sctac_append(S, A) sctac_append_(&(S), (A))
+#define sctac_delete(S, B, L) sctac_delete_(&(S), (B), (L))
+#define sctac_clone(S, B, L) sctac_clone_(&(S), (B), (L))
+
+
+#endif
+#include <stdio.h>
+#include "scta.h"
+#include "sctac.h"
+
+int main(){
+    /*
+    char *s;
+    s = scta_new(char);
+    puts(s);
+    sctac_append(s, "hello their my friend!");
+    puts(s);
+    sctac_insert(s, "epic ", -7);
+    puts(s);
+    sctac_delete(s, 1, 7);
+    puts(s);
+    sctac_delete(s, 0, 5);
+    puts(s);
+    scta_free(s);
+    */
+
+    printf("[ok] %10s %d:%d:%d    %s\n", "sctac",
+        sctac_config_version[0], sctac_config_version[1], 
+        sctac_config_version[2], __TIMESTAMP__);    
+    return 0;
+    
+}

c/Makefile

-test: sctac.* test.c
-	gcc -o test -std=c99 -pedantic -g -Wall -Wextra -I../a ../a/scta.c sctac.c test.c
-
-memcheck: test
-	valgrind --tool=memcheck ./test
-
-clean:
-	rm test

c/sctac.c

-#include "scta.h"
-#include "string.h"
-
-FILE *sctac_config_debug = NULL;
-int sctac_config_version[3] = {1, 0, 0};
-
-char *sctac_insert_(char **string, char *appendee, int at){
-    char *s = *string;
-    int len = strlen(appendee);
-    
-    if (!scta_insert_array(s, at, appendee, len)) {
-        return NULL;
-    }
-    
-    *string = s;
-    return s;
-}
-
-char *sctac_append_(char **string, char *appendee){
-    return sctac_insert_(string, appendee, scta_length(*string));
-}
-
-
-char *sctac_delete_(char **string, int start, int length){
-    char *s = *string;
-    
-    if (!scta_delete_subset (s, start, length)) {
-        return NULL;
-    }
-    
-    *string = s;
-    return s;
-}
-
-
-char *sctac_clone_(char **string, int start, int length){
-    char *s = *string;
-    
-    if (!scta_subset (s, start, length)) {
-        return NULL;
-    }
-    
-    *string = s;
-    return s;
-}
-
-

c/sctac.h

-#ifndef SCTAC_H
-#define SCTAC_H
-
-extern FILE *sctac_config_debug;
-extern int sctac_config_version[3];
-
-
-char *sctac_insert_(char **string, char *appendee, int at);
-char *sctac_append_(char **string, char *appendee);
-char *sctac_delete_(char **string, int start, int length);
-char *sctac_clone_(char **string, int start, int length);
-
-#define sctac_insert(S, A, T) sctac_insert_(&(S), (A), (T))
-#define sctac_append(S, A) sctac_append_(&(S), (A))
-#define sctac_delete(S, B, L) sctac_delete_(&(S), (B), (L))
-#define sctac_clone(S, B, L) sctac_clone_(&(S), (B), (L))
-
-
-
-#endif

c/test

Binary file removed.

c/test.c

-#include <stdio.h>
-#include "scta.h"
-#include "sctac.h"
-
-int main(){
-    char *s;
-    
-    s = scta_new(char);
-    puts(s);
-    sctac_append(s, "hello their my friend!");
-    puts(s);
-    sctac_insert(s, "epic ", -7);
-    puts(s);
-    sctac_delete(s, 1, 7);
-    puts(s);
-    sctac_delete(s, 0, 5);
-    puts(s);
-    
-    scta_free(s);
-    
-    return 0;
-    
-}
+#!/bin/bash
+
+test(){
+	cd "$1"
+	printf "\e[1;31m"
+	make -s test 2>&1 > /dev/null || {
+		echo "make failed for '$1'."
+		printf "\e[0m"
+		exit 1
+	}
+	printf "\e[0m"
+
+	printf "\e[1m"
+	./test || exit 1
+	printf "\e[0m"
+	make -s clean 2>&1 > /dev/null
+	cd - > /dev/null
+
+}
+
+test "a"
+test "ac"
+test "frame"
+test "time"
+test "os"
+test "ml"
     
     
     
-    printf("sctframe version (%d:%d:%d) ok. (compiled on %s)\n", 
+    printf("[ok] %10s %d:%d:%d    %s\n", "sctframe",
         sctframe_config_version[0], sctframe_config_version[1], 
         sctframe_config_version[2], __TIMESTAMP__);
     return 0;
     
     
     
-    printf("sctml version (%d:%d:%d) ok. (compiled on %s)\n", 
+    printf("[ok] %10s %d:%d:%d    %s\n", "sctml",
         sctml_config_version[0], sctml_config_version[1], 
         sctml_config_version[2], __TIMESTAMP__);
     return 0;
     assert(!sctos_load("test.d/test-2.txt", &b));
     sctos_config_verbose = true;
     
-    printf("sctos version (%d:%d:%d) ok. (compiled on %s)\n", 
+    printf("[ok] %10s %d:%d:%d    %s\n", "os",
         sctos_config_version[0], sctos_config_version[1], 
         sctos_config_version[2], __TIMESTAMP__);
     return 0;

testlib

-#!/bin/bash
-
-test(){
-	cd "$1"
-	printf "\e[1;31m"
-	make -s test 2>&1 > /dev/null || {
-		echo "make failed for '$1'."
-		printf "\e[0m"
-		exit 1
-	}
-	printf "\e[0m"
-
-	printf "\e[1m"
-	./test || exit 1
-	printf "\e[0m"
-	make -s clean 2>&1 > /dev/null
-	cd - > /dev/null
-
-}
-
-test "a"
-test "frame"
-test "time"
-test "os"
-test "ml"
     assert(!strcmp(scttime_rfc3339((time_t)((~ (uint32_t)0)>>1), datastring), "2038-01-19T03:14:07Z"));
     assert(!strcmp(scttime_rfc3339(1392879390, datastring), "2014-02-20T06:56:30Z"));
     
-    
-    
-    
-
-
-
-
-    printf("sctframe version (%d:%d:%d) ok. (compiled on %s)\n", 
+    printf("[ok] %10s %d:%d:%d    %s\n", "scttime",
         scttime_config_version[0], scttime_config_version[1], 
         scttime_config_version[2], __TIMESTAMP__);
     return 0;