Home » Archimedes archive » Acorn User » AU 1997-01 B.adf » Regulars » Rambles/SplitS/Source/Splitf_c

Rambles/SplitS/Source/Splitf_c

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-01 B.adf » Regulars
Filename: Rambles/SplitS/Source/Splitf_c
Read OK:
File size: 49B7 bytes
Load address: 0000
Exec address: 0000
File contents
/********************************************************************************/
/*                                                                              */
/* Splitf.c                                                                     */
/* Part of Splitf and Joinf distribution                                        */
/* version 1.13, � 1993-1995 Adam Hamilton                                      */
/* See the README file for copyright information                                */
/*                                                                              */
/********************************************************************************/


/*********************************/
/* Include required header files */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"


/**********************************/
/* Program macros and definitions */

#ifndef Bool
#  define Bool char
#endif

#define False   0
#define True    !False
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

#ifndef LEAFNAME_MAX
#  define LEAFNAME_MAX  FILENAME_MAX
#endif



/********************************************************************************/
/*                                                                              */
/* Function    : usage                                                          */
/* Description : Displays program usage to standard error, and exits.           */
/* Arguments   : progname - pointer to character string containing the program  */
/*                          name.                                               */
/* Returns     : None.                                                          */
/*                                                                              */
/********************************************************************************/


void usage (char *progname)
{
  fprintf (stderr, "File splitter. Version 1.13 - 4th Feburary 1995 by A.Hamilton\n\n");
  fprintf (stderr, "Usage : %s [options] <filename>\n\n", progname);
  fprintf (stderr, "Options (can be abbreviated) :\n");
  fprintf (stderr, "    -filesize     [filesize in K]          default = 1423\n");
#ifndef PC
  fprintf (stderr, "    -buffersize   [buffersize in K]        default = 32\n");
#endif
  fprintf (stderr, "    -path         [new path]\n");
  fprintf (stderr, "    -interactive\n");

  exit (EXIT_FAILURE);
}



/********************************************************************************/
/*                                                                              */
/* Function    : examine_filename                                               */
/* Description : Splits filename into component parts.                           */
/* Arguments   : original_name - character array, filename to be examined.      */
/*               name          - pointer to a character array in which to store */
/*                               file leafname (excluding extention).           */
/*               ext           - pointer to a character array in which to store */
/*                               the source files extention (if any).           */
/* Returns     : If the source file has an extention, then return ".spt",       */
/*               otherwise return "".                                           */
/*                                                                              */
/********************************************************************************/


char *examine_filename (char original_name[], char *name, char *ext)
{
  char main_name[256];                  /* Temporary store for leafname.        */
  char *original;                       /* Pointer to start of leafname.        */
  char *pointer;                        /* Pointer to any ':' characters found. */
  register int i = -1, n;               /* Pointer & counter.                   */


  if (COLON)                                                    /* If our system uses ':' in    */
    pointer = strrchr (original_name, ':');                     /* the file path, then remember */
  else                                                          /* where it is.                 */
    pointer = NULL;

  original = strrchr (original_name, SEPARATOR_SEARCH);         /* Find the address where the   */
  if ((original = MAX (original, pointer)) == NULL)             /* leafname starts.             */
    original = original_name;
  else {
    original++;
  }

  do {
    i++;
    main_name[i] = original[i];                                 /* Get files leafname           */
  } while (main_name[i] != '.' && main_name[i] != '\0');        /* (excluding any extention).   */

  for (n = 0; (ext[n] = original[i]) != '\0'; n++, i++) ;       /* Now copy any extention.      */

  if (main_name[i - n] == '\0') {                               /* If the file doesn't have an  */
    strcpy (name, main_name);                                   /* extention, copy the leafname */
    return ("");                                                /* and return an empty string.  */
  }
  main_name[i - n] = '\0';                                      /* Otherwise, terminate the     */
  strcpy (name, main_name);                                     /* leafname, copy it, and       */
  return (".spt");                                              /* the output extention to use. */
}



/********************************************************************************/
/*                                                                              */
/* Function    : numtostr                                                       */
/* Description : Converts a number into a 2 didget character string.            */
/* Arguments   : number - number to be converted.                               */
/*               name   - pointer to a character array to store the number.     */
/* Returns     : None.                                                          */
/*                                                                              */
/********************************************************************************/


void numtostr (short number, char *name)
{
  name[0] = (short) (number / 10) + '0';
  name[1] = (number % 10) + '0';
  name[2] = '\0';
}



/********************************************************************************/
/*                                                                              */
/* Function    : main                                                           */
/* Description : Main control function.                                         */
/* Arguments   : Command line parameters.                                       */
/* Returns     : Exit status.                                                   */
/*                                                                              */
/********************************************************************************/


int main (int argc, char **argv)
{
  char  source_filename[256];           /* Source filename.                     */
  char  out_filename[256];              /* Output leafname.                     */
  char  out_path[256];                  /* Output path.                         */
  char  file_ext[32];                   /* Output extention.                    */
  char  out_name[256];                  /* Full output filename.                */
  char  header[50];                     /* Output file header.                  */
  char  fnum[3];                        /* Output part number.                  */
  char  *progname;                      /* Program name.                        */
  char  string[256];                    /* Input string.                        */
  char  type[5];                        /* Filetype (Acorn systems only).       */
  char  interactive = 0;                /* Interactive status flag.             */
  char  orig_ext[20];                   /* Original filename extention.         */

  short file_number = 0;                /* Current part number.                 */
  long  disk_size = 1423 * 1024;        /* Output part size (default 1423K).    */
  long  read_size = 32 * 1024;          /* Buffer size (default 32K).           */
  long  data_size;
  long  out_position;                   /* Position within output file.         */
  long  in_position;                    /* Position within input file.          */
  long  bytes_read;                     /* Number of bytes read.                */
  long  bytes_written;                  /* Number of bytes written.             */
  long  file_length;                    /* Length of source file.               */
  long  *buffer;                        /* Pointer to buffer.                   */
  int   args;                           /* Number of command line arguments.    */
  int   i;                              /* Counter.                             */
  FILE  *source_file;                   /* Source file ID.                      */
  FILE  *out_file;                      /* Output file ID.                      */


#ifdef ACORN
  _kernel_swi_regs regs;
  _kernel_oserror *err;
#endif

  progname = *argv;                                     /* Get the program name.                */

  out_path[0] = '\0';                                   /* Set path to CWD.                     */
  source_filename[0] = '\0';                            /* Clear source filename.               */
  strcpy (type, "0");                                   /* No filetype set.                     */

  args = argc - 1;                                      /* Initialise count of arguments.       */
  if (!args) usage (progname);                          /* If no arguments supplied, show usage.*/

  while (args--) {
    argv++;                                             /* Look at next argument.               */

    if (!strncmp ("-filesize", *argv, MAX (2, strlen (*argv)))) {       /* -filesize            */
      if (!args) {
        fprintf (stderr, "File size required.\n\n");
        usage (progname);
      }
      disk_size = (long) atoi (*++argv) * 1024;                         /* Read file size.      */
      args--;
    }

#ifndef PC
    else if (!strncmp ("-buffersize", *argv, MAX (2, strlen (*argv)))) {        /* -buffersize  */
      if (!args) {
        fprintf (stderr, "Buffer size required\n\n");
        usage (progname);
      }
      read_size = (long) atoi (*++argv) * 1024;                         /* Read buffer size.    */
      args--;
    }
#endif

    else if (!strncmp ("-path", *argv, MAX (2, strlen (*argv)))) {      /* -path                */
      if (!args) {
        fprintf (stderr, "Path required\n\n");
        usage (progname);
      }
      sprintf (out_path, "%s%c", *++argv, FILE_SEPARATOR);              /* Read new output path.*/
      args--;
    }

    else if (!strncmp ("-interactive", *argv, MAX (2, strlen (*argv)))) /* -interactive         */
      interactive = 1;

    else {
      strcpy (source_filename, *argv);                                  /* Read source filename.*/
      if (args) usage (progname);
    }
  }

  if (source_filename[0] == NULL) {
    fprintf (stderr, "Source filename required\n\n");
    usage (progname);
  }

                                                        /* Get file detail from source filename.*/
  strcpy (file_ext, examine_filename (source_filename, out_filename, orig_ext));
  out_filename[MIN (LEAFNAME_MAX, 256) - 2] = '\0';     /* and reduce if necessary.             */

  source_file = fopen (source_filename, "rb");          /* Open read binary source file.        */
  if (source_file == NULL) {                            /* Report if error, and stop.           */
    fprintf (stderr, "Fatal error opening %s for input.\n", source_filename);
    exit (EXIT_FAILURE);
  }

  printf ("Using file size of %ld bytes.\n", disk_size);
  fseek (source_file, 0L, SEEK_END);                    /* Set file pointer to end of file,     */
  file_length = ftell (source_file);                    /* get file length                      */
  fseek (source_file, 0L, SEEK_SET);                    /* and reset pointer to the start.      */
  if (file_length <= disk_size) {
    fprintf (stderr, "No need to split file.\n");
    fclose (source_file);
    exit (EXIT_SUCCESS);
  }

  buffer = (long *) malloc ((size_t) read_size);        /* Allocate memory for a buffer.        */
  if (buffer == NULL) {
    fprintf (stderr, "Fatal error, unable to allocate memory block of %ld bytes\n", read_size);
    exit (EXIT_FAILURE);
  }

  printf ("Using buffer size of %ld bytes.\n", read_size);

#ifdef ACORN
  regs.r[0] = 5;                                /* Perform an OS_File to read file data.        */
  regs.r[1] = (int) source_filename;
  err = _kernel_swi (SWI_OS_File, &regs, &regs);
  if (err != NULL || (regs.r[0] != 1 && regs.r[0] != 3)) {
    fprintf (stderr, "Fatal error, %s is not a file\n", source_filename);
    exit (EXIT_FAILURE);
  }
  sprintf (type, "t%x", (0xFFF & regs.r[2] >> 8));
#endif

  sprintf (header, "Split:%s%s=%d=%s|", out_filename, orig_ext,         /* Create the output    */
      (int) (file_length / (disk_size - 7 - strlen (out_filename) -     /* file header.         */
      strlen (orig_ext)) + 1), type);

  file_number = 0;                              /* Initialise file number counter.              */
  in_position = 0;                              /* Initialise source file position pointer.     */

  while (file_length - in_position > 0) {       /* If any data left to transfer                 */
    file_number++;                              /* increment file number counter.               */
    numtostr (file_number, fnum);               /* Convert to a number.                         */

    while (interactive == 1) {                  /* If interactive option selected, ask for      */
      printf ("Enter path for %s%s%s (Return for %s) :\n",      /* destination of output file.  */
          out_filename, fnum, file_ext,
          out_path[0] == '\0' ? "current directory" : out_path);

      gets (string);                            /* Get output destination.                      */
      if (strchr (string, ' ') != NULL) {
        printf ("Invalid path name.\n");
        continue;
      }
      if (string[0] != '\0') {                  /* If nothing entered, then use the default.    */
        strcpy (out_path, string);
        i = strlen (out_path);
        if (out_path[i - 1] != FILE_SEPARATOR)
          if (!COLON || (COLON && out_path[i - 1] != ':')) {
            out_path[i] = FILE_SEPARATOR;
            out_path[i + 1] = '\0';
          }

      }
      interactive = interactive | 2;            /* Set flag to say data has been accepted.      */
    }

    interactive = interactive & 1;                      /* Mask off unrequired data.            */

                                                        /* Create the full output filename.     */
    sprintf (out_name, "%s%s%s%s", out_path, out_filename, fnum, file_ext);

    if (file_number > 1) {                                      /* If it's not the first part,  */
      numtostr (file_number, fnum);                             /* create a smaller header.     */
      sprintf (header, "Sp:%s%s=%s|", out_filename, orig_ext, fnum);
    }

#ifdef ACORN
    regs.r[0] = 7;                                              /* Create the file with SWI     */
    regs.r[1] = (int) out_name;                                 /* OS_File 7                    */
    regs.r[2] = 0xdeaddead;
    regs.r[3] = 0xdeaddead;
    regs.r[4] = 0;
    regs.r[5] = (int) MIN (file_length - in_position + strlen (header), disk_size);
    if ((err = _kernel_swi (SWI_OS_File, &regs, &regs)) != NULL) {
      fprintf (stderr, "Fatal error opening %s for output:\n-- %s\n", out_name, err->errmess);
      exit (EXIT_FAILURE);
    }
#endif

    out_file = fopen (out_name, "wb");                          /* Open output file.            */
    if (out_file == NULL) {                                     /* Report if error, and stop.   */
      fprintf (stderr, "Fatal error opening %s for output.\n", out_name);
      exit (1);
    }

    out_position = 0;                           /* Initialise output file position pointer.     */
    printf ("Writing data to %s\n", out_name);

    fprintf (out_file, header);                 /* Write the header information,                */
    out_position = (long) strlen (header);      /* and update the output file pointer.          */

    if (disk_size > file_length - in_position + out_position)   /* Set the size of the file we  */
      disk_size = file_length - in_position + out_position;     /* want to write.               */

    while (disk_size - out_position > 0) {                      /* While there's any data left  */
      if (disk_size - out_position < read_size)                 /* to transfer                  */
        data_size = disk_size - out_position;
      else
        data_size = read_size;

      bytes_read = fread (buffer, 1, (size_t) data_size, source_file);          /* read         */
      bytes_written = fwrite (buffer, 1, (size_t) bytes_read, out_file);        /* and write.   */

                                /* Check to see that all the data has been transfered ok.       */
      if (bytes_written < data_size && bytes_written < file_length - out_position) {
        fprintf (stderr, "Fatal error while writing %s\n", out_name);
        exit (EXIT_FAILURE);                                    /* If unsucessfull, stop.       */
      }
      in_position += bytes_read;                                /* Update the file position     */
      out_position += bytes_written;                            /* pointers.                    */
    }

    fclose (out_file);                                          /* Close output file.           */

#ifdef ACORN
    regs.r[0] = 18;                                             /* Set the filetype with SWI    */
    regs.r[1] = (int) out_name;                                 /* OS_File 18                   */
    regs.r[2] = SPLIT_FILETYPE;
    err = _kernel_swi (SWI_OS_File, &regs, &regs);
#endif

  }

  fclose (source_file);                                                 /* Close source file    */
  free (buffer);                                                        /* and free buffer.     */

  fprintf (stderr, "%ld bytes written to %d %s.\n", in_position +
      (int) (file_number * (7 + strlen (source_filename))) + 4 + strlen (type),
      file_number, (file_number == 1) ? "file" : "files");              /* Report status.       */
  fprintf (stderr, "Use : joinf %s01%s \nto restore file.\n",
      out_filename, (file_ext[0] == '\0') ? "" : ".spt");

  exit (EXIT_SUCCESS);                                                  /* and finish.          */
}
00000000  2f 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |/***************|
00000010  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000050  2a 2f 0a 2f 2a 20 20 20  20 20 20 20 20 20 20 20  |*/./*           |
00000060  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000000a0  20 20 20 2a 2f 0a 2f 2a  20 53 70 6c 69 74 66 2e  |   */./* Splitf.|
000000b0  63 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |c               |
000000c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000000f0  20 20 20 20 20 20 2a 2f  0a 2f 2a 20 50 61 72 74  |      */./* Part|
00000100  20 6f 66 20 53 70 6c 69  74 66 20 61 6e 64 20 4a  | of Splitf and J|
00000110  6f 69 6e 66 20 64 69 73  74 72 69 62 75 74 69 6f  |oinf distributio|
00000120  6e 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |n               |
00000130  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000140  20 20 20 20 20 20 20 20  20 2a 2f 0a 2f 2a 20 76  |         */./* v|
00000150  65 72 73 69 6f 6e 20 31  2e 31 33 2c 20 a9 20 31  |ersion 1.13, . 1|
00000160  39 39 33 2d 31 39 39 35  20 41 64 61 6d 20 48 61  |993-1995 Adam Ha|
00000170  6d 69 6c 74 6f 6e 20 20  20 20 20 20 20 20 20 20  |milton          |
00000180  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000190  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 2f  |            */./|
000001a0  2a 20 53 65 65 20 74 68  65 20 52 45 41 44 4d 45  |* See the README|
000001b0  20 66 69 6c 65 20 66 6f  72 20 63 6f 70 79 72 69  | file for copyri|
000001c0  67 68 74 20 69 6e 66 6f  72 6d 61 74 69 6f 6e 20  |ght information |
000001d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000001e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |               *|
000001f0  2f 0a 2f 2a 20 20 20 20  20 20 20 20 20 20 20 20  |/./*            |
00000200  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000240  20 20 2a 2f 0a 2f 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |  */./**********|
00000250  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000290  2a 2a 2a 2a 2a 2a 2f 0a  0a 0a 2f 2a 2a 2a 2a 2a  |******/.../*****|
000002a0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
000002b0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2f 0a 2f 2a  |************/./*|
000002c0  20 49 6e 63 6c 75 64 65  20 72 65 71 75 69 72 65  | Include require|
000002d0  64 20 68 65 61 64 65 72  20 66 69 6c 65 73 20 2a  |d header files *|
000002e0  2f 0a 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |/..#include <std|
000002f0  69 6f 2e 68 3e 0a 23 69  6e 63 6c 75 64 65 20 3c  |io.h>.#include <|
00000300  73 74 64 6c 69 62 2e 68  3e 0a 23 69 6e 63 6c 75  |stdlib.h>.#inclu|
00000310  64 65 20 3c 73 74 72 69  6e 67 2e 68 3e 0a 23 69  |de <string.h>.#i|
00000320  6e 63 6c 75 64 65 20 22  63 6f 6e 66 69 67 2e 68  |nclude "config.h|
00000330  22 0a 0a 0a 2f 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |".../***********|
00000340  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
00000350  2a 2a 2a 2a 2a 2a 2a 2f  0a 2f 2a 20 50 72 6f 67  |*******/./* Prog|
00000360  72 61 6d 20 6d 61 63 72  6f 73 20 61 6e 64 20 64  |ram macros and d|
00000370  65 66 69 6e 69 74 69 6f  6e 73 20 2a 2f 0a 0a 23  |efinitions */..#|
00000380  69 66 6e 64 65 66 20 42  6f 6f 6c 0a 23 20 20 64  |ifndef Bool.#  d|
00000390  65 66 69 6e 65 20 42 6f  6f 6c 20 63 68 61 72 0a  |efine Bool char.|
000003a0  23 65 6e 64 69 66 0a 0a  23 64 65 66 69 6e 65 20  |#endif..#define |
000003b0  46 61 6c 73 65 20 20 20  30 0a 23 64 65 66 69 6e  |False   0.#defin|
000003c0  65 20 54 72 75 65 20 20  20 20 21 46 61 6c 73 65  |e True    !False|
000003d0  0a 23 64 65 66 69 6e 65  20 4d 49 4e 28 61 2c 20  |.#define MIN(a, |
000003e0  62 29 20 28 61 20 3c 20  62 20 3f 20 61 20 3a 20  |b) (a < b ? a : |
000003f0  62 29 0a 23 64 65 66 69  6e 65 20 4d 41 58 28 61  |b).#define MAX(a|
00000400  2c 20 62 29 20 28 61 20  3e 20 62 20 3f 20 61 20  |, b) (a > b ? a |
00000410  3a 20 62 29 0a 0a 23 69  66 6e 64 65 66 20 4c 45  |: b)..#ifndef LE|
00000420  41 46 4e 41 4d 45 5f 4d  41 58 0a 23 20 20 64 65  |AFNAME_MAX.#  de|
00000430  66 69 6e 65 20 4c 45 41  46 4e 41 4d 45 5f 4d 41  |fine LEAFNAME_MA|
00000440  58 20 20 46 49 4c 45 4e  41 4d 45 5f 4d 41 58 0a  |X  FILENAME_MAX.|
00000450  23 65 6e 64 69 66 0a 0a  0a 0a 2f 2a 2a 2a 2a 2a  |#endif..../*****|
00000460  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000004a0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2f 0a 2f 2a 20  |***********/./* |
000004b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000004f0  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
00000500  2f 2a 20 46 75 6e 63 74  69 6f 6e 20 20 20 20 3a  |/* Function    :|
00000510  20 75 73 61 67 65 20 20  20 20 20 20 20 20 20 20  | usage          |
00000520  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000550  2a 2f 0a 2f 2a 20 44 65  73 63 72 69 70 74 69 6f  |*/./* Descriptio|
00000560  6e 20 3a 20 44 69 73 70  6c 61 79 73 20 70 72 6f  |n : Displays pro|
00000570  67 72 61 6d 20 75 73 61  67 65 20 74 6f 20 73 74  |gram usage to st|
00000580  61 6e 64 61 72 64 20 65  72 72 6f 72 2c 20 61 6e  |andard error, an|
00000590  64 20 65 78 69 74 73 2e  20 20 20 20 20 20 20 20  |d exits.        |
000005a0  20 20 20 2a 2f 0a 2f 2a  20 41 72 67 75 6d 65 6e  |   */./* Argumen|
000005b0  74 73 20 20 20 3a 20 70  72 6f 67 6e 61 6d 65 20  |ts   : progname |
000005c0  2d 20 70 6f 69 6e 74 65  72 20 74 6f 20 63 68 61  |- pointer to cha|
000005d0  72 61 63 74 65 72 20 73  74 72 69 6e 67 20 63 6f  |racter string co|
000005e0  6e 74 61 69 6e 69 6e 67  20 74 68 65 20 70 72 6f  |ntaining the pro|
000005f0  67 72 61 6d 20 20 2a 2f  0a 2f 2a 20 20 20 20 20  |gram  */./*     |
00000600  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000610  20 20 20 20 20 6e 61 6d  65 2e 20 20 20 20 20 20  |     name.      |
00000620  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000640  20 20 20 20 20 20 20 20  20 2a 2f 0a 2f 2a 20 52  |         */./* R|
00000650  65 74 75 72 6e 73 20 20  20 20 20 3a 20 4e 6f 6e  |eturns     : Non|
00000660  65 2e 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |e.              |
00000670  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000690  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 2f  |            */./|
000006a0  2a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |*               |
000006b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000006e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |               *|
000006f0  2f 0a 2f 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |/./*************|
00000700  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000740  2a 2a 2a 2f 0a 0a 0a 76  6f 69 64 20 75 73 61 67  |***/...void usag|
00000750  65 20 28 63 68 61 72 20  2a 70 72 6f 67 6e 61 6d  |e (char *prognam|
00000760  65 29 0a 7b 0a 20 20 66  70 72 69 6e 74 66 20 28  |e).{.  fprintf (|
00000770  73 74 64 65 72 72 2c 20  22 46 69 6c 65 20 73 70  |stderr, "File sp|
00000780  6c 69 74 74 65 72 2e 20  56 65 72 73 69 6f 6e 20  |litter. Version |
00000790  31 2e 31 33 20 2d 20 34  74 68 20 46 65 62 75 72  |1.13 - 4th Febur|
000007a0  61 72 79 20 31 39 39 35  20 62 79 20 41 2e 48 61  |ary 1995 by A.Ha|
000007b0  6d 69 6c 74 6f 6e 5c 6e  5c 6e 22 29 3b 0a 20 20  |milton\n\n");.  |
000007c0  66 70 72 69 6e 74 66 20  28 73 74 64 65 72 72 2c  |fprintf (stderr,|
000007d0  20 22 55 73 61 67 65 20  3a 20 25 73 20 5b 6f 70  | "Usage : %s [op|
000007e0  74 69 6f 6e 73 5d 20 3c  66 69 6c 65 6e 61 6d 65  |tions] <filename|
000007f0  3e 5c 6e 5c 6e 22 2c 20  70 72 6f 67 6e 61 6d 65  |>\n\n", progname|
00000800  29 3b 0a 20 20 66 70 72  69 6e 74 66 20 28 73 74  |);.  fprintf (st|
00000810  64 65 72 72 2c 20 22 4f  70 74 69 6f 6e 73 20 28  |derr, "Options (|
00000820  63 61 6e 20 62 65 20 61  62 62 72 65 76 69 61 74  |can be abbreviat|
00000830  65 64 29 20 3a 5c 6e 22  29 3b 0a 20 20 66 70 72  |ed) :\n");.  fpr|
00000840  69 6e 74 66 20 28 73 74  64 65 72 72 2c 20 22 20  |intf (stderr, " |
00000850  20 20 20 2d 66 69 6c 65  73 69 7a 65 20 20 20 20  |   -filesize    |
00000860  20 5b 66 69 6c 65 73 69  7a 65 20 69 6e 20 4b 5d  | [filesize in K]|
00000870  20 20 20 20 20 20 20 20  20 20 64 65 66 61 75 6c  |          defaul|
00000880  74 20 3d 20 31 34 32 33  5c 6e 22 29 3b 0a 23 69  |t = 1423\n");.#i|
00000890  66 6e 64 65 66 20 50 43  0a 20 20 66 70 72 69 6e  |fndef PC.  fprin|
000008a0  74 66 20 28 73 74 64 65  72 72 2c 20 22 20 20 20  |tf (stderr, "   |
000008b0  20 2d 62 75 66 66 65 72  73 69 7a 65 20 20 20 5b  | -buffersize   [|
000008c0  62 75 66 66 65 72 73 69  7a 65 20 69 6e 20 4b 5d  |buffersize in K]|
000008d0  20 20 20 20 20 20 20 20  64 65 66 61 75 6c 74 20  |        default |
000008e0  3d 20 33 32 5c 6e 22 29  3b 0a 23 65 6e 64 69 66  |= 32\n");.#endif|
000008f0  0a 20 20 66 70 72 69 6e  74 66 20 28 73 74 64 65  |.  fprintf (stde|
00000900  72 72 2c 20 22 20 20 20  20 2d 70 61 74 68 20 20  |rr, "    -path  |
00000910  20 20 20 20 20 20 20 5b  6e 65 77 20 70 61 74 68  |       [new path|
00000920  5d 5c 6e 22 29 3b 0a 20  20 66 70 72 69 6e 74 66  |]\n");.  fprintf|
00000930  20 28 73 74 64 65 72 72  2c 20 22 20 20 20 20 2d  | (stderr, "    -|
00000940  69 6e 74 65 72 61 63 74  69 76 65 5c 6e 22 29 3b  |interactive\n");|
00000950  0a 0a 20 20 65 78 69 74  20 28 45 58 49 54 5f 46  |..  exit (EXIT_F|
00000960  41 49 4c 55 52 45 29 3b  0a 7d 0a 0a 0a 0a 2f 2a  |AILURE);.}..../*|
00000970  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000009b0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2f  |***************/|
000009c0  0a 2f 2a 20 20 20 20 20  20 20 20 20 20 20 20 20  |./*             |
000009d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000a10  20 2a 2f 0a 2f 2a 20 46  75 6e 63 74 69 6f 6e 20  | */./* Function |
00000a20  20 20 20 3a 20 65 78 61  6d 69 6e 65 5f 66 69 6c  |   : examine_fil|
00000a30  65 6e 61 6d 65 20 20 20  20 20 20 20 20 20 20 20  |ename           |
00000a40  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000a60  20 20 20 20 2a 2f 0a 2f  2a 20 44 65 73 63 72 69  |    */./* Descri|
00000a70  70 74 69 6f 6e 20 3a 20  53 70 6c 69 74 73 20 66  |ption : Splits f|
00000a80  69 6c 65 6e 61 6d 65 20  69 6e 74 6f 20 63 6f 6d  |ilename into com|
00000a90  70 6f 6e 65 6e 74 20 70  61 72 74 73 2e 20 20 20  |ponent parts.   |
00000aa0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000ab0  20 20 20 20 20 20 20 20  2a 2f 0a 2f 2a 20 41 72  |        */./* Ar|
00000ac0  67 75 6d 65 6e 74 73 20  20 20 3a 20 6f 72 69 67  |guments   : orig|
00000ad0  69 6e 61 6c 5f 6e 61 6d  65 20 2d 20 63 68 61 72  |inal_name - char|
00000ae0  61 63 74 65 72 20 61 72  72 61 79 2c 20 66 69 6c  |acter array, fil|
00000af0  65 6e 61 6d 65 20 74 6f  20 62 65 20 65 78 61 6d  |ename to be exam|
00000b00  69 6e 65 64 2e 20 20 20  20 20 20 2a 2f 0a 2f 2a  |ined.      */./*|
00000b10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 6e  |               n|
00000b20  61 6d 65 20 20 20 20 20  20 20 20 20 20 2d 20 70  |ame          - p|
00000b30  6f 69 6e 74 65 72 20 74  6f 20 61 20 63 68 61 72  |ointer to a char|
00000b40  61 63 74 65 72 20 61 72  72 61 79 20 69 6e 20 77  |acter array in w|
00000b50  68 69 63 68 20 74 6f 20  73 74 6f 72 65 20 2a 2f  |hich to store */|
00000b60  0a 2f 2a 20 20 20 20 20  20 20 20 20 20 20 20 20  |./*             |
00000b70  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000b80  20 20 66 69 6c 65 20 6c  65 61 66 6e 61 6d 65 20  |  file leafname |
00000b90  28 65 78 63 6c 75 64 69  6e 67 20 65 78 74 65 6e  |(excluding exten|
00000ba0  74 69 6f 6e 29 2e 20 20  20 20 20 20 20 20 20 20  |tion).          |
00000bb0  20 2a 2f 0a 2f 2a 20 20  20 20 20 20 20 20 20 20  | */./*          |
00000bc0  20 20 20 20 20 65 78 74  20 20 20 20 20 20 20 20  |     ext        |
00000bd0  20 20 20 2d 20 70 6f 69  6e 74 65 72 20 74 6f 20  |   - pointer to |
00000be0  61 20 63 68 61 72 61 63  74 65 72 20 61 72 72 61  |a character arra|
00000bf0  79 20 69 6e 20 77 68 69  63 68 20 74 6f 20 73 74  |y in which to st|
00000c00  6f 72 65 20 2a 2f 0a 2f  2a 20 20 20 20 20 20 20  |ore */./*       |
00000c10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000c20  20 20 20 20 20 20 20 20  74 68 65 20 73 6f 75 72  |        the sour|
00000c30  63 65 20 66 69 6c 65 73  20 65 78 74 65 6e 74 69  |ce files extenti|
00000c40  6f 6e 20 28 69 66 20 61  6e 79 29 2e 20 20 20 20  |on (if any).    |
00000c50  20 20 20 20 20 20 20 2a  2f 0a 2f 2a 20 52 65 74  |       */./* Ret|
00000c60  75 72 6e 73 20 20 20 20  20 3a 20 49 66 20 74 68  |urns     : If th|
00000c70  65 20 73 6f 75 72 63 65  20 66 69 6c 65 20 68 61  |e source file ha|
00000c80  73 20 61 6e 20 65 78 74  65 6e 74 69 6f 6e 2c 20  |s an extention, |
00000c90  74 68 65 6e 20 72 65 74  75 72 6e 20 22 2e 73 70  |then return ".sp|
00000ca0  74 22 2c 20 20 20 20 20  20 20 2a 2f 0a 2f 2a 20  |t",       */./* |
00000cb0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 6f 74  |              ot|
00000cc0  68 65 72 77 69 73 65 20  72 65 74 75 72 6e 20 22  |herwise return "|
00000cd0  22 2e 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |".              |
00000ce0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000cf0  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
00000d00  2f 2a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |/*              |
00000d10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000d50  2a 2f 0a 2f 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |*/./************|
00000d60  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000da0  2a 2a 2a 2a 2f 0a 0a 0a  63 68 61 72 20 2a 65 78  |****/...char *ex|
00000db0  61 6d 69 6e 65 5f 66 69  6c 65 6e 61 6d 65 20 28  |amine_filename (|
00000dc0  63 68 61 72 20 6f 72 69  67 69 6e 61 6c 5f 6e 61  |char original_na|
00000dd0  6d 65 5b 5d 2c 20 63 68  61 72 20 2a 6e 61 6d 65  |me[], char *name|
00000de0  2c 20 63 68 61 72 20 2a  65 78 74 29 0a 7b 0a 20  |, char *ext).{. |
00000df0  20 63 68 61 72 20 6d 61  69 6e 5f 6e 61 6d 65 5b  | char main_name[|
00000e00  32 35 36 5d 3b 20 20 20  20 20 20 20 20 20 20 20  |256];           |
00000e10  20 20 20 20 20 20 20 2f  2a 20 54 65 6d 70 6f 72  |       /* Tempor|
00000e20  61 72 79 20 73 74 6f 72  65 20 66 6f 72 20 6c 65  |ary store for le|
00000e30  61 66 6e 61 6d 65 2e 20  20 20 20 20 20 20 20 2a  |afname.        *|
00000e40  2f 0a 20 20 63 68 61 72  20 2a 6f 72 69 67 69 6e  |/.  char *origin|
00000e50  61 6c 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |al;             |
00000e60  20 20 20 20 20 20 20 20  20 20 2f 2a 20 50 6f 69  |          /* Poi|
00000e70  6e 74 65 72 20 74 6f 20  73 74 61 72 74 20 6f 66  |nter to start of|
00000e80  20 6c 65 61 66 6e 61 6d  65 2e 20 20 20 20 20 20  | leafname.      |
00000e90  20 20 2a 2f 0a 20 20 63  68 61 72 20 2a 70 6f 69  |  */.  char *poi|
00000ea0  6e 74 65 72 3b 20 20 20  20 20 20 20 20 20 20 20  |nter;           |
00000eb0  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00000ec0  50 6f 69 6e 74 65 72 20  74 6f 20 61 6e 79 20 27  |Pointer to any '|
00000ed0  3a 27 20 63 68 61 72 61  63 74 65 72 73 20 66 6f  |:' characters fo|
00000ee0  75 6e 64 2e 20 2a 2f 0a  20 20 72 65 67 69 73 74  |und. */.  regist|
00000ef0  65 72 20 69 6e 74 20 69  20 3d 20 2d 31 2c 20 6e  |er int i = -1, n|
00000f00  3b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;               |
00000f10  2f 2a 20 50 6f 69 6e 74  65 72 20 26 20 63 6f 75  |/* Pointer & cou|
00000f20  6e 74 65 72 2e 20 20 20  20 20 20 20 20 20 20 20  |nter.           |
00000f30  20 20 20 20 20 20 20 20  2a 2f 0a 0a 0a 20 20 69  |        */...  i|
00000f40  66 20 28 43 4f 4c 4f 4e  29 20 20 20 20 20 20 20  |f (COLON)       |
00000f50  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000f70  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00000f80  49 66 20 6f 75 72 20 73  79 73 74 65 6d 20 75 73  |If our system us|
00000f90  65 73 20 27 3a 27 20 69  6e 20 20 20 20 2a 2f 0a  |es ':' in    */.|
00000fa0  20 20 20 20 70 6f 69 6e  74 65 72 20 3d 20 73 74  |    pointer = st|
00000fb0  72 72 63 68 72 20 28 6f  72 69 67 69 6e 61 6c 5f  |rrchr (original_|
00000fc0  6e 61 6d 65 2c 20 27 3a  27 29 3b 20 20 20 20 20  |name, ':');     |
00000fd0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000fe0  2f 2a 20 74 68 65 20 66  69 6c 65 20 70 61 74 68  |/* the file path|
00000ff0  2c 20 74 68 65 6e 20 72  65 6d 65 6d 62 65 72 20  |, then remember |
00001000  2a 2f 0a 20 20 65 6c 73  65 20 20 20 20 20 20 20  |*/.  else       |
00001010  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001040  20 20 20 2f 2a 20 77 68  65 72 65 20 69 74 20 69  |   /* where it i|
00001050  73 2e 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |s.              |
00001060  20 20 20 2a 2f 0a 20 20  20 20 70 6f 69 6e 74 65  |   */.    pointe|
00001070  72 20 3d 20 4e 55 4c 4c  3b 0a 0a 20 20 6f 72 69  |r = NULL;..  ori|
00001080  67 69 6e 61 6c 20 3d 20  73 74 72 72 63 68 72 20  |ginal = strrchr |
00001090  28 6f 72 69 67 69 6e 61  6c 5f 6e 61 6d 65 2c 20  |(original_name, |
000010a0  53 45 50 41 52 41 54 4f  52 5f 53 45 41 52 43 48  |SEPARATOR_SEARCH|
000010b0  29 3b 20 20 20 20 20 20  20 20 20 2f 2a 20 46 69  |);         /* Fi|
000010c0  6e 64 20 74 68 65 20 61  64 64 72 65 73 73 20 77  |nd the address w|
000010d0  68 65 72 65 20 74 68 65  20 20 20 2a 2f 0a 20 20  |here the   */.  |
000010e0  69 66 20 28 28 6f 72 69  67 69 6e 61 6c 20 3d 20  |if ((original = |
000010f0  4d 41 58 20 28 6f 72 69  67 69 6e 61 6c 2c 20 70  |MAX (original, p|
00001100  6f 69 6e 74 65 72 29 29  20 3d 3d 20 4e 55 4c 4c  |ointer)) == NULL|
00001110  29 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |)             /*|
00001120  20 6c 65 61 66 6e 61 6d  65 20 73 74 61 72 74 73  | leafname starts|
00001130  2e 20 20 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |.             */|
00001140  0a 20 20 20 20 6f 72 69  67 69 6e 61 6c 20 3d 20  |.    original = |
00001150  6f 72 69 67 69 6e 61 6c  5f 6e 61 6d 65 3b 0a 20  |original_name;. |
00001160  20 65 6c 73 65 20 7b 0a  20 20 20 20 6f 72 69 67  | else {.    orig|
00001170  69 6e 61 6c 2b 2b 3b 0a  20 20 7d 0a 0a 20 20 64  |inal++;.  }..  d|
00001180  6f 20 7b 0a 20 20 20 20  69 2b 2b 3b 0a 20 20 20  |o {.    i++;.   |
00001190  20 6d 61 69 6e 5f 6e 61  6d 65 5b 69 5d 20 3d 20  | main_name[i] = |
000011a0  6f 72 69 67 69 6e 61 6c  5b 69 5d 3b 20 20 20 20  |original[i];    |
000011b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000011c0  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
000011d0  47 65 74 20 66 69 6c 65  73 20 6c 65 61 66 6e 61  |Get files leafna|
000011e0  6d 65 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |me           */.|
000011f0  20 20 7d 20 77 68 69 6c  65 20 28 6d 61 69 6e 5f  |  } while (main_|
00001200  6e 61 6d 65 5b 69 5d 20  21 3d 20 27 2e 27 20 26  |name[i] != '.' &|
00001210  26 20 6d 61 69 6e 5f 6e  61 6d 65 5b 69 5d 20 21  |& main_name[i] !|
00001220  3d 20 27 5c 30 27 29 3b  20 20 20 20 20 20 20 20  |= '\0');        |
00001230  2f 2a 20 28 65 78 63 6c  75 64 69 6e 67 20 61 6e  |/* (excluding an|
00001240  79 20 65 78 74 65 6e 74  69 6f 6e 29 2e 20 20 20  |y extention).   |
00001250  2a 2f 0a 0a 20 20 66 6f  72 20 28 6e 20 3d 20 30  |*/..  for (n = 0|
00001260  3b 20 28 65 78 74 5b 6e  5d 20 3d 20 6f 72 69 67  |; (ext[n] = orig|
00001270  69 6e 61 6c 5b 69 5d 29  20 21 3d 20 27 5c 30 27  |inal[i]) != '\0'|
00001280  3b 20 6e 2b 2b 2c 20 69  2b 2b 29 20 3b 20 20 20  |; n++, i++) ;   |
00001290  20 20 20 20 2f 2a 20 4e  6f 77 20 63 6f 70 79 20  |    /* Now copy |
000012a0  61 6e 79 20 65 78 74 65  6e 74 69 6f 6e 2e 20 20  |any extention.  |
000012b0  20 20 20 20 2a 2f 0a 0a  20 20 69 66 20 28 6d 61  |    */..  if (ma|
000012c0  69 6e 5f 6e 61 6d 65 5b  69 20 2d 20 6e 5d 20 3d  |in_name[i - n] =|
000012d0  3d 20 27 5c 30 27 29 20  7b 20 20 20 20 20 20 20  |= '\0') {       |
000012e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000012f0  20 20 20 20 20 20 20 20  2f 2a 20 49 66 20 74 68  |        /* If th|
00001300  65 20 66 69 6c 65 20 64  6f 65 73 6e 27 74 20 68  |e file doesn't h|
00001310  61 76 65 20 61 6e 20 20  2a 2f 0a 20 20 20 20 73  |ave an  */.    s|
00001320  74 72 63 70 79 20 28 6e  61 6d 65 2c 20 6d 61 69  |trcpy (name, mai|
00001330  6e 5f 6e 61 6d 65 29 3b  20 20 20 20 20 20 20 20  |n_name);        |
00001340  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001350  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 65 78  |           /* ex|
00001360  74 65 6e 74 69 6f 6e 2c  20 63 6f 70 79 20 74 68  |tention, copy th|
00001370  65 20 6c 65 61 66 6e 61  6d 65 20 2a 2f 0a 20 20  |e leafname */.  |
00001380  20 20 72 65 74 75 72 6e  20 28 22 22 29 3b 20 20  |  return ("");  |
00001390  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000013b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
000013c0  20 61 6e 64 20 72 65 74  75 72 6e 20 61 6e 20 65  | and return an e|
000013d0  6d 70 74 79 20 73 74 72  69 6e 67 2e 20 20 2a 2f  |mpty string.  */|
000013e0  0a 20 20 7d 0a 20 20 6d  61 69 6e 5f 6e 61 6d 65  |.  }.  main_name|
000013f0  5b 69 20 2d 20 6e 5d 20  3d 20 27 5c 30 27 3b 20  |[i - n] = '\0'; |
00001400  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001420  20 20 20 20 20 2f 2a 20  4f 74 68 65 72 77 69 73  |     /* Otherwis|
00001430  65 2c 20 74 65 72 6d 69  6e 61 74 65 20 74 68 65  |e, terminate the|
00001440  20 20 20 20 20 2a 2f 0a  20 20 73 74 72 63 70 79  |     */.  strcpy|
00001450  20 28 6e 61 6d 65 2c 20  6d 61 69 6e 5f 6e 61 6d  | (name, main_nam|
00001460  65 29 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |e);             |
00001470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001480  20 20 20 20 20 20 20 20  2f 2a 20 6c 65 61 66 6e  |        /* leafn|
00001490  61 6d 65 2c 20 63 6f 70  79 20 69 74 2c 20 61 6e  |ame, copy it, an|
000014a0  64 20 20 20 20 20 20 20  2a 2f 0a 20 20 72 65 74  |d       */.  ret|
000014b0  75 72 6e 20 28 22 2e 73  70 74 22 29 3b 20 20 20  |urn (".spt");   |
000014c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000014e0  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 74 68  |           /* th|
000014f0  65 20 6f 75 74 70 75 74  20 65 78 74 65 6e 74 69  |e output extenti|
00001500  6f 6e 20 74 6f 20 75 73  65 2e 20 2a 2f 0a 7d 0a  |on to use. */.}.|
00001510  0a 0a 0a 2f 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |.../************|
00001520  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00001560  2a 2a 2a 2a 2f 0a 2f 2a  20 20 20 20 20 20 20 20  |****/./*        |
00001570  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000015b0  20 20 20 20 20 20 2a 2f  0a 2f 2a 20 46 75 6e 63  |      */./* Func|
000015c0  74 69 6f 6e 20 20 20 20  3a 20 6e 75 6d 74 6f 73  |tion    : numtos|
000015d0  74 72 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |tr              |
000015e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001600  20 20 20 20 20 20 20 20  20 2a 2f 0a 2f 2a 20 44  |         */./* D|
00001610  65 73 63 72 69 70 74 69  6f 6e 20 3a 20 43 6f 6e  |escription : Con|
00001620  76 65 72 74 73 20 61 20  6e 75 6d 62 65 72 20 69  |verts a number i|
00001630  6e 74 6f 20 61 20 32 20  64 69 64 67 65 74 20 63  |nto a 2 didget c|
00001640  68 61 72 61 63 74 65 72  20 73 74 72 69 6e 67 2e  |haracter string.|
00001650  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 2f  |            */./|
00001660  2a 20 41 72 67 75 6d 65  6e 74 73 20 20 20 3a 20  |* Arguments   : |
00001670  6e 75 6d 62 65 72 20 2d  20 6e 75 6d 62 65 72 20  |number - number |
00001680  74 6f 20 62 65 20 63 6f  6e 76 65 72 74 65 64 2e  |to be converted.|
00001690  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000016a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |               *|
000016b0  2f 0a 2f 2a 20 20 20 20  20 20 20 20 20 20 20 20  |/./*            |
000016c0  20 20 20 6e 61 6d 65 20  20 20 2d 20 70 6f 69 6e  |   name   - poin|
000016d0  74 65 72 20 74 6f 20 61  20 63 68 61 72 61 63 74  |ter to a charact|
000016e0  65 72 20 61 72 72 61 79  20 74 6f 20 73 74 6f 72  |er array to stor|
000016f0  65 20 74 68 65 20 6e 75  6d 62 65 72 2e 20 20 20  |e the number.   |
00001700  20 20 2a 2f 0a 2f 2a 20  52 65 74 75 72 6e 73 20  |  */./* Returns |
00001710  20 20 20 20 3a 20 4e 6f  6e 65 2e 20 20 20 20 20  |    : None.     |
00001720  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001750  20 20 20 20 20 2a 2f 0a  2f 2a 20 20 20 20 20 20  |     */./*      |
00001760  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000017a0  20 20 20 20 20 20 20 20  2a 2f 0a 2f 2a 2a 2a 2a  |        */./****|
000017b0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000017f0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2f 0a 0a 0a  |************/...|
00001800  76 6f 69 64 20 6e 75 6d  74 6f 73 74 72 20 28 73  |void numtostr (s|
00001810  68 6f 72 74 20 6e 75 6d  62 65 72 2c 20 63 68 61  |hort number, cha|
00001820  72 20 2a 6e 61 6d 65 29  0a 7b 0a 20 20 6e 61 6d  |r *name).{.  nam|
00001830  65 5b 30 5d 20 3d 20 28  73 68 6f 72 74 29 20 28  |e[0] = (short) (|
00001840  6e 75 6d 62 65 72 20 2f  20 31 30 29 20 2b 20 27  |number / 10) + '|
00001850  30 27 3b 0a 20 20 6e 61  6d 65 5b 31 5d 20 3d 20  |0';.  name[1] = |
00001860  28 6e 75 6d 62 65 72 20  25 20 31 30 29 20 2b 20  |(number % 10) + |
00001870  27 30 27 3b 0a 20 20 6e  61 6d 65 5b 32 5d 20 3d  |'0';.  name[2] =|
00001880  20 27 5c 30 27 3b 0a 7d  0a 0a 0a 0a 2f 2a 2a 2a  | '\0';.}..../***|
00001890  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000018d0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2f 0a 2f  |*************/./|
000018e0  2a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |*               |
000018f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001920  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |               *|
00001930  2f 0a 2f 2a 20 46 75 6e  63 74 69 6f 6e 20 20 20  |/./* Function   |
00001940  20 3a 20 6d 61 69 6e 20  20 20 20 20 20 20 20 20  | : main         |
00001950  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001980  20 20 2a 2f 0a 2f 2a 20  44 65 73 63 72 69 70 74  |  */./* Descript|
00001990  69 6f 6e 20 3a 20 4d 61  69 6e 20 63 6f 6e 74 72  |ion : Main contr|
000019a0  6f 6c 20 66 75 6e 63 74  69 6f 6e 2e 20 20 20 20  |ol function.    |
000019b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000019d0  20 20 20 20 20 2a 2f 0a  2f 2a 20 41 72 67 75 6d  |     */./* Argum|
000019e0  65 6e 74 73 20 20 20 3a  20 43 6f 6d 6d 61 6e 64  |ents   : Command|
000019f0  20 6c 69 6e 65 20 70 61  72 61 6d 65 74 65 72 73  | line parameters|
00001a00  2e 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
00001a10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001a20  20 20 20 20 20 20 20 20  2a 2f 0a 2f 2a 20 52 65  |        */./* Re|
00001a30  74 75 72 6e 73 20 20 20  20 20 3a 20 45 78 69 74  |turns     : Exit|
00001a40  20 73 74 61 74 75 73 2e  20 20 20 20 20 20 20 20  | status.        |
00001a50  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001a70  20 20 20 20 20 20 20 20  20 20 20 2a 2f 0a 2f 2a  |           */./*|
00001a80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001ac0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |              */|
00001ad0  0a 2f 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |./**************|
00001ae0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00001b20  2a 2a 2f 0a 0a 0a 69 6e  74 20 6d 61 69 6e 20 28  |**/...int main (|
00001b30  69 6e 74 20 61 72 67 63  2c 20 63 68 61 72 20 2a  |int argc, char *|
00001b40  2a 61 72 67 76 29 0a 7b  0a 20 20 63 68 61 72 20  |*argv).{.  char |
00001b50  20 73 6f 75 72 63 65 5f  66 69 6c 65 6e 61 6d 65  | source_filename|
00001b60  5b 32 35 36 5d 3b 20 20  20 20 20 20 20 20 20 20  |[256];          |
00001b70  20 2f 2a 20 53 6f 75 72  63 65 20 66 69 6c 65 6e  | /* Source filen|
00001b80  61 6d 65 2e 20 20 20 20  20 20 20 20 20 20 20 20  |ame.            |
00001b90  20 20 20 20 20 20 20 20  20 2a 2f 0a 20 20 63 68  |         */.  ch|
00001ba0  61 72 20 20 6f 75 74 5f  66 69 6c 65 6e 61 6d 65  |ar  out_filename|
00001bb0  5b 32 35 36 5d 3b 20 20  20 20 20 20 20 20 20 20  |[256];          |
00001bc0  20 20 20 20 2f 2a 20 4f  75 74 70 75 74 20 6c 65  |    /* Output le|
00001bd0  61 66 6e 61 6d 65 2e 20  20 20 20 20 20 20 20 20  |afname.         |
00001be0  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 20  |            */. |
00001bf0  20 63 68 61 72 20 20 6f  75 74 5f 70 61 74 68 5b  | char  out_path[|
00001c00  32 35 36 5d 3b 20 20 20  20 20 20 20 20 20 20 20  |256];           |
00001c10  20 20 20 20 20 20 20 2f  2a 20 4f 75 74 70 75 74  |       /* Output|
00001c20  20 70 61 74 68 2e 20 20  20 20 20 20 20 20 20 20  | path.          |
00001c30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |               *|
00001c40  2f 0a 20 20 63 68 61 72  20 20 66 69 6c 65 5f 65  |/.  char  file_e|
00001c50  78 74 5b 33 32 5d 3b 20  20 20 20 20 20 20 20 20  |xt[32];         |
00001c60  20 20 20 20 20 20 20 20  20 20 2f 2a 20 4f 75 74  |          /* Out|
00001c70  70 75 74 20 65 78 74 65  6e 74 69 6f 6e 2e 20 20  |put extention.  |
00001c80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001c90  20 20 2a 2f 0a 20 20 63  68 61 72 20 20 6f 75 74  |  */.  char  out|
00001ca0  5f 6e 61 6d 65 5b 32 35  36 5d 3b 20 20 20 20 20  |_name[256];     |
00001cb0  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00001cc0  46 75 6c 6c 20 6f 75 74  70 75 74 20 66 69 6c 65  |Full output file|
00001cd0  6e 61 6d 65 2e 20 20 20  20 20 20 20 20 20 20 20  |name.           |
00001ce0  20 20 20 20 20 2a 2f 0a  20 20 63 68 61 72 20 20  |     */.  char  |
00001cf0  68 65 61 64 65 72 5b 35  30 5d 3b 20 20 20 20 20  |header[50];     |
00001d00  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001d10  2f 2a 20 4f 75 74 70 75  74 20 66 69 6c 65 20 68  |/* Output file h|
00001d20  65 61 64 65 72 2e 20 20  20 20 20 20 20 20 20 20  |eader.          |
00001d30  20 20 20 20 20 20 20 20  2a 2f 0a 20 20 63 68 61  |        */.  cha|
00001d40  72 20 20 66 6e 75 6d 5b  33 5d 3b 20 20 20 20 20  |r  fnum[3];     |
00001d50  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001d60  20 20 20 2f 2a 20 4f 75  74 70 75 74 20 70 61 72  |   /* Output par|
00001d70  74 20 6e 75 6d 62 65 72  2e 20 20 20 20 20 20 20  |t number.       |
00001d80  20 20 20 20 20 20 20 20  20 20 20 2a 2f 0a 20 20  |           */.  |
00001d90  63 68 61 72 20 20 2a 70  72 6f 67 6e 61 6d 65 3b  |char  *progname;|
00001da0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001db0  20 20 20 20 20 20 2f 2a  20 50 72 6f 67 72 61 6d  |      /* Program|
00001dc0  20 6e 61 6d 65 2e 20 20  20 20 20 20 20 20 20 20  | name.          |
00001dd0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |              */|
00001de0  0a 20 20 63 68 61 72 20  20 73 74 72 69 6e 67 5b  |.  char  string[|
00001df0  32 35 36 5d 3b 20 20 20  20 20 20 20 20 20 20 20  |256];           |
00001e00  20 20 20 20 20 20 20 20  20 2f 2a 20 49 6e 70 75  |         /* Inpu|
00001e10  74 20 73 74 72 69 6e 67  2e 20 20 20 20 20 20 20  |t string.       |
00001e20  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001e30  20 2a 2f 0a 20 20 63 68  61 72 20 20 74 79 70 65  | */.  char  type|
00001e40  5b 35 5d 3b 20 20 20 20  20 20 20 20 20 20 20 20  |[5];            |
00001e50  20 20 20 20 20 20 20 20  20 20 20 20 2f 2a 20 46  |            /* F|
00001e60  69 6c 65 74 79 70 65 20  28 41 63 6f 72 6e 20 73  |iletype (Acorn s|
00001e70  79 73 74 65 6d 73 20 6f  6e 6c 79 29 2e 20 20 20  |ystems only).   |
00001e80  20 20 20 20 2a 2f 0a 20  20 63 68 61 72 20 20 69  |    */.  char  i|
00001e90  6e 74 65 72 61 63 74 69  76 65 20 3d 20 30 3b 20  |nteractive = 0; |
00001ea0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2f  |               /|
00001eb0  2a 20 49 6e 74 65 72 61  63 74 69 76 65 20 73 74  |* Interactive st|
00001ec0  61 74 75 73 20 66 6c 61  67 2e 20 20 20 20 20 20  |atus flag.      |
00001ed0  20 20 20 20 20 20 20 2a  2f 0a 20 20 63 68 61 72  |       */.  char|
00001ee0  20 20 6f 72 69 67 5f 65  78 74 5b 32 30 5d 3b 20  |  orig_ext[20]; |
00001ef0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001f00  20 20 2f 2a 20 4f 72 69  67 69 6e 61 6c 20 66 69  |  /* Original fi|
00001f10  6c 65 6e 61 6d 65 20 65  78 74 65 6e 74 69 6f 6e  |lename extention|
00001f20  2e 20 20 20 20 20 20 20  20 20 2a 2f 0a 0a 20 20  |.         */..  |
00001f30  73 68 6f 72 74 20 66 69  6c 65 5f 6e 75 6d 62 65  |short file_numbe|
00001f40  72 20 3d 20 30 3b 20 20  20 20 20 20 20 20 20 20  |r = 0;          |
00001f50  20 20 20 20 20 20 2f 2a  20 43 75 72 72 65 6e 74  |      /* Current|
00001f60  20 70 61 72 74 20 6e 75  6d 62 65 72 2e 20 20 20  | part number.   |
00001f70  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |              */|
00001f80  0a 20 20 6c 6f 6e 67 20  20 64 69 73 6b 5f 73 69  |.  long  disk_si|
00001f90  7a 65 20 3d 20 31 34 32  33 20 2a 20 31 30 32 34  |ze = 1423 * 1024|
00001fa0  3b 20 20 20 20 20 20 20  20 2f 2a 20 4f 75 74 70  |;        /* Outp|
00001fb0  75 74 20 70 61 72 74 20  73 69 7a 65 20 28 64 65  |ut part size (de|
00001fc0  66 61 75 6c 74 20 31 34  32 33 4b 29 2e 20 20 20  |fault 1423K).   |
00001fd0  20 2a 2f 0a 20 20 6c 6f  6e 67 20 20 72 65 61 64  | */.  long  read|
00001fe0  5f 73 69 7a 65 20 3d 20  33 32 20 2a 20 31 30 32  |_size = 32 * 102|
00001ff0  34 3b 20 20 20 20 20 20  20 20 20 20 2f 2a 20 42  |4;          /* B|
00002000  75 66 66 65 72 20 73 69  7a 65 20 28 64 65 66 61  |uffer size (defa|
00002010  75 6c 74 20 33 32 4b 29  2e 20 20 20 20 20 20 20  |ult 32K).       |
00002020  20 20 20 20 2a 2f 0a 20  20 6c 6f 6e 67 20 20 64  |    */.  long  d|
00002030  61 74 61 5f 73 69 7a 65  3b 0a 20 20 6c 6f 6e 67  |ata_size;.  long|
00002040  20 20 6f 75 74 5f 70 6f  73 69 74 69 6f 6e 3b 20  |  out_position; |
00002050  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002060  20 20 2f 2a 20 50 6f 73  69 74 69 6f 6e 20 77 69  |  /* Position wi|
00002070  74 68 69 6e 20 6f 75 74  70 75 74 20 66 69 6c 65  |thin output file|
00002080  2e 20 20 20 20 20 20 20  20 20 2a 2f 0a 20 20 6c  |.         */.  l|
00002090  6f 6e 67 20 20 69 6e 5f  70 6f 73 69 74 69 6f 6e  |ong  in_position|
000020a0  3b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;               |
000020b0  20 20 20 20 20 2f 2a 20  50 6f 73 69 74 69 6f 6e  |     /* Position|
000020c0  20 77 69 74 68 69 6e 20  69 6e 70 75 74 20 66 69  | within input fi|
000020d0  6c 65 2e 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |le.          */.|
000020e0  20 20 6c 6f 6e 67 20 20  62 79 74 65 73 5f 72 65  |  long  bytes_re|
000020f0  61 64 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |ad;             |
00002100  20 20 20 20 20 20 20 20  2f 2a 20 4e 75 6d 62 65  |        /* Numbe|
00002110  72 20 6f 66 20 62 79 74  65 73 20 72 65 61 64 2e  |r of bytes read.|
00002120  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002130  2a 2f 0a 20 20 6c 6f 6e  67 20 20 62 79 74 65 73  |*/.  long  bytes|
00002140  5f 77 72 69 74 74 65 6e  3b 20 20 20 20 20 20 20  |_written;       |
00002150  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 4e 75  |           /* Nu|
00002160  6d 62 65 72 20 6f 66 20  62 79 74 65 73 20 77 72  |mber of bytes wr|
00002170  69 74 74 65 6e 2e 20 20  20 20 20 20 20 20 20 20  |itten.          |
00002180  20 20 20 2a 2f 0a 20 20  6c 6f 6e 67 20 20 66 69  |   */.  long  fi|
00002190  6c 65 5f 6c 65 6e 67 74  68 3b 20 20 20 20 20 20  |le_length;      |
000021a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
000021b0  20 4c 65 6e 67 74 68 20  6f 66 20 73 6f 75 72 63  | Length of sourc|
000021c0  65 20 66 69 6c 65 2e 20  20 20 20 20 20 20 20 20  |e file.         |
000021d0  20 20 20 20 20 20 2a 2f  0a 20 20 6c 6f 6e 67 20  |      */.  long |
000021e0  20 2a 62 75 66 66 65 72  3b 20 20 20 20 20 20 20  | *buffer;       |
000021f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002200  20 2f 2a 20 50 6f 69 6e  74 65 72 20 74 6f 20 62  | /* Pointer to b|
00002210  75 66 66 65 72 2e 20 20  20 20 20 20 20 20 20 20  |uffer.          |
00002220  20 20 20 20 20 20 20 20  20 2a 2f 0a 20 20 69 6e  |         */.  in|
00002230  74 20 20 20 61 72 67 73  3b 20 20 20 20 20 20 20  |t   args;       |
00002240  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002250  20 20 20 20 2f 2a 20 4e  75 6d 62 65 72 20 6f 66  |    /* Number of|
00002260  20 63 6f 6d 6d 61 6e 64  20 6c 69 6e 65 20 61 72  | command line ar|
00002270  67 75 6d 65 6e 74 73 2e  20 20 20 20 2a 2f 0a 20  |guments.    */. |
00002280  20 69 6e 74 20 20 20 69  3b 20 20 20 20 20 20 20  | int   i;       |
00002290  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000022a0  20 20 20 20 20 20 20 2f  2a 20 43 6f 75 6e 74 65  |       /* Counte|
000022b0  72 2e 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |r.              |
000022c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |               *|
000022d0  2f 0a 20 20 46 49 4c 45  20 20 2a 73 6f 75 72 63  |/.  FILE  *sourc|
000022e0  65 5f 66 69 6c 65 3b 20  20 20 20 20 20 20 20 20  |e_file;         |
000022f0  20 20 20 20 20 20 20 20  20 20 2f 2a 20 53 6f 75  |          /* Sou|
00002300  72 63 65 20 66 69 6c 65  20 49 44 2e 20 20 20 20  |rce file ID.    |
00002310  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002320  20 20 2a 2f 0a 20 20 46  49 4c 45 20 20 2a 6f 75  |  */.  FILE  *ou|
00002330  74 5f 66 69 6c 65 3b 20  20 20 20 20 20 20 20 20  |t_file;         |
00002340  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00002350  4f 75 74 70 75 74 20 66  69 6c 65 20 49 44 2e 20  |Output file ID. |
00002360  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002370  20 20 20 20 20 2a 2f 0a  0a 0a 23 69 66 64 65 66  |     */...#ifdef|
00002380  20 41 43 4f 52 4e 0a 20  20 5f 6b 65 72 6e 65 6c  | ACORN.  _kernel|
00002390  5f 73 77 69 5f 72 65 67  73 20 72 65 67 73 3b 0a  |_swi_regs regs;.|
000023a0  20 20 5f 6b 65 72 6e 65  6c 5f 6f 73 65 72 72 6f  |  _kernel_oserro|
000023b0  72 20 2a 65 72 72 3b 0a  23 65 6e 64 69 66 0a 0a  |r *err;.#endif..|
000023c0  20 20 70 72 6f 67 6e 61  6d 65 20 3d 20 2a 61 72  |  progname = *ar|
000023d0  67 76 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |gv;             |
000023e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000023f0  20 20 20 20 20 20 20 20  2f 2a 20 47 65 74 20 74  |        /* Get t|
00002400  68 65 20 70 72 6f 67 72  61 6d 20 6e 61 6d 65 2e  |he program name.|
00002410  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002420  2a 2f 0a 0a 20 20 6f 75  74 5f 70 61 74 68 5b 30  |*/..  out_path[0|
00002430  5d 20 3d 20 27 5c 30 27  3b 20 20 20 20 20 20 20  |] = '\0';       |
00002440  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002450  20 20 20 20 20 20 20 20  20 20 20 20 2f 2a 20 53  |            /* S|
00002460  65 74 20 70 61 74 68 20  74 6f 20 43 57 44 2e 20  |et path to CWD. |
00002470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002480  20 20 20 20 2a 2f 0a 20  20 73 6f 75 72 63 65 5f  |    */.  source_|
00002490  66 69 6c 65 6e 61 6d 65  5b 30 5d 20 3d 20 27 5c  |filename[0] = '\|
000024a0  30 27 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |0';             |
000024b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2f  |               /|
000024c0  2a 20 43 6c 65 61 72 20  73 6f 75 72 63 65 20 66  |* Clear source f|
000024d0  69 6c 65 6e 61 6d 65 2e  20 20 20 20 20 20 20 20  |ilename.        |
000024e0  20 20 20 20 20 20 20 2a  2f 0a 20 20 73 74 72 63  |       */.  strc|
000024f0  70 79 20 28 74 79 70 65  2c 20 22 30 22 29 3b 20  |py (type, "0"); |
00002500  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00002520  20 20 2f 2a 20 4e 6f 20  66 69 6c 65 74 79 70 65  |  /* No filetype|
00002530  20 73 65 74 2e 20 20 20  20 20 20 20 20 20 20 20  | set.           |
00002540  20 20 20 20 20 20 20 20  20 20 2a 2f 0a 0a 20 20  |          */..  |
00002550  61 72 67 73 20 3d 20 61  72 67 63 20 2d 20 31 3b  |args = argc - 1;|
00002560  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00002580  20 20 20 20 20 20 2f 2a  20 49 6e 69 74 69 61 6c  |      /* Initial|
00002590  69 73 65 20 63 6f 75 6e  74 20 6f 66 20 61 72 67  |ise count of arg|
000025a0  75 6d 65 6e 74 73 2e 20  20 20 20 20 20 20 2a 2f  |uments.       */|
000025b0  0a 20 20 69 66 20 28 21  61 72 67 73 29 20 75 73  |.  if (!args) us|
000025c0  61 67 65 20 28 70 72 6f  67 6e 61 6d 65 29 3b 20  |age (progname); |
000025d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000025e0  20 20 20 20 20 20 20 20  20 2f 2a 20 49 66 20 6e  |         /* If n|
000025f0  6f 20 61 72 67 75 6d 65  6e 74 73 20 73 75 70 70  |o arguments supp|
00002600  6c 69 65 64 2c 20 73 68  6f 77 20 75 73 61 67 65  |lied, show usage|
00002610  2e 2a 2f 0a 0a 20 20 77  68 69 6c 65 20 28 61 72  |.*/..  while (ar|
00002620  67 73 2d 2d 29 20 7b 0a  20 20 20 20 61 72 67 76  |gs--) {.    argv|
00002630  2b 2b 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |++;             |
00002640  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00002660  2f 2a 20 4c 6f 6f 6b 20  61 74 20 6e 65 78 74 20  |/* Look at next |
00002670  61 72 67 75 6d 65 6e 74  2e 20 20 20 20 20 20 20  |argument.       |
00002680  20 20 20 20 20 20 20 20  2a 2f 0a 0a 20 20 20 20  |        */..    |
00002690  69 66 20 28 21 73 74 72  6e 63 6d 70 20 28 22 2d  |if (!strncmp ("-|
000026a0  66 69 6c 65 73 69 7a 65  22 2c 20 2a 61 72 67 76  |filesize", *argv|
000026b0  2c 20 4d 41 58 20 28 32  2c 20 73 74 72 6c 65 6e  |, MAX (2, strlen|
000026c0  20 28 2a 61 72 67 76 29  29 29 29 20 7b 20 20 20  | (*argv)))) {   |
000026d0  20 20 20 20 2f 2a 20 2d  66 69 6c 65 73 69 7a 65  |    /* -filesize|
000026e0  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 20  |            */. |
000026f0  20 20 20 20 20 69 66 20  28 21 61 72 67 73 29 20  |     if (!args) |
00002700  7b 0a 20 20 20 20 20 20  20 20 66 70 72 69 6e 74  |{.        fprint|
00002710  66 20 28 73 74 64 65 72  72 2c 20 22 46 69 6c 65  |f (stderr, "File|
00002720  20 73 69 7a 65 20 72 65  71 75 69 72 65 64 2e 5c  | size required.\|
00002730  6e 5c 6e 22 29 3b 0a 20  20 20 20 20 20 20 20 75  |n\n");.        u|
00002740  73 61 67 65 20 28 70 72  6f 67 6e 61 6d 65 29 3b  |sage (progname);|
00002750  0a 20 20 20 20 20 20 7d  0a 20 20 20 20 20 20 64  |.      }.      d|
00002760  69 73 6b 5f 73 69 7a 65  20 3d 20 28 6c 6f 6e 67  |isk_size = (long|
00002770  29 20 61 74 6f 69 20 28  2a 2b 2b 61 72 67 76 29  |) atoi (*++argv)|
00002780  20 2a 20 31 30 32 34 3b  20 20 20 20 20 20 20 20  | * 1024;        |
00002790  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000027a0  20 2f 2a 20 52 65 61 64  20 66 69 6c 65 20 73 69  | /* Read file si|
000027b0  7a 65 2e 20 20 20 20 20  20 2a 2f 0a 20 20 20 20  |ze.      */.    |
000027c0  20 20 61 72 67 73 2d 2d  3b 0a 20 20 20 20 7d 0a  |  args--;.    }.|
000027d0  0a 23 69 66 6e 64 65 66  20 50 43 0a 20 20 20 20  |.#ifndef PC.    |
000027e0  65 6c 73 65 20 69 66 20  28 21 73 74 72 6e 63 6d  |else if (!strncm|
000027f0  70 20 28 22 2d 62 75 66  66 65 72 73 69 7a 65 22  |p ("-buffersize"|
00002800  2c 20 2a 61 72 67 76 2c  20 4d 41 58 20 28 32 2c  |, *argv, MAX (2,|
00002810  20 73 74 72 6c 65 6e 20  28 2a 61 72 67 76 29 29  | strlen (*argv))|
00002820  29 29 20 7b 20 20 20 20  20 20 20 20 2f 2a 20 2d  |)) {        /* -|
00002830  62 75 66 66 65 72 73 69  7a 65 20 20 2a 2f 0a 20  |buffersize  */. |
00002840  20 20 20 20 20 69 66 20  28 21 61 72 67 73 29 20  |     if (!args) |
00002850  7b 0a 20 20 20 20 20 20  20 20 66 70 72 69 6e 74  |{.        fprint|
00002860  66 20 28 73 74 64 65 72  72 2c 20 22 42 75 66 66  |f (stderr, "Buff|
00002870  65 72 20 73 69 7a 65 20  72 65 71 75 69 72 65 64  |er size required|
00002880  5c 6e 5c 6e 22 29 3b 0a  20 20 20 20 20 20 20 20  |\n\n");.        |
00002890  75 73 61 67 65 20 28 70  72 6f 67 6e 61 6d 65 29  |usage (progname)|
000028a0  3b 0a 20 20 20 20 20 20  7d 0a 20 20 20 20 20 20  |;.      }.      |
000028b0  72 65 61 64 5f 73 69 7a  65 20 3d 20 28 6c 6f 6e  |read_size = (lon|
000028c0  67 29 20 61 74 6f 69 20  28 2a 2b 2b 61 72 67 76  |g) atoi (*++argv|
000028d0  29 20 2a 20 31 30 32 34  3b 20 20 20 20 20 20 20  |) * 1024;       |
000028e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000028f0  20 20 2f 2a 20 52 65 61  64 20 62 75 66 66 65 72  |  /* Read buffer|
00002900  20 73 69 7a 65 2e 20 20  20 20 2a 2f 0a 20 20 20  | size.    */.   |
00002910  20 20 20 61 72 67 73 2d  2d 3b 0a 20 20 20 20 7d  |   args--;.    }|
00002920  0a 23 65 6e 64 69 66 0a  0a 20 20 20 20 65 6c 73  |.#endif..    els|
00002930  65 20 69 66 20 28 21 73  74 72 6e 63 6d 70 20 28  |e if (!strncmp (|
00002940  22 2d 70 61 74 68 22 2c  20 2a 61 72 67 76 2c 20  |"-path", *argv, |
00002950  4d 41 58 20 28 32 2c 20  73 74 72 6c 65 6e 20 28  |MAX (2, strlen (|
00002960  2a 61 72 67 76 29 29 29  29 20 7b 20 20 20 20 20  |*argv)))) {     |
00002970  20 2f 2a 20 2d 70 61 74  68 20 20 20 20 20 20 20  | /* -path       |
00002980  20 20 20 20 20 20 20 20  20 2a 2f 0a 20 20 20 20  |         */.    |
00002990  20 20 69 66 20 28 21 61  72 67 73 29 20 7b 0a 20  |  if (!args) {. |
000029a0  20 20 20 20 20 20 20 66  70 72 69 6e 74 66 20 28  |       fprintf (|
000029b0  73 74 64 65 72 72 2c 20  22 50 61 74 68 20 72 65  |stderr, "Path re|
000029c0  71 75 69 72 65 64 5c 6e  5c 6e 22 29 3b 0a 20 20  |quired\n\n");.  |
000029d0  20 20 20 20 20 20 75 73  61 67 65 20 28 70 72 6f  |      usage (pro|
000029e0  67 6e 61 6d 65 29 3b 0a  20 20 20 20 20 20 7d 0a  |gname);.      }.|
000029f0  20 20 20 20 20 20 73 70  72 69 6e 74 66 20 28 6f  |      sprintf (o|
00002a00  75 74 5f 70 61 74 68 2c  20 22 25 73 25 63 22 2c  |ut_path, "%s%c",|
00002a10  20 2a 2b 2b 61 72 67 76  2c 20 46 49 4c 45 5f 53  | *++argv, FILE_S|
00002a20  45 50 41 52 41 54 4f 52  29 3b 20 20 20 20 20 20  |EPARATOR);      |
00002a30  20 20 20 20 20 20 20 20  2f 2a 20 52 65 61 64 20  |        /* Read |
00002a40  6e 65 77 20 6f 75 74 70  75 74 20 70 61 74 68 2e  |new output path.|
00002a50  2a 2f 0a 20 20 20 20 20  20 61 72 67 73 2d 2d 3b  |*/.      args--;|
00002a60  0a 20 20 20 20 7d 0a 0a  20 20 20 20 65 6c 73 65  |.    }..    else|
00002a70  20 69 66 20 28 21 73 74  72 6e 63 6d 70 20 28 22  | if (!strncmp ("|
00002a80  2d 69 6e 74 65 72 61 63  74 69 76 65 22 2c 20 2a  |-interactive", *|
00002a90  61 72 67 76 2c 20 4d 41  58 20 28 32 2c 20 73 74  |argv, MAX (2, st|
00002aa0  72 6c 65 6e 20 28 2a 61  72 67 76 29 29 29 29 20  |rlen (*argv)))) |
00002ab0  2f 2a 20 2d 69 6e 74 65  72 61 63 74 69 76 65 20  |/* -interactive |
00002ac0  20 20 20 20 20 20 20 20  2a 2f 0a 20 20 20 20 20  |        */.     |
00002ad0  20 69 6e 74 65 72 61 63  74 69 76 65 20 3d 20 31  | interactive = 1|
00002ae0  3b 0a 0a 20 20 20 20 65  6c 73 65 20 7b 0a 20 20  |;..    else {.  |
00002af0  20 20 20 20 73 74 72 63  70 79 20 28 73 6f 75 72  |    strcpy (sour|
00002b00  63 65 5f 66 69 6c 65 6e  61 6d 65 2c 20 2a 61 72  |ce_filename, *ar|
00002b10  67 76 29 3b 20 20 20 20  20 20 20 20 20 20 20 20  |gv);            |
00002b20  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002b30  20 20 20 20 20 20 2f 2a  20 52 65 61 64 20 73 6f  |      /* Read so|
00002b40  75 72 63 65 20 66 69 6c  65 6e 61 6d 65 2e 2a 2f  |urce filename.*/|
00002b50  0a 20 20 20 20 20 20 69  66 20 28 61 72 67 73 29  |.      if (args)|
00002b60  20 75 73 61 67 65 20 28  70 72 6f 67 6e 61 6d 65  | usage (progname|
00002b70  29 3b 0a 20 20 20 20 7d  0a 20 20 7d 0a 0a 20 20  |);.    }.  }..  |
00002b80  69 66 20 28 73 6f 75 72  63 65 5f 66 69 6c 65 6e  |if (source_filen|
00002b90  61 6d 65 5b 30 5d 20 3d  3d 20 4e 55 4c 4c 29 20  |ame[0] == NULL) |
00002ba0  7b 0a 20 20 20 20 66 70  72 69 6e 74 66 20 28 73  |{.    fprintf (s|
00002bb0  74 64 65 72 72 2c 20 22  53 6f 75 72 63 65 20 66  |tderr, "Source f|
00002bc0  69 6c 65 6e 61 6d 65 20  72 65 71 75 69 72 65 64  |ilename required|
00002bd0  5c 6e 5c 6e 22 29 3b 0a  20 20 20 20 75 73 61 67  |\n\n");.    usag|
00002be0  65 20 28 70 72 6f 67 6e  61 6d 65 29 3b 0a 20 20  |e (progname);.  |
00002bf0  7d 0a 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |}..             |
00002c00  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00002c20  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 47 65  |           /* Ge|
00002c30  74 20 66 69 6c 65 20 64  65 74 61 69 6c 20 66 72  |t file detail fr|
00002c40  6f 6d 20 73 6f 75 72 63  65 20 66 69 6c 65 6e 61  |om source filena|
00002c50  6d 65 2e 2a 2f 0a 20 20  73 74 72 63 70 79 20 28  |me.*/.  strcpy (|
00002c60  66 69 6c 65 5f 65 78 74  2c 20 65 78 61 6d 69 6e  |file_ext, examin|
00002c70  65 5f 66 69 6c 65 6e 61  6d 65 20 28 73 6f 75 72  |e_filename (sour|
00002c80  63 65 5f 66 69 6c 65 6e  61 6d 65 2c 20 6f 75 74  |ce_filename, out|
00002c90  5f 66 69 6c 65 6e 61 6d  65 2c 20 6f 72 69 67 5f  |_filename, orig_|
00002ca0  65 78 74 29 29 3b 0a 20  20 6f 75 74 5f 66 69 6c  |ext));.  out_fil|
00002cb0  65 6e 61 6d 65 5b 4d 49  4e 20 28 4c 45 41 46 4e  |ename[MIN (LEAFN|
00002cc0  41 4d 45 5f 4d 41 58 2c  20 32 35 36 29 20 2d 20  |AME_MAX, 256) - |
00002cd0  32 5d 20 3d 20 27 5c 30  27 3b 20 20 20 20 20 2f  |2] = '\0';     /|
00002ce0  2a 20 61 6e 64 20 72 65  64 75 63 65 20 69 66 20  |* and reduce if |
00002cf0  6e 65 63 65 73 73 61 72  79 2e 20 20 20 20 20 20  |necessary.      |
00002d00  20 20 20 20 20 20 20 2a  2f 0a 0a 20 20 73 6f 75  |       */..  sou|
00002d10  72 63 65 5f 66 69 6c 65  20 3d 20 66 6f 70 65 6e  |rce_file = fopen|
00002d20  20 28 73 6f 75 72 63 65  5f 66 69 6c 65 6e 61 6d  | (source_filenam|
00002d30  65 2c 20 22 72 62 22 29  3b 20 20 20 20 20 20 20  |e, "rb");       |
00002d40  20 20 20 2f 2a 20 4f 70  65 6e 20 72 65 61 64 20  |   /* Open read |
00002d50  62 69 6e 61 72 79 20 73  6f 75 72 63 65 20 66 69  |binary source fi|
00002d60  6c 65 2e 20 20 20 20 20  20 20 20 2a 2f 0a 20 20  |le.        */.  |
00002d70  69 66 20 28 73 6f 75 72  63 65 5f 66 69 6c 65 20  |if (source_file |
00002d80  3d 3d 20 4e 55 4c 4c 29  20 7b 20 20 20 20 20 20  |== NULL) {      |
00002d90  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002da0  20 20 20 20 20 20 2f 2a  20 52 65 70 6f 72 74 20  |      /* Report |
00002db0  69 66 20 65 72 72 6f 72  2c 20 61 6e 64 20 73 74  |if error, and st|
00002dc0  6f 70 2e 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |op.           */|
00002dd0  0a 20 20 20 20 66 70 72  69 6e 74 66 20 28 73 74  |.    fprintf (st|
00002de0  64 65 72 72 2c 20 22 46  61 74 61 6c 20 65 72 72  |derr, "Fatal err|
00002df0  6f 72 20 6f 70 65 6e 69  6e 67 20 25 73 20 66 6f  |or opening %s fo|
00002e00  72 20 69 6e 70 75 74 2e  5c 6e 22 2c 20 73 6f 75  |r input.\n", sou|
00002e10  72 63 65 5f 66 69 6c 65  6e 61 6d 65 29 3b 0a 20  |rce_filename);. |
00002e20  20 20 20 65 78 69 74 20  28 45 58 49 54 5f 46 41  |   exit (EXIT_FA|
00002e30  49 4c 55 52 45 29 3b 0a  20 20 7d 0a 0a 20 20 70  |ILURE);.  }..  p|
00002e40  72 69 6e 74 66 20 28 22  55 73 69 6e 67 20 66 69  |rintf ("Using fi|
00002e50  6c 65 20 73 69 7a 65 20  6f 66 20 25 6c 64 20 62  |le size of %ld b|
00002e60  79 74 65 73 2e 5c 6e 22  2c 20 64 69 73 6b 5f 73  |ytes.\n", disk_s|
00002e70  69 7a 65 29 3b 0a 20 20  66 73 65 65 6b 20 28 73  |ize);.  fseek (s|
00002e80  6f 75 72 63 65 5f 66 69  6c 65 2c 20 30 4c 2c 20  |ource_file, 0L, |
00002e90  53 45 45 4b 5f 45 4e 44  29 3b 20 20 20 20 20 20  |SEEK_END);      |
00002ea0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
00002eb0  20 53 65 74 20 66 69 6c  65 20 70 6f 69 6e 74 65  | Set file pointe|
00002ec0  72 20 74 6f 20 65 6e 64  20 6f 66 20 66 69 6c 65  |r to end of file|
00002ed0  2c 20 20 20 20 20 2a 2f  0a 20 20 66 69 6c 65 5f  |,     */.  file_|
00002ee0  6c 65 6e 67 74 68 20 3d  20 66 74 65 6c 6c 20 28  |length = ftell (|
00002ef0  73 6f 75 72 63 65 5f 66  69 6c 65 29 3b 20 20 20  |source_file);   |
00002f00  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002f10  20 2f 2a 20 67 65 74 20  66 69 6c 65 20 6c 65 6e  | /* get file len|
00002f20  67 74 68 20 20 20 20 20  20 20 20 20 20 20 20 20  |gth             |
00002f30  20 20 20 20 20 20 20 20  20 2a 2f 0a 20 20 66 73  |         */.  fs|
00002f40  65 65 6b 20 28 73 6f 75  72 63 65 5f 66 69 6c 65  |eek (source_file|
00002f50  2c 20 30 4c 2c 20 53 45  45 4b 5f 53 45 54 29 3b  |, 0L, SEEK_SET);|
00002f60  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002f70  20 20 20 20 2f 2a 20 61  6e 64 20 72 65 73 65 74  |    /* and reset|
00002f80  20 70 6f 69 6e 74 65 72  20 74 6f 20 74 68 65 20  | pointer to the |
00002f90  73 74 61 72 74 2e 20 20  20 20 20 20 2a 2f 0a 20  |start.      */. |
00002fa0  20 69 66 20 28 66 69 6c  65 5f 6c 65 6e 67 74 68  | if (file_length|
00002fb0  20 3c 3d 20 64 69 73 6b  5f 73 69 7a 65 29 20 7b  | <= disk_size) {|
00002fc0  0a 20 20 20 20 66 70 72  69 6e 74 66 20 28 73 74  |.    fprintf (st|
00002fd0  64 65 72 72 2c 20 22 4e  6f 20 6e 65 65 64 20 74  |derr, "No need t|
00002fe0  6f 20 73 70 6c 69 74 20  66 69 6c 65 2e 5c 6e 22  |o split file.\n"|
00002ff0  29 3b 0a 20 20 20 20 66  63 6c 6f 73 65 20 28 73  |);.    fclose (s|
00003000  6f 75 72 63 65 5f 66 69  6c 65 29 3b 0a 20 20 20  |ource_file);.   |
00003010  20 65 78 69 74 20 28 45  58 49 54 5f 53 55 43 43  | exit (EXIT_SUCC|
00003020  45 53 53 29 3b 0a 20 20  7d 0a 0a 20 20 62 75 66  |ESS);.  }..  buf|
00003030  66 65 72 20 3d 20 28 6c  6f 6e 67 20 2a 29 20 6d  |fer = (long *) m|
00003040  61 6c 6c 6f 63 20 28 28  73 69 7a 65 5f 74 29 20  |alloc ((size_t) |
00003050  72 65 61 64 5f 73 69 7a  65 29 3b 20 20 20 20 20  |read_size);     |
00003060  20 20 20 2f 2a 20 41 6c  6c 6f 63 61 74 65 20 6d  |   /* Allocate m|
00003070  65 6d 6f 72 79 20 66 6f  72 20 61 20 62 75 66 66  |emory for a buff|
00003080  65 72 2e 20 20 20 20 20  20 20 20 2a 2f 0a 20 20  |er.        */.  |
00003090  69 66 20 28 62 75 66 66  65 72 20 3d 3d 20 4e 55  |if (buffer == NU|
000030a0  4c 4c 29 20 7b 0a 20 20  20 20 66 70 72 69 6e 74  |LL) {.    fprint|
000030b0  66 20 28 73 74 64 65 72  72 2c 20 22 46 61 74 61  |f (stderr, "Fata|
000030c0  6c 20 65 72 72 6f 72 2c  20 75 6e 61 62 6c 65 20  |l error, unable |
000030d0  74 6f 20 61 6c 6c 6f 63  61 74 65 20 6d 65 6d 6f  |to allocate memo|
000030e0  72 79 20 62 6c 6f 63 6b  20 6f 66 20 25 6c 64 20  |ry block of %ld |
000030f0  62 79 74 65 73 5c 6e 22  2c 20 72 65 61 64 5f 73  |bytes\n", read_s|
00003100  69 7a 65 29 3b 0a 20 20  20 20 65 78 69 74 20 28  |ize);.    exit (|
00003110  45 58 49 54 5f 46 41 49  4c 55 52 45 29 3b 0a 20  |EXIT_FAILURE);. |
00003120  20 7d 0a 0a 20 20 70 72  69 6e 74 66 20 28 22 55  | }..  printf ("U|
00003130  73 69 6e 67 20 62 75 66  66 65 72 20 73 69 7a 65  |sing buffer size|
00003140  20 6f 66 20 25 6c 64 20  62 79 74 65 73 2e 5c 6e  | of %ld bytes.\n|
00003150  22 2c 20 72 65 61 64 5f  73 69 7a 65 29 3b 0a 0a  |", read_size);..|
00003160  23 69 66 64 65 66 20 41  43 4f 52 4e 0a 20 20 72  |#ifdef ACORN.  r|
00003170  65 67 73 2e 72 5b 30 5d  20 3d 20 35 3b 20 20 20  |egs.r[0] = 5;   |
00003180  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003190  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
000031a0  50 65 72 66 6f 72 6d 20  61 6e 20 4f 53 5f 46 69  |Perform an OS_Fi|
000031b0  6c 65 20 74 6f 20 72 65  61 64 20 66 69 6c 65 20  |le to read file |
000031c0  64 61 74 61 2e 20 20 20  20 20 20 20 20 2a 2f 0a  |data.        */.|
000031d0  20 20 72 65 67 73 2e 72  5b 31 5d 20 3d 20 28 69  |  regs.r[1] = (i|
000031e0  6e 74 29 20 73 6f 75 72  63 65 5f 66 69 6c 65 6e  |nt) source_filen|
000031f0  61 6d 65 3b 0a 20 20 65  72 72 20 3d 20 5f 6b 65  |ame;.  err = _ke|
00003200  72 6e 65 6c 5f 73 77 69  20 28 53 57 49 5f 4f 53  |rnel_swi (SWI_OS|
00003210  5f 46 69 6c 65 2c 20 26  72 65 67 73 2c 20 26 72  |_File, &regs, &r|
00003220  65 67 73 29 3b 0a 20 20  69 66 20 28 65 72 72 20  |egs);.  if (err |
00003230  21 3d 20 4e 55 4c 4c 20  7c 7c 20 28 72 65 67 73  |!= NULL || (regs|
00003240  2e 72 5b 30 5d 20 21 3d  20 31 20 26 26 20 72 65  |.r[0] != 1 && re|
00003250  67 73 2e 72 5b 30 5d 20  21 3d 20 33 29 29 20 7b  |gs.r[0] != 3)) {|
00003260  0a 20 20 20 20 66 70 72  69 6e 74 66 20 28 73 74  |.    fprintf (st|
00003270  64 65 72 72 2c 20 22 46  61 74 61 6c 20 65 72 72  |derr, "Fatal err|
00003280  6f 72 2c 20 25 73 20 69  73 20 6e 6f 74 20 61 20  |or, %s is not a |
00003290  66 69 6c 65 5c 6e 22 2c  20 73 6f 75 72 63 65 5f  |file\n", source_|
000032a0  66 69 6c 65 6e 61 6d 65  29 3b 0a 20 20 20 20 65  |filename);.    e|
000032b0  78 69 74 20 28 45 58 49  54 5f 46 41 49 4c 55 52  |xit (EXIT_FAILUR|
000032c0  45 29 3b 0a 20 20 7d 0a  20 20 73 70 72 69 6e 74  |E);.  }.  sprint|
000032d0  66 20 28 74 79 70 65 2c  20 22 74 25 78 22 2c 20  |f (type, "t%x", |
000032e0  28 30 78 46 46 46 20 26  20 72 65 67 73 2e 72 5b  |(0xFFF & regs.r[|
000032f0  32 5d 20 3e 3e 20 38 29  29 3b 0a 23 65 6e 64 69  |2] >> 8));.#endi|
00003300  66 0a 0a 20 20 73 70 72  69 6e 74 66 20 28 68 65  |f..  sprintf (he|
00003310  61 64 65 72 2c 20 22 53  70 6c 69 74 3a 25 73 25  |ader, "Split:%s%|
00003320  73 3d 25 64 3d 25 73 7c  22 2c 20 6f 75 74 5f 66  |s=%d=%s|", out_f|
00003330  69 6c 65 6e 61 6d 65 2c  20 6f 72 69 67 5f 65 78  |ilename, orig_ex|
00003340  74 2c 20 20 20 20 20 20  20 20 20 2f 2a 20 43 72  |t,         /* Cr|
00003350  65 61 74 65 20 74 68 65  20 6f 75 74 70 75 74 20  |eate the output |
00003360  20 20 20 2a 2f 0a 20 20  20 20 20 20 28 69 6e 74  |   */.      (int|
00003370  29 20 28 66 69 6c 65 5f  6c 65 6e 67 74 68 20 2f  |) (file_length /|
00003380  20 28 64 69 73 6b 5f 73  69 7a 65 20 2d 20 37 20  | (disk_size - 7 |
00003390  2d 20 73 74 72 6c 65 6e  20 28 6f 75 74 5f 66 69  |- strlen (out_fi|
000033a0  6c 65 6e 61 6d 65 29 20  2d 20 20 20 20 20 2f 2a  |lename) -     /*|
000033b0  20 66 69 6c 65 20 68 65  61 64 65 72 2e 20 20 20  | file header.   |
000033c0  20 20 20 20 20 20 2a 2f  0a 20 20 20 20 20 20 73  |      */.      s|
000033d0  74 72 6c 65 6e 20 28 6f  72 69 67 5f 65 78 74 29  |trlen (orig_ext)|
000033e0  29 20 2b 20 31 29 2c 20  74 79 70 65 29 3b 0a 0a  |) + 1), type);..|
000033f0  20 20 66 69 6c 65 5f 6e  75 6d 62 65 72 20 3d 20  |  file_number = |
00003400  30 3b 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |0;              |
00003410  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003420  2f 2a 20 49 6e 69 74 69  61 6c 69 73 65 20 66 69  |/* Initialise fi|
00003430  6c 65 20 6e 75 6d 62 65  72 20 63 6f 75 6e 74 65  |le number counte|
00003440  72 2e 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |r.              |
00003450  2a 2f 0a 20 20 69 6e 5f  70 6f 73 69 74 69 6f 6e  |*/.  in_position|
00003460  20 3d 20 30 3b 20 20 20  20 20 20 20 20 20 20 20  | = 0;           |
00003470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003480  20 20 20 2f 2a 20 49 6e  69 74 69 61 6c 69 73 65  |   /* Initialise|
00003490  20 73 6f 75 72 63 65 20  66 69 6c 65 20 70 6f 73  | source file pos|
000034a0  69 74 69 6f 6e 20 70 6f  69 6e 74 65 72 2e 20 20  |ition pointer.  |
000034b0  20 20 20 2a 2f 0a 0a 20  20 77 68 69 6c 65 20 28  |   */..  while (|
000034c0  66 69 6c 65 5f 6c 65 6e  67 74 68 20 2d 20 69 6e  |file_length - in|
000034d0  5f 70 6f 73 69 74 69 6f  6e 20 3e 20 30 29 20 7b  |_position > 0) {|
000034e0  20 20 20 20 20 20 20 2f  2a 20 49 66 20 61 6e 79  |       /* If any|
000034f0  20 64 61 74 61 20 6c 65  66 74 20 74 6f 20 74 72  | data left to tr|
00003500  61 6e 73 66 65 72 20 20  20 20 20 20 20 20 20 20  |ansfer          |
00003510  20 20 20 20 20 20 20 2a  2f 0a 20 20 20 20 66 69  |       */.    fi|
00003520  6c 65 5f 6e 75 6d 62 65  72 2b 2b 3b 20 20 20 20  |le_number++;    |
00003530  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003540  20 20 20 20 20 20 20 20  20 20 2f 2a 20 69 6e 63  |          /* inc|
00003550  72 65 6d 65 6e 74 20 66  69 6c 65 20 6e 75 6d 62  |rement file numb|
00003560  65 72 20 63 6f 75 6e 74  65 72 2e 20 20 20 20 20  |er counter.     |
00003570  20 20 20 20 20 20 20 20  20 20 2a 2f 0a 20 20 20  |          */.   |
00003580  20 6e 75 6d 74 6f 73 74  72 20 28 66 69 6c 65 5f  | numtostr (file_|
00003590  6e 75 6d 62 65 72 2c 20  66 6e 75 6d 29 3b 20 20  |number, fnum);  |
000035a0  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
000035b0  43 6f 6e 76 65 72 74 20  74 6f 20 61 20 6e 75 6d  |Convert to a num|
000035c0  62 65 72 2e 20 20 20 20  20 20 20 20 20 20 20 20  |ber.            |
000035d0  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
000035e0  0a 20 20 20 20 77 68 69  6c 65 20 28 69 6e 74 65  |.    while (inte|
000035f0  72 61 63 74 69 76 65 20  3d 3d 20 31 29 20 7b 20  |ractive == 1) { |
00003600  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003610  20 2f 2a 20 49 66 20 69  6e 74 65 72 61 63 74 69  | /* If interacti|
00003620  76 65 20 6f 70 74 69 6f  6e 20 73 65 6c 65 63 74  |ve option select|
00003630  65 64 2c 20 61 73 6b 20  66 6f 72 20 20 20 20 20  |ed, ask for     |
00003640  20 2a 2f 0a 20 20 20 20  20 20 70 72 69 6e 74 66  | */.      printf|
00003650  20 28 22 45 6e 74 65 72  20 70 61 74 68 20 66 6f  | ("Enter path fo|
00003660  72 20 25 73 25 73 25 73  20 28 52 65 74 75 72 6e  |r %s%s%s (Return|
00003670  20 66 6f 72 20 25 73 29  20 3a 5c 6e 22 2c 20 20  | for %s) :\n",  |
00003680  20 20 20 20 2f 2a 20 64  65 73 74 69 6e 61 74 69  |    /* destinati|
00003690  6f 6e 20 6f 66 20 6f 75  74 70 75 74 20 66 69 6c  |on of output fil|
000036a0  65 2e 20 20 2a 2f 0a 20  20 20 20 20 20 20 20 20  |e.  */.         |
000036b0  20 6f 75 74 5f 66 69 6c  65 6e 61 6d 65 2c 20 66  | out_filename, f|
000036c0  6e 75 6d 2c 20 66 69 6c  65 5f 65 78 74 2c 0a 20  |num, file_ext,. |
000036d0  20 20 20 20 20 20 20 20  20 6f 75 74 5f 70 61 74  |         out_pat|
000036e0  68 5b 30 5d 20 3d 3d 20  27 5c 30 27 20 3f 20 22  |h[0] == '\0' ? "|
000036f0  63 75 72 72 65 6e 74 20  64 69 72 65 63 74 6f 72  |current director|
00003700  79 22 20 3a 20 6f 75 74  5f 70 61 74 68 29 3b 0a  |y" : out_path);.|
00003710  0a 20 20 20 20 20 20 67  65 74 73 20 28 73 74 72  |.      gets (str|
00003720  69 6e 67 29 3b 20 20 20  20 20 20 20 20 20 20 20  |ing);           |
00003730  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003740  20 2f 2a 20 47 65 74 20  6f 75 74 70 75 74 20 64  | /* Get output d|
00003750  65 73 74 69 6e 61 74 69  6f 6e 2e 20 20 20 20 20  |estination.     |
00003760  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003770  20 2a 2f 0a 20 20 20 20  20 20 69 66 20 28 73 74  | */.      if (st|
00003780  72 63 68 72 20 28 73 74  72 69 6e 67 2c 20 27 20  |rchr (string, ' |
00003790  27 29 20 21 3d 20 4e 55  4c 4c 29 20 7b 0a 20 20  |') != NULL) {.  |
000037a0  20 20 20 20 20 20 70 72  69 6e 74 66 20 28 22 49  |      printf ("I|
000037b0  6e 76 61 6c 69 64 20 70  61 74 68 20 6e 61 6d 65  |nvalid path name|
000037c0  2e 5c 6e 22 29 3b 0a 20  20 20 20 20 20 20 20 63  |.\n");.        c|
000037d0  6f 6e 74 69 6e 75 65 3b  0a 20 20 20 20 20 20 7d  |ontinue;.      }|
000037e0  0a 20 20 20 20 20 20 69  66 20 28 73 74 72 69 6e  |.      if (strin|
000037f0  67 5b 30 5d 20 21 3d 20  27 5c 30 27 29 20 7b 20  |g[0] != '\0') { |
00003800  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003810  20 2f 2a 20 49 66 20 6e  6f 74 68 69 6e 67 20 65  | /* If nothing e|
00003820  6e 74 65 72 65 64 2c 20  74 68 65 6e 20 75 73 65  |ntered, then use|
00003830  20 74 68 65 20 64 65 66  61 75 6c 74 2e 20 20 20  | the default.   |
00003840  20 2a 2f 0a 20 20 20 20  20 20 20 20 73 74 72 63  | */.        strc|
00003850  70 79 20 28 6f 75 74 5f  70 61 74 68 2c 20 73 74  |py (out_path, st|
00003860  72 69 6e 67 29 3b 0a 20  20 20 20 20 20 20 20 69  |ring);.        i|
00003870  20 3d 20 73 74 72 6c 65  6e 20 28 6f 75 74 5f 70  | = strlen (out_p|
00003880  61 74 68 29 3b 0a 20 20  20 20 20 20 20 20 69 66  |ath);.        if|
00003890  20 28 6f 75 74 5f 70 61  74 68 5b 69 20 2d 20 31  | (out_path[i - 1|
000038a0  5d 20 21 3d 20 46 49 4c  45 5f 53 45 50 41 52 41  |] != FILE_SEPARA|
000038b0  54 4f 52 29 0a 20 20 20  20 20 20 20 20 20 20 69  |TOR).          i|
000038c0  66 20 28 21 43 4f 4c 4f  4e 20 7c 7c 20 28 43 4f  |f (!COLON || (CO|
000038d0  4c 4f 4e 20 26 26 20 6f  75 74 5f 70 61 74 68 5b  |LON && out_path[|
000038e0  69 20 2d 20 31 5d 20 21  3d 20 27 3a 27 29 29 20  |i - 1] != ':')) |
000038f0  7b 0a 20 20 20 20 20 20  20 20 20 20 20 20 6f 75  |{.            ou|
00003900  74 5f 70 61 74 68 5b 69  5d 20 3d 20 46 49 4c 45  |t_path[i] = FILE|
00003910  5f 53 45 50 41 52 41 54  4f 52 3b 0a 20 20 20 20  |_SEPARATOR;.    |
00003920  20 20 20 20 20 20 20 20  6f 75 74 5f 70 61 74 68  |        out_path|
00003930  5b 69 20 2b 20 31 5d 20  3d 20 27 5c 30 27 3b 0a  |[i + 1] = '\0';.|
00003940  20 20 20 20 20 20 20 20  20 20 7d 0a 0a 20 20 20  |          }..   |
00003950  20 20 20 7d 0a 20 20 20  20 20 20 69 6e 74 65 72  |   }.      inter|
00003960  61 63 74 69 76 65 20 3d  20 69 6e 74 65 72 61 63  |active = interac|
00003970  74 69 76 65 20 7c 20 32  3b 20 20 20 20 20 20 20  |tive | 2;       |
00003980  20 20 20 20 20 2f 2a 20  53 65 74 20 66 6c 61 67  |     /* Set flag|
00003990  20 74 6f 20 73 61 79 20  64 61 74 61 20 68 61 73  | to say data has|
000039a0  20 62 65 65 6e 20 61 63  63 65 70 74 65 64 2e 20  | been accepted. |
000039b0  20 20 20 20 20 2a 2f 0a  20 20 20 20 7d 0a 0a 20  |     */.    }.. |
000039c0  20 20 20 69 6e 74 65 72  61 63 74 69 76 65 20 3d  |   interactive =|
000039d0  20 69 6e 74 65 72 61 63  74 69 76 65 20 26 20 31  | interactive & 1|
000039e0  3b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;               |
000039f0  20 20 20 20 20 20 20 2f  2a 20 4d 61 73 6b 20 6f  |       /* Mask o|
00003a00  66 66 20 75 6e 72 65 71  75 69 72 65 64 20 64 61  |ff unrequired da|
00003a10  74 61 2e 20 20 20 20 20  20 20 20 20 20 20 20 2a  |ta.            *|
00003a20  2f 0a 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |/..             |
00003a30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003a50  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 43 72  |           /* Cr|
00003a60  65 61 74 65 20 74 68 65  20 66 75 6c 6c 20 6f 75  |eate the full ou|
00003a70  74 70 75 74 20 66 69 6c  65 6e 61 6d 65 2e 20 20  |tput filename.  |
00003a80  20 20 20 2a 2f 0a 20 20  20 20 73 70 72 69 6e 74  |   */.    sprint|
00003a90  66 20 28 6f 75 74 5f 6e  61 6d 65 2c 20 22 25 73  |f (out_name, "%s|
00003aa0  25 73 25 73 25 73 22 2c  20 6f 75 74 5f 70 61 74  |%s%s%s", out_pat|
00003ab0  68 2c 20 6f 75 74 5f 66  69 6c 65 6e 61 6d 65 2c  |h, out_filename,|
00003ac0  20 66 6e 75 6d 2c 20 66  69 6c 65 5f 65 78 74 29  | fnum, file_ext)|
00003ad0  3b 0a 0a 20 20 20 20 69  66 20 28 66 69 6c 65 5f  |;..    if (file_|
00003ae0  6e 75 6d 62 65 72 20 3e  20 31 29 20 7b 20 20 20  |number > 1) {   |
00003af0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003b10  20 20 20 2f 2a 20 49 66  20 69 74 27 73 20 6e 6f  |   /* If it's no|
00003b20  74 20 74 68 65 20 66 69  72 73 74 20 70 61 72 74  |t the first part|
00003b30  2c 20 20 2a 2f 0a 20 20  20 20 20 20 6e 75 6d 74  |,  */.      numt|
00003b40  6f 73 74 72 20 28 66 69  6c 65 5f 6e 75 6d 62 65  |ostr (file_numbe|
00003b50  72 2c 20 66 6e 75 6d 29  3b 20 20 20 20 20 20 20  |r, fnum);       |
00003b60  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003b70  20 20 20 20 20 20 2f 2a  20 63 72 65 61 74 65 20  |      /* create |
00003b80  61 20 73 6d 61 6c 6c 65  72 20 68 65 61 64 65 72  |a smaller header|
00003b90  2e 20 20 20 20 20 2a 2f  0a 20 20 20 20 20 20 73  |.     */.      s|
00003ba0  70 72 69 6e 74 66 20 28  68 65 61 64 65 72 2c 20  |printf (header, |
00003bb0  22 53 70 3a 25 73 25 73  3d 25 73 7c 22 2c 20 6f  |"Sp:%s%s=%s|", o|
00003bc0  75 74 5f 66 69 6c 65 6e  61 6d 65 2c 20 6f 72 69  |ut_filename, ori|
00003bd0  67 5f 65 78 74 2c 20 66  6e 75 6d 29 3b 0a 20 20  |g_ext, fnum);.  |
00003be0  20 20 7d 0a 0a 23 69 66  64 65 66 20 41 43 4f 52  |  }..#ifdef ACOR|
00003bf0  4e 0a 20 20 20 20 72 65  67 73 2e 72 5b 30 5d 20  |N.    regs.r[0] |
00003c00  3d 20 37 3b 20 20 20 20  20 20 20 20 20 20 20 20  |= 7;            |
00003c10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003c30  20 20 2f 2a 20 43 72 65  61 74 65 20 74 68 65 20  |  /* Create the |
00003c40  66 69 6c 65 20 77 69 74  68 20 53 57 49 20 20 20  |file with SWI   |
00003c50  20 20 2a 2f 0a 20 20 20  20 72 65 67 73 2e 72 5b  |  */.    regs.r[|
00003c60  31 5d 20 3d 20 28 69 6e  74 29 20 6f 75 74 5f 6e  |1] = (int) out_n|
00003c70  61 6d 65 3b 20 20 20 20  20 20 20 20 20 20 20 20  |ame;            |
00003c80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003c90  20 20 20 20 20 2f 2a 20  4f 53 5f 46 69 6c 65 20  |     /* OS_File |
00003ca0  37 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |7               |
00003cb0  20 20 20 20 20 2a 2f 0a  20 20 20 20 72 65 67 73  |     */.    regs|
00003cc0  2e 72 5b 32 5d 20 3d 20  30 78 64 65 61 64 64 65  |.r[2] = 0xdeadde|
00003cd0  61 64 3b 0a 20 20 20 20  72 65 67 73 2e 72 5b 33  |ad;.    regs.r[3|
00003ce0  5d 20 3d 20 30 78 64 65  61 64 64 65 61 64 3b 0a  |] = 0xdeaddead;.|
00003cf0  20 20 20 20 72 65 67 73  2e 72 5b 34 5d 20 3d 20  |    regs.r[4] = |
00003d00  30 3b 0a 20 20 20 20 72  65 67 73 2e 72 5b 35 5d  |0;.    regs.r[5]|
00003d10  20 3d 20 28 69 6e 74 29  20 4d 49 4e 20 28 66 69  | = (int) MIN (fi|
00003d20  6c 65 5f 6c 65 6e 67 74  68 20 2d 20 69 6e 5f 70  |le_length - in_p|
00003d30  6f 73 69 74 69 6f 6e 20  2b 20 73 74 72 6c 65 6e  |osition + strlen|
00003d40  20 28 68 65 61 64 65 72  29 2c 20 64 69 73 6b 5f  | (header), disk_|
00003d50  73 69 7a 65 29 3b 0a 20  20 20 20 69 66 20 28 28  |size);.    if ((|
00003d60  65 72 72 20 3d 20 5f 6b  65 72 6e 65 6c 5f 73 77  |err = _kernel_sw|
00003d70  69 20 28 53 57 49 5f 4f  53 5f 46 69 6c 65 2c 20  |i (SWI_OS_File, |
00003d80  26 72 65 67 73 2c 20 26  72 65 67 73 29 29 20 21  |&regs, &regs)) !|
00003d90  3d 20 4e 55 4c 4c 29 20  7b 0a 20 20 20 20 20 20  |= NULL) {.      |
00003da0  66 70 72 69 6e 74 66 20  28 73 74 64 65 72 72 2c  |fprintf (stderr,|
00003db0  20 22 46 61 74 61 6c 20  65 72 72 6f 72 20 6f 70  | "Fatal error op|
00003dc0  65 6e 69 6e 67 20 25 73  20 66 6f 72 20 6f 75 74  |ening %s for out|
00003dd0  70 75 74 3a 5c 6e 2d 2d  20 25 73 5c 6e 22 2c 20  |put:\n-- %s\n", |
00003de0  6f 75 74 5f 6e 61 6d 65  2c 20 65 72 72 2d 3e 65  |out_name, err->e|
00003df0  72 72 6d 65 73 73 29 3b  0a 20 20 20 20 20 20 65  |rrmess);.      e|
00003e00  78 69 74 20 28 45 58 49  54 5f 46 41 49 4c 55 52  |xit (EXIT_FAILUR|
00003e10  45 29 3b 0a 20 20 20 20  7d 0a 23 65 6e 64 69 66  |E);.    }.#endif|
00003e20  0a 0a 20 20 20 20 6f 75  74 5f 66 69 6c 65 20 3d  |..    out_file =|
00003e30  20 66 6f 70 65 6e 20 28  6f 75 74 5f 6e 61 6d 65  | fopen (out_name|
00003e40  2c 20 22 77 62 22 29 3b  20 20 20 20 20 20 20 20  |, "wb");        |
00003e50  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003e60  20 20 2f 2a 20 4f 70 65  6e 20 6f 75 74 70 75 74  |  /* Open output|
00003e70  20 66 69 6c 65 2e 20 20  20 20 20 20 20 20 20 20  | file.          |
00003e80  20 20 2a 2f 0a 20 20 20  20 69 66 20 28 6f 75 74  |  */.    if (out|
00003e90  5f 66 69 6c 65 20 3d 3d  20 4e 55 4c 4c 29 20 7b  |_file == NULL) {|
00003ea0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003ec0  20 20 20 20 20 2f 2a 20  52 65 70 6f 72 74 20 69  |     /* Report i|
00003ed0  66 20 65 72 72 6f 72 2c  20 61 6e 64 20 73 74 6f  |f error, and sto|
00003ee0  70 2e 20 20 20 2a 2f 0a  20 20 20 20 20 20 66 70  |p.   */.      fp|
00003ef0  72 69 6e 74 66 20 28 73  74 64 65 72 72 2c 20 22  |rintf (stderr, "|
00003f00  46 61 74 61 6c 20 65 72  72 6f 72 20 6f 70 65 6e  |Fatal error open|
00003f10  69 6e 67 20 25 73 20 66  6f 72 20 6f 75 74 70 75  |ing %s for outpu|
00003f20  74 2e 5c 6e 22 2c 20 6f  75 74 5f 6e 61 6d 65 29  |t.\n", out_name)|
00003f30  3b 0a 20 20 20 20 20 20  65 78 69 74 20 28 31 29  |;.      exit (1)|
00003f40  3b 0a 20 20 20 20 7d 0a  0a 20 20 20 20 6f 75 74  |;.    }..    out|
00003f50  5f 70 6f 73 69 74 69 6f  6e 20 3d 20 30 3b 20 20  |_position = 0;  |
00003f60  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003f70  20 20 20 20 20 20 20 20  20 2f 2a 20 49 6e 69 74  |         /* Init|
00003f80  69 61 6c 69 73 65 20 6f  75 74 70 75 74 20 66 69  |ialise output fi|
00003f90  6c 65 20 70 6f 73 69 74  69 6f 6e 20 70 6f 69 6e  |le position poin|
00003fa0  74 65 72 2e 20 20 20 20  20 2a 2f 0a 20 20 20 20  |ter.     */.    |
00003fb0  70 72 69 6e 74 66 20 28  22 57 72 69 74 69 6e 67  |printf ("Writing|
00003fc0  20 64 61 74 61 20 74 6f  20 25 73 5c 6e 22 2c 20  | data to %s\n", |
00003fd0  6f 75 74 5f 6e 61 6d 65  29 3b 0a 0a 20 20 20 20  |out_name);..    |
00003fe0  66 70 72 69 6e 74 66 20  28 6f 75 74 5f 66 69 6c  |fprintf (out_fil|
00003ff0  65 2c 20 68 65 61 64 65  72 29 3b 20 20 20 20 20  |e, header);     |
00004000  20 20 20 20 20 20 20 20  20 20 20 20 2f 2a 20 57  |            /* W|
00004010  72 69 74 65 20 74 68 65  20 68 65 61 64 65 72 20  |rite the header |
00004020  69 6e 66 6f 72 6d 61 74  69 6f 6e 2c 20 20 20 20  |information,    |
00004030  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 20  |            */. |
00004040  20 20 20 6f 75 74 5f 70  6f 73 69 74 69 6f 6e 20  |   out_position |
00004050  3d 20 28 6c 6f 6e 67 29  20 73 74 72 6c 65 6e 20  |= (long) strlen |
00004060  28 68 65 61 64 65 72 29  3b 20 20 20 20 20 20 2f  |(header);      /|
00004070  2a 20 61 6e 64 20 75 70  64 61 74 65 20 74 68 65  |* and update the|
00004080  20 6f 75 74 70 75 74 20  66 69 6c 65 20 70 6f 69  | output file poi|
00004090  6e 74 65 72 2e 20 20 20  20 20 20 20 20 20 20 2a  |nter.          *|
000040a0  2f 0a 0a 20 20 20 20 69  66 20 28 64 69 73 6b 5f  |/..    if (disk_|
000040b0  73 69 7a 65 20 3e 20 66  69 6c 65 5f 6c 65 6e 67  |size > file_leng|
000040c0  74 68 20 2d 20 69 6e 5f  70 6f 73 69 74 69 6f 6e  |th - in_position|
000040d0  20 2b 20 6f 75 74 5f 70  6f 73 69 74 69 6f 6e 29  | + out_position)|
000040e0  20 20 20 2f 2a 20 53 65  74 20 74 68 65 20 73 69  |   /* Set the si|
000040f0  7a 65 20 6f 66 20 74 68  65 20 66 69 6c 65 20 77  |ze of the file w|
00004100  65 20 20 2a 2f 0a 20 20  20 20 20 20 64 69 73 6b  |e  */.      disk|
00004110  5f 73 69 7a 65 20 3d 20  66 69 6c 65 5f 6c 65 6e  |_size = file_len|
00004120  67 74 68 20 2d 20 69 6e  5f 70 6f 73 69 74 69 6f  |gth - in_positio|
00004130  6e 20 2b 20 6f 75 74 5f  70 6f 73 69 74 69 6f 6e  |n + out_position|
00004140  3b 20 20 20 20 20 2f 2a  20 77 61 6e 74 20 74 6f  |;     /* want to|
00004150  20 77 72 69 74 65 2e 20  20 20 20 20 20 20 20 20  | write.         |
00004160  20 20 20 20 20 20 2a 2f  0a 0a 20 20 20 20 77 68  |      */..    wh|
00004170  69 6c 65 20 28 64 69 73  6b 5f 73 69 7a 65 20 2d  |ile (disk_size -|
00004180  20 6f 75 74 5f 70 6f 73  69 74 69 6f 6e 20 3e 20  | out_position > |
00004190  30 29 20 7b 20 20 20 20  20 20 20 20 20 20 20 20  |0) {            |
000041a0  20 20 20 20 20 20 20 20  20 20 2f 2a 20 57 68 69  |          /* Whi|
000041b0  6c 65 20 74 68 65 72 65  27 73 20 61 6e 79 20 64  |le there's any d|
000041c0  61 74 61 20 6c 65 66 74  20 20 2a 2f 0a 20 20 20  |ata left  */.   |
000041d0  20 20 20 69 66 20 28 64  69 73 6b 5f 73 69 7a 65  |   if (disk_size|
000041e0  20 2d 20 6f 75 74 5f 70  6f 73 69 74 69 6f 6e 20  | - out_position |
000041f0  3c 20 72 65 61 64 5f 73  69 7a 65 29 20 20 20 20  |< read_size)    |
00004200  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00004210  74 6f 20 74 72 61 6e 73  66 65 72 20 20 20 20 20  |to transfer     |
00004220  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
00004230  20 20 20 20 20 20 20 20  64 61 74 61 5f 73 69 7a  |        data_siz|
00004240  65 20 3d 20 64 69 73 6b  5f 73 69 7a 65 20 2d 20  |e = disk_size - |
00004250  6f 75 74 5f 70 6f 73 69  74 69 6f 6e 3b 0a 20 20  |out_position;.  |
00004260  20 20 20 20 65 6c 73 65  0a 20 20 20 20 20 20 20  |    else.       |
00004270  20 64 61 74 61 5f 73 69  7a 65 20 3d 20 72 65 61  | data_size = rea|
00004280  64 5f 73 69 7a 65 3b 0a  0a 20 20 20 20 20 20 62  |d_size;..      b|
00004290  79 74 65 73 5f 72 65 61  64 20 3d 20 66 72 65 61  |ytes_read = frea|
000042a0  64 20 28 62 75 66 66 65  72 2c 20 31 2c 20 28 73  |d (buffer, 1, (s|
000042b0  69 7a 65 5f 74 29 20 64  61 74 61 5f 73 69 7a 65  |ize_t) data_size|
000042c0  2c 20 73 6f 75 72 63 65  5f 66 69 6c 65 29 3b 20  |, source_file); |
000042d0  20 20 20 20 20 20 20 20  20 2f 2a 20 72 65 61 64  |         /* read|
000042e0  20 20 20 20 20 20 20 20  20 2a 2f 0a 20 20 20 20  |         */.    |
000042f0  20 20 62 79 74 65 73 5f  77 72 69 74 74 65 6e 20  |  bytes_written |
00004300  3d 20 66 77 72 69 74 65  20 28 62 75 66 66 65 72  |= fwrite (buffer|
00004310  2c 20 31 2c 20 28 73 69  7a 65 5f 74 29 20 62 79  |, 1, (size_t) by|
00004320  74 65 73 5f 72 65 61 64  2c 20 6f 75 74 5f 66 69  |tes_read, out_fi|
00004330  6c 65 29 3b 20 20 20 20  20 20 20 20 2f 2a 20 61  |le);        /* a|
00004340  6e 64 20 77 72 69 74 65  2e 20 20 20 2a 2f 0a 0a  |nd write.   */..|
00004350  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00004370  2f 2a 20 43 68 65 63 6b  20 74 6f 20 73 65 65 20  |/* Check to see |
00004380  74 68 61 74 20 61 6c 6c  20 74 68 65 20 64 61 74  |that all the dat|
00004390  61 20 68 61 73 20 62 65  65 6e 20 74 72 61 6e 73  |a has been trans|
000043a0  66 65 72 65 64 20 6f 6b  2e 20 20 20 20 20 20 20  |fered ok.       |
000043b0  2a 2f 0a 20 20 20 20 20  20 69 66 20 28 62 79 74  |*/.      if (byt|
000043c0  65 73 5f 77 72 69 74 74  65 6e 20 3c 20 64 61 74  |es_written < dat|
000043d0  61 5f 73 69 7a 65 20 26  26 20 62 79 74 65 73 5f  |a_size && bytes_|
000043e0  77 72 69 74 74 65 6e 20  3c 20 66 69 6c 65 5f 6c  |written < file_l|
000043f0  65 6e 67 74 68 20 2d 20  6f 75 74 5f 70 6f 73 69  |ength - out_posi|
00004400  74 69 6f 6e 29 20 7b 0a  20 20 20 20 20 20 20 20  |tion) {.        |
00004410  66 70 72 69 6e 74 66 20  28 73 74 64 65 72 72 2c  |fprintf (stderr,|
00004420  20 22 46 61 74 61 6c 20  65 72 72 6f 72 20 77 68  | "Fatal error wh|
00004430  69 6c 65 20 77 72 69 74  69 6e 67 20 25 73 5c 6e  |ile writing %s\n|
00004440  22 2c 20 6f 75 74 5f 6e  61 6d 65 29 3b 0a 20 20  |", out_name);.  |
00004450  20 20 20 20 20 20 65 78  69 74 20 28 45 58 49 54  |      exit (EXIT|
00004460  5f 46 41 49 4c 55 52 45  29 3b 20 20 20 20 20 20  |_FAILURE);      |
00004470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00004480  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
00004490  20 49 66 20 75 6e 73 75  63 65 73 73 66 75 6c 6c  | If unsucessfull|
000044a0  2c 20 73 74 6f 70 2e 20  20 20 20 20 20 20 2a 2f  |, stop.       */|
000044b0  0a 20 20 20 20 20 20 7d  0a 20 20 20 20 20 20 69  |.      }.      i|
000044c0  6e 5f 70 6f 73 69 74 69  6f 6e 20 2b 3d 20 62 79  |n_position += by|
000044d0  74 65 73 5f 72 65 61 64  3b 20 20 20 20 20 20 20  |tes_read;       |
000044e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000044f0  20 20 20 20 20 20 20 20  20 2f 2a 20 55 70 64 61  |         /* Upda|
00004500  74 65 20 74 68 65 20 66  69 6c 65 20 70 6f 73 69  |te the file posi|
00004510  74 69 6f 6e 20 20 20 20  20 2a 2f 0a 20 20 20 20  |tion     */.    |
00004520  20 20 6f 75 74 5f 70 6f  73 69 74 69 6f 6e 20 2b  |  out_position +|
00004530  3d 20 62 79 74 65 73 5f  77 72 69 74 74 65 6e 3b  |= bytes_written;|
00004540  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00004550  20 20 20 20 20 20 20 20  20 20 20 20 2f 2a 20 70  |            /* p|
00004560  6f 69 6e 74 65 72 73 2e  20 20 20 20 20 20 20 20  |ointers.        |
00004570  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a 20  |            */. |
00004580  20 20 20 7d 0a 0a 20 20  20 20 66 63 6c 6f 73 65  |   }..    fclose|
00004590  20 28 6f 75 74 5f 66 69  6c 65 29 3b 20 20 20 20  | (out_file);    |
000045a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000045c0  20 20 20 20 20 20 2f 2a  20 43 6c 6f 73 65 20 6f  |      /* Close o|
000045d0  75 74 70 75 74 20 66 69  6c 65 2e 20 20 20 20 20  |utput file.     |
000045e0  20 20 20 20 20 20 2a 2f  0a 0a 23 69 66 64 65 66  |      */..#ifdef|
000045f0  20 41 43 4f 52 4e 0a 20  20 20 20 72 65 67 73 2e  | ACORN.    regs.|
00004600  72 5b 30 5d 20 3d 20 31  38 3b 20 20 20 20 20 20  |r[0] = 18;      |
00004610  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00004630  20 20 20 20 20 20 20 2f  2a 20 53 65 74 20 74 68  |       /* Set th|
00004640  65 20 66 69 6c 65 74 79  70 65 20 77 69 74 68 20  |e filetype with |
00004650  53 57 49 20 20 20 20 2a  2f 0a 20 20 20 20 72 65  |SWI    */.    re|
00004660  67 73 2e 72 5b 31 5d 20  3d 20 28 69 6e 74 29 20  |gs.r[1] = (int) |
00004670  6f 75 74 5f 6e 61 6d 65  3b 20 20 20 20 20 20 20  |out_name;       |
00004680  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00004690  20 20 20 20 20 20 20 20  20 20 2f 2a 20 4f 53 5f  |          /* OS_|
000046a0  46 69 6c 65 20 31 38 20  20 20 20 20 20 20 20 20  |File 18         |
000046b0  20 20 20 20 20 20 20 20  20 20 2a 2f 0a 20 20 20  |          */.   |
000046c0  20 72 65 67 73 2e 72 5b  32 5d 20 3d 20 53 50 4c  | regs.r[2] = SPL|
000046d0  49 54 5f 46 49 4c 45 54  59 50 45 3b 0a 20 20 20  |IT_FILETYPE;.   |
000046e0  20 65 72 72 20 3d 20 5f  6b 65 72 6e 65 6c 5f 73  | err = _kernel_s|
000046f0  77 69 20 28 53 57 49 5f  4f 53 5f 46 69 6c 65 2c  |wi (SWI_OS_File,|
00004700  20 26 72 65 67 73 2c 20  26 72 65 67 73 29 3b 0a  | &regs, &regs);.|
00004710  23 65 6e 64 69 66 0a 0a  20 20 7d 0a 0a 20 20 66  |#endif..  }..  f|
00004720  63 6c 6f 73 65 20 28 73  6f 75 72 63 65 5f 66 69  |close (source_fi|
00004730  6c 65 29 3b 20 20 20 20  20 20 20 20 20 20 20 20  |le);            |
00004740  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00004760  20 20 20 20 20 2f 2a 20  43 6c 6f 73 65 20 73 6f  |     /* Close so|
00004770  75 72 63 65 20 66 69 6c  65 20 20 20 20 2a 2f 0a  |urce file    */.|
00004780  20 20 66 72 65 65 20 28  62 75 66 66 65 72 29 3b  |  free (buffer);|
00004790  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000047c0  20 20 20 20 20 20 20 20  2f 2a 20 61 6e 64 20 66  |        /* and f|
000047d0  72 65 65 20 62 75 66 66  65 72 2e 20 20 20 20 20  |ree buffer.     |
000047e0  2a 2f 0a 0a 20 20 66 70  72 69 6e 74 66 20 28 73  |*/..  fprintf (s|
000047f0  74 64 65 72 72 2c 20 22  25 6c 64 20 62 79 74 65  |tderr, "%ld byte|
00004800  73 20 77 72 69 74 74 65  6e 20 74 6f 20 25 64 20  |s written to %d |
00004810  25 73 2e 5c 6e 22 2c 20  69 6e 5f 70 6f 73 69 74  |%s.\n", in_posit|
00004820  69 6f 6e 20 2b 0a 20 20  20 20 20 20 28 69 6e 74  |ion +.      (int|
00004830  29 20 28 66 69 6c 65 5f  6e 75 6d 62 65 72 20 2a  |) (file_number *|
00004840  20 28 37 20 2b 20 73 74  72 6c 65 6e 20 28 73 6f  | (7 + strlen (so|
00004850  75 72 63 65 5f 66 69 6c  65 6e 61 6d 65 29 29 29  |urce_filename)))|
00004860  20 2b 20 34 20 2b 20 73  74 72 6c 65 6e 20 28 74  | + 4 + strlen (t|
00004870  79 70 65 29 2c 0a 20 20  20 20 20 20 66 69 6c 65  |ype),.      file|
00004880  5f 6e 75 6d 62 65 72 2c  20 28 66 69 6c 65 5f 6e  |_number, (file_n|
00004890  75 6d 62 65 72 20 3d 3d  20 31 29 20 3f 20 22 66  |umber == 1) ? "f|
000048a0  69 6c 65 22 20 3a 20 22  66 69 6c 65 73 22 29 3b  |ile" : "files");|
000048b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
000048c0  20 52 65 70 6f 72 74 20  73 74 61 74 75 73 2e 20  | Report status. |
000048d0  20 20 20 20 20 20 2a 2f  0a 20 20 66 70 72 69 6e  |      */.  fprin|
000048e0  74 66 20 28 73 74 64 65  72 72 2c 20 22 55 73 65  |tf (stderr, "Use|
000048f0  20 3a 20 6a 6f 69 6e 66  20 25 73 30 31 25 73 20  | : joinf %s01%s |
00004900  5c 6e 74 6f 20 72 65 73  74 6f 72 65 20 66 69 6c  |\nto restore fil|
00004910  65 2e 5c 6e 22 2c 0a 20  20 20 20 20 20 6f 75 74  |e.\n",.      out|
00004920  5f 66 69 6c 65 6e 61 6d  65 2c 20 28 66 69 6c 65  |_filename, (file|
00004930  5f 65 78 74 5b 30 5d 20  3d 3d 20 27 5c 30 27 29  |_ext[0] == '\0')|
00004940  20 3f 20 22 22 20 3a 20  22 2e 73 70 74 22 29 3b  | ? "" : ".spt");|
00004950  0a 0a 20 20 65 78 69 74  20 28 45 58 49 54 5f 53  |..  exit (EXIT_S|
00004960  55 43 43 45 53 53 29 3b  20 20 20 20 20 20 20 20  |UCCESS);        |
00004970  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00004990  20 20 20 20 20 20 20 20  20 20 2f 2a 20 61 6e 64  |          /* and|
000049a0  20 66 69 6e 69 73 68 2e  20 20 20 20 20 20 20 20  | finish.        |
000049b0  20 20 2a 2f 0a 7d 0a                              |  */.}.|
000049b7