home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / fixcli_429.lzh / FixCLI / fixcli.c < prev    next >
C/C++ Source or Header  |  1991-01-10  |  5KB  |  142 lines

  1. #ifdef THIS_IS_A_COMMENT
  2.  
  3.    FixCLI by Paul Kienitz (originally just called FixCD, first version
  4.    12/11/88).  Does a CD if we're not really CD'ed anywhere deliberately;
  5.    i.e.  CD'ed to root of boot disk by default.  It also copies the
  6.    Workbench's or another CLI's command path if we have no path.  And it
  7.    fills in your pr_WindowPtr if your current window is on a custom screen. 
  8.    Intended for use in Shell-Startup scripts for use with PopCLI, DMouse, and
  9.    other programs that can start up a CLI in a non-CLI environment, e.g. 
  10.    MyMenu.  Public domain.  Do anything you want with it, as long as you
  11.    don't do it in the middle of the street and frighten the horses.
  12.  
  13.    1/16/89: oops!  Made it not waste a Lock (and forget to UnLock!) when it's
  14.    not going to do anything.  Added fancier error message.
  15.  
  16.    Next day: made it default to present assignment of SYS:, rather than
  17.    original boot disk.  Made it set WARN code when it acts, so that Shell-
  18.    Startup can know that it has to run PATH.  Decided not to try to remove
  19.    need for saying CD "" to fix the prompt afterwards, because you have to do
  20.    that anyway with a Workbench launched Shell that doesn't need FixCD.
  21.  
  22.    9/28/89: added path copying, changed name from FixCD to FixPathCD. 
  23.    Dublicating the Workbench's path is much quicker than using a Path command
  24.    in response to a WARN return.  Also added copying of argument string into
  25.    SetName.  NOTE that you don't allocate a new buffer for a new SetName; the
  26.    one it's using is on the CLI's own stack.  It's 88 bytes long.  Wrote doc
  27.    file FixPathCD.readme.
  28.  
  29.    10/3/89: added feature to set pr_WindowPtr when current window is not on
  30.    the Workbench screen.  This is needed by the current version of CLImax. 
  31.    This feature will probably be removed here when CLImax is fixed.  On
  32.    second thought, this feature is useful with NewShell CON:S*/blah too. 
  33.    Also added thing so that if it can't find the Workbench's path it looks
  34.    for a CLI's path.  Changed the name to FixCLI.  Then added #ifdef WINDOWPTR
  35.    to control whether it has the WindowPtr feature or not.
  36.  
  37.    11/21/90: recompiled with aztec C 5.0 (cleaned up some sloppy type
  38.    mismatches); sized reduced by (gasp) 2.5 percent
  39.  
  40. #endif
  41.  
  42.  
  43. #include <libraries/dosextens.h>
  44. #include <Paul.h>
  45.  
  46. #ifdef WINDOWPTR
  47.  
  48. #include <exec/exec.h>
  49. #include <intuition/intuition.h>
  50. #include <devices/conunit.h>
  51.  
  52.  
  53. void FixWindowPtr(me) struct Process *me;
  54. {
  55.     import long dos_packet();        /* a Manx convenience */
  56.     struct InfoData *ind;
  57.     adr cont = me->pr_ConsoleTask;
  58.     if (cont && (ind = NewP(struct InfoData))) {
  59.     if (dos_packet(cont, ACTION_DISK_INFO, (long) ind >> 2)) {
  60.         register struct Window *w = (adr) ind->id_VolumeNode;
  61.         register struct Screen *s = w->WScreen;
  62.         if ((s->Flags & SCREENTYPE) == CUSTOMSCREEN)
  63.         me->pr_WindowPtr = (APTR) w;
  64.     }
  65.     Free(struct InfoData, ind);
  66.     }
  67. }
  68.  
  69. #endif
  70.  
  71.  
  72. BPTR FindPath(taskname) str taskname;
  73. {
  74.     struct Process *teacher = (adr) FindTask(taskname);
  75.     struct CommandLineInterface *teachcli;
  76.     register BPTR *wext, *mext, *lastmext;
  77.     BPTR newpath = 0;
  78.  
  79.     if (!teacher) return 0;
  80.     lastmext = &newpath;
  81.     if (!(teachcli = gbip(teacher->pr_CLI))) return 0;
  82.     for (wext = gbip(teachcli->cli_CommandDir); wext; wext = gbip(*wext)) {
  83.     if (!(mext = AllocP(3 * sizeof(BPTR))))
  84.         break;
  85.     *lastmext = (long) (mext + 1) >> 2;
  86.     lastmext = mext + 1;
  87.     mext[2] = DupLock(wext[1]);
  88.     mext[1] = 0;
  89.     *mext = 3L * sizeof(BPTR);        /* size for DOS memory freer */
  90.     }
  91.     return newpath;
  92. }
  93.  
  94.  
  95. long _main(alen, aptr) long alen; char *aptr;
  96. {
  97.     register struct Process *me = ThisProcess();
  98.     register BPTR newlock, out = Output();
  99.     str setname;
  100.     struct CommandLineInterface *cle = gbip(me->pr_CLI);
  101.     long ret = 0;
  102.  
  103. #ifdef WINDOWPTR
  104.     FixWindowPtr(me);
  105. #endif
  106.     while (alen && aptr[alen - 1] <= ' ') aptr[--alen] = 0;
  107.     if (*aptr == '"') {
  108.         if (aptr[alen - 1] == '"') aptr[--alen] = 0;
  109.         aptr++;
  110.     }
  111.     if (!me->pr_CurrentDir) {
  112.     if (!alen) aptr = "SYS:";
  113.     if (!(newlock = RLock(aptr))) {
  114.         Write(out, "\nFixCLI couldn't find directory \"", 33L);
  115.         Write(out, aptr, alen);
  116.         Write(out, "\".\n", 3L);
  117.         me->pr_Result2 = ERROR_OBJECT_NOT_FOUND;
  118.         return 10;                    /* failure */
  119.     }
  120.     me->pr_CurrentDir = newlock;
  121.     if (cle) {
  122.         short len = strlen(aptr);
  123.         if (len > 87) len = 87;        /* setname buffer is 88 bytes */
  124.         setname = gbip(cle->cli_SetName);
  125.         *setname = len;
  126.         strncpy(setname + 1, aptr, len);
  127.     }
  128.     ret = 5;
  129.     }
  130.     if (cle && !cle->cli_CommandDir) {
  131.     register BPTR path = FindPath("Workbench");
  132.     if (!path) path = FindPath("Initial CLI");
  133.     if (!path) path = FindPath("AmigaShell");
  134.     if (!path) path = FindPath("New CLI");
  135.     if (!path) path = FindPath("Background CLI");
  136.     cle->cli_CommandDir = path;
  137.     ret = 5;
  138.     }
  139.     me->pr_Result2 = 0;
  140.     return ret;
  141. }
  142.