home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / cpm / alphatronic / MIXED110.ZIP / CFGDATE.C < prev    next >
Text File  |  1997-11-10  |  4KB  |  129 lines

  1. #define TITLE "Cfgdate         Version 0.0       6-28-84"
  2. #define NOTICE "Copyright (c) 1984 Kenmore Computer Technologies"
  3. /*
  4.     Program Name: cfgdate
  5.     Purpose: To configure the executable code for 'date' and 'setdate'
  6.     to differant port base addresses without recompiling or relinking
  7.     the code.
  8.  
  9.     Written by:
  10.         Alan D. Percy
  11.         Kenmore Computer Technologies
  12.         PO Box 635
  13.         Kenmore, NY   14217
  14.     
  15.     This program or program section can not 
  16.     be resold, given away or copied (other than
  17.     normal use and backup copies) without
  18.     written permission of the above copyright
  19.     holder.
  20. */
  21.  
  22. #include <0/bdscio.h>
  23.  
  24. #define SSTRING "Cbase: 0x"
  25. #define TFNAME "CFGDATE.TMP"
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char *argv[];
  30. /*
  31.     For each filename in the argument list,
  32.     perform search and configure.
  33. */
  34. {
  35.     char base[10];       /* space for hex base */
  36.  
  37.     printf("%s\n%s\n\n",TITLE,NOTICE);
  38.  
  39.     puts("Enter TWO digit HEX port address for object files: ");
  40.     scanf("%s",base);
  41.  
  42.     if(strlen(base) != 2) {      /* if user didn't type two characters */
  43.         puts("Cfgdate: A TWO digit address is required\n");
  44.         exit(-1);                /* stop */
  45.     }
  46.  
  47.     argc--;             /* skip program name */
  48.     argv++;
  49.  
  50.     while (argc--) 
  51.         cfgdate(*argv++,base);/* pass pointer to filename and port address */
  52.  
  53. }
  54.  
  55. cfgdate(fname,base)
  56. char *fname,*base;
  57. /*
  58.     Open the file 'fname' and search it for the string
  59.     SSTRING, replacing the next two characters in the file
  60.     from the characters in 'base'.
  61. */
  62. {
  63.     char infile[BUFSIZ];              /* input file */
  64.     char outfile[BUFSIZ];             /* output file */
  65.     char ch,hold[11];                 /* space to keep search string in */
  66.     int i;                            /* offset into hold string */
  67.     int instat;                       /* input file status */
  68.     int slen;                         /* string length variable */
  69.  
  70.     strcpy(hold,SSTRING);             /* stick search string in array */
  71.     slen=strlen(hold);                /* number of chars in search string */
  72.     i=0;                              /* index into search string */
  73.  
  74.     printf("Processing file: %s\n",fname);
  75.  
  76.     if(fopen(fname,infile) == -1) {
  77.         printf("Cfgdate: infile open error: %s\n",errmsg(errno()));
  78.         return(0);
  79.     }
  80.  
  81.     if(fcreat(TFNAME,outfile) == -1) {
  82.         printf("Cfgdate: outfile open error: %s\n",errmsg(errno()));
  83.         return(0);
  84.     }
  85.  
  86.     do {
  87.         ch = instat = getc(infile);       /* get next character */
  88.  
  89.         if(i < slen) {                    /* if still searching */
  90.             if(hold[i]==ch)               /* if next character matches */
  91.                 i++;                      /* move to next */
  92.             else
  93.                 i=0;                      /* otherwise start over */
  94.         }
  95.         else                              /* match found */
  96.             if(i-slen == 0) {             /* first character of replacement */
  97.                 ch = base[i - slen];
  98.                 i++;
  99.             }
  100.             else {                        /* second character of repl. */
  101.                 ch = base[i - slen];
  102.                 i = 0;                    /* repl all done, so start over */
  103.             }
  104.  
  105.         if(putc(ch,outfile) == -1) {      /* output character */
  106.             printf("Cfgdate: outfile write error: %s\n",errmsg(errno()));
  107.             fclose(infile);
  108.             fclose(outfile);
  109.             return(0);
  110.         }
  111.     }
  112.     while(instat != -1);
  113.  
  114.     if(errno() != 1) {
  115.          printf("Cfgdate: infile read error: %s\n",errmsg(errno()));
  116.          fclose(infile);
  117.          fclose(outfile);
  118.          return(0);
  119.     }
  120.  
  121.     fclose(infile);        /* close files */
  122.     fclose(outfile);
  123.  
  124.     /* delete original and rename temporary */
  125.     unlink(fname);
  126.     rename(TFNAME,fname);
  127. }
  128.  
  129.