w_main.c
  1  //
  2  // Copyright(C) 1993-1996 Id Software, Inc.
  3  // Copyright(C) 2005-2014 Simon Howard
  4  //
  5  // This program is free software; you can redistribute it and/or
  6  // modify it under the terms of the GNU General Public License
  7  // as published by the Free Software Foundation; either version 2
  8  // of the License, or (at your option) any later version.
  9  //
 10  // This program is distributed in the hope that it will be useful,
 11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  // GNU General Public License for more details.
 14  //
 15  // DESCRIPTION:
 16  //     Common code to parse command line, identifying WAD files to load.
 17  //
 18  
 19  #include "doomfeatures.h"
 20  #include "d_iwad.h"
 21  #include "m_argv.h"
 22  #include "w_main.h"
 23  #include "w_merge.h"
 24  #include "w_wad.h"
 25  #include "z_zone.h"
 26  
 27  // Parse the command line, merging WAD files that are sppecified.
 28  // Returns true if at least one file was added.
 29  
 30  boolean W_ParseCommandLine(void)
 31  {
 32      boolean modifiedgame = false;
 33      int p;
 34  
 35  #ifdef FEATURE_WAD_MERGE
 36  
 37      // Merged PWADs are loaded first, because they are supposed to be 
 38      // modified IWADs.
 39  
 40      //!
 41      // @arg <files>
 42      // @category mod
 43      //
 44      // Simulates the behavior of deutex's -merge option, merging a PWAD
 45      // into the main IWAD.  Multiple files may be specified.
 46      //
 47  
 48      p = M_CheckParmWithArgs("-merge", 1);
 49  
 50      if (p > 0)
 51      {
 52          for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
 53          {
 54              char *filename;
 55  
 56              modifiedgame = true;
 57  
 58              filename = D_TryFindWADByName(myargv[p]);
 59  
 60              printf(" merging %s\n", filename);
 61              W_MergeFile(filename);
 62          }
 63      }
 64  
 65      // NWT-style merging:
 66  
 67      // NWT's -merge option:
 68  
 69      //!
 70      // @arg <files>
 71      // @category mod
 72      //
 73      // Simulates the behavior of NWT's -merge option.  Multiple files
 74      // may be specified.
 75  
 76      p = M_CheckParmWithArgs("-nwtmerge", 1);
 77  
 78      if (p > 0)
 79      {
 80          for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
 81          {
 82              char *filename;
 83  
 84              modifiedgame = true;
 85  
 86              filename = D_TryFindWADByName(myargv[p]);
 87  
 88              printf(" performing NWT-style merge of %s\n", filename);
 89              W_NWTDashMerge(filename);
 90          }
 91      }
 92      
 93      // Add flats
 94  
 95      //!
 96      // @arg <files>
 97      // @category mod
 98      //
 99      // Simulates the behavior of NWT's -af option, merging flats into
100      // the main IWAD directory.  Multiple files may be specified.
101      //
102  
103      p = M_CheckParmWithArgs("-af", 1);
104  
105      if (p > 0)
106      {
107          for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
108          {
109              char *filename;
110  
111              modifiedgame = true;
112  
113              filename = D_TryFindWADByName(myargv[p]);
114  
115              printf(" merging flats from %s\n", filename);
116              W_NWTMergeFile(filename, W_NWT_MERGE_FLATS);
117          }
118      }
119  
120      //!
121      // @arg <files>
122      // @category mod
123      //
124      // Simulates the behavior of NWT's -as option, merging sprites
125      // into the main IWAD directory.  Multiple files may be specified.
126      //
127  
128      p = M_CheckParmWithArgs("-as", 1);
129  
130      if (p > 0)
131      {
132          for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
133          {
134              char *filename;
135  
136              modifiedgame = true;
137              filename = D_TryFindWADByName(myargv[p]);
138  
139              printf(" merging sprites from %s\n", filename);
140              W_NWTMergeFile(filename, W_NWT_MERGE_SPRITES);
141          }
142      }
143  
144      //!
145      // @arg <files>
146      // @category mod
147      //
148      // Equivalent to "-af <files> -as <files>".
149      //
150  
151      p = M_CheckParmWithArgs("-aa", 1);
152  
153      if (p > 0)
154      {
155          for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
156          {
157              char *filename;
158  
159              modifiedgame = true;
160  
161              filename = D_TryFindWADByName(myargv[p]);
162  
163              printf(" merging sprites and flats from %s\n", filename);
164              W_NWTMergeFile(filename, W_NWT_MERGE_SPRITES | W_NWT_MERGE_FLATS);
165          }
166      }
167  
168  #endif
169  
170      //!
171      // @arg <files>
172      // @vanilla
173      //
174      // Load the specified PWAD files.
175      //
176  
177      p = M_CheckParmWithArgs ("-file", 1);
178      if (p)
179      {
180  	// the parms after p are wadfile/lump names,
181  	// until end of parms or another - preceded parm
182  	modifiedgame = true;            // homebrew levels
183  	while (++p != myargc && myargv[p][0] != '-')
184          {
185              char *filename;
186  
187              filename = D_TryFindWADByName(myargv[p]);
188  
189              printf(" adding %s\n", filename);
190  	    W_AddFile(filename);
191          }
192      }
193  
194  //    W_PrintDirectory();
195  
196      return modifiedgame;
197  }
198