home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / mycap.exe / MYCAP.C next >
Text File  |  1994-08-17  |  11KB  |  428 lines

  1. /****************************************************************************
  2. **    File:    MYCAP.C
  3. **
  4. **    Prof: Print Services
  5. **
  6. **    Desc:    Sample Capture program.
  7. **
  8. **            This program mimics the functionality of the CAPTURE.EXE 
  9. **            NetWare Utility.
  10. **        
  11. **        
  12. **        
  13. **        
  14. **        
  15. **        
  16. **
  17. **        DISCLAIMER  
  18. **  
  19. **    Novell, Inc. makes no representations or warranties with respect to
  20. **    any NetWare software, and specifically disclaims any express or
  21. **    implied warranties of merchantability, title, or fitness for a
  22. **    particular purpose.  
  23. **
  24. **    Distribution of any NetWare software is forbidden without the
  25. **    express written consent of Novell, Inc.  Further, Novell reserves
  26. **    the right to discontinue distribution of any NetWare software.
  27. **    
  28. **    Novell is not responsible for lost profits or revenue, loss of use
  29. **    of the software, loss of data, costs of re-creating lost data, the
  30. **    cost of any substitute equipment or program, or claims by any party
  31. **    other than you.  Novell strongly recommends a backup be made before
  32. **    any software is installed.   Technical support for this software
  33. **    may be provided at the discretion of Novell.
  34. **
  35. **    Programmer(s):
  36. **
  37. **        Ini    Who                        Firm
  38. **        -----------------------------------------------------------------------
  39. **        KLB    Karl Bunnell                Novell Developer Support.
  40. **
  41. **    History:
  42. **
  43. **        When        Who    What
  44. **        -----------------------------------------------------------------------
  45. **        06-17-94    klb    First code.
  46. **        06-24-94 klb    Added capture flags and functions.
  47. */
  48.  
  49. /****************************************************************************
  50. **    Include headers, macros, function prototypes, etc.
  51. */
  52.  
  53.     /*------------------------------------------------------------------------
  54.     **    Macros
  55.     */
  56.     #define NWDOS
  57.  
  58.     /*------------------------------------------------------------------------
  59.     **    ANSI
  60.     */
  61.     #include <stdio.h>
  62.     #include <stdlib.h>
  63.     #include <string.h>
  64.  
  65.  
  66.     /*------------------------------------------------------------------------
  67.     **    NetWare
  68.     */
  69.     #include <nwcalls.h>
  70.     #include <nwerror.h>
  71.  
  72. /****************************************************************************
  73. **    This function contains the entire program.
  74. **    
  75. */
  76.  
  77.  
  78. void main(int argC, char *argV[])
  79.     {
  80.     NWCCODE                cCode;
  81.     NWCONN_HANDLE        connHandle;
  82.     NWCAPTURE_FLAGS1    captureFlags;
  83.     NWOBJ_ID               queueID;
  84.     WORD                    count;
  85.     NWLPT                    lptPort = 0x01;
  86.     int                    tiValue;
  87.     char                    serverName[48];
  88.     char                    queueName[48];
  89.     char                    *p, *ptr;
  90.     char                    c;
  91.  
  92.     cCode = NWCallsInit(NULL,NULL);
  93.  
  94.     if (cCode)
  95.         {
  96.         printf("\nCall to NWCallsInit failed!! Error code %04X\n", cCode);
  97.         exit(1);
  98.         }
  99.     
  100.     if (argC < 2)
  101.         {
  102.                        printf("\n---------------------------------------------------------------------------\n");
  103.                         printf("\nUSAGE: MYCAP <options>");
  104.                         printf("\nWhere options can be a combination of the following:\n");
  105.                         printf("\n  OPTION      DESCRIPTION");
  106.                         printf("\n  ------      -----------");
  107.                         printf("\n  A           Autoendcap");
  108.                         printf("\n  NA          NoAutoendcap");
  109.                         printf("\n  NB          No Banner");
  110.                         printf("\n  NFF         No Form Feed");
  111.                         printf("\n  NT          No Tabs expansion");
  112.                         printf("\n  TI=         TImeout");
  113.                         printf("\n  L=          Local LPT port");
  114.                         printf("\n  S=          Server Name");
  115.                         printf("\n  Q=          Queue Name");
  116.                         printf("\n  F=          Form Number");
  117.                         printf("\n  C=          Copies ");
  118.                         printf("\n  T=          Tabs - Number of spaces in tab");
  119.                         printf("\n  B=          Banner Name");
  120.                         printf("\n  NF=         No Form Feed");
  121.                         printf("\n  K           Keep if server goes down");
  122.  
  123.                         exit(0);
  124.           }
  125.  
  126. /*-------------------------------------------------------------------------
  127. ** Default capture flag settings:
  128. */
  129.     strcpy(captureFlags.jobDescription, "LPT Catch");
  130.     captureFlags.jobControlFlags = 0x0400;
  131.     captureFlags.tabSize = 0x08;
  132.     captureFlags.numCopies = 0x0001;
  133.     captureFlags.printFlags = 0xC0;
  134.     captureFlags.maxLines = 100;
  135.     captureFlags.maxChars = 120;
  136.     strcpy(captureFlags.formName, "\0");
  137.     captureFlags.formType = 0x0000;
  138.     strcpy(captureFlags.bannerText, "LST:");
  139.     captureFlags.flushCaptureTimeout = 0x0000;
  140.     captureFlags.flushCaptureOnClose = 0x0000;
  141.  
  142. /*-------------------------------------------------------------------------
  143. **
  144. */
  145.  
  146.                 /* Retrieve connection ID */
  147.  
  148.     cCode = NWGetDefaultConnectionID(&connHandle);
  149.  
  150.                 if(cCode)
  151.                 {
  152.                 printf("Call to NWGetDefaultConnectionID failed!! Error Code %04X\n", cCode);
  153.                 exit(1);
  154.                 }
  155.  
  156.     cCode = NWGetFileServerName(
  157.                 /* Connection Handle */ connHandle,
  158.                 /* Server Name       */ serverName
  159.                 );
  160.  
  161.  
  162.                 if(cCode)
  163.                 {
  164.                 printf("Call to NWGetFileServerName failed!! Error Code %04X\n", cCode);
  165.                 exit(1);
  166.                 }
  167.  
  168.     for (count=1; count<argC; ++count)
  169.         {
  170.  
  171.         switch (argV[count][0])
  172.             {
  173.             case 'L':
  174.             case 'l':
  175.                         p = argV[count];     /* p= Get LPT Number */ 
  176.                         p = (p+2);
  177.  
  178.                         lptPort = atoi(p);
  179.  
  180.                         break;
  181.  
  182.             case 'S':
  183.             case 's':
  184.                         p = argV[count];     /* p= Get Server Name */ 
  185.                         p = (p+2);
  186.                         ptr = strupr(p);
  187.                         strcpy(serverName, ptr);
  188.  
  189.                        cCode = NWGetConnectionHandle(
  190.                                         /* Server Name    */ serverName,
  191.                                         /* Reserved       */ 0,
  192.                                         /* Connect handle */ &connHandle,
  193.                                         /* Reserved       */ NULL
  194.                                         );
  195.  
  196.                         if(cCode)
  197.                             {
  198.                             cCode = NWAttachToFileServer(
  199.                                         /* Server Name     */ serverName,
  200.                                         /* scope must be 0 */ 0,
  201.                                         /* New Conn Handle */ &connHandle
  202.                                         );
  203.                                     if (cCode)
  204.                                         {
  205.                                         switch (cCode)
  206.                                             {
  207.                                             case INVALID_CONNECTION:
  208.                                                   printf("\nInvalid Connection!\n");
  209.                                                   exit(1);
  210.  
  211.                                             case NO_SERVER_ERROR:
  212.                                                   printf("\nNO Server Error!\n");
  213.                                                   exit(1);
  214.  
  215.                                             case UNKNOWN_FILE_SERVER:
  216.                                                   printf("\nUnknown File Server!\n");
  217.                                                   exit(1);
  218.                                             default :
  219.                                                   printf("\nUnknown error! Code = %04X\n", cCode);
  220.                                                   exit(1);
  221.                                             }
  222.                                         }
  223.  
  224.                             cCode = NWLoginToFileServer(
  225.                                         /* connHandle    */ connHandle,
  226.                                         /* Object Name   */ "GUEST",
  227.                                         /* Object Type   */ OT_USER,
  228.                                         /* Password      */ ""
  229.                                         );
  230.  
  231.                                     if (cCode)
  232.                                         {
  233.                                         switch (cCode)
  234.                                             {
  235.                                             case INVALID_CONNECTION:
  236.                                                   printf("\nInvalid Connection!\n");
  237.                                                   exit(1);
  238.  
  239.                                             default :
  240.                                                   printf("\nUnknown error! Code = %04X\n", cCode);
  241.                                                   exit(1);
  242.                                             }
  243.                                         }
  244.  
  245.  
  246.                             }
  247.  
  248.                          break;
  249.  
  250.             case 'Q':
  251.             case 'q':
  252.  
  253.                         p = argV[count];     /* p= Get QUEUE Name */
  254.                         p = (p+2);
  255.                         ptr = strupr(p);
  256.                         strcpy(queueName, ptr);
  257.  
  258.                         cCode = NWGetObjectID(
  259.                                     /* Conn Handle */ connHandle,
  260.                                     /* Object Name */ queueName,
  261.                                     /* Object type */ OT_PRINT_QUEUE,
  262.                                     /* Object ID   */ &queueID
  263.                                     );
  264.  
  265.                         if(cCode)
  266.                             {
  267.                             printf("\nQueue %s does not exist on file server %s\n", queueName, serverName);
  268.                             exit(1);
  269.                             }
  270.                          break;
  271.  
  272.             case 'T':
  273.             case 't':
  274.                          switch(argV[count][1])
  275.                             {
  276.                             case 'I':
  277.                             case 'i':
  278.                                         p = argV[count];     /* p= Get time interval */ 
  279.                                         p = (p+3);
  280.                                         tiValue = atoi(p);
  281.                                         
  282.                                         if (tiValue > 3640)
  283.                                         tiValue = 3640;
  284.  
  285.                                         tiValue = tiValue * 18; /* convert ticks to seconds */
  286.  
  287.                                         captureFlags.flushCaptureOnClose = 0x0001;
  288.                                         captureFlags.flushCaptureTimeout = tiValue;
  289.                                         break;
  290.  
  291.                             default :
  292.                                         p = argV[count];     /* p= Get tab size */ 
  293.                                         p = (p+2);
  294.                                         captureFlags.tabSize = (NWTAB)atoi(p);
  295.                                          break;
  296.                              }
  297.  
  298.                         break;
  299.  
  300.             case 'N':
  301.             case 'n':
  302.                        switch(argV[count][1])
  303.                          {
  304.                          case 'T':
  305.                          case 't':
  306.                                     captureFlags.printFlags = (captureFlags.printFlags & 0x80);
  307.                                     break;
  308.  
  309.                          case 'B':
  310.                          case 'b':
  311.                                     captureFlags.printFlags = (captureFlags.printFlags & 0x40);
  312.                                     break;
  313.  
  314.                          case 'F':
  315.                          case 'f':
  316.                                     captureFlags.printFlags = (captureFlags.printFlags & 0xC8);
  317.                                   break;
  318.  
  319.                          case 'A':
  320.                          case 'a':
  321.                                     captureFlags.flushCaptureOnClose = 0x0001;
  322.                                   break;
  323.  
  324.                         }
  325.  
  326.                         break;
  327.  
  328.             case 'K':
  329.             case 'k':
  330.                        captureFlags.printFlags = (captureFlags.printFlags & 0xC4);
  331.                          break;
  332.             
  333.             case 'B':
  334.             case 'b':
  335.                         p = argV[count];     /* p= Get name */ 
  336.                         p = (p+2);
  337.                    strcpy(captureFlags.bannerText, p);
  338.                         break;
  339.  
  340.             case 'C':
  341.             case 'c':
  342.                         p = argV[count];     /* p= Get number of copies */ 
  343.                         p = (p+2);
  344.  
  345.                         captureFlags.numCopies = atoi(p);
  346.                         break;
  347.  
  348.  
  349.             case 'F':
  350.             case 'f':
  351.                         p = argV[count];     /* p= Get form number */ 
  352.                         p = (p+2);
  353.  
  354.                         captureFlags.formType = atoi(p);
  355.                         break;
  356.                         
  357.             case 'A':
  358.             case 'a':
  359.                           captureFlags.flushCaptureOnClose = 0x0000;
  360.  
  361.                         break;
  362.             
  363.                      
  364.             }
  365.  
  366.         }
  367.  
  368.  
  369.  
  370.     cCode = NWStartQueueCapture(
  371.                 /* Conn Handle    */ connHandle,
  372.                 /* LPTDevice      */ lptPort,
  373.                 /* queueID            */ queueID,
  374.                 /* Queue Name     */ queueName
  375.                 );
  376.  
  377.     if(cCode)
  378.         {
  379.         printf("Call to NWStartQueueCapture failed!! Error Code %04X\n", cCode);
  380.         exit(1);
  381.         }
  382.  
  383.  
  384.  
  385.     cCode = NWSetCaptureFlags(
  386.                     /* Conn Handle  */ connHandle,
  387.                     /* LPTDevice    */ lptPort,
  388.                     /* RW Cap. flgs */ &captureFlags
  389.                     );
  390.  
  391.     if(cCode)
  392.         {
  393.         printf("Call to NWSetCaptureFlags failed!! Error Code %04X\n", cCode);
  394.         exit(1);
  395.         }
  396.  
  397.  
  398.     cCode = NWGetCaptureFlags(
  399.                 /*    LPT Device  */ lptPort,
  400.                 /* RW Cap flgs */ &captureFlags,
  401.                 /* RO Cap flgs */ NULL
  402.                 );
  403.  
  404.                 if(cCode)
  405.                 {
  406.                 printf("Call to NWGetCaptureFlags failed!! Error Code %04X\n", cCode);
  407.                 exit(1);
  408.                 }
  409.  
  410.             printf("\nJob Control Flags     : %02X", captureFlags.jobControlFlags);
  411.             printf("\nTabSize               : %02X", captureFlags.tabSize);
  412.             printf("\nNumber of Copies      : %04X", captureFlags.numCopies);
  413.             printf("\nPrintFlags            : %04X", captureFlags.printFlags);
  414.             printf("\nMaxLines              : %04X", captureFlags.maxLines);
  415.             printf("\nMaxChars              : %04X", captureFlags.maxChars);
  416.             printf("\nFormName              : %s",   captureFlags.formName);
  417.             printf("\nFormType              : %04X", captureFlags.formType);
  418.             printf("\nBanner Text           : %s",   captureFlags.bannerText);
  419.             printf("\nFlushCaptureTimeout   : %04X", captureFlags.flushCaptureTimeout/18);
  420.             printf("\nFlushCaptureOnClose   : %02X", captureFlags.flushCaptureOnClose);
  421.  
  422.  
  423.     printf("\nLPT%d successfully redirected to queue %s on server %s.\n",
  424.               lptPort, queueName, serverName);
  425.  
  426.  
  427. }
  428.