home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 455.lha / CLIanywhere_v1.0 / CLIanywhere.c < prev    next >
C/C++ Source or Header  |  1990-12-10  |  2KB  |  99 lines

  1. ;/*
  2. FailAt 1
  3. LC -M -v -cs -O -iINCLUDE:CompactH/ CLIanywhere.c
  4. Blink CLIanywhere.o ND
  5. Protect CLIanywhere +p
  6. Quit
  7. */
  8.  
  9. #include <string.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/intuitionbase.h>
  12. #include <libraries/dos.h>
  13. #include <exec/memory.h>
  14. #include <proto/intuition.h>
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17.  
  18. #define iswhite(c) ((c)==' '||(c)=='\t'||(c)=='\n')
  19.  
  20. int __asm CLIanywhere(register __a0 char *args, register __d0 int argl)
  21. {
  22.   ULONG ilock;
  23.   struct Screen *s;
  24.   USHORT flags;
  25.   BPTR file, nullfh;
  26.   char *cmd, *c;
  27.   ULONG size = 0L;   /* this flags whether to FreeMem(cmd) or not */
  28.   struct DosLibrary *DOSBase;
  29.   struct IntuitionBase *IntuitionBase;
  30.  
  31.   DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",33);
  32.   if (!DOSBase) return(100);
  33.   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",33);
  34.   if (!IntuitionBase) return(100);
  35.  
  36. /*
  37. **  process the command line args
  38. */
  39.  
  40. /* NULL-delimit args */
  41.   c = (args + argl);
  42.   *c = '\0';
  43. /* trunc trailing newline */
  44.   for(c--; (c > args) && iswhite(*c); c--) *c = '\0';
  45. /* skip leading white space */
  46.   while(iswhite(*args)) args++;
  47.  
  48.   if (*args)
  49.     {
  50.       cmd = args;
  51.     }
  52.   else
  53.     {
  54.       file = Open("s:CLIanywhere.cmd",MODE_OLDFILE);
  55.       if (!file)
  56.         {
  57.           cmd = "c:NewShell \"NEWCON:0/11/640/50/ CLIanywhereShell \"";
  58.         }
  59.       else
  60.         {
  61.           Seek(file,0L,OFFSET_END);
  62.           size = Seek(file,0L,OFFSET_CURRENT);
  63.           size++;
  64.           cmd = AllocMem(size,MEMF_PUBLIC);
  65.           if (!cmd)
  66.             {
  67.               Close(file);
  68.               return(100);
  69.             }
  70.           Seek(file,0L,OFFSET_BEGINNING);
  71.           Read(file,(UBYTE *)cmd,size);
  72.           Close(file);
  73.           *(char *)(cmd + size - 1) = '\0';
  74.         }
  75.     }
  76.  
  77.   ilock = LockIBase(0L);
  78.   s = IntuitionBase->FirstScreen;
  79.   flags = s->Flags;
  80.   s->Flags = ( (s->Flags & (~SCREENTYPE)) | WBENCHSCREEN);
  81.   UnlockIBase(ilock);
  82.  
  83.   nullfh = Open("NIL:",MODE_NEWFILE);
  84.   if (nullfh)
  85.     {
  86.       Execute(cmd,nullfh,nullfh);
  87.       Close(nullfh);
  88.     }
  89.  
  90.   ilock = LockIBase(0L);
  91.   if (s == IntuitionBase->FirstScreen) s->Flags = flags;
  92.   UnlockIBase(ilock);
  93.  
  94.   if (size > 0L) FreeMem(cmd,size);
  95.   CloseLibrary((struct Library *)IntuitionBase);
  96.   CloseLibrary((struct Library *)DOSBase);
  97.   return(0);
  98. }
  99.