[5338] in Athena Bugs
enhancements to xman; part 2 -- "tabbing"
daemon@ATHENA.MIT.EDU (vanharen@ATHENA.MIT.EDU)
Thu Jun 28 05:13:12 1990
From: vanharen@ATHENA.MIT.EDU
Date: Thu, 28 Jun 90 05:12:51 -0400
To: bugs@ATHENA.MIT.EDU
The patch following is a patch to 1 file: ScrollByL.c
This patch allows xman to simulate tabbing, which makes tables line up
nicely. It does not necessarily always do the correct thing, in that it
"tabs" sometimes when you would not want it to, but in my experience,
this happens very rarely, and the benefit of nicely lined-up tables far
outweighs the slim chance that a manpage might be formatted strangely
for a line or 2.
A description of the patch:
- ScrollByL.c: whenever there are 2 or more consecutive spaces,
it is assumed that the intent was to tab over to some horizontal
location. Manpages are formatted with multiple spaces to tab out to a
particular place, and while this works with monospaced fonts,
variable-width fonts lose horribly. Therefore, a new counter "h_col"
keeps track of the horizontal column that we would be in if printing in
a fixed-width font (or you can consider it the number of characters
already printed on that line). The x location ("x_loc") used to print
the text after a "tab" is then set to the "h_col" * 60% of the maximum
width of a character in the current font. The number 60% was arrived at
by experimentation. You will see lines added to keep track of "h_col"
sprinkled throughout this patch...
NOTE:
This patch contains context diffs against the code arrived at by
applying the 2 previous patches submitted to "bugs" (both the
first-line-misprint-bug patch, and the real "bullet" printing patch).
Therefore, both of those should be audited and tested and applied before
applying this patch. This is due to the fact that this patch makes
additions inside the "bullet" printing patch, to keep track of the
horizontal column as mentioned earlier, and so a patch to the original
code in /mit/x11/src/mit/clients/xman would not contain all of the
necessary diffs to work with the "bullet" patch as well.
-Chris.
==============================================================================
*** /mit/x11/src/mit/clients/xman/ScrollByLP.h Thu Dec 7 15:49:51 1989
--- ScrollByLP.h Sat Jun 9 01:02:33 1990
***************
*** 54,62 ****
use_right; /* put scroll bar on right side of window. */
FILE * file; /* The file to display. */
Dimension indent; /* amount to indent the file. */
! XFontStruct * bold_font, /* The three fonts. */
* normal_font,
! * italic_font;
/* variables not in resource list. */
--- 54,63 ----
use_right; /* put scroll bar on right side of window. */
FILE * file; /* The file to display. */
Dimension indent; /* amount to indent the file. */
! XFontStruct * bold_font, /* The four fonts. */
* normal_font,
! * italic_font,
! * symbol_font;
/* variables not in resource list. */
***************
*** 66,72 ****
of the window being displayed. */
Dimension offset; /* Drawing offset because of scrollbar. */
GC move_gc; /* GC to use when moving the text. */
! GC bold_gc, normal_gc, italic_gc; /* gc for drawing. */
char ** top_line; /* The top line of the file. */
int lines; /* number of line in the file. */
--- 67,73 ----
of the window being displayed. */
Dimension offset; /* Drawing offset because of scrollbar. */
GC move_gc; /* GC to use when moving the text. */
! GC bold_gc, normal_gc, italic_gc, symbol_gc; /* gc for drawing. */
char ** top_line; /* The top line of the file. */
int lines; /* number of line in the file. */
==============================================================================
*** /mit/x11/src/mit/clients/xman/ScrollByL.h Fri Jul 21 17:33:50 1989
--- ScrollByL.h Sat Jun 9 01:01:40 1990
***************
*** 37,46 ****
--- 37,48 ----
#define MANPAGE_NORMAL "fixed"
#define MANPAGE_BOLD "helvetica-bold12"
#define MANPAGE_ITALIC "helvetica-boldoblique12"
+ #define MANPAGE_SYMBOL "symbol-medium12"
#else
#define MANPAGE_NORMAL "*-new century schoolbook-medium-r-normal--*-120-*"
#define MANPAGE_BOLD "*-new century schoolbook-bold-r-normal--*-120-*"
#define MANPAGE_ITALIC "*-new century schoolbook-bold-i-normal--*-120-*"
+ #define MANPAGE_SYMBOL "*-symbol-medium-r-normal--*-120-*"
#endif /* ATHENA */
#define XtNindent "indent"
***************
*** 48,53 ****
--- 50,56 ----
#define XtNmanualFontNormal "manualFontNormal"
#define XtNmanualFontBold "manualFontBold"
#define XtNmanualFontItalic "manualFontItalic"
+ #define XtNmanualFontSymbol "manualFontSymbol"
#define XtCIndent "Indent"
==============================================================================
*** /mit/x11/src/mit/clients/xman/ScrollByL.c Sat Jan 27 07:45:11 1990
--- ScrollByL.c Thu Jun 28 04:25:09 1990
***************
*** 2,8 ****
* xman - X window system manual page display program.
*
* $XConsortium: ScrollByL.c,v 1.13 90/01/11 20:09:00 keith Exp $
! * $Header: /afs/testers.athena.mit.edu/src/x11r4/src/mit/clients/xman/RCS/ScrollByL.c,v 1.2 90/01/27 07:45:03 epeisach Exp $
*
* Copyright 1987, 1988 Massachusetts Institute of Technology
*
--- 2,8 ----
* xman - X window system manual page display program.
*
* $XConsortium: ScrollByL.c,v 1.13 90/01/11 20:09:00 keith Exp $
! * $Header: /site/usr/local/xman.src/RCS/ScrollByL.c,v 1.3 90/06/28 03:36:11 vanharen Exp $
*
* Copyright 1987, 1988 Massachusetts Institute of Technology
*
***************
*** 77,82 ****
--- 77,84 ----
Offset(bold_font), XtRString, MANPAGE_BOLD},
{XtNmanualFontItalic, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
Offset(italic_font), XtRString, MANPAGE_ITALIC},
+ {XtNmanualFontSymbol, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
+ Offset(symbol_font), XtRString, MANPAGE_SYMBOL},
{XtNfile, XtCFile, XtRFile, sizeof(FILE *),
Offset(file), XtRImmediate, (caddr_t) NULL},
};
***************
*** 648,653 ****
--- 650,658 ----
values.font = sblw->scroll.bold_font->fid;
sblw->scroll.bold_gc = XtGetGC(w, mask, &values);
+
+ values.font = sblw->scroll.symbol_font->fid;
+ sblw->scroll.symbol_gc = XtGetGC(w, mask, &values);
}
/* Function Name: DestroyGCs
***************
*** 666,671 ****
--- 671,677 ----
XtReleaseGC(w, sblw->scroll.bold_gc);
XtReleaseGC(w, sblw->scroll.italic_gc);
XtReleaseGC(w, sblw->scroll.move_gc);
+ XtReleaseGC(w, sblw->scroll.symbol_gc);
}
static void
***************
*** 871,876 ****
--- 877,890 ----
me to bold the first line of each page.*/
#define BACKSPACE 010 /* I doubt you would want to change this. */
+ #define NORMAL 0
+ #define BOLD 1
+ #define ITALIC 2
+ #define SYMBOL 3
+ #define WHICH(italic, bold) ((bold) ? BOLD : ((italic) ? ITALIC : NORMAL))
+ /* Choose BOLD over ITALICS. If neither */
+ /* is chosen, use NORMAL. */
+
/* Function Name: PrintText
* Description: This function actually prints the text.
* Arguments: w - the ScrollByLine widget.
***************
*** 950,956 ****
switch(*c) {
case '\0': /* If we reach the end of the file then return */
! DumpText(w, x_loc, y_loc, buf, bufp - buf, italicflag, FALSE);
return;
case '\n':
--- 964,970 ----
switch(*c) {
case '\0': /* If we reach the end of the file then return */
! DumpText(w, x_loc, y_loc, buf, bufp - buf, WHICH(italicflag, first));
return;
case '\n':
***************
*** 960,966 ****
bold = ( (first) || ((x_loc == (sblw->scroll.offset +
sblw->scroll.indent)) && Boldify(buf)) );
! (void) DumpText(w, x_loc, y_loc, buf, bufp - buf, italicflag, bold);
if (bold)
first = FALSE;
}
--- 974,982 ----
bold = ( (first) || ((x_loc == (sblw->scroll.offset +
sblw->scroll.indent)) && Boldify(buf)) );
! (void) DumpText(w, x_loc, y_loc, buf, bufp - buf,
! WHICH(italicflag, bold));
!
if (bold)
first = FALSE;
}
***************
*** 984,992 ****
*/
case '\t': /* TAB */
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, italicflag, FALSE);
bufp = buf;
! italicflag = 0;
x_loc += width - (x_loc % width);
break;
--- 1000,1009 ----
*/
case '\t': /* TAB */
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
! WHICH(italicflag, first));
bufp = buf;
! italicflag = FALSE;
x_loc += width - (x_loc % width);
break;
***************
*** 1003,1014 ****
if (c[-1] == c[1] && c[1] != BACKSPACE) { /* overstriking one char */
bufp--; /* Zap 1st instance of char to bolden */
if (bufp > buf) {
! x_loc = DumpText(w, x_loc, y_loc, buf,
! bufp - buf, italicflag, FALSE);
bufp = buf;
}
*bufp++ = c[1];
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, FALSE, TRUE);
bufp = buf;
first = FALSE;
--- 1020,1031 ----
if (c[-1] == c[1] && c[1] != BACKSPACE) { /* overstriking one char */
bufp--; /* Zap 1st instance of char to bolden */
if (bufp > buf) {
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
! WHICH(italicflag, FALSE));
bufp = buf;
}
*bufp++ = c[1];
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, BOLD);
bufp = buf;
first = FALSE;
***************
*** 1025,1032 ****
else {
if ((c[-1] == 'o' && c[1] == '+') /* Nroff bullet */
|| (c[-1] == '+' && c[1] == 'o')) { /* Nroff bullet */
! /* I would prefer to put a 'bullet' char here */
! *bufp++ = 'o';
c++;
}
else { /* 'real' backspace - back up output ptr */
--- 1042,1056 ----
else {
if ((c[-1] == 'o' && c[1] == '+') /* Nroff bullet */
|| (c[-1] == '+' && c[1] == 'o')) { /* Nroff bullet */
! /* If we run into a bullet, print out */
! /* everything that's accumulated to this */
! /* point, then the bullet, then resume. */
! bufp--;
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
! WHICH(italicflag, FALSE));
! bufp = buf;
! *bufp = (char)183;
! x_loc = DumpText(w, x_loc, y_loc, buf, 1, SYMBOL);
c++;
}
else { /* 'real' backspace - back up output ptr */
***************
*** 1041,1047 ****
if(*(c + 1) == BACKSPACE) {
if(!italicflag) { /* font change? */
if (bufp != buf) {
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, FALSE, FALSE);
bufp = buf;
}
italicflag = TRUE;
--- 1065,1071 ----
if(*(c + 1) == BACKSPACE) {
if(!italicflag) { /* font change? */
if (bufp != buf) {
! x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, NORMAL);
bufp = buf;
}
italicflag = TRUE;
***************
*** 1056,1062 ****
if(italicflag) { /* font change? */
if (bufp != buf) {
x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
! italicflag, FALSE);
bufp = buf;
}
italicflag = FALSE;
--- 1080,1086 ----
if(italicflag) { /* font change? */
if (bufp != buf) {
x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
! WHICH(italicflag, FALSE));
bufp = buf;
}
italicflag = FALSE;
***************
*** 1079,1112 ****
*/
static int
! DumpText(w, x_loc, y_loc, buf, len, italic, bold)
Widget w;
int x_loc, y_loc;
char * buf;
int len;
! Boolean italic, bold;
{
ScrollByLineWidget sblw = (ScrollByLineWidget) w;
GC gc;
XFontStruct * font;
! if (italic) {
! if (bold)
! XtAppError(XtWidgetToApplicationContext(w),
! "SBLW: cannot be both bold and italic.");
gc = sblw->scroll.italic_gc;
font = sblw->scroll.italic_font;
! }
! else {
! if (bold) {
gc = sblw->scroll.bold_gc;
font = sblw->scroll.bold_font;
! }
! else {
gc = sblw->scroll.normal_gc;
font = sblw->scroll.normal_font;
}
! }
XDrawString(XtDisplay(w), XtWindow(w), gc, x_loc, y_loc, buf, len);
return(x_loc + XTextWidth(font, buf, len));
}
--- 1103,1142 ----
*/
static int
! DumpText(w, x_loc, y_loc, buf, len, format)
Widget w;
int x_loc, y_loc;
char * buf;
int len;
! int format;
{
ScrollByLineWidget sblw = (ScrollByLineWidget) w;
GC gc;
XFontStruct * font;
! switch(format) {
!
! case ITALIC:
gc = sblw->scroll.italic_gc;
font = sblw->scroll.italic_font;
! break;
!
! case BOLD:
gc = sblw->scroll.bold_gc;
font = sblw->scroll.bold_font;
! break;
!
! case SYMBOL:
! gc = sblw->scroll.symbol_gc;
! font = sblw->scroll.symbol_font;
! break;
!
! default:
gc = sblw->scroll.normal_gc;
font = sblw->scroll.normal_font;
+ break;
}
!
XDrawString(XtDisplay(w), XtWindow(w), gc, x_loc, y_loc, buf, len);
return(x_loc + XTextWidth(font, buf, len));
}