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 ZipCode format error

Definition at line 230 of file zip2disk.c.

References infile, init_files(), inname, max_sect, open_file(), outfile, outname, read_track(), track, and trackbuf.

{
  if (argc != 2 && argc != 3) {
    fputs ("ZipCode disk image extractor v1.2.1\n"
         "Usage: zip2disk zip_image_name [disk_image_name]\n", stderr);
    return 1;
  }

  outname = (argc == 3) ? argv[2] : 0;

  switch (init_files (argv[1])) {
  case 3:
    fprintf (stderr, "zip2disk: Could not create %s.\n", outname);
    return 3;
  case 2:
    fprintf (stderr, "zip2disk: File %s not found.\n", inname);
    return 3;
  case 1:
    fputs ("zip2disk: Out of memory.\n", stderr);
    return 2;
  }

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

    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 (read_track ()) {
      fclose (infile);
      fclose (outfile);
      return 4;
    }

    if (max_sect != fwrite (trackbuf, 256, max_sect, outfile)) {
      fclose (infile);
      fclose (outfile);
      fputs ("zip2disk: Error in writing the output file.\n", stderr);
      return 3;
    }
  }

  return 0;

OpenError:
  fprintf (stderr, "zip2disk: Error in opening file %s.\n", inname);
  return 3;
}


Generated by  Doxygen 1.6.0   Back to index