Пример #1
0
static bool process_config_parameter(const parm_desc *arg, char *val, priority_t precedence)
/* returns true if ok, false if error */
{
    bool ok = true;
    if (arg->addr.v == NULL)
       return ok;
    switch (arg->type)
    {
       case CP_BOOLEAN:
           {
               *arg->addr.b = str_to_bool(val);
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> %s\n", arg->name,
                           *arg->addr.b ? "Yes" : "No");
               break;
           }
       case CP_INTEGER:
           {
               remove_comment(val);
               if (!xatoi(arg->addr.i, val))
                   return false;
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> %d\n", arg->name, *arg->addr.i);
               break;
           }
       case CP_DOUBLE:
           {
               remove_comment(val);
               if (!xatof(arg->addr.d, val))
                   return false;
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> %f\n", arg->name, *arg->addr.d);
               break;
           }
       case CP_CHAR:
           {
               *arg->addr.c = *val;
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> '%c'\n", arg->name, *arg->addr.c);
               break;
           }
       case CP_STRING:
           {
               *arg->addr.s = xstrdup(val);
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> '%s'\n", arg->name, *arg->addr.s);
               break;
           }
       case CP_DIRECTORY:
           {
               char *dir = tildeexpand(val, true);
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> '%s'\n", arg->name, dir);
               if (setup_wordlists(dir, precedence) != 0)
                   exit(EX_ERROR);
                          xfree(dir);
               break;
           }
       case CP_FUNCTION:
       {
           ok = (*arg->addr.f)((unsigned char *)val);
           if (DEBUG_CONFIG(2))
               fprintf(dbgout, "%s -> '%s'\n", arg->name, val);
           break;
       }
       case CP_WORDLIST:
       {
           char c = *val;
           switch (c) {
           case 'c': wl_mode = WL_M_COMBINED; break;
           case 's': wl_mode = WL_M_SEPARATE; break;
           default:
               fprintf(stderr, "Unknown wordlist type - '%s'.\n", val);
               exit(EX_ERROR);
           }
           if (DEBUG_CONFIG(2))
               fprintf(dbgout, "%s -> '%s'\n", arg->name, val);
           break;
       }
       default:
       {
           ok = false;
           break;
       }
    }
    return ok;
}
Пример #2
0
void getargs(args *a, int argc, char **argv) {
  int c;

  a->out_file = "-";
  a->hit_num = n_def;
  a->two_strands = 0;
  a->delete_pseudo = D_def;
  a->no_delete_pseudo = E_def;
  a->insert_pseudo = I_def;
  a->no_insert_pseudo = J_def;
  a->dirichlet_file = NULL;

  /* non-ANSI: */
  while ((c = getopt(argc, argv, "ho:n:2D:E:I:J:d:")) != -1) {
    switch (c) {
    case 'h':
      help();
    case 'o':
      a->out_file = optarg;
      break;
    case 'n':
      a->hit_num = xatoi(optarg);
      if (a->hit_num < 0)  /* let's allow 0, even though it's stupid */
	die("%s: option -n should be at least 0\n", prog_name);
      break;
    case '2':
      a->two_strands = 1;
      break;
    case 'D':
      a->delete_pseudo = xatof(optarg);
      if (a->delete_pseudo <= 0)
	die("%s: option -D should be > 0\n", prog_name);
      break;
    case 'E':
      a->no_delete_pseudo = xatof(optarg);
      if (a->no_delete_pseudo <= 0)
	die("%s: option -E should be > 0\n", prog_name);
      break;
    case 'I':
      a->insert_pseudo = xatof(optarg);
      if (a->insert_pseudo <= 0)
	die("%s: option -I should be > 0\n", prog_name);
      break;
    case 'J':
      a->no_insert_pseudo = xatof(optarg);
      if (a->no_insert_pseudo <= 0)
	die("%s: option -J should be > 0\n", prog_name);
      break;
    case 'd':
      a->dirichlet_file = optarg;
      break;
    case '?':
      usage();
    }
  }

  if (optind != argc-3)
    usage();
  a->alph_name = argv[optind++];
  a->motif_file = argv[optind++];
  a->seq_file = argv[optind++];
}