/*      Print an ASCII file and change tab characters to
        spaces.
                By Paul Sumberg  1985
*/
#include "stdio.h"

main(argc,argv)
/***  arguments are passed to main when program is invoked.
            The proper format is "PROGRAM filename.ext"   ***/
int argc;
char **argv;
    {
        /***  initialize variables  ***/
        FILE *read_file, *out_file, *fopen ();
        char in_name[15];
        int c;
        char next_char;
        int counter = 0;
        int lines = 0;
        /* * * test for proper number of arguments     * * */
        if(argc != 2)
            {
            printf("\nUsage: Print filename.ext\n");
            exit(1);
            }

/** * open input file that was given to main as argument      * * */

        read_file = fopen (argv[1], "r");

            /*    RATS! cant open it.     */
            if ( read_file == NULL )
            printf("couldn't open %s for reading.\n",argv[1]);
            else
            {

            /** open "printer" file   for output..      * */

            out_file = fopen ("prn:" , "w");
                if (out_file == NULL )
                    Printf("check printer.\n");

                else

           {
                    /** give printer some linefeeds.    * */
                    fprintf(out_file,"\n\n\n");

/*read each character and send to printer,replacing TABs with SPACES.     */
                    while ( (c = getc(read_file)) != EOF )
                        {
                        next_char = c;  

                /** check page length and if near end, give FF    * */
                        if (next_char == '\r')
                            {
                            ++lines;
                            next_char - '\0';
                            }
                                if(lines >= 60)
                                {       putc('\f',out_file);
                                    lines = 0;

                                /*give new page some linefeeds    */
                                    fprintf("\n\n\n");
                                }       


                    /** Is this sucker the tab character??      * */
                        if (next_char == '\t')
                            {
                            for(counter = 0; counter != 3; ++counter)
                                putc(' ', out_file);
                            continue;
                            }

                /** * Stuff that thing out the printer port.  * * */
                        putc (c, out_file);         
                        }
                        printf("file has been PRINTED!\n");
                    }
        }
                fclose(out_file);       /** * Put files to bed
                fclose(read_file);      * * * Night Night.    * * */
    }
