home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qdtool10 / qdimport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-03  |  2.9 KB  |  111 lines

  1. /*
  2.  * Copyright (C) 1996 by Chris Johnson.  All rights reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and
  5.  * its documentation for any purpose and without fee is hereby
  6.  * granted, provided that the above copyright notice appear in all
  7.  * copies and that both that copyright notice and this permission
  8.  * notice appear in supporting documentation.  If more than a few
  9.  * lines of this code are used in a program which displays a copyright
  10.  * notice or credit notice, the following acknowledgment must also be
  11.  * displayed on the same screen: "This product includes software
  12.  * developed by Chris Johnson for use in the QuakeDef Tools package."
  13.  * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESSED OR IMPLIED
  14.  * WARRANTY.
  15.  *
  16.  * (Thanks to Raphael Quinet for this nifty disclaimer!)
  17.  */
  18.  
  19. #include <io.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include "qdimport.h"
  24. #include "fileutil.h"
  25. #include "qdfunct.h"
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.     FILE *    old_bsp;
  30.     FILE *    new_bsp;
  31.     FILE *    qdf;
  32.     long *    addr = NULL;
  33.     long    diff;
  34.  
  35.     if (argc < 4)
  36.     {
  37.         show_help();
  38.         exit(ERROR);
  39.     }
  40.  
  41.     if (! fexist(argv[1]))
  42.         exit(ERROR);
  43.  
  44.     if ((old_bsp = safeopen(argv[2], "rb")) == NULL)
  45.         exit(ERROR);
  46.  
  47.     if ((new_bsp = safeopen(argv[3], "wb")) == NULL)
  48.         exit(ERROR);
  49.  
  50.     // Get old bsp header
  51.     if ((addr = grab_addresses(old_bsp)) == NULL)
  52.         exit(ERROR);
  53.  
  54.     // Copy pre-QuakeDef portion
  55.     if (copy(new_bsp, old_bsp, addr[BH_QD_ELEM]) == EOF)
  56.     {
  57.         fprintf(stderr, "\nError during copy process.\n");
  58.         exit(ERROR);
  59.     }
  60.  
  61.     // Uhhhhh... In case of freak accident....  :)
  62.     if ((qdf = safeopen(argv[1], "rt")) == NULL)
  63.         exit(ERROR);
  64.  
  65.     // Copy QuakeDef portion
  66.     import_quake_def(qdf, new_bsp);
  67.  
  68.     fclose(qdf);
  69.  
  70.     // Calculate size difference between new and old QuakeDefs
  71.     diff = ftell(new_bsp) - addr[BH_POSTQD_ELEM];
  72.  
  73.     // Copy post-QuakeDef portion
  74.     fseek(old_bsp, addr[BH_POSTQD_ELEM], SEEK_SET);
  75.     if (copy(new_bsp, old_bsp,
  76.              filelength(fileno(old_bsp)) - ftell(old_bsp)) == EOF)
  77.     {
  78.         fprintf(stderr, "\nError during copy process.\n");
  79.         exit(ERROR);
  80.     }
  81.  
  82.     // Fix BSP Header info
  83.     fix_bsp_hdr(new_bsp, addr, diff);
  84.  
  85.     // Tidy up
  86.     free(addr);
  87.  
  88.     fclose(old_bsp);
  89.     fclose(new_bsp);
  90.  
  91.     fprintf(stderr, "\nImport of QuakeDef file successful!\n");
  92.  
  93.     return (OKAY);
  94. }
  95.  
  96. void show_help(void)
  97. {
  98.     printf("\nQuakeDef Importer v1.0.  Copyright 1996 by Chris Johnson.");
  99.     printf("\n\nUsage:");
  100.     printf("\n\nqdimport <drive:><\\path\\><deffile.def> "
  101.             "<drive:><\\path\\><old_map.bsp>");
  102.     printf("\n         <drive:><\\path\\><new_map.bsp>");
  103.     printf("\n\n<drive:> and <\\path\\> unnecessary if "
  104.             "current directory is adequate.");
  105.     printf("\n<deffile.def> is the filename of the QuakeDef ASCII file.");
  106.     printf("\n<old_map.bsp> is the filename of the .BSP "
  107.             "file that deffile.def");
  108.     printf("\n              came from.");
  109.     printf("\n<new_map.bsp> is the filename of the new .BSP "
  110.             "file to create.\n");
  111. }