home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / termcap.zoo / termcap.1 next >
Encoding:
Text File  |  1990-04-04  |  49.1 KB  |  2,058 lines

  1. #!/bin/sh
  2. # This is tinfo, a shell archive (shar 3.10)
  3. # made 04/02/1990 08:46 UTC by ross@contact
  4. # Source directory /usr/spool/users/ross/src/tinfo/Shar
  5. #
  6. # existing files WILL be overwritten
  7. #
  8. # This is part 1 of a multipart archive                                    
  9. # do not concatenate these parts, unpack them in order with /bin/sh        
  10. #
  11. # This shar contains:
  12. # length  mode       name
  13. # ------ ---------- ------------------------------------------
  14. #   5721 -rw-r--r-- Makefile
  15. #    275 -rw-r--r-- TODO
  16. #   3708 -rw-r--r-- README
  17. #   4731 -rw-r--r-- README.doc
  18. #   6056 -rw-r--r-- INSTALL
  19. #    483 -rw-rw-r-- DECL
  20. #   1470 -rw-r--r-- fillterm.c
  21. #   4428 -rw-r--r-- findterm.c
  22. #    551 -rw-r--r-- tmatch.c
  23. #   1903 -rw-r--r-- terminfo.c
  24. #    318 -rw-r--r-- compar.c
  25. #   2565 -rw-r--r-- termcap.c
  26. #   4051 -rw-r--r-- tputs.c
  27. #   7042 -rw-r--r-- tty.c
  28. #  16585 -rw-r--r-- tparm.c
  29. #   1141 -rw-r--r-- tiget.c
  30. #   2435 -rw-r--r-- tgoto.c
  31. #   3998 -rw-r--r-- buildpath.c
  32. #   5023 -rw-r--r-- tcapconv.c
  33. #   6363 -rw-r--r-- qsort.c
  34. #   6271 -rw-r--r-- gettcap.c
  35. #   7453 -rw-r--r-- gettinfo.c
  36. #    671 -rw-r--r-- getother.c
  37. #   1508 -rw-r--r-- addstr.c
  38. #   2908 -rw-r--r-- mktermhead.c
  39. #   3281 -rw-r--r-- mkcaplist.c
  40. #   3629 -rw-r--r-- mkcapsort.c
  41. #   2211 -rw-r--r-- readcaps.c
  42. #    470 -rw-r--r-- tcapvars.c
  43. #   2151 -rw-r--r-- mkbinorder.c
  44. #   2512 -rw-r--r-- gettbin.c
  45. #    992 -rw-r--r-- quit.c
  46. #   4213 -rw-r--r-- ttest.c
  47. #   3264 -rw-r--r-- caps.c
  48. #  25042 -rw-r--r-- conv.c
  49. #   1993 -rw-r--r-- bsearch.c
  50. #   1327 -rw-r--r-- strtok.c
  51. #   1740 -rw-r--r-- fake_stdio.c
  52. #   8573 -rw-r--r-- sprintf.c
  53. #   1295 -rw-r--r-- clear.c
  54. #   2146 -rw-r--r-- term.tail
  55. #   3602 -rw-r--r-- defs.h
  56. #   1816 -rw-r--r-- config.h
  57. #   8689 -rw-r--r-- cap_list
  58. #   4429 -rw-r--r-- terminfo.src
  59. #   1552 -rw-r--r-- bin_order
  60. #   1221 -rw-r--r-- fake_stdio.h
  61. #   3726 -rw-r--r-- conv.1
  62. #   1850 -rw-r--r-- config.h.xenix
  63. #
  64. touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
  65. if [ -s /tmp/s3_touch$$ ]
  66. then
  67.     TOUCH=can
  68. else
  69.     TOUCH=cannot
  70. fi
  71. rm -f /tmp/s3_touch$$
  72. if test -r s3_seq_.tmp
  73. then echo "Must unpack archives in sequence!"
  74.      next=`cat s3_seq_.tmp`; echo "Please unpack part $next next"
  75.      exit 1; fi
  76. # ============= Makefile ==============
  77. echo "x - extracting Makefile (Text)"
  78. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  79. X#
  80. X# Makefile
  81. X#
  82. X# By Ross Ridge
  83. X# Public Domain
  84. X# 90/04/02 04:21:20
  85. X#
  86. X# make the terminfo/termcap library
  87. X#
  88. X# @(#) Makefile 1.6.1.2
  89. X#
  90. X# See the file INSTALL for configuration instructions
  91. X#
  92. X
  93. XCC = cc
  94. XCFLAGS = $(DFLAGS) -O
  95. X
  96. X#CFLAGS = $(DFLAGS) -W1 -Ox
  97. X#CC = gcc
  98. X#CFLAGS = $(DFLAGS) -O -Wall -Wpointer-arith -fstrength-reduce -ansi
  99. X
  100. XLDFLAGS = $(DFLAGS)  
  101. X
  102. XCAPS = 1000
  103. X
  104. XAR = ar
  105. XARFLAGS = qcv
  106. X
  107. X# System V should use echo instead of ranlib
  108. XRANLIB = ranlib
  109. X#RANLIB = echo 
  110. X
  111. XSHELL = /bin/sh
  112. X
  113. XALLCSRCS = fillterm.c findterm.c tmatch.c terminfo.c compar.c\
  114. Xtermcap.c tputs.c tty.c tparm.c tiget.c tgoto.c buildpath.c\
  115. Xtcapconv.c qsort.c gettcap.c gettinfo.c getother.c addstr.c\
  116. Xmktermhead.c mkcaplist.c mkcapsort.c readcaps.c tcapvars.c\
  117. Xmkbinorder.c gettbin.c quit.c ttest.c caps.c conv.c\
  118. Xbsearch.c strtok.c fake_stdio.c sprintf.c clear.c
  119. XALLSRCS = $(ALLCSRCS)\
  120. Xterm.tail defs.h config.h cap_list terminfo.src bin_order fake_stdio.h conv.1
  121. XALLOTHERS = Makefile TODO README README.doc INSTALL DECL
  122. XALL = $(ALLSRCS) $(ALLOTHERS)
  123. X
  124. XSRCS = capsort.c caplist.c fillterm.c findterm.c tmatch.c\
  125. Xterminfo.c compar.c bsearch.c strtok.c binorder.c\
  126. Xtermcap.c tputs.c tty.c tparm.c tiget.c tgoto.c buildpath.c\
  127. Xtcapconv.c gettcap.c gettinfo.c getother.c addstr.c tcapvars.c\
  128. Xgettbin.c fake_stdio.c sprintf.c
  129. XOBJS = capsort.o caplist.o fillterm.o findterm.o tmatch.o\
  130. Xterminfo.o compar.o bsearch.o strtok.o binorder.o\
  131. Xtermcap.o tputs.o tty.o tparm.o tiget.o tgoto.o buildpath.o\
  132. Xtcapconv.o gettcap.o gettinfo.o getother.o addstr.o tcapvars.o\
  133. Xgettbin.o fake_stdio.o sprintf.o
  134. X
  135. XLINTFLAGS = # -Z -O -C
  136. X
  137. XDEFS_H = defs.h config.h fake_stdio.h
  138. X
  139. Xtinfo.a: $(OBJS)
  140. X    rm -f tinfo.a
  141. X    $(AR) $(ARFLAGS) tinfo.a $(OBJS)
  142. X    $(RANLIB) tinfo.a
  143. X
  144. Xtinfo_g.a: $(OBJS)
  145. X    rm -f tinfo_g.a
  146. X    $(AR) $(ARFLAGS) tinfo_g.a $(OBJS)
  147. X    $(RANLIB) tinfo_g.a
  148. X
  149. Xtinfo_p.a: $(OBJS)
  150. X    rm -f tinfo_p.a
  151. X    $(AR) $(ARFLAGS) tinfo_p.a $(OBJS)
  152. X    $(RANLIB) tinfo_p.a
  153. X
  154. Xdebug: 
  155. X    $(MAKE) DFLAGS="-g" CFLAGS="${CFLAGS} -DDEBUG" tinfo_g.a
  156. X
  157. Xprofiled: mv mktermhead mkcaplist mkcapsort mkbinorder
  158. X    @if test ! -d Profile; then mkdir Profile; fi
  159. X    @if test ! -d Objs; then mkdir Objs; fi
  160. X    -mv -f Profile/*.o . 2> /dev/null
  161. X    $(MAKE) DFLAGS="-p" tinfo_p.a
  162. X    -mv -f $(OBJS) Profile 2> /dev/null
  163. X    -mv -f Objs/*.o . 2> /dev/null
  164. X    rm -f mon.out
  165. X
  166. Xrm:
  167. X    rm -f $(OBJS)
  168. X
  169. Xmv:
  170. X    -mv -f $(OBJS) Objs 2> /dev/null
  171. X
  172. Xtest: ttest tputs.test tparm.test readcaps.test caps sprintf.test
  173. X
  174. Xttest: ttest.o quit.o debug
  175. X    $(CC) -o ttest -g $(LDFLAGS) ttest.o quit.o tinfo_g.a 
  176. X
  177. Xttest.o: ttest.c $(DEFS_H) term.h
  178. X    $(CC) -c -g $(CFLAGS) ttest.c
  179. X
  180. Xcaps: caps.o quit.o debug
  181. X    $(CC) -o caps -g $(LDFLAGS) caps.o quit.o tinfo_g.a
  182. X
  183. Xcaps.o: ttest.c $(DEFS_H) term.h
  184. X    $(CC) -c -g $(CFLAGS) caps.c
  185. X
  186. X.SUFFIXES: .test
  187. X
  188. X.c.test:
  189. X    $(CC) -o $< -DTEST -g $(LDFLAGS) $(CFLAGS) $< -o $@
  190. X
  191. Xtputs.test: tputs.c term.h $(DEFS_H)
  192. X
  193. Xtparm.test: tparm.c term.h $(DEFS_H)
  194. X
  195. Xreadcaps.test: readcaps.c $(DEFS_H)
  196. X
  197. Xsprintf.test: sprintf.c $(DEFS_H)
  198. X
  199. Xcapsort.c: mkcapsort
  200. X    ./mkcapsort > capsort.c
  201. X
  202. Xmkcapsort: mkcapsort.o caplist.o compar.o qsort.o
  203. X    $(CC) $(LDFLAGS) -o mkcapsort mkcapsort.o caplist.o compar.o \
  204. Xqsort.o
  205. X
  206. Xbinorder.c: mkbinorder bin_order
  207. X    ./mkbinorder bin_order > binorder.c
  208. X
  209. Xmkbinorder.o: mkbinorder.c term.h $(DEFS_H)
  210. X
  211. Xmkbinorder: mkbinorder.o capsort.o caplist.o compar.o bsearch.o
  212. X    $(CC) $(LDFLAGS) -o mkbinorder mkbinorder.o capsort.o \
  213. Xcaplist.o compar.o bsearch.o
  214. X
  215. Xterm.h: term.head term.tail
  216. X    cat term.head term.tail > term.h
  217. X
  218. Xterm.head: mktermhead cap_list
  219. X    ./mktermhead -n $(CAPS) cap_list > term.head
  220. X
  221. Xcaplist.c: mkcaplist cap_list
  222. X    ./mkcaplist -n $(CAPS) cap_list > caplist.c
  223. X
  224. Xmktermhead: mktermhead.o readcaps.o
  225. X    $(CC) $(LDFLAGS) -o mktermhead mktermhead.o readcaps.o
  226. X
  227. Xmkcaplist: mkcaplist.o readcaps.o
  228. X    $(CC) $(LDFLAGS) -o mkcaplist mkcaplist.o readcaps.o
  229. X
  230. Xcap2info: conv
  231. X    rm -f cap2info
  232. X    ln conv cap2info
  233. X
  234. Xtic: conv
  235. X    rm -f tic
  236. X    ln conv tic
  237. X
  238. Xconv: conv.o quit.o tinfo.a 
  239. X    $(CC) $(LDFLAGS) -o conv conv.o quit.o tinfo.a
  240. X
  241. Xclear: clear.tcap clear.tinfo
  242. X
  243. Xclear.tcap: clear.c tinfo.a $(DEFS_H)
  244. X    $(CC) $(LDFLAGS) $(CFLAGS) -o clear.tcap clear.c tinfo.a
  245. X
  246. Xclear.tinfo: clear.c tinfo.a $(DEFS_H) term.h
  247. X    $(CC) $(LDFLAGS) $(CFLAGS) -DUSE_TERMINFO -o clear.tinfo clear.c tinfo.a
  248. X
  249. Xquit.o mktermhead.o mkcaplist.o readcaps.o: $(DEFS_H)
  250. X
  251. Xconv.o mkcapsort.o: term.h $(DEFS_H)
  252. X
  253. X$(OBJS): $(DEFS_H) term.h
  254. X
  255. Xprintf.o: sprintf.c $(DEFS_H)
  256. X    -mv -f sprintf.o sprintf..o 
  257. X    $(CC) $(CFLAGS) -c -DUSE_FAKE_STDIO -DPRINTF sprintf.c
  258. X    -mv -f sprintf.o printf.o
  259. X    -mv -f sprintf..o sprintf.o
  260. X
  261. Xprint: $(ALL)
  262. X    pr $(ALL) | lpr
  263. X
  264. Xlint: $(SRCS) term.h $(DEFS_H)
  265. X    lint $(LINTFLAGS) $(SRCS)
  266. X
  267. Xclean:
  268. X    rm -f *.o mkcapsort capsort.c term.head caplist.c
  269. X    rm -f mkbinorder binorder.c mkcaplist mktermhead
  270. X    rm -f Debug/*.o Profile/*.o Objs/*.o
  271. X
  272. Xspotless: clean
  273. X    rm -f tinfo.a term.h tparm.test tputs.test tinfo_g.a
  274. X    rm -f tinfo_p.a ttest sprintf.test clear.tcap clear.tinfo
  275. X    rm -f readcaps.test caps cap2info conv tic 
  276. X    rm -f core a.out 
  277. X#    rm -rf Shar
  278. X
  279. Xall: tinfo.a term.h conv cap2info tic clear
  280. X    
  281. Xlorder: $(OBJS)
  282. X    rm -f tinfo.a
  283. X    $(AR) $(ARFLAGS) `lorder $(OBJS) | tsort`
  284. X    $(RANLIB) tinfo.a
  285. X
  286. X#
  287. X#.DEFAULT: $(ALLSRCS)
  288. X#    test -f SCCS/s.$< && get SCCS/s.$<
  289. X#
  290. X#get:
  291. X#    get SCCS
  292. X#    
  293. X#edit:
  294. X#    get -e SCCS
  295. X#
  296. X#create: $(ALLSRCS)
  297. X#    for i in $(ALLSRCS); do echo $$i:; admin -i$$i -fb -fi -aross SCCS/s.$$i; done
  298. X#
  299. X#nuke: spotless
  300. X#    -mv -f $(ALLSRCS) Backup 2> /dev/null
  301. X#    rm -f makerrs
  302. X#
  303. X#shar: $(ALLOTHERS)
  304. X#    rm -rf Shar
  305. X#    mkdir Shar
  306. X#    cp $(ALLOTHERS) Shar
  307. X#    (cd Shar;for i in $(ALLSRCS);do echo "$$i:";get -r1 ../SCCS/s.$$i;done)
  308. X#    rm -f Shar/config.h
  309. X#    get -r1.3.1 -p SCCS/s.config.h > Shar/config.h
  310. X#    get -r1.3.2 -p SCCS/s.config.h > Shar/config.h.xenix
  311. X#    get -r1.6.1 -p s.Makefile > Shar/Makefile
  312. X#    chmod u+w Shar/*
  313. X#    (cd Shar; shar -l50 -o"part" -c -v -w -n"tinfo" $(ALL) config.h.xenix)
  314. SHAR_EOF
  315. chmod 0644 Makefile || echo "restore of Makefile fails"
  316. case $TOUCH in
  317. can)
  318.     touch -am 0402044690 Makefile
  319.     ;;
  320. esac
  321. set `wc -c Makefile`;Wc_c=$1
  322. case "$Wc_c" in
  323. "5721") ;;
  324. *) echo original size 5721, current size $Wc_c ;;
  325. esac
  326. # ============= TODO ==============
  327. echo "x - extracting TODO (Text)"
  328. sed 's/^X//' << 'SHAR_EOF' > TODO &&
  329. X- SysV R3.2 (R4?) caps (eg. colour)
  330. X- tinfoconv?
  331. X- tcapconv: handle cursor key map
  332. X- better hack for tgoto
  333. X- don't call bsearch directly
  334. X- (perfect?) hash table lookup
  335. X- make tparm work with '%\066'
  336. X- GNU's tparam
  337. X- conv: handle translations to termcap
  338. X- doc's, doc's, doc's
  339. SHAR_EOF
  340. chmod 0644 TODO || echo "restore of TODO fails"
  341. case $TOUCH in
  342. can)
  343.     touch -am 0402044690 TODO
  344.     ;;
  345. esac
  346. set `wc -c TODO`;Wc_c=$1
  347. case "$Wc_c" in
  348. "275") ;;
  349. *) echo original size 275, current size $Wc_c ;;
  350. esac
  351. # ============= README ==============
  352. echo "x - extracting README (Text)"
  353. sed 's/^X//' << 'SHAR_EOF' > README &&
  354. XThis is a beta-release.  It is public domain, and comes with no guarantees.
  355. XBy Ross Ridge (ross@contact.uucp).
  356. X
  357. XThis library is a merging of termcap and terminfo.  It has all termcap and
  358. Xterminfo functions, and reads both termcap and terminfo databases.  It can
  359. Xalso get terminal descriptions from terminfo source files.  
  360. X
  361. XThis library is designed useful on sites that use programmes the use
  362. Xboth the terminfo and termcap databases.  New terminal descriptions
  363. Xdon't need to be added to both, and users maintaining their own private
  364. Xdatabases wouldn't to have both.  Sites that only have termcap can
  365. Xuse this library to compile programmes that use terminfo, and they don't
  366. Xneed to have a terminfo database online to use it either.
  367. X
  368. XYou should be able to compile this library on almost all versions of
  369. XUnix.  Much of the developement was done on '386 Xenix, but an earlier
  370. Xversion compiled successfuly under BSD 4.3 with both cc and gcc.
  371. XThere hasn't been a terrible amount of real world testing of the library
  372. Xbut it has been used with rn, vi and nethack.
  373. X
  374. XThe environment variables TERMCAP and TERMINFO can have multiple filenames
  375. Xseperated by space a feature not in terminfo and not in all termcaps.
  376. XThis is very handy users for users that maintain private databases,
  377. Xas they don't have to copy the entire database.
  378. X    TERMCAP="$HOME/.termcap /etc/termcap"
  379. X    TERMINFO="$HOME/terminfo /usr/lib/terminfo"
  380. X    export TERMCAP TERMINFO
  381. XThe library will also check in compiled in default locations for terminal
  382. Xdescriptions. Like most termcaps, the TERMCAP variable can also contain
  383. Xthe complete termcap terminal description, usually supplied from tset at login.
  384. XThe TERMINFO variable can also contain a complete terminfo description, but
  385. Xthere is no programme like tset to supply it. 
  386. X
  387. XParameterized strings can either be in termcap or terminfo format regardless
  388. Xof which type of description they come from. Two extensions to the standard
  389. Xtermcap % codes are supported, GNU's %a, %m, %b, and %f, and the University
  390. Xof Waterloo's, %-, %a, and %s.
  391. X
  392. XUnlike termcap, programmes that use this library can only use capabilities
  393. Xthat it knows about. However it is fairly simple to add to list of
  394. Xcapabilities it knows. Included in the list are all terminfo capabilities
  395. Xto Release 3.0 of System V, obsolete termcap capabilities, a few caps used
  396. Xby UW, a couple by GNU Emacs, and a few I tacked onto the end.
  397. X
  398. XTermcap and terminfo source descriptions can be mixed in one file, however
  399. Xbecause of this termcap databases must be in a certain style. All contination
  400. Xlines of a termcap entry must be indented from the left margin by white space.
  401. XThis shouldn't be a problem with most sites since this is style that most
  402. Xtermcap files are distributed, but local additions may not adhere to this
  403. Xstyle. Another possible problem is that termcap entries should end with
  404. Xa colon (:), but in most distributed termcaps there are entries that
  405. Xdon't. If a one line termcap entry doesn't end with a colon, it will be
  406. Xignored.
  407. X
  408. XIncluded in the package is conv, an "all-in-one" programme that will compile
  409. Xterminfo sources to binary format and translate termcap to terminfo. 
  410. X
  411. XSee the file INSTALL for instructions on configuring and installing this
  412. Xlibrary. The file README.doc lists the functions supported by the library,
  413. Xand gives short description of the conv programme. conv.1 is the start
  414. Xof man page for conv. terminfo.src contains a few sample terminal
  415. Xdescriptions in terminfo source format.
  416. X
  417. XPlease let me know of any bugs you find, and any ideas you have for
  418. Ximprovement.
  419. X
  420. XRoss Ridge
  421. X
  422. Xross@contact.uucp
  423. Xuunet!mnetor!becker!contact!ross
  424. X(if the above fails you can try these:)
  425. Xross@watcsc.waterloo.edu
  426. Xrridge@watmath.waterloo.edu
  427. SHAR_EOF
  428. chmod 0644 README || echo "restore of README fails"
  429. case $TOUCH in
  430. can)
  431.     touch -am 0402044690 README
  432.     ;;
  433. esac
  434. set `wc -c README`;Wc_c=$1
  435. case "$Wc_c" in
  436. "3708") ;;
  437. *) echo original size 3708, current size $Wc_c ;;
  438. esac
  439. # ============= README.doc ==============
  440. echo "x - extracting README.doc (Text)"
  441. sed 's/^X//' << 'SHAR_EOF' > README.doc &&
  442. X----------------------------------------------------------------------------
  443. Xconv [-b] [-c [-OUGd]] [-i] [-B [-D dir]] [-I] [-k] [-t term] [file]
  444. Xtic [file]
  445. Xcap2info [-t term] [-OUGdk] [file]
  446. X
  447. X-c        convert from termcap
  448. X-i        convert from terminfo source
  449. X-b        convert from terminfo binary
  450. X-B        convert to terminfo binary
  451. X-I        convert to terminfo source
  452. X
  453. XThe following switches are available when converting from termcap:
  454. X-d        don't supply any defaults for missing capabilities
  455. X-O        include obsolete termcap capabilities
  456. X-G        include GNU capabilities
  457. X-U        include UW capabilities
  458. X
  459. X-k        keep comments
  460. X-D dir        directory to put terminfo binaries in
  461. X
  462. X-t term        name of terminal to translate
  463. Xfile        filename of termcap/terminfo database to use 
  464. X
  465. XIf a file is specifed and no terminal is given the entire file we be translated.
  466. XIf no terminal and no file is specified then the terminal name will be taken
  467. Xfrom the environment varible TERM. Unless compiling to a terminfo binary,
  468. Xoutput is to stdout.
  469. X----------------------------------------------------------------------------
  470. X
  471. Xchar *tparm(char *str, ...);    /* up to nine parameters */
  472. Xchar *tgoto(char *str, int column, int row);
  473. X
  474. Xtparm and tgoto support the following termcap and terminfo % codes:
  475. X
  476. XTerminfo % Codes
  477. X
  478. X    %%    output a '%'
  479. X    %[[:][-+# ][width][.precision]][doxXs]
  480. X        output pop according to the printf format
  481. X    %c    output pop as a char
  482. X    %'c'    push character constant c.
  483. X    %{n}    push decimal constant n.
  484. X    %p[1-9] push paramter [1-9]
  485. X    %g[a-z] push variable [a-z]
  486. X    %P[a-z] put pop in variable [a-z]
  487. X    %l    push the length of pop (a string)
  488. X    %+    add pop to pop and push the result
  489. X    %-    subtract pop from pop and push the result
  490. X    %*    multiply pop and pop and push the result
  491. X    %&    bitwise and pop and pop and push the result
  492. X    %|    bitwise or pop and pop and push the result
  493. X    %^    bitwise xor pop and pop and push the result
  494. X    %~    push the bitwise not of pop
  495. X    %=    compare if pop and pop are equal and push the result
  496. X    %>    compare if pop is less than pop and push the result
  497. X    %<    compare if pop is greater than pop and push the result
  498. X    %A    logical and pop and pop and push the result
  499. X    %O    logical or pop and pop and push the result
  500. X    %!    push the logical not of pop
  501. X    %? condition %t if_true [%e if_false] %;
  502. X        if condtion evaulates as true then evaluate if_true,
  503. X        else evaluate if_false. elseif's can be done:
  504. X%? cond %t true [%e cond2 %t true2] ... [%e condN %t trueN] [%e false] %;
  505. X    %i    add one to parameters 1 and 2. (ANSI)
  506. X
  507. XTermcap Codes
  508. X
  509. X    %%    output a %
  510. X    %.    output parameter as a character
  511. X    %d    output parameter as a decimal number
  512. X    %2    output parameter in printf format %02d
  513. X    %3    output parameter in printf format %03d
  514. X    %+x    add the character x to parameter and output it as a character
  515. X(UW)    %-x    subtract parameter FROM the character x and output it as a char
  516. X(UW)    %ax    add the character x to parameter
  517. X(GNU)    %a[+*-/=][cp]x
  518. X        GNU arithmetic. 
  519. X(UW)    %sx    subtract parameter FROM the character x
  520. X    %>xy    if parameter > character x then add character y to parameter
  521. X    %B    convert to BCD (parameter = (parameter/10)*16 + parameter%16)
  522. X    %D    Delta Data encode (parameter = parameter - 2*(paramter%16))
  523. X    %i    increment the first two parameters by one
  524. X    %n    xor the first two parameters by 0140
  525. X(GNU)    %m    xor the first two parameters by 0177
  526. X    %r    swap the first two parameters
  527. X(GNU)    %b    backup to previous parameter
  528. X(GNU)    %f    skip this parameter
  529. X
  530. X(GNU) used by GNU Emacs termcap libraries
  531. X(UW) used by the University of Waterloo (MFCF) termcap libraries
  532. X
  533. XNote the two definitions of %a, the GNU defintion is used if the characters
  534. Xafter the 'a' are valid, otherwise the UW definition is used.
  535. X----------------------------------------------------------------------------
  536. X
  537. Xint setupterm(char *term; int fd; int *err);
  538. Xint set_curterm(TERMINAL *new);
  539. Xint del_curterm(TERMINAL *old);
  540. Xchar *tparm(char *str, ...);        /* see above */
  541. Xint tputs(char *str, int count, int (*putc)());
  542. Xint putp(str);
  543. Xint tigetflag(char *cap);
  544. Xint tigetnum(char *cap);
  545. Xchar *tigetstr(char *cap);
  546. Xint def_prog_mode();
  547. Xint def_shell_mode();
  548. Xint reset_prog_mode();
  549. Xint reset_shell_mode();
  550. Xchar *boolnames[], *boolcodes[], *boolfnames[];
  551. Xchar *numnames[], *numcodes[], *numfnames[];
  552. Xchar *strnames[], *strcodes[], *strfnames[];
  553. X
  554. XThese functions work just like the terminfo functions. Note, restartterm(),
  555. Xvidputs(), vidattr(), and mvcur() are not available.
  556. X----------------------------------------------------------------------------
  557. X
  558. Xint tgetent(char *buf, char *term);
  559. Xint tgetflag(char *cap);
  560. Xint tgetnum(char *cap);
  561. Xchar *tgetstr(char *cap, char **area);
  562. Xchar *tgoto(char *cap, int column, int row);
  563. Xint tputs(char *str, int count, int (*putc)());
  564. X
  565. XThese functions work just like termcap functions.
  566. X----------------------------------------------------------------------------
  567. SHAR_EOF
  568. chmod 0644 README.doc || echo "restore of README.doc fails"
  569. case $TOUCH in
  570. can)
  571.     touch -am 0402044690 README.doc
  572.     ;;
  573. esac
  574. set `wc -c README.doc`;Wc_c=$1
  575. case "$Wc_c" in
  576. "4731") ;;
  577. *) echo original size 4731, current size $Wc_c ;;
  578. esac
  579. # ============= INSTALL ==============
  580. echo "x - extracting INSTALL (Text)"
  581. sed 's/^X//' << 'SHAR_EOF' > INSTALL &&
  582. XTo compile the library you are going to have to edit the Makefile and
  583. Xthe config.h header. In the Makefile you have to specify the compiler
  584. Xand any compiler/loader options. config.h will have to be edited to 
  585. Xreflect your compiler, system and to enable certain features.
  586. X
  587. X
  588. XDefines in config.h
  589. X===================
  590. X
  591. XUSE_ANSIC 
  592. X
  593. XNormally this will be defined automaticly if __STDC__ is defined but
  594. Xsome compilers lie, so you can undefine this if necessary. 
  595. X
  596. XUSE_TERMIO
  597. X
  598. XDefine this if your system uses the termio tty driver. System III and
  599. XSystem V use termio. 
  600. X
  601. XUSE_SGTTY
  602. X
  603. XDefine this if your system uses the "sgtty" tty driver. V7 Unix and BSD
  604. Xuse sgtty.
  605. X
  606. XUSE_WINSZ
  607. X
  608. XIf you defined USE_SGTTY you can define this if your system supports
  609. XSIGWINSZ and the accompaning ioctls. If this is defined the library
  610. Xwill get number of columns and lines from the tty driver not the
  611. Xterminal description. BSD 4.3 supports SIGWINSZ.
  612. X
  613. XDo not define both USE_TERMIO and USE_SGTTY. If your system supports both
  614. Xyou'd probably be better of defining USE_TERMIO, unless you want to
  615. Xdefine USE_WINSZ. If your system supports neither termio or sgtty you
  616. Xcan leave USE_TERMIO and USE_SGTTY undefined, but this only recomened
  617. Xfor micros.
  618. X
  619. XUSE_STRINGS
  620. X
  621. XIf you define this then the header file <strings.h> will be included
  622. Xand BSD type string library assumed (index instead of strchr), otherwise
  623. X<string.h> will included.  If you have BSD type system define this.
  624. XIf you have an ANSI C, System III, or System V type system leave it
  625. Xundefined.
  626. X
  627. XUSE_MYBSEARCH
  628. X
  629. XIf your system's C library doesn't include bsearch, define this.
  630. XMost System V systems have bsearch.
  631. X
  632. XUSE_MYSTRTOK
  633. X
  634. XIf your system's C library doesn't include strtok, define this.
  635. XMost ANSI C, System III, and System V systems have this.
  636. X
  637. XUSE_MYQSORT
  638. X
  639. XIf your system's C library doesn't include qsort, define this.
  640. XAll most all systems should have this function, if it doesn't complain
  641. Xto your vendor.
  642. X
  643. XUSE_MEMORY
  644. X
  645. XIf your system has a <memory.h> header define this. If USE_MEMORY
  646. Xis not defined bcopy will used instead of memcpy.
  647. X
  648. XUSE_SMALLMEM 
  649. X
  650. XUse you can define use this to save some memory, but it doesn't
  651. Xsave much at moment, and will only slow the library down.
  652. X
  653. XUSE_FAKE_STDIO
  654. X
  655. XIf you define this then the library won't use the real stdio but a
  656. Xfake one instead. This is for compatiblity with termcap and vi which don't
  657. Xuse stdio.
  658. X
  659. XUSE_DOPRNT
  660. X
  661. XIf you don't have a vfprintf function, but you have a _doprnt function
  662. Xdefine this.  If you don't have either than you can compile the library
  663. Xbut not the support programmes.  System V has vfprintf and most Unixes
  664. Xhave a _doprnt (but probably not documented).  BSD has released a freely
  665. Xdistributable vfprintf for BSD Unixes.
  666. X
  667. XUSE_UPBC_KLUDGE
  668. X
  669. XDefine this if you want the library's tgoto to work like termcap's tgoto
  670. Xand avoid putting ^D, and \n into an output string by using the
  671. Xcursor up and backspace strings.
  672. X
  673. XUSE_EXTERN_UPBC
  674. X
  675. XIf you defined USE_UPBC_KLUDGE you can define this so tgoto will,
  676. Xlike termcap's tgoto, get the cursor up and backspace strings from the
  677. Xexterns UP and BC instead from the libraries internal record.
  678. X
  679. XUSE_LITOUT_KLUDGE
  680. X
  681. XDon't define this. It's another kludge for tgoto.
  682. X
  683. XIf neither USE_UPBC_KLUDGE or USE_LITOUT_KLUDGE is defined than tgoto
  684. Xwon't worry about putting ^D, and \n in a string.
  685. X
  686. XUSE_PROTOTYPES
  687. X
  688. XDefine this if your compiler supports ANSI C style prototypes.
  689. X
  690. XUSE_STDLIB
  691. X
  692. XDefine this if your system has an <stdlib.h> header.
  693. X
  694. XUSE_STDARG
  695. X
  696. XDefine this if your system has an <stdarg.h> header. If this isn't
  697. Xdefined <varargs.h> will be included instead.
  698. X
  699. XUSE_STDDEF
  700. X
  701. XDefine this if your system has an <stddef.h> header. If this isn't
  702. Xdefined <sys/types.h> will be included instead.
  703. X
  704. Xtypedef char *anyptr;
  705. X
  706. XYou should change the typedef to a type that any pointer can be assigned
  707. Xto or from. ANSI C compilers can use "typedef void *anyptr", most
  708. Xother compilers should use "typedef char *anyptr".
  709. X
  710. XTERMCAPFILE
  711. X
  712. XDefine this to a string containing the default termcap file(s) to look
  713. Xfor terminal descriptions in. Multiple filenames should be seperated
  714. Xby spaces and environment variables can be specfied by prefixing them
  715. Xwith dolar signs ($).
  716. X    #define TERMCAPFILE "$TERMCAPFILE $HOME/.termcap /etc/termcap"
  717. X
  718. XTERMINFOSRC
  719. X
  720. XDefine this to a string containing the default terminfo source file to
  721. Xlook for terminal descriptions in.
  722. X
  723. XTERMINFODIR
  724. X
  725. XDefine this as the directory containing the default terminfo database,
  726. Xusually "/usr/lib/terminfo".
  727. X
  728. X
  729. Xdefs.h
  730. X======
  731. X
  732. XYou may also need to edit defs.h. If the type size_t isn't defined
  733. Xin <stddef.h>, <sys/types.h> or some other header, typedef it somewhere
  734. Xhere ("typedef unsigned long size_t", or "typedef unsigned size_t").
  735. XYou may also want to change the definitions of MAX_BUF, MAX_LINE,
  736. Xand MAX_NAME. Unless you are seriously starved for memory I don't
  737. Xrecomend making them smaller.
  738. X
  739. X
  740. Xcap_list
  741. X========
  742. X
  743. XYou can add new capabilities to the file cap_list. You must provide
  744. Xa type, terminfo variable name, terminfo capname, and termcap name for
  745. Xall capabilities and you must make sure they are all unique.
  746. X
  747. X
  748. XMaking in the library
  749. X=====================
  750. X
  751. XOnce you've configured the package you can just type "make" and it
  752. Xwill build the library and the "term.h" header. You can enter
  753. X"make all" to make the library and the support programmes, conv,
  754. Xcap2info, tic, and caps.  If you want a profiled library you can 
  755. Xenter "make profiled".  You can remove all the intermediate files
  756. Xwith "make clean", and you remove the target files as well with 
  757. X"make spotless".
  758. X
  759. X
  760. XInstalling the library
  761. X======================
  762. X
  763. XAs for installing it, that's up to you.  Depending on how much you
  764. Xplan to use the libraries and whether or not you have termcap and/or
  765. Xterminfo already you can install them "standard" places (ie. /usr/lib,
  766. X/usr/include, /usr/bin), in local directories, or just leave them in
  767. Xthe source directory. However if you are compiling programmes that
  768. Xuse terminfo and linking it with this library you must make sure that
  769. Xthis library's term.h file is used and not the system supplied one.
  770. SHAR_EOF
  771. chmod 0644 INSTALL || echo "restore of INSTALL fails"
  772. case $TOUCH in
  773. can)
  774.     touch -am 0402044690 INSTALL
  775.     ;;
  776. esac
  777. set `wc -c INSTALL`;Wc_c=$1
  778. case "$Wc_c" in
  779. "6056") ;;
  780. *) echo original size 6056, current size $Wc_c ;;
  781. esac
  782. # ============= DECL ==============
  783. echo "x - extracting DECL (Text)"
  784. sed 's/^X//' << 'SHAR_EOF' > DECL &&
  785. Xint setupterm(char *, int, int *);
  786. Xint set_curterm(TERMINAL *);
  787. Xint del_curterm(TERMINAL *);
  788. Xchar *tparm(char *, ...);
  789. Xint tputs(char *, int, int (*)());
  790. Xint putp(char *);
  791. Xint def_prog_mode(void);
  792. Xint def_shell_mode(void);
  793. Xint reset_prog_mode(void);
  794. Xint reset_shell_mode(void);
  795. Xint tigetnum(char *);
  796. Xint tigetflag(char *);
  797. Xchar *tigetstr(char *);
  798. Xint tgetent(char *, char *);
  799. Xint tgetnum(char *);
  800. Xint tgetflag(char *);
  801. Xchar *tgetstr(char *, char * *);
  802. Xchar *tgoto(char *, int, int);
  803. SHAR_EOF
  804. chmod 0664 DECL || echo "restore of DECL fails"
  805. case $TOUCH in
  806. can)
  807.     touch -am 0402044690 DECL
  808.     ;;
  809. esac
  810. set `wc -c DECL`;Wc_c=$1
  811. case "$Wc_c" in
  812. "483") ;;
  813. *) echo original size 483, current size $Wc_c ;;
  814. esac
  815. # ============= fillterm.c ==============
  816. echo "x - extracting fillterm.c (Text)"
  817. sed 's/^X//' << 'SHAR_EOF' > fillterm.c &&
  818. X/*
  819. X * fillterm.c
  820. X *
  821. X * By Ross Ridge
  822. X * Public Domain
  823. X * 90/03/22 03:43:31
  824. X *
  825. X */
  826. X
  827. X#include "defs.h"
  828. X#include "term.h"
  829. X
  830. X#ifdef USE_SCCS_IDS
  831. Xstatic char SCCSid[] = "@(#) fillterm.c 1.1";
  832. X#endif
  833. XTERMINAL _term_buf;
  834. XTERMINAL *cur_term;
  835. X
  836. Xint _fillterm(name, path, buf)
  837. Xchar *name, *buf;
  838. Xstruct term_path *path; {
  839. X    register int i, r;
  840. X
  841. X    r = -1;
  842. X
  843. X    for(i = NUM_OF_BOOLS; i;)
  844. X        _term_buf.bools[--i] = -1;
  845. X    for(i = NUM_OF_NUMS; i;)
  846. X        _term_buf.nums[--i] = -2;
  847. X    for(i = NUM_OF_STRS; i;)
  848. X        _term_buf.strs[--i] = (char *) -1;
  849. X
  850. X    _term_buf.name_all = NULL;
  851. X    
  852. X    r = _findterm(name, path, buf);
  853. X    switch(r) {
  854. X    case 1:
  855. X        if (_gettcap(buf, &_term_buf, path) != 0)
  856. X            return -3;
  857. X        _tcapconv(); 
  858. X        _tcapdefault();
  859. X        break;
  860. X    case 2:
  861. X        if (_gettinfo(buf, &_term_buf, path) != 0)
  862. X            return -3;
  863. X        break;
  864. X    case 3:
  865. X        if (_gettbin(buf, &_term_buf) != 0)
  866. X            return -3;
  867. X        break;
  868. X    default:
  869. X        return r;
  870. X    }
  871. X
  872. X    if ((_term_buf.name = _addstr(name)) == NULL)
  873. X        return -3;
  874. X
  875. X    for(i = NUM_OF_BOOLS; i;)
  876. X        if (_term_buf.bools[--i] == -1)
  877. X            _term_buf.bools[i] = 0;
  878. X    for(i = NUM_OF_NUMS; i;)
  879. X        if (_term_buf.nums[--i] == -2)
  880. X            _term_buf.nums[i] = -1;
  881. X    for(i = NUM_OF_STRS; i;)
  882. X        if (_term_buf.strs[--i] == (char *) -1)
  883. X            _term_buf.strs[i] = NULL;
  884. X
  885. X    _term_buf.fd = 1;
  886. X    _term_buf.pad = 1;
  887. X    _term_buf.baudrate = 0;
  888. X    _term_buf.strbuf = _endstr();
  889. X
  890. X    cur_term = (TERMINAL *) malloc(sizeof(_term_buf));
  891. X    if (cur_term == NULL)
  892. X        return -3;
  893. X    memcpy((anyptr)cur_term, (anyptr)&_term_buf, sizeof(_term_buf));
  894. X
  895. X    return 1;
  896. X}
  897. SHAR_EOF
  898. chmod 0644 fillterm.c || echo "restore of fillterm.c fails"
  899. case $TOUCH in
  900. can)
  901.     touch -am 0402044690 fillterm.c
  902.     ;;
  903. esac
  904. set `wc -c fillterm.c`;Wc_c=$1
  905. case "$Wc_c" in
  906. "1470") ;;
  907. *) echo original size 1470, current size $Wc_c ;;
  908. esac
  909. # ============= findterm.c ==============
  910. echo "x - extracting findterm.c (Text)"
  911. sed 's/^X//' << 'SHAR_EOF' > findterm.c &&
  912. X/* findterm.c
  913. X *
  914. X * By Ross Ridge
  915. X * Public Domain
  916. X * 90/03/22 03:43:31
  917. X *
  918. X */
  919. X
  920. X#include "defs.h"
  921. X
  922. X#include <ctype.h>
  923. X#include <fcntl.h>
  924. X#include <sys/stat.h>
  925. X
  926. X#ifdef USE_SCCS_IDS
  927. Xstatic char SCCSid[] = "@(#) findterm.c 1.1";
  928. X#endif
  929. Xstatic int linecnt;
  930. X
  931. Xstatic int getln(f, buf, len)
  932. XFILE *f;
  933. Xregister char *buf;
  934. Xint len; {
  935. X    register int c, i = 0;
  936. X
  937. X    while((c = getc(f)) == '#') {
  938. X        linecnt++;
  939. X        while((c = getc(f)) != '\n')
  940. X            if (c == EOF)
  941. X                return -1;
  942. X    }
  943. X
  944. X    while(c != '\n') {
  945. X        if (c == EOF)
  946. X            return -1;
  947. X        if (i < len) {
  948. X            i++;
  949. X            *buf++ = c;
  950. X        }
  951. X        c = getc(f);
  952. X    }
  953. X
  954. X    while(isspace(*(buf-1))) {
  955. X        buf--;
  956. X        i--;
  957. X    }
  958. X
  959. X    *buf = '\0';
  960. X    return i;
  961. X}
  962. X
  963. Xint _findterm2(name, file, buf)
  964. Xchar *name, *buf;
  965. Xchar *file; {
  966. X    char line[MAX_LINE];
  967. X    FILE *f;
  968. X    register char *sp, *dp;
  969. X    int c;
  970. X    int l;
  971. X    int cont;
  972. X    int fd;
  973. X    struct stat st;
  974. X
  975. X    linecnt = 0;
  976. X
  977. X#ifdef DEBUG
  978. X    printf("open: %s\n", file);
  979. X#endif
  980. X    fd = open(file, O_RDONLY);
  981. X    if (fd == -1)
  982. X        return -1;
  983. X    if (fstat(fd, &st) == -1)
  984. X        return -1;
  985. X    if ((st.st_mode & 0170000) == 0040000) {
  986. X        sprintf(buf, "%s/%c/%s", file, name[0], name);
  987. X        close(fd);
  988. X        fd = open(buf, O_RDONLY);
  989. X        if (fd == -1)
  990. X            return -1;
  991. X        if (read(fd, buf, MAX_BUF) < 12
  992. X            || buf[0] != 032 || buf[1] != 1) {
  993. X            close(fd);
  994. X            return -1;
  995. X        }
  996. X        close(fd);
  997. X        return 3;
  998. X    }
  999. X    f = fdopen(fd, "r");
  1000. X    if (f == NULL)
  1001. X        return -1;
  1002. X
  1003. X    while ((l = getln(f, buf, MAX_LINE)) != -1) {
  1004. X        linecnt++;
  1005. X        if (!isspace(buf[0]) && l != 0) {
  1006. X            sp = buf + l - 1;
  1007. X            cont = 0;
  1008. X            switch(*sp) {
  1009. X            case '\\':
  1010. X                cont = 1;
  1011. X                *sp = '\0';
  1012. X                /* FALLTHROUGH */
  1013. X            case ':':
  1014. X                sp = buf;
  1015. X                dp = line;
  1016. X                while (*sp != ':') {
  1017. X                    if (*sp == '\0' && cont &&
  1018. X                        (l = getln(f, buf, MAX_LINE))
  1019. X                         != -1) {
  1020. X                        linecnt++;
  1021. X                        sp = buf;
  1022. X                        if (l > 0 && buf[l-1] == '\\')
  1023. X                            cont = 1;
  1024. X                        else
  1025. X                            cont = 0;
  1026. X                        continue;
  1027. X                    }
  1028. X                    if (*sp == '\0') {
  1029. X#ifdef DEBUG
  1030. X                        printf("bad line (%d)\n",
  1031. X                               linecnt);
  1032. X                        fclose(f);
  1033. X                        return -2;
  1034. X#else
  1035. X                        goto err;
  1036. X#endif
  1037. X                    }
  1038. X                    *dp++ = *sp++;
  1039. X                }
  1040. X                *dp = '\0';
  1041. X                if (!_tmatch(line, name))
  1042. X                    break;
  1043. X                l = strlen(buf);
  1044. X                dp = buf + l;
  1045. X                while((c = getc(f)) != EOF && l < MAX_BUF) {
  1046. X                    if (c == '\n')
  1047. X                        break;
  1048. X                    if (c == '\\') {
  1049. X                        c = getc(f);
  1050. X                        if (c == EOF)
  1051. X                            break;
  1052. X                        if (c == '\n') {
  1053. X                            c = getc(f);
  1054. X                            if (c == EOF)
  1055. X                                break;
  1056. X                            if (c == '#') {
  1057. X                                while((c = getc(f)) != EOF && c != '\n');
  1058. X                                if (c == EOF)
  1059. X                                    break;
  1060. X                                continue;
  1061. X                            }
  1062. X                            *dp++ = c;
  1063. X                            continue;
  1064. X                        }
  1065. X                        *dp++ = '\\';
  1066. X                        *dp++ = c;
  1067. X                        continue;
  1068. X                    } 
  1069. X                    *dp++ = c;
  1070. X                }
  1071. X                *dp = '\0';
  1072. X                return 1;
  1073. X            case ',':
  1074. X                sp = buf;
  1075. X                dp = line;
  1076. X                while(*sp != ',')
  1077. X                    *dp++ = *sp++;
  1078. X                *dp = '\0';
  1079. X                if (!_tmatch(line, name))
  1080. X                    break;
  1081. X                dp = buf + l;
  1082. X                while ((c = getc(f)) != EOF && l < MAX_BUF) {
  1083. X                    if (c == '\n') {
  1084. X                        c = getc(f);
  1085. X                        if (isspace(c))
  1086. X                            continue;
  1087. X                        if (c == '\n') {
  1088. X                            ungetc(c, f);
  1089. X                            continue;
  1090. X                        }
  1091. X                        if (c == '#') {
  1092. X                            while((c = getc(f)) != EOF)
  1093. X                                if (c == '\n')
  1094. X                                    break;
  1095. X                            if (c == EOF)
  1096. X                                break;
  1097. X                            ungetc(c, f);
  1098. X                            continue;
  1099. X                        }
  1100. X                        break;
  1101. X                    }
  1102. X                    *dp++ = c;
  1103. X                    l++;
  1104. X                }
  1105. X                *dp = '\0';
  1106. X                return 2;
  1107. X            default:
  1108. X            err:
  1109. X#ifdef DEBUG
  1110. X                printf("strange line (%d)\n", linecnt);
  1111. X#endif
  1112. X                break;
  1113. X            }
  1114. X        }
  1115. X    }
  1116. X    return 0;
  1117. X}
  1118. X
  1119. Xint _findterm(name, path, buf)
  1120. Xchar *name;
  1121. Xstruct term_path *path;
  1122. Xchar *buf; {
  1123. X    register char *s, *d;
  1124. X    int r = 0;
  1125. X    while(path->file != NULL) {
  1126. X        switch(path->type) {
  1127. X        case 0:
  1128. X            r = _findterm2(name, path->file, buf);
  1129. X            break;
  1130. X        case 1:
  1131. X            if (path->file[0] == '/') {
  1132. X                r = _findterm2(name, path->file, buf);
  1133. X            } else {
  1134. X                s = path->file;
  1135. X                d = buf;
  1136. X                while(*s != '\0' && *s != ':')
  1137. X                    *d++ = *s++;
  1138. X                *d = '\0';
  1139. X                if (_tmatch(buf, name)) {
  1140. X                    while(*s != '\0')
  1141. X                        *d++ = *s++;
  1142. X                    return 1;
  1143. X                }
  1144. X                r = 0;
  1145. X            }
  1146. X            break;
  1147. X        case 2:
  1148. X            if (path->file[0] == '/') {
  1149. X                r = _findterm2(name, path->file, buf);
  1150. X            } else {
  1151. X                s = path->file;
  1152. X                d = buf;
  1153. X                while(*s != '\0' && *s != ',')
  1154. X                    *d++ = *s++;
  1155. X                *d = '\0';
  1156. X                if (_tmatch(buf, name)) {
  1157. X                    while(*s != '\0')
  1158. X                        *d++ = *s++;
  1159. X                    return 2;
  1160. X                }
  1161. X                r = 0;
  1162. X            }
  1163. X            break;
  1164. X        default:
  1165. X            r = 0;
  1166. X            break;
  1167. X        }
  1168. X        if (r == 1 || r == 2 || r == 3) {
  1169. X#ifdef DEBUG
  1170. X            printf("found in %s\n", path->file);
  1171. X#endif
  1172. X            break;
  1173. X        }
  1174. X        path++;
  1175. X    }
  1176. X    return r;
  1177. X}
  1178. SHAR_EOF
  1179. chmod 0644 findterm.c || echo "restore of findterm.c fails"
  1180. case $TOUCH in
  1181. can)
  1182.     touch -am 0402044690 findterm.c
  1183.     ;;
  1184. esac
  1185. set `wc -c findterm.c`;Wc_c=$1
  1186. case "$Wc_c" in
  1187. "4428") ;;
  1188. *) echo original size 4428, current size $Wc_c ;;
  1189. esac
  1190. # ============= tmatch.c ==============
  1191. echo "x - extracting tmatch.c (Text)"
  1192. sed 's/^X//' << 'SHAR_EOF' > tmatch.c &&
  1193. X/*
  1194. X * tmatch.c
  1195. X *
  1196. X * By Ross Ridge
  1197. X * Public Domain
  1198. X * 90/03/22 03:43:32
  1199. X *
  1200. X * See if a terminal name matches a list of terminal names from a
  1201. X * terminal description
  1202. X *
  1203. X */
  1204. X
  1205. X#include "defs.h"
  1206. X
  1207. X#ifdef USE_SCCS_IDS
  1208. Xstatic char SCCSid[] = "@(#) tmatch.c 1.1";
  1209. X#endif
  1210. Xint _tmatch(line, name)
  1211. Xchar *line, *name; {
  1212. X    char term[MAX_LINE];
  1213. X    char *sp, *dp;
  1214. X
  1215. X    sp = line;
  1216. X    while (*sp != '\0') {
  1217. X        dp = term;
  1218. X        while (*sp != '\0' && *sp != '|')
  1219. X            *dp++ = *sp++;
  1220. X        *dp = '\0';
  1221. X        if (strcmp(term, name) == 0)
  1222. X            return 1;
  1223. X        if (*sp == '|')
  1224. X            sp++;
  1225. X    }
  1226. X    return 0;
  1227. X}
  1228. SHAR_EOF
  1229. chmod 0644 tmatch.c || echo "restore of tmatch.c fails"
  1230. case $TOUCH in
  1231. can)
  1232.     touch -am 0402044690 tmatch.c
  1233.     ;;
  1234. esac
  1235. set `wc -c tmatch.c`;Wc_c=$1
  1236. case "$Wc_c" in
  1237. "551") ;;
  1238. *) echo original size 551, current size $Wc_c ;;
  1239. esac
  1240. # ============= terminfo.c ==============
  1241. echo "x - extracting terminfo.c (Text)"
  1242. sed 's/^X//' << 'SHAR_EOF' > terminfo.c &&
  1243. X/*
  1244. X * terminfo.c
  1245. X *
  1246. X * By Ross Ridge
  1247. X * Public Domain
  1248. X * 90/03/27 18:29:45
  1249. X *
  1250. X * terminfo compatible libary functions
  1251. X *
  1252. X */
  1253. X
  1254. X#include "defs.h"
  1255. X#include "term.h"
  1256. X
  1257. X#ifdef USE_SCCS_IDS
  1258. Xstatic char SCCSid[] = "@(#) terminfo.c 1.2";
  1259. X#endif
  1260. X#ifdef USE_FAKE_STDIO
  1261. X
  1262. Xstatic int printerr(msg)
  1263. Xchar *msg; {
  1264. X    return write(2, msg, strlen(msg));
  1265. X}
  1266. X
  1267. X#define RETERR(e, msg)  { (err == NULL ? (printerr(msg), exit(1), 0) : (*err = e)); return ERR; }
  1268. X
  1269. X#else
  1270. X
  1271. X#define RETERR(e, msg)  { (err == NULL ? (fprintf(stderr, msg), exit(1), 0) : (*err = e)); return ERR; }
  1272. X
  1273. X#endif
  1274. X
  1275. Xint setupterm(term, fd, err)
  1276. Xchar *term;
  1277. Xint fd;
  1278. Xint *err; {
  1279. X    struct term_path *path;
  1280. X    char *s, *getenv();
  1281. X    int r = -1;
  1282. X    char buf[MAX_BUF];
  1283. X
  1284. X
  1285. X    if (term == NULL) 
  1286. X        term = getenv("TERM");
  1287. X    if (term == NULL)
  1288. X        RETERR(0, "TERM not set\n")
  1289. X
  1290. X    path = _buildpath("$TERMINFO", 2,
  1291. X              "$MYTERMINFO", 2,
  1292. X              "$TERMCAP", 1,
  1293. X#ifdef TERMINFODIR
  1294. X              TERMINFODIR, 0,
  1295. X#endif
  1296. X#ifdef TERMINFOSRC
  1297. X              TERMINFOSRC, 0,
  1298. X#endif
  1299. X#ifdef TERMCAPFILE
  1300. X              TERMCAPFILE, 0,
  1301. X#endif
  1302. X              NULL, -1);
  1303. X
  1304. X    if (path == NULL)
  1305. X        RETERR(0, "malloc error\n");
  1306. X
  1307. X    r = _fillterm(term, path, buf);
  1308. X
  1309. X    _delpath(path);
  1310. X
  1311. X    switch(r) {
  1312. X    case -3:
  1313. X        RETERR(0, "malloc error\n");
  1314. X    case -2:
  1315. X        RETERR(-1, "bad format\n");
  1316. X    case -1:
  1317. X        RETERR(-1, "database not found\n");
  1318. X    case 0:
  1319. X        RETERR(0, "terminal not found\n");
  1320. X    case 1:
  1321. X        cur_term->fd = fd;
  1322. X        _term_buf.fd = fd;
  1323. X        if (_init_tty() == ERR)
  1324. X            RETERR(0, "problem initializing tty\n");
  1325. X        if ((s = getenv("LINES")) != NULL && atoi(s) > 0) 
  1326. X            lines = atoi(s);
  1327. X        if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
  1328. X            columns = atoi(s);
  1329. X        if (err != NULL)
  1330. X            *err = 1;
  1331. X        return OK;
  1332. X    default:
  1333. X        RETERR(0, "oops...\n");
  1334. X    }
  1335. X}
  1336. X
  1337. Xint set_curterm(p)
  1338. XTERMINAL *p; {
  1339. X    cur_term = p;
  1340. X    if (_init_tty() == ERR)
  1341. X        return ERR;
  1342. X    if (_check_tty() == ERR)
  1343. X        return ERR;
  1344. X    return OK;
  1345. X}
  1346. X
  1347. Xint del_curterm(p)
  1348. XTERMINAL *p; {
  1349. X    _del_strs(p);
  1350. X    free((anyptr) p);
  1351. X
  1352. X    return OK;
  1353. X}
  1354. SHAR_EOF
  1355. chmod 0644 terminfo.c || echo "restore of terminfo.c fails"
  1356. case $TOUCH in
  1357. can)
  1358.     touch -am 0402044690 terminfo.c
  1359.     ;;
  1360. esac
  1361. set `wc -c terminfo.c`;Wc_c=$1
  1362. case "$Wc_c" in
  1363. "1903") ;;
  1364. *) echo original size 1903, current size $Wc_c ;;
  1365. esac
  1366. # ============= compar.c ==============
  1367. echo "x - extracting compar.c (Text)"
  1368. sed 's/^X//' << 'SHAR_EOF' > compar.c &&
  1369. X/*
  1370. X * compar.c
  1371. X *
  1372. X * By Ross Ridge
  1373. X * Public Domain
  1374. X * 90/03/22 03:43:32
  1375. X *
  1376. X */
  1377. X
  1378. X#include "defs.h"
  1379. X
  1380. X#ifdef USE_SCCS_IDS
  1381. Xstatic char SCCSid[] = "@(#) compar.c 1.1";
  1382. X#endif
  1383. X/* compare two elements a sorted list of pointers to strings */
  1384. Xint _compar(a, b)
  1385. Xanyptr a, b; {
  1386. X    return (strcmp(**(char ***)a, **(char ***)b));
  1387. X}
  1388. SHAR_EOF
  1389. chmod 0644 compar.c || echo "restore of compar.c fails"
  1390. case $TOUCH in
  1391. can)
  1392.     touch -am 0402044690 compar.c
  1393.     ;;
  1394. esac
  1395. set `wc -c compar.c`;Wc_c=$1
  1396. case "$Wc_c" in
  1397. "318") ;;
  1398. *) echo original size 318, current size $Wc_c ;;
  1399. esac
  1400. # ============= termcap.c ==============
  1401. echo "x - extracting termcap.c (Text)"
  1402. sed 's/^X//' << 'SHAR_EOF' > termcap.c &&
  1403. X/*
  1404. X * termcap.c
  1405. X *
  1406. X * By Ross Ridge
  1407. X * Public Domain
  1408. X * 90/03/22 03:43:33
  1409. X *
  1410. X * termcap compatibility functions
  1411. X *
  1412. X */
  1413. X
  1414. X#include "defs.h"
  1415. X#include "term.h"
  1416. X
  1417. X#ifdef USE_SCCS_IDS
  1418. Xstatic char SCCSid[] = "@(#) termcap.c 1.1";
  1419. X#endif
  1420. Xint tgetent(buf, term)
  1421. Xchar *term, *buf; {
  1422. X    char *s, *getenv();
  1423. X    struct term_path *path;
  1424. X    int r = -1;
  1425. X    int fd;
  1426. X
  1427. X    if (term == NULL) 
  1428. X        term = getenv("TERM");
  1429. X    if (term == NULL)
  1430. X        return 0;
  1431. X
  1432. X    path = _buildpath("$TERMCAP", 1,
  1433. X              "$MYTERMINFO", 2,
  1434. X              "$TERMINFO", 2,
  1435. X#ifdef TERMCAPFILE
  1436. X              TERMCAPFILE, 0,
  1437. X#endif
  1438. X#ifdef TERMINFOSRC
  1439. X              TERMINFOSRC, 0,
  1440. X#endif
  1441. X#ifdef TERMINFODIR
  1442. X              TERMINFODIR, 0,
  1443. X#endif
  1444. X              NULL, -1);
  1445. X
  1446. X    if (path == NULL)
  1447. X        return -1;
  1448. X
  1449. X    r = _fillterm(term, path, buf);
  1450. X
  1451. X    _delpath(path);
  1452. X
  1453. X    switch(r) {
  1454. X    case -3:
  1455. X    case -2:
  1456. X    case -1:
  1457. X        return -1;
  1458. X    case 0:
  1459. X        return 0;
  1460. X    case 1:
  1461. X        if (isatty(1))
  1462. X            fd = 1;
  1463. X        else if (isatty(2))
  1464. X            fd = 2;
  1465. X        else if (isatty(3))    /* V10 /dev/tty ?? */
  1466. X            fd = 3;
  1467. X        else if (isatty(0))
  1468. X            fd = 0;
  1469. X        else
  1470. X            fd = 1;
  1471. X
  1472. X        cur_term->fd = fd;
  1473. X        _term_buf.fd = fd;
  1474. X
  1475. X        if (_init_tty() == ERR)
  1476. X            return 0;
  1477. X        if ((s = getenv("LINES")) != NULL && atoi(s) > 0) 
  1478. X            lines = atoi(s);
  1479. X        if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
  1480. X            columns = atoi(s);
  1481. X        cur_term->termcap = 1;
  1482. X        return 1;
  1483. X    default:
  1484. X        return -1;
  1485. X    }
  1486. X}
  1487. X
  1488. Xextern char **_sboolcodes[], **_snumcodes[], **_sstrcodes[];
  1489. X
  1490. Xextern int _compar();
  1491. X
  1492. Xstatic char cap2[3];
  1493. Xstatic char *p2c = cap2;
  1494. Xstatic char **p2p2c = &p2c;
  1495. X
  1496. Xint tgetnum(cap)
  1497. Xchar *cap; {
  1498. X    register char ***match;
  1499. X
  1500. X    cap2[0] = cap[0]; 
  1501. X    cap2[1] = cap[1];
  1502. X    cap2[2] = '\0';
  1503. X
  1504. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _snumcodes,
  1505. X                   NUM_OF_NUMS, sizeof(char **), _compar);
  1506. X    if (match == NULL)
  1507. X        return -1;
  1508. X    return cur_term->nums[*match - numcodes];
  1509. X}
  1510. X
  1511. Xint tgetflag(cap)
  1512. Xchar *cap; {
  1513. X    register char ***match;
  1514. X
  1515. X    cap2[0] = cap[0]; 
  1516. X    cap2[1] = cap[1];
  1517. X    cap2[2] = '\0';
  1518. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sboolcodes,
  1519. X                   NUM_OF_BOOLS, sizeof(char **), _compar);
  1520. X    if (match == NULL)
  1521. X        return 0;
  1522. X    return cur_term->bools[*match - boolcodes];
  1523. X}
  1524. X
  1525. Xchar *tgetstr(cap, area)
  1526. Xchar *cap;
  1527. Xchar **area; {
  1528. X    register char *sp, *dp;
  1529. X    register char ***match;
  1530. X
  1531. X    cap2[0] = cap[0]; 
  1532. X    cap2[1] = cap[1];
  1533. X    cap2[2] = '\0';
  1534. X
  1535. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sstrcodes,
  1536. X                   NUM_OF_STRS, sizeof(char **), _compar);
  1537. X    if (match == NULL)
  1538. X        return NULL;
  1539. X    sp = cur_term->strs[*match - strcodes];
  1540. X    if (area == NULL || sp == NULL)
  1541. X        return sp;
  1542. X    dp = *area;
  1543. X    while (*sp != '\0')
  1544. X        *dp++ = *sp++;
  1545. X    *dp++ = '\0';
  1546. X    sp = *area;
  1547. X    *area = dp;
  1548. X    return sp;
  1549. X}
  1550. X
  1551. X
  1552. SHAR_EOF
  1553. chmod 0644 termcap.c || echo "restore of termcap.c fails"
  1554. case $TOUCH in
  1555. can)
  1556.     touch -am 0402044690 termcap.c
  1557.     ;;
  1558. esac
  1559. set `wc -c termcap.c`;Wc_c=$1
  1560. case "$Wc_c" in
  1561. "2565") ;;
  1562. *) echo original size 2565, current size $Wc_c ;;
  1563. esac
  1564. # ============= tputs.c ==============
  1565. echo "x - extracting tputs.c (Text)"
  1566. sed 's/^X//' << 'SHAR_EOF' > tputs.c &&
  1567. X/*
  1568. X * tputs.c
  1569. X *
  1570. X * By Ross Ridge
  1571. X * Public Domain
  1572. X * 90/03/27 18:29:20
  1573. X *
  1574. X * Output a terminal capability string with any needed padding
  1575. X *
  1576. X */
  1577. X
  1578. X#include "defs.h"
  1579. X#include "term.h"
  1580. X
  1581. X#include <ctype.h>
  1582. X
  1583. X#ifdef USE_SCCS_IDS
  1584. Xstatic char SCCSid[] = "@(#) tputs.c 1.2";
  1585. X#endif
  1586. X#ifdef TEST
  1587. X#define def_prog_mode()    (OK)
  1588. X#define _norm_output()    ((void)(0))
  1589. X#define _lit_output()    (1)
  1590. X#endif
  1591. X
  1592. X/*
  1593. X * BITSPERCHAR (as actually transmitted over a serial line) is usually 10
  1594. X * (not 8). 1 stop bit, 1 start bit, 7 data bits, and one parity bit.
  1595. X */
  1596. X
  1597. X#define BITSPERCHAR    10
  1598. X
  1599. X#ifdef USE_FAKE_STDIO
  1600. X#undef putchar
  1601. X#endif
  1602. X
  1603. X#define PUTCHAR(c) (outc == (int (*)()) 0 ? (putchar(c)):(*outc)(c))
  1604. X
  1605. Xint tputs(sp, count, outc)
  1606. Xregister char *sp;
  1607. Xint count;
  1608. Xregister int (*outc)();
  1609. X{
  1610. X    register int l;
  1611. X    register long cnt;
  1612. X    int must_pad, multiply_pad;
  1613. X    int forced_lit = 0;
  1614. X
  1615. X    if (cur_term->termcap) {
  1616. X        _figure_termcap();
  1617. X    }
  1618. X
  1619. X    while(*sp != '\0') {
  1620. X        switch(*sp) {
  1621. X        case '\\':
  1622. X            switch(*++sp) {
  1623. X            case 'n': PUTCHAR('\n'); sp++; break;
  1624. X            case 'b': PUTCHAR('\b'); sp++; break;
  1625. X            case 't': PUTCHAR('\t'); sp++; break;
  1626. X            case 'r': PUTCHAR('\r'); sp++; break;
  1627. X            case 'f': PUTCHAR('\f'); sp++; break;
  1628. X            case 'l': PUTCHAR('\012'); sp++; break;
  1629. X            case 's': PUTCHAR(' '); sp++; break;
  1630. X            case 'e': case 'E': PUTCHAR('\033'); sp++; break;
  1631. X
  1632. X            case '^':
  1633. X            case '\\':
  1634. X            case ',':
  1635. X            case ':':
  1636. X            case '\'':
  1637. X            case '$':
  1638. X                PUTCHAR(*sp++);
  1639. X                break;
  1640. X
  1641. X            case '0':
  1642. X                if (*(sp + 1) < '0' || *(sp + 1) > '7') {
  1643. X                    PUTCHAR('\200'); /* I'd prefer \0 */
  1644. X                    sp++;
  1645. X                    break;
  1646. X                }
  1647. X                ;/* FALLTHROUGH */
  1648. X            case '1': case '2': case '3': case '4':
  1649. X            case '5': case '6': case '7':
  1650. X                l = *sp++ - '0';
  1651. X                if (*sp >= '0' && *sp <= '7') {
  1652. X                    l = l * 8 + (*sp++ - '0');
  1653. X                    if (*sp >= '0' && *sp <= '7')
  1654. X                        l = l * 8 + (*sp++ - '0');
  1655. X                }
  1656. X                PUTCHAR(l);
  1657. X                break;
  1658. X
  1659. X            case '\0':
  1660. X                PUTCHAR('\\');
  1661. X                break;
  1662. X
  1663. X            case '@':
  1664. X                if (!forced_lit)
  1665. X                    forced_lit = _lit_output();
  1666. X                sp++;
  1667. X                break;
  1668. X
  1669. X            default:
  1670. X                PUTCHAR('\\');
  1671. X                PUTCHAR(*sp++);
  1672. X                break;
  1673. X            }
  1674. X            break;
  1675. X        case '^':
  1676. X            if (*++sp == '\0')
  1677. X                break;
  1678. X            l = *sp - '@';
  1679. X            if (l > 31)
  1680. X                l -= 32;
  1681. X            if (l < 0 || l > 31) {
  1682. X                PUTCHAR('^');
  1683. X                PUTCHAR(*sp++);
  1684. X            } else {
  1685. X                PUTCHAR(l);
  1686. X                sp++;
  1687. X            }
  1688. X            break;
  1689. X        case '$':
  1690. X            if (*++sp != '<') {
  1691. X                PUTCHAR('$');
  1692. X                break;
  1693. X            }
  1694. X            must_pad = 0;
  1695. X            multiply_pad = 0;
  1696. X            l = 0;
  1697. X            sp++;
  1698. X            while (isdigit(*sp))
  1699. X                l = l * 10 + (*sp++ - '0');
  1700. X            l *= 10;
  1701. X            if (*sp == '.') {
  1702. X                sp++;
  1703. X                if (isdigit(*sp))
  1704. X                    l += *sp++ - '0';
  1705. X            }
  1706. X            if (*sp == '/') {
  1707. X                must_pad = 1;
  1708. X                if (*++sp == '*') {
  1709. X                    multiply_pad = 1;
  1710. X                    sp++;
  1711. X                }
  1712. X            } else if (*sp == '*') {
  1713. X                multiply_pad = 1;
  1714. X                if (*++sp == '/') {
  1715. X                    must_pad = 1;
  1716. X                    sp++;
  1717. X                }
  1718. X            }
  1719. X            if (*sp != '>') {
  1720. X                PUTCHAR('p');
  1721. X                PUTCHAR('a');
  1722. X                PUTCHAR('d');
  1723. X                PUTCHAR('?');
  1724. X                break;
  1725. X            }
  1726. X            sp++;
  1727. X#ifdef TEST
  1728. X            printf("\nl = %d", l);
  1729. X#endif
  1730. X            if (cur_term->pad || must_pad) {
  1731. X                cnt = ((long) l * cur_term->baudrate * (multiply_pad ? count : 1) + (10000 * BITSPERCHAR / 2)) / (10000 * BITSPERCHAR);
  1732. X#ifdef TEST
  1733. X                printf("; cnt = %d\n", cnt);
  1734. X#endif
  1735. X                while(cnt--)
  1736. X                    PUTCHAR(cur_term->padch);
  1737. X            }
  1738. X#ifdef TEST
  1739. X            printf("\n");
  1740. X#endif
  1741. X            break;
  1742. X        default:
  1743. X            PUTCHAR(*sp++);
  1744. X        }
  1745. X    }
  1746. X    if (forced_lit)
  1747. X        _norm_output();
  1748. X    return OK;
  1749. X}
  1750. X
  1751. Xint putp(str)
  1752. Xchar *str; {
  1753. X    return(tputs(str, 1,(int (*)()) 0));
  1754. X}
  1755. X
  1756. X#ifdef TEST
  1757. X
  1758. XTERMINAL test_term, *cur_term = &test_term;
  1759. X
  1760. Xvoid putch(c)
  1761. Xint c; {
  1762. X    c &= 0xff;
  1763. X    if (c > 127 || c < 0) {
  1764. X        printf("\\%03o", c);
  1765. X    } else if (c < 32) {
  1766. X        printf("^%c", c + '@');
  1767. X    } else if (c == 127) {
  1768. X        printf("^?");
  1769. X    } else {
  1770. X        putchar(c);
  1771. X    }
  1772. X}
  1773. X
  1774. Xchar line[MAX_LINE];
  1775. X
  1776. Xint main(argc, argv)
  1777. Xint argc;
  1778. Xchar **argv; {
  1779. X    test_term.termcap = 0;
  1780. X    test_term.baudrate = 1200;
  1781. X    test_term.pad = 0;
  1782. X    test_term.padch = 0;
  1783. X    if (argc > 1) 
  1784. X        test_term.baudrate = atoi(argv[1]);
  1785. X    if (argc > 2)
  1786. X        test_term.padch = argv[2][0];
  1787. X    if (argc > 3)
  1788. X        test_term.pad = 1;
  1789. X
  1790. X    putchar('\n');
  1791. X
  1792. X    while(gets(line) != NULL) {
  1793. X        tputs(line, 7, putch);
  1794. X        putchar('\n');
  1795. X    }
  1796. X    return 0;
  1797. X}
  1798. X#endif
  1799. SHAR_EOF
  1800. chmod 0644 tputs.c || echo "restore of tputs.c fails"
  1801. case $TOUCH in
  1802. can)
  1803.     touch -am 0402044690 tputs.c
  1804.     ;;
  1805. esac
  1806. set `wc -c tputs.c`;Wc_c=$1
  1807. case "$Wc_c" in
  1808. "4051") ;;
  1809. *) echo original size 4051, current size $Wc_c ;;
  1810. esac
  1811. # ============= tty.c ==============
  1812. echo "x - extracting tty.c (Text)"
  1813. sed 's/^X//' << 'SHAR_EOF' > tty.c &&
  1814. X/*
  1815. X * tty.c
  1816. X *
  1817. X * By Ross Ridge
  1818. X * Public Domain
  1819. X * 90/03/22 03:43:34
  1820. X *
  1821. X * Do some tty related things
  1822. X *
  1823. X */
  1824. X
  1825. X#include "defs.h"
  1826. X#include "term.h"
  1827. X
  1828. X#ifdef USE_SCCS_IDS
  1829. Xstatic char SCCSid[] = "@(#) tty.c 1.1";
  1830. X#endif
  1831. X#ifndef EXTA_IS
  1832. X#define EXTA_IS 19200
  1833. X#endif
  1834. X
  1835. X#ifndef EXTB_IS
  1836. X#define EXTB_IS 38400
  1837. X#endif
  1838. X
  1839. X#ifdef lint
  1840. X#define ioctl _ioctl
  1841. X/* shutup lint */
  1842. X/* ARGSUSED */
  1843. X/* VARARGS2 */
  1844. Xint ioctl(a, b, p) int a; long b; anyptr *p;  { return 0; }
  1845. X#endif
  1846. X
  1847. X#ifdef USE_TERMIO
  1848. X
  1849. X#ifdef USE_SMALLMEM
  1850. Xunsigned short _baud_tbl[] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  1851. X                  1800, 2400, 4800, 9600, EXTA_IS, EXTB_IS};
  1852. X#else
  1853. Xlong _baud_tbl[] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800,
  1854. X            2400, 4800, 9600, EXTA_IS, EXTB_IS};
  1855. X#endif
  1856. X
  1857. Xstatic struct termio old;
  1858. X
  1859. Xint _lit_output() {
  1860. X    struct termio tmp;
  1861. X    ioctl(cur_term->fd, TCGETA, &old);
  1862. X    if (!(old.c_oflag & OPOST) || !(old.c_oflag & ONLCR)) 
  1863. X        return 0;
  1864. X    memcpy((anyptr)&tmp, (anyptr)&old, sizeof(old));
  1865. X    tmp.c_oflag &= ~OPOST;
  1866. X    ioctl(cur_term->fd, TCSETA, &tmp);
  1867. X        return 0;
  1868. X}
  1869. X
  1870. Xvoid _norm_output() {
  1871. X    ioctl(cur_term->fd, TCSETA, &old);
  1872. X}
  1873. X    
  1874. Xint _check_tty() {
  1875. X    if ((cur_term->prog_mode.c_iflag & IXON) && cur_term->xon)
  1876. X        cur_term->pad = 0;
  1877. X    else
  1878. X        cur_term->pad = 1;
  1879. X    cur_term->baudrate = _baud_tbl[cur_term->prog_mode.c_cflag & CBAUD];
  1880. X    return OK;
  1881. X}
  1882. X
  1883. Xint def_prog_mode() {
  1884. X    if (ioctl(cur_term->fd, TCGETA, &cur_term->prog_mode) == 0
  1885. X            && _check_tty() == OK)
  1886. X        return OK;
  1887. X    return ERR;
  1888. X}
  1889. X
  1890. Xint def_shell_mode() {
  1891. X    cur_term->termcap = 0;
  1892. X    return ioctl(cur_term->fd, TCGETA, &cur_term->shell_mode)==0 ? OK : ERR;
  1893. X}
  1894. X
  1895. Xint reset_prog_mode() {
  1896. X    return ioctl(cur_term->fd, TCSETA, &cur_term->prog_mode)==0 ? OK : ERR;
  1897. X}
  1898. X
  1899. Xint reset_shell_mode() {
  1900. X    return ioctl(cur_term->fd, TCSETA, &cur_term->shell_mode)==0 ? OK : ERR;
  1901. X}
  1902. X
  1903. Xint _init_tty() {
  1904. X    cur_term->true_lines = lines;
  1905. X    cur_term->true_columns = columns;
  1906. X    if (pad_char == NULL)
  1907. X        cur_term->padch = '\000';
  1908. X    else
  1909. X        cur_term->padch = pad_char[0];
  1910. X    cur_term->xon = xon_xoff && (xon_character == NULL || xon_character[0] == '\023') && (xoff_character == NULL || xoff_character[0] == '\021');
  1911. X    return def_shell_mode()==ERR ? ERR : def_prog_mode()==ERR ? ERR : OK;
  1912. X}
  1913. X
  1914. X#else
  1915. X
  1916. X#ifdef USE_SGTTY
  1917. X
  1918. X#ifdef USE_SMALLMEM
  1919. Xunsigned short _baud_tbl[] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  1920. X                  1800, 2400, 4800, 9600, EXTA_IS, EXTB_IS};
  1921. X#else
  1922. Xlong _baud_tbl[] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  1923. X            1800, 2400, 4800, 9600, EXTA_IS, EXTB_IS};
  1924. X#endif
  1925. X
  1926. X
  1927. X#ifdef TIOCLGET
  1928. X
  1929. Xstatic int old;
  1930. X
  1931. Xint _lit_output() {
  1932. X    struct sgttyb buf;
  1933. X    int tmp;
  1934. X
  1935. X    ioctl(cur_term->fd, TIOCGETP, &buf);
  1936. X    if (buf.sg_flags & RAW)
  1937. X        return 0;
  1938. X    ioctl(cur_term->fd, TIOCLGET, &old);
  1939. X    if (old & LLITOUT)
  1940. X        return 0;
  1941. X    tmp = old | LLITOUT;
  1942. X    ioctl(cur_term->fd, TIOCLSET, &tmp);
  1943. X    return 1;
  1944. X}
  1945. X
  1946. Xvoid _norm_output() {
  1947. X    ioctl(cur_term->fd, TIOCLSET, &old);
  1948. X}
  1949. X
  1950. X#else
  1951. X
  1952. Xstatic struct sgttyb old;
  1953. X
  1954. Xint _lit_output() {
  1955. X    struct sgttyb tmp;
  1956. X    ioctl(cur_term->fd, TIOCGETP, &old);
  1957. X    if (old.sg_flags & RAW)
  1958. X        return 0;
  1959. X    memcpy((anyptr)&tmp, (anyptr)&old, sizeof(old));
  1960. X    tmp.sg_flags |= RAW;
  1961. X    ioctl(cur_term->fd, TIOCSETP, &tmp);
  1962. X    return 1;
  1963. X}
  1964. X
  1965. Xvoid _norm_output() {
  1966. X    ioctl(cur_term->fd, TIOCSETP, &old);
  1967. X}
  1968. X
  1969. X#endif 
  1970. X
  1971. Xint _check_tty() {
  1972. X    if (!(cur_term->prog_mode.v6.sg_flags & RAW) && cur_term->xon)
  1973. X        cur_term->pad = 0;
  1974. X    else
  1975. X        cur_term->pad = 1;
  1976. X    cur_term->baudrate = _baud_tbl[cur_term->prog_mode.v6.sg_ospeed & 0xf];
  1977. X    return OK;
  1978. X}
  1979. X
  1980. Xint def_shell_mode() {
  1981. X    if (ioctl(cur_term->fd, TIOCGETP, &cur_term->shell_mode.v6) < 0)
  1982. X        return ERR;
  1983. X#ifdef TIOCGETC
  1984. X    if (ioctl(cur_term->fd, TIOCGETC, &cur_term->shell_mode.v7) < 0)
  1985. X        return ERR;
  1986. X#endif
  1987. X#ifdef TIOCLGET
  1988. X    if (ioctl(cur_term->fd, TIOCLGET, &cur_term->shell_mode.bsd) < 0)
  1989. X        return ERR;
  1990. X#endif
  1991. X#ifdef TIOCGLTC
  1992. X    if (ioctl(cur_term->fd, TIOCGLTC, &cur_term->shell_mode.bsd_new) < 0)
  1993. X        return ERR;
  1994. X#endif
  1995. X#ifdef USE_WINSZ
  1996. X#ifdef TIOCGWINSZ
  1997. X    if (ioctl(cur_term->fd, TIOCGWINSZ, &cur_term->shell_mode.bsd_winsz)<0)
  1998. X        return ERR;
  1999. X#endif
  2000. X#endif
  2001. X    cur_term->termcap = 0;
  2002. X    return OK;
  2003. X}
  2004. X
  2005. Xint def_prog_mode() {
  2006. X    if (ioctl(cur_term->fd, TIOCGETP, &cur_term->prog_mode.v6) < 0)
  2007. X        return ERR;
  2008. X#ifdef TIOCGETC
  2009. X    if (ioctl(cur_term->fd, TIOCGETC, &cur_term->prog_mode.v7) < 0)
  2010. X        return ERR;
  2011. X#endif
  2012. X#ifdef TIOCLGET
  2013. X    if (ioctl(cur_term->fd, TIOCLGET, &cur_term->prog_mode.bsd) < 0)
  2014. X        return ERR;
  2015. X#endif
  2016. X#ifdef TIOCGLTC
  2017. X    if (ioctl(cur_term->fd, TIOCGLTC, &cur_term->prog_mode.bsd_new) < 0)
  2018. X        return ERR;
  2019. X#endif
  2020. X#ifdef USE_WINSZ
  2021. X#ifdef TIOCGWINSZ
  2022. X    if (ioctl(cur_term->fd, TIOCGWINSZ, &cur_term->prog_mode.bsd_winsz)<0)
  2023. X        return ERR;
  2024. X#endif
  2025. X#endif
  2026. X    return _check_tty();
  2027. X}
  2028. X
  2029. Xint reset_shell_mode() {
  2030. X    if (ioctl(cur_term->fd, TIOCSETP, &cur_term->shell_mode.v6) < 0)
  2031. X        return ERR;
  2032. X#ifdef TIOCGETC
  2033. X    if (ioctl(cur_term->fd, TIOCSETC, &cur_term->shell_mode.v7) < 0)
  2034. X        return ERR;
  2035. X#endif
  2036. X#ifdef TIOCLGET
  2037. X    if (ioctl(cur_term->fd, TIOCLSET, &cur_term->shell_mode.bsd) < 0)
  2038. X        return ERR;
  2039. X#endif
  2040. X#ifdef TIOCGLTC
  2041. X    if (ioctl(cur_term->fd, TIOCSLTC, &cur_term->shell_mode.bsd_new) < 0)
  2042. X        return ERR;
  2043. X#endif
  2044. X    return OK;
  2045. X}
  2046. SHAR_EOF
  2047. echo "End of tinfo part 1"
  2048. echo "File tty.c is continued in part 2"
  2049. echo "2" > s3_seq_.tmp
  2050. exit 0
  2051. -- 
  2052. Ross Ridge                                 //
  2053. "The Great HTMU"                            [oo]
  2054. ross@contact.uucp                            -()-
  2055. ross@watcsc.waterloo.edu                         //
  2056.  
  2057.  
  2058.