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

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) 
2.45    ! eric       64:        HTTrace("Alert Add... HTAlertCallback %p\n", (void *) cbf);
2.39      frystyk    65:     if (list && cbf) {
2.44      frystyk    66:        HTAlert *me;
                     67:        if ((me = (HTAlert  *) HT_CALLOC(1, sizeof(HTAlert))) == NULL)
                     68:            HT_OUTOFMEM("HTAlertCall_add");
2.39      frystyk    69:        me->cbf = cbf;
                     70:        me->opcode = opcode;
                     71:        return HTList_addObject(list, (void *) me);
                     72:     }
                     73:     return NO;
                     74: }
                     75: 
                     76: /*     HTAlertCall_delete
                     77: **     ------------------
                     78: **     Unregister a call back function from a list
                     79: */
                     80: PUBLIC BOOL HTAlertCall_delete (HTList * list, HTAlertCallback *cbf)
                     81: {
                     82:     if (WWWTRACE) 
2.45    ! eric       83:        HTTrace("Call delete HTAlertCallback %p\n", (void *) cbf);
2.39      frystyk    84:     if (list && cbf) {
                     85:        HTList *cur = list;
                     86:        HTAlert *pres;
                     87:        while ((pres = (HTAlert *) HTList_nextObject(cur))) {
                     88:            if (pres->cbf == cbf) {
                     89:                HTList_removeObject(list, (void *) pres);
2.44      frystyk    90:                HT_FREE(pres);
2.39      frystyk    91:                return YES;
                     92:            }
                     93:        }
                     94:     }
                     95:     return NO;
                     96: }
2.28      frystyk    97: 
2.39      frystyk    98: /*     HTAlertCall_deleteAll
                     99: **     ---------------------
                    100: **     Unregisters all call back functions
                    101: */
                    102: PUBLIC BOOL HTAlertCall_deleteAll (HTList * list)
                    103: {
                    104:     if (WWWTRACE) 
2.45    ! eric      105:        HTTrace("Call delete All callback functions\n");
2.39      frystyk   106:     if (list) {
                    107:        HTList *cur = list;
                    108:        HTAlert *pres;
                    109:        while ((pres = (HTAlert *) HTList_nextObject(cur))) {
                    110:            HTList_removeObject(list, (void *) pres);
2.44      frystyk   111:            HT_FREE(pres);
2.39      frystyk   112:        }
                    113:        HTList_delete(list);
                    114:        return YES;
2.28      frystyk   115:     }
2.39      frystyk   116:     return NO;
                    117: }
                    118: 
                    119: /*     HTAlertCall_find
                    120: **     ----------------
                    121: **     Finds a callback function corresponding to the opcode. If none has
                    122: **     been registered then NULL is returned.
                    123: */
                    124: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
                    125: {
                    126:     if (list && HTInteractive) {
                    127:        HTAlert * pres;
                    128:        while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
                    129:            if (pres->opcode & opcode)
                    130:                return pres->cbf;
2.28      frystyk   131:        }
2.39      frystyk   132:        if (WWWTRACE)
2.45    ! eric      133:            HTTrace("Alert Find.. No entry found for opcode %d\n",opcode);
2.28      frystyk   134:     }
2.39      frystyk   135:     return NULL;
2.21      frystyk   136: }
                    137: 
2.39      frystyk   138: /*
                    139: **     Global List of Alert functions. list can be NULL
                    140: */
                    141: PUBLIC void HTAlert_setGlobal (HTList * list)
                    142: {
                    143:     HTMessages = list;
                    144: }
2.21      frystyk   145: 
2.39      frystyk   146: PUBLIC HTList * HTAlert_global (void)
1.1       timbl     147: {
2.39      frystyk   148:     return HTMessages;
1.1       timbl     149: }
                    150: 
2.39      frystyk   151: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1       timbl     152: {
2.39      frystyk   153:     if (!HTMessages) HTMessages = HTList_new();
                    154:     return HTAlertCall_add(HTMessages, cbf, opcode);
1.1       timbl     155: }
                    156: 
2.42      frystyk   157: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
                    158: {
                    159:     if (!HTMessages) HTMessages = HTList_new();
                    160:     return HTAlertCall_delete(HTMessages, cbf);
                    161: }
                    162: 
2.39      frystyk   163: /*     HTAlert_find
                    164: **     ------------
                    165: **     Finds a global callback function corresponding to the opcode
1.1       timbl     166: */
2.39      frystyk   167: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1       timbl     168: {
2.39      frystyk   169:     return HTAlertCall_find(HTMessages, opcode);
1.1       timbl     170: }
2.8       luotonen  171: 
2.39      frystyk   172: PUBLIC HTAlertPar * HTAlert_newReply (void)
                    173: {
2.44      frystyk   174:     HTAlertPar * me;
                    175:     if ((me = (HTAlertPar  *) HT_CALLOC(1, sizeof(HTAlertPar))) == NULL)
                    176:         HT_OUTOFMEM("HTAlert_newReply");
2.39      frystyk   177:     return me;
                    178: }
2.8       luotonen  179: 
2.39      frystyk   180: /*     HTAlert_deleteReply
                    181: **     -------------------
                    182: **     Delete reply structure but don't touch the replies themselves.
2.8       luotonen  183: */
2.39      frystyk   184: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8       luotonen  185: {
2.44      frystyk   186:     if (old) HT_FREE(old);
2.11      luotonen  187: }
                    188: 
2.39      frystyk   189: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
                    190: {
                    191:     return me ? me->message : NULL;
                    192: }
2.11      luotonen  193: 
2.39      frystyk   194: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, CONST char * message)
2.11      luotonen  195: {
2.39      frystyk   196:     if (me && message) {
                    197:        StrAllocCopy(me->message, message);
                    198:        return YES;
                    199:     }
                    200:     return NO;
2.8       luotonen  201: }
                    202: 
2.43      frystyk   203: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
                    204: {
                    205:     if (me) me->message = message;
                    206:     return YES;
                    207: }
                    208: 
2.39      frystyk   209: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
                    210: {
                    211:     return me ? me->secret : NULL;
                    212: }
2.21      frystyk   213: 
2.39      frystyk   214: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, CONST char * secret)
2.21      frystyk   215: {
2.39      frystyk   216:     if (me && secret) {
                    217:        StrAllocCopy(me->secret, secret);
                    218:        return YES;
                    219:     }
                    220:     return NO;
                    221: }
2.21      frystyk   222: 
2.39      frystyk   223: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
                    224: {
                    225:     return me ? me->output : NULL;
                    226: }
2.21      frystyk   227: 
2.39      frystyk   228: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
                    229: {
                    230:     if (me) {
                    231:        me->output = output;
                    232:        return YES;
2.21      frystyk   233:     }
2.39      frystyk   234:     return NO;
2.21      frystyk   235: }
2.38      frystyk   236: 
                    237: /*     TTYPrint
                    238: **     --------
                    239: **     Single function through which all trace messages must pass - EGP
                    240: */
2.41      frystyk   241: #if WWWTRACE_MODE == WWWTRACE_TTY && !defined(WWW_WIN_WINDOW)
2.40      frystyk   242: int TTYPrint(FILE* file, CONST char* fmt, ...)
2.38      frystyk   243: {
                    244:     int len;
                    245:     char space[513];
                    246:     char* pArgs;
                    247: 
                    248:     pArgs = (char*)(&fmt + 1);
                    249:     len = vsprintf(space, (char*)fmt, (char*)pArgs);
                    250:     fprintf(file, space);
                    251:     return (len);
                    252: }
2.39      frystyk   253: /* otherwise handled in www.c with the rest of the window stuff */
2.38      frystyk   254: #endif
2.39      frystyk   255: 

Webmaster