home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilss / support / Source / Splitf_c < prev    next >
Text File  |  1995-02-04  |  19KB  |  391 lines

  1. /********************************************************************************/
  2. /*                                                                              */
  3. /* Splitf.c                                                                     */
  4. /* Part of Splitf and Joinf distribution                                        */
  5. /* version 1.13, © 1993-1995 Adam Hamilton                                      */
  6. /* See the README file for copyright information                                */
  7. /*                                                                              */
  8. /********************************************************************************/
  9.  
  10.  
  11. /*********************************/
  12. /* Include required header files */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include "config.h"
  18.  
  19.  
  20. /**********************************/
  21. /* Program macros and definitions */
  22.  
  23. #ifndef Bool
  24. #  define Bool char
  25. #endif
  26.  
  27. #define False   0
  28. #define True    !False
  29. #define MIN(a, b) (a < b ? a : b)
  30. #define MAX(a, b) (a > b ? a : b)
  31.  
  32. #ifndef LEAFNAME_MAX
  33. #  define LEAFNAME_MAX  FILENAME_MAX
  34. #endif
  35.  
  36.  
  37.  
  38. /********************************************************************************/
  39. /*                                                                              */
  40. /* Function    : usage                                                          */
  41. /* Description : Displays program usage to standard error, and exits.           */
  42. /* Arguments   : progname - pointer to character string containing the program  */
  43. /*                          name.                                               */
  44. /* Returns     : None.                                                          */
  45. /*                                                                              */
  46. /********************************************************************************/
  47.  
  48.  
  49. void usage (char *progname)
  50. {
  51.   fprintf (stderr, "File splitter. Version 1.13 - 4th Feburary 1995 by A.Hamilton\n\n");
  52.   fprintf (stderr, "Usage : %s [options] <filename>\n\n", progname);
  53.   fprintf (stderr, "Options (can be abbreviated) :\n");
  54.   fprintf (stderr, "    -filesize     [filesize in K]          default = 1423\n");
  55. #ifndef PC
  56.   fprintf (stderr, "    -buffersize   [buffersize in K]        default = 32\n");
  57. #endif
  58.   fprintf (stderr, "    -path         [new path]\n");
  59.   fprintf (stderr, "    -interactive\n");
  60.  
  61.   exit (EXIT_FAILURE);
  62. }
  63.  
  64.  
  65.  
  66. /********************************************************************************/
  67. /*                                                                              */
  68. /* Function    : examine_filename                                               */
  69. /* Description : Splits filename into component parts.                           */
  70. /* Arguments   : original_name - character array, filename to be examined.      */
  71. /*               name          - pointer to a character array in which to store */
  72. /*                               file leafname (excluding extention).           */
  73. /*               ext           - pointer to a character array in which to store */
  74. /*                               the source files extention (if any).           */
  75. /* Returns     : If the source file has an extention, then return ".spt",       */
  76. /*               otherwise return "".                                           */
  77. /*                                                                              */
  78. /********************************************************************************/
  79.  
  80.  
  81. char *examine_filename (char original_name[], char *name, char *ext)
  82. {
  83.   char main_name[256];                  /* Temporary store for leafname.        */
  84.   char *original;                       /* Pointer to start of leafname.        */
  85.   char *pointer;                        /* Pointer to any ':' characters found. */
  86.   register int i = -1, n;               /* Pointer & counter.                   */
  87.  
  88.  
  89.   if (COLON)                                                    /* If our system uses ':' in    */
  90.     pointer = strrchr (original_name, ':');                     /* the file path, then remember */
  91.   else                                                          /* where it is.                 */
  92.     pointer = NULL;
  93.  
  94.   original = strrchr (original_name, SEPARATOR_SEARCH);         /* Find the address where the   */
  95.   if ((original = MAX (original, pointer)) == NULL)             /* leafname starts.             */
  96.     original = original_name;
  97.   else {
  98.     original++;
  99.   }
  100.  
  101.   do {
  102.     i++;
  103.     main_name[i] = original[i];                                 /* Get files leafname           */
  104.   } while (main_name[i] != '.' && main_name[i] != '\0');        /* (excluding any extention).   */
  105.  
  106.   for (n = 0; (ext[n] = original[i]) != '\0'; n++, i++) ;       /* Now copy any extention.      */
  107.  
  108.   if (main_name[i - n] == '\0') {                               /* If the file doesn't have an  */
  109.     strcpy (name, main_name);                                   /* extention, copy the leafname */
  110.     return ("");                                                /* and return an empty string.  */
  111.   }
  112.   main_name[i - n] = '\0';                                      /* Otherwise, terminate the     */
  113.   strcpy (name, main_name);                                     /* leafname, copy it, and       */
  114.   return (".spt");                                              /* the output extention to use. */
  115. }
  116.  
  117.  
  118.  
  119. /********************************************************************************/
  120. /*                                                                              */
  121. /* Function    : numtostr                                                       */
  122. /* Description : Converts a number into a 2 didget character string.            */
  123. /* Arguments   : number - number to be converted.                               */
  124. /*               name   - pointer to a character array to store the number.     */
  125. /* Returns     : None.                                                          */
  126. /*                                                                              */
  127. /********************************************************************************/
  128.  
  129.  
  130. void numtostr (short number, char *name)
  131. {
  132.   name[0] = (short) (number / 10) + '0';
  133.   name[1] = (number % 10) + '0';
  134.   name[2] = '\0';
  135. }
  136.  
  137.  
  138.  
  139. /********************************************************************************/
  140. /*                                                                              */
  141. /* Function    : main                                                           */
  142. /* Description : Main control function.                                         */
  143. /* Arguments   : Command line parameters.                                       */
  144. /* Returns     : Exit status.                                                   */
  145. /*                                                                              */
  146. /********************************************************************************/
  147.  
  148.  
  149. int main (int argc, char **argv)
  150. {
  151.   char  source_filename[256];           /* Source filename.                     */
  152.   char  out_filename[256];              /* Output leafname.                     */
  153.   char  out_path[256];                  /* Output path.                         */
  154.   char  file_ext[32];                   /* Output extention.                    */
  155.   char  out_name[256];                  /* Full output filename.                */
  156.   char  header[50];                     /* Output file header.                  */
  157.   char  fnum[3];                        /* Output part number.                  */
  158.   char  *progname;                      /* Program name.                        */
  159.   char  string[256];                    /* Input string.                        */
  160.   char  type[5];                        /* Filetype (Acorn systems only).       */
  161.   char  interactive = 0;                /* Interactive status flag.             */
  162.   char  orig_ext[20];                   /* Original filename extention.         */
  163.  
  164.   short file_number = 0;                /* Current part number.                 */
  165.   long  disk_size = 1423 * 1024;        /* Output part size (default 1423K).    */
  166.   long  read_size = 32 * 1024;          /* B