LINE -- Line Number Pipe for MS-DOS 
Author Message
 LINE -- Line Number Pipe for MS-DOS

This is the source code showing the implementation of pipes on
MS-DOS.

------------------LINE.C starts-----------------------------

/*
        LINE.C
        Simple MS-DOS pipe to add line-numbers to files
        (c) Masud Reza, 1995

        Tested and comiled using Turbo C 2.0 and the Turbo De{*filter*}
        MAXLINE is set at 1000 which is enough for most files.

        LINE may be used at the end of a command-line or in the
        middle.
        e.g.

        type myfile.c | line | more
        add line-numbers and show myfile.c one screen at a time

        or

        type myfile.c | line > lpt1:
        print listing with line numbers on screen

*/

#include <stdio.h>

#define MAXLINE 1000            /* max. number of chars in a line       */

char    inputline [MAXLINE];            /* line read from stdin         */
char    outputline[MAXLINE];            /* line to be written to stdout */

short main ( void )
{

static  unsigned long   linenumber;

        /* while there's a line in the input-line, read it, add a line-number
           and write the line back to stdout
        */

        while ( fgets( inputline, MAXLINE, stdin ) )
                {
                        ++linenumber;
                        vsprintf( outputline, "%lu: ", &linenumber );
                        strcat( outputline, inputline );
                        fputs( outputline, stdout );
                }

        return 0;

Quote:
}

----------------------LINE.C ends------------------------------

          +
      **      **  
     * *    * *    +
 +  *  *  *  *  
   *   **   *         +
| *    *   *   A  S  U  D|



Sun, 16 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

Quote:

>    Simple MS-DOS pipe to add line-numbers to files
>    (c) Masud Reza, 1995

I find this reasonably annoying for 2 reasons...

1. Why post copyrighted code to a newsgroup since the copyright means
   that no one else can use it?

2. Why would anyone attach a copyright notice to such an admittedly
   "simple" program?!? C'mon, excluding comments, it's only 16 lines, and
   could probably be done in half that!

-------------------------------------------------------------
MicroFirm: Down to the C in chips...
FidoNet 1:106/2000.6

Home of SNIPPETS - Current release:
        oak.oakland.edu:/SimTel/msdos/c/snip9503.zip
        juge.com:/c/file/c/snip9503.lzh



Sat, 22 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

Quote:

>    LINE.C
>    Simple MS-DOS pipe to add line-numbers to files
>    (c) Masud Reza, 1995

Apropos of my previous comments, here's an 11-line version with a smaller
footprint that's public domain...

/*
**  LINE.C
**  Simple MS-DOS filter to add line-numbers to files
**
**  public domain demo by Bob Stout
**  portable to all DOS compilers
**
**  Syntax:
**  LINE may be used at the end of a command-line or in the middle, e.g.
**
**  type myfile.c | line | more
**  add line-numbers and show myfile.c one screen at a time
**
**  or
**
**  type myfile.c | line > lpt1:
**  print listing with line numbers on screen
**
**  or
**
**  line < myfile.c
**  display file with line numbers on screen
*/

#include <stdio.h>
#include <stdlib.h>

#define MAXLINE 512                 /* max.  chars/line per ANSI/ISO    */

int main()
{
      char line[MAXLINE];           /* line read from stdin             */
      static unsigned long linenumber = 0;

      while (fgets(line, MAXLINE-1, stdin))
            fprintf(stdout, "%06lu: %s", ++linenumber, line);

      return EXIT_SUCCESS;

Quote:
}

-------------------------------------------------------------
MicroFirm: Down to the C in chips...
FidoNet 1:106/2000.6

Home of SNIPPETS - Current release:
        oak.oakland.edu:/SimTel/msdos/c/snip9503.zip
        juge.com:/c/file/c/snip9503.lzh


Sat, 22 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

: This is the source code showing the implementation of pipes on
: MS-DOS.

: ------------------LINE.C starts-----------------------------

: /*
:       LINE.C
:       Simple MS-DOS pipe to add line-numbers to files
:       (c) Masud Reza, 1995

:       Tested and comiled using Turbo C 2.0 and the Turbo De{*filter*}
:       MAXLINE is set at 1000 which is enough for most files.

: #include <stdio.h>

: #define       MAXLINE 1000            /* max. number of chars in a line       */

: char  inputline [MAXLINE];            /* line read from stdin         */
: char  outputline[MAXLINE];            /* line to be written to stdout */

: short main ( void )

Is this allowed...I though main had to return type int.
Just a curious beginner...
Fabio Clavijo

: {

: static        unsigned long   linenumber;

:       /* while there's a line in the input-line, read it, add a line-number
:          and write the line back to stdout
:       */

:       while ( fgets( inputline, MAXLINE, stdin ) )
:               {
:                       ++linenumber;
:                       vsprintf( outputline, "%lu: ", &linenumber );
:                       strcat( outputline, inputline );
:                       fputs( outputline, stdout );
:               }

:       return 0;
: }

: ----------------------LINE.C ends------------------------------

:           +
:       **      **  
:      * *    * *    +
:  +  *  *  *  *  
:    *   **   *         +
: | *    *   *   A  S  U  D|



Sat, 22 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

Quote:
> 1. Why post copyrighted code to a newsgroup since the copyright means
>    that no one else can use it?

        Well, a copyright doesn't neccesarily mean that it's not for public
consumption.  It's basically a way of claiming your program as officially
yours.  It's a title thing more than a usage license.

--
 _/  _/_/  _/_/  _/  _/_/  _/_/  _/_/  _/  _/    _/  _/_/  _/    _/  _/  _/


 _/_/  _/_/  _/  _/_/_/  _/  _/_/  _/ _/_/  _/ _/_/  _/_/  _/_/  _/_/  _/_/



Sat, 22 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

Quote:
>    Well, a copyright doesn't neccesarily mean that it's not for public
> consumption.  It's basically a way of claiming your program as officially
> yours.  It's a title thing more than a usage license.

Yours is the type of attitude that lets lawyers afford to send their kids
to Harvard Law School to perpetuate the species. A copyright is a very
specific legal claim, and one which attaches automatically in all nations
which are signatories of the Berne Convention.

More than a "title thing", a copyright invests the author with all
available intellectual property rights over his/her work. The right to
use, publish, and/or profit from derivative works are among those rights
which are inherent in claiming a copyright. Since copyrights do attach
automatically, the only way you can post code free for reuse is to either
include an explicit free use license or to explicitly release the work to
the public domain.

-------------------------------------------------------------
MicroFirm: Down to the C in chips...
FidoNet 1:106/2000.6

Home of SNIPPETS - Current release:
        oak.oakland.edu:/SimTel/msdos/c/snip9503.zip
        juge.com:/c/file/c/snip9503.lzh



Sat, 22 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

Quote:

>This is the source code showing the implementation of pipes on
>MS-DOS.

>#include <stdio.h>

You'd want to include a proto type for the strcat

Quote:
>#define    MAXLINE 1000        /* max. number of chars in a line   */
>char   inputline [MAXLINE];        /* line read from stdin     */

>short main ( void )

 ^^^^^
I'm sure I saw someone mention an int here.
Quote:
>{

>static unsigned long   linenumber;

>   while ( fgets( inputline, MAXLINE, stdin ) ) {
>     ++linenumber;
>     vsprintf( outputline, "%lu: ", &linenumber );
>     strcat( outputline, inputline );
>     fputs( outputline, stdout );
>     }

  while ( fgets( inputline, MAXLINE, stdin ) )
    fprintf(stdout, "%5lu: %s", linenumber++, inputline);
Quote:

>   return 0;
>}
>          +      **      **     * *    * *    + +  *  *  *  *
>   *   **   *         +| *    *   *   A  S  U  D|


Nice sig.

Regards,
  M A R K



Sun, 23 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS

writes:
<snip>
|> : short main ( void )
|>
|> Is this allowed...I though main had to return type int.
|> Just a curious beginner...
|> Fabio Clavijo

short main(void) is as bad as void main(void). It makes an otherwise
conforming program non-conforming: i.e. it works only if your compiler is
friendly (or, `unfriendly' because a friend ought to warn you when you make
mistakes :-)

Cheers
Tanmoy
--

Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]



Mon, 24 Nov 1997 03:00:00 GMT  
 LINE -- Line Number Pipe for MS-DOS
: : short main ( void )

: Is this allowed...I though main had to return type int.
: Just a curious beginner...
: Fabio Clavijo
:  

: :     return 0;
: : }

Isn't that what this is?



Tue, 02 Dec 1997 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. LINE -- Line Number Pipe

2. MS-DOS Command-Line Switches

3. Command line stdin versus piped in?

4. Processing lines received through a pipe

5. Return Line without pipe symbol

6. Printing line-by-line

7. Reading from a text file line by line

8. Opening a text file/Displaying text line by line

9. Multi-Line Comments Nested in Single Line Comments

10. char *line vs. char line[]

11. Reading Line per line in C

12. Dispaly lines of Lines of file with Win 3.1 SDK

 

 
Powered by phpBB® Forum Software