baum
changeset 62:80df58d240b2 tip
merge
author | meillo@marmaro.de |
---|---|
date | Thu, 13 Nov 2008 13:19:42 +0100 |
parents | 73de2151aebd be637b2ea482 |
children | |
files | baum.c |
diffstat | 5 files changed, 45 insertions(+), 57 deletions(-) [+] |
line diff
1.1 --- a/.hgtags Thu Nov 13 13:15:11 2008 +0100 1.2 +++ b/.hgtags Thu Nov 13 13:19:42 2008 +0100 1.3 @@ -1,3 +1,4 @@ 1.4 69a7cf2f0c06a5e0f0609f80c875e2ceb7ffa9c2 0.1 1.5 3903effae5efcba191a6b459da457a3cff897c22 0.2 1.6 f9fc4c4f9e3d666dad2bd1efa627fb646334433c 0.3 1.7 +7adeee76ce3e24c4ab12f16d48ed4eab09a7daed 0.4
2.1 --- a/Makefile Thu Nov 13 13:15:11 2008 +0100 2.2 +++ b/Makefile Thu Nov 13 13:19:42 2008 +0100 2.3 @@ -9,7 +9,7 @@ 2.4 DOCS=LICENSE README ChangeLog TODO examples 2.5 2.6 # paths 2.7 -PREFIX = /usr 2.8 +PREFIX = /usr/local 2.9 BINDIR = ${PREFIX}/bin 2.10 MANDIR = ${PREFIX}/share/man 2.11 2.12 @@ -26,9 +26,10 @@ 2.13 DEP = baum.h 2.14 2.15 2.16 +.PHONY: all 2.17 +all: options $(NAME) 2.18 2.19 -all: options build 2.20 - 2.21 +.PHONY: options 2.22 options: 2.23 @echo build options: 2.24 @echo "CC = ${CC}" 2.25 @@ -37,56 +38,48 @@ 2.26 @echo "LDFLAGS = ${LDFLAGS}" 2.27 @echo 2.28 2.29 -build: options ${NAME} 2.30 2.31 ${NAME}: $(OBJ) ${DEP} 2.32 $(CC) $(LDFLAGS) $(OBJ) -o $@ 2.33 2.34 + 2.35 ${OBJ}: ${DEP} 2.36 2.37 -car: clean all 2.38 2.39 -debug: all 2.40 - gdb ${NAME} 2.41 - 2.42 +.PHONY: strip 2.43 strip: ${NAME} 2.44 @echo stripping ${NAME} 2.45 @strip ${NAME} 2.46 2.47 -dist: build changelog 2.48 + 2.49 +.PHONY: dist 2.50 +dist: all changelog 2.51 @echo "generating tarball" 2.52 @mkdir -p ${NV} 2.53 @cp -rf ${SRC} ${DEP} ${NAME}.1 Makefile ${DOCS} ${NV} 2.54 @fakeroot tar -czhof ${NV}.tar.gz ${NV} 2.55 @rm -rf ${NV} 2.56 2.57 -deb: dist 2.58 - @mkdir -p Packages 2.59 - @cp ${NV}.tar.gz Packages/ 2.60 - @( \ 2.61 - cd Packages/ ;\ 2.62 - tar -xzf ${NV}.tar.gz ;\ 2.63 - mv ${NV}.tar.gz ${NAME}_${VERSION}.orig.tar.gz ;\ 2.64 - cd ${NV}/ ;\ 2.65 - cp -r ../../debian/ . ;\ 2.66 - debuild ;\ 2.67 - ) 2.68 - @rm -rf Packages/${NV} 2.69 2.70 +.PHONY: changelog 2.71 changelog: 2.72 @echo generating changelog from mercurial log 2.73 @hg log -v --style changelog > ChangeLog 2.74 2.75 -install: build strip 2.76 + 2.77 +.PHONY: install 2.78 +install: all strip 2.79 @echo installing executable file to ${DESTDIR}${BINDIR} 2.80 @mkdir -p ${DESTDIR}${BINDIR} 2.81 @cp ${NAME} ${DESTDIR}${BINDIR} 2.82 @chmod 755 ${DESTDIR}${BINDIR}/${NAME} 2.83 @echo installing manual page to ${DESTDIR}${MANDIR}/man1 2.84 @mkdir -p ${DESTDIR}${MANDIR}/man1 2.85 - @sed 's/VERSION/${VERSION}/g' < ${NAME}.1 > ${DESTDIR}${MANDIR}/man1/${NAME}.1 2.86 + @cp ${NAME}.1 ${DESTDIR}${MANDIR}/man1 2.87 @chmod 644 ${DESTDIR}${MANDIR}/man1/${NAME}.1 2.88 2.89 + 2.90 +.PHONY: uninstall 2.91 uninstall: 2.92 @echo removing executable file from ${DESTDIR}${BINDIR} 2.93 @rm -f ${DESTDIR}${BINDIR}/${NAME} 2.94 @@ -94,17 +87,11 @@ 2.95 @rm -f ${DESTDIR}${MANDIR}/man1/${NAME}.1 2.96 2.97 2.98 +.PHONY: clean 2.99 clean: 2.100 rm -f *.o 2.101 2.102 + 2.103 +.PHONY: realclean 2.104 realclean: clean 2.105 - rm -f ${NAME} 2.106 - 2.107 -distclean: realclean 2.108 - @rm -f ${NAME}-*.tar.gz ChangeLog 2.109 - 2.110 -debclean: distclean 2.111 - @cd Packages/${NV}/ ; debuild clean ; 2.112 - 2.113 - 2.114 -.PHONY: all dist deb changelog clean distclean debclean build install uninstall 2.115 + rm -f ${NAME} ChangeLog
3.1 --- a/actions.c Thu Nov 13 13:15:11 2008 +0100 3.2 +++ b/actions.c Thu Nov 13 13:19:42 2008 +0100 3.3 @@ -11,9 +11,26 @@ 3.4 unsigned char action_if(struct Node* node); 3.5 unsigned char action_while(struct Node* node); 3.6 3.7 +struct action { 3.8 + char* name; 3.9 + unsigned char (*func)(struct Node* node); 3.10 +}; 3.11 + 3.12 +struct action actions[] = { 3.13 + {"print", action_print}, 3.14 + {"sum", action_sum}, 3.15 + {"number", action_number}, 3.16 + {"create", action_create}, 3.17 + {"times", action_times}, 3.18 + {"if", action_if}, 3.19 + {"while", action_while}, 3.20 +}; 3.21 + 3.22 3.23 3.24 unsigned char action(struct Node* node) { 3.25 + int i; 3.26 + 3.27 if (node == NULL) { 3.28 if (option_verbose) { 3.29 fprintf(stderr, "warning: action of non existing node\n"); 3.30 @@ -21,31 +38,14 @@ 3.31 return 0; 3.32 } 3.33 3.34 - if (strcmp(node->name, "print") == 0) { 3.35 - return action_print(node); 3.36 + for (i = 0; i < (sizeof(actions)/sizeof(actions[0])); i++) { 3.37 + if (strcmp(actions[i].name, node->name) == 0) { 3.38 + return (actions[i].func)(node); 3.39 + } 3.40 + } 3.41 3.42 - } else if (strcmp(node->name, "sum") == 0) { 3.43 - return action_sum(node); 3.44 - 3.45 - } else if (strcmp(node->name, "number") == 0) { 3.46 - return action_number(node); 3.47 - 3.48 - } else if (strcmp(node->name, "create") == 0) { 3.49 - return action_create(node); 3.50 - 3.51 - } else if (strcmp(node->name, "times") == 0) { 3.52 - return action_times(node); 3.53 - 3.54 - } else if (strcmp(node->name, "if") == 0) { 3.55 - return action_if(node); 3.56 - 3.57 - } else if (strcmp(node->name, "while") == 0) { 3.58 - return action_while(node); 3.59 - 3.60 - } else { 3.61 fprintf(stderr, "unknown kind of node\n"); 3.62 exit(4); 3.63 - } 3.64 } 3.65 3.66