home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD1.img / d1xx / d162 / cli_utilities / pwfix / pwfix.c < prev    next >
C/C++ Source or Header  |  1988-10-02  |  5KB  |  158 lines

  1. /*  PWfix.c  Version 1.0
  2.     22 May 1988
  3.     Compiles clean under Manx 3.4a
  4.  
  5.     Copyright (c) 1988 by Dan Fish
  6.     All rights reserved.
  7.  
  8.     Permission is granted to redistribute this program in a non-profit
  9.     manner provided the source code is included in the distribution and 
  10.     this copyright notice is unchanged.
  11.  
  12.     Power Windows V1.3, wonderful program that it is, makes several 
  13.     incorrect type declarations within the structures it writes for
  14.     compilation under Manx.
  15.     
  16.           BorderVectors is defined as USHORT and should be SHORT
  17.           
  18.           By default, the text pointer in an IntuiText structure
  19.           is defined as BYTE * and should be UBYTE *
  20.  
  21.           The same is also true of the text pointer to the window 
  22.           name in a NewWindow structure.
  23.  
  24.     So far these are the only noted problems, though there may be more.
  25.     (I haven't generated anything extremely complicated with Power 
  26.     Windows yet.)  Left untreated, these incorrect declarations, cause 
  27.     great aggravation in the form of a humongous compiler warning list.
  28.  
  29.     Crude, but effective, this program reads the source code file
  30.     generated by Power Windows; through "casting" corrects the 
  31.     troublesome buggers and writes out a corrected file with a .pwfix
  32.     suffix in the same directory.
  33.    
  34.     If you plan on modifying the Power Windows source code (putting 
  35.     things on the same line, etc.), I suggest you do so after running
  36.     PWfix on it, as its relies heavily on the line structure of the 
  37.     code to accomplish its goals.
  38.  
  39.     If you find other problems or modify this code substantially, please
  40.     drop a hardcopy of your new source code listing in the mail to:
  41.  
  42.                                          Dan Fish
  43.                                          7293 W. Desert Cove #95
  44.                                          Peoria, Az.
  45.                                                       85345
  46.    "C"-ya! */
  47.  
  48.  
  49.     
  50.  
  51.  
  52.  
  53.  
  54. #include <stdio.h>
  55. #include <exec/types.h>
  56.  
  57. #define MAXLIN 100
  58. #define TAB 9
  59.  
  60. main(argc,argv)
  61. int argc;
  62. char *argv[];
  63.  
  64. {
  65.  
  66.  
  67.  
  68.  FILE *infile, *outfile;
  69.  static char fname[30];  /* copy of the input filename       */
  70.  char string[MAXLIN];    /* maximum characters per line      */
  71.  char *adr;              /* variable pointer to above string */
  72.  
  73.  int i=0, j=0, k=0;      /* event counters  */
  74.  int line=0;             /* line counter    */
  75.  int ch;
  76.  
  77.  
  78. /* Initialize these next variables to some ridiculous value so lines
  79.    preceeding the first Itext and NewWindow structures won't be affected  */
  80.  
  81.  int Itxt=99999, NewWind=99999;
  82.  
  83.  
  84.  if (argc<2)
  85.     {
  86.       printf("\n");
  87.       printf("      Usage: PWFix <Power Windows filename>\n\n");
  88.       exit();
  89.     }
  90.  
  91.  
  92.  if((infile = fopen(argv[1],"r")) != NULL)
  93.     {
  94.      strcpy(fname,argv[1]);
  95.      strcat(fname,".pwfix");
  96.      outfile = fopen(fname,"w");
  97.  
  98.      while (fgets(string,MAXLIN,infile)!=NULL)  /* until EOF */
  99.         
  100.       {
  101.         line++;  /* Let's see now... what line are we on?  */
  102.  
  103.         if ( strncmp(string,"USHORT BorderVectors",20) == 0)
  104.            {
  105.              i++;                /* running tab on # of occurences */
  106.              adr = string;
  107.              adr++;              /* Get rid of the "U" */
  108.              fputs(adr,outfile);
  109.            }
  110.  
  111.         else if (strncmp(string,"struct IntuiText IText",22)==0)
  112.            {
  113.              j++;                   /* another running tab  */
  114.              Itxt = line;           /* remember the line    */   
  115.              fputs(string,outfile);
  116.            }
  117.         else if (strncmp(string,"struct NewWindow",16)==0)
  118.            {
  119.              k++;                   /* yet another running tab       */
  120.              NewWind = line;        /* don't forget this line either */
  121.              fputs(string,outfile);
  122.            }               
  123.  
  124.         else if ((line == Itxt + 4)||(line == NewWind + 8)) 
  125.            {
  126.              adr = string;
  127.              adr ++;                     /*  Get rid of the old Tab  */
  128.              putc(TAB,outfile);             /*  Write a new tab         */
  129.              fputs("(UBYTE *)",outfile); /*  Add the "cast"          */
  130.              fputs(adr,outfile);         /*  and tack on the string  */
  131.            }
  132.  
  133.         else                              /*  Don't change anything,  */
  134.              fputs(string,outfile);       /*  just pass on the line   */
  135.                                       /*  to the output file      */
  136.     }
  137.      printf("\n");
  138.      printf("Corrected: %3d BorderVector(s)\n", i);            /* Output */
  139.      printf("           %3d Intuitext structure(s)\n", j);     /*  the   */
  140.      printf("           %3d NewWindow structure(s)\n\n", k);   /*  tally */
  141.  
  142.      fclose(infile);
  143.      fclose(outfile);
  144.      exit();
  145.  
  146.  }
  147.  
  148. printf("\n");
  149. printf(" Ack ! -- Can't open \"%s\" for input!\n\n", argv[1]);
  150.  
  151.  
  152. }
  153.  
  154.  
  155. /* end of manual input source generation!!! */
  156.  
  157.  
  158.