home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / msdos / apps / 6249 < prev    next >
Encoding:
Text File  |  1993-01-27  |  12.2 KB  |  408 lines

  1. Newsgroups: comp.os.msdos.apps
  2. Path: sparky!uunet!tcsi.com!iat.holonet.net!news.cerf.net!usc!cs.utexas.edu!torn!newshost.uwo.ca!news
  3. From: bhansen@valve.heart.rri.uwo.ca (Bjarne Hansen)
  4. Subject: Re: Postscript files in WordPerfect 5.1
  5. Reply-To: bhansen@valve.heart.rri.uwo.ca
  6. Organization: University of Western Ontario
  7. Date: Tue, 26 Jan 1993 19:57:34 GMT
  8. Message-ID: <1993Jan26.195734.9080@julian.uwo.ca>
  9. References: <1993Jan22.213806.6123@sol.UVic.CA>
  10. Keywords: Postscript, printing, control codes
  11. Sender: news@julian.uwo.ca (USENET News System)
  12. Nntp-Posting-Host: next2god.heart.rri.uwo.ca
  13. Lines: 393
  14.  
  15. In article <1993Jan22.213806.6123@sol.UVic.CA> rhorner@ugly.UVic.CA (Roger   
  16. Horner) writes:
  17. > ...
  18. > I then uploaded the postscript file to the unix machine with kermit
  19. > in text mode and tried to print it.  The printer gave an error
  20. > message (C5 I think), and then removed the file from the queue without
  21. > printing anything.
  22. > I have a friend who successfully printed the a file created in
  23. > MS-Word using a similar technique.  I compared his and my postscript
  24. > files and mine seems to have a slightly different format, but both
  25. > files can be displayed successfully with ghostscript. 
  26. >
  27. > Roger Horner (rhorner@sirius.UVic.ca)          University of Victoria
  28. > 4th Year Electrical Engineering Student        Victoria, BC, Canada
  29. >
  30.  
  31. I don't know what the error codes on your particular printer mean, but
  32. we have struggled in the past with printing PostScript files exported
  33. from various DOS programs (CorelDraw and WP51 come to mind).  In each 
  34. case the printer (a NEC LC-890) consistently choked on the PS file,
  35. regardless of whether it was brought over to our network via Kermit,
  36. FTP, or floppy.  
  37.  
  38. We discovered that the files that wouldn't print had unprintable 
  39. characters (often a control-D together with other assorted control
  40. characters) at the beginning and/or at the end of the file.  Once 
  41. these were removed, the files printed OK.  You can check whether the
  42. file you had problems with is corrupted the same way by opening it
  43. with an editor capable of displaying control characters.  Under
  44. Unix, vi or emacs will work.  The start of a PS file should look
  45. something like:  
  46.  
  47. %!PS-Adobe-1.0
  48. %%comments and document details
  49. %%more comments and document details
  50. ..
  51. ( if you want more detailed info, the 'PostScript Language Reference
  52. Manual' by Adobe Systems Inc, Addison-Wesley Publishing Co., will 
  53. tell you more than you want to know :-)
  54.  
  55. Solution:  If this is why your file isn't printing, then try deleting
  56. all the unprintable characters.  The above editors can do this, or you
  57. can use the program below.  Cut out the C code and compile it either
  58. on your PC or on a Unix machine (I tested it with MS-QuickC 2.51 on
  59. a PC, and with the compiler on our Silicon Graphics.  Both work.)
  60. To use, type 'isps postscript_print_file output_file' and 'output_file'
  61. will be created from 'postscript_print_file' minus the nasty 
  62. characters.  
  63.  
  64. Hope this helps with your problem.  If not, email me a copy of the 
  65. PS file.  If you need a copy of the isps executable, let me know...
  66.  
  67. Bjarne Hansen  <bhansen@valve.heart.rri.uwo.ca>
  68.                or NeXTmail at <bhansen@next2god.heart.rri.uwo.ca>
  69.  
  70. The axis of the earth sticks out visibly through the centre of each
  71. and every town or city.  Oliver Wendell Holmes 1809-1894.
  72. (especially Toronto...)
  73. ====================================================================
  74.  
  75. Sorry about the lines longer than 80 characters - hard not to exceed
  76. in a program.  If the text is too messed up to make sense of, I can 
  77. email, or repost without the tabs...
  78. ---------------------cut here-----isps.c source code------------------
  79. /* isps.c  accepts two arguments, an input filename and an output
  80.     filename.  It reads the first 2 characters of the input file
  81.     and if they are "%!", it assumes that it is a Postscript file.
  82.     Return codes are:
  83.         0 - No errors, file is not Postscript
  84.         1 - No filename or more than one supplied as arguments
  85.         2 - Error in opening filename (e.g. doesn't exist)
  86.         3 - Couldn't allocate enough memory for the file buffer
  87.         4 - File had embedded control characters, and doesn't
  88.             appear to be Postscript
  89.         5 - File had embedded control characters, but appears to
  90.             be Postscript
  91.         6 - File is Postscript
  92.  
  93.     Some CorelDraw files seem to include a <CTRL>D as the first
  94.     character.  To get around this, the program will scan the 1st
  95.     256 characters for the strings "%!" and "PS" if the initial
  96.     %! is not found.  WordPerfect generated PS files have also
  97.     been observed that contain control characters.
  98.  
  99.     Written by Bjarne Hansen.  4-1318 Highbury Ave, London, Ont,
  100.     Canada N5Y 5E5.    bhansen@valve.heart.RRI.UWO.CA
  101.         
  102.     You may freely distribute and use this program, but may not
  103.     charge any fee for doing so.  Any modified versions of this
  104.     program are subject to the same conditions.  
  105.  
  106.     Last modified 25 Jan 93.
  107. */
  108.  
  109. #include <stdio.h>
  110. #include <stdlib.h>
  111. #include <ctype.h>
  112. #include <malloc.h>
  113. #include <string.h>
  114. #include <errno.h>
  115.  
  116. #define TRUE 1
  117. #define FALSE 0
  118. #define VERSION 1.04
  119. #define KEYWORDS_THRESHOLD 13 /*# PS keywords to declare file PS*/
  120. #define NUM_KEYWORDS 13
  121. #define MIN_BUF_SIZE 1000 /*arbitrary min buffer for PS file*/
  122.  
  123. typedef short int Boolean;
  124.  
  125. extern int main( int argc, char *argv[])
  126. {
  127.     FILE *fptr, *fptr2;
  128.     char *buf, *tmp_buf_ptr;
  129.     char keywords[NUM_KEYWORDS][12] =   {   "{",
  130.                                      
  131.         "}",
  132.                                      
  133.         " def",
  134.                                      
  135.         " dup",
  136.                                      
  137.         " pop",
  138.                                      
  139.         " exch",
  140.                                      
  141.         " dict",
  142.                                      
  143.         " bind",
  144.                                      
  145.         " lineto",
  146.                                      
  147.         " moveto",
  148.                                      
  149.         " newpath",
  150.                                      
  151.         " stroke",
  152.                                      
  153.         " showpage"
  154.                                      
  155.     };
  156.     Boolean First_Time_Thru = TRUE;
  157.     Boolean Found_Ctrl_Chr = FALSE;
  158.     Boolean Found_PS = FALSE, Found_PS_in_middle = FALSE;
  159.     Boolean Found_Trailer = FALSE;
  160.     Boolean Verbose = FALSE;
  161.     int i, j, num_keywords_found = 0, num_end = 0;
  162.     long int file_length, buf_length = 40000;
  163.     size_t num_char_read, num_char_written;
  164.  
  165.     if( argc == 4 && (argv[3][0] == '/') && 
  166.             (toupper(argv[3][1]) == 'V') )
  167.         Verbose = TRUE;
  168.     if( argc == 3 || (argc == 4 && Verbose) )
  169.     {   if( (fptr = fopen(argv[1], "rb")) && 
  170.             (fptr2 = fopen(argv[2], "wb")) )
  171.         {   fseek(fptr, (long)0, SEEK_END);
  172.             file_length = ftell(fptr);
  173.             rewind(fptr);
  174.             if( Verbose ) printf("Length = %ld\n",  
  175. file_length);
  176.             
  177.             /*use the length of the file as buffer size, or*/
  178.             /*40000, whichever is less*/ 
  179.             if( file_length < buf_length )
  180.                 buf_length = file_length;   
  181.             
  182.             /* Dynamically allocate a large file buffer.*/
  183.             /* If there's not enough memory for it, cut the*/
  184.             /* buffer size in half and try again.*/
  185.             while( (buf = (char *)malloc( (size_t)buf_length  
  186. )) == NULL )
  187.             {   buf_length /= 2;
  188.                 if( buf_length < MIN_BUF_SIZE )
  189.                 {   fprintf( stderr, "Can't allocate  
  190. enough memory for the file buffer.\n");
  191.                     exit( 3 );
  192.                 }
  193.             }
  194.             
  195.             /*Read in file to buffer, changing non-printable*/
  196.              /*characters to whitespace*/
  197.             /*Rewrite the file to 'outputfile'.Repeat until  
  198. EOF */
  199.             while( !ferror(fptr) && !feof(fptr) && 
  200.                 !ferror(fptr2) && !feof(fptr2) )
  201.             {   num_char_read = fread( buf, 1, (size_t)
  202.                      buf_length-1, fptr );
  203.                 buf[num_char_read] = '\0';  
  204.                 /*change buf to a string for string fcns*/
  205.                 for( i = 0; i < num_char_read-1; i++ )
  206.                 {   if( !isprint( buf[i] ) && ( buf[i] !=
  207.  0xa) && ( buf[i] != 0xd) && (buf[i] != 0x9) )
  208.                     {   buf[i] = ' ';  /*CTRL chrs to  
  209. whitespace*/
  210.                         Found_Ctrl_Chr = TRUE;
  211.                     }
  212.                 }
  213.  
  214.                 if( First_Time_Thru )
  215.                 {   /*check 1st two char for '%!'*/
  216.                     if( buf[0] == '%' && buf[1] == '!'  
  217. )
  218.                     {   Found_PS = TRUE;
  219.                     }else
  220.                     {   /*look for strings "%!"  
  221. followed by "PS"*/
  222.                         if( ((tmp_buf_ptr =  
  223. strstr( buf, "%!") ) != NULL) && (strstr( tmp_buf_ptr, "PS") != NULL) )
  224.                         {   /*seems to be PS, so  
  225. put 1st two */
  226.                             /*char to "%!" and  
  227. whitespace the */
  228.                             /*rest up to  
  229. tmp_buf_ptr+2  */
  230.                             buf[0] = '%';
  231.                             buf[1] = '!';
  232.                             for( i = 2; i <  
  233. tmp_buf_ptr - buf + 2; i++ )
  234.                             {   buf[i] = ' ';
  235.                             }
  236.                             Found_PS_in_middle  
  237. = TRUE;
  238.                         }
  239.  
  240.                         /*count # keywords in 1st  
  241. 2000 chars */
  242.                         for( i=0; i<NUM_KEYWORDS;  
  243. i++)
  244.                         {   tmp_buf_ptr = buf;
  245.                             if( Verbose )  
  246. printf("counting keyword %s", keywords[i]);
  247.                             j = 0;
  248.                             do
  249.                             {   tmp_buf_ptr =  
  250. strstr( tmp_buf_ptr+1, keywords[i]);
  251.                                 j++;
  252.                             }while(  
  253. (tmp_buf_ptr != NULL) && ((tmp_buf_ptr - buf) < 2000) );
  254.                             j--;
  255.                             if( Verbose )  
  256. printf(" - %d instances\n", j);
  257.                             num_keywords_found  
  258. += j;
  259.                         }
  260.                     }   /*end of else, when '%!' are  
  261. not 1st */
  262.                         /*two chrs in file*/
  263.                     First_Time_Thru = FALSE;
  264.                 }   /*end of 1st time thru checks*/
  265.  
  266.                 /*look for %%Trailer*/
  267.                 if( (tmp_buf_ptr = strstr(buf,  
  268. "%%Trailer")) != NULL )
  269.                 {   if( Verbose ) printf("found Trailer  
  270. comment.\n");
  271.                     Found_Trailer = TRUE;
  272.                     /*search for "end" */
  273.                     if( (tmp_buf_ptr =  
  274. strstr(tmp_buf_ptr, "end")) != NULL )
  275.                     {   if( Verbose ) printf("found  
  276. 'end'.\n");
  277.                         *(tmp_buf_ptr + 3) = '\0';
  278.                         strcat( buf,  
  279. "\nshowpage\n");
  280.                     }else
  281.                     {   if( Verbose ) printf("did not  
  282. find 'end'.\n");
  283.                         tmp_buf_ptr = strstr(buf,  
  284. "%%Trailer");
  285.                         *(tmp_buf_ptr + 9) = '\0';
  286.                         strcat( buf,  
  287. "\nshowpage\n");
  288.                     }
  289.                 }else
  290.                 {   /*did not find a %%Trailer*/
  291.                 }
  292.  
  293.                 /*write the changed buffer to output file  
  294. */
  295.                 num_char_written = fwrite( buf, 1,  
  296. strlen(buf), fptr2 );
  297.             
  298.             }   /*end of while that reads in file, writes out  
  299. */
  300.             if( ferror(fptr) )
  301.             {   fclose(fptr);
  302.                 fclose(fptr2);
  303.                 fprintf(stderr, "Error occurred while  
  304. reading file.\n");
  305.                 exit( 2 );
  306.             }else if( ferror(fptr2) | feof(fptr2) )
  307.             {   fclose(fptr);
  308.                 fclose(fptr2);
  309.                 fprintf(stderr, "Error occurred while  
  310. writing file.\n");
  311.                 exit( 2 );
  312.             }else if( feof(fptr) )
  313.             {   /*finished reading in file,  ctrl chrs to '  
  314. '*/
  315.                 /*and writing to output file.*/
  316.  
  317.                 fclose(fptr);
  318.                 fclose(fptr2);
  319.  
  320.                 /*now check the various flags to decide  
  321. what */
  322.                 /*type of file it is*/
  323.                 if( Found_PS )
  324.                 {   if( Verbose ) 
  325.                     {   printf("Found 'percent-bang'  
  326. as 1st two characters in the file.\n");
  327.                         if( Found_Ctrl_Chr )
  328.                             printf("Found  
  329. non-printable characters in file.  They were removed.\n");
  330.                         printf("It is  
  331. PostScript.\n");
  332.                     }
  333.                     if( Found_Ctrl_Chr ) 
  334.                         exit( 5 );
  335.                     else
  336.                         exit( 6 );
  337.                 }else if( Found_PS_in_middle )
  338.                 {   if( Verbose ) 
  339.                     {   printf("Found 'percent-bang',  
  340. but not as 1st two characters in the file.\n");
  341.                         if( Found_Ctrl_Chr )
  342.                             printf("Found  
  343. non-printable characters in file.  They were removed.\n");
  344.                         printf("Found %d instances  
  345. of PostScript keywords in file.\n", num_keywords_found);
  346.                         if( num_keywords_found >  
  347. KEYWORDS_THRESHOLD )
  348.                             printf("It is  
  349. PostScript.\n");
  350.                         else
  351.                             printf("It is not  
  352. PostScript.\n");
  353.                     }
  354.                     if( num_keywords_found >  
  355. KEYWORDS_THRESHOLD )
  356.                         exit( 5 );
  357.                     else
  358.                         exit( 4 );
  359.                 }else if( num_keywords_found  
  360. >KEYWORDS_THRESHOLD )
  361.                 {   if( Verbose )
  362.                     {   printf("Found %d instances of  
  363. PostScript keywords in file.\n", num_keywords_found);
  364.                         printf("It is  
  365. PostScript.\n");
  366.                     }
  367.                     exit( 5 );
  368.                 }else
  369.                 {   if( Verbose ) printf("File is not  
  370. PostScript.\n");
  371.                     exit( 0 );
  372.                 }
  373.             }
  374.         }   /*end of if that tried to open file */
  375.         else
  376.         {   printf( "Error in opening file %s.\n", argv[1] );
  377.             exit( 2 );
  378.         }
  379.     }   /*end of if that checked command-line parameters rec'd*/
  380.     else
  381.     {   printf("\n\nISPS - Checks text files to determine if they are  
  382. PostScript.\n");
  383.         printf("Corrects some irregularities and rewrites the file  
  384. to 'outputfile'.\n");
  385.         printf("Version %4.2f by Bjarne Hansen\n\n", VERSION);
  386.         printf("Return codes are:\n");
  387.         printf("\t0 - No errors, file is not Postscript\n"); 
  388.         printf("\t1 - No filename or more than one supplied as  
  389. arguments\n"); 
  390.         printf("\t2 - Error in opening filename (e.g. doesn't  
  391. exist)\n"); 
  392.         printf("\t3 - Couldn't allocate enough memory for the file  
  393. buffer\n"); 
  394.         printf("\t4 - File had too few PS characteristics to be  
  395. sure it is Postscript\n"); 
  396.         printf("\t5 - File had extraneous characters, but appears  
  397. to be Postscript\n"); 
  398.         printf("\t6 - File is Postscript\n\n"); 
  399.         printf("Syntax:  %s filetotest outputfile  
  400. [/V[erbose]]\n\n", argv[0] );
  401.         exit( 1 );
  402.     }
  403. }    /*end of isps.c */
  404. ------------------------------end----------------------------------------
  405.  
  406.    
  407.