const char *const def_short_options="C:c:T:BhVjsbPHrU:Sx";
const char *const def_short_options="C:c:T:BhVvjsbPHrU:Sx";
int complearn_getopt_long(int argc,  char * const argv[], const char *optstring,                const struct option *longopts, int *longindex, struct GeneralConfig *cfg){  static int fCmdSaved;  int oldargc = argc;  int oldoptind;  char *oldargv[64];  int result;  int oldopterr = opterr;  int oldlongind = 0;  int i;  int fDidOurOption;  assert(argv);  assert(argc > 0);  for (i = 0; i < argc; i += 1)    oldargv[i] = gstrdup(argv[i]);  oldargv[i] = NULL;  if (!fCmdSaved) {    saveCmd(cfg, oldargc, oldargv);    fCmdSaved = 1;  }  assert(cfg);  curEnv = cfg;  do {    oldoptind = optind;    fDidOurOption = 0;    if (longindex)      oldlongind = *longindex;    opterr = 0; /* suppress error message here *//*  if (longindex) {    printf("Longindex is first %d\n", *longindex);  }  */  result = getopt_long(argc, argv, optstring, longopts, longindex);//  printf("Got first result %c with longindex %d\n", result, *longindex);  opterr = oldopterr; /* restore old opterr value */  if (result == ':' && oldopterr) { /* missing parameter must print error */    if (longindex)      *longindex = oldlongind;    optind = oldoptind;    result = getopt_long(argc, argv, optstring, longopts, longindex);    if (longindex)      *longindex = oldlongind;  }  if (result == -1) { /* long option successful */    return result;  }  if (result == '?') {    optind = oldoptind;    if (longindex)      *longindex = oldlongind;    const char *const def_short_options="C:c:T:BhVjsbPHrU:Sx";    static struct option def_long_options[] = {      { "config-file", 1, NULL, 'c' },      { "version", 0, NULL, 'V' },      { "verbose", 0, NULL, 'v' },      { "suppress", 0, NULL, 's' }, /* suppress ASCII output */      { "binary", 0, NULL, 'B' },   /* binary output mode */      { "both", 0, NULL, 'b' },   /* both output mode */      { "svd-project", 0, NULL, 'P' },      { "compressor", 1, NULL, 'C' },      { "size", 0, NULL, 'S' },     /* Just the compressed size, not NCD */      { "exp", 0, NULL, 'x' }, /* print out 2^val instead of val */      { "html", 0, NULL, 'H' },      { "treeout", 1, NULL, 'T' },   /* tree output file <filename> */      { "suppressdetails", 0, NULL, 'r' },      { "user-settings", 1, NULL, 'U' },      { "help", 0, NULL, 'h' },      { 0, 0, 0, 0 }  };//    printf("Passing in %d for argc, %s for av0, %s for av1, %p for av2\n", oldargc, oldargv[0], oldargv[1], oldargv[2]);    result = getopt_long(oldargc, oldargv, def_short_options, def_long_options, NULL);//    printf("Got second result %d with optind %d\n", result, optind);    if (result == -1) /* options done */      break;    fDidOurOption = 1;    switch (result) {      case 'h':        printOptionHelp();        cleanupBeforeExit();        exit(0);      case 'v':        curEnv->fVerbose = 1;        break;      case 'V':        printf("%s version %s, please send bugs to %s\n", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_BUGREPORT);        cleanupBeforeExit();        exit(0);      case 'T':        curEnv->output_tree_fname = gstrdup(optarg);        break;      case 'B':        curEnv->fBinary = 1;        break;      case 'S':        curEnv->fJustSize = 1;        break;      case 'x':        curEnv->fDoExponentiate = 1;        break;      case 'b':        curEnv->fBinary = 1;        curEnv->fAscii = 1;        break;      case 'C':        gfreeifpresent(curEnv->compressor_name);        curEnv->compressor_name = gstrdup(optarg);        break;      case 's':        curEnv->fAscii = 0;        break;      case 'c':        curEnv->config_filename = gstrdup(optarg);        readSpecificFile(curEnv->em, curEnv->config_filename);        updateEMToConfig(curEnv);        break;      case 'r':        curEnv->fSuppressVisibleDetails = 1;        break;      case 'U':        handleLine(curEnv->em,optarg);        updateEMToConfig(curEnv);        break;      case 'P':        curEnv->fSVD = 1;        break;      case 'H':        curEnv->fHTML = 1;        break;      default:        fDidOurOption = 0;        if (oldopterr)          fprintf(stderr,"Unrecognized command-line option phase %d with long index %d\n", result, *longindex);        break;    }  }  } while (fDidOurOption);  memcpy(cfg, curEnv, sizeof(*curEnv));  curEnv = NULL;  return result;}