Commit 714519b0cef06c449e59600305c648dab729f997

Authored by perry.werneck@gmail.com
1 parent a85d5f96

Evoluindo chamada do interpretador para o formato do Rexx4

Showing 1 changed file with 67 additions and 73 deletions   Show diff stats
src/plugins/rx3270/pluginmain.cc
... ... @@ -219,76 +219,17 @@
219 219 return lib3270_get_text(hSession,baddr,len);
220 220 }
221 221  
222   -extern "C"
223   -{
224   -
225   - static RXSTRING * build_args(const gchar **arg, size_t *argc)
226   - {
227   - size_t sz = g_strv_length((gchar **)arg);
228   - size_t szText = 0;
229   - gchar * ptr;
230   - int f;
231   - RXSTRING * rxArgs;
232   -
233   - for(f=0;f< (int) sz;f++)
234   - szText += strlen(arg[f])+1;
235   -
236   - *argc = sz;
237   - rxArgs = (RXSTRING *) g_malloc0((sizeof(RXSTRING) * (sz+1))+szText);
238   - ptr = (gchar *) &(rxArgs[sz+1]);
239   -
240   - for(f=0;f< (int) sz;f++)
241   - {
242   - strcpy(ptr,arg[f]);
243   -
244   - rxArgs[f].strptr = ptr;
245   - rxArgs[f].strlength = strlen(ptr);
246   - ptr += ((size_t) rxArgs[f].strlength+1);
247   - }
248   -
249   - return rxArgs;
250   - }
251   -
252 222 static void call_rexx_script(GtkAction *action, GtkWidget *widget, const gchar *filename)
253 223 {
254   - gchar * args = (gchar *) g_object_get_data(G_OBJECT(action),"args");
  224 + const gchar * args = (const gchar *) g_object_get_data(G_OBJECT(action),"args");
255 225  
256   - RXSTRING * rxArgs;
257   - int ret;
258   - short rc;
259   - size_t argc = 0;
260   - RXSTRING retstr;
261   - unsigned char userArea[10];
  226 + RexxInstance * instance;
  227 + RexxThreadContext * threadContext;
  228 + RexxOption options[25];
262 229  
263   - if(args)
264   - {
265   - gchar ** arg = g_strsplit(args,",",-1);
266   - rxArgs = build_args((const gchar **)arg,&argc);
267   - g_strfreev(arg);
268   - }
269   - else
270   - {
271   - static const gchar *arg[] = { "", NULL };
272   - rxArgs = build_args(arg,&argc);
273   - }
274   -
275   - // set up default return
276   - memset(&retstr,0,sizeof(retstr));
277   -
278   - memset(userArea,' ',10);
279   - userArea[9] = 0;
  230 + memset(options,0,sizeof(options));
280 231  
281   - ret = RexxStart( argc, // argument count
282   - (PCONSTRXSTRING) rxArgs, // argument array
283   - (char *) filename, // REXX procedure name
284   - (PRXSTRING) 0, // no instore used
285   - PACKAGE_NAME, // default address name
286   - RXCOMMAND, // calling as a subcommand
287   - NULL, // EXITs for this call
288   - &rc, // converted return code
289   - &retstr); // returned result
290   -
291   - if(ret)
  232 + if(!RexxCreateInterpreter(&instance, &threadContext, options))
292 233 {
293 234 GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
294 235 GTK_DIALOG_DESTROY_WITH_PARENT,
... ... @@ -296,25 +237,78 @@ extern &quot;C&quot;
296 237 GTK_BUTTONS_CANCEL,
297 238 "%s", _( "Can't start script" ));
298 239  
299   - gtk_window_set_title(GTK_WINDOW(dialog),_( "Startup error" ));
300   - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),_("Error %d starting rexx script"),ret);
  240 + gtk_window_set_title(GTK_WINDOW(dialog),_( "Rexx error" ));
  241 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",_( "Can't create rexx interpreter instance" ));
301 242  
302 243 gtk_dialog_run(GTK_DIALOG (dialog));
303 244 gtk_widget_destroy(dialog);
304   -
305 245 }
306 246 else
307 247 {
308   - RexxWaitForTermination();
309   - }
  248 + RexxArrayObject rxArgs;
  249 +
  250 + if(args)
  251 + {
  252 + gchar **arg = g_strsplit(args,",",-1);
  253 + size_t sz = g_strv_length(arg);
  254 +
  255 + rxArgs = threadContext->NewArray(sz);
  256 + for(unsigned int i = 0; i<sz; i++)
  257 + threadContext->ArrayPut(rxArgs, threadContext->String(arg[i]), i + 1);
  258 +
  259 + g_strfreev(arg);
  260 + }
  261 + else
  262 + {
  263 + rxArgs = threadContext->NewArray(1);
  264 + threadContext->ArrayPut(rxArgs, threadContext->String(""),1);
  265 + }
  266 +
  267 + RexxObjectPtr result = threadContext->CallProgram(filename, rxArgs);
  268 +
  269 + if (threadContext->CheckCondition())
  270 + {
  271 + RexxCondition condition;
310 272  
311   - if(RXSTRPTR(retstr))
312   - RexxFreeMemory(RXSTRPTR(retstr));
  273 + // retrieve the error information and get it into a decoded form
  274 + RexxDirectoryObject cond = threadContext->GetConditionInfo();
  275 + threadContext->DecodeConditionInfo(cond, &condition);
  276 + // display the errors
  277 + GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  278 + GTK_DIALOG_DESTROY_WITH_PARENT,
  279 + GTK_MESSAGE_ERROR,
  280 + GTK_BUTTONS_CANCEL,
  281 + "%s", _( "Script error" ));
313 282  
314   - g_free(rxArgs);
  283 + gtk_window_set_title(GTK_WINDOW(dialog),_( "System busy" ));
  284 +
  285 + gtk_message_dialog_format_secondary_text(
  286 + GTK_MESSAGE_DIALOG(dialog),
  287 + _( "Rexx error %d: %s\n%s" ),
  288 + (int) condition.code,
  289 + threadContext->CString(condition.errortext),
  290 + threadContext->CString(condition.message)
  291 +
  292 + );
  293 +
  294 + gtk_dialog_run(GTK_DIALOG (dialog));
  295 + gtk_widget_destroy(dialog);
  296 +
  297 + }
  298 + else if (result != NULLOBJECT)
  299 + {
  300 + CSTRING resultString = threadContext->CString(result);
  301 + lib3270_write_log(NULL,"REXX","%s exits with rc=%s",filename,resultString);
  302 + }
  303 +
  304 + instance->Terminate();
  305 + }
315 306  
316 307 }
317 308  
  309 +
  310 +extern "C"
  311 +{
318 312 LIB3270_EXPORT void pw3270_action_rexx_activated(GtkAction *action, GtkWidget *widget)
319 313 {
320 314 gchar *filename = (gchar *) g_object_get_data(G_OBJECT(action),"src");
... ...