[comp.sources.bugs] Allowing site specific printers in xfig 2.0

michael@parns.nsc.com (Michael C. Wagnitz) (03/09/90)

I find it extremely disheartening when someone opts to place site specific
dependencies in their source code.  It makes the program so very unportable.

Below is a set of patches for xfig version 2.0 (patchlevel 3) which provides
run-time support for a site's printer(s).  Users may now specify the default
(and additional) printer(s) using the environment variable PRINTER.  If more
than one printer exists for a site, the additional printers may be specified
by using PRINTER2 through PRINTER9 environment definitions (PRINTER1 is also
an equivalent definition for PRINTER).

Enjoy.
--
Michael Wagnitz M/S D3-677   uucp: {sun|hplabs|amdhal|decwrl}!nsc!parns!michael
National Semiconductor     Domain: michael@parns.nsc.com
2900 Semiconductor Dr.      Phone: 408/721-3266
Santa Clara, CA 95052-8090

This patch is predicated on the existance of patch 3 in the xfig source files.
Prereq: 3

*** patchlevel.h.orig	Thu Mar  8 12:29:28 1990
--- patchlevel.h	Thu Mar  8 12:29:36 1990
***************
*** 1 ****
! #define PATCHLEVEL 3
--- 1 ----
! #define PATCHLEVEL 4
*** global.c.orig	Thu Mar  8 09:49:23 1990
--- global.c	Thu Mar  8 09:57:25 1990
***************
*** 139,146 ****
  char			current_file[200] = "";
  int			cur_printer=0;
  char			*printer="";
! char			*printer_list[MAXPRINTERS]={"ap5","at6"};
  int			figure_modified = 0;
  
  /************************  Error messages  ****************************/
  
--- 139,147 ----
  char			current_file[200] = "";
  int			cur_printer=0;
  char			*printer="";
! char			**printer_list;
  int			figure_modified = 0;
+ int			MAXPRINTERS = 0;
  
  /************************  Error messages  ****************************/
  
*** const.h.orig	Thu Mar  8 09:56:03 1990
--- const.h	Thu Mar  8 09:56:20 1990
***************
*** 28,33 ****
  #define		SWITCH_ICON_HEIGHT	32
  #define		SWITCH_ICON_SPACING	4
  
- #define		MAXPRINTERS		2
- 
  #define		DEF_PRINTFONTSIZE	12	/* default printer font size (points) */
--- 28,31 ----
*** panel.c.orig	Thu Mar  8 09:55:40 1990
--- panel.c	Thu Mar  8 13:40:55 1990
***************
*** 36,42 ****
  extern	int	type_button;
  extern	char	*printer;
  extern	int	cur_printer;
! extern	char	*printer_list[];
  extern	int	INCHES;
  extern	TOOL	fontmenu;		/* popup menu for printer fonts */
  
--- 36,44 ----
  extern	int	type_button;
  extern	char	*printer;
  extern	int	cur_printer;
! extern	char	**printer_list;
! extern  int	MAXPRINTERS;
! 
  extern	int	INCHES;
  extern	TOOL	fontmenu;		/* popup menu for printer fonts */
  
***************
*** 1223,1232 ****
--- 1225,1263 ----
  
  printer_select()
  	{
+ 	char	*pname, *getenv(), tmpname[9];
+ 	int	i = 1;
+ 
  	if (*printer != '\0')	/* increment printer number if not first time here */
  		{
  		if (++cur_printer >= MAXPRINTERS)
  			cur_printer=0;
+ 		} else { /* initialize printer list if this is the first time thru */
+ /*
+ ** First, count total number of printers available, and make a list.  Default
+ ** definition is PRINTER, with optional (or alternate) printer list beginning
+ ** with PRINTER1, PRINTER2, etc.  If PRINTER is defined, assume list continues
+ ** with PRINTER2, etc. (i.e. PRINTER is an alias for PRINTER1).
+ */
+ 		if ((pname = getenv("PRINTER")) != NULL) {
+ 		   MAXPRINTERS++;
+ 		   i++;
+ 		  }
+ 		for (; sprintf(tmpname, "PRINTER%d", i) && getenv(tmpname); MAXPRINTERS++)
+ 		   { if (i++ == 9) break; }
+ 
+ 		printer_list = (char **) XtMalloc(MAXPRINTERS * sizeof(char *));
+ 
+ 		i = 0;
+ 		if ((pname = getenv("PRINTER")) != NULL) {
+ 		   printer_list[i] = XtNewString(pname);
+ 		   i++;
+ 		  }
+ 
+ 		for (; i < MAXPRINTERS; i++) {
+ 		    sprintf(tmpname, "PRINTER%d", i + 1);
+ 		    printer_list[i] = XtNewString(getenv(tmpname));
+ 		   }
  		}
  	printer=printer_list[cur_printer];
  	put_msg("SELECT PRINTER: %s",printer);
*** xfig.l.orig	Thu Mar  8 12:22:05 1990
--- xfig.l	Thu Mar  8 12:44:47 1990
***************
*** 1,4 ****
! .TH XFIG 1 "8 August 1988"
  .SH NAME
  xfig \- Facility for Interactive Generation of figures under X11
  .SH SYNOPSIS
--- 1,6 ----
! .ds Xf \fIxfig\fP
! .ds Xp \fIpostscript\fP
! .TH XFIG 1 "8 March 1990"
  .SH NAME
  xfig \- Facility for Interactive Generation of figures under X11
  .SH SYNOPSIS
***************
*** 19,40 ****
  [ \fB-normal[Font]\fP \fIfont\fP ]
  [ \fB-bold[Font]\fP \fIfont\fP ]
  .SH DESCRIPTION
! .I Xfig 
! is a menu-driven tool that allows the user to draw and manipulate objects
  interactively in an X window.  It runs under X version 11 release 3 or 4 and
  requires a three-button mouse.
  .I File 
  specifies the name of a file to be edited. The description of objects in
! the file will be read at the start of \fIxfig\fP. 
  .PP
! The output from \fIxfig\fP can be printed on a postcript printer:
  .PP
! f2ps (\fIxfig\fP to \fIpostscript\fP translator) is used to produce a 
! .I postscript
! file from an \fIxfig\fP file.
! The 
! .I postscript
! file can be sent directly to a postscript printer.
  .SH OPTIONS
  .TP
  .B \-ri
--- 21,38 ----
  [ \fB-normal[Font]\fP \fIfont\fP ]
  [ \fB-bold[Font]\fP \fIfont\fP ]
  .SH DESCRIPTION
! \*(Xf is a menu-driven tool that allows the user to draw and manipulate objects
  interactively in an X window.  It runs under X version 11 release 3 or 4 and
  requires a three-button mouse.
  .I File 
  specifies the name of a file to be edited. The description of objects in
! the file will be read at the start of \*(Xf. 
  .PP
! The output from \*(Xf can be printed on a postcript printer:
  .PP
! f2ps (\*(Xf to \*(Xp translator) is used to produce a \*(Xp
! file from an \*(Xf file.
! The \*(Xp file can be sent directly to a postscript printer.
  .SH OPTIONS
  .TP
  .B \-ri
***************
*** 45,60 ****
  Change the position of the side panel window to the left of the canvas window.
  .TP
  .B \-L
! Make \fIxfig\fP come up in landscape mode (10" x 7.5").  This is the default.
  .TP
  .B \-P
! Make \fIxfig\fP come up in portrait mode (7.5" x 10").
  .TP
  \fB-w\fP \fIunits\fP
! Make \fIxfig\fP come up \fIunits\fP wide (where units are either cm or in).
  .TP
  \fB-h\fP \fIunits\fP
! Make \fIxfig\fP come up \fIunits\fP high (where units are either cm or in).
  .TP
  \fB-tr\fP
  Turn on cursor (mouse) tracking arrows.
--- 43,58 ----
  Change the position of the side panel window to the left of the canvas window.
  .TP
  .B \-L
! Make \*(Xf come up in landscape mode (10" x 7.5").  This is the default.
  .TP
  .B \-P
! Make \*(Xf come up in portrait mode (7.5" x 10").
  .TP
  \fB-w\fP \fIunits\fP
! Make \*(Xf come up \fIunits\fP wide (where units are either cm or in).
  .TP
  \fB-h\fP \fIunits\fP
! Make \*(Xf come up \fIunits\fP high (where units are either cm or in).
  .TP
  \fB-tr\fP
  Turn on cursor (mouse) tracking arrows.
***************
*** 82,88 ****
  \fB-bold\fP \fIfont\fP
  Cause the font used for displaying messages to be \fIfont\fP.
  .SH "GRAPHICAL OBJECTS"
! The objects in \fIxfig\fP are divided into \fBprimitive objects\fP and
  \fBcompound object\fP. The primitive objects are: \fIARC\fP, \fICIRCLE\fP,
  \fICLOSED SPLINE\fP, \fIELLIPSE\fP, \fIPOLYLINE\fP, \fIPOLYGON\fP,
  \fISPLINE\fP, and \fITEXT\fP.  A primitive can be moved, rotated,
--- 80,86 ----
  \fB-bold\fP \fIfont\fP
  Cause the font used for displaying messages to be \fIfont\fP.
  .SH "GRAPHICAL OBJECTS"
! The objects in \*(Xf are divided into \fBprimitive objects\fP and
  \fBcompound object\fP. The primitive objects are: \fIARC\fP, \fICIRCLE\fP,
  \fICLOSED SPLINE\fP, \fIELLIPSE\fP, \fIPOLYLINE\fP, \fIPOLYGON\fP,
  \fISPLINE\fP, and \fITEXT\fP.  A primitive can be moved, rotated,
***************
*** 93,99 ****
  copied or erased.  An extra function that can be applied to a compound
  object is \fBscaling\fP, which is not available for primitive objects.
  .SH "DISPLAY WINDOWS"
! Nine windows comprise the display area of \fIxfig\fP: the 
  top ruler, the side ruler, two panel windows, the message window,
  three indicator windows showing current line thickness, area-fill gray
  color and rounded box corner radius, and the canvas window. 
--- 91,97 ----
  copied or erased.  An extra function that can be applied to a compound
  object is \fBscaling\fP, which is not available for primitive objects.
  .SH "DISPLAY WINDOWS"
! Nine windows comprise the display area of \*(Xf: the 
  top ruler, the side ruler, two panel windows, the message window,
  three indicator windows showing current line thickness, area-fill gray
  color and rounded box corner radius, and the canvas window. 
***************
*** 110,117 ****
  There are a number of file accessing functions in the pop-up menu.
  Most of the time when one of these functions is selected, the user
  will be asked for a file name.  If the specified file can be located
! and the access permission are granted, \fIxfig\fP will carry out
! the function.  However in case things go wrong, \fIxfig\fP will
  abort the function and printed the causes on the message window.
  Most of the functions in the pop-up menu can be directly access with
  the lower button panel.
--- 108,115 ----
  There are a number of file accessing functions in the pop-up menu.
  Most of the time when one of these functions is selected, the user
  will be asked for a file name.  If the specified file can be located
! and the access permission are granted, \*(Xf will carry out
! the function.  However in case things go wrong, \*(Xf will
  abort the function and printed the causes on the message window.
  Most of the functions in the pop-up menu can be directly access with
  the lower button panel.
***************
*** 153,164 ****
  will employ the current working directory.
  .TP
  .I Save & Quit
! Save the objects in the current file and exit from \fIxfig\fP.
  If there is no current file, the user will be asked for a file name.
  No confirmation will be asked.
  .TP
  .I Quit
! Exit from \fIxfig\fP, discarding all objects. The user will be asked to 
  confirm the action, by clicking the left button.
  .SH "BOTTOM PANEL COMMAND FUNCTIONS"
  Most of the buttons in the bottom panel are counterparts to the pop-up menu functions.
--- 151,162 ----
  will employ the current working directory.
  .TP
  .I Save & Quit
! Save the objects in the current file and exit from \*(Xf.
  If there is no current file, the user will be asked for a file name.
  No confirmation will be asked.
  .TP
  .I Quit
! Exit from \*(Xf, discarding all objects. The user will be asked to 
  confirm the action, by clicking the left button.
  .SH "BOTTOM PANEL COMMAND FUNCTIONS"
  Most of the buttons in the bottom panel are counterparts to the pop-up menu functions.
***************
*** 176,184 ****
  what that font looks like.
  If a corresponding X11 font exists, new text is created 
  on the canvas using that font.
! \fIxfig\fP uses the size of X11 font closest to that selected 
  by the font size button.
! If the X11 font doesn't exist, \fIxfig\fP uses the font 
  selected by the "-normal" option.
  To abort selection of a font, click on the title of the menu.
  .TP
--- 174,182 ----
  what that font looks like.
  If a corresponding X11 font exists, new text is created 
  on the canvas using that font.
! \*(Xf uses the size of X11 font closest to that selected 
  by the font size button.
! If the X11 font doesn't exist, \*(Xf uses the font 
  selected by the "-normal" option.
  To abort selection of a font, click on the title of the menu.
  .TP
***************
*** 188,198 ****
  .TP
  .I LANDSCAPE/PORTRAIT
  Select landscape or portrait mode of printing.
! The default setting is that of the \fIxfig\fP canvas.
  .TP
  .I PRINTER SELECT
  Toggle through a list of printers available for printing the figure. 
! At present this list must be compiled into \fIxfig\fP.
  .TP
  .I TEXT JUSTIFICATION
  Clicking this button cycles through selection of left, center and right justification
--- 186,201 ----
  .TP
  .I LANDSCAPE/PORTRAIT
  Select landscape or portrait mode of printing.
! The default setting is that of the \*(Xf canvas.
  .TP
  .I PRINTER SELECT
  Toggle through a list of printers available for printing the figure. 
! The printer selection list is now computed at run-time.  The environment
! variable PRINTER (or PRINTER1) designates the default printer for your system.
! Additional printers may be added to the list using the environment variables
! PRINTER1 through PRINTER9.  If PRINTER is designated in your environment, the
! additional entries should begin with PRINTER2.  A maximum of nine printer
! entries may be designated.
  .TP
  .I TEXT JUSTIFICATION
  Clicking this button cycles through selection of left, center and right justification
***************
*** 452,458 ****
  boldFont
  (string:8x13bold) -bold argument
  .PP
! These arguments correspond to the widgets which make up \fIxfig\fP.
  .TP 1.5i
  overall window
  form(Form)
--- 455,461 ----
  boldFont
  (string:8x13bold) -bold argument
  .PP
! These arguments correspond to the widgets which make up \*(Xf.
  .TP 1.5i
  overall window
  form(Form)
***************
*** 494,503 ****
  \f(CWxfig*form.panel.background: blue\fP
  .SH BUGS
  .PP
! Sometimes, \fIxfig\fP doesn't see that a figure has been modified,
  and will allow the user to quit or edit a new figure without confirmation.
  .PP
! Drawing text sometimes freezes up xfig.  Working on it.  Any help in this 
  area is welcome.
  .PP
  Creating a text object is not "Undoable".
--- 497,506 ----
  \f(CWxfig*form.panel.background: blue\fP
  .SH BUGS
  .PP
! Sometimes, \*(Xf doesn't see that a figure has been modified,
  and will allow the user to quit or edit a new figure without confirmation.
  .PP
! Drawing text sometimes freezes up \*(Xf.  Working on it.  Any help in this 
  area is welcome.
  .PP
  Creating a text object is not "Undoable".
***************
*** 509,515 ****
  Undoing the creation of a compound object deletes the objects
  inside the compound object.  Undoing the undo doesn't bring them back.
  .PP
! Ellipses which are too narrow may cause \fIxfig\fP to loop forever.
  .PP
  Objects which are created while one of the 
  .I grids
--- 512,518 ----
  Undoing the creation of a compound object deletes the objects
  inside the compound object.  Undoing the undo doesn't bring them back.
  .PP
! Ellipses which are too narrow may cause \*(Xf to loop forever.
  .PP
  Objects which are created while one of the 
  .I grids
***************
*** 577,579 ****
--- 580,590 ----
  (standard disclaimer applies)
  .br
  (bvsmith@lbl.gov)
+ .sp
+ Run-time support for site specific printers added by:
+ .br
+ Michael C. Wagnitz
+ .br
+ National Semiconductor Corporation
+ .br
+ (michael@parns.nsc.com)