[comp.sys.ibm.pc] setargv.c for Turbo C 1.5

sweet@scubed.UUCP (Kevin Sweet) (02/13/88)

In article <383@sun.soe.clarkson.edu> nelson@sun.soe.clarkson.edu.UUCP (Russ Nelson) writes:
>In article <1282@nmtsun.nmt.edu>, greg@nmtsun.nmt.edu (Greg Lindhorst) writes:
>> I have a stupid question to ask.  How can one get Turbo C to expand
>> wild carded arguments on the command line?
>> 
>> I.E. Translate something like:    "doitto *.c"
>>      into somthing like:          "doitto first_file.c second_file.c ..."
>
>How's about this solution?  It's the best of all I've seen:
>
>-russ
>AT&T: (315)268-6591  BITNET: NELSON@CLUTX  Internet: nelson@clutx.clarkson.edu
>GEnie: BH01  Compu$erve: 70441,205

[Russ includes the source for _setargv()]

What follows is a one line addition to the code that (at least on my IBM PC/XT)
allows arguements to maintain their directory hierarchy: 

    i.e., say your root directory of drive 'c' looks like this:
           autoexec.bat    config.sys   tmp/

    if you are in directory c:\tmp and you use the wildcard expansion with a 
    main program like:
          #include <stdio.h>
          main(int argc, char *argv[])
          {
              int i;
              for (i = 1; i < argc; i++) printf("argv[%d] = %s\n", i, argv[i]);
          }

    and do "main ..\*.*" the program would print:
          argv[1] = ..\AUTOEXEC.BAT
          argv[2] = ..\CONFIG.SYS

    but if you did "main ../*.*" the program would print:
          argv[1] = AUTOEXEC.BAT
          argv[2] = CONFIG.SYS

The following patch make the result of both commands the same (like the first):

*** old/setargv.c	Fri Feb 12 12:56:51 1988
--- new/setargv.c	Fri Feb 12 15:53:43 1988
***************
*** 27,33
  #include <ctype.h>
  #include <dir.h>
  #include <dos.h>
- #include <ctype.h>
  #include <process.h>
  
  #define FALSE           0

--- 27,32 -----
  #include <ctype.h>
  #include <dir.h>
  #include <dos.h>
  #include <process.h>
  
  #define FALSE           0
***************
*** 94,99
      {
        /* wild is TRUE if word contains * or ? */
        wild |= (c == '*' || c == '?');
        *(p++) = c;
  
        /* lastdir points to the first character of the base file name */

--- 93,99 -----
      {
        /* wild is TRUE if word contains * or ? */
        wild |= (c == '*' || c == '?');
+       if (c == '/') c = '\\';
        *(p++) = c;
  
        /* lastdir points to the first character of the base file name */

--- end of patch ---

Kevin
-- 
---- kevin sweet --------------------------------------------------------------
home:           12205 carmel vista 242, san diego, ca 92130-2237,  619-259-9338
work:            3398 carmel mountain,  san diego, ca 92121-1095,  619-587-8499
---- ARPA: sweet@kelvin -------------- UUCP: ...{ames!scubed!}kelvin!sweet ----