ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

int main ( int argc  ,
argv   
)

Definition at line 230 of file ansi2knr.c.

{   FILE *in = stdin;
    FILE *out = stdout;
    char *filename = 0;
    char *program_name = argv[0];
    char *output_name = 0;
#define bufsize 5000            /* arbitrary size */
    char *buf;
    char *line;
    char *more;
    char *usage =
      "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
    /*
     * In previous versions, ansi2knr recognized a --varargs switch.
     * If this switch was supplied, ansi2knr would attempt to convert
     * a ... argument to va_alist and va_dcl; if this switch was not
     * supplied, ansi2knr would simply drop any such arguments.
     * Now, ansi2knr always does this conversion, and we only
     * check for this switch for backward compatibility.
     */
    int convert_varargs = 1;
    int output_error;

    while ( argc > 1 && argv[1][0] == '-' ) {
      if ( !strcmp(argv[1], "--varargs") ) {
        convert_varargs = 1;
        argc--;
        argv++;
        continue;
      }
      if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
        filename = argv[2];
        argc -= 2;
        argv += 2;
        continue;
      }
      fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name,
          argv[1]);
      fprintf(stderr, usage);
      exit(1);
    }
    switch ( argc )
       {
    default:
        fprintf(stderr, usage);
        exit(0);
    case 3:
        output_name = argv[2];
        out = fopen(output_name, "w");
        if ( out == NULL ) {
          fprintf(stderr, "%s: Cannot open output file %s\n",
              program_name, output_name);
          exit(1);
        }
        /* falls through */
    case 2:
        in = fopen(argv[1], "r");
        if ( in == NULL ) {
          fprintf(stderr, "%s: Cannot open input file %s\n",
              program_name, argv[1]);
          exit(1);
        }
        if ( filename == 0 )
          filename = argv[1];
        /* falls through */
    case 1:
        break;
       }
    if ( filename )
      fprintf(out, "#line 1 \"%s\"\n", filename);
    buf = malloc(bufsize);
    if ( buf == NULL )
       {
        fprintf(stderr, "Unable to allocate read buffer!\n");
        exit(1);
       }
    line = buf;
    while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
       {
test:       line += strlen(line);
        switch ( test1(buf) )
           {
        case 2:         /* a function header */
            convert1(buf, out, 1, convert_varargs);
            break;
        case 1:         /* a function */
            /* Check for a { at the start of the next line. */
            more = ++line;
f:          if ( line >= buf + (bufsize - 1) ) /* overflow check */
              goto wl;
            if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
              goto wl;
            switch ( *skipspace(ppdirforward(more), 1) )
              {
              case '{':
                /* Definitely a function header. */
                convert1(buf, out, 0, convert_varargs);
                fputs(more, out);
                break;
              case 0:
                /* The next line was blank or a comment: */
                /* keep scanning for a non-comment. */
                line += strlen(line);
                goto f;
              default:
                /* buf isn't a function header, but */
                /* more might be. */
                fputs(buf, out);
                strcpy(buf, more);
                line = buf;
                goto test;
              }
            break;
        case -1:        /* maybe the start of a function */
            if ( line != buf + (bufsize - 1) ) /* overflow check */
              continue;
            /* falls through */
        default:        /* not a function */
wl:         fputs(buf, out);
            break;
           }
        line = buf;
       }
    if ( line != buf )
      fputs(buf, out);
    free(buf);
    if ( output_name ) {
      output_error = ferror(out);
      output_error |= fclose(out);
    } else {        /* out == stdout */
      fflush(out);
      output_error = ferror(out);
    }
    if ( output_error ) {
      fprintf(stderr, "%s: error writing to %s\n", program_name,
          (output_name ? output_name : "stdout"));
      exit(1);
    }
    if ( in != stdin )
      fclose(in);
    return 0;
}

Generated on Sat May 26 2012 04:47:55 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.