aboutsummaryrefslogtreecommitdiffstats
path: root/install-sh
blob: c122ef95bd89629e8eb364591155d9d420307a7b (plain)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission.  M.I.T. makes no representations about the
# suitability of this software for any purpose.  It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.  It can only install one file at a time, a restriction
# shared with many OS's install programs.


# set DOITPROG to echo to test this script

# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"


# put in absolute paths if you don't have them in your path; or use env. vars.

mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"

transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""

while [ x"$1" != x ]; do
    case $1 in
	-c) instcmd="$cpprog"
	    shift
	    continue;;

	-d) dir_arg=true
	    shift
	    continue;;

	-m) chmodcmd="$chmodprog $2"
	    shift
	    shift
	    continue;;

	-o) chowncmd="$chownprog $2"
	    shift
	    shift
	    continue;;

	-g) chgrpcmd="$chgrpprog $2"
	    shift
	    shift
	    continue;;

	-s) stripcmd="$stripprog"
	    shift
	    continue;;

	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
	    shift
	    continue;;

	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
	    shift
	    continue;;

	*)  if [ x"$src" = x ]
	    then
		src=$1
	    else
		# this colon is to work around a 386BSD /bin/sh bug
		:
		dst=$1
	    fi
	    shift
	    continue;;
    esac
done

if [ x"$src" = x ]
then
	echo "install:	no input file specified"
	exit 1
else
	true
fi

if [ x"$dir_arg" != x ]; then
	dst=$src
	src=""
	
	if [ -d $dst ]; then
		instcmd=:
		chmodcmd=""
	else
		instcmd=mkdir
	fi
else

# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad 
# if $src (and thus $dsttmp) contains '*'.

	if [ -f $src -o -d $src ]
	then
		true
	else
		echo "install:  $src does not exist"
		exit 1
	fi
	
	if [ x"$dst" = x ]
	then
		echo "install:	no destination specified"
		exit 1
	else
		true
	fi

# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic

	if [ -d $dst ]
	then
		dst="$dst"/`basename $src`
	else
		true
	fi
fi

## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`

# Make sure that the destination directory exists.
#  this part is taken from Noah Friedman's mkinstalldirs script

# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS=' 	
'
IFS="${IFS-${defaultIFS}}"

oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"

pathcomp=''

while [ $# -ne 0 ] ; do
	pathcomp="${pathcomp}${1}"
	shift

	if [ ! -d "${pathcomp}" ] ;
        then
		$mkdirprog "${pathcomp}"
	else
		true
	fi

	pathcomp="${pathcomp}/"
done
fi

if [ x"$dir_arg" != x ]
then
	$doit $instcmd $dst &&

	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else

# If we're going to rename the final executable, determine the name now.

	if [ x"$transformarg" = x ] 
	then
		dstfile=`basename $dst`
	else
		dstfile=`basename $dst $transformbasename | 
			sed $transformarg`$transformbasename
	fi

# don't allow the sed command to completely eliminate the filename

	if [ x"$dstfile" = x ] 
	then
		dstfile=`basename $dst`
	else
		true
	fi

# Make a temp file name in the proper directory.

	dsttmp=$dstdir/#inst.$$#

# Move or copy the file name to the temp name

	$doit $instcmd $src $dsttmp &&

	trap "rm -f ${dsttmp}" 0 &&

# and set any options; do chmod last to preserve setuid bits

# If any of these fail, we abort the whole thing.  If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.

	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&

# Now rename the file to the real destination.

	$doit $rmcmd -f $dstdir/$dstfile &&
	$doit $mvcmd $dsttmp $dstdir/$dstfile 

fi &&


exit 0
span class="cm"> * extern int CHARS, CHAR0; number of user-defineable characters, ASCII of first char * extern int ICONS; number of user-defineable characters reserved for icons * extern int GOTO_COST; number of bytes a goto command requires * extern int INVALIDATE; re-send a modified userdefined char? * * * these functions must be implemented by the real driver: * * void (*drv_generic_text_real_write)(int row, int col, unsigned char *data, int len); * writes a text of specified length at position (row, col) * * void (*drv_generic_text_real_defchar)(int ascii, unsigned char *buffer); * defines the bitmap of a user-defined character * * * exported fuctions: * * int drv_generic_text_init (char *section, char *driver); * initializes the generic text driver * * int drv_generic_text_draw (WIDGET *W); * renders Text widget into framebuffer * calls drv_generic_text_real_write() * * int drv_generic_text_icon_init (void); * initializes the generic icon driver * * int drv_generic_text_icon_draw (WIDGET *W); * renders Icon widget into framebuffer * calls drv_generic_text_real_write() and drv_generic_text_real_defchar() * * int drv_generic_text_bar_init (int single_segments); * initializes the generic icon driver * * void drv_generic_text_bar_add_segment (int val1, int val2, DIRECTION dir, int ascii); * adds a 'fixed' character to the bar-renderer * * int drv_generic_text_bar_draw (WIDGET *W); * renders Bar widget into framebuffer * calls drv_generic_text_real_write() and drv_generic_text_real_defchar() * * int drv_generic_text_quit (void); * closes the generic text driver * */ #include "config.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <termios.h> #include <fcntl.h> #include "debug.h" #include "cfg.h" #include "plugin.h" #include "widget.h" #include "widget_text.h" #include "widget_icon.h" #include "widget_bar.h" #include "drv.h" #include "drv_generic_text.h" #ifdef WITH_DMALLOC #include <dmalloc.h> #endif typedef struct { int val1; int val2; DIRECTION dir; int segment; int invalid; } BAR; typedef struct { int val1; int val2; DIRECTION dir; int used; int ascii; } SEGMENT; static char *Section=NULL; static char *Driver=NULL; int DROWS = 20; /* display size: rows */ int DCOLS = 4; /* display size: columns */ int LROWS = 20; /* layout size: rows */ int LCOLS = 4; /* layout size: columns */ int XRES = 6; /* pixels of one char cell */ int YRES = 8; /* pixels of one char cell */ int CHARS = 0; /* number of user-defineable characters */ int CHAR0 = 0; /* ASCII of first user-defineable char */ int ICONS = 0; /* number of user-defineable characters reserved for icons */ int GOTO_COST = 0; /* number of bytes a goto command requires */ int INVALIDATE = 0; /* re-send a modified userdefined char? */ static char *LayoutFB = NULL; static char *DisplayFB = NULL; static int Single_Segments = 0; static int nSegment = 0; static int fSegment = 0; static SEGMENT Segment[128]; static BAR *BarFB = NULL; /****************************************/ /*** generic Framebuffer stuff ***/ /****************************************/ static void drv_generic_text_resizeFB (int rows, int cols) { char *newFB; BAR *newBar; int i, row, col; /* Layout FB is large enough */ if (rows <= LROWS && cols <= LCOLS) return; /* get maximum values */ if (rows < LROWS) rows = LROWS; if (cols < LCOLS) cols = LCOLS; /* allocate new Layout FB */ newFB = malloc(cols * rows * sizeof(char)); memset (newFB, ' ', rows * cols * sizeof(char)); /* transfer contents */ if (LayoutFB != NULL) { for (row = 0; row < LROWS; row++) { for (col = 0; col < LCOLS; col++) { newFB[row * cols + col] = LayoutFB[row * LCOLS + col]; } } free (LayoutFB); } LayoutFB = newFB; /* resize Bar buffer */ if (BarFB) { newBar = malloc (rows * cols * sizeof(BAR)); for (i = 0; i < rows * cols; i++) { newBar[i].val1 = -1; newBar[i].val2 = -1; newBar[i].dir = 0; newBar[i].segment = -1; newBar[i].invalid = 0; } /* transfer contents */ for (row = 0; row < LROWS; row++) { for (col = 0; col < LCOLS; col++) { newBar[row * cols + col] = BarFB[row * LCOLS + col]; } } free (BarFB); BarFB = newBar; } LCOLS = cols; LROWS = rows; } /****************************************/ /*** generic text handling ***/ /****************************************/ int drv_generic_text_init (const char *section, const char *driver) { Section = (char*)section; Driver = (char*)driver; /* init display framebuffer */ DisplayFB = (char*)malloc(DCOLS * DROWS * sizeof(char)); memset (DisplayFB, ' ', DROWS * DCOLS * sizeof(char)); /* init layout framebuffer */ LROWS = 0; LCOLS = 0; LayoutFB = NULL; drv_generic_text_resizeFB (DROWS, DCOLS); /* sanity check */ if (LayoutFB == NULL || DisplayFB == NULL) { error ("%s: framebuffer could not be allocated: malloc() failed", Driver); return -1; } return 0; } /* say hello to the user */ int drv_generic_text_greet (const char *msg1, const char *msg2) { int i; int flag = 0; char *line1[] = { "* LCD4Linux " VERSION " *", "LCD4Linux " VERSION, "* LCD4Linux *", "LCD4Linux", "L4Linux", NULL }; char *line2[] = { "http://lcd4linux.bulix.org", "lcd4linux.bulix.org", NULL }; for (i = 0; line1[i]; i++) { if (strlen(line1[i]) <= (unsigned)DCOLS) { drv_generic_text_real_write (0, (DCOLS - strlen(line1[i])) / 2, line1[i], strlen(line1[i])); flag = 1; break; } } if (DROWS >= 2) { for (i = 0; line2[i]; i++) { if (strlen(line2[i]) <= (unsigned)DCOLS) { drv_generic_text_real_write (1, (DCOLS - strlen(line2[i])) / 2, line2[i], strlen(line2[i])); flag = 1; break; } } } if (msg1 && DROWS >= 3) { int len = strlen(msg1); if ( len <= DCOLS) { drv_generic_text_real_write (2, (DCOLS-len) / 2, msg1, len); flag = 1; } } if (msg2 && DROWS >= 4) { int len = strlen(msg2); if ( len <= DCOLS) { drv_generic_text_real_write (3, (DCOLS-len) / 2, msg2, len); flag = 1; } } return flag; } int drv_generic_text_draw (WIDGET *W) { WIDGET_TEXT *Text = W->data; char *txt, *fb1, *fb2; int row, col, col0, len, end; row = W->row; col = W->col; txt = Text->buffer; len = strlen(txt); end = col + len; /* maybe grow layout framebuffer */ drv_generic_text_resizeFB (row+1, col+len); fb1 = LayoutFB + row*LCOLS; fb2 = DisplayFB + row*DCOLS; /* transfer new text into layout buffer */ memcpy (fb1 + col, txt, len); if (row<DROWS) { for (; col <= end && col < DCOLS; col++) { int pos1, pos2, equal; if (fb1[col] == fb2[col]) continue; col0 = col; for (pos1 = col, pos2 = pos1, col++, equal = 0; col <= end && col < DCOLS; col++) { if (fb1[col] == fb2[col]) { /* If we find just one equal byte, we don't break, because this */ /* would require a goto, which takes several bytes, too. */ if (GOTO_COST >= 0 && ++equal > GOTO_COST) break; } else { pos2 = col; equal = 0; } } memcpy ( fb2+pos1, fb1+pos1, pos2-pos1+1); drv_generic_text_real_write (row, col0, fb2+pos1, pos2-pos1+1); } } return 0; } int drv_generic_text_quit (void) { if (LayoutFB) { free(LayoutFB); LayoutFB = NULL; } if (DisplayFB) { free(DisplayFB); DisplayFB = NULL; } if (BarFB) { free (BarFB); BarFB = NULL; } widget_unregister(); return (0); } /****************************************/ /*** generic icon handling ***/ /****************************************/ int drv_generic_text_icon_init (void) { if (cfg_number(Section, "Icons", 0, 0, CHARS, &ICONS) < 0) return -1; if (ICONS>0) { info ("%s: reserving %d of %d user-defined characters for icons", Driver, ICONS, CHARS); } return 0; } int drv_generic_text_icon_draw (WIDGET *W) { static int icon_counter = 0; WIDGET_ICON *Icon = W->data; int row, col; int l_idx, d_idx; int invalidate = 0; unsigned char ascii; row = W->row; col = W->col; /* maybe grow layout framebuffer */ drv_generic_text_resizeFB (row+1, col+1); /* icon deactivated? */ if (Icon->ascii == -2) return 0; /* ASCII already assigned? */ if (Icon->ascii == -1) { if (icon_counter >= ICONS) { error ("cannot process icon '%s': out of icons", W->name); Icon->ascii = -2; return -1; } icon_counter++; Icon->ascii = CHAR0 + CHARS - icon_counter; } /* maybe redefine icon */ if (Icon->curmap != Icon->prvmap && Icon->visible) { Icon->prvmap = Icon->curmap; drv_generic_text_real_defchar(Icon->ascii, Icon->bitmap + YRES * Icon->curmap); invalidate = INVALIDATE; } /* use blank if invisible */ ascii = Icon->visible ? Icon->ascii : ' '; /* index into the two framebuffers */ l_idx = row * LCOLS + col; d_idx = row * DCOLS + col; /* transfer icon into layout buffer */ LayoutFB[l_idx] = ascii; /* maybe send icon to the display */ if (row < DROWS && col < DCOLS && (DisplayFB[d_idx] != ascii || invalidate)) { DisplayFB[d_idx] = ascii; drv_generic_text_real_write (row, col, DisplayFB + d_idx, 1); } return 0; } /****************************************/ /*** generic bar handling ***/ /****************************************/ static void drv_generic_text_bar_clear(void) { int i; for (i = 0; i < LROWS*LCOLS; i++) { BarFB[i].val1 = -1; BarFB[i].val2 = -1; BarFB[i].dir = 0; BarFB[i].segment = -1; BarFB[i].invalid = 0; } for (i = 0; i < nSegment; i++) { Segment[i].used = 0; } } int drv_generic_text_bar_init (const int single_segments) { if (BarFB) free (BarFB); if ((BarFB = malloc (LROWS * LCOLS * sizeof(BAR))) == NULL) { error ("bar buffer allocation failed: out of memory"); return -1; } Single_Segments = single_segments; nSegment = 0; fSegment = 0; drv_generic_text_bar_clear(); return 0; } void drv_generic_text_bar_add_segment(const int val1, const int val2, const DIRECTION dir, const int ascii) { Segment[fSegment].val1 = val1; Segment[fSegment].val2 = val2; Segment[fSegment].dir = dir; Segment[fSegment].used = 0; Segment[fSegment].ascii = ascii; fSegment++; nSegment = fSegment; } static void drv_generic_text_bar_create_bar (int row, int col, const DIRECTION dir, int len, int val1, int val2) { int rev = 0; switch (dir) { case DIR_WEST: val1 = len-val1; val2 = len-val2; rev = 1; case DIR_EAST: while (len > 0 && col < LCOLS) { BarFB[row*LCOLS+col].dir = dir; BarFB[row*LCOLS+col].segment = -1; if (val1 >= XRES) { BarFB[row*LCOLS+col].val1 = rev ? 0 : XRES; val1 -= XRES; } else { BarFB[row*LCOLS+col].val1 = rev ? XRES-val1 : val1; val1 = 0; } if (val2 >= XRES) { BarFB[row*LCOLS+col].val2 = rev ? 0 : XRES; val2 -= XRES; } else { BarFB[row*LCOLS+col].val2 = rev ? XRES-val2 : val2; val2 = 0; } len--; col++; } break; case DIR_SOUTH: val1 = len-val1; val2 = len-val2; rev = 1; case DIR_NORTH: while (len > 0 && row < LROWS) { BarFB[row*LCOLS+col].dir = dir; BarFB[row*LCOLS+col].segment = -1; if (val1 >= YRES) { BarFB[row*LCOLS+col].val1 = rev ? 0 : YRES; val1 -= YRES; } else { BarFB[row*LCOLS+col].val1 = rev ? YRES-val1 : val1; val1 = 0; } if (val2 >= YRES) { BarFB[row*LCOLS+col].val2 = rev ? 0 : YRES; val2 -= YRES; } else { BarFB[row*LCOLS+col].val2 = rev ? YRES - val2 : val2; val2 = 0; } len--; row++; } break; } } static void drv_generic_text_bar_create_segments (void) { int i, j, n; int res, l1, l2; /* find first unused segment */ for (i = fSegment; i < nSegment && Segment[i].used; i++); /* pack unused segments */ for (j = i+1; j < nSegment; j++) { if (Segment[j].used) Segment[i++] = Segment[j]; } nSegment = i; /* create needed segments */ for (n = 0; n < LROWS*LCOLS; n++) { if (BarFB[n].dir == 0) continue; res = BarFB[n].dir & (DIR_EAST|DIR_WEST) ? XRES:YRES; for (i = 0; i < nSegment; i++) { if (Segment[i].dir & BarFB[n].dir) { l1 = Segment[i].val1; if (l1 > res) l1=res; l2 = Segment[i].val2; if (l2 > res) l2=res; if (l1 == BarFB[n].val1 && l2 == BarFB[n].val2) break; } } if (i == nSegment) { nSegment++; Segment[i].val1 = BarFB[n].val1; Segment[i].val2 = BarFB[n].val2; Segment[i].dir = BarFB[n].dir; Segment[i].used = 0; Segment[i].ascii = -1; } BarFB[n].segment = i; } } static int drv_generic_text_bar_segment_error (const int i, const int j) { int res; int i1, i2, j1, j2; if (i == j) return 65535; if (!(Segment[i].dir & Segment[j].dir)) return 65535; res = Segment[i].dir&(DIR_EAST|DIR_WEST) ? XRES:YRES; i1 = Segment[i].val1; if (i1 > res) i1 = res; i2 = Segment[i].val2; if (i2 > res) i2 = res; j1 = Segment[j].val1; if (j1 > res) j1 = res; j2 = Segment[j].val2; if (j2 > res) j2 = res; if (i1 == 0 && j1 != 0) return 65535; if (i2 == 0 && j2 != 0) return 65535; if (i1 == res && j1 < res) return 65535; if (i2 == res && j2 < res) return 65535; if (i1 == 1 && j1 != 1 && i2 > 0) return 65535; if (i2 == 1 && j2 != 1 && j1 > 0) return 65535; if (i1 == i2 && j1 != j2) return 65535; return (i1-j1)*(i1-j1) + (i2-j2)*(i2-j2); } static void drv_generic_text_bar_pack_segments (void) { int i, j, n, min; int pack_i, pack_j; int pass1 = 1; int error[nSegment][nSegment]; if (nSegment <= fSegment + CHARS - ICONS) { return; } for (i = 0; i < nSegment; i++) { for (j = 0; j < nSegment; j++) { error[i][j] = drv_generic_text_bar_segment_error(i, j); } } while (nSegment > fSegment + CHARS - ICONS) { min = 65535; pack_i = -1; pack_j = -1; for (i = fSegment; i < nSegment; i++) { if (pass1 && Segment[i].used) continue; for (j = 0; j < nSegment; j++) { if (error[i][j] < min) { min = error[i][j]; pack_i = i; pack_j = j; } } } if (pack_i == -1) { if (pass1) { pass1 = 0; continue; } else { error ("unable to compact bar characters"); error ("nSegment=%d fSegment=%d CHARS=%d ICONS=%d", nSegment, fSegment, CHARS, ICONS); error ("Segment[0].val1=%d val2=%d", Segment[0].val1, Segment[0].val2); error ("Segment[1].val1=%d val2=%d", Segment[1].val1, Segment[1].val2); error ("Segment[2].val1=%d val2=%d", Segment[2].val1, Segment[2].val2); nSegment = CHARS - ICONS; break; } } #if 0 debug ("pack_segment: n=%d i=%d j=%d min=%d", nSegment, pack_i, pack_j, min); debug ("Pack_segment: i1=%d i2=%d j1=%d j2=%d\n", Segment[pack_i].val1, Segment[pack_i].val2, Segment[pack_j].val1, Segment[pack_j].val2); #endif nSegment--; Segment[pack_i] = Segment[nSegment]; for (i = 0; i < nSegment; i++) { error[pack_i][i] = error[nSegment][i]; error[i][pack_i] = error[i][nSegment]; } for (n = 0; n < LROWS * LCOLS; n++) { if (BarFB[n].segment == pack_i) BarFB[n].segment = pack_j; if (BarFB[n].segment == nSegment) BarFB[n].segment = pack_i; } } } static void drv_generic_text_bar_define_chars(void) { int c, i, j; unsigned char buffer[8]; for (i = fSegment; i < nSegment; i++) { if (Segment[i].used) continue; if (Segment[i].ascii != -1) continue; for (c = 0; c < CHARS - ICONS; c++) { for (j = fSegment; j < nSegment; j++) { if (Segment[j].ascii == c) break; } if (j == nSegment) break; } Segment[i].ascii = c; switch (Segment[i].dir) { case DIR_WEST: for (j = 0; j < 4; j++) { buffer[j ] = (1<<Segment[i].val1)-1; buffer[j+4] = (1<<Segment[i].val2)-1; } break; case DIR_EAST: for (j = 0; j < 4; j++) { buffer[j ] = 255<<(XRES-Segment[i].val1); buffer[j+4] = 255<<(XRES-Segment[i].val2); } break; case DIR_NORTH: for (j = 0; j < Segment[i].val1; j++) { buffer[7-j] = (1<<XRES)-1; } for (; j < YRES; j++) { buffer[7-j] = 0; } break; case DIR_SOUTH: for (j = 0; j < Segment[i].val1; j++) { buffer[j] = (1<<XRES)-1; } for (; j < YRES; j++) { buffer[j] = 0; } break; } drv_generic_text_real_defchar(CHAR0+c, buffer); /* maybe invalidate framebuffer */ if (INVALIDATE) { for (j = 0; j < LROWS*LCOLS; j++) { if (BarFB[j].segment == i) { BarFB[j].invalid = 1; } } } } } int drv_generic_text_bar_draw (WIDGET *W) { WIDGET_BAR *Bar = W->data; int row, col, col0, len, res, max, val1, val2; int c, n, s; DIRECTION dir; row = W->row; col = W->col; dir = Bar->direction; len = Bar->length; /* maybe grow layout framebuffer */ /* bars *always* grow heading North or East! */ if (dir & (DIR_EAST|DIR_WEST)) { drv_generic_text_resizeFB (row+1, col+len); } else { drv_generic_text_resizeFB (row+1, col+1); } res = dir & (DIR_EAST|DIR_WEST) ? XRES : YRES; max = len * res; val1 = Bar->val1 * (double)(max); val2 = Bar->val2 * (double)(max); if (val1 < 1) val1 = 1; else if (val1 > max) val1 = max; if (val2 < 1) val2 = 1; else if (val2 > max) val2 = max; if (Single_Segments) val2 = val1; /* create this bar */ drv_generic_text_bar_create_bar (row, col, dir, len, val1, val2); /* process all bars */ drv_generic_text_bar_create_segments (); drv_generic_text_bar_pack_segments (); drv_generic_text_bar_define_chars(); /* reset usage flags */ for (s = 0; s < nSegment; s++) { Segment[s].used = 0; } /* set usage flags */ for (n = 0; n < LROWS*LCOLS; n++) { if ((s = BarFB[n].segment) != -1) Segment[s].used = 1; } /* transfer bars into layout buffer */ for (row = 0; row < LROWS; row++) { for (col = 0; col < LCOLS; col++) { n = row*LCOLS+col; s = BarFB[n].segment; if (s == -1) continue; c = Segment[s].ascii; if (c == -1) continue; if (s >= fSegment) c += CHAR0; /* ascii offset for user-defineable chars */ LayoutFB[n] = c; /* maybe invalidate display framebuffer */ if (BarFB[n].invalid) { BarFB[n].invalid = 0; DisplayFB[row*DCOLS+col] = ~LayoutFB[n]; } } } /* transfer differences to the display */ for (row = 0; row < DROWS; row++) { for (col = 0; col < DCOLS; col++) { int pos1, pos2, equal; if (LayoutFB[row*LCOLS+col] == DisplayFB[row*DCOLS+col]) continue; col0 = col; for (pos1 = col, pos2 = pos1, col++, equal = 0; col < DCOLS; col++) { if (LayoutFB[row*LCOLS+col] == DisplayFB[row*DCOLS+col]) { /* If we find just one equal byte, we don't break, because this */ /* would require a goto, which takes several bytes, too. */ if (++equal > GOTO_COST) break; } else { pos2 = col; equal = 0; } } memcpy ( DisplayFB+row*DCOLS+pos1, LayoutFB+row*LCOLS+pos1, pos2-pos1+1); drv_generic_text_real_write (row, col0, DisplayFB+row*DCOLS+pos1, pos2-pos1+1); } } return 0; }