2 Copyright © 2009-2010, The AROS Development Team. All rights reserved.
5 Desc: Request string from user
8 /******************************************************************************
13 RequestString [STRING] [TEXT] [TITLE] [NOGADS] [WIDTH] [SAFE] [PERSIST]
14 [ENCRYPT] [COMPARE] [PUBSCREEN]
18 STRING, TEXT/K, TITLE/K, NOGADS/S, WIDTH/N, SAFE/S, PERSIST/S,
19 ENCRYPT/S, COMPARE/K, PUBSCREEN/K
27 Shows a requester with a string gadget for user input.
31 STRING -- Initial content of string gadget.
33 TITLE -- Title string of requester. This also adds dragbar, closegadget
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.
52 PERSIST doesn't allways work.
53 WIDTH not implemented.
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>
71 AROS_UFH3(VOID
, persistfunc
,
72 AROS_UFPA(struct Hook
* , hook
, A0
),
73 AROS_UFPA(Object
* , obj
, A2
),
74 AROS_UFPA(Msg
, msg
, A1
))
78 DoMethod(obj
, MUIM_Window_ScreenToFront
);
79 DoMethod(obj
, MUIM_Window_ToFront
);
80 SET(obj
, MUIA_Window_Activate
, TRUE
);
85 #define TEMPLATE "STRING,TEXT/K,TITLE/K,NOGADS/S,WIDTH/N,SAFE/S,PERSIST/S,ENCRYPT/S,COMPARE/K,PUBSCREEN/K"
101 const char version
[] = "\0$VER: RequestString 40.0 (24.10.2010)";
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");
120 if (args
[ARG_TITLE
] && !args
[ARG_NOGADS
])
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
,
143 MUIA_Text_PreParse
, "\33c", // center text
144 MUIA_Text_Contents
, args
[ARG_TEXT
], // safe to use with NULL
146 Child
, string
= StringObject
,
148 MUIA_String_Contents
, args
[ARG_STRING
], // safe to use with NULL
149 MUIA_String_Secret
, args
[ARG_SAFE
],
157 persisthook
.h_Entry
= (HOOKFUNC
)persistfunc
;
161 win
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
163 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
167 string
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
169 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
172 if (args
[ARG_PERSIST
])
176 win
, MUIM_Notify
, MUIA_Window_Activate
, FALSE
,
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)
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;
212 MUI_DisposeObject(app
);