/* LJPLOT */ /* this program takes an AUTOCAD HPGL plot file sends it to an */ /* HP LaserJet III printer. The printer is prepared as: */ /* 1 - reset */ /* 2 - HPGL mode */ /* the file has all escape sequences before the HPGL "IN" */ /* command stripped out. Then, the "IN" command is replaced */ /* by "INRO90", basically doing a landscape plot */ /* The AUTOCAD setup is: */ /* Plotter: */ /* Pens don't seem to matter */ /* This software is provided as is without any waranty or gaurantee */ /* It is Copyright (c) 1990, SIRIUS Systems Co., Albuquerque, NM */ /* This is free software and you may make and use and give away */ /* as many coppies as you like. You may not sell this software in */ /* any form, alone or bundled. */ /* Exit codes: 1 - no args 2 - command line error */ /* 3 - plot file open error 4 - printer error */ /* 5 - plot file not HPGL ? */ #define ERR_ARGS 1 #define ERR_COMMAND_LINE 2 #define ERR_FILE 3 #define ERR_PRINTER 4 #define ERR_HPGL 5 #include #include #include #include #include #include #define BUFSIZE 16384 int inpath,outpath; /* input and output file pointers */ int port = 0; /* flag for portrait mode on command line */ char *width = 0; /* value (string in mm) of pen width from command line */ int errabort = 0; /* flag to abort on error or not */ int overplot = 0; /* flag is set to prevent a reset between plots */ /* this prevents the form feed and allows two plots */ /* to be overlaid in memery before actually printing */ char buffer[BUFSIZE]; /* plotfile Read/Write buffer */ int plotnum = 0; /* count the number of plots here */ int final_reset = 1; /* default to reset at the end, also the beginning */ main(argc,argv) int argc; char *argv[]; { char *file_of_names = 0; /* pointer to a file containing file names to plot */ FILE *names_fp; /* FILE pointer to file for reading names from */ /* char *defext = "plt"; */ char *def_width = ".25"; int i,j,k; char linebuf[128]; /* buffer for reading filenames */ /* process files as they are encountered */ /* For menu help, -? or /? must be the first arg (or no args at all) */ /* Check for help */ if(argc==1 || !strcmp(argv[1],"/?") || !strcmp(argv[2],"-?") ) { prusage(); exit((argc>1)?0:ERR_ARGS); } if ( (outpath=open("PRN",O_WRONLY)) == -1 ) { printf("can't open printer\n"); /* exit with printer error */ exit(ERR_PRINTER); } for( i=1; i 1 ) { printf(" as overlay"); } printf("\n"); /* start new file name line */ /* step 3 */ char_count = read(inpath,buffer,BUFSIZE); p = buffer; while( strncmp(p,"IN;",3) && char_count ) { /* make p point to HPGL INIT */ p++; char_count--; /* keep track of skipped garbage */ } if( !char_count ) { printf("NO PLOT INITIALIZATION FOUND - CHECK FILE\n"); return(ERR_HPGL); } p+=3; /* pass it */ char_count-=3; /* and send that many less chars */ /* step 4 */ strcpy(header,"IN"); if( !port ) strcat(header,"RO90"); if( width ) { strcat(header,"PW"); strcat(header,width); strcat(header,";"); itoa(width,&header[strlen(header)],10); } write(outpath,header,strlen(header)); /* step 5 */ write(outpath,p,char_count); /* send what's in the buffer */ while( (char_count=read(inpath,buffer,BUFSIZE)) >0 ) { /* send the rest */ /* any processing of file params goes here */ write(outpath,buffer,char_count); } /* steps 6 and 7 */ if( ! overplot ) write(outpath,"\033E",2); else overplot++; plotnum++; close(inpath); return(0); } prusage() { printf("LJPLOT: Send AUTOCAD HPGL plot files to HP LaserJet III, V1.0\n"); printf("Copyright (c) 1990, SIRIUS Systems Co.\n"); printf("Syntax: [switches] files [switches] files\n"); printf("Command line processed left to right\n"); printf("Switches:\n"); printf(" /o - overplot following files (toggle)\n"); printf(" /p - use portrait mode (don't rotate plot) (toggle)\n"); printf(" /ffilename - read file list\n"); printf(" /wnum - set pen width\n"); }