Annotation of sbbs/uifc/uifc.h, revision 1.1.1.3

1.1.1.3 ! root        1: /* uifc.h */
1.1       root        2: 
1.1.1.2   root        3: /* Rob Swindell's Text-mode User Interface Library */
                      4: 
1.1.1.3 ! root        5: /* $Id: uifc.h,v 1.53 2004/11/19 03:04:00 rswindell Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            12:  *                                                                                                                                                     *
        !            13:  * This library is free software; you can redistribute it and/or                       *
        !            14:  * modify it under the terms of the GNU Lesser General Public License          *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
        !            18:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: #ifndef _UIFC_H_
        !            39: #define _UIFC_H_
1.1.1.2   root       40: 
1.1       root       41: #include <time.h>
1.1.1.2   root       42: #include <fcntl.h>
1.1       root       43: #include <ctype.h>
                     44: #include <stdio.h>
                     45: #include <string.h>
                     46: #include <stdarg.h>
                     47: #include <stdlib.h>
1.1.1.2   root       48: /* OS Specific */
1.1.1.3 ! root       49: #if defined(_WIN32)
        !            50:     #include <windows.h>
        !            51: #endif
        !            52: #if defined(__unix__)
        !            53:        #include <sys/param.h>  /* PATH_MAX */
        !            54: #endif
        !            55: #if (defined(__unix__) || defined(_WIN32)) && !defined(__FLAT__)
        !            56:     #define __FLAT__
        !            57: #endif
        !            58: 
1.1.1.2   root       59: #if defined(__FLAT__)
                     60:        #define far
                     61: #endif
                     62: 
1.1.1.3 ! root       63: #if !defined(__FLAT__)
1.1.1.2   root       64:     #include <bios.h>
                     65: #endif
                     66: 
1.1.1.3 ! root       67: #if defined(__unix__) && !defined(stricmp)
        !            68:     #define stricmp strcasecmp
        !            69:        #define strnicmp strncasecmp
        !            70: #endif
1.1.1.2   root       71: 
                     72: /****************************************************************************/
                     73: /* MALLOC/FREE Macros for various compilers and environments                           */
                     74: /* MALLOC is used for allocations of 64k or less                                                       */
                     75: /* FREE is used to free buffers allocated with MALLOC                                          */
                     76: /* LMALLOC is used for allocations of possibly larger than 64k                         */
                     77: /* LFREE is used to free buffers allocated with LMALLOC                                        */
                     78: /* REALLOC is used to re-size a previously MALLOCed or LMALLOCed buffer        */
                     79: /****************************************************************************/
                     80: #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
                     81:        #if defined(__TURBOC__)
                     82:                #define REALLOC(x,y) farrealloc(x,y)
                     83:                #define LMALLOC(x) farmalloc(x)
                     84:                #define MALLOC(x) farmalloc(x)
                     85:                #define LFREE(x) farfree(x)
                     86:                #define FREE(x) farfree(x)
                     87:        #elif defined(__WATCOMC__)
                     88:                #define REALLOC realloc
                     89:                #define LMALLOC(x) halloc(x,1)  /* far heap, but slow */
                     90:                #define MALLOC malloc                   /* far heap, but 64k max */
                     91:                #define LFREE hfree
                     92:                #define FREE free
                     93:        #else   /* Other 16-bit Compiler */
                     94:                #define REALLOC realloc
                     95:                #define LMALLOC malloc
                     96:                #define MALLOC malloc
                     97:                #define LFREE free
                     98:                #define FREE free
                     99:        #endif
                    100: #else          /* 32-bit Compiler or Small Memory Model */
                    101:        #define REALLOC realloc
                    102:        #define LMALLOC malloc
                    103:        #define MALLOC malloc
                    104:        #define LFREE free
                    105:        #define FREE free
                    106: #endif
                    107: 
1.1.1.3 ! root      108: #if !defined(MAX_PATH) /* maximum path length */
        !           109:        #if defined MAXPATHLEN
        !           110:                #define MAX_PATH MAXPATHLEN     /* clib.h */
        !           111:        #elif defined PATH_MAX
        !           112:                #define MAX_PATH PATH_MAX
        !           113:        #elif defined _MAX_PATH
        !           114:                #define MAX_PATH _MAX_PATH
        !           115:        #else
        !           116:                #define MAX_PATH 260            
        !           117:        #endif
        !           118: #endif
        !           119: 
1.1.1.2   root      120: #ifdef __DPMI32__
                    121:        #define INT_86(i,j,k) int386(i,j,k)
                    122: #else
                    123:        #define INT_86(i,j,k) int86(i,j,k)
                    124: #endif
                    125: 
                    126: #ifdef __FLAT__
1.1.1.3 ! root      127:        #define MAX_OPTS        10000
1.1.1.2   root      128:        #define MSK_ON          0xf0000000
                    129:        #define MSK_OFF         0x0fffffff
                    130:        #define MSK_INS         0x10000000
                    131:        #define MSK_DEL         0x20000000
                    132:        #define MSK_GET         0x30000000
                    133:        #define MSK_PUT         0x40000000
1.1.1.3 ! root      134:        /* Dont forget, negative return values are used for extended keys (if WIN_EXTKEYS used)! */
1.1.1.2   root      135: #else
                    136:        #define MAX_OPTS        500     /* Maximum number of options per menu call */
                    137:        #define MSK_ON          0xf000
                    138:        #define MSK_OFF         0x0fff
                    139:        #define MSK_INS         0x1000
                    140:        #define MSK_DEL         0x2000
                    141:        #define MSK_GET         0x3000
                    142:        #define MSK_PUT         0x4000
                    143: #endif
                    144: #define MAX_OPLN       75              /* Maximum length of each option per menu call */
                    145: #define MAX_BUFS       7               /* Maximum number of screen buffers to save */
1.1.1.3 ! root      146: #define MIN_LINES   14      /* Minimum number of screen lines supported */
        !           147: #define MAX_LINES   60      /* Maximum number of screen rows supported */ 
        !           148: #define MAX_BFLN       80*MAX_LINES*2  /* Maximum size of screen buffers */
1.1       root      149: 
                    150: #ifndef uint
                    151: #define uint unsigned int
                    152: #endif
                    153: 
1.1.1.3 ! root      154:                             /* Bits in uifcapi_t.mode */
1.1       root      155: #define UIFC_INMSG     (1<<0)  /* Currently in Message Routine non-recursive */
1.1.1.2   root      156: #define UIFC_MOUSE     (1<<1)  /* Mouse installed and available */
                    157: #define UIFC_MONO      (1<<2)  /* Force monochrome mode */
                    158: #define UIFC_COLOR     (1<<3)  /* Force color mode */
1.1.1.3 ! root      159: #define UIFC_IBM       (1<<4)  /* Force use of IBM charset     */
1.1       root      160: 
1.1.1.3 ! root      161:                             /* Bits in uifcapi_t.list mode */
1.1       root      162: #define WIN_ORG        (1<<0)  /* Original menu - destroy valid screen area */
                    163: #define WIN_SAV        (1<<1)  /* Save existing text and replace when finished */
                    164: #define WIN_ACT        (1<<2)  /* Menu remains active after a selection */
                    165: #define WIN_L2R        (1<<3)  /* Center the window based on 'width'   */
                    166: #define WIN_T2B        (1<<4)  /* Center the window based on 'height'  */
                    167: #define WIN_INS        (1<<5)  /* Allows user to user insert key */
                    168: #define WIN_INSACT     (1<<6)  /* Remains active after insert key */
                    169: #define WIN_DEL        (1<<7)  /* Allows user to use delete key */
                    170: #define WIN_DELACT     (1<<8)  /* Remains active after delete key */
                    171: #define WIN_ESC        (1<<9)  /* Screen is active when escape is hit                   */
1.1.1.2   root      172: #define WIN_RHT        (1<<10) /* Place window against right side of screen */
                    173: #define WIN_BOT        (1<<11) /* Place window against botton of screen */
                    174: #define WIN_GET        (1<<12) /* Allows F5 to Get a menu item */
                    175: #define WIN_PUT        (1<<13) /* Allows F6 to Put a menu item */
                    176: #define WIN_CHE        (1<<14) /* Stay active after escape if changes */
                    177: #define WIN_XTR        (1<<15) /* Add extra line at end for inserting at end */
1.1.1.3 ! root      178: #define WIN_DYN        (1<<16) /* Dynamic window - return at least every second */
        !           179: #define WIN_HLP        (1<<17) /* Parse 'Help codes' */
        !           180: #define WIN_PACK       (1<<18) /* Pack text in window (No padding) */
        !           181: #define WIN_IMM        (1<<19) /* Draw window and return immediately */
        !           182: #define WIN_FAT                (1<<20) /* Do not pad outside borders */
        !           183: #define WIN_REDRAW     (1<<21) /* Force redraw on dynamic window */
        !           184: #define WIN_NODRAW     (1<<22) /* Force not to redraw on dynamic window */
        !           185: #define WIN_EXTKEYS    (1<<23) /* Return on any keypress... if it's not handled internally
        !           186:                                                         * Return value is -2 - keyvalue
        !           187:                                                         */
1.1       root      188: 
                    189: #define WIN_MID WIN_L2R|WIN_T2B  /* Place window in middle of screen */
                    190: 
                    191: #define SCRN_TOP       3
                    192: #define SCRN_LEFT      5
1.1.1.3 ! root      193: #define SCRN_RIGHT     ((int)api->scrn_width-4)
1.1       root      194: 
1.1.1.2   root      195:                                                                /* Bits in 'mode' for getkey and getstr     */
                    196: #define K_UPPER        (1L<<0)         /* Converts all letters to upper case           */
                    197: #define K_UPRLWR       (1L<<1)         /* Upper/Lower case automatically                       */
                    198: #define K_NUMBER       (1L<<2)         /* Allow numbers only                                           */
                    199: #define K_WRAP         (1L<<3)         /* Allows word wrap                                             */
                    200: #define K_MSG          (1L<<4)         /* Allows ANSI, ^N ^A ^G                                        */
                    201: #define K_SPIN         (1L<<5)         /* Spinning cursor (same as SPIN)                       */
                    202: #define K_LINE         (1L<<6)         /* Input line (inverse color)                           */
                    203: #define K_EDIT         (1L<<7)         /* Edit string passed                                           */
                    204: #define K_CHAT         (1L<<8)         /* In chat multi-chat                                           */
                    205: #define K_NOCRLF       (1L<<9)         /* Don't print CRLF after string input      */
                    206: #define K_ALPHA        (1L<<10)        /* Only allow alphabetic characters             */
1.1.1.3 ! root      207: #define K_SCANNING     (1L<<11)        /* UPC Scanner is active... return on '%'       */
        !           208: #define K_TABEXIT      (1L<<12)        /* Return on TAB                                                */
        !           209: #define K_DECIMAL      (1L<<13)        /* Allow floating point numbers only            */
        !           210: #define K_DEUCEEXIT    (1L<<13)        /* Return whenever Deuce wants to exit          */
        !           211:                                                                /* Define this behaviour better - ToDo          */
1.1.1.2   root      212: 
                    213: #define HELPBUF_SIZE 4000
                    214: 
1.1.1.3 ! root      215: #ifndef _GEN_DEFS_H
1.1.1.2   root      216:                                                                        /* Control characters */
                    217: #define STX    0x02                            /* Start of text                        ^B      */
                    218: #define ETX    0x03                            /* End of text                          ^C      */
1.1.1.3 ! root      219: #define BS             '\b'                            /* Back space                           ^H      */
        !           220: #define TAB    '\t'                            /* Horizontal tabulation        ^I      */
        !           221: #define LF             '\n'                            /* Line feed                            ^J      */
1.1.1.2   root      222: #define FF             0x0c                            /* Form feed                            ^L      */
1.1.1.3 ! root      223: #define CR             '\r'                            /* Carriage return                      ^M      */
1.1.1.2   root      224: #define ESC    0x1b                            /* Escape                                       ^[      */
1.1.1.3 ! root      225: #define DEL     0x7f                /* Delete                   ^BS */
1.1       root      226: 
1.1.1.3 ! root      227: enum {
        !           228:         CTRL_A=1
        !           229:        ,CTRL_B
        !           230:        ,CTRL_C
        !           231:        ,CTRL_D 
        !           232:        ,CTRL_E
        !           233:        ,CTRL_F
        !           234:        ,CTRL_G
        !           235:        ,CTRL_H
        !           236:        ,CTRL_I
        !           237:        ,CTRL_J
        !           238:        ,CTRL_K
        !           239:        ,CTRL_L
        !           240:        ,CTRL_M
        !           241:        ,CTRL_N
        !           242:        ,CTRL_O
        !           243:        ,CTRL_P
        !           244:        ,CTRL_Q
        !           245:        ,CTRL_R
        !           246:        ,CTRL_S
        !           247:        ,CTRL_T
        !           248:        ,CTRL_U
        !           249:        ,CTRL_V
        !           250:        ,CTRL_W
        !           251:        ,CTRL_X
        !           252:        ,CTRL_Y
        !           253:        ,CTRL_Z
        !           254: };
1.1       root      255: 
1.1.1.3 ! root      256: #endif
1.1       root      257: 
1.1.1.2   root      258: #ifndef uchar                          /* Short-hand for unsigned data types */
                    259: #define uchar unsigned char
                    260: #endif
                    261: #ifndef uint
                    262: #define uint unsigned int
                    263: #endif
                    264: #ifndef ulong
                    265: #define ulong unsigned long
                    266: #endif
1.1       root      267: 
1.1.1.3 ! root      268: #ifndef BOOL
        !           269: #define BOOL    int
        !           270: #ifndef TRUE
        !           271: #define TRUE    1
        !           272: #endif
        !           273: #ifndef FALSE
        !           274: #define FALSE   0
        !           275: #endif
        !           276: #endif
1.1       root      277: 
                    278: typedef struct {
1.1.1.3 ! root      279:        uint    left,top,right,bot;
        !           280:     uchar   *buf;
        !           281: } win_t;
        !           282: 
        !           283: #if !defined(__FLAT__)
        !           284:     /* LCLOLL.ASM */
        !           285:     int lclini(int);
        !           286:     void lclxy(int,int);
        !           287:     int lclwx(void);
        !           288:     int lclwy(void);
        !           289:     int lclatr(int);
        !           290:     void lputc(int);
        !           291:     long lputs(char far *);
        !           292: #endif    
1.1       root      293: 
1.1.1.2   root      294: #if defined(__OS2__) || !defined(__FLAT__)
                    295: void mswait(int msecs);
                    296: extern mswtyp;
                    297: #endif
1.1       root      298: 
1.1.1.3 ! root      299: typedef struct {
        !           300: /****************************************************************************/
        !           301: /* Size of the structure (for version compatibility verification).                     */
        !           302: /****************************************************************************/
        !           303:     size_t  size;
        !           304: /****************************************************************************/
        !           305: /* Controls general UIFC library behavior.                                                                     */
        !           306: /****************************************************************************/
        !           307:     long    mode;
        !           308: /****************************************************************************/
        !           309: /* Set to TRUE when changes to data have been made by input function.          */ 
        !           310: /****************************************************************************/
        !           311:     BOOL    changes;
        !           312: /****************************************************************************/
        !           313: /* The overlapped-window save buffer number.                                                           */
        !           314: /****************************************************************************/
        !           315:     uint    savnum;
        !           316: /****************************************************************************/
        !           317: /* The current overlapped-window save buffer depth.                                                    */
        !           318: /****************************************************************************/
        !           319:     uint    savdepth;
        !           320: /****************************************************************************/
        !           321: /* Screen length                                                                                                                       */
        !           322: /****************************************************************************/
        !           323:     uint    scrn_len;
        !           324: /****************************************************************************/
        !           325: /* Screen Width                                                                                                                        */
        !           326: /****************************************************************************/
        !           327:     uint    scrn_width;
        !           328: /****************************************************************************/
        !           329: /* ESC key delay for curses                                                                                                    */
        !           330: /****************************************************************************/
        !           331:     uint    esc_delay;
        !           332: /****************************************************************************/
        !           333: /* Alternative method of setting current help text.                                                    */
        !           334: /****************************************************************************/
        !           335:     char*   helpbuf;
        !           336: /****************************************************************************/
        !           337: /* Location of the help data and index files.                                                          */
        !           338: /****************************************************************************/
        !           339:     char    helpdatfile[MAX_PATH+1];
        !           340:     char    helpixbfile[MAX_PATH+1];
        !           341: /****************************************************************************/
        !           342: /* Help and exit button locations for current/last window                                      */
        !           343: /****************************************************************************/
        !           344:        int             buttony;
        !           345:        int             exitstart;
        !           346:        int             exitend;
        !           347:        int             helpstart;
        !           348:        int             helpend;
        !           349: /****************************************************************************/
        !           350: /* Exit/uninitialize function.                                                                                         */
        !           351: /****************************************************************************/
        !           352:     void    (*bail) (void);
        !           353: /****************************************************************************/
        !           354: /* Fill the screen with the appropriate background attribute.                          */
        !           355: /* str is the title for the application banner.                                                                */
        !           356: /* Returns 0 on success, non-zero on failure.                                                          */
        !           357: /****************************************************************************/
        !           358:     int     (*scrn) (char* str);
        !           359: /****************************************************************************/
        !           360: /* Popup a message, maybe wait for the user to hit a key or click button.      */
        !           361: /****************************************************************************/
        !           362:     void    (*msg)  (char* str);
        !           363: /****************************************************************************/
        !           364: /* Popup/down a status message.                                                                                                */
        !           365: /* str is the message to display on popup.                                                                     */
        !           366: /* if str==NULL, then the the status is to be cleared (popdown).                       */
        !           367: /****************************************************************************/
        !           368:     void    (*pop)  (char* str);
        !           369: /****************************************************************************/
        !           370: /* General menu function.                                                                                                      */
        !           371: /* mode contains WIN_* flags to control display and functionality.                     */
        !           372: /* left, top and width specify desired screen locations and window size.       */
        !           373: /* cur is a pointer to the current (default) option.                                           */
        !           374: /* bar is a pointer to the current location of the lightbar (which used).      */
        !           375: /* title is the caption for the menu.                                                                          */
        !           376: /* Menus can centered left to right and top to bottom automatically.           */
        !           377: /* mode bits are set with macros WIN_*.                                                                                */
        !           378: /* option is an array of char arrays, first element of last char array         */
        !           379: /* must be NULL.                                                                                                                       */
        !           380: /* Returns the 0-based selected option number, -1 for ESC, or the selected     */
        !           381: /* option number OR'd with MSK_INS, MSK_DEL, MSK_GET, or MSK_PUT.                      */
        !           382: /****************************************************************************/
        !           383:     int     (*list) (int mode, int left, int top, int width, int* dflt
        !           384:                         ,int* bar, char *title, char** option);
        !           385: /****************************************************************************/
        !           386: /* Windowed string input routine.                                                                                      */
        !           387: /* mode contains WIN_* flags to control display and functionality.                     */
        !           388: /* left and top specify desired screen location.                                                       */
        !           389: /* prompt is displayed before the input is requested.                                          */
        !           390: /* str is the string to input or edit.                                                                         */
        !           391: /* len is the maximum length of the string.                                                                    */
        !           392: /* kmode contains flags that control the string input (K_* macros).                    */
        !           393: /* This function sets uifcapi_t.changes to TRUE if the string is modified.     */
        !           394: /* Returns the length of the string or -1 on escape/abort.                                     */
        !           395: /****************************************************************************/
        !           396:     int     (*input)(int mode, int left, int top, char* prompt, char* str
        !           397:                        ,int len, int kmode);
        !           398: /****************************************************************************/
        !           399: /* Sets the current help index by source code file and line number.                    */
        !           400: /****************************************************************************/
        !           401:     void    (*sethelp)(int line, char* file);
        !           402: 
        !           403: /****************************************************************************/
        !           404: /* Shows the current help text                                                                                         */
        !           405: /****************************************************************************/
        !           406:     void    (*showhelp)(void);
        !           407:        
        !           408: /****************************************************************************/
        !           409: /* Shows a scrollable text buffer - optionally parsing "help markup codes"     */
        !           410: /****************************************************************************/
        !           411:        void (*showbuf)(int mode, int left, int top, int width, int height, char *title, char *hbuf, int *curp, int *barp);
        !           412: 
        !           413: /****************************************************************************/
        !           414: /* Updates time in upper left corner of screen with current time in ASCII/  */
        !           415: /* Unix format                                                                                                                         */
        !           416: /****************************************************************************/
        !           417:        void (*timedisplay)(void);
        !           418: 
        !           419: /****************************************************************************/
        !           420: /* String input/exit box at a specified position                                                       */
        !           421: /****************************************************************************/
        !           422:        int (*getstrxy)(int left, int top, int width, char *outstr, int max, long mode, int *lastkey);
        !           423: } uifcapi_t;
        !           424: 
        !           425: /****************************************************************************/
        !           426: /* Initialization routines for each UIFC implementation.                                       */
        !           427: /* Returns 0 on success, non-zero on failure.                                                          */
        !           428: /****************************************************************************/
        !           429: int uifcini(uifcapi_t*);       /* Original implementation based on conio               */
        !           430: int uifcinix(uifcapi_t*);      /* Standard I/O implementation                                  */
        !           431: int uifcinic(uifcapi_t*);      /* Unix curses implementation (by Deuce)                */
        !           432: int uifcinid(uifcapi_t*);      /* Unix libdialog implementation (by Deuce)             */
        !           433: int uifcini32(uifcapi_t*);     /* conio/curses implementation                                  */
        !           434: #ifdef __cplusplus
        !           435: extern "C"
        !           436: #endif
        !           437: int uifcinifltk(uifcapi_t*);   /* FLTK implementation (by Deuce)                       */
        !           438: /****************************************************************************/
        !           439: 
        !           440: #endif /* Don't add anything after this line! */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.