don't check when its clang masquerading as gcc
[AROS.git] / workbench / c / RequestString.c
blob859d281d7b127cafbd67d2200e937ce45b6b7a74
1 /*
2 Copyright © 2009-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Request string from user
6 */
8 /******************************************************************************
11 NAME
13 RequestString [STRING] [TEXT] [TITLE] [NOGADS] [WIDTH] [SAFE] [PERSIST]
14 [ENCRYPT] [COMPARE] [PUBSCREEN]
16 SYNOPSIS
18 STRING, TEXT/K, TITLE/K, NOGADS/S, WIDTH/N, SAFE/S, PERSIST/S,
19 ENCRYPT/S, COMPARE/K, PUBSCREEN/K
21 LOCATION
25 FUNCTION
27 Shows a requester with a string gadget for user input.
29 INPUTS
31 STRING -- Initial content of string gadget.
32 TEXT -- Label string.
33 TITLE -- Title string of requester. This also adds dragbar, closegadget
34 and a depthgadget.
35 NOGADS -- Suppress gadgets when TITLE argument is given.
36 WIDTH -- Minimal width as number of characters.
37 SAFE -- Hide user input with "*".
38 PERSIST -- Intuition is blocked until requester is quitted.
39 ENCRYPT -- Encrypt result before returning. Requires that one of these
40 environment variables is set: USER, USERNAME or LOGIN.
41 COMPARE -- If the input string is not equal to the argument
42 of COMPARE return WARN.
43 PUBSCREEN -- Open requester on given pubscreen.
45 RESULT
47 NOTES
49 EXAMPLE
51 BUGS
52 PERSIST doesn't allways work.
53 WIDTH not implemented.
55 SEE ALSO
57 INTERNALS
59 ******************************************************************************/
61 #include <aros/debug.h>
62 #include <libraries/mui.h>
64 #include <proto/dos.h>
65 #include <proto/intuition.h>
66 #include <proto/muimaster.h>
67 #include <clib/alib_protos.h>
69 #include <string.h>
71 AROS_UFH3(VOID, persistfunc,
72 AROS_UFPA(struct Hook * , hook, A0),
73 AROS_UFPA(Object * , obj, A2),
74 AROS_UFPA(Msg , msg, A1))
76 AROS_USERFUNC_INIT
78 DoMethod(obj, MUIM_Window_ScreenToFront);
79 DoMethod(obj, MUIM_Window_ToFront);
80 SET(obj, MUIA_Window_Activate, TRUE);
82 AROS_USERFUNC_EXIT
85 #define TEMPLATE "STRING,TEXT/K,TITLE/K,NOGADS/S,WIDTH/N,SAFE/S,PERSIST/S,ENCRYPT/S,COMPARE/K,PUBSCREEN/K"
87 enum {
88 ARG_STRING,
89 ARG_TEXT,
90 ARG_TITLE,
91 ARG_NOGADS,
92 ARG_WIDTH,
93 ARG_SAFE,
94 ARG_PERSIST,
95 ARG_ENCRYPT,
96 ARG_COMPARE,
97 ARG_PUBSCREEN,
98 ARG_COUNT
101 const char version[] = "\0$VER: RequestString 40.0 (24.10.2010)";
103 int main(void)
105 IPTR args[ARG_COUNT] = {0};
106 struct RDArgs *rdargs = NULL;
107 Object *app, *win, *string;
108 TEXT cbuffer[12], uname[48];
109 struct Hook persisthook = { {0} , 0, 0, 0};
110 STRPTR returntext = NULL;
111 BOOL havegads = FALSE;
112 LONG retval = RETURN_FAIL;
114 if ((rdargs = ReadArgs(TEMPLATE, args, NULL)) == NULL)
116 PrintFault(IoErr(), "RequestString");
117 return RETURN_FAIL;
120 if (args[ARG_TITLE] && !args[ARG_NOGADS])
122 havegads = TRUE;
125 app = ApplicationObject,
126 MUIA_Application_Title, "RequestString",
127 MUIA_Application_Version, version,
128 MUIA_Application_Copyright, "© 2009-2010 The AROS Development Team",
129 MUIA_Application_Author, "The AROS Development Team",
130 MUIA_Application_Description, "Request string from user",
131 MUIA_Application_Base, "REQUESTSTRING",
132 MUIA_Application_UseCommodities, FALSE,
133 MUIA_Application_UseRexx, FALSE,
134 SubWindow, win = WindowObject,
135 MUIA_Window_Title, args[ARG_TITLE], // safe to use with NULL
136 MUIA_Window_PublicScreen, args[ARG_PUBSCREEN], // silently ignored when NULL or not available
137 MUIA_Window_CloseGadget, havegads,
138 MUIA_Window_DepthGadget, havegads,
139 MUIA_Window_DragBar, havegads,
140 MUIA_Window_NoMenus, TRUE,
141 WindowContents, VGroup,
142 Child, TextObject,
143 MUIA_Text_PreParse, "\33c", // center text
144 MUIA_Text_Contents, args[ARG_TEXT], // safe to use with NULL
145 End,
146 Child, string = StringObject,
147 StringFrame,
148 MUIA_String_Contents, args[ARG_STRING], // safe to use with NULL
149 MUIA_String_Secret, args[ARG_SAFE],
150 End,
151 End,
152 End,
153 End;
155 if (app)
157 persisthook.h_Entry = (HOOKFUNC)persistfunc;
159 DoMethod
161 win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
162 app, 2,
163 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
165 DoMethod
167 string, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
168 app, 2,
169 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
172 if (args[ARG_PERSIST])
174 DoMethod
176 win, MUIM_Notify, MUIA_Window_Activate, FALSE,
177 win, 2,
178 MUIM_CallHook, &persisthook
182 SET(win, MUIA_Window_Open, TRUE);
183 SET(win, MUIA_Window_ActiveObject, string);
184 DoMethod(app, MUIM_Application_Execute);
186 returntext = (STRPTR)XGET(string, MUIA_String_Contents);
188 /* Try to find out who the user is if we are to encrypt the output.
189 * I really don't know how to acquire the username, but this might
190 * be a good guess of how to do it.
192 if (args[ARG_ENCRYPT] != 0)
194 if (GetVar("USER", uname, 47, 0) == -1)
195 if (GetVar("USERNAME", uname, 47, 0) == -1)
196 if (GetVar("LOGIN", uname, 47, 0) == -1)
197 uname[0] = 0;
198 ACrypt(cbuffer, returntext, uname);
199 returntext = cbuffer;
202 Printf("\"%s\"\n", returntext);
204 /* Here follows the COMPARE parameter. If the input string is not equal
205 * to the argument of COMPARE we return WARN.
207 if (args[ARG_COMPARE] != 0)
208 retval = (strcmp(returntext, (STRPTR)args[ARG_COMPARE])) ? RETURN_WARN : 0;
209 else
210 retval = 0;
212 MUI_DisposeObject(app);
215 return retval;