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

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