Annotation of libwww/Library/src/HTAlert.c, revision 2.18.2.2
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 */
! 45: #ifdef 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:
67: /* Prompt for answer and get text back
68: */
69: PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
70: {
71: char Tmp[200];
72: char * rep = 0;
2.18.2.2! frystyk 73: fprintf(TDEST, "WWW: %s", Msg);
! 74: if (deflt) fprintf(TDEST, " (RETURN for [%s]) ", deflt);
! 75: #ifdef STDIO
2.16 frystyk 76: if (!HTInteractive || !fgets(Tmp, 200, stdin))
2.18.2.2! frystyk 77: #endif
2.17 frystyk 78: return NULL; /* NULL string on error, Henrik */
79: Tmp[strlen(Tmp)-1] = (char) 0; /* Overwrite newline */
1.1 timbl 80:
81: StrAllocCopy(rep, *Tmp ? Tmp : deflt);
82: return rep;
83: }
2.8 luotonen 84:
85:
2.18.2.2! frystyk 86: /* Prompt for password without echoing the reply. Returns pointer to
! 87: ** static buffer :-(
2.8 luotonen 88: */
89: PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
90: {
2.18.2.2! frystyk 91: static char result[MAXPASSWDLEN];
! 92: *result = '\0';
! 93: #ifdef GOT_PASSWD
! 94: if (HTInteractive) {
! 95: char *pw = (char *) getpass(Msg ? Msg : "Password: ");
! 96: strncpy(result, pw, MAXPASSWDLEN-1);
! 97: *(result+MAXPASSWDLEN-1) = '\0';
! 98: }
! 99: #endif
2.8 luotonen 100: return result;
2.11 luotonen 101: }
102:
103:
104: /* Prompt both username and password HTPromptUsernameAndPassword()
105: ** ---------------------------------
106: ** On entry,
107: ** Msg is the prompting message.
108: ** *username and
109: ** *password are char pointers; they are changed
110: ** to point to result strings.
111: **
112: ** If *username is not NULL, it is taken
113: ** to point to a default value.
114: ** Initial value of *password is
115: ** completely discarded.
116: **
117: ** On exit,
118: ** *username and *password point to newly allocated
119: ** strings -- original strings pointed to by them
120: ** are NOT freed.
121: **
122: */
123: PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *, Msg,
124: char **, username,
125: char **, password)
126: {
2.16 frystyk 127: if (!HTInteractive) {
128: *username = "";
129: *password = "";
130: return;
131: }
2.11 luotonen 132: if (Msg)
2.18.2.2! frystyk 133: fprintf(TDEST, "WWW: %s\n", Msg);
2.11 luotonen 134: *username = HTPrompt("Username: ", *username);
135: *password = HTPromptPassword("Password: ");
2.8 luotonen 136: }
137:
Webmaster