This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:nbrimme1:portfolio:oct17 [2013/10/25 00:41] – nbrimme1 | user:nbrimme1:portfolio:oct17 [2013/12/14 20:17] (current) – nbrimme1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====October 17, 2013==== | ||
+ | Matt finished the make file for our stack program. Matt's code is included at the bottom of this entry. Information on Make files can be found [[http:// | ||
+ | __**On a lab46 terminal: | ||
+ | < | ||
+ | **Then copy the contents of the directory: | ||
+ | * **To copy into your ~/ | ||
+ | < | ||
+ | * **To copy into a different directory: | ||
+ | < | ||
+ | |||
+ | __**In Matt's Make file:**__ | ||
+ | * Variables are at the top. | ||
+ | * Then there are " | ||
+ | * Written in " | ||
+ | * The **/inc** directory contains only headers. | ||
+ | * The **/lib** directory contains only libraries. | ||
+ | * The **/src** directory contains only the source code. //**Note:** The parts rule equals the running of the shell command. This means Matt's Make file will only work on a Unix system.// | ||
+ | * **ar:** Sets up the archiver. | ||
+ | * **cc:** Sets up the compiler. | ||
+ | * **src:** Lists all .c files in the src directory. | ||
+ | * **obj:** Turns every .c file into a .o object file. | ||
+ | * **lib:** Finds the current directory the script is in. | ||
+ | * **all:** Compiles src, handles objects, handles libraries. | ||
+ | * **debug rule:** Checks to see if the source code was compiled with debug symbols. | ||
+ | * **lib rule:** Checks library information. | ||
+ | * **clean rule:** Removes all .o object files. | ||
+ | * **testing dir:** Makes the libraries, renames the executable from the source code, then builds the final executable. | ||
+ | |||
+ | __**To use Matt's Make file:**__ | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - **The terminal output for Matt's Make file:** < | ||
+ | make[1]: Entering directory `/ | ||
+ | make[2]: Entering directory `/ | ||
+ | [L] ... SUCCESS | ||
+ | make[2]: Leaving directory `/ | ||
+ | |||
+ | make[2]: Entering directory `/ | ||
+ | [B] | ||
+ | [B] | ||
+ | [B] | ||
+ | [L] ... SUCCESS | ||
+ | make[2]: Leaving directory `/ | ||
+ | |||
+ | make[2]: Entering directory `/ | ||
+ | [B] | ||
+ | peek.c:6: warning: control reaches end of non-void function | ||
+ | OK | ||
+ | [B] | ||
+ | [B] | ||
+ | [B] | ||
+ | [L] ... SUCCESS | ||
+ | make[2]: Leaving directory `/ | ||
+ | |||
+ | |||
+ | make[1]: Leaving directory `/ | ||
+ | |||
+ | |||
+ | lab46: | ||
+ | liblist.a | ||
+ | lab46: | ||
+ | make[1]: Entering directory `/ | ||
+ | make[2]: Entering directory `/ | ||
+ | rm -f *.o core | ||
+ | make[2]: Leaving directory `/ | ||
+ | make[2]: Entering directory `/ | ||
+ | rm -f *.o cp.o mk.o rm.o core | ||
+ | make[2]: Leaving directory `/ | ||
+ | make[2]: Entering directory `/ | ||
+ | rm -f *.o peek.o pop.o push.o stackops.o core | ||
+ | make[2]: Leaving directory `/ | ||
+ | make[1]: Leaving directory `/ | ||
+ | make[1]: Entering directory `/ | ||
+ | rm -f *.o stacktest core | ||
+ | make[1]: Leaving directory `/ | ||
+ | lab46: | ||
+ | make[1]: Entering directory `/ | ||
+ | make[2]: Entering directory `/ | ||
+ | ar rcs ../ | ||
+ | make[2]: Leaving directory `/ | ||
+ | |||
+ | make[2]: Entering directory `/ | ||
+ | gcc -Wall -I ../ | ||
+ | gcc -Wall -I ../ | ||
+ | gcc -Wall -I ../ | ||
+ | ar rcs ../ | ||
+ | make[2]: Leaving directory `/ | ||
+ | |||
+ | make[2]: Entering directory `/ | ||
+ | gcc -Wall -I ../ | ||
+ | peek.c: In function ' | ||
+ | peek.c:6: warning: control reaches end of non-void function | ||
+ | gcc -Wall -I ../ | ||
+ | gcc -Wall -I ../ | ||
+ | gcc -Wall -I ../ | ||
+ | ar rcs ../ | ||
+ | make[2]: Leaving directory `/ | ||
+ | |||
+ | |||
+ | make[1]: Leaving directory `/ | ||
+ | |||
+ | |||
+ | lab46: | ||
+ | \\ | ||
+ | __**Matt' | ||
+ | * **/ | ||
+ | * **/inc** | ||
+ | * **list.h**< | ||
+ | #ifndef _LIST_H | ||
+ | #define _LIST_H | ||
+ | |||
+ | #include " | ||
+ | |||
+ | struct list { | ||
+ | Node *start; | ||
+ | Node *end; | ||
+ | int qty; | ||
+ | }; | ||
+ | typedef struct list List; | ||
+ | |||
+ | List *mklist(); | ||
+ | List *insert(List *, Node *, Node *); | ||
+ | List *append(List *, Node *, Node *); | ||
+ | List *removeNode(List *, Node **); | ||
+ | void displayf(List *); | ||
+ | void displayb(List *); | ||
+ | List *clearlist(List *); | ||
+ | List *sortlist(List *); | ||
+ | |||
+ | # | ||
+ | * **node.h**< | ||
+ | #ifndef _NODE_H | ||
+ | #define _NODE_H | ||
+ | |||
+ | #include < | ||
+ | |||
+ | struct node { | ||
+ | struct node *next; | ||
+ | struct node *prev; | ||
+ | int value; | ||
+ | }; | ||
+ | typedef struct node Node; | ||
+ | |||
+ | Node *mknode(int); | ||
+ | void rmnode(Node **); | ||
+ | Node *cpnode(Node *); | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | * **queue.h**< | ||
+ | #ifndef _QUEUE_H | ||
+ | #define _QUEUE_H | ||
+ | |||
+ | #include " | ||
+ | |||
+ | struct queue { | ||
+ | List *data; | ||
+ | Node *front; | ||
+ | Node *back; | ||
+ | int bufsize; | ||
+ | }; | ||
+ | typedef struct queue Queue; | ||
+ | |||
+ | Queue *mkqueue(int); | ||
+ | Queue *enqueue(Queue *, Node *); | ||
+ | Node *dequeue(Queue **); | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | * **stack.h**< | ||
+ | #ifndef _STACK_H | ||
+ | #define _STACK_H | ||
+ | |||
+ | #include " | ||
+ | |||
+ | struct stack { | ||
+ | List *data; | ||
+ | Node *top; | ||
+ | int size; | ||
+ | }; | ||
+ | typedef struct stack Stack; | ||
+ | |||
+ | Stack *mkstack(int); | ||
+ | Stack *push | ||
+ | Node *pop (Stack **); | ||
+ | Node *peek | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | * **/lib** | ||
+ | * **liblist.a**: | ||
+ | * **libnode.a**: | ||
+ | * **libstack.a**: | ||
+ | * **/src** | ||
+ | * **/ | ||
+ | * **Makefile**< | ||
+ | CFLAGS = -Wall | ||
+ | INC = -I ../../inc | ||
+ | AR = ar | ||
+ | CC = gcc $(CFLAGS) $(INC) | ||
+ | SRC = $(shell /bin/ls -1 *.c 2>/ | ||
+ | OBJ = $(SRC: | ||
+ | LIB = $(shell /bin/pwd | /bin/sed ' | ||
+ | all: $(SRC) $(OBJ) lib | ||
+ | |||
+ | debug: CC += -DDEBUG -g | ||
+ | debug: DEBUG = debug | ||
+ | debug: $(SRC) $(OBJ) lib | ||
+ | |||
+ | .c.o: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(CC) -c $< && echo " | ||
+ | else | ||
+ | $(CC) -c $< | ||
+ | endif | ||
+ | |||
+ | lib: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(AR) rcs ../ | ||
+ | else | ||
+ | $(AR) rcs ../ | ||
+ | endif | ||
+ | |||
+ | |||
+ | clean: | ||
+ | rm -f *.o $(OBJ) core</ | ||
+ | * **/ | ||
+ | * **Makefile**< | ||
+ | CFLAGS = -Wall | ||
+ | INC = -I ../../inc | ||
+ | AR = ar | ||
+ | CC = gcc $(CFLAGS) $(INC) | ||
+ | SRC = $(shell /bin/ls -1 *.c 2>/ | ||
+ | OBJ = $(SRC: | ||
+ | LIB = $(shell /bin/pwd | /bin/sed ' | ||
+ | all: $(SRC) $(OBJ) lib | ||
+ | |||
+ | debug: CC += -DDEBUG -g | ||
+ | debug: DEBUG = debug | ||
+ | debug: $(SRC) $(OBJ) lib | ||
+ | |||
+ | .c.o: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(CC) -c $< && echo " | ||
+ | else | ||
+ | $(CC) -c $< | ||
+ | endif | ||
+ | |||
+ | lib: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(AR) rcs ../ | ||
+ | else | ||
+ | $(AR) rcs ../ | ||
+ | endif | ||
+ | |||
+ | |||
+ | clean: | ||
+ | rm -f *.o $(OBJ) core | ||
+ | </ | ||
+ | * **/ | ||
+ | * **cp.c**< | ||
+ | #include " | ||
+ | |||
+ | Node *cpnode(Node *tmp) | ||
+ | { | ||
+ | Node *newNode = mknode(tmp -> value); | ||
+ | |||
+ | newNode -> prev = newNode -> next = NULL; | ||
+ | |||
+ | return(newNode); | ||
+ | } | ||
+ | </ | ||
+ | * **mk.c**< | ||
+ | #include " | ||
+ | |||
+ | Node *mknode(int value) | ||
+ | { | ||
+ | Node *tmp = (Node *) malloc (sizeof(Node)); | ||
+ | |||
+ | tmp -> prev = tmp -> next = NULL; | ||
+ | tmp -> value = | ||
+ | |||
+ | return(tmp); | ||
+ | } | ||
+ | </ | ||
+ | * **rm.c**< | ||
+ | #include " | ||
+ | |||
+ | void rmnode(Node **tmp) | ||
+ | { | ||
+ | if ((*tmp) -> prev != NULL) | ||
+ | { | ||
+ | (*tmp) -> prev -> next = (*tmp) -> next; | ||
+ | } | ||
+ | |||
+ | if ((*tmp) -> next != NULL) | ||
+ | { | ||
+ | (*tmp) -> next -> prev = (*tmp) -> prev; | ||
+ | } | ||
+ | |||
+ | (*tmp) -> prev = (*tmp) -> next = NULL; | ||
+ | } | ||
+ | </ | ||
+ | * **cp.o**: Object file for cp.c | ||
+ | * **mk.o**: Object file for mk.o | ||
+ | * **rm.o**: Object file for rm.o | ||
+ | * **/ | ||
+ | * **Makefile**< | ||
+ | CFLAGS = -Wall | ||
+ | INC = -I ../../inc | ||
+ | AR = ar | ||
+ | CC = gcc $(CFLAGS) $(INC) | ||
+ | SRC = $(shell /bin/ls -1 *.c 2>/ | ||
+ | OBJ = $(SRC: | ||
+ | LIB = $(shell /bin/pwd | /bin/sed ' | ||
+ | all: $(SRC) $(OBJ) lib | ||
+ | |||
+ | debug: CC += -DDEBUG -g | ||
+ | debug: DEBUG = debug | ||
+ | debug: $(SRC) $(OBJ) lib | ||
+ | |||
+ | .c.o: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(CC) -c $< && echo " | ||
+ | else | ||
+ | $(CC) -c $< | ||
+ | endif | ||
+ | |||
+ | lib: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(AR) rcs ../ | ||
+ | else | ||
+ | $(AR) rcs ../ | ||
+ | endif | ||
+ | |||
+ | |||
+ | clean: | ||
+ | rm -f *.o $(OBJ) core | ||
+ | </ | ||
+ | * **peek.c**< | ||
+ | #include " | ||
+ | |||
+ | Node *peek(Stack *myStack) | ||
+ | { | ||
+ | // exercise left to the implementer | ||
+ | } | ||
+ | </ | ||
+ | * **pop.c**< | ||
+ | #include " | ||
+ | |||
+ | Node *pop(Stack **myStack) | ||
+ | { | ||
+ | Node *tmp = NULL; | ||
+ | |||
+ | if ((*myStack) != NULL) | ||
+ | { | ||
+ | tmp = (*myStack) -> data -> end; | ||
+ | (*myStack) -> data = removeNode((*myStack) -> data, &tmp); | ||
+ | (*myStack) -> top = (*myStack) -> data -> end; | ||
+ | } | ||
+ | |||
+ | return (tmp); | ||
+ | } | ||
+ | </ | ||
+ | * **push.c**< | ||
+ | #include " | ||
+ | |||
+ | Stack *push(Stack *myStack, Node *newNode) | ||
+ | { | ||
+ | if ((myStack -> size <= 0) || ((myStack -> data -> qty) < (myStack -> size))) | ||
+ | { | ||
+ | myStack -> data = append(myStack -> data, myStack -> data -> end, newNode); | ||
+ | myStack -> top = myStack -> data -> end; | ||
+ | } | ||
+ | |||
+ | return(myStack); | ||
+ | } | ||
+ | </ | ||
+ | * **stackops.c**< | ||
+ | #include " | ||
+ | |||
+ | Stack *mkstack(int size) | ||
+ | { | ||
+ | Stack *myStack; | ||
+ | |||
+ | myStack = (Stack *) malloc (sizeof(Stack)); | ||
+ | |||
+ | myStack -> data = mklist(); | ||
+ | myStack -> size = size; | ||
+ | myStack -> top = myStack -> data -> end; | ||
+ | |||
+ | return (myStack); | ||
+ | } | ||
+ | </ | ||
+ | * **peek.o**: Object file for peek.c. | ||
+ | * **pop.o**: Object file for pop.c. | ||
+ | * **push.o**: Object file for push.c. | ||
+ | * **stackops.o**: | ||
+ | * **Makefile**< | ||
+ | SHELL = /bin/bash -e | ||
+ | CC = g++ $(CFLAGS) $(OPTS) $(INC) | ||
+ | INC = -I ../include/ | ||
+ | CFLAGS = -Wall | ||
+ | OBJ = $(shell find . -name *.o) | ||
+ | OPTS = | ||
+ | PARTS = $(shell /bin/ls -1Ad * | grep -v ' | ||
+ | AR = ar | ||
+ | DEBUG = | ||
+ | default: libs | ||
+ | |||
+ | debug: CC += -DDEBUG -g | ||
+ | debug: DEBUG = debug | ||
+ | debug: libs | ||
+ | |||
+ | libs: | ||
+ | @for i in $(PARTS); do make -C $$i $(DEBUG); echo; done | ||
+ | @echo | ||
+ | |||
+ | clean: | ||
+ | @for i in $(PARTS); do make -C $$i clean; done | ||
+ | @rm -f ${LIB}</ | ||
+ | * **/ | ||
+ | * **Makefile**< | ||
+ | SHELL = /bin/bash -e | ||
+ | INC = -I inc/ | ||
+ | CCFLAGS = -Wall | ||
+ | OPTS = | ||
+ | CC = gcc $(CCFLAGS) $(OPTS) $(INC) | ||
+ | OBJ = | ||
+ | AR = ar | ||
+ | DEBUG = | ||
+ | LIBS = src | ||
+ | UNIT = testing | ||
+ | ALL = $(LIBS) testing | ||
+ | BIN = | ||
+ | default: libs testing | ||
+ | debug: libs-debug testing-debug | ||
+ | #default: $(LIBS) $(BIN) | ||
+ | |||
+ | libs-debug: CC += -DDEBUG -g | ||
+ | libs-debug: DEBUG = debug | ||
+ | libs-debug: libs | ||
+ | |||
+ | libs: | ||
+ | @for i in $(LIBS); do make -C $$i $(DEBUG); echo; done | ||
+ | @echo | ||
+ | |||
+ | testing-debug: | ||
+ | testing-debug: | ||
+ | testing-debug: | ||
+ | |||
+ | testing: | ||
+ | @for i in $(UNIT); do make -C $$i $(DEBUG); echo; done | ||
+ | @echo | ||
+ | |||
+ | clean: | ||
+ | @for i in $(ALL); do make -C $$i clean; done | ||
+ | # @rm -f bin/* | ||
+ | |||
+ | copy: | ||
+ | mkdir -p ~/ | ||
+ | cp -av / | ||
+ | |||
+ | help: | ||
+ | @echo | ||
+ | @echo " | ||
+ | @echo "** make - build everything | ||
+ | @echo "** make debug - build everything with debug symbols | ||
+ | @echo " | ||
+ | @echo "** make testing | ||
+ | @echo "** make testing-debug | ||
+ | @echo "** make libs - build all supporting libraries | ||
+ | @echo "** make libs-debug | ||
+ | @echo " | ||
+ | @echo "** make clean - clean; remove all objects/ | ||
+ | @echo "** make help - this information | ||
+ | @echo " | ||
+ | </ | ||
+ | * **stacktest.c**< | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | Node *tmp; | ||
+ | Stack *myStack; | ||
+ | myStack = mkstack(0); | ||
+ | tmp = create(); | ||
+ | tmp -> value = fgetc(stdin); | ||
+ | fgetc(stdin); | ||
+ | |||
+ | while(tmp-> | ||
+ | { | ||
+ | myStack = push(myStack, | ||
+ | tmp = create(); | ||
+ | tmp-> | ||
+ | fgetc(stdin); | ||
+ | } | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | do { | ||
+ | tmp = pop(& | ||
+ | if(tmp != NULL) | ||
+ | { | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | rmnode(*tmp); | ||
+ | } | ||
+ | while(tmp != NULL); | ||
+ | |||
+ | fprintf(stdout, | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | * **Makefile**< | ||
+ | SHELL = /bin/bash -e | ||
+ | INC = -I inc/ | ||
+ | CCFLAGS = -Wall | ||
+ | OPTS = | ||
+ | CC = gcc $(CCFLAGS) $(OPTS) $(INC) | ||
+ | OBJ = | ||
+ | AR = ar | ||
+ | DEBUG = | ||
+ | LIBS = src | ||
+ | UNIT = testing | ||
+ | ALL = $(LIBS) testing | ||
+ | BIN = | ||
+ | default: libs testing | ||
+ | debug: libs-debug testing-debug | ||
+ | #default: $(LIBS) $(BIN) | ||
+ | |||
+ | libs-debug: CC += -DDEBUG -g | ||
+ | libs-debug: DEBUG = debug | ||
+ | libs-debug: libs | ||
+ | |||
+ | libs: | ||
+ | @for i in $(LIBS); do make -C $$i $(DEBUG); echo; done | ||
+ | @echo | ||
+ | |||
+ | testing-debug: | ||
+ | testing-debug: | ||
+ | testing-debug: | ||
+ | |||
+ | testing: | ||
+ | @for i in $(UNIT); do make -C $$i $(DEBUG); echo; done | ||
+ | @echo | ||
+ | |||
+ | clean: | ||
+ | @for i in $(ALL); do make -C $$i clean; done | ||
+ | # @rm -f bin/* | ||
+ | |||
+ | copy: | ||
+ | mkdir -p ~/ | ||
+ | cp -av / | ||
+ | |||
+ | help: | ||
+ | @echo | ||
+ | @echo " | ||
+ | @echo "** make - build everything | ||
+ | @echo "** make debug - build everything with debug symbols | ||
+ | @echo " | ||
+ | @echo "** make testing | ||
+ | @echo "** make testing-debug | ||
+ | @echo "** make libs - build all supporting libraries | ||
+ | @echo "** make libs-debug | ||
+ | @echo " | ||
+ | @echo "** make clean - clean; remove all objects/ | ||
+ | @echo "** make help - this information | ||
+ | @echo " | ||
+ | </ | ||
+ | |||
+ | I'm finding that GDB is quickly becoming an indispensable and invaluable tool when finding and fixing bugs. The command alias **gcc=' | ||
+ | |||
+ | I had the idea to use 2 lists instead of modifying just 1. My logic is complicated and that logic seems far more simpler; and hopefully simpler to implement. | ||
+ | |||
+ | **Pseudocode/ | ||
+ | - Create 2 lists: (Not sure this will work; Could copy tmp's list into tmp2's list, then call clearList() on tmp2?). | ||
+ | - tmp -> unsorted list. | ||
+ | - tmp2 -> sorted list. | ||
+ | - Find the lowest value in tmp's list | ||
+ | - Insert that value into tmp2's list | ||
+ | - Remove the lowest value from tmp's list | ||
+ | - Repeat steps 2-4 until the program is at the end of the tmp's list. | ||
+ | - Not sure if this is needed; delete empty tmp list? | ||
+ | - Display tmp2's sorted list. | ||
+ | |||
+ | [[http:// |