Annotation of libwww/Library/src/HTAlert.c, revision 2.17
1.1 timbl 1: /* Displaying messages and getting input for LineMode Browser
2: ** ==========================================================
3: **
4: ** REPLACE THIS MODULE with a GUI version in a GUI environment!
5: **
6: ** History:
7: ** Jun 92 Created May 1992 By C.T. Barker
8: ** Feb 93 Simplified, portablised TBL
2.8 luotonen 9: ** Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
1.1 timbl 10: */
11:
12: #include "HTAlert.h"
13:
2.16 frystyk 14: PUBLIC BOOL HTInteractive=YES; /* Any prompts from the Library? */
1.1 timbl 15:
16: PUBLIC void HTAlert ARGS1(CONST char *, Msg)
17: {
2.6 timbl 18: #ifdef NeXTStep
19: NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
20: #else
1.1 timbl 21: fprintf(stderr, "WWW Alert: %s\n", Msg);
2.6 timbl 22: #endif
1.1 timbl 23: }
24:
25:
26: PUBLIC void HTProgress ARGS1(CONST char *, Msg)
27: {
28: fprintf(stderr, " %s ...\n", Msg);
29: }
30:
31:
32: PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
33: {
2.8 luotonen 34: char Reply[4]; /* One more for terminating NULL -- AL */
1.1 timbl 35: char *URep;
36:
2.16 frystyk 37: fprintf(stderr, "WWW: %s (y/n) ", Msg); /* (y/n) came twice -- AL */
38: if (!HTInteractive || !fgets(Reply, 4, stdin)) /* get reply, max 3 chars */
2.14 frystyk 39: return NO;
1.1 timbl 40: URep=Reply;
2.8 luotonen 41: while (*URep) {
2.9 luotonen 42: if (*URep == '\n') {
2.10 luotonen 43: *URep = (char)0; /* Overwrite newline */
2.9 luotonen 44: break;
45: }
2.8 luotonen 46: *URep=TOUPPER(*URep);
47: URep++; /* This was previously embedded in the TOUPPER */
48: /* call an it became evaluated twice because */
49: /* TOUPPER is a macro -- AL */
50: }
51:
1.1 timbl 52: if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
53: return(YES);
54: else
55: return(NO);
56: }
57:
58: /* Prompt for answer and get text back
59: */
60: PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
61: {
62: char Tmp[200];
63: char * rep = 0;
64: fprintf(stderr, "WWW: %s", Msg);
2.8 luotonen 65: if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
2.16 frystyk 66: if (!HTInteractive || !fgets(Tmp, 200, stdin))
2.17 ! frystyk 67: return NULL; /* NULL string on error, Henrik */
! 68: Tmp[strlen(Tmp)-1] = (char) 0; /* Overwrite newline */
1.1 timbl 69:
70: StrAllocCopy(rep, *Tmp ? Tmp : deflt);
71: return rep;
72: }
2.8 luotonen 73:
74:
75: /* Prompt for password without echoing the reply
76: */
77: PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
78: {
79: char *result = NULL;
2.16 frystyk 80: char *pw;
2.13 luotonen 81:
2.16 frystyk 82: if (!HTInteractive)
83: return "";
84: pw = (char *) getpass(Msg ? Msg : "Password: ");
2.8 luotonen 85: StrAllocCopy(result, pw);
86: return result;
2.11 luotonen 87: }
88:
89:
90: /* Prompt both username and password HTPromptUsernameAndPassword()
91: ** ---------------------------------
92: ** On entry,
93: ** Msg is the prompting message.
94: ** *username and
95: ** *password are char pointers; they are changed
96: ** to point to result strings.
97: **
98: ** If *username is not NULL, it is taken
99: ** to point to a default value.
100: ** Initial value of *password is
101: ** completely discarded.
102: **
103: ** On exit,
104: ** *username and *password point to newly allocated
105: ** strings -- original strings pointed to by them
106: ** are NOT freed.
107: **
108: */
109: PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *, Msg,
110: char **, username,
111: char **, password)
112: {
2.16 frystyk 113: if (!HTInteractive) {
114: *username = "";
115: *password = "";
116: return;
117: }
2.11 luotonen 118: if (Msg)
119: fprintf(stderr, "WWW: %s\n", Msg);
120: *username = HTPrompt("Username: ", *username);
121: *password = HTPromptPassword("Password: ");
2.8 luotonen 122: }
123:
Webmaster