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

2.18      frystyk     1: /*                                                                   HTAlert.c
                      2: **     DISPLAYING MESSAGES AND GETTING INPUT FOR LINEMODE BROWSER
                      3: **
                      4: **     (c) COPYRIGHT CERN 1994.
                      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
1.1       timbl      13: */
                     14: 
2.19    ! roeber     15: #include "sysdep.h"
        !            16: 
1.1       timbl      17: #include "HTAlert.h"
                     18: 
2.16      frystyk    19: PUBLIC BOOL HTInteractive=YES;             /* Any prompts from the Library? */
1.1       timbl      20: 
                     21: PUBLIC void HTAlert ARGS1(CONST char *, Msg)
                     22: {
2.19    ! roeber     23: #ifdef HAVE_NXRUNALERTPANEL
2.6       timbl      24:     NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
                     25: #else
1.1       timbl      26:     fprintf(stderr, "WWW Alert:  %s\n", Msg);
2.6       timbl      27: #endif
1.1       timbl      28: }
                     29: 
                     30: 
                     31: PUBLIC void HTProgress ARGS1(CONST char *, Msg)
                     32: {
                     33:     fprintf(stderr, "   %s ...\n", Msg);
                     34: }
                     35: 
                     36: 
                     37: PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
                     38: {
2.8       luotonen   39:   char Reply[4];       /* One more for terminating NULL -- AL */
1.1       timbl      40:   char *URep;
                     41:   
2.16      frystyk    42:   fprintf(stderr, "WWW: %s (y/n) ", Msg);         /* (y/n) came twice -- AL */
                     43:   if (!HTInteractive || !fgets(Reply, 4, stdin))   /* get reply, max 3 chars */
2.14      frystyk    44:       return NO;
1.1       timbl      45:   URep=Reply;
2.8       luotonen   46:   while (*URep) {
2.9       luotonen   47:     if (*URep == '\n') {
2.10      luotonen   48:        *URep = (char)0;        /* Overwrite newline */
2.9       luotonen   49:        break;
                     50:     }
2.8       luotonen   51:     *URep=TOUPPER(*URep);
                     52:     URep++;    /* This was previously embedded in the TOUPPER */
                     53:                 /* call an it became evaluated twice because   */
                     54:                 /* TOUPPER is a macro -- AL */
                     55:   }
                     56: 
1.1       timbl      57:   if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
                     58:     return(YES);
                     59:   else
                     60:     return(NO);
                     61: }
                     62: 
                     63: /*     Prompt for answer and get text back
                     64: */
                     65: PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
                     66: {
                     67:     char Tmp[200];
                     68:     char * rep = 0;
                     69:     fprintf(stderr, "WWW: %s", Msg);
2.8       luotonen   70:     if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
2.16      frystyk    71:     if (!HTInteractive || !fgets(Tmp, 200, stdin))
2.17      frystyk    72:        return NULL;                         /* NULL string on error, Henrik */
                     73:     Tmp[strlen(Tmp)-1] = (char) 0;                     /* Overwrite newline */
1.1       timbl      74:    
                     75:     StrAllocCopy(rep, *Tmp ? Tmp : deflt);
                     76:     return rep;
                     77: }
2.8       luotonen   78: 
                     79: 
                     80: /*     Prompt for password without echoing the reply
                     81: */
                     82: PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
                     83: {
                     84:     char *result = NULL;
2.16      frystyk    85:     char *pw;
2.13      luotonen   86: 
2.19    ! roeber     87: #ifdef HAVE_GETPASS
2.16      frystyk    88:     if (!HTInteractive)
                     89:        return "";
                     90:     pw = (char *) getpass(Msg ? Msg : "Password: ");
2.8       luotonen   91:     StrAllocCopy(result, pw);
                     92:     return result;
2.19    ! roeber     93: #else
        !            94:     return HTPrompt(Msg, NULL);
        !            95: #endif
        !            96: 
2.11      luotonen   97: }
                     98: 
                     99: 
                    100: /*     Prompt both username and password       HTPromptUsernameAndPassword()
                    101: **     ---------------------------------
                    102: ** On entry,
                    103: **     Msg             is the prompting message.
                    104: **     *username and
                    105: **     *password       are char pointers; they are changed
                    106: **                     to point to result strings.
                    107: **
                    108: **                     If *username is not NULL, it is taken
                    109: **                     to point to  a default value.
                    110: **                     Initial value of *password is
                    111: **                     completely discarded.
                    112: **
                    113: ** On exit,
                    114: **     *username and *password point to newly allocated
                    115: **     strings -- original strings pointed to by them
                    116: **     are NOT freed.
                    117: **     
                    118: */
                    119: PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *,    Msg,
                    120:                                              char **,          username,
                    121:                                              char **,          password)
                    122: {
2.16      frystyk   123:     if (!HTInteractive) {
                    124:        *username = "";
                    125:        *password = "";
                    126:        return;
                    127:     }
2.11      luotonen  128:     if (Msg)
                    129:        fprintf(stderr, "WWW: %s\n", Msg);
                    130:     *username = HTPrompt("Username: ", *username);
                    131:     *password = HTPromptPassword("Password: ");
2.8       luotonen  132: }
                    133: 

Webmaster