- Timestamp:
- 07/31/05 11:00:59 (19 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/Makefile
r34 r38 1 1 # $Id$ 2 2 3 default: 3 BUILD_FILES=$(BUILD_DOC)/man/man1/reglookup.1.gz 4 5 default: $(BUILD_FILES) 6 7 $(BUILD_DOC)/man/man1/reglookup.1.gz: man/man1/reglookup.1.gz 4 8 mkdir -p $(BUILD_DOC)/man/man1 5 cp man/man1/reglookup.1.gz $ (BUILD_DOC)/man/man1/reglookup.1.gz9 cp man/man1/reglookup.1.gz $@ 6 10 7 11 install: -
trunk/include/void_stack.h
r33 r38 37 37 38 38 void_stack* void_stack_new(unsigned short max_size); 39 void_stack* void_stack_copy(const void_stack* v); 40 void_stack* void_stack_copy_reverse(const void_stack* v); 39 41 void void_stack_destroy(void_stack* stack); 42 void void_stack_destroy_deep(void_stack* stack); 40 43 unsigned short void_stack_size(void_stack* stack); 41 44 void* void_stack_pop(void_stack* stack); -
trunk/lib/void_stack.c
r33 r38 50 50 51 51 52 void_stack* void_stack_copy(const void_stack* v) 53 { 54 unsigned int i; 55 void_stack* ret_val; 56 if(v == NULL) 57 return NULL; 58 59 ret_val = void_stack_new(v->max_size); 60 if(ret_val == NULL) 61 return NULL; 62 63 for(i = 0; i < v->top; i++) 64 ret_val->elements[i] = v->elements[i]; 65 ret_val->top = v->top; 66 67 return ret_val; 68 } 69 70 71 void_stack* void_stack_copy_reverse(const void_stack* v) 72 { 73 unsigned int i; 74 void_stack* ret_val; 75 if(v == NULL) 76 return NULL; 77 78 ret_val = void_stack_new(v->max_size); 79 if(ret_val == NULL) 80 return NULL; 81 82 for(i = 0; i < v->top; i++) 83 ret_val->elements[i] = v->elements[v->top-i-1]; 84 ret_val->top = v->top; 85 86 return ret_val; 87 } 88 89 52 90 void void_stack_destroy(void_stack* stack) 91 { 92 free(stack); 93 } 94 95 96 void void_stack_destroy_deep(void_stack* stack) 53 97 { 54 98 unsigned short i; -
trunk/src/reglookup.c
r37 r38 28 28 #include "../include/void_stack.h" 29 29 30 /* XXX: this needs to be rewritten to malloc each resulting string, instead of 31 * altering them in place 32 */ 30 31 void bailOut(int code, char* message) 32 { 33 fprintf(stderr, message); 34 exit(code); 35 } 36 37 33 38 void_stack* path2Stack(const char* s) 34 39 { 35 void_stack* ret_val = void_stack_new(1024); 40 void_stack* ret_val; 41 void_stack* rev_ret = void_stack_new(1024); 42 const char* cur = s; 36 43 char* next = NULL; 37 char* cur; 44 char* copy; 45 46 if (rev_ret == NULL) 47 return NULL; 38 48 if (s == NULL) 39 return ret_val; 40 else 41 cur = strdup(s); 42 43 while((next = strrchr(cur, '/')) != NULL) 44 { 45 next[0] = '\0'; 46 if(strlen(next+1) > 0) 47 void_stack_push(ret_val, next+1); 49 return rev_ret; 50 51 while((next = strchr(cur, '/')) != NULL) 52 { 53 if ((next-cur) > 0) 54 { 55 copy = (char*)malloc((next-cur+1)*sizeof(char)); 56 if(copy == NULL) 57 bailOut(2, "ERROR: Memory allocation problem.\n"); 58 59 memcpy(copy, cur, next-cur); 60 copy[next-cur] = '\0'; 61 void_stack_push(rev_ret, copy); 62 } 63 cur = next+1; 48 64 } 49 65 if(strlen(cur) > 0) 50 void_stack_push(ret_val, cur); 66 { 67 copy = strdup(cur); 68 void_stack_push(rev_ret, copy); 69 } 70 71 ret_val = void_stack_copy_reverse(rev_ret); 72 void_stack_destroy(rev_ret); 51 73 52 74 return ret_val; … … 284 306 if(argc < 2) 285 307 { 286 printf("ERROR: Requires 1 argument.\n");287 308 usage(); 288 exit(1);309 bailOut(1, "ERROR: Requires 1 argument.\n"); 289 310 } 290 311 … … 295 316 if(++argi > argc) 296 317 { 297 fprintf(stderr, "ERROR: '-f' option requires parameter.\n");298 318 usage(); 299 exit(1);319 bailOut(1, "ERROR: '-f' option requires parameter.\n"); 300 320 } 301 321 if((prefix_filter = strdup(argv[argi])) == NULL) 302 { 303 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 304 exit(2); 305 } 322 bailOut(2, "ERROR: Memory allocation problem.\n"); 323 306 324 prefix_filter_enabled = true; 307 325 } … … 310 328 if(++argi > argc) 311 329 { 312 fprintf(stderr, "ERROR: '-t' option requires parameter.\n");313 330 usage(); 314 exit(1);331 bailOut(1, "ERROR: '-t' option requires parameter.\n"); 315 332 } 316 333 if((prefix_filter = strdup(argv[argi])) == NULL) 317 { 318 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 319 exit(2); 320 } 334 bailOut(2, "ERROR: Memory allocation problem.\n"); 335 321 336 type_filter_enabled = true; 322 337 } … … 327 342 else if (argv[argi][0] == '-') 328 343 { 344 usage(); 329 345 fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]); 330 usage(); 331 exit(1); 346 bailOut(1, ""); 332 347 } 333 348 else 334 349 { 335 350 if((registry_file = strdup(argv[argi])) == NULL) 336 { 337 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 338 exit(2); 339 } 351 bailOut(2, "ERROR: Memory allocation problem.\n"); 340 352 } 341 353 } … … 345 357 { 346 358 fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file); 347 exit(1); 348 } 359 bailOut(3, ""); 360 } 361 349 362 root = regfio_rootkey(f); 350 363 nk_stack = void_stack_new(1024); … … 361 374 fprintf(stderr, "WARNING: specified path not found.\n"); 362 375 else if(retr_path_ret != 0) 363 fprintf(stderr, "ERROR:\n");376 bailOut(4, "ERROR:\n"); 364 377 } 365 378 } 366 379 else 367 { 368 fprintf(stderr, "ERROR: Memory allocation problem.\n"); 369 exit(2); 370 } 371 void_stack_destroy(nk_stack); 372 380 bailOut(2, "ERROR: Memory allocation problem.\n"); 381 382 void_stack_destroy_deep(nk_stack); 373 383 regfio_close(f); 374 384
Note: See TracChangeset
for help on using the changeset viewer.