home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / util / mbq314 / qver.c next >
Encoding:
C/C++ Source or Header  |  1996-07-27  |  2.7 KB  |  114 lines

  1. /* QVER BSP Version Converter 1.0 by Tom Grandgent (Woofer)  7/27/96
  2.  *
  3.  * This should be completely portable C.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10.  
  11. int main(int argc, char **argv) {
  12.  
  13.     FILE *fp;
  14.     int i, extension, ver = 29;
  15.     char fname[80], vername[80];
  16.  
  17.     printf("QVER BSP Version Converter 1.0 by Tom Grandgent (Woofer)  7/27/96\n\n");
  18.  
  19. /* Check arguments. */
  20.     if (argc < 2) {
  21.         printf("Syntax: QVER blah[.bsp] [version]\n\n");
  22.         printf("Possible values for version:\n\n");
  23.         printf("  shareware\n");
  24.         printf("  sw\n");
  25.         printf("  registered\n");
  26.         printf("  reg\n");
  27.         printf("  [any valid version number from 1 to 255]\n\n");
  28.         printf("Version 28 is shareware, 29 is registered.\n\n");
  29.         printf("If the version number is omitted, the version of the BSP will be displayed.\n");
  30.         return 1;
  31.     }
  32.  
  33.     if (argc > 2) {
  34.  
  35.         ver = atoi(argv[2]);
  36.         strcpy(vername, argv[2]);
  37.  
  38.         if (!stricmp(vername, "shareware"))
  39.             ver = 28;
  40.         else
  41.             if (!stricmp(vername, "sw"))
  42.                 ver = 28;
  43.             else
  44.                 if (!stricmp(vername, "registered"))
  45.                     ver = 29;
  46.                 else
  47.                     if (!stricmp(vername, "reg"))
  48.                         ver = 29;
  49.                         else
  50.                             if (!stricmp(vername, "regged"))
  51.                                 ver = 29;
  52.  
  53.         if (ver < 1 || ver > 255) {
  54.             printf("ERROR: Valid version numbers range from 1 to 255.\n");
  55.             printf("(If you typed a word for the version, I didn't know what it meant.)\n");
  56.             return 1;
  57.         }
  58.     }
  59.  
  60.     strcpy(fname, argv[1]);
  61.  
  62. /* Check for an extension.  Add .BSP if it's not already there. */
  63.     extension = 0;
  64.     for (i = 0; i < strlen(fname); i++) {
  65.         if (fname[i] == '.')
  66.             extension = 1;
  67.     }
  68.     if (!extension)
  69.         strcat(fname, ".BSP");
  70.  
  71. /* Try to open the BSP file. */
  72.     if (!(fp = fopen(fname, "rb+"))) {
  73.         printf("ERROR: Couldn't open %s for reading.\n", fname);
  74.         return 1;
  75.     }
  76.  
  77. /* Display the file name (in caps). */
  78.     for (i = 0; i < strlen(fname); i++)
  79.         fname[i] = toupper(fname[i]);
  80.     printf("BSP %s:\n\n", fname);
  81.  
  82. /* See what the version number of the BSP was. */
  83.     i = fgetc(fp);
  84.  
  85.     if (argc > 2)
  86.         printf("Old version: %d ", i);
  87.     else
  88.         printf("Version: %d ", i);
  89.     switch (i) {
  90.         case 28: printf("(Shareware)\n"); break;
  91.         case 29: printf("(Registered)\n"); break;
  92.         default: printf("\n");
  93.     }
  94.  
  95. /* If the user wants to patch the BSP, do it. */
  96.  
  97.     if (argc > 2) {
  98.         printf("New version: %d ", ver);
  99.         switch (ver) {
  100.             case 28: printf("(Shareware)\n"); break;
  101.             case 29: printf("(Registered)\n"); break;
  102.             default: printf("\n");
  103.         }
  104.         fseek(fp, 0, SEEK_SET);
  105.         fputc(ver, fp);
  106.     }
  107.  
  108. // Close the file, we're done.
  109.     if (fclose(fp) == EOF) {
  110.         printf("ERROR: Unable to close file %s.\n", fname);
  111.     }
  112.  
  113.     return 0;
  114. }