Annotation of libwww/Library/src/HTAlert.c, revision 2.43

2.18      frystyk     1: /*                                                                   HTAlert.c
2.39      frystyk     2: **     DIALOG MANAGER
2.18      frystyk     3: **
2.23      frystyk     4: **     (c) COPYRIGHT MIT 1995.
2.18      frystyk     5: **     Please first read the full copyright statement in the file COPYRIGH.
1.1       timbl       6: **
                      7: **     REPLACE THIS MODULE with a GUI version in a GUI environment!
                      8: **
                      9: ** History:
                     10: **        Jun 92 Created May 1992 By C.T. Barker
                     11: **        Feb 93 Simplified, portablised TBL
2.8       luotonen   12: **        Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
2.39      frystyk    13: **        Nov 95 Rewritten using callbacks HFN
1.1       timbl      14: */
                     15: 
2.20      frystyk    16: /* Library include files */
2.29      frystyk    17: #include "WWWLib.h"
2.21      frystyk    18: #include "HTError.h"                                    /* Implemented here */
                     19: #include "HTAlert.h"                                    /* Implemented here */
1.1       timbl      20: 
2.39      frystyk    21: typedef struct _HTAlert {
                     22:     HTAlertCallback *  cbf;
                     23:     HTAlertOpcode      opcode;
                     24: } HTAlert;
                     25: 
                     26: struct _HTAlertPar {
                     27:     char *     message;
                     28:     char *     secret;
                     29:     void *     output;
                     30: };
2.28      frystyk    31: 
2.25      frystyk    32: PRIVATE BOOL HTInteractive=YES;                    /* Any prompts from the Library? */
1.1       timbl      33: 
2.39      frystyk    34: PRIVATE HTList * HTMessages = NULL;       /* Global list of alert functions */
                     35: 
2.21      frystyk    36: /* ------------------------------------------------------------------------- */
2.25      frystyk    37: 
2.39      frystyk    38: /*
                     39: **     All messaging can be turned on or off as you like
                     40: */
                     41: PUBLIC void HTAlert_setInteractive (BOOL interactive)
2.25      frystyk    42: {
                     43:     HTInteractive = interactive;
                     44: }
                     45: 
2.39      frystyk    46: PUBLIC BOOL HTAlert_interactive (void)
2.25      frystyk    47: {
                     48:     return HTInteractive;
                     49: }
2.21      frystyk    50: 
2.39      frystyk    51: /*     HTAlertCall_add
                     52: **     ---------------
                     53: **     Register a call back function that is to be called when generating
                     54: **     messages, dialog, prompts, progress reports etc.
                     55: **
                     56: **     The opcode signifies which call back function to call depending of the 
                     57: **     type of the message. Opcode can be one of the enumerations defined
                     58: **     by HTAlertOpcode.
                     59: */
                     60: PUBLIC BOOL HTAlertCall_add (HTList * list, HTAlertCallback * cbf,
                     61:                             HTAlertOpcode opcode)
                     62: {
                     63:     if (WWWTRACE) 
                     64:        TTYPrint(TDEST, "Alert Add... HTAlertCallback %p\n", (void *) cbf);
                     65:     if (list && cbf) {
                     66:        HTAlert *me = (HTAlert *) calloc(1, sizeof(HTAlert));
                     67:        if (!me) outofmem(__FILE__, "HTAlertCall_add");
                     68:        me->cbf = cbf;
                     69:        me->opcode = opcode;
                     70:        return HTList_addObject(list, (void *) me);
                     71:     }
                     72:     return NO;
                     73: }
                     74: 
                     75: /*     HTAlertCall_delete
                     76: **     ------------------
                     77: **     Unregister a call back function from a list
                     78: */
                     79: PUBLIC BOOL HTAlertCall_delete (HTList * list, HTAlertCallback *cbf)
                     80: {
                     81:     if (WWWTRACE) 
                     82:        TTYPrint(TDEST, "Call delete HTAlertCallback %p\n", (void *) cbf);
                     83:     if (list && cbf) {
                     84:        HTList *cur = list;
                     85:        HTAlert *pres;
                     86:        while ((pres = (HTAlert *) HTList_nextObject(cur))) {
                     87:            if (pres->cbf == cbf) {
                     88:                HTList_removeObject(list, (void *) pres);
                     89:                free(pres);
                     90:                return YES;
                     91:            }
                     92:        }
                     93:     }
                     94:     return NO;
                     95: }
2.28      frystyk    96: 
2.39      frystyk    97: /*     HTAlertCall_deleteAll
                     98: **     ---------------------
                     99: **     Unregisters all call back functions
                    100: */
                    101: PUBLIC BOOL HTAlertCall_deleteAll (HTList * list)
                    102: {
                    103:     if (WWWTRACE) 
                    104:        TTYPrint(TDEST, "Call delete All callback functions\n");
                    105:     if (list) {
                    106:        HTList *cur = list;
                    107:        HTAlert *pres;
                    108:        while ((pres = (HTAlert *) HTList_nextObject(cur))) {
                    109:            HTList_removeObject(list, (void *) pres);
                    110:            free(pres);
                    111:        }
                    112:        HTList_delete(list);
                    113:        return YES;
2.28      frystyk   114:     }
2.39      frystyk   115:     return NO;
                    116: }
                    117: 
                    118: /*     HTAlertCall_find
                    119: **     ----------------
                    120: **     Finds a callback function corresponding to the opcode. If none has
                    121: **     been registered then NULL is returned.
                    122: */
                    123: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
                    124: {
                    125:     if (list && HTInteractive) {
                    126:        HTAlert * pres;
                    127:        while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
                    128:            if (pres->opcode & opcode)
                    129:                return pres->cbf;
2.28      frystyk   130:        }
2.39      frystyk   131:        if (WWWTRACE)
                    132:            TTYPrint(TDEST, "Alert Find.. No entry found for opcode %d\n",opcode);
2.28      frystyk   133:     }
2.39      frystyk   134:     return NULL;
2.21      frystyk   135: }
                    136: 
2.39      frystyk   137: /*
                    138: **     Global List of Alert functions. list can be NULL
                    139: */
                    140: PUBLIC void HTAlert_setGlobal (HTList * list)
                    141: {
                    142:     HTMessages = list;
                    143: }
2.21      frystyk   144: 
2.39      frystyk   145: PUBLIC HTList * HTAlert_global (void)
1.1       timbl     146: {
2.39      frystyk   147:     return HTMessages;
1.1       timbl     148: }
                    149: 
2.39      frystyk   150: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1       timbl     151: {
2.39      frystyk   152:     if (!HTMessages) HTMessages = HTList_new();
                    153:     return HTAlertCall_add(HTMessages, cbf, opcode);
1.1       timbl     154: }
                    155: 
2.42      frystyk   156: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
                    157: {
                    158:     if (!HTMessages) HTMessages = HTList_new();
                    159:     return HTAlertCall_delete(HTMessages, cbf);
                    160: }
                    161: 
2.39      frystyk   162: /*     HTAlert_find
                    163: **     ------------
                    164: **     Finds a global callback function corresponding to the opcode
1.1       timbl     165: */
2.39      frystyk   166: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1       timbl     167: {
2.39      frystyk   168:     return HTAlertCall_find(HTMessages, opcode);
1.1       timbl     169: }
2.8       luotonen  170: 
2.39      frystyk   171: PUBLIC HTAlertPar * HTAlert_newReply (void)
                    172: {
                    173:     HTAlertPar * me = (HTAlertPar *) calloc(1, sizeof(HTAlertPar));
                    174:     if (!me) outofmem(__FILE__, "HTAlert_newReply");
                    175:     return me;
                    176: }
2.8       luotonen  177: 
2.39      frystyk   178: /*     HTAlert_deleteReply
                    179: **     -------------------
                    180: **     Delete reply structure but don't touch the replies themselves.
2.8       luotonen  181: */
2.39      frystyk   182: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8       luotonen  183: {
2.39      frystyk   184:     if (old) free(old);
2.11      luotonen  185: }
                    186: 
2.39      frystyk   187: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
                    188: {
                    189:     return me ? me->message : NULL;
                    190: }
2.11      luotonen  191: 
2.39      frystyk   192: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, CONST char * message)
2.11      luotonen  193: {
2.39      frystyk   194:     if (me && message) {
                    195:        StrAllocCopy(me->message, message);
                    196:        return YES;
                    197:     }
                    198:     return NO;
2.8       luotonen  199: }
                    200: 
2.43    ! frystyk   201: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
        !           202: {
        !           203:     if (me) me->message = message;
        !           204:     return YES;
        !           205: }
        !           206: 
2.39      frystyk   207: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
                    208: {
                    209:     return me ? me->secret : NULL;
                    210: }
2.21      frystyk   211: 
2.39      frystyk   212: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, CONST char * secret)
2.21      frystyk   213: {
2.39      frystyk   214:     if (me && secret) {
                    215:        StrAllocCopy(me->secret, secret);
                    216:        return YES;
                    217:     }
                    218:     return NO;
                    219: }
2.21      frystyk   220: 
2.39      frystyk   221: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
                    222: {
                    223:     return me ? me->output : NULL;
                    224: }
2.21      frystyk   225: 
2.39      frystyk   226: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
                    227: {
                    228:     if (me) {
                    229:        me->output = output;
                    230:        return YES;
2.21      frystyk   231:     }
2.39      frystyk   232:     return NO;
2.21      frystyk   233: }
2.38      frystyk   234: 
                    235: /*     TTYPrint
                    236: **     --------
                    237: **     Single function through which all trace messages must pass - EGP
                    238: */
2.41      frystyk   239: #if WWWTRACE_MODE == WWWTRACE_TTY && !defined(WWW_WIN_WINDOW)
2.40      frystyk   240: int TTYPrint(FILE* file, CONST char* fmt, ...)
2.38      frystyk   241: {
                    242:     int len;
                    243:     char space[513];
                    244:     char* pArgs;
                    245: 
                    246:     pArgs = (char*)(&fmt + 1);
                    247:     len = vsprintf(space, (char*)fmt, (char*)pArgs);
                    248:     fprintf(file, space);
                    249:     return (len);
                    250: }
2.39      frystyk   251: /* otherwise handled in www.c with the rest of the window stuff */
2.38      frystyk   252: #endif
2.39      frystyk   253: 

Webmaster