[net.lang.c] Command line arguments, redirection, etc.

cbk@se-sd.UUCP (cbk) (02/20/86)

[ Inscribed on the line, in very tiny letters, were the words: EAT ME ]

   Hopefully, this "discussion" about argument passing, redirection, and
such can be put to rest once and for all.  Here's my two cents worth, 
having just completed porting the PCC C compiler to a proprietary,
decidedly non-UNIX (tm) operating system.

1. Redirection of standard I/O is a part of C, piping is not.
   Ref: K&R, chapter 7

   "Finally, the routines are meant to be 'portable', in the sense that
    they will exist *in compatible form* on any system where C exists"...

   The routines mentioned are those which use "standard I/O".  See page
   144... "output can be redirected to a file by using >...", and "On
   the UNIX system, a pipe can also be used..."  This implies that
   redirection is required functionality, whereas piping is a part of
   a particular operating system.

2. Command-line arguments are a part of C.
   Ref: K&R, chapter 5.11

   "In environments that support C, there is a way to pass command-line
    arguments or parameters to a program when it begins executing."

It sounds to me like this whole issue boils down to whether or not someone
has taken the time to *correctly* implement C to provide the functionality
as specified in K&R (or whatever else happens to be your favorite standard).

[ Personal opinion, FLAME ON ]

Any implementation of C that doesn't provide redirection and command-line
argument passing is half-assed at best.

[ FLAME OFF]

You know, I feel better already!  Hey kiddies, get out YOUR copy of K&R and
read, read, read!   

-- Carl Kuck  (apply all standard disclaimers to the preceeding babble)
  
UseNet (west) : {wherever}!sdcsvax!ncr-sd!se-sd!cbk 
       (east) : {wherever}!ihnp4!ncr-sd!se-sd!cbk

PacBell: (619) 450-6271 (w), 944-1705 (h)

Quote #1: Only those who attempt the absurd can achieve the impossible.
Quote #2: 55 mph isn't a good idea, it's just the law...

guy@sun.uucp (Guy Harris) (02/20/86)

> 1. Redirection of standard I/O is a part of C, piping is not.
>    Ref: K&R, chapter 7
> 
>    "Finally, the routines are meant to be 'portable', in the sense that
>     they will exist *in compatible form* on any system where C exists"...
> 
>    The routines mentioned are those which use "standard I/O".  See page
>    144... "output can be redirected to a file by using >...", and "On
>    the UNIX system, a pipe can also be used..."  This implies that
>    redirection is required functionality, whereas piping is a part of
>    a particular operating system.

No, you are *inferring*, incorrectly, that redirection is required
functionality.  First of all, the only part of K&R that is close to Sacred
Writ is Appendix A, which is the reference manual.  The rest of it is
tutorial information.  Second of all, if you'd read that stuff carefully,
you would have seen that it said "*In most environments that support C*, a
file may be substituted for the terminal by using the "<" convention...".
In other words, it is a property of the *environment* (including the
operating system), not of the language.  The UNIX Standard I/O library does
not "support" redirection; it's done by the shell (which, I hope, is NOT a
required portion of a C environment - the ANSI C committee is already
standardizing too many things which are properly part of the C binding of
the UNIX system or the P1003 standard).

(As for passing arguments to the program, it should use the conventions of
the host environment if possible; i.e., on VMS, it should presumably
tokenize the commands string (assuming VMS still, in effect, hands you the
whole string as a single lump) and set "argv" to point to the tokens, on
OS/360 and successors, it should use the "PARM=" string, presumably
tokenizing it using "," as the token separator, etc..  If the host
environment doesn't provide command parsing, it's up to the implementor;
they can request a single line of input and use that (and accept redirection
specifications on that line, too), which is what some implementations do, or
they can probably do nothing at all and still meet the ANSI standard's
specifications.)

> You know, I feel better already!  Hey kiddies, get out YOUR copy of K&R and
> read, read, read!   

Yes, read, but read what it says, not what you wish it had said....
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.arpa	(yes, really)

barmar@mit-eddie.UUCP (Barry Margolin) (02/21/86)

In article <36@se-sd.UUCP> cbk@se-sd.UUCP (Carl Kuck) writes:
>[ Personal opinion, FLAME ON ]
>
>Any implementation of C that doesn't provide redirection and command-line
>argument passing is half-assed at best.
>
>[ FLAME OFF]

This whole discussion is pretty silly, but...

The above comment implies that a computer that doesn't have command
lines and files "is half-assed at best".  Most of the computers one uses
do not have these features.  For example, the computer in my VCR, my
terminal, my microwave, my thermostat, etc.  I would be willing to bet
that none of these is currently programmed in C, but it would be
possible for C to be used.
-- 
    Barry Margolin
    ARPA: barmar@MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar

throopw@dg_rtp.UUCP (02/24/86)

[   Warning.  Some of my comentary below contains (gasp) Humorous
    Content.  In no way should the Mild Humor in this posting be
    confused with Hurtful and Counterproductive Sarcasm.
    You have been Warned!  ]

>   Hopefully, this "discussion" about argument passing, redirection, and
> such can be put to rest once and for all.

Close, but no cigar.

> 1. Redirection of standard I/O is a part of C, piping is not.
>    Ref: K&R, chapter 7
>
>    "Finally, the routines are meant to be 'portable', in the sense that
>     they will exist *in compatible form* on any system where C exists"...
>
>    The routines mentioned are those which use "standard I/O".  See page
>    144... "output can be redirected to a file by using >...", and "On
>    the UNIX system, a pipe can also be used..."  This implies that
>    redirection is required functionality, whereas piping is a part of
>    a particular operating system.

Well, your heart's in the right place, you *do* got religion, but I
don't think you've really imersed yourself in the Holy Texts.  In
particular, you missed the fact that on page 143, to introduce the whole
chapter on IO, The Book says

        And DMR created Facilities, Input and Output created He Them,
        And these Facilities were separate from The Language of C,

Oops, sorry, that was the King James version.
Let me get my Modern Reformed copy...

        Input and output facilities are not part of the C language,

Now, you can dismiss this by saying that in common usage the phrase "the
C language" refers to both the formal language definition *and* the
supporting libraries (at least stdio).  But worse yet (you heretic you),
you missed the quote just above the one you took from page 144:

        In most environments that support C, a file may be substituted
        for the terminal by using the < convention

In particular, The Book says "most" (not "all") environments that
support C, so it is *not* a requirement, merely a coincidence.  So, even
if one takes the standard IO libraries to be "part of the language", C
doesn't require "<>" style redirection any more than it requires the "|"
piping convention.

> 2. Command-line arguments are a part of C.
>    Ref: K&R, chapter 5.11
>
>    "In environments that support C, there is a way to pass command-line
>     arguments or parameters to a program when it begins executing."

Again, you don't catch on to the subtleties.  The phrase is
"command-line arguments *or* parameters".  In fact, careful reading of
K&R convinces me that C can be correctly implemented on systems that
(shudder) *have* *no* *commands* *or* *command* *lines*, let alone
"command-line arguments".  All that is nailed down is some way to pass
text string parameters to programs at execution time.  The method isn't
spelled out, and in particular it needen't be "commands" which have
"arguments".

> It sounds to me like this whole issue boils down to whether or not someone
> has taken the time to *correctly* implement C to provide the functionality
> as specified in K&R (or whatever else happens to be your favorite standard).

I guess I agree with that.

> [ Personal opinion, FLAME ON ]
>
> Any implementation of C that doesn't provide redirection and command-line
> argument passing is half-assed at best.
>
> [ FLAME OFF]

It may be half-assed, but it could still be a legal C implementation.

> You know, I feel better already!  Hey kiddies, get out YOUR copy of K&R and
> read, read, read!   

Good idea.  Try Harbison and Steele also.

> -- Carl Kuck (apply all standard disclaimers to the preceeding babble)

--
(Gee, isn't being a language lawyer fun?  Just think what can be done
 with interpreting ANSI C when it comes out!  Can you say "job security"?
 I knew you could...)
-- 
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!dg_rtp!throopw