components/prboom/d_main.c
//
// DoLooseFiles
//
// Take any file names on the command line before the first switch parm
// and insert the appropriate -file, -deh or -playdemo switch in front
// of them.
//
// Note that more than one -file, etc. entry on the command line won't
// work, so we have to go get all the valid ones if any that show up
// after the loose ones.  This means that boom fred.wad -file wilma
// will still load fred.wad and wilma.wad, in that order.
// The response file code kludges up its own version of myargv[] and
// unfortunately we have to do the same here because that kludge only
// happens if there _is_ a response file.  Truth is, it's more likely
// that there will be a need to do one or the other so it probably
// isn't important.  We'll point off to the original argv[], or the
// area allocated in FindResponseFile, or our own areas from strdups.
//
// CPhipps - OUCH! Writing into *myargv is too dodgy, damn
DoLooseFiles
Take any file names on the command line before the first switch parm
and insert the appropriate -file, -deh or -playdemo switch in front
of them.

Note that more than one -file, etc. entry on the command line won't
work, so we have to go get all the valid ones if any that show up
after the loose ones.  This means that boom fred.wad -file wilma
will still load fred.wad and wilma.wad, in that order.
The response file code kludges up its own version of myargv[] and
unfortunately we have to do the same here because that kludge only
happens if there _is_ a response file.  Truth is, it's more likely
that there will be a need to do one or the other so it probably
isn't important.  We'll point off to the original argv[], or the
area allocated in FindResponseFile, or our own areas from strdups.

OUCH. Writing into *myargv is too dodgy, damn
DoLooseFiles Take any file names on the command line before the first switch parm and insert the appropriate - file - deh or - playdemo switch in front of them . Note that more than one - file etc . entry on the command line won ' t work so we have to go get all the valid ones if any that show up after the loose ones . This means that boom fred . wad - file wilma will still load fred . wad and wilma . wad in that order . The response file code kludges up its own version of myargv [] and unfortunately we have to do the same here because that kludge only happens if there _is_ a response file . Truth is it ' s more likely that there will be a need to do one or the other so it probably isn ' t important . We ' ll point off to the original argv [] or the area allocated in FindResponseFile or our own areas from strdups . OUCH . Writing into * myargv is too dodgy damn
static void DoLooseFiles(void)
{
  char *wads[MAXARGVS];  
  char *lmps[MAXARGVS];
  char *dehs[MAXARGVS];
  int wadcount = 0;      
  int lmpcount = 0;
  int dehcount = 0;
  int i,j,p;
  const char **tmyargv;  
  int tmyargc;
  boolean skip[MAXARGVS]; 
  for (i=0; i<MAXARGVS; i++)
    skip[i] = false;
  for (i=1;i<myargc;i++)
  {
    if (*myargv[i] == '-') break;  
    j = strlen(myargv[i]);
    if (!stricmp(&myargv[i][j-4],".wad"))
      wads[wadcount++] = strdup(myargv[i]);
    if (!stricmp(&myargv[i][j-4],".lmp"))
      lmps[lmpcount++] = strdup(myargv[i]);
    if (!stricmp(&myargv[i][j-4],".deh"))
      dehs[dehcount++] = strdup(myargv[i]);
    if (!stricmp(&myargv[i][j-4],".bex"))
      dehs[dehcount++] = strdup(myargv[i]);
    if (myargv[i][j-4] != '.')  
      wads[wadcount++] = strdup(myargv[i]);
    skip[i] = true; 
  }
  if (wadcount+lmpcount+dehcount == 0) return;  
  if ((p = M_CheckParm ("-file")))
  {
    skip[p] = true;    
    while (++p != myargc && *myargv[p] != '-')
    {
      wads[wadcount++] = strdup(myargv[p]);
      skip[p] = true;  
    }
  }
  if ((p = M_CheckParm ("-deh")))
  {
    skip[p] = true;    
    while (++p != myargc && *myargv[p] != '-')
    {
      dehs[dehcount++] = strdup(myargv[p]);
      skip[p] = true;  
    }
  }
  if ((p = M_CheckParm ("-playdemo")))
  {
    skip[p] = true;    
    while (++p != myargc && *myargv[p] != '-')
    {
      lmps[lmpcount++] = strdup(myargv[p]);
      skip[p] = true;  
    }
  }
  tmyargv = calloc(sizeof(char *),MAXARGVS);
  tmyargv[0] = myargv[0]; 
  tmyargc = 1;
  if (wadcount > 0)
  {
    tmyargv[tmyargc++] = strdup("-file"); 
    for (i=0;i<wadcount;)
      tmyargv[tmyargc++] = wads[i++]; 
  }
  if (dehcount > 0)
  {
    tmyargv[tmyargc++] = strdup("-deh");
    for (i=0;i<dehcount;)
      tmyargv[tmyargc++] = dehs[i++];
  }
  if (lmpcount > 0)
  {
    tmyargv[tmyargc++] = strdup("-playdemo");
    for (i=0;i<lmpcount;)
      tmyargv[tmyargc++] = lmps[i++];
  }
  for (i=1;i<myargc;i++)
  {
    if (!skip[i])  
      tmyargv[tmyargc++] = myargv[i];  
  }
  myargv = tmyargv;
  myargc = tmyargc;
}
static void DoLooseFiles ( void ) { char * wads [ MAXARGVS ] ; char * lmps [ MAXARGVS ] ; char * dehs [ MAXARGVS ] ; int wadcount = 0 ; int lmpcount = 0 ; int dehcount = 0 ; int i , j , p ; const char * * tmyargv ; int tmyargc ; boolean skip [ MAXARGVS ] ; for ( i = 0 ; i < MAXARGVS ; i ++ ) skip [ i ] = false ; for ( i = 1 ; i < myargc ; i ++ ) { if ( * myargv [ i ] == ' ' ) break ; j = strlen ( myargv [ i ] ) ; if ( ! stricmp ( & myargv [ i ] [ j - 4 ] , " " ) ) wads [ wadcount ++ ] = strdup ( myargv [ i ] ) ; if ( ! stricmp ( & myargv [ i ] [ j - 4 ] , " " ) ) lmps [ lmpcount ++ ] = strdup ( myargv [ i ] ) ; if ( ! stricmp ( & myargv [ i ] [ j - 4 ] , " " ) ) dehs [ dehcount ++ ] = strdup ( myargv [ i ] ) ; if ( ! stricmp ( & myargv [ i ] [ j - 4 ] , " " ) ) dehs [ dehcount ++ ] = strdup ( myargv [ i ] ) ; if ( myargv [ i ] [ j - 4 ] != ' ' ) wads [ wadcount ++ ] = strdup ( myargv [ i ] ) ; skip [ i ] = true ; } if ( wadcount + lmpcount + dehcount == 0 ) return ; if ( ( p = M_CheckParm ( " " ) ) ) { skip [ p ] = true ; while ( ++ p != myargc && * myargv [ p ] != ' ' ) { wads [ wadcount ++ ] = strdup ( myargv [ p ] ) ; skip [ p ] = true ; } } if ( ( p = M_CheckParm ( " " ) ) ) { skip [ p ] = true ; while ( ++ p != myargc && * myargv [ p ] != ' ' ) { dehs [ dehcount ++ ] = strdup ( myargv [ p ] ) ; skip [ p ] = true ; } } if ( ( p = M_CheckParm ( " " ) ) ) { skip [ p ] = true ; while ( ++ p != myargc && * myargv [ p ] != ' ' ) { lmps [ lmpcount ++ ] = strdup ( myargv [ p ] ) ; skip [ p ] = true ; } } tmyargv = calloc ( sizeof ( char * ) , MAXARGVS ) ; tmyargv [ 0 ] = myargv [ 0 ] ; tmyargc = 1 ; if ( wadcount > 0 ) { tmyargv [ tmyargc ++ ] = strdup ( " " ) ; for ( i = 0 ; i < wadcount ; ) tmyargv [ tmyargc ++ ] = wads [ i ++ ] ; } if ( dehcount > 0 ) { tmyargv [ tmyargc ++ ] = strdup ( " " ) ; for ( i = 0 ; i < dehcount ; ) tmyargv [ tmyargc ++ ] = dehs [ i ++ ] ; } if ( lmpcount > 0 ) { tmyargv [ tmyargc ++ ] = strdup ( " " ) ; for ( i = 0 ; i < lmpcount ; ) tmyargv [ tmyargc ++ ] = lmps [ i ++ ] ; } for ( i = 1 ; i < myargc ; i ++ ) { if ( ! skip [ i ] ) tmyargv [ tmyargc ++ ] = myargv [ i ] ; } myargv = tmyargv ; myargc = tmyargc ; }
DoLooseFiles
Take any file names on the command line before the first switch parm
and insert the appropriate -file, -deh or -playdemo switch in front
of them.
DoLooseFiles Take any file names on the command line before the first switch parm and insert the appropriate - file - deh or - playdemo switch in front of them .
// store the respective loose filenames // count the loose filenames // use these to recreate the argv array // CPhipps - should these be skipped at the end // quit at first switch // so now we must have a loose file.  Find out what kind and store it. // assume wad if no extension // nuke that entry so it won't repeat later // Now, if we didn't find any loose files, we can just leave. // ******* early return **** // nuke the entry // null any we find and save // nuke the entry // null any we find and save // nuke the entry // null any we find and save // Now go back and redo the whole myargv array with our stuff in it. // First, create a new myargv array to copy into // invocation // put our stuff into it // put the switch in // allocated by strdup above // for -deh // for -playdemo // then copy everything that's there now // skip any zapped entries // pointers are still valid // now make the global variables point to our array