Article View: comp.windows.interviews
Article #54Filter for displaying refman.PS on GhostView
From: Steinar Bang
Date: Tue, 03 Nov 1992 13:56
Date: Tue, 03 Nov 1992 13:56
97 lines
3338 bytes
3338 bytes
Hi!
Attached to this message is a postscript filter that will change the
iv/src/man/refman/refman.PS file of IV-3.1beta3 into a Conforming
Postscript file that will display correctly in the GhostView X
PostScript previewer.
GhostView will only display the first page of the refman.PS doc and
refuse to go any further in the document.
Compile with:
gcc -o conformps conformps.c
Run with:
conformps <refman.PS >ivman.ps
- Steinar
-----conformps.c------------------------------------
/* This is a tiny postscript filter that will turn the concatenated
* Conforming PostScript documents that make up iv/src/man/refman/refman.PS
* into a single Conforming Postscript document.
* This program changes the %%Page: lines to reflect the total position
* in the document. It also removes mid-document headers, prologs and
* trailers.
*
* Usage is: conformps <input-file >output-file
*
* Written by: Steinar Bang <steinarb@idt.unit.no>
* Dept. of EE & CS
* Norwegian Institute of Technology/University of Trondheim
* Trondheim, Norway
* Date: 921103
*
* This program is free for all use without any guarantees, implied or
* otherwise.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main(int argc,char* argv[]) {
char buf[256];
int totPages = 0,lineNo = 0;
FILE* fin = stdin;
FILE* fout = stdout;
while(fgets(buf,255,stdin) != NULL){
int pageNo = 0, match;
lineNo++;
if (sscanf(buf,"%%%%Page: %d",&pageNo) == 1) {
totPages++;
/* fprintf(stderr,"Page: %d Abspage: %d\n",pageNo,totPages); */
fprintf(stdout,"%%%%Page: %d %d \n",pageNo,totPages);
} else if (strncmp(buf,"%%Trailer",sizeof("%%Trailer") - 1) == 0) {
/* fprintf(stderr,"Trailer at line: %d \n",lineNo); */
/* gobble two more lines with:
* end restore
* Pages: <total page count>
*/
fgets(buf,255,stdin);
fgets(buf,255,stdin);
if (!gobbleProlog(stdin,&lineNo)) {
fprintf(stdout,"%%%%Trailer\nend restore\n");
fprintf(stdout,"%%%%Pages: %d\n",totPages);
return 0; /* Successfull exit */
}
} else {
/* fprintf(stdout,"%s",buf); */
fputs(buf,stdout);
}
}
return 1; /* Error exit */
}
/* This function gobbles the PostScript prolog and returns a 0 value if
* there is no prolog to be found (ie. the end of the file).
*/
int gobbleProlog(FILE* fp,int* lineNo) {
char buf[256];
/* If this is the end of the file, return NULL, no prolog to gobble
*/
if (fgets(buf,255,fp) == NULL) {
return 0;
} else {
(*lineNo)++;
while (strncmp(buf,"%%EndProlog",sizeof("%%EndProlog") - 1) != 0) {
if (fgets(buf,255,fp) == NULL) {
fprintf(stderr,"Unexpected EOF in line %d\n",*lineNo);
exit(1);
}
(*lineNo)++;
}
return 1; /* Gobbled a prolog */
}
}
Technical Details
Message-ID:
<STEINARB.92Nov3135608@hagtorn.idt.unit.no>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!ugle.unit.no!ugle.unit.no!steinarbShow Full Headers
Complete Article Headers
Newsgroups: comp.windows.interviews Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!ugle.unit.no!ugle.unit.no!steinarb From: steinarb@idt.unit.no (Steinar Bang) Subject: Filter for displaying refman.PS on GhostView Message-ID: <STEINARB.92Nov3135608@hagtorn.idt.unit.no> Sender: news@ugle.unit.no (NetNews Administrator) Organization: Norwegian Institute of Technology, Trondheim, Norway Date: 3 Nov 92 13:56:08 Lines: 97