Annotation of sbbs/src/uifc/uifc.h, revision 1.1.1.2

1.1       root        1: /* uifc.h */
                      2: 
                      3: /* Rob Swindell's Text-mode User Interface Library */
                      4: 
1.1.1.2 ! root        5: /* $Id: uifc.h,v 1.80 2011/04/23 17:42:19 deuce Exp $ */
1.1       root        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:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       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_
                     40: 
                     41: #include <time.h>
                     42: #include <fcntl.h>
                     43: #include <ctype.h>
                     44: #include <stdio.h>
                     45: #include <string.h>
                     46: #include <stdarg.h>
                     47: #include <stdlib.h>
                     48: /* OS Specific */
                     49: #if defined(_WIN32)
                     50:     #include <windows.h>
                     51: #endif
                     52: #if defined(__unix__)
                     53:        #include <sys/param.h>  /* PATH_MAX */
                     54: #endif
                     55: 
                     56: #if defined(__unix__) && !defined(stricmp)
                     57:     #define stricmp strcasecmp
                     58:        #define strnicmp strncasecmp
                     59: #endif
                     60: 
                     61: #if !defined(FREE_AND_NULL)
                     62:        #define FREE_AND_NULL(x)                        if(x!=NULL) { free(x); x=NULL; }
                     63: #endif
                     64: 
                     65: #if !defined(MAX_PATH) /* maximum path length */
                     66:        #if defined MAXPATHLEN
                     67:                #define MAX_PATH MAXPATHLEN     /* clib.h */
                     68:        #elif defined PATH_MAX
                     69:                #define MAX_PATH PATH_MAX
                     70:        #elif defined _MAX_PATH
                     71:                #define MAX_PATH _MAX_PATH
                     72:        #else
                     73:                #define MAX_PATH 260            
                     74:        #endif
                     75: #endif
                     76: 
                     77: #define MAX_OPTS       10000
                     78: #define MSK_ON         0xf0000000
                     79: #define MSK_OFF        0x0fffffff
                     80: #define MSK_INS        0x10000000
                     81: #define MSK_DEL        0x20000000
                     82: #define MSK_GET        0x30000000
                     83: #define MSK_PUT        0x40000000
                     84: #define MSK_EDIT       0x50000000
                     85: /* Dont forget, negative return values are used for extended keys (if WIN_EXTKEYS used)! */
                     86: #define MAX_OPLN       75              /* Maximum length of each option per menu call */
                     87: #define MAX_BUFS       7               /* Maximum number of screen buffers to save */
                     88: #define MIN_LINES   14      /* Minimum number of screen lines supported */
1.1.1.2 ! root       89: #define MAX_LINES   255     /* Maximum number of screen lines supported (ciolib screenheight is a uchar) */ 
        !            90: #define MAX_COLS       255             /* Maximum number of screen columns supported (ciolib screenwidth is a uchar) */ 
        !            91: #define MAX_BFLN       (MAX_COLS*MAX_LINES*2)  /* Maximum size of screen buffers, char + attr */
1.1       root       92: 
                     93: #ifndef uint
                     94: #define uint unsigned int
                     95: #endif
                     96: 
                     97:                                                        /**************************/
                     98:                             /* Bits in uifcapi_t.mode */
                     99:                                                        /**************************/
                    100: #define UIFC_INMSG     (1<<0)  /* Currently in Message Routine non-recursive */
                    101: #define UIFC_MOUSE     (1<<1)  /* Mouse installed and available */
                    102: #define UIFC_MONO      (1<<2)  /* Force monochrome mode */
                    103: #define UIFC_COLOR     (1<<3)  /* Force color mode */
                    104: #define UIFC_IBM       (1<<4)  /* Force use of IBM charset     */
                    105: #define UIFC_NOCTRL    (1<<5)  /* Don't allow useage of CTRL keys for movement 
                    106:                                                         * etc in menus (Still available in text boxes) */
1.1.1.2 ! root      107: #define UIFC_NHM       (1<<6)  /* Don't hide the mouse pointer */
1.1       root      108: 
                    109:                                                        /*******************************/
                    110:                             /* Bits in uifcapi_t.list mode */
                    111:                                                        /*******************************/
                    112: #define WIN_ORG        (1<<0)  /* Original menu - destroy valid screen area */
                    113: #define WIN_SAV        (1<<1)  /* Save existing text and replace when finished */
                    114: #define WIN_ACT        (1<<2)  /* Menu remains active after a selection */
                    115: #define WIN_L2R        (1<<3)  /* Center the window based on 'width'   */
                    116: #define WIN_T2B        (1<<4)  /* Center the window based on 'height'  */
                    117: #define WIN_INS        (1<<5)  /* Allows user to user insert key */
                    118: #define WIN_INSACT     (1<<6)  /* Remains active after insert key */
                    119: #define WIN_DEL        (1<<7)  /* Allows user to use delete key */
                    120: #define WIN_DELACT     (1<<8)  /* Remains active after delete key */
                    121: #define WIN_ESC        (1<<9)  /* Screen is active when escape is hit                   */
                    122: #define WIN_RHT        (1<<10) /* Place window against right side of screen */
                    123: #define WIN_BOT        (1<<11) /* Place window against botton of screen */
                    124: #define WIN_GET        (1<<12) /* Allows F5 to Get a menu item */
                    125: #define WIN_PUT        (1<<13) /* Allows F6 to Put a menu item */
                    126: #define WIN_CHE        (1<<14) /* Stay active after escape if changes */
                    127: #define WIN_XTR        (1<<15) /* Add extra line at end for inserting at end */
                    128: #define WIN_DYN        (1<<16) /* Dynamic window - return at least every second */
                    129: #define WIN_HLP        (1<<17) /* Parse 'Help codes' */
                    130: #define WIN_PACK       (1<<18) /* Pack text in window (No padding) */
                    131: #define WIN_IMM        (1<<19) /* Draw window and return immediately */
                    132: #define WIN_FAT                (1<<20) /* Do not pad outside borders */
                    133: #define WIN_REDRAW     (1<<21) /* Force redraw on dynamic window */
                    134: #define WIN_NODRAW     (1<<22) /* Force not to redraw on dynamic window */
                    135: #define WIN_EXTKEYS    (1<<23) /* Return on any keypress... if it's not handled internally
                    136:                                                         * Return value is -2 - keyvalue */
                    137: #define WIN_NOBRDR     (1<<24) /* Do not draw a border around the window */
                    138: #define WIN_FIXEDHEIGHT        (1<<25) /* Use list_height from uifc struct */
                    139: #define WIN_UNGETMOUSE  (1<<26) /* If the mouse is clicked outside the window, */
                    140:                                                                /* Put the mouse event back into the event queue */
                    141: #define WIN_EDIT       (1<<27) /* Allow F2 to edit a menu item */
                    142: #define WIN_EDITACT    (1<<28) /* Remain active after edit key */
                    143: #define WIN_INACT      (1<<29) /* Draw window inactive... intended for use with WIN_IMM */
1.1.1.2 ! root      144: #define WIN_POP                (1<<30) /* Exit the list. Act as though ESC was pressed. */
        !           145:                                                        /* Intended for use after a WIN_EXTKEYS or WIN_DYN */
        !           146: #define WIN_SEL                (1<<31) /* Exit the list. Act as though ENTER was pressed. */
        !           147:                                                        /* Intended for use after a WIN_EXTKEYS or WIN_DYN */
1.1       root      148: 
                    149: #define WIN_MID WIN_L2R|WIN_T2B  /* Place window in middle of screen */
                    150: 
                    151: #define SCRN_TOP       3
                    152: #define SCRN_LEFT      5
                    153: #define SCRN_RIGHT     ((int)api->scrn_width-4)
                    154: 
                    155:                                                                /* Bits in 'mode' for getkey and getstr     */
                    156: #define K_UPPER        (1L<<0)         /* Converts all letters to upper case           */
                    157: #define K_UPRLWR       (1L<<1)         /* Upper/Lower case automatically                       */
                    158: #define K_NUMBER       (1L<<2)         /* Allow numbers only                                           */
                    159: #define K_WRAP         (1L<<3)         /* Allows word wrap                                             */
                    160: #define K_MSG          (1L<<4)         /* Allows ANSI, ^N ^A ^G                                        */
                    161: #define K_SPIN         (1L<<5)         /* Spinning cursor (same as SPIN)                       */
                    162: #define K_LINE         (1L<<6)         /* Input line (inverse color)                           */
                    163: #define K_EDIT         (1L<<7)         /* Edit string passed                                           */
                    164: #define K_CHAT         (1L<<8)         /* In chat multi-chat                                           */
                    165: #define K_NOCRLF       (1L<<9)         /* Don't print CRLF after string input      */
                    166: #define K_ALPHA        (1L<<10)        /* Only allow alphabetic characters             */
                    167: #define K_SCANNING     (1L<<11)        /* UPC Scanner is active... return on '%'       */
                    168: #define K_TABEXIT      (1L<<12)        /* Return on TAB or BACKTAB                             */
                    169: #define K_DECIMAL      (1L<<13)        /* Allow floating point numbers only            */
                    170: #define K_DEUCEEXIT    (1L<<14)        /* Return whenever Deuce wants to exit          */
                    171:                                                                /* Returns on up/down/F2                                        */
                    172: #define K_MOUSEEXIT    (1L<<15)        /* Returns when mouse is clicked outside of */
                    173:                                                                /* Input area (NOT outside of window!)          */
                    174:                                                                /* And ungets the mouse event.                          */
                    175: #define K_PASSWORD     (1L<<16)        /* Does not display text while editing          */
                    176: 
                    177:                                                /* Bottom line elements */
                    178: #define BL_INS      (1<<0)  /* INS key */
                    179: #define BL_DEL      (1<<1)  /* DEL key */
                    180: #define BL_GET      (1<<2)  /* Get key */
                    181: #define BL_PUT      (1<<3)  /* Put key */
                    182: #define BL_EDIT     (1<<4)  /* Edit key */
                    183: #define BL_HELP     (1<<5)  /* Help key */
                    184: 
                    185: #define HELPBUF_SIZE 4000
                    186: 
                    187: #ifndef _GEN_DEFS_H
                    188:                                                                        /* Control characters */
                    189: #define STX    0x02                            /* Start of text                        ^B      */
                    190: #define ETX    0x03                            /* End of text                          ^C      */
                    191: #define BS             '\b'                            /* Back space                           ^H      */
                    192: #define TAB    '\t'                            /* Horizontal tabulation        ^I      */
                    193: #define LF             '\n'                            /* Line feed                            ^J      */
                    194: #define FF             0x0c                            /* Form feed                            ^L      */
                    195: #define CR             '\r'                            /* Carriage return                      ^M      */
                    196: #define ESC    0x1b                            /* Escape                                       ^[      */
                    197: #define DEL     0x7f                /* Delete                   ^BS */
                    198: 
                    199: enum {
                    200:         CTRL_A=1
                    201:        ,CTRL_B
                    202:        ,CTRL_C
                    203:        ,CTRL_D 
                    204:        ,CTRL_E
                    205:        ,CTRL_F
                    206:        ,CTRL_G
                    207:        ,CTRL_H
                    208:        ,CTRL_I
                    209:        ,CTRL_J
                    210:        ,CTRL_K
                    211:        ,CTRL_L
                    212:        ,CTRL_M
                    213:        ,CTRL_N
                    214:        ,CTRL_O
                    215:        ,CTRL_P
                    216:        ,CTRL_Q
                    217:        ,CTRL_R
                    218:        ,CTRL_S
                    219:        ,CTRL_T
                    220:        ,CTRL_U
                    221:        ,CTRL_V
                    222:        ,CTRL_W
                    223:        ,CTRL_X
                    224:        ,CTRL_Y
                    225:        ,CTRL_Z
                    226: };
                    227: 
                    228: #endif
                    229: 
                    230: #ifndef uchar                          /* Short-hand for unsigned data types */
                    231: #define uchar unsigned char
                    232: #endif
                    233: #ifndef uint
                    234: #define uint unsigned int
                    235: #endif
                    236: #ifndef ulong
                    237: #define ulong unsigned long
                    238: #endif
                    239: 
                    240: #ifndef BOOL
                    241: #define BOOL    int
                    242: #ifndef TRUE
                    243: #define TRUE    1
                    244: #endif
                    245: #ifndef FALSE
                    246: #define FALSE   0
                    247: #endif
                    248: #endif
                    249: 
                    250: typedef struct {
                    251:        int             left,top,right,bot;
                    252:        int             *cur,*bar;
                    253:     uchar*     buf;
                    254: } win_t;
                    255: 
                    256: typedef struct {
                    257: /****************************************************************************/
                    258: /* Size of the structure (for version compatibility verification).                     */
                    259: /****************************************************************************/
                    260:     size_t  size;
                    261: /****************************************************************************/
                    262: /* Controls general UIFC library behavior.                                                                     */
                    263: /****************************************************************************/
                    264:     long    mode;
                    265: /****************************************************************************/
                    266: /* Set to TRUE when changes to data have been made by input function.          */ 
                    267: /****************************************************************************/
                    268:     BOOL    changes;
                    269: /****************************************************************************/
                    270: /* The overlapped-window save buffer number.                                                           */
                    271: /****************************************************************************/
                    272:     uint    savnum;
                    273: /****************************************************************************/
                    274: /* The current overlapped-window save buffer depth.                                                    */
                    275: /****************************************************************************/
                    276:     uint    savdepth;
                    277: /****************************************************************************/
                    278: /* Screen length                                                                                                                       */
                    279: /****************************************************************************/
                    280:     uint    scrn_len;
                    281: /****************************************************************************/
                    282: /* Screen Width                                                                                                                        */
                    283: /****************************************************************************/
                    284:     uint    scrn_width;
                    285: /****************************************************************************/
                    286: /* ESC key delay for curses                                                                                                    */
                    287: /****************************************************************************/
                    288:     uint    esc_delay;
                    289: /****************************************************************************/
                    290: /* Alternative method of setting current help text.                                                    */
                    291: /****************************************************************************/
                    292:     char*   helpbuf;
                    293: /****************************************************************************/
                    294: /* Location of the help data and index files.                                                          */
                    295: /****************************************************************************/
                    296:     char    helpdatfile[MAX_PATH+1];
                    297:     char    helpixbfile[MAX_PATH+1];
                    298: /****************************************************************************/
                    299: /* Help and exit button locations for current/last window                                      */
                    300: /****************************************************************************/
                    301:        int             buttony;
                    302:        int             exitstart;
                    303:        int             exitend;
                    304:        int             helpstart;
                    305:        int             helpend;
                    306: /****************************************************************************/
                    307: /* List height for WIN_FIXEDHEIGHT lists.                                                                      */
                    308: /****************************************************************************/
                    309:        int             list_height;
                    310: 
                    311: /****************************************************************************/
                    312: /* Colours for the various bits                                                                                                */
                    313: /****************************************************************************/
                    314:        uchar   hclr,lclr,bclr,cclr,lbclr;
                    315: 
                    316: /****************************************************************************/
                    317: /* Have we initialized successfully?                                                                           */
                    318: /****************************************************************************/
                    319:        BOOL    initialized;
                    320: 
                    321: /****************************************************************************/
                    322: /* Exit/uninitialize function.                                                                                         */
                    323: /****************************************************************************/
                    324:     void    (*bail) (void);
                    325: /****************************************************************************/
                    326: /* Fill the screen with the appropriate background attribute.                          */
                    327: /* str is the title for the application banner.                                                                */
                    328: /* Returns 0 on success, non-zero on failure.                                                          */
                    329: /****************************************************************************/
                    330:     int     (*scrn) (char* str);
                    331: /****************************************************************************/
                    332: /* Popup a message, maybe wait for the user to hit a key or click button.      */
                    333: /****************************************************************************/
                    334:     void    (*msg)  (char* str);
                    335: /****************************************************************************/
                    336: /* Popup/down a status message.                                                                                                */
                    337: /* str is the message to display on popup.                                                                     */
                    338: /* if str==NULL, then the the status is to be cleared (popdown).                       */
                    339: /****************************************************************************/
                    340:     void    (*pop)  (char* str);
                    341: /****************************************************************************/
                    342: /* General menu function.                                                                                                      */
                    343: /* mode contains WIN_* flags to control display and functionality.                     */
                    344: /* left, top and width specify desired screen locations and window size.       */
                    345: /* cur is a pointer to the current (default) option.                                           */
                    346: /* bar is a pointer to the current location of the lightbar (which used).      */
                    347: /* title is the caption for the menu.                                                                          */
                    348: /* Menus can centered left to right and top to bottom automatically.           */
                    349: /* mode bits are set with macros WIN_*.                                                                                */
                    350: /* option is an array of char arrays, first element of last char array         */
                    351: /* must be NULL.                                                                                                                       */
                    352: /* Returns the 0-based selected option number, -1 for ESC, or the selected     */
                    353: /* option number OR'd with MSK_INS, MSK_DEL, MSK_GET, MSK_PUT, or MSK_EDIT.    */
                    354: /****************************************************************************/
                    355:     int     (*list) (int mode, int left, int top, int width, int* dflt
                    356:                         ,int* bar, char *title, char** option);
                    357: /****************************************************************************/
                    358: /* Windowed string input routine.                                                                                      */
                    359: /* mode contains WIN_* flags to control display and functionality.                     */
                    360: /* left and top specify desired screen location.                                                       */
                    361: /* prompt is displayed before the input is requested.                                          */
                    362: /* str is the string to input or edit.                                                                         */
                    363: /* len is the maximum length of the string.                                                                    */
                    364: /* kmode contains flags that control the string input (K_* macros).                    */
                    365: /* This function sets uifcapi_t.changes to TRUE if the string is modified.     */
                    366: /* Returns the length of the string or -1 on escape/abort.                                     */
                    367: /****************************************************************************/
                    368:     int     (*input)(int mode, int left, int top, char* prompt, char* str
                    369:                        ,int len, int kmode);
                    370: /****************************************************************************/
                    371: /* Sets the current help index by source code file and line number.                    */
                    372: /****************************************************************************/
                    373:     void    (*sethelp)(int line, char* file);
                    374: 
                    375: /****************************************************************************/
                    376: /* Shows the current help text                                                                                         */
                    377: /****************************************************************************/
                    378:     void    (*showhelp)(void);
                    379:        
                    380: /****************************************************************************/
                    381: /* Shows a scrollable text buffer - optionally parsing "help markup codes"     */
                    382: /****************************************************************************/
                    383:        void    (*showbuf)(int mode, int left, int top, int width, int height
                    384:                                                        ,char *title, char *hbuf, int *curp, int *barp);
                    385: 
                    386: /****************************************************************************/
                    387: /* Updates time in upper left corner of screen with current time in ASCII/  */
                    388: /* Unix format                                                                                                                         */
                    389: /****************************************************************************/
                    390:        void    (*timedisplay)(BOOL force);
                    391: 
                    392: /****************************************************************************/
                    393: /* Displays the bottom line using the BL_* macros                                                      */
                    394: /****************************************************************************/
                    395:     void       (*bottomline)(int line);
                    396: 
                    397: /****************************************************************************/
                    398: /* String input/exit box at a specified position                                                       */
                    399: /****************************************************************************/
                    400:        int             (*getstrxy)(int left, int top, int width, char *outstr, int max
                    401:                                                        ,long mode, int *lastkey);
                    402: 
                    403: /****************************************************************************/
                    404: /* Formatted print with attribute                                                                                      */
                    405: /****************************************************************************/
                    406:        int             (*printf)(int x, int y, unsigned attr, char *fmat, ...);
                    407: 
                    408: } uifcapi_t;
                    409: 
1.1.1.2 ! root      410: #ifdef __cplusplus
        !           411: extern "C" {
        !           412: #endif
        !           413: 
        !           414: /* Return value from uifc_api.list() when uifcYesNoOpts is used */
        !           415: enum {
        !           416:        uifcYes=0,
        !           417:        uifcNo=1
        !           418: };
        !           419: 
        !           420: extern char* uifcYesNoOpts[];
        !           421: 
1.1       root      422: /****************************************************************************/
                    423: /* Initialization routines for each UIFC implementation.                                       */
                    424: /* Returns 0 on success, non-zero on failure.                                                          */
                    425: /****************************************************************************/
                    426: int uifcini(uifcapi_t*);       /* Original implementation based on conio               */
                    427: int uifcinix(uifcapi_t*);      /* Standard I/O implementation                                  */
                    428: int uifcini32(uifcapi_t*);     /* conio/curses implementation                                  */
                    429: /****************************************************************************/
                    430: 
1.1.1.2 ! root      431: #ifdef __cplusplus
        !           432: }
        !           433: #endif
        !           434: 
1.1       root      435: #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.