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

static int disk_params ( const char *  cmd,
unsigned *  unit,
unsigned *  track,
unsigned *  track_end 
) [static]

read the disk parameters

Parameters:
cmd the -dr or -dw command
unit (output) the drive unit number
track (output) number of the start track
track_end (output) number of the last track, plus 1
Returns:
0 on success; nonzero on failure

end-of-number pointer for strtoul

start-of-number pointer for strtoul

Definition at line 595 of file cbmlink.c.

References interleave.

Referenced by drive_image_read(), and drive_image_write().

{
  /** end-of-number pointer for strtoul */
  char* endp = 0;
  /** start-of-number pointer for strtoul */
  const char* s = cmd + 3;

  if (*s && *s != ',') {
    *unit = strtoul (s, &endp, 0);
    if ((*endp && *endp != ',') || *unit > 1) {
      fputs (cmd, stderr);
      fputs (": invalid unit number: ", stderr);
      fputs (s, stderr);
      fputc ('\n', stderr);
      return -1;
    }
    if (*(s = endp) == ',') s++;
  }
  else {
    *unit = 0;
    if (*s == ',') s++;
  }

  if (*s && *s != ',') {
    interleave = strtoul (s, &endp, 0);
    if ((*endp && *endp != ',') || interleave > 999) {
      fputs (cmd, stderr);
      fputs (": invalid interleave factor: ", stderr);
      fputs (s, stderr);
      fputc ('\n', stderr);
      return -1;
    }
    if (*(s = endp) == ',') s++;
  }
  else {
    interleave = 5;
    if (*s == ',') s++;
  }

  if (*s && *s != ',') {
    *track = strtoul (s, &endp, 0);
    if ((*endp && *endp != ',') || *track > 999) {
      fputs (cmd, stderr);
      fputs (": invalid start track number: ", stderr);
      fputs (s, stderr);
      fputc ('\n', stderr);
      return -1;
    }
    if (*(s = endp) == ',') s++;
  }
  else {
    *track = 1;
    if (*s == ',') s++;
  }

  if (*s) {
    *track_end = strtoul (s, &endp, 0);
    if (*endp || *track_end > 1000 || *track_end <= *track) {
      fputs (cmd, stderr);
      fputs (": invalid end track number: ", stderr);
      fputs (s, stderr);
      fputc ('\n', stderr);
      return -1;
    }
    if (*(s = endp) == ',') s++;
  }
  else
    *track_end = 1000;

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index