home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / UTILITY / WW4PAL.ZIP / WW4PAL.C next >
C/C++ Source or Header  |  1996-06-24  |  4KB  |  145 lines

  1. /*
  2. WW4PAL.C
  3. A WWIV Palette Changer by Xanth, IceNET #1 @9404, Internet aev@cis.ufl.edu
  4. Last updated on June 23, 1996.
  5.  
  6. This program is designed to be run as a WWIV chain.  It will redefine
  7. everyone's colors to match the user who runs it.  This is useful
  8. for boards that have a paint coordinator, that is, someone in charge
  9. with periodically changing the colors to make things interesting.
  10.  
  11. This source code is freeware and may be freely used, modified, and
  12. distributed without credit to the author.  It has been compiled successfully
  13. under Borland's Turbo C++ v3.0 for DOS.
  14.  
  15. A typical CHAINEDIT configuration might look like:
  16.  
  17. A. Description  : WWIV Palette Changer
  18. B. Filename     : WW4PAL.EXE %1 putpasswordhere
  19. C. SL           : 10
  20. D. AR           : None.
  21. E. ANSI         : Optional
  22. F. DOS Interrupt: Used      !!! THIS OPTION MUST BE SET TO "USED" !!!
  23. G. 300 Baud     : Allowed
  24. H. Shrink       : Yes
  25. I. Disable pause: Yes
  26. J. Local only   : No
  27. K. Multi user   : No
  28. L. Registered by: MAHARET
  29. M. Usage        : 21
  30. N. Age limit    : 0 - 255
  31. R. RIP mode     : Optional
  32.  
  33. */
  34.  
  35. #include <stdio.h>
  36. #include <dir.h>
  37. #include "vardec.h"
  38.  
  39. int yesno (void);
  40.  
  41. /***************************************************************************/
  42.  
  43. void main (int argc, char *argv[])
  44. {
  45.     char *initial  = "▒▒▒▒▒▒▒▒▒▒\r";
  46.     char *progress = "██████████";
  47.     char temp[80];
  48.     char userdata[MAXPATH];
  49.     FILE *fp;
  50.     int  usernum,
  51.          numusers,
  52.          i,
  53.          j;
  54.     float sofar;
  55.     userrec master,
  56.             tmpusr;
  57.  
  58.     puts ("\n\nWWIV Palette Changer");
  59.     puts ("A little program by Xanth, 1@9404.IceNET\n");
  60.     if (argc < 3)
  61.     {
  62.         puts ("## USAGE: ww4pal <chain.txt> <password>");
  63.         puts ("   Giving up...");
  64.         exit (1);
  65.     }
  66.  
  67.     printf ("Do you wish to change everyone's colors to match yours? ");
  68.  
  69.     if (!yesno())
  70.     {
  71.         puts ("\nVery well.  Now exiting...\n");
  72.         exit (0);
  73.     }
  74.  
  75.     printf ("\nPlease enter the Paint Coordinator Password: ");
  76.     gets (temp);
  77.     if (stricmp (temp, argv[2]) != 0)
  78.     {
  79.         puts ("\nYou did not enter the correct password.  Butthead.");
  80.         puts ("Now exiting...\n");
  81.         exit (0);
  82.     }
  83.  
  84.     fp = fopen (argv[1], "rt");
  85.     fgets (temp, sizeof (temp), fp); // grab the user number off the 1st line
  86.     usernum = atoi (temp);           // and convert from string to integer
  87.     for (i = 1; i < 17; i++)         // move to the end of line #17
  88.         fgets (temp, sizeof (temp), fp);
  89.  
  90.     fgets (userdata, sizeof (userdata), fp);  // grab datadir off line #18
  91.     userdata[strlen (userdata) - 1] = '\0';  // strip trailing \n
  92.     fclose (fp);
  93.  
  94.     strcat (userdata, "USER.LST");
  95.     fp = fopen (userdata, "r+b");
  96.     fseek (fp, 0L, SEEK_END);
  97.     numusers = ftell (fp) / sizeof (userrec);
  98.     numusers--;  // on account of the unused zeroth record
  99.     rewind (fp);
  100.     fseek (fp, usernum * sizeof (userrec), SEEK_SET);
  101.     fread (&master, sizeof (userrec), 1, fp);
  102.     puts ("");
  103.     printf (initial);
  104.     for (i = 1; i < numusers; i++)
  105.     {
  106.         sofar = (float) i / (float) numusers;
  107.         sofar *= strlen (progress);
  108.         printf ("%.*s\r", (int) sofar+1, progress);
  109.         fseek (fp, i * sizeof (userrec), SEEK_SET);
  110.         fread (&tmpusr, sizeof (userrec), 1, fp);
  111.         for (j = 0; j < 10; j++)
  112.         {
  113.             tmpusr.colors[j] = master.colors[j];
  114.             tmpusr.bwcolors[j] = master.bwcolors[j];
  115.         }
  116.         fseek (fp, i * sizeof (userrec), SEEK_SET);
  117.         fwrite (&tmpusr, sizeof (userrec), 1, fp);
  118.     }
  119.     fclose (fp);
  120.     puts ("\nDone!");
  121. }
  122.  
  123. /***************************************************************************/
  124.  
  125. int yesno (void)
  126. {
  127.     int inchar;
  128.  
  129.     repeat:
  130.     inchar = toupper (getch());
  131.  
  132.     if ( (inchar == 'Y') || (inchar == '\r') )
  133.     {
  134.         printf ("Yes\n");
  135.         return 1;
  136.     } else if (inchar == 'N')
  137.     {
  138.         printf ("No\n");
  139.         return 0;
  140.     } else goto repeat;  // My regards to Edsgar Dijkstra
  141. }
  142.  
  143. /***EOF*********************************************************************/
  144.  
  145.