Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!sunic!tut!korppi.tut.fi!av74381 From: av74381@korppi.tut.fi (Vesterinen Arto) Newsgroups: comp.sys.atari.st Subject: Calling callgulam from TC Message-ID: <11368@etana.tut.fi> Date: 28 Feb 90 11:11:16 GMT Sender: News@tut.fi Reply-To: av74381@korppi.tut.fi (Vesterinen Arto) Organization: Tampere University of Technology, Finland Lines: 246 I have been developing a Turbo-C program which will transfer usenet articles to my BBS. They are received as packets which are archieved using zoo. Host will send them using zmodem. I decided to do the receiving using my humble servant Gulam. Gulam would start zmodem at receiving end and then extract articles from zoo. Unfortunately have not been able to call gulam from a Turbo-C program. I have tried out Michal Jaegermann's method for MWC but it does not work out for TC. If anyone has figured out how to call gulam from TC, please e-mail me how to do it. I just do not understand why my example works for MWC but not with TC, it gives me two warning messages when I compile it: Call to function with no prototype in main. Lines where I get the warnings are those where I call gulam (* gcp) ("command");. When I try to run the program It prints out "-Start of test-" and then comes out two bombs (bus error). -----------This is what I tried out with Turbo C ---------------- #include #include #include #include #define SHELLP ((char **) 0x04f6L) #define G_MAGIC 0x0135 int main() { long save_ssp; short sh_magic; char *tgptr; /* storage for togu_ */ /* if you really would like to have it right, then */ /* tgptr should be a pointer to void - */ /* a bit of overkill on ST :-) */ int (* cgp)(); /* pointer to callgulam() */ /* also contains togu_, but */ /* a type is different */ fprintf(stderr, "Welcome to callgulam demo.\n"); save_ssp = Super(0L); tgptr = *SHELLP; Super((void *)save_ssp); if (G_MAGIC != (sh_magic = *((short *)(tgptr - 8)))) { fprintf (stderr, "wrong magic value %x\n", sh_magic); return(1); } cgp = *((int (*)()) tgptr); printf("-Start of test-\n"); (* cgp)("echo 'executing ls'"); (* cgp)("ls"); printf("-End of test-\n"); return(0); } ---------- Michal's original posting follows -------------------------- # this example is for Mark Williams C From myrias!mj Thu Oct 20 15:44:19 EDT 1988 X-RN-Article: 12125 of comp.sys.atari.st >From: mj@myrias.UUCP (Michal Jaegermann) Newsgroups: comp.sys.atari.st Subject: Calling callgulam - explanation and example keywords: gulam, shell Date: 19 Oct 88 23:47:47 GMT Organization: Myrias Research, Edmonton (Whatever is described below was checked for a gulam version which identifies itself as: xD beta test version 1.03.04.05 121887 of yet another shell for AtariST/TOS Your mileage may vary!!) As you may not know, a very popular Gulam shell (many thanks to Prabhaker Mateti and Jwahar R. Bammi). includes quite powerful facility to invoke gulam services from a program started from gulam. In contrast to many others shells floating aroung this is not done by executing the next incarnation of gulam. Instead there are provided two pointers which provide execution 'hooks' for all gulam commands. A bright sight is that this approach does not take any extra memory and a start-up time is negligible. A dark side is that documentation describing this facility is either misleading or plainly wrong. (As an aside - this is, alas, not the only place in documentation requiring touch-up. For this version, gulam.hlp, for example, does not correspond very well tp reality). This note is a kind of erratum, which, hopefuly, will help to clarify an ensuing confusion, which seems to be quite widespread. When you are running Gulam a TOS variable '_shell_p', at 0x4f6, contains an address of a location named 'togu_', which is the last entry in a 16 byte long table. The format of the table is (this is mostly quoted from the documentation): .long 0x86420135 / our magic number (4 bytes) jmp getlineviaue_ / 0x4ef9,address (6 bytes) togu_: jmp callgulam_ / 0x4ef9,address (6 bytes) It clearly follows from that that magic number is located 10 bytes before 'togu_' and not, the documentation suggested, 12. What's more, the magic number should be equal *(long *)(*(char **)0x4f6 - 10), instead of a given *((long *)0x46fL - 12L), which will produce a value from an address way off. On the top of it, an actual magic number in my copy of Gulam is not like the documented but it equals 0x00420135. Use Gulam 'peekw' to check what you got. To be on a safe side, until the matter is fully clarified, I am using only a lower half of the magic number, which seems to be correct; i.e. short_magic = *(short *)(*(char **)0x4f6-8). Two other items in the table are entry points to two functions 'getlineviaue' and 'callgulam'. The information given in the documentation about them is mostly correct, with a similar mix-up in a calculation of an address of entry to 'getlineviaue', like the one described above. Also, strictly speaking, 'getlinevalue' does not return anything, since it is declared as 'void'. As a side effect it modifies a contents of a user supplied buffer, copying there a contents of a command line. It would be probably more convenient if, instead of being void, it would return something useful, say a number of copied characters, but it doesn't, so we may have to live with that. Just to make our life more interesting, the other function, 'callgulam', returns 'int' - the return status of an executed command. This makes wonders to types of your pointers. See the supplied program example for to see how to cast. All of this to ensure that your C-compiler will not get totally lost. If you have a compiler which accepts the stuff in a form from an original docs - replace your compiler. Fast! (As an aside - all this pointer play would be easier in assembler, if you feel so inclined). While experimenting whith the program example try the following. Call 'ue' on some file, position cursor somewher down the text and stop editor with ^Z. Try some other commands and upon return to Gulam type 'fg'. Repeat experiment stopping the editor in Gulam and typing 'fg' from the demo program prompt. Don't you think that this is a nice way to run editor for your, say, Lisp interpreter? Some things are still missing. One cannot tell 'ue', on a command line, to load a file and go to the line 247. Or there is a way and I am simply not aware of it? And I know of no way to grab a result of a command, stuff it into a variable and use it for a test of conditional script execution. Oh well, maybe in some future release... Two other, non-interactive, ways of calling Gulam are also mentioned in docs. I did not try 'Pexec method', but attempts to execute gulam as a program with arguments, as described, produced only nonsensical error messages about 'invalid regexp' and error number -33. Can anybody shed some light on that matter? Michal Jaegermann Myrias Research Corporation Edmonton, Alberta, CANADA ...alberta!myrias!mj (or you may try mj@myrias.UUCP) ------------------------------------------------------------------------------ /* * A demo program to show a usage of Gulam 'hooks' - call from * Gulam shell! When asked, try different gulam commands, ue * in particular. * * A numbers of pointers floating around is a little bit higher * than necessary, but we will waiste some memore for the sake * of clarity. * * Michal Jaegermann, October 1988 */ #include #include #include #define SHELLP ((char **) 0x04f6L) #define G_MAGIC 0x0135 main() { long save_ssp; short sh_magic; char buf[258]; char *tgptr; /* storage for togu_ */ /* if you really would like to have it right, then */ /* tgptr should be a pointer to void - */ /* a bit of overkill on ST :-) */ int (* cgp)(); /* pointer to callgulam() */ /* also contains togu_, but */ /* a type is different */ void (* glp)(); /* pointer to getlineviaue() */ fprintf(stderr, "Welcome to callgulam demo.\n"); save_ssp = Super(0L); tgptr = *SHELLP; Super(save_ssp); if (G_MAGIC != (sh_magic = *((short *)(tgptr - 8)))) { fprintf (stderr, "wrong magic value %x\n", sh_magic); exit (1); } cgp = *((int (*)()) tgptr); glp = *((void (*)()) (tgptr - 6)); (* cgp)("echo 'test of Gulam'"); (* cgp)("echo 'executing ls -l'"); (* cgp)("ls -l"); (* cgp)("echo '-----------------'"); (* cgp)("ls -R -t a:\\ "); (* cgp)("echo ' '"); (* cgp)("echo ' '"); (* cgp)("set tmp_old_prompt $prompt"); (* cgp)("set prompt 'At your service, Sir!'"); /* change a gender if a need will arise */ (* cgp)("echo 'Awaiting your commands!!'"); /* the following loop will cycle until it will get an empty line */ while ((* glp)(buf), putchar('\n'), 0 != strlen(buf)) { /* the new line not supplied */ /* by Gulam - DIY, mate */ (* cgp)(buf); } (* cgp)("set prompt $tmp_old_prompt"); (* cgp)("unset tmp_old_prompt"); fprintf (stderr,"\nNice talking to you, see you later.\n"); exit(0); } /* -----------------/ that is all for today /--------------------- */ -- Michal Jaegermann Myrias Research Corporation Edmonton, Alberta, CANADA ...{ihnp4, ubc-vision}!elberta!myrias!mj ------------------------------------------------------------------- I Arto Vesterinen I Internet av74381@tut.fi I I Tampere University of Technology I UUCP tut!av74381 I I Finland I Bitnet av74381@fintut I