File: stdlib.mc

package info (click to toggle)
printfilters-ppd 2.12-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 560 kB
  • ctags: 8
  • sloc: sh: 1,177; makefile: 78; perl: 54; awk: 14; ansic: 7
file content (245 lines) | stat: -rw-r--r-- 6,087 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
m4_divert(-1)

m4_changequote(`[', `]')


dnl
dnl  === Preamble and clean-up macros ===
dnl

m4_define(_GETDIALOG, [
if test "x$DIALOG" = "x"; then
	DIALOG=`which dialog`
	if test $? -ne 0; then
		DIALOG=`which whiptail`
		if test $? -ne 0; then
			DIALOG=`which gdialog`
			if test $? -ne 0; then
				echo "Could not find dialog or whiptail." 
				exit 1
			fi
		fi
	fi
	export DIALOG
fi
])

m4_define(_STARTLOG, [
if test "x$LOGFILE" = "x"; then
	LOGFILE=_PROJECTNAME().log
	export LOGFILE
	echo "Starting $LOGFILE" > $LOGFILE
fi
])

m4_define(_STARTCHECKLIST, [
if test "x$CHECKLIST" = "x"; then
	CHECKLIST=_PROJECTNAME().txt
	export CHECKLIST
	echo "Starting $CHECKLIST" > $CHECKLIST
fi
echo "========== _PROJECTNAME() Checklist ==========" >> $CHECKLIST
])

m4_define(_MERGELOG, [
if test "x$MASTERLOG" != "x"; then
	cat $LOGFILE >> $MASTERLOG
fi
])

m4_define(_MKTEMP, [
	TEMPFILE=`mktemp -q /tmp/_PROJECTNAME().XXXXXX`
	export TEMPFILE
])

m4_define(_GETPATH, [
if test "x$TESTPATH" = "x"; then
	TESTPATH="./"
	export TESTPATH
fi
])

m4_define(_START, [

# The following test script was made from M4 macros.  If you wish to
# make any changes, please do so there.
#
# This script pays attention to the variables $MASTERLOG and $DIALOG


	m4_define(_PROJECTNAME, $1)
	_GETDIALOG()
	_STARTLOG()
	_MKTEMP()
	_GETPATH()
	_LOG("Temp file is: $TEMPFILE")
])

m4_define(_STOP, [
	_MERGELOG()
	rm -f $TEMPFILE
])

dnl  === Here's where the fresh, meaty stuff is ===

m4_define(_DIALOGWIDTH, 65)

dnl how many 65-char lines can we break this up into?  Note margin for
dnl error.  *shrug* This is hardly scientific.

m4_define(_NUMLINES, [m4_eval(m4_len($1) / _DIALOGWIDTH() + 7)])

dnl Random flags
m4_define(_DIALOGFLAGS, [])

dnl convenience macros for logging stuff
m4_define(_LOG, [echo "m4_patsubst([$1], ", \\")" >> $LOGFILE])
m4_define(_DOCHECK, [echo "m4_patsubst([$1], ", \\")" >> $CHECKLIST])
m4_define(_CHECK, [_LOG($1) 
_DOCHECK($1)])

m4_define(_PASS, [_CHECK(	{OK} $1)])
m4_define(_FAIL, [_CHECK(	=FAIL= $1)])
m4_define(_SKIP, [_CHECK(	{SKIP} $1)])


dnl format:  _CHECKRET([stuff-if-OK], [stuff-if-CANCEL], [stuff-if-ESC])
dnl result: runs code depending on the return value of the most recent program
m4_define(_CHECKRET, [
RETVAL=$?

case $RETVAL in
  0)
  	$1;;
  1)
  	$2;;
  255)
  	$3;;
  *)
  	$2;;
esac
])

m4_define(_PASSFAILDIE, [_CHECKRET(_PASS($1), _FAIL($1), [exit 1])])
m4_define(_DOORDIE, [_CHECKRET($1, [exit 1], [exit 1])])
m4_define(_DOORSCREAM, [_CHECKRET($1, _BUGOUT($2), _BUGOUT($2))])
m4_define(_DOORSCOLD, [_CHECKRET($1, _SCOLD($2), _SCOLD($2))])


dnl format: _GRABOUTPUT([dialog-to-run], [variable-to-store])
dnl result: stores stderr from the dialog into the variable, or dies
m4_define(_GRABOUTPUT, [
$1 2> $TEMPFILE
_DOORDIE($2=`cat $TEMPFILE`)
])

dnl format: _BUGOUT([error message])
dnl result: prints up a msgbox and exits messily
m4_define(_BUGOUT, [
$DIALOG --title "ERROR" --infobox "m4_patsubst([$1], ", \\")" _NUMLINES($1) _DIALOGWIDTH()
_LOG($1)
exit 1
])

dnl format: _SCOLD([error message])
dnl result: prints up a msgbox 
m4_define(_SCOLD, [
$DIALOG --title "ERROR" --msgbox "m4_patsubst([$1], ", \\")" _NUMLINES($1) _DIALOGWIDTH()
_LOG($1)
])

dnl format: _NOTIFY([title], [message])
dnl result: prints up a msgbox
m4_define(_NOTIFY, [
$DIALOG --msgbox "m4_patsubst([$2], ", \\")" _NUMLINES($2) _DIALOGWIDTH()
])

dnl format: _NOTICE([title], [message])
dnl result: prints up a msgbox
m4_define(_NOTICE, [_NOTIFY($1, $2)])


dnl format: _YESNO([title], [body text])
dnl result: asks a yes or no question, and logs the answer
m4_define(_YESNO, [
$DIALOG _DIALOGFLAGS() --yesno "m4_patsubst([$2], ", \\")" _NUMLINES($2) _DIALOGWIDTH()
_PASSFAILDIE($1)
])

dnl format: _INPUTBOX([title], [body text], [variable name])
dnl result: stores user input into the variable
m4_define(_INPUTBOX, [
_GRABOUTPUT([$DIALOG _DIALOGFLAGS() --inputbox "m4_patsubst([$2], ", \\")" m4_eval(_NUMLINES($2) + 2) _DIALOGWIDTH()], $3)
])

dnl format: _MENU([title], [body text], [variable], ["key" "value" "key" "value]
dnl result: A menu is displayed, and the key of the selected item ends up in the variable
m4_define(_MENU, [
_GRABOUTPUT([$DIALOG _DIALOGFLAGS() --menu "m4_patsubst([$2], ", \\")" m4_eval(_NUMLINES($2) + m4_eval(($# - 3) / 2)) _DIALOGWIDTH() m4_eval(($# - 3) / 2) m4_patsubst([m4_shift(m4_shift(m4_shift($*)))], [","], [" "])], $3)
])

dnl format: _YESNOSKIP([title], [body text])
dnl format: asks a yes, no, or skip question and logs the answer
m4_define(_YESNOSKIP, [
_MENU($1, $2, YESNOVAL, "Yes", "The test worked.", "No", "The test failed.", "Skip", "Ignore this test.")

case $YESNOVAL in
  "Yes")
  	_PASS($1);;
  "No")
  	_FAIL($1);;
  "Skip")
  	_SKIP($1);;
esac
])

dnl format: _SHOWFILE([filename])
dnl format: displays the file in a nice window
m4_define(_SHOWFILE, [
$DIALOG --title "m4_patsubst([$1], ", \\")" _DIALOGFLAGS() --textbox $1 23 78
_DOORSCOLD([], [Could not open $1])
])

dnl format: _DO([command-to-run])
dnl result: puts up a please wait noticebox and runs the program
m4_define(_DO, [
$DIALOG --title "Program running..." --infobox "Running m4_patsubst([$1], ", \\")   Please wait." _NUMLINES($1) _DIALOGWIDTH()
_LOG([Running $1 ...])
$1 > $TEMPFILE 2>> $LOGFILE
])

dnl format: _RUN([command-to-run], [Log message]
m4_define(_RUN, [
_DO($1)
_YESNO($1, Did the page print?)
])

dnl format: _TRY([command-to-run], [variable-for-result], [message-on-fail])
dnl result: runs a program, and stores stdout in the variable, or notifies the user on failure
m4_define(_TRY, [
_DO($1)
_DOORSCOLD($2=`cat $TEMPFILE`, $3)
])

dnl format: _MUST([command-to-run], [variable-for-result], [message-on-fail])
dnl result: runs the command and stores stdout in the variable, or screams the message and dies
m4_define(_MUST, [
_DO($1)
_DOORSCREAM($2=`cat $TEMPFILE`, $3)
])

dnl format: _MYTRY([command-to-run], [variable-for-result], [command-on-fail])
dnl result: runs a program, and stores stdout in the variable, or runs the other command if there's a failure
m4_define(_MYTRY, [
_DO($1)
$2
])







m4_divert(0)