home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / apps / text_ed / elv16b2 / st / curses.h < prev    next >
C/C++ Source or Header  |  1992-05-13  |  11KB  |  322 lines

  1. /* curses.h */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    14407 SW Teal Blvd. #C
  6.  *    Beaverton, OR 97005
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10.  
  11. /* This is the header file for a small, fast, fake curses package */
  12.  
  13. /* termcap stuff */
  14. extern char    *tgoto();
  15. extern char    *tgetstr();
  16. extern void    tputs();
  17.  
  18. #if MSDOS
  19. /* BIOS interface used instead of termcap for MS-DOS */
  20. extern int    vmode;
  21. extern void    v_up();
  22. extern void    v_cb();
  23. extern void    v_cs();
  24. extern void    v_ce();
  25. extern void    v_cl();
  26. extern void    v_cd();
  27. extern void    v_al();
  28. extern void    v_dl();
  29. extern void    v_sr();
  30. extern void    v_move();
  31. #endif
  32.  
  33. /* faddch() is a function.  a pointer to it is passed to tputs() */
  34. extern int    faddch();
  35.  
  36. /* data types */
  37. #define WINDOW    char
  38.  
  39. /* CONSTANTS & SYMBOLS */
  40. #define TRUE        1
  41. #define FALSE        0
  42. #define A_NORMAL    0
  43. #define A_STANDOUT    1
  44. #define A_BOLD        2
  45. #define A_UNDERLINE    3
  46. #define A_ALTCHARSET    4
  47. #define A_POPUP        5
  48. #define A_VISIBLE    6
  49. #define KBSIZ        4096
  50.  
  51. /* figure out how many function keys we need to allow. */
  52. #ifndef NO_FKEY
  53. # ifdef NO_SHIFT_FKEY
  54. #  define    NFKEYS    10
  55. # else
  56. #  ifdef NO_CTRL_FKEY
  57. #   define    NFKEYS    20
  58. #  else
  59. #   ifdef NO_ALT_FKEY
  60. #    define    NFKEYS    30
  61. #   else
  62. #    define    NFKEYS    40
  63. #   endif
  64. #  endif
  65. # endif
  66. extern char    *FKEY[NFKEYS];    /* :k0=:...:k9=: codes sent by function keys */
  67. #endif
  68.  
  69. /* extern variables, defined in curses.c */
  70. extern char    *termtype;    /* name of terminal entry */
  71. extern short    ospeed;        /* tty speed, eg B2400 */
  72. #if OSK
  73. extern char PC_;    /* Pad char */
  74. extern char    *BC;    /* Backspace char string */
  75. #else
  76. extern char    PC;        /* Pad char */
  77. #endif
  78. extern WINDOW    *stdscr;    /* pointer into kbuf[] */
  79. extern WINDOW    kbuf[KBSIZ];    /* a very large output buffer */
  80. extern int    LINES;        /* :li#: number of rows */
  81. extern int    COLS;        /* :co#: number of columns */
  82. extern int    AM;        /* :am:  boolean: auto margins? */
  83. extern int    PT;        /* :pt:  boolean: physical tabs? */
  84. extern char    *VB;        /* :vb=: visible bell */
  85. extern char    *UP;        /* :up=: move cursor up */
  86. extern char    *SO;        /* :so=: standout start */
  87. extern char    *SE;        /* :se=: standout end */
  88. extern char    *US;        /* :us=: underline start */
  89. extern char    *UE;        /* :ue=: underline end */
  90. extern char    *MD;        /* :md=: bold start */
  91. extern char    *ME;        /* :me=: bold end */
  92. extern char    *AS;        /* :as=: alternate (italic) start */
  93. extern char    *AE;        /* :ae=: alternate (italic) end */
  94. #ifndef NO_VISIBLE
  95. extern char    *MV;        /* :mv=: "visible" selection start */
  96. #endif
  97. extern char    *CM;        /* :cm=: cursor movement */
  98. extern char    *CE;        /* :ce=: clear to end of line */
  99. extern char    *CD;        /* :cd=: clear to end of screen */
  100. extern char    *AL;        /* :al=: add a line */
  101. extern char    *DL;        /* :dl=: delete a line */
  102. #if OSK
  103. extern char    *SR_;        /* :sr=: scroll reverse */
  104. #else
  105. extern char    *SR;        /* :sr=: scroll reverse */
  106. #endif
  107. extern char    *KU;        /* :ku=: sequence sent by up key */
  108. extern char    *KD;        /* :kd=: sequence sent by down key */
  109. extern char    *KL;        /* :kl=: sequence sent by left key */
  110. extern char    *KR;        /* :kr=: sequence sent by right key */
  111. extern char    *PU;        /* :PU=: key sequence sent by PgUp key */
  112. extern char    *PD;        /* :PD=: key sequence sent by PgDn key */
  113. extern char    *HM;        /* :HM=: key sequence sent by Home key */
  114. extern char    *EN;        /* :EN=: key sequence sent by End key */
  115. extern char    *KI;        /* :kI=: key sequence sent by Insert key */
  116. extern char    *IM;        /* :im=: insert mode start */
  117. extern char    *IC;        /* :ic=: insert following char */
  118. extern char    *EI;        /* :ei=: insert mode end */
  119. extern char    *DC;        /* :dc=: delete a character */
  120. extern char    *TI;        /* :ti=: terminal init */    /* GB */
  121. extern char    *TE;        /* :te=: terminal exit */    /* GB */
  122. #ifndef NO_CURSORSHAPE
  123. extern char    *CQ;        /* :cQ=: normal cursor */
  124. extern char    *CX;        /* :cX=: cursor used for EX command/entry */
  125. extern char    *CV;        /* :cV=: cursor used for VI command mode */
  126. extern char    *CI;        /* :cI=: cursor used for VI input mode */
  127. extern char    *CR;        /* :cR=: cursor used for VI replace mode */
  128. #endif
  129. extern char    *aend;        /* end an attribute -- either UE or ME */
  130. extern char    ERASEKEY;    /* taken from the ioctl structure */
  131. #ifndef NO_COLOR
  132. extern char    SOcolor[];
  133. extern char    SEcolor[];
  134. extern char    UScolor[];
  135. extern char    UEcolor[];
  136. extern char    MDcolor[];
  137. extern char    MEcolor[];
  138. extern char    AScolor[];
  139. extern char    AEcolor[];
  140. # ifndef NO_POPUP
  141. extern char    POPUPcolor[];
  142. # endif
  143. # ifndef NO_VISIBLE
  144. extern char    VISIBLEcolor[];
  145. # endif
  146. extern char    normalcolor[];
  147. #endif /* undef NO_COLOR */
  148.  
  149. /* Msdos-versions may use bios; others always termcap.
  150.  * Will emit some 'code has no effect' warnings in unix.
  151.  */
  152.  
  153. #if MSDOS
  154. extern char o_pcbios[1];        /* BAH! */
  155. #define    CHECKBIOS(x,y)    (*o_pcbios ? (x) : (y))
  156. #define VOIDBIOS(x,y)    {if (*o_pcbios) {x;} else {y;}}
  157. #else
  158. #define    CHECKBIOS(x,y)    (y)
  159. #define VOIDBIOS(x,y)    {y;}
  160. #endif
  161.  
  162. #ifndef NO_COLOR
  163. # define setcolor(m,a)    CHECKBIOS(bioscolor(m,a), ansicolor(m,a))
  164. # define fixcolor()    VOIDBIOS(;, tputs(normalcolor, 1, faddch))
  165. # define quitcolor()    CHECKBIOS(biosquit(), ansiquit())
  166. # define do_SO()    VOIDBIOS((vmode=A_STANDOUT), tputs(SOcolor, 1, faddch))
  167. # define do_SE()    VOIDBIOS((vmode=A_NORMAL), tputs(SEcolor, 1, faddch))
  168. # define do_US()    VOIDBIOS((vmode=A_UNDERLINE), tputs(UScolor, 1, faddch))
  169. # define do_UE()    VOIDBIOS((vmode=A_NORMAL), tputs(UEcolor, 1, faddch))
  170. # define do_MD()    VOIDBIOS((vmode=A_BOLD), tputs(MDcolor, 1, faddch))
  171. # define do_ME()    VOIDBIOS((vmode=A_NORMAL), tputs(MEcolor, 1, faddch))
  172. # define do_AS()    VOIDBIOS((vmode=A_ALTCHARSET), tputs(AScolor, 1, faddch))
  173. # define do_AE()    VOIDBIOS((vmode=A_NORMAL), tputs(AEcolor, 1, faddch))
  174. # define do_POPUP()    VOIDBIOS((vmode=A_POPUP), tputs(POPUPcolor, 1, faddch))
  175. # define do_VISIBLE()    VOIDBIOS((vmode=A_VISIBLE), tputs(VISIBLEcolor, 1, faddch))
  176. #else
  177. # define do_SO()    VOIDBIOS((vmode=A_STANDOUT), tputs(SO, 1, faddch))
  178. # define do_SE()    VOIDBIOS((vmode=A_NORMAL), tputs(SE, 1, faddch))
  179. # define do_US()    VOIDBIOS((vmode=A_UNDERLINE), tputs(US, 1, faddch))
  180. # define do_UE()    VOIDBIOS((vmode=A_NORMAL), tputs(UE, 1, faddch))
  181. # define do_MD()    VOIDBIOS((vmode=A_BOLD), tputs(MD, 1, faddch))
  182. # define do_ME()    VOIDBIOS((vmode=A_NORMAL), tputs(ME, 1, faddch))
  183. # define do_AS()    VOIDBIOS((vmode=A_ALTCHARSET), tputs(AS, 1, faddch))
  184. # define do_AE()    VOIDBIOS((vmode=A_NORMAL), tputs(AE, 1, faddch))
  185. # define do_POPUP()    VOIDBIOS((vmode=A_POPUP), tputs(SO, 1, faddch))
  186. # define do_VISIBLE()    VOIDBIOS((vmode=A_VISIBLE), tputs(MV, 1, faddch))
  187. #endif
  188.  
  189. #define    do_VB()        VOIDBIOS(;, tputs(VB, 1, faddch))
  190. #define    do_UP()        VOIDBIOS(v_up(), tputs(UP, 1, faddch))
  191. #undef    do_CM        /* move */
  192. #define    do_CE()        VOIDBIOS(v_ce(), tputs(CE, 1, faddch))
  193. #define    do_CD()        VOIDBIOS(v_cd(), tputs(CD, 1, faddch))
  194. #define    do_AL()        VOIDBIOS(v_al(), tputs(AL, LINES, faddch))
  195. #define    do_DL()        VOIDBIOS(v_dl(), tputs(DL, LINES, faddch))
  196. #if OSK
  197. #define    do_SR()        VOIDBIOS(v_sr(), tputs(SR_, 1, faddch))
  198. #else
  199. #define    do_SR()        VOIDBIOS(v_sr(), tputs(SR, 1, faddch))
  200. #endif
  201. #define    do_IM()        VOIDBIOS(;, tputs(IM, 1, faddch))
  202. #define    do_IC()        VOIDBIOS(;, tputs(IC, 1, faddch))
  203. #define    do_EI()        VOIDBIOS(;, tputs(EI, 1, faddch))
  204. #define    do_DC()        VOIDBIOS(;, tputs(DC, COLS, faddch))
  205. #define    do_TI()        VOIDBIOS(;, (void)ttywrite(TI, (unsigned)strlen(TI)))
  206. #define    do_TE()        VOIDBIOS(;, (void)ttywrite(TE, (unsigned)strlen(TE)))
  207. #ifndef NO_CURSORSHAPE
  208. # if MINT /* ctputs() knows about #blink / #noblink and calling ST BIOS... */
  209. #  define do_CQ()    VOIDBIOS(v_cs(), ctputs(CQ, 1, faddch))
  210. #  define do_CX()    VOIDBIOS(v_cs(), ctputs(CX, 1, faddch))
  211. #  define do_CV()    VOIDBIOS(v_cs(), ctputs(CV, 1, faddch))
  212. #  define do_CI()    VOIDBIOS(v_cb(), ctputs(CI, 1, faddch))
  213. #  define do_CR()    VOIDBIOS(v_cb(), ctputs(CR, 1, faddch))
  214. # else
  215. #  define do_CQ()    VOIDBIOS(v_cs(), tputs(CQ, 1, faddch))
  216. #  define do_CX()    VOIDBIOS(v_cs(), tputs(CX, 1, faddch))
  217. #  define do_CV()    VOIDBIOS(v_cs(), tputs(CV, 1, faddch))
  218. #  define do_CI()    VOIDBIOS(v_cb(), tputs(CI, 1, faddch))
  219. #  define do_CR()    VOIDBIOS(v_cb(), tputs(CR, 1, faddch))
  220. # endif
  221. #endif
  222. #ifndef NO_COLOR
  223. # define do_aend()    VOIDBIOS((vmode=A_NORMAL), endcolor())
  224. #else
  225. # define do_aend()    VOIDBIOS((vmode=A_NORMAL), tputs(aend, 1, faddch))
  226. #endif
  227.  
  228. #define    has_AM        CHECKBIOS(1, AM)
  229. #define    has_PT        CHECKBIOS(0, PT)
  230. #define    has_VB        CHECKBIOS((char *)0, VB)
  231. #define    has_UP        CHECKBIOS((char *)1, UP)
  232. #define    has_SO        CHECKBIOS((char)1, (*SO))
  233. #define    has_SE        CHECKBIOS((char)1, (*SE))
  234. #define    has_US        CHECKBIOS((char)1, (*US))
  235. #define    has_UE        CHECKBIOS((char)1, (*UE))
  236. #define    has_MD        CHECKBIOS((char)1, (*MD))
  237. #define    has_ME        CHECKBIOS((char)1, (*ME))
  238. #define    has_AS        CHECKBIOS((char)1, (*AS))
  239. #define    has_AE        CHECKBIOS((char)1, (*AE))
  240. #undef    has_CM        /* cursor move: don't need */
  241. #define    has_CB        CHECKBIOS(1, 0)
  242. #define    has_CS        CHECKBIOS(1, 0)
  243. #define    has_CE        CHECKBIOS((char *)1, CE)
  244. #define    has_CD        CHECKBIOS((char *)1, CD)
  245. #define    has_AL        CHECKBIOS((char *)1, AL)
  246. #define    has_DL        CHECKBIOS((char *)1, DL)
  247. #if OSK
  248. #define    has_SR        CHECKBIOS((char *)1, SR_)
  249. #else
  250. #define    has_SR        CHECKBIOS((char *)1, SR)
  251. #endif
  252. #define    has_KU        KU
  253. #define    has_KD        KD
  254. #define    has_KL        KL
  255. #define    has_KR        KR
  256. #define has_HM        HM
  257. #define has_EN        EN
  258. #define has_PU        PU
  259. #define has_PD        PD
  260. #define has_KI        KI
  261. #define    has_IM        CHECKBIOS((char)0, (*IM))
  262. #define    has_IC        CHECKBIOS((char)0, (*IC))
  263. #define    has_EI        CHECKBIOS((char)0, (*EI))
  264. #define    has_DC        CHECKBIOS((char *)0, DC)
  265. #define    has_TI        CHECKBIOS((char)0, (*TI))
  266. #define    has_TE        CHECKBIOS((char)0, (*TE))
  267. #ifndef NO_CURSORSHAPE
  268. #define has_CQ        CHECKBIOS((char *)1, CQ)
  269. #endif
  270.  
  271. /* (pseudo)-Curses-functions */
  272.  
  273. #ifdef lint
  274. # define _addCR        VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\r') : (stdscr[-1] = '\n')))
  275. #else
  276. # if OSK
  277. #  define _addCR    VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\l') : (stdscr[-1] = stdscr[-1])))
  278. # else
  279. #  define _addCR    VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\r') : 0))
  280. # endif
  281. #endif
  282.  
  283. #ifdef AZTEC_C
  284. # define qaddch(ch)    CHECKBIOS(v_put(ch), (*stdscr = (ch), *stdscr++))
  285. #else
  286. #define qaddch(ch)    CHECKBIOS(v_put(ch), (*stdscr++ = (ch)))
  287. #endif
  288.  
  289. #if OSK
  290. #define addch(ch)    if (qaddch(ch) == '\n') qaddch('\l'); else
  291. #else
  292. #define addch(ch)    if (qaddch(ch) == '\n') qaddch('\r'); else
  293. #endif
  294.  
  295. extern void initscr();
  296. extern void endwin();
  297. extern void suspend_curses();
  298. extern void resume_curses();
  299. extern void attrset();
  300. extern void insch();
  301. extern void qaddstr();
  302. extern void wrefresh();
  303. extern void wqrefresh();
  304. #define addstr(str)    {qaddstr(str); _addCR;}
  305. #define move(y,x)    VOIDBIOS(v_move(x,y), tputs(tgoto(CM, x, y), 1, faddch))
  306. #define mvaddch(y,x,ch)    {move(y,x); addch(ch);}
  307. #define refresh()    VOIDBIOS(;, wrefresh())
  308. #define standout()    do_SO()
  309. #define standend()    do_SE()
  310. #define clrtoeol()    do_CE()
  311. #define clrtobot()    do_CD()
  312. #define insertln()    do_AL()
  313. #define deleteln()    do_DL()
  314. #define delch()        do_DC()
  315. #define scrollok(w,b)
  316. #define raw()
  317. #define echo()
  318. #define cbreak()
  319. #define noraw()
  320. #define noecho()
  321. #define nocbreak()
  322.