Annotation of libwww/Library/src/HTAlert.c, revision 2.18.2.1
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:
15: #include "HTAlert.h"
16:
2.16 frystyk 17: PUBLIC BOOL HTInteractive=YES; /* Any prompts from the Library? */
1.1 timbl 18:
19: PUBLIC void HTAlert ARGS1(CONST char *, Msg)
20: {
2.6 timbl 21: #ifdef NeXTStep
22: NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
23: #else
2.18.2.1! frystyk 24: fprintf(stderr, "\nWWW Alert: %s\n", Msg);
2.6 timbl 25: #endif
1.1 timbl 26: }
27:
28:
29: PUBLIC void HTProgress ARGS1(CONST char *, Msg)
30: {
31: fprintf(stderr, " %s ...\n", Msg);
32: }
33:
34:
35: PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
36: {
2.8 luotonen 37: char Reply[4]; /* One more for terminating NULL -- AL */
1.1 timbl 38: char *URep;
39:
2.16 frystyk 40: fprintf(stderr, "WWW: %s (y/n) ", Msg); /* (y/n) came twice -- AL */
41: if (!HTInteractive || !fgets(Reply, 4, stdin)) /* get reply, max 3 chars */
2.14 frystyk 42: return NO;
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);
2.16 frystyk 69: if (!HTInteractive || !fgets(Tmp, 200, stdin))
2.17 frystyk 70: return NULL; /* NULL string on error, Henrik */
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.16 frystyk 83: char *pw;
2.13 luotonen 84:
2.16 frystyk 85: if (!HTInteractive)
86: return "";
87: pw = (char *) getpass(Msg ? Msg : "Password: ");
2.8 luotonen 88: StrAllocCopy(result, pw);
89: return result;
2.11 luotonen 90: }
91:
92:
93: /* Prompt both username and password HTPromptUsernameAndPassword()
94: ** ---------------------------------
95: ** On entry,
96: ** Msg is the prompting message.
97: ** *username and
98: ** *password are char pointers; they are changed
99: ** to point to result strings.
100: **
101: ** If *username is not NULL, it is taken
102: ** to point to a default value.
103: ** Initial value of *password is
104: ** completely discarded.
105: **
106: ** On exit,
107: ** *username and *password point to newly allocated
108: ** strings -- original strings pointed to by them
109: ** are NOT freed.
110: **
111: */
112: PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *, Msg,
113: char **, username,
114: char **, password)
115: {
2.16 frystyk 116: if (!HTInteractive) {
117: *username = "";
118: *password = "";
119: return;
120: }
2.11 luotonen 121: if (Msg)
122: fprintf(stderr, "WWW: %s\n", Msg);
123: *username = HTPrompt("Username: ", *username);
124: *password = HTPromptPassword("Password: ");
2.8 luotonen 125: }
126:
Webmaster