home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / iface / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-01-30  |  9.0 KB

  1. Subject:  v13i064:  Generic user interface kit, Part02/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Marc Majka <majka@ubc.csnet>
  7. Posting-number: Volume 13, Issue 64
  8. Archive-name: iface/part02
  9.  
  10. Here is a manual for iface, the generic user interface.  The program 
  11. is intended to be hacked by programmers who want to use the it for the 
  12. front end of an application.  The manual focuses on the programming 
  13. aspects of iface.  Those reading the manual are encouraged to have a
  14. copy of the sources on their screens.
  15.  
  16. ---
  17. Marc Majka
  18.  
  19.  
  20. - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - -
  21. : This is a shar archive.  Extract with sh, not csh.
  22. : This archive ends with exit, so do not worry about trailing junk.
  23. echo 'Extracting iface.1'
  24. sed 's/^X//' > iface.1 << '+ END-OF-FILE iface.1'
  25. X.TH IFACE 1
  26. X.SH NAME
  27. Xiface - generic user interface
  28. X.SH SYNOPSIS
  29. X.B iface
  30. X.SH DESCRIPTION
  31. X.I iface
  32. Xis a program shell which is useful as a basis for writing other programs.
  33. XIt provides several user interface features:
  34. X.sp
  35. X.in +4
  36. X\- CBREAK mode (single character) Input / Output
  37. X.br
  38. X\- Keystroke based function invocation
  39. X.br
  40. X\- User definable keybindings
  41. X.br
  42. X\- Input word completion
  43. X.br
  44. X\- Interrupt handling
  45. X.in -4
  46. X.sp
  47. XThis program is in the public domain.  I hope it can be useful to you.
  48. XYou should find that you can add the functions you want for an application
  49. Xprogram without fighting the interface code too much.  Look carefully
  50. Xat the code for 
  51. X.B do-something
  52. Xand 
  53. X.B do-nothing.
  54. XThey are models of application-level functions.  Keep a clean copy of 
  55. X.I iface
  56. Xsomewhere, and modify copies.  If you want clarification on how it works,
  57. Xfeel free to drop me a message.  Please pass the code on to others if you
  58. Xthink it deserves distribution.
  59. X.sp
  60. XMarc Majka
  61. X.in +4
  62. X.br
  63. X<majka%vision.ubc.cdn@relay.cs.net>
  64. X.br
  65. X<majka@ubc-vision.uucp>
  66. X.br
  67. X<majka@vision.ubc.cdn>
  68. X.br
  69. X<majka@ubc.csnet>
  70. X.in -4
  71. X.SH KEYBINDINGS
  72. XWhen 
  73. X.I iface
  74. Xis invoked, it waits for character input from the user. An input character
  75. Xis used as an index in a table, which itself stores an index into a
  76. Xsymbol table.  An entry exists in the symbol table for each function,
  77. Xand includes the function's name and yet another index into a table
  78. Xof pointers to functions.  The appropriate function is invoked.  Keys
  79. Xare associated by default with the function 
  80. X.B BOGUS,
  81. Xwhich rings the terminal bell and does
  82. Xnothing else.  
  83. X.sp
  84. XThree characters are bound to functions which repeat the process of
  85. Xreading an input character and invoking an associated function.  These are 
  86. Xthe ESC (escape) CTL-X (control x) and CTL-Y (control y) characters.  Thus
  87. Xthese characters act as prefix keys, allowing functions to be invoked by
  88. Xa sequence of keystrokes such as (ESC x) or (CTL-X 1).
  89. X.sp
  90. XNew bindings of functions to keys may be accomplished with the 
  91. X.B bind-key
  92. Xcommand.  Keys may be \*(lqunbound\*(rq be binding them to the
  93. X.B BOGUS
  94. Xcommand.  The
  95. X.B describe-key
  96. Xcommand prints the name of the function bound to a key or key sequence.
  97. X.SH "NAME COMPLETION"
  98. XSome functions other than 
  99. X.B BOGUS
  100. Xare associated (bound) with keys.  The
  101. Xkey sequence ESC-x (escape, then x) is bound by default to the function
  102. X.B extended-command.
  103. XThis function prompts the user with a colon, and allows the user to type
  104. Xthe name of a function, which will then be invoked.  A list of all possible
  105. Xinputs is maintained by the program, which allows 
  106. X.B extended-command
  107. Xto help the user.  At any point while the user is entering a word, typing a
  108. Xquestion mark (?) will cause a list of all possible words which match the
  109. Xinput so far to be printed, along with a little help message explaining the
  110. Xinput word completion mechanism.  Typing a space will cause the current word 
  111. Xto be expanded (completed) as much as possible. 
  112. X.sp
  113. XFor example, typing
  114. X.sp
  115. X.in +4
  116. XESC-x
  117. X.br
  118. Xdes<space>
  119. X.sp
  120. X.in -4
  121. Xwould result in the input being expanded to
  122. X.sp
  123. X.in +4
  124. Xdescribe-
  125. X.sp
  126. X.in -4
  127. XTyping ? at this point would result in the message:
  128. X.sp
  129. X.in +4
  130. X.sp
  131. X? choose one of the following
  132. X.sp
  133. Xdescribe-bindings  describe-key
  134. X.sp
  135. X? ? for command list
  136. X.br
  137. X? ^D, ^G or ESC to exit, ^U to clear
  138. X.br
  139. X? <space>, <tab> or <return> to complete
  140. X.br
  141. X? <linefeed> to insist on first choice
  142. X.br
  143. X.sp
  144. X: describe-
  145. X.sp
  146. X.in -4
  147. XTyping b<space> would cause the input to be completed to
  148. X.sp
  149. X.in +4
  150. X: describe-bindings
  151. X.in -4
  152. X.sp
  153. Xand the
  154. X.B describe-bindings
  155. Xfunction would be invoked.  Try this to get a list of default bindings.
  156. X.SH "NAME COMPLETION - INTERNALS"
  157. XThe name completion routine 
  158. X.I getcom
  159. X(get command) takes a list of
  160. Xwords, the number of words in the list, and a prompt string as arguments.
  161. XIt picks up characters and appends them to a string.  Special characters,
  162. Xsuch as a space, are dealt with individually.  Space, tab and return character
  163. s
  164. Xcause getcom to call a matching routine.  The matching routine works by
  165. Xmoving a pair of pointers together from the ends of the list.  One
  166. Xpointer points at the first possible match for the input string, one for the
  167. Xlast possible match.  If these pointers meet, then only one word matches the
  168. Xuser's input.  The word can be \*(lqcompleted\*(rq by the routine appending
  169. Xthe tail end of the string for the user.  If the pointers do not meet, it
  170. Xstill may be the case that all the words between them contain one or more
  171. Xcommon characters following the given string.  The user's word is appended
  172. Xwith these common characters.  Be careful about modifying the code in the
  173. X.I try_match
  174. Xroutine - it is a bit tricky.
  175. X.SH "ADDING FUNCTIONS"
  176. XTwo sample functions are included in the distribution version of
  177. X.I iface.
  178. XThese are 
  179. X.B do-something
  180. Xand 
  181. X.B do-nothing.
  182. XIt is instructive to look through the sources to see how these functions
  183. Xwork as part of 
  184. X.I iface.
  185. X.sp
  186. XThe function 
  187. X.B do-nothing,
  188. Xfor example, is defined in the file fns.c.  The definition is:
  189. X.sp
  190. X.in +4
  191. Xdo_nothing() {printf(\*(lqDone!\\n\*(rq);}
  192. X.in -4
  193. X.sp
  194. XThe function is tied into the interface in the file init.c.  In the
  195. Xroutine 
  196. X.I init_symbols,
  197. Xthere is the call:
  198. X.sp
  199. X.in +4
  200. Xaddcom(\*(lqdo-nothing\*(rq);
  201. X.in -4
  202. X.sp
  203. XThis adds the string \*(lqdo-nothing\*(rq to the list of commands used by the
  204. Xword completion routine, and it creates a symbol table entry for the
  205. Xcommand.  (Note that the names must be sorted in the word list for
  206. Xthe completion routine.  This version insists that the names be added
  207. Xin sorted order.  Writing an insertion sort is left as an exercise for
  208. Xthe programmer who wishes it otherwise.)  The addcom routine also
  209. Xputs a pointer to the 
  210. X.I do_nothing 
  211. Xroutine in a table, and stores its index in the symbol table.
  212. X.sp
  213. XThe 
  214. X.I command_ptr
  215. Xroutine links names with pointers to functions.  The 
  216. X.I do_nothing
  217. Xroutine is declared:
  218. X.sp
  219. X.in +4
  220. Xint do_nothing();
  221. X.in -4
  222. X.sp
  223. XThe pointer value is returned in the test:
  224. X.sp
  225. X.in +4
  226. Xif (!strcmp(str,\*(lqdo-nothing\*(rq)) return(do_nothing);
  227. X.in -4
  228. X.sp
  229. XAlthough there are faster ways to do the name - pointer linking, this
  230. Xroutine is only called once for each function at startup time, and this
  231. Xscheme is easy and flexible.
  232. X.sp
  233. XThe
  234. X.B do-nothing
  235. Xcommand is bound to the \*(lqn\*(rq key in the 
  236. X.I init_bindings
  237. Xroutine:
  238. X.sp
  239. X.in +4
  240. Xbinding['n'][0] = sym_ref(\*(lqdo-nothing\*(rq);
  241. X.in -4
  242. X.SH "SYMBOL TABLE"
  243. XThe symbol table contains names and values.  As already mentioned, function
  244. Xnames are stored there, along with an index into a table of function pointers.
  245. XThe symbol table may also contain other information which may be useful to
  246. Xthe application.  In the distribution, two \*(lqvariables\*(rq have been
  247. Xadded to the symbol table. These are initialized in the 
  248. X.I init_variables
  249. Xroutine:
  250. X.sp
  251. X.in +4
  252. Xaddvar(\*(lqdummy\*(rq,\*(lq\*(rq,0);
  253. X.br
  254. Xaddvar(\*(lqversion\*(rq,\*(lq0.0\*(rq,0);
  255. X.in -4
  256. X.sp
  257. XVariables have a name, a string value, and an integer value.  Objects
  258. Xin the symbol table may be found by name using the 
  259. X.I sym_ref
  260. Xroutine.
  261. XFor example, the 
  262. X.I print_version
  263. Xfunction prints the string value stored
  264. Xunder the \*(lqversion\*(rq variable using the code:
  265. X.sp
  266. X.in +4
  267. Xref = sym_ref(\*(lqversion\*(rq);
  268. X.br
  269. Xprintf(\*(lqversion %s\\n\*(rq,symbol[ref].strval);
  270. X.in -4
  271. X.sp
  272. XThe contents of the symbol table may be examined with
  273. X.B dump-symbol-table.
  274. X.SH INTERRUPTS
  275. X.I iface
  276. Xcatches interrupt and hangup signals in the sigtrap routine. Interrupts
  277. Xcause execution to jump back to the top level loop in the 
  278. X.I user_level
  279. Xroutine.
  280. XNote that one could easily add a 
  281. X.B user-level
  282. Xcommand, thereby making the
  283. Xinterface recursive.
  284. X.SH "CBREAK I/O"
  285. XThis is the only place where 
  286. X.I iface
  287. Xreally is hooked to UNIX.  The terminal is placed in CBREAK mode
  288. Xwith the ioctl calls in newterm, and restored to its initial mode
  289. Xin oldterm, both in exec.c.  Since 
  290. X.I iface
  291. Xdoes its own I/O with 
  292. X.I get_string
  293. Xand
  294. X.I put_char
  295. Xin io.c, character echo is turned off.
  296. X.SH AUTHOR
  297. XMarc Majka
  298. + END-OF-FILE iface.1
  299. chmod 'u=rw,g=r,o=r' 'iface.1'
  300. echo '    -rw-r--r--  1 majka        7952 Nov  4 13:08 iface.1        (as sent)'
  301. echo -n '    '
  302. /bin/ls -l iface.1
  303. exit 0
  304.