home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / amiga / programm / 11739 < prev    next >
Encoding:
Text File  |  1992-07-28  |  4.0 KB  |  139 lines

  1. Organization: Pittsburgh Supercomputing Center, Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!eb15+
  3. Newsgroups: comp.sys.amiga.programmer
  4. Message-ID: <MeRMtnC00WB78cLkMF@andrew.cmu.edu>
  5. Date: Tue, 28 Jul 1992 14:14:11 -0400 
  6. From: "Edward D. Berger" <eb15+@andrew.cmu.edu>
  7. Subject: Still confused about System() and paths...
  8. Lines: 129
  9.  
  10. I guess I don't really understand AmigaDOS data structures, especially
  11. BPTRs, TagItems, etc.
  12.  
  13. I want to add a simple "execute AmigaDOS Command" function to my program,
  14. and for it to have a valid search path without regards to it being started
  15. from a CLI or from Workbench.  The following program loses its path from
  16. the CLI, and starts to give a search path for Workbench then green screen.
  17. Anyone want to fix it?
  18.  
  19. ;/* MySys.c - Execute me to compile me with SAS/C 5.10a
  20. ;   Demonstration of System(), AUTO CON, and broken paths from Workbench
  21. LC -b1 -cfistq -v -y -j73 mysys.c
  22. Blink FROM LIB:c.o,mysys.o TO MySys LIBRARY LIB:LC.lib,LIB:Amiga.lib
  23. quit
  24. */
  25.  
  26. #include <exec/types.h>
  27. #include <exec/memory.h>
  28. #include <exec/libraries.h>
  29. #include <dos/dos.h>
  30. #include <dos/dosextens.h>
  31. #include <dos/dostags.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37.  
  38. #ifdef LATTICE
  39. #include <clib/intuition_protos.h>
  40. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  41. int chkabort(void) { return(0); }  /* really */
  42. #endif
  43.  
  44. /* our function error codes */
  45. #define SYSTEMFAIL      (-1L)
  46. #define WINDOWFAIL      (-2L)
  47.  
  48.  
  49. /* function prototypes */
  50. LONG beginCommand( UBYTE *command );
  51. BPTR CopyPath( char *tass );
  52. /* Formatted version string for the 2.0 VERSION command */
  53. UBYTE *vers = "\0$VER: mysys_is_broken 0.01";
  54. /* global BPTR, so that beginCommand can use it? */
  55. BPTR wb_path = NULL;
  56.  
  57.  
  58. int main(int argc, char **argv)
  59.     {
  60.     extern struct Library *DOSBase;
  61.  
  62.     LONG result;
  63.     UBYTE *command;
  64.  
  65.     if(DOSBase->lib_Version < 36)
  66.         {
  67.         printf("This example requires dos.library V36 or higher\n");
  68.         exit(RETURN_FAIL);
  69.         }
  70.  
  71.     if( argc == 0 )  /* We are a child of Workbench? */
  72.       {
  73.        printf("Started from Workbench, Searching for Path! \n");
  74.        Forbid();
  75.        wb_path = CopyPath("Workbench");
  76.        Permit();
  77.       }
  78.  
  79.     /* ASYNCHRONOUS SYSTEM() WITH ON-DEMAND AUTO/WAIT CON:
  80.      */
  81.     printf("\n*** SystemTest: Asynchronous startup of 'path':\n");
  82.     command = "path";
  83.     result = beginCommand(command);
  84.  
  85.     printf("\nSystemTest exiting. Close Shell and Autocon window when you wish.\n");
  86.  
  87.     /* So we can see what the SAS/C stdio window for Workbench prints out */
  88.     Delay(500);
  89.  
  90.     exit(RETURN_OK);
  91.     }
  92.  
  93. UBYTE *autocon="CON:0/40/640/150/Auto CON Window Opens if Needed/auto/close/wait";
  94. LONG beginCommand( UBYTE *command )
  95.     {
  96.     struct TagItem stags[6];
  97.     BPTR file;
  98.  
  99.     if(file = Open(autocon, MODE_OLDFILE))
  100.         {
  101.         stags[0].ti_Tag = SYS_Input;
  102.         stags[0].ti_Data = file;
  103.         stags[1].ti_Tag = SYS_Output;
  104.         stags[1].ti_Data = NULL;
  105.         stags[2].ti_Tag = SYS_Asynch;
  106.         stags[2].ti_Data = TRUE;
  107.         stags[3].ti_Tag = SYS_UserShell;
  108.         stags[3].ti_Data = TRUE;
  109.         stags[4].ti_Tag = NP_Path;
  110.         stags[4].ti_Data = wb_path;
  111.         stags[5].ti_Tag = TAG_DONE;
  112.         return(System(command, stags));
  113.         }
  114.     else return(WINDOWFAIL);
  115.     }
  116.  
  117.  
  118. BPTR CopyPath( tass ) char *tass;
  119.   {
  120.       struct Process *wb = (void *) FindTask( tass );
  121.       struct CommandLineInterface *wbclap;
  122.       BPTR *wext, *mext, *lastmext, newpath = 0;
  123.  
  124.       lastmext = &newpath;
  125.       if( !wb ) return 0;
  126.       if( !( wbclap = BADDR( wb->pr_CLI ) ) )
  127.           return 0;
  128.  
  129.       for( wext = BADDR( wbclap->cli_CommandDir ); wext; wext = BADDR( *wext ) ) {
  130.           if( !( mext = (BPTR *)AllocMem(  2 * sizeof(BPTR) , MEMF_PUBLIC ) ) )
  131.               break;
  132.           *lastmext = (long) mext >> 2;
  133.           lastmext = mext;
  134.           mext[1] = DupLock( wext[1] );
  135.           mext[0] = 0;
  136.       }
  137.       return( newpath );
  138.   }
  139.