home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 199_01 / ged11.c < prev    next >
Text File  |  1987-12-17  |  12KB  |  403 lines

  1. /*
  2. Header:          CUG199;
  3. Title:           Terminal specific module for ged editor;
  4. Last Updated:    12/01/87;
  5.  
  6. Description:    "PURPOSE: terminal dependent screen control functions.
  7.                  Uses DeSmet's PCIO.A screen code w/additions"
  8.  
  9. Keywords:        e, editor, qed, ged, DeSmet, MSDOS;
  10. Filename:        ged11.c;
  11. Warnings:       "O file must be present during link for ged";
  12.  
  13. Authors:         G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
  14. Compilers:       DeSmet 3.0;
  15.  
  16. References:
  17. Endref;
  18. */
  19.  
  20. /*
  21. e/qed/ged screen editor
  22.  
  23. (C) G. Nigel Gilbert, MICROLOGY, 1981 - August-December 1981
  24.  
  25. Modified:   Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  26.             March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  27.  
  28.             May       1986:  qed converted to ged         (Mel Tearle)
  29.             August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  30.  
  31. File:       ged11.c
  32.  
  33. Functions:  delpage,
  34.             norm, high, keytranslate, displayhelp
  35.  
  36. Note:       This file is very specific to IBM-PC like hardware.
  37.             Mostly interrupt routines for time, pathnames, keyboard
  38.             definitions, and help screen.
  39. */
  40.  
  41. #ifndef  TC
  42. #include "ged.h"
  43. #else
  44. #include "ged.t"
  45. #endif
  46.  
  47.  
  48. /* control key codes, here for convenience in defining terminal sequences
  49.  */
  50. #define CTRLA   0x01    /*  SOH */
  51. #define CTRLB   0x02    /*  STX */
  52. #define CTRLC   0x03    /*  ETX */
  53. #define CTRLD   0x04    /*  EOT */
  54. #define CTRLE   0x05    /*  ENQ */
  55. #define CTRLF   0x06    /*  ACK */
  56. #define CTRLG   0x07    /*  BEL */
  57. #define CTRLH   0x08    /*  BS  */
  58. #define CTRLI   0x09    /*  HT  */
  59. #define CTRLJ   0x0a    /*  LF  */
  60. #define CTRLK   0x0b    /*  VT  */
  61. #define CTRLL   0x0c    /*  FF  */
  62. #define CTRLM   0x0d    /*  CR  */
  63. #define CTRLN   0x0e    /*  SO  */
  64. #define CTRLO   0x0f    /*  SI  */
  65. #define CTRLP   0x10    /*  DLE */
  66. #define CTRLQ   0x11    /*  DC1 */
  67. #define CTRLR   0x12    /*  DC2 */
  68. #define CTRLS   0x13    /*  DC3 */
  69. #define CTRLT   0x14    /*  DC4 */
  70. #define CTRLU   0x15    /*  NAK */
  71. #define CTRLV   0x16    /*  SYN */
  72. #define CTRLW   0x17    /*  ETB */
  73. #define CTRLX   0x18    /*  CAN */
  74. #define CTRLY   0x19    /*  EM  */
  75. #define CTRLZ   0x1a    /*  SUB */
  76.  
  77.  
  78. /* defines the terminal key codes
  79.  * which perform the editor commands
  80.  */
  81. void keytranslate()
  82. {
  83. /* each tran[xxxx]= should be set to the code emitted by the terminal
  84. key which will perform the indicated action.  The recommended (control)
  85. key assignments are shown in round brackets.
  86.     Some terminals precede their codes by a lead-in character
  87. (eg the Hazeltine uses the tilde).  This char should be assigned to
  88. tran[LEADIN].  If there is no lead-in character, set tran[LEADIN] to zero.
  89.     'e' will ignore the leadin character if tran[LEADIN] is non-zero,
  90. but will set the parity bit on the next character. All other chars from the
  91. keyboard will already have any parity bits removed as they are read in.  Thus
  92. codes with lead-ins should be entered in the table below as code+0x80, or
  93. more clearly, as code+PARBIT.
  94.     For example, suppose that one is coding the Hazeltine 1420, which
  95. generates a tilde,^L (0x0d) sequence when the cursor up key is pressd.  To
  96. recognise this sequence, set tran[LEADIN] to tilde (0x7e) and set
  97. tran[UPKEY] to 0x0d+PARBIT.
  98. */
  99.     tran[LEADIN]    = 0;       /*  0 lead-in character, 0 if not used */
  100.     tran[DOWNKEY]   = CTRLX;   /*  1 cursor down */
  101.     tran[UPKEY]     = CTRLE;   /*  2 cursor up */
  102.     tran[LEFTKEY]   = CTRLS;   /*  3 cursor left */
  103.     tran[RIGHTKEY]  = CTRLD;   /*  4 cursor right */
  104.     tran[RIGHTWKEY] = CTRLF;   /*  5 cursor right one word (F) */
  105.     tran[LEFTWKEY]  = CTRLA;   /*  6 cursor left one word (A) */
  106.     tran[EOLKEY]    = CTRLP;   /*  7 cursor to end of line (P) */
  107.     tran[BOLKEY]    = CTRLO;   /*  8 cursor to beginning of line (P) */
  108.     tran[UPPAGE]    = CTRLR;   /*  9 scroll up a page (R) */
  109.     tran[DOWNPAGE]  = CTRLC;   /* 10 scroll down a page (C) */
  110.     tran[BOFKEY]    = CTRLU;   /* 11 cursor to beginning of file (U) */
  111.     tran[HOMEKEY]   = CTRLB;   /* 12 cursor to end of file (B) */
  112.     tran[DELLEFT]   = 0x7f;    /* 13 delete char to left of cursor (DEL) */
  113.     tran[DELRIGHT]  = CTRLG;   /* 14 delete char under cursor (G) */
  114.     tran[DELLNKEY]  = 0x1C;    /* 15 delete cursor line (^\) */
  115.     tran[DELWDKEY]  = CTRLT;   /* 16 delete word to right of cursor (T) */
  116.     tran[JUMPKEY]   = CTRLJ;   /* 17 jump to (J) */
  117.     tran[CRSTILL]   = CTRLN;   /* 18 insert newline after cursor (N) */
  118.     tran[QWIKKEY]   = CTRLQ;   /* 19 quit (Q) */
  119.     tran[SCRLUPKEY] = CTRLW;   /* 20 scroll up thru text (W) */
  120.     tran[TOPSCRKEY] = CTRLY;   /* 21 top of screen (Y) */
  121.     tran[BOTSCRKEY] = CTRLV;   /* 22 bottom of screen (V) */
  122.     tran[BLOCKKEY]  = CTRLK;   /* 23 block operations (K) */
  123.     tran[SCRLDNKEY] = CTRLZ;   /* 24 scroll down thru text (Z) */
  124.     tran[REPKEY]    = CTRLL;   /* 25 repeat last find/alter (L) */
  125.     tran[HELPKEY]   = 0x1e;    /* 26 display help menu (^^) */
  126.     tran[OOPSKEY]   = 0x1f;    /* 27 restore unedited line (^_) */
  127.     tran[TAB]       = CTRLI;   /* 28 tab (I) */
  128.     tran[RETRIEVE]  = CTRLL;   /* 29 retrieve (L) */
  129.     tran[CR]        = 0x0d;    /* 30 return */
  130.     tran[ESCKEY]    = 0x1b;    /* 31 escape, the magic key (ESC) */
  131. }
  132.  
  133.  
  134. /* interrupt routines follow */
  135.  
  136. #ifndef DS
  137.  
  138. union   REGS   r;
  139. struct  SREGS  seg;
  140.  
  141. /* get current cursor position
  142.  */
  143. int getcursor()
  144. {
  145. r.x.ax = 0x0300;
  146. r.x.bx = 0 << 8;
  147. int86( 0x10, &r, &r );
  148. return ( r.h.dl );
  149. }
  150.  
  151.  
  152. void curdrv(drv)
  153. char drv[];
  154. {
  155. r.x.ax = 0x1900;               /* DOS interrupt 19 */
  156. intdos( &r, &r );              /* gets current drive number */
  157.  
  158. drv[0] = ( char ) ( r.x.ax + 'a');  /* convert to symbolic drive name */
  159. drv[1] = ':';
  160. drv[2] = '\0';
  161. }
  162.  
  163.  
  164. /* getpath - get path to directory on default drive
  165.  */
  166. void getpath(path)
  167. char path[];
  168. {
  169. strcat( path, "\\" );
  170.  
  171. r.x.ax = 0x4700;             /*   DOS interrupt 47 gets path string  */
  172. r.x.dx = path[0] - '`';      /*   convert to index */
  173. r.x.si = (unsigned)&path[3];
  174. intdos( &r, &r );
  175. }
  176.  
  177.  
  178. /* this function originally used sprintf to format timestr, however
  179.  * that added 4K of overhead to ged and was only used by this routine
  180.  */
  181. void xgettime()
  182. {
  183. unsigned  hour, min;
  184. char str[4];
  185.  
  186. r.x.ax = 0x2C00;
  187. intdos( &r, &r );
  188.  
  189. min  = r.x.cx  &  0x00ff;
  190. hour = r.x.cx  >>  8;
  191.  
  192. zf_time( hour, str );   strcpy( timestr, str );   strcat( timestr, ":" );
  193. zf_time( min, str );    strcat( timestr, str );
  194. }
  195.  
  196.  
  197. /* get status of parallel printer port - is the printer turned on?
  198.  * report if error
  199.  */
  200. int prnstat()
  201. {
  202. r.x.ax = ( 0x02 << 8 );
  203. r.x.dx = 0;                /* 0 = prn */
  204. intdos( &r, &r );
  205.  
  206. if ( ( ( r.x.ax >> 8 ) & 0x80 ) ||
  207.      ( ( r.x.ax >> 8 ) & 0x40 ) ||
  208.      ( ( r.x.ax >> 8 ) & 0x10 ) )
  209.       return( 1 );
  210. else  {
  211.      scr_co( '\07' );
  212.      error( "error on printer " );
  213.      return( 0 );
  214.   }
  215. }
  216.  
  217. #else
  218.  
  219. /* DeSmet C variables for 8086 registers and flags
  220.  */
  221. unsigned  _rax, _rbx, _rcx, _rdx, _rsi, _rdi, _res, _rds;
  222.     char  _carryf, _zerof;
  223.  
  224.  
  225. /* get current cursor position
  226.  */
  227. int getcursor()
  228. {
  229. _rax = 0x0300;
  230. _rbx = 0 << 8;
  231. _doint( 0x10 );
  232. return ( _rdx & 0xff );
  233. }
  234.  
  235.  
  236. /* curdrv - get current default drive
  237.  * from ed nather's ls.c
  238.  */
  239. void curdrv(drv)
  240. char *drv;
  241. {
  242. int i;
  243.  
  244. i = _os( 0x19, 0 );       /* gets current drive number */
  245.  
  246. *drv++ = i + 'a';         /* convert to symbolic drive name */
  247. *drv++ = ':';
  248. return;
  249. }
  250.  
  251.  
  252. /* get path to directory on indicated drive
  253.  * from ed nather's ls.c
  254.  */
  255. void getpath(path)
  256. char *path;
  257. {
  258. extern int _showds();
  259.  
  260. strcat( path, "\\" );     /* append root file symbol to drive name */
  261.  
  262. _rax = 0x4700;            /* DOS interrupt 47 gets path string */
  263. _rdx = *path - '`';       /* convert drive name to index */
  264. _rsi = path + 3;          /* paste string after root symbol */
  265. _rds = _showds();
  266. _doint( DOSINT );
  267. return;
  268. }
  269.  
  270.  
  271. /* this function originally used sprintf to format timestr, however
  272.  * that added 4K of overhead to ged and was only used by this routine
  273.  */
  274. char xgettime()
  275. {
  276. unsigned  hour, min;
  277. char str[4];
  278.  
  279. _rax = 0x2C00;
  280. _doint( DOSINT );
  281.  
  282. min  = _rcx  &  0x00ff;
  283. hour = _rcx  >>  8;
  284.  
  285. zf_time( hour, str );   strcpy( timestr, str );   strcat( timestr, ":" );
  286. zf_time( min, str );    strcat( timestr, str );
  287. }
  288.  
  289.  
  290. /* get status of parallel printer port - is the printer turned on?
  291.  * report if error
  292.  */
  293. int prnstat()
  294. {
  295. _rax = ( 0x02 << 8 );
  296. _rdx = 0;                /* 0 = prn */
  297. _doint( 0x017 );
  298.  
  299. if ( ( ( _rax >> 8 ) & 0x80 ) ||
  300.      ( ( _rax >> 8 ) & 0x40 ) ||
  301.      ( ( _rax >> 8 ) & 0x10 ) )
  302.       return( 1 );
  303. else  {
  304.      scr_co( '\07' );
  305.      error( "error on printer " );
  306.      return( 0 );
  307.   }
  308. }
  309.  
  310. #endif
  311.  
  312.  
  313. /* convert time to a 2 character zerofilled string
  314.  * borrowed from Richard Threlkeld's itoa.c
  315.  * uses strrev - DeSmet 3.0
  316.  */
  317. void zf_time(n,s)
  318. int   n;
  319. char s[];
  320. {
  321. int i = 0;
  322.  
  323. do  {
  324.    s[i++] = ( char )( n % 10 + '0');
  325. }  while ( ( n /= 10 ) > 0 );
  326.  
  327. while( i < 2 )  s[i++] = '0';
  328. s[i] = '\0';
  329. strrev(s);
  330. }
  331.  
  332.  
  333. /* the following code may do strange things if printed
  334.  */
  335.  
  336. /* display the help menu
  337.  * must be (helplines-1) lines of menu here
  338.  */
  339. void display_help()
  340. {
  341. scr_putstr( 0, 1,
  342. "╔═ Help 1 of 1 ═╤════════════════╤═════════════════╤══════════════╤════════════╗", RSFW );
  343. scr_putstr( 0, 2,
  344. "║Quit/Query  ^KQ│Char left ^S,^H │Line left ^O,Home│Top of File ^U│Scroll Up ^W║", RSFW );
  345. scr_putstr( 0, 3,
  346. "║Quit/Exit   ^KX│Char rght ^D    │Line rght ^P,End │End of File ^B│Scroll Dn ^Z║", RSFW );
  347. scr_putstr( 0, 4,
  348. "║Read a File ^KR│Char delt ^G,Del│Line delt ^\\     │Delete EOL ^QY│Page Up   ^R║", RSFW );
  349. scr_putstr( 0, 5,
  350. "║Block Mark  ^KB│Word left ^A,F3 │Cursor up    ^E  │Find       ^QF│Page Down ^C║", RSFW );
  351. scr_putstr( 0, 6,
  352. "║  (Options)    │Word rght ^F,F4 │Cursor down  ^X  │Replace    ^QA│Screen Up ^Y║", RSFW );
  353. scr_putstr( 0, 7,
  354. "║Undelete    ^_ │Word delt ^T    │Jump to Line ^J  │Repeat Cmd  ^L│Screen Dn ^V║", RSFW );
  355. scr_putstr( 0, 8,
  356. "╚════════════════════════════════╧═════════════════╧═════════ Esc to Restore ══╝", RSFW );
  357. }
  358.  
  359.  
  360. void display_table1()
  361. {
  362. scr_putstr( 0, 1,
  363. "╔═ Graphics 1 of 2 ═╤══════════════════════════════════════╤═══════════════════╗", RSFW );
  364. scr_putstr( 0, 2,
  365. "║ 218 ┌ 194 ┬ 191 ┐ │ 213 ╒ 209 ╤ 184 ╕  214 ╓ 210 ╥ 183 ╖ │ 201 ╔ 203 ╦ 187 ╗ ║", RSFW );
  366. scr_putstr( 0, 3,
  367. "║ 195 ├ 197 ┼ 180 ┤ │ 198 ╞ 216 ╪ 181 ╡  199 ╟ 215 ╫ 182 ╢ │ 204 ╠ 206 ╬ 185 ╣ ║", RSFW );
  368. scr_putstr( 0, 4,
  369. "║ 192 └ 193 ┴ 217 ┘ │ 212 ╘ 207 ╧ 190 ╛  211 ╙ 208 ╨ 189 ╜ │ 200 ╚ 202 ╩ 188 ╝ ║", RSFW );
  370. scr_putstr( 0, 5,
  371. "║ 176 ░ 177 ▒ 178 ▓ │ 179 │ 196 ─ 186 ║  205 ═ 220 ▄ 223 ▀ │ 219 █ 221 ▌ 222 ▐ ║", RSFW );
  372. scr_putstr( 0, 6,
  373. "╟───────────────────┴──────────────────────────────────────┴───────────────────╢", RSFW );
  374. scr_putstr( 0, 7,
  375. "║Enter Alt and Character's Decimal Value Using Numeric Keypad.  ^L Repeat Key. ║", RSFW );
  376. scr_putstr( 0, 8,
  377. "╚════════════════════════════════════════════════════════════ Esc to Restore ══╝", RSFW );
  378. }
  379.  
  380.  
  381. void display_table2()
  382. {
  383. scr_putstr( 0, 1,
  384. "╔═ Graphics 2 of 2 ═╤══════════════════════════════════════╤═══════════════════╗", RSFW );
  385. scr_putstr( 0, 2,
  386. "║  01   02   03  │  04   05   06    07   08   09 na│  10 na 11    12   ║", RSFW );
  387. scr_putstr( 0, 3,
  388. "║  13   14   15  │  16   17   18    19   20   21  │  22   23   24  ║", RSFW );
  389. scr_putstr( 0, 4,
  390. "║  25   26 na 27  │        28   29    30   31        │ 155 ¢ 156 £ 157 ¥ ║", RSFW );
  391. scr_putstr( 0, 5,
  392. "║ 171 ½ 172 ¼ 173 ¡ │ 174 « 175 » 224 α  225 ß 226 Γ 227 π │ 228 Σ 229 σ 230 µ ║", RSFW );
  393. scr_putstr( 0, 6,
  394. "║ 231 τ 232 Φ 233 Θ │ 234 Ω 235 δ 236 ∞  237 φ 238 ε 239 ∩ │ 240 ≡ 241 ± 242 ≥ ║", RSFW );
  395. scr_putstr( 0, 7,
  396. "║ 243 ≤ 244 ⌠ 245 ⌡ │ 246 ÷ 247 ≈ 248 °  249 ∙ 250 · 251 √ │ 252 ⁿ 253 ² 254 ■ ║", RSFW );
  397. scr_putstr( 0, 8,
  398. "╚═══════════════════╧══════════════════════════════════════╧═ Esc to Restore ══╝", RSFW );
  399. }
  400.  
  401.  
  402. /* that's all */
  403.