Annotation of libwww/Library/src/HTAlert.c, revision 2.13
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.9 luotonen 42: fgets(Reply, 4, stdin); /* get reply, max 3 characters */
1.1 timbl 43: URep=Reply;
2.8 luotonen 44: while (*URep) {
2.9 luotonen 45: if (*URep == '\n') {
2.10 luotonen 46: *URep = (char)0; /* Overwrite newline */
2.9 luotonen 47: break;
48: }
2.8 luotonen 49: *URep=TOUPPER(*URep);
50: URep++; /* This was previously embedded in the TOUPPER */
51: /* call an it became evaluated twice because */
52: /* TOUPPER is a macro -- AL */
53: }
54:
1.1 timbl 55: if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
56: return(YES);
57: else
58: return(NO);
59: }
60:
61: /* Prompt for answer and get text back
62: */
63: PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
64: {
65: char Tmp[200];
66: char * rep = 0;
67: fprintf(stderr, "WWW: %s", Msg);
2.8 luotonen 68: if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
1.1 timbl 69:
2.9 luotonen 70: fgets(Tmp, 200, stdin);
2.10 luotonen 71: Tmp[strlen(Tmp)-1] = (char)0; /* Overwrite newline */
1.1 timbl 72:
73: StrAllocCopy(rep, *Tmp ? Tmp : deflt);
74: return rep;
75: }
2.8 luotonen 76:
77:
78: /* Prompt for password without echoing the reply
79: */
80: PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
81: {
82: char *result = NULL;
2.13 ! luotonen 83: char *pw = (char*)getpass(Msg ? Msg : "Password: ");
! 84:
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: {
113: if (Msg)
114: fprintf(stderr, "WWW: %s\n", Msg);
115: *username = HTPrompt("Username: ", *username);
116: *password = HTPromptPassword("Password: ");
2.8 luotonen 117: }
118:
Webmaster