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 >
Wrap
Text File
|
1994-08-17
|
11KB
|
428 lines
/****************************************************************************
** File: MYCAP.C
**
** Prof: Print Services
**
** Desc: Sample Capture program.
**
** This program mimics the functionality of the CAPTURE.EXE
** NetWare Utility.
**
**
**
**
**
**
**
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** Programmer(s):
**
** Ini Who Firm
** -----------------------------------------------------------------------
** KLB Karl Bunnell Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 06-17-94 klb First code.
** 06-24-94 klb Added capture flags and functions.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** Macros
*/
#define NWDOS
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwcalls.h>
#include <nwerror.h>
/****************************************************************************
** This function contains the entire program.
**
*/
void main(int argC, char *argV[])
{
NWCCODE cCode;
NWCONN_HANDLE connHandle;
NWCAPTURE_FLAGS1 captureFlags;
NWOBJ_ID queueID;
WORD count;
NWLPT lptPort = 0x01;
int tiValue;
char serverName[48];
char queueName[48];
char *p, *ptr;
char c;
cCode = NWCallsInit(NULL,NULL);
if (cCode)
{
printf("\nCall to NWCallsInit failed!! Error code %04X\n", cCode);
exit(1);
}
if (argC < 2)
{
printf("\n---------------------------------------------------------------------------\n");
printf("\nUSAGE: MYCAP <options>");
printf("\nWhere options can be a combination of the following:\n");
printf("\n OPTION DESCRIPTION");
printf("\n ------ -----------");
printf("\n A Autoendcap");
printf("\n NA NoAutoendcap");
printf("\n NB No Banner");
printf("\n NFF No Form Feed");
printf("\n NT No Tabs expansion");
printf("\n TI= TImeout");
printf("\n L= Local LPT port");
printf("\n S= Server Name");
printf("\n Q= Queue Name");
printf("\n F= Form Number");
printf("\n C= Copies ");
printf("\n T= Tabs - Number of spaces in tab");
printf("\n B= Banner Name");
printf("\n NF= No Form Feed");
printf("\n K Keep if server goes down");
exit(0);
}
/*-------------------------------------------------------------------------
** Default capture flag settings:
*/
strcpy(captureFlags.jobDescription, "LPT Catch");
captureFlags.jobControlFlags = 0x0400;
captureFlags.tabSize = 0x08;
captureFlags.numCopies = 0x0001;
captureFlags.printFlags = 0xC0;
captureFlags.maxLines = 100;
captureFlags.maxChars = 120;
strcpy(captureFlags.formName, "\0");
captureFlags.formType = 0x0000;
strcpy(captureFlags.bannerText, "LST:");
captureFlags.flushCaptureTimeout = 0x0000;
captureFlags.flushCaptureOnClose = 0x0000;
/*-------------------------------------------------------------------------
**
*/
/* Retrieve connection ID */
cCode = NWGetDefaultConnectionID(&connHandle);
if(cCode)
{
printf("Call to NWGetDefaultConnectionID failed!! Error Code %04X\n", cCode);
exit(1);
}
cCode = NWGetFileServerName(
/* Connection Handle */ connHandle,
/* Server Name */ serverName
);
if(cCode)
{
printf("Call to NWGetFileServerName failed!! Error Code %04X\n", cCode);
exit(1);
}
for (count=1; count<argC; ++count)
{
switch (argV[count][0])
{
case 'L':
case 'l':
p = argV[count]; /* p= Get LPT Number */
p = (p+2);
lptPort = atoi(p);
break;
case 'S':
case 's':
p = argV[count]; /* p= Get Server Name */
p = (p+2);
ptr = strupr(p);
strcpy(serverName, ptr);
cCode = NWGetConnectionHandle(
/* Server Name */ serverName,
/* Reserved */ 0,
/* Connect handle */ &connHandle,
/* Reserved */ NULL
);
if(cCode)
{
cCode = NWAttachToFileServer(
/* Server Name */ serverName,
/* scope must be 0 */ 0,
/* New Conn Handle */ &connHandle
);
if (cCode)
{
switch (cCode)
{
case INVALID_CONNECTION:
printf("\nInvalid Connection!\n");
exit(1);
case NO_SERVER_ERROR:
printf("\nNO Server Error!\n");
exit(1);
case UNKNOWN_FILE_SERVER:
printf("\nUnknown File Server!\n");
exit(1);
default :
printf("\nUnknown error! Code = %04X\n", cCode);
exit(1);
}
}
cCode = NWLoginToFileServer(
/* connHandle */ connHandle,
/* Object Name */ "GUEST",
/* Object Type */ OT_USER,
/* Password */ ""
);
if (cCode)
{
switch (cCode)
{
case INVALID_CONNECTION:
printf("\nInvalid Connection!\n");
exit(1);
default :
printf("\nUnknown error! Code = %04X\n", cCode);
exit(1);
}
}
}
break;
case 'Q':
case 'q':
p = argV[count]; /* p= Get QUEUE Name */
p = (p+2);
ptr = strupr(p);
strcpy(queueName, ptr);
cCode = NWGetObjectID(
/* Conn Handle */ connHandle,
/* Object Name */ queueName,
/* Object type */ OT_PRINT_QUEUE,
/* Object ID */ &queueID
);
if(cCode)
{
printf("\nQueue %s does not exist on file server %s\n", queueName, serverName);
exit(1);
}
break;
case 'T':
case 't':
switch(argV[count][1])
{
case 'I':
case 'i':
p = argV[count]; /* p= Get time interval */
p = (p+3);
tiValue = atoi(p);
if (tiValue > 3640)
tiValue = 3640;
tiValue = tiValue * 18; /* convert ticks to seconds */
captureFlags.flushCaptureOnClose = 0x0001;
captureFlags.flushCaptureTimeout = tiValue;
break;
default :
p = argV[count]; /* p= Get tab size */
p = (p+2);
captureFlags.tabSize = (NWTAB)atoi(p);
break;
}
break;
case 'N':
case 'n':
switch(argV[count][1])
{
case 'T':
case 't':
captureFlags.printFlags = (captureFlags.printFlags & 0x80);
break;
case 'B':
case 'b':
captureFlags.printFlags = (captureFlags.printFlags & 0x40);
break;
case 'F':
case 'f':
captureFlags.printFlags = (captureFlags.printFlags & 0xC8);
break;
case 'A':
case 'a':
captureFlags.flushCaptureOnClose = 0x0001;
break;
}
break;
case 'K':
case 'k':
captureFlags.printFlags = (captureFlags.printFlags & 0xC4);
break;
case 'B':
case 'b':
p = argV[count]; /* p= Get name */
p = (p+2);
strcpy(captureFlags.bannerText, p);
break;
case 'C':
case 'c':
p = argV[count]; /* p= Get number of copies */
p = (p+2);
captureFlags.numCopies = atoi(p);
break;
case 'F':
case 'f':
p = argV[count]; /* p= Get form number */
p = (p+2);
captureFlags.formType = atoi(p);
break;
case 'A':
case 'a':
captureFlags.flushCaptureOnClose = 0x0000;
break;
}
}
cCode = NWStartQueueCapture(
/* Conn Handle */ connHandle,
/* LPTDevice */ lptPort,
/* queueID */ queueID,
/* Queue Name */ queueName
);
if(cCode)
{
printf("Call to NWStartQueueCapture failed!! Error Code %04X\n", cCode);
exit(1);
}
cCode = NWSetCaptureFlags(
/* Conn Handle */ connHandle,
/* LPTDevice */ lptPort,
/* RW Cap. flgs */ &captureFlags
);
if(cCode)
{
printf("Call to NWSetCaptureFlags failed!! Error Code %04X\n", cCode);
exit(1);
}
cCode = NWGetCaptureFlags(
/* LPT Device */ lptPort,
/* RW Cap flgs */ &captureFlags,
/* RO Cap flgs */ NULL
);
if(cCode)
{
printf("Call to NWGetCaptureFlags failed!! Error Code %04X\n", cCode);
exit(1);
}
printf("\nJob Control Flags : %02X", captureFlags.jobControlFlags);
printf("\nTabSize : %02X", captureFlags.tabSize);
printf("\nNumber of Copies : %04X", captureFlags.numCopies);
printf("\nPrintFlags : %04X", captureFlags.printFlags);
printf("\nMaxLines : %04X", captureFlags.maxLines);
printf("\nMaxChars : %04X", captureFlags.maxChars);
printf("\nFormName : %s", captureFlags.formName);
printf("\nFormType : %04X", captureFlags.formType);
printf("\nBanner Text : %s", captureFlags.bannerText);
printf("\nFlushCaptureTimeout : %04X", captureFlags.flushCaptureTimeout/18);
printf("\nFlushCaptureOnClose : %02X", captureFlags.flushCaptureOnClose);
printf("\nLPT%d successfully redirected to queue %s on server %s.\n",
lptPort, queueName, serverName);
}