Annotation of coherent/d/bin/rev.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Reverse the order of the characters
        !             3:  * in every line of every file (or the
        !             4:  * standard input if no files are given).
        !             5:  */
        !             6: 
        !             7: #include <stdio.h>
        !             8: 
        !             9: #define        MAXLINE 1000
        !            10: 
        !            11: main(argc, argv)
        !            12: char *argv[];
        !            13: {
        !            14:        FILE *fp;
        !            15:        register int i;
        !            16: 
        !            17:        if (argc < 2)
        !            18:                rev(stdin);
        !            19:        else for (i=1; i<argc; i++)
        !            20:                if ((fp = fopen(argv[i], "r")) == NULL)
        !            21:                        fprintf(stderr, "Cannot open `%s'\n", argv[i]);
        !            22:                else {
        !            23:                        rev(fp);
        !            24:                        fclose(fp);
        !            25:                }
        !            26:        exit(0);
        !            27: }
        !            28: 
        !            29: /*
        !            30:  * Reverse the characters in every
        !            31:  * line of the file described by
        !            32:  * the given I/O stream.
        !            33:  */
        !            34: rev(stream)
        !            35: FILE *stream;
        !            36: {
        !            37:        register char *ep;
        !            38:        register c;
        !            39:        static char line[MAXLINE];
        !            40: 
        !            41:        do {
        !            42:                ep = line;
        !            43:                while ((c=getc(stream))!='\n' && c!=EOF)
        !            44:                        *ep++=c;
        !            45:                while (ep > line)
        !            46:                        putchar(*--ep);
        !            47:                if (c=='\n')
        !            48:                        putchar('\n');
        !            49:        } while (c != EOF);
        !            50: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.