Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Programme synchron/asynchron in Shell starten
- (öffnet sich selbstständig, wenn erforderlich!)
- */
- #include <exec/types.h>
- #include <exec/libraries.h>
- #include <dos/dos.h>
- #include <dos/dostags.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/intuition.h>
- #include <proto/utility.h>
- /* our function error codes for user shell functions */
- #define SYSTEMFAIL (-1L)
- #define WINDOWFAIL (-2L)
- LONG beginCommand(UBYTE *command); // asynchrone Ausgabe -> aufrufende Shell
- LONG doCommand(UBYTE *command, BPTR other); // synchrone Ausgabe mit AutoCon
- VOID checkResult(UBYTE *command, LONG result); // testet Rückgabewert der Shell
- /*
- * Synchronous external command (wait for return)
- * Uses your Input/Output unless you supply other handle
- * Result will be return code of the command, unless the System() call
- * itself fails, in which case the result will be -1
- */
- LONG doCommand(UBYTE *command, BPTR other)
- {
- struct TagItem stags[4];
- stags[0].ti_Tag = SYS_Input;
- stags[0].ti_Data = other ? other : Input();
- stags[1].ti_Tag = SYS_Output;
- stags[1].ti_Data = other ? NULL: Output();
- stags[3].ti_Tag = TAG_END;
- return System(command, stags);
- }
- /*
- * Asynchronous external command started with its own autocon Input/Output
- * This routine shows use of the SYS_UserShell tag as well.
- * Result will only reflect whether System() call itself succeeded.
- * If System() call fails, result will be -1L
- * We are using -2L as result if our Open of CON: fails
- */
- UBYTE *autocon="CON:60/94/640/150/My private Shell (burn after reading!)/shell/auto/close/wait";
- LONG beginCommand(UBYTE *command)
- {
- struct TagItem stags[5];
- BPTR file;
- if(file = Open(autocon, MODE_OLDFILE))
- {
- stags[0].ti_Tag = SYS_Input;
- stags[0].ti_Data = file;
- stags[1].ti_Tag = SYS_Output;
- stags[1].ti_Data = NULL;
- stags[2].ti_Tag = SYS_Asynch;
- stags[2].ti_Data = TRUE;
- stags[3].ti_Tag = SYS_UserShell;
- stags[3].ti_Data = TRUE;
- stags[4].ti_Tag = TAG_END;
- return System(command, stags);
- }
- else return(WINDOWFAIL);
- }
- /*
- * Demo routine outputs result of System
- */
- VOID checkResult(UBYTE *command, LONG result)
- {
- if(result == SYSTEMFAIL)
- Printf("*** SystemTest: could not start process for command\n");
- else if(result == WINDOWFAIL)
- Printf("*** SystemTest: can't open con: for command\n");
- else
- Printf("*** SystemTest: command (if synchronous) returned %ld\n",result);
- }
- /* -------- DEMO ---------------------------------------------------------------------- */
- int main()
- {
- extern struct DosLibrary *DOSBase;
- struct Screen *scr = NULL;
- struct Window *win = NULL;
- ULONG penspecterm = ~0;
- LONG result;
- BPTR file;
- UBYTE *command;
- UBYTE buf[128];
- if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39L)))
- {
- Printf("This example requires intuition.library V39 or higher\n");
- return RETURN_FAIL;
- }
- //Printf("\f");
- // SYNCHRONE Ausgabe an aufrufende Shell:
- Printf("\n*** SystemTest: Synchronous System call 'dir libs:':\n");
- command = "dir libs:";
- result = doCommand(command, NULL);
- checkResult(command,result);
- Printf("\n*** SystemTest: Synchronous System call of nonexistant command:\n");
- command = "badcommand";
- result = doCommand(command,NULL);
- checkResult(command,result);
- Printf("\n*** SystemTest: Synchronous System call 'ask \"...Answer y now\"':\n");
- command = "ask \"Ready for Asynchronous demo? Answer y now (should return 5):\"";
- result = doCommand(command,NULL);
- checkResult(command,result);
- Printf("\n*** SystemTest: Synchronous startup of 'avail':\n");
- command = "System:C/avail";
- result = doCommand(command, NULL);
- checkResult(command,result);
- /* ASYNCHRONOUS SYSTEM() WITH ON-DEMAND AUTO/WAIT CON:
- */
- Printf("\n*** SystemTest: Asynchronous startup of 'avail':\n");
- command = "Stack";
- result = beginCommand(command);
- checkResult(command,result);
- Printf("\n*** SystemTest: Asynchronous startup of 'Sys:Utilities/Clock':\n");
- command = "SYS:Utilities/Clock LEFT 2 TOP 15 WIDTH 150 HEIGHT 170 SECONDS DATE";
- result = beginCommand(command);
- checkResult(command,result);
- Printf("\n*** SystemTest: Asynchronous System call of nonexistant command:\n");
- command = "badcommand";
- result = beginCommand(command);
- checkResult(command,result);
- Printf("\nSystemTest exiting. Close Clock and AutoCon window when you wish.\n");
- CloseLibrary((struct Library *)IntuitionBase);
- return RETURN_OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement