home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / editor / tvx_edit.arc / TVX_PTCH.C < prev    next >
C/C++ Source or Header  |  1986-03-17  |  8KB  |  370 lines

  1. /* -------------------------- tvx_ptch.c --------------------------- */
  2. #include "tvx_defs.ic"
  3.  
  4. #define EXTERN
  5. #include "tvx_glbl.ic"
  6.  
  7. /*=======================================================================
  8.  
  9.     tvpatch - program to patch tvx with config.tvx file
  10.  
  11.     first version 6/19/84
  12.     7/25/84 - fixed to correspond to tvx version, add extra command
  13.     2/14/85 - version to correspond with rest
  14.     5/15/85 - again, batched to correspond
  15.     9/20/85 - fixed for new version of tvx, unix added
  16.  
  17. ======================================================================= */
  18.  
  19. #ifndef UNIX
  20.     char filein[] = "A:TVX.EXE";
  21.     char fileout[]= "A:TEMP1.$$$";
  22. #else
  23.     char filein[80] = "tvx";
  24.     char fileout[80]= "tvx_temp";
  25. #endif
  26.     char config[80];
  27.  
  28.  
  29. /*  define our general control item structure for general patching */
  30.  
  31. #define BL remark("")
  32. #define RMK remark
  33. #define PR prompt
  34.  
  35.     char clower(), cupper();
  36.     extern char *malloc();
  37.     extern FILE *fopen();
  38.     FILE *tvxin, *cfgin, *tvxout;
  39.  
  40. /* =============================>>> MAIN   <<<============================= */
  41.   main()
  42.   {
  43.  
  44.     char ans[80];
  45.  
  46. TOP:
  47.     cls();
  48.     RMK("TVX_PTCH - Version 11/12/85");
  49.     BL;
  50. RMK("  This program is used to permanently alter TVX to match the options");
  51. RMK("selected with the TVX_CNFG program.  It will read in the configuration");
  52. RMK("file you specify (such as CONFIG.TVX), and patch TVX to reflect those");
  53. RMK("values.  Then you won't need to use the '-c' switch when using TVX.");
  54.     BL;
  55. RMK("*** You may press CONTROL-C at any time to cancel this installation. ***");
  56.  
  57.     do 
  58.       {
  59.     BL;
  60. #ifndef UNIX
  61.     PR("On which drive is TVX.EXE located? (A, B, ...): ");
  62.     ureply(ans,10);
  63.     filein[0] = ans[0];
  64. #endif
  65.     if ( !(tvxin = fopen(filein,FILEREAD)))
  66.       {
  67.         PR("TVX not found on specified drive, try again: ");
  68.         RMK(filein);
  69. #ifdef UNIX
  70.         PR("Please enter name of tvx executable file: ");
  71.         reply(filein,79);
  72. #endif
  73.         continue;
  74.       }
  75.     fclose(tvxin);
  76.     break;
  77.       }
  78.     while (1);
  79.  
  80. #ifndef UNIX
  81.     fileout[0] = cupper(ans[0]);
  82. #endif
  83.  
  84.     do 
  85.       {
  86.     BL;
  87.     PR("Enter the name of the configuration file to use: ");
  88.     reply(config,79);
  89.     if ( !(cfgin = fopen(config,FILEREAD)))
  90.       {
  91.         RMK("Configuration not found on specified drive, try again.");
  92.         continue;
  93.       }
  94.  
  95.     rdcfg(lexsym,LEXVALUES+1);
  96.     rdcfg(synofr,20);
  97.     rdcfg(synoto,20);
  98.     rdcfg(funchar,50);
  99.     rdcfg(funcmd,50);
  100.     rdcfg(&funkey,1);
  101.     rdcfg(&autoin,1);
  102.     rdcfg(&ddline,1);
  103.     rdcfg(&dscrl,1);
  104.     rdcfg(&dxcase,1);
  105.     rdcfg(&wraplm,1);
  106.     rdcfg(&use_wild,1);
  107.     rdcfg(&usebak,1);
  108.     logdef = usebak;
  109.     rdcfg(&cut_mode,1);
  110. #ifdef MSDOS
  111.     rdcfg(&usecz,1);
  112. #endif
  113.     fclose(cfgin);
  114.     break;
  115.       }
  116.     while (1);
  117.  
  118.     BL;
  119.     RMK("TVX is being modified to match your choices.");
  120.     RMK("This may take several minutes.");
  121.     BL;
  122.  
  123.     fpatch(filein);    /* patch tvx */
  124.  
  125.     cls();
  126.     RMK("Modification completed.  TVX is ready to use without the -c now.");
  127.     BL;
  128.   }
  129.  
  130. /* =============================>>> RDCFG <<<============================= */
  131.   rdcfg(toset,cnt)
  132.   char *toset;
  133.   int cnt;
  134.     {    /* read cnt vals from cfgin */
  135.  
  136.     FAST int i,val;
  137.  
  138.     for (i = 0 ; i < cnt ; ++i)
  139.       {
  140.     if ((val = fgetc(cfgin)) == EOF)
  141.      {
  142.         remark("Invalid configuration file, aborting");
  143.         fclose(cfgin);
  144.         exit(999);
  145.      }
  146.     *toset++ = val;    /* replace with new commands */
  147.       }
  148.   }
  149.  
  150. /* =============================>>> FPATCH <<<============================= */
  151.   fpatch(fn)
  152.   char *fn;
  153.   {
  154.     static int byt;
  155.     static int i;
  156.     static int didpatch;
  157.     static char *begptr;    /* patch area pointers */
  158.  
  159.     prompt("Patching "); remark(filein);
  160.  
  161. #ifndef UNIX
  162.     fn[0] = fileout[0];        /* set drive */
  163. #endif
  164.     didpatch = FALSE;
  165.     if (!(tvxin = fopen(fn,FILEREAD)))
  166.       {
  167.     PR("Unable to find file to patch: "); PR(fn);
  168.         RMK(".  Aborting to operating system.");
  169.     exit(999);
  170.       }
  171.     if (!(tvxout = fopen(fileout,FILEWRITE)))
  172.       {
  173.     PR("Unable to create new file, aborting: ");
  174.     RMK(fileout);
  175.     exit(999);
  176.       }
  177.  
  178.     while ((byt = fgetc(tvxin)) != EOF)
  179.       {
  180.     fputc(byt,tvxout);
  181.     if (byt == '#')            /* look for first sharp */
  182.       {
  183.         for (i = 1 ; i <= 4 ; ++i)
  184.           {
  185.         if ((byt = fgetc(tvxin)) == EOF)
  186.             goto l900;
  187.         fputc(byt,tvxout);    /* echo */
  188.         if (byt != '#')
  189.             goto l800;
  190.           }
  191.         byt = fgetc(tvxin);        /* should be : next */
  192.         fputc(byt,tvxout);
  193.         if (byt != ':')
  194.         goto l800;
  195.  
  196. /*   fall thru means found patch area -- code to patch follows */
  197.  
  198.         for (begptr = (char *) &addx ; begptr < (char *) &endpatch ;
  199.           ++begptr)
  200.           {
  201.         if ((byt = fgetc(tvxin)) == EOF) /* read byte from file */
  202.             goto l900;
  203.         fputc(*begptr,tvxout); /* replace with byte from my area */
  204.           }
  205.         didpatch = TRUE;
  206.       }
  207. l800:    byt = byt;        /* compiler bug */
  208.       }
  209.  
  210.  
  211. l900:
  212.     fclose(tvxin);
  213.     fclose(tvxout);
  214.     if (!didpatch)
  215.       {
  216.     RMK("*********  ERROR ********");
  217.     RMK("The file just checked was not a proper version of the program!");
  218.     RMK("Please check that your are using a valid copy of the");
  219.     RMK("program file supplied with this initialization program!");
  220.     RMK("Unable to make patch, aborting");
  221.     exit(999);
  222.       }
  223.     unlink(fn);
  224.     fn[0] = fileout[0];        /* fix the drive */
  225.     if (rename(fileout,fn) != 0)
  226.       {
  227.     RMK("Unable to rename temporary patch file");
  228.     exit(999);
  229.       }
  230.   }
  231.  
  232. /* =============================>>> OK <<<============================= */
  233.   ok(msg)
  234.   char *msg;
  235.   {
  236.     char rp[11];
  237.     PR(msg); PR(" (y/n) ");
  238.     lreply(rp,10);
  239.     return (rp[0] == 'y');
  240.   }
  241.  
  242. /* ============================>>> RVALID <<<=========================== */
  243.   rvalid(chr,okstr)
  244.   char chr,*okstr;
  245.   {
  246.     /* sees if chr is in okstr */
  247.    
  248.     SLOW int i;
  249.     SLOW char ch;
  250.  
  251.     ch = clower(chr);
  252.     while (*okstr)
  253.       {
  254.     if (ch == clower(*okstr++))
  255.         return TRUE;
  256.       }
  257.     return FALSE;
  258.   }
  259.   
  260. /* =============================>>> CLS  <<<============================= */
  261.   cls()
  262.   {
  263.     int i;
  264.  
  265.     for (i = 0  ; i < 25 ; ++i)
  266.     BL;
  267.   }
  268.  
  269. #define EXTENDED    /* my own extended lib functions */
  270. /* #define STANDARD    /* the set of standard functions i use */
  271. #define LOCAL static    /* make all local globals, i think */
  272.  
  273.  
  274. #ifdef EXTENDED
  275. /*=============================>>> CLOWER  <<<================================*/
  276.   char clower(ch)
  277.   char ch;
  278.   {
  279.     return ((ch >='A' && ch<='Z') ? ch + ' ' : ch);
  280.   }
  281.  
  282. /*=============================>>> CUPPER  <<<================================*/
  283.   char cupper(ch)
  284.   char ch;
  285.   {
  286.     return ((ch >= 'a' && ch <= 'z') ? ch - ' ' : ch);
  287.   }
  288.  
  289. /* =========================>>> LOWER  <<<==============================*/
  290.   lower(str)
  291.   char str[];
  292.   {
  293.     FAST int i;
  294.  
  295.     for (i=0 ; str[i] ; ++i)
  296.     str[i]=clower(str[i]);
  297.  
  298.   }
  299.  
  300. /*=============================>>> PROMPT <<<================================*/
  301.   prompt(msg)
  302.   char msg[];
  303.   {
  304.     printf("%s",msg);
  305.   }
  306.  
  307.  
  308. /*=============================>>> REMARK <<<================================*/
  309.   remark(msg)
  310.   char msg[];
  311.   {
  312.     printf("%s\n",msg);
  313.   }
  314.  
  315. /*=============================>>> UPPER  <<<================================*/
  316.   upper(str)
  317.   char str[];
  318.   {
  319.     static int i;
  320.  
  321.     for (i=0 ; str[i] ; ++i)
  322.     str[i]=cupper(str[i]);
  323.   }
  324.  
  325.  
  326. /*=============================>>> LREPLY <<<================================*/
  327.   lreply(msg,maxc)
  328.   char msg[];
  329.   int maxc;
  330.   {
  331.     reply(msg,maxc);
  332.     lower(msg);
  333.   }
  334.  
  335. /*=============================>>> UREPLY <<<================================*/
  336.   ureply(msg,maxc)
  337.   char msg[];
  338.   int maxc;
  339.   {
  340.     reply(msg,maxc);
  341.     upper(msg);
  342.   }
  343.  
  344. /*=============================>>> REPLY <<<================================*/
  345.   reply(msg,maxc)
  346.   char msg[];
  347.   int maxc;
  348.   {
  349. #ifdef UNIX
  350.     gets(msg);
  351. #endif
  352. #ifdef MSDOS
  353.     gets(msg,maxc,stdin);
  354. #endif
  355. #ifdef GEMDOS
  356.     gemdos(0x0a,msg);
  357. #endif
  358.   }
  359.  
  360. /*=============================>>> RDINT <<<================================*/
  361.   rdint(val)
  362.   int *val;
  363.   {
  364.     char chrrep[12];
  365.     reply(chrrep,11);
  366.     *val = atoi(chrrep);
  367.   }
  368. #endif
  369. /* -------------------------- tvx_ptch.c --------------------------- */
  370.