home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / cpfile.exe / FILECAP.C < prev    next >
Text File  |  1995-03-03  |  7KB  |  202 lines

  1. /****************************************************************************
  2. **      DISCLAIMER  
  3. **  
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.  
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **   
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. *****************************************************************************
  20. **
  21. **   File:   
  22. **
  23. **   Desc:  The program will capture to the specified file.
  24. **          Print the data "this is a test" to the file then end the capture.
  25. **          Note: If the default capture flags are used in capturing
  26. **                the file then as soon as you write to that file the 
  27. **                capture will close.  If you wish the file to stay open then
  28. **                you will have to set the flushCaptureOnClose to off (1).
  29. **          WARNING: Do not use an NWEndCapture() on a file capture, instead 
  30. **                   use an NWCancelCapture().  See the sample code for
  31. **                   endcap in RNDCAP.EXE ON COMPUSERV.
  32. **        
  33. **   Programmers:
  34. **   Ini   Who               Firm
  35. **   ------------------------------------------------------------------------
  36. **   ARM   A. Ray Maxwell    Novell Developer Support.
  37. **
  38. **   History:
  39. **       
  40. **   ------------------------------------------------------------------------
  41. **   07-13-94   ARM   First code.
  42. **   09-08-94   ARM   Added comments to API calls.
  43. **   01-08-95   ARM   Added the set of flushCaptureOnClose to off.
  44. */
  45.  
  46. /****************************************************************************
  47. ** Include Headers, Macros & function Prototypes.
  48. */
  49.    /*------------------------------------------------------------------------
  50.    ** Borland C.
  51.    */
  52.    #include <stdio.h>    /* getch()       */
  53.    #include <stdlib.h>   /* exit() atoi() */
  54.    #include <conio.h>    /* cputs()       */
  55.    #include <string.h>   /* strcpy()      */
  56.  
  57.    /*------------------------------------------------------------------------
  58.    ** Netware NWCALLS etc.
  59.    */
  60.    #include <nwcalls.h>
  61.  
  62.    /*------------------------------------------------------------------------
  63.     **  Prototypes
  64.     */
  65.     void captureTheQueue(void);
  66.     void printData(void);
  67.     void helpScreen(void);
  68.  
  69.     /*------------------------------------------------------------------------
  70.     **  Global variables.
  71.     */
  72.      NWCAPTURE_FLAGS1 f1;           /* new capture flags for queue         */
  73.      NWCAPTURE_FLAGS2 f2;           /* new capture flags for queue         */
  74.      NWCONN_HANDLE    connHandle;   /* connection handle                   */
  75.      NWOBJ_ID         *objectID;    /* Bindery object ID                   */
  76.      int              lptPort;      /* buffer for lpt                      */
  77.      BYTE NWFAR       server[48];   /* server name                         */
  78.      char NWFAR       filePath[256];/* file path to file to be create      */
  79.      NWCCODE          ccode;        /* error code buffer                   */
  80.  
  81.  
  82. /****************************************************************************
  83. **   Program Start
  84. */
  85. void main (int argc, char **argv)
  86. {
  87.  
  88.  
  89.     if ((argc != 4)){
  90.         helpScreen();
  91.         exit(-1);
  92.     }
  93.  
  94.     lptPort=atoi(argv[3]);                 /* set up the port */
  95.     strcpy(server,strupr(argv[1]));        /* server name     */
  96.     strcpy(filePath,strupr(argv[2]));      /* path to file    */
  97.  
  98.     ccode = NWCallsInit(NULL, NULL);
  99.     if (ccode != 0x0000){
  100.         printf("NWCallsInit failed with ccode =%X\n",ccode);
  101.     }
  102.  
  103.     captureTheQueue();
  104.     printData();
  105. }
  106.  
  107. /****************************************************************************
  108. ** Captures the specified file and prints the test data "this is a test"
  109. */
  110. void captureTheQueue(void)
  111. {
  112.  
  113.     /*--------------------------------------------------------------------
  114.     ** Check the capture status and if captured exit the program.
  115.     ** into temp buffers.
  116.     */
  117.     ccode = NWGetCaptureStatus(lptPort);
  118.     if (ccode ==0x00FF){
  119.         printf("LPT %d is already captured\n",lptPort);
  120.         exit(-1);
  121.     }
  122.  
  123.     ccode = NWGetConnectionHandle(
  124.               /* server name     >  */ server,
  125.               /* Novell reserved >  */ 0,
  126.               /* Conn Handle     <  */ &connHandle,
  127.               /* Novell Reserved <  */ NULL);
  128.  
  129.     if (ccode){
  130.         printf("NWGetConnectionHandle failed with ccode =%X\n",ccode);
  131.         exit(-1);
  132.     }
  133.  
  134.     ccode = NWStartFileCapture(
  135.               /* conn Handle    > */ connHandle,
  136.               /* port 1,2,3     > */ lptPort,
  137.               /* dir handle     > */ NULL,
  138.               /* file Path      > */ filePath);
  139.  
  140.     if (ccode){
  141.         printf("NWStartFileCapture failed with ccode =%X\n",ccode);
  142.         exit(-1);
  143.     }
  144.  
  145.     ccode = NWGetCaptureFlags(
  146.               /* port 1,2,3    > */ lptPort,
  147.               /* captureflags1 < */ &f1,
  148.               /* captureflags2 < */ &f2);
  149.  
  150.     if (ccode){
  151.         printf("NWGetCaptureFlags failed with ccode =%X\n",ccode);
  152.         exit(-1);
  153.     }
  154.     /*--------------------------------------------------------------------
  155.     ** setting the flushCaptureonClose=1 to turn it off will keep the file open     ** to continue to write to it. With the autoendcap (fluschcapt
  156.     */
  157.  
  158.     f1.flushCaptureOnClose=1;
  159.  
  160.  
  161.     ccode = NWSetCaptureFlags(
  162.               /* conn Handle    > */ connHandle,
  163.               /* port 1,2 or 3  > */ lptPort,
  164.               /* captureflags1  > */ &f1);
  165.  
  166.     if (ccode != 0x0000){
  167.         printf ("NWSetCaptureFlags error ccode=%X\n",ccode);
  168.         exit(-1);
  169.     }
  170.  }
  171.  
  172. /****************************************************************************
  173. ** Usage and help screen.
  174. */
  175. void helpScreen (void)
  176. {
  177.     clrscr();
  178.     gotoxy (34,5);
  179.     cputs ("CAP Usage");
  180.     gotoxy (11,7);
  181.     cprintf("Usage: FILECAP <server> <filename> <lpt port>");
  182.     gotoxy (15,8);
  183.     cputs("server   = server the queue is on.");
  184.     gotoxy (15,9);
  185.     cputs("file path= file to capture to:server\volume:Dir\..\Dir\file.\n");
  186.     gotoxy (15,10);
  187.     cputs("lpt port = the port 1 to 3 if netx and 1to 9 if vlm's");
  188.     gotoxy (31,16);
  189.     cputs ("Hit Return to Exit");
  190.     getch();
  191. }
  192.  
  193. /****************************************************************************
  194. ** Print the data to the file.
  195. */
  196. void printData(void)
  197. {
  198.     fprintf (stdprn,"This is a test");
  199. }
  200.  
  201.  
  202.