Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

int main ( int  argc,
char **  argv 
)

Main program

Parameters:
argc number of command-line arguments
argv contents of command-line arguments
Returns:
0 on success;
1 on usage error;
2 on out of memory;
3 on input or output error;
4 on error in the disk image

Definition at line 230 of file disk2zip.c.

References ASC2HEX, eveninc, infile, init_files(), inname, ISHEX, max_sect, open_file(), outfile, outname, track, trackbuf, and write_track().

{
optloop:
  argv++;

  if (argc > 1 && **argv == '-') {
    switch ((*argv)[1]) {
    case 0:
      infile = stdin;
      break;
    case '-':
      if (!(*argv)[2]) { /* "--" disables processing further options */
        argv++;
        argc--;
        break;
      }
    case 'i':
      if (!(*argv)[2] && argv[1]) { /* "-i" specifies disk identifier */
        argv++;
        argc-=2;
      if (ISHEX ((*argv)[0]) && ISHEX ((*argv)[1]) &&
          ISHEX ((*argv)[2]) && ISHEX ((*argv)[3]) &&
          !(*argv)[4]) {
        id[0] = ASC2HEX((*argv)[1]) | (ASC2HEX((*argv)[0]) << 4);
        id[1] = ASC2HEX((*argv)[3]) | (ASC2HEX((*argv)[2]) << 4);
        goto optloop;
      }
      }
      /* fall through */
    default: /* unknown option */
      goto Usage;
    }
  }

  if (argc != 2 && argc != 3) {
  Usage:
    fputs ("ZipCode disk image compressor v1.0.1\n"
         "Usage: disk2zip [options] disk_image_name [zip_image_name]\n"
         "Options: -i nnmm: Use $nn $mm (hexadecimal) as disk identifier.\n",
         stderr);
    return 1;
  }

  inname = *argv++;

  switch (init_files (*argv ? *argv : inname)) {
  case 2:
    fprintf (stderr, "disk2zip: File %s not found.\n", inname);
    return 3;
  case 1:
    fputs ("disk2zip: Out of memory.\n", stderr);
    return 2;
  }

  for (track = 1; track <= 35; track++) {
    max_sect = 17 + (track < 31) + (track < 25) + ((track < 18) << 1);

    if (track == 18 || track == 25) eveninc++, oddinc--;

    switch (track) {
    case 1:
      if (open_file ('1'))
        goto OpenError;
      break;
    case 9:
      if (open_file ('2'))
        goto OpenError;
      break;
    case 17:
      if (open_file ('3'))
        goto OpenError;
      break;
    case 26:
      if (open_file ('4'))
        goto OpenError;
      break;
    }

    if (max_sect != fread (trackbuf, 256, max_sect, infile)) {
      if (infile != stdin)
      fclose (infile);
      fclose (outfile);
      fputs ("disk2zip: Error in reading the input file.\n", stderr);
      return 4;
    }

    if (write_track()) {
      if (infile != stdin)
      fclose (infile);
      fclose (outfile);
      return 3;
    }
  }

  if (infile != stdin)
    fclose (infile);
  fclose (outfile);
  return 0;

OpenError:
  fprintf (stderr, "disk2zip: Error in opening file %s.\n", outname);
  if (infile != stdin)
    fclose (infile);
  return 3;
}


Generated by  Doxygen 1.6.0   Back to index