newt.patch 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312
  1. Index: Makefile.in
  2. --- Makefile.in.orig 2003-11-06 07:56:47.000000000 +0100
  3. +++ Makefile.in 2003-12-14 12:02:42.000000000 +0100
  4. @@ -1,153 +1,72 @@
  5. -LIBS = -lslang -lm #-lefence
  6. -SHLIBS = -lslang -lm -lc
  7. -GPM_SUPPORT=@gpm_support@
  8. +VERSION = @VERSION@
  9. -CFLAGS = $(RPM_OPT_FLAGS) -Wall -I/usr/include/slang -D_GNU_SOURCE
  10. -ifeq ($(RPM_OPT_FLAGS),)
  11. -CFLAGS += -g
  12. -endif
  13. -
  14. -VERSION = @VERSION@
  15. -CVSTAG = r$(subst .,-,$(VERSION))
  16. -SONAME = @SONAME@
  17. -
  18. -PYTHONVERS = $(shell ls /usr/include/python*/Python.h | sed "s|/usr/include/||g"| sed "s|/Python.h||g")
  19. -
  20. -WHIPTCLSO=
  21. -#WHIPTCLSO=whiptcl.so
  22. -
  23. -PROGS = test whiptail $(WHIPTCLSO) testgrid testtree showchars showkey
  24. -TESTOBJS = test.o
  25. -NDIALOGOBJS = whiptail.o dialogboxes.o
  26. -WHIPTCLOBJS = whiptcl.o dialogboxes.o
  27. -LIBNEWT = libnewt.a
  28. -LIBNEWTSH = libnewt.so.$(VERSION)
  29. -LIBNEWTSONAME = libnewt.so.$(SONAME)
  30. -LIBOBJS = newt.o button.o form.o checkbox.o entry.o label.o listbox.o \
  31. - scrollbar.o textbox.o scale.o grid.o windows.o buttonbar.o \
  32. - checkboxtree.o
  33. -
  34. -SHCFLAGS = -fPIC
  35. -
  36. -prefix = /usr
  37. -includedir = $(prefix)/include
  38. -libdir = $(prefix)/lib
  39. -bindir = $(prefix)/bin
  40. -ARCHNAME = $(shell uname -m | sed 's/i.86/i386/')
  41. -
  42. -#--------------------------------------
  43. -
  44. -SOURCES = $(subst .o,.c,$(TESTOBJS) $(NDIALOGOBJS) $(LIBOBJS))
  45. -
  46. -SHAREDDIR = shared
  47. -SHAREDOBJS = $(patsubst %,$(SHAREDDIR)/%, $(LIBOBJS))
  48. -
  49. -ifeq (.depend,$(wildcard .depend))
  50. -TARGET=$(PROGS)
  51. -else
  52. -TARGET=depend $(PROGS)
  53. -endif
  54. -
  55. -all: $(TARGET) _snackmodule.so
  56. -
  57. -test: $(TESTOBJS) $(LIBNEWT)
  58. - gcc -g -o test $(TESTOBJS) $(LIBNEWT) $(LIBS) -static
  59. -
  60. -testgrid: testgrid.o $(LIBNEWT)
  61. - gcc -g -o testgrid testgrid.o $(LIBNEWT) $(LIBS)
  62. -
  63. -testtree: testtree.o $(LIBNEWT)
  64. - gcc -g -o testtree testtree.o $(LIBNEWT) $(LIBS)
  65. -
  66. -showchars: showchars.o $(LIBNEWT)
  67. - gcc -g -o showchars showchars.o $(LIBNEWT) $(LIBS)
  68. -
  69. -showkey: showkey.o $(LIBNEWT)
  70. - gcc -g -o showkey showkey.o $(LIBNEWT) $(LIBS)
  71. -
  72. -_snackmodule.so: snackmodule.c $(LIBNEWTSH)
  73. - for ver in $(PYTHONVERS) ; do \
  74. - if [ ! -f "$$ver/_snackmodule.so" -o $(LIBNEWTSH) -nt "$$ver/_snackmodule.so" ]; then \
  75. - mkdir -p $$ver ;\
  76. - gcc $(CFLAGS) -I/usr/include/$$ver -fPIC -c -o $$ver/snackmodule.o snackmodule.c ;\
  77. - gcc --shared $(SHCFLAGS) -o $$ver/_snackmodule.so $$ver/snackmodule.o -L . $(LIBNEWTSH) ;\
  78. - fi ; \
  79. - done
  80. -
  81. -whiptail: $(NDIALOGOBJS) $(LIBNEWTSH)
  82. - gcc -g -o whiptail $(NDIALOGOBJS) -L . $(LIBNEWTSH) $(LIBS) -lpopt
  83. -
  84. -whiptcl.so: $(WHIPTCLOBJS) $(LIBNEWTSH)
  85. - gcc -shared $(SHCFLAGS) -o whiptcl.so $(WHIPTCLOBJS) -L . $(LIBNEWTSH) -ltcl -lslang -lpopt -lm
  86. -
  87. -$(LIBNEWT): $(LIBOBJS)
  88. - ar rv $@ $^
  89. -
  90. -newt.o: newt.c Makefile
  91. - $(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
  92. -
  93. -veryclean: clean
  94. - rm -f .depend
  95. +CC = @CC@
  96. +CFLAGS = @CFLAGS@
  97. +CPPFLAGS = @CPPFLAGS@
  98. +LDFLAGS = @LDFLAGS@
  99. +LIBS = -lslang -lpopt -lm @LIBS@
  100. +RM = rm -f
  101. +AR = ar
  102. +RANLIB = ranlib
  103. +SHTOOL = sh ./shtool
  104. +
  105. +LIBNEWT = libnewt.a
  106. +TARGETS = $(LIB) test whiptail testgrid testtree
  107. +OBJS_LIBNEWT = newt.o button.o form.o checkbox.o entry.o label.o listbox.o \
  108. + scrollbar.o textbox.o scale.o grid.o windows.o buttonbar.o \
  109. + checkboxtree.o
  110. +OBJS_TEST = test.o
  111. +OBJS_TESTGRID = testgrid.o
  112. +OBJS_TESTTREE = testtree.o
  113. +OBJS_WHIPTAIL = whiptail.o dialogboxes.o
  114. +
  115. +DESTDIR =
  116. +prefix = @prefix@
  117. +exec_prefix = @exec_prefix@
  118. +bindir = @bindir@
  119. +libdir = @libdir@
  120. +includedir = @includedir@
  121. +mandir = @mandir@
  122. +
  123. +.SUFFIXES: .c .o
  124. +
  125. +.c.o:
  126. + $(CC) $(CFLAGS) $(CPPFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
  127. +
  128. +all: $(LIBNEWT) $(TARGETS)
  129. +
  130. +test: $(OBJS_TEST) $(LIBNEWT)
  131. + $(CC) -o $@ $(OBJS_TEST) $(LIBNEWT) $(LDFLAGS) $(LIBS)
  132. +
  133. +testgrid: $(OBJS_TESTGRID) $(LIBNEWT)
  134. + $(CC) -o $@ $(OBJS_TESTGRID) $(LIBNEWT) $(LDFLAGS) $(LIBS)
  135. +
  136. +testtree: $(OBJS_TESTTREE) $(LIBNEWT)
  137. + $(CC) -o $@ $(OBJS_TESTTREE) $(LIBNEWT) $(LDFLAGS) $(LIBS)
  138. +
  139. +whiptail: $(OBJS_WHIPTAIL) $(LIBNEWT)
  140. + $(CC) -o $@ $(OBJS_WHIPTAIL) $(LIBNEWT) $(LDFLAGS) $(LIBS)
  141. +
  142. +$(LIBNEWT): $(OBJS_LIBNEWT)
  143. + $(RM) $@
  144. + $(AR) rc $@ $(OBJS_LIBNEWT)
  145. + $(RANLIB) $@
  146. clean:
  147. - rm -f $(PROGS) *.o $(LIBNEWT) core $(LIBNEWTSH) \
  148. - $(SHAREDOBJS) *.so*
  149. -
  150. -depend:
  151. - $(CPP) $(CFLAGS) -M $(SOURCES) > .depend
  152. + $(RM) $(LIBNEWT) $(TARGETS) *.o
  153. -$(SHAREDDIR):
  154. - mkdir -p $(SHAREDDIR)
  155. +distclean: clean
  156. + $(RM) config.cache config.status config.log
  157. + $(RM) Makefile
  158. +
  159. +install: all
  160. + $(SHTOOL) mkdir -p -m 755 $(DESTDIR)$(bindir)
  161. + $(SHTOOL) mkdir -p -m 755 $(DESTDIR)$(libdir)
  162. + $(SHTOOL) mkdir -p -m 755 $(DESTDIR)$(includedir)
  163. + $(SHTOOL) mkdir -p -m 755 $(DESTDIR)$(mandir)/man1
  164. + $(SHTOOL) install -c -m 644 newt.h $(DESTDIR)$(includedir)/
  165. + $(SHTOOL) install -c -m 644 $(LIBNEWT) $(DESTDIR)$(libdir)/
  166. + $(SHTOOL) install -c -m 755 -s whiptail $(DESTDIR)$(bindir)/
  167. + $(SHTOOL) install -c -m 644 whiptail.1 $(DESTDIR)$(mandir)/man1/
  168. -sharedlib: $(LIBNEWTSH)
  169. -
  170. -$(LIBNEWTSH): $(SHAREDDIR) $(SHAREDOBJS)
  171. - gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(SHLIBS)
  172. -
  173. -$(SHAREDDIR)/%.o : %.c
  174. - $(CC) $(SHCFLAGS) -c $(CFLAGS) -o $@ $<
  175. -
  176. -$(SHAREDDIR)/newt.o: newt.c Makefile
  177. - $(CC) $(SHCFLAGS) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
  178. -
  179. -
  180. -install: $(LIBNEWT) install-sh whiptail
  181. - [ -d $(instroot)/$(bindir) ] || install -m 755 -d $(instroot)/$(bindir)
  182. - [ -d $(instroot)/$(libdir) ] || install -m 755 -d $(instroot)/$(libdir)
  183. - [ -d $(instroot)/$(includedir) ] || install -m 755 -d $(instroot)/$(includedir)
  184. - install -m 644 newt.h $(instroot)/$(includedir)
  185. - install -m 644 $(LIBNEWT) $(instroot)/$(libdir)
  186. - install -m 755 whiptail $(instroot)/$(bindir)
  187. -
  188. -install-sh: sharedlib $(WHIPTCLSO) _snackmodule.so
  189. - [ -d $(instroot)/$(libdir) ] || install -m 755 -d $(instroot)/$(libdir)
  190. - install -m 755 $(LIBNEWTSH) $(instroot)/$(libdir)
  191. - ln -sf $(LIBNEWTSH) $(instroot)/$(libdir)/libnewt.so
  192. - [ -n "$(WHIPTCLSO)" ] && install -m 755 whiptcl.so $(instroot)/$(libdir) || :
  193. - for ver in $(PYTHONVERS) ; do \
  194. - [ -d $(instroot)/$(libdir)/$$ver/site-packages ] || install -m 755 -d $(instroot)/$(libdir)/$$ver/site-packages ;\
  195. - install -m 755 $$ver/_snackmodule.so $(instroot)/$(libdir)/$$ver/site-packages ;\
  196. - install -m 755 snack.py $(instroot)/$(libdir)/$$ver/site-packages ;\
  197. - done
  198. -
  199. -configure: configure.in
  200. - autoconf
  201. - echo "You need to rerun ./configure before continuing"
  202. - exit 1
  203. -
  204. -archive: configure
  205. - @cvs tag -F $(CVSTAG)
  206. - @rm -rf /tmp/newt-$(VERSION) /tmp/newt
  207. - @cd /tmp; cvs export -r$(CVSTAG) newt; mv newt newt-$(VERSION)
  208. - @cd /tmp/newt-$(VERSION); autoconf
  209. - @cd /tmp; tar czSpf newt-$(VERSION).tar.gz newt-$(VERSION)
  210. - @rm -rf /tmp/newt-$(VERSION)
  211. - @cp /tmp/newt-$(VERSION).tar.gz .
  212. - @rm -f /tmp/newt-$(VERSION).tar.gz
  213. - @echo " "
  214. - @echo "The final archive is ./newt-$(VERSION).tar.gz."
  215. -
  216. -ifeq (.depend,$(wildcard .depend))
  217. -include .depend
  218. -endif
  219. Index: newt.c
  220. --- newt.c.orig 2003-02-05 08:11:35.000000000 +0100
  221. +++ newt.c 2003-12-14 12:02:42.000000000 +0100
  222. @@ -9,7 +9,9 @@
  223. #include <sys/types.h>
  224. #include <termios.h>
  225. #include <unistd.h>
  226. +#ifdef HAVE_WCHAR
  227. #include <wchar.h>
  228. +#endif
  229. #ifdef HAVE_ALLOCA_H
  230. #include <alloca.h>
  231. @@ -146,13 +148,16 @@
  232. }
  233. int wstrlen(const char *str, int len) {
  234. +#ifdef HAVE_WCHAR
  235. mbstate_t ps;
  236. wchar_t tmp;
  237. +#endif
  238. int nchars = 0;
  239. if (!str) return 0;
  240. if (!len) return 0;
  241. if (len < 0) len = strlen(str);
  242. +#ifdef HAVE_WCHAR
  243. memset(&ps,0,sizeof(mbstate_t));
  244. while (len > 0) {
  245. int x,y;
  246. @@ -166,6 +171,9 @@
  247. nchars+=y;
  248. } else break;
  249. }
  250. +#else
  251. + nchars = len;
  252. +#endif
  253. return nchars;
  254. }
  255. Index: shtool
  256. --- shtool.orig 2003-12-14 12:02:42.000000000 +0100
  257. +++ shtool 2003-12-14 12:02:42.000000000 +0100
  258. @@ -0,0 +1,628 @@
  259. +#!/bin/sh
  260. +##
  261. +## GNU shtool -- The GNU Portable Shell Tool
  262. +## Copyright (c) 1994-2002 Ralf S. Engelschall <rse@engelschall.com>
  263. +##
  264. +## See http://www.gnu.org/software/shtool/ for more information.
  265. +## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
  266. +##
  267. +## Version: 1.6.2 (02-Nov-2002)
  268. +## Contents: 2/19 available modules
  269. +##
  270. +
  271. +##
  272. +## This program is free software; you can redistribute it and/or modify
  273. +## it under the terms of the GNU General Public License as published by
  274. +## the Free Software Foundation; either version 2 of the License, or
  275. +## (at your option) any later version.
  276. +##
  277. +## This program is distributed in the hope that it will be useful,
  278. +## but WITHOUT ANY WARRANTY; without even the implied warranty of
  279. +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  280. +## General Public License for more details.
  281. +##
  282. +## You should have received a copy of the GNU General Public License
  283. +## along with this program; if not, write to the Free Software
  284. +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  285. +## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
  286. +##
  287. +## NOTICE: Given that you include this file verbatim into your own
  288. +## source tree, you are justified in saying that it remains separate
  289. +## from your package, and that this way you are simply just using GNU
  290. +## shtool. So, in this situation, there is no requirement that your
  291. +## package itself is licensed under the GNU General Public License in
  292. +## order to take advantage of GNU shtool.
  293. +##
  294. +
  295. +##
  296. +## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
  297. +##
  298. +## Available commands:
  299. +## install Install a program, script or datafile
  300. +## mkdir Make one or more directories
  301. +##
  302. +## Not available commands (because module was not built-in):
  303. +## echo Print string with optional construct expansion
  304. +## mdate Pretty-print modification time of a file or dir
  305. +## table Pretty-print a field-separated list as a table
  306. +## prop Display progress with a running propeller
  307. +## move Move files with simultaneous substitution
  308. +## mkln Make link with calculation of relative paths
  309. +## mkshadow Make a shadow tree through symbolic links
  310. +## fixperm Fix file permissions inside a source tree
  311. +## rotate Logfile rotation
  312. +## tarball Roll distribution tarballs
  313. +## subst Apply sed(1) substitution operations
  314. +## guessos Simple operating system guesser
  315. +## arx Extended archive command
  316. +## slo Separate linker options by library class
  317. +## scpp Sharing C Pre-Processor
  318. +## version Maintain a version information file
  319. +## path Deal with program paths
  320. +##
  321. +
  322. +if [ $# -eq 0 ]; then
  323. + echo "$0:Error: invalid command line" 1>&2
  324. + echo "$0:Hint: run \`$0 -h' for usage" 1>&2
  325. + exit 1
  326. +fi
  327. +if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
  328. + echo "This is GNU shtool, version 1.6.2 (02-Nov-2002)"
  329. + echo "Copyright (c) 1994-2002 Ralf S. Engelschall <rse@engelschall.com>"
  330. + echo "Report bugs to <bug-shtool@gnu.org>"
  331. + echo ''
  332. + echo "Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]"
  333. + echo ''
  334. + echo 'Available global <options>:'
  335. + echo ' -v, --version display shtool version information'
  336. + echo ' -h, --help display shtool usage help page (this one)'
  337. + echo ' -d, --debug display shell trace information'
  338. + echo ' -r, --recreate recreate this shtool script via shtoolize'
  339. + echo ''
  340. + echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
  341. + echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
  342. + echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
  343. + echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
  344. + echo ' <sed-cmd>] <file> [<file> ...] <path>'
  345. + echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
  346. + echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
  347. + echo ' [<dir> ...]'
  348. + echo ''
  349. + echo 'Not available <cmd-name> (because module was not built-in):'
  350. + echo ' echo [-n|--newline] [-e|--expand] [<str> ...]'
  351. + echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
  352. + echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
  353. + echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
  354. + echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
  355. + echo ' prop [-p|--prefix <str>]'
  356. + echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
  357. + echo ' <src-file> <dst-file>'
  358. + echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
  359. + echo ' [<src-path> ...] <dst-path>'
  360. + echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
  361. + echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
  362. + echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
  363. + echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
  364. + echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
  365. + echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-o|--owner'
  366. + echo ' <owner>] [-g|--group <group>] [-m|--mode <mode>] [-M|--migrate'
  367. + echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
  368. + echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
  369. + echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
  370. + echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
  371. + echo ' <path> [<path> ...]'
  372. + echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-s|--stealth]'
  373. + echo ' [-i|--interactive] [-b|--backup <ext>] [-e|--exec <cmd>]'
  374. + echo ' [-f|--file <cmd-file>] [<file>] [...]'
  375. + echo ' guessos '
  376. + echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
  377. + echo ' ...]'
  378. + echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
  379. + echo ' ...]'
  380. + echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
  381. + echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
  382. + echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
  383. + echo ' <file> [<file> ...]'
  384. + echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
  385. + echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
  386. + echo ' <knob>] [-d|--display <type>] <file>'
  387. + echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
  388. + echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
  389. + echo ''
  390. + exit 0
  391. +fi
  392. +if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
  393. + echo "GNU shtool 1.6.2 (02-Nov-2002)"
  394. + exit 0
  395. +fi
  396. +if [ ".$1" = ".-r" -o ".$1" = ."--recreate" ]; then
  397. + shtoolize -oshtool install mkdir
  398. + exit 0
  399. +fi
  400. +if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
  401. + shift
  402. + set -x
  403. +fi
  404. +name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
  405. +case "$name" in
  406. + install|mkdir )
  407. + # implicit tool command selection
  408. + tool="$name"
  409. + ;;
  410. + * )
  411. + # explicit tool command selection
  412. + tool="$1"
  413. + shift
  414. + ;;
  415. +esac
  416. +arg_spec=""
  417. +opt_spec=""
  418. +gen_tmpfile=no
  419. +
  420. +##
  421. +## DISPATCH INTO SCRIPT PROLOG
  422. +##
  423. +
  424. +case $tool in
  425. + install )
  426. + str_tool="install"
  427. + str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
  428. + arg_spec="1+"
  429. + opt_spec="v.t.d.c.C.s.m:o:g:e+"
  430. + opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
  431. + opt_v=no
  432. + opt_t=no
  433. + opt_d=no
  434. + opt_c=no
  435. + opt_C=no
  436. + opt_s=no
  437. + opt_m="0755"
  438. + opt_o=""
  439. + opt_g=""
  440. + opt_e=""
  441. + ;;
  442. + mkdir )
  443. + str_tool="mkdir"
  444. + str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
  445. + arg_spec="1+"
  446. + opt_spec="t.f.p.m:o:g:"
  447. + opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
  448. + opt_t=no
  449. + opt_f=no
  450. + opt_p=no
  451. + opt_m=""
  452. + opt_o=""
  453. + opt_g=""
  454. + ;;
  455. + -* )
  456. + echo "$0:Error: unknown option \`$tool'" 2>&1
  457. + echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  458. + exit 1
  459. + ;;
  460. + * )
  461. + echo "$0:Error: unknown command \`$tool'" 2>&1
  462. + echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  463. + exit 1
  464. + ;;
  465. +esac
  466. +
  467. +##
  468. +## COMMON UTILITY CODE
  469. +##
  470. +
  471. +# commonly used ASCII values
  472. +ASC_TAB=" "
  473. +ASC_NL="
  474. +"
  475. +
  476. +# determine name of tool
  477. +if [ ".$tool" != . ]; then
  478. + # used inside shtool script
  479. + toolcmd="$0 $tool"
  480. + toolcmdhelp="shtool $tool"
  481. + msgprefix="shtool:$tool"
  482. +else
  483. + # used as standalone script
  484. + toolcmd="$0"
  485. + toolcmdhelp="sh $0"
  486. + msgprefix="$str_tool"
  487. +fi
  488. +
  489. +# parse argument specification string
  490. +eval `echo $arg_spec |\
  491. + sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
  492. +
  493. +# parse option specification string
  494. +eval `echo h.$opt_spec |\
  495. + sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
  496. +
  497. +# parse option alias string
  498. +eval `echo h:help,$opt_alias |\
  499. + tr 'x-' 'x_' | sed -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
  500. +
  501. +# interate over argument line
  502. +opt_PREV=''
  503. +while [ $# -gt 0 ]; do
  504. + # special option stops processing
  505. + if [ ".$1" = ".--" ]; then
  506. + shift
  507. + break
  508. + fi
  509. +
  510. + # determine option and argument
  511. + opt_ARG_OK=no
  512. + if [ ".$opt_PREV" != . ]; then
  513. + # merge previous seen option with argument
  514. + opt_OPT="$opt_PREV"
  515. + opt_ARG="$1"
  516. + opt_ARG_OK=yes
  517. + opt_PREV=''
  518. + else
  519. + # split argument into option and argument
  520. + case "$1" in
  521. + --[a-zA-Z0-9]*=*)
  522. + eval `echo "x$1" |\
  523. + sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
  524. + opt_STR=`echo $opt_OPT | tr 'x-' 'x_'`
  525. + eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  526. + ;;
  527. + --[a-zA-Z0-9]*)
  528. + opt_OPT=`echo "x$1" | cut -c4-`
  529. + opt_STR=`echo $opt_OPT | tr 'x-' 'x_'`
  530. + eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  531. + opt_ARG=''
  532. + ;;
  533. + -[a-zA-Z0-9]*)
  534. + eval `echo "x$1" |\
  535. + sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
  536. + -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
  537. + ;;
  538. + -[a-zA-Z0-9])
  539. + opt_OPT=`echo "x$1" | cut -c3-`
  540. + opt_ARG=''
  541. + ;;
  542. + *)
  543. + break
  544. + ;;
  545. + esac
  546. + fi
  547. +
  548. + # eat up option
  549. + shift
  550. +
  551. + # determine whether option needs an argument
  552. + eval "opt_MODE=\$opt_MODE_${opt_OPT}"
  553. + if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then
  554. + if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then
  555. + opt_PREV="$opt_OPT"
  556. + continue
  557. + fi
  558. + fi
  559. +
  560. + # process option
  561. + case $opt_MODE in
  562. + '.' )
  563. + # boolean option
  564. + eval "opt_${opt_OPT}=yes"
  565. + ;;
  566. + ':' )
  567. + # option with argument (multiple occurances override)
  568. + eval "opt_${opt_OPT}=\"\$opt_ARG\""
  569. + ;;
  570. + '+' )
  571. + # option with argument (multiple occurances append)
  572. + eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
  573. + ;;
  574. + * )
  575. + echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
  576. + echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  577. + exit 1
  578. + ;;
  579. + esac
  580. +done
  581. +if [ ".$opt_PREV" != . ]; then
  582. + echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
  583. + echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  584. + exit 1
  585. +fi
  586. +
  587. +# process help option
  588. +if [ ".$opt_h" = .yes ]; then
  589. + echo "Usage: $toolcmdhelp $str_usage"
  590. + exit 0
  591. +fi
  592. +
  593. +# complain about incorrect number of arguments
  594. +case $arg_MODE in
  595. + '=' )
  596. + if [ $# -ne $arg_NUMS ]; then
  597. + echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
  598. + echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  599. + exit 1
  600. + fi
  601. + ;;
  602. + '+' )
  603. + if [ $# -lt $arg_NUMS ]; then
  604. + echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
  605. + echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  606. + exit 1
  607. + fi
  608. + ;;
  609. +esac
  610. +
  611. +# establish a temporary file on request
  612. +if [ ".$gen_tmpfile" = .yes ]; then
  613. + if [ ".$TMPDIR" != . ]; then
  614. + tmpdir="$TMPDIR"
  615. + elif [ ".$TEMPDIR" != . ]; then
  616. + tmpdir="$TEMPDIR"
  617. + else
  618. + tmpdir="/tmp"
  619. + fi
  620. + tmpfile="$tmpdir/.shtool.$$"
  621. + rm -f $tmpfile >/dev/null 2>&1
  622. + touch $tmpfile
  623. + chmod 600 $tmpfile
  624. +fi
  625. +
  626. +##
  627. +## DISPATCH INTO SCRIPT BODY
  628. +##
  629. +
  630. +case $tool in
  631. +
  632. +install )
  633. + ##
  634. + ## install -- Install a program, script or datafile
  635. + ## Copyright (c) 1997-2002 Ralf S. Engelschall <rse@engelschall.com>
  636. + ## Originally written for shtool
  637. + ##
  638. +
  639. + # special case: "shtool install -d <dir> [...]" internally
  640. + # maps to "shtool mkdir -f -p -m 755 <dir> [...]"
  641. + if [ "$opt_d" = yes ]; then
  642. + cmd="$0 mkdir -f -p -m 755"
  643. + if [ ".$opt_o" != . ]; then
  644. + cmd="$cmd -o '$opt_o'"
  645. + fi
  646. + if [ ".$opt_g" != . ]; then
  647. + cmd="$cmd -g '$opt_g'"
  648. + fi
  649. + if [ ".$opt_v" = .yes ]; then
  650. + cmd="$cmd -v"
  651. + fi
  652. + if [ ".$opt_t" = .yes ]; then
  653. + cmd="$cmd -t"
  654. + fi
  655. + for dir in "$@"; do
  656. + eval "$cmd $dir" || exit $?
  657. + done
  658. + exit 0
  659. + fi
  660. +
  661. + # determine source(s) and destination
  662. + argc=$#
  663. + srcs=""
  664. + while [ $# -gt 1 ]; do
  665. + srcs="$srcs $1"
  666. + shift
  667. + done
  668. + dstpath="$1"
  669. +
  670. + # type check for destination
  671. + dstisdir=0
  672. + if [ -d $dstpath ]; then
  673. + dstpath=`echo "$dstpath" | sed -e 's:/$::'`
  674. + dstisdir=1
  675. + fi
  676. +
  677. + # consistency check for destination
  678. + if [ $argc -gt 2 -a $dstisdir = 0 ]; then
  679. + echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
  680. + exit 1
  681. + fi
  682. +
  683. + # iterate over all source(s)
  684. + for src in $srcs; do
  685. + dst=$dstpath
  686. +
  687. + # if destination is a directory, append the input filename
  688. + if [ $dstisdir = 1 ]; then
  689. + dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
  690. + dst="$dst/$dstfile"
  691. + fi
  692. +
  693. + # check for correct arguments
  694. + if [ ".$src" = ".$dst" ]; then
  695. + echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
  696. + continue
  697. + fi
  698. + if [ -d "$src" ]; then
  699. + echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
  700. + continue
  701. + fi
  702. +
  703. + # make a temp file name in the destination directory
  704. + dsttmp=`echo $dst |\
  705. + sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
  706. + -e "s;\$;/#INST@$$#;"`
  707. +
  708. + # verbosity
  709. + if [ ".$opt_v" = .yes ]; then
  710. + echo "$src -> $dst" 1>&2
  711. + fi
  712. +
  713. + # copy or move the file name to the temp name
  714. + # (because we might be not allowed to change the source)
  715. + if [ ".$opt_C" = .yes ]; then
  716. + opt_c=yes
  717. + fi
  718. + if [ ".$opt_c" = .yes ]; then
  719. + if [ ".$opt_t" = .yes ]; then
  720. + echo "cp $src $dsttmp" 1>&2
  721. + fi
  722. + cp $src $dsttmp || exit $?
  723. + else
  724. + if [ ".$opt_t" = .yes ]; then
  725. + echo "mv $src $dsttmp" 1>&2
  726. + fi
  727. + mv $src $dsttmp || exit $?
  728. + fi
  729. +
  730. + # adjust the target file
  731. + if [ ".$opt_e" != . ]; then
  732. + sed='sed'
  733. + OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
  734. + for e
  735. + do
  736. + sed="$sed -e '$e'"
  737. + done
  738. + cp $dsttmp $dsttmp.old
  739. + eval "$sed <$dsttmp.old >$dsttmp" || exit $?
  740. + rm -f $dsttmp.old
  741. + fi
  742. + if [ ".$opt_s" = .yes ]; then
  743. + if [ ".$opt_t" = .yes ]; then
  744. + echo "strip $dsttmp" 1>&2
  745. + fi
  746. + strip $dsttmp || exit $?
  747. + fi
  748. + if [ ".$opt_o" != . ]; then
  749. + if [ ".$opt_t" = .yes ]; then
  750. + echo "chown $opt_o $dsttmp" 1>&2
  751. + fi
  752. + chown $opt_o $dsttmp || exit $?
  753. + fi
  754. + if [ ".$opt_g" != . ]; then
  755. + if [ ".$opt_t" = .yes ]; then
  756. + echo "chgrp $opt_g $dsttmp" 1>&2
  757. + fi
  758. + chgrp $opt_g $dsttmp || exit $?
  759. + fi
  760. + if [ ".$opt_m" != ".-" ]; then
  761. + if [ ".$opt_t" = .yes ]; then
  762. + echo "chmod $opt_m $dsttmp" 1>&2
  763. + fi
  764. + chmod $opt_m $dsttmp || exit $?
  765. + fi
  766. +
  767. + # determine whether to do a quick install
  768. + # (has to be done _after_ the strip was already done)
  769. + quick=no
  770. + if [ ".$opt_C" = .yes ]; then
  771. + if [ -r $dst ]; then
  772. + if cmp -s $src $dst; then
  773. + quick=yes
  774. + fi
  775. + fi
  776. + fi
  777. +
  778. + # finally, install the file to the real destination
  779. + if [ $quick = yes ]; then
  780. + if [ ".$opt_t" = .yes ]; then
  781. + echo "rm -f $dsttmp" 1>&2
  782. + fi
  783. + rm -f $dsttmp
  784. + else
  785. + if [ ".$opt_t" = .yes ]; then
  786. + echo "rm -f $dst && mv $dsttmp $dst" 1>&2
  787. + fi
  788. + rm -f $dst && mv $dsttmp $dst
  789. + fi
  790. + done
  791. + ;;
  792. +
  793. +mkdir )
  794. + ##
  795. + ## mkdir -- Make one or more directories
  796. + ## Copyright (c) 1996-2002 Ralf S. Engelschall <rse@engelschall.com>
  797. + ## Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu>
  798. + ## Cleaned up and enhanced for shtool
  799. + ##
  800. +
  801. + errstatus=0
  802. + for p in ${1+"$@"}; do
  803. + # if the directory already exists...
  804. + if [ -d "$p" ]; then
  805. + if [ ".$opt_f" = .no -a ".$opt_p" = .no ]; then
  806. + echo "$msgprefix:Error: directory already exists: $p" 1>&2
  807. + errstatus=1
  808. + break
  809. + else
  810. + continue
  811. + fi
  812. + fi
  813. + # if the directory has to be created...
  814. + if [ ".$opt_p" = .no ]; then
  815. + if [ ".$opt_t" = .yes ]; then
  816. + echo "mkdir $p" 1>&2
  817. + fi
  818. + mkdir $p || errstatus=$?
  819. + if [ ".$opt_o" != . ]; then
  820. + if [ ".$opt_t" = .yes ]; then
  821. + echo "chown $opt_o $p" 1>&2
  822. + fi
  823. + chown $opt_o $p || errstatus=$?
  824. + fi
  825. + if [ ".$opt_g" != . ]; then
  826. + if [ ".$opt_t" = .yes ]; then
  827. + echo "chgrp $opt_g $p" 1>&2
  828. + fi
  829. + chgrp $opt_g $p || errstatus=$?
  830. + fi
  831. + if [ ".$opt_m" != . ]; then
  832. + if [ ".$opt_t" = .yes ]; then
  833. + echo "chmod $opt_m $p" 1>&2
  834. + fi
  835. + chmod $opt_m $p || errstatus=$?
  836. + fi
  837. + else
  838. + # the smart situation
  839. + set fnord `echo ":$p" |\
  840. + sed -e 's/^:\//%/' \
  841. + -e 's/^://' \
  842. + -e 's/\// /g' \
  843. + -e 's/^%/\//'`
  844. + shift
  845. + pathcomp=''
  846. + for d in ${1+"$@"}; do
  847. + pathcomp="$pathcomp$d"
  848. + case "$pathcomp" in
  849. + -* ) pathcomp="./$pathcomp" ;;
  850. + esac
  851. + if [ ! -d "$pathcomp" ]; then
  852. + if [ ".$opt_t" = .yes ]; then
  853. + echo "mkdir $pathcomp" 1>&2
  854. + fi
  855. + mkdir $pathcomp || errstatus=$?
  856. + if [ ".$opt_o" != . ]; then
  857. + if [ ".$opt_t" = .yes ]; then
  858. + echo "chown $opt_o $pathcomp" 1>&2
  859. + fi
  860. + chown $opt_o $pathcomp || errstatus=$?
  861. + fi
  862. + if [ ".$opt_g" != . ]; then
  863. + if [ ".$opt_t" = .yes ]; then
  864. + echo "chgrp $opt_g $pathcomp" 1>&2
  865. + fi
  866. + chgrp $opt_g $pathcomp || errstatus=$?
  867. + fi
  868. + if [ ".$opt_m" != . ]; then
  869. + if [ ".$opt_t" = .yes ]; then
  870. + echo "chmod $opt_m $pathcomp" 1>&2
  871. + fi
  872. + chmod $opt_m $pathcomp || errstatus=$?
  873. + fi
  874. + fi
  875. + pathcomp="$pathcomp/"
  876. + done
  877. + fi
  878. + done
  879. + exit $errstatus
  880. + ;;
  881. +
  882. +esac
  883. +
  884. +exit 0
  885. +
  886. +##EOF##
  887. Index: textbox.c
  888. --- textbox.c.orig 2003-01-03 21:54:45.000000000 +0100
  889. +++ textbox.c 2003-12-14 12:02:42.000000000 +0100
  890. @@ -4,7 +4,9 @@
  891. #include <stdlib.h>
  892. #include <string.h>
  893. #include <wchar.h>
  894. +#ifdef HAVE_WCHAR
  895. #include <wctype.h>
  896. +#endif
  897. #include "newt.h"
  898. #include "newt_pr.h"
  899. @@ -161,8 +163,10 @@
  900. int i;
  901. int howbad = 0;
  902. int height = 0;
  903. +#ifdef HAVE_WCHAR
  904. wchar_t tmp;
  905. mbstate_t ps;
  906. +#endif
  907. if (resultPtr) {
  908. /* XXX I think this will work */
  909. @@ -170,7 +174,9 @@
  910. *result = '\0';
  911. }
  912. +#ifdef HAVE_WCHAR
  913. memset(&ps,0,sizeof(mbstate_t));
  914. +#endif
  915. while (*text) {
  916. end = strchr(text, '\n');
  917. if (!end)
  918. @@ -202,6 +208,7 @@
  919. chptr = text;
  920. w2 = 0;
  921. for (i = 0; i < width - 1;) {
  922. +#ifdef HAVE_WCHAR
  923. if ((x=mbrtowc(&tmp,chptr,end-chptr,&ps))<=0)
  924. break;
  925. if (spc && !iswspace(tmp))
  926. @@ -215,6 +222,17 @@
  927. x = wcwidth(tmp);
  928. if (x>0)
  929. i+=x;
  930. +#else
  931. + if (spc && !isspace(*chptr))
  932. + spc = 0;
  933. + else if (!spc && isspace(*chptr)) {
  934. + spc = 1;
  935. + spcptr = chptr;
  936. + w2 = i;
  937. + }
  938. + chptr++;
  939. + i++;
  940. +#endif
  941. }
  942. howbad += width - w2 + 1;
  943. #ifdef DEBUG_WRAP
  944. @@ -229,9 +247,14 @@
  945. text = chptr;
  946. while (1) {
  947. +#ifdef HAVE_WCHAR
  948. if ((x=mbrtowc(&tmp,text,end-text,NULL))<=0)
  949. break;
  950. if (!iswspace(tmp)) break;
  951. +#else
  952. + x = 1;
  953. + if (!isspace(*text)) break;
  954. +#endif
  955. text += x;
  956. }
  957. }
  958. Index: tutorial.txt
  959. --- tutorial.txt.orig 2003-12-14 12:19:49.000000000 +0100
  960. +++ tutorial.txt 2003-12-14 12:19:54.000000000 +0100
  961. @@ -0,0 +1,1079 @@
  962. +
  963. +Writing Programs Using newtErik Troan, <ewt@redhat.com>
  964. +
  965. +v0.31, 2003-Jan-06
  966. +
  967. + The newt windowing system is a terminal-based window and widget
  968. + library designed for writing applications with a simple, but
  969. + user-friendly, interface. While newt is not intended to provide the
  970. + rich feature set advanced applications may require, it has proven to
  971. + be flexible enough for a wide range of applications (most notably, Red
  972. + Hat's installation process). This tutorial explains the design
  973. + philosophy behind newt and how to use newt from your programs.
  974. + _________________________________________________________________
  975. +
  976. + Table of Contents
  977. + 1. Introduction
  978. +
  979. + 1.1. Background
  980. + 1.2. Designing newt applications
  981. + 1.3. Components
  982. + 1.4. Conventions
  983. +
  984. + 2. Basic Newt Functions
  985. +
  986. + 2.1. Starting and Ending newt Services
  987. + 2.2. Handling Keyboard Input
  988. + 2.3. Drawing on the Root Window
  989. + 2.4. Refreshing the Screen
  990. + 2.5. Other Miscellaneous Functions
  991. + 2.6. Basic newt Example
  992. +
  993. + 3. Windows
  994. +
  995. + 3.1. Creating Windows
  996. + 3.2. Destroying Windows
  997. +
  998. + 4. Components
  999. +
  1000. + 4.1. Introduction to Forms
  1001. + 4.2. Components
  1002. + 4.3. General Component Manipulation
  1003. + 4.4. Buttons
  1004. +
  1005. + 4.4.1. Button Example
  1006. +
  1007. + 4.5. Labels
  1008. + 4.6. Entry Boxes
  1009. + 4.7. Checkboxes
  1010. + 4.8. Radio Buttons
  1011. + 4.9. Scales
  1012. + 4.10. Textboxes
  1013. +
  1014. + 4.10.1. Reflowing Text
  1015. +
  1016. + 4.11. Scrollbars
  1017. + 4.12. Listboxes
  1018. +
  1019. + 4.12.1. Basic Listboxes
  1020. + 4.12.2. Manipulating Listbox Contents
  1021. + 4.12.3. Multiple Selections
  1022. +
  1023. + 4.13. Advanced Forms
  1024. +
  1025. + 4.13.1. Exiting From Forms
  1026. +
  1027. +1. Introduction
  1028. +
  1029. +Newt has a definite design philosophy behind it, and knowing that design
  1030. +makes it significantly easier to craft robust newt applications. This
  1031. +tutorial documents newt 0.30 --- older versions of newt had annoying
  1032. +inconsistencies in it (which writing this tutorial pointed out), which were
  1033. +removed while this tutorial was written. The latest version of newt is
  1034. +always available from Red Hat.
  1035. + _________________________________________________________________
  1036. +
  1037. +1.1. Background
  1038. +
  1039. +Newt was originally designed for use in the install code for Red Hat Linux.
  1040. +As this install code runs in an environment with limited resources (most
  1041. +importantly limited filesystem space), newt's size was immediately an issue.
  1042. +To help minimize its size, the following design decisions were made early in
  1043. +its implementation:
  1044. +
  1045. + * newt does not use an event-driven architecture.
  1046. + * newt is written in C, not C++. While there has been interest in
  1047. + constructing C++ wrapper classes around the newt API, nothing has
  1048. + yet come of those ideas.
  1049. + * Windows must be created and destroyed as a stack (in other words,
  1050. + all newt windows behave as modal dialogs). This is probably the
  1051. + greatest functionality restriction of newt.
  1052. + * The tty keyboard is the only supported input device.
  1053. + * Many behaviours, such as widget traversal order, are difficult or
  1054. + impossible to change.
  1055. +
  1056. + While newt provides a complete API, it does not handle the low-level
  1057. + screen drawing itself. Instead, newt is layered on top of the screen
  1058. + management capabilities of John E. Davis's S-Lang library.
  1059. + _________________________________________________________________
  1060. +
  1061. +1.2. Designing newt applications
  1062. +
  1063. +As newt is not event driven and forces modal windows (forcing window order
  1064. +to behave like a stack), newt applications tend to look quite like other
  1065. +text-mode programs. It is quite straightforward to convert a command line
  1066. +program which uses simple user prompts into a newt application. Some of the
  1067. +programs run as part of the Red Hat installation process (such as
  1068. +Xconfigurator and mouseconfig) were originally written as simple terminal
  1069. +mode programs which used line-oriented menus to get input from the user and
  1070. +were later converted into newt applications (through a process
  1071. +affectionately known as newtering). Such a conversion does not require
  1072. +changes to the control flow of most applications. Programming newt is
  1073. +dramatically different from writing programs for most other windowing
  1074. +systems as newt's API is not event driven. This means that newt applications
  1075. +look dramatically different from programs written for event-driven
  1076. +architectures such as Motif, gtk, or even Borland's old TurboVision
  1077. +libraries. When you're designing your newt program, keep this
  1078. +differentiation in mind. As long as you plan your application to call a
  1079. +function to get input and then continue (rather then having your program
  1080. +called when input is ready), programming with the newt libraries should be
  1081. +simple.
  1082. + _________________________________________________________________
  1083. +
  1084. +1.3. Components
  1085. +
  1086. +Displayable items in newt are known as components, which are analogous to
  1087. +the widgets provided by most Unix widget sets. There are two main types of
  1088. +components in newt, forms and everything else. Forms logically group
  1089. +components into functional sets. When an application is ready to get input
  1090. +from a user, it ``runs a form'', which makes the form active and lets the
  1091. +user enter information into the components the form contains. A form may
  1092. +contain any other component, including other forms. Using subforms in this
  1093. +manner lets the application change the details of how the user tabs between
  1094. +components on the form, scroll regions of the screen, and control background
  1095. +colors for portions of windows. Every component is of type newtComponent,
  1096. +which is an opaque type. It's guaranteed to be a pointer though, which lets
  1097. +applications move it through void pointers if the need arises. Variables of
  1098. +type newtComponent should never be directly manipulated -- they should only
  1099. +be passed to newt functions. As newtComponent variables are pointers,
  1100. +remember that they are always passed by value -- if you pass a newtComponent
  1101. +to a function which manipulates it, that component is manipulated
  1102. +everywhere, not just inside of that function (which is nearly always the
  1103. +behaviour you want).
  1104. + _________________________________________________________________
  1105. +
  1106. +1.4. Conventions
  1107. +
  1108. +Newt uses a number of conventions to make it easier for programmers to use.
  1109. +
  1110. + * All functions which manipulate data structures take the data
  1111. + structure being modified as their first parameter. For example,
  1112. + all of the functions which manipulate forms expect the
  1113. + newtComponent for that form to be the first parameter.
  1114. + * As newt is loosely typed (forcing all of the components into a
  1115. + single variable makes coding easier, but nullifies the value of
  1116. + type checking), newt functions include the name of the type they
  1117. + are manipulating. An example of this is newtFormAddComponent(),
  1118. + which adds a component to a form. Note that the first parameter to
  1119. + this function is a form, as the name would suggest.
  1120. + * When screen coordinates are passed into a function, the x location
  1121. + precedes the y location. To help keep this clear, we'll use the
  1122. + words ``left'' and ``top'' to describe those indicators (with left
  1123. + corresponding to the x position).
  1124. + * When box sizes are passed, the horizontal width precedes the
  1125. + vertical width.
  1126. + * When both a screen location and a box size are being passed, the
  1127. + screen location precedes the box size.
  1128. + * When any component other then a form is created, the first two
  1129. + parameters are always the (left, right) location.
  1130. + * Many functions take a set of flags as the final parameter. These
  1131. + flags may be logically ORed together to pass more then one flag at
  1132. + a time.
  1133. + * Newt uses callback functions to convey certain events to the
  1134. + application. While callbacks differ slightly in their parameters,
  1135. + most of them allow the application to specify an arbitrary
  1136. + argument to be passed to the callback when the callback is
  1137. + invoked. This argument is always a void *, which allows the
  1138. + application great flexibility.
  1139. + _________________________________________________________________
  1140. +
  1141. +2. Basic Newt Functions
  1142. +
  1143. +While most newt functions are concerned with widgets or groups of widgets
  1144. +(called grids and forms), some parts of the newt API deal with more global
  1145. +issues, such as initializing newt or writing to the root window.
  1146. + _________________________________________________________________
  1147. +
  1148. +2.1. Starting and Ending newt Services
  1149. +
  1150. +There are three functions which nearly every newt application use. The first
  1151. +two are used to initialize the system.
  1152. +int newtInit(void);
  1153. +void newtCls(void);
  1154. +
  1155. +newtInit() should be the first function called by every newt program. It
  1156. +initializes internal data structures and places the terminal in raw mode.
  1157. +Most applications invoke newtCls() immediately after newtInit(), which
  1158. +causes the screen to be cleared. It's not necessary to call newtCls() to use
  1159. +any of newt's features, but doing so will normally give a much neater
  1160. +appearance. When a newt program is ready to exit, it should call
  1161. +newtFinished().
  1162. +
  1163. +int newtFinished(void);
  1164. +
  1165. + newtFinished() restores the terminal to its appearance when newtInit()
  1166. + was called (if possible -- on some terminals the cursor will be moved
  1167. + to the bottom, but it won't be possible to remember the original
  1168. + terminal contents) and places the terminal in its original input
  1169. + state. If this function isn't called, the terminal will probably need
  1170. + to be reset with the reset command before it can be used easily.
  1171. + _________________________________________________________________
  1172. +
  1173. +2.2. Handling Keyboard Input
  1174. +
  1175. +Normally, newt programs don't read input directly from the user. Instead,
  1176. +they let newt read the input and hand it to the program in a semi-digested
  1177. +form. Newt does provide a couple of simple functions which give programs (a
  1178. +bit of) control over the terminal.
  1179. +void newtWaitForKey(void);
  1180. +void newtClearKeyBuffer(void);
  1181. +
  1182. + The first of these, newtWaitForKey(), doesn't return until a key has
  1183. + been pressed. The keystroke is then ignored. If a key is already in
  1184. + the terminal's buffer, newtWaitForKey() discards a keystroke and
  1185. + returns immediately. newtClearKeyBuffer() discards the contents of the
  1186. + terminal's input buffer without waiting for additional input.
  1187. + _________________________________________________________________
  1188. +
  1189. +2.3. Drawing on the Root Window
  1190. +
  1191. +The background of the terminal's display (the part without any windows
  1192. +covering it) is known as the root window (it's the parent of all windows,
  1193. +just like the system's root directory is the parent of all subdirectories).
  1194. +Normally, applications don't use the root window, instead drawing all of
  1195. +their text inside of windows (newt doesn't require this though -- widgets
  1196. +may be placed directly on the root window without difficulty). It is often
  1197. +desirable to display some text, such as a program's name or copyright
  1198. +information, on the root window, however. Newt provides two ways of
  1199. +displaying text on the root window. These functions may be called at any
  1200. +time. They are the only newt functions which are meant to write outside of
  1201. +the current window.
  1202. +void newtDrawRootText(int left, int top, const char * text);
  1203. +
  1204. + This function is straightforward. It displays the string text at the
  1205. + position indicated. If either the left or top is negative, the
  1206. + position is measured from the opposite side of the screen. The final
  1207. + measurement will seem to be off by one though. For example, a top of
  1208. + -1 indicates the last line on the screen, and one of -2 is the line
  1209. + above that. As it's common to use the last line on the screen to
  1210. + display help information, newt includes special support for doing
  1211. + exactly that. The last line on the display is known as the help line,
  1212. + and is treated as a stack. As the value of the help line normally
  1213. + relates to the window currently displayed, using the same structure
  1214. + for window order and the help line is very natural. Two functions are
  1215. + provided to manipulate the help line.
  1216. +void newtPushHelpLine(const char * text);
  1217. +void newtPopHelpLine(void);
  1218. +
  1219. + The first function, newtPushHelpLine(), saves the current help line on
  1220. + a stack (which is independent of the window stack) and displays the
  1221. + new line. If text is NULL, newt's default help line is displayed
  1222. + (which provides basic instructions on using newt). If text is a string
  1223. + of length 0, the help line is cleared. For all other values of text,
  1224. + the passed string is displayed at the bottom, left-hand corner of the
  1225. + display. The space between the end of the displayed string the the
  1226. + right-hand edge of the terminal is cleared. newtPopHelpLine() replaces
  1227. + the current help line with the one it replaced. It's important not to
  1228. + call tt/newtPopHelpLine()/ more then newtPushHelpLine()! Suspending
  1229. + Newt Applications By default, newt programs cannot be suspended by the
  1230. + user (compare this to most Unix programs which can be suspended by
  1231. + pressing the suspend key (normally ^Z). Instead, programs can specify
  1232. + a callback function which gets invoked when the user presses the
  1233. + suspend key.
  1234. +typedef void (*newtSuspendCallback)(void);
  1235. +
  1236. +void newtSetSuspendCallback(newtSuspendCallback cb);
  1237. +
  1238. + The suspend function neither expects nor returns any value, and can do
  1239. + whatever it likes to when it is invoked. If no suspend callback is
  1240. + registered, the suspend keystroke is ignored. If the application
  1241. + should suspend and continue like most user applications, the suspend
  1242. + callback needs two other newt functions.
  1243. +void newtSuspend(void);
  1244. +void newtResume(void);
  1245. +
  1246. + newtSuspend() tells newt to return the terminal to its initial state.
  1247. + Once this is done, the application can suspend itself (by sending
  1248. + itself a SIGTSTP, fork a child program, or do whatever else it likes.
  1249. + When it wants to resume using the newt interface, it must call
  1250. + newtResume before doing so. Note that suspend callbacks are not signal
  1251. + handlers. When newtInit() takes over the terminal, it disables the
  1252. + part of the terminal interface which sends the suspend signal.
  1253. + Instead, if newt sees the suspend keystroke during normal input
  1254. + processing, it immediately calls the suspend callback if one has been
  1255. + set. This means that suspending newt applications is not asynchronous.
  1256. + _________________________________________________________________
  1257. +
  1258. +2.4. Refreshing the Screen
  1259. +
  1260. +To increase performance, S-Lang only updates the display when it needs to,
  1261. +not when the program tells S-Lang to write to the terminal. ``When it needs
  1262. +to'' is implemented as ``right before the we wait for the user to press a
  1263. +key''. While this allows for optimized screen displays most of the time,
  1264. +this optimization makes things difficult for programs which want to display
  1265. +progress messages without forcing the user to input characters. Applications
  1266. +can force S-Lang to immediately update modified portions of the screen by
  1267. +calling newtRefresh.
  1268. +
  1269. + 1. The program wants to display a progress message, without forcing
  1270. + for the user to enter any characters.
  1271. + 2. A misfeature of the program causes part of the screen to be
  1272. + corrupted. Ideally, the program would be fixed, but that may not
  1273. + always be practical.
  1274. + _________________________________________________________________
  1275. +
  1276. +2.5. Other Miscellaneous Functions
  1277. +
  1278. +As always, some function defy characterization. Two of newt's general
  1279. +function fit this oddball category.
  1280. +void newtBell(void);
  1281. +void newtGetScreenSize(int * cols, int * rows);
  1282. +
  1283. +The first sends a beep to the terminal. Depending on the terminal's
  1284. +settings, this been may or may not be audible. The second function,
  1285. +newtGetScreenSize(), fills in the passed pointers with the current size of
  1286. +the terminal.
  1287. + _________________________________________________________________
  1288. +
  1289. +2.6. Basic newt Example
  1290. +
  1291. +To help illustrate the functions presented in this section here is a short
  1292. +sample newt program which uses many of them. While it doesn't do anything
  1293. +interesting, it does show the basic structure of newt programs.
  1294. +#include <newt.h>
  1295. +#include <stdlib.h>
  1296. +
  1297. +int main(void) {
  1298. + newtInit();
  1299. + newtCls();
  1300. +
  1301. + newtDrawRootText(0, 0, "Some root text");
  1302. + newtDrawRootText(-25, -2, "Root text in the other corner");
  1303. +
  1304. + newtPushHelpLine(NULL);
  1305. + newtRefresh();
  1306. + sleep(1);
  1307. +
  1308. + newtPushHelpLine("A help line");
  1309. + newtRefresh();
  1310. + sleep(1);
  1311. +
  1312. + newtPopHelpLine();
  1313. + newtRefresh();
  1314. + sleep(1);
  1315. +
  1316. + newtFinished();
  1317. +}
  1318. + _________________________________________________________________
  1319. +
  1320. +3. Windows
  1321. +
  1322. +While most newt applications do use windows, newt's window support is
  1323. +actually extremely limited. Windows must be destroyed in the opposite of the
  1324. +order they were created, and only the topmost window may be active.
  1325. +Corollaries to this are:
  1326. +
  1327. + * The user may not switch between windows.
  1328. + * Only the top window may be destroyed.
  1329. +
  1330. +While this is quite a severe limitation, adopting it greatly simplifies both
  1331. +writing newt applications and developing newt itself, as it separates newt
  1332. +from the world of event-driven programming. However, this tradeoff between
  1333. +function and simplicity may make newt unsuitable for some tasks.
  1334. + _________________________________________________________________
  1335. +
  1336. +3.1. Creating Windows
  1337. +
  1338. +There are two main ways of opening newt windows: with or without explicit
  1339. +sizings. When grids (which will be introduced later in this tutorial) are
  1340. +used, a window may be made to just fit the grid. When grids are not used,
  1341. +explicit sizing must be given.
  1342. +int newtCenteredWindow(int width, int height, const char * title);
  1343. +int newtOpenWindow(int left, int top, int width, int height,
  1344. + const char * title);
  1345. +
  1346. +The first of these functions open a centered window of the specified size.
  1347. +The title is optional -- if it is NULL, then no title is used.
  1348. +newtOpenWindow*( is similar, but it requires a specific location for the
  1349. +upper left-hand corner of the window.
  1350. + _________________________________________________________________
  1351. +
  1352. +3.2. Destroying Windows
  1353. +
  1354. +All windows are destroyed in the same manner, no matter how the windows were
  1355. +originally created.
  1356. +void newtPopWindow(void);
  1357. +
  1358. +This function removes the top window from the display, and redraws the
  1359. +display areas which the window overwrote.
  1360. + _________________________________________________________________
  1361. +
  1362. +4. Components
  1363. +
  1364. +Components are the basic user interface element newt provides. A single
  1365. +component may be (for example) a listbox, push button checkbox, a collection
  1366. +of other components. Most components are used to display information in a
  1367. +window, provide a place for the user to enter data, or a combination of
  1368. +these two functions. Forms, however, are a component whose primary purpose
  1369. +is not noticed by the user at all. Forms are collections of components (a
  1370. +form may contain another form) which logically relate the components to one
  1371. +another. Once a form is created and had all of its constituent components
  1372. +added to it, applications normally then run the form. This gives control of
  1373. +the application to the form, which then lets the user enter data onto the
  1374. +form. When the user is done (a number of different events qualify as
  1375. +``done''), the form returns control to the part of the application which
  1376. +invoked it. The application may then read the information the user provided
  1377. +and continue appropriately. All newt components are stored in a common data
  1378. +type, a newtComponent (some of the particulars of newtComponents have
  1379. +already been mentioned. While this makes it easy for programmers to pass
  1380. +components around, it does force them to make sure they don't pass entry
  1381. +boxes to routines expecting push buttons, as the compiler can't ensure that
  1382. +for them. We start off with a brief introduction to forms. While not
  1383. +terribly complete, this introduction is enough to let us illustrate the rest
  1384. +of the components with some sample code. We'll then discuss the remainder of
  1385. +the components, and end this section with a more exhaustive description of
  1386. +forms.
  1387. + _________________________________________________________________
  1388. +
  1389. +4.1. Introduction to Forms
  1390. +
  1391. +As we've mentioned, forms are simply collections of components. As only one
  1392. +form can be active (or running) at a time, every component which the user
  1393. +should be able to access must be on the running form (or on a subform of the
  1394. +running form). A form is itself a component, which means forms are stored in
  1395. +newtComponent data structures.
  1396. +newtComponent newtForm(newtComponent vertBar, const char * help, int flags);
  1397. +
  1398. +To create a form, call newtForm(). The first parameter is a vertical
  1399. +scrollbar which should be associated with the form. For now, that should
  1400. +always be NULL (we'll discuss how to create scrolling forms later in this
  1401. +section). The second parameter, help, is currently unused and should always
  1402. +be NULL. The flags is normally 0, and other values it can take will be
  1403. +discussed later. Now that we've waved away the complexity of this function,
  1404. +creating a form boils down to simply:
  1405. +
  1406. +newtComponent myForm;
  1407. +
  1408. +myForm = newtForm(NULL, NULL, 0);
  1409. +
  1410. + After a form is created, components need to be added to it --- after
  1411. + all, an empty form isn't terribly useful. There are two functions
  1412. + which add components to a form.
  1413. +void newtFormAddComponent(newtComponent form, newtComponent co);
  1414. +void newtFormAddComponents(newtComponent form, ...);
  1415. +
  1416. + The first function, newtFormAddComponent(), adds a single component to
  1417. + the form which is passed as the first parameter. The second function
  1418. + is simply a convenience function. After passing the form to
  1419. + newtFormAddComponents(), an arbitrary number of components is then
  1420. + passed, followed by NULL. Every component passed is added to the form.
  1421. + Once a form has been created and components have been added to it,
  1422. + it's time to run the form.
  1423. +newtComponent newtRunForm(newtComponent form);
  1424. +
  1425. + This function runs the form passed to it, and returns the component
  1426. + which caused the form to stop running. For now, we'll ignore the
  1427. + return value completely. Notice that this function doesn't fit in with
  1428. + newt's normal naming convention. It is an older interface which will
  1429. + not work for all forms. It was left in newt only for legacy
  1430. + applications. It is a simpler interface than the new newtFormRun()
  1431. + though, and is still used quite often as a result. When an application
  1432. + is done with a form, it destroys the form and all of the components
  1433. + the form contains.
  1434. +void newtFormDestroy(newtComponent form);
  1435. +
  1436. + This function frees the memory resources used by the form and all of
  1437. + the components which have been added to the form (including those
  1438. + components which are on subforms). Once a form has been destroyed,
  1439. + none of the form's components can be used.
  1440. + _________________________________________________________________
  1441. +
  1442. +4.2. Components
  1443. +
  1444. +Non-form components are the most important user-interface component for
  1445. +users. They determine how users interact with newt and how information is
  1446. +presented to them.
  1447. + _________________________________________________________________
  1448. +
  1449. +4.3. General Component Manipulation
  1450. +
  1451. +There are a couple of functions which work on more then one type of
  1452. +components. The description of each component indicates which (if any) of
  1453. +these functions are valid for that particular component.
  1454. +typedef void (*newtCallback)(newtComponent, void *);
  1455. +
  1456. +void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
  1457. +void newtComponentTakesFocus(newtComponent co, int val);
  1458. +
  1459. +The first registers a callback function for that component. A callback
  1460. +function is a function the application provides which newt calls for a
  1461. +particular component. Exactly when (if ever) the callback is invoked depends
  1462. +on the type of component the callback is attached to, and will be discussed
  1463. +for the components which support callbacks. newtComponentTakesFocus() works
  1464. +on all components. It allows the application to change which components the
  1465. +user is allowed to select as the current component, and hence provide input
  1466. +to. Components which do not take focus are skipped over during form
  1467. +traversal, but they are displayed on the terminal. Some components should
  1468. +never be set to take focus, such as those which display static text.
  1469. + _________________________________________________________________
  1470. +
  1471. +4.4. Buttons
  1472. +
  1473. +Nearly all forms contain at least one button. Newt buttons come in two
  1474. +flavors, full buttons and compact buttons. Full buttons take up quit a bit
  1475. +of screen space, but look much better then the single-row compact buttons.
  1476. +Other then their size, both button styles behave identically. Different
  1477. +functions are used to create the two types of buttons.
  1478. +newtComponent newtButton(int left, int top, const char * text);
  1479. +newtComponent newtCompactButton(int left, int top, const char * text);
  1480. +
  1481. +Both functions take identical parameters. The first two parameters are the
  1482. +location of the upper left corner of the button, and the final parameter is
  1483. +the text which should be displayed in the button (such as ``Ok'' or
  1484. +``Cancel'').
  1485. + _________________________________________________________________
  1486. +
  1487. +4.4.1. Button Example
  1488. +
  1489. +Here is a simple example of both full and compact buttons. It also
  1490. +illustrates opening and closing windows, as well a simple form.
  1491. +#include <newt.h>
  1492. +#include <stdlib.h>
  1493. +
  1494. +void main(void) {
  1495. + newtComponent form, b1, b2;
  1496. + newtInit();
  1497. + newtCls();
  1498. +
  1499. + newtOpenWindow(10, 5, 40, 6, "Button Sample");
  1500. +
  1501. + b1 = newtButton(10, 1, "Ok");
  1502. + b2 = newtCompactButton(22, 2, "Cancel");
  1503. + form = newtForm(NULL, NULL, 0);
  1504. + newtFormAddComponents(form, b1, b2, NULL);
  1505. +
  1506. + newtRunForm(form);
  1507. +
  1508. + newtFormDestroy(form);
  1509. + newtFinished();
  1510. +}
  1511. + _________________________________________________________________
  1512. +
  1513. +4.5. Labels
  1514. +
  1515. +Labels are newt's simplest component. They display some given text and don't
  1516. +allow any user input.
  1517. +newtComponent newtLabel(int left, int top, const char * text);
  1518. +void newtLabelSetText(newtComponent co, const char * text);
  1519. +
  1520. +Creating a label is just like creating a button; just pass the location of
  1521. +the label and the text it should display. Unlike buttons, labels do let the
  1522. +application change the text in the label with newtLabelSetText. When the
  1523. +label's text is changed, the label automatically redraws itself. It does not
  1524. +clear out any old text which may be leftover from the previous time is was
  1525. +displayed, however, so be sure that the new text is at least as long as the
  1526. +old text.
  1527. + _________________________________________________________________
  1528. +
  1529. +4.6. Entry Boxes
  1530. +
  1531. +Entry boxes allow the user to enter a text string into the form which the
  1532. +application can later retrieve.
  1533. +typedef int (*newtEntryFilter)(newtComponent entry, void * data, int ch,
  1534. + int cursor);
  1535. +
  1536. +newtComponent newtEntry(int left, int top, const char * initialValue, int width
  1537. +,
  1538. + char ** resultPtr, int flags);
  1539. +void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
  1540. +char * newtEntryGetValue(newtComponent co);
  1541. +void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data);
  1542. +
  1543. + newtEntry() creates a new entry box. After the location of the entry
  1544. + box, the initial value for the entry box is passed, which may be NULL
  1545. + if the box should start off empty. Next, the width of the physical box
  1546. + is given. This width may or may not limit the length of the string the
  1547. + user is allowed to enter; that depends on the flags. The resultPtr
  1548. + must be the address of a char *. Until the entry box is destroyed by
  1549. + newtFormDestroy(), that char * will point to the current value of the
  1550. + entry box. It's important that applications make a copy of that value
  1551. + before destroying the form if they need to use it later. The resultPtr
  1552. + may be NULL, in which case the user must use the newtEntryGetValue()
  1553. + function to get the value of the entry box. Entry boxes support a
  1554. + number of flags:
  1555. +
  1556. + NEWT_ENTRY_SCROLL
  1557. + If this flag is not specified, the user cannot enter text into
  1558. + the entry box which is wider then the entry box itself. This
  1559. + flag removes this limitation, and lets the user enter data of
  1560. + an arbitrary length.
  1561. +
  1562. + NEWT_FLAG_HIDDEN
  1563. + If this flag is specified, the value of the entry box is not
  1564. + displayed. This is useful when the application needs to read a
  1565. + password, for example.
  1566. +
  1567. + NEWT_FLAG_RETURNEXIT
  1568. + When this flag is given, the entry box will cause the form to
  1569. + stop running if the user pressed return inside of the entry
  1570. + box. This can provide a nice shortcut for users.
  1571. +
  1572. + After an entry box has been created, its contents can be set by
  1573. + newtEntrySet(). After the entry box itself, the new string to place in
  1574. + the entry box is passed. The final parameter, cursorAtEnd, controls
  1575. + where the cursor will appear in the entry box. If it is zero, the
  1576. + cursor remains at its present location; a nonzero value moves the
  1577. + cursor to the end of the entry box's new value. While the simplest way
  1578. + to find the value of an entry box is by using a resultPtr, doing so
  1579. + complicates some applications. newtEntryGetValue() returns a pointer
  1580. + to the string which the entry box currently contains. The returned
  1581. + pointer may not be valid once the user further modifies the entry box,
  1582. + and will not be valid after the entry box has been destroyed, so be
  1583. + sure to save its value in a more permanent location if necessary.
  1584. + Entry boxes allow applications to filter characters as they are
  1585. + entered. This allows programs to ignore characters which are invalid
  1586. + (such as entering a ^ in the middle of a phone number) and provide
  1587. + intelligent aids to the user (such as automatically adding a '.' after
  1588. + the user has typed in the first three numbers in an IP address). When
  1589. + a filter is registered through newtEntrySetFilter(), both the filter
  1590. + itself and an arbitrary void *, which passed to the filter whenever it
  1591. + is invoked, are recorded. This data pointer isn't used for any other
  1592. + purpose, and may be NULL. Entry filters take four arguments.
  1593. +
  1594. + 1. The entry box which had data entered into it
  1595. + 2. The data pointer which was registered along with the filter
  1596. + 3. The new character which newt is considering inserting into the
  1597. + entry box
  1598. + 4. The current cursor position (0 is the leftmost position)
  1599. +
  1600. + The filter returns 0 if the character should be ignored, or the value
  1601. + of the character which should be inserted into the entry box. Filter
  1602. + functions which want to do complex manipulations of the string should
  1603. + use newtEntrySet() to update the entry box and then return 0 to
  1604. + prevent the new character from being inserted. When a callback is
  1605. + attached to a entry box, the callback is invoked whenever the user
  1606. + moves off of the callback and on to another component. Here is a
  1607. + sample program which illustrates the use of both labels and entry
  1608. + boxes.
  1609. +#include <newt.h>
  1610. +#include <stdlib.h>
  1611. +#include <stdio.h>
  1612. +
  1613. +void main(void) {
  1614. + newtComponent form, label, entry, button;
  1615. + char * entryValue;
  1616. +
  1617. + newtInit();
  1618. + newtCls();
  1619. +
  1620. + newtOpenWindow(10, 5, 40, 8, "Entry and Label Sample");
  1621. +
  1622. + label = newtLabel(1, 1, "Enter a string");
  1623. + entry = newtEntry(16, 1, "sample", 20, &entryValue,
  1624. + NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
  1625. + button = newtButton(17, 3, "Ok");
  1626. + form = newtForm(NULL, NULL, 0);
  1627. + newtFormAddComponents(form, label, entry, button, NULL);
  1628. +
  1629. + newtRunForm(form);
  1630. +
  1631. + newtFinished();
  1632. +
  1633. + printf("Final string was: %s\n", entryValue);
  1634. +
  1635. + /* We cannot destroy the form until after we've used the value
  1636. + from the entry widget. */
  1637. + newtFormDestroy(form);
  1638. +}
  1639. + _________________________________________________________________
  1640. +
  1641. +4.7. Checkboxes
  1642. +
  1643. +Most widget sets include checkboxes which toggle between two value (checked
  1644. +or not checked). Newt checkboxes are more flexible. When the user presses
  1645. +the space bar on a checkbox, the checkbox's value changes to the next value
  1646. +in an arbitrary sequence (which wraps). Most checkboxes have two items in
  1647. +that sequence, checked or not, but newt allows an arbitrary number of value.
  1648. +This is useful when the user must pick from a limited number of choices.
  1649. +Each item in the sequence is a single character, and the sequence itself is
  1650. +represented as a string. The checkbox components displays the character
  1651. +which currently represents its value the left of a text label, and returns
  1652. +the same character as its current value. The default sequence for checkboxes
  1653. +is " *", with ' ' indicating false and '*' true.
  1654. +newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
  1655. + const char * seq, char * result);
  1656. +char newtCheckboxGetValue(newtComponent co);
  1657. +
  1658. + Like most components, the position of the checkbox is the first thing
  1659. + passed to the function that creates one. The next parameter, text, is
  1660. + the text which is displayed to the right of the area which is checked.
  1661. + The defValue is the initial value for the checkbox, and seq is the
  1662. + sequence which the checkbox should go through (defValue must be in
  1663. + seq. seq may be NULL, in which case " *" is used. The final parameter,
  1664. + result, should point to a character which the checkbox should always
  1665. + record its current value in. If result is NULL, newtCheckboxGetValue()
  1666. + must be used to get the current value of the checkbox.
  1667. + newtCheckboxGetValue() is straightforward, returning the character in
  1668. + the sequence which indicates the current value of the checkbox If a
  1669. + callback is attached to a checkbox, the callback is invoked whenever
  1670. + the checkbox responds to a user's keystroke. The entry box may respond
  1671. + by taking focus or giving up focus, as well as by changing its current
  1672. + value.
  1673. + _________________________________________________________________
  1674. +
  1675. +4.8. Radio Buttons
  1676. +
  1677. +Radio buttons look very similar to checkboxes. The key difference between
  1678. +the two is that radio buttons are grouped into sets, and exactly one radio
  1679. +button in that set may be turned on. If another radio button is selected,
  1680. +the button which was selected is automatically deselected.
  1681. +newtComponent newtRadiobutton(int left, int top, const char * text,
  1682. + int isDefault, newtComponent prevButton);
  1683. +newtComponent newtRadioGetCurrent(newtComponent setMember);
  1684. +
  1685. +Each radio button is created by calling newtRadiobutton(). After the
  1686. +position of the radio button, the text displayed with the button is passed.
  1687. +isDefault should be nonzero if the radio button is to be turned on by
  1688. +default. The final parameter, prevMember is used to group radio buttons into
  1689. +sets. If prevMember is NULL, the radio button is assigned to a new set. If
  1690. +the radio button should belong to a preexisting set, prevMember must be the
  1691. +previous radio button added to that set. Discovering which radio button in a
  1692. +set is currently selected necessitates newtRadioGetCurrent(). It may be
  1693. +passed any radio button in the set you're interested in, and it returns the
  1694. +radio button component currently selected. Here is an example of both
  1695. +checkboxes and radio buttons.
  1696. +
  1697. +#include <newt.h>
  1698. +#include <stdlib.h>
  1699. +#include <stdio.h>
  1700. +
  1701. +void main(void) {
  1702. + newtComponent form, checkbox, rb[3], button;
  1703. + char cbValue;
  1704. + int i;
  1705. +
  1706. + newtInit();
  1707. + newtCls();
  1708. +
  1709. + newtOpenWindow(10, 5, 40, 11, "Checkboxes and Radio buttons");
  1710. +
  1711. + checkbox = newtCheckbox(1, 1, "A checkbox", ' ', " *X", &cbValue);
  1712. +
  1713. + rb[0] = newtRadiobutton(1, 3, "Choice 1", 1, NULL);
  1714. + rb[1] = newtRadiobutton(1, 4, "Choice 2", 0, rb[0]);
  1715. + rb[2] = newtRadiobutton(1, 5, "Choice 3", 0, rb[1]);
  1716. +
  1717. + button = newtButton(1, 7, "Ok");
  1718. +
  1719. + form = newtForm(NULL, NULL, 0);
  1720. + newtFormAddComponent(form, checkbox);
  1721. + for (i = 0; i < 3; i++)
  1722. + newtFormAddComponent(form, rb[i]);
  1723. + newtFormAddComponent(form, button);
  1724. +
  1725. + newtRunForm(form);
  1726. + newtFinished();
  1727. +
  1728. + /* We cannot destroy the form until after we've found the current
  1729. + radio button */
  1730. +
  1731. + for (i = 0; i < 3; i++)
  1732. + if (newtRadioGetCurrent(rb[0]) == rb[i])
  1733. + printf("radio button picked: %d\n", i);
  1734. + newtFormDestroy(form);
  1735. +
  1736. + /* But the checkbox's value is stored locally */
  1737. + printf("checkbox value: '%c'\n", cbValue);
  1738. +}
  1739. + _________________________________________________________________
  1740. +
  1741. +4.9. Scales
  1742. +
  1743. +It's common for programs to need to display a progress meter on the terminal
  1744. +while it performs some length operation (it behaves like an anesthetic). The
  1745. +scale component is a simple way of doing this. It displays a horizontal bar
  1746. +graph which the application can update as the operation continues.
  1747. +newtComponent newtScale(int left, int top, int width, long long fullValue);
  1748. +void newtScaleSet(newtComponent co, unsigned long long amount);
  1749. +
  1750. +When the scale is created with newtScale, it is given the width of the scale
  1751. +itself as well as the value which means that the scale should be drawn as
  1752. +full. When the position of the scale is set with newtScaleSet(), the scale
  1753. +is told the amount of the scale which should be filled in relative to the
  1754. +fullAmount. For example, if the application is copying a file, fullValue
  1755. +could be the number of bytes in the file, and when the scale is updated
  1756. +newtScaleSet() would be passed the number of bytes which have been copied so
  1757. +far.
  1758. + _________________________________________________________________
  1759. +
  1760. +4.10. Textboxes
  1761. +
  1762. +Textboxes display a block of text on the terminal, and is appropriate for
  1763. +display large amounts of text.
  1764. +newtComponent newtTextbox(int left, int top, int width, int height, int flags);
  1765. +void newtTextboxSetText(newtComponent co, const char * text);
  1766. +
  1767. +newtTextbox() creates a new textbox, but does not fill it with data. The
  1768. +function is passed the location for the textbox on the screen, the width and
  1769. +height of the textbox (in characters), and zero or more of the following
  1770. +flags:
  1771. +
  1772. + NEWT_FLAG_WRAP
  1773. + All text in the textbox should be wrapped to fit the width of
  1774. + the textbox. If this flag is not specified, each newline
  1775. + delimited line in the text is truncated if it is too long to
  1776. + fit. When newt wraps text, it tries not to break lines on
  1777. + spaces or tabs. Literal newline characters are respected, and
  1778. + may be used to force line breaks.
  1779. +
  1780. + NEWT_FLAG_SCROLL
  1781. + The text box should be scrollable. When this option is
  1782. + used, the scrollbar which is added increases the width of
  1783. + the area used by the textbox by 2 characters; that is the
  1784. + textbox is 2 characters wider then the width passed to
  1785. + newtTextbox().
  1786. +
  1787. + After a textbox has been created, text may be added to it
  1788. + through newtTextboxSetText(), which takes only the textbox and
  1789. + the new text as parameters. If the textbox already contained
  1790. + text, that text is replaced by the new text. The textbox makes
  1791. + its own copy of the passed text, so these is no need to keep
  1792. + the original around unless it's convenient.
  1793. + _________________________________________________________________
  1794. +
  1795. +4.10.1. Reflowing Text
  1796. +
  1797. +When applications need to display large amounts of text, it's common not to
  1798. +know exactly where the linebreaks should go. While textboxes are quite
  1799. +willing to scroll the text, the programmer still must know what width the
  1800. +text will look ``best'' at (where ``best'' means most exactly rectangular;
  1801. +no lines much shorter or much longer then the rest). This common is
  1802. +especially prevalent in internationalized programs, which need to make a
  1803. +wide variety of message string look god on a screen. To help with this, newt
  1804. +provides routines to reformat text to look good. It tries different widths
  1805. +to figure out which one will look ``best'' to the user. As these commons are
  1806. +almost always used to format text for textbox components, newt makes it easy
  1807. +to construct a textbox with reflowed text.
  1808. +char * newtReflowText(char * text, int width, int flexDown, int flexUp,
  1809. + int * actualWidth, int * actualHeight);
  1810. +newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
  1811. + int flexDown, int flexUp, int flags);
  1812. +int newtTextboxGetNumLines(newtComponent co);
  1813. +
  1814. + newtReflowText() reflows the text to a target width of width. The
  1815. + actual width of the longest line in the returned string is between
  1816. + width - flexDown and width + flexUp; the actual maximum line length is
  1817. + chosen to make the displayed check look rectangular. The ints pointed
  1818. + to by actualWidth and actualHeight are set to the width of the longest
  1819. + line and the number of lines in in the returned text, respectively.
  1820. + Either one may be NULL. The return value points to the reflowed text,
  1821. + and is allocated through malloc(). When the reflowed text is being
  1822. + placed in a textbox it may be easier to use newtTextboxReflowed(),
  1823. + which creates a textbox, reflows the text, and places the reflowed
  1824. + text in the listbox. It's parameters consist of the position of the
  1825. + final textbox, the width and flex values for the text (which are
  1826. + identical to the parameters passed to newtReflowText(), and the flags
  1827. + for the textbox (which are the same as the flags for newtTextbox().
  1828. + This function does not let you limit the height of the textbox,
  1829. + however, making limiting it's use to constructing textboxes which
  1830. + don't need to scroll. To find out how tall the textbox created by
  1831. + newtTextboxReflowed() is, use newtTextboxGetNumLines(), which returns
  1832. + the number of lines in the textbox. For textboxes created by
  1833. + newtTextboxReflowed(), this is always the same as the height of the
  1834. + textbox. Here's a simple program which uses a textbox to display a
  1835. + message.
  1836. +#include <newt.h>
  1837. +#include <stdlib.h>
  1838. +
  1839. +char message[] = "This is a pretty long message. It will be displayed "
  1840. + "in a newt textbox, and illustrates how to construct "
  1841. + "a textbox from arbitrary text which may not have "
  1842. + "very good line breaks.\n\n"
  1843. + "Notice how literal \\n characters are respected, and "
  1844. + "may be used to force line breaks and blank lines.";
  1845. +
  1846. +void main(void) {
  1847. + newtComponent form, text, button;
  1848. +
  1849. + newtInit();
  1850. + newtCls();
  1851. +
  1852. + text = newtTextboxReflowed(1, 1, message, 30, 5, 5, 0);
  1853. + button = newtButton(12, newtTextboxGetNumLines(text) + 2, "Ok");
  1854. +
  1855. + newtOpenWindow(10, 5, 37,
  1856. + newtTextboxGetNumLines(text) + 7, "Textboxes");
  1857. +
  1858. + form = newtForm(NULL, NULL, 0);
  1859. + newtFormAddComponents(form, text, button, NULL);
  1860. +
  1861. + newtRunForm(form);
  1862. + newtFormDestroy(form);
  1863. + newtFinished();
  1864. +}
  1865. + _________________________________________________________________
  1866. +
  1867. +4.11. Scrollbars
  1868. +
  1869. +Scrollbars (which, currently, are always vertical in newt), may be attached
  1870. +to forms to let them contain more data then they have space for. While the
  1871. +actual process of making scrolling forms is discussed at the end of this
  1872. +section, we'll go ahead and introduce scrollbars now so you'll be ready.
  1873. +newtComponent newtVerticalScrollbar(int left, int top, int height,
  1874. + int normalColorset, int thumbColorset);
  1875. +
  1876. +When a scrollbar is created, it is given a position on the screen, a height,
  1877. +and two colors. The first color is the color used for drawing the scrollbar,
  1878. +and the second color is used for drawing the thumb. This is the only place
  1879. +in newt where an application specifically sets colors for a component. It's
  1880. +done here to let the colors a scrollbar use match the colors of the
  1881. +component the scrollbar is mated too. When a scrollbar is being used with a
  1882. +form, normalColorset is often NEWT_COLORSET_WINDOW and thumbColorset
  1883. +NEWT_COLORSET_ACTCHECKBOX. Of course, feel free to peruse <newt.h> and pick
  1884. +your own colors. As the scrollbar is normally updated by the component it is
  1885. +mated with, there is no public interface for moving the thumb.
  1886. + _________________________________________________________________
  1887. +
  1888. +4.12. Listboxes
  1889. +
  1890. +Listboxes are the most complicated components newt provides. They can allow
  1891. +a single selection or multiple selection, and are easy to update.
  1892. +Unfortunately, their API is also the least consistent of newt's components.
  1893. +Each entry in a listbox is a ordered pair of the text which should be
  1894. +displayed for that item and a key, which is a void * that uniquely
  1895. +identifies that listbox item. Many applications pass integers in as keys,
  1896. +but using arbitrary pointers makes many applications significantly easier to
  1897. +code.
  1898. + _________________________________________________________________
  1899. +
  1900. +4.12.1. Basic Listboxes
  1901. +
  1902. +Let's start off by looking at the most important listbox functions.
  1903. +newtComponent newtListbox(int left, int top, int height, int flags);
  1904. +int newtListboxAppendEntry(newtComponent co, const char * text,
  1905. + const void * data);
  1906. +void * newtListboxGetCurrent(newtComponent co);
  1907. +void newtListboxSetWidth(newtComponent co, int width);
  1908. +void newtListboxSetCurrent(newtComponent co, int num);
  1909. +void newtListboxSetCurrentByKey(newtComponent co, void * key);
  1910. +
  1911. + A listbox is created at a certain position and a given height. The
  1912. + height is used for two things. First of all, it is the minimum height
  1913. + the listbox will use. If there are less items in the listbox then the
  1914. + height, suggests the listbox will still take up that minimum amount of
  1915. + space. Secondly, if the listbox is set to be scrollable (by setting
  1916. + the NEWT_FLAG_SCROLL flag, the height is also the maximum height of
  1917. + the listbox. If the listbox may not scroll, it increases its height to
  1918. + display all of its items. The following flags may be used when
  1919. + creating a listbox:
  1920. +
  1921. + NEWT_FLAG_SCROLL
  1922. + The listbox should scroll to display all of the items it
  1923. + contains.
  1924. +
  1925. + NEWT_FLAG_RETURNEXIT
  1926. + When the user presses return on an item in the list, the form
  1927. + should return.
  1928. +
  1929. + NEWT_FLAG_BORDER
  1930. + A frame is drawn around the listbox, which can make it easier
  1931. + to see which listbox has the focus when a form contains
  1932. + multiple listboxes.
  1933. +
  1934. + NEWT_FLAG_MULTIPLE
  1935. + By default, a listbox only lets the user select one item in the
  1936. + list at a time. When this flag is specified, they may select
  1937. + multiple items from the list.
  1938. +
  1939. + Once a listbox has been created, items are added to it by invoking
  1940. + newtListboxAppendEntry(), which adds new items to the end of the list.
  1941. + In addition to the listbox component, newtListboxAppendEntry() needs
  1942. + both elements of the (text, key) ordered pair. For lists which only
  1943. + allow a single selection, newtListboxGetCurrent() should be used to
  1944. + find out which listbox item is currently selected. It returns the key
  1945. + of the currently selected item. Normally, a listbox is as wide as its
  1946. + widest element, plus space for a scrollbar if the listbox is supposed
  1947. + to have one. To make the listbox any larger then that, use
  1948. + newtListboxSetWidth(), which overrides the natural list of the
  1949. + listbox. Once the width has been set, it's fixed. The listbox will no
  1950. + longer grow to accommodate new entries, so bad things may happen! An
  1951. + application can change the current position of the listbox (where the
  1952. + selection bar is displayed) by calling newtListboxSetCurrent() or
  1953. + newtListboxSetCurrentByKey(). The first sets the current position to
  1954. + the entry number which is passed as the second argument, with 0
  1955. + indicating the first entry. newtListboxSetCurrentByKey() sets the
  1956. + current position to the entry whose key is passed into the function.
  1957. + _________________________________________________________________
  1958. +
  1959. +4.12.2. Manipulating Listbox Contents
  1960. +
  1961. +While the contents of many listboxes never need to change, some applications
  1962. +need to change the contents of listboxes regularly. Newt includes complete
  1963. +support for updating listboxes. These new functions are in addition to
  1964. +newtListboxAppendEntry(), which was already discussed.
  1965. +void newtListboxSetEntry(newtComponent co, void * key, const char * text);
  1966. +int newtListboxInsertEntry(newtComponent co, const char * text,
  1967. + const void * data, void * key);
  1968. +int newtListboxDeleteEntry(newtComponent co, void * key);
  1969. +void newtListboxClear(newtComponent co);
  1970. +
  1971. + The first of these, newtListboxSetEntry(), updates the text for a key
  1972. + which is already in the listbox. The key specifies which listbox entry
  1973. + should be modified, and text becomes the new text for that entry in
  1974. + the listbox. newtListboxInsertEntry() inserts a new listbox entry
  1975. + after an already existing entry, which is specified by the key
  1976. + parameter. The text and data parameters specify the new entry which
  1977. + should be added. Already-existing entries are removed from a listbox
  1978. + with newtListboxDeleteEntry(). It removes the listbox entry with the
  1979. + specified key. If you want to remove all of the entries from a
  1980. + listbox, use newtListboxClear().
  1981. + _________________________________________________________________
  1982. +
  1983. +4.12.3. Multiple Selections
  1984. +
  1985. +When a listbox is created with NEWT_FLAG_MULTIPLE, the user can select
  1986. +multiple items from the list. When this option is used, a different set of
  1987. +functions must be used to manipulate the listbox selection.
  1988. +void newtListboxClearSelection(newtComponent co);
  1989. +void **newtListboxGetSelection(newtComponent co, int *numitems);
  1990. +void newtListboxSelectItem(newtComponent co, const void * key,
  1991. + enum newtFlagsSense sense);
  1992. +
  1993. +The simplest of these is newtListboxClearSelection(), which deselects all of
  1994. +the items in the list (listboxes which allow multiple selections also allow
  1995. +zero selections). newtListboxGetSelection() returns a pointer to an array
  1996. +which contains the keys for all of the items in the listbox currently
  1997. +selected. The int pointed to by numitems is set to the number of items
  1998. +currently selected (and hence the number of items in the returned array).
  1999. +The returned array is dynamically allocated, and must be released through
  2000. +free(). newtListboxSelectItem() lets the program select and deselect
  2001. +specific listbox entries. The key of the listbox entry is being affected is
  2002. +passed, and sense is one of NEWT_FLAGS_RESET, which deselects the entry,
  2003. +NEWT_FLAGS_SET, which selects the entry, or NEWT_FLAGS_TOGGLE, which
  2004. +reverses the current selection status.
  2005. + _________________________________________________________________
  2006. +
  2007. +4.13. Advanced Forms
  2008. +
  2009. +Forms, which tie components together, are quite important in the world of
  2010. +newt. While we've already discussed the basics of forms, we've omitted many
  2011. +of the details.
  2012. + _________________________________________________________________
  2013. +
  2014. +4.13.1. Exiting From Forms
  2015. +
  2016. +Forms return control to the application for a number of reasons:
  2017. +
  2018. + * A component can force the form to exit. Buttons do this whenever
  2019. + they are pushed, and other components exit when
  2020. + NEWT_FLAG_RETURNEXIT has been specified.
  2021. + * Applications can setup hot keys which cause the form to exit when
  2022. + they are pressed.
  2023. + * Newt can exit when file descriptors are ready to be read or ready
  2024. + to be written to.
  2025. +
  2026. +By default, newt forms exit when the F12 key is pressed (F12 is setup as a
  2027. +hot key by default). Newt applications should treat F12 as an ``Ok'' button.
  2028. +If applications don't want F12 to exit the form, they can specify
  2029. +NEWT_FLAG_NOF12 as flag when creating the form with newtForm.
  2030. +
  2031. +void newtFormAddHotKey(newtComponent co, int key);
  2032. +void newtFormWatchFd(newtComponent form, int fd, int fdFlags);
  2033. +void newtDrawForm(newtComponent form);
  2034. +newtComponent newtFormGetCurrent(newtComponent co);
  2035. +void newtFormSetCurrent(newtComponent co, newtComponent subco);
  2036. +void newtFormRun(newtComponent co, struct newtExitStruct * es);
  2037. +newtComponent newtForm(newtComponent vertBar, const char * help, int flags);
  2038. +void newtFormSetBackground(newtComponent co, int color);
  2039. +void newtFormSetHeight(newtComponent co, int height);
  2040. +void newtFormSetWidth(newtComponent co, int width);
  2041. Index: whiptail.1
  2042. --- whiptail.1.orig 2003-12-14 12:02:42.000000000 +0100
  2043. +++ whiptail.1 2003-12-14 12:02:42.000000000 +0100
  2044. @@ -0,0 +1,242 @@
  2045. +.TH WHIPTAIL 1 "10 January 1998" "Whiptail Version 0.21"
  2046. +.SH NAME
  2047. +whiptail \- display dialog boxes from shell scripts
  2048. +.SH SYNOPSIS
  2049. +.B whiptail
  2050. +[
  2051. +.B \-\-title
  2052. +.I title
  2053. +]
  2054. +[
  2055. +.B \-\-backtitle
  2056. +.I backtitle
  2057. +]
  2058. +[
  2059. +.B \-\-clear
  2060. +]
  2061. +[
  2062. +.B \-\-defaultno
  2063. +]
  2064. +[
  2065. +.B \-\-fb
  2066. +]
  2067. +[
  2068. +.B \-\-nocancel
  2069. +]
  2070. +[
  2071. +.B \-\-noitem
  2072. +]
  2073. +[
  2074. +.B \-\-separate\-output
  2075. +]
  2076. +[
  2077. +.B \-\-scrolltext
  2078. +]
  2079. +.B box-options
  2080. +.SH DESCRIPTION
  2081. +.B whiptail
  2082. +is a program that will let you to present a variety of questions or
  2083. +display messages using dialog boxes from a shell script. Currently,
  2084. +these types of dialog boxes are implemented:
  2085. +.LP
  2086. +.BR yes/no " box," " menu" " box," " input" " box,"
  2087. +.BR message " box," " text" " box," " info" " box,"
  2088. +.BR checklist " box," " radiolist" " box" " gauge" " box, and"
  2089. +.BR password " box."
  2090. +.SH OPTIONS
  2091. +.TP
  2092. +.B \-\-clear
  2093. +The screen will be cleared to the
  2094. +.BR "screen attribute" " on exit."
  2095. +This doesn't work in an xterm (and descendants) if alternate screen
  2096. +switching is enabled, because in that case slang writes to (and clears)
  2097. +an alternate screen.
  2098. +.TP
  2099. +.B \-\-defaultno
  2100. +The dialog box will open with the cursor over the
  2101. +.BR No " button."
  2102. +.TP
  2103. +.B \-\-fb
  2104. +Use full buttons. (By default,
  2105. +.B whiptail
  2106. +uses compact buttons).
  2107. +.TP
  2108. +.B \-\-nocancel
  2109. +The dialog box won't have a
  2110. +.BR Cancel " button".
  2111. +.TP
  2112. +.B \-\-noitem
  2113. +The menu, checklist and radiolist widgets will display tags only, not
  2114. +the item strings.
  2115. +.TP
  2116. +.BI \-\-separate\-output
  2117. +For checklist widgets, output result one line at a time, with no
  2118. +quoting. This facilitates parsing by another program.
  2119. +.TP
  2120. +.BI \-\-title " title"
  2121. +Specifies a
  2122. +.I title
  2123. +string to be displayed at the top of the dialog box.
  2124. +.TP
  2125. +.BI \-\-backtitle " backtitle"
  2126. +Specifies a
  2127. +.I backtitle
  2128. +string to be displayed on the backdrop, at the top of the screen.
  2129. +.TP
  2130. +.BI \-\-scrolltext
  2131. +Force the display of a vertical scrollbar.
  2132. +.TP
  2133. +.B Box Options
  2134. +.TP
  2135. +.BI \-\-yesno " text height width"
  2136. +.RB A " yes/no" " dialog box of size"
  2137. +.I height
  2138. +rows by
  2139. +.I width
  2140. +columns will be displayed. The string specified by
  2141. +.I text
  2142. +is displayed inside the dialog box. If this string is too long to be fitted
  2143. +in one line, it will be automatically divided into multiple lines at
  2144. +appropriate places. The
  2145. +.I text
  2146. +string may also contain the sub-string
  2147. +.I
  2148. +"\en"
  2149. +or newline characters
  2150. +.I `\en'
  2151. +to control line breaking explicitly. This dialog box is useful for
  2152. +asking questions that require the user to answer either yes or no.
  2153. +.RB "The dialog box has a" " Yes" " button and a " No
  2154. +button, in which the user can switch between by pressing the
  2155. +.IR TAB " key."
  2156. +.TP
  2157. +.BI \-\-msgbox " text height width"
  2158. +.RB A " message" " box is very similar to a" " yes/no" " box."
  2159. +The only difference between a
  2160. +.B message
  2161. +box and a
  2162. +.B yes/no
  2163. +box is that a
  2164. +.B message
  2165. +box has only a single
  2166. +.B OK
  2167. +button. You can use this dialog box to display any message you like.
  2168. +After reading the message, the user can press the
  2169. +.I ENTER
  2170. +key so that
  2171. +.B whiptail
  2172. +will exit and the calling shell script can continue its operation.
  2173. +.TP
  2174. +.BI \-\-infobox " text height width"
  2175. +.RB An " info" " box is basically a" " message" " box."
  2176. +However, in this case,
  2177. +.B whiptail
  2178. +will exit immediately after displaying the message to the user. The
  2179. +screen is not cleared when
  2180. +.B whiptail
  2181. +exits, so that the message will remain on the screen until the calling
  2182. +shell script clears it later. This is useful when you want to inform
  2183. +the user that some operations are carrying on that may require some
  2184. +time to finish.
  2185. +.TP
  2186. +.BI \-\-inputbox " text height width [init]"
  2187. +.RB "An " input " box is useful when you want to ask questions that"
  2188. +require the user to input a string as the answer. If init is supplied
  2189. +it is used to initialize the input string.
  2190. +When inputing the
  2191. +string, the
  2192. +.I BACKSPACE
  2193. +key can be used to correct typing errors. If the input string is longer than
  2194. +can be fitted in the dialog box, the input field will be scrolled. On exit,
  2195. +the input string will be printed on
  2196. +.IR stderr "."
  2197. +.TP
  2198. +.BI \-\-passwordbox " text height width [init]"
  2199. +.RB "A " password " box is similar to an input box, except the text the user"
  2200. +enters is not displayed. This is useful when prompting for passwords or other
  2201. +sensative information. Be aware that if anything is passed in "init", it
  2202. +will be visible in the system's process table to casual snoopers. Also, it
  2203. +is very confusing to the user to provide them with a default password they
  2204. +cannot see. For these reasons, using "init" is highly discouraged.
  2205. +.TP
  2206. +.BI \-\-textbox " file height width"
  2207. +.RB A " text" " box lets you display the contents of a text file in a"
  2208. +dialog box. It is like a simple text file viewer. The user can move
  2209. +through the file by using the
  2210. +.IR UP/DOWN ", " PGUP/PGDN
  2211. +.RI and " HOME/END" " keys available on most keyboards."
  2212. +If the lines are too long to be displayed in the box, the
  2213. +.I LEFT/RIGHT
  2214. +keys can be used to scroll the text region horizontally. For more
  2215. +convenience, forward and backward searching functions are also provided.
  2216. +.IP "\fB\-\-menu \fItext height width menu-height \fR[ \fItag item \fR] \fI..."
  2217. +As its name suggests, a
  2218. +.B menu
  2219. +box is a dialog box that can be used to present a list of choices in
  2220. +the form of a menu for the user to choose. Each menu entry consists of a
  2221. +.IR tag " string and an " item " string. The"
  2222. +.I tag
  2223. +gives the entry a name to distinguish it from the other entries in the
  2224. +menu. The
  2225. +.I item
  2226. +is a short description of the option that the entry represents. The
  2227. +user can move between the menu entries by pressing the
  2228. +.I UP/DOWN
  2229. +keys, the first letter of the
  2230. +.I tag
  2231. +as a hot-key, or the number keys
  2232. +.IR 1-9 ". There are"
  2233. +.I menu-height
  2234. +entries displayed in the menu at one time, but the menu will be
  2235. +scrolled if there are more entries than that. When
  2236. +.B whiptail
  2237. +exits, the
  2238. +.I tag
  2239. +of the chosen menu entry will be printed on
  2240. +.IR stderr "."
  2241. +.IP "\fB\-\-checklist \fItext height width list-height \fR[ \fItag item status \fR] \fI..."
  2242. +.RB "A " checklist " box is similar to a " menu " box in that there are"
  2243. +multiple entries presented in the form of a menu. Instead of choosing
  2244. +one entry among the entries, each entry can be turned on or off by the
  2245. +user. The initial on/off state of each entry is specified by
  2246. +.IR status "."
  2247. +On exit, a list of the
  2248. +.I tag
  2249. +strings of those entries that are turned on will be printed on
  2250. +.IR stderr "."
  2251. +
  2252. +.IP "\fB\-\-radiolist \fItext height width list-height \fR [ \fItag item status \fR] \fI..."
  2253. +.RB "A " radiolist " box is similar to a " menu " box. The only difference is"
  2254. +that you can indicate which entry is currently selected, by setting its
  2255. +.IR status " to " on "."
  2256. +
  2257. +.IP "\fB\-\-gauge \fItext height width percent\fR"
  2258. +.RB "A " gauge " box displays a meter along the bottom of the box.
  2259. +The meter indicates the percentage. New percentages are read from
  2260. +standard input, one integer per line. The meter is updated
  2261. +to reflect each new percentage. If stdin is XXX, then subsequent
  2262. +lines up to another XXX are used for a new prompt.
  2263. +The gauge exits when EOF is reached on stdin.
  2264. +
  2265. +.SH DIAGNOSTICS
  2266. +Exit status is 0 if
  2267. +.BR whiptail " is exited by pressing the " Yes " or " OK
  2268. +button, and 1 if the
  2269. +.BR No " or " Cancel
  2270. +button is pressed. Otherwise, if errors occur inside
  2271. +.B whiptail
  2272. +or
  2273. +.B whiptail
  2274. +is exited by pressing the
  2275. +.I ESC
  2276. +key, the exit status is -1.
  2277. +.SH AUTHOR
  2278. +Based on the man page for dialog(1) by:
  2279. +.LP
  2280. +Savio Lam (lam836@cs.cuhk.hk) - version 0.3
  2281. +.LP
  2282. +Stuart Herbert (S.Herbert@sheffield.ac.uk) - patch for version 0.4
  2283. +.LP
  2284. +Modifications for whiptail by:
  2285. +.LP
  2286. +Enrique Zanardi (ezanard@debian.org)
  2287. Index: whiptail.c
  2288. --- whiptail.c.orig 2003-01-03 21:54:45.000000000 +0100
  2289. +++ whiptail.c 2003-12-14 12:02:42.000000000 +0100
  2290. @@ -24,7 +24,7 @@
  2291. #define OPT_INFOBOX 1008
  2292. static void usage(void) {
  2293. - fprintf(stderr, "whiptail: bad parameters (see man dialog(1) for details)\n");
  2294. + fprintf(stderr, "whiptail: bad parameters (see man whiptail(1) for details)\n");
  2295. exit(1);
  2296. }