home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sun / admin / 4992 < prev    next >
Encoding:
Text File  |  1992-07-27  |  4.3 KB  |  187 lines

  1. Newsgroups: comp.sys.sun.admin
  2. Path: sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!zrz.tu-berlin.de!math.fu-berlin.de!Sirius.dfn.de!Urmel.Informatik.RWTH-Aachen.DE!martha!peter
  3. From: peter@martha.informatik.rwth-aachen.de (Peter Heimann)
  4. Subject: Re: Help! pac does'nt work
  5. Message-ID: <peter.712237768@rwthi3>
  6. Keywords: pac, printer accounting
  7. Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
  8. Nntp-Posting-Host: martha
  9. Reply-To: peter@rwthi3.informatik.rwth-aachen.de
  10. Organization: Informatik III, RWTH Aachen
  11. References: <1992Jul22.175929.12505@Logibec.COM>
  12. Date: 27 Jul 92 11:49:28 GMT
  13. Lines: 172
  14.  
  15. In <1992Jul22.175929.12505@Logibec.COM> guy@Logibec.COM (Guy Thibault) writes:
  16. >I try to use the command pac and the resuslt is always
  17. >  Login               pages/feet   runs    price
  18. >total                       0.00    0   $  0.00
  19.  
  20. In the BSD printer spooling system, the input filter has to write the page
  21. accounting entries. In the standard SunOS distribution, no filter for this
  22. purpose is provided.
  23.  
  24. A while ago, I simplified the vpf filter from the freely available
  25. BSD sources and turned it into a simple input filter for line printers -
  26. see code below.
  27. Compile, install the filter in /usr/local/bin (or wherever you put local
  28. enhancements and optional software) and add
  29.     :af=/var/adm/lp.acct:\
  30.     :if=/usr/local/bin/ipf:
  31. to the /etc/printcap file.
  32.  
  33. --- Peter Heimann
  34.  
  35. Lehrstuhl fuer Informatik III        peter@rwthi3.informatik.rwth-aachen.de
  36. RWTH Aachen
  37.  
  38. ------- cut here - c program follows -------------------------------------
  39. /* ipf
  40.  * A simple pass-through input filter for line printers
  41.  * Does page accounting, expands tabs, indents, chops long lines.
  42.  *
  43.  * 11.11.1991
  44.  *   Peter Heimann, Lehrstuhl fuer Informatik III, RWTH Aachen
  45.  *   peter@rwthi3.informatik.rwth-aachen.de
  46.  *
  47.  * Tested on Sun3 (SunOS 4.0.3) and Sun4 (SunOS 4.1.1+4.1.2)
  48.  * Use this code at your own risk.
  49.  *
  50.  * Based on ideas from the BSD vpf filter,
  51.  *   Copyright (c) 1983 Regents of the University of California.
  52.  *   All rights reserved.
  53.  */
  54.  
  55. #include <stdio.h>
  56.  
  57. #define LINELN 140
  58.  
  59. int    lineno;
  60. int    width = 132;    /* default line length */
  61. int    indent = 0;    /* default indent length */
  62. int    length = 72;    /* 72 for 12" long paper */
  63. int    npages = 0;
  64. int    literal;
  65. char    *name;        /* user's login name */
  66. char    *host;        /* user's machine name */
  67. char    *acctfile;    /* accounting information file */
  68.  
  69. main(argc, argv)
  70.     int argc;
  71.     char *argv[];
  72. {
  73.     register int i;
  74.  
  75.     while (--argc) {
  76.         if (*(*++argv) == '-') {
  77.             switch (argv[0][1]) {
  78.             case 'n':
  79.                 argc--;
  80.                 name = *++argv;
  81.                 break;
  82.  
  83.             case 'h':
  84.                 argc--;
  85.                 host = *++argv;
  86.                 break;
  87.  
  88.             case 'w':
  89.                 if ((i = atoi(&argv[0][2])) > 0 && i < LINELN)
  90.                     width = i;
  91.                 break;
  92.  
  93.             case 'l':
  94.                 length = atoi(&argv[0][2]);
  95.                 break;
  96.  
  97.             case 'i':
  98.                 if ((i = atoi(&argv[0][2])) >= 0 &&
  99.                     i < LINELN - 1)
  100.                     indent = i;
  101.                 break;
  102.  
  103.             case 'c':    /* Print input without throwing away
  104.                        control chars and without putting
  105.                        in page breaks. */
  106.                 literal++;
  107.                 break;
  108.             }
  109.         } else
  110.             acctfile = *argv;
  111.     }
  112.     filter();
  113.     if (name && acctfile && access(acctfile, 02) >= 0 &&
  114.         freopen(acctfile, "a", stdout) != NULL) {
  115.         printf("%7.2f\t%s:%s\n", (float)npages, host, name);
  116.     }
  117.     exit(0);
  118. }
  119.  
  120. filter()
  121. {
  122.     register int c, col;
  123.  
  124.     lineno = 0;
  125.     col = 0;
  126.     while ((c = getchar()) != EOF)
  127.     {
  128.         /* put out spaces for indentation */
  129.         while ((col < indent) && (col < width))
  130.         {   
  131.         putchar(' '); col++;
  132.         }
  133.  
  134.         switch(c)
  135.         {
  136.         case '\f':
  137.             lineno = length - 1;
  138.             /* fall through, ff is line break too */
  139.         case '\n':
  140.             col = 0;
  141.             if (++lineno % length == 0)
  142.             npages++;
  143.             putchar(c);
  144.             continue;
  145.         case '\r':
  146.             col = 0;
  147.             putchar(c);
  148.             continue;
  149.         case '\b':
  150.             if (col > 0)
  151.             {
  152.             col--;
  153.             putchar(c);
  154.             }
  155.             continue;
  156.         case '\t':
  157.             if (! literal)
  158.             {
  159.             do
  160.             {
  161.                 putchar(' '); col++;
  162.             }
  163.             while ((col % 8 != 0) && (col < width));
  164.             }
  165.             continue;
  166.         default:
  167.             /* discard control chars, cut off long lines */
  168.             if (((c >= ' ') && (col < width)) || literal)
  169.             {
  170.             putchar(c); col++;
  171.             }
  172.             continue;
  173.         }
  174.     }
  175.  
  176.     /* finish the job with a formfeed, if not already on page boundary */
  177.     if ((lineno % length != 0) || (col > 0))
  178.     {
  179.         npages++;
  180.         putchar('\f');
  181.     }
  182.  
  183.     if (ferror(stdout))
  184.         exit(1);
  185. } /* filter() */
  186.  
  187.