earlybrowserreborn - Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 roytam 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
9 **         Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
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 {
20 #ifdef NeXTStep
21     NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
22 #else
23     user_alert(Msg);
24 /*    fprintf(stderr, "WWW Alert:  %s\n", Msg);*/
25 #endif
26 }
27  
28  
29 PUBLIC void HTProgress ARGS1(CONST char *, Msg)
30 {
31     user_message(Msg);
32 /*  fprintf(stderr, "   %s ...\n", Msg);
33 */
34 }
35  
36  
37 PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
38 {
39     if (user_message_confirm(Msg)) return YES;
40     else return NO;
41  
42 #ifdef TTYMODE
43   char Reply[4];        /* One more for terminating NULL -- AL */
44   char *URep;
45  
46   fprintf(stderr, "WWW: %s (y/n) ", Msg);
47                        /* (y/n) came twice -- AL */
48  
49   fgets(Reply, 4, stdin); /* get reply, max 3 characters */
50   URep=Reply;
51   while (*URep) {
52     if (*URep == '\n') {
53         *URep = (char)0;        /* Overwrite newline */
54         break;
55     }
56     *URep=TOUPPER(*URep);
57     URep++;     /* This was previously embedded in the TOUPPER */
58                 /* call an it became evaluated twice because   */
59                 /* TOUPPER is a macro -- AL */
60   }
61  
62   if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
63     return(YES);
64   else
65     return(NO);
66 #endif
67 }
68  
69 /*      Prompt for answer and get text back
70 */
71 PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
72 {
73     return user_prompt_default(Msg, deflt);
74  
75 #ifdef TTYMODE
76     char Tmp[200];
77     char * rep = 0;
78     fprintf(stderr, "WWW: %s", Msg);
79     if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
80  
81     fgets(Tmp, 200, stdin);
82     Tmp[strlen(Tmp)-1] = (char)0;       /* Overwrite newline */
83  
84     StrAllocCopy(rep, *Tmp ? Tmp : deflt);
85     return rep;
86 #endif
87 }
88  
89  
90 /*      Prompt for password without echoing the reply
91 */
92 PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
93 {
94     return user_prompt_password(Msg);
95  
96 #ifdef TTYMODE
97     char *result = NULL;
98     char *pw = (char*)getpass(Msg ? Msg : "Password: ");
99  
100     StrAllocCopy(result, pw);
101     return result;
102 #endif
103 }
104  
105  
106 /*      Prompt both username and password       HTPromptUsernameAndPassword()
107 **      ---------------------------------
108 ** On entry,
109 **      Msg             is the prompting message.
110 **      *username and
111 **      *password       are char pointers; they are changed
112 **                      to point to result strings.
113 **
114 **                      If *username is not NULL, it is taken
115 **                      to point to  a default value.
116 **                      Initial value of *password is
117 **                      completely discarded.
118 **
119 ** On exit,
120 **      *username and *password point to newly allocated
121 **      strings -- original strings pointed to by them
122 **      are NOT freed.
123 **     
124 */
125 PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *,     Msg,
126                                               char **,          username,
127                                               char **,          password)
128 {
129     user_prompt_username_and_password(Msg, username, password);
130  
131 #ifdef TTYMODE
132     if (Msg)
133         fprintf(stderr, "WWW: %s\n", Msg);
134     *username = HTPrompt("Username: ", *username);
135     *password = HTPromptPassword("Password: ");
136 #endif
137 }
138