Changeset 31 for trunk/test
- Timestamp:
- 07/16/05 15:05:19 (19 years ago)
- Location:
- trunk/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Makefile
r30 r31 3 3 ################################################################################ 4 4 5 CC=gcc 6 OPTS=-ggdb -std=gnu89 -pedantic -Wall 7 5 8 REGFIO_O=../lib/regfio.o 6 9 LIB_REGFIO_O=lib-regfio.o 7 10 LIB_REGFIO=lib-regfio 8 FILES=$(LIB_REGFIO) $( REGFIO_O)11 FILES=$(LIB_REGFIO) $(LIB_REGFIO_O) 9 12 10 13 all: $(FILES) 11 12 $(REGFIO_O): ../lib/regfio.c13 $(CC) $(CFLAGS) $(OPTS) -c -o $@ ../lib/regfio.c14 14 15 15 $(LIB_REGFIO_O): lib-regfio.c 16 16 $(CC) $(CFLAGS) $(OPTS) -c -o $@ lib-regfio.c 17 17 18 $(LIB_REGFIO): $(LIB_REGFIO_O) $(REGFIO_O) 19 $(CC) $(CFLAGS) $(OPTS) -o $@ $(LIB_REGFIO_O) $(REGFIO_O) ../lib/smb_deps.c 18 $(LIB_REGFIO): $(LIB_REGFIO_O) $(REGFIO_O) ../lib/smb_deps.o ../lib/void_stack.o 19 $(CC) $(CFLAGS) $(OPTS) -o $@ $(LIB_REGFIO_O) $(REGFIO_O) ../lib/smb_deps.o ../lib/void_stack.o 20 21 22 clean: 23 rm -f $(FILES) -
trunk/test/lib-regfio.c
r30 r31 1 1 /* 2 * A utility to test functionality of Gerald Carter''s reg io interface.2 * A utility to test functionality of Gerald Carter''s regfio interface. 3 3 * 4 4 * Copyright (C) 2005 Timothy D. Morgan … … 25 25 #include <string.h> 26 26 #include "../include/regfio.h" 27 #include "../include/void_stack.h" 27 28 28 void printKeyTree(REGF_FILE* f, REGF_NK_REC* cur, char* prefix) 29 30 char* getStackPath(void_stack* nk_stack) 29 31 { 32 REGF_NK_REC* cur; 33 unsigned int buf_left = 127; 34 unsigned int buf_len = buf_left+1; 35 unsigned int name_len = 0; 36 unsigned int grow_amt; 37 char* buf; 38 char* new_buf; 39 void_stack_iterator* iter; 40 41 buf = (char*)malloc((buf_len)*sizeof(char)); 42 if (buf == NULL) 43 return NULL; 44 buf[0] = '\0'; 45 46 iter = void_stack_iterator_new(nk_stack); 47 if (iter == NULL) 48 { 49 free(buf); 50 return NULL; 51 } 52 53 while((cur = void_stack_iterator_next(iter)) != NULL) 54 { 55 name_len = strlen(cur->keyname); 56 if(name_len+1 > buf_left) 57 { 58 grow_amt = (unsigned int)(buf_len/3); 59 buf_len += name_len+1+grow_amt-buf_left; 60 if((new_buf = realloc(buf, buf_len)) == NULL) 61 { 62 free(buf); 63 free(iter); 64 return NULL; 65 } 66 buf = new_buf; 67 buf_left = grow_amt + name_len + 1; 68 } 69 strncpy(buf+(buf_len-buf_left-1), cur->keyname, name_len); 70 buf_left -= name_len; 71 buf[buf_len-buf_left-1] = '/'; 72 buf_left -= 1; 73 buf[buf_len-buf_left-1] = '\0'; 74 } 75 76 return buf; 77 } 78 79 80 void printKeyTree(REGF_FILE* f, void_stack* nk_stack) 81 { 82 REGF_NK_REC* cur; 30 83 REGF_NK_REC* sub; 31 char* sub_prefix;84 char* path; 32 85 33 if(prefix!= NULL)86 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 34 87 { 35 sub_prefix = (char*)zalloc(strlen(prefix)+strlen(cur->keyname)+2); 36 strcpy(sub_prefix, prefix); 37 strcat(sub_prefix, "/"); 88 if((sub = regfio_fetch_subkey(f, cur)) != NULL) 89 { 90 path = getStackPath(nk_stack); 91 if(path != NULL) 92 { 93 printf("%s%s:KEY\n", path, sub->keyname); 94 free(path); 95 } 96 void_stack_push(nk_stack, sub); 97 } 98 else 99 { 100 cur = void_stack_pop(nk_stack); 101 /* XXX: This is just a shallow free. Need to write deep free 102 * routines to replace the Samba code for this. 103 */ 104 if(cur != NULL) 105 free(cur); 106 } 38 107 } 39 else40 sub_prefix = (char*)zalloc(strlen(cur->keyname)+2);41 42 strcat(sub_prefix, cur->keyname);43 44 printf("%s:KEY\n", sub_prefix);45 while ((sub = regfio_fetch_subkey(f, cur)) != NULL)46 printKeyTree(f, sub, sub_prefix);47 48 free(sub_prefix);49 108 } 50 109 … … 52 111 int main(int argc, char** argv) 53 112 { 113 void_stack* nk_stack; 114 REGF_FILE* f; 115 REGF_NK_REC* root; 116 54 117 if(argc < 2) 55 118 { … … 58 121 } 59 122 60 REGF_FILE*f = regfio_open( argv[1] );61 REGF_NK_REC*root = regfio_rootkey(f);123 f = regfio_open( argv[1] ); 124 root = regfio_rootkey(f); 62 125 63 printKeyTree(f, root, NULL); 126 nk_stack = void_stack_new(1024); 127 if(void_stack_push(nk_stack, root)) 128 printKeyTree(f, nk_stack); 129 void_stack_destroy(nk_stack); 130 64 131 regfio_close(f); 65 132 /*
Note: See TracChangeset
for help on using the changeset viewer.