Changeset 40 for trunk


Ignore:
Timestamp:
07/31/05 12:52:57 (19 years ago)
Author:
tim
Message:

Added type filtering to new reglookup.

Changed -f option to -p, since that letter makes more sense now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/reglookup.c

    r39 r40  
    2929
    3030
     31/* Globals, influenced by command line parameters */
     32bool print_verbose = false;
     33bool print_security = false;
     34bool path_filter_enabled = false;
     35bool type_filter_enabled = false;
     36char* path_filter = NULL;
     37int type_filter;
     38char* registry_file = NULL;
     39
     40
    3141void bailOut(int code, char* message)
    3242{
     
    131141void printValue(REGF_VK_REC* vk, char* prefix)
    132142{
    133   const char* str_type;
    134  
    135   str_type = type_val2str(vk->type);
    136   printf("%s/%s:%s=\n", prefix, vk->valuename, str_type);
     143  if(!type_filter_enabled || (vk->type == type_filter))
     144    printf("%s/%s:%s=\n", prefix, vk->valuename, type_val2str(vk->type));
    137145}
    138146
     
    154162  char* path;
    155163  char* val_path;
     164  int key_type = type_str2val("KEY");
    156165
    157166  if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)
     
    161170   
    162171    if(strlen(path) > 0)
    163       printf("%s%s:KEY\n", prefix, path);
    164     printValueList(cur, path);
     172      if(!type_filter_enabled || (key_type == type_filter))
     173        printf("%s%s:KEY\n", prefix, path);
     174    if(!type_filter_enabled || (key_type != type_filter))
     175      printValueList(cur, path);
    165176    while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)
    166177    {
     
    174185          val_path = (char*)malloc(strlen(prefix)+strlen(path)+1);
    175186          sprintf(val_path, "%s%s", prefix, path);
    176           printf("%s:KEY\n", val_path);
    177           printValueList(sub, val_path);
     187          if(!type_filter_enabled || (key_type == type_filter))
     188            printf("%s:KEY\n", val_path);
     189          if(!type_filter_enabled || (key_type != type_filter))
     190            printValueList(sub, val_path);
    178191          free(val_path);
    179192          free(path);
     
    275288{
    276289  fprintf(stderr, "Usage: readreg [-v] [-s]"
    277           " [-f <PREFIX_FILTER>] [-t <TYPE_FILTER>]"
     290          " [-p <PATH_FILTER>] [-t <TYPE_FILTER>]"
    278291          " <REGISTRY_FILE>\n");
    279292  /* XXX: replace version string with Subversion property? */
     
    282295  fprintf(stderr, "\t-v\t sets verbose mode.\n");
    283296  fprintf(stderr, "\t-s\t prints security descriptors.\n");
    284   fprintf(stderr, "\t-f\t restricts output to elements below this path.\n");
    285   fprintf(stderr, "\t-t\t restrict results to a specific data type.\n");
     297  fprintf(stderr, "\t-p\t restrict output to elements below this path.\n");
     298  fprintf(stderr, "\t-t\t restrict results to this specific data type.\n");
    286299  fprintf(stderr, "\n");
    287300}
    288 
    289 /* Globals, influenced by command line parameters */
    290 bool print_verbose = false;
    291 bool print_security = false;
    292 bool prefix_filter_enabled = false;
    293 bool type_filter_enabled = false;
    294 char* prefix_filter = NULL;
    295 char* type_filter = NULL;
    296 char* registry_file = NULL;
    297301
    298302
     
    315319  for(argi = 1; argi < argc; argi++)
    316320  {
    317     if (strcmp("-f", argv[argi]) == 0)
     321    if (strcmp("-p", argv[argi]) == 0)
    318322    {
    319323      if(++argi > argc)
    320324      {
    321325        usage();
    322         bailOut(1, "ERROR: '-f' option requires parameter.\n");
    323       }
    324       if((prefix_filter = strdup(argv[argi])) == NULL)
     326        bailOut(1, "ERROR: '-p' option requires parameter.\n");
     327      }
     328      if((path_filter = strdup(argv[argi])) == NULL)
    325329        bailOut(2, "ERROR: Memory allocation problem.\n");
    326330
    327       prefix_filter_enabled = true;
     331      path_filter_enabled = true;
    328332    }
    329333    else if (strcmp("-t", argv[argi]) == 0)
     
    334338        bailOut(1, "ERROR: '-t' option requires parameter.\n");
    335339      }
    336       if((prefix_filter = strdup(argv[argi])) == NULL)
    337         bailOut(2, "ERROR: Memory allocation problem.\n");
     340      if((type_filter = type_str2val(argv[argi])) == 0)
     341      {
     342        fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]);
     343        bailOut(1, "");
     344      }
    338345
    339346      type_filter_enabled = true;
     
    368375  if(void_stack_push(nk_stack, root))
    369376  {
    370     path_stack = path2Stack(prefix_filter);
     377    path_stack = path2Stack(path_filter);
    371378    if(void_stack_size(path_stack) < 1)
    372379      printKeyTree(f, nk_stack, "");
Note: See TracChangeset for help on using the changeset viewer.