From 9d57b532f6fb710e2d9cca6e39d98a665224d182 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sat, 10 Dec 2016 02:28:10 +0100 Subject: [PATCH] Add true makefile + lists --- LibCell/CellElement.c | 16 ++ CellElement.h => LibCell/CellElement.h | 1 + LibList/list.c | 217 +++++++++++++++++++++++++ LibList/list.h | 99 +++++++++++ Makefile | 79 +++++---- main | Bin 0 -> 8656 bytes main.c | 16 ++ main.o | Bin 0 -> 2352 bytes 8 files changed, 399 insertions(+), 29 deletions(-) create mode 100644 LibCell/CellElement.c rename CellElement.h => LibCell/CellElement.h (92%) create mode 100644 LibList/list.c create mode 100644 LibList/list.h create mode 100755 main create mode 100644 main.c create mode 100644 main.o diff --git a/LibCell/CellElement.c b/LibCell/CellElement.c new file mode 100644 index 0000000..07484f9 --- /dev/null +++ b/LibCell/CellElement.c @@ -0,0 +1,16 @@ +/* +* @Author: klmp200 +* @Date: 2016-12-10 01:32:50 +* @Last Modified by: klmp200 +* @Last Modified time: 2016-12-10 01:33:40 +*/ + +#include +#include +#include + +void freeCellElement(cellElement* element) { + if (element != NULL){ + free(element); + } +} \ No newline at end of file diff --git a/CellElement.h b/LibCell/CellElement.h similarity index 92% rename from CellElement.h rename to LibCell/CellElement.h index 83c7111..58c2623 100644 --- a/CellElement.h +++ b/LibCell/CellElement.h @@ -40,5 +40,6 @@ struct cellElement { typedef struct cellElement * cellElement; +void freeCellElement(cellElement* element); #endif \ No newline at end of file diff --git a/LibList/list.c b/LibList/list.c new file mode 100644 index 0000000..e87000a --- /dev/null +++ b/LibList/list.c @@ -0,0 +1,217 @@ +/********************************************************************************* +* File Name : list.c +* Created By : Bartuccio Antoine +* Creation Date : [2016-10-18 13:53] +* Last Modified : [2016-11-08 15:00] +* Description : +**********************************************************************************/ + +#include +#include +#include +#include +#include + +#define SUCCESS 0 +#define FAILURE 1 + +List * CreateList() { + List *list = malloc(sizeof(*list)); + + if(list != NULL){ + list->head = NULL; + list->tail = NULL; + list->size = 0; + } + + return list; +} + +int unshift(List *list, cellElement *data){ + int ok = SUCCESS; + + cellElement* newData = (cellElement*) malloc(sizeof(cellElement)); + + /* Create a new element */ + + ListElement *newElement = malloc(sizeof(*newElement)); + if (list != NULL && newElement != NULL && newData != NULL){ + memcpy(newData, data, size); + newElement->data = newData; + + /* Insert the element at the begining of the list */ + + newElement->previous = NULL; + + if (list->head != NULL){ + list->head->previous = newElement; + } else { + list->tail = newElement; + } + newElement->next = list->head; + + list->head = newElement; + list->size = list->size + 1; + } else { + if (newElement != NULL){ + free(newElement); + } + if (newData != NULL){ + free(newData); + } + ok = FAILURE; + } + + return ok; +} + +int push(List *list, cellElement *data){ + int ok = SUCCESS; + cellElement *newData = (cellElement*) malloc(sizeof(cellElement)); + + ListElement *newElement = malloc(sizeof(*newElement)); + if(list != NULL && newElement != NULL && newData != NULL){ + memcpy(newData, data, size); + newElement->data = newData; + newElement->next = NULL; + if (list->tail == NULL){ + list->tail = newElement; + list->head = newElement; + newElement->previous = NULL; + } else { + newElement->previous = list->tail; + list->tail->next = newElement; + list->tail = newElement; + } + list->size = list->size + 1; + } else { + if (newElement != NULL){ + free(newElement); + } + if (newData != NULL){ + free(newData); + } + ok = FAILURE; + } + return ok; +} + +ListElement * GetElement(List *list, int nb){ + ListElement *current = NULL; + int i; + + if (list != NULL && (nb < list->size || -nb < list->size)){ + if (nb == list->size -1 || nb == -1){ + current = list->tail; + } else if (nb == 0){ + current = list->head; + } else if (nb <= (list->size - 1)/2 && nb > 0){ + i = 0; + current = list->head; + while(inext; + i++; + } + } else { + i = list->size - 1; + if (nb < 0){ + nb = list->size + nb -1; + } + while(i>nb){ + current = current->previous; + i = i - 1; + } + } + } + return current; +} + +int PopPtnList(List *list, ListElement *element){ + int ok = SUCCESS; + + if (list != NULL && element != NULL){ + if (list->head == element && list->tail == element){ + list->head = NULL; + list->tail = NULL; + } else if (list->head == element){ + list->head = element->next; + element->previous = NULL; + } else if (list->tail == element){ + list->tail = element->previous; + element->previous->next = NULL; + } else { + element->next->previous = element->previous; + element->previous->next = element->next; + } + + if (element->data != NULL){ + freeCellElement(element->data); + } + free(element); + list->size = list->size - 1; + } else { + ok = FAILURE; + } + return ok; +} + +int RemoveElement(List *list, int nb){ + int ok = SUCCESS; + ListElement *toDelete = GetElement(list, nb); + + if (toDelete != NULL){ + ok = PopPtnList(list, toDelete); + } else { + ok = FAILURE; + } + return ok; +} + +int shift(List *list){ + return RemoveElement(list, 0); +} + +int pop(List *list){ + return RemoveElement(list, -1); +} + +int DeleteListContent(List *list){ + int ok = SUCCESS; + ListElement * current = NULL; + ListElement * toDelete = NULL; + + if (list != NULL){ + current = list->head; + while (current != NULL){ + toDelete = current; + current = current->next; + + if (toDelete->data != NULL){ + freeCellElement(toDelete->data); + } + + freeCellElement(toDelete); + } + list->head = NULL; + list->tail = NULL; + list->size = 0; + } else { + ok = FAILURE; + } + + return ok; +} + +int FreeList(List *list){ + int ok = SUCCESS; + + if (list != NULL){ + ok = DeleteListContent(list); + if (ok == SUCCESS){ + free(list); + } + } else { + ok = FAILURE; + } + return ok; +} diff --git a/LibList/list.h b/LibList/list.h new file mode 100644 index 0000000..514e02a --- /dev/null +++ b/LibList/list.h @@ -0,0 +1,99 @@ +#ifndef LIST_H +#define LIST_H + +#import + +#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, int size); + +/* + * 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 bf4ff53..b69a9ff 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,56 @@ -CXX = gcc -TARGET = exe -SOURCEFILE = main -CFLAGS = -Wall -Werror -I. -ansi -pedantic -fpic -g -LIST_LIBRARY = matrix/libMatrix +# 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 $(TARGET) - -$(SOURCEFILE).o: $(LIST_LIBRARY).so - @echo "Generating $(SOURCEFILE).o" - $(CXX) $(CFLAGS) -Lmatrix -lmatrix -c $(SOURCEFILE).c -o $@ -LlibMatrix -llibMatrix.so - -$(LIST_LIBRARY).so:clean - @echo "Generating libMatrix.so" $@ - #gcc matrix.c -I. -Wall -Werror -fpic -shared -o $(LIST_LIBRARY).so - $(CXX) -Wall -Werror -ansi -pedantic -I. matrix.c -o $(LIST_LIBRARY).so -shared -fpic +CC=gcc +CFLAGS=-Wall -Werror -ansi -pedantic -fpic -g -#Cleaning the executable -clean: - @echo "Cleaning temporary files and libMatrix.so" - rm -rf *.o *- *.so $(TARGET) - rm -rf $(LIST_LIBRARY).so -#Generating library +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 "Generating libMatrix.so" - $(CXX) -Wall -Werror -ansi -pedantic -I. matrix.c -o $(LIST_LIBRARY).so -shared -fpic + @echo "\n Generating the automaton library binary" + $(MAKE) -C LibCell -release: - @echo "Generating a release version of the program" - make CFLAGS= '-Wall -Werror -I. -ansi -pedantic -fpic' +$(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 "\n Cleaning" + rm -rf *.o ./Libs/*.so *.exe + $(MAKE) -C LibPoly clean + $(MAKE) -C LibList clean diff --git a/main b/main new file mode 100755 index 0000000000000000000000000000000000000000..c1dee6249dde64de6786e3b40f9999d90aa6cd28 GIT binary patch literal 8656 zcmeHM&1(}u6rb2uOZ`f3ezQs|+CvkIsNkiQhDI#4wG}_0j7_q&(M?izH?%zzinT&O z!K0v8J$dNCf4~o@da>R-2_F0c6^}*K`1@^Uo87dECl4|YX5aqad-G=IH?y$2@5Q&z zKi3HnsS{#mjSylp+I+nbbHc!#5L?lbXj1lf^(4+GPMxGRERir=6*12%1WGxSI6D*$ z@%l%@HlZ-)CK^;@gp{s1>GG~3wfXw70OmWW{KQyJRqDk|6)>OU7E{i$sW#tLm2a(z z@Uh>aQRVafm3(r{w8l*vLACj=t9;v30%G#MEGy=hc3eA~zo-Ig^W9VVHYz`HP(r!k zkg}Mc$mTOLn;$KBIJ_SZR6g!Gg}63H#Z$R*Uq7Hp+1)kN74TsHLi_6PZ(v_>=9Y6y znYW}fl}i;YIqurO&F81#`Cxxv$iFw9GDvBS{3%}){Tbh=;)#R#cmv` zKJK4kqh_7Jltnce<_XSg51z9)1B}YpjnG?&l^BNbj(!}Papa!qvCFfv-3k7UGy|Fe&46Y=GoTsJ3}^;41DXNNfM!55@c%H-yeB%q)iigq*yk0)WeW9S6t4$t zaZ}jQ=1w_|0<=2{1c^x0mFhF?%YT=FIxE%qE0OCVl2eJq1mq` z($2bF5XXT>>muUzxf5sU=Rb&cT>N_eFmOu%)6d!?|7}o+`)~>342??C(3>M(rP7O? z@NhN%G%&)Kd(72f)>T<^g>>@X5V6yaX*;pYR&Kl_9*=bw(#4#acb!7)Pv literal 0 HcmV?d00001 diff --git a/main.c b/main.c new file mode 100644 index 0000000..32d1521 --- /dev/null +++ b/main.c @@ -0,0 +1,16 @@ +/********************************************************************************* +* File Name : main.c +* Created By : klmp200 +* Creation Date : [2016-12-10 01:06] +* Last Modified : [2016-12-10 01:07] +* Description : +**********************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + printf("Hello World\n"); + return 0; +} diff --git a/main.o b/main.o new file mode 100644 index 0000000000000000000000000000000000000000..61c790f46947dda575cdd0f75944b455e2f6f8a2 GIT binary patch literal 2352 zcmb7G-ESL35Z|?PPKX`HZ9oF?p_6DStyokBm>CA}s`M(HfA^fhmZ`$p})a?X9(=d8A*Oxq9i5 zZf0-rgz#wFA4h~pkZnk8kT9f_+iHh3e~}GJ_2U_wG5&sw<1_0urcof3n)l{b78O9X zRjKLO@`d-h9%Y^dEPspP!Q2OF@alo9SH$tQ8OMlH%FMd*K)mYQTZe2o~-cQ=N&0X(9;C&WkRk|T%oD2=+gpQp()(cFfl z?}$U3CwmW3zJ`0u15GbGoqNvaecSoQI*J9iXLKWWzSwg*E4xnT_O|$)a3+80%-rw% z>}=k$um9wD^?G2>24Q`ERFtW0>`LXz2llELwrYWIPvy_#i}veo9ld#Kst6^2X7adb zRBL|T6@|+!_!T~?H=3u5#lm#pt~5Nq-71_9gJlo0^5N+z?JR13TU5hEmxfj0E>%Mz z56Pq12`ib+rC!V)l82FZA`jzXSsG1d-%P)iK9)H*@lFQSV2K2q&Q0JEIUUj93Yv_B9?i?%Ehl4;S7zZLGjf?kGV$%&4Xu+3tx0tuGaq9V zL)S1^Llz!VVSP>pa!N_zTr4~0>PRAPO_42n1DDr-xOoy*y&Ggca_L)3ruf=@P%r+| zd?-QUXUP#n?IcAC(!vu=g-1GmayPz8yY}}tOPF5-Q*LCZl(@b1i9n@P+4NtL3}Y9H z7T$*VkO{YsOmOnE3qr2tWG*v2vIQ^NC}|I{GzAJ3ZP&f-WJX$v(UF~k_&M$V_`IN% Zn~l@JM9*N4iid^TM5reIYqatB{tKOM1AqVk literal 0 HcmV?d00001