
|
/*********************************************************************/ /* Transform an AFP spool file */ /* */ /* Name: TWPTAFP */ /* */ /* Function: Get an existing AFP spool file and load it into a */ /* userspace. Call the Transform AFP to ASCII API and */ /* pass it the user space loaded with AFP data, an */ /* output controls table, an output user space, and */ /* an error code parameter. */ /* Open a spool file and write to it the ASCII data */ /* from the output user space. */ /* */ /* Any error reported to this program ends the process. */ /* */ /* Parameters: */ /* 1. Spooled File Name : TYPE(*CHAR) LEN(10) */ /* */ /* This parameter specifies the name */ /* of the spooled file to be */ /* converted. */ /* */ |
/* 2. Qualified Job Name : TYPE(*CHAR) LEN(26) */ /* */ /* This parameter is used to identify */ /* the spooled file to transform. */ /* It contains the following three */ /* parts: */ /* */ /* Job Name : TYPE(*CHAR) LEN(10) */ /* Specifies the name of the job. */ /* Special values are not accepted. */ /* */ /* User Name : TYPE(*CHAR) LEN(10) */ /* Specifies the name of the user */ /* that owns the spooled file to be */ /* Transformed. */ /* Special values are not accepted. */ /* */ /* Job Number : TYPE(*CHAR) LEN(6) */ /* This parameter specifies the job */ /* number of the qualified job name. */ /* This is used to identify the */ /* spooled file to be converted. */ |
/* Special values are not accepted. */ /* */ /* 3. Spooled File Number : TYPE(*BIN) LEN(4) */ /* */ /* This parameter specifies the */ /* spooled file number. 1-9999 */ /* Two special values are accepted. */ /* 0 - Only one has the */ /* specified file name */ /* -1 - Uses the highest */ /* numbered spooled file */ /* with the specified */ /* file name. (default) */ /* */ /* 4. Data Stream Type : TYPE(*BIN) LEN(4) */ /* */ /* This parameter is an interger */ /* value that represents the type of */ /* ASCII data stream to be generated */ /* by the Transform AFP to ASCII API. */ /* */ /* 5. Top Border Size : TYPE(*BIN) LEN(4) */ |
/* */ /* This parameter specifies the size */ /* of the border on the top of the */ /* paper in 300ths of an inch. */ /* */ /* 6. Left Border Size : TYPE(*BIN) LEN(4) */ /* */ /* This parameter specifies the size */ /* of the border on the left side of */ /* the paper in 300ths of an inch. */ /* */ /* 7. Start Page Number : TYPE(*BIN) LEN(4) */ /* */ /* This parameter specifies the number*/ /* of the page to start transforming. */ /* */ /* 8. End Page Number : TYPE(*BIN) LEN(4) */ /* */ /* This parameter specifies the number*/ /* of the last page to transform. */ /* Special value *END means */ /* transform to end of data. */ |
/* */ /* 9. Set Character Position : TYPE(*CHAR) LEN(1) */ /* */ /* If this parameter is 'Y', the */ /* transform will set the position of */ /* each character on the page. */ /* This will produce a larger ASCII */ /* data stream but may improve the */ /* appearance of the output. */ /* If this parameter is 'N', the */ /* transform will not set the position*/ /* of each character. */ /* */ /* 10. Download Fonts : TYPE(*CHAR) LEN(1) */ /* */ /* If this parameter is 'Y', the */ /* transform may download a font to */ /* the printer in order to produce the*/ /* output. */ /* If this parameter is 'N', only */ /* fonts resident on the printer will */ /* be used to produce the output. */ |
/* */ /* Function Call Environment: */ /* Call this program by command ZTRNAFP. */ /* */ /* Running Environment : */ /* Other APIs needed: */ /* 1. QUSRJOBI (Retrieve Job Information) */ /* 2. QUSRSPLA (Get Spooled File Attributes) */ /* 3. QUSCRTUS (Create User Space) */ /* 4. QUSPTRUS (Retrieve User Space Using Pointer) */ /* 5. QSPOPNSP (Open A Spool File ) */ /* 6. QSPGETSP (Write Spool File's Data Into User Space) */ /* 7. QSPCLOSP (Close Spool File) */ /* 8. QUSDLTUS (Delete User Space) */ /* */ /*********************************************************************/ /* ***************************************************************** */ /* Include files. */ /* ***************************************************************** */ £include <stdio.h> /* Standard I/O routines */ |
£include <string.h> /* String handling routines */ £include <stdlib.h> /* Standard library */ £include "qusrtool/qattsysc(opusapi)" /* US API C header */ £include "qusrtool/qattsysc(opspapi)" /* SP API C header */ £include "qusrtool/qattsysc(opwpapi)" /* WP API C header */ £include <xxcvt.h> £define ON 1 £define OFF 0 £define TRUE 1 £define FALSE 0 £define MAX_SPACE_SIZE 16776704 £define PRINTF "QTAAPRTF" /*********************************************************************/ /* Declare data structures which will be used in the program. */ /*********************************************************************/ typedef struct é char NM¬10|; char LIB¬10|; |
è QNAME; /* Define the qualified name */ typedef struct é char JOBNAME¬10|; char USRNAME¬10|; char JOBNUM¬6|; è QJOBNAM; /* Define the qualified job name structure */ typedef struct é int BYTESPRO; int BYTESAVL; char EXCPID¬7|; char RESRVD; char EXCPDATA¬100|; è ERRSTRUCTURE; /* Define the error return structure */ typedef struct é int JOBIPL ; int JOBOFF ; char JOBTOD¬8|; è JOBID; /* Define the internal identifier structure */ |
typedef struct é int SPLFIPL ; int SPLFOFF ; char SPLFTOD¬8|; è SPLFID; /* Define internal spooled file identifier structure */ /*********************************************************************/ /* Declare all the global variables used in the program. */ /*********************************************************************/ QJOBNAM qjobnam; /* Qualified job name */ char format¬8|; /* Format name */ jobi0100 jobinfo; /* Receiver variable for */ /* QUSRJOBI */ /* Variables for QSPOPNSP */ JOBID ijobid; /* Internal Job Identifier */ SPLFID isplfid; /* Internal spool file */ /* identifier */ int erroccrd; /* Exception message occurred?*/ char msgid¬7|; /* CPF message ID */ char excpid¬7|; /* Error Code ID */ char excpmsg¬100|; /* Error Message */ char tbuf¬100|; /* Temporary buffer */ |
ERRSTRUCTURE errcode; /* Error Code Structure */ int info_len; /* int i; */ char user¬10|; char splfname¬10|; char job_name¬10|; char jobnumbr¬10|; char splfnumr¬10|; output_cntls o_c; int o_c_len; char * in_buf; char * out_buf; FILE * prtf; spla0200 splinfo; int len; int fnum; int h; /* char ch; */ |
char splfnam¬10|; spfr_header * space; spfr_header * inspace; int readrecs; /* Number of records to read */ int splfnum; /* Spool file number */ int buffer; /* Ordinal number of the */ /* buffer to get */ char eofind¬10|; /* Action on end of file */ char devcls¬10|; /* Device class */ /*********************************************************************/ /* Variables for QUSCRTUS API. */ /*********************************************************************/ QNAME inname; /* Qualified user space name */ QNAME outname; /* Qualified user space name */ char extattrib¬10|; /* External attributes */ long int initialsize; int in_size; int out_size; char initialvalue; char authority¬10|; char description¬50|; |
char replace¬10|; /*********************************************************************/ /* Beginning of Function Declarations. */ /*********************************************************************/ /*********************************************************************/ /* min - Get the smaller number of two numbers. */ /*********************************************************************/ int min( const int a1, const int a2) é if (a1 < a2) return a1 ; else return a2 ; è /*********************************************************************/ /* clear - Fill the string variable (cptr) with (len) blanks. */ /*********************************************************************/ void clear(char *cptr, const int len) é int i; |
char *charptr;
charptr = cptr;
for (i = 0; i < len; i++, charptr++) *charptr = ' ';
è
/*********************************************************************/
/* del_usr_sp - Delete a user space */
/*********************************************************************/
void del_usr_sp(char * us_name)
é
erroccrd = 0;
QUSDLTUS(us_name, (char *)&errcode);
if (erroccrd) é
printf("Error occurred during QUSDLTUS API. çn");
printf("User space %10s could not be deleted çn",
us_name);
è
è
|
/*********************************************************************/
/* signal_handler - Error handling for all CPF messages. */
/*********************************************************************/
void signal_handler(int sig)
é
sigdata_t *data;
usrmsg_t *msg;
exmsg_t *emsg;
data = sigdata(); /* Retrieve error data */
data->sigact->xumsg = OFF; /* Actions to be taken */
data->sigact->xhalt = OFF;
data->sigact->xdebug = OFF;
data->sigact->xdecerr = ON;
data->sigact->xremovemsg = OFF;
memcpy(msgid, data->exmsg->exmsgid, sizeof(msgid));
printf("Message Received : %sçn", msgid);
signal(SIGABRT, &signal_handler); /* Always remember to re- */
|
erroccrd = TRUE; /* declare signal handler */ è /******************************************************************* */ /* Beginning of Main routine. */ /******************************************************************* */ main(argc, argv) int argc; char *argv¬|; é /*-------------------------------------------------------------------*/ /* Declare the function signal_handler as the routine to be called */ /* when an exception message is received. */ /*-------------------------------------------------------------------*/ signal(SIGABRT, &signal_handler); /*-------------------------------------------------------------------*/ /* Copy the input parameters to local variables. */ /*-------------------------------------------------------------------*/ clear(splfname, sizeof(splfname) ); info_len = min(strlen(argv¬1|), 10); memcpy(splfname, argv¬1|, info_len ); |
clear(job_name, sizeof(job_name) ); info_len = min(strlen(argv¬2|), 10); memcpy(job_name, argv¬2|, info_len ); clear(user, sizeof(user)); info_len = min(strlen(argv¬2| + 10), 10); memcpy(user, argv¬2| + 10, info_len ); clear(jobnumbr, sizeof(jobnumbr)); info_len = min(strlen(argv¬2| + 20), 6); memcpy(jobnumbr, argv¬2| + 20, info_len ); clear(splfnumr, sizeof(splfnumr)); info_len = min(strlen(argv¬3|), 10); memcpy(splfnumr, argv¬3|, info_len ); o_c.data_stream = atoi(argv¬4|); o_c.top_border = atoi(argv¬5|); o_c.left_border = atoi(argv¬6|); |
o_c.start_page = atoi(argv¬7|); o_c.end_page = atoi(argv¬8|); o_c.set_char_pos = *argv¬9|; o_c.download_fonts = *argv¬10|; /*-------------------------------------------------------------------*/ /* Call QUSRJOBI API to retrieve current user name. */ /*-------------------------------------------------------------------*/ memcpy(format, "JOBI0100",8); clear((char *)&qjobnam, 26); memcpy((char *)&qjobnam, "*", 1); clear((char *)&ijobid,sizeof(ijobid)); erroccrd = FALSE; QUSRJOBI((char *)&jobinfo, sizeof(jobinfo), format, (char *)&qjobnam, |
(char *)&ijobid);
if (erroccrd) é
printf("Job information cannot be retrieved successfully§ çn");
printf("Ending the program çn");
exit(1);
è
/*-------------------------------------------------------------------*/
/* Call QUSRSPLA API to get information about the spooled file. */
/*-------------------------------------------------------------------*/
memcpy(format, "SPLA0200", sizeof(format));
clear(qjobnam.JOBNAME, 10);
memcpy(qjobnam.JOBNAME, job_name, sizeof(qjobnam.JOBNAME));
clear(qjobnam.USRNAME, sizeof(qjobnam.USRNAME));
memcpy(qjobnam.USRNAME, user, sizeof(qjobnam.USRNAME));
clear(qjobnam.JOBNUM, sizeof(qjobnam.JOBNUM));
memcpy(qjobnam.JOBNUM, jobnumbr, sizeof(qjobnam.JOBNUM));
clear((char *)(&ijobid), sizeof(ijobid));
clear((char *)(&isplfid), sizeof(isplfid));
fnum = atoi(splfnumr);
len = sizeof(splinfo);
|
clear((char *)(&splinfo), sizeof(splinfo));
memcpy(splfnam, splfname, sizeof(splfnam));
QUSRSPLA((char *)(&splinfo), len, format, (char *)(&qjobnam),
(char *)(&ijobid), (char *)(&isplfid), splfnam, fnum);
if (erroccrd) é
printf("The spooled file cannot be retrieved§ çn");
printf("Ending this program.çn");
exit(1);
è
/*-------------------------------------------------------------------*/
/* Process only printer files. */
/*-------------------------------------------------------------------*/
clear(devcls,sizeof(devcls));
strncpy (devcls, splinfo.dev_type, 10);
if (strncmp(devcls, "PRINTER ", 10) == 0) é
/*-------------------------------------------------------------------*/
/* Beginning of printer file processing. */
|
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ /* Call QUSCRTUS API to create a user space for retrieving the */ /* spooled file datastream. */ /*-------------------------------------------------------------------*/ /* set up user space name to be created */ clear(inname.NM, sizeof(inname.NM) ); memcpy(inname.NM, "IN ", 10); memcpy(inname.LIB, "QTEMP ", sizeof(inname.LIB)); /*-------------------------------------------------------------------*/ /* Set initial size of user space */ /* The size is calculated using the spooled file buffer size, */ /* the number of buffers in the spooled file and the number of */ /* pages. Additional constants are added for header information. */ /*-------------------------------------------------------------------*/ initialsize = (splinfo.file_buffer_size+84) * splinfo.number_buffers + (splinfo.total_pages*12) + 128 + sizeof(splinfo); |
/* Initialize the user space by NULL character */ initialvalue = 'ç0'; /* Public authority */ memcpy(authority, "*ALL ", sizeof(authority)); /* Set the external attributes of the user space */ memcpy(extattrib, "SPOOL_FILE", sizeof(extattrib)); /* Set the comments to the user space */ clear(description, sizeof(description)); strncpy(description, splinfo.splf_name,10) ; erroccrd = FALSE; /* Do not replace the user space if it exists */ memcpy(replace, "*NO ", sizeof(replace)); QUSCRTUS((char *)(&inname), extattrib, initialsize, &initialvalue, authority, description, replace, (char *)(&errcode)); |
if (erroccrd) é
printf("User Space %.10s in library %.10s cannot be createdçn",
inname.NM, inname.LIB);
printf("Ending this program.çn");
exit(0);
è
/*-------------------------------------------------------------------*/
/* Call QUSCRTUS API to create a user space for storing the trans- */
/* formed spooled file data. */
/*-------------------------------------------------------------------*/
/* set up user space name to be created */
clear(outname.NM, sizeof(outname.NM) );
memcpy(outname.NM, "OUT ", 10);
memcpy(outname.LIB, "QTEMP ", sizeof(outname.LIB));
/*-------------------------------------------------------------------*/
/* Set initial size of user space */
/* The size is made 10 times the size of the input user space or */
/* the maximum user space size, whichever is smaller. */
/*-------------------------------------------------------------------*/
|
out_size = min(MAX_SPACE_SIZE, (10 * initialsize));
QUSCRTUS((char *)(&outname), extattrib, out_size,
&initialvalue, authority, description, replace,
(char *)(&errcode));
if (erroccrd) é
printf("User Space %.10s in library %.10s cannot be createdçn",
outname.NM, outname.LIB);
printf("Ending this program.çn");
del_usr_sp((char *)&inname);
exit(0);
è
/*-------------------------------------------------------------------*/
/* Call QSPOPNSP API to open the spooled file */
/*-------------------------------------------------------------------*/
clear(qjobnam.JOBNAME, 10);
memcpy(qjobnam.JOBNAME, job_name, sizeof(qjobnam.JOBNAME));
clear(qjobnam.USRNAME, sizeof(qjobnam.USRNAME));
memcpy(qjobnam.USRNAME, user, sizeof(qjobnam.USRNAME));
|
clear(qjobnam.JOBNUM, sizeof(qjobnam.JOBNUM));
memcpy(qjobnam.JOBNUM, jobnumbr, sizeof(qjobnam.JOBNUM));
readrecs = -1;
splfnum = atoi(splfnumr);
memcpy(splfnam, splfname, sizeof(splfnam));
QSPOPNSP(&h,(char *)(&qjobnam), (char *)(&ijobid),
(char *)(&isplfid), splfnam, splfnum, readrecs,
(char *)(&errcode));
if (erroccrd) é
printf("Error occurs during open the spool file§ çn");
printf("Ending the program çn");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è
/*-------------------------------------------------------------------*/
/* Call QSPGETSP API to get data from spool file and put into a */
/* user space. */
/*-------------------------------------------------------------------*/
|
memcpy(format,"SPFR0300",sizeof(format));
buffer = -1;
memcpy(eofind,"*WAIT ", sizeof(eofind));
QSPGETSP(h, (char *)(&inname), format,
buffer, eofind, (char *)(&errcode));
if (erroccrd) é
printf("Error occurs during calling QSPGETSP API§ çn");
printf("Ending the program çn");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è
/*-------------------------------------------------------------------*/
/* CALL QUSPTRUS API to get a pointer to the input user space. */
/*-------------------------------------------------------------------*/
QUSPTRUS((char *)(&inname), &inspace);
if (erroccrd) é
|
printf("Error occurred during QUSPTRUS API çn");
printf("Ending the program çn");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è
/*------------------------------------------------------------------*/
/* CALL QSPCLOSP API to close the spooled file being transformed. */
/*------------------------------------------------------------------*/
QSPCLOSP(h, (char *)(&errcode) );
if (erroccrd) é
printf("Error occurred during closing the source spooled file.çn ");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è
/*--------------------------------------------------------------*/
/* Get the size of the input data. */
|
/*--------------------------------------------------------------*/ in_size= inspace->usrspc_used -(inspace->first_buffer_offset -1); /*--------------------------------------------------------------*/ /* Set pointer to the start of the input data. */ /*--------------------------------------------------------------*/ in_buf = ((char *)inspace) + inspace->first_buffer_offset; /*--------------------------------------------------------------*/ /* Move input data to the begining of the user space. */ /*--------------------------------------------------------------*/ memmove((char *)inspace, in_buf, in_size); /*--------------------------------------------------------------*/ /* Call Transform AFP to ASCII API */ /*--------------------------------------------------------------*/ o_c_len = sizeof(output_cntls); |
errcode.BYTESPRO = sizeof(errcode);
clear(errcode.EXCPID, sizeof(errcode.EXCPID));
clear(errcode.EXCPDATA, sizeof(errcode.EXCPDATA));
QWPZTAFP((char *)&inname, in_size, (char *)&outname,
&out_size, (char *)&o_c, o_c_len, (char *)&errcode);
memcpy(excpid, errcode.EXCPID, sizeof(excpid));
memcpy(excpmsg, errcode.EXCPDATA, sizeof(excpmsg));
excpid¬sizeof(excpid)| = 'ç0';
errcode.BYTESPRO = 0;
if (erroccrd) é
printf("Error occurred while transforming the AFP data to ASCII.çn ");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è else if (strcmp(excpid, " ") §= 0) é
printf("Error Code Returned : %s çn", excpid);
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
|
è
/*-------------------------------------------------------------------*/
/* CALL QUSPTRUS API to get a pointer to the output user space. */
/*-------------------------------------------------------------------*/
QUSPTRUS((char *)(&outname), &out_buf);
if (erroccrd) é
printf("Error occurred during QUSPTRUS API çn");
printf("Ending the program çn");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è
/*------------------------------------------------------------------*/
/* Open print file PRINTF which has a device type */
/* of *USERASCII. */
/*------------------------------------------------------------------*/
if ((prtf= fopen(PRINTF, "wb type=record recfm=fa lrecl=100"))
== NULL) é
printf ( "Could not open print file "PRINTF "çn" );
|
printf("Ending the program çn");
del_usr_sp((char *)&inname);
del_usr_sp((char *)&outname);
exit(0);
è
/*------------------------------------------------------------------*/
/* Write the output buffer to the print file */
/*------------------------------------------------------------------*/
while ( out_size >= 100 ) é
fwrite ( out_buf, 1, 100, prtf );
out_size -= 100;
out_buf += 100;
è
if (out_size) é
memset(tbuf, 0, sizeof(tbuf));
memcpy(tbuf, out_buf, out_size);
fwrite ( tbuf, 1, 100, prtf );
è
fclose (prtf);
|
/*-------------------------------------------------------------------*/ /* Delete the user spaces which have been created by this program. */ /*-------------------------------------------------------------------*/ del_usr_sp((char *)&inname); del_usr_sp((char *)&outname); /*-------------------------------------------------------------------*/ /* End of printer file processing. */ /*-------------------------------------------------------------------*/ è è /* end of main */ |