aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcathook <cat.hook31894@gmail.com>2013-11-25 13:40:45 +0800
committercathook <cat.hook31894@gmail.com>2013-11-25 13:40:45 +0800
commit8551cc2325027a2dbeb51e1c01e2619621676c9f (patch)
treeb66ef637b5d3c6468af6ff507e49d906cc7b2ca1
parent24ec80854b0145eac5f6401ca34ee82121468064 (diff)
downloadctl-8551cc2325027a2dbeb51e1c01e2619621676c9f.tar.gz
ctl-8551cc2325027a2dbeb51e1c01e2619621676c9f.tar.zst
ctl-8551cc2325027a2dbeb51e1c01e2619621676c9f.zip
update readme and makefile
-rw-r--r--Makefile68
-rw-r--r--README139
2 files changed, 144 insertions, 63 deletions
diff --git a/Makefile b/Makefile
index 7b00a4e..375806f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,33 @@
-###################### path name ###########################
+####################### path name ##########################
LIB = lib
-INC = include
-SRC = src
OBJ = obj
+
+INC = $(shell pwd)/include
+SRC = src
+
TST = test
################ compiler information: gcc #################
-C_OPT := -I$(INC) -L$(LIB) -O2
-A_OPT :=
+GCC_OPT := -I$(INC) -L$(LIB) -O2
+AR_OPT := cvr
-TEST_CC := gcc $(C_OPT) -o
+TEST_CC := gcc $(GCC_OPT) -o
-OBJ_CC := gcc $(C_OPT) -c -o
-DLIB_CC := gcc $(C_OPT) -shared -fPIC -o
-SLIB_CC := ar $(A_OPT) cvr
+OBJ_CC := gcc $(GCC_OPT) -c
+SLIB_CC := ar $(AR_OPT)
######################## targets ###########################
-TARGET = utility vector #list queue stack dequeue heap map hash
-COMMON = utility
+OBJECT = utility vector #list queue stack dequeue heap map hash
+
+SOURCE := $(foreach n,$(OBJECT),$(SRC)/$(n).c)
+HEADER := $(foreach n,$(OBJECT),$(INC)/$(n).h)
+OBJFIL := $(foreach n,$(OBJECT),$(OBJ)/$(n).o)
-TEST = vector
+TARGET := $(LIB)/libctl.a
-#SRC_NAME := $(foreach n,$(TARGET),$(SRC)/$(n).c)
-#HEA_NAME := $(foreach n,$(TARGET),$(INC)/$(n).h)
-#OBJ_NAME := $(foreach n,$(TARGET),$(OBJ)/$(n).o)
-#SLIB_NAME := $(foreach n,$(TARGET),$(LIB)/lib$(n).a)
-#DLIB_NAME := $(foreach n,$(TARGET),$(LIB)/lib$(n).so)
+TSTFIL := $(TST)/test.c
+TSTOUT := $(TST)/test
######################## setting ###########################
.SUFFIXES:
@@ -37,40 +38,27 @@ TEST = vector
######################## targets ###########################
all: $(TARGET);
-$(TARGET): %: $(LIB)/%.a $(LIB)/%.so $(OBJ)/%.o;
-
-$(LIB)/%.a: $(OBJ)/%.o
- @echo 'make static library ........ $@'
- @$(SLIB_CC) $@ $<
+$(TARGET): $(OBJFIL)
+ @echo 'make static library ....... $@'
+ @-rm -f $@
+ @$(SLIB_CC) $@ $^
-$(LIB)/%.so: $(SRC)/%.c $(INC)/%.h
- @echo 'make dynamic library ....... $@'
- @$(DLIB_CC) $@ $<
-
-$(OBJ)/%.o: $(SRC)/%.c $(INC)/%.h
- @echo 'make obj file .............. $@'
- @$(OBJ_CC) $@ $<
-
-test: $(addprefix $(TST)/test_,$(TEST))
+$(OBJFIL): $(OBJ)/%.o: $(SRC)/%.c $(INC)/%.h
+ @echo 'make object file .......... $@'
+ @cd $(OBJ) && $(OBJ_CC) ../$<
-$(TST)/test_%: $(TST)/test_%.slib $(TST)/test_%.dlib $(TST)/test_%.oooo;
+test: $(TSTOUT)_slib $(TSTOUT)_objs
-$(TST)/test_%.slib: $(TST)/test_%.c $(LIB)/%.a $(LIB)/$(COMMON).a
- @echo 'make test program for ...... $^'
- @$(TEST_CC) $@ $^
-
-$(TST)/test_%.dlib: $(TST)/test_%.c $(LIB)/%.so $(LIB)/$(COMMON).so
+$(TSTOUT)_slib: $(TSTFIL) $(TARGET)
@echo 'make test program for ...... $^'
@$(TEST_CC) $@ $^
-$(TST)/test_%.oooo: $(TST)/test_%.c $(OBJ)/%.o $(OBJ)/$(COMMON).o
+$(TSTOUT)_objs: $(TSTFIL) $(OBJFIL)
@echo 'make test program for ...... $^'
@$(TEST_CC) $@ $^
-
clean:
-rm -f $(LIB)/*
-rm -f $(OBJ)/*
-rm -f $(TST)/*.slib
- -rm -f $(TST)/*.dlib
-rm -f $(TST)/*.oooo
diff --git a/README b/README
index fc29483..9f7b5d1 100644
--- a/README
+++ b/README
@@ -1,31 +1,124 @@
ctl -- C Template Library
+ It contain some useful objects, functions, macros about some data
+ structure.
-File "lib/*.so" are dynamic libraries. (create by "gcc -shared -fPIC ...")
-File "lib/*.a" are static libraries. (create by "ar cvr ....")
-File "obj/*.o" are object file. (create by "gcc -c ....")
+Compile:
+ Type "make" and it will create "lib/libctl.a", "obj/$.o" where $
+ means all the objects.
+ By the way, you can type "make test" to compile a test file
+ which name is "test/test.c", and the results are "test/test_slib"
+ and "test/test_dlib". Both of them are executive file. To run
+ one of them, you will be shown a simple example about how to use
+ the objects and functions in this project -- "C Template Library".
-In the directory "src" and "include" are the source files and the header files
-for user to include
+Target/goal:
+ -utility:
+ This object contain some useful functions, constants and types.
+ Enums:
+ ErrorType contain kinds of errors.
+
+ Structures:
+
+ Types:
+ uint unsigned int
+ pchar char*
+ ppchar char**
+ pvoid void*
+ ppvoid void**
+ cchar const char
+ pcchar (const char)*
+ ppcchar (const char)**
+ cvoid const void
+ pcvoid (cosnt void)*
+ ppcvoid (const void)**
+
+ Type transform:
+ Char(), pChar(), ppChar()
+ Void(), pVoid(), ppVoid()
+ cChar(), pcChar(), ppcChar()
+ cVoid(), pcVoid(), ppcVoid()
+
+ Functions:
+ ctl_malloc like malloc(), but will exit on error
+ ctl_realloc like realloc(), but will exit on erro
+ ctl_die print some message and exit()
+ ctl_swap swap two elements with given type
+
-blablablabla......
+ -vector:
+ This object is an array with dynamic table size.
+ methods:
+ init(addr of the vector, size per entry, size)
+ The vector's type depends on what user want to
+ store. For example: if you want an array for int,
+ you should decleare like "int* v", and call the
+ init() like this "init(&v, sizeof(int), 5)", and
+ it will initalize an array with 5 elements.
+
+ free(addr of the vector)
+ Free the memory the vector use. Yous should call
+ it when you don't need the container.
+
+
+ getSize(addr of the vector)
+ Return the number of elements.
+
+ getEntrySize(addr of the vector)
+ Return the size per entry, it dependent on what
+ type of data you store in the container.
+
+ getEntry(addr of the vector, index)
+ Return a const pointer which point to the entry
+ with the index you give.
+
+
+ setSize(addr of the vector, new_size)
+ Resize the table to new_size. Note that it won't
+ initalize the newly element if you increase size.
+
+ setEntry(addr of the vector, index, data)
+ Let the element with index you give be data.
+
+
+ addBack(addr of the vector, data)
+ Add an element which contain data at the back of
+ the vector.
+
+ delBack(addr of the vector)
+ Remove the last element of the vector.
+
+ addFront(addr of the vector, data) !! UNFINISHED !!
+ Add an element which contain data at the front of
+ the vector.
+
+ delFront(addr of the vector) !! UNFINISHED !!
+ Remove the first element of the vector.
+
+
+ cat(addr of the v1, addr of the v2)
+ Concatenate the vector2 to the back of vector1.
+
+ copy(addr of the v1, addr of the v2)
+ Let the contain in the v1 be the one in the v2
+
+ replace(addr of the v1, a, b, addr of the v2, x, y)
+ If b == 0, it will insert v2[x ... x+y-1] into
+ the place between v[a]
+ and v[a-1]
+ If y >= 0, it will replace v1[a ... a+b-1]
+ to v2[x ... x+y-1]
+ If y < 0, it will replace v1[a ... a+b-1]
+ to v2[x-y-1 ... x] with
+ reverse order.
+
+ -list:
+ -stack:
+ -queue:
+ -dequeue:
+ -heap:
+ -map:
+ -hash:
-target/goal:
- -utility: just contain some useful functions...
- -vector: like std::vector in C++, it is an array with dynamic size
- + functions..........
- + operator[]
- -list:
- -stack:
- -queue:
- -dequeue:
- -heap:
- -map:
- -hash:
-
-===========================================================================
-
-make => create all *.o, *.a, *.so
-make test => create test file in test/
--cathook, cat_leopard