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

  1. /*
  2. Header:          CUG199;
  3. Title:           Header include file of ged editor DeSmet, MSC and TurboC;
  4. Last Updated:    11/29/87;
  5.  
  6. Description:    "PURPOSE: standard header file, included in all function files,
  7.                  NB. e/qed/ged does NOT require <stdio.h>)";
  8.  
  9. Keywords:        e, editor, qed, ged, DeSmet, MSDOS;
  10. Filename:        ged.h;
  11. Warnings:        must be included in all ged files
  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.       licensed for private non-profitmaking use 1983
  25.  
  26. Modified:  Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  27.            March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  28.  
  29.            May       1986:  qed converted to ged         (Mel Tearle)
  30.            August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  31.  
  32. File:      ged.h
  33.  
  34. */
  35.  
  36. #include  <dos.h>
  37.  
  38. #ifdef  MSC
  39. #include  <stdio.h>
  40. #include  <stdlib.h>
  41. #include  <ctype.h>
  42.  
  43. #include  <io.h>
  44. #include  <direct.h>
  45. #include  <fcntl.h>
  46. #include  <process.h>
  47.  
  48. #include  <malloc.h>
  49. #include  <string.h>
  50. #include  <sys\types.h>
  51. #include  <sys\stat.h>
  52. #include  <setjmp.h>
  53. #endif                   /* MSC */
  54.  
  55.  
  56. #ifdef  TC
  57. #include  <stdio.h>
  58. #include  <stdlib.h>
  59. #include  <ctype.h>
  60.  
  61. #include  <io.h>
  62. #include  <fcntl.h>
  63. #include  <process.h>
  64.  
  65. #include  <mem.h>
  66. #include  <string.h>
  67. #include  <sys\stat.h>
  68.  
  69. #define   _memavl  coreleft
  70. #endif                /* TC */
  71.  
  72.  
  73. /* fixes for DeSmet - MSC/TC
  74.  */
  75. #ifndef  DS
  76. #define  index         strchr
  77. #define  _os(a,b)      bdos(a,b,0)
  78. #define  creat(file)   creat(file,S_IREAD|S_IWRITE)
  79. #endif
  80.  
  81.  
  82. #define STKSPACE   1024      /* space for the stack */
  83. #define SECSIZ      128      /* file buffer definitions */
  84. #define NSECTS       16
  85. #define IOBUFSIZ ( NSECTS * SECSIZ + 6 )
  86. #define FILELEN      64      /* max length of file name */
  87.  
  88. #define JBUFSIZE   6     /* size of buffer required for longjumps */
  89. #define BUFFER    16     /* generic buffer size */
  90. #define REFORM    72     /* default line size used in reformatting paragraph */
  91. #define FLIM      80     /* max length of find/alter string */
  92. #define LLIM     255     /* max length of a line */
  93.  
  94. #define FAIL      -1
  95. #define DFAIL   0xff     /* DeSmet read fail flag for returning char */
  96. #define NULL       0
  97. #define YES        1
  98. #define NO         0
  99. #define FALSE      0
  100. #define TRUE       1
  101. #define PREV      -2
  102.  
  103. #define HELP          1    /* table assignments */
  104. #define TABLE1        2
  105. #define TABLE2        3
  106. #define WINDOW        9    /* last line of display */
  107.  
  108. #define PAGEOVERLAP   1    /* overlap between pages with UP,DOWN-PAGE */
  109. #define OFFWIDTH     32    /* horizontal scroll increment */
  110.  
  111. #define SHEIGHT      23    /* screen height */
  112. #define PATHLEN      32    /* display lenght of path */
  113. #define SWIDTH       79    /* screen width */
  114.  
  115. #define NLINES        6    /* number of lines to skip at bottom of page */
  116. #define PAGELEN      66    /* length of page, used in listfile() */
  117.  
  118. #define EMPOS         0    /* position of error message */
  119. #define WAITPOS       0    /* position of cursor when searching/reading */
  120. #define LNPOS         0    /* position of line number */
  121. #define COLPOS       10    /* position of column number */
  122. #define REPPOS       19    /* position of "Replace?" cursor */
  123.  
  124. #define CAPLK        19    /* position of capslock message */
  125. #define FNPOS        27    /* status line - position of file name */
  126. #define OVERT        64    /* position of overstrike message */
  127. #define TIMEPOS      75    /* position of current time */
  128.  
  129. #define BACKSP     0x08    /* backspace */
  130. #define ENDFILE    0x1a    /* CP/M end of text file mark */
  131. #define CTRL       0x1f    /* last control char */
  132. #define PARBIT     0x80    /* parity bit used as a flag by testkey() */
  133. #define NKEYS        32    /* number of key codes */
  134.  
  135. #define HISTLEN     100    /* history stack of commands for undoing */
  136. #define HISTINSERT    1    /* type of command on history stack */
  137. #define HISTDELETE    2
  138. #define HISTREPLACE   3
  139.  
  140. /* Internal key codes - recommended key assignments in brackets
  141.  */
  142. #define LEADIN     0     /* lead in chararacter to key codes -
  143.                             ignored, but following key code parity set */
  144. #define DOWNKEY    1     /* cursor down */
  145. #define UPKEY      2     /* cursor up */
  146. #define LEFTKEY    3     /* cursor left */
  147. #define RIGHTKEY   4     /* cursor right */
  148. #define RIGHTWKEY  5     /* cursor right one word (D) */
  149. #define LEFTWKEY   6     /* cursor left one word (S) */
  150. #define EOLKEY     7     /* cursor to end of line (E) */
  151. #define BOLKEY     8     /* cursor to beginning of line (B) */
  152. #define UPPAGE     9     /* scroll up a page (W) */
  153. #define DOWNPAGE  10     /* scroll down a page (Z) */
  154. #define BOFKEY    11     /* cursor to beginning of file (U) */
  155. #define HOMEKEY   12     /* cursor to end of file (HOME) */
  156. #define DELLEFT   13     /* delete char to left of cursor (DEL) */
  157. #define DELRIGHT  14     /* delete char under cursor (G) */
  158. #define DELLNKEY  15     /* delete cursor line (Y) */
  159. #define DELWDKEY  16     /* delete word to right of cursor (T) */
  160. #define JUMPKEY   17     /* jump to (X) */
  161. #define CRSTILL   18     /* insert newline after cursor (N) */
  162. #define QWIKKEY   19     /* quit (Q) */
  163. #define SCRLDNKEY 20     /* edit and file context (C) */
  164. #define TOPSCRKEY 21     /* find (F) */
  165. #define BOTSCRKEY 22     /* alter (A) */
  166. #define BLOCKKEY  23     /* block operations (O) */
  167. #define SCRLUPKEY 24     /* read a file (P) */
  168. #define REPKEY    25     /* repeat last find/alter (R) */
  169. #define HELPKEY   26     /* display help menu (V) */
  170. #define OOPSKEY   27     /* restore unedited line (\) */
  171. #define TAB       28     /* tab (I) */
  172. #define RETRIEVE  29     /* retrieve last name etc entered here (R) */
  173. #define CR        30     /* return (M) */
  174. #define ESCKEY    31     /* the magic escape key (ESC) */
  175.  
  176.  
  177. /* key codes + 0x80 (PARBIT) - used in scanning strings of ctrl chars
  178.  */
  179. #define LEFTKEY_P   131
  180. #define DELLEFT_P   141
  181. #define RETRIEVE_P  157
  182. #define CR_P        158
  183. #define ESCKEY_P    159
  184.  
  185. #define F1KEY       128   /* these chars are now off limits */
  186. #define F2KEY       129   /* but I doubt if it will matter much */
  187. #define F3KEY       130
  188. #define F4KEY       145
  189. #define F5KEY       132
  190. #define F6KEY       133
  191. #define F7KEY       134
  192. #define F8KEY       135
  193. #define F9KEY       136
  194. #define F10KEY      137
  195. #define INSKEY      138
  196. #define CAPSLKON    139
  197. #define CAPSLKOFF   140
  198. #define ALTKEY      146
  199. #define GREYMINUS   142
  200. #define GREYPLUS    143
  201.  
  202.  
  203. /* screen attributes */
  204.  
  205. #define BRIDIM       '|'   /* char placed in message strings to start/stop
  206.                               dim ( half-intensity ) display */
  207.  
  208. #define DIM            4
  209. #define HIGH          13
  210. #define RSFW         104
  211. #define REVS         112
  212.  
  213. #define dim()    attr = DIM
  214. #define high()   attr = HIGH
  215.  
  216.  
  217. /* dos interrupts */
  218.  
  219. #define DOSINT      0x21
  220. #define SELDSK      0x0E
  221. #define CURDSK      0x19
  222. #define LSTOUT      0x05
  223. #define SETDIR      0x3b
  224. #define GETDIR      0x47
  225.  
  226.  
  227. /* file management */
  228.  
  229. #define MAXSLOTS     255      /* virtual memory constants */
  230. #define MAXMEMSLOTS   64      /* 36 for 64k TPA (CP/M816); old = 20 */
  231. #define PAGESIZE    1024
  232. #define PAGESECTS  ( PAGESIZE/SECSIZ )
  233.  
  234. #define FREE           0
  235. #define INUSE          1
  236. #define NOTAVAIL      -1
  237. #define MAXINT     32767
  238. #define NOFILE   (MAXINT)
  239. #define ABSOLUTE       0
  240. #define UNKNOWN  (MAXINT)
  241. #define VERNO    0x30        /* get MSDOS version number */
  242.  
  243. #define debug   scr_delete(0,24);       /* 24th line */
  244.  
  245.  
  246. /* the structure of the file buffers
  247.  */
  248. struct iobuffer  {
  249.   int   _fd;
  250.   int   _nleft;
  251.   char *_nextp;
  252.   char  _buff[ NSECTS * SECSIZ ];
  253. };
  254.  
  255.  
  256. /* address of text of each line
  257.  */
  258. struct addr  {
  259.   int  page;
  260.   int  moffset;
  261. }  *tp;
  262.  
  263.  
  264. /* command history stack for undo()
  265.  */
  266. struct histstep  {
  267.   struct addr histp;    /* address of text modified by command */
  268.   int histline;         /* line number of modified text */
  269.   int histtype;         /* type of command (insert,delete,replace) */
  270.   int histcomm;         /* number of command modulo 256 */
  271. }   history[HISTLEN];
  272.  
  273.  
  274. int histptr;            /* pointer into history stack  */
  275. int histcnt;            /* number of commands on stack */
  276. int storehist;          /* commands only stored on history when true */
  277.  
  278. unsigned ncommand;      /* count of commands executed since startup  */
  279.  
  280. int allocp;             /* location of next free in newpage */
  281. int attr;               /* attribute for norm() and high()  */
  282. int pclock;             /* counter for least recently used paging */
  283.  
  284. int newpage;                 /* page no of page being filled with text */
  285. int pagefd;                  /* file descriptor of paging file */
  286. int pageloc[MAXSLOTS];       /* current location of each page */
  287. int slotsinmem;              /* max no. of slots available in memory */
  288. int tppages;                 /* no. of pages used to hold text pointers */
  289. int usage[MAXMEMSLOTS];      /* records usage of in memory slots */
  290.  
  291. char dskslots[MAXSLOTS];      /* is disk slot free */
  292. char *npaddr;                 /* base of slot holding newpage */
  293. char pagingfile[FILELEN];     /* name of paging file */
  294. char pagingdisk;              /* disk to put paging file on */
  295. char *slotaddr[MAXMEMSLOTS];  /* memory addr of start of each in memory slot */
  296.  
  297. char timestr[6];              /* used to in xgettime */
  298.  
  299. char altered;              /* if YES, current line has been altered by edits */
  300. char blankedmess;          /* message area has been blanked, not overwritten */
  301. char changed;              /* true if file has been modified */
  302. char dskerr[JBUFSIZE];     /* for bdos disk error traps */
  303.  
  304. char goteof;               /* true when eof of file being edited */
  305. char inbuf[BUFFER];        /* input buffer for typeahead */
  306. char isdim;                /* last char was in dim */
  307.  
  308. char lastgraph;            /* graphic character returned from get_graphic() */
  309. char mainmenu[JBUFSIZE];   /* for emergency longjump */
  310.  
  311. char text[LLIM];           /* buffer for current line of text */
  312. char textbuf[IOBUFSIZ];    /* io buffer for file being edited */
  313.  
  314. unsigned char tran[NKEYS];     /* translation table from al to internal
  315.                                   key codes */
  316.  
  317. int  charn;                /* position of current char in current line */
  318. int  cline;                /* current line */
  319. int  curdsk;               /* currently logged in (default) disk */
  320. int  cursorx, cursory;     /* current position of cursor */
  321.  
  322. int  goodline;          /* line number we know we can display */
  323. int  inbufp;            /* pointer to next char in inbuf */
  324.  
  325. int  lastl;             /* number of last line of text */
  326. int  lastoff;           /* offset last time resetcursor() was called */
  327. int  lastread;          /* last line actually read to date */
  328.  
  329. int  offset;            /* first col. to display on screen */
  330. int  pfirst, plast;     /* top and bottom line displayed on screen */
  331. int  rtmarg;            /* used in reform function */
  332.  
  333. int  screen;            /* current value of help screen */
  334. int  topline;           /* first line on screen for text */
  335. int  window;            /* number of lines for top psuedo-window area */
  336.  
  337. /* --------------->>  environment options  <<--------------- */
  338.  
  339. char autoin;            /* do auto indentation */
  340. char backup;            /* at end, old version becomes file.bak */
  341. char blockscroll;       /* horizontal scroll whole page */
  342.  
  343. char overtype;          /* INSKEY toggle */
  344. char readall;           /* to read as much text as possible */
  345.  
  346. char trail;             /* don't chop trailing blanks from text lines */
  347.  
  348. char ans[6];            /* line to jump to */
  349. char blocking;          /* true if block is or has been defined */
  350. char changeto[FLIM];    /* replacement string */
  351. char defext[4];         /* default file extension, saved from last file */
  352.  
  353. char *envstr;           /* used with getenv to hold environmental string */
  354. char *errmess;          /* last error message */
  355. char fbuf[IOBUFSIZ];    /* file buffer for all file ops other than edited file */
  356. char filename[FILELEN]; /* current file being edited */
  357.  
  358. char name[FILELEN];     /* filename for read and write files */
  359. char nocheck;           /* don't ask for confirmation before replacing */
  360. char opts[5];           /* options for alter */
  361.  
  362. char pathname[FILELEN]; /* pathname of file being edited */
  363. char patt[FLIM];        /* pattern to find */
  364. char repeat;            /* repeat last find/replace */
  365. char replace;           /* last find/replace was a replace */
  366.  
  367. int  findir;            /* direction of last find */
  368. int  from, to;          /* block start and end */
  369. int  jmpto, initjmp;    /* initial line to jump */
  370. int  tabwidth;          /* width between tabstops */
  371.  
  372. #ifndef DS
  373.  
  374. jmp_buf mark;
  375.  
  376. int   caps_on(void);
  377.  
  378. int   scr_ci(void);
  379. int   scr_setup(void);
  380. int   scr_sinp(void);
  381.  
  382. void   scr_aputch(int,int,char,int);
  383. void   scr_aputs(int,int,char *,int);
  384. void   scr_clr(void);
  385. void   scr_clrl(void);
  386. void   scr_cls(int);
  387. void   scr_co(int);
  388. void   scr_cursoff(void);
  389. void   scr_curson(void);
  390.  
  391. void   scr_delete(int,int);
  392. void   scr_putch(char,int);
  393. void   scr_putstr(int,int,char *,int);
  394. void   scr_scdn(void);
  395. void   scr_scrdn(int,int,int,int,int);
  396. void   scr_scrup(int,int,int,int,int);
  397. void   scr_scup(void);
  398. void   scr_setmode(int);
  399. void   scr_term(void);
  400. void   scr_xy(int,int);
  401.  
  402. char   *firstwhite(char *,int ,char *);
  403. char   *getline(int);
  404.  
  405. char   dirmsk(void);
  406. char   get_graphic(void);
  407. char   getkey(void);
  408. char   getlow(void);
  409. char   getscankey(void);
  410. char   inkey(void);
  411. char   scr_csts(void);
  412. char   setstatusname(void);
  413. char   testkey(void);
  414. char   testlow(void);
  415.  
  416. int   askforfile(void);
  417. int   balloc(unsigned int);
  418. int   blockops(void);
  419. int   blockpos(int);
  420. int   calcoffset(void);
  421. int   checkexists(char *);
  422.  
  423. int   dflush(struct iobuffer *);
  424. int   dispose(void);
  425. int   egetc(struct iobuffer *);
  426. int   eputc(char ,struct iobuffer *);
  427. int   exists(char *);
  428.  
  429. int   fcreat(char *,struct iobuffer *);
  430. int   ffclose(struct iobuffer *);
  431. int   ffopen(char *,struct iobuffer *);
  432. int   files(void);
  433. int   find(void);
  434. int   finish(int);
  435. int   freememslot(void);
  436. int   frename(char *,char *);
  437. int   funlink(char *);
  438.  
  439. int   getcursor(void);
  440. int   getnumb(void);
  441. int   inword(char);
  442. int   jumpline(int);
  443. int   loc(int ,int);
  444.  
  445. int   movechar(int);
  446. int   moveline(int);
  447. int   opentext(char *);
  448. int   prnstat(void);
  449. int   readfile(char *);
  450.  
  451. int   scans(char *,int);
  452. int   seldisk(int);
  453. int   swappin(int);
  454. int   uspr(int ,long);
  455. int   writefile(int ,int ,char *,char *,int);
  456. int   writ_txb(int ,char *);
  457.  
  458. unsigned int writepage(int);
  459.  
  460. void   addhistory(int ,int);
  461. void   adjustc(int);
  462. void   calcjmp(void);
  463. void   chkbuf(void);
  464. void   crdelete(int);
  465. void   crinsert(int);
  466. void   curdrv(char *);
  467.  
  468. void   deletechar(int);
  469. void   deleteword(void);
  470. void   deltp(int);
  471. void   display_help(void);
  472. void   display_table1(void);
  473. void   display_table2(void);
  474. void   dofindrep(int);
  475.  
  476. void   edit(void);
  477. void   envir(void);
  478. void   error(char *);
  479. void   fatalerror(char *);
  480. void   findorrep(void);
  481. void   format(char *);
  482. void   getpath(char *);
  483. void   gettext(int);
  484.  
  485. void   info(void);
  486. void   initialise(void);
  487. void   initvm(void);
  488. void   insertchar(char);
  489. void   keytranslate(void);
  490. void   listfile(int ,int);
  491.  
  492. void   main(int ,char * *);
  493. void   makebright(void);
  494. void   makedim(void);
  495. void   makeother(void);
  496. void   movepage(int);
  497. void   moveword(int);
  498.  
  499. void   putline(int ,int);
  500. void   putlineno(int);
  501. void   putmess(char *);
  502. void   putonoff(int);
  503. void   putpage(void);
  504. void   putpart(int ,int);
  505. void   putret(void);
  506. void   putstatusline(int);
  507. void   putstr(char *);
  508. void   puttext(void);
  509.  
  510. void   readpage(unsigned int ,unsigned int);
  511. void   readtext(int);
  512. void   reform(int ,int);
  513. void   resetcursor(void);
  514. void   retag(char *,char *);
  515. void   rewrite(int ,int);
  516. void   run(char *,char *,int);
  517.  
  518. void   scroll(int);
  519. void   show_envir(void);
  520. void   show_fkeys(void);
  521. void   show_table(int);
  522. void   show_time(void);
  523. void   swapout(int);
  524. void   sync(int);
  525.  
  526. void   undo(void);
  527. void   unmess(void);
  528. void   xit(void);
  529. void   xgettime(void);
  530. void   zf_time(int ,char *);
  531.  
  532. #else
  533.  
  534. unsigned int writepage();
  535.  
  536. char  *getline();
  537. char  *strcpy();
  538.  
  539. char   dirmsk();
  540. char   getkey();
  541. char   getlow();
  542. char   getscankey();
  543. char   inkey();
  544. char   testkey();
  545. char   testlow();
  546.  
  547. void   addhistory();
  548. void   adjustc();
  549. void   crdelete();
  550. void   dofindrep();
  551. void   edit();
  552. void   error();
  553.  
  554. void   fatalerror();
  555. void   findorrep();
  556. void   initialise();
  557. void   listfile();
  558.  
  559. void   putlineno();
  560. void   putonoff();
  561. void   putpart();
  562. void   putstr();
  563. void   readtext();
  564. void   readpage();
  565.  
  566. void   scroll();
  567. void   show_envir();
  568. void   show_fkeys();
  569. void   swapout();
  570. void   sync();
  571.  
  572. void   xit();
  573. void   zf_time();
  574.  
  575. #endif
  576.  
  577.  
  578. /* end of standard header */
  579.