306 lines
12 KiB
Diff
306 lines
12 KiB
Diff
gv (the successor to Tim Theisen's ghostview) by default can uncompress gziped
|
|
files on the fly. This patch allows to also uncompress bzip2-compressed files
|
|
on the fly.
|
|
|
|
Compressed input can't be read from a pipe, the input must be seekable. The
|
|
name of the compressed file is irrelevant, detection is by magic file ID. gv
|
|
can't read from stdin.
|
|
|
|
gv only allows to specify one program to handle the decompression, it might
|
|
make more sense to extend this to two, but it's also possible to use a short
|
|
shell script to handle both bzip2 and gzip decompression, which is what
|
|
gv_uncompress does.
|
|
|
|
Volker Kuhlmann <VolkerKuhlmann@gmx.de>, 22 Aug 2003
|
|
|
|
// Just extended to use bzip2 after the detection of bzip2 magic
|
|
// without the usage of an extern script.
|
|
// <werner@suse.de>
|
|
|
|
--- source/Imakefile
|
|
+++ source/Imakefile Fri Aug 22 16:13:35 2003
|
|
@@ -320,7 +320,8 @@
|
|
@echo "GV.gsSafer: True" >> $(GV_INTERN_RES_DAT)
|
|
@echo "GV.gsQuiet: True" >> $(GV_INTERN_RES_DAT)
|
|
@echo "GV.gsArguments:" >> $(GV_INTERN_RES_DAT)
|
|
- @echo "GV.uncompressCommand: gzip -d -c %s > %s" >> $(GV_INTERN_RES_DAT)
|
|
+ @echo "GV.uncompressCommand: gzip -d -c %s > %s" >> $(GV_INTERN_RES_DAT)
|
|
+ @echo "GV.bunzip2Command: bzip2 -d -c %s > %s" >> $(GV_INTERN_RES_DAT)
|
|
@echo "GV.printCommand: $(PRINT_COMMAND)" >> $(GV_INTERN_RES_DAT)
|
|
|
|
clean::
|
|
--- source/callbacks.c
|
|
+++ source/callbacks.c Fri Aug 22 15:49:25 2003
|
|
@@ -1271,6 +1271,7 @@
|
|
GV_XtFree(gv_miscmenu_entries_res);
|
|
GV_XtFree(gv_print_command);
|
|
GV_XtFree(gv_uncompress_command);
|
|
+ GV_XtFree(gv_bunzip2_command);
|
|
GV_XtFree(gv_gs_interpreter);
|
|
GV_XtFree(gv_gs_cmd_scan_pdf);
|
|
GV_XtFree(gv_gs_cmd_conv_pdf);
|
|
--- source/doc_misc.c
|
|
+++ source/doc_misc.c Fri Aug 22 16:04:43 2003
|
|
@@ -49,7 +49,7 @@
|
|
/*##################################################################*/
|
|
|
|
int
|
|
-doc_scanFile(fPP,docP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_uncP,cmd_uncompress,scanstyle)
|
|
+doc_scanFile(fPP,docP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_uncP,cmd_uncompress,cmd_bunzip2,scanstyle)
|
|
FILE ** fPP;
|
|
Document *docP;
|
|
String filename;
|
|
@@ -58,6 +58,7 @@
|
|
String cmd_scan_pdf;
|
|
String *filename_uncP;
|
|
String cmd_uncompress;
|
|
+ String cmd_bunzip2;
|
|
int scanstyle;
|
|
{
|
|
Document d;
|
|
@@ -67,7 +68,7 @@
|
|
d = (Document)NULL;
|
|
ret = 0;
|
|
if (*fPP && filename)
|
|
- d = psscan(fPP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_uncP,cmd_uncompress,scanstyle);
|
|
+ d = psscan(fPP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_uncP,cmd_uncompress,cmd_bunzip2,scanstyle);
|
|
if (d) {
|
|
d->labels_useful=0;
|
|
d->structured =0;
|
|
--- source/doc_misc.h
|
|
+++ source/doc_misc.h Fri Aug 22 15:51:37 2003
|
|
@@ -38,6 +38,7 @@
|
|
String,
|
|
String*,
|
|
String,
|
|
+ String,
|
|
int /* scanstyle */
|
|
#endif
|
|
);
|
|
--- source/file.c
|
|
+++ source/file.c Fri Aug 22 15:49:25 2003
|
|
@@ -376,6 +376,7 @@
|
|
while (*ext) { *ext = tolower(*ext); ext++; }
|
|
if (!strncmp(mext,".gz",3)) ext = "";
|
|
else if (!strncmp(mext,".z",2)) ext = "";
|
|
+ else if (!strncmp(mext,".bz2",4)) ext = "";
|
|
else if (!strncmp(mext,".ps",3)) ext = ".ps";
|
|
else if (!strncmp(mext,".pdf",4)) ext = ".pdf";
|
|
else ext = e;
|
|
--- source/main.c
|
|
+++ source/main.c Fri Aug 22 15:49:25 2003
|
|
@@ -348,6 +348,7 @@
|
|
main_setGhostscriptResources(gv_database);
|
|
main_setInternResource(gv_database,&gv_print_command,"printCommand");
|
|
main_setInternResource(gv_database,&gv_uncompress_command,"uncompressCommand");
|
|
+ main_setInternResource(gv_database,&gv_bunzip2_command,"bunzip2Command");
|
|
|
|
gv_user_defaults_file = resource_userDefaultsFile();
|
|
gv_screen = XtScreen(toplevel);
|
|
--- source/main_globals.h
|
|
+++ source/main_globals.h Fri Aug 22 15:49:25 2003
|
|
@@ -128,6 +128,7 @@
|
|
EXTERN String gv_user_defaults_file;
|
|
EXTERN String gv_print_command; /* command used to print doc, usually "lpr" */
|
|
EXTERN String gv_uncompress_command; /* command used to uncompress a file */
|
|
+EXTERN String gv_bunzip2_command; /* command used to bunzip2 a file */
|
|
EXTERN int gv_print_kills_file; /* whether the print symbiont removes the file after printing */
|
|
EXTERN int gv_exiting; /* flag set when exiting gv */
|
|
EXTERN String gv_dirs;
|
|
--- source/main_resources.h
|
|
+++ source/main_resources.h Fri Aug 22 15:58:27 2003
|
|
@@ -89,6 +89,7 @@
|
|
DECLARE_STRING(scales)
|
|
DECLARE_STRING(printCommand)
|
|
DECLARE_STRING(uncompressCommand)
|
|
+DECLARE_STRING(bunzip2Command)
|
|
|
|
DECLARE_STRING(gsInterpreter)
|
|
DECLARE_STRING(gsCmdScanPDF)
|
|
--- source/misc.c
|
|
+++ source/misc.c Fri Aug 22 15:49:25 2003
|
|
@@ -952,7 +952,7 @@
|
|
gv_filename,
|
|
gv_filename_raw,
|
|
&gv_filename_dsc,gv_gs_cmd_scan_pdf,
|
|
- &gv_filename_unc,gv_uncompress_command,
|
|
+ &gv_filename_unc,gv_uncompress_command,gv_bunzip2_command,
|
|
gv_scanstyle);
|
|
{
|
|
int m;
|
|
--- source/options_setup.c
|
|
+++ source/options_setup.c Fri Aug 22 15:49:25 2003
|
|
@@ -71,7 +71,7 @@
|
|
static Widget eyeGuideToggle,reverseScrollingToggle,confirmPrintToggle,autoCenterToggle;
|
|
static Widget pixmapToggle,miscLabel;
|
|
static Widget confirmLabel,confirmButton,confirmMenu,showTitleToggle;
|
|
-static Widget print_command,scales,uncompress,screenSize,medias,magmenu,miscmenu;
|
|
+static Widget print_command,scales,uncompress,bunzip2,screenSize,medias,magmenu,miscmenu;
|
|
|
|
static String confirm_quit_styles[4] = { "Never","When processing","Always", NULL };
|
|
|
|
@@ -117,6 +117,8 @@
|
|
widgets_setText(print_command, gv_print_command);
|
|
SMESSAGE(gv_uncompress_command)
|
|
widgets_setText(uncompress,gv_uncompress_command);
|
|
+ SMESSAGE(gv_bunzip2_command)
|
|
+ widgets_setText(bunzip2,gv_bunzip2_command);
|
|
SMESSAGE(gv_scales_res)
|
|
s = options_squeezeMultiline(gv_scales_res);
|
|
widgets_setText(scales,s);
|
|
@@ -178,6 +180,7 @@
|
|
}
|
|
|
|
options_textApply(uncompress,NULL,&gv_uncompress_command);
|
|
+ options_textApply(bunzip2,NULL,&gv_bunzip2_command);
|
|
options_textApply(print_command,NULL,&gv_print_command);
|
|
options_textApply(magmenu,NULL,&gv_magmenu_entries_res);
|
|
magmenu_freeMagMenuEntries(gv_magmenu_entries);
|
|
@@ -312,6 +315,8 @@
|
|
++argn;
|
|
options_setArg(&(argi[argn]),&(argv[argn]),s_uncompressCommand ,gv_class,widgets_getText(uncompress));
|
|
++argn;
|
|
+ options_setArg(&(argi[argn]),&(argv[argn]),s_bunzip2Command ,gv_class,widgets_getText(bunzip2));
|
|
+ ++argn;
|
|
options_setArg(&(argi[argn]),&(argv[argn]),s_confirmPrint ,gv_class ,SwitchIsSet(confirmPrintToggle) ? t : f);
|
|
++argn;
|
|
options_setArg(&(argi[argn]),&(argv[argn]),s_reverseScrolling ,gv_class ,SwitchIsSet(reverseScrollingToggle) ? t : f);
|
|
@@ -405,6 +410,7 @@
|
|
magmenu = widgets_createLabeledTextField("magmenu", optionControl);
|
|
medias = widgets_createLabeledTextField("medias", optionControl);
|
|
uncompress = widgets_createLabeledLineTextField("uncompress", optionControl);
|
|
+ bunzip2 = widgets_createLabeledLineTextField("bunzip2", optionControl);
|
|
print_command = widgets_createLabeledLineTextField("printCommand", optionControl);
|
|
scales = widgets_createLabeledTextField("scales", optionControl);
|
|
screenSize = widgets_createLabeledLineTextField("screenSize", optionControl);
|
|
--- source/ps.c
|
|
+++ source/ps.c Fri Aug 22 16:11:14 2003
|
|
@@ -353,7 +353,7 @@
|
|
/*###########################################################*/
|
|
|
|
struct document *
|
|
-psscan(fileP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_uncP,cmd_uncompress,scanstyle)
|
|
+psscan(fileP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_uncP,cmd_uncompress,cmd_bunzip2,scanstyle)
|
|
FILE **fileP;
|
|
char *filename;
|
|
char *filename_raw;
|
|
@@ -361,6 +361,7 @@
|
|
char *cmd_scan_pdf;
|
|
char **filename_uncP;
|
|
char *cmd_uncompress;
|
|
+ char *cmd_bunzip2;
|
|
int scanstyle;
|
|
{
|
|
FILE *file;
|
|
@@ -404,18 +405,27 @@
|
|
int ignore_dsc; /* Derived from scanstyle.
|
|
If set the document structure will be ignored.
|
|
*/
|
|
+ char *run_uncompress = NULL;
|
|
|
|
BEGINMESSAGE(psscan)
|
|
|
|
if (cmd_uncompress) {
|
|
- char b[2];
|
|
- if (!(fread(b, sizeof(char),2, *fileP) == 2)
|
|
- || b[0] != '\037' || (b[1] != '\235' && b[1] != '\213')) {
|
|
+ char b[4];
|
|
+ /* 0x1F9D, 0x1F8B = gzip */
|
|
+ #define is_gzip (b[0] == '\037' && (b[1] == '\235' || b[1] == '\213'))
|
|
+ /* "BZ" = bzip2; should we skip the test in b[3]? */
|
|
+ #define is_bzip2 (b[0] == 'B' && b[1] == 'Z' \
|
|
+ && (b[3] >= 48) && (b[3] <=57) )
|
|
+ if (fread(b, sizeof(char),4, *fileP) != 4) { /* I/O error */
|
|
rewind(*fileP);
|
|
- cmd_uncompress=NULL;
|
|
+ } else {
|
|
+ if (is_gzip)
|
|
+ run_uncompress=cmd_uncompress;
|
|
+ if (is_bzip2)
|
|
+ run_uncompress=cmd_bunzip2;
|
|
}
|
|
}
|
|
- if (cmd_uncompress) {
|
|
+ if (run_uncompress) {
|
|
struct document *retval = NULL;
|
|
FILE *tmpfile = (FILE*)NULL;
|
|
char *filename_unc;
|
|
@@ -425,7 +435,7 @@
|
|
filename_unc=file_getTmpFilename(NULL,filename_raw);
|
|
quoted_filename = quote_filename(filename);
|
|
quoted_filename_unc = quote_filename(filename_unc);
|
|
- sprintf(cmd,cmd_uncompress,quoted_filename,quoted_filename_unc);
|
|
+ sprintf(cmd,run_uncompress,quoted_filename,quoted_filename_unc);
|
|
GV_XtFree(quoted_filename);
|
|
GV_XtFree(quoted_filename_unc);
|
|
INFMESSAGE(is compressed)
|
|
@@ -449,7 +459,7 @@
|
|
if (!tmpfile) goto unc_exec_failed;
|
|
fclose(*fileP);
|
|
*fileP = tmpfile;
|
|
- retval = psscan(fileP,filename_unc,filename_raw,filename_dscP,cmd_scan_pdf,NULL,NULL,scanstyle);
|
|
+ retval = psscan(fileP,filename_unc,filename_raw,filename_dscP,cmd_scan_pdf,NULL,NULL,NULL,scanstyle);
|
|
#if 0
|
|
if (!retval) {
|
|
sprintf(s,"333 Scanning\n%s\nfailed.",filename_unc);
|
|
@@ -548,7 +558,7 @@
|
|
if (!tmpfile) goto scan_exec_failed;
|
|
fclose(*fileP);
|
|
*fileP = tmpfile;
|
|
- retval = psscan(fileP,filename_dsc,filename_raw,filename_dscP,cmd_scan_pdf,NULL,NULL,scanstyle);
|
|
+ retval = psscan(fileP,filename_dsc,filename_raw,filename_dscP,cmd_scan_pdf,NULL,NULL,NULL,scanstyle);
|
|
if (!retval) {
|
|
sprintf(s,"Scanning\n%s\nfailed.",filename_dsc);
|
|
goto scan_failed;
|
|
--- source/ps.h
|
|
+++ source/ps.h Fri Aug 22 16:10:21 2003
|
|
@@ -116,6 +116,7 @@
|
|
char *,
|
|
char **,
|
|
char *,
|
|
+ char *,
|
|
int /* scanstyle */
|
|
#endif
|
|
);
|
|
--- source/save.c
|
|
+++ source/save.c Fri Aug 22 16:00:03 2003
|
|
@@ -270,7 +270,7 @@
|
|
String s = GV_XtNewString(src_filename);
|
|
s = file_getUsefulName(s);
|
|
INFMESSAGE(scanning document)
|
|
- doc_scanFile(&src_file,&src_doc,src_filename,s,NULL,NULL,NULL,NULL,scanstyle);
|
|
+ doc_scanFile(&src_file,&src_doc,src_filename,s,NULL,NULL,NULL,NULL,NULL,scanstyle);
|
|
if (src_doc) {
|
|
INFMESSAGE(calling pscopydoc)
|
|
pscopydoc(save_file,src_filename,src_doc,pagelist);
|
|
--- source/gv_misc_res.dat
|
|
+++ source/gv_misc_res.dat 2003-08-25 12:35:43.000000000 +0000
|
|
@@ -349,6 +349,7 @@
|
|
GV*eyeGuide.label: Scrolling Eye Guide
|
|
GV*confirmPrint.label: Confirm Printing
|
|
GV*uncompressLabel.label: Uncompress
|
|
+GV*bunzip2Label.label: Bunzip2
|
|
GV*autoCenter.label: Auto Center
|
|
GV*printCommandLabel.label: Print Command
|
|
GV*scratchDirLabel.label: Scratch Directory
|
|
--- source/gv_layout_res.dat
|
|
+++ source/gv_layout_res.dat 2003-08-25 12:46:04.000000000 +0000
|
|
@@ -283,6 +283,8 @@
|
|
printCommandLabel<+[1]*>\
|
|
$bs\
|
|
uncompressLabel<+[1]*>\
|
|
+ $bs\
|
|
+ bunzip2Label<+[1]*>\
|
|
}\
|
|
$s\
|
|
|v{\
|
|
@@ -291,6 +293,8 @@
|
|
printCommandFrame<+[2]-100%*>\
|
|
$s\
|
|
uncompressFrame<+[2]-100%*>\
|
|
+ $s\
|
|
+ bunzip2Frame<+[2]-100%*>\
|
|
}\
|
|
}\
|
|
}\
|