home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sources / unix / 276 next >
Encoding:
Text File  |  1992-12-27  |  106.0 KB  |  4,781 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!decwrl!pa.dec.com!vixie
  2. From: ross@zooid.guild.org (Ross Ridge)
  3. Newsgroups: comp.sources.unix
  4. Subject: v26i077: mytinfo - a replacement for terminfo and termcap, Part01/03
  5. Date: 27 Dec 1992 22:50:29 GMT
  6. Organization: Digital Equipment Corporation Palo Alto, CA
  7. Lines: 4767
  8. Sender: unix-sources-moderator@pa.dec.com
  9. Approved: vixie@pa.dec.com
  10. Message-ID: <1hlbvlINN74r@usenet.pa.dec.com>
  11. NNTP-Posting-Host: cognition.pa.dec.com
  12. Originator: vixie@cognition.pa.dec.com
  13.  
  14. Submitted-By: ross@zooid.guild.org (Ross Ridge)
  15. Posting-Number: Volume 26, Issue 77
  16. Archive-Name: mytinfo/part01
  17.  
  18. Mytinfo is Public Domain and comes with no guarantees.
  19. By Ross Ridge (ross@zooid.guild.org).
  20.  
  21. Mytinfo is a single library that combines the functionality of the
  22. standard Unix termcap and terminfo libraries.  It has the special
  23. ability of being able to fetch terminal descriptions from both
  24. termcap and terminfo databases regardless of which set of functions,
  25. termcap or terminfo, are used.  It can even read terminal descriptions
  26. from terminfo source files. 
  27.  
  28. #! /bin/sh
  29. # This is a shell archive.  Remove anything before this line, then unpack
  30. # it by saving it into a file and typing "sh file".  To overwrite existing
  31. # files, type "sh file -c".  You can also feed this as standard input via
  32. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  33. # will see the following message at the end:
  34. #        "End of archive 1 (of 3)."
  35. # Contents:  DECL MANIFEST README README.doc TODO addstr.c bin_order
  36. #   bsearch.c buildpath.c caps.c clear.c compar.c config.h defs.h
  37. #   fake_stdio.c fake_stdio.h fillterm.c findcap.c getother.c
  38. #   gettbin.c mkbinorder.c mkcaplist.c mkcapsort.c mkdir.c
  39. #   mktermhead.c mkversion.c quit.c readcaps.c strtok.c tcapvars.c
  40. #   tconv.1 term.tail termcap.c terminfo.c terminfo.src tgoto.c
  41. #   tiget.c tmatch.c tput.c tputs.c version.h
  42. # Wrapped by vixie@cognition.pa.dec.com on Sun Dec 27 14:45:19 1992
  43. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  44. if test -f 'DECL' -a "${1}" != "-c" ; then 
  45.   echo shar: Will not clobber existing file \"'DECL'\"
  46. else
  47. echo shar: Extracting \"'DECL'\" \(483 characters\)
  48. sed "s/^X//" >'DECL' <<'END_OF_FILE'
  49. int setupterm(char *, int, int *);
  50. int set_curterm(TERMINAL *);
  51. int del_curterm(TERMINAL *);
  52. char *tparm(char *, ...);
  53. int tputs(char *, int, int (*)());
  54. int putp(char *);
  55. int def_prog_mode(void);
  56. int def_shell_mode(void);
  57. int reset_prog_mode(void);
  58. int reset_shell_mode(void);
  59. int tigetnum(char *);
  60. int tigetflag(char *);
  61. char *tigetstr(char *);
  62. int tgetent(char *, char *);
  63. int tgetnum(char *);
  64. int tgetflag(char *);
  65. char *tgetstr(char *, char * *);
  66. char *tgoto(char *, int, int);
  67. END_OF_FILE
  68. if test 483 -ne `wc -c <'DECL'`; then
  69.     echo shar: \"'DECL'\" unpacked with wrong size!
  70. fi
  71. # end of 'DECL'
  72. fi
  73. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  74.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  75. else
  76. echo shar: Extracting \"'MANIFEST'\" \(1832 characters\)
  77. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  78. X   File Name        Archive #    Description
  79. X-----------------------------------------------------------
  80. X DECL                       1    
  81. X DIFFS-moderator            2    
  82. X INSTALL                    2    
  83. X MANIFEST                   1    
  84. X Makefile                   2    
  85. X README                     1    
  86. X README.doc                 1    
  87. X TODO                       1    
  88. X addstr.c                   1    
  89. X bin_order                  1    
  90. X bsearch.c                  1    
  91. X buildpath.c                1    
  92. X cap_list                   2    
  93. X caps.c                     1    
  94. X clear.c                    1    
  95. X compar.c                   1    
  96. X config.h                   1    
  97. X defs.h                     1    
  98. X fake_stdio.c               1    
  99. X fake_stdio.h               1    
  100. X fillterm.c                 1    
  101. X findcap.c                  1    
  102. X findterm.c                 2    
  103. X getother.c                 1    
  104. X gettbin.c                  1    
  105. X gettcap.c                  2    
  106. X gettinfo.c                 2    
  107. X mkbinorder.c               1    
  108. X mkcaplist.c                1    
  109. X mkcapsort.c                1    
  110. X mkdir.c                    1    
  111. X mktermhead.c               1    
  112. X mkversion.c                1    
  113. X qsort.c                    2    
  114. X quit.c                     1    
  115. X readcaps.c                 1    
  116. X sprintf.c                  2    
  117. X strtok.c                   1    
  118. X tcapconv.c                 2    
  119. X tcapvars.c                 1    
  120. X tconv.1                    1    
  121. X tconv.c                    3    
  122. X term.tail                  1    
  123. X termcap.c                  1    
  124. X terminfo.c                 1    
  125. X terminfo.src               1    
  126. X tgoto.c                    1    
  127. X tiget.c                    1    
  128. X tmatch.c                   1    
  129. X tparm.c                    3    
  130. X tput.c                     1    
  131. X tputs.c                    1    
  132. X tset.c                     3    
  133. X ttest.c                    2    
  134. X tty.c                      2    
  135. X version.h                  1    
  136. END_OF_FILE
  137. if test 1832 -ne `wc -c <'MANIFEST'`; then
  138.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  139. fi
  140. # end of 'MANIFEST'
  141. fi
  142. if test -f 'README' -a "${1}" != "-c" ; then 
  143.   echo shar: Will not clobber existing file \"'README'\"
  144. else
  145. echo shar: Extracting \"'README'\" \(4032 characters\)
  146. sed "s/^X//" >'README' <<'END_OF_FILE'
  147. Mytinfo is Public Domain and comes with no guarantees.
  148. By Ross Ridge (ross@zooid.guild.org).
  149. X
  150. Mytinfo is a single library that combines the functionality of the
  151. standard Unix termcap and terminfo libraries.  It has the special
  152. ability of being able to fetch terminal descriptions from both
  153. termcap and terminfo databases regardless of which set of functions,
  154. termcap or terminfo, are used.  It can even read terminal descriptions
  155. from terminfo source files. 
  156. X
  157. You should be able to compile this library on almost all versions of Unix.
  158. Much of it's development was done on '386 Xenix, but I've sucessfuly built
  159. mytinfo under BSD 4.3, HP-UX 2.1 (System III), SunOS 3.5, and Amix
  160. X(System V R4).  There hasn't been a large amount of testing of the support
  161. programmes that come with the library, but the library itself has been in
  162. use on a couple of public access Unix sites for over two years.  It has
  163. successfully linked and run with many programmes such as rn, vi and nethack.
  164. X
  165. Included in the package is tconv, an "all-in-one" programme that will
  166. compile terminfo sources to binary format and also translate termcap to
  167. either terminfo source or binary.  tic and cap2info are just links
  168. to the tconv programme.  I've also written replacement for tset,
  169. that uses the mytinfo library, in case tset doesn't come with your
  170. system or if you aren't too pleased with the one that did.  Since this
  171. is the newest part of the package it probably still has a few bugs.
  172. You'll also find tput, as well two versions of clear, one that uses
  173. termcap and the other that uses terminfo.
  174. X
  175. The environment variables TERMCAP and TERMINFO can have multiple
  176. filenames separated by a space, a feature not in terminfo and not in
  177. most termcaps.  This is very handy for users that maintain their own
  178. private databases, as they don't have to have a copy the entire
  179. database.  Eg:
  180. X    TERMCAP="$HOME/.termcap /etc/termcap"
  181. X    TERMINFO="$HOME/terminfo /usr/lib/terminfo"
  182. X    export TERMCAP TERMINFO
  183. The library will also check compiled-in default locations for terminal
  184. descriptions.  Like most termcaps, the TERMCAP variable can also
  185. contain the complete termcap terminal description, usually supplied
  186. from tset at login.  The TERMINFO variable can also contain a complete
  187. terminfo description, but there is no programme like tset to supply it.
  188. X
  189. Unlike termcap, this library can only use capabilities that it knows about.
  190. However it does knows about all the standard ones, and you can easily
  191. add your own to it's list.  Included in the list are all terminfo
  192. capabilities to Release 4 of System V, obsolete termcap capabilities, a
  193. few caps used from the University of Waterloo (UW), a couple from GNU Emacs,
  194. and a few I made up myself. Two extensions to the standard termcap % codes
  195. are supported, GNU's %a, %m, %b, and %f, and UW's %-, %a, and %s.
  196. X
  197. Termcap and terminfo source descriptions can be mixed in one file, but
  198. because of this termcap databases must be in a certain style.  All
  199. continuation lines of a termcap entry must be indented from the left
  200. margin by white space.  This shouldn't be a problem with most sites
  201. since this is the style that most termcap files are distributed, but local
  202. additions may not adhere to this style.  Another possible problem is
  203. that termcap entries should end with a colon (:), but in most
  204. distributed termcaps there are entries that don't.  If a one line
  205. termcap entry doesn't end with a colon, it will be ignored.  A quick
  206. way to find these is "tconv -c /etc/termcap > /dev/null".
  207. X
  208. See the file INSTALL for instructions on configuring and installing
  209. this library. The file README.doc lists the functions supported by the
  210. library, and gives short description of the tconv programme.  tconv.1 is
  211. a simple man page for tconv.  terminfo.src contains a few sample
  212. terminal descriptions in terminfo source format.  TODO is a list of
  213. possible enhancements too the library, your comments and additions
  214. are welcome.
  215. X
  216. Please let me know of any bugs you find, as well as any ideas you have
  217. for improvement.
  218. X
  219. Ross Ridge
  220. X
  221. ross@zooid.guild.org
  222. END_OF_FILE
  223. if test 4032 -ne `wc -c <'README'`; then
  224.     echo shar: \"'README'\" unpacked with wrong size!
  225. fi
  226. # end of 'README'
  227. fi
  228. if test -f 'README.doc' -a "${1}" != "-c" ; then 
  229.   echo shar: Will not clobber existing file \"'README.doc'\"
  230. else
  231. echo shar: Extracting \"'README.doc'\" \(4738 characters\)
  232. sed "s/^X//" >'README.doc' <<'END_OF_FILE'
  233. X----------------------------------------------------------------------------
  234. tconv [-b] [-c [-OUGd]] [-i] [-B [-D dir]] [-I] [-k] [-t term] [file]
  235. tic [file]
  236. cap2info [-t term] [-OUGdk] [file]
  237. X
  238. X-c        convert from termcap
  239. X-i        convert from terminfo source
  240. X-b        convert from terminfo binary
  241. X-B        convert to terminfo binary
  242. X-I        convert to terminfo source
  243. X
  244. The following switches are available when converting from termcap:
  245. X-d        don't supply any defaults for missing capabilities
  246. X-O        include obsolete termcap capabilities
  247. X-G        include GNU capabilities
  248. X-U        include UW capabilities
  249. X
  250. X-k        keep comments
  251. X-D dir        directory to put terminfo binaries in
  252. X
  253. X-t term        name of terminal to translate
  254. file        filename of termcap/terminfo database to use 
  255. X
  256. If a file is specifed and no terminal is given the entire file we be translated.
  257. If no terminal and no file is specified then the terminal name will be taken
  258. from the environment varible TERM. Unless compiling to a terminfo binary,
  259. output is to stdout.
  260. X----------------------------------------------------------------------------
  261. X
  262. char *tparm(char *str, ...);    /* up to nine parameters */
  263. char *tgoto(char *str, int column, int row);
  264. X
  265. tparm and tgoto support the following termcap and terminfo % codes:
  266. X
  267. Terminfo % Codes
  268. X
  269. X    %%    output a '%'
  270. X    %[[:][-+# ][width][.precision]][doxXs]
  271. X        output pop according to the printf format
  272. X    %c    output pop as a char
  273. X    %'c'    push character constant c.
  274. X    %{n}    push decimal constant n.
  275. X    %p[1-9] push paramter [1-9]
  276. X    %g[a-z] push variable [a-z]
  277. X    %P[a-z] put pop in variable [a-z]
  278. X    %l    push the length of pop (a string)
  279. X    %+    add pop to pop and push the result
  280. X    %-    subtract pop from pop and push the result
  281. X    %*    multiply pop and pop and push the result
  282. X    %&    bitwise and pop and pop and push the result
  283. X    %|    bitwise or pop and pop and push the result
  284. X    %^    bitwise xor pop and pop and push the result
  285. X    %~    push the bitwise not of pop
  286. X    %=    compare if pop and pop are equal and push the result
  287. X    %>    compare if pop is less than pop and push the result
  288. X    %<    compare if pop is greater than pop and push the result
  289. X    %A    logical and pop and pop and push the result
  290. X    %O    logical or pop and pop and push the result
  291. X    %!    push the logical not of pop
  292. X    %? condition %t if_true [%e if_false] %;
  293. X        if condtion evaulates as true then evaluate if_true,
  294. X        else evaluate if_false. elseif's can be done:
  295. X%? cond %t true [%e cond2 %t true2] ... [%e condN %t trueN] [%e false] %;
  296. X    %i    add one to parameters 1 and 2. (ANSI)
  297. X
  298. Termcap Codes
  299. X
  300. X    %%    output a %
  301. X    %.    output parameter as a character
  302. X    %d    output parameter as a decimal number
  303. X    %2    output parameter in printf format %02d
  304. X    %3    output parameter in printf format %03d
  305. X    %+x    add the character x to parameter and output it as a character
  306. X(UW)    %-x    subtract parameter FROM the character x and output it as a char
  307. X(UW)    %ax    add the character x to parameter
  308. X(GNU)    %a[+*-/=][cp]x
  309. X        GNU arithmetic. 
  310. X(UW)    %sx    subtract parameter FROM the character x
  311. X    %>xy    if parameter > character x then add character y to parameter
  312. X    %B    convert to BCD (parameter = (parameter/10)*16 + parameter%16)
  313. X    %D    Delta Data encode (parameter = parameter - 2*(paramter%16))
  314. X    %i    increment the first two parameters by one
  315. X    %n    xor the first two parameters by 0140
  316. X(GNU)    %m    xor the first two parameters by 0177
  317. X    %r    swap the first two parameters
  318. X(GNU)    %b    backup to previous parameter
  319. X(GNU)    %f    skip this parameter
  320. X
  321. X(GNU) used by GNU Emacs termcap libraries
  322. X(UW) used by the University of Waterloo (MFCF) termcap libraries
  323. X
  324. Note the two definitions of %a, the GNU defintion is used if the characters
  325. after the 'a' are valid for it, otherwise the UW definition is used.
  326. X----------------------------------------------------------------------------
  327. X
  328. int setupterm(char *term; int fd; int *err);
  329. int set_curterm(TERMINAL *new);
  330. int del_curterm(TERMINAL *old);
  331. char *tparm(char *str, ...);        /* see above */
  332. int tputs(char *str, int count, int (*putc)());
  333. int putp(str);
  334. int tigetflag(char *cap);
  335. int tigetnum(char *cap);
  336. char *tigetstr(char *cap);
  337. int def_prog_mode();
  338. int def_shell_mode();
  339. int reset_prog_mode();
  340. int reset_shell_mode();
  341. char *boolnames[], *boolcodes[], *boolfnames[];
  342. char *numnames[], *numcodes[], *numfnames[];
  343. char *strnames[], *strcodes[], *strfnames[];
  344. X
  345. These functions work just like the terminfo functions. Note restartterm(),
  346. vidputs(), vidattr(), and mvcur() are not available.
  347. X----------------------------------------------------------------------------
  348. X
  349. int tgetent(char *buf, char *term);
  350. int tgetflag(char *cap);
  351. int tgetnum(char *cap);
  352. char *tgetstr(char *cap, char **area);
  353. char *tgoto(char *cap, int column, int row);
  354. int tputs(char *str, int count, int (*putc)());
  355. X
  356. These functions work just like termcap functions.
  357. X----------------------------------------------------------------------------
  358. END_OF_FILE
  359. if test 4738 -ne `wc -c <'README.doc'`; then
  360.     echo shar: \"'README.doc'\" unpacked with wrong size!
  361. fi
  362. # end of 'README.doc'
  363. fi
  364. if test -f 'TODO' -a "${1}" != "-c" ; then 
  365.   echo shar: Will not clobber existing file \"'TODO'\"
  366. else
  367. echo shar: Extracting \"'TODO'\" \(85 characters\)
  368. sed "s/^X//" >'TODO' <<'END_OF_FILE'
  369. X- docs, docs, docs
  370. X- rewrite tparm so it's no so disgusting
  371. X- better string handling
  372. END_OF_FILE
  373. if test 85 -ne `wc -c <'TODO'`; then
  374.     echo shar: \"'TODO'\" unpacked with wrong size!
  375. fi
  376. # end of 'TODO'
  377. fi
  378. if test -f 'addstr.c' -a "${1}" != "-c" ; then 
  379.   echo shar: Will not clobber existing file \"'addstr.c'\"
  380. else
  381. echo shar: Extracting \"'addstr.c'\" \(1523 characters\)
  382. sed "s/^X//" >'addstr.c' <<'END_OF_FILE'
  383. X/*
  384. X * addstr.c
  385. X *
  386. X * By Ross Ridge
  387. X * Public Domain
  388. X * 92/02/01 07:34:01
  389. X *
  390. X */
  391. X
  392. X#include "defs.h"
  393. X#include "term.h"
  394. X
  395. X#include <ctype.h>
  396. X
  397. X#ifdef USE_SCCS_IDS
  398. static char const SCCSid[] = "@(#) mytinfo addstr.c 3.2 92/02/01 public domain, By Ross Ridge";
  399. X#endif
  400. X/*
  401. X * I think this routine could be improved, as it is now it searches a
  402. X * linked list of strbufs for one that has enough room left for the
  403. X * string. The only thing else I can think of doing would be to 
  404. X * expand a buffer by realloc and then fix the string pointers if it
  405. X * moves.
  406. X */
  407. X
  408. static struct strbuf *strbuf = NULL;
  409. X   
  410. struct strbuf *
  411. X_endstr() {
  412. X    register struct strbuf *p;
  413. X
  414. X    p = strbuf;
  415. X    strbuf = NULL;
  416. X    return p;
  417. X}
  418. X
  419. char *
  420. X_addstr(s)
  421. register char *s; {
  422. X    register struct strbuf *p;
  423. X    register int l;
  424. X
  425. X    if (s == NULL) {
  426. X        strbuf = NULL;
  427. X        return NULL;
  428. X    }
  429. X
  430. X    if (strbuf == NULL) {
  431. X        strbuf = (struct strbuf *) malloc(sizeof(struct strbuf));
  432. X        if (strbuf == NULL)
  433. X            return NULL;
  434. X        strbuf->len = 0;
  435. X        strbuf->next = NULL;
  436. X    }
  437. X    l = strlen(s) + 1;
  438. X    if (l > MAX_CHUNK)
  439. X        return NULL;
  440. X    p = strbuf;
  441. X    while (l + p->len > MAX_CHUNK) {
  442. X        if (p->next == NULL) {
  443. X            p->next = (struct strbuf *)
  444. X                    malloc(sizeof(struct strbuf));
  445. X            p = p->next;
  446. X            if (p == NULL)
  447. X                return NULL;
  448. X            p->len = 0;
  449. X            p->next = NULL;
  450. X            break;
  451. X        }
  452. X        p = p->next;
  453. X    }
  454. X    s = strcpy(p->buf + p->len, s);
  455. X    p->len += l;
  456. X    return s;
  457. X}
  458. X
  459. void
  460. X_del_strs(p)
  461. TERMINAL *p; {
  462. X    struct strbuf *q;
  463. X
  464. X    q = p->strbuf;
  465. X    while(q != NULL) {
  466. X        p->strbuf = q->next; 
  467. X        free((anyptr) q);
  468. X        q = p->strbuf;
  469. X    }
  470. X}
  471. END_OF_FILE
  472. if test 1523 -ne `wc -c <'addstr.c'`; then
  473.     echo shar: \"'addstr.c'\" unpacked with wrong size!
  474. fi
  475. # end of 'addstr.c'
  476. fi
  477. if test -f 'bin_order' -a "${1}" != "-c" ; then 
  478.   echo shar: Will not clobber existing file \"'bin_order'\"
  479. else
  480. echo shar: Extracting \"'bin_order'\" \(2353 characters\)
  481. sed "s/^X//" >'bin_order' <<'END_OF_FILE'
  482. X bin_order
  483. X
  484. X By Ross Ridge
  485. X Public Domain
  486. X 92/02/01 07:29:39
  487. X
  488. X Order of entries in a terminfo binary
  489. X
  490. X @(#) mytinfo bin_order 3.2 92/02/01 public domain, By Ross Ridge
  491. X
  492. X
  493. X!
  494. bw am xsb xhp xenl eo gn hc km hs in da db mir msgr os eslok xt hz ul
  495. xon nxon mc5i chts nrrmc npc ndscr ccc bce hls xhpa crxm daisy xvpa sam
  496. cpix lpix
  497. X
  498. X#
  499. cols it lines lm xmc pb vt wsl nlab lh lw ma wnum colors pairs ncv bufsz
  500. spinv spinh maddr mjump mcs mls npins orc orl orhi orvi cps widcs btns
  501. bitwin bitype
  502. X
  503. X$
  504. cbt bel cr csr tbc clear el ed hpa cmdch cup cud1 home civis cub1 mrcup cnorm
  505. cuf1 ll cuu1 cvvis dch1 dl1 dsl hd smacs blink bold smcup smdc dim smir invis
  506. prot rev smso smul ech rmacs sgr0 rmcup rmdc rmir rmso rmul flash ff fsl is1
  507. is2 is3 if ich1 il1 ip kbs ktbc kclr kctab kdch1 kdl1 kcud1 krmir kel ked
  508. kf0 kf1 kf10 kf2 kf3 kf4 kf5 kf6 kf7 kf8 kf9 khome kich1 kil1 kcub1 kll
  509. knp kpp kcuf1 kind kri khts kcuu1 rmkx smkx lf0 lf1 lf10 lf2 lf3 lf4 lf5
  510. lf6 lf7 lf8 lf9 rmm smm nel pad dch dl cud ich indn il cub cuf rin cuu pfkey
  511. pfloc pfx mc0 mc4 mc5 rep rs1 rs2 rs3 rf rc vpa sc ind ri sgr hts wind ht
  512. tsl uc hu iprog ka1 ka3 kb2 kc1 kc3 mc5p rmp acsc pln kcbt smxon rmxon
  513. smam rmam xonc xoffc enacs smln rmln kbeg kcan kclo kcmd kcpy kcrt kend
  514. kent kext kfnd khlp kmrk kmsg kmov knxt kopn kopt kprv kprt krdo kref
  515. krfr krpl krst kres ksav kspd kund kBEG kCAN kCMD kCPY kCRT kDC kDL kslt
  516. kEND kEOL kEXT kFND kHLP kHOM kIC kLFT kMSG kMOV kNXT kOPT kPRV kPRT kRDO
  517. kRPL kRIT kRES kSAV kSPD kUND rfi kf11 kf12 kf13 kf14 kf15 kf16 kf17 kf18
  518. kf19 kf20 kf21 kf22 kf23 kf24 kf25 kf26 kf27 kf28 kf29 kf30 kf31 kf32
  519. kf33 kf34 kf35 kf36 kf37 kf38 kf39 kf40 kf41 kf42 kf43 kf44 kf45 kf46 kf47
  520. kf48 kf49 kf50 kf51 kf52 kf53 kf54 kf55 kf56 kf57 kf58 kf59 kf60 kf61 kf62
  521. kf63 el1 mgc smgl smgr fln sclk dclk rmclk cwin wingo hup dial qdial tone
  522. pulse hook pause wait u0 u1 u2 u3 u4 u5 u6 u7 u8 u9 op oc initc initp scp
  523. setf setb cpi lpi chr cvr defc swidm sdrfq sitm slm smicm snlq snrmq sshm
  524. ssubm ssupm sum rwidm ritm rlm rmicm rshm rsubm rsupm rum mhpa mcud1 mcub1
  525. mcuf1 mvpa mcuu1 porder mcud mcub mcuf mcuu scs smgb smgbp smglp smgrp smgt
  526. smgtp sbim scsd rbim rcsd subcs supcs docr zerom csnm kmous minfo reqmp
  527. getm setaf setab pfxl devt csin s0ds s1ds s2ds s3ds smglr smgtb birep binel
  528. bicr colornm defbi endbi setcolor slines dispc smpch rmpch smsc rmsc pctrm
  529. scesc scesa
  530. END_OF_FILE
  531. if test 2353 -ne `wc -c <'bin_order'`; then
  532.     echo shar: \"'bin_order'\" unpacked with wrong size!
  533. fi
  534. # end of 'bin_order'
  535. fi
  536. if test -f 'bsearch.c' -a "${1}" != "-c" ; then 
  537.   echo shar: Will not clobber existing file \"'bsearch.c'\"
  538. else
  539. echo shar: Extracting \"'bsearch.c'\" \(2102 characters\)
  540. sed "s/^X//" >'bsearch.c' <<'END_OF_FILE'
  541. X/*
  542. X * bsearch.c
  543. X *
  544. X * This is something I found on watmath. I've made some minor changes for use
  545. X * in this package.
  546. X *
  547. X * 92/06/04 11:35:15
  548. X */
  549. X
  550. X#if 0
  551. X#ifndef lint
  552. static char *RCSid = "$OHeader: /usr/mfcf/src/accounts/libuw/RCS/bsearch.c,v 1.1 88/06/11 20:41:48 root Exp $";
  553. X#endif
  554. X#endif
  555. X
  556. X#include "defs.h"
  557. X
  558. X#ifdef USE_MYBSEARCH
  559. X
  560. X#ifdef USE_SCCS_IDS
  561. static char const SCCSid[] = "@(#) mytinfo bsearch.c 3.4 92/06/04 public domain, By Ross Ridge";
  562. X#endif
  563. X
  564. X#ifdef USE_SHORT_BSEARCH
  565. X#define fast_int short
  566. X#else
  567. X#define fast_int mysize_t
  568. X#endif
  569. X
  570. X/*
  571. X * bsearch - find an element of a sorted vector
  572. X *
  573. X *    found = bsearch(key, array, dimension, width, compare)
  574. X *        returns a pointer to the specified element in the array,
  575. X *        or (char*)0 if the element can't be found.
  576. X *    key
  577. X *        pointer to the element to be searched for in the array
  578. X *    array
  579. X *        address of an array of elements
  580. X *    dimension
  581. X *        number of elements in the array
  582. X *    width
  583. X *        sizeof(type) of each element
  584. X *    compare
  585. X *        pointer to a function taking (char *) pointers to two elements
  586. X *        and returning <0, 0, or >0 as the first element comes before,
  587. X *        at, or after the second element.  A compare function is provided
  588. X *        for comparing strings.
  589. X*/
  590. X#if 0
  591. X/*
  592. X * $OLog:    bsearch.c,v $
  593. X * Revision 1.1  88/06/11  20:41:48  root
  594. X * Initial revision
  595. X * 
  596. X*/
  597. X#endif
  598. X
  599. X    static anyptr
  600. bsearch(key, array, dimension, iwidth, compare)
  601. X    anyptr key;
  602. X    anyptr array;
  603. X    int dimension;
  604. X    mysize_t iwidth;
  605. X    compar_fn compare;
  606. X{
  607. X    register fast_int start;   /* offset to start of current interval */
  608. X    register fast_int end;     /* offset to end+1 of current interval */
  609. X    register fast_int middle;  /* offset to middle of current interval */
  610. X    auto int status;
  611. X    register fast_int width;
  612. X
  613. X    width = iwidth / sizeof(char);
  614. X
  615. X    start = 0;
  616. X    middle = 0;
  617. X    end = dimension;
  618. X
  619. X    while (start < end) {
  620. X
  621. X        middle = (start + end) / 2;
  622. X
  623. X        status = (*compare)(key, ((char *)array + middle*width));
  624. X
  625. X        if (status < 0)
  626. X            end = middle;
  627. X
  628. X        else if (status > 0)
  629. X            start = middle + 1;
  630. X
  631. X        else return (anyptr)(((char *)array) + middle*width);
  632. X    }
  633. X
  634. X    return  0;
  635. X}
  636. X
  637. X#endif /* USE_MYBSEARCH */
  638. END_OF_FILE
  639. if test 2102 -ne `wc -c <'bsearch.c'`; then
  640.     echo shar: \"'bsearch.c'\" unpacked with wrong size!
  641. fi
  642. # end of 'bsearch.c'
  643. fi
  644. if test -f 'buildpath.c' -a "${1}" != "-c" ; then 
  645.   echo shar: Will not clobber existing file \"'buildpath.c'\"
  646. else
  647. echo shar: Extracting \"'buildpath.c'\" \(4092 characters\)
  648. sed "s/^X//" >'buildpath.c' <<'END_OF_FILE'
  649. X/*
  650. X * buildpath.c
  651. X * 
  652. X * By Ross Ridge
  653. X * Public Domain
  654. X * 92/02/01 07:29:42
  655. X *
  656. X * _buildpath builds a list of file names and terminal descriprions extracted
  657. X * from its arguments. It returns a pointer to a structure that is used by
  658. X * other routines as the list of file names to search for terminal
  659. X * descriptions.  It is passed a variable number of arguments consisting
  660. X * of file name and type pairs. The file name can actually be a list of 
  661. X * file names seperated by spaces and any environment variables specified
  662. X * by a dollar sign ($) followed by its name are substituted in. A type
  663. X * of 1 indicates that the file name may actually be termcap description
  664. X * and a type of 2 indicates it may be a terminfo description. A type of 0
  665. X * indicates that the file name can only be a file name (or list of them).
  666. X *
  667. X */
  668. X
  669. X#include "defs.h"
  670. X
  671. X#include <ctype.h>
  672. X
  673. X#include "strtok.c"
  674. X
  675. X#ifdef USE_SCCS_IDS
  676. static const char SCCSid[] = "@(#) mytinfo buildpath.c 3.2 92/02/01 public domain, By Ross Ridge";
  677. X#endif
  678. X
  679. X/* more memory is allocated for file names every HUNK file names */
  680. X#define HUNK 32    
  681. X
  682. X/* characters that seperate file names in a list */
  683. X#define SEPERATORS " :"
  684. X
  685. static struct term_path *path = NULL;    /* the list of files */
  686. static int files = 0;            /* # of files in the list */
  687. static int size = 0;            /* # of files there is space for */
  688. X
  689. X/* add a file name, type pair to the list */
  690. static int
  691. addfile(file, type)
  692. char *file;
  693. int type; {
  694. X    int l;
  695. X    char *s;
  696. X
  697. X    if (file == NULL) {
  698. X        if (type != -1)
  699. X            return -1;
  700. X    } else if (file[0] == '\0')
  701. X        return -1;
  702. X
  703. X#ifdef DEBUG
  704. X    if (file != NULL)
  705. X        printf("addfile: %s\n", file);
  706. X#endif
  707. X
  708. X    if (files >= size) {
  709. X        size += HUNK;
  710. X        if (path == NULL)
  711. X            path = (struct term_path *) 
  712. X                malloc(size * sizeof(struct term_path));
  713. X        else
  714. X            path = (struct term_path *)
  715. X                realloc((anyptr) path,
  716. X                    size * sizeof(struct term_path));
  717. X        if (path == NULL)
  718. X            return 0;
  719. X    }
  720. X    if (file == NULL) {
  721. X        path[files].file = file;
  722. X    } else {
  723. X        l = strlen(file) + 1;
  724. X        s = (char *) malloc(l * sizeof(char));
  725. X        if (s == NULL)
  726. X            return 0;
  727. X        path[files].file = strcpy(s, file);
  728. X    }
  729. X    path[files].type = type;
  730. X    
  731. X    return ++files;
  732. X}
  733. X
  734. X/* deallocate space used by the path list */
  735. void
  736. X_delpath(ppath)
  737. struct term_path *ppath; {
  738. X    struct term_path *p;
  739. X
  740. X    p = ppath;
  741. X    while(p->file != NULL) {
  742. X        free((anyptr)p->file);
  743. X        p++;
  744. X    }
  745. X
  746. X    free((anyptr)ppath);
  747. X}
  748. X
  749. X/* build a list of paths. see above */
  750. X#ifdef lint
  751. X/*VARARGS2*/
  752. struct term_path *
  753. X_buildpath(file, type)
  754. char *file;
  755. int type;
  756. X#else
  757. X#ifdef USE_STDARG
  758. X#ifdef USE_PROTOTYPES
  759. struct term_path *_buildpath(char *file, int type, ...)
  760. X#else
  761. struct term_path *_buildpath(file, type)
  762. char *file;
  763. int type;
  764. X#endif /* USE_PROTOTYPES */
  765. X#else /* USE_STDARG */
  766. struct term_path *_buildpath(va_alist)
  767. va_dcl
  768. X#endif /* USE_STDARG */
  769. X#endif /* lint */
  770. X{
  771. X#ifndef lint
  772. X#ifndef USE_STDARG
  773. X    char *file;
  774. X    int type;
  775. X#endif
  776. X#endif
  777. X    va_list ap;
  778. X    register char *s, *d, *e;
  779. X    char line[MAX_BUF+1];
  780. X    char name[MAX_NAME+1];
  781. X    int i,j;
  782. X
  783. X    size = 0;
  784. X    files = 0;
  785. X    path = NULL;
  786. X
  787. X#ifdef lint
  788. X    ap = NULL;
  789. X#else
  790. X#ifdef USE_STDARG
  791. X    va_start(ap, type);
  792. X#else
  793. X    va_start(ap);
  794. X    file = va_arg(ap, char *);
  795. X    type = va_arg(ap, int);
  796. X#endif
  797. X#endif
  798. X
  799. X    while (type >= 0 && type <= 2) {
  800. X        s = file;
  801. X        d = line;
  802. X        i = 0;
  803. X        while(*s != '\0') {
  804. X            if (*s == '$') {
  805. X                s++;
  806. X                j = 0;
  807. X                while(*s != '\0' && (*s == '_' || isalnum(*s))) 
  808. X                    if (j < MAX_NAME) {
  809. X                        name[j] = *s++;
  810. X                        j++;
  811. X                    } else
  812. X                        break;
  813. X                name[j] = '\0';
  814. X                e = getenv(name);
  815. X                if (e != NULL) {
  816. X                    while(*e != '\0') {
  817. X                        if (i < MAX_BUF) {
  818. X                            *d++ = *e++;
  819. X                            i++;
  820. X                        } else
  821. X                            break;
  822. X                    }
  823. X                } else if (*s == '/') 
  824. X                    s++;
  825. X            } else {
  826. X                if (i < MAX_BUF) {
  827. X                    *d++ = *s++;
  828. X                    i++;
  829. X                } else
  830. X                    break;
  831. X            }
  832. X        }
  833. X        *d = '\0';
  834. X        if (type == 0 || line[0] == '/') {
  835. X            s = strtok(line, SEPERATORS);
  836. X            while(s != NULL) {
  837. X                if (addfile(s, 0) == 0)
  838. X                    return NULL;
  839. X                s = strtok(NULL, SEPERATORS);
  840. X            }
  841. X        } else 
  842. X            if (addfile(line, type) == 0)
  843. X                return NULL;
  844. X        file = va_arg(ap, char *);
  845. X        type = va_arg(ap, int);
  846. X    }
  847. X    addfile(NULL, -1);
  848. X    return path;
  849. X}
  850. END_OF_FILE
  851. if test 4092 -ne `wc -c <'buildpath.c'`; then
  852.     echo shar: \"'buildpath.c'\" unpacked with wrong size!
  853. fi
  854. # end of 'buildpath.c'
  855. fi
  856. if test -f 'caps.c' -a "${1}" != "-c" ; then 
  857.   echo shar: Will not clobber existing file \"'caps.c'\"
  858. else
  859. echo shar: Extracting \"'caps.c'\" \(3316 characters\)
  860. sed "s/^X//" >'caps.c' <<'END_OF_FILE'
  861. X/*
  862. X * caps.c
  863. X * 
  864. X * By Ross Ridge
  865. X * Public Domain
  866. X * 92/02/01 07:29:45
  867. X *
  868. X * caps [-c | -t] [term]
  869. X *
  870. X * -c        use termcap names instead of terminfo variable names
  871. X * -t        use terminfo capnames instead of variables names
  872. X * term     name of terminal to use
  873. X *
  874. X * prints out all the capabilities given the specified terminal. If no
  875. X * terminal is given, it is taken from the environment variable TERM.
  876. X *
  877. X */
  878. X
  879. X#define NOTLIB
  880. X#include "defs.h"
  881. X#include "term.h"
  882. X
  883. static const char SCCSid[] = "@(#) mytinfo caps.c 3.2 92/02/01 public domain, By Ross Ridge";
  884. X
  885. X/* output a string in a human readable format */
  886. void
  887. putstr(s)
  888. char *s; {
  889. X    while(*s != '\0') {
  890. X        switch(*s) {
  891. X        case '\n': printf("\\n"); break;
  892. X        case '\b': printf("\\b"); break;
  893. X        case '\t': printf("\\t"); break;
  894. X        case '\r': printf("\\r"); break;
  895. X        case '\f': printf("\\f"); break;
  896. X        case ' ': printf("\\s"); break;
  897. X        case '\177': printf("^?"); break;
  898. X        case '\200': printf("\\0"); break;
  899. X        default:
  900. X            if (*s > 0 && *s < 32)
  901. X                printf("^%c", *s + 64);
  902. X            else if (*s < 0 || *s > 127)
  903. X                printf("\\%03o", *s & 0xff);
  904. X            else
  905. X                putchar(*s);
  906. X            break;
  907. X        }
  908. X        s++;
  909. X    }
  910. X}
  911. X
  912. void
  913. do_cleanup(e)
  914. int e; {
  915. X    fprintf(stderr, "usage: %s [-c | -t ] [terminal]\n", prg_name);
  916. X    return;
  917. X}
  918. X
  919. int
  920. main(argc, argv)
  921. int argc;
  922. char **argv; {
  923. X    int names = 0;
  924. X    register int i;
  925. X    int flag, num;
  926. X    char *str;
  927. X
  928. X    prg_name = argv[0];
  929. X    cleanup = do_cleanup;
  930. X
  931. X    if (argc > 3)
  932. X        quit(-1, "argument count");
  933. X
  934. X    if (argc == 1)
  935. X        setupterm(NULL, 2, (int *) 0);
  936. X    else if (argc == 2)
  937. X        setupterm(argv[1], 2, (int *) 0);
  938. X    else {
  939. X        if (argv[1][0] != '-')
  940. X            quit(-1, "bad switch");
  941. X        if (argv[1][1] == 'c')
  942. X            names = 2;
  943. X        else if (argv[1][1] == 't')
  944. X            names = 1;
  945. X        else
  946. X            quit(-1, "unknown switch '%c'", argv[1][1]);
  947. X        setupterm(argv[2], 2, (int *) 0);
  948. X
  949. X    }
  950. X
  951. X    fflush(stderr);
  952. X    fflush(stdout);
  953. X    printf("\n");
  954. X#ifdef _CUR_TERM
  955. X    printf("%s: %s\n", cur_term->name, cur_term->name_all);
  956. X    printf("pad: %d xon: %d termcap: %d\n",
  957. X            cur_term->pad, cur_term->xon, cur_term->termcap);
  958. X    printf("true_columns: %d true_lines: %d baudrate: %d\n",
  959. X        cur_term->true_columns, cur_term->true_lines,
  960. X        cur_term->baudrate);
  961. X    printf("\n");
  962. X#endif
  963. X
  964. X    printf("Booleans:\n");
  965. X    for(i = 0; boolnames[i] != NULL; i++) {
  966. X#ifdef _CUR_TERM
  967. X        flag = cur_term->bools[i];
  968. X#else
  969. X        flag = tigetflag(boolnames[i]);
  970. X#endif
  971. X        if (flag != -1 && flag != 0) {
  972. X            switch(names) {
  973. X            case 0:
  974. X                printf("  %s\n", boolfnames[i]);
  975. X                break;
  976. X            case 1:
  977. X                printf("  %s\n", boolnames[i]);
  978. X                break;
  979. X            case 2:
  980. X                printf("  %s\n", boolcodes[i]);
  981. X                break;
  982. X            }
  983. X        }
  984. X    }
  985. X
  986. X    printf("\nNumerics:\n");
  987. X    for(i = 0; numnames[i] != NULL; i++) {
  988. X        num = tigetnum(numnames[i]);
  989. X        if (num != -2 && num != -1) {
  990. X            switch(names) {
  991. X            case 0:
  992. X                printf("  %-32s: %d\n", numfnames[i], num);
  993. X                break;
  994. X            case 1:
  995. X                printf("  %-5s: %d\n", numnames[i], num);
  996. X                break;
  997. X            case 2:
  998. X                printf("  %-2s: %d\n", numcodes[i], num);
  999. X                break;
  1000. X            }
  1001. X        }
  1002. X    }
  1003. X    printf("\nStrings:\n");
  1004. X    for(i = 0; strnames[i] != NULL; i++) {
  1005. X        str = tigetstr(strnames[i]);
  1006. X        if (str != (char *) -1 && str != (char *) 0) {
  1007. X            switch(names) {
  1008. X            case 0:
  1009. X                printf("  %-32s: ", strfnames[i]);
  1010. X                break;
  1011. X            case 1:
  1012. X                printf("  %-5s: ", strnames[i]);
  1013. X                break;
  1014. X            case 2:
  1015. X                printf("  %-2s: ", strcodes[i]);
  1016. X                break;
  1017. X            }
  1018. X            putstr(str);
  1019. X            putchar('\n');
  1020. X        }
  1021. X    }
  1022. X    return 0;
  1023. X}
  1024. END_OF_FILE
  1025. if test 3316 -ne `wc -c <'caps.c'`; then
  1026.     echo shar: \"'caps.c'\" unpacked with wrong size!
  1027. fi
  1028. # end of 'caps.c'
  1029. fi
  1030. if test -f 'clear.c' -a "${1}" != "-c" ; then 
  1031.   echo shar: Will not clobber existing file \"'clear.c'\"
  1032. else
  1033. echo shar: Extracting \"'clear.c'\" \(1388 characters\)
  1034. sed "s/^X//" >'clear.c' <<'END_OF_FILE'
  1035. X/*
  1036. X * clear.c
  1037. X *
  1038. X * By Ross Ridge
  1039. X * Public Domain
  1040. X * 92/02/01 07:29:47
  1041. X *
  1042. X * clear
  1043. X * 
  1044. X * clears the terminal's screen
  1045. X *
  1046. X */
  1047. X
  1048. X#include "defs.h"
  1049. X
  1050. static const char SCCSid[] = "@(#) mytinfo clear.c 3.2 92/02/01 public domain, By Ross Ridge";
  1051. X
  1052. X#ifndef USE_TERMINFO
  1053. X
  1054. X#ifdef USE_SGTTY
  1055. X#include <sgtty.h>
  1056. X#endif
  1057. X#ifdef USE_TERMIO
  1058. X#include <termio.h>
  1059. X#endif
  1060. X
  1061. char PC;
  1062. short ospeed;
  1063. X
  1064. int
  1065. putch(c)
  1066. int c; {
  1067. X    return putchar(c);
  1068. X}
  1069. X
  1070. int
  1071. main(argc, argv)
  1072. int argc;
  1073. char **argv; {
  1074. X#ifdef USE_PROTYPES
  1075. X    char *tgetstr(char *, char **);
  1076. X#else
  1077. X    char *tgetstr();
  1078. X#endif
  1079. X    char *term;
  1080. X    char buf[MAX_BUF];
  1081. X    char CL[MAX_LINE];
  1082. X    char *s, *pc;
  1083. X
  1084. X#ifdef USE_SGTTY
  1085. X    struct sgttyb tty;
  1086. X
  1087. X    gtty(1, &tty);
  1088. X    ospeed = tty.sg_ospeed;
  1089. X#else
  1090. X#ifdef USE_TERMIO
  1091. X    struct termio tty;
  1092. X
  1093. X    ioctl(1, TCGETA, &tty);
  1094. X    ospeed = tty.c_cflag & CBAUD;
  1095. X#else
  1096. X    ospeed = 0;
  1097. X#endif
  1098. X#endif
  1099. X
  1100. X    term = getenv("TERM");
  1101. X    if (term == NULL)
  1102. X        exit(1);
  1103. X
  1104. X    if (tgetent(buf, term) != 1)
  1105. X        exit(1);
  1106. X
  1107. X    s = CL;
  1108. X    pc = tgetstr("pc", &s);
  1109. X    if (pc != NULL)
  1110. X        PC = *pc;
  1111. X
  1112. X    s = CL;
  1113. X    tgetstr("cl", &s);
  1114. X
  1115. X    if (CL != NULL) {
  1116. X        tputs(CL, tgetnum("li"), putch);
  1117. X        exit(1);
  1118. X    }
  1119. X
  1120. X    return 0;
  1121. X}
  1122. X
  1123. X#else /* USE_TERMINFO */
  1124. X
  1125. X#include "term.h"
  1126. X
  1127. int
  1128. putch(c)
  1129. int c; {
  1130. X    return putchar(c);
  1131. X}
  1132. X
  1133. int
  1134. main() {
  1135. X    setupterm((char *) 0, 1, (int *) 0); 
  1136. X    if (clear_screen == (char *) 0)
  1137. X        exit(1);
  1138. X    tputs(clear_screen, lines > 0 ? lines : 1, putch);
  1139. X    return 0;
  1140. X}
  1141. X
  1142. X#endif /* USE_TERMINFO */
  1143. END_OF_FILE
  1144. if test 1388 -ne `wc -c <'clear.c'`; then
  1145.     echo shar: \"'clear.c'\" unpacked with wrong size!
  1146. fi
  1147. # end of 'clear.c'
  1148. fi
  1149. if test -f 'compar.c' -a "${1}" != "-c" ; then 
  1150.   echo shar: Will not clobber existing file \"'compar.c'\"
  1151. else
  1152. echo shar: Extracting \"'compar.c'\" \(735 characters\)
  1153. sed "s/^X//" >'compar.c' <<'END_OF_FILE'
  1154. X/*
  1155. X * compar.c
  1156. X *
  1157. X * By Ross Ridge
  1158. X * Public Domain
  1159. X * 92/06/04 11:36:24
  1160. X *
  1161. X */
  1162. X
  1163. X#include "defs.h"
  1164. X
  1165. X#ifdef USE_SCCS_IDS
  1166. static const char SCCSid[] = "@(#) mytinfo compar.c 3.3 92/06/04 public domain, By Ross Ridge";
  1167. X#endif
  1168. X
  1169. X/* compare two elements a sorted list of pointers to strings */
  1170. int
  1171. X_compar(a, b)
  1172. X#ifdef USE_ANSIC
  1173. void const *a;
  1174. void const *b; {
  1175. X#else
  1176. anyptr a, b; {
  1177. X#endif
  1178. X    register char *aa = **(char ***)a;
  1179. X    register char *bb = **(char ***)b;
  1180. X
  1181. X    /* An optimization trick from C News, compare the first
  1182. X     * two chars of the string here to avoid a the overhead of a
  1183. X     * call to strcmp.
  1184. X     */
  1185. X
  1186. X#ifdef __GNUC__
  1187. X    return ((*aa - *bb) ? : strcmp(aa, bb));
  1188. X#else
  1189. X    if (*aa != *bb)
  1190. X        return *aa - *bb;
  1191. X    return strcmp(aa, bb);
  1192. X#endif
  1193. X}
  1194. END_OF_FILE
  1195. if test 735 -ne `wc -c <'compar.c'`; then
  1196.     echo shar: \"'compar.c'\" unpacked with wrong size!
  1197. fi
  1198. # end of 'compar.c'
  1199. fi
  1200. if test -f 'config.h' -a "${1}" != "-c" ; then 
  1201.   echo shar: Will not clobber existing file \"'config.h'\"
  1202. else
  1203. echo shar: Extracting \"'config.h'\" \(2141 characters\)
  1204. sed "s/^X//" >'config.h' <<'END_OF_FILE'
  1205. X/*
  1206. X * config.h
  1207. X *
  1208. X * By Ross Ridge
  1209. X * Public Domain
  1210. X * 92/02/19 18:56:28
  1211. X *
  1212. X * @(#) mytinfo config.h 3.3 92/02/19 public domain, By Ross Ridge
  1213. X *
  1214. X * Read the file INSTALL for more information on configuring mytinfo
  1215. X *
  1216. X */
  1217. X
  1218. X#ifndef _CONFIG_H_
  1219. X#define _CONFIG_H_
  1220. X
  1221. X#ifdef __STDC__
  1222. X#define USE_ANSIC        /* undefine this if your compiler lies */
  1223. X#endif
  1224. X
  1225. X#define USE_TERMIO        /* use termio (SysIII, SysV) */
  1226. X#undef USE_SGTTY        /* use sgtty (v7, BSD) */
  1227. X#define USE_WINSZ        /* get window size from the tty driver */
  1228. X#undef USE_STRINGS        /* include <strings.h> instead of <string.h> */
  1229. X#define USE_MYBSEARCH        /* your library doesn't have bsearch */
  1230. X#define USE_MYSTRTOK        /* your library doesn't have strtok */
  1231. X#define USE_MYQSORT        /* your library doesn't have qsort */
  1232. X#define USE_MYMKDIR        /* your library doesn't have mkdir */
  1233. X#define USE_MEMORY        /* you have an <memory.h> header */
  1234. X#define USE_FAKE_STDIO        /* don't use real stdio */
  1235. X#undef USE_DOPRNT        /* no vfprintf, use _doprnt */
  1236. X
  1237. X#define USE_SHORT_BSEARCH    /* speeds up MYBSEARCH on most machines */
  1238. X
  1239. X#define USE_SMALLMEM         /* save some memory */
  1240. X
  1241. X#undef USE_UPBC_KLUDGE        /* do tgoto like real togo */
  1242. X#undef USE_EXTERN_UPBC        /* get cuu1 and cub1 from externs UP and BC */
  1243. X#undef USE_LITOUT_KLUDGE    /* an alternate tgoto kludge, not recommened */
  1244. X
  1245. X
  1246. X#ifndef USE_ANSIC
  1247. X
  1248. X#undef USE_PROTOTYPES        /* use ANSI C prototypes */
  1249. X#undef USE_STDLIB        /* you have a <stdlib.h> */
  1250. X#undef USE_STDARG        /* you have a <stdarg.h> */
  1251. X#undef USE_STDDEF        /* you have a <stddef.h> */
  1252. X
  1253. X#define const 
  1254. X#define volatile
  1255. X#define noreturn        /* a function that doesn't return */
  1256. X
  1257. typedef char *anyptr;        /* a type that any pointer can be assigned to */
  1258. X
  1259. X#define mysize_t unsigned    /* size_t, the size of an object */
  1260. X
  1261. X#else /* USE_ANSIC */
  1262. X
  1263. X#define USE_PROTOTYPES
  1264. X#define USE_STDLIB
  1265. X#define USE_STDARG
  1266. X#define USE_STDDEF
  1267. X
  1268. typedef void *anyptr;
  1269. X
  1270. X#define mysize_t size_t
  1271. X
  1272. X#ifdef __GNUC__
  1273. X#define noreturn volatile
  1274. X#else
  1275. X#define noreturn
  1276. X#endif
  1277. X
  1278. X#endif /* USE_ANSIC */
  1279. X
  1280. X#define TERMCAPFILE "$TERMCAPFILE $HOME/.termcap /etc/termcap"
  1281. X
  1282. X#define TERMINFOSRC "/usr/lib/terminfo/terminfo.src"
  1283. X
  1284. X#define TERMINFODIR "/usr/lib/terminfo"
  1285. X
  1286. X#endif 
  1287. END_OF_FILE
  1288. if test 2141 -ne `wc -c <'config.h'`; then
  1289.     echo shar: \"'config.h'\" unpacked with wrong size!
  1290. fi
  1291. # end of 'config.h'
  1292. fi
  1293. if test -f 'defs.h' -a "${1}" != "-c" ; then 
  1294.   echo shar: Will not clobber existing file \"'defs.h'\"
  1295. else
  1296. echo shar: Extracting \"'defs.h'\" \(3946 characters\)
  1297. sed "s/^X//" >'defs.h' <<'END_OF_FILE'
  1298. X/*
  1299. X * defs.h
  1300. X *
  1301. X * By Ross Ridge
  1302. X * Public Domain
  1303. X * 92/06/04 11:37:02
  1304. X *
  1305. X * @(#) mytinfo defs.h 3.3 92/06/04 public domain, By Ross Ridge
  1306. X */
  1307. X
  1308. X#ifndef _DEFS_H_
  1309. X#define _DEFS_H_
  1310. X
  1311. X#ifdef TEST
  1312. X#undef NOTLIB
  1313. X#define NOTLIB
  1314. X#endif
  1315. X
  1316. X#include "config.h"
  1317. X
  1318. X#ifdef NOTLIB
  1319. X#undef USE_FAKE_STDIO
  1320. X#endif
  1321. X
  1322. X#ifdef USE_STDDEF
  1323. X#include <stddef.h>
  1324. X#else
  1325. X#include <sys/types.h>
  1326. X#endif
  1327. X
  1328. X#ifdef USE_STDLIB
  1329. X#include <stdlib.h>
  1330. X#else
  1331. X#ifdef USE_PROTOTYPES
  1332. anyptr malloc(mysize_t);
  1333. anyptr realloc(anyptr, mysize_t);
  1334. char *getenv(char const *);
  1335. X#else
  1336. anyptr malloc();
  1337. anyptr realloc();
  1338. char *getenv();
  1339. X#endif
  1340. X#endif
  1341. X
  1342. X#ifdef USE_STDARG
  1343. X#include <stdarg.h>
  1344. X#else
  1345. X#include <varargs.h>
  1346. X#endif
  1347. X
  1348. X#ifndef _VA_LIST
  1349. X#define _VA_LIST
  1350. X#endif
  1351. X
  1352. X#ifdef USE_FAKE_STDIO
  1353. X#include "fake_stdio.h"
  1354. X#define sprintf _fake_sprintf
  1355. X#ifdef USE_PROTOTYPES
  1356. int sprintf(char *, char *, ...);
  1357. X#else
  1358. int sprintf();
  1359. X#endif
  1360. X#else /* USE_FAKE_STDIO */
  1361. X#if 0
  1362. X#include <stdio.h>
  1363. X#else
  1364. X#undef NULL
  1365. X#include <stdio.h>
  1366. X#endif
  1367. X#endif /* !USE_FAKE_STDIO */
  1368. X
  1369. X#ifdef USE_STRINGS
  1370. X#include <strings.h>
  1371. X#define strchr(s, c) index(s, c)
  1372. X#define strrchr(s, c) rindex(s, c)
  1373. X#ifndef USE_MYSTRTOK
  1374. X#ifdef USE_PROTOTYPES
  1375. char *strtok(char *, char *);
  1376. X#else
  1377. char *strtok();
  1378. X#endif
  1379. X#endif
  1380. X#else
  1381. X#include <string.h>
  1382. X#endif
  1383. X
  1384. X#ifdef USE_MEMORY
  1385. X#include <memory.h>
  1386. X#else
  1387. X#define memcpy(b, a, n) bcopy(a, b, n)
  1388. X#endif
  1389. X
  1390. X#include <errno.h>
  1391. X
  1392. X#define MAX_BUF    4096
  1393. X#define MAX_LINE 640
  1394. X#define MAX_NAME 128
  1395. X
  1396. X#define MAX_CHUNK MAX_LINE
  1397. X
  1398. X#define MAX_DEPTH 32
  1399. X
  1400. X#define MAX_VARNAME    32
  1401. X#define MAX_TINFONAME    5
  1402. X#define MAX_TCAPNAME    2
  1403. X
  1404. struct caplist {
  1405. X    char    type;
  1406. X    char    flag;
  1407. X    char    var[MAX_VARNAME + 1];
  1408. X    char    tinfo[MAX_TINFONAME + 1];
  1409. X    char    tcap[MAX_TCAPNAME + 1];
  1410. X};
  1411. X
  1412. struct term_path {
  1413. X    char *file;
  1414. X    int type;    /* 0 = file, 1 = TERMCAP env, 2 = TERMINFO env */
  1415. X};
  1416. X
  1417. struct _terminal;
  1418. X
  1419. X#ifdef USE_PROTOTYPES
  1420. X
  1421. int _gettcap(char *, struct _terminal *, struct term_path *);
  1422. int _gettinfo(char *, struct _terminal *, struct term_path *);
  1423. int _fillterm(char *, struct term_path *, char *);
  1424. int _findterm(char *, struct term_path *, char *);
  1425. int _init_tty(void), _lit_output(void), _check_tty(void);
  1426. void _figure_termcap(void);
  1427. int _tmatch(char *, char *);
  1428. void _norm_output(void);
  1429. int readcaps(FILE *, struct caplist *, int);
  1430. noreturn void quit(int, char *, ...);
  1431. X#ifdef lint
  1432. extern void (*cleanup)();
  1433. X#else
  1434. extern void (*cleanup)(int);
  1435. X#endif
  1436. struct term_path *_buildpath(char *, int, ...);
  1437. void _delpath(struct term_path *);
  1438. char *_addstr(char *);
  1439. struct strbuf *_endstr(void);
  1440. void _del_strs(struct _terminal *);
  1441. void _tcapconv(void);
  1442. void _tcapdefault(void);
  1443. int _getother(char *, struct term_path *, struct _terminal *);
  1444. int _gettbin(char *, struct _terminal *);
  1445. int _findboolcode(char *), _findnumcode(char *), _findstrcode(char *);
  1446. int _findboolname(char *), _findnumname(char *), _findstrname(char *);
  1447. int _findboolfname(char *), _findnumfname(char *), _findstrfname(char *);
  1448. X
  1449. X#ifdef USE_ANSIC
  1450. int _compar(void const *, void const *);
  1451. typedef int (*compar_fn)(void const *, void const *);
  1452. X#else
  1453. int _compar(anyptr, anyptr);
  1454. typedef int (*compar_fn)(anyptr, anyptr);
  1455. X#endif
  1456. X
  1457. X#else /* USE_PROTOTYPES */
  1458. X
  1459. int _gettcap(), _gettinfo(), _fillterm(), _findterm(), _init_tty();
  1460. int _lit_output(), _check_tty();
  1461. void _figure_termcap();
  1462. int _tmatch();
  1463. void _norm_output();
  1464. int readcaps();
  1465. noreturn void /* GOTO */ quit(/*FORMAT2*/);
  1466. extern void (*cleanup)();
  1467. struct term_path *_buildpath();
  1468. void _delpath();
  1469. char *_addstr();
  1470. struct strbuf *_endstr();
  1471. void _del_strs();
  1472. void _tcapconv();
  1473. void _tcapdefault();
  1474. int _getother();
  1475. int _gettbin();
  1476. int _findboolcode(), _findnumcode(), _findstrcode();
  1477. int _findboolname(), _findnumname(), _findstrname();
  1478. int _findboolfname(), _findnumfname(), _findstrfname();
  1479. int _compar();
  1480. typedef int (*compar_fn)();
  1481. X
  1482. X#endif /* USE_PROTOTYPES */
  1483. X
  1484. extern char _strflags[];
  1485. X
  1486. extern char _mytinfo_version[];
  1487. X
  1488. X/* for quit.c */
  1489. extern int sys_nerr;
  1490. extern char *sys_errlist[];
  1491. extern char *prg_name;
  1492. X
  1493. X#endif /* _DEFS_H_ */
  1494. END_OF_FILE
  1495. if test 3946 -ne `wc -c <'defs.h'`; then
  1496.     echo shar: \"'defs.h'\" unpacked with wrong size!
  1497. fi
  1498. # end of 'defs.h'
  1499. fi
  1500. if test -f 'fake_stdio.c' -a "${1}" != "-c" ; then 
  1501.   echo shar: Will not clobber existing file \"'fake_stdio.c'\"
  1502. else
  1503. echo shar: Extracting \"'fake_stdio.c'\" \(1803 characters\)
  1504. sed "s/^X//" >'fake_stdio.c' <<'END_OF_FILE'
  1505. X/*
  1506. X * fake_stdio.c
  1507. X *
  1508. X * By Ross Ridge
  1509. X * Public Domain
  1510. X * 92/02/01 07:29:52
  1511. X *
  1512. X * fake some stdio functions
  1513. X *
  1514. X */
  1515. X
  1516. X#include "defs.h"
  1517. X
  1518. X#include <fcntl.h>
  1519. X
  1520. X#ifdef USE_FAKE_STDIO
  1521. X
  1522. X#ifdef USE_SCCS_IDS
  1523. static const char SCCSid[] = "@(#) mytinfo fake_stdio.c 3.2 92/02/01 public domain, By Ross Ridge";
  1524. X#endif
  1525. X#include "fake_stdio.h"
  1526. X
  1527. static FILE _fake_files[] = {
  1528. X    {NULL, NULL, -1, {'\0'}},
  1529. X    {NULL, NULL, -1, {'\0'}},
  1530. X    {NULL, NULL, -1, {'\0'}},
  1531. X    {NULL, NULL, -1, {'\0'}},
  1532. X    {NULL, NULL, -1, {'\0'}}
  1533. X};
  1534. X
  1535. int
  1536. X_fillbuf(f)
  1537. register FILE *f; {
  1538. X    register int r;
  1539. X
  1540. X    r = read(f->fd, f->buf, FAKE_BUF_SIZE);
  1541. X    if (r == -1 || r == 0) {
  1542. X        f->pos = f->end = f->buf;
  1543. X        return EOF;
  1544. X    }
  1545. X    f->pos = f->buf + 1;
  1546. X    f->end = f->buf + r;
  1547. X
  1548. X    return f->buf[0];
  1549. X}
  1550. X
  1551. int
  1552. fgetc(f)
  1553. register FILE *f; {
  1554. X    return getc(f);
  1555. X}
  1556. X
  1557. char *
  1558. fgets(s, n, f)
  1559. char *s;
  1560. int n;
  1561. register FILE *f; {
  1562. X    register char *d;
  1563. X    register int l;
  1564. X    register int c;
  1565. X
  1566. X    d = s;
  1567. X    l = 1;
  1568. X    while(l < n) {
  1569. X        if ((c = getc(f)) == EOF) {
  1570. X            if (l == 0)
  1571. X                return NULL;
  1572. X            break;
  1573. X        }
  1574. X        *d++ = c;
  1575. X        if (c == '\n') 
  1576. X            break;
  1577. X        l++;
  1578. X    }
  1579. X    *d = '\0';
  1580. X    return s;
  1581. X}
  1582. X
  1583. static FILE *
  1584. X_fdopen(fd)
  1585. int fd; {
  1586. X    register FILE *f;
  1587. X    int i, r;
  1588. X
  1589. X    for(f = _fake_files, i = 0; i < FILES; i++, f++) {
  1590. X        if (f->fd == -1) {
  1591. X            f->fd = fd;
  1592. X            r = read(fd, f->buf, FAKE_BUF_SIZE);
  1593. X            if (r == -1) {
  1594. X                f->pos = f->end = f->buf;
  1595. X                return NULL;
  1596. X            }
  1597. X            f->pos = f->buf;
  1598. X            f->end = f->buf + r;
  1599. X            return f;
  1600. X        }
  1601. X    }
  1602. X    return NULL;
  1603. X}
  1604. X
  1605. XFILE *
  1606. fopen(name, type)
  1607. char *name;
  1608. char *type; {
  1609. X    FILE *f;
  1610. X    int fd;
  1611. X
  1612. X    if (strcmp(type, "r") != 0)
  1613. X        return NULL;
  1614. X    fd = open(name, O_RDONLY);
  1615. X    if (fd == -1)
  1616. X        return NULL;
  1617. X    f = _fdopen(fd);
  1618. X    if (f == NULL)
  1619. X        close(fd);
  1620. X    return f;
  1621. X}
  1622. X
  1623. XFILE *
  1624. fdopen(fd, type)
  1625. int fd;
  1626. char *type; {
  1627. X    if (strcmp(type, "r") != 0)
  1628. X        return NULL;
  1629. X    return _fdopen(fd);
  1630. X}
  1631. X
  1632. X#endif /* USE_FAKE_STDIO */
  1633. END_OF_FILE
  1634. if test 1803 -ne `wc -c <'fake_stdio.c'`; then
  1635.     echo shar: \"'fake_stdio.c'\" unpacked with wrong size!
  1636. fi
  1637. # end of 'fake_stdio.c'
  1638. fi
  1639. if test -f 'fake_stdio.h' -a "${1}" != "-c" ; then 
  1640.   echo shar: Will not clobber existing file \"'fake_stdio.h'\"
  1641. else
  1642. echo shar: Extracting \"'fake_stdio.h'\" \(1257 characters\)
  1643. sed "s/^X//" >'fake_stdio.h' <<'END_OF_FILE'
  1644. X/*
  1645. X * fake_stdio.h
  1646. X *
  1647. X * By Ross Ridge
  1648. X * Public Domain
  1649. X * 92/02/01 07:29:53
  1650. X *
  1651. X * A fake stdio.h for a fake stdio (read only)
  1652. X *
  1653. X * @(#) mytinfo fake_stdio.h 3.2 92/02/01 public domain, By Ross Ridge
  1654. X */
  1655. X
  1656. X#ifndef _FAKE_STDIO_H_
  1657. X
  1658. X#define _FAKE_STDIO_H_
  1659. X
  1660. X#if 1
  1661. X#define getc _fake_getc
  1662. X#define fgetc _fake_fgetc
  1663. X#define fgets _fake_fgets
  1664. X#define fclose _fake_fclose
  1665. X#define _fillbuf _fake_fillbuf
  1666. X#define ungetc _fake_ungetc
  1667. X#define fopen _fake_fopen
  1668. X#define fdopen _fake_fdopen
  1669. X#endif
  1670. X
  1671. X#define FILES    5
  1672. X#define FAKE_BUF_SIZE    512
  1673. X
  1674. struct _fake_file {
  1675. X    char *pos;
  1676. X    char *end;
  1677. X    int fd;
  1678. X    char buf[FAKE_BUF_SIZE];
  1679. X};
  1680. X
  1681. X#undef FILE
  1682. X#define FILE struct _fake_file
  1683. X#undef EOF
  1684. X#define EOF (-1)
  1685. X
  1686. X#define _fake_getc(f) ((f)->pos >= (f)->end ? _fillbuf(f) : *((f)->pos)++)
  1687. X#define _fake_fclose(f) (close((f)->fd) == -1 ? EOF : ((f)->fd = -1, 0))
  1688. X#define _fake_ungetc(c, f) ((f)->pos > (f)->buf ? (*--((f)->pos) = c) : EOF)
  1689. X
  1690. X#ifdef USE_PROTOYPES
  1691. int fgetc(FILE *);
  1692. int _fillbuf(FILE *);
  1693. char *fgets(char *, int, FILE *);
  1694. XFILE *fopen(char *, char *);
  1695. XFILE *fdopen(int, char *);
  1696. X#else
  1697. int fgetc();
  1698. int _fillbuf();
  1699. char *fgets();
  1700. XFILE *fopen();
  1701. XFILE *fdopen();
  1702. X#endif
  1703. X
  1704. X#if !defined(NULL) && !defined(USE_STRINGS)
  1705. X#define NULL ((anyptr) 0)
  1706. X#endif
  1707. X
  1708. X#endif /* !_FAKE_STDIO_H_ */
  1709. END_OF_FILE
  1710. if test 1257 -ne `wc -c <'fake_stdio.h'`; then
  1711.     echo shar: \"'fake_stdio.h'\" unpacked with wrong size!
  1712. fi
  1713. # end of 'fake_stdio.h'
  1714. fi
  1715. if test -f 'fillterm.c' -a "${1}" != "-c" ; then 
  1716.   echo shar: Will not clobber existing file \"'fillterm.c'\"
  1717. else
  1718. echo shar: Extracting \"'fillterm.c'\" \(1523 characters\)
  1719. sed "s/^X//" >'fillterm.c' <<'END_OF_FILE'
  1720. X/*
  1721. X * fillterm.c
  1722. X *
  1723. X * By Ross Ridge
  1724. X * Public Domain
  1725. X * 92/02/01 07:29:54
  1726. X *
  1727. X */
  1728. X
  1729. X#include "defs.h"
  1730. X#include "term.h"
  1731. X
  1732. X#ifdef USE_SCCS_IDS
  1733. static const char SCCSid[] = "@(#) mytinfo fillterm.c 3.2 92/02/01 public domain, By Ross Ridge";
  1734. X#endif
  1735. X
  1736. TERMINAL _term_buf;
  1737. TERMINAL *cur_term;
  1738. X
  1739. int
  1740. X_fillterm(name, path, buf)
  1741. char *name, *buf;
  1742. struct term_path *path; {
  1743. X    register int i, r;
  1744. X
  1745. X    r = -1;
  1746. X
  1747. X    for(i = NUM_OF_BOOLS; i;)
  1748. X        _term_buf.bools[--i] = -1;
  1749. X    for(i = NUM_OF_NUMS; i;)
  1750. X        _term_buf.nums[--i] = -2;
  1751. X    for(i = NUM_OF_STRS; i;)
  1752. X        _term_buf.strs[--i] = (char *) -1;
  1753. X
  1754. X    _term_buf.name_all = NULL;
  1755. X    
  1756. X    r = _findterm(name, path, buf);
  1757. X    switch(r) {
  1758. X    case 1:
  1759. X        if (_gettcap(buf, &_term_buf, path) != 0)
  1760. X            return -3;
  1761. X        _tcapconv(); 
  1762. X        _tcapdefault();
  1763. X        break;
  1764. X    case 2:
  1765. X        if (_gettinfo(buf, &_term_buf, path) != 0)
  1766. X            return -3;
  1767. X        break;
  1768. X    case 3:
  1769. X        if (_gettbin(buf, &_term_buf) != 0)
  1770. X            return -3;
  1771. X        break;
  1772. X    default:
  1773. X        return r;
  1774. X    }
  1775. X
  1776. X    if ((_term_buf.name = _addstr(name)) == NULL)
  1777. X        return -3;
  1778. X
  1779. X    for(i = NUM_OF_BOOLS; i;)
  1780. X        if (_term_buf.bools[--i] == -1)
  1781. X            _term_buf.bools[i] = 0;
  1782. X    for(i = NUM_OF_NUMS; i;)
  1783. X        if (_term_buf.nums[--i] == -2)
  1784. X            _term_buf.nums[i] = -1;
  1785. X    for(i = NUM_OF_STRS; i;)
  1786. X        if (_term_buf.strs[--i] == (char *) -1)
  1787. X            _term_buf.strs[i] = NULL;
  1788. X
  1789. X    _term_buf.fd = 1;
  1790. X    _term_buf.pad = 1;
  1791. X    _term_buf.baudrate = 0;
  1792. X    _term_buf.strbuf = _endstr();
  1793. X
  1794. X    cur_term = (TERMINAL *) malloc(sizeof(_term_buf));
  1795. X    if (cur_term == NULL)
  1796. X        return -3;
  1797. X    memcpy((anyptr)cur_term, (anyptr)&_term_buf, sizeof(_term_buf));
  1798. X
  1799. X    return r;
  1800. X}
  1801. END_OF_FILE
  1802. if test 1523 -ne `wc -c <'fillterm.c'`; then
  1803.     echo shar: \"'fillterm.c'\" unpacked with wrong size!
  1804. fi
  1805. # end of 'fillterm.c'
  1806. fi
  1807. if test -f 'findcap.c' -a "${1}" != "-c" ; then 
  1808.   echo shar: Will not clobber existing file \"'findcap.c'\"
  1809. else
  1810. echo shar: Extracting \"'findcap.c'\" \(2619 characters\)
  1811. sed "s/^X//" >'findcap.c' <<'END_OF_FILE'
  1812. X/*
  1813. X * findcap.c
  1814. X *
  1815. X * By Ross Ridge
  1816. X * Public Domain
  1817. X * 92/02/01 07:29:55
  1818. X *
  1819. X */
  1820. X
  1821. X#include "defs.h"
  1822. X#include "term.h"
  1823. X
  1824. X#include "bsearch.c"
  1825. X
  1826. X#ifdef USE_SCCS_IDS
  1827. static const char SCCSid[] = "@(#) mytinfo findcap.c 3.2 92/02/01 public domain, By Ross Ridge";
  1828. X#endif
  1829. X
  1830. extern char **_sboolcodes[], **_snumcodes[], **_sstrcodes[];
  1831. extern char **_sboolnames[], **_snumnames[], **_sstrnames[];
  1832. extern char **_sboolfnames[], **_snumfnames[], **_sstrfnames[];
  1833. X
  1834. static char **p2p2c;
  1835. X
  1836. int
  1837. X_findboolcode(s)
  1838. char *s; {
  1839. X    char ***match;
  1840. X
  1841. X    p2p2c = &s;
  1842. X
  1843. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sboolcodes,
  1844. X                   NUM_OF_BOOLS, sizeof(p2p2c), _compar);
  1845. X    if (match == NULL)
  1846. X        return -1;
  1847. X    return *match - boolcodes;
  1848. X}
  1849. X
  1850. int
  1851. X_findboolname(s)
  1852. char *s; {
  1853. X    char ***match;
  1854. X
  1855. X    p2p2c = &s;
  1856. X
  1857. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sboolnames,
  1858. X                   NUM_OF_BOOLS, sizeof(p2p2c), _compar);
  1859. X    if (match == NULL)
  1860. X        return -1;
  1861. X    return *match - boolnames;
  1862. X}
  1863. X
  1864. int
  1865. X_findboolfname(s)
  1866. char *s; {
  1867. X    char ***match;
  1868. X
  1869. X    p2p2c = &s;
  1870. X
  1871. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sboolfnames,
  1872. X                   NUM_OF_BOOLS, sizeof(p2p2c), _compar);
  1873. X    if (match == NULL)
  1874. X        return -1;
  1875. X    return *match - boolfnames;
  1876. X}
  1877. X
  1878. int
  1879. X_findnumcode(s)
  1880. char *s; {
  1881. X    char ***match;
  1882. X
  1883. X    p2p2c = &s;
  1884. X
  1885. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _snumcodes,
  1886. X                   NUM_OF_NUMS, sizeof(p2p2c), _compar);
  1887. X    if (match == NULL)
  1888. X        return -1;
  1889. X    return *match - numcodes;
  1890. X}
  1891. X
  1892. int
  1893. X_findnumname(s)
  1894. char *s; {
  1895. X    char ***match;
  1896. X
  1897. X    p2p2c = &s;
  1898. X
  1899. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _snumnames,
  1900. X                   NUM_OF_NUMS, sizeof(p2p2c), _compar);
  1901. X    if (match == NULL)
  1902. X        return -1;
  1903. X    return *match - numnames;
  1904. X}
  1905. X
  1906. int
  1907. X_findnumfname(s)
  1908. char *s; {
  1909. X    char ***match;
  1910. X
  1911. X    p2p2c = &s;
  1912. X
  1913. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _snumfnames,
  1914. X                   NUM_OF_NUMS, sizeof(p2p2c), _compar);
  1915. X    if (match == NULL)
  1916. X        return -1;
  1917. X    return *match - numfnames;
  1918. X}
  1919. X
  1920. int
  1921. X_findstrcode(s)
  1922. char *s; {
  1923. X    char ***match;
  1924. X
  1925. X    p2p2c = &s;
  1926. X
  1927. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sstrcodes,
  1928. X                   NUM_OF_STRS, sizeof(p2p2c), _compar);
  1929. X    if (match == NULL)
  1930. X        return -1;
  1931. X    return *match - strcodes;
  1932. X}
  1933. X
  1934. int
  1935. X_findstrname(s)
  1936. char *s; {
  1937. X    char ***match;
  1938. X
  1939. X    p2p2c = &s;
  1940. X
  1941. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sstrnames,
  1942. X                   NUM_OF_STRS, sizeof(p2p2c), _compar);
  1943. X    if (match == NULL)
  1944. X        return -1;
  1945. X    return *match - strnames;
  1946. X}
  1947. X
  1948. int
  1949. X_findstrfname(s)
  1950. char *s; {
  1951. X    char ***match;
  1952. X
  1953. X    p2p2c = &s;
  1954. X
  1955. X    match = (char ***) bsearch((anyptr) &p2p2c, (anyptr) _sstrfnames,
  1956. X                   NUM_OF_STRS, sizeof(p2p2c), _compar);
  1957. X    if (match == NULL)
  1958. X        return -1;
  1959. X    return *match - strfnames;
  1960. X}
  1961. END_OF_FILE
  1962. if test 2619 -ne `wc -c <'findcap.c'`; then
  1963.     echo shar: \"'findcap.c'\" unpacked with wrong size!
  1964. fi
  1965. # end of 'findcap.c'
  1966. fi
  1967. if test -f 'getother.c' -a "${1}" != "-c" ; then 
  1968.   echo shar: Will not clobber existing file \"'getother.c'\"
  1969. else
  1970. echo shar: Extracting \"'getother.c'\" \(724 characters\)
  1971. sed "s/^X//" >'getother.c' <<'END_OF_FILE'
  1972. X/*
  1973. X * getother.c
  1974. X *
  1975. X * By Ross Ridge
  1976. X * Public Domain
  1977. X * 92/02/01 07:29:58
  1978. X *
  1979. X */
  1980. X
  1981. X#include "defs.h"
  1982. X#include "term.h"
  1983. X
  1984. X#ifdef USE_SCCS_IDS
  1985. static const char SCCSid[] = "@(#) mytinfo getother.c 3.2 92/02/01 public domain, By Ross Ridge";
  1986. X#endif
  1987. X
  1988. int
  1989. X_getother(name, path, ct)
  1990. char *name;
  1991. struct term_path *path;
  1992. TERMINAL *ct; {
  1993. X    static int depth = 0;
  1994. X    int r;
  1995. X    char buf[MAX_BUF];
  1996. X
  1997. X    if (depth >= MAX_DEPTH)
  1998. X        return 1;        /* infinite loop */
  1999. X
  2000. X#ifdef DEBUG
  2001. X    printf("\ngetother: %s\n", name);
  2002. X#endif
  2003. X
  2004. X    switch(_findterm(name, path, buf)) {
  2005. X    case -3:
  2006. X        return 1;
  2007. X    case 1:
  2008. X        depth++;
  2009. X        r = _gettcap(buf, ct, path);
  2010. X        break;
  2011. X    case 2:
  2012. X        depth++;
  2013. X        r = _gettinfo(buf, ct, path);
  2014. X        break;
  2015. X    default:
  2016. X        return 0;
  2017. X    }
  2018. X    depth--;
  2019. X    return r;
  2020. X}
  2021. END_OF_FILE
  2022. if test 724 -ne `wc -c <'getother.c'`; then
  2023.     echo shar: \"'getother.c'\" unpacked with wrong size!
  2024. fi
  2025. # end of 'getother.c'
  2026. fi
  2027. if test -f 'gettbin.c' -a "${1}" != "-c" ; then 
  2028.   echo shar: Will not clobber existing file \"'gettbin.c'\"
  2029. else
  2030. echo shar: Extracting \"'gettbin.c'\" \(2573 characters\)
  2031. sed "s/^X//" >'gettbin.c' <<'END_OF_FILE'
  2032. X/*
  2033. X * gettbin.c
  2034. X *
  2035. X * By Ross Ridge
  2036. X * Public Domain
  2037. X * 92/02/01 07:29:59
  2038. X *
  2039. X * Get a terminfo binary entry
  2040. X *
  2041. X */
  2042. X
  2043. X#include "defs.h"
  2044. X#include "term.h"
  2045. X
  2046. X#ifdef USE_SCCS_IDS
  2047. static const char SCCSid[] = "@(#) mytinfo gettbin.c 3.2 92/02/01 public domain, By Ross Ridge";
  2048. X#endif
  2049. X
  2050. extern int _boolorder[], _numorder[], _strorder[];
  2051. X
  2052. X#ifdef TRUE_BYTE_ORDERING 
  2053. X/* 8 bit char, 16 bit short, lsb first, twos complement */
  2054. X#define convshort(s) (*(short *)(s))
  2055. X
  2056. X#else
  2057. X
  2058. X#ifdef TWOS_COPLEMENT 
  2059. X/* 8 bit char, 16 bit short, lsb last, twos complement */
  2060. X#define convshort(s) ((short)(((s[0] & 0377) << 8) | (s[1] & 0377)))
  2061. X
  2062. X#else
  2063. X
  2064. X/* anything else... */
  2065. X
  2066. static short
  2067. convshort(s)
  2068. char *s; {
  2069. X    register int a,b;
  2070. X
  2071. X    a = (int) s[0] & 0377;
  2072. X    b = (int) s[1] & 0377;
  2073. X
  2074. X    if (a == 0377 && b == 0377)
  2075. X        return -1;
  2076. X    if (a == 0376 && b == 0377)
  2077. X        return -2;
  2078. X
  2079. X    return a + b * 256;
  2080. X}
  2081. X#endif
  2082. X#endif
  2083. X
  2084. int
  2085. X_gettbin(buf, cur)
  2086. char *buf;
  2087. TERMINAL *cur; {
  2088. X    register char *s;
  2089. X    int i;
  2090. X    int sz_names, sz_bools, sz_nums, sz_offs, sz_strs;
  2091. X    int n_bools, n_nums, n_strs;
  2092. X    char *strtbl;
  2093. X
  2094. X    buf[MAX_BUF-1] = '\0';
  2095. X    s = buf;
  2096. X
  2097. X    if (convshort(s) != 0432)
  2098. X        return 1;
  2099. X    sz_names = convshort(s + 2);
  2100. X    sz_bools = convshort(s + 4);
  2101. X    n_nums = convshort(s + 6);
  2102. X    n_strs = convshort(s + 8);
  2103. X    sz_strs = convshort(s + 10);
  2104. X
  2105. X    n_bools = sz_bools;
  2106. X    sz_nums = n_nums * 2;
  2107. X    sz_offs = n_strs * 2;
  2108. X
  2109. X    if ((sz_names + sz_bools) & 1)
  2110. X        sz_bools++;
  2111. X
  2112. X    if (12 + sz_names + sz_bools + sz_nums + sz_offs + sz_strs >= MAX_BUF)
  2113. X        return 1;
  2114. X
  2115. X    s += 12;
  2116. X    if ((cur->name_all = _addstr(s)) == NULL)
  2117. X        return 1;
  2118. X    s += sz_names;
  2119. X    while(--s >= buf + 12) {
  2120. X        if (*s == '|') {
  2121. X            if ((cur->name_long = _addstr(s + 1)) == NULL)
  2122. X                return 1;
  2123. X            break;
  2124. X        }
  2125. X    }
  2126. X
  2127. X    s = buf + 12 + sz_names;
  2128. X    for(i = 0; i < n_bools && _boolorder[i] != -1; i++, s++) {
  2129. X        if (cur->bools[_boolorder[i]] == -1 && *s == 1)
  2130. X            cur->bools[_boolorder[i]] = 1;
  2131. X    }
  2132. X
  2133. X    s = buf + 12 + sz_names + sz_bools;
  2134. X    for(i = 0; i < n_nums && _numorder[i] != -1; i++, s += 2) {
  2135. X        if (convshort(s) == -2) 
  2136. X            cur->nums[_numorder[i]] = -1;
  2137. X        else if (cur->nums[_numorder[i]] == -2 && convshort(s) != -1)
  2138. X            cur->nums[_numorder[i]] = convshort(s);
  2139. X    }
  2140. X
  2141. X    s = buf + 12 + sz_names + sz_bools + sz_nums;
  2142. X    strtbl = s + sz_offs;
  2143. X    for(i = 0; i < n_strs && _strorder[i] != -1; i++, s += 2) {
  2144. X        if (convshort(s) == -2)
  2145. X            cur->strs[_strorder[i]] = NULL;
  2146. X        else if (cur->strs[_strorder[i]] == (char *) -1
  2147. X             && convshort(s) != -1) {
  2148. X#ifdef DEBUG
  2149. X            printf("$%s ", strnames[_strorder[i]]);
  2150. X#endif
  2151. X            if ((cur->strs[_strorder[i]]
  2152. X                 = _addstr(strtbl + convshort(s))) == NULL)
  2153. X                return 1;
  2154. X        } 
  2155. X    }
  2156. X
  2157. X    return 0;
  2158. X}
  2159. END_OF_FILE
  2160. if test 2573 -ne `wc -c <'gettbin.c'`; then
  2161.     echo shar: \"'gettbin.c'\" unpacked with wrong size!
  2162. fi
  2163. # end of 'gettbin.c'
  2164. fi
  2165. if test -f 'mkbinorder.c' -a "${1}" != "-c" ; then 
  2166.   echo shar: Will not clobber existing file \"'mkbinorder.c'\"
  2167. else
  2168. echo shar: Extracting \"'mkbinorder.c'\" \(1960 characters\)
  2169. sed "s/^X//" >'mkbinorder.c' <<'END_OF_FILE'
  2170. X/*
  2171. X * mkbinorder.c
  2172. X *
  2173. X * By Ross Ridge
  2174. X * Public Domain
  2175. X * 92/02/01 07:30:04
  2176. X *
  2177. X */
  2178. X
  2179. X#define NOTLIB
  2180. X#include "defs.h"
  2181. X#include "term.h"
  2182. X
  2183. static const char SCCSid[] = "@(#) mytinfo mkbinorder.c 3.2 92/02/01 public domain, By Ross Ridge";
  2184. X
  2185. char cap[MAX_NAME];
  2186. char *p2c = cap;
  2187. char **p2p2c = &p2c;
  2188. X
  2189. int
  2190. main(argc, argv)
  2191. int argc;
  2192. char **argv; {
  2193. X    int r;
  2194. X    int ind;
  2195. X    FILE *f;
  2196. X
  2197. X    if (argc == 1)
  2198. X        f = stdin;
  2199. X    else if (argc == 2) {
  2200. X        f = fopen(argv[1], "r");
  2201. X        if (f == NULL) {
  2202. X            fprintf(stderr, "can't open %s\n", argv[1]);
  2203. X            exit(1);
  2204. X        }
  2205. X    } else {
  2206. X        fprintf(stderr, "argument count\n");
  2207. X        exit(1);
  2208. X    }
  2209. X
  2210. X    do {
  2211. X        r = fscanf(f, "%s", cap);
  2212. X    } while(r == 1 && strcmp(cap, "!") != 0);
  2213. X    if (r != 1) {
  2214. X        fprintf(stderr, "expected '!'\n");
  2215. X        exit(1);
  2216. X    }
  2217. X
  2218. X    puts("/*");
  2219. X    puts(" * binorder.c");
  2220. X    puts(" *");
  2221. X    puts(" * This file was generated automatically");
  2222. X    puts(" *");
  2223. X    puts(" */\n");
  2224. X
  2225. X    puts("int _boolorder[] = {");
  2226. X
  2227. X    while(1) {
  2228. X        r = fscanf(f, "%s", cap);
  2229. X        cap[MAX_TINFONAME] = '\0';
  2230. X        if (r != 1) {
  2231. X            fprintf(stderr, "unexpected EOF\n");
  2232. X            exit(1);
  2233. X        }
  2234. X        if (strcmp(cap, "#") == 0)
  2235. X            break;
  2236. X        ind = _findboolname(cap);
  2237. X        if (ind == -1) {
  2238. X            fprintf(stderr, "unknown bool name '%s'\n", cap);
  2239. X            continue;
  2240. X        }
  2241. X        printf("\t%d,\n", ind);
  2242. X    }
  2243. X    puts("\t-1");
  2244. X    puts("};\n");
  2245. X
  2246. X    puts("int _numorder[] = {");
  2247. X
  2248. X    while(1) {
  2249. X        r = fscanf(f, "%s", cap);
  2250. X        cap[MAX_TINFONAME] = '\0';
  2251. X        if (r != 1) {
  2252. X            fprintf(stderr, "unexpected EOF\n");
  2253. X            exit(1);
  2254. X        }
  2255. X        if (strcmp(cap, "$") == 0)
  2256. X            break;
  2257. X        ind = _findnumname(cap);
  2258. X        if (ind == -1) {
  2259. X            fprintf(stderr, "unknown num name '%s'\n", cap);
  2260. X            continue;
  2261. X        }
  2262. X        printf("\t%d,\n", ind);
  2263. X    }
  2264. X    puts("\t-1");
  2265. X    puts("};\n");
  2266. X
  2267. X    puts("int _strorder[] = {");
  2268. X
  2269. X    while(1) {
  2270. X        r = fscanf(f, "%s", cap);
  2271. X        cap[MAX_TINFONAME] = '\0';
  2272. X        if (r != 1)
  2273. X            break;
  2274. X        ind = _findstrname(cap);
  2275. X        if (ind == -1) {
  2276. X            fprintf(stderr, "unknown str name '%s'\n", cap);
  2277. X            continue;
  2278. X        }
  2279. X        printf("\t%d,\n", ind);
  2280. X    }
  2281. X    puts("\t-1");
  2282. X    puts("};\n");
  2283. X
  2284. X    return 0;
  2285. X}
  2286. END_OF_FILE
  2287. if test 1960 -ne `wc -c <'mkbinorder.c'`; then
  2288.     echo shar: \"'mkbinorder.c'\" unpacked with wrong size!
  2289. fi
  2290. # end of 'mkbinorder.c'
  2291. fi
  2292. if test -f 'mkcaplist.c' -a "${1}" != "-c" ; then 
  2293.   echo shar: Will not clobber existing file \"'mkcaplist.c'\"
  2294. else
  2295. echo shar: Extracting \"'mkcaplist.c'\" \(3333 characters\)
  2296. sed "s/^X//" >'mkcaplist.c' <<'END_OF_FILE'
  2297. X/*
  2298. X * mkcaplist.c
  2299. X *
  2300. X * By Ross Ridge
  2301. X * Public Domain
  2302. X * 92/02/01 07:30:05
  2303. X *
  2304. X * mkcaplist [-n caps] [file]
  2305. X *
  2306. X * makes caplist.c from the cap_list file
  2307. X *
  2308. X */
  2309. X
  2310. X#define NOTLIB
  2311. X#include "defs.h"
  2312. X
  2313. static const char SCCSid[] = "@(#) mytinfo mkcaplist.c 3.2 92/02/01 public domain, By Ross Ridge";
  2314. X
  2315. X#define DEFAULT_CAPS    1000
  2316. X
  2317. struct caplist *list;
  2318. X
  2319. int
  2320. main(argc, argv)
  2321. int argc;
  2322. char **argv; {
  2323. X    FILE *f;
  2324. X    int caps = DEFAULT_CAPS;
  2325. X    int n;
  2326. X    register int i;
  2327. X
  2328. X    if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'n') {
  2329. X        caps = atoi(argv[2]);
  2330. X        argv += 2;
  2331. X        argc -= 2;
  2332. X    }
  2333. X
  2334. X    if (argc == 1) {
  2335. X        f = stdin;
  2336. X    } else if (argc == 2) {
  2337. X        f = fopen(argv[1], "r");
  2338. X        if (f == NULL) {
  2339. X            fprintf(stderr, "%s: can't open '%s'\n", argv[0],
  2340. X                argv[1]);
  2341. X            return 1;
  2342. X        }
  2343. X    } else {
  2344. X        fprintf(stderr, "%s: too many arguments\n", argv[0]);
  2345. X        fprintf(stderr, "usage: %s [-n caps] [file]\n", argv[0]);
  2346. X        return 1;
  2347. X    }
  2348. X
  2349. X    list = (struct caplist *) malloc(caps * sizeof(struct caplist));
  2350. X    if (list == NULL) {
  2351. X        fprintf(stderr, "%s: malloc failed.\n", argv[0]);
  2352. X        return 1;
  2353. X    }
  2354. X
  2355. X    n = readcaps(f, list, caps);
  2356. X    if (n > caps) {
  2357. X        fprintf(stderr, "%s: too many caps, use -n.\n", argv[0]);
  2358. X        return 1;
  2359. X    }
  2360. X    if (n == 0) {
  2361. X        fprintf(stderr, "%s: no caps in file.\n", argv[0]);
  2362. X        return 1;
  2363. X    }
  2364. X    if (n == -1) {
  2365. X        fprintf(stderr, "%s: bad caps line.\n", argv[0]);
  2366. X        return 1;
  2367. X    }
  2368. X    if (n == -2) {
  2369. X        fprintf(stderr, "%s: unexpected EOF.\n", argv[0]);
  2370. X        return 1;
  2371. X    }
  2372. X
  2373. X    puts("/*");
  2374. X    puts(" * caplist.c ");
  2375. X    puts(" *");
  2376. X    puts(" * This file was generated automatically.");
  2377. X    puts(" *");
  2378. X    puts(" */");
  2379. X    putchar('\n');
  2380. X
  2381. X    puts("char *boolnames[] = {");
  2382. X    for (i = 0; i < n; i++)
  2383. X        if (list[i].type == '!')
  2384. X            printf("\t\"%s\",\n", list[i].tinfo);
  2385. X    puts("\t(char *)0");
  2386. X    puts("};");
  2387. X    putchar('\n');
  2388. X
  2389. X    puts("char *boolcodes[] = {");
  2390. X    for (i = 0; i < n; i++)
  2391. X        if (list[i].type == '!')
  2392. X            printf("\t\"%s\",\n", list[i].tcap);
  2393. X    puts("\t(char *)0");
  2394. X    puts("};");
  2395. X    putchar('\n');
  2396. X
  2397. X    puts("char *boolfnames[] = {");
  2398. X    for (i = 0; i < n; i++)
  2399. X        if (list[i].type == '!')
  2400. X            printf("\t\"%s\",\n", list[i].var);
  2401. X    puts("\t(char *)0");
  2402. X    puts("};");
  2403. X    putchar('\n');
  2404. X
  2405. X    puts("char *numnames[] = {");
  2406. X    for (i = 0; i < n; i++)
  2407. X        if (list[i].type == '#')
  2408. X            printf("\t\"%s\",\n", list[i].tinfo);
  2409. X    puts("\t(char *)0");
  2410. X    puts("};");
  2411. X    putchar('\n');
  2412. X
  2413. X    puts("char *numcodes[] = {");
  2414. X    for (i = 0; i < n; i++)
  2415. X        if (list[i].type == '#')
  2416. X            printf("\t\"%s\",\n", list[i].tcap);
  2417. X    puts("\t(char *)0");
  2418. X    puts("};");
  2419. X    putchar('\n');
  2420. X
  2421. X    puts("char *numfnames[] = {");
  2422. X    for (i = 0; i < n; i++)
  2423. X        if (list[i].type == '#')
  2424. X            printf("\t\"%s\",\n", list[i].var);
  2425. X    puts("\t(char *)0");
  2426. X    puts("};");
  2427. X    putchar('\n');
  2428. X
  2429. X    puts("char *strnames[] = {");
  2430. X    for (i = 0; i < n; i++)
  2431. X        if (list[i].type == '$')
  2432. X            printf("\t\"%s\",\n", list[i].tinfo);
  2433. X    puts("\t(char *)0");
  2434. X    puts("};");
  2435. X    putchar('\n');
  2436. X
  2437. X    puts("char *strcodes[] = {");
  2438. X    for (i = 0; i < n; i++)
  2439. X        if (list[i].type == '$')
  2440. X            printf("\t\"%s\",\n", list[i].tcap);
  2441. X    puts("\t(char *)0");
  2442. X    puts("};");
  2443. X    putchar('\n');
  2444. X
  2445. X    puts("char *strfnames[] = {");
  2446. X    for (i = 0; i < n; i++)
  2447. X        if (list[i].type == '$')
  2448. X            printf("\t\"%s\",\n", list[i].var);
  2449. X    puts("\t(char *)0");
  2450. X    puts("};");
  2451. X    putchar('\n');
  2452. X
  2453. X    puts("char _strflags[] = {");
  2454. X    for (i = 0; i < n; i++)
  2455. X        if (list[i].type == '$')
  2456. X            printf("\t'%c',\n", list[i].flag);
  2457. X    puts("\t'\\0'");
  2458. X    puts("};");
  2459. X    putchar('\n');
  2460. X
  2461. X    return 0;
  2462. X}
  2463. END_OF_FILE
  2464. if test 3333 -ne `wc -c <'mkcaplist.c'`; then
  2465.     echo shar: \"'mkcaplist.c'\" unpacked with wrong size!
  2466. fi
  2467. # end of 'mkcaplist.c'
  2468. fi
  2469. if test -f 'mkcapsort.c' -a "${1}" != "-c" ; then 
  2470.   echo shar: Will not clobber existing file \"'mkcapsort.c'\"
  2471. else
  2472. echo shar: Extracting \"'mkcapsort.c'\" \(3687 characters\)
  2473. sed "s/^X//" >'mkcapsort.c' <<'END_OF_FILE'
  2474. X/*
  2475. X * mkcapsort.c
  2476. X *
  2477. X * By Ross Ridge
  2478. X * Public Domain
  2479. X * 92/06/04 11:38:02
  2480. X *
  2481. X * mkcapsort
  2482. X *
  2483. X * make the sorted lists of pointers to strins
  2484. X *
  2485. X */
  2486. X
  2487. X#define NOTLIB
  2488. X#include "defs.h"
  2489. X#include "term.h"
  2490. X
  2491. X#ifdef USE_MYQSORT
  2492. X#include "qsort.c"
  2493. X#endif
  2494. X
  2495. static const char SCCSid[] = "@(#) mytinfo mkcapsort.c 3.3 92/06/04 public domain, By Ross Ridge";
  2496. X
  2497. char **sboolnames[NUM_OF_BOOLS], **sboolcodes[NUM_OF_BOOLS], **sboolfnames[NUM_OF_BOOLS];
  2498. char **snumnames[NUM_OF_NUMS], **snumcodes[NUM_OF_NUMS], **snumfnames[NUM_OF_NUMS];
  2499. char **sstrnames[NUM_OF_STRS], **sstrcodes[NUM_OF_STRS], **sstrfnames[NUM_OF_STRS];
  2500. X
  2501. X
  2502. int
  2503. main() {
  2504. X    register int i;
  2505. X    
  2506. X    i = NUM_OF_BOOLS;
  2507. X    while(i) {
  2508. X        i--;
  2509. X        sboolnames[i] = &boolnames[i];
  2510. X        sboolcodes[i] = &boolcodes[i];
  2511. X        sboolfnames[i] = &boolfnames[i];
  2512. X    }
  2513. X    
  2514. X    i = NUM_OF_NUMS;
  2515. X    while(i) {
  2516. X        i--;
  2517. X        snumnames[i] = &numnames[i];
  2518. X        snumcodes[i] = &numcodes[i];
  2519. X        snumfnames[i] = &numfnames[i];
  2520. X    }
  2521. X
  2522. X    i = NUM_OF_STRS;
  2523. X    while(i) {
  2524. X        i--;
  2525. X        sstrnames[i] = &strnames[i];
  2526. X        sstrcodes[i] = &strcodes[i];
  2527. X        sstrfnames[i] = &strfnames[i];
  2528. X    }
  2529. X
  2530. X    qsort((anyptr) sboolnames, NUM_OF_BOOLS, sizeof(*sboolnames), _compar);
  2531. X    qsort((anyptr) sboolcodes, NUM_OF_BOOLS, sizeof(*sboolcodes), _compar);
  2532. X    qsort((anyptr) sboolfnames, NUM_OF_BOOLS, sizeof(*sboolfnames),_compar);
  2533. X    qsort((anyptr) snumnames, NUM_OF_NUMS, sizeof(*snumnames), _compar);
  2534. X    qsort((anyptr) snumcodes, NUM_OF_NUMS, sizeof(*snumcodes), _compar);
  2535. X    qsort((anyptr) snumfnames, NUM_OF_NUMS, sizeof(*snumfnames), _compar);
  2536. X    qsort((anyptr) sstrnames, NUM_OF_STRS, sizeof(*sstrnames), _compar);
  2537. X    qsort((anyptr) sstrcodes, NUM_OF_STRS, sizeof(*sstrcodes), _compar);
  2538. X    qsort((anyptr) sstrfnames, NUM_OF_STRS, sizeof(*sstrfnames), _compar);
  2539. X
  2540. X    printf("/*\n");
  2541. X    printf(" * capsort.c\n");
  2542. X    printf(" *\n");
  2543. X    printf(" * This file was generated automatically.\n");
  2544. X    printf(" *\n");
  2545. X    printf(" */\n\n");
  2546. X
  2547. X    puts("extern char *boolnames[], *boolcodes[], *boolfnames[];");
  2548. X    puts("extern char *numnames[], *numcodes[], *numfnames[];");
  2549. X    puts("extern char *strnames[], *strcodes[], *strfnames[];");
  2550. X    putchar('\n');
  2551. X
  2552. X    printf("char **_sboolnames[] = {\n");
  2553. X    for(i = 0; i < NUM_OF_BOOLS; i++)
  2554. X        printf("\tboolnames + %d,\n", sboolnames[i] - boolnames);
  2555. X    printf("    (char **) 0\n");
  2556. X    printf("};\n\n");
  2557. X
  2558. X    printf("char **_sboolcodes[] = {\n");
  2559. X    for(i = 0; i < NUM_OF_BOOLS; i++)
  2560. X        printf("\tboolcodes + %d,\n", sboolcodes[i] - boolcodes);
  2561. X    printf("    (char **) 0\n");
  2562. X    printf("};\n\n");
  2563. X
  2564. X    printf("char **_sboolfnames[] = {\n");
  2565. X    for(i = 0; i < NUM_OF_BOOLS; i++)
  2566. X        printf("\tboolfnames + %d,\n", sboolfnames[i] - boolfnames);
  2567. X    printf("    (char **) 0\n");
  2568. X    printf("};\n\n");
  2569. X
  2570. X    printf("char **_snumnames[] = {\n");
  2571. X    for(i = 0; i < NUM_OF_NUMS; i++)
  2572. X        printf("\tnumnames + %d,\n", snumnames[i] - numnames);
  2573. X    printf("    (char **) 0\n");
  2574. X    printf("};\n\n");
  2575. X
  2576. X    printf("char **_snumcodes[] = {\n");
  2577. X    for(i = 0; i < NUM_OF_NUMS; i++)
  2578. X        printf("\tnumcodes + %d,\n", snumcodes[i] - numcodes);
  2579. X    printf("    (char **) 0\n");
  2580. X    printf("};\n\n");
  2581. X
  2582. X    printf("char **_snumfnames[] = {\n");
  2583. X    for(i = 0; i < NUM_OF_NUMS; i++)
  2584. X        printf("\tnumfnames + %d,\n", snumfnames[i] - numfnames);
  2585. X    printf("    (char **) 0\n");
  2586. X    printf("};\n\n");
  2587. X
  2588. X    printf("char **_sstrnames[] = {\n");
  2589. X    for(i = 0; i < NUM_OF_STRS; i++)
  2590. X        printf("\tstrnames + %d,\n", sstrnames[i] - strnames);
  2591. X    printf("    (char **) 0\n");
  2592. X    printf("};\n\n");
  2593. X
  2594. X    printf("char **_sstrcodes[] = {\n");
  2595. X    for(i = 0; i < NUM_OF_STRS; i++) 
  2596. X        printf("\tstrcodes + %d,\n", sstrcodes[i] - strcodes);
  2597. X    printf("    (char **) 0\n");
  2598. X    printf("};\n\n");
  2599. X
  2600. X    printf("char **_sstrfnames[] = {\n");
  2601. X    for(i = 0; i < NUM_OF_STRS; i++)
  2602. X        printf("\tstrfnames + %d,\n", sstrfnames[i] - strfnames);
  2603. X    printf("    (char **) 0\n");
  2604. X    printf("};\n\n");
  2605. X
  2606. X    return 0;
  2607. X}
  2608. END_OF_FILE
  2609. if test 3687 -ne `wc -c <'mkcapsort.c'`; then
  2610.     echo shar: \"'mkcapsort.c'\" unpacked with wrong size!
  2611. fi
  2612. # end of 'mkcapsort.c'
  2613. fi
  2614. if test -f 'mkdir.c' -a "${1}" != "-c" ; then 
  2615.   echo shar: Will not clobber existing file \"'mkdir.c'\"
  2616. else
  2617. echo shar: Extracting \"'mkdir.c'\" \(570 characters\)
  2618. sed "s/^X//" >'mkdir.c' <<'END_OF_FILE'
  2619. X/*
  2620. X * mkdir.c
  2621. X *
  2622. X * By Ross Ridge
  2623. X * Public Domain
  2624. X * 92/06/04 11:38:33
  2625. X */
  2626. X
  2627. X#ifdef USE_MYMKDIR
  2628. X
  2629. X#define MKDIR_COMMAND "/bin/mkdir"
  2630. X
  2631. X#ifdef USE_SCCS_IDS
  2632. static char const SCCSid[] = "@(#) mytinfo mkdir.c 3.2 92/06/04 public domain, By Ross Ridge";
  2633. X#endif
  2634. X
  2635. static int
  2636. mkdir(name, perms) 
  2637. char *name;
  2638. int perms; {
  2639. X    static const char cmd[] = MKDIR_COMMAND;
  2640. X    char *s;
  2641. X
  2642. X    s = malloc(strlen(name) + sizeof(cmd) + 1);
  2643. X    if (s == NULL) {
  2644. X        return -1;
  2645. X    }
  2646. X    sprintf(s, "%s %s", cmd, name);
  2647. X    if (system(s)) {
  2648. X        free(s);
  2649. X        return -1;
  2650. X    }
  2651. X    free(s);
  2652. X    return chmod(name, perms);
  2653. X}
  2654. X
  2655. X#endif
  2656. END_OF_FILE
  2657. if test 570 -ne `wc -c <'mkdir.c'`; then
  2658.     echo shar: \"'mkdir.c'\" unpacked with wrong size!
  2659. fi
  2660. # end of 'mkdir.c'
  2661. fi
  2662. if test -f 'mktermhead.c' -a "${1}" != "-c" ; then 
  2663.   echo shar: Will not clobber existing file \"'mktermhead.c'\"
  2664. else
  2665. echo shar: Extracting \"'mktermhead.c'\" \(2916 characters\)
  2666. sed "s/^X//" >'mktermhead.c' <<'END_OF_FILE'
  2667. X/*
  2668. X * mktermhead.c
  2669. X *
  2670. X * By Ross Ridge
  2671. X * Public Domain 
  2672. X * 92/06/04 11:38:57
  2673. X *
  2674. X * mktermhead [-n caps] file
  2675. X *
  2676. X * generates term.head
  2677. X *
  2678. X */
  2679. X
  2680. X#define NOTLIB
  2681. X#include "defs.h"
  2682. X
  2683. static const char SCCSid[] = "@(#) mytinfo mktermhead.c 3.3 92/06/04 public domain, By Ross Ridge";
  2684. X
  2685. X#define DEFAULT_CAPS    1000
  2686. X
  2687. X
  2688. int
  2689. main(argc, argv)
  2690. int argc;
  2691. char **argv; {
  2692. X    FILE *f;
  2693. X    int caps = DEFAULT_CAPS;
  2694. X    int n;
  2695. X    register int i;
  2696. X    int nb, ns, nn;
  2697. X    struct caplist *list;
  2698. X
  2699. X    if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'n') {
  2700. X        caps = atoi(argv[2]);
  2701. X        argv += 2;
  2702. X        argc -= 2;
  2703. X    }
  2704. X
  2705. X    if (argc == 1) {
  2706. X        f = stdin;
  2707. X    } else if (argc == 2) {
  2708. X        f = fopen(argv[1], "r");
  2709. X        if (f == NULL) {
  2710. X            fprintf(stderr, "%s: can't open '%s'\n", argv[0],
  2711. X                argv[1]);
  2712. X            return 1;
  2713. X        }
  2714. X    } else {
  2715. X        fprintf(stderr, "%s: too many arguments\n", argv[0]);
  2716. X        fprintf(stderr, "usage: %s [-n caps] [file]\n", argv[0]);
  2717. X        return 1;
  2718. X    }
  2719. X
  2720. X    list = (struct caplist *) malloc(caps * sizeof(struct caplist));
  2721. X    if (list == NULL) {
  2722. X        fprintf(stderr, "%s: malloc failed.\n", argv[0]);
  2723. X        return 1;
  2724. X    }
  2725. X
  2726. X    n = readcaps(f, list, caps);
  2727. X    if (n > caps) {
  2728. X        fprintf(stderr, "%s: too many caps, use -n.\n", argv[0]);
  2729. X        return 1;
  2730. X    }
  2731. X    switch(n) {
  2732. X    case 0:
  2733. X        fprintf(stderr, "%s: no caps in file.\n", argv[0]);
  2734. X        return 1;
  2735. X    case -1:
  2736. X        fprintf(stderr, "%s: bad caps line.\n", argv[0]);
  2737. X        return 1;
  2738. X    case -2:
  2739. X        fprintf(stderr, "%s: unexpected EOF.\n", argv[0]);
  2740. X        return 1;
  2741. X    }
  2742. X
  2743. X    puts("/*");
  2744. X    puts(" * term.h ");
  2745. X    puts(" *");
  2746. X    puts(" * This file was generated automatically.");
  2747. X    puts(" *");
  2748. X    puts(" */");
  2749. X    putchar('\n');
  2750. X    puts("#ifndef _TERM_H_");
  2751. X    puts("#define _TERM_H_");
  2752. X    putchar('\n');
  2753. X    nb = 0;
  2754. X    for (i = 0; i < n; i++) {
  2755. X        if (list[i].type == '!') {
  2756. X            printf("#define %-*s (_CUR_TERM.bools[%d])\n",
  2757. X                   MAX_VARNAME, list[i].var, nb);
  2758. X            nb++;
  2759. X        }
  2760. X    }
  2761. X
  2762. X    nn = 0;
  2763. X    for (i = 0; i < n; i++) {
  2764. X        if (list[i].type == '#') {
  2765. X            printf("#define %-*s (_CUR_TERM.nums[%d])\n",
  2766. X                   MAX_VARNAME, list[i].var, nn);
  2767. X            nn++;
  2768. X        }
  2769. X    }
  2770. X
  2771. X    ns = 0;
  2772. X    for (i = 0; i < n; i++) {
  2773. X        if (list[i].type == '$') {
  2774. X            printf("#define %-*s (_CUR_TERM.strs[%d])\n",
  2775. X                   MAX_VARNAME, list[i].var, ns);
  2776. X            ns++;
  2777. X        }
  2778. X    }
  2779. X
  2780. X    putchar('\n');
  2781. X
  2782. X    printf ("#define NUM_OF_BOOLS\t%d\n", nb);
  2783. X    printf ("#define NUM_OF_NUMS\t%d\n", nn);
  2784. X    printf ("#define NUM_OF_STRS\t%d\n", ns);
  2785. X
  2786. X    putchar('\n');
  2787. X    puts("#ifndef OVERRIDE");
  2788. X    puts("#undef _USE_SGTTY");
  2789. X#ifdef USE_SGTTY
  2790. X    puts("#define _USE_SGTTY");
  2791. X#endif
  2792. X    puts("#undef _USE_TERMIO");
  2793. X#ifdef USE_TERMIO
  2794. X    puts("#define _USE_TERMIO");
  2795. X#endif
  2796. X    puts("#undef _USE_SMALLMEM");
  2797. X#ifdef USE_SMALLMEM
  2798. X    puts("#define _USE_SMALLMEM");
  2799. X#endif
  2800. X#if 0
  2801. X    puts("#undef _USE_PROTOTYPES");
  2802. X#ifdef USE_PROTOTYPES
  2803. X    puts("#define _USE_PROTOTYPES");
  2804. X#endif
  2805. X#endif
  2806. X    puts("#undef _USE_WINSZ");
  2807. X#ifdef USE_WINSZ
  2808. X    puts("#define _USE_WINSZ");
  2809. X#endif
  2810. X    puts("#undef _MAX_CHUNK");
  2811. X    printf("#define _MAX_CHUNK %d\n", MAX_CHUNK);
  2812. X    puts("#endif /* OVERRIDE */");
  2813. X    putchar('\n');
  2814. X
  2815. X    return 0;
  2816. X}
  2817. END_OF_FILE
  2818. if test 2916 -ne `wc -c <'mktermhead.c'`; then
  2819.     echo shar: \"'mktermhead.c'\" unpacked with wrong size!
  2820. fi
  2821. # end of 'mktermhead.c'
  2822. fi
  2823. if test -f 'mkversion.c' -a "${1}" != "-c" ; then 
  2824.   echo shar: Will not clobber existing file \"'mkversion.c'\"
  2825. else
  2826. echo shar: Extracting \"'mkversion.c'\" \(588 characters\)
  2827. sed "s/^X//" >'mkversion.c' <<'END_OF_FILE'
  2828. X/*
  2829. X * mkversion.c
  2830. X *
  2831. X * By Ross Ridge
  2832. X * Public Domain 
  2833. X * 92/02/01 07:30:09
  2834. X *
  2835. X * generates version.c
  2836. X *
  2837. X */
  2838. X
  2839. X#define NOTLIB
  2840. X#include "defs.h"
  2841. X
  2842. X#include "version.h"
  2843. X
  2844. static const char SCCSid[] = "@(#) mytinfo mkversion.c 3.2 92/02/01 public domain, By Ross Ridge";
  2845. X
  2846. int
  2847. main(argc, argv)
  2848. int argc;
  2849. char **argv; {
  2850. X    puts("/*");
  2851. X    puts(" * version.c ");
  2852. X    puts(" *");
  2853. X    puts(" * This file was generated automatically.");
  2854. X    puts(" *");
  2855. X    puts(" */");
  2856. X    putchar('\n');
  2857. X
  2858. X    printf("char _mytinfo_version[] = \"@(#) mytinfo: Release %d, Patchlevel %d.\";\n",
  2859. X           RELEASE, PATCHLEVEL);
  2860. X
  2861. X    return 0;
  2862. X}
  2863. END_OF_FILE
  2864. if test 588 -ne `wc -c <'mkversion.c'`; then
  2865.     echo shar: \"'mkversion.c'\" unpacked with wrong size!
  2866. fi
  2867. # end of 'mkversion.c'
  2868. fi
  2869. if test -f 'quit.c' -a "${1}" != "-c" ; then 
  2870.   echo shar: Will not clobber existing file \"'quit.c'\"
  2871. else
  2872. echo shar: Extracting \"'quit.c'\" \(1053 characters\)
  2873. sed "s/^X//" >'quit.c' <<'END_OF_FILE'
  2874. X/*
  2875. X * quit.c
  2876. X *
  2877. X * By Ross Ridge
  2878. X * Public Domain
  2879. X * 92/02/01 07:30:14
  2880. X *
  2881. X * quit with a diagnostic message printed on stderr
  2882. X *
  2883. X */
  2884. X
  2885. X#define NOTLIB
  2886. X#include "defs.h"
  2887. X
  2888. X#ifdef USE_SCCS_IDS
  2889. static const char SCCSid[] = "@(#) mytinfo quit.c 3.2 92/02/01 public domain, By Ross Ridge";
  2890. X#endif
  2891. X
  2892. char *prg_name;
  2893. X
  2894. X#if defined(USE_PROTOTYPES) && !defined(lint)
  2895. void (*cleanup)(int);
  2896. X#else
  2897. void (*cleanup)();
  2898. X#endif
  2899. X
  2900. X/* PRINTFLIKE2 */
  2901. X#ifdef USE_STDARG
  2902. X#ifdef USE_PROTOTYPES
  2903. void
  2904. quit(int e, char *fmt, ...)
  2905. X#else
  2906. void quit(e, fmt)
  2907. int e;
  2908. char *fmt;
  2909. X#endif
  2910. X#else
  2911. void quit(va_alist)
  2912. va_dcl
  2913. X#endif
  2914. X{
  2915. X#ifndef USE_STDARG
  2916. X    int e;
  2917. X    char *fmt;
  2918. X#endif
  2919. X    va_list ap;
  2920. X
  2921. X#ifdef USE_STDARG
  2922. X    va_start(ap, fmt);
  2923. X#else
  2924. X    va_start(ap);
  2925. X    e = va_arg(ap, int);
  2926. X    fmt = va_arg(ap, char *);
  2927. X#endif
  2928. X
  2929. X    (*cleanup)(e);
  2930. X
  2931. X    if (e != 0)
  2932. X        fprintf(stderr, "%s: ", prg_name);
  2933. X#ifdef USE_DOPRNT
  2934. X    _doprnt(fmt, ap, stderr);
  2935. X#else
  2936. X    vfprintf(stderr, fmt, ap);
  2937. X#endif
  2938. X    putc('\n', stderr);
  2939. X    if (e > 0 && e < sys_nerr) {
  2940. X        fprintf(stderr, "%d - %s\n", e, sys_errlist[e]);
  2941. X    }
  2942. X    fflush(stderr);
  2943. X    exit(e);
  2944. X}
  2945. END_OF_FILE
  2946. if test 1053 -ne `wc -c <'quit.c'`; then
  2947.     echo shar: \"'quit.c'\" unpacked with wrong size!
  2948. fi
  2949. # end of 'quit.c'
  2950. fi
  2951. if test -f 'readcaps.c' -a "${1}" != "-c" ; then 
  2952.   echo shar: Will not clobber existing file \"'readcaps.c'\"
  2953. else
  2954. echo shar: Extracting \"'readcaps.c'\" \(2264 characters\)
  2955. sed "s/^X//" >'readcaps.c' <<'END_OF_FILE'
  2956. X/*
  2957. X * readcaps.c
  2958. X *
  2959. X * By Ross Ridge
  2960. X * Public Domain
  2961. X * 92/02/01 07:30:15
  2962. X *
  2963. X * Read in the cap_list file
  2964. X *
  2965. X */
  2966. X
  2967. X#define NOTLIB
  2968. X#include "defs.h"
  2969. X
  2970. X#include <ctype.h>
  2971. X
  2972. X#ifdef USE_SCCS_IDS
  2973. static const char SCCSid[] = "@(#) mytinfo readcaps.c 3.2 92/02/01 public domain, By Ross Ridge";
  2974. X#endif
  2975. X
  2976. X#ifdef __GNUC__
  2977. X__inline__
  2978. X#endif
  2979. static int
  2980. skipline(f)
  2981. register FILE *f; {
  2982. X    register int c;
  2983. X
  2984. X    do {
  2985. X        c = getc(f);
  2986. X        if (c == EOF)
  2987. X            return EOF;
  2988. X#ifdef TEST
  2989. X        putchar(c);
  2990. X#endif
  2991. X    } while (c != '\n');
  2992. X
  2993. X    return 0;
  2994. X}
  2995. X
  2996. X#ifdef __GNUC__
  2997. X__inline__
  2998. X#endif
  2999. static int
  3000. getfield(f, s, len)
  3001. register FILE *f;
  3002. register char *s;
  3003. int len; {
  3004. X    register int c;
  3005. X    int i;
  3006. X#ifdef TEST
  3007. X    char *start = s;
  3008. X#endif
  3009. X
  3010. X    do {
  3011. X        c = getc(f);
  3012. X        if (c == EOF)
  3013. X            return EOF;
  3014. X    } while (c != '\n' && isspace(c));
  3015. X    if (c == '\n')
  3016. X        return 0;
  3017. X
  3018. X    i = 0;
  3019. X    while(!isspace(c)) {
  3020. X        if (i++ < len)
  3021. X            *s++ = c;
  3022. X        c = getc(f);
  3023. X        if (c == EOF)
  3024. X            return EOF;
  3025. X            
  3026. X    }
  3027. X    *s = '\0';
  3028. X#ifdef TEST
  3029. X    printf(" %s", start);
  3030. X#endif
  3031. X    return c;
  3032. X}
  3033. X
  3034. int
  3035. readcaps(f, buf, max)
  3036. XFILE *f;
  3037. register struct caplist *buf;
  3038. int max; {
  3039. X    int type;
  3040. X    register int count;
  3041. X    int c;
  3042. X    static char dummy;
  3043. X
  3044. X    count = 0;
  3045. X    type = getc(f);
  3046. X    while(type != EOF) {
  3047. X        if (type == '$' || type == '!' || type == '#') {
  3048. X            if (count >= max)
  3049. X                return count + 1;
  3050. X#ifdef TEST
  3051. X            putchar(type);
  3052. X#endif
  3053. X            buf[count].type = type;
  3054. X
  3055. X            if (type == '$') {
  3056. X                c = getc(f);
  3057. X                if (c == EOF)
  3058. X                    break;
  3059. X                if (c == 'G')
  3060. X                    buf[count].flag = 'G';
  3061. X                else if (c == 'K')
  3062. X                    buf[count].flag = 'K';
  3063. X                else
  3064. X                    buf[count].flag = ' ';
  3065. X            }
  3066. X    
  3067. X            c = getfield(f, buf[count].var, MAX_VARNAME);
  3068. X            if (c == EOF || c == '\n' || c == 0)
  3069. X                return -1;
  3070. X            c = getfield(f, buf[count].tinfo, MAX_TINFONAME);
  3071. X            if (c == EOF || c == '\n' || c == 0)
  3072. X                return -1;
  3073. X            c = getfield(f, buf[count].tcap, MAX_TCAPNAME);
  3074. X            if (c == EOF || c == 0)
  3075. X                return -1;
  3076. X            if (c != '\n')
  3077. X                if (getfield(f, &dummy, 1) != 0)
  3078. X                    return -1;
  3079. X            count++;
  3080. X#ifdef TEST
  3081. X            putchar('\n');
  3082. X#endif
  3083. X        } else {
  3084. X#ifdef TEST
  3085. X            putchar(type);
  3086. X#endif
  3087. X            if (type != '\n' && skipline(f) == EOF)
  3088. X                return -1;
  3089. X        }
  3090. X        type = getc(f);
  3091. X    }
  3092. X    return count;
  3093. X}
  3094. X
  3095. X#ifdef TEST
  3096. struct caplist list[1000];
  3097. X
  3098. int
  3099. main() {
  3100. X    int ret;
  3101. X
  3102. X    ret = readcaps(stdin, list, 1000);
  3103. X    printf("ret = %d\n", ret);
  3104. X    return 0;
  3105. X}
  3106. X#endif
  3107. END_OF_FILE
  3108. if test 2264 -ne `wc -c <'readcaps.c'`; then
  3109.     echo shar: \"'readcaps.c'\" unpacked with wrong size!
  3110. fi
  3111. # end of 'readcaps.c'
  3112. fi
  3113. if test -f 'strtok.c' -a "${1}" != "-c" ; then 
  3114.   echo shar: Will not clobber existing file \"'strtok.c'\"
  3115. else
  3116. echo shar: Extracting \"'strtok.c'\" \(1366 characters\)
  3117. sed "s/^X//" >'strtok.c' <<'END_OF_FILE'
  3118. X/*
  3119. X * strtok.c
  3120. X *
  3121. X * By Ross Ridge
  3122. X * Public Domain
  3123. X * 92/06/04 11:40:12
  3124. X *
  3125. X */
  3126. X
  3127. X#ifdef TEST
  3128. X
  3129. X#ifndef LIBTEST
  3130. X#define USE_MYSTRTOK
  3131. X#endif
  3132. X#include <stdio.h>
  3133. X
  3134. X#else
  3135. X
  3136. X#include "defs.h"
  3137. X
  3138. X#endif
  3139. X
  3140. X#ifdef USE_MYSTRTOK
  3141. X
  3142. X#ifdef USE_SCCS_IDS
  3143. static const char SCCSid[] = "@(#) mytinfo strtok.c 3.3 92/06/04 public domain, By Ross Ridge";
  3144. X#endif
  3145. X
  3146. static char *
  3147. strtok(s1, s2)
  3148. char *s1, *s2; {
  3149. X    static char *pos = NULL;
  3150. X    register char *s, *d;
  3151. X    char *start;
  3152. X
  3153. X    if (s1 == NULL) {
  3154. X        s = pos;
  3155. X        if (s == NULL)
  3156. X            return NULL;
  3157. X    } else {
  3158. X        s = s1;
  3159. X        while(*s != '\0') {
  3160. X            d = s2;
  3161. X            while(*d != *s) {
  3162. X                if (*d == '\0')
  3163. X                    goto first; /* Oh, no! A goto! */
  3164. X                d++;
  3165. X            }
  3166. X            s++;
  3167. X        }
  3168. X        pos = NULL;
  3169. X        return NULL;
  3170. X    }
  3171. X
  3172. first:
  3173. X    start = s;
  3174. X    while(*s != '\0') {
  3175. X        d = s2;
  3176. X        while(*d != '\0') {
  3177. X            if (*s == *d) {
  3178. X                *s++ = '\0';
  3179. X                while(*s != '\0') {
  3180. X                    d = s2;
  3181. X                    while(*s != *d) {
  3182. X                        if (*d == '\0') {
  3183. X                            pos = s;
  3184. X                            return start;
  3185. X                        }
  3186. X                        d++;
  3187. X                    }
  3188. X                    s++;
  3189. X                }
  3190. X                pos = NULL;
  3191. X                return start;
  3192. X            }
  3193. X            d++;
  3194. X        }
  3195. X        s++;
  3196. X    }
  3197. X    pos = NULL;
  3198. X    return start;
  3199. X}
  3200. X
  3201. X#endif
  3202. X
  3203. X#ifdef TEST
  3204. int main(argc, argv)
  3205. int argc;
  3206. char **argv; {
  3207. X    char *s;
  3208. X    char s1[100];
  3209. X    char *s2;
  3210. X
  3211. X    if (argc > 1)
  3212. X        s2 = argv[1];
  3213. X    else
  3214. X        s2 = " ";
  3215. X
  3216. X    while (gets(s1) != NULL) {
  3217. X        s = strtok(s1, s2);
  3218. X        while(s != NULL) {
  3219. X            printf("'%s'\n", s);
  3220. X            s = strtok(NULL, s2);
  3221. X        }
  3222. X    }
  3223. X
  3224. X    return 0;
  3225. X}
  3226. X#endif
  3227. END_OF_FILE
  3228. if test 1366 -ne `wc -c <'strtok.c'`; then
  3229.     echo shar: \"'strtok.c'\" unpacked with wrong size!
  3230. fi
  3231. # end of 'strtok.c'
  3232. fi
  3233. if test -f 'tcapvars.c' -a "${1}" != "-c" ; then 
  3234.   echo shar: Will not clobber existing file \"'tcapvars.c'\"
  3235. else
  3236. echo shar: Extracting \"'tcapvars.c'\" \(524 characters\)
  3237. sed "s/^X//" >'tcapvars.c' <<'END_OF_FILE'
  3238. X/*
  3239. X * tcapvars.c
  3240. X *
  3241. X * By Ross Ridge
  3242. X * Public Domain
  3243. X * 92/02/01 07:30:21
  3244. X *
  3245. X */
  3246. X
  3247. X#include "defs.h"
  3248. X#include "term.h"
  3249. X
  3250. X#ifdef USE_SCCS_IDS
  3251. static const char SCCSid[] = "@(#) mytinfo tcapvars.c 3.2 92/02/01 public domain, By Ross Ridge";
  3252. X#endif
  3253. X
  3254. char PC;
  3255. short ospeed;
  3256. char *UP, *BC;
  3257. X
  3258. void
  3259. X_figure_termcap() {
  3260. X#if defined(USE_SGTTY) || defined(USE_TERMIO)
  3261. X#ifdef USE_SMALLMEM
  3262. X    extern unsigned short _baud_tbl[];
  3263. X#else
  3264. X    extern long _baud_tbl[];
  3265. X#endif
  3266. X    cur_term->padch = PC;
  3267. X    cur_term->baudrate = _baud_tbl[ospeed];
  3268. X#endif
  3269. X}
  3270. END_OF_FILE
  3271. if test 524 -ne `wc -c <'tcapvars.c'`; then
  3272.     echo shar: \"'tcapvars.c'\" unpacked with wrong size!
  3273. fi
  3274. # end of 'tcapvars.c'
  3275. fi
  3276. if test -f 'tconv.1' -a "${1}" != "-c" ; then 
  3277.   echo shar: Will not clobber existing file \"'tconv.1'\"
  3278. else
  3279. echo shar: Extracting \"'tconv.1'\" \(3823 characters\)
  3280. sed "s/^X//" >'tconv.1' <<'END_OF_FILE'
  3281. X.\" @(#) mytinfo tconv.1 3.2 92/02/01 public domain, By Ross Ridge
  3282. X.TH CONV 1 "92/02/01" "tinfo"
  3283. X.SH NAME
  3284. tconv \- convert between termcap, terminfo source and terminfo binary
  3285. X.SH SYNOPSIS
  3286. X.B tconv
  3287. X[\fB\-b\fR]
  3288. X[\fB\-c\fR\ [\fB\-OUGd\fR]]
  3289. X[\fB\-i\fR]
  3290. X[\fB\-B\fR\ [\fB\-D\fR\ dir]]
  3291. X[\fB\-I\fR]
  3292. X[\fB\-k\fR]
  3293. X[\fB\-V\fR]
  3294. X[\fB\-t\fR\ term]
  3295. X[file]
  3296. X.br
  3297. X.B tic
  3298. X[file]
  3299. X.br
  3300. X.B cap2info
  3301. X[\fB\-t\fR\ term]
  3302. X[\fB\-OUGdk\fR]]
  3303. X[file]
  3304. X.SH DESCRIPTION
  3305. X.I tconv
  3306. converts between the three terminal descriptions,
  3307. termcap, terminfo source, and terminfo binary,
  3308. that the
  3309. X.I tinfo
  3310. library uses.
  3311. It performs the same functions of
  3312. X.IR captoinfo (1M)
  3313. and 
  3314. X.IR tic (1M)
  3315. of System V.
  3316. It also can be used to generate a terminfo source listing from a terminfo
  3317. binary, one of the functions of System V's
  3318. X.IR infocmp (1M).
  3319. X.SS Translation Options
  3320. X.PD 0
  3321. X.TP
  3322. X.B \-c
  3323. convert from termcap
  3324. X.TP
  3325. X.B \-i
  3326. convert from terminfo source
  3327. X.TP
  3328. X.B \-b
  3329. convert from terminfo binary
  3330. X.TP
  3331. X.B \-B
  3332. convert to terminfo binary
  3333. X.TP
  3334. X.B \-I
  3335. convert to terminfo source
  3336. X.PD
  3337. X.PP
  3338. If a file is specified, one of
  3339. X.B \-c
  3340. or
  3341. X.B \-i
  3342. must specified and the whole file while be translated.
  3343. If no file is specified then the input options will only restrict looking
  3344. for the terminal to be translated in places likely have descriptions
  3345. of the desired type
  3346. X(ie. with the
  3347. X.B -c
  3348. option in the
  3349. X.B TERMCAP
  3350. environment variable, and in
  3351. X.IR /etc/termcap ,
  3352. with the
  3353. X.B -i
  3354. option in the
  3355. X.B TERMINFO
  3356. environment variable, and in
  3357. X.IR /usr/lib/terminfo ),
  3358. otherwise
  3359. X.I tconv
  3360. will look in all available databases.
  3361. If neither 
  3362. X.B \-I
  3363. or
  3364. X.B \-B
  3365. are given the
  3366. X.B \-I
  3367. option will be assumed.
  3368. If the 
  3369. X.B \-B
  3370. option is used, the compiled output will be put in the the
  3371. terminfo database, otherwise standard output is used.
  3372. X.PP
  3373. You cannot translate from terminfo binary to terminfo binary.
  3374. Translating from terminfo source to terminfo source is possible, 
  3375. but not of much use in most cases, as 
  3376. X.B use=
  3377. fields will be followed and incorporated into the output terminal
  3378. description. 
  3379. X.PP
  3380. X.I tconv
  3381. should be able translate all standard termcap parameterized strings
  3382. terminfo format, but complex strings using GNU's %a code may be
  3383. too hard to translate.
  3384. If
  3385. X.I tconv
  3386. thinks a termcap string is already in terminfo format (if a %p
  3387. code appears in the string), it won't try to translate it.
  3388. String capabilities that don't take parameters won't be translated.
  3389. X.PP
  3390. X.B 
  3391. X.SS Termcap options
  3392. The following options are available when translating termcap entries 
  3393. X(\fB\-c\fR options is used).
  3394. X.PP
  3395. X.PD 0
  3396. X.TP 
  3397. X.B \-d
  3398. don't supply any defaults for missing capabilities
  3399. X.TP
  3400. X.B \-O
  3401. include obsolete termcap capabilities
  3402. X.TP
  3403. X.B \-G
  3404. include GNU capabilities
  3405. X.TP
  3406. X.B \-U
  3407. include UW capabilities
  3408. X.PD
  3409. X.SS Other Options
  3410. X.PD 0
  3411. X.TP
  3412. X.B \-k
  3413. keep comments when translating a file
  3414. X.TP
  3415. X.B \-V
  3416. print version information and exit
  3417. X.TP
  3418. X.BI \-D " " dir
  3419. directory to put terminfo binaries in
  3420. X.TP
  3421. X.BI \-t " " term
  3422. terminal name to translate
  3423. X.PD
  3424. X.PP
  3425. If no terminal specified with the
  3426. X.B \-t
  3427. option, then the terminal name to to translate will be taken from the
  3428. environment variable
  3429. X.BR TERM .
  3430. X.SH FILES
  3431. X.PD 0
  3432. X.TP 2i
  3433. X.B /usr/lib/terminfo
  3434. The default location to get and put terminfo binaries.
  3435. X.TP
  3436. X.B /usr/lib/terminfo/terminfo.src
  3437. The default filename of the terminfo source file.
  3438. X.TP
  3439. X.B /etc/termcap
  3440. The default filename of the termcap database.
  3441. X.PD
  3442. X.SH "SEE ALSO"
  3443. captoinfo(1M),
  3444. tic(1M),
  3445. infocmp(1M),
  3446. termcap(3),
  3447. curses(3X),
  3448. term(4),
  3449. termcap(4),
  3450. terminfo(4).
  3451. X.SH DIAGNOSTICS
  3452. The line number of a warning message when translating a file
  3453. may refer to the last line of an entry instead of the line in the entry 
  3454. that generated the warning.
  3455. X.SH BUGS
  3456. More warning messages could be generated.
  3457. X.I tconv
  3458. can't translate to termcap.  Binaries generated will have cancelled
  3459. capabilities marked as cancelled, which is incompatible with
  3460. System V Release 2.0 terminfo.
  3461. END_OF_FILE
  3462. if test 3823 -ne `wc -c <'tconv.1'`; then
  3463.     echo shar: \"'tconv.1'\" unpacked with wrong size!
  3464. fi
  3465. # end of 'tconv.1'
  3466. fi
  3467. if test -f 'term.tail' -a "${1}" != "-c" ; then 
  3468.   echo shar: Will not clobber existing file \"'term.tail'\"
  3469. else
  3470. echo shar: Extracting \"'term.tail'\" \(2340 characters\)
  3471. sed "s/^X//" >'term.tail' <<'END_OF_FILE'
  3472. X/* 
  3473. X * 92/02/01 07:30:28
  3474. X * @(#) mytinfo term.tail 3.2 92/02/01 public domain, By Ross Ridge
  3475. X *
  3476. X */
  3477. X
  3478. X#ifdef _USE_TERMIO
  3479. X#ifndef ICANON
  3480. X#include <termio.h>
  3481. X#endif
  3482. X#if defined(_USE_WINSZ) && defined(xenix)
  3483. X#include <sys/stream.h>
  3484. X#include <sys/ptem.h>
  3485. X#endif
  3486. X#endif
  3487. X
  3488. X#ifdef _USE_SGTTY
  3489. X#ifndef CBREAK
  3490. X#include <sgtty.h>
  3491. X#endif
  3492. X#endif
  3493. X
  3494. typedef struct _terminal {
  3495. X    int fd;
  3496. X#ifdef _USE_SMALLMEM
  3497. X    unsigned short baudrate;
  3498. X    unsigned pad:1, xon:1, termcap:1;
  3499. X#else
  3500. X    int pad;
  3501. X    int xon;
  3502. X    int termcap;
  3503. X    long baudrate;
  3504. X#endif
  3505. X    char padch;
  3506. X    short true_lines, true_columns;
  3507. X    struct strbuf {
  3508. X        struct strbuf *next;
  3509. X#ifdef _USE_SMALLMEM
  3510. X        short len;
  3511. X#else
  3512. X        int len;
  3513. X#endif
  3514. X        char buf[_MAX_CHUNK];
  3515. X    } *strbuf;
  3516. X    char *name, *name_long, *name_all;
  3517. X#ifdef _USE_SGTTY
  3518. X    struct sgtty_str {
  3519. X        struct sgttyb v6;
  3520. X#ifdef TIOCGETC
  3521. X        struct tchars v7;
  3522. X#endif
  3523. X#ifdef TIOCLGET
  3524. X        int bsd;
  3525. X#endif
  3526. X#ifdef TIOCGLTC
  3527. X        struct ltchars bsd_new;
  3528. X#endif
  3529. X    } prog_mode, shell_mode;
  3530. X#else    /* _USE_SGTTY */
  3531. X#ifdef _USE_TERMIO
  3532. X    struct termio prog_mode, shell_mode;
  3533. X#endif 
  3534. X#endif    /* else _USE_SGTTY */
  3535. X#ifdef _USE_WINSZ
  3536. X#ifdef TIOCGWINSZ
  3537. X    struct winsize prog_winsz, shell_winsz;
  3538. X#endif
  3539. X#endif
  3540. X    char bools[NUM_OF_BOOLS];
  3541. X    short nums[NUM_OF_NUMS];
  3542. X    char *strs[NUM_OF_STRS];
  3543. X} TERMINAL;
  3544. X
  3545. X#ifndef _CUR_TERM
  3546. X#ifdef SINGLE
  3547. X#define _CUR_TERM _term_buf
  3548. X#else
  3549. X#define _CUR_TERM (*cur_term)
  3550. X#endif
  3551. X#endif
  3552. X
  3553. extern TERMINAL *cur_term;
  3554. extern TERMINAL _term_buf;
  3555. X
  3556. X#ifdef USE_PROTOTYPES
  3557. extern char *tparm(char *, ...);
  3558. extern int setupterm(char *, int, int *), set_curterm(TERMINAL *);
  3559. extern int del_curterm(TERMINAL *), tputs(char *, int, int (*)());
  3560. extern int putp(char *);
  3561. extern int tigetflag(char *), tigetnum(char *);
  3562. extern char *tigetstr(char *);
  3563. extern int def_prog_mode(void), def_shell_mode(void);
  3564. extern int reset_prog_mode(void), reset_shell_mode(void);
  3565. X#else
  3566. extern char *tparm();
  3567. extern int setupterm(), set_curterm();
  3568. extern int del_curterm(), tputs();
  3569. extern int putp();
  3570. extern int tigetflag(), tigetnum();
  3571. extern char *tigetstr();
  3572. extern int def_prog_mode(), def_shell_mode();
  3573. extern int reset_prog_mode(), reset_shell_mode();
  3574. X#endif
  3575. X
  3576. extern char *boolnames[], *boolcodes[], *boolfnames[];
  3577. extern char *numnames[], *numcodes[], *numfnames[];
  3578. extern char *strnames[], *strcodes[], *strfnames[];
  3579. X
  3580. X#ifndef OK
  3581. X#undef ERR
  3582. X#define OK (0)
  3583. X#define ERR (-1)
  3584. X#endif
  3585. X
  3586. X#endif /* _TERM_H_ */
  3587. END_OF_FILE
  3588. if test 2340 -ne `wc -c <'term.tail'`; then
  3589.     echo shar: \"'term.tail'\" unpacked with wrong size!
  3590. fi
  3591. # end of 'term.tail'
  3592. fi
  3593. if test -f 'termcap.c' -a "${1}" != "-c" ; then 
  3594.   echo shar: Will not clobber existing file \"'termcap.c'\"
  3595. else
  3596. echo shar: Extracting \"'termcap.c'\" \(2255 characters\)
  3597. sed "s/^X//" >'termcap.c' <<'END_OF_FILE'
  3598. X/*
  3599. X * termcap.c
  3600. X *
  3601. X * By Ross Ridge
  3602. X * Public Domain
  3603. X * 92/06/01 07:43:08
  3604. X *
  3605. X * termcap compatibility functions
  3606. X *
  3607. X */
  3608. X
  3609. X#include "defs.h"
  3610. X#include "term.h"
  3611. X
  3612. static const char SCCSid[] = "@(#) mytinfo termcap.c 3.3 92/06/01 public domain, By Ross Ridge";
  3613. X
  3614. extern char _mytinfo_version[];
  3615. static char *force = _mytinfo_version;
  3616. X
  3617. int
  3618. tgetent(buf, term)
  3619. char *term, *buf; {
  3620. X    char *s;
  3621. X    struct term_path *path;
  3622. X    int r = -1;
  3623. X    int fd;
  3624. X
  3625. X    if (term == NULL) 
  3626. X        term = getenv("TERM");
  3627. X    if (term == NULL)
  3628. X        return 0;
  3629. X
  3630. X    path = _buildpath("$MYTERMINFO", 2,
  3631. X              "$TERMINFO", 2,
  3632. X              "$TERMCAP", 1,
  3633. X#ifdef TERMINFODIR
  3634. X              TERMINFODIR, 0,
  3635. X#endif
  3636. X#ifdef TERMCAPFILE
  3637. X              TERMCAPFILE, 0,
  3638. X#endif
  3639. X#ifdef TERMINFOSRC
  3640. X              TERMINFOSRC, 0,
  3641. X#endif
  3642. X              NULL, -1);
  3643. X
  3644. X    if (path == NULL)
  3645. X        return -1;
  3646. X
  3647. X#if 1
  3648. X    {
  3649. X        char buf1[MAX_BUF];
  3650. X        r = _fillterm(term, path, buf1);
  3651. X    }
  3652. X#else
  3653. X    r = _fillterm(term, path, buf);
  3654. X#endif
  3655. X
  3656. X    _delpath(path);
  3657. X
  3658. X    switch(r) {
  3659. X    case -3:
  3660. X    case -2:
  3661. X    case -1:
  3662. X        return -1;
  3663. X    case 0:
  3664. X        return 0;
  3665. X    case 1:
  3666. X    case 2:
  3667. X    case 3:
  3668. X        if (isatty(1))
  3669. X            fd = 1;
  3670. X        else if (isatty(2))
  3671. X            fd = 2;
  3672. X        else if (isatty(3))    /* V10 /dev/tty ?? */
  3673. X            fd = 3;
  3674. X        else if (isatty(0))
  3675. X            fd = 0;
  3676. X        else
  3677. X            fd = 1;
  3678. X
  3679. X        cur_term->fd = fd;
  3680. X        _term_buf.fd = fd;
  3681. X
  3682. X        if (_init_tty() == ERR)
  3683. X            return 0;
  3684. X        if ((s = getenv("LINES")) != NULL && atoi(s) > 0) 
  3685. X            lines = atoi(s);
  3686. X        if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
  3687. X            columns = atoi(s);
  3688. X        cur_term->termcap = 1;
  3689. X        return 1;
  3690. X    default:
  3691. X        return -1;
  3692. X    }
  3693. X}
  3694. X
  3695. static char cap2[3];
  3696. X
  3697. int
  3698. tgetnum(cap)
  3699. char *cap; {
  3700. X    int ind;
  3701. X
  3702. X    cap2[0] = cap[0]; 
  3703. X    cap2[1] = cap[1];
  3704. X    cap2[2] = '\0';
  3705. X
  3706. X    ind = _findnumcode(cap2);
  3707. X    if (ind == -1)
  3708. X        return -1;
  3709. X    return cur_term->nums[ind];
  3710. X}
  3711. X
  3712. int
  3713. tgetflag(cap)
  3714. char *cap; {
  3715. X    int ind;
  3716. X
  3717. X    cap2[0] = cap[0]; 
  3718. X    cap2[1] = cap[1];
  3719. X    cap2[2] = '\0';
  3720. X
  3721. X    ind = _findboolcode(cap2);
  3722. X    if (ind == -1)
  3723. X        return 0;
  3724. X    return cur_term->bools[ind];
  3725. X}
  3726. X
  3727. char *
  3728. tgetstr(cap, area)
  3729. char *cap;
  3730. char **area; {
  3731. X    register char *sp, *dp;
  3732. X    int ind;
  3733. X
  3734. X    cap2[0] = cap[0]; 
  3735. X    cap2[1] = cap[1];
  3736. X    cap2[2] = '\0';
  3737. X
  3738. X    ind = _findstrcode(cap2);
  3739. X    if (ind == -1)
  3740. X        return NULL;
  3741. X    sp = cur_term->strs[ind];
  3742. X    if (area == NULL || sp == NULL)
  3743. X        return sp;
  3744. X    dp = *area;
  3745. X    while (*sp != '\0')
  3746. X        *dp++ = *sp++;
  3747. X    *dp++ = '\0';
  3748. X    sp = *area;
  3749. X    *area = dp;
  3750. X    return sp;
  3751. X}
  3752. END_OF_FILE
  3753. if test 2255 -ne `wc -c <'termcap.c'`; then
  3754.     echo shar: \"'termcap.c'\" unpacked with wrong size!
  3755. fi
  3756. # end of 'termcap.c'
  3757. fi
  3758. if test -f 'terminfo.c' -a "${1}" != "-c" ; then 
  3759.   echo shar: Will not clobber existing file \"'terminfo.c'\"
  3760. else
  3761. echo shar: Extracting \"'terminfo.c'\" \(2068 characters\)
  3762. sed "s/^X//" >'terminfo.c' <<'END_OF_FILE'
  3763. X/*
  3764. X * terminfo.c
  3765. X *
  3766. X * By Ross Ridge
  3767. X * Public Domain
  3768. X * 92/02/01 07:30:30
  3769. X *
  3770. X * terminfo compatible libary functions
  3771. X *
  3772. X */
  3773. X
  3774. X#include "defs.h"
  3775. X#include "term.h"
  3776. X
  3777. static const char SCCSid[] = "@(#) mytinfo terminfo.c 3.2 92/02/01 public domain, By Ross Ridge";
  3778. X
  3779. extern char _mytinfo_version[];
  3780. static char *force = _mytinfo_version;
  3781. X
  3782. X#ifdef USE_FAKE_STDIO
  3783. X
  3784. X#ifdef __GNUC__
  3785. X__inline__
  3786. X#endif
  3787. static int
  3788. printerr(msg)
  3789. char *msg; {
  3790. X    return write(2, msg, strlen(msg));
  3791. X}
  3792. X
  3793. X#define RETERR(e, msg)  { (err == NULL ? (printerr(msg), exit(1), 0) \
  3794. X                       : (*err = e)); return ERR; }
  3795. X
  3796. X#else
  3797. X
  3798. X#define RETERR(e, msg)  { (err == NULL ? (fprintf(stderr, msg), exit(1), 0) \
  3799. X                       : (*err = e)); return ERR; }
  3800. X
  3801. X#endif
  3802. X
  3803. int
  3804. setupterm(term, fd, err)
  3805. char *term;
  3806. int fd;
  3807. int *err; {
  3808. X    struct term_path *path;
  3809. X    char *s;
  3810. X    int r = -1;
  3811. X    char buf[MAX_BUF];
  3812. X
  3813. X
  3814. X    if (term == NULL) 
  3815. X        term = getenv("TERM");
  3816. X    if (term == NULL)
  3817. X        RETERR(0, "TERM not set\n")
  3818. X
  3819. X    path = _buildpath("$MYTERMINFO", 2,
  3820. X              "$TERMINFO", 2,
  3821. X              "$TERMCAP", 1,
  3822. X#ifdef TERMINFODIR
  3823. X              TERMINFODIR, 0,
  3824. X#endif
  3825. X#ifdef TERMCAPFILE
  3826. X              TERMCAPFILE, 0,
  3827. X#endif
  3828. X#ifdef TERMINFOSRC
  3829. X              TERMINFOSRC, 0,
  3830. X#endif
  3831. X              NULL, -1);
  3832. X
  3833. X    if (path == NULL)
  3834. X        RETERR(0, "malloc error\n");
  3835. X
  3836. X    r = _fillterm(term, path, buf);
  3837. X
  3838. X    _delpath(path);
  3839. X
  3840. X    switch(r) {
  3841. X    case -3:
  3842. X        RETERR(0, "malloc error\n");
  3843. X    case -2:
  3844. X        RETERR(-1, "bad format\n");
  3845. X    case -1:
  3846. X        RETERR(-1, "database not found\n");
  3847. X    case 0:
  3848. X        RETERR(0, "terminal not found\n");
  3849. X    case 1:
  3850. X    case 2:
  3851. X    case 3:
  3852. X        cur_term->fd = fd;
  3853. X        _term_buf.fd = fd;
  3854. X        if (_init_tty() == ERR)
  3855. X            RETERR(0, "problem initializing tty\n");
  3856. X        if ((s = getenv("LINES")) != NULL && atoi(s) > 0) 
  3857. X            lines = atoi(s);
  3858. X        if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
  3859. X            columns = atoi(s);
  3860. X        if (err != NULL)
  3861. X            *err = 1;
  3862. X        return OK;
  3863. X    default:
  3864. X        RETERR(0, "oops...\n");
  3865. X    }
  3866. X}
  3867. X
  3868. int
  3869. set_curterm(p)
  3870. TERMINAL *p; {
  3871. X    cur_term = p;
  3872. X    if (_init_tty() == ERR)
  3873. X        return ERR;
  3874. X    if (_check_tty() == ERR)
  3875. X        return ERR;
  3876. X    return OK;
  3877. X}
  3878. X
  3879. int
  3880. del_curterm(p)
  3881. TERMINAL *p; {
  3882. X    _del_strs(p);
  3883. X    free((anyptr) p);
  3884. X
  3885. X    return OK;
  3886. X}
  3887. END_OF_FILE
  3888. if test 2068 -ne `wc -c <'terminfo.c'`; then
  3889.     echo shar: \"'terminfo.c'\" unpacked with wrong size!
  3890. fi
  3891. # end of 'terminfo.c'
  3892. fi
  3893. if test -f 'terminfo.src' -a "${1}" != "-c" ; then 
  3894.   echo shar: Will not clobber existing file \"'terminfo.src'\"
  3895. else
  3896. echo shar: Extracting \"'terminfo.src'\" \(4475 characters\)
  3897. sed "s/^X//" >'terminfo.src' <<'END_OF_FILE'
  3898. X# 
  3899. X# terminfo.src
  3900. X#
  3901. X# By Ross Ridge
  3902. X# Public Domain
  3903. X# 92/02/01 07:30:32
  3904. X#
  3905. X# Some sample terminfo definitions
  3906. X#
  3907. X# @(#) mytinfo terminfo.src 3.2 92/02/01 public domain, By Ross Ridge
  3908. X#
  3909. X#
  3910. dumb|dumb terminal, gn, co#80,
  3911. X#
  3912. X# Note not all ANSI terminals will support all of these capabilities.
  3913. X# This doesn't define any real terminal, and probably wouldn't work
  3914. X# with any real terminal either.
  3915. X#
  3916. ansi-all|ANS X3.64-1979 terminal,
  3917. X    cr=^M, cud1=^J, ind=^J, nel=^M^J, bell=^G, cub1=^H, 
  3918. X    cuu1=\EM, ff=^L, ht=^I,
  3919. X    .ind=\ED, .nel=\EE, hts=\EH, hd=\EK, hu=\EL, ri=\EM,
  3920. X    .ich1=\E[@, .ich=\E[%p1%d@, .cuu1=\E[A, cuu=\E[%p1%dA,
  3921. X    cud1=\E[B, .cud=\E[%p1%dB, cuf1=\E[C, cuf=\E[%p1%dC,
  3922. X    .cub1=\E[D, cub=\E[%p1%dD, .cnl=\E[%p1%dE, .cpl=\E[%p1%dF,
  3923. X    .hpa=\E[%i%p1%dG, cup=\E[%i%p1%d;%p2%dH, .cht=\E[%p1%dI,
  3924. X    ed=\E[J, el=\E[K, el1=\E[1K, il1=\E[L, il=\E[%p1%dL,
  3925. X    dl1=\E[M, dl=\E[%p1%dM, .ef=\E[N, .ea=\E[O,
  3926. X    dch1=\E[P, dch=\E[%p1%dP, .sem=\E[%p1%dQ,
  3927. X    .cpr=\E[%i%p1%d;%p2%dR, indn=\E[%p1%dS, .ind=\E[S,
  3928. X    rin=\E[%p1%dT, .ri=\E[T, .np=\E[%p1%dU, .pp=\E[%p1%dU,
  3929. X    .ctc=\E[%p1%dW, ech=\E[%p1%dX, .cvt=\E[%p1%dY,
  3930. X    cbt=\E[Z, hpa=\E[%i%p1%d`, .hpr=\E[%p1%da,
  3931. X    rep=%p1%c%?%p2%{1}%>%t\E[%p2%{1}%-%db%;,
  3932. X    .da=\E[c, vpa=\E[%i%p1%dd, .vpr=\E[%p1%e,
  3933. X    .hvp=\E[%i%p1%d;%p2%df, tbc=\E[3g,
  3934. X    mc=\E[0i, mc4=\E[4i, mc5=\E[5i,
  3935. X    sgr=\E[%?%p6%t;1%;%?%p5%p1%|%t;2%;%?%p2%t;4%;%?%p4%t;6%;%?%p3%p1%|%t;7%;%?%p7%t;8%;m,
  3936. X    smso=\E[1;7m, rmso=\E[m, smul=\E[4m, rmul=\E[m,
  3937. X    blink=\E[6m, bold=\E[1m, invis=\E[8m, rev=\E[7m,
  3938. X    sgr0=\E[m, .dsr=\E[%p1%dn, .daq=\E[%p1%do,
  3939. X    .sl=\E[%p1%d\s@, .sr=\E[%p1%d\sA, clear=\E[H\EJ, home=\E[H,
  3940. X    smir=\E[4h, rmir=\E[4l,
  3941. X    is2=\E[1Q\E[1;2;3;4;5;7;10;11;13;14;16;15;17;18;19;20l\E[6;12h\E[m,
  3942. X    rs2=\Ec\E[1Q\E[1;2;3;4;5;7;10;11;13;14;16;15;17;18;19;20l\E[6;12h\E[m\E[H\EJ,
  3943. ansi-all-8|ANS X3.64-1979 terminal (8 bit),
  3944. X    cr=^M, cud1=^J, ind=^J, nel=^M^J, bell=^G, cub1=^H, 
  3945. X    cuu1=\215, ff=^L, ht=^I,
  3946. X    .ind=\204, .nel=\205, hts=\207, hd=\213, hu=\214, ri=\215,
  3947. X    .ich1=\233@, .ich=\E%p1%d@, .cuu1=\233A, cuu=\233%p1%dA,
  3948. X    cud1=\233B, .cud=\233%p1%dB, cuf1=\233C, cuf=\233%p1%dC,
  3949. X    .cub1=\233D, cub=\233%p1%dD, .cnl=\233%p1%dE, .cpl=\233%p1%dF,
  3950. X    .hpa=\233%i%p1%dG, cup=\233%i%p1%d;%p2%dH, .cht=\233%p1%dI,
  3951. X    ed=\233J, el=\233K, el1=\2331K, il1=\233L, il=\233%p1%dL,
  3952. X    dl1=\233M, dl=\233%p1%dM, .ef=\233N, .ea=\233O,
  3953. X    dch1=\233P, dch=\233%p1%dP, .sem=\233%p1%dQ,
  3954. X    .cpr=\233%i%p1%d;%p2%dR, indn=\233%p1%dS, .ind=\233S,
  3955. X    rin=\233%p1%dT, .ri=\233T, .np=\233%p1%dU, .pp=\233%p1%dU,
  3956. X    .ctc=\233%p1%dW, ech=\233%p1%dX, .cvt=\233%p1%dY,
  3957. X    cbt=\233Z, hpa=\233%i%p1%d`, .hpr=\233%p1%da,
  3958. X    rep=%p1%c%?%p2%{1}%>%t\233%p2%{1}%-%db%;,
  3959. X    .da=\233c, vpa=\233%i%p1%dd, .vpr=\233%p1%e,
  3960. X    .hvp=\233%i%p1%d;%p2%df, tbc=\2333g,
  3961. X    mc=\2330i, mc4=\2334i, mc5=\2334i,
  3962. X    sgr=\233%?%p6%t;1%;%?%p5%p1%|%t;2%;%?%p2%t;4%;%?%p4%t;6%;%?%p3%p1%|%t;7%;%?%p7%t;8%;m,
  3963. X    smso=\2331;7m, rmso=\233m, smul=\2334m, rmul=\233m,
  3964. X    blink=\2336m, bold=\2331m, invis=\2338m, rev=\2337m,
  3965. X    sgr0=\233m, .dsr=\233%p1%dn, .daq=\233%p1%do,
  3966. X    .sl=\233%p1%d\s@, .sr=\233%p1%d\sA, clear=\233H\EJ, home=\233H,
  3967. X    smir=\2334h, rmir=\2334l,
  3968. X    is2=\2331Q\2331;2;3;4;5;7;10;11;13;14;16;15;17;18;19;20l\2336;12h\233m,
  3969. X    rs2=\Ec\2331Q\2331;2;3;4;5;7;10;11;13;14;16;15;17;18;19;20l\2336;12h\233m\233H\EJ,
  3970. X#
  3971. X# Not tested...
  3972. X#
  3973. vt100|dec vt100,
  3974. X    xon, UWxc, msgr, 
  3975. X    cols#80, lines#24, it#8, vt#3,
  3976. X    cr=\r, csr=^[[%i%p1%d;%p2%dr, tbc=^[[3g, clear=^[[;H^[[2J$<100>,
  3977. X    el=^[[K$<3>, ed=^[[J$<50>, cup=^[[%i%p1%d;%p2%dH$<5>, cud1=^[[B,
  3978. X    home=^[[H, cub1=^[[D, cuf1=^[[C$<2>, cuu1=^[[A$<2>, blink=^[[5m$<2>,
  3979. X    bold=^[[1m$<2>, rev=^[[7m$<2>, smso=^[[7m$<2>, smul=^[[4m$<2>,
  3980. X    sgr0=^[[m^N$<2>, rmso=^[[m$<2>, rmul=^[[m$<2>, hts=^[H, ht=^I,
  3981. X    is2=^[[1;24r^[[?1l^[[?3l^[[30h^[[?7h^[>, bell=^G,
  3982. X    kbs=\b, kcud1=^[[B, kf0=^[OP, kf1=^[OQ, kf2=^[OR, kf3=^[OS,
  3983. X    kcub1=^[[D, kcuf1=^[[C, kcuu1=^[[A, lf0=PF1, lf1=PF2,
  3984. X    lf2=PF3, lf3=PF4, nel=\r^[D, cud=^[[%p1%dB, cub=^[[%p1%dD,
  3985. X    cuf=^[[%p1%dC, cuu=^[[%p1%dA, rc=^[8, sc=^[7, ind=^[D, ri=^[M$<5>,
  3986. X    sgr=^[[0;%?%p4%t;5%;%?%p6%t;1%;%?%p3%p1%|%t;7%;%?%p2%t;4%;m%?%p1%t^N%e^O%;$<2>,
  3987. X    smacs=^O, rmacs=^N,
  3988. vt100-am|vt100 with automatic margins,
  3989. X    am, xenl, @el, @ed,
  3990. X    use=vt100,
  3991. vt102|dec vt102,
  3992. X    is=\E<\E[1;24r\E[?1l\E[?3l\E[?5l\E[?7h\E>,
  3993. X    il=\E[%p1%dL, dch=\E[%p1%dP, dl=\E[%p1%dM,
  3994. X    il1=\E[L, dch1=\E[P, dl1=\E[M,
  3995. X    mir, rmir=\E[4l, smir=\E[4h,
  3996. X    use=vt100,
  3997. vt200|vt220|vt200-js|vt220-js|dec vt200 series with jump scroll,
  3998. X    clear=\E[H\E[J, rmso=\E[27m, rmul=\E[24m,
  3999. X    is2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E[1;24r\E[24;1H,
  4000. X    rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h,
  4001. X    use=vt102, 
  4002. END_OF_FILE
  4003. if test 4475 -ne `wc -c <'terminfo.src'`; then
  4004.     echo shar: \"'terminfo.src'\" unpacked with wrong size!
  4005. fi
  4006. # end of 'terminfo.src'
  4007. fi
  4008. if test -f 'tgoto.c' -a "${1}" != "-c" ; then 
  4009.   echo shar: Will not clobber existing file \"'tgoto.c'\"
  4010. else
  4011. echo shar: Extracting \"'tgoto.c'\" \(2489 characters\)
  4012. sed "s/^X//" >'tgoto.c' <<'END_OF_FILE'
  4013. X/*
  4014. X * tgoto.c
  4015. X *
  4016. X * By Ross Ridge
  4017. X * Public Domain
  4018. X * 92/02/01 07:30:33
  4019. X *
  4020. X * A few kludged attempts to worry outputing ^D's and NL's...
  4021. X * My advice is to get a decent terminal.
  4022. X *
  4023. X */
  4024. X
  4025. X#include "defs.h"
  4026. X#include "term.h"
  4027. X
  4028. X#ifdef USE_SCCS_IDS
  4029. static const char SCCSid[] = "@(#) mytinfo tgoto.c 3.2 92/02/01 public domain, By Ross Ridge";
  4030. X#endif
  4031. X
  4032. X#ifdef USE_LITOUT_KLUDGE
  4033. X
  4034. X/*
  4035. X * This kludge works by telling tputs to switch the tty driver to
  4036. X * "literal output" when printing the string so we don't have worry
  4037. X * about newlines and EOTs. The problem is that ioctls used to
  4038. X * switch modes might flush buffers and cause other problems.
  4039. X */
  4040. X
  4041. X
  4042. char *
  4043. tgoto(str, x, y)
  4044. char *str;
  4045. int x,y; {
  4046. X    register char *sp;
  4047. X    
  4048. X    static char buf[MAX_LINE] = {'\\', '@'};
  4049. X
  4050. X    sp = str = tparm(str, y, x);
  4051. X
  4052. X    while (*sp != '\0') {
  4053. X        if (*sp == '\004' || *sp == '\n') {
  4054. X            strncpy(buf + 2, str, MAX_LINE - 2);
  4055. X            buf[MAX_LINE - 2] = '\0';
  4056. X            return buf;
  4057. X        }
  4058. X        sp++;
  4059. X    }
  4060. X    return sp;
  4061. X}
  4062. X#else
  4063. X
  4064. X#ifdef USE_UPBC_KLUDGE
  4065. X
  4066. X#ifdef USE_EXTERN_UPBC
  4067. extern char *BC, *UP;
  4068. X#else
  4069. X#define BC    cursor_left
  4070. X#define UP    cursor_right
  4071. X#endif
  4072. X
  4073. X#ifdef __GNUC__
  4074. X__inline__
  4075. X#endif
  4076. static int
  4077. checkit(s)
  4078. register char *s; {
  4079. X    while(*s != '\0') {
  4080. X        if (*s == '\004' || *s == '\n')
  4081. X            return 1;
  4082. X        s++;
  4083. X    }
  4084. X    return 0;
  4085. X}
  4086. X
  4087. X/*
  4088. X * Major kludge, basically we just change the parmeters until we get
  4089. X * a string that doesn't contain a newline or EOT.
  4090. X */
  4091. X
  4092. char *
  4093. tgoto(str, x, y)
  4094. char *str;
  4095. int x,y; {
  4096. X    static char buf[MAX_LINE];
  4097. X    register char *orig, *s;
  4098. X    int l;
  4099. X
  4100. X    orig = tparm(str, y, x);
  4101. X
  4102. X    if (!checkit(orig))
  4103. X        return orig;
  4104. X
  4105. X    s = tparm(str, y + 1, x);
  4106. X
  4107. X    if (!checkit(s)) {
  4108. X        if (BC == NULL)
  4109. X            return s;
  4110. X        l = strlen(s);
  4111. X        strncpy(buf, s, MAX_LINE - 1);
  4112. X        if (l < MAX_LINE - 1)
  4113. X            strncpy(buf + l, BC, MAX_LINE - 1 - l);
  4114. X        return s;
  4115. X    }
  4116. X
  4117. X    s = tparm(str, y, x + 1);
  4118. X
  4119. X    if (!checkit(s)) {
  4120. X        if (UP == NULL)
  4121. X            return s;
  4122. X        l = strlen(s);
  4123. X        strncpy(buf, s, MAX_LINE - 1);
  4124. X        if (l < MAX_LINE - 1)
  4125. X            strncpy(buf + l, UP, MAX_LINE - 1 - l);
  4126. X        return s;
  4127. X    }
  4128. X
  4129. X    s = tparm(str, y + 1, x + 1);
  4130. X
  4131. X    if (!checkit(s)) {
  4132. X        if (UP == NULL || BC == NULL)
  4133. X            return s;
  4134. X        l = strlen(s);
  4135. X        strncpy(buf, s, MAX_LINE - 1);
  4136. X        if (l < MAX_LINE - 1)
  4137. X            strncpy(buf + l, UP, MAX_LINE - 1 - l);
  4138. X        l += strlen(UP);
  4139. X        if (l < MAX_LINE - 1)
  4140. X            strncpy(buf + l, BC, MAX_LINE - 1 - l);
  4141. X        return s;
  4142. X    }
  4143. X
  4144. X    return orig;
  4145. X}
  4146. X
  4147. X#else
  4148. X
  4149. X/* the simple tgoto, don't worry about any of this newline/EOT crap */
  4150. X
  4151. char *
  4152. tgoto(str, x, y)
  4153. char *str;
  4154. int x,y; {
  4155. X    return tparm(str, y, x);
  4156. X}
  4157. X
  4158. X#endif
  4159. X
  4160. X#endif
  4161. END_OF_FILE
  4162. if test 2489 -ne `wc -c <'tgoto.c'`; then
  4163.     echo shar: \"'tgoto.c'\" unpacked with wrong size!
  4164. fi
  4165. # end of 'tgoto.c'
  4166. fi
  4167. if test -f 'tiget.c' -a "${1}" != "-c" ; then 
  4168.   echo shar: Will not clobber existing file \"'tiget.c'\"
  4169. else
  4170. echo shar: Extracting \"'tiget.c'\" \(684 characters\)
  4171. sed "s/^X//" >'tiget.c' <<'END_OF_FILE'
  4172. X/*
  4173. X * tiget.c
  4174. X *
  4175. X * By Ross Ridge
  4176. X * Public Domain
  4177. X * 92/02/01 07:30:34
  4178. X *
  4179. X * The various tiget terminfo functions.
  4180. X */
  4181. X
  4182. X#include "defs.h"
  4183. X#include "term.h"
  4184. X
  4185. X#ifdef USE_SCCS_IDS
  4186. static const char SCCSid[] = "@(#) mytinfo tiget.c 3.2 92/02/01 public domain, By Ross Ridge";
  4187. X#endif
  4188. X
  4189. int
  4190. tigetnum(cap)
  4191. char *cap; {
  4192. X    int ind;
  4193. X
  4194. X    ind = _findnumname(cap);
  4195. X    if (ind == -1)
  4196. X        return -2;
  4197. X    return cur_term->nums[ind];
  4198. X}
  4199. X
  4200. int
  4201. tigetflag(cap)
  4202. char *cap; {
  4203. X    int ind;
  4204. X
  4205. X    ind = _findboolname(cap);
  4206. X    if (ind == -1)
  4207. X        return -1;
  4208. X    return cur_term->bools[ind];
  4209. X}
  4210. X
  4211. char *
  4212. tigetstr(cap)
  4213. char *cap; {
  4214. X    int ind;
  4215. X
  4216. X    ind = _findstrname(cap);
  4217. X    if (ind == -1)
  4218. X        return (char *) -1;
  4219. X    return cur_term->strs[ind];
  4220. X}
  4221. X
  4222. X
  4223. END_OF_FILE
  4224. if test 684 -ne `wc -c <'tiget.c'`; then
  4225.     echo shar: \"'tiget.c'\" unpacked with wrong size!
  4226. fi
  4227. # end of 'tiget.c'
  4228. fi
  4229. if test -f 'tmatch.c' -a "${1}" != "-c" ; then 
  4230.   echo shar: Will not clobber existing file \"'tmatch.c'\"
  4231. else
  4232. echo shar: Extracting \"'tmatch.c'\" \(604 characters\)
  4233. sed "s/^X//" >'tmatch.c' <<'END_OF_FILE'
  4234. X/*
  4235. X * tmatch.c
  4236. X *
  4237. X * By Ross Ridge
  4238. X * Public Domain
  4239. X * 92/02/01 07:30:35
  4240. X *
  4241. X * See if a terminal name matches a list of terminal names from a
  4242. X * terminal description
  4243. X *
  4244. X */
  4245. X
  4246. X#include "defs.h"
  4247. X
  4248. X#ifdef USE_SCCS_IDS
  4249. static const char SCCSid[] = "@(#) mytinfo tmatch.c 3.2 92/02/01 public domain, By Ross Ridge";
  4250. X#endif
  4251. X
  4252. int
  4253. X_tmatch(line, name)
  4254. char *line, *name; {
  4255. X    char term[MAX_LINE];
  4256. X    char *sp, *dp;
  4257. X
  4258. X    sp = line;
  4259. X    while (*sp != '\0') {
  4260. X        dp = term;
  4261. X        while (*sp != '\0' && *sp != '|')
  4262. X            *dp++ = *sp++;
  4263. X        *dp = '\0';
  4264. X        if (strcmp(term, name) == 0)
  4265. X            return 1;
  4266. X        if (*sp == '|')
  4267. X            sp++;
  4268. X    }
  4269. X    return 0;
  4270. X}
  4271. END_OF_FILE
  4272. if test 604 -ne `wc -c <'tmatch.c'`; then
  4273.     echo shar: \"'tmatch.c'\" unpacked with wrong size!
  4274. fi
  4275. # end of 'tmatch.c'
  4276. fi
  4277. if test -f 'tput.c' -a "${1}" != "-c" ; then 
  4278.   echo shar: Will not clobber existing file \"'tput.c'\"
  4279. else
  4280. echo shar: Extracting \"'tput.c'\" \(3436 characters\)
  4281. sed "s/^X//" >'tput.c' <<'END_OF_FILE'
  4282. X/*
  4283. X * tput.c
  4284. X * 
  4285. X * By Ross Ridge
  4286. X * Public Domain
  4287. X * 92/02/01 07:30:39
  4288. X *
  4289. X */
  4290. X
  4291. X#define NOTLIB
  4292. X
  4293. X#include "defs.h"
  4294. X
  4295. static const char SCCSid[] = "@(#) mytinfo tput.c 3.2 92/02/01 public domain, By Ross Ridge";
  4296. X
  4297. X#define SINGLE
  4298. X#include "term.h"
  4299. X
  4300. X#include <ctype.h>
  4301. X
  4302. X#define PUTS(s)        putp(s)
  4303. X#define PUTCHAR(c)    putchar(c)
  4304. X#define FLUSH        fflush(stdout)
  4305. X
  4306. extern void (*cleanup)();
  4307. X
  4308. static void
  4309. clean(e)
  4310. int e; {
  4311. X    return;
  4312. X}
  4313. X
  4314. static void
  4315. usage(e)
  4316. int e; {
  4317. X    fprintf(stderr, "usage: %s [-T term] capname\n", prg_name);
  4318. X    return;
  4319. X}
  4320. X
  4321. int
  4322. main(argc, argv)
  4323. int argc;
  4324. char **argv; {
  4325. X    char *s;
  4326. X    int i, j, c;
  4327. X    int reset;
  4328. X    FILE *f;
  4329. X    char *term;
  4330. X
  4331. X    prg_name = argv[0];
  4332. X    s = strrchr(prg_name, '/');
  4333. X    if (s != NULL && *++s != '\0') {
  4334. X        prg_name = s;
  4335. X    }
  4336. X
  4337. X    term = getenv("TERM");
  4338. X
  4339. X    cleanup = usage;
  4340. X
  4341. X    if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'T') {
  4342. X        if (argv[1][2] == '\0' && argc > 3) {
  4343. X            term = argv[2];
  4344. X            argc--;
  4345. X            argv++;
  4346. X        } else {
  4347. X            term = argv[1] + 2;
  4348. X        }
  4349. X        argc--;
  4350. X        argv++;
  4351. X    }
  4352. X
  4353. X    if (argc != 2) {
  4354. X        quit(-1, "arg count");
  4355. X    }
  4356. X
  4357. X    cleanup = clean;
  4358. X
  4359. X    setupterm(term, 1, (int *)0);
  4360. X
  4361. X    reset = 0;
  4362. X    if (strcmp(argv[1], "reset") == 0) {
  4363. X        reset = 1;
  4364. X    }
  4365. X    if (reset || strcmp(argv[1], "init") == 0) {
  4366. X
  4367. X        if (init_prog != NULL) {
  4368. X            system(init_prog);
  4369. X        }
  4370. X        FLUSH;
  4371. X
  4372. X        if (reset && reset_1string != NULL) {
  4373. X            PUTS(reset_1string);
  4374. X        } else if (init_1string != NULL) {
  4375. X            PUTS(init_1string);
  4376. X        }
  4377. X        FLUSH;
  4378. X
  4379. X        if (reset && reset_2string != NULL) {
  4380. X            PUTS(reset_2string);
  4381. X        } else if (init_2string != NULL) {
  4382. X            PUTS(init_2string);
  4383. X        }
  4384. X        FLUSH;
  4385. X
  4386. X        if (set_lr_margin != NULL) {
  4387. X            PUTS(tparm(set_lr_margin, 0, columns - 1));
  4388. X        } else if (set_left_margin_parm != NULL
  4389. X               && set_right_margin_parm != NULL) {
  4390. X            PUTS(tparm(set_left_margin_parm, 0));
  4391. X            PUTS(tparm(set_right_margin_parm, columns - 1));
  4392. X        } else if (clear_margins != NULL && set_left_margin != NULL
  4393. X               && set_right_margin != NULL) {
  4394. X            PUTS(clear_margins);
  4395. X            if (carriage_return != NULL) {
  4396. X                PUTS(carriage_return);
  4397. X            } else {
  4398. X                PUTCHAR('\r');
  4399. X            }
  4400. X            PUTS(set_left_margin);
  4401. X            if (parm_right_cursor) {
  4402. X                PUTS(tparm(parm_right_cursor, columns - 1));
  4403. X            } else {
  4404. X                for(i = 0; i < columns - 1; i++) {
  4405. X                    PUTCHAR(' ');
  4406. X                }
  4407. X            }
  4408. X            PUTS(set_right_margin);
  4409. X            if (carriage_return != NULL) {
  4410. X                PUTS(carriage_return);
  4411. X            } else {
  4412. X                PUTCHAR('\r');
  4413. X            }
  4414. X        }
  4415. X        FLUSH;
  4416. X
  4417. X        if (init_tabs != 8) {
  4418. X            if (clear_all_tabs != NULL && set_tab != NULL) {
  4419. X                for(i = 0; i < columns - 1; i += 8) {
  4420. X                    if (parm_right_cursor) {
  4421. X                        PUTS(tparm(parm_right_cursor,
  4422. X                             8));
  4423. X                    } else {
  4424. X                        for(j = 0; j < 8; j++) {
  4425. X                            PUTCHAR(' ');
  4426. X                        }
  4427. X                    }
  4428. X                    PUTS(set_tab);
  4429. X                }
  4430. X                FLUSH;
  4431. X            }
  4432. X        }
  4433. X
  4434. X        if (reset && reset_file != NULL) {
  4435. X            f = fopen(reset_file, "r");
  4436. X            if (f == NULL) {
  4437. X                quit(errno, "Can't open reset_file: '%s'",
  4438. X                     reset_file);
  4439. X            }
  4440. X            while((c = fgetc(f)) != EOF) {
  4441. X                PUTCHAR(c);
  4442. X            }
  4443. X            fclose(f);
  4444. X        } else if (init_file != NULL) {
  4445. X            f = fopen(init_file, "r");
  4446. X            if (f == NULL) {
  4447. X                quit(errno, "Can't open init_file: '%s'",
  4448. X                     init_file);
  4449. X            }
  4450. X            while((c = fgetc(f)) != EOF) {
  4451. X                PUTCHAR(c);
  4452. X            }
  4453. X            fclose(f);
  4454. X        }
  4455. X        FLUSH;
  4456. X
  4457. X        if (reset && reset_3string != NULL) {
  4458. X            PUTS(reset_3string);
  4459. X        } else if (init_2string != NULL) {
  4460. X            PUTS(init_3string);
  4461. X        }
  4462. X        FLUSH;
  4463. X        return 0;
  4464. X    }
  4465. X
  4466. X    s = tigetstr(argv[1]);
  4467. X
  4468. X    if (s == (char *) -1) {
  4469. X        quit(-1, "unknown capname '%s'", argv[1]);
  4470. X    } else if (s == NULL) {
  4471. X        return 0;
  4472. X    }
  4473. X
  4474. X    putp(s);
  4475. X
  4476. X    return 0;
  4477. X}
  4478. END_OF_FILE
  4479. if test 3436 -ne `wc -c <'tput.c'`; then
  4480.     echo shar: \"'tput.c'\" unpacked with wrong size!
  4481. fi
  4482. # end of 'tput.c'
  4483. fi
  4484. if test -f 'tputs.c' -a "${1}" != "-c" ; then 
  4485.   echo shar: Will not clobber existing file \"'tputs.c'\"
  4486. else
  4487. echo shar: Extracting \"'tputs.c'\" \(4288 characters\)
  4488. sed "s/^X//" >'tputs.c' <<'END_OF_FILE'
  4489. X/*
  4490. X * tputs.c
  4491. X *
  4492. X * By Ross Ridge
  4493. X * Public Domain
  4494. X * 92/06/04 11:41:15
  4495. X *
  4496. X * Output a terminal capability string with any needed padding
  4497. X *
  4498. X */
  4499. X
  4500. X#include "defs.h"
  4501. X#include "term.h"
  4502. X
  4503. X#include <ctype.h>
  4504. X
  4505. X#ifdef USE_SCCS_IDS
  4506. static const char SCCSid[] = "@(#) mytinfo tputs.c 3.3 92/06/04 public domain, By Ross Ridge";
  4507. X#endif
  4508. X
  4509. X#ifdef TEST
  4510. X#define def_prog_mode()    (OK)
  4511. X#define _norm_output()    ((void)(0))
  4512. X#define _lit_output()    (1)
  4513. X#endif
  4514. X
  4515. X/*
  4516. X * BITSPERCHAR (as actually transmitted over a serial line) is usually 10
  4517. X * (not 8). 1 stop bit, 1 start bit, 7 data bits, and one parity bit.
  4518. X */
  4519. X
  4520. X#define BITSPERCHAR    10
  4521. X
  4522. X#ifdef USE_FAKE_STDIO
  4523. X#undef putchar
  4524. X#endif
  4525. X
  4526. X#define PUTCHAR(c) (outc == (int (*)()) 0 ? (putchar(c)):(*outc)(c))
  4527. X
  4528. int
  4529. tputs(sp, count, outc)
  4530. register char *sp;
  4531. int count;
  4532. register int (*outc)();
  4533. X{
  4534. X    register int l;
  4535. X    register long cnt;
  4536. X    int must_pad, multiply_pad;
  4537. X    int forced_lit = 0;
  4538. X
  4539. X    /* some programmes expect this behaviour from tputs */
  4540. X    if (sp == NULL) {
  4541. X#ifdef DEBUG
  4542. X        fprintf(stderr, "tputs: NULL\n");    
  4543. X#endif
  4544. X        return 0;
  4545. X    }
  4546. X
  4547. X    if (cur_term->termcap) {
  4548. X        _figure_termcap();
  4549. X    }
  4550. X
  4551. X    while(*sp != '\0') {
  4552. X        switch(*sp) {
  4553. X        case '\\':
  4554. X            switch(*++sp) {
  4555. X            case 'n': PUTCHAR('\n'); sp++; break;
  4556. X            case 'b': PUTCHAR('\b'); sp++; break;
  4557. X            case 't': PUTCHAR('\t'); sp++; break;
  4558. X            case 'r': PUTCHAR('\r'); sp++; break;
  4559. X            case 'f': PUTCHAR('\f'); sp++; break;
  4560. X            case 'l': PUTCHAR('\012'); sp++; break;
  4561. X            case 's': PUTCHAR(' '); sp++; break;
  4562. X            case 'e': case 'E': PUTCHAR('\033'); sp++; break;
  4563. X
  4564. X            case '^':
  4565. X            case '\\':
  4566. X            case ',':
  4567. X            case ':':
  4568. X            case '\'':
  4569. X            case '$':
  4570. X                PUTCHAR(*sp++);
  4571. X                break;
  4572. X
  4573. X            case '0':
  4574. X                if (*(sp + 1) < '0' || *(sp + 1) > '7') {
  4575. X                    PUTCHAR('\200'); /* I'd prefer \0 */
  4576. X                    sp++;
  4577. X                    break;
  4578. X                }
  4579. X                ;/* FALLTHROUGH */
  4580. X            case '1': case '2': case '3': case '4':
  4581. X            case '5': case '6': case '7':
  4582. X                l = *sp++ - '0';
  4583. X                if (*sp >= '0' && *sp <= '7') {
  4584. X                    l = l * 8 + (*sp++ - '0');
  4585. X                    if (*sp >= '0' && *sp <= '7')
  4586. X                        l = l * 8 + (*sp++ - '0');
  4587. X                }
  4588. X                PUTCHAR(l);
  4589. X                break;
  4590. X
  4591. X            case '\0':
  4592. X                PUTCHAR('\\');
  4593. X                break;
  4594. X
  4595. X            case '@':
  4596. X                if (!forced_lit)
  4597. X                    forced_lit = _lit_output();
  4598. X                sp++;
  4599. X                break;
  4600. X
  4601. X            default:
  4602. X                PUTCHAR('\\');
  4603. X                PUTCHAR(*sp++);
  4604. X                break;
  4605. X            }
  4606. X            break;
  4607. X        case '^':
  4608. X            if (*++sp == '\0')
  4609. X                break;
  4610. X            l = *sp - '@';
  4611. X            if (l > 31)
  4612. X                l -= 32;
  4613. X            if (l < 0 || l > 31) {
  4614. X                PUTCHAR('^');
  4615. X                PUTCHAR(*sp++);
  4616. X            } else {
  4617. X                PUTCHAR(l);
  4618. X                sp++;
  4619. X            }
  4620. X            break;
  4621. X        case '$':
  4622. X            if (*++sp != '<') {
  4623. X                PUTCHAR('$');
  4624. X                break;
  4625. X            }
  4626. X            must_pad = 0;
  4627. X            multiply_pad = 0;
  4628. X            l = 0;
  4629. X            sp++;
  4630. X            while (isdigit(*sp))
  4631. X                l = l * 10 + (*sp++ - '0');
  4632. X            l *= 10;
  4633. X            if (*sp == '.') {
  4634. X                sp++;
  4635. X                if (isdigit(*sp))
  4636. X                    l += *sp++ - '0';
  4637. X            }
  4638. X            if (*sp == '/') {
  4639. X                must_pad = 1;
  4640. X                if (*++sp == '*') {
  4641. X                    multiply_pad = 1;
  4642. X                    sp++;
  4643. X                }
  4644. X            } else if (*sp == '*') {
  4645. X                multiply_pad = 1;
  4646. X                if (*++sp == '/') {
  4647. X                    must_pad = 1;
  4648. X                    sp++;
  4649. X                }
  4650. X            }
  4651. X            if (*sp != '>') {
  4652. X                PUTCHAR('p');
  4653. X                PUTCHAR('a');
  4654. X                PUTCHAR('d');
  4655. X                PUTCHAR('?');
  4656. X                break;
  4657. X            }
  4658. X            sp++;
  4659. X#ifdef TEST
  4660. X            printf("\nl = %d", l);
  4661. X#endif
  4662. X            if (cur_term->pad || must_pad) {
  4663. X                cnt = ((long) l * cur_term->baudrate
  4664. X                       * (multiply_pad ? count : 1) 
  4665. X                       + (10000L * BITSPERCHAR / 2L))
  4666. X                      / (10000L * BITSPERCHAR);
  4667. X#ifdef TEST
  4668. X                printf("; cnt = %d\n", cnt);
  4669. X#endif
  4670. X                while(cnt--)
  4671. X                    PUTCHAR(cur_term->padch);
  4672. X            }
  4673. X#ifdef TEST
  4674. X            printf("\n");
  4675. X#endif
  4676. X            break;
  4677. X        default:
  4678. X            PUTCHAR(*sp++);
  4679. X        }
  4680. X    }
  4681. X    if (forced_lit)
  4682. X        _norm_output();
  4683. X    return OK;
  4684. X}
  4685. X
  4686. int
  4687. putp(str)
  4688. char *str; {
  4689. X    return(tputs(str, 1,(int (*)()) 0));
  4690. X}
  4691. X
  4692. X#ifdef TEST
  4693. X
  4694. TERMINAL test_term, *cur_term = &test_term;
  4695. X
  4696. void
  4697. putch(c)
  4698. int c; {
  4699. X    c &= 0xff;
  4700. X    if (c > 127 || c < 0) {
  4701. X        printf("\\%03o", c);
  4702. X    } else if (c < 32) {
  4703. X        printf("^%c", c + '@');
  4704. X    } else if (c == 127) {
  4705. X        printf("^?");
  4706. X    } else {
  4707. X        putchar(c);
  4708. X    }
  4709. X}
  4710. X
  4711. char line[MAX_LINE];
  4712. X
  4713. int
  4714. main(argc, argv)
  4715. int argc;
  4716. char **argv; {
  4717. X    test_term.termcap = 0;
  4718. X    test_term.baudrate = 1200;
  4719. X    test_term.pad = 0;
  4720. X    test_term.padch = 0;
  4721. X    if (argc > 1) 
  4722. X        test_term.baudrate = atoi(argv[1]);
  4723. X    if (argc > 2)
  4724. X        test_term.padch = argv[2][0];
  4725. X    if (argc > 3)
  4726. X        test_term.pad = 1;
  4727. X
  4728. X    putchar('\n');
  4729. X
  4730. X    while(gets(line) != NULL) {
  4731. X        tputs(line, 7, putch);
  4732. X        putchar('\n');
  4733. X    }
  4734. X    return 0;
  4735. X}
  4736. X#endif
  4737. END_OF_FILE
  4738. if test 4288 -ne `wc -c <'tputs.c'`; then
  4739.     echo shar: \"'tputs.c'\" unpacked with wrong size!
  4740. fi
  4741. # end of 'tputs.c'
  4742. fi
  4743. if test -f 'version.h' -a "${1}" != "-c" ; then 
  4744.   echo shar: Will not clobber existing file \"'version.h'\"
  4745. else
  4746. echo shar: Extracting \"'version.h'\" \(101 characters\)
  4747. sed "s/^X//" >'version.h' <<'END_OF_FILE'
  4748. X/*
  4749. X * version.h
  4750. X *
  4751. X * By Ross Ridge
  4752. X * Public Domain
  4753. X *
  4754. X */
  4755. X
  4756. X#define RELEASE        3
  4757. X#define PATCHLEVEL    0
  4758. END_OF_FILE
  4759. if test 101 -ne `wc -c <'version.h'`; then
  4760.     echo shar: \"'version.h'\" unpacked with wrong size!
  4761. fi
  4762. # end of 'version.h'
  4763. fi
  4764. echo shar: End of archive 1 \(of 3\).
  4765. cp /dev/null ark1isdone
  4766. MISSING=""
  4767. for I in 1 2 3 ; do
  4768.     if test ! -f ark${I}isdone ; then
  4769.     MISSING="${MISSING} ${I}"
  4770.     fi
  4771. done
  4772. if test "${MISSING}" = "" ; then
  4773.     echo You have unpacked all 3 archives.
  4774.     rm -f ark[1-9]isdone
  4775. else
  4776.     echo You still need to unpack the following archives:
  4777.     echo "        " ${MISSING}
  4778. fi
  4779. ##  End of shell archive.
  4780. exit 0
  4781.