diff --git a/CellElemFunc.o b/CellElemFunc.o deleted file mode 100644 index 96608af..0000000 Binary files a/CellElemFunc.o and /dev/null differ diff --git a/Exe b/Exe deleted file mode 100755 index c2c0af9..0000000 Binary files a/Exe and /dev/null differ diff --git a/LibCell/Makefile b/LibCell/Makefile new file mode 100644 index 0000000..aa62e0a --- /dev/null +++ b/LibCell/Makefile @@ -0,0 +1,27 @@ +CC=gcc +CFLAGS=-Wall -Werror -pedantic -fpic -g + + +LIBSDIR=-L/usr/lib -L../Libs +INCLUDEDIR=-I/usr/include -I. + +#Library variables +LIBTARGET=libCellElement.so +LIBSOURCE=CellElement +LIBSOURCECFILE=$(LIBSOURCE:=.c) +LIBSOURCEOFILE=$(LIBSOURCE:=.o) + +#Generating the library binary +$(LIBTARGET): $(LIBSOURCEOFILE) + @echo "\n Generating the library binary" + $(CC) $(CFLAGS) -shared $(LIBSOURCEOFILE) -o ../Libs/$(LIBTARGET) + +#Generating object files +.c.o: + @echo "\n Generating " $@ " from " $< + $(CC) $(CFLAGS) $(INCLUDEDIR) -c -o $@ $< + +#Cleaning +clean: + @echo "\n Cleaning" + rm -rf *.o *.exe *.so diff --git a/CellElemFunc.c b/LibList/CellElement.c similarity index 84% rename from CellElemFunc.c rename to LibList/CellElement.c index 39105d0..a9ce164 100644 --- a/CellElemFunc.c +++ b/LibList/CellElement.c @@ -1,4 +1,4 @@ -/*** +/*** --- CellElemFunc --- ---Created by : Naej Doree --- ***/ @@ -7,29 +7,11 @@ #include #include -int main(int argc, char **argv){ - cellElement * tree = NULL; - tree = CreateCellElem(); - tree->colIndex = 1; - AddNextRow(tree); - tree->nextRow->colIndex = 2; - AddNextCol(tree); - tree->nextCol->colIndex = 3; - recursivePrint(tree); - removeNextRow(tree); - removeNextCol(tree); - - recursivePrint(tree); - - - return 0; - -} cellElement * CreateCellElem(){ cellElement * elem = NULL; elem = (cellElement*) malloc(sizeof(cellElement)); - + if (elem == NULL){ return NULL; } @@ -40,8 +22,8 @@ cellElement * CreateCellElem(){ elem->nextCol = NULL; elem->nextRow = NULL; - - return elem; + + return elem; } void freeCellElem(cellElement * elem){ @@ -53,7 +35,7 @@ int AddNextCol(cellElement* tree){ cellElement * elem = NULL; elem = (cellElement*) malloc(sizeof(cellElement)); - + if (elem == NULL){ return -1; } @@ -69,7 +51,7 @@ int AddNextCol(cellElement* tree){ }else{ return -2; } - + return 1; } @@ -78,7 +60,7 @@ int AddNextRow(cellElement* tree){ cellElement * elem = NULL; elem = (cellElement*) malloc(sizeof(cellElement)); - + if (elem == NULL){ return -1; } @@ -104,7 +86,7 @@ void removeNextCol(cellElement* tree){ free(elem); elem = NULL; tree->nextCol = NULL; - + } } @@ -117,7 +99,7 @@ void removeNextRow(cellElement* tree){ free(elem); elem =NULL; tree->nextRow = NULL; - + } } @@ -135,4 +117,10 @@ void recursivePrint(cellElement * tree){ } } -} \ No newline at end of file +} + +void FreeCellElement(cellElement* element) { + if (element != NULL){ + free(element); + } +} diff --git a/CellElement.h b/LibList/CellElement.h similarity index 94% rename from CellElement.h rename to LibList/CellElement.h index 67b0a9e..9c8f5e9 100644 --- a/CellElement.h +++ b/LibList/CellElement.h @@ -7,7 +7,7 @@ *@false : 0 */ typedef enum Bool{ - + true = 1, false = 0 @@ -27,7 +27,7 @@ typedef enum Bool{ * */ struct cellElement { - + int colIndex; int rowIndex; @@ -47,7 +47,8 @@ int AddNextRow(cellElement* tree); void removeNextCol(cellElement* list); void removeNextRow(cellElement* list); - void recursivePrint(cellElement * tree); -#endif \ No newline at end of file +void FreeCellElement(cellElement* element); + +#endif diff --git a/LibList/Makefile b/LibList/Makefile new file mode 100644 index 0000000..5f92df2 --- /dev/null +++ b/LibList/Makefile @@ -0,0 +1,29 @@ +CC=gcc +CFLAGS=-Wall -Werror -pedantic -fpic -g + + +LIBSDIR=-L/usr/lib -L../Libs +INCLUDEDIR=-I/usr/include -I. + +#Library variables +LIBTARGET=libList.so +LIBSOURCE=list CellElement +LIBSOURCECFILE=$(LIBSOURCE:=.c) +LIBSOURCEOFILE=$(LIBSOURCE:=.o) + +#Generating the library binary +$(LIBTARGET): $(LIBSOURCEOFILE) + @echo "\n Generating the library binary" + $(CC) $(CFLAGS) -shared $(LIBSOURCEOFILE) -o ../Libs/$(LIBTARGET) + +#Generating object files +.c.o: + @echo "\n Generating " $@ " from " $< + $(CC) $(CFLAGS) $(INCLUDEDIR) -c -o $@ $< + +#Cleaning +clean: + @echo "\n Cleaning" + rm -rf *.o *.exe *.so + + diff --git a/LibList/list.h b/LibList/list.h new file mode 100644 index 0000000..455c941 --- /dev/null +++ b/LibList/list.h @@ -0,0 +1,99 @@ +#ifndef LIST_H +#define LIST_H + +#include + +#define SUCCESS 0 +#define FAILURE 1 + +typedef struct ListElement ListElement; +struct ListElement { + void *data; + ListElement *next; + ListElement *previous; +}; + +typedef struct List { + ListElement *head; + ListElement *tail; + int size; +} List; + +/* + * Create a new list + * @return a pointer of list + */ +List * CreateList(); + +/* + * Insert an element at the begining of a list + * @param list pointer of a list + * @param data any type of data + * @param size size of the data + * @return status of the operation + */ +int unshift(List* list, cellElement* data); + +/* + * Insert an element at the end of a list + * @param list pointer of a list + * @param data any type of data + * @param size size of the data + * @return status of the operation + */ +int push(List* list, cellElement* data); + +/* + * Get an element in a given list + * @param list as a pointer + * @param nb the number of the element (can be negative) + * @return an element + */ +ListElement * GetElement(List *list, int nb); + +/* + * Delete an element with a pointer of element in the list + * @param list as a pointer + * @param element of the list as a pointer + * @return status of the operation + */ +int PopPtnList(List *list, ListElement *element); + +/* + * Delete an element with a position in the list + * @param list as a pointer + * @param position of the element + * @return status of the operation + */ +int RemoveElement(List *list, int nb); + +/* + * Delete the first element of the list + * @param list as a pointer + * @return status of the operation + */ +int shift(List *list); + +/* + * Delete the last element of the list + * @param list as a pointer + * @return status of the operation + */ +int pop(List *list); + +/* + * Delete every elements in a list + * @param list as a pointer + * @return status of the operation + */ +int DeleteListContent(List *list); + + +/* + * Free a list + * @param list as a pointer + * @return status of the operation + */ +int FreeList(List *list); + +#endif /* LIST_H */ diff --git a/Makefile b/Makefile index 6d01a5e..d7e22c6 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,57 @@ -CXX = gcc -TARGET = Exe -SOURCEFILE = CellElemFunc -CFLAGS = -Wall -Werror -ansi -pedantic -fpic -I. -g +# Makefile compiling the whole project +# Don't forget before the first compilation to run that command: +# export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./Libs -#Generating the executable -$(TARGET): $(SOURCEFILE).o - @echo "Generating the executable" $@ - $(CXX) $(CFLAGS) $(SOURCEFILE).o -o $@ +CC=gcc +CFLAGS=-Wall -Werror -pedantic -fpic -g -$(SOURCEFILE).o: - @echo "Generating objectfiles" $@ - $(CXX) $(CFLAGS) -c $(SOURCEFILE).c -o $@ -#Cleaning the executable +LIBSDIR=-L/usr/lib -L./Libs +INCLUDEDIR=-I/usr/include -I. -I./LibCell -I./LibList + +#Exe test variables +TARGET=main.exe +SOURCE=main + +SOURCECFILE=$(SOURCE:=.c) +SOURCEOFILE=$(SOURCE:=.o) + +#Library variables +DEPENDENCE=libCellElement.so +DEPENDENCENAME=CellElement + +DEPENDENCELIST=libList.so +DEPENDENCENAMELIST=List + + +all: $(TARGET) + +#Generating the main.exe +$(TARGET): $(SOURCEOFILE) $(DEPENDENCELIST) lib + @echo "\n Generating the " $(TARGET) " binary" + $(CC) $(SOURCEOFILE) $(LIBSDIR) -l$(DEPENDENCENAME) -l$(DEPENDENCENAMELIST) -o $(TARGET) + +#Generating the library binary +lib: + @echo "\n Generating the automaton library binary" + mkdir -p Libs + $(MAKE) -C LibCell + +$(DEPENDENCELIST): + @echo "\n Generating the list library binary" + $(MAKE) -C LibList + + +#Generating object files +.c.o: + @echo "\n Generating " $@ " from " $< + $(CC) $(CFLAGS) $(INCLUDEDIR) -c -o $@ $< + + +#Cleaning clean: - @echo "Cleaning temporary files" - rm -rf *.o *- *.so $(TARGET) - + @echo "\n Cleaning" + rm -rf *.o ./Libs/*.so *.exe + $(MAKE) -C LibCell clean + $(MAKE) -C LibList clean - diff --git a/main.c b/main.c new file mode 100644 index 0000000..b1efa8a --- /dev/null +++ b/main.c @@ -0,0 +1,28 @@ +/********************************************************************************* +* File Name : main.c +* Created By : klmp200 +* Creation Date : [2016-12-10 01:06] +* Last Modified : [2016-12-10 01:07] +* Description : +**********************************************************************************/ + +#include +#include +#include + +int main(int argc, char **argv){ + cellElement * tree = NULL; + tree = CreateCellElem(); + tree->colIndex = 1; + AddNextRow(tree); + tree->nextRow->colIndex = 2; + AddNextCol(tree); + tree->nextCol->colIndex = 3; + recursivePrint(tree); + removeNextRow(tree); + removeNextCol(tree); + recursivePrint(tree); + + return 0; + +}