Advertisement
micha_b

shellstack.c

Apr 20th, 2023 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. /*
  2.     shellstack.c
  3.     Amiga User-Shell for command execution,
  4.     with customizable stack
  5.    
  6.     Micha B. 2023
  7.    
  8.     sc ICONS shellstack.c LINK TO shellstack
  9. */
  10. #include    <exec/types.h>
  11. #include    <exec/libraries.h>
  12. #include    <dos/dos.h>
  13. #include    <dos/dostags.h>
  14.  
  15. #include    <proto/exec.h>
  16. #include    <proto/dos.h>
  17. #include    <proto/intuition.h>
  18. #include    <proto/utility.h>
  19.  
  20. /* our function error codes for user shell functions */
  21. #define SYSTEMFAIL      (-1L)
  22. #define WINDOWFAIL      (-2L)
  23.  
  24. /* --- global vars --- */
  25. UBYTE *autocon="VNC:60/94/640/150/Micha B.'s Shell (executing STACK)/SHELL/AUTO/CLOSE/WAIT/ICONIFY";
  26.  
  27. /* --- Function prototypes --- */
  28. LONG beginCommand(UBYTE *command);
  29.  
  30. /*
  31.  * ASYNCH User Shell for command execution
  32.  */
  33. LONG beginCommand(UBYTE *command)
  34. {
  35.     struct TagItem stags[8];
  36.     BPTR file;
  37.  
  38.     if(file = Open(autocon, MODE_OLDFILE))
  39.         {
  40.         stags[0].ti_Tag = SYS_Input;        // what to execute?
  41.         stags[0].ti_Data = file;            // command to be executed
  42.         stags[1].ti_Tag = SYS_Output;
  43.         stags[1].ti_Data = NULL;
  44.         stags[2].ti_Tag = SYS_Asynch;       // asynchronous I/O
  45.         stags[2].ti_Data = TRUE;
  46.         stags[3].ti_Tag = SYS_UserShell;    // spawn own Shell
  47.         stags[3].ti_Data = TRUE;
  48.         stags[4].ti_Tag = NP_StackSize;     // inform to set own stacksize
  49.         stags[4].ti_Data = 32000L;          // own stack size for command execution
  50.         stags[7].ti_Tag = TAG_END;
  51.         return SystemTagList(command, stags);   // ...now execute given command or script!
  52.         }
  53.     else return(WINDOWFAIL);
  54. }
  55.  
  56.  
  57. int main(void)
  58. {
  59.     UBYTE *command;
  60.     long error;
  61.     extern struct DosLibrary *DOSBase;  
  62.    
  63.     /* open intuition.library */
  64.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 47L)))
  65.     {
  66.         Printf("This example requires intuition.library V47 or higher\n");
  67.         return RETURN_FAIL;
  68.     }
  69.    
  70.     Printf("I am a test program\nSo what?!...\n\n");
  71.     Printf("\n*** SystemTest: Asynchronous startup of 'Stack':\n");
  72.     command = "Stack";
  73.    
  74.     error = beginCommand(command);
  75.     Printf("error = %ld\n", error);
  76.        
  77.     /* close intuition.library */
  78.     CloseLibrary((struct Library *)IntuitionBase);
  79.    
  80.     return(RETURN_OK);
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement