home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / prntutil / mlist17 / mlist.c < prev    next >
Encoding:
Text File  |  1995-04-25  |  38.7 KB  |  1,042 lines

  1. /**********************************************************************
  2. **                                                                   **
  3. ** MList [/t tab] [/b bias] [/l] [/n] [/p] [/f] fname [fname [...]]  **
  4. **                                                                   **
  5. ** Create a numbered listing with intelligent line wrap, titles and  **
  6. ** pagination                                                        **
  7. **                                                                   **
  8. **  Author : Dan Rhea                                                **
  9. **    Date : 07/07/88                                                **
  10. ** History : 07/07/88 v1.00 - Started coding                         **
  11. **           07/17/88 v1.01 - Added the /t option                    **
  12. **                            Bumped buffer size up to 255           **
  13. **                            Added code to finish of a partial page **
  14. **           07/13/88 v1.02 - Added full title and footer centering  **
  15. **           07/28/88 v1.03 - Added error tab check and set default  **
  16. **                            tab to 8 Fixed starting line of first  **
  17. **                            page                                   **
  18. **           08/03/88 v1.04 - Fixed header and footer positions      **
  19. **                            Added a blank line after the header    **
  20. **                            and before the footer so entire        **
  21. **                            listing is visible if it is kept in a  **
  22. **                            binder Added total lines printed       **
  23. **           08/22/88 v1.05 - Added code to finish off partial lines **
  24. **                            when EOF is hit (i.e. last line ends   **
  25. **                            in EOF not a newline)                  **
  26. **           08/29/88 v1.06 - By request... a warm fuzzy every 100   **
  27. **                            lines Added a screen centering routine **
  28. **                            Some general output cleanup...         **
  29. **                            Center all the normal screen output... **
  30. **           09/01/88 v1.07 - The ATARI version! (conditional code   **
  31. **                            included)                              **
  32. **           09/04/88 v1.08 - Minor changes to make the source file  **
  33. **                            compile and link in either environment **
  34. **                            without changes                        **
  35. **           11/07/88 v1.09 - Re-sized page length to work well with **
  36. **                            a typical laser printer.               **
  37. **           11/10/88 v1.10 - Re-worked the centering routines to    **
  38. **                            reduce a lot of redundant code         **
  39. **           03/29/89 v1.11 - Added a line number bias option [/b n] **
  40. **           05/01/89 v1.12 - Changed tab logic to use modulis       **
  41. **                            calculation                            **
  42. **           05/09/89 v1.13 - Added an inhibit line number option    **
  43. **                            [/l]                                   **
  44. **           08/26/89 v1.14 - Corrected count error caused by bias   **
  45. **           11/24/89 v1.15 - Corrections to get Atari version in    **
  46. **                            sync                                   **
  47. **           04/01/91 v1.16 - Added code send a proper newline for   **
  48. **                            HP type laser printers (i.e. LF CR)    **
  49. **                            [/n]                                   **
  50. **                            Also did major cleanup on the code     **
  51. **           06/07/91 v1.17 - Added /p (pause between pages)         **
  52. **                            Added /f (pause between files)         **
  53. **                                                                   **
  54. ** This program has been written such that this source code can be   **
  55. ** used on an Atari-ST on an IBM compatible without modification     **
  56. ** provided you use the compilers and directives below.              **
  57. **                                                                   **
  58. ** Microsoft C 5.1 Compile and link directive (MS-DOS Version)       **
  59. **                                                                   **
  60. **    CL /AL /Ox \MSC\SRC\MLIST.C \MSC\LIB\SETARGV.OBJ /link /NOE    **
  61. **                                                                   **
  62. ** Mark Williams C 2.0 CC Directive (Atari GEMDOS Version)           **
  63. **                                                                   **
  64. **    CC -v MLIST.C                                                  **
  65. **                                                                   **
  66. ** Copyright (c) 1988-1991 by Dan Rhea, All rights reserved          **
  67. **                         program may be copied freely,             **
  68. **                         but never sold or rented                  **
  69. **                                                                   **
  70. ** You are free to enhance this program so long as my copyright is   **
  71. ** kept intact. If you have suggestions for improvements or want me  **
  72. ** me to include your changes to the "official" version of MLIST     **
  73. ** then contact me at (305)431-9343 or on CompuServe 76703,4364 in   **
  74. ** the ATARIPRO Forum or the IBMSYS Forum. You could also contact me **
  75. ** on my BBS at (305)435-8786.                                       **
  76. **                                                                   **
  77. ** If I add your enhancement to the program, I will credit you in    **
  78. ** program help screen.                                              **
  79. **                                                                   **
  80. **********************************************************************/
  81.  
  82. #include "stdio.h"
  83. #if GEMDOS
  84. #include "osbind.h"
  85. #else
  86. #include "string.h"
  87. #include "malloc.h"
  88. #endif
  89.  
  90. #define  FALSE    0           /* Well, like this means false eh      */
  91. #define  TRUE     1           /* True, so true                       */
  92. #define  WIDTH    80          /* Predefined page width (till I       */
  93.                               /* get around to making it variable)   */
  94. #define  TAB      0x09        /* Tab - used in tab expansion         */
  95. #define  BLANK    0x20        /* More tab expansion stuff            */
  96. #define  BSIZE    255         /* Input buffer size (text width)      */
  97. #define  PAGELEN  57          /* The predefine page length (for now) */
  98. #define  CR       \015        /* A carrige return                    */
  99. #define  LF       \012        /* A line feed                         */
  100. #define  FF       0x0C        /* A form feed                         */
  101.  
  102. int   ch,                     /* Character in process                */
  103.       cntr,                   /* Tab expansion counter               */
  104.       last_char,              /* Last character processed            */
  105.       tab_set;                /* Tab expansion value                 */
  106.  
  107. unsigned int   ocount,        /* Output buffer line counter          */
  108.                no_ecr,        /* .T. = Narrow, .F. = Normal          */
  109.                page_pause,    /* If True, pause at end of page       */
  110.                file_pause;    /* If True, pause at end of file       */
  111.  
  112. /*********************************************************************/
  113.  
  114. main (argc, argv)
  115. int  argc;
  116. char **argv;
  117. {
  118.  
  119.    /*
  120.    ** Define a bunch of stuff...
  121.    */
  122.    FILE  *fin;                /* File input stream                   */
  123. #if GEMDOS
  124.    FILE  *stdprn;             /* Printer stream (Atari ST only)      */
  125. #endif
  126.    unsigned char  *lineout,   /* Text output buffer                  */
  127.                   *title,     /* Title buffer                        */
  128.                   *footer,    /* Footer buffer                       */
  129.                   *junk,      /* Scratch buffer                      */
  130.                   *to_screen, /* Screen line buffer                  */
  131.                   *lptr,      /* Text buffer pointer                 */
  132.                   *sptr;      /* Screen buffer pointer               */
  133.  
  134.    unsigned int   c,          /* Current character                   */
  135.                   i,          /* Loop index                          */
  136.                   wrap,       /* Line wrap flag                      */
  137.                   lcount,     /* Output line counter (for display)   */
  138.                   pcount,     /* Page counter (for display)          */
  139.                   ccount,     /* Character counter (internal)        */
  140.                   tcount,     /* Real line counter (internal)        */
  141.                   acount,     /* All lines printed counter           */
  142.                   xcount,     /* Adjusted counter                    */
  143.                   pad,        /* Lines to pad out last page          */
  144.                   tof,        /* Top of form flag                    */
  145.                   first1,     /* First file flag                     */
  146.                   fuzzy,      /* Warm fuzzy variable                 */
  147.                   l_bias,     /* Line counter bias (usually 1)       */
  148.                   l_num,      /* Line number flag F=Inhibit          */
  149.                   l_wid;      /* Text line width (71 or 80)          */
  150.  
  151.    /*
  152.    ** Allocate buffers (no heap for me please)
  153.    */
  154.    lineout   = (unsigned char *) malloc(BSIZE * sizeof(unsigned char));
  155.    title     = (unsigned char *) malloc(BSIZE * sizeof(unsigned char));
  156.    footer    = (unsigned char *) malloc(BSIZE * sizeof(unsigned char));
  157.    junk      = (unsigned char *) malloc(BSIZE * sizeof(unsigned char));
  158.    to_screen = (unsigned char *) malloc(WIDTH * sizeof(unsigned char));
  159.  
  160. #if GEMDOS
  161.  
  162.    /*
  163.    ** Open the printer (The DOS machines have a PRN: assigned
  164.    ** automaticly just like stdin and stdout)
  165.    */
  166.    printf ("\033E");
  167.    if ((stdprn = fopen ("PRN:","w")) == NULL) {
  168.       center_scr ("\007Error: Unable to open printer.", TRUE);
  169.       go_away(1);
  170.    }
  171. #endif
  172.  
  173.    /*
  174.    ** Init stuff
  175.    */
  176.    last_char   = BLANK;       /* The last character processed        */
  177.    ch          = BLANK;       /* The current or character in process */
  178.    cntr        = FALSE;       /* If true, we are expanding a tab     */
  179.    tab_set     = 8;           /* Default tab width (I prefer 3...)   */
  180.    lptr        = lineout;     /* Point to the output line buffer     */
  181.    sptr        = to_screen;   /* Point to screen output buffer       */
  182.    first1      = TRUE;        /* If true, this is the first file     */
  183.    acount      = 0;           /* All lines printed (all files)       */
  184.    l_bias      = 1;           /* Default line number bias            */
  185.    l_num       = TRUE;        /* If true, we are numberin lines      */
  186.    l_wid       = 71;          /* Set the defailt line width          */
  187.    no_ecr      = FALSE;       /* If FALSE we don't use laser newline */
  188.    page_pause  = FALSE;       /* If TRUE, wait between page feeds    */
  189.    file_pause  = FALSE;       /* If TRUE, wait between files         */
  190.  
  191.    /*
  192.    ** Greetings earth person...
  193.    */
  194.    printf ("\n");
  195.    center_scr ("MLIST v1.17 (c) Copyright 1988-1991 by Dan Rhea,",
  196.               WIDTH, TRUE);
  197.    center_scr ("All rights reserved.",
  198.               WIDTH, TRUE);
  199.    center_scr ("This program can be freely copied but not sold.",
  200.               WIDTH, TRUE);
  201.    center_scr (" ",
  202.               WIDTH, TRUE);
  203.  
  204.    /*
  205.    ** Make sure we've got something to do
  206.    */
  207.    if (argc <= 1) {
  208.       help();
  209.       go_away(1);
  210.    }
  211.  
  212.    /*
  213.    ** Loop once for each file supplied via the command line
  214.    */
  215.    while (--argc > 0) {
  216.  
  217.       /*
  218.       ** Open file and handle an error if need be
  219.       */
  220.       if ((fin = fopen (*++argv, "r")) == NULL) {
  221.  
  222.          /*
  223.          ** If the file open falied, see if this is an option
  224.          */
  225.          if ((*argv)[0] == '-'|| (*argv)[0] == '/') {
  226.  
  227.             /*
  228.             ** See if it's a tab option
  229.             */
  230.             if ((*argv)[1] == 'T' || (*argv)[1] == 't') {
  231.                tab_set = atoi (*++argv);
  232.                argc--;
  233.                if (tab_set < 2 || tab_set > 255) {
  234.                   sprintf (sptr,
  235.                      "\007Error: Tab out of range (2-255), ");
  236.                   center_scr (sptr, WIDTH, TRUE);
  237.                   sptr = to_screen;
  238.                   sprintf (sptr, "forced to tab of 8.");
  239.                   center_scr (sptr, WIDTH, TRUE);
  240.                   sptr = to_screen;
  241.                   tab_set = 8;
  242.                }
  243.             } else {
  244.  
  245.                /*
  246.                ** See if it's a line bias option
  247.                */
  248.                if ((*argv)[1] == 'B' || (*argv)[1] == 'b') {
  249.                   l_bias = atoi (*++argv);
  250.                   argc--;
  251.                   if ((l_bias < 1) || (l_bias > 9999999L)) {
  252.                      sprintf (sptr,
  253.                         "\007Error: Line bias out of range (1-9999999), ");
  254.                      center_scr (sptr, WIDTH, TRUE);
  255.                      sptr = to_screen;
  256.                      sprintf (sptr, "forced to default of 1.");
  257.                      center_scr (sptr, WIDTH, TRUE);
  258.                      sptr = to_screen;
  259.                      l_bias = 1;
  260.                   }
  261.                } else {
  262.  
  263.                   /*
  264.                   ** See if we have a line number inhibit
  265.                   */
  266.                   if (((*argv)[1] == 'L') || ((*argv)[1] == 'l')) {
  267.                      if (l_num == TRUE) {
  268.                         l_num = FALSE;
  269.                         l_wid = 79;
  270.                      } else {
  271.                         l_num = TRUE;
  272.                         l_wid = 71;
  273.                      }
  274.                   } else {
  275.  
  276.                      /*
  277.                      ** See if we need to adjust for a laser
  278.                      */
  279.                      if (((*argv)[1] == 'N') || ((*argv)[1] == 'n')) {
  280.                         if (no_ecr == TRUE) {
  281.                            no_ecr = FALSE;
  282.                         } else {
  283.                            no_ecr = TRUE;
  284.                         }
  285.                      } else {
  286.  
  287.                         /*
  288.                         ** See if we should pause between pages
  289.                         */
  290.                         if (((*argv)[1] == 'P') || ((*argv)[1] == 'p')) {
  291.                            if (page_pause == FALSE) {
  292.                               page_pause = TRUE;
  293.                            } else {
  294.                               page_pause = FALSE;
  295.                            }
  296.                         } else {
  297.  
  298.                            /*
  299.                            ** See if we should pause between files
  300.                            */
  301.                            if (((*argv)[1] == 'F') || ((*argv)[1] == 'f')) {
  302.                               if (file_pause == FALSE) {
  303.                                  file_pause = TRUE;
  304.                               } else {
  305.                                  file_pause = FALSE;
  306.                               }
  307.                            } else {
  308.  
  309.                               /*
  310.                               ** Option? I don know dis stenkin option...
  311.                               */
  312.                               sprintf (sptr,
  313.                                  "\007Error: Invalid command argument.");
  314.                               center_scr (sptr, WIDTH, TRUE);
  315.                               sptr = to_screen;
  316.                            }
  317.                         }
  318.                      }
  319.                   }
  320.                }
  321.             }
  322.          } else {
  323.  
  324.             /*
  325.             ** See if they want help
  326.             */
  327.             if ((*argv)[0] == '?') {
  328.                help ();
  329.                go_away (1);
  330.             } else {
  331.  
  332.                /*
  333.                ** No it's just your plain old everyday non-existant
  334.                ** file
  335.                */
  336.                sprintf (sptr, "\007Error: Unable to open %s.", *argv);
  337.                center_scr (sptr, WIDTH, TRUE);
  338.                sptr = to_screen;
  339.             }
  340.          }
  341.       } else {
  342.  
  343.          /*
  344.          ** Initialize things since we have a new file to do
  345.          */
  346.          ccount = 0;          /* Character counter (internal)        */
  347.          tcount = 0;          /* Real line counter (internal)        */
  348.          ocount = 0;          /* Output buffer, line counter         */
  349.          pcount = 1;          /* Page counter (for display)          */
  350.          lcount = l_bias;     /* Output line counter (for display)   */
  351.                               /* It is set to the current or default */
  352.                               /* bias                                */
  353.          sptr = to_screen;    /* Point to the screen output buffer   */
  354.  
  355.          /*
  356.          ** Adjust the line width trigger if we are adjusting for a
  357.          ** laser or if we have inhibited line numbers
  358.          */
  359.          if (l_num == TRUE) {
  360.             l_wid = 71;       /* 72 characters if we are numbering   */
  361.          } else {
  362.             l_wid = 79;       /* 80 characters if not                */
  363.          }
  364.  
  365.          /*
  366.          ** Let the world know of our dirty deeds
  367.          */
  368.          sprintf (sptr, "Printing %s", *argv);
  369.          center_scr (sptr, WIDTH, FALSE);
  370.          sptr = to_screen;
  371.  
  372.          /*
  373.          ** Print a title on the listing
  374.          */
  375.          strcpy (title, "File : ");
  376.          sprintf (junk, "%s", *argv);
  377.          strcat (title, junk);
  378.          tcount = 5;
  379.          if (first1) {
  380.  
  381.             /*
  382.             ** This is the first time around so double up on the C/R
  383.             */
  384.             if (no_ecr == TRUE) {
  385.                fprintf (stdprn, "\012\015\012\015");
  386.             } else {
  387.                fprintf (stdprn, "\n\n");
  388.             }
  389.          } else {
  390.  
  391.             /*
  392.             ** Once the initial page is done, we need only do a
  393.             ** single C/R
  394.             */
  395.             if (no_ecr == TRUE) {
  396.                fprintf (stdprn, "\012\015");
  397.             } else {
  398.                fprintf (stdprn, "\n");
  399.             }
  400.          }
  401.          center_prn (stdprn, title, WIDTH, TRUE);
  402.          if (first1) {
  403.  
  404.             /*
  405.             ** This is the first time around so double up on the C/R
  406.             */
  407.             if (no_ecr == TRUE) {
  408.                fprintf (stdprn, "\012\015\012\015");
  409.             } else {
  410.                fprintf (stdprn, "\n\n");
  411.             }
  412.             first1 = FALSE;
  413.          } else {
  414.  
  415.             /*
  416.             ** Once the initial page is done, we need only do a
  417.             ** single C/R
  418.             */
  419.             if (no_ecr == TRUE) {
  420.                fprintf (stdprn, "\012\015\012\015");
  421.             } else {
  422.                fprintf (stdprn, "\n\n");
  423.             }
  424.          }
  425.  
  426.          /*
  427.          ** Initialize text buffer for output
  428.          */
  429.          lptr = lineout;
  430.          for (i = 0; i <= BSIZE; i++) {
  431.             *lptr = BLANK;
  432.             lptr++;
  433.          }
  434.          lcount = l_bias;
  435.          lptr = lineout;
  436.  
  437.          /*
  438.          ** Start grabbing data from the input file
  439.          */
  440.          wrap = FALSE;
  441.          c = get_stuff (fin);
  442.          while (c != EOF) {
  443.             ccount = ccount + 1;
  444.  
  445.             /*
  446.             ** Output the line if we get a newline
  447.             */
  448.             if (c == '\n') {
  449.  
  450.                /*
  451.                ** Process a wrapped line
  452.                */
  453.                if (ocount > l_wid && wrap == TRUE) {
  454.                   if (l_num == TRUE) {
  455.                      if (no_ecr == TRUE) {
  456.                         fprintf (stdprn, "------> %-72.72s%\012\015",
  457.                            lineout);
  458.                      } else {
  459.                         fprintf (stdprn, "------> %-72.72s\n",
  460.                            lineout);
  461.                      }
  462.                   } else {
  463.                      if (no_ecr == TRUE) {
  464.                         fprintf (stdprn, "%-80.80s\012\015",
  465.                            lineout);
  466.                      } else {
  467.                         fprintf (stdprn, "%-80.80s\n",
  468.                            lineout);
  469.                      }
  470.                   }
  471.                } else {
  472.  
  473.                   /*
  474.                   ** Otherwise show a normal numbered one
  475.                   */
  476.                   if (l_num == TRUE) {
  477.                      if (no_ecr == TRUE) {
  478.                         fprintf (stdprn, "%7d %-72.72s\012\015",
  479.                            lcount, lineout);
  480.                      } else {
  481.                         fprintf (stdprn, "%7d %-72.72s\n",
  482.                            lcount, lineout);
  483.                      }
  484.                   } else {
  485.                      if (no_ecr == TRUE) {
  486.                         fprintf (stdprn, "%-80.80s\012\015",
  487.                            lineout);
  488.                      } else {
  489.                         fprintf (stdprn, "%-80.80s\n",
  490.                            lineout);
  491.                      }
  492.                   }
  493.                }
  494.  
  495.                /*
  496.                ** Set things up for the next line
  497.                */
  498.                wrap = FALSE;
  499.                ccount = ocount = 0;
  500.                fflush (stdprn);
  501.                lptr = lineout;
  502.                for (i = 0; i <= BSIZE; i++) {
  503.                   *lptr = BLANK;
  504.                   lptr++;
  505.                }
  506.                lptr = lineout;
  507.                tcount++;
  508.                lcount++;
  509.  
  510.                /*
  511.                ** Put a warm fuzzy on the screen every 10 lines
  512.                */
  513.                if (l_bias == 1) {
  514.                   xcount = lcount;
  515.                } else {
  516.                   xcount = lcount - l_bias;
  517.                }
  518.                if (l_bias == 1) {
  519.                   fuzzy = lcount / 10;
  520.                } else {
  521.                   fuzzy = (lcount - l_bias) / 10;
  522.                }
  523.                if ((fuzzy * 10) == xcount) {
  524.                   sprintf (sptr, "Printing %s. %d lines so far.",
  525.                      *argv, xcount);
  526.                   center_scr (sptr, WIDTH, FALSE);
  527.                   sptr = to_screen;
  528.                }
  529.             } else {
  530.  
  531.                /*
  532.                ** Do a clean line wrap if the line get's too long
  533.                */
  534.                if (ocount > l_wid && wrap == FALSE) {
  535.                   wrap = TRUE;
  536.                   if (l_num == TRUE) {
  537.  
  538.                      /*
  539.                      ** If we are doing line numbers we have to shift
  540.                      ** the text over a bit
  541.                      */
  542.                      if (no_ecr == TRUE) {
  543.                         fprintf (stdprn, "%7d %-72.72s\012\015",
  544.                            lcount, lineout);
  545.                      } else {
  546.                         fprintf (stdprn, "%7d %-72.72s\n",
  547.                            lcount, lineout);
  548.                      }
  549.                   } else {
  550.  
  551.                      /*
  552.                      ** Simply print the text if we don't have line
  553.                      ** numbers
  554.                      */
  555.                      if (no_ecr == TRUE) {
  556.                         fprintf (stdprn, "%-80.80s\012\015",
  557.                            lineout);
  558.                      } else {
  559.                         fprintf (stdprn, "%-80.80s\n",
  560.                            lineout);
  561.                      }
  562.                   }
  563.                   tcount++;
  564.  
  565.                   /*
  566.                   ** Start the next line to be output
  567.                   */
  568.                   lptr = lineout;
  569.                   for (i = 0; i <= BSIZE; i++) {
  570.                      *lptr = BLANK;
  571.                      lptr++;
  572.                   }
  573.                   lptr = lineout;
  574.                   ccount = 0;
  575.                   *lptr = c;
  576.                   lptr++;
  577.                   ocount++;
  578.                } else {
  579.  
  580.                   /*
  581.                   ** Otherwise just put the character into the output
  582.                   ** buffer
  583.                   */
  584.                   *lptr = c;
  585.                   lptr++;
  586.                   ocount++;
  587.                }
  588.             }
  589.  
  590.             /*
  591.             ** If end of page do footer and advance a page
  592.             */
  593.             if (tcount >= PAGELEN) {
  594.                strcpy (footer, " \0");
  595.                strcpy (footer, "Page : ");
  596.                strcpy (junk, " \0");
  597.                sprintf (junk, "%5d\014", pcount);
  598.                strcat (footer, junk);
  599.                if (no_ecr == TRUE) {
  600.                   fprintf (stdprn, "\012\015\012\015");
  601.                } else {
  602.                   fprintf (stdprn, "\n\n");
  603.                }
  604.                center_prn (stdprn, footer, WIDTH, FALSE);
  605.                tcount = 0;
  606.                tof = TRUE;
  607.                fflush (stdprn);
  608.                new_page();
  609.             }
  610.  
  611.             /*
  612.             ** Grab another character
  613.             */
  614.             c = get_stuff (fin);
  615.  
  616.             /*
  617.             ** Do a top of form if needed and not EOF
  618.             */
  619.             if (tof == TRUE && c != EOF) {
  620.                pcount++;
  621.                tcount = 5;
  622.                if (no_ecr == TRUE) {
  623.                   fprintf (stdprn, "\012\015");
  624.                } else {
  625.                   fprintf (stdprn, "\n");
  626.                }
  627.  
  628.                /*
  629.                ** Print the title on the top of the page
  630.                */
  631.                center_prn (stdprn, title, WIDTH, TRUE);
  632.                if (no_ecr == TRUE) {
  633.                   fprintf (stdprn, "\012\015\012\015");
  634.                } else {
  635.                   fprintf (stdprn, "\n\n");
  636.                }
  637.  
  638.                tof = FALSE;
  639.             }
  640.          }
  641.  
  642.          /*
  643.          ** Finish off any partial line that may be left over
  644.          */
  645.          if (ccount > 0) {
  646.             if (wrap == TRUE) {
  647.                if (l_num == TRUE) {
  648.  
  649.                   /*
  650.                   ** If we are doing line numbers we have to shift
  651.                   ** the text over a bit
  652.                   */
  653.                   if (no_ecr == TRUE) {
  654.                      fprintf (stdprn, "------> %-72.72s\012\015",
  655.                         lineout);
  656.                   } else {
  657.                      fprintf (stdprn, "------> %-72.72s\n",
  658.                         lineout);
  659.                   }
  660.                } else {
  661.  
  662.                   /*
  663.                   ** Simply print the text if we don't have line
  664.                   ** numbers
  665.                   */
  666.                   if (no_ecr == TRUE) {
  667.                      fprintf (stdprn, "%-80.80s\012\015",
  668.                         lineout);
  669.                   } else {
  670.                      fprintf (stdprn, "%-80.80s\n",
  671.                         lineout);
  672.                   }
  673.                }
  674.                wrap = FALSE;
  675.             } else {
  676.                if (l_num == TRUE) {
  677.  
  678.                   /*
  679.                   ** If we are doing line numbers we have to shift
  680.                   ** the text over a bit
  681.                   */
  682.                   if (no_ecr == TRUE) {
  683.                      fprintf (stdprn, "%7d %-72.72s\012\015",
  684.                         lcount, lineout);
  685.                   } else {
  686.                      fprintf (stdprn, "%7d %-72.72s\n",
  687.                         lcount, lineout);
  688.                   }
  689.                } else {
  690.  
  691.                   /*
  692.                   ** Simply print the text if we don't have line
  693.                   ** numbers
  694.                   */
  695.                   if (no_ecr == TRUE) {
  696.                      fprintf (stdprn, "%-80.80s\012\015",
  697.                         lineout);
  698.                   } else {
  699.                      fprintf (stdprn, "%-80.80s\n",
  700.                         lineout);
  701.                   }
  702.                }
  703.             }
  704.             fflush (stdprn);
  705.             tcount++;
  706.             lcount++;
  707.          }
  708.  
  709.          /*
  710.          ** Finish the page and force a form feed between files
  711.          */
  712.          lcount--;
  713.          if (l_bias == 1) {
  714.             xcount = lcount;
  715.          } else {
  716.             xcount = lcount - l_bias;
  717.          }
  718.          sprintf (sptr, "Printing %s done, %d lines printed.",
  719.             *argv, xcount);
  720.          center_scr (sptr, WIDTH, FALSE);
  721.          sptr = to_screen;
  722.          printf ("\n");
  723.          if (l_bias == 1) {
  724.             acount = acount + lcount;
  725.          } else {
  726.             acount = acount + (lcount - l_bias);
  727.          }
  728.          if (tcount != 0) {
  729.  
  730.             /*
  731.             ** Purge line buffer if we have a partial line
  732.             ** (EOF without EOL)
  733.             */
  734.             pad = PAGELEN - tcount;
  735.             for (i = 0; i <= pad; i++) {
  736.                if (no_ecr == TRUE) {
  737.                   fprintf (stdprn, "\012\015");
  738.                } else {
  739.                   fprintf (stdprn, "\n");
  740.                }
  741.             }
  742.             if (no_ecr == TRUE) {
  743.                fprintf (stdprn, "\012\015");
  744.             } else {
  745.                fprintf (stdprn, "\n");
  746.             }
  747.             strcpy (footer, " \0");
  748.             strcpy (footer, "Page : ");
  749.             strcpy (junk, " \0");
  750.             sprintf (junk, "%5d\014", pcount);
  751.             strcat (footer, junk);
  752.             center_prn (stdprn, footer, WIDTH, FALSE);
  753.             fflush (stdprn);
  754.             new_file();
  755.          }
  756.          fclose (fin);
  757.          l_bias = 1;
  758.       }
  759.    }
  760.  
  761.    /*
  762.    ** Say goodnight...
  763.    */
  764.    printf ("\n");
  765.    sprintf (sptr, "Total lines printed was %d.", acount);
  766.    center_scr (sptr, WIDTH, TRUE);
  767.    sptr = to_screen;
  768.    center_scr ("Done!", WIDTH, TRUE);
  769.    go_away(0);
  770. }
  771.  
  772. /**********************************************************************
  773. **                                                                   **
  774. ** ret = get_stuff (stream)                                          **
  775. **                                                                   **
  776. ** Simply reads characters from the file stream and returns it as    **
  777. ** an integer character. If the tab expansion is on and a tab        **
  778. ** character is detected it will be expanded with spaces to the      **
  779. ** requested size                                                    **
  780. **                                                                   **
  781. **********************************************************************/
  782.  
  783. int
  784. get_stuff (st)
  785.  
  786. FILE  *st;                    /* Input stream handle                 */
  787.  
  788.    {
  789.  
  790.    /*
  791.    ** See if we are expanding a tab character
  792.    */
  793.    if (last_char == TAB) {
  794.  
  795.       /*
  796.       ** Finish up the expansion if we reach tab size + 1
  797.       */
  798.       if ((ocount % tab_set) == 0) {
  799.          ch = getc (st);
  800.          cntr = FALSE;
  801.          last_char = ch;
  802.       } else {
  803.  
  804.          /*
  805.          ** Otherwise substitute a blank
  806.          */
  807.          ch = BLANK;
  808.       }
  809.    } else {
  810.  
  811.       /*
  812.       ** If we aren't expanding tabs then simply pass on the
  813.       ** character
  814.       */
  815.       ch = getc (st);
  816.       last_char = ch;
  817.       cntr = FALSE;
  818.    }
  819.  
  820.    /*
  821.    ** See if the current character is a tab, if so start expansion
  822.    */
  823.    if (ch == TAB) {
  824.       ch = BLANK;
  825.       cntr = TRUE;
  826.    }
  827.  
  828.    /*
  829.    ** Return with expansion or a new character
  830.    */
  831.    return (ch);
  832. }
  833.  
  834. /**********************************************************************
  835. **                                                                   **
  836. ** center_prn (strm, text, width, flag)                              **
  837. **                                                                   **
  838. ** Centers "text" within "width" and sends the result to "stream" If **
  839. ** "flag" is true end with a newline.                                **
  840. **                                                                   **
  841. **********************************************************************/
  842.  
  843. int
  844. center_prn (strm, text, width, flag)
  845.  
  846. FILE          *strm;          /* Output stream                       */
  847.  
  848. unsigned char *text;          /* Text to center                      */
  849.  
  850. int           width,          /* Width to center within              */
  851.               flag;           /* Newline flag                        */
  852.  
  853. {
  854.    int   i,                   /* Intermediate input buffer           */
  855.          to_pad;              /* Padding buffer                      */
  856.  
  857.    /*
  858.    ** Determine the length of "text" and use it to calculate
  859.    ** the padding we need to do, pad the line and output the
  860.    ** text
  861.    */
  862.    to_pad = (width - strlen (text)) / 2;
  863.    if (no_ecr == TRUE)
  864.       to_pad = to_pad - 2;
  865.    for (i = 0; i <= to_pad; i++)
  866.       fprintf (strm, " ");
  867.    fprintf (strm, "%s", text);
  868.    if (flag == TRUE) {
  869.       if (no_ecr == TRUE) {
  870.          fprintf (strm, "\012\015");
  871.       } else {
  872.          fprintf (strm, "\n");
  873.       }
  874.    }
  875.    return (0);
  876. }
  877.  
  878. /**********************************************************************
  879. **                                                                   **
  880. ** center_scr (text, width, flag)                                    **
  881. **                                                                   **
  882. ** Centers "text" within "width" and sends the result to stdout. If  **
  883. ** "flag" is true, do a newline                                      **
  884. **                                                                   **
  885. **********************************************************************/
  886.  
  887. int
  888. center_scr (text, width, flag)
  889.  
  890. unsigned char *text;          /* Text to be centered                 */
  891.  
  892. int           width,          /* Width to center within              */
  893.               flag;           /* If true finish with a newline       */
  894. {
  895.    int   i,                   /* Intermediate character              */
  896.          to_pad;              /* Padding buffer                      */
  897.  
  898.    /*
  899.    ** Determine the length of "text" and use it to calculate the
  900.    ** padding we need to do, pad the line and output the text
  901.    */
  902.    to_pad = (width - strlen (text)) / 2;
  903.    printf ("\r");
  904.    for (i = 0; i <= to_pad; i++)
  905.       printf (" ");
  906.    printf ("%s", text);
  907.    if (flag == TRUE) {
  908.       printf ("\n");
  909.    }
  910.    return (0);
  911. }
  912.  
  913. /**********************************************************************
  914. **                                                                   **
  915. ** go_away (exitval)                                                 **
  916. **                                                                   **
  917. ** Exit with exitval but if this is Atari GEMDOS then prompt for a   **
  918. ** character before returning to shell or desktop                    **
  919. **                                                                   **
  920. **********************************************************************/
  921.  
  922. go_away (exitval)
  923. int exitval;
  924. {
  925.  
  926.    int   c;                   /* Scratch input byte                  */
  927.  
  928. #if GEMDOS
  929.    center_scr (" ", WIDTH, TRUE);
  930.    center_scr ("Press Return/Enter for the desktop or shell.",
  931.                WIDTH, TRUE);
  932.    c = getc (stdin);
  933. #endif
  934.    exit (exitval);
  935. }
  936.  
  937. /**********************************************************************
  938. **                                                                   **
  939. ** help ()                                                           **
  940. **                                                                   **
  941. ** This routine simply displays program information                  **
  942. **                                                                   **
  943. **********************************************************************/
  944.  
  945. help () {
  946.  
  947. #if GEMDOS
  948.    center_scr (
  949.      "usage: MLIST [-t tab] [-b bias] [-l] [-n] [-p] [-f] file [file [...]]",
  950.      WIDTH, TRUE);
  951. #else
  952.    center_scr (
  953.      "usage: MLIST [/t tab] [/b bias] [/l] [/n] [/p] [/f] file [file [...]]",
  954.      WIDTH, TRUE);
  955. #endif
  956.    center_scr (" ", WIDTH, TRUE);
  957.    center_scr (
  958.      "?    = This HELP screen.                                    ",
  959.      WIDTH, TRUE);
  960.    center_scr (
  961.      "/t   = Tab stop change option.                              ",
  962.      WIDTH, TRUE);
  963.    center_scr (
  964.      "/b   = Bias line number option.                             ",
  965.      WIDTH, TRUE);
  966.    center_scr (
  967.      "/l   = Inhibit line numbers option toggle (default off).    ",
  968.      WIDTH, TRUE);
  969.    center_scr (
  970.      "/n   = Newline for lasers (LF-GR) toggle (default off).     ",
  971.      WIDTH, TRUE);
  972.    center_scr (
  973.      "/p   = Pause between pages toggle (default off).            ",
  974.      WIDTH, TRUE);
  975.    center_scr (
  976.      "/f   = Pause between files toggle (default off).            ",
  977.      WIDTH, TRUE);
  978.    center_scr (
  979.      "tab  = Tab expansion of 2 to 255 (defaults to 8).           ",
  980.      WIDTH, TRUE);
  981.    center_scr (
  982.      "bias = Value added to line counter (defaults to 1). This is ",
  983.      WIDTH, TRUE);
  984.    center_scr (
  985.      "       most usefull for printing file fragments.            ",
  986.      WIDTH, TRUE);
  987.    center_scr (
  988.      "file = Full path name of files to print (supports wildcards)",
  989.      WIDTH, TRUE);
  990.    center_scr (" ", WIDTH, TRUE);
  991.    center_scr (
  992.      "Note: Options selected remain in effect until changed or the",
  993.      WIDTH, TRUE);
  994.    center_scr (
  995.      "      program terminates.                                   ",
  996.      WIDTH, TRUE);
  997.  
  998. }
  999.  
  1000. /**********************************************************************
  1001. **                                                                   **
  1002. ** new_page ()                                                       **
  1003. **                                                                   **
  1004. ** If needed, prompt for and wait for a keypress from the user. This **
  1005. ** gives them time to load single sheet paper                        **
  1006. **                                                                   **
  1007. **********************************************************************/
  1008.  
  1009. new_page () {
  1010.  
  1011.    int   gleep;
  1012.  
  1013.    if (page_pause == TRUE) {
  1014.       center_scr ("                                                          ", WIDTH, FALSE);
  1015.       center_scr ("Please ready printer for new page, press a key when ready.", WIDTH, FALSE);
  1016.       gleep = getch();
  1017.       center_scr ("                                                          ", WIDTH, FALSE);
  1018.    }
  1019. }
  1020.  
  1021. /**********************************************************************
  1022. **                                                                   **
  1023. ** new_file ()                                                       **
  1024. **                                                                   **
  1025. ** If needed, prompt for and wait for a keypress from the user. This **
  1026. ** gives them time to prepare for a new file.                        **
  1027. **                                                                   **
  1028. **********************************************************************/
  1029.  
  1030. new_file () {
  1031.  
  1032.    char  *slop;
  1033.    int   gleep;
  1034.  
  1035.    if (file_pause == TRUE) {
  1036.       center_scr ("                                                          ", WIDTH, FALSE);
  1037.       center_scr ("Please ready printer for new file, press a key when ready.", WIDTH, FALSE);
  1038.       gleep = getch();
  1039.       center_scr ("                                                          ", WIDTH, FALSE);
  1040.    }
  1041. }
  1042.