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