home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / s / select14.zip / SELECT.CPP < prev    next >
Text File  |  1992-10-22  |  20KB  |  967 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4. #include <dir.h>
  5. #include <string.h>
  6. #include <mem.h>
  7. #include <stdlib.h>
  8. #include <graphics.h>
  9. #include <ctype.h>
  10.  
  11. typedef unsigned char BYTE;
  12. typedef unsigned int  WORD;
  13. typedef unsigned long LONG;
  14.  
  15. #define zap(a)                {memset ( &a, NULL, sizeof(a));}
  16. #define MaxLines            20
  17.  
  18. struct scanBindReq {
  19.     WORD    Length;
  20.     BYTE    Function;
  21.     LONG    LastObjectID;
  22.     WORD    ObjectType;
  23.     BYTE    ObjectNameLength;
  24.     BYTE    ObjectName[48];
  25.     };
  26.  
  27. struct scanBindRep {
  28.     WORD    Length;
  29.     LONG    ObjectID;
  30.     WORD    ObjectType;
  31.     BYTE    ObjectName[48];
  32.     BYTE    ObjectFlag;
  33.     BYTE    ObjectSecurity;
  34.     BYTE    ObjectHasProperties;
  35.     };
  36.  
  37. struct readPropValueReq {
  38.     WORD     Length;
  39.     BYTE    Function;
  40.     WORD    ObjectType;
  41.     BYTE    ObjectNameLength;
  42.     BYTE    ObjectName[48];
  43.     BYTE    SegmentNumber;
  44.     BYTE    PropertyNameLength;
  45.     BYTE    PropertyName[16];
  46.     };
  47.  
  48. struct readPropValueRep {
  49.     WORD    Length;
  50.     BYTE    PropertyValue[128];
  51.     BYTE    MoreSegments;
  52.     BYTE    PropertyFlags;
  53.     };
  54.  
  55. struct readQueueStatReq {
  56.     WORD    Length;
  57.     BYTE    Function;
  58.     LONG    ObjectID;
  59.     };
  60.  
  61. struct readQueueStatRep {
  62.     WORD    Length;
  63.     LONG    ObjectID;
  64.     BYTE    QueueStatus;
  65.     BYTE    NumberOfJobs;
  66.     BYTE    NumberOfServers;
  67.     LONG    ServerID[25];
  68.     BYTE    ServerStation[25];
  69.     BYTE    MaxServers;
  70.     };
  71.  
  72. struct getBindObjNameReq {
  73.     WORD    Length;
  74.     BYTE    Function;
  75.     LONG    ObjectID;
  76.     };
  77.  
  78. struct getBindObjNameRep {
  79.     WORD    Length;
  80.     LONG    ObjectID;
  81.     WORD    ObjectType;
  82.     BYTE    ObjectName[48];
  83.     };
  84.  
  85. char ProgName[]="Select";
  86. int  VerMaj=1;
  87. int  VerMin=4;
  88. char ENET[]="000000000000";
  89. char *ptr;
  90. FILE *LocationSrt;
  91. char DefQ[48];
  92. char qlst[100][100];
  93. char qloc[100][100];
  94. int  qrdy[100];
  95. int  qcnt=0;
  96. int  MaxQueueNameLength=0;
  97. int  MaxServerNameLength=0;
  98. int  Banner=1;
  99. int  LptNum=1;
  100. int  timeout=30;
  101. int  xl,xh,yl,yh;
  102. char *qstat[]={    "  <Off>  ",
  103.                 "Available",
  104.                 " Default ",
  105.                 "  Local  "};
  106.  
  107. int API_E3(void *Request, void *Reply)
  108. {
  109.     _SI=(unsigned)Request;
  110.     _DI=(unsigned)Reply;
  111.     _ES=_DS;
  112.     _AH=0xE3;
  113.     geninterrupt(0x21);
  114.     return(_AL);
  115. }
  116.  
  117. void pause()
  118. {
  119.     getch();
  120. }
  121.  
  122. void perror(int ern)
  123. {
  124.     switch (ern)
  125.     {
  126.         case 0x00: printf("Success\n");                  break;
  127.         case 0x96: printf("Server Out Of Memory\n");     break;
  128.         case 0x9C: printf("Invalid Path\n");             break;
  129.         case 0xD0: printf("Q Error\n");                  break;
  130.         case 0xD1: printf("No Queue\n");                 break;
  131.         case 0xD2: printf("No Q Server\n");              break;
  132.         case 0xD3: printf("No Q Rights\n");              break;
  133.         case 0xD5: printf("No Q Job\n");                 break;
  134.         case 0xEC: printf("No Such Segment\n");          break;
  135.         case 0xEF: printf("Invalid name\n");             break;
  136.         case 0xF0: printf("Wildcard Not Allowed\n");     break;
  137.         case 0xF1: printf("Invalid Bindary Security\n"); break;
  138.         case 0xFB: printf("No Such Property\n");         break;
  139.         case 0xFC: printf("No Such Object\n");           break;
  140.         case 0xFE: printf("Server Bindary Locked\n");    break;
  141.         case 0xFF: printf("Bindary Failure\n");          break;
  142.         default:   printf("Unknown error #%2x#2\n",ern); break;
  143.     }
  144. }
  145.  
  146. int ScanBinderyObject (char *searchObjectName, WORD searchObjectType,
  147.     long *objectID, char *objectName, WORD *objectType,
  148.     char *objectHasProperties, char *objectFlag,
  149.     char *objectSecurity)
  150. {
  151.     static long Last_ObjectID=0xFFFFFFFF;
  152.  
  153.     struct scanBindReq Request;
  154.     struct scanBindRep Reply;
  155.  
  156.     int result;
  157.  
  158. //    memset ( & Request, NULL, sizeof(Request));
  159. //    memset ( & Reply,   NULL, sizeof(Reply  ));
  160.     zap(Request);
  161.     zap(Reply);
  162.  
  163.     Request.Length=          sizeof(Request)-2;
  164.     Request.Function=        0x37;
  165.     Request.LastObjectID=    Last_ObjectID;
  166.     Request.ObjectType=      searchObjectType;
  167.     Request.ObjectNameLength=strlen(searchObjectName);
  168.     strcpy(Request.ObjectName,searchObjectName);
  169.  
  170.     Reply.Length=sizeof(Reply)-2;
  171.  
  172.     result=API_E3(&Request,&Reply);
  173.  
  174.     *objectID           =Reply.ObjectID;
  175.     strcpy(objectName,Reply.ObjectName);
  176.     *objectType            =Reply.ObjectType;
  177.     *objectHasProperties=Reply.ObjectHasProperties;
  178.     *objectFlag         =Reply.ObjectFlag;
  179.     *objectSecurity     =Reply.ObjectSecurity;
  180.  
  181.     Last_ObjectID=*objectID;
  182.  
  183.     return (result);
  184. }
  185.  
  186. void GetPrintServerName(long qsid,char *sname)
  187. {
  188.     struct getBindObjNameReq Request;
  189.     struct getBindObjNameRep Reply;
  190.  
  191.     int result;
  192.  
  193.     zap(Request);
  194.     zap(Reply);
  195.  
  196.     Request.Length=  sizeof(Request)-2;
  197.     Request.Function=0x36;
  198.     Request.ObjectID=qsid;
  199.  
  200.     Reply.Length=    sizeof(Reply  )-2;
  201.  
  202.     result=API_E3(&Request,&Reply);
  203.  
  204.     if (result>0) {
  205.         perror(result);
  206.         strcpy(sname,"");
  207.     }
  208.     else {
  209.         strcpy(sname,Reply.ObjectName);
  210.     }
  211.  
  212.     return;
  213. }
  214.  
  215. void GetPrintServer (long qid,char *sname)
  216. {
  217.     struct readQueueStatReq Request;
  218.     struct readQueueStatRep Reply;
  219.  
  220.     int result;
  221.  
  222.     zap(Request);
  223.     zap(Reply);
  224.  
  225.     Request.Length=sizeof(Request)-2;
  226.     Request.Function=0x66;
  227.     Request.ObjectID=qid;
  228.  
  229.     Reply.Length=  sizeof(Reply  )-2;
  230.  
  231.     result=API_E3(&Request,&Reply);
  232.  
  233.     if (result!=0) perror(result);
  234.  
  235.     if (Reply.NumberOfServers>0) {
  236.         GetPrintServerName(Reply.ServerID[0],sname);
  237.     }
  238.     else {
  239.         strcpy(sname,"");
  240.     }
  241.  
  242.     return;
  243. }
  244.  
  245. void GetQueueLocation(LONG qid,char *qloc)
  246. {
  247.     struct readPropValueReq Request;
  248.     struct readPropValueRep Reply;
  249.  
  250.     int result;
  251.     char sname[100];
  252.  
  253.     zap(Request);
  254.     zap(Reply);
  255.     zap(sname);
  256.  
  257.     GetPrintServer(qid,sname);
  258.  
  259.     Request.Length=sizeof(Request)-2;
  260.     Request.Function=0x3D;
  261.     Request.ObjectType=0x0700; // 0x0700 = Queue (Byte swapped)
  262.     Request.ObjectNameLength=sizeof(Request.ObjectName);
  263.     strcpy(Request.ObjectName,sname);
  264.     Request.SegmentNumber=1;
  265.     Request.PropertyNameLength=14;
  266.     strcpy(Request.PropertyName,"IDENTIFICATION");
  267.  
  268.     Reply.Length=sizeof(Reply)-2;
  269.  
  270.     if (sname[0]=='\0')
  271.     {
  272.         result=0;
  273.     }
  274.     else
  275.     {
  276.         result=API_E3(&Request,&Reply);
  277.     }
  278.  
  279.     if (result!=0) {
  280.         perror(result);
  281.         strcpy(qloc,"");
  282.     }
  283.     else strcpy(qloc,Reply.PropertyValue);
  284.     return;
  285. }
  286.  
  287. void GetServerLocation(LONG qsid, char *qloc)
  288. {
  289.     struct readPropValueReq Request;
  290.     struct readPropValueRep Reply;
  291.  
  292.     int result;
  293.     char stmp[100];
  294.  
  295.     zap(Request);
  296.     zap(Reply);
  297.     zap(stmp);
  298.  
  299.     GetPrintServerName(qsid,stmp);
  300.  
  301.     Request.Length=sizeof(Request)-2;
  302.     Request.Function=0x3D;
  303.     Request.ObjectType=0x0700; // 0x0700 = Queue (Byte swapped)
  304.     Request.ObjectNameLength=sizeof(Request.ObjectName);
  305.     strcpy(Request.ObjectName,stmp);
  306.     Request.SegmentNumber=1;
  307.     Request.PropertyNameLength=14;
  308.     strcpy(Request.PropertyName,"IDENTIFICATION");
  309.  
  310.     Reply.Length=sizeof(Reply)-2;
  311.  
  312.     result=API_E3(&Request,&Reply);
  313.  
  314.     if (result!=0)
  315.     {
  316.         perror(result);
  317.         strcpy(qloc,"");
  318.     }
  319.     else strcpy(qloc,Reply.PropertyValue);
  320.     return;
  321. }
  322.  
  323. void GetQueueDefaultLocation(char *qname, char *qloc)
  324. {
  325.     struct readPropValueReq Request;
  326.     struct readPropValueRep Reply;
  327.  
  328.     int result;
  329.  
  330.     union
  331.     {
  332.         char s[4];
  333.         LONG l;
  334.     } PServer;
  335.  
  336.     zap(Request);
  337.     zap(Reply);
  338.  
  339.     Request.Length=sizeof(Request)-2;
  340.     Request.Function=0x3D;
  341.     Request.ObjectType=0x0300; // 0x0300 = Print Queue (Byte swapped)
  342.     Request.ObjectNameLength=sizeof(Request.ObjectName);
  343.     strcpy(Request.ObjectName,qname);
  344.     Request.SegmentNumber=1;
  345.     Request.PropertyNameLength=9;
  346.     strcpy(Request.PropertyName,"Q_SERVERS");
  347.  
  348.     Reply.Length=sizeof(Reply)-2;
  349.  
  350.     result=API_E3(&Request,&Reply);
  351.  
  352.     if (result!=0) {
  353.         if (result!=0xFC) perror(result);
  354.         strcpy(qloc,"");
  355.     }
  356.     else
  357.     {
  358.         PServer.s[0]=Reply.PropertyValue[0];
  359.         PServer.s[1]=Reply.PropertyValue[1];
  360.         PServer.s[2]=Reply.PropertyValue[2];
  361.         PServer.s[3]=Reply.PropertyValue[3];
  362.         GetServerLocation(PServer.l,qloc);
  363.     }
  364.     return;
  365. }
  366.  
  367. int QueueServerReady (long qid)
  368. {
  369.     struct readQueueStatReq Request;
  370.     struct readQueueStatRep Reply;
  371.  
  372.     int result;
  373.  
  374.     zap(Request);
  375.     zap(Reply);
  376.  
  377.     Request.Length=sizeof(Request)-2;
  378.     Request.Function=0x66;
  379.     Request.ObjectID=qid;
  380.  
  381.     Reply.Length=  sizeof(Reply  )-2;
  382.  
  383.     result=API_E3(&Request,&Reply);
  384.  
  385.     if (result!=0) perror(result);
  386.  
  387.     result=0;
  388.     if (Reply.NumberOfServers>0) result=1;
  389.  
  390.     return (result);
  391. }
  392.  
  393. void GetDefaultQueue()
  394. {
  395.     char *s1;
  396.     char *s2;
  397.     char s[100];
  398.     int t;
  399.  
  400.     strcpy(qlst[qcnt],"NONE");
  401.     strcpy(qloc[qcnt],"Local printer");
  402.     qrdy[qcnt]=3;
  403.     qcnt++;
  404.  
  405.     ptr = getenv("PATH");
  406.     s1=ptr;
  407.     s2=ptr;
  408.     while (*s1!=NULL)
  409.     {
  410.         while ((*s2!=NULL)&&(*s2!=';')) s2++;
  411.         if (*s2==';')
  412.         {
  413.             *s2=NULL;
  414.             strcpy(s,s1);
  415.             *s2=';';
  416.             s2++;
  417.         }
  418.         else
  419.         {
  420.             strcpy(s,s1);
  421.         }
  422.         s1=s2;
  423.         s2++;
  424.         strcat(s,"\\LOCATION.SRT");
  425.         LocationSrt=fopen(s,"rt");
  426.         if (LocationSrt!=NULL) break;
  427.     }
  428.     strcpy(DefQ,"NONE");
  429.     if (LocationSrt==NULL) return;
  430.     t=1;
  431.     while (t==1)
  432.     {
  433.         if (fgets(s,sizeof(s),LocationSrt)==NULL)
  434.         {
  435.             fclose(LocationSrt);
  436.             strcpy(DefQ,"NONE");
  437.             return;
  438.         }
  439.         if (strlen(s)<20)
  440.         {
  441.             fclose(LocationSrt);
  442.             strcpy(DefQ,"NONE");
  443.             return;
  444.         }
  445.         s1=(char *)&s;
  446.         s2=s1;
  447.         while (*s1!=' ') s1++;
  448.         while ((s1>s2)&&(*s1!=':')) s1--;
  449.         if (*s1==':') s1++;
  450.         while (*s2!=' ') s2++;
  451.         *s2=NULL;
  452.         t=strcmp(ENET,s1);
  453.         *s2=' ';
  454.         if (t==0)
  455.         {
  456.             s2++;
  457.             for (t=32;t>0;t--) s2++;
  458.             s2++;
  459.             s1=(char *)&DefQ;
  460.             while ((*s2!=' ')&&(*s2!='\n')) *(s1++)=*(s2++);
  461.             *s1=NULL;
  462.         }
  463.         if (t!=0) t=1;
  464.     }
  465.     fclose(LocationSrt);
  466.     strcpy(qlst[qcnt],DefQ);
  467.     strcpy(qloc[qcnt],"Normal network location");
  468.     qrdy[qcnt]=2;
  469.     qcnt++;
  470. }
  471.  
  472. void GetEthernetNumber()
  473. {
  474.     union REGS regs;
  475.  
  476.     regs.h.ah = 0xEE;
  477.     intdos(®s, ®s);
  478.     sprintf(ENET,"%04X%04X%04X",regs.x.cx,regs.x.bx,regs.x.ax);
  479. }
  480.  
  481. void LoadList()
  482. {
  483.     BYTE searchObjectName[48]="*";
  484.     WORD searchObjectType=0x0300; // 0x0300 = Print Queue
  485.     long objectID;
  486.     BYTE objectName[48];
  487.     WORD objectType;
  488.     BYTE objectHasProperties;
  489.     BYTE objectFlag;
  490.     BYTE objectSecurity;
  491.  
  492.     int result;
  493.     result=0;
  494.  
  495.     while (result==0)
  496.     {
  497.         result=ScanBinderyObject (
  498.                searchObjectName, searchObjectType, &objectID, objectName,
  499.                &objectType, &objectHasProperties, &objectFlag,
  500.                &objectSecurity);
  501.         if (result!=0 && result!=0xFC) perror(result);
  502.         if (qcnt<100-1 && result==0)
  503.         {
  504.             qrdy[qcnt]=QueueServerReady(objectID);
  505.             strcpy(qlst[qcnt],objectName);
  506.             GetQueueLocation(objectID,qloc[qcnt]);
  507.             if (*qloc[qcnt]==NULL)
  508.             {
  509.                 GetQueueDefaultLocation(objectName,qloc[qcnt]);
  510.             }
  511.             qcnt++;
  512.         }
  513.     }
  514. }
  515.  
  516. void SortList()
  517. {
  518.     char tstr[100];
  519.     int  i,j,t;
  520.  
  521.     for (i=0;i<qcnt-1;i++)
  522.     {
  523.         for (j=i+1;j<qcnt;j++)
  524.         {
  525.             if (strcmp(qlst[i],qlst[j])>0)
  526.             {
  527.                 strcpy(tstr,qlst[i]);
  528.                 strcpy(qlst[i],qlst[j]);
  529.                 strcpy(qlst[j],tstr);
  530.                 strcpy(tstr,qloc[i]);
  531.                 strcpy(qloc[i],qloc[j]);
  532.                 strcpy(qloc[j],tstr);
  533.                 t=qrdy[i]; qrdy[i]=qrdy[j]; qrdy[j]=t;
  534.             }
  535.         }
  536.     }
  537. }
  538.  
  539. int getArrow()
  540. {
  541.     char ch;
  542.  
  543.     ch=' ';
  544.     while (ch==' ')
  545.     {
  546.         ch=getch();
  547.         if (ch==0x000D) {ch='s'; break;}  // Return
  548.         if (ch==0x001B) {ch='e'; break;}  // Escape
  549.         if (ch==0x0018) {ch='X'; break;}  // Ctl-X
  550.         if (ch==0x0042) {ch='b'; break;}  // 'B'
  551.         if (ch==0x0062) {ch='b'; break;}  // 'b'
  552.         if (ch==0x0031) {ch='1'; break;}  // '1'
  553.         if (ch==0x0032) {ch='2'; break;}  // '2'
  554.         if (ch==0x0033) {ch='3'; break;}  // '3'
  555.         if (ch==0X003F) {ch='?'; break;}  // '?'
  556.         if (ch==0x0058) {ch='X'; break;}  // 'X'
  557.         if (ch==0x0078) {ch='X'; break;}  // 'x'
  558.         if (ch==0x002B) {ch='+'; break;}  // '+'
  559.         if (ch==0x002D) {ch='-'; break;}  // '-'
  560.         if (ch==0x0000)  // Extended key as follows:
  561.         {
  562.             ch=getch();
  563.             if (ch==0x0047) {ch='H'; break;}  // Home
  564.             if (ch==0x0048) {ch='u'; break;}  // Up
  565.             if (ch==0x0049) {ch='U'; break;}  // PgUp
  566.             if (ch==0x004F) {ch='E'; break;}  // End
  567.             if (ch==0x0050) {ch='d'; break;}  // Down
  568.             if (ch==0x0051) {ch='D'; break;}  // PgDn
  569.             if (ch==0x003B) {ch='?'; break;}  // F1 (Help)
  570.             if (ch==0x002D) {ch='X'; break;}  // Alt-X
  571.         }
  572.         ch=' ';
  573.     }
  574.     return (ch);
  575. }
  576.  
  577. void ShowQ(int i, int j)
  578. {
  579.     int t;
  580.  
  581.     if (j==0)
  582.     {
  583.         textcolor(WHITE);
  584.         textbackground(BLUE);
  585.     }
  586.     t=xh-xl-1-MaxQueueNameLength-MaxServerNameLength;
  587.     cprintf("%-*s %-*s %*s",MaxQueueNameLength,qlst[i],
  588.                             MaxServerNameLength,qloc[i],
  589.                             t,qstat[qrdy[i]]);
  590.     textcolor(LIGHTGRAY);
  591.     textbackground(BLACK);
  592. }
  593.  
  594. int ShowUpdate(int WinTop, int WinPos)
  595. {
  596.     static OldTop=-2;
  597.     static OldPos=-2;
  598.     int i,j;
  599.     REGS scroll;
  600.  
  601.     if (OldTop==WinTop)
  602.     {
  603.         gotoxy(xl,2+OldPos-OldTop);
  604.         ShowQ(OldPos,1);
  605.         gotoxy(xl,2+WinPos-WinTop);
  606.         ShowQ(WinPos,0);
  607.     }
  608.     else
  609.     if (OldTop-WinTop==1)
  610.     {
  611.         gotoxy(xl,2+OldPos-OldTop);
  612.         ShowQ(OldPos,1);
  613.         zap(scroll);
  614.         scroll.h.ah=0x07;
  615.         scroll.h.al=1;
  616.         scroll.h.bh=BLACK<<4+LIGHTGRAY;
  617.         scroll.h.ch=yl-1;
  618.         scroll.h.cl=xl-1;
  619.         scroll.h.dh=yh-1;
  620.         scroll.h.dl=xh-1;
  621.         int86(0x10,&scroll,&scroll);
  622.         gotoxy(xl,yh);
  623.         gotoxy(xl,2+WinPos-WinTop);
  624.         ShowQ(WinPos,0);
  625.     }
  626.     else
  627.     if (WinTop-OldTop==1)
  628.     {
  629.         gotoxy(xl,2+OldPos-OldTop);
  630.         ShowQ(OldPos,1);
  631.         zap(scroll);
  632.         scroll.h.ah=0x06;
  633.         scroll.h.al=1;
  634.         scroll.h.bh=BLACK<<4+LIGHTGRAY;
  635.         scroll.h.ch=yl-1;
  636.         scroll.h.cl=xl-1;
  637.         scroll.h.dh=yh-1;
  638.         scroll.h.dl=xh-1;
  639.         int86(0x10,&scroll,&scroll);
  640.         gotoxy(xl,yl);
  641.         gotoxy(xl,2+WinPos-WinTop);
  642.         ShowQ(WinPos,0);
  643.     }
  644.     else
  645.     {
  646.         j=qcnt-1;
  647.         if (j>MaxLines) j=MaxLines;
  648.         for (i=0; i<j; i++)
  649.         {
  650.             gotoxy(xl,2+i);
  651.             ShowQ(WinTop+i,WinTop+i-WinPos);
  652.         }
  653.     }
  654.  
  655.     gotoxy(xl-1,2);
  656.     cprintf("%s",(WinTop>0)?"":"║");
  657.     gotoxy(xl-1,MaxLines+1);
  658.     cprintf("%s",(WinTop+MaxLines<qcnt)?"":"║");
  659.  
  660.     gotoxy(xl,yh+2);
  661.     cprintf("<ESC> to Exit, <CR> to Select, B for %s",
  662.             Banner==0?"no banner":"a banner ");
  663.     gotoxy(xl,yh+3);
  664.     cprintf("1=LPT1, 2=LPT2, 3=LPT3: <%d>      ±=Timeout %3d",LptNum,timeout);
  665.     gotoxy(1,1);
  666.  
  667.     OldTop=WinTop;
  668.     OldPos=WinPos;
  669.     return getArrow();
  670. }
  671.  
  672. void ShowList()
  673. {
  674. //    ╚╔╩╦╠═╣║╗╝
  675. //    │┤┐└┴┬├─┼
  676.     int i,j,o;
  677.  
  678.     o=(80-MaxQueueNameLength-MaxServerNameLength-strlen(qstat[0])) / 2;
  679.     if (o>17) o=17;
  680.     j=qcnt;
  681.     if (j>MaxLines) j=MaxLines;
  682.  
  683.     xl=o+1;
  684.     yl=2;
  685.     xh=xl+80-o-o;
  686.     yh=yl+j-1;
  687.  
  688.     clrscr();
  689.     gotoxy(o,1);
  690.     cprintf("╔");
  691.     for (i=1; i<(82-o-o); i++) cprintf("═");
  692.     cprintf("╗");
  693.  
  694.     for (i=0; i<j; i++)
  695.     {
  696.         gotoxy(xl-1,2+i);
  697.         cprintf("║");
  698.         ShowQ(i,i);
  699.         gotoxy(xh+1,2+i);
  700.         cprintf("║");
  701.     }
  702.  
  703.     if (j>=MaxLines)
  704.     {
  705.         gotoxy(xl-1,j+1);
  706.         cprintf("");
  707.     }
  708.  
  709.     gotoxy(o,j+2);
  710.     cprintf("╠");
  711.     for (i=1; i<(82-o-o); i++) cprintf("═");
  712.     cprintf("╣");
  713.  
  714.     gotoxy(o,j+3);
  715.     cprintf("║");
  716.     for (i=1; i<(82-o-o); i++) cprintf(" ");
  717.     cprintf("║");
  718.  
  719.     gotoxy(o,j+4);
  720.     cprintf("║");
  721.     for (i=1; i<(82-o-o); i++) cprintf(" ");
  722.     cprintf("║");
  723.  
  724.     gotoxy(o,j+5);
  725.     cprintf("╚");
  726.     for (i=1; i<(82-o-o); i++) cprintf("═");
  727.     cprintf("╝");
  728.  
  729.     gotoxy(o+1,j+3);
  730.     cprintf("<ESC> to Exit, <CR> to Select, B for %sbanner",
  731.             Banner==0?"no ":"a ");
  732.  
  733.     gotoxy(o+1,j+4);
  734.     cprintf("1=LPT1, 2=LPT2, 3=LPT3: <%d>      ±=Timeout %3d",LptNum,timeout);
  735.  
  736.     gotoxy(1,j+5);
  737.  
  738.     return;
  739. }
  740.  
  741. void SelectQueue(int i)
  742. {
  743.     char stmp[100];
  744.  
  745.     strcpy(stmp,"");
  746.  
  747.     if (i==-2) i=qcnt-2;
  748.     if (i==-3) i=qcnt-1;
  749.  
  750.     if (i==qcnt-1) // reset
  751.     {
  752.         if (strcmp("NONE",qlst[i])==0) i--; // reset IS none
  753.         Banner=0; // reset already has banner defined
  754.     }
  755.     if (i==qcnt-2) // none
  756.     {
  757.         sprintf(stmp,"ENDCAP");
  758.     }
  759.     if (i==-1)
  760.     {
  761.         sprintf(stmp,"CAPTURE /SHOW");
  762.     }
  763.     if ((i>=0)&&(i<qcnt))
  764.     {
  765.         sprintf(stmp,"CAPTURE /Q=%s%s /NT /TI=%d /L=%d",
  766.                 qlst[i],Banner>0?" /NB":"",timeout,LptNum);
  767.     }
  768.     normvideo();
  769.     if (_argc==1) clrscr();
  770.     system(stmp);
  771.     return;
  772. }
  773.  
  774. void usage()
  775. {
  776.     printf("%s v%d.%d\n",ProgName,VerMaj,VerMin);
  777.     printf("Created by Jeff Pilant <pilant@nadc.nadc.navy.mil>\n");
  778.     printf("\n");
  779.     printf("Usage:\n");
  780.     printf("\n");
  781.     printf("   SELECT <queue> [/NB] | <keyword> | FILE <filename>\n");
  782.     printf("\n");
  783.     printf("Where:\n");
  784.     printf("   <queue> is the name of a print queue\n");
  785.     printf("   /NB     selects no banner\n");
  786.     printf("   HELP    this text\n");
  787.     printf("   RESET   reset to login setup\n");
  788.     printf("   LPT     set for no capturing of printers\n");
  789.     printf("   NONE    set for no capturing of printers\n");
  790.     printf("   LOCAL   set for no capturing of printers\n");
  791.     printf("   SHOW    display capture status\n");
  792.     printf("   FILE    set for capture to file <filename>\n");
  793.     printf("           the captured file must reside on the server\n");
  794.     printf("\n");
  795.     printf("With no arguments, select give a menu and allows you to\n");
  796.     printf("set the timeout and choose queues for lpt2 and lpt3 as well.\n");
  797.  
  798.     exit (0);
  799.     return;
  800. }
  801.  
  802. void SetFile(char *fn)
  803. {
  804.     char stmp[100];
  805.  
  806.     zap(stmp);
  807.  
  808.     sprintf(stmp,"CAPTURE /CR=%s /TI=300 /NT /NFF /NB",fn);
  809.     system(stmp);
  810.     exit(0);
  811. }
  812.  
  813. void UseArg()
  814. {
  815.     char *kw[]={"HELP","?","/?","RESET","LPT","NONE","LOCAL","SHOW","FILE",""};
  816.     int i;
  817.     int reset=0;
  818.     int help=0;
  819.     int local=0;
  820.     int show=0;
  821.  
  822.     char *ch;
  823.  
  824.     ch=_argv[1];
  825.     while (*ch!=NULL) {*ch=toupper(*ch); ch++;}
  826.  
  827.     Banner=0; // default command line entry to banner
  828.  
  829.     if (_argc==3)
  830.     {
  831.         ch=_argv[2];
  832.         while (*ch!=NULL) {*ch=toupper(*ch); ch++;}
  833.         if (strcmp("/NB",_argv[2])==0) Banner=1;
  834.         if (strcmp("NB",_argv[2])==0) Banner=1;
  835.         if (Banner==0)
  836.         {
  837.             if (strcmp(_argv[1],kw[8])==0)
  838.             {
  839.                 SetFile(_argv[2]);
  840.             }
  841.             else usage();
  842.         }
  843.     }
  844.  
  845.     for (i=0; kw[i][0]!=NULL; i++)
  846.     {
  847.         if (strcmp(kw[i],_argv[1])==0)
  848.         {
  849.             switch (i)
  850.             {
  851.                 case 0: help=1;  break;
  852.                 case 1: help=1;  break;
  853.                 case 2: help=1;  break;
  854.                 case 3: reset=1; break;
  855.                 case 4: local=1; break;
  856.                 case 5: local=1; break;
  857.                 case 6: local=1; break;
  858.                 case 7: show=1;  break;
  859.             }
  860.         }
  861.     }
  862.     if (help==1)  {usage();         exit (0);}
  863.     if (show==1)  {SelectQueue(-1); exit (0);}
  864.     LoadList();
  865.     SortList();
  866.     GetEthernetNumber();
  867.     GetDefaultQueue();
  868.     if (local==1) {SelectQueue(-2); exit (0);}
  869.     if (reset==1) {SelectQueue(-3); exit (0);}
  870.  
  871. //    given queue name
  872.     for (i=0;i<qcnt;i++)
  873.     {
  874.         if (strcmp(_argv[1],qlst[i])==0)
  875.         {
  876.             SelectQueue(i);
  877.             exit (0);
  878.         }
  879.         if ((qlst[i][0]=='Q')&&(qlst[i][1]=='_')&&strcmp(_argv[1],&qlst[i][2])==0)
  880.         {
  881.             SelectQueue(i);
  882.             exit (0);
  883.         }
  884.     }
  885.     printf("Queue \"%s\" is unknown\n",_argv[1]);
  886.     exit (1);
  887.  
  888.     return;
  889. }
  890.  
  891. main()
  892. {
  893.     int i,j,k;
  894.     int WinPos;
  895.     int WinTop;
  896.     char result;
  897.  
  898.     if (_argc>3) usage();
  899.     if (_argc>1) UseArg();
  900.  
  901.     clrscr();
  902.     textcolor(LIGHTGRAY);
  903.     textbackground(BLACK);
  904.  
  905.     LoadList();
  906.     SortList();
  907.     GetEthernetNumber();
  908.     GetDefaultQueue();
  909.  
  910.     for (i=0;i<qcnt;i++)
  911.     {
  912.         j=strlen(qlst[i]);
  913.         k=strlen(qloc[i]);
  914.         if (j>MaxQueueNameLength ) MaxQueueNameLength =j;
  915.         if (k>MaxServerNameLength) MaxServerNameLength=k;
  916.     }
  917.     j=MaxQueueNameLength;
  918.     k=MaxServerNameLength;
  919.  
  920.     WinPos=0;
  921.     WinTop=0;
  922.     result=' ';
  923.  
  924.     ShowList();
  925.  
  926.     while (result==' ')
  927.     {
  928.         result=ShowUpdate(WinTop,WinPos);
  929.         switch (result)
  930.         {
  931.             case 'H':    WinPos=0;
  932.                         result=' '; break;
  933.             case 'U':     WinPos-=(MaxLines-1);
  934.                         if (WinPos<0) WinPos=0;
  935.                         result=' '; break;
  936.             case 'u':     if (--WinPos<0) WinPos=qcnt-1;
  937.                         result=' '; break;
  938.             case 'd':     if (++WinPos>qcnt-1) WinPos=0;
  939.                         result=' '; break;
  940.             case 'D':     WinPos+=(MaxLines-1);
  941.                         if (WinPos>qcnt-1) WinPos=qcnt-1;
  942.                         result=' '; break;
  943.             case 'E':     WinPos=qcnt-1;
  944.                         result=' '; break;
  945.             case 'b':     Banner=1-Banner;
  946.                         result=' '; break;
  947.             case 's':     SelectQueue(WinPos);
  948.                         break;
  949.             case 'e':     SelectQueue(-1);
  950.                         break;
  951.             case '1':    LptNum=1; result=' '; break;
  952.             case '2':    LptNum=2; result=' '; break;
  953.             case '3':    LptNum=3; result=' '; break;
  954.             case '?':   clrscr(); usage(); break;
  955.             case 'X':   clrscr(); break;
  956.             case '+':    timeout++; if (timeout>900) timeout=0; result=' '; break;
  957.             case '-':    timeout--; if (timeout<0) timeout=900; result=' '; break;
  958.             default :    break;
  959.         }
  960.         if (WinPos<WinTop) WinTop=WinPos;
  961.         if ((WinPos-WinTop)>=MaxLines) WinTop=WinPos-MaxLines+1;
  962.     }
  963.  
  964.     exit(0);
  965.     return(0);
  966. }
  967.