Changeset 54 for trunk/src


Ignore:
Timestamp:
09/04/05 21:19:05 (19 years ago)
Author:
tim
Message:

Added some verbose output

code cleanup and minor bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/reglookup.c

    r53 r54  
    184184
    185185  /* XXX: this MULTI_SZ parser is pretty inefficient.  Should be
    186    *      redone with fewer malloc and better string concatenation.
     186   *      redone with fewer malloc calls and better string concatenation.
    187187   */
    188188  case REG_MULTI_SZ:
     
    317317  if (buf == NULL)
    318318    return NULL;
    319   buf[0] = '/';
    320   buf[1] = '\0';
     319  buf[0] = '\0';
    321320
    322321  iter = void_stack_iterator_new(nk_stack);
     
    472471
    473472
    474 /* XXX: this function is god-awful.  Needs to be re-designed. */
     473/* XXX: this function is awful.  Needs to be re-designed. */
    475474void printKeyTree(REGF_FILE* f, void_stack* nk_stack, char* prefix)
    476475{
     
    479478  char* path = NULL;
    480479  char* val_path = NULL;
    481 
    482480  int key_type = regfio_type_str2val("KEY");
    483481 
     
    486484    cur->subkey_index = 0;
    487485    path = stack2Path(nk_stack);
    488    
     486
     487    if(print_verbose)
     488    {
     489      if(prefix[0] == '\0')
     490        fprintf(stderr, "VERBOSE: Printing key tree under path: /\n");
     491      else
     492        fprintf(stderr, "VERBOSE: Printing key tree under path: %s\n",
     493                prefix);
     494    }
    489495
    490496    val_path = (char*)malloc(strlen(prefix)+strlen(path)+1);
    491497    sprintf(val_path, "%s%s", prefix, path);
     498    if(val_path[0] == '\0')
     499    {
     500      val_path[0] = '/';
     501      val_path[1] = '\0';
     502    }
     503
    492504    if(!type_filter_enabled || (key_type == type_filter))
    493505      printKey(cur, val_path);
    494 
    495506    if(!type_filter_enabled || (key_type != type_filter))
    496507      printValueList(cur, val_path);
     
    527538    }
    528539  }
     540  if(print_verbose)
     541    fprintf(stderr, "VERBOSE: Finished printing key tree.\n");
    529542}
    530543
     
    559572  cur = (REGF_NK_REC*)void_stack_cur(nk_stack);
    560573
     574  if(print_verbose)
     575    fprintf(stderr, "VERBOSE: Beginning retrieval of specified path: %s\n",
     576            path_filter);
     577
    561578  while(void_stack_size(path_stack) > 1)
    562579  {
     
    575592      }
    576593    }
     594    if(print_verbose && !found_cur)
     595      fprintf(stderr, "VERBOSE: Could not find KEY '%s' in specified path.\n",
     596              cur_str);
     597
    577598    free(cur_str);
    578 
    579599    if(!found_cur)
    580600      return 1;
     
    583603  /* Last round, search value and key records */
    584604  cur_str = (char*)void_stack_pop(path_stack);
     605
     606  if(print_verbose)
     607    fprintf(stderr, "VERBOSE: Searching values for last component"
     608                    " of specified path.\n");
    585609
    586610  for(i=0; (i < cur->num_values); i++)
     
    594618      if(path != NULL)
    595619        free(path);
     620
     621      if(print_verbose)
     622        fprintf(stderr, "VERBOSE: Found final path element as value.\n");
     623
    596624      return 0;
    597625    }
    598626  }
     627
     628  if(print_verbose)
     629    fprintf(stderr, "VERBOSE: Searching keys for last component"
     630                    " of specified path.\n");
    599631
    600632  while((sub = regfio_fetch_subkey(f, cur)) != NULL)
     
    611643      strcat(prefix, "/");
    612644      strcat(prefix, sub->keyname);
     645
     646      if(print_verbose)
     647        fprintf(stderr, "VERBOSE: Found final path element as key.\n");
     648
    613649      printKeyTree(f, sub_nk_stack, prefix);
     650
    614651      return 0;
    615652    }
    616653  }
     654
     655  if(print_verbose)
     656    fprintf(stderr, "VERBOSE: Could not find last element of path.\n");
    617657
    618658  return 1;
Note: See TracChangeset for help on using the changeset viewer.