[net.bizarre] backwards

nather@utastro.UUCP (Ed Nather) (08/02/85)

>From: jeff (Jeff Brown the Scumbag)
>Subject: self-recursion in silly software

The following output is the result of running a program on itself:


                                                                            
                                                                            #include <stdio.h>
                                                                            #define BACKSPACE '\010'
                                                                            #define LONG 300
                                                                            #define LINELENGTH 76
                                                                            #define FINIS -17
                                                                            
                                                                            main()          /* to make easy cn line lists */
                                                                            {
                                                                            char in[LONG], out[LONG];
                                                                            int i, lin, lout;
                                                                            
                                                                            while ((lin = getline(in)) != FINIS)    {
                                                                                    if(lin > LINELENGTH)    {
                                                                                            lin = LINELENGTH;
                                                                                            in[lin+1] = '\0';
                                                                                            }
                                                                                    for(i = 0; i < LINELENGTH; i++)         out[i] = ' '
;
                                                                                    lout = LINELENGTH;
                                                                                    if(lin == 0)    { }
                                                                                    else if (lin == 1) out[lout++] = in[0];
                                                                                    else    {
                                                                                            for(i = 0; i <= lin-1; i++)     {
                                                                                                    out[lout++] = in[i];
                                                                                                    out[lout++] = BACKSPACE;
                                                                                                    out[lout++] = BACKSPACE;
                                                                                                    }
                                                                                            }
                                                                                    out[lout++] = '\n';
                                                                                    out[lout] = '\0';
                                                                                    for(i = 0; i < lout; i++) printf("%c",out[i]);
                                                                            }
                                                                            }
                                                                            getline(pn)     /*read the whole buffer, then truncate at ne
wline */
                                                                            char pn[];
                                                                            {
                                                                            int i;
                                                                            char c;
                                                                            i = 0;
                                                                            while((c = getchar()) != '\n' && c != EOF)       pn[i++] = c
;
                                                                            pn[i] = '\0';
                                                                            if(c == EOF) i = FINIS;
                                                                            return(i);
                                                                            }

-----
Note:  If your input file contains tabs the program will not work (I'm
working on it, though).  You have to pipe it through expand first to
get the effect you want.

*********************************************************************

-- 
Ed Nather
Astronomy Dept, U of Texas @ Austin
{allegra,ihnp4}!{noao,ut-sally}!utastro!nather
nather%utastro.UTEXAS@ut-sally.ARPA