Annotation of libwww/Library/src/HTAlert.c, revision 2.11
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.11 ! luotonen 83: char *pw = (char*)getpass(Msg ? Msg : "Password: ");
2.8 luotonen 84: StrAllocCopy(result, pw);
85: return result;
2.11 ! luotonen 86: }
! 87:
! 88:
! 89: /* Prompt both username and password HTPromptUsernameAndPassword()
! 90: ** ---------------------------------
! 91: ** On entry,
! 92: ** Msg is the prompting message.
! 93: ** *username and
! 94: ** *password are char pointers; they are changed
! 95: ** to point to result strings.
! 96: **
! 97: ** If *username is not NULL, it is taken
! 98: ** to point to a default value.
! 99: ** Initial value of *password is
! 100: ** completely discarded.
! 101: **
! 102: ** On exit,
! 103: ** *username and *password point to newly allocated
! 104: ** strings -- original strings pointed to by them
! 105: ** are NOT freed.
! 106: **
! 107: */
! 108: PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *, Msg,
! 109: char **, username,
! 110: char **, password)
! 111: {
! 112: if (Msg)
! 113: fprintf(stderr, "WWW: %s\n", Msg);
! 114: *username = HTPrompt("Username: ", *username);
! 115: *password = HTPromptPassword("Password: ");
2.8 luotonen 116: }
117:
Webmaster