home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume35 / ee / part04 < prev    next >
Encoding:
Text File  |  1993-02-21  |  54.5 KB  |  2,181 lines

  1. Newsgroups: comp.sources.misc
  2. From: hugh@nsmdserv.cnd.hp.com (Hugh F. Mahon)
  3. Subject: v35i083:  ee - Easy Editor, a simple editor for UNIX, Part04/05
  4. Message-ID: <1993Feb22.041501.15413@sparky.imd.sterling.com>
  5. X-Md4-Signature: d5b0c1abecc217641218b3bfa757d076
  6. Date: Mon, 22 Feb 1993 04:15:01 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: hugh@nsmdserv.cnd.hp.com (Hugh F. Mahon)
  10. Posting-number: Volume 35, Issue 83
  11. Archive-name: ee/part04
  12. Environment: SYSV, SunOS, Curses
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  ee.1 new_curse.c.A
  19. # Wrapped by kent@sparky on Sat Feb 20 21:31:19 1993
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 4 (of 5)."'
  23. if test -f 'ee.1' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'ee.1'\"
  25. else
  26.   echo shar: Extracting \"'ee.1'\" \(14671 characters\)
  27.   sed "s/^X//" >'ee.1' <<'END_OF_FILE'
  28. X.\"
  29. X.\"
  30. X.\"  To format this reference page, use the command:
  31. X.\"
  32. X.\"    nroff -man ee.1
  33. X.\"
  34. X.\"  $Header: /users/hugh/tmp/old_ae/ee.1,v 1.14 1993/01/25 04:13:39 hugh Exp $
  35. X.\"
  36. X.TH ee 1 "" "" "" ""
  37. X.SH NAME
  38. Xee \- easy editor
  39. X.SH SYNOPSIS
  40. X.nf
  41. Xee [-e] [-i] [-h] [\fIfile\fR ...]
  42. Xree [-e] [-i] [-h] [\fIfile\fR ...]
  43. X.ta
  44. X.fi
  45. X.ad b
  46. X.SH DESCRIPTION
  47. XThe command 
  48. X.I ee 
  49. Xis a simple screen oriented text editor.  It is always in text insertion 
  50. Xmode unless there is a prompt at the bottom of the terminal, or a 
  51. Xmenu present (in a box in the middle of the terminal).  The command 
  52. X.I ree 
  53. Xis the same as 
  54. X.I ee, 
  55. Xbut restricted to editing the named 
  56. Xfile (no file operations, or shell escapes are allowed).
  57. X.PP
  58. XFor 
  59. X.I ee
  60. Xto work properly, the environment variable 
  61. X.SM TERM 
  62. Xmust be set to indicate the type of terminal being used.  For 
  63. Xexample, for an 
  64. X.SM HP 700/92 
  65. Xterminal, the 
  66. X.SM TERM 
  67. Xvariable should be set to "70092".  See your System Administrator if 
  68. Xyou need more information.
  69. X.\"
  70. X.\"     options
  71. X.\"
  72. X.SS Options
  73. XThe following options are available from the command line:
  74. X.PP
  75. X.TP 4
  76. X.B -e
  77. XTurns off expansion of tab character to spaces.
  78. X.TP 
  79. X.B -i
  80. XTurns off display of information window at top of terminal.
  81. X.TP
  82. X.B -h
  83. XTurns off highlighting of borders of windows and menus (improves 
  84. Xperformance on some terminals).
  85. X.br
  86. X.\"
  87. X.\"     command summary
  88. X.\"
  89. X.SS Command Summary
  90. XTo do anything other than insert text, the user must use the control 
  91. Xkeys (the 
  92. X.B Control 
  93. Xkey, represented by a "^",  pressed in conjunction with an 
  94. Xalphabetic key, e.g., ^a) and function keys available on the keyboard 
  95. X(such as 
  96. X.BR "Next Page" ", " "Prev Page" ,
  97. Xarrow keys, etc.).
  98. X.PP
  99. XSince not all terminals have function keys, 
  100. X.I ee
  101. Xhas the basic cursor movement functions assigned to control keys as 
  102. Xwell as more intuitive keys on the keyboard when available.  For 
  103. Xinstance, to move the cursor up, the user can use the up arrow key, 
  104. Xor 
  105. X.BR ^u .
  106. X.RS 4
  107. X.PP
  108. X.\"
  109. X.\"     control keys
  110. X.\"
  111. X.SS Control keys
  112. X.PP
  113. X.nf
  114. X.ta 1.4i
  115. X.sp
  116. X^a     Prompt for the decimal value of a character to insert.
  117. X^b     Move to the bottom of the text.
  118. X^c     Get the prompt for a command.
  119. X^d     Move the cursor down.
  120. X^e     Prompt for the string to search for.
  121. X^f     Undelete the last deleted character.
  122. X^g     Move to the beginning of the line.
  123. X^h     Backspace.
  124. X^i     Tab.
  125. X^j     Insert a newline.
  126. X^k     Delete the character the cursor is sitting on.
  127. X^l     Move the cursor left.
  128. X^m     Insert a newline.
  129. X^n     Move to the next page.
  130. X^o     Move to the end of the line.
  131. X^p     Move to the previous page.
  132. X^r     Move the cursor to the right.
  133. X^t     Move to the top of the text.
  134. X^u     Move the cursor up.
  135. X^v     Undelete the last deleted word.
  136. X^w     Delete the word beginning at the cursor position.
  137. X^x     Search.
  138. X^y     Delete from the cursor position to the end of line.
  139. X^z     Undelete the last deleted line.
  140. X^[ (\s-1ESC\s+1)    Pop up menu.
  141. X.RE
  142. X.ta
  143. X.fi
  144. X.sp
  145. X.\"
  146. X.\"     function keys
  147. X.\"
  148. X.SS Function Keys
  149. X.RS 4
  150. X.IP "\fBNext Page\fR"
  151. XMove to the next page.
  152. X.IP "\fBPrev Page\fR"
  153. XMove to the previous page.
  154. X.IP "\fBDelete Char\fR"
  155. XDelete the character the cursor is on.
  156. X.IP "\fBDelete Line\fR"
  157. XDelete from the cursor to the end of line.
  158. X.IP "\fBInsert line\fR"
  159. XInsert a newline at the cursor position.
  160. X.IP "\fBArrow keys\fR"
  161. XMove the cursor in the direction indicated.
  162. X.RE
  163. X.\"
  164. X.\"     commands
  165. X.\"
  166. X.SS Commands
  167. X.PP
  168. XSome operations require more information than a single keystroke can 
  169. Xprovide.  For the most basic operations, there is a menu that can be 
  170. Xobtained by pressing the 
  171. X.SM \fBESC\fR
  172. Xkey.  The same operations, and more can be performed by obtaining the 
  173. Xcommand prompt (^c) and typing in one of the commands below.
  174. X.RS 4
  175. X.IP "!\fBcmd\fR"
  176. XExecute \fBcmd\fR in a shell.
  177. X.IP "\fB0-9\fR"
  178. XMove to the line indicated.
  179. X.IP "\fBcase\fR"
  180. XMake searches case sensitive.
  181. X.IP "\fBcharacter\fR"
  182. XDisplay the ascii value of the character at the cursor.
  183. X.IP "\fBexit\fR"
  184. XSave the edited text, and leave the editor.
  185. X.IP "\fBexpand\fR"
  186. XExpand tabs to spaces.
  187. X.IP "\fBfile\fR"
  188. XPrint the name of the file.
  189. X.IP "\fBhelp\fR"
  190. XDisplay help screen.
  191. X.IP "\fBline\fR"
  192. XDisplay the current line number.
  193. X.IP "\fBnocase\fR
  194. XMake searches insensitive to case (the default).
  195. X.IP "\fBnoexpand\fR"
  196. XDon't expand tab to spaces when the \s-1TAB\s+1 key is pressed.
  197. X.IP "\fBquit\fR"
  198. XLeave the editor without saving changes.
  199. X.IP "\fBread\fR \fIfile\fR"
  200. XRead the named \fIfile\fR.
  201. X.IP "\fBwrite\fR \fIfile\fR"
  202. XWrite the text to the named \fIfile\fR.
  203. X.RE
  204. X.\"
  205. X.\"     menu options
  206. X.\"
  207. X.SS Menu Operations
  208. X.PP
  209. XPop-up menus can be obtained by pressing the 
  210. X.B escape 
  211. Xkey (or 
  212. X.B ^[ 
  213. Xif no 
  214. X.B escape 
  215. Xkey is present).  When in the menu, the escape key can be 
  216. Xused to leave the menu without performing any operations.  Use the up and 
  217. Xdown arrow keys, or 
  218. X.B ^u
  219. Xfor moving up and 
  220. X.B ^d 
  221. Xfor moving down to move to the desired items in the menu, then press 
  222. X.B return 
  223. Xto perform the indicated task.
  224. X.PP
  225. XThe main menu in \fIee\fR is as follows:
  226. X.RS 4
  227. X.IP "\fBleave editor\fR" 
  228. XIf changes have been made, the user will get a menu prompting whether or 
  229. Xnot the changes should be saved.
  230. X.IP "\fBhelp\fR"
  231. XDisplays a help screen, with all of the keyboard operations and commands.
  232. X.IP "\fBfile operations\fR"
  233. XPops up a menu for selecting whether to read a file, write to a file, or 
  234. Xsave the current contents of the editor, as well as send the contents of 
  235. Xthe editor to a print command (see the section \fBInitializing ee from a 
  236. Xfile\fR).
  237. X.IP "\fBredraw screen\fR"
  238. XProvides a means to repaint the screen if the screen has been corrupted.
  239. X.IP "\fBsettings\fR"
  240. XShows the current values of the operating modes, and right margin.  By 
  241. Xpressing return when the cursor is on a particular item, the value can be 
  242. Xchanged.  To leave this menu, press the \fBescape\fR key.  (See \fBModes\fR 
  243. Xbelow.)
  244. X.IP "\fBsearch\fR"
  245. X.br
  246. XPops up a menu in which the user may choose to enter a string to search 
  247. Xfor, or search for a string already entered.
  248. X.IP "\fBmiscellaneous\fR"
  249. XPops up a menu that allows the user to format the current paragraph, 
  250. Xexecute a shell command, or check the spelling of the text in the editor.
  251. X.RE
  252. X.\"
  253. X.\"     paragraph formatting
  254. X.\"
  255. X.SS Paragraph Formatting
  256. X.PP
  257. XParagraphs are defined for \fIee\fR by a block of text bounded by:
  258. X.sp 
  259. X.RS 8
  260. X.IP \(bu 
  261. XBegin or end of file.
  262. X.IP \(bu
  263. XLine with no characters, or only spaces and/or tabs.
  264. X.IP \(bu
  265. XLine starting with a period ('.') or right angle bracket ('>').
  266. X.RE
  267. X.PP
  268. XA paragraph may be formatted two ways:  explicitly by choosing the 
  269. X\fBformat paragraph\fR menu item, or by setting \fIee\fR to automatically 
  270. Xformat paragraphs.  The automatic mode may be set via a menu, or via the 
  271. Xinitialization file.
  272. X.PP
  273. XThere are three states for text operation in \fIee\fR: free-form, margins, 
  274. Xand automatic formatting.
  275. X.PP
  276. X"Free-form" is best used for things like programming.  There are no 
  277. Xrestrictions on the length of lines, and no formatting takes place.
  278. X.PP
  279. X"Margins" allows the user to type in text without having to worry about going 
  280. Xbeyond the right margin (the right margin may be set in the \fBsettings\fR 
  281. Xmenu, the default is for the margin to be the right edge of the 
  282. Xterminal).  This is the mode that allows the \fBformat paragraph\fR menu 
  283. Xitem to work.
  284. X.PP
  285. X"Automatic formatting" provides word-processor-like behavior.  The user 
  286. Xmay type in text, while \fIee\fR will make sure the entire paragraph fits 
  287. Xwithin the width of the terminal every time the user inserts a space after 
  288. Xtyping or deleting text.  Margin observation must also be enabled in order for 
  289. Xautomatic formatting to occur.
  290. X.\"
  291. X.\"     modes
  292. X.\"
  293. X.SS Modes
  294. X.PP
  295. XAlthough ee is a 'modeless' editor (it is in text insertion mode all the 
  296. Xtime), there are modes in some of the things it does.  These include:
  297. X.RS 4
  298. X.IP "\fBtab expansion\fR"
  299. XTabs may be inserted as a single tab character, or replaced with spaces.
  300. X.IP "\fBcase sensitivity\fR"
  301. XThe search operation can be sensitive to whether characters are upper- or 
  302. Xlower-case, or ignore case completely.
  303. X.IP "\fBmargins observed\fR"
  304. XLines can either be truncated at the right margin, or extend on forever.
  305. X.IP "\fBauto paragraph formatting\fR"
  306. XWhile typing in text, the editor can try to keep it looking reasonably well 
  307. Xwithin the width of the screen.
  308. X.IP "\fBeightbit characters\fR"
  309. XToggles whether eight bit characters are displayed as their value in angle 
  310. Xbrackets (e.g. "<220>") or as a character.
  311. X.IP "\fBinfo window\fR"
  312. XA window showing the keyboard operations that can be performed can be 
  313. Xdisplayed or not.
  314. X.RE
  315. X.PP
  316. XYou may set these modes via the initialization file (see below), or with a 
  317. Xmenu (see above).
  318. X.\"
  319. X.\"     spell checking
  320. X.\"
  321. X.SS Spell Checking
  322. X.PP
  323. XThere are two ways to have the spelling in the text checked from \fIee\fR.  
  324. XOne is by the traditional \fIspell\fR(1) command, the other is with the 
  325. Xoptional \fIispell\fR(1) command.
  326. X.PP
  327. XUsing \fIspell\fR, the words that are not recognized will be placed at the top 
  328. Xof the file.  For the \fIispell\fR option, the file is written to disk, 
  329. Xthen \fIispell\fR run on the file, and the file read back in once 
  330. X\fIispell\fR has completed making changes to the file.
  331. X.\"
  332. X.\"     printing
  333. X.\"
  334. X.SS Printing the contents of the editor
  335. X.PP
  336. XThe user may select a menu item which prints the contents of the editor.  
  337. X.I ee
  338. Xpipes the text in the editor to the command specified by the 
  339. Xinitialization command 
  340. X.B printcommand
  341. X(see the section 
  342. X.B Initializing ee from a file 
  343. Xbelow).  The default is to send the contents to "lp".  
  344. X.PP
  345. XWhatever the user assigns to 
  346. X.B printcommand 
  347. Xmust take input from 
  348. Xstandard input.  See your system administrator for more details.
  349. X.\"
  350. X.\"     shell operations
  351. X.\"
  352. X.SS Shell operations
  353. X.PP
  354. XShell commands can be executed from within 
  355. X.I ee 
  356. Xby selecting the 
  357. X.B shell command 
  358. Xitem in the 
  359. X.B miscellaneous 
  360. Xmenu, or by placing an exclamation mark ("!") before the command to 
  361. Xexecute at the 
  362. X.B command: 
  363. Xprompt.  Additionally, the user may direct the contents of the edit buffer 
  364. Xout to a shell operation (via a pipe) by using the left angle bracket 
  365. X(">"), followed by a "!" and the shell command to execute.  The output of 
  366. Xa shell operation can also be directed into the edit buffer by using a 
  367. Xright angle bracket ("<") before the exclamation mark.  These can even be 
  368. Xused together to send output to a shell operation and read back the 
  369. Xresults into the editor.  So, if the editor contained a list of words 
  370. Xto be sorted, they could be sorted by typing the following at the command 
  371. Xprompt:
  372. X.RS 4
  373. X.sp
  374. X><!sort
  375. X.sp
  376. X.RE
  377. XThis would send the contents of the editor to be piped into the 
  378. X.I sort 
  379. Xutility and the result would be placed into the edit buffer at the current 
  380. Xcursor location.  The old information would have to be deleted by the user.
  381. X.\"
  382. X.\"     initializing ee from a file
  383. X.\"
  384. X.SS Initializing ee from a file
  385. X.PP
  386. XSince different users have different preferences, \fIee\fR allows some 
  387. Xslight configurability.  There are three possible locations for an 
  388. Xinitialization file for ee:  the file \fI/usr/local/lib/init.ee\fR, the 
  389. Xfile \fI.init.ee\fR in the user's home directory, or the file \fI.init.ee\fR 
  390. Xin the current directory (if different from the home 
  391. Xdirectory).  This allows system administrators to set some preferences for 
  392. Xthe users on a system-wide basis (for example, the \fBprint\fR command), 
  393. Xand the user to customize settings for particular directories (like one 
  394. Xfor correspondence, and a different directory for programming).
  395. X.PP
  396. XThe file \fI\/usr/local/lib/init.ee\fR is read first, then 
  397. X\fI$HOME/.init.ee\fR, then \fI.init.ee\fR, with the settings specified by the 
  398. Xmost recent file read taking precedence.
  399. X.PP
  400. XThe following items may be entered in the initialization file:
  401. X.RS 4
  402. X.IP \fBcase\fR
  403. XSets searches to be case sensitive.
  404. X.IP \fBnocase\fR
  405. XSets searches to be insensitive to case (default).
  406. X.IP \fBexpand\fR
  407. XCauses \fIee\fR to expand tabs to spaces (default).
  408. X.IP \fBnoexpand\fR 
  409. XCauses \fIee\fR to insert tabs as a single character.
  410. X.IP \fBinfo\fR
  411. XA small information window is displayed at the top of the terminal 
  412. X(default).
  413. X.IP \fBnoinfo\fR
  414. XTurns off the display of the information window.
  415. X.IP \fBmargins\fR
  416. XCauses \fIee\fR to truncate lines at the right margin when the 
  417. Xcursor passes beyond the right margin as set by the user 
  418. Xwhile text is being inserted 
  419. X(default).
  420. X.IP \fBnomargins\fR
  421. XAllows lines to extend beyond the right margin.
  422. X.IP \fBautoformat\fR
  423. XCauses \fIee\fR to automatically try to format the current paragraph while 
  424. Xtext insertion is occurring.
  425. X.IP \fBnoautoformat\fR
  426. XTurns off automatic paragraph formatting (default).
  427. X.IP \fBprintcommand\fR
  428. XAllows the setting of the print command (default: "lp").
  429. X.IP \fBrightmargin\fR
  430. XThe user can select a value for the right margin (the first column on the 
  431. Xscreen is zero).
  432. X.IP \fBhighlight\fR
  433. XTurns on highlighting border of information window and menus (default).
  434. X.IP \fBnohighlight\fR
  435. XTurns off highlighting of border of information window and menus.
  436. X.IP \fBeightbit\fR
  437. XTurns on display of eight bit characters.
  438. X.IP \fBnoeightbit\fR
  439. XTurns off display of eight bit characters (they are displayed as their decimal 
  440. Xvalue inside angle brackets, e.g., "<220>").
  441. X.RE
  442. X.SH CAVEATS
  443. X.PP
  444. XTHIS MATERIAL IS PROVIDED "AS IS".  THERE ARE 
  445. XNO WARRANTIES OF ANY KIND WITH REGARD TO THIS 
  446. XMATERIAL, INCLUDING, BUT NOT LIMITED TO, THE 
  447. XIMPLIED WARRANTIES OF MERCHANTABILITY AND 
  448. XFITNESS FOR A PARTICULAR PURPOSE.  Neither 
  449. XHewlett-Packard nor Hugh Mahon shall be liable 
  450. Xfor errors contained herein, nor for 
  451. Xincidental or consequential damages in 
  452. Xconnection with the furnishing, performance or 
  453. Xuse of this material.  Neither Hewlett-Packard 
  454. Xnor Hugh Mahon assumes any responsibility for 
  455. Xthe use or reliability of this software or 
  456. Xdocumentation.  This software and 
  457. Xdocumentation is totally UNSUPPORTED.  There 
  458. Xis no support contract available.  Hewlett-Packard 
  459. Xhas done NO Quality Assurance on ANY 
  460. Xof the program or documentation.  You may find 
  461. Xthe quality of the materials inferior to 
  462. Xsupported materials. 
  463. X.PP
  464. XAlways make a copy of files that cannot be easily reproduced before 
  465. Xediting.  Save files early, and save often.
  466. X.SS International Code Set Support
  467. X.I ee 
  468. Xsupports single-byte character code sets (eight-bit clean).
  469. X.SH WARNINGS
  470. XThe automatic paragraph formatting operation 
  471. Xmay be too slow for slower systems.
  472. X.SH FILES
  473. X.PP
  474. X.I /usr/local/lib/init.ee
  475. X.br
  476. X.I $HOME/.init.ee
  477. X.br
  478. X.I .init.ee
  479. X.SH AUTHOR
  480. X.PP
  481. XThe software 
  482. X.I ee
  483. Xwas developed by Hugh Mahon.
  484. X.PP
  485. XThis software and documentation contains 
  486. Xproprietary information which is protected by 
  487. Xcopyright.  All rights are reserved. 
  488. X.PP
  489. XCopyright (c) 1990, 1991, 1992, 1993 Hugh Mahon.
  490. X.SH SEE ALSO
  491. X.PP
  492. Xterminfo(4), environ(5), spell(1), ispell(1), lp(1)
  493. X
  494. END_OF_FILE
  495.   if test 14671 -ne `wc -c <'ee.1'`; then
  496.     echo shar: \"'ee.1'\" unpacked with wrong size!
  497.   fi
  498.   # end of 'ee.1'
  499. fi
  500. if test -f 'new_curse.c.A' -a "${1}" != "-c" ; then 
  501.   echo shar: Will not clobber existing file \"'new_curse.c.A'\"
  502. else
  503.   echo shar: Extracting \"'new_curse.c.A'\" \(36627 characters\)
  504.   sed "s/^X//" >'new_curse.c.A' <<'END_OF_FILE'
  505. X/*
  506. X |    new_curse.c
  507. X |
  508. X |    A subset of curses developed for use with ae.
  509. X |
  510. X |    written by Hugh Mahon
  511. X |
  512. X |    THIS MATERIAL IS PROVIDED "AS IS".  THERE ARE
  513. X |    NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
  514. X |    MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
  515. X |    IMPLIED WARRANTIES OF MERCHANTABILITY AND
  516. X |    FITNESS FOR A PARTICULAR PURPOSE.  Neither
  517. X |    Hewlett-Packard nor Hugh Mahon shall be liable
  518. X |    for errors contained herein, nor for
  519. X |    incidental or consequential damages in
  520. X |    connection with the furnishing, performance or
  521. X |    use of this material.  Neither Hewlett-Packard
  522. X |    nor Hugh Mahon assumes any responsibility for
  523. X |    the use or reliability of this software or
  524. X |    documentation.  This software and
  525. X |    documentation is totally UNSUPPORTED.  There
  526. X |    is no support contract available.  Hewlett-
  527. X |    Packard has done NO Quality Assurance on ANY
  528. X |    of the program or documentation.  You may find
  529. X |    the quality of the materials inferior to
  530. X |    supported materials.
  531. X |
  532. X |    This software is not a product of Hewlett-Packard, Co., or any 
  533. X |    other company.  No support is implied or offered with this software.
  534. X |    You've got the source, and you're on your own.
  535. X |
  536. X |    This software is for free distribution, and is not to be sold, or 
  537. X |    otherwise traded for value without the expressed, written consent of 
  538. X |    the author.  Likewise, any derivatives of this software cannot be 
  539. X |    sold or traded without the consent of the author.  
  540. X |
  541. X |    This notice must be included with this software and any derivatives.
  542. X |
  543. X |    Copyright (c) 1986, 1987, 1988, 1991, 1992 Hugh Mahon
  544. X |    All are rights reserved.
  545. X |
  546. X |    $Header: /users/hugh/tmp/old_ae/new_curse.c,v 1.20 1992/12/18 05:04:39 hugh Exp $
  547. X |
  548. X */
  549. X
  550. X#include "new_curse.h"
  551. X#include <signal.h>
  552. X
  553. Xchar *copyright_message[] = { "Copyright (c) 1986, 1987, 1988, 1991, 1992 Hugh Mahon",
  554. X                "All rights are reserved."};
  555. X
  556. Xchar * new_curse_name= "@(#) new_curse.c $Revision: 1.20 $";
  557. X
  558. XWINDOW *curscr;
  559. Xstatic WINDOW *virtual_scr;
  560. XWINDOW *stdscr;
  561. XWINDOW *newwin();
  562. XWINDOW *last_window_refreshed;
  563. X
  564. X#ifndef CAP
  565. X#define String_Out(table, stack, place) Info_Out(table, stack, place)
  566. X#else
  567. X#define String_Out(table, stack, place) Cap_Out(table, stack, place)
  568. X#endif
  569. X
  570. X#define bw__ 0    /* booleans    */
  571. X#define am__ 1
  572. X#define xb__ 2
  573. X#define xs__ 3    /* hp glitch (standout not erased by overwrite)    */
  574. X#define xn__ 4
  575. X#define eo__ 5
  576. X#define gn__ 6    /* generic type terminal    */
  577. X#define hc__ 7    /* hardcopy terminal        */
  578. X#define km__ 8
  579. X#define hs__ 9
  580. X#define in__ 10
  581. X#define da__ 11
  582. X#define db__ 12
  583. X#define mi__ 13    /* safe to move during insert mode    */
  584. X#define ms__ 14    /* safe to move during standout mode    */
  585. X#define os__ 15
  586. X#define es__ 16
  587. X#define xt__ 17
  588. X#define hz__ 18    /* hazeltine glitch    */
  589. X#define ul__ 19
  590. X#define xo__ 20
  591. X#define chts__ 21
  592. X#define nxon__ 22
  593. X#define nrrmc__ 23
  594. X#define npc__ 24
  595. X#define mc5i__ 25
  596. X
  597. X#define co__ 0    /* number of columns    */    /* numbers        */
  598. X#define it__ 1    /* spaces per tab    */
  599. X#define li__ 2    /* number of lines    */
  600. X#define lm__ 3
  601. X#define sg__ 4    /* magic cookie glitch    */
  602. X#define pb__ 5
  603. X#define vt__ 6
  604. X#define ws__ 7
  605. X
  606. X#define cols__ 0
  607. X#define lines__ 2
  608. X#define xmc__ 4
  609. X#define vt__ 6
  610. X#define wsl__ 7
  611. X#define nlab__ 8
  612. X#define lh__ 9
  613. X#define lw__ 10
  614. X
  615. X#define bt__ 0    /* back tab        */    /* strings    */
  616. X#define bl__ 1    /* bell            */
  617. X#define cr__ 2    /* carriage return    */
  618. X#define cs__ 3    /* change scroll region    */
  619. X#define ct__ 4    /* clear all tab stops    */
  620. X#define cl__ 5    /* clear screen and home cursor    */
  621. X#define ce__ 6    /* clear to end of line    */
  622. X#define cd__ 7    /* clear to end of display    */
  623. X#define ch__ 8    /* set cursor column    */
  624. X#define CC__ 9    /* term, settable cmd char in     */
  625. X#define cm__ 10    /* screen rel cursor motion, row, column    */
  626. X#define do__ 11    /* down one line    */
  627. X#define ho__ 12    /* home cursor    */
  628. X#define vi__ 13    /* make cursor invisible    */
  629. X#define le__ 14    /* move cursor left one space    */
  630. X#define CM__ 15    /* memory rel cursor addressing    */
  631. X#define ve__ 16    /* make cursor appear normal    */
  632. X#define nd__ 17    /* non-destructive space (cursor right)    */
  633. X#define ll__ 18    /* last line, first col    */
  634. X#define up__ 19    /* cursor up        */
  635. X#define vs__ 20
  636. X#define dc__ 21    /* delete character    */
  637. X#define dl__ 22    /* delete line        */
  638. X#define ds__ 23
  639. X#define hd__ 24
  640. X#define as__ 25
  641. X#define mb__ 26
  642. X#define md__ 27    /* turn on bold        */
  643. X#define ti__ 28
  644. X#define dm__ 29    /* turn on delete mode    */
  645. X#define mh__ 30    /* half bright mode    */
  646. X#define im__ 31    /* insert mode        */
  647. X#define mk__ 32
  648. X#define mp__ 33
  649. X#define mr__ 34
  650. X#define so__ 35    /* enter standout mode    */
  651. X#define us__ 36
  652. X#define ec__ 37
  653. X#define ae__ 38
  654. X#define me__ 39
  655. X#define te__ 40
  656. X#define ed__ 41
  657. X#define ei__ 42    /* exit insert mode    */
  658. X#define se__ 43    /* exit standout mode    */
  659. X#define ue__ 44
  660. X#define vb__ 45
  661. X#define ff__ 46
  662. X#define fs__ 47
  663. X#define i1__ 48
  664. X#define i2__ 49
  665. X#define i3__ 50
  666. X#define if__ 51
  667. X#define ic__ 52
  668. X#define al__ 53
  669. X#define ip__ 54
  670. X#define kb__ 55        /* backspace key    */
  671. X#define ka__ 56
  672. X#define kC__ 57
  673. X#define kt__ 58
  674. X#define kD__ 59
  675. X#define kL__ 60
  676. X#define kd__ 61
  677. X#define kM__ 62
  678. X#define kE__ 63
  679. X#define kS__ 64
  680. X#define k0__ 65
  681. X#define k1__ 66
  682. X#define kf10__ 67
  683. X#define k2__ 68
  684. X#define k3__ 69
  685. X#define k4__ 70
  686. X#define k5__ 71
  687. X#define k6__ 72
  688. X#define k7__ 73
  689. X#define k8__ 74
  690. X#define k9__ 75
  691. X#define kh__ 76
  692. X#define kI__ 77
  693. X#define kA__ 78
  694. X#define kl__ 79
  695. X#define kH__ 80
  696. X#define kN__ 81
  697. X#define kP__ 82
  698. X#define kr__ 83
  699. X#define kF__ 84
  700. X#define kR__ 85
  701. X#define kT__ 86
  702. X#define ku__ 87    /* key up    */
  703. X#define ke__ 88
  704. X#define ks__ 89
  705. X#define l0__ 90
  706. X#define l1__ 91
  707. X#define la__ 92
  708. X#define l2__ 93
  709. X#define l3__ 94
  710. X#define l4__ 95
  711. X#define l5__ 96
  712. X#define l6__ 97
  713. X#define l7__ 98
  714. X#define l8__ 99
  715. X#define l9__ 100
  716. X#define mo__ 101
  717. X#define mm__ 102
  718. X#define nw__ 103
  719. X#define pc__ 104
  720. X#define DC__ 105
  721. X#define DL__ 106
  722. X#define DO__ 107
  723. X#define IC__ 118
  724. X#define SF__ 109
  725. X#define AL__ 110
  726. X#define LE__ 111
  727. X#define RI__ 112
  728. X#define SR__ 113
  729. X#define UP__ 114
  730. X#define pk__ 115
  731. X#define pl__ 116
  732. X#define px__ 117
  733. X#define ps__ 118
  734. X#define pf__ 119
  735. X#define po__ 120
  736. X#define rp__ 121
  737. X#define r1__ 122
  738. X#define r2__ 123
  739. X#define r3__ 124
  740. X#define rf__ 125
  741. X#define rc__ 126
  742. X#define cv__ 127
  743. X#define sc__ 128
  744. X#define sf__ 129
  745. X#define sr__ 130
  746. X#define sa__ 131    /* sgr    */
  747. X#define st__ 132
  748. X#define wi__ 133
  749. X#define ta__ 134
  750. X#define ts__ 135
  751. X#define uc__ 136
  752. X#define hu__ 137
  753. X#define iP__ 138
  754. X#define K1__ 139
  755. X#define K2__ 140
  756. X#define K3__ 141
  757. X#define K4__ 142
  758. X#define K5__ 143
  759. X#define pO__ 144
  760. X#define ml__ 145
  761. X#define mu__ 146
  762. X#define rmp__ 145
  763. X#define acsc__ 146
  764. X#define pln__ 147
  765. X#define kcbt__ 148
  766. X#define smxon__ 149
  767. X#define rmxon__ 150
  768. X#define smam__ 151
  769. X#define rmam__ 152
  770. X#define xonc__ 153
  771. X#define xoffc__ 154
  772. X#define enacs__ 155
  773. X#define smln__ 156
  774. X#define rmln__ 157
  775. X#define kbeg__ 158
  776. X#define kcan__ 159
  777. X#define kclo__ 160
  778. X#define kcmd__ 161
  779. X#define kcpy__ 162
  780. X#define kcrt__ 163
  781. X#define kend__ 164
  782. X#define kent__ 165
  783. X#define kext__ 166
  784. X#define kfnd__ 167
  785. X#define khlp__ 168
  786. X#define kmrk__ 169
  787. X#define kmsg__ 170
  788. X#define kmov__ 171
  789. X#define knxt__ 172
  790. X#define kopn__ 173
  791. X#define kopt__ 174
  792. X#define kprv__ 175
  793. X#define kprt__ 176
  794. X#define krdo__ 177
  795. X#define kref__ 178
  796. X#define krfr__ 179
  797. X#define krpl__ 180
  798. X#define krst__ 181
  799. X#define kres__ 182
  800. X#define ksav__ 183
  801. X#define kspd__ 184
  802. X#define kund__ 185
  803. X#define kBEG__ 186
  804. X#define kCAN__ 187
  805. X#define kCMD__ 188
  806. X#define kCPY__ 189
  807. X#define kCRT__ 190
  808. X#define kDC__ 191
  809. X#define kDL__ 192
  810. X#define kslt__ 193
  811. X#define kEND__ 194
  812. X#define kEOL__ 195
  813. X#define kEXT__ 196
  814. X#define kFND__ 197
  815. X#define kHLP__ 198
  816. X#define kHOM__ 199
  817. X#define kIC__ 200
  818. X#define kLFT__ 201
  819. X#define kMSG__ 202
  820. X#define kMOV__ 203
  821. X#define kNXT__ 204
  822. X#define kOPT__ 205
  823. X#define kPRV__ 206
  824. X#define kPRT__ 207
  825. X#define kRDO__ 208
  826. X#define kRPL__ 209
  827. X#define kRIT__ 210
  828. X#define kRES__ 211
  829. X#define kSAV__ 212
  830. X#define kSPD__ 213
  831. X#define kUND__ 214
  832. X#define rfi__ 215
  833. X#define kf11__ 216
  834. X#define kf12__ 217
  835. X#define kf13__ 218
  836. X#define kf14__ 219
  837. X#define kf15__ 220
  838. X#define kf16__ 221
  839. X#define kf17__ 222
  840. X#define kf18__ 223
  841. X#define kf19__ 224
  842. X#define kf20__ 225
  843. X#define kf21__ 226
  844. X#define kf22__ 227
  845. X#define kf23__ 228
  846. X#define kf24__ 229
  847. X#define kf25__ 230
  848. X#define kf26__ 231
  849. X#define kf27__ 232
  850. X#define kf28__ 233
  851. X#define kf29__ 234
  852. X#define kf30__ 235
  853. X#define kf31__ 236
  854. X#define kf32__ 237
  855. X#define kf33__ 238
  856. X#define kf34__ 239
  857. X#define kf35__ 240
  858. X#define kf36__ 241
  859. X#define kf37__ 242
  860. X#define kf38__ 243
  861. X#define kf39__ 244
  862. X#define kf40__ 245
  863. X#define kf41__ 246
  864. X#define kf42__ 247
  865. X#define kf43__ 248
  866. X#define kf44__ 249
  867. X#define kf45__ 250
  868. X#define kf46__ 251
  869. X#define kf47__ 252
  870. X#define kf48__ 253
  871. X#define kf49__ 254
  872. X#define kf50__ 255
  873. X#define kf51__ 256
  874. X#define kf52__ 257
  875. X#define kf53__ 258
  876. X#define kf54__ 259
  877. X#define kf55__ 260
  878. X#define kf56__ 261
  879. X#define kf57__ 262
  880. X#define kf58__ 263
  881. X#define kf59__ 264
  882. X#define kf60__ 265
  883. X#define kf61__ 266
  884. X#define kf62__ 267
  885. X#define kf63__ 268
  886. X#define el1__ 269
  887. X#define mgc__ 270
  888. X#define smgl__ 271
  889. X#define smgr__ 272
  890. X
  891. X#ifdef CAP
  892. Xchar *Boolean_names[] = {
  893. X"bw", "am", "xb", "xs", "xn", "eo", "gn", "hc", "km", "hs", "in", "da", "db", 
  894. X"mi", "ms", "os", "es", "xt", "hz", "ul", "xo", "HC", "nx", "NR", "NP", "5i"
  895. X}; 
  896. X
  897. Xchar *Number_names[] = { 
  898. X"co#", "it#", "li#", "lm#", "sg#", "pb#", "vt#", "ws#", "Nl#", "lh#", "lw#"
  899. X};
  900. X
  901. Xchar *String_names[] = {
  902. X"bt=", "bl=", "cr=", "cs=", "ct=", "cl=", "ce=", "cd=", "ch=", "CC=", "cm=", 
  903. X"do=", "ho=", "vi=", "le=", "CM=", "ve=", "nd=", "ll=", "up=", "vs=", "dc=", 
  904. X"dl=", "ds=", "hd=", "as=", "mb=", "md=", "ti=", "dm=", "mh=", "im=", "mk=", 
  905. X"mp=", "mr=", "so=", "us=", "ec=", "ae=", "me=", "te=", "ed=", "ei=", "se=", 
  906. X"ue=", "vb=", "ff=", "fs=", "i1=", "i2=", "i3=", "if=", "ic=", "al=", "ip=", 
  907. X"kb=", "ka=", "kC=", "kt=", "kD=", "kL=", "kd=", "kM=", "kE=", "kS=", "k0=", 
  908. X"k1=", "k;=", "k2=", "k3=", "k4=", "k5=", "k6=", "k7=", "k8=", "k9=", "kh=", 
  909. X"kI=", "kA=", "kl=", "kH=", "kN=", "kP=", "kr=", "kF=", "kR=", "kT=", "ku=", 
  910. X"ke=", "ks=", "l0=", "l1=", "la=", "l2=", "l3=", "l4=", "l5=", "l6=", "l7=", 
  911. X"l8=", "l9=", "mo=", "mm=", "nw=", "pc=", "DC=", "DL=", "DO=", "IC=", "SF=", 
  912. X"AL=", "LE=", "RI=", "SR=", "UP=", "pk=", "pl=", "px=", "ps=", "pf=", "po=", 
  913. X"rp=", "r1=", "r2=", "r3=", "rf=", "rc=", "cv=", "sc=", "sf=", "sr=", "sa=", 
  914. X"st=", "wi=", "ta=", "ts=", "uc=", "hu=", "iP=", "K1=", "K3=", "K2=", "K4=", 
  915. X"K5=", "pO=", "rP=", "ac=", "pn=", "kB=", "SX=", "RX=", "SA=", "RA=", "XN=", 
  916. X"XF=", "eA=", "LO=", "LF=", "@1=", "@2=", "@3=", "@4=", "@5=", "@6=", "@7=", 
  917. X"@8=", "@9=", "@0=", "%1=", "%2=", "%3=", "%4=", "%5=", "%6=", "%7=", "%8=", 
  918. X"%9=", "%0=", "&1=", "&2=", "&3=", "&4=", "&5=", "&6=", "&7=", "&8=", "&9=", 
  919. X"&0=", "*1=", "*2=", "*3=", "*4=", "*5=", "*6=", "*7=", "*8=", "*9=", "*0=", 
  920. X"#1=", "#2=", "#3=", "#4=", "%a=", "%b=", "%c=", "%d=", "%e=", "%f=", "%g=", 
  921. X"%h=", "%i=", "%j=", "!1=", "!2=", "!3=", "RF=", "F1=", "F2=", "F3=", "F4=", 
  922. X"F5=", "F6=", "F7=", "F8=", "F9=", "FA=", "FB=", "FC=", "FD=", "FE=", "FF=", 
  923. X"FG=", "FH=", "FI=", "FJ=", "FK=", "FL=", "FM=", "FN=", "FO=", "FP=", "FQ=", 
  924. X"FR=", "FS=", "FT=", "FU=", "FV=", "FW=", "FX=", "FY=", "FZ=", "Fa=", "Fb=", 
  925. X"Fc=", "Fd=", "Fe=", "Ff=", "Fg=", "Fh=", "Fi=", "Fj=", "Fk=", "Fl=", "Fm=", 
  926. X"Fn=", "Fo=", "Fp=", "Fq=", "Fr=", "cb=", "MC=", "ML=", "MR="
  927. X};
  928. X#endif
  929. X
  930. Xchar *new_curse = "October 1987";
  931. X
  932. Xchar in_buff[100];    /* buffer for ungetch            */
  933. Xint bufp;        /* next free position in in_buff    */
  934. X
  935. Xchar *TERMINAL_TYPE = NULL; /* terminal type to be gotten from environment    */
  936. Xint CFOUND = NULL;
  937. Xint Data_Line_len = 0;
  938. Xint Max_Key_len;    /* max length of a sequence sent by a key    */
  939. Xchar *Data_Line = NULL;
  940. Xchar *TERM_PATH = NULL;
  941. Xchar *TERM_data_ptr = NULL;
  942. Xchar *Term_File_name = NULL;    /* name of file containing terminal description    */
  943. XFILE *TFP;        /* file pointer to file with terminal des.    */
  944. Xint Fildes;        /* file descriptor for terminfo file        */
  945. Xint STAND = FALSE;    /* is standout mode activated?            */
  946. Xint TERM_INFO = FALSE;    /* is terminfo being used (TRUE), or termcap (FALSE) */
  947. Xint Time_Out;    /* set when time elapsed while trying to read function key */
  948. Xint Curr_x;        /* current x position on screen            */
  949. Xint Curr_y;        /* current y position on the screen        */
  950. Xint LINES;
  951. Xint COLS;
  952. Xint Move_It;        /* flag to move cursor if magic cookie glitch    */
  953. Xint initialized = FALSE;    /* tells whether new_curse is initialized    */
  954. Xfloat speed;
  955. Xfloat chars_per_millisecond;
  956. Xint Repaint_screen;    /* if an operation to change screen impossible, repaint screen    */
  957. Xint Intr;        /* storeage for interrupt character        */
  958. Xint Parity;        /* 0 = no parity, 1 = odd parity, 2 = even parity */
  959. Xint Nowait;        /* for BSD systems                */
  960. Xint Num_bits;    /* number of bits per character    */
  961. Xint Flip_Bytes;    /* some systems have byte order reversed    */
  962. X
  963. X#ifndef CAP
  964. Xchar *Strings;
  965. X#endif
  966. X
  967. Xstruct KEYS {
  968. X    int length;    /* length of string sent by key            */
  969. X    char *string;    /* string sent by key                */
  970. X    int value;    /* CURSES value of key (9-bit)            */
  971. X    };
  972. X
  973. Xstruct KEY_STACK {
  974. X    struct KEYS *element;
  975. X    struct KEY_STACK *next;
  976. X    };
  977. X
  978. Xstruct KEY_STACK *KEY_TOS = NULL;
  979. Xstruct KEY_STACK *KEY_POINT;
  980. X
  981. Xstruct Parameters {
  982. X    int value;
  983. X    struct Parameters *next;
  984. X    };
  985. X
  986. Xint Key_vals[] = { 
  987. X    0407, 0526, 0515, 0525, 0512, 0510, 0402, 0514, 0517, 0516, 0410, 0411, 
  988. X    0422, 0412, 0413, 0414, 0415, 0416, 0417, 0420, 0421, 0406, 0513, 0511, 
  989. X    0404, 0533, 0522, 0523, 0405, 0520, 0521, 0524, 0403, 
  990. X    0534, 0535, 0536, 0537, 0540, 0541, 0542, 0543, 0544, 0545, 0546, 0547, 
  991. X    0550, 0527, 0551, 0552, 0553, 0554, 0555, 0556, 0557, 0560, 0561, 0562, 
  992. X    0532, 0563, 0564, 0565, 0566, 0567, 0570, 0571, 0627, 0630, 0572, 0573, 
  993. X    0574, 0575, 0576, 0577, 0600, 0601, 0602, 0603, 0604, 0605, 0606, 0607, 
  994. X    0610, 0611, 0612, 0613, 0614, 0615, 0616, 0617, 0620, 0621, 0622, 0623, 
  995. X    0624, 0625, 0626, 0423, 0424, 0425, 0426, 0427, 0430, 0431, 
  996. X    0432, 0433, 0434, 0435, 0436, 0437, 0440, 0441, 0442, 0443, 0444, 0445, 
  997. X    0446, 0447, 0450, 0451, 0452, 0453, 0454, 0455, 0456, 0457, 0460, 0461, 
  998. X    0462, 0463, 0464, 0465, 0466, 0467, 0470, 0471, 0472, 0473, 0474, 0475, 
  999. X    0476, 0477, 0500, 0501, 0502, 0503, 0504, 0505, 0506, 0507
  1000. X};
  1001. X
  1002. Xint attributes_set[9];
  1003. X
  1004. X#ifdef SYS5
  1005. Xstruct termio Terminal;
  1006. Xstruct termio Saved_tty;
  1007. X#else
  1008. Xstruct sgttyb Terminal;
  1009. Xstruct sgttyb Saved_tty;
  1010. X#endif
  1011. X
  1012. Xchar *tc_;
  1013. X
  1014. Xint Booleans[128];    
  1015. Xint Numbers[128];
  1016. Xchar *String_table[1024];
  1017. X
  1018. Xint *virtual_lines;
  1019. X
  1020. Xinitscr()        /* initialize terminal for operations    */
  1021. X{
  1022. X    char *pointer;
  1023. X    int value;
  1024. X    char *lines_string;
  1025. X    char *columns_string;
  1026. X
  1027. X#ifdef DIAG
  1028. Xprintf("starting initscr \n");fflush(stdout);
  1029. X#endif
  1030. X    if (initialized)
  1031. X        return;
  1032. X    Flip_Bytes = FALSE;
  1033. X    Parity = 0;
  1034. X    Time_Out = FALSE;
  1035. X    bufp = 0;
  1036. X    Move_It = FALSE;
  1037. X    Nowait = FALSE;
  1038. X#ifdef SYS5
  1039. X    value = ioctl(0, TCGETA, &Terminal);
  1040. X    if (Terminal.c_cflag & PARENB)
  1041. X    {
  1042. X        if (Terminal.c_cflag & PARENB)
  1043. X            Parity = 1;
  1044. X        else
  1045. X            Parity = 2;
  1046. X    }
  1047. X    if ((Terminal.c_cflag & CS8) == CS8)
  1048. X    {
  1049. X        Num_bits = 8;
  1050. X    }
  1051. X    else if ((Terminal.c_cflag & CS7) == CS7)
  1052. X        Num_bits = 7;
  1053. X    else if ((Terminal.c_cflag & CS6) == CS6)
  1054. X        Num_bits = 6;
  1055. X    else
  1056. X        Num_bits = 5;
  1057. X    value = Terminal.c_cflag & 037;
  1058. X    switch (value) {
  1059. X    case 01:    speed = 50.0;
  1060. X        break;
  1061. X    case 02:    speed = 75.0;
  1062. X        break;
  1063. X    case 03:    speed = 110.0;
  1064. X        break;
  1065. X    case 04:    speed = 134.5;
  1066. X        break;
  1067. X    case 05:    speed = 150.0;
  1068. X        break;
  1069. X    case 06:    speed = 200.0;
  1070. X        break;
  1071. X    case 07:    speed = 300.0;
  1072. X        break;
  1073. X    case 010:    speed = 600.0;
  1074. X        break;
  1075. X    case 011:    speed = 900.0;
  1076. X        break;
  1077. X    case 012:    speed = 1200.0;
  1078. X        break;
  1079. X    case 013:    speed = 1800.0;
  1080. X        break;
  1081. X    case 014:    speed = 2400.0;
  1082. X        break;
  1083. X    case 015:    speed = 3600.0;
  1084. X        break;
  1085. X    case 016:    speed = 4800.0;
  1086. X        break;
  1087. X    case 017:    speed = 7200.0;
  1088. X        break;
  1089. X    case 020:    speed = 9600.0;
  1090. X        break;
  1091. X    case 021:    speed = 19200.0;
  1092. X        break;
  1093. X    case 022:    speed = 38400.0;
  1094. X        break;
  1095. X    default:    speed = 0.0;
  1096. X    }
  1097. X#else
  1098. X    value = ioctl(0, TIOCGETP, &Terminal);
  1099. X    if (Terminal.sg_flags & EVENP)
  1100. X        Parity = 2;
  1101. X    else if (Terminal.sg_flags & ODDP)
  1102. X        Parity = 1;
  1103. X    value = Terminal.sg_ospeed;
  1104. X    switch (value) {
  1105. X    case 01:    speed = 50.0;
  1106. X        break;
  1107. X    case 02:    speed = 75.0;
  1108. X        break;
  1109. X    case 03:    speed = 110.0;
  1110. X        break;
  1111. X    case 04:    speed = 134.5;
  1112. X        break;
  1113. X    case 05:    speed = 150.0;
  1114. X        break;
  1115. X    case 06:    speed = 200.0;
  1116. X        break;
  1117. X    case 07:    speed = 300.0;
  1118. X        break;
  1119. X    case 010:    speed = 600.0;
  1120. X        break;
  1121. X    case 011:    speed = 1200.0;
  1122. X        break;
  1123. X    case 012:    speed = 1800.0;
  1124. X        break;
  1125. X    case 013:    speed = 2400.0;
  1126. X        break;
  1127. X    case 014:    speed = 4800.0;
  1128. X        break;
  1129. X    case 015:    speed = 9600.0;
  1130. X        break;
  1131. X    default:    speed = 0.0;
  1132. X    }
  1133. X#endif
  1134. X    chars_per_millisecond = (0.001 * speed) / 8.0;
  1135. X    TERMINAL_TYPE = getenv("TERM");
  1136. X    if (TERMINAL_TYPE == NULL)
  1137. X    {
  1138. X        printf("unknown terminal type\n");
  1139. X        exit(0);
  1140. X    }
  1141. X#ifndef CAP
  1142. X    TERM_PATH = getenv("TERMINFO");
  1143. X    if (TERM_PATH != NULL)
  1144. X    {
  1145. X        Data_Line_len = 23 + strlen(TERM_PATH) + strlen(TERMINAL_TYPE);
  1146. X        pointer = Term_File_name = malloc(Data_Line_len);
  1147. X        strcpy(Term_File_name, TERM_PATH);
  1148. X        while (*pointer != NULL)
  1149. X            pointer++;
  1150. X        *pointer = '/';
  1151. X        pointer++;
  1152. X    }
  1153. X    else
  1154. X    {
  1155. X        pointer = Term_File_name = malloc(22 + strlen(TERMINAL_TYPE));
  1156. X        strcpy(Term_File_name, "/usr/lib/terminfo/");
  1157. X        while (*pointer != NULL)
  1158. X            pointer++;
  1159. X    }
  1160. X    *pointer = *TERMINAL_TYPE;
  1161. X    pointer++;
  1162. X    *pointer = '/';
  1163. X    pointer++;
  1164. X    strcpy(pointer, TERMINAL_TYPE);
  1165. X    if ((Fildes = open(Term_File_name, 0)) == -1)
  1166. X    {
  1167. X        free(Term_File_name);
  1168. X        Term_File_name = NULL;
  1169. X    }
  1170. X    else
  1171. X        TERM_INFO = INFO_PARSE();
  1172. X#else
  1173. X    Term_File_name = "/etc/termcap";
  1174. X    if ((TFP = fopen(Term_File_name, "r")) == NULL)
  1175. X    {
  1176. X        printf("unable to open /etc/termcap file \n");
  1177. X        exit(0);
  1178. X    }
  1179. X     for (value = 0; value < 1024; value++)    
  1180. X        String_table[value] = NULL;
  1181. X    for (value = 0; value < 128; value++)    
  1182. X        Booleans[value] = 0;
  1183. X    for (value = 0; value < 128; value++)    
  1184. X        Numbers[value] = 0;
  1185. X    Find_term();
  1186. X    CAP_PARSE();
  1187. X#endif
  1188. X    if ((String_table[cm__] == NULL) || (Booleans[hc__]))
  1189. X    {
  1190. X        fprintf(stderr, "sorry, unable to use this terminal type for screen editing\n");
  1191. X        exit(0);
  1192. X    }
  1193. X    Key_Get();
  1194. X    LINES = Numbers[li__];
  1195. X    COLS = Numbers[co__];
  1196. X    if ((lines_string = getenv("LINES")) != NULL)
  1197. X    {
  1198. X        value = atoi(lines_string);
  1199. X        if (value > 0)
  1200. X            LINES = value;
  1201. X    }
  1202. X    if ((columns_string = getenv("COLUMNS")) != NULL)
  1203. X    {
  1204. X        value = atoi(columns_string);
  1205. X        if (value > 0)
  1206. X            COLS = value;
  1207. X    }
  1208. X    virtual_scr = newwin(LINES, COLS, 0, 0);
  1209. X    stdscr = newwin(LINES, COLS, 0, 0);
  1210. X    curscr = newwin(LINES, COLS, 0, 0);
  1211. X    wmove(stdscr, 0, 0);
  1212. X    werase(stdscr);
  1213. X    Repaint_screen = TRUE;
  1214. X    initialized = TRUE;
  1215. X    virtual_lines = (int *) malloc(LINES * (sizeof(int)));
  1216. X}
  1217. X
  1218. X#ifndef CAP
  1219. XGet_int()        /* get a two-byte integer from the terminfo file */
  1220. X{
  1221. X    int High_byte;
  1222. X    int Low_byte;
  1223. X    int temp;
  1224. X
  1225. X    Low_byte = *((unsigned char *) TERM_data_ptr++);
  1226. X    High_byte = *((unsigned char *) TERM_data_ptr++);
  1227. X    if (Flip_Bytes)
  1228. X    {
  1229. X        temp = Low_byte;
  1230. X        Low_byte = High_byte;
  1231. X        High_byte = temp;
  1232. X    }
  1233. X    if ((High_byte == 255) && (Low_byte == 255))
  1234. X        return (-1);
  1235. X    else
  1236. X        return(Low_byte + (High_byte * 256));
  1237. X}
  1238. X
  1239. XINFO_PARSE()        /* parse off the data in the terminfo data file    */
  1240. X{
  1241. X    int offset;
  1242. X    int magic_number = 0;
  1243. X    int counter = 0;
  1244. X    int Num_names = 0;
  1245. X    int Num_bools = 0;
  1246. X    int Num_ints = 0;
  1247. X    int Num_strings = 0;
  1248. X    int string_table_len = 0;
  1249. X    char *temp_ptr;
  1250. X
  1251. X    TERM_data_ptr = Data_Line = calloc(1, (10240 * (sizeof(char))));
  1252. X    Data_Line_len = read(Fildes, Data_Line, 10240);
  1253. X    if ((Data_Line_len >= 10240) || (Data_Line_len < 0))
  1254. X        return(0);
  1255. X    /*
  1256. X     |    get magic number
  1257. X     */
  1258. X    magic_number = Get_int();
  1259. X    /*
  1260. X     |    if magic number not right, reverse byte order and check again
  1261. X     */
  1262. X    if (magic_number != 282)
  1263. X    {
  1264. X        Flip_Bytes = TRUE;
  1265. X        TERM_data_ptr--;
  1266. X        TERM_data_ptr--;
  1267. X        magic_number = Get_int();
  1268. X        if (magic_number != 282)
  1269. X            return(0);
  1270. X    }
  1271. X    /*
  1272. X     |    get the number of each type in the terminfo data file
  1273. X     */
  1274. X    Num_names = Get_int();
  1275. X    Num_bools = Get_int();
  1276. X    Num_ints = Get_int();
  1277. X    Num_strings = Get_int();
  1278. X    string_table_len = Get_int();
  1279. X    Strings = calloc(1, string_table_len);
  1280. X    while (Num_names > 0)
  1281. X    {
  1282. X        TERM_data_ptr++;
  1283. X        Num_names--;
  1284. X    }
  1285. X    counter = 0;
  1286. X    while (Num_bools)
  1287. X    {
  1288. X        Num_bools--;
  1289. X        Booleans[counter++] = *TERM_data_ptr++;
  1290. X    }
  1291. X    if (((unsigned int) TERM_data_ptr) & 1)    /* force alignment    */
  1292. X        TERM_data_ptr++;
  1293. X    counter = 0;
  1294. X    while (Num_ints)
  1295. X    {
  1296. X        Num_ints--;
  1297. X        Numbers[counter] = Get_int();
  1298. X        counter++;
  1299. X    }
  1300. X    temp_ptr = TERM_data_ptr + Num_strings + Num_strings;
  1301. X    memcpy(Strings, temp_ptr, string_table_len);
  1302. X    counter = bt__;
  1303. X    while (Num_strings)
  1304. X    {
  1305. X        Num_strings--;
  1306. X        if ((offset=Get_int()) != -1)
  1307. X        {
  1308. X            if (String_table[counter] == NULL)
  1309. X                String_table[counter] = Strings + offset;
  1310. X        }
  1311. X        else
  1312. X            String_table[counter] = NULL;
  1313. X        counter++;
  1314. X    }
  1315. X    close(Fildes);
  1316. X    cfree(Data_Line);
  1317. X    return(TRUE);
  1318. X}
  1319. X#endif        /* ifndef CAP    */
  1320. X
  1321. XAtoI()        /* convert ascii text to integers    */
  1322. X{
  1323. X    int Temp;
  1324. X
  1325. X    Temp = 0;
  1326. X    while ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))
  1327. X    {
  1328. X        Temp = (Temp * 10) + (*TERM_data_ptr - '0');
  1329. X        TERM_data_ptr++;
  1330. X    }
  1331. X    return(Temp);
  1332. X}
  1333. X
  1334. XKey_Get()        /* create linked list with all key sequences obtained from terminal database    */
  1335. X{
  1336. X    int Counter;
  1337. X    int Klen;
  1338. X    int key_def;
  1339. X    struct KEY_STACK *Spoint;
  1340. X
  1341. X    Max_Key_len = 0;
  1342. X    Counter = 0;
  1343. X    key_def = kb__;
  1344. X    while (key_def <= kf63__)
  1345. X    {
  1346. X        if (key_def == ke__)
  1347. X            key_def = K1__;
  1348. X        else if (key_def == (K5__ + 1))
  1349. X            key_def = kcbt__;
  1350. X        else if (key_def == (kcbt__ + 1))
  1351. X            key_def = kbeg__;
  1352. X        else if (key_def == (kUND__ + 1))
  1353. X            key_def = kf11__;
  1354. X        if (String_table[key_def] != NULL)
  1355. X        {
  1356. X            if (KEY_TOS == NULL)
  1357. X                Spoint = KEY_TOS = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));
  1358. X            else
  1359. X            {
  1360. X                Spoint = KEY_TOS;
  1361. X                while (Spoint->next != NULL)
  1362. X                    Spoint = Spoint->next;
  1363. X                Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));
  1364. X                Spoint = Spoint->next;
  1365. X            }
  1366. X            Spoint->next = NULL;
  1367. X            Spoint->element = (struct KEYS *) malloc(sizeof(struct KEYS));
  1368. X            Spoint->element->string = String_table[key_def];
  1369. X            Spoint->element->length = strlen(String_table[key_def]);
  1370. X            Spoint->element->value = Key_vals[Counter];
  1371. X            Klen = strlen(Spoint->element->string);
  1372. X            if (Klen > Max_Key_len)
  1373. X                Max_Key_len = Klen;
  1374. X        }
  1375. X        key_def++;
  1376. X        Counter++;
  1377. X    }
  1378. X}
  1379. X
  1380. X#ifdef CAP
  1381. Xchar *String_Get(param)        /* read the string */
  1382. Xchar *param;
  1383. X{
  1384. X    char *String;
  1385. X    char *Temp;
  1386. X    int Counter;
  1387. X
  1388. X    if (param == NULL)
  1389. X    {
  1390. X        while (*TERM_data_ptr != '=')
  1391. X            TERM_data_ptr++;
  1392. X        Temp = ++TERM_data_ptr;
  1393. X        Counter = 1;
  1394. X        while ((*Temp != ':') && (*Temp != NULL))
  1395. X        {
  1396. X            Counter++;
  1397. X            Temp++;
  1398. X        }
  1399. X        String = Temp = malloc(Counter);
  1400. X        while ((*TERM_data_ptr != ':') && (*TERM_data_ptr != NULL))
  1401. X        {
  1402. X            if (*TERM_data_ptr == '\\')
  1403. X            {
  1404. X                TERM_data_ptr++;
  1405. X                if (*TERM_data_ptr == 'n')
  1406. X                    *Temp = '\n';
  1407. X                else if (*TERM_data_ptr == 't')
  1408. X                    *Temp = '\t';
  1409. X                else if (*TERM_data_ptr == 'b')
  1410. X                    *Temp = '\b';
  1411. X                else if (*TERM_data_ptr == 'r')
  1412. X                    *Temp = '\r';
  1413. X                else if (*TERM_data_ptr == 'f')
  1414. X                    *Temp = '\f';
  1415. X                else if ((*TERM_data_ptr == 'e') || (*TERM_data_ptr == 'E'))
  1416. X                    *Temp = '\033';        /* escape */
  1417. X                else if (*TERM_data_ptr == '\\')
  1418. X                    *Temp = '\\';
  1419. X                else if (*TERM_data_ptr == '\'')
  1420. X                    *Temp = '\'';
  1421. X                else if ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))
  1422. X                {
  1423. X                    Counter = 0;
  1424. X                    while ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))
  1425. X                    {
  1426. X                        Counter = (8 * Counter) + (*TERM_data_ptr - '0');
  1427. X                        *TERM_data_ptr++;
  1428. X                    }
  1429. X                    *Temp = Counter;
  1430. X                    TERM_data_ptr--;
  1431. X                }
  1432. X                TERM_data_ptr++;
  1433. X                Temp++;
  1434. X            }
  1435. X            else if (*TERM_data_ptr == '^')
  1436. X            {
  1437. X                TERM_data_ptr++;
  1438. X                if ((*TERM_data_ptr >= '@') && (*TERM_data_ptr <= '_'))
  1439. X                    *Temp = *TERM_data_ptr - '@';
  1440. X                else if (*TERM_data_ptr == '?')
  1441. X                    *Temp = 127;
  1442. X                TERM_data_ptr++;
  1443. X                Temp++;
  1444. X            }
  1445. X            else
  1446. X                *Temp++ = *TERM_data_ptr++;
  1447. X        }
  1448. X        *Temp = NULL;
  1449. X        param = String;
  1450. X    }
  1451. X    else
  1452. X    {
  1453. X        while ((*TERM_data_ptr != NULL) && (*TERM_data_ptr != ':'))
  1454. X            TERM_data_ptr++;
  1455. X        if (*TERM_data_ptr == ':')
  1456. X            TERM_data_ptr++;
  1457. X    }
  1458. X    return(param);
  1459. X}
  1460. X
  1461. XGet_int(param)        /* read the integer                */
  1462. Xint param;
  1463. X{
  1464. X    char *Temp;
  1465. X    int Itemp;
  1466. X
  1467. X    if (param == 0)
  1468. X    {
  1469. X        while ((*TERM_data_ptr != NULL) && (*TERM_data_ptr != '#'))
  1470. X            TERM_data_ptr++;
  1471. X        TERM_data_ptr++;
  1472. X        Itemp = AtoI();
  1473. X        if (*TERM_data_ptr == ':')
  1474. X            TERM_data_ptr++;
  1475. X        param = Itemp;
  1476. X    }
  1477. X    else
  1478. X    {
  1479. X        while (*TERM_data_ptr != ':')
  1480. X            TERM_data_ptr++;
  1481. X        if (*TERM_data_ptr == ':')
  1482. X            TERM_data_ptr++;
  1483. X    }
  1484. X    return(param);
  1485. X}
  1486. X
  1487. XFind_term()        /* find terminal description in termcap file    */
  1488. X{
  1489. X    char *Name;
  1490. X    char *Ftemp;
  1491. X
  1492. X    Ftemp = Name = malloc(strlen(TERMINAL_TYPE + 1) + 1);
  1493. X    strcpy(Name, TERMINAL_TYPE);
  1494. X    while (*Ftemp != NULL)
  1495. X        Ftemp++;
  1496. X    *Ftemp++ = '|';
  1497. X    *Ftemp = NULL;
  1498. X    Data_Line = malloc(512);
  1499. X    CFOUND = FALSE;
  1500. X    Data_Line_len = strlen(TERMINAL_TYPE) + 1;
  1501. X    while ((!CFOUND) && ((TERM_data_ptr=fgets(Data_Line, 512, TFP)) != NULL))
  1502. X    {
  1503. X        if ((*TERM_data_ptr != ' ') && (*TERM_data_ptr != '\t') && (*TERM_data_ptr != '#'))
  1504. X        {
  1505. X            while ((!CFOUND) && (*TERM_data_ptr != NULL))
  1506. X            {
  1507. X                CFOUND = !strncmp(TERM_data_ptr, Name, Data_Line_len);
  1508. X                while ((*TERM_data_ptr != NULL) && (*TERM_data_ptr != '|') && (*TERM_data_ptr != '#') && (*TERM_data_ptr != ':'))
  1509. X                    TERM_data_ptr++;
  1510. X                if (*TERM_data_ptr == '|')
  1511. X                    TERM_data_ptr++;
  1512. X                else if (!CFOUND)
  1513. X                    *TERM_data_ptr = NULL;
  1514. X            }
  1515. X        }
  1516. X    }
  1517. X    if (!CFOUND)
  1518. X    {
  1519. X        printf("terminal type %s not found\n", TERMINAL_TYPE);
  1520. X        exit(0);
  1521. X    }
  1522. X}
  1523. X
  1524. XCAP_PARSE()        /* parse off the data in the termcap data file    */
  1525. X{
  1526. X    int offset;
  1527. X    int Cip = 0;
  1528. X    int found;
  1529. X
  1530. X    do
  1531. X    {
  1532. X        while (*TERM_data_ptr != NULL)
  1533. X        {
  1534. X            for (found = FALSE, offset = 0; (!found) && (offset < 26); offset++)
  1535. X            {
  1536. X                if (!strncmp(TERM_data_ptr, Boolean_names[offset], 2))
  1537. X                {
  1538. X                    found = TRUE;
  1539. X                    Booleans[offset] = TRUE;
  1540. X                }
  1541. X            }
  1542. X            if (!found)
  1543. X            {
  1544. X                for (found = FALSE, offset = 0; (!found) && (offset < lw__); offset++)
  1545. X                {
  1546. X                    if (!strncmp(TERM_data_ptr, Number_names[offset], 3))
  1547. X                    {
  1548. X                        found = TRUE;
  1549. X                        Numbers[offset] = Get_int(Numbers[offset]);
  1550. X                    }
  1551. X                }
  1552. X            }
  1553. X            if (!found)
  1554. X            {
  1555. X                for (found = FALSE, offset = 0; (!found) && (offset < smgr__); offset++)
  1556. X                {
  1557. X                    if (!strncmp(TERM_data_ptr, String_names[offset], 3))
  1558. X                    {
  1559. X                        found = TRUE;
  1560. X                        String_table[offset] = String_Get(String_table[offset]);
  1561. X                    }
  1562. X                }
  1563. X            }
  1564. X
  1565. X            if (!strncmp(TERM_data_ptr, "tc=", 3))
  1566. X                tc_ = String_Get(NULL);
  1567. X            while ((*TERM_data_ptr != ':') && (*TERM_data_ptr != NULL))
  1568. X                TERM_data_ptr++;
  1569. X            if (*TERM_data_ptr == ':')
  1570. X                TERM_data_ptr++;
  1571. X        }
  1572. X    } while (((TERM_data_ptr = fgets(Data_Line, 512, TFP)) != NULL) && ((*TERM_data_ptr == ' ') || (*TERM_data_ptr == '\t')));
  1573. X    if (tc_ != NULL)
  1574. X    {
  1575. X        TERMINAL_TYPE = tc_;
  1576. X        rewind(TFP);
  1577. X        Find_term();
  1578. X        free(tc_);
  1579. X        tc_ = NULL;
  1580. X        CAP_PARSE();
  1581. X    }
  1582. X    else
  1583. X        fclose(TFP);
  1584. X}
  1585. X#endif        /* ifdef CAP    */
  1586. X
  1587. Xstruct _line *
  1588. XScreenalloc(columns)
  1589. Xint columns;
  1590. X{
  1591. X    int i;
  1592. X    struct _line *tmp;
  1593. X
  1594. X    tmp = (struct _line *) malloc(sizeof (struct _line));
  1595. X    tmp->row = malloc(columns + 1);
  1596. X    tmp->attributes = malloc(columns + 1);
  1597. X    tmp->prev_screen = NULL;
  1598. X    tmp->next_screen = NULL;
  1599. X    for (i = 0; i < columns; i++)
  1600. X    {
  1601. X        tmp->row[i] = ' ';
  1602. X        tmp->attributes[i] = NULL;
  1603. X    }
  1604. X    tmp->scroll = tmp->changed = FALSE;
  1605. X    tmp->row[0] = NULL;
  1606. X    tmp->attributes[0] = NULL;
  1607. X    tmp->row[columns] = NULL;
  1608. X    tmp->attributes[columns] = NULL;
  1609. X    tmp->last_char = 0;
  1610. X    return(tmp);
  1611. X}
  1612. X
  1613. XWINDOW *newwin(lines, cols, start_l, start_c)
  1614. Xint lines, cols;    /* number of lines and columns to be in window    */
  1615. Xint start_l, start_c;    /* starting line and column to be inwindow    */
  1616. X{
  1617. X    WINDOW *Ntemp;
  1618. X    struct _line *temp_screen;
  1619. X    int i;
  1620. X
  1621. X    Ntemp = (WINDOW *) malloc(sizeof(WINDOW));
  1622. X    Ntemp->SR = start_l;
  1623. X    Ntemp->SC = start_c;
  1624. X    Ntemp->Num_lines = lines;
  1625. X    Ntemp->Num_cols = cols;
  1626. X    Ntemp->LX = 0;
  1627. X    Ntemp->LY = 0;
  1628. X    Ntemp->scroll_down = Ntemp->scroll_up = 0;
  1629. X    Ntemp->SCROLL_CLEAR = FALSE;
  1630. X    Ntemp->Attrib = FALSE;
  1631. X    Ntemp->first_line = temp_screen = Screenalloc(cols);
  1632. X    Ntemp->first_line->number = 0;
  1633. X    for (i = 1; i < lines; i++)
  1634. X    {
  1635. X        temp_screen->next_screen = Screenalloc(cols);
  1636. X        temp_screen->next_screen->number = i;
  1637. X        temp_screen->next_screen->prev_screen = temp_screen;
  1638. X        temp_screen = temp_screen->next_screen;
  1639. X    }
  1640. X    Ntemp->first_line->prev_screen = NULL;
  1641. X    temp_screen->next_screen = NULL;
  1642. X    return(Ntemp);
  1643. X}
  1644. X
  1645. X#ifdef CAP
  1646. XCap_Out(string, p_list, place)        /* interpret the output string if necessary */
  1647. Xchar *string;
  1648. Xint p_list[];            /* stack of values    */
  1649. Xint place;            /* place keeper of top of stack    */
  1650. X{
  1651. X    char *Otemp;        /* temporary string pointer to parse output */
  1652. X    int delay;
  1653. X    int p1, p2, temp;
  1654. X    float chars;
  1655. X    int old_arg, value;
  1656. X
  1657. X    if (string == NULL)
  1658. X        return;
  1659. X
  1660. X/*#ifndef SYS5
  1661. X    old_arg = fcntl(0, F_GETFL, 0);
  1662. X    value = fcntl(0, F_SETFL, old_arg & ~FNDELAY);
  1663. X#endif*/
  1664. X
  1665. X    if (p_list != NULL)
  1666. X    {
  1667. X        p1 = p_list[--place];
  1668. X        p2 = p_list[--place];
  1669. X    }
  1670. X    delay = 0;
  1671. X    Otemp = string;
  1672. X    if ((*Otemp >= '0') && (*Otemp <= '9'))
  1673. X    {
  1674. X        delay = atoi(Otemp);
  1675. X        while ((*Otemp >= '0') && (*Otemp <= '9'))
  1676. X            Otemp++;
  1677. X        if (*Otemp == '*')
  1678. X            Otemp++;
  1679. X    }
  1680. X    while (*Otemp != NULL)
  1681. X    {
  1682. X        if (*Otemp == '%')
  1683. X        {
  1684. X            Otemp++;
  1685. X            if ((*Otemp == 'd') || (*Otemp == '2') || (*Otemp == '3') || (*Otemp == '.') || (*Otemp == '+')) 
  1686. X            {
  1687. X                if (*Otemp == 'd')
  1688. X                     printf("%d", p1);
  1689. X                else if (*Otemp == '2')
  1690. X                    printf("%2d", p1);
  1691. X                else if (*Otemp == '3')
  1692. X                    printf("%3d", p1);
  1693. X                else if (*Otemp == '+')
  1694. X                {
  1695. X                    Otemp++;
  1696. X                    p1 += *Otemp;
  1697. X                    putchar(p1);
  1698. X                }
  1699. X                else if (*Otemp == '.')
  1700. X                    putchar(p1);
  1701. X                p1 = p2;
  1702. X                p2 = 0;
  1703. X            }
  1704. X            else if (*Otemp == '>')
  1705. X            {
  1706. X                Otemp++;
  1707. X                if (p1 > *Otemp)
  1708. X                {
  1709. X                    Otemp++;
  1710. X                    p1 += *Otemp;
  1711. X                }
  1712. X                else
  1713. X                    Otemp++;
  1714. X            }
  1715. X            else if (*Otemp == 'r')
  1716. X            {
  1717. X                temp = p1;
  1718. X                p1 = p2;
  1719. X                p2 = temp;
  1720. X            }
  1721. X            else if (*Otemp == 'i')
  1722. X            {
  1723. X                p1++;
  1724. X                p2++;
  1725. X            }
  1726. X            else if (*Otemp == '%')
  1727. X                putchar(*Otemp);
  1728. X            else if (*Otemp == 'n')
  1729. X            {
  1730. X                p1 ^= 0140;
  1731. X                p2 ^= 0140;
  1732. X            }
  1733. X            else if (*Otemp == 'B')
  1734. X            {
  1735. X                p1 = (16 * (p1/10)) + (p1 % 10);
  1736. X                p2 = (16 * (p2/10)) + (p2 % 10);
  1737. X            }
  1738. X            else if (*Otemp == 'D')
  1739. X            {
  1740. X                p1 = (p1 - 2 * (p1 % 16));
  1741. X                p2 = (p2 - 2 * (p2 % 16));
  1742. X            }
  1743. X        }
  1744. X        else
  1745. X            putchar (*Otemp);
  1746. X        Otemp++;
  1747. X    }
  1748. X    if (delay != 0)
  1749. X    {
  1750. X        chars = delay * chars_per_millisecond;
  1751. X        delay = chars;
  1752. X        if ((chars - delay) > 0.0)
  1753. X            delay++;
  1754. X        for (; delay > 0; delay--)
  1755. X            putchar(*String_table[pc__]);
  1756. X    }
  1757. X    fflush(stdout);
  1758. X/*#ifndef SYS5
  1759. X    old_arg = fcntl(0, F_GETFL, 0);
  1760. X    value = fcntl(0, F_SETFL, old_arg | FNDELAY);
  1761. X#endif*/
  1762. X}
  1763. X
  1764. X#else
  1765. X
  1766. X    char *Otemp;        /* temporary string pointer to parse output */
  1767. X    float chars;
  1768. X    int p[10];
  1769. X    int variable[27];
  1770. X
  1771. XOperation(Temp_Stack, place)        /* handle conditional operations    */
  1772. Xint Temp_Stack[];
  1773. Xint place;
  1774. X{
  1775. X    int temp;
  1776. X
  1777. X    if (*Otemp == 'd')
  1778. X    {
  1779. X        Otemp++;
  1780. X        temp = Temp_Stack[--place];
  1781. X         printf("%d", temp);
  1782. X    }
  1783. X    else if (!strncmp(Otemp, "2d", 2))
  1784. X    {
  1785. X        temp = Temp_Stack[--place];
  1786. X        printf("%2d", temp);
  1787. X        Otemp++;
  1788. X        Otemp++;
  1789. X    }
  1790. X    else if (!strncmp(Otemp, "3d", 2))
  1791. X    {
  1792. X        temp = Temp_Stack[--place];
  1793. X        printf("%0d", temp);
  1794. X        Otemp++;
  1795. X        Otemp++;
  1796. X    }
  1797. X    else if (!strncmp(Otemp, "02d", 3))
  1798. X    {
  1799. X        temp = Temp_Stack[--place];
  1800. X        printf("%02d", temp);
  1801. X        Otemp++;
  1802. X        Otemp++;
  1803. X        Otemp++;
  1804. X    }
  1805. X    else if (!strncmp(Otemp, "03d", 3))
  1806. X    {
  1807. X        temp = Temp_Stack[--place];
  1808. X        printf("%03d", temp);
  1809. X        Otemp++;
  1810. X        Otemp++;
  1811. X        Otemp++;
  1812. X    }
  1813. X    else if (*Otemp == '+')
  1814. X    {
  1815. X        Otemp++;
  1816. X        temp = Temp_Stack[--place];
  1817. X        temp += Temp_Stack[--place];
  1818. X        Temp_Stack[place++] = temp;
  1819. X    }
  1820. X    else if (*Otemp == '-')
  1821. X    {
  1822. X        Otemp++;
  1823. X        temp = Temp_Stack[--place];
  1824. X        temp -= Temp_Stack[--place];
  1825. X        Temp_Stack[place++] = temp;
  1826. X    }
  1827. X    else if (*Otemp == '*')
  1828. X    {
  1829. X        Otemp++;
  1830. X        temp = Temp_Stack[--place];
  1831. X        temp *= Temp_Stack[--place];
  1832. X        Temp_Stack[place++] = temp;
  1833. X    }
  1834. X    else if (*Otemp == '/')
  1835. X    {
  1836. X        Otemp++;
  1837. X        temp = Temp_Stack[--place];
  1838. X        temp /= Temp_Stack[--place];
  1839. X        Temp_Stack[place++] = temp;
  1840. X    }
  1841. X    else if (*Otemp == 'm')
  1842. X    {
  1843. X        Otemp++;
  1844. X        temp = Temp_Stack[--place];
  1845. X        temp %= Temp_Stack[--place];
  1846. X        Temp_Stack[place++] = temp;
  1847. X    }
  1848. X    else if (*Otemp == '&')
  1849. X    {
  1850. X        Otemp++;
  1851. X        temp = Temp_Stack[--place];
  1852. X        temp &= Temp_Stack[--place];
  1853. X        Temp_Stack[place++] = temp;
  1854. X    }
  1855. X    else if (*Otemp == '|')
  1856. X    {
  1857. X        Otemp++;
  1858. X        temp = Temp_Stack[--place];
  1859. X        temp |= Temp_Stack[--place];
  1860. X        Temp_Stack[place++] = temp;
  1861. X    }
  1862. X    else if (*Otemp == '^')
  1863. X    {
  1864. X        Otemp++;
  1865. X        temp = Temp_Stack[--place];
  1866. X        temp ^= Temp_Stack[--place];
  1867. X        Temp_Stack[place++] = temp;
  1868. X    }
  1869. X    else if (*Otemp == '=')
  1870. X    {
  1871. X        Otemp++;
  1872. X        temp = Temp_Stack[--place];
  1873. X        temp = (temp == Temp_Stack[--place]);
  1874. X        Temp_Stack[place++] = temp;
  1875. X    }
  1876. X    else if (*Otemp == '>')
  1877. X    {
  1878. X        Otemp++;
  1879. X        temp = Temp_Stack[--place];
  1880. X        temp = temp > Temp_Stack[--place];
  1881. X        Temp_Stack[place++] = temp;
  1882. X    }
  1883. X    else if (*Otemp == '<')
  1884. X    {
  1885. X        Otemp++;
  1886. X        temp = Temp_Stack[--place];
  1887. X        temp = temp < Temp_Stack[--place];
  1888. X        Temp_Stack[place++] = temp;
  1889. X    }
  1890. X    else if (*Otemp == 'c')
  1891. X    {
  1892. X        Otemp++;
  1893. X        putchar(Temp_Stack[--place]);
  1894. X    }
  1895. X    else if (*Otemp == 'i')
  1896. X    {
  1897. X        Otemp++;
  1898. X        p[1]++;
  1899. X        p[2]++;
  1900. X    }
  1901. X    else if (*Otemp == '%')
  1902. X    {
  1903. X        putchar(*Otemp);
  1904. X        Otemp++;
  1905. X    }
  1906. X    else if (*Otemp == '!')
  1907. X    {
  1908. X        temp = ! Temp_Stack[--place];
  1909. X        Temp_Stack[place++] = temp;
  1910. X        Otemp++;
  1911. X    }
  1912. X    else if (*Otemp == '~')
  1913. X    {
  1914. X        temp = ~Temp_Stack[--place];
  1915. X        Temp_Stack[place++] = temp;
  1916. X        Otemp++;
  1917. X    }
  1918. X    else if (*Otemp == 'p')
  1919. X    {
  1920. X        Otemp++;
  1921. X        Temp_Stack[place++] = p[*Otemp - '0'];
  1922. X        Otemp++;
  1923. X    }
  1924. X    else if (*Otemp == 'P')
  1925. X    {
  1926. X        Otemp++;
  1927. X        Temp_Stack[place++] = variable[*Otemp - 'a'];
  1928. X        Otemp++;
  1929. X    }
  1930. X    else if (*Otemp == 'g')
  1931. X    {
  1932. X        Otemp++;
  1933. X        variable[*Otemp - 'a'] = Temp_Stack[--place];
  1934. X        Otemp++;
  1935. X    }
  1936. X    else if (*Otemp == '\'')
  1937. X    {
  1938. X        Otemp++;
  1939. X        Temp_Stack[place++] = *Otemp;
  1940. X        Otemp++;
  1941. X        Otemp++;
  1942. X    }
  1943. X    else if (*Otemp == '{')
  1944. X    {
  1945. X        Otemp++;
  1946. X        temp = atoi(Otemp);
  1947. X        Temp_Stack[place++] = temp;
  1948. X        while (*Otemp != '}')
  1949. X            Otemp++;
  1950. X        Otemp++;
  1951. X    }
  1952. X    return(place);
  1953. X}
  1954. X
  1955. XInfo_Out(string, p_list, place)    /* interpret the output string if necessary */
  1956. Xchar *string;
  1957. Xint p_list[];
  1958. Xint place;
  1959. X{
  1960. X    char *tchar;
  1961. X    int delay;
  1962. X    int temp;
  1963. X    int value;
  1964. X    int Cond_FLAG;
  1965. X    int EVAL;
  1966. X    int Cond_Stack[128];
  1967. X    int Cond_place;
  1968. X    int Stack[128];
  1969. X    int Top_of_stack;
  1970. X
  1971. X    if (string == NULL)
  1972. X        return;
  1973. X
  1974. X    Cond_FLAG = FALSE;
  1975. X    Cond_place = 0;
  1976. X    Top_of_stack = 0;
  1977. X    p[0] = 0;
  1978. X    p[1] = 0;
  1979. X    p[2] = 0;
  1980. X    p[3] = 0;
  1981. X    p[4] = 0;
  1982. X    p[5] = 0;
  1983. X    p[6] = 0;
  1984. X    p[7] = 0;
  1985. X    p[8] = 0;
  1986. X    p[9] = 0;
  1987. X    if (p_list != NULL)
  1988. X    {
  1989. X        for (temp = 1; (place != 0); temp++)
  1990. X        {
  1991. X            p[temp] = p_list[--place];
  1992. X        }
  1993. X    }
  1994. X    delay = 0;
  1995. X    Otemp = string;
  1996. X    while (*Otemp != NULL)
  1997. X    {
  1998. X        if (*Otemp == '%')
  1999. X        {
  2000. X            Otemp++;
  2001. X            if ((*Otemp == '?') || (*Otemp == 't') || (*Otemp == 'e') || (*Otemp == ';'))
  2002. X            {
  2003. X                if (*Otemp == '?')
  2004. X                {
  2005. X                    Otemp++;
  2006. X                    Cond_FLAG = TRUE;
  2007. X                    EVAL = TRUE;
  2008. X                    while (EVAL)
  2009. X                    {
  2010. X                        /*
  2011. X                         |  find the end of the 
  2012. X                         |  conditional statement
  2013. X                         */
  2014. X                        while ((strncmp(Otemp, "%t", 2)) && (*Otemp != NULL))
  2015. X                        {
  2016. X                            /*
  2017. X                             |  move past '%'
  2018. X                             */
  2019. X                            Otemp++;
  2020. X                            Cond_place = Operation(Cond_Stack, Cond_place);
  2021. X                        }
  2022. X
  2023. X                        /*
  2024. X                         |  if condition is true
  2025. X                         */
  2026. X                        if ((Cond_place > 0) && (Cond_Stack[Cond_place-1]))
  2027. X                        {
  2028. X                            /*
  2029. X                             |  end conditional 
  2030. X                             |  parsing
  2031. X                             */
  2032. X                            EVAL = FALSE;
  2033. X                            Otemp++;
  2034. X                            Otemp++;
  2035. X                        }
  2036. X                        else    /* condition is false */
  2037. X                        {
  2038. X                            /*
  2039. X                             |  find 'else' or end 
  2040. X                             |  of if statement
  2041. X                             */
  2042. X                            while ((strncmp(Otemp, "%e", 2)) && (strncmp(Otemp, "%;", 2)) && (*Otemp != NULL))
  2043. X                                Otemp++;
  2044. X                            /*
  2045. X                             |  if an 'else' found
  2046. X                             */
  2047. X                            if ((*Otemp != NULL) && (!strncmp(Otemp, "%e", 2)))
  2048. X                            {
  2049. X                                Otemp++;
  2050. X                                Otemp++;
  2051. X                                tchar = Otemp;
  2052. X                                /*
  2053. X                                 |  check for 'then' part
  2054. X                                 */
  2055. X                                while ((*tchar != NULL) && (strncmp(tchar, "%t", 2)) && (strncmp(tchar, "%;", 2)))
  2056. X                                    tchar++;
  2057. X                                /*
  2058. X                                 |  if end of string
  2059. X                                 */
  2060. X                                if (*tchar == NULL)
  2061. X                                {
  2062. X                                    EVAL = FALSE;
  2063. X                                    Cond_FLAG = FALSE;
  2064. X                                    Otemp = tchar;
  2065. X                                }
  2066. X                                /*
  2067. X                                 |  if end of if found,
  2068. X                                 |  set up to parse 
  2069. X                                 |  info
  2070. X                                 */
  2071. X                                else if (!strncmp(tchar, "%;", 2))
  2072. X                                    EVAL = FALSE;
  2073. X                                /*
  2074. X                                 |  otherwise, check 
  2075. X                                 |  conditional in 
  2076. X                                 |  'else'
  2077. X                                 */
  2078. X                            }
  2079. X                            /*
  2080. X                             |  if end of if found,
  2081. X                             |  get out of if 
  2082. X                             |  statement
  2083. X                             */
  2084. X                            else if ((*Otemp != NULL) && (!strncmp(Otemp, "%;", 2)))
  2085. X                            {
  2086. X                                EVAL = FALSE;
  2087. X                                Otemp++;
  2088. X                                Otemp++;
  2089. X                            }
  2090. X                            else /* Otemp == NULL */
  2091. X                            {
  2092. X                                EVAL = FALSE;
  2093. X                                Cond_FLAG = FALSE;
  2094. X                            }
  2095. X                        }
  2096. X                    }
  2097. X                }
  2098. X                else
  2099. X                {
  2100. X                    Otemp++;
  2101. X                    Cond_FLAG = FALSE;
  2102. X                    if (*Otemp != ';')
  2103. X                    {
  2104. X                        while ((*Otemp != NULL) && (strncmp(Otemp, "%;", 2)))
  2105. X                            Otemp++;
  2106. X                        if (*Otemp != NULL)
  2107. X                        {
  2108. X                            Otemp++;
  2109. X                            Otemp++;
  2110. X                        }
  2111. X                    }
  2112. X                    else
  2113. X                        Otemp++;
  2114. X                }
  2115. X            }
  2116. X            else
  2117. X            {
  2118. X                Top_of_stack = Operation(Stack, Top_of_stack);
  2119. X            }
  2120. X        }
  2121. X        else if (!strncmp(Otemp, "$<", 2))
  2122. X        {
  2123. X            Otemp++;
  2124. X            Otemp++;
  2125. X            delay = atoi(Otemp);
  2126. X            while (*Otemp != '>')
  2127. X                Otemp++;
  2128. X            Otemp++;
  2129. X            chars = delay * chars_per_millisecond;
  2130. X            delay = chars;
  2131. X            if ((chars - delay) > 0.0)
  2132. X                delay++;
  2133. X            if (String_table[pc__] == NULL)
  2134. X                temp = 0;
  2135. X            else
  2136. X                temp = *String_table[pc__];
  2137. X            for (; delay > 0; delay--)
  2138. X                putc(temp, stdout);
  2139. X        }
  2140. X        else
  2141. X        {
  2142. X            putchar(*Otemp);
  2143. X            Otemp++;
  2144. X        }
  2145. X    }
  2146. X    fflush(stdout);
  2147. X}
  2148. X#endif
  2149. X
  2150. END_OF_FILE
  2151.   if test 36627 -ne `wc -c <'new_curse.c.A'`; then
  2152.     echo shar: \"'new_curse.c.A'\" unpacked with wrong size!
  2153.   elif test -f 'new_curse.c.B'; then
  2154.     echo shar: Combining  \"'new_curse.c'\" \(73709 characters\)
  2155.     cat 'new_curse.c.A' 'new_curse.c.B' > 'new_curse.c'
  2156.     if test 73709 -ne `wc -c <'new_curse.c'`; then
  2157.       echo shar: \"'new_curse.c'\" combined with wrong size!
  2158.     else
  2159.       rm new_curse.c.A new_curse.c.B
  2160.     fi
  2161.   fi
  2162.   # end of 'new_curse.c.A'
  2163. fi
  2164. echo shar: End of archive 4 \(of 5\).
  2165. cp /dev/null ark4isdone
  2166. MISSING=""
  2167. for I in 1 2 3 4 5 ; do
  2168.     if test ! -f ark${I}isdone ; then
  2169.     MISSING="${MISSING} ${I}"
  2170.     fi
  2171. done
  2172. if test "${MISSING}" = "" ; then
  2173.     echo You have unpacked all 5 archives.
  2174.     rm -f ark[1-9]isdone
  2175. else
  2176.     echo You still must unpack the following archives:
  2177.     echo "        " ${MISSING}
  2178. fi
  2179. exit 0
  2180. exit 0 # Just in case...
  2181.