1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/* <<< Start of information >>> */
/* This file is part of the xwatch package. */
/* Copyright (C) 1995 Karel Kubat. All rights reserved. */
/* */
/* This program is free software; you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by the */
/* Free Software Foundation; either version 2 of the License, or (at your */
/* option) any later version. */
/* */
/* You may link this software with XForms (Copyright (C) by T.C. Zhao and */
/* Mark Overmars) and distribute the resulting binary, under the */
/* restrictions in clause 3 of the GPL, even though the resulting binary is */
/* not, as a whole, covered by the GPL. (You still need a separate license */
/* to do so from the owner(s) of the copyright for XForms, however). If a */
/* derivative no longer requires XForms, you may use the unsupplemented GPL */
/* as its license by deleting this paragraph and therefore removing this */
/* exemption for XForms. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* <<< End of information >>> */
#include "xwatch.h"
void addline (char *buf, int colindex)
{
char
outbuf [1000];
int
i,
length_so_far,
extra_length,
curwidth,
curheight,
curx,
cury;
char
*bufcopy,
*cp;
/* clear trailing \n chars */
if ( (cp = strchr (buf, '\n')) && cp > buf )
*cp = '\0';
if (! *buf)
return;
/* see if the contents of the line is `gagged' */
for (i = 0; i < ngagstring; i++)
if (strstr (buf, gagstring [i]))
return;
if (!watch_browser) {
fprintf(stderr, "%s\n", buf);
return;
}
/* determine width to use */
fl_get_browser_dimension (watch_browser, &curx, &cury,
&curwidth, &curheight);
/*
Debian Bug#43157: xwatch: horizontal scrollbar not needed (Patch included)
Date: Wed, 18 Aug 1999 11:54:00 +0200
From: Roland Rosenfeld <roland@spinnaker.de>
Package: xwatch
Version: 2.11-1
xwatch linked with the actual version of xforms has some problems with
long lines: Sometimes the line wrapping seems not to work correct,
which has the effect that a horizontal scrollbar is displayed (for
scrolling less than 10 pixel right or left). The disadvantage of this
scroll bar is, that it reduces the height of the xwatch window by
ca. two lines (which makes my 5 line window to a 3 line window).
To avoid this effect, subtract 10 to curwidth instead of 5:
*/
/* curwidth -= 5; */
curwidth -= 10;
/* reset outbuffer */
outbuf [0] = '\0';
/* process whole buf, cut it up if necessary */
bufcopy = xstrdup (buf);
cp = strtok (bufcopy, " \t");
while (cp)
{
int empty_outbuf = 0;
/* add color code if necessary */
if (! outbuf [0])
{
if (colindex != foregr)
sprintf (outbuf, "@C%d ", colindex);
else
strcpy (outbuf, " ");
empty_outbuf = 1;
}
/* determine length of string so far, flush if necessary */
length_so_far = fl_get_string_width (fontstyle, fontsize, outbuf,
strlen (outbuf));
extra_length = fl_get_string_width (fontstyle, fontsize, cp,
strlen (cp));
/* If the next word is too long to fit, and we have nothing */
/* to print, */
if (empty_outbuf && length_so_far + extra_length > curwidth)
{
/* print it anyway */
/* break it into width-sized chunks */
while (*cp)
{
int
len_to_print,
len_of_color_code;
/* start each line with color code */
if (colindex != foregr)
sprintf (outbuf, "@C%d ", colindex);
else
strcpy (outbuf, " ");
strcat (outbuf, " ");
len_of_color_code = strlen(outbuf);
strcat(outbuf, cp);
len_to_print = strlen(outbuf);
while (fl_get_string_width (fontstyle, fontsize, outbuf,
len_to_print) > curwidth
&& len_to_print > len_of_color_code)
{
--len_to_print;
}
/* Make sure we manage to print at least one new character */
if (len_to_print <= len_of_color_code)
len_to_print = len_of_color_code + 1;
outbuf[len_to_print] = '\0';
fl_addto_browser (watch_browser, outbuf);
cp += len_to_print - len_of_color_code;
}
outbuf[0] = '\0';
/* and get the next word */
cp = strtok (NULL, " \t");
}
else if (length_so_far + extra_length > curwidth)
{
fl_addto_browser (watch_browser, outbuf);
outbuf [0] = '\0';
}
else
{
strcat (outbuf, " ");
strcat (outbuf, cp);
cp = strtok (NULL, " \t");
}
}
/* flush whatever's left */
if (cp)
strcat (outbuf, cp);
if (outbuf [0])
fl_addto_browser (watch_browser, outbuf);
/* release memory */
free (bufcopy);
}
|