home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / mast2pcb.zip / MAST2PCB.C next >
Text File  |  1990-05-04  |  2KB  |  90 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. /* strip spaces off the end of the string */
  6. void pascal stripspaces(char *Str) {
  7.   char *p;
  8.  
  9.   for (p = &Str[strlen(Str)-1]; *p == ' ' && p >= Str; p--);
  10.   p++;
  11.   *p = 0;
  12. }
  13.  
  14. /* convert "ABC      ZIP" to "ABC.ZIP     " */
  15. void pascal convertfilename(char *Str) {
  16.   char *p;
  17.  
  18.   if ((p = strchr(Str,' ')) != NULL) {
  19.     if (p != &Str[9]) {
  20.       *p++ = '.';
  21.       *p++ = Str[9];
  22.       *p++ = Str[10];
  23.       *p++ = Str[11];
  24.       for (; p < &Str[12]; p++)
  25.         *p = ' ';
  26.     }
  27.   }
  28. }
  29.  
  30. /* convert filename, strip spaces off the end then shift the file size, date */
  31. /* and description to the right by one space and add the CR/LF back on       */
  32. void pascal convert(char *Str) {
  33.   convertfilename(Str);
  34.   Str[77] = 0;
  35.   stripspaces(Str);
  36.  
  37.   /* if the last digit of the SIZE is a space - then we need to shift it all */
  38.   /* to the right by one character because everything has been shifted left  */
  39.  
  40.   if (Str[20] == ' ') {
  41.     memmove(&Str[15],&Str[14],strlen(Str)+1);
  42.     Str[14] = ' ';
  43.   }
  44.  
  45.   /* if the first digit of the DATE is a space then change it to a zero */
  46.  
  47.   if (Str[23] == ' ' && Str[25] == '-')
  48.     Str[23] = '0';
  49.  
  50.   /* if we've accidently stripped off the NEWLINE character then put it back */
  51.  
  52.   if (strchr(Str,'\n') == NULL)
  53.     strcat(Str,"\n");
  54. }
  55.  
  56.  
  57. void main(int argc, char **argv) {
  58.   char Str[100];
  59.   FILE *In;
  60.   FILE *Out;
  61.  
  62.   if (argc < 3) {
  63.     puts("Run the program by typing the following:\n"
  64.          "\n"
  65.          "   MAST2PCB <infile> <outfile>\n"
  66.          "\n"
  67.          "where <infile> is the full name of the text file to be converted to PCBoard\n"
  68.          "format and <outfile> is the name of the PCBoard DIR file to be created.");
  69.     return;
  70.   }
  71.  
  72.   if ((In = fopen(argv[1],"rt")) == NULL) {
  73.     puts("Unable to open source file");
  74.     return;
  75.   }
  76.  
  77.   if ((Out = fopen(argv[2],"wt")) == NULL) {
  78.     puts("Unable to open destination file");
  79.     return;
  80.   }
  81.  
  82.   while (fgets(Str,sizeof(Str),In) != NULL) {
  83.     convert(Str);
  84.     fputs(Str,Out);
  85.   }
  86.  
  87.   fclose(Out);
  88.   fclose(In);
  89. }
  90.