/*- Author: Brian Tiffin Dedicated to the public domain Date started: December 2016 Modified: 2016-12-16/22:39-0500 +*/ /* Unicon integration with Open Object Rexx, classic C API */ /* tectonics: gcc -o unirexx.so -shared -fPIC unirexx.c */ #include #include #include "icall.h" int unirexx(int argc, descriptor argv[]) { int rc; /* RexxStart fields */ size_t ArgCount = 0; PCONSTRXSTRING ArgList = NULL; const char *ProgramName; PRXSTRING PassStore; RXSTRING Instore[2]; const char *EnvName = NULL; int CallType = RXCOMMAND; PRXSYSEXIT Exits = NULL; short ReturnCode; RXSTRING Result; char returnBuffer[256]; /* Need a Rexx ProgramName and/or Instore evaluation string */ fprintf(stderr, "argc: %d\n", argc); fflush(stderr); if (argc < 1) Error(105); /* Need a filename or PARSE SOURCE */ ArgString(1); /* Second string is optional, will be text to interpret */ if (argc > 1) ArgString(2); /* Instore is two Rexx string descriptors */ /* one for the text and second for precompiled image */ /* no precompiled image is used here */ RXNULLSTRING(Instore[0]); RXNULLSTRING(Instore[1]); if (argc > 1) { MAKERXSTRING(Instore[0], StringVal(argv[2]), StringLen(argv[2])); PassStore = &Instore[0]; } else { /* If only the file name is passed, Instore is NULL */ PassStore = NULL; } /* set up initial Result string space, Rexx may allocate its own */ MAKERXSTRING(Result, returnBuffer, sizeof(returnBuffer)); rc = RexxStart(ArgCount, ArgList, StringVal(argv[1]), PassStore, EnvName, CallType, Exits, &ReturnCode, &Result); fprintf(stderr, "RexxStart rc: %d\nRexx ReturnCode: %d, Result: %s\n", rc, ReturnCode, RXSTRPTR(Result)); fflush(stderr); /* A RetStringN, but Rexx may need to free the space */ argv[0].dword = Result.strlength; argv[0].vword.sptr = alcstr(RXSTRPTR(Result), RXSTRLEN(Result)); /* Rexx may have decided to allocate a return result space */ if (RXSTRPTR(Result) != returnBuffer) { RexxFreeMemory(RXSTRPTR(Result)); } Return; }