🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #40628

Re: Why is comma delimiter in batch files?

#40628
From: Ben Cox
Date: Tue, 02 Jan 1990 13:51
41 lines
2612 bytes
In article <3445@cbnewsl.ATT.COM> rl@cbnewsl.ATT.COM (roger.h.levy) writes:
>
>I've noticed that batch files regard both blanks and commas as delimiters
>whereas c programs regard only blanks as a delimeter (If it matters, I'm
>using DOS 3.2).  For example:
[a C program to echo all the command-line parameters]
>When this program is fed a parameter string of "one,two", it prints that
>string back exactly, i.e. it regards the string as a single parameter.
>
>However, when the following batch file is fed the same string:
[a batch file to do the same thing]
>It prints "one" and "two" on different lines, i.e. it regards a comma
>delimited string as multiple parameters.
>
>My question: Is there a way to convince batch files to think of the comma
>as part of the parameter, i.e. to regard only blanks as delimiters so as
>to be consistent with c programs?

No, unless you want to patch DOS.  An alternative, if you want to do it and
have source to your C startup code, is to patch that (Turbo C Pro comes with
this source, Microsoft may/may not -- Turbo C's name is "c0?.obj" where the ?
is the memory model) to parse a comma as a delimiter.

The problem is that when a DOS program gets a command line, it gets it all in
one string.  The C0S (for small) module contains code which sets up error
handlers, parses the command line out into the argv[] array, and calls your
main() function with a counter of args, the pointers to the args, and a pointer
to the environment: main(argc,argv,envp).  So the fact that "one,two" is being
treated as one arg is entirely the fault of the startup code.  When you run a
batch file, DOS parses the command-line string out for the batch file and lets
you reference the individual strings as %0-%9.  The difference is, of course,
in the way the things are parsed out.  Anyway :-), the point is that while you
can customize your C command-line parser, you can't customize DOS's command-
line parser (unless you want to patch dos, which is generally a Bad Idea).

>Roger H. Levy
>Bell Labs, Whippany NJ
>att!groucho!rl

Ben Cox
b-cox2@uiuc.edu (this gets forwarded to me wherever I am)
Technical Details
Message-ID: <2646@jolnet.ORPK.IL.US>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!attctc!jolnet!cox
References: <3445@cbnewsl.ATT.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!attctc!jolnet!cox
From: cox@jolnet.ORPK.IL.US (Ben Cox)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Why is comma delimiter in batch files?
Keywords: batch MSDOS
Message-ID: <2646@jolnet.ORPK.IL.US>
Date: 2 Jan 90 13:51:36 GMT
References: <3445@cbnewsl.ATT.COM>
Reply-To: b-cox2@uiuc.edu
Organization: Jolnet, Public Access Unix, Orland Park (Joliet), Ill.
Lines: 41