Annotation of researchv10no/games/rot.c, revision 1.1

1.1     ! root        1: /*%cc -O %
        !             2:  */
        !             3: #include <stdio.h>
        !             4: struct line{
        !             5:        struct line *next;
        !             6:        int count;
        !             7:        char str[1];
        !             8: }line;
        !             9: copy(p,q)
        !            10:        register char *p, *q;
        !            11: {
        !            12:        while(*q++ = *p++);
        !            13: }
        !            14: int eof;
        !            15: char *
        !            16: getstr(buf)
        !            17:        char *buf;
        !            18: {
        !            19:        register char *s, c;
        !            20:        s=buf;
        !            21:        if(eof){
        !            22:                *s++='\0';
        !            23:                return(buf);
        !            24:        }
        !            25:        while((c=getchar())!='\n' && c!=EOF)
        !            26:                *s++=c;
        !            27:        *s++='\0';
        !            28:        if(c==EOF)
        !            29:                eof++;
        !            30:        return(buf);
        !            31: }
        !            32: int spcnt;
        !            33: putch(c){
        !            34:        register i;
        !            35:        if(c==' ')
        !            36:                spcnt++;
        !            37:        else if(c=='\n'){
        !            38:                spcnt=0;
        !            39:                putchar(c);
        !            40:        }
        !            41:        else{
        !            42:                for(i=0;i<spcnt;i++)
        !            43:                        putchar(' ');
        !            44:                spcnt=0;
        !            45:                putchar(c);
        !            46:        }
        !            47: }
        !            48: length(s)
        !            49:        register char *s;
        !            50: {
        !            51:        register i;
        !            52:        for(i=0;*s++;i++);
        !            53:        return(i);
        !            54: }
        !            55: char buf[2048];
        !            56: char obuf[BUFSIZ];
        !            57: main(){
        !            58:        register struct line *p, *q;
        !            59:        register done;
        !            60:        p=0;
        !            61:        setbuf(stdout,obuf);
        !            62:        for(;;){
        !            63:                getstr(buf);
        !            64:                if(eof) break;
        !            65:                q=p;
        !            66:                p=(struct line *)malloc(sizeof line+length(buf));
        !            67:                p->next=q;
        !            68:                p->count=0;
        !            69:                copy(buf, p->str);
        !            70:        }
        !            71:        for(;;){
        !            72:                done=1;
        !            73:                for(q=p;q;q=q->next){
        !            74:                        if(q->str[q->count]){
        !            75:                                putch(q->str[q->count++]);
        !            76:                                done=0;
        !            77:                        }
        !            78:                        else
        !            79:                                putch(' ');
        !            80:                }
        !            81:                if(done) break;
        !            82:                putch('\n');
        !            83:        }
        !            84: }

unix.superglobalmegacorp.com

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