Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Section - 6.11: How can I access the comp.unix.aix newsgroup via email (or Web)?

( Part1 - Part2 - Part3 - Part4 - Part5 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Schools ]


Top Document: comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Previous Document: 6.10: Comp.unix.aix archive availible on the WWW
Next Document: 8.04: How can I find out the machine type?
See reader questions & answers on this topic! - Help others by sharing your knowledge
From: Ciaran Deignan  <C.Deignan@frec.bull.fr>

It is possible to get "digests" of the AIX newsgroup by email. Each
digest contains a summary (just the subject lines from each post)
plus the contents of a series of news articles posted to the newsgroup.
Each digest is about 800 lines long, and the newsgroup typically generates
5 digest mails per day.

To get these digests, you have to subscribe to a mailing list. Send
an email to the address majordomo@dmshome.youngstown.oh.us, and put
the text "subscribe aix-digest" in the body of the message.

[Editor's note: The above address does not appear to work any longer, if
anyone knows of a functional equivalent please drop me a note.]

It is equally possible to post articles to the newsgroup via email.
Any mail sent to the address aixnews@cc.ysu.edu will be forwarded to
the comp.unix.aix newsgroup.

These services are provided by Doug Sewell <doug@cc.ysu.edu>.

Comp.unix.aix can be accessed from the web via http://www.deja.com/

------------------------------


Subject: 8.03: How do I set up postscript accounting?

[ formerly in section 1.118 ]

/*  pswrap.c

 compile with:   cc pswrap.c -o pswrap -lqb
 (for doc on the qb library see "understanding backend routines in libqb")

 BTW:  The log_charge() function doesn't seem to do anything,
       but log_pages() updates the accounting info.

Ephraim Vider, original author 

--
Feb 10, 1993

You can set pswrap up to use either the accounting file specified in
/etc/qconfig (which means that you need to get your data from 'pac') or
you can comment out the #define WANT_PAC line and then the accounting
data will only go into the ACCTFILE.

Also modified the logging to the ASCII acctfile so that it looks more
readable.

Vince Taluskie
*/

 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <setjmp.h>
 #include <sys/wait.h>
 #include <IN/backend.h>
 #include <IN/standard.h>
 #include "qprocs.h"
 
 char     *nextword (char *p);
 char     *skipvalue (char *p);
 
 #define LOGDIR     "/tmp"
 #define ACCTFILE   "/usr/adm/acct/lpr/ps-acct"
/* #define WANT_PAC 	1 */     /* this define will also send accounting
                                 info to the acctfile specified in
				 /etc/qconfig file.  If this define is 
				 commented out then accounting info will
				 only go to ACCTFILE  */
 

 char     pcprog[] = "statusdict begin pagecount = end\n\x04";
 
 char     *keyw[] = {
     "idle",
     "busy",
     "waiting",
     "printing",
     "initializing",
     NULL
 };
 enum     { PS_IDLE, PS_BUSY, PS_WAIT, PS_PRINT, PS_INIT, PS_UNKNOWN };
 
 void     giveup();
 jmp_buf  jumper;
 
 char     logfname[30];
 FILE     *logfile, *acctfile;
 
 main (argc, argv)
 int argc;
 char     *argv[];
 {
     char *devname;
     int  pagcnt, c;
     int  pid;
     int  w, status;
 
     if (argc < 2) {
          fprintf(stderr, "Usage: psbe file\n");
          exit(-1);
     }
     if (log_init(argv[1]) < 0) {
          fprintf(stderr, "log_init failed!\n");
          exit(EXITBAD);
     }
     sprintf(logfname, "%s/%s.log", LOGDIR, get_device_name());
     if ((logfile = fopen(logfname, "a")) == NULL) {
          fprintf(stderr, "Can't open logfile.\n");
          exit(EXITBAD);
     }

     if ((acctfile = fopen(ACCTFILE, "a")) == NULL) {
	 fprintf(stderr, "Can't open logfile.\n");
	 exit(EXITBAD);
	 }

     setvbuf(logfile, NULL, _IOLBF, BUFSIZ);
     setvbuf(acctfile, NULL, _IOLBF, BUFSIZ);

     setvbuf(stdin, NULL, _IONBF, 0);
     setvbuf(stdout, NULL, _IONBF, 0);
     fprintf(logfile, "start Job no. %d, queued on %s\n", get_job_number(),
               get_qdate());
     log_status(WAITING);
     pagcnt = getpagecnt();
     log_status(RUNNING);
     if ((pid = fork()) < 0) {
          perror("fork");
          exit(EXITBAD);
     }
     if (pid == 0) {
          argv[0] = "piobe";
          execv("/usr/lpd/piobe", argv);
          perror("exec");
          exit(EXITBAD);
     }
     while ((w = wait(&status)) != pid)
          if (w == -1) {
               perror("wait");
               exit(EXITBAD);
          }
     if (WEXITSTATUS(status) != 0)
          exit(WEXITSTATUS(status));
     log_status(WAITING);

     if (pagcnt > 0 && (c = getpagecnt()) > 0) {
#ifdef WANT_PAC 
          log_pages(c - pagcnt);
#endif
	}

     fprintf(logfile, "end Job no. %d, queued on %s\n", get_job_number(),
               get_qdate());

/* the accounting file format is 

pages_printed     user     queue_printed_on   time_queued

*/

     fprintf(acctfile, "%d %35s %7s    %s \n", (c - pagcnt), get_from(), get_queue_name(), get_qdate());

     fclose(logfile);
     fclose(acctfile);
     exit(EXITOK);
 }
 
 void     giveup ()
 {
     longjmp(jumper, 1);
 }
 
 getpagecnt ()
 {
     int  pc = 0, pstat;
     char buf[81];
 
     if (setjmp(jumper) != 0) {
          fprintf(logfile, "giving up on status\n");
          return (0);
     }
     alarm(60 * 2);
     signal(SIGALRM, giveup);
     do {
          if (!gets(buf)) {
               sleep(5);
               putchar('\x14');    /* ^T returns status */
               sleep(1); /* wait for answer from printer */
               if (!gets(buf))
                    return (0);
          }
          fprintf(logfile, "%s\n", buf);
          if ((pstat = getstatus(buf)) == PS_WAIT) {
               putchar('\x04');
               sleep(1);
          }
     } while (pstat != PS_IDLE);
     alarm(0);
     while (gets(buf))
          fprintf(logfile, "%s\n", buf);
     printf("%s", pcprog);
     sleep(1); /* wait for answer from printer */
     if (!gets(buf))
          return (0);
     if (sscanf(buf, "%d", &pc) != 1)
          return (0);
     fprintf(logfile, "%d\n", pc);
     return (pc);
 }
 
 /*
  * Parser for printer status messages
  */
 
 getstatus (p)
 char     *p;
 {
     char *t;
     int  i;
 
     if ((p = strchr(p, '%')) == NULL)
          return (PS_UNKNOWN);
     if (strncmp(p, "%%[", 3) != 0)
          return (PS_UNKNOWN);
     for (p = nextword(p + 3) ; p != NULL ; p = skipvalue(p)) {
          t = p;
          p = strchr(p, ':');
          *p++ = '\0';
          p = nextword(p);
          if (strcmp(t, "status") == 0)
               break;
     }
     if (p == NULL)
          return (PS_UNKNOWN);
     t = p;
     p = strchr(p, ' ');
     if (p[-1] == ';')
          p--;
     *p = '\0';
     for (i = 0 ; keyw[i] != NULL ; i++)
          if (strcmp(t, keyw[i]) == 0)
               break;
     return (i);
 }
 
 char     *nextword (p)
 char     *p;
 {
     while (isspace(*p))
          p++;
     if (strncmp(p, "]%%", 3) == 0)
          return (NULL);
     return (p);
 }
 
 char     *skipvalue (p)
 char     *p;
 {
     char *t;
 
     while (p != NULL) {
          p = strchr(p, ' ');
          t = p;
          p = nextword(p);
          if (t[-1] == ';')
               break;
     }
     return (p);
 }

 /*********    qprocs.h    ***********/
 /* functions for communication between qdaemon and the backend */
 
 char     *get_from();
 char     *get_to();
 char     *get_qdate();
 char     *get_queue_name();
 char     *get_device_name();
 char     *get_title();


User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Previous Document: 6.10: Comp.unix.aix archive availible on the WWW
Next Document: 8.04: How can I find out the machine type?

Part1 - Part2 - Part3 - Part4 - Part5 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
bofh@mail.teleweb.pt (Jose Pina Coelho)





Last Update March 27 2014 @ 02:11 PM