rem: char cmd[512], fstring[16], status = 0, curopt, *optstr = "ftsmhbcra:u";
add: char cmd[512], fstring[16], status = 0, *optstr = "ftsmhbcra:u"; int curopt;
context: int main(int argc, char *argv[]) {   char cmd[512], fstring[16], status = 0, curopt, *optstr = "ftsmhbcra:u";   unsigned char sec;   float curfilelength, totlength = 0;   unsigned int min, curarg;   FILE *file;   struct options opts;   /* No surprises please */  opts.adjust = FALSE;  opts.format = FALSE;   opts.total = FALSE;   opts.script = FALSE;   opts.human = FALSE;   opts.bits = FALSE;  opts.ccount = FALSE;  opts.rate = FALSE;  opts.samples = FALSE;  /* Now let's parse and set. */  while ((curopt = getopt(argc, argv, optstr)) != -1) {     switch (curopt) {     case 'a' : opts.adjust = TRUE;      strcpy(fstring, optarg);      break;    case 'f' : opts.format = TRUE;       break;     case 't' : opts.total = TRUE;       break;     case 's' : opts.script = TRUE;       break;     case 'm' : opts.human = TRUE;       break;     case 'b' : opts.bits = TRUE;      break;    case 'c' : opts.ccount = TRUE;      break;    case 'r' : opts.rate = TRUE;      break;    case 'u' : opts.samples = TRUE;      break;    case 'h' : print_help(argv[0]);      exit(0);    case '?' : print_usage(argv[0]);      exit(1);    }   }   /* No file? */  if (argc-optind == 0) {    print_help(argv[0]);    exit(1);  }  /* Well, let's not just shut up if options are out of context, let's whine    * about it a bit so that people know why they're not getting what they    * expected. */  if (!opts.script) {     /* If not in script mode then we should check and make sure that we warn       * if script options have been set. I assume it's fine to spit to stdout       * here. */       /* Local string where we store naughty switches. */      char badopts[10] = "\0";            /* Off we go. */      if (opts.format) { strcat(badopts, "f"); }      if (opts.bits) { strcat(badopts, "b"); }      if (opts.ccount) { strcat(badopts, "c"); }      if (opts.rate) { strcat(badopts, "r"); }      if (opts.human) { strcat(badopts, "m"); }      if (opts.samples) { strcat(badopts, "u"); }      if (strlen(badopts)) {        printf("-%s :: Out of context options will be ignored.\n",                         badopts);       }  } else {      /* Now, if we're in script mode we want to make sure of a few things,        * we also want to warn on stderr, of course. */      char badopts[20] = "\0";      /* The whole format thing is a bit complex so I guess we want to help        * out. */      if (!opts.format) {         if (opts.bits) { strcat(badopts, "b"); }         if (opts.ccount) { strcat(badopts, "c"); }         if (opts.rate) { strcat(badopts, "r"); }         if (strlen(badopts) == 1) {            fprintf(stderr, "You can't specify -%s just like that, you need to enter format mode with -f.\n", badopts);         }         if (strlen(badopts) > 1) {            fprintf(stderr, "Look out, you're not in format mode and you have more than one format specifier anyway: just use the -h switch for now.\n");         }      }      /* Catch-all piece of logic to filter errors. */      if ((opts.script) && (((opts.format) && (opts.human)) || ((opts.format)                                       && (((opts.bits) && ((opts.ccount) ||                                                             (opts.rate))) ||                                           ((opts.ccount) && (opts.rate)))) ||                        (opts.samples && (opts.format || opts.human)))) {         fprintf(stderr, "Error: In script mode not more than one further mode can be specified.\n");         print_usage(argv[0]);         exit(1);      }  }  /* Setting things up. */  eci_init();   eci_command("cs-add main");   eci_command("c-add main");   eci_command("ao-add null");   /* Setting the format if needed. */  if (opts.adjust) {    if (strncmp(":", fstring, 1) == 0) { sprintf(cmd, "cs-set-audio-format %s", fstring+1); }    else { sprintf(cmd, "cs-set-audio-format %s", fstring); }    eci_command(cmd);    if (strlen(eci_last_error()) != 0) {      fprintf(stderr, "Argument to -a is badly formatted.\n");      print_usage(argv[0]);      exit(1);    }  }  curarg = optind;   /* The real thing. */  while(curarg < argc) {     if ((file = fopen(argv[curarg], "r")) != NULL) {       fclose(file);       sprintf(cmd, "ai-add \"%s\"", argv[curarg]);       eci_command(cmd);       eci_command("cs-connect");       if (strlen(eci_last_error()) == 0) {        sprintf(cmd, "ai-select \"%s\"", argv[curarg]);         eci_command(cmd);         eci_command("ai-get-length");         curfilelength = eci_last_float();         if (opts.format) {           eci_command("ai-get-format");           strcpy(fstring, eci_last_string());         }        /* We wanted to print the length in samples so we've done nothing        * all along; let's act now. */        if (opts.script && opts.samples) {            long samplecount;            eci_command("ai-get-length-samples");            samplecount = eci_last_long_integer();            printf("%li", samplecount);        }                /* Here cometh the cleansing. */        eci_command("cs-disconnect");         eci_command("ai-remove");                 /* Need we humanize ourselves? */        if (!(opts.script) || ((opts.script && opts.human))) {           make_human((int)(curfilelength+0.5), &min, &sec);         }         if (!(opts.script)) { printf("%s: ", argv[curarg]); }         if (!(opts.script) ||              ((opts.script) && (!(opts.format) && !(opts.human) &&                              !(opts.samples)))) {           printf("%.3f", curfilelength);         }         if (!(opts.script)) { printf("s   \t("); }         if (!(opts.script) || ((opts.script) && (opts.human))) {           printf("%im%is", min, sec);         }         if (!(opts.script)) { printf(")"); }         if ((opts.format) &&             !((opts.format) && ((opts.bits) || (opts.ccount) || (opts.rate)))) {           if (!(opts.script)) { printf("   \t"); }           printf("%s", fstring);         }         if ((opts.format) && (opts.script) && (opts.bits)) {           printf("%s", strtok(fstring+1, "_"));         }        if ((opts.script) && (opts.format) && (opts.ccount)) {          strtok(fstring, ",");          printf("%s", strtok(NULL, ","));        }        if ((opts.format) && (opts.script) && (opts.rate)) {          strtok(fstring, ",");          strtok(NULL, ",");          printf("%s", strtok(NULL, ","));        }        printf("\n");         if ((opts.total) && !(opts.script)) {           totlength += curfilelength;         }       }          else {            if (opts.script) { printf("-2\n"); }            else { printf("%s: Read error.\n", argv[curarg]); }            status = -2;            eci_command("ai-remove");          }    }     else {       if (opts.script) { printf("-1\n"); }      else { printf("%s: fopen error.\n", argv[curarg]); }      status = -1;    }     curarg++;   }   if ((opts.total) && !(opts.script)) {     /* This could be made a script option as well, does anyone care? */    make_human((int)(totlength+0.5), &min, &sec);     printf("Total: %.3fs \t\t(%im%is)\n", totlength, min, sec);   }   eci_command("cs-remove");   eci_cleanup();   exit(status); } 