1: /* $Header: getprintstatus.c,v 2.0 85/11/21 07:23:10 jqj Exp $ */
   2: 
   3: /*
   4:  * $Log:	getprintstatus.c,v $
   5:  * Revision 2.0  85/11/21  07:23:10  jqj
   6:  * 4.3BSD standard release
   7:  *
   8:  * Revision 1.1  85/11/20  13:56:47  jqj
   9:  * Initial revision
  10:  *
  11:  */
  12: #include <stdio.h>
  13: #include <sys/types.h>
  14: #include <netns/ns.h>
  15: #include "Printing3_defs.h"
  16: #include <xnscourier/Clearinghouse2.h>
  17: #include <xnscourier/except.h>
  18: 
  19: main(argc, argv)
  20:     int argc;
  21:     char *argv[];
  22: {
  23:     GetPrinterStatusResults result;
  24:     struct xn_addr *destaddr;
  25:     CourierConnection *conn;
  26:     char *xnshost;
  27:     extern struct xn_addr *getXNSaddr();
  28:     extern struct xn_addr *CH_LookupAddr();
  29:     Clearinghouse2_Name hostname;
  30:     static Clearinghouse2_Name defaultname = {"Cornell-Univ",
  31:         "Computer Science","Slander"};
  32:     extern Clearinghouse2_Name CH_StringToName();
  33: 
  34:     xnshost = "2-273#2-852-159-207";    /* CornellS2 */
  35: 
  36:         /* default to CornellS1 2-273, 2-852-151-014 */
  37:         /* xnshost = "8E1#00.00.AA.00.5E.E6"; */
  38: 
  39:     switch (argc) {
  40:     case 2: xnshost = argv[1];
  41:     case 1: if ((destaddr = getXNSaddr(xnshost)) != NULL)
  42:             break;      /* got a valid host number */
  43:         hostname = CH_StringToName(xnshost,&defaultname);
  44:         if ((destaddr = CH_LookupAddr(hostname)) != NULL)
  45:             break;      /* got a valid host name */
  46:         else
  47:             fprintf(stderr,"Invalid machine name.\n");
  48:     default:
  49:         fprintf(stderr,"Usage: %s [machine]\n",argv[0]);
  50:         exit(1);
  51:     }
  52: 
  53:     if ((conn = CourierOpen(destaddr)) == NULL) {
  54:         fprintf(stderr,"Can't open connection to %s\n",xnshost);
  55:         exit(1);
  56:     }
  57: 
  58:     DURING
  59:         result = GetPrinterStatus(conn,NULL);
  60:     HANDLER {
  61:         switch (Exception.Code) {
  62:         case ServiceUnavailable:
  63:             fprintf(stderr,"Service unavailable\n");
  64:             break;
  65:         case SystemError:
  66:             fprintf(stderr,"System Error\n");
  67:             break;
  68:         case Undefined:
  69:             fprintf(stderr,"Undefined error, number %d\n",
  70:                 CourierErrArgs(UndefinedArgs,problem));
  71: 
  72:         case REJECT_ERROR:
  73:             fprintf(stderr,"REJECT:  type = %d\n",
  74:                 CourierErrArgs(rejectionDetails, designator));
  75:             break;
  76:         default:
  77:             fprintf(stderr,"Some random error, code %d\n",
  78:                 Exception.Code);
  79:             break;
  80:         }
  81:     exit(1);
  82:     } END_HANDLER;
  83: 
  84:     CourierClose(conn);
  85:     printresults(result.status);
  86: }
  87: 
  88: printresults(status)
  89:     PrinterStatus status;
  90: {
  91:     int i, typ;
  92:     static char *spoollist[] = {"available","busy","disabled","full"};
  93:     static char *formatlist[] = {"available","busy","disabled"};
  94:     static char *printlist[] = {"available","busy","disabled",
  95:             "needs attention","needs key operator"};
  96: 
  97:     for (i = 0; i < status.length; i++) {
  98:         switch (status.sequence[i].designator) {
  99:         case spooler:
 100:             typ = (int) status.sequence[i].spooler_case;
 101:             printf("Spooling status:  %s\n", spoollist[typ]);
 102:             break;
 103:         case formatter:
 104:             typ = (int) status.sequence[i].formatter_case;
 105:             printf("Formatting status:  %s\n", formatlist[typ]);
 106:             break;
 107:         case printer:
 108:             typ = (int) status.sequence[i].printer_case;
 109:             printf("Printer status:  %s\n", printlist[typ]);
 110:             break;
 111:         case media:
 112:             printmedia(status.sequence[i].media_case);
 113:             break;
 114:         }
 115:     }
 116: }
 117: 
 118: printmedia(media)
 119:     Media media;
 120: {
 121:     int j;
 122:     for (j = 0; j <media.length; j++) {
 123:         switch (media.sequence[j].designator) {
 124:         case paper:
 125:             printf("Paper #%d:  ", j+1);
 126:             printpaper(media.sequence[j].paper_case);
 127:             break;
 128:         default:
 129:             printf("Unknown medium type\n");
 130:             break;
 131:         }
 132:     }
 133: }
 134: 
 135: printpaper(paper)
 136:     Paper paper;
 137: {
 138:     switch (paper.designator) {
 139:     case unknown:
 140:         printf("unknown\n");
 141:         break;
 142:     case knownSize:
 143:         switch (paper.knownSize_case) {
 144:         case usLetter:
 145:             printf("US letter\n");
 146:             break;
 147:         case usLegal:
 148:             printf("US legal\n");
 149:             break;
 150:         default:
 151:             printf("known size %d\n", paper.knownSize_case);
 152:             break;
 153:         }
 154:         break;
 155:     case otherSize:
 156:         printf("\tother size: width = %dmm, length = %d mm\n",
 157:             paper.otherSize_case.width,
 158:             paper.otherSize_case.length);
 159:         break;
 160:     default:
 161:         printf("Unknown paper type");
 162:         break;
 163:     }
 164: }

Defined functions

main defined in line 19; never used
printmedia defined in line 118; used 1 times
printpaper defined in line 135; used 1 times
printresults defined in line 88; used 1 times
  • in line 85
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 916
Valid CSS Valid XHTML 1.0 Strict