home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 115_01 / config1.c < prev    next >
Text File  |  1979-12-31  |  15KB  |  739 lines

  1. /* Screen editor:  configuration program
  2.  *
  3.  * Source:  config1.c
  4.  * Version: June 4, 1981.
  5.  */
  6.  
  7. /* Values of control keys go here */
  8.  
  9. int up;            /* value of cursor up key */
  10. int down;        /* cursor down key */
  11. int left;        /* cursor left key */
  12. int right;        /* cursor right key */
  13. int ins;        /* enter insert mode key */
  14. int del;        /* delete character key */
  15. int esc;        /* leave current mode key */
  16. int abt;        /* undo editing key */
  17. int altup;        /* alternate up key */
  18. int altdn;        /* alternate down key */
  19. int delline;        /* delete line key */
  20. int govid;        /* enter video mode key */
  21.  
  22. /* Video screen  and printer characteristics go here */
  23.  
  24. int scrnl;        /* number of rows on screen */
  25. int scrnw;        /* # of columns on screen */
  26. int haseol;        /* has erase to end of line */
  27. int hasel;        /* has erase line */
  28. int hassup;        /* has hardware scroll up */
  29. int hassdn;        /* has hardware scroll down */
  30. int lwidth;        /* width of list device */
  31.  
  32. /* Define array which contains the code that the
  33.  * user gives to do special screen functions.
  34.  */
  35.  
  36. #define BYTEMAX    1000    /* size of byte array */
  37. char bytes[BYTEMAX];
  38. int bytec;        /* index of next free entry */
  39.  
  40. /* Define indices into bytes[] which point at start
  41.  * of code for each special screen function.
  42.  */
  43.  
  44. int gotoind;        /* index to gotoxy code */
  45. int eolind;        /* erase to end of line */
  46. int elind;        /* erase line */
  47. int supind;        /* scroll up */
  48. int sdnind;        /* scroll down */
  49.  
  50. /* Define return codes */
  51.  
  52. #define    YES    1    /* all ok */
  53. #define NO    2    /* try again */
  54. #define EXIT    3    /* stop the program */
  55.  
  56. /* Define special characters */
  57.  
  58. #define CR    13    /* carriage return */
  59. #define LF    10    /* line feed */
  60. #define    TAB    9    /* tab */
  61.  
  62. /* define output file index */
  63.  
  64. int    output;
  65.  
  66. /* This program has 5 parts.
  67.  *
  68.  * Part 1 asks which keys do which special functions.
  69.  * Part 2 asks which special functions the screen has.
  70.  * Part 3 asks what code sequences must be output
  71.  *        to the screen to do the functions in part 2.
  72.  * Part 4 creates the file ed1.ccc from the answers to
  73.  *        Part 1.
  74.  * Part 5 creates the file ed6.ccc from the answers to
  75.  *        Parts 2 and 3.
  76.  */
  77.  
  78. main()
  79. {
  80.     /* initialize byte count */
  81.     bytec=0;
  82.     /* sign on and give general information */
  83.     signon();
  84.     /* get keyboard information */
  85.     while (part1()==NO) {
  86.         ;
  87.     }
  88.     /* get screen features */
  89.     while (part2()==NO) {
  90.         ;
  91.     }
  92.     /* get control sequences for screen features */
  93.     while (part3()==NO) {
  94.         ;
  95.     }
  96.     /* make sure we want to continue */
  97.     blank();
  98.     plc("You are now ready to create files ");
  99.     pc("ed1.ccc and ed6.ccc.");
  100.     plc("Do you want to proceed ?");
  101.     if (yesno()==NO) {
  102.         return;
  103.     }
  104.     /* write keyboard info to file ed1.ccc */
  105.     if (part4()!=YES) {
  106.         return;
  107.     }
  108.     /* write control sequences for screen features
  109.      * to file ed6.ccc
  110.      */
  111.     part5();
  112.     /* sign off and tell about compiling */
  113.     signoff();
  114. }
  115.  
  116. /* sign on and tell how to abort */
  117.  
  118. signon()
  119. {
  120. plc("Welcome to the configuration program for the ");
  121. pc("screen editor.");
  122. plc("Hit control-c to exit this program early.");
  123. plc("Hit control-p to send output to the printer.");
  124. }
  125.  
  126. /* part 1.  find out what keys will be used for
  127.  *          special functions.
  128.  */
  129.  
  130. part1()
  131. {
  132.  
  133. blank();
  134. plc("This section deals with your keyboard.");
  135. plc("For each function key, enter the DECIMAL ");
  136. pc("value of the ascii ");
  137. plc("code that you want to assign to that function key.");
  138. plc("Hit carriage return to indicate the default value.");
  139.  
  140. blank();
  141. plc("up key:");
  142. indent();
  143. pc("This key usually moves the cursor up.  In insert mode");
  144. indent();
  145. pc("this key inserts a line above the current line.");
  146. indent();
  147. pc("The default is line feed (10).");
  148. up=getval(10);
  149.  
  150. plc("down key:");
  151. indent();
  152. pc("This key usually moves the cursor down.  In insert mode");
  153. indent();
  154. pc("this key inserts a line below the current line.");
  155. indent();
  156. pc("The default is carriage return (13).");
  157. down=getval(13);
  158.  
  159. plc("alternate up key:");
  160. indent();
  161. pc("This key usually inserts a line above the current line.");
  162. indent();
  163. pc("In insert mode it just moves the cursor up");
  164. indent();
  165. pc("The default is control-u (21).");
  166. altup=getval(21);
  167.  
  168. plc("alternate down key:");
  169. indent();
  170. pc("This key usually inserts a line below the current line.");
  171. indent();
  172. pc("In insert mode it just moves the cursor down");
  173. indent();
  174. pc("The default is control-d (4).");
  175. altdn=getval(4);
  176.  
  177. plc("left key:");
  178. indent();
  179. pc("This key moves the cursor left ");
  180. pc("in all edit modes.");
  181. indent();
  182. pc("The default is back space (8).");
  183. left=getval(8);
  184.  
  185. plc("right key:");
  186. indent();
  187. pc("This key moves the cursor right ");
  188. pc("in all edit modes.");
  189. indent();
  190. pc("The default is control-r (18).");
  191. right=getval(18);
  192.  
  193. plc("insert key:");
  194. indent();
  195. pc("This key enters insert mode.");
  196. indent();
  197. pc("The default is control-n (14).");
  198. ins=getval(14);
  199.  
  200. plc("video key:");
  201. indent();
  202. pc("This key enters video mode.");
  203. indent();
  204. pc("The default is control-v (22).");
  205. govid=getval(22);
  206.  
  207. plc("exit current mode key:");
  208. indent();
  209. pc("This key exits the current mode.");
  210. indent();
  211. pc("The default is esc (27).");
  212. esc=getval(27);
  213.  
  214. plc("delete character key:");
  215. indent();
  216. pc("This key deletes the character to the left ");
  217. pc("of the cursor.");
  218. indent();
  219. pc("The default is del (127).");
  220. del=getval(127);
  221.  
  222. plc("delete line key:");
  223. indent();
  224. pc("This key deletes the line on which the cursor rests.");
  225. indent();
  226. pc("The default is control-z (26).");
  227. delline=getval(26);
  228.  
  229. plc("abort key:");
  230. indent();
  231. pc("This key undoes the editing done on a line.");
  232. indent();
  233. pc("The default is control-x (24).");
  234. abt=getval(24);
  235.  
  236. /* recap what the user has typed.
  237.  * ask if everything is all right.
  238.  */
  239.  
  240. plc("The values of the keyboard keys are:");
  241. plc("up:           ");
  242. putdec(up,3);
  243. plc("down:         ");
  244. putdec(down,3);
  245. plc("alternate up: ");
  246. putdec(altup,3);
  247. plc("alt down:     ");
  248. putdec(altdn,3);
  249. plc("left:         ");
  250. putdec(left,3);
  251. plc("right:        ");
  252. putdec(right,3);
  253. plc("insert move:  ");
  254. putdec(ins,3);
  255. plc("video mode:   ");
  256. putdec(govid,3);
  257. plc("exit mode:    ");
  258. putdec(esc,3);
  259. plc("delete char:  ");
  260. putdec(del,3);
  261. plc("delete line:  ");
  262. putdec(delline,3);
  263. plc("abort:        ");
  264. putdec(abt,3);
  265.  
  266. blank();
  267. plc("are all values correct ?");
  268. return(yesno());
  269. }
  270.  
  271. /* get features of the video screen */
  272.  
  273. part2()
  274. {
  275.  
  276. blank();
  277. plc("This section deals with the video screen.");
  278. plc("The screen MUST have a cursor positioning function,");
  279. plc("but no other special screen functions are required.");
  280.  
  281. blank();
  282. plc("screen length:");
  283. indent();
  284. pc("How many rows does your screen have ?");
  285. indent();
  286. pc("The default is 16.");
  287. scrnl=getval(16);
  288.  
  289. blank();
  290. plc("screen width:");
  291. indent();
  292. pc("How many columns does your screen have ?");
  293. indent();
  294. pc("The default is 64.");
  295. scrnw=getval(64);
  296.  
  297. blank();
  298. plc("printer width:");
  299. indent();
  300. pc("How many columns does your printer have ?");
  301. indent();
  302. pc("The default is 132.");
  303. lwidth=getval(132);
  304.  
  305. blank();
  306. plc("erase line:");
  307. indent();
  308. pc("Does your screen have a function which erases ");
  309. indent();
  310. pc("the line on which the cursor rests ?");
  311. hasel=yesno();
  312.  
  313. plc("erase to end of line:");
  314. indent();
  315. pc("Does your screen have a function which erases ");
  316. indent();
  317. pc("from the cursor to the end of the line ?");
  318. haseol=yesno();
  319.  
  320. plc("hardware scroll up: (line feed)");
  321. indent();
  322. pc("Does your screen have a function that scrolls the");
  323. indent();
  324. pc("screen up when the cursor is on the bottom line ?");
  325. hassup=yesno();
  326.  
  327. plc("hardware scroll down:");
  328. indent();
  329. pc("Does your screen have a function which scrolls the");
  330. indent();
  331. pc("screen down when the cursor is on the top line ?");
  332. hassdn=yesno();
  333.  
  334. blank();
  335. plc("You have answered as follows: ");
  336. plc("screen length:            ");
  337. putdec(scrnl,1);
  338. plc("screen width:             ");
  339. putdec(scrnw,1);
  340. plc("printer width:            ");
  341. putdec(lwidth,1);
  342. plc("erase line ?              ");
  343. putyesno(hasel);
  344. plc("erase to end of line ?    ");
  345. putyesno(haseol);
  346. plc("hardware scroll up ?