Re: Why some PC C compilers are useless

sjg@melb.bull.oz.au (Simon J Gerraty)
Wed, 13 May 1992 04:48:27 GMT

          From comp.compilers

Related articles
Why some PC C compilers are useless sjg@zen.void.oz.au (1992-05-07)
Re: Why some PC C compilers are useless cliffc@rice.edu (1992-05-08)
Re: Why some PC C compilers are useless sjg@melb.bull.oz.au (1992-05-11)
Re: Why some PC C compilers are useless Zoid@mindlink.bc.ca (1992-05-11)
Re: Why some PC C compilers are useless bobmon@sandshark.cs.indiana.edu (Bob Montante) (1992-05-12)
Re: Why some PC C compilers are useless sjg@melb.bull.oz.au (1992-05-13)
Re: Why some PC C compilers are useless sdm7g@aemsun.med.Virginia.EDU (1992-05-14)
| List of all articles for this month |
Newsgroups: comp.compilers
From: sjg@melb.bull.oz.au (Simon J Gerraty)
Followup-To: comp.lang.c
Keywords: C, MSDOS
Organization: Bull HN Information Systems Australia
References: 92-05-067
Date: Wed, 13 May 1992 04:48:27 GMT

In 92-05-067 Zoid@mindlink.bc.ca (Dave Kirsch) writes:
>>[I run DOS under Unix here and can second the complaints about programs that
>>freak out when they encounter newlines without carriage returns. I can have
>>some sympathy for dusty old programs, but not much for current supported ones
>>when they do this. -John]


>One problem of this is the standard i/o routines provided in the C
>libraries by most (if not all) DOS compilers don't handle lines without
>carriage returns. Sure, you could use read() and write() and write your
>own 'read a line from the file' function that understands cr/lf and just
>lf, but you shouldn't have to. The stdio functions take care of that for
>you.


No. All you need to do is: (... means insert your own code here :-)


    if ((fh = fopen(name, "rb")) != NULL)
    {
...
        int c;


        while ((c = getc(fh)) != EOF)
        {
...
              switch (c)
              {
              case '\r':
                  if ((c = getc(fh)) == '\n')
return EOL;
ungetc(c, fh);
return CR;
                  break;
              case '\n':
                  return EOL;
                  break;
...


Of course that code won't do anything useful. But the point is that the
compiler should simply read the file in DOS's binary mode, and ignore a CR
(esp. if followed by a LF). The details are left up to the implementor.


You could use lex, but my experience is that hand written lexical
analyzers are smaller and faster which are both important for a DOS C
compiler.


--
Simon J. Gerraty <sjg@melb.bull.oz.au> (Work)
<sjg@zen.void.oz.au> (Home)
[I've sent followups to comp.lang.c, since this is no longer a general
compilers topic. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.