Annotation of libwww/Library/src/HTAlert.c, revision 2.15
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:
13: #include "HTAlert.h"
14:
15: #include "tcp.h" /* for TOUPPER */
16: #include <ctype.h> /* for toupper - should be in tcp.h */
17:
18: PUBLIC void HTAlert ARGS1(CONST char *, Msg)
19: {
2.6 timbl 20: #ifdef NeXTStep
21: NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
22: #else
1.1 timbl 23: fprintf(stderr, "WWW Alert: %s\n", Msg);
2.6 timbl 24: #endif
1.1 timbl 25: }
26:
27:
28: PUBLIC void HTProgress ARGS1(CONST char *, Msg)
29: {
30: fprintf(stderr, " %s ...\n", Msg);
31: }
32:
33:
34: PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
35: {
2.8 luotonen 36: char Reply[4]; /* One more for terminating NULL -- AL */
1.1 timbl 37: char *URep;
38:
39: fprintf(stderr, "WWW: %s (y/n) ", Msg);
2.8 luotonen 40: /* (y/n) came twice -- AL */
1.1 timbl 41:
2.14 frystyk 42: if (!fgets(Reply, 4, stdin)) /* get reply, max 3 characters */
43: return NO;
1.1 timbl 44: URep=Reply;
2.8 luotonen 45: while (*URep) {
2.9 luotonen 46: if (*URep == '\n') {
2.10 luotonen 47: *URep = (char)0; /* Overwrite newline */
2.9 luotonen 48: break;
49: }
2.8 luotonen 50: *URep=TOUPPER(*URep);
51: URep++; /* This was previously embedded in the TOUPPER */
52: /* call an it became evaluated twice because */
53: /* TOUPPER is a macro -- AL */
54: }
55:
1.1 timbl 56: if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
57: return(YES);
58: else
59: return(NO);
60: }
61:
62: /* Prompt for answer and get text back
63: */
64: PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
65: {
66: char Tmp[200];
67: char * rep = 0;
68: fprintf(stderr, "WWW: %s", Msg);
2.8 luotonen 69: if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
1.1 timbl 70:
2.14 frystyk 71: if (!fgets(Tmp, 200, stdin))
2.15 ! frystyk 72: return NULL; /* NULL string on error, Henrik */
2.10 luotonen 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.13 luotonen 85: char *pw = (char*)getpass(Msg ? Msg : "Password: ");
86:
2.8 luotonen 87: StrAllocCopy(result, pw);
88: return result;
2.11 luotonen 89: }
90:
91:
92: /* Prompt both username and password HTPromptUsernameAndPassword()
93: ** ---------------------------------
94: ** On entry,
95: ** Msg is the prompting message.
96: ** *username and
97: ** *password are char pointers; they are changed
98: ** to point to result strings.
99: **
100: ** If *username is not NULL, it is taken
101: ** to point to a default value.
102: ** Initial value of *password is
103: ** completely discarded.
104: **
105: ** On exit,
106: ** *username and *password point to newly allocated
107: ** strings -- original strings pointed to by them
108: ** are NOT freed.
109: **
110: */
111: PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *, Msg,
112: char **, username,
113: char **, password)
114: {
115: if (Msg)
116: fprintf(stderr, "WWW: %s\n", Msg);
117: *username = HTPrompt("Username: ", *username);
118: *password = HTPromptPassword("Password: ");
2.8 luotonen 119: }
120:
Webmaster