#ifdef THIS_IS_A_COMMENT FixCLI by Paul Kienitz (originally just called FixCD, first version 12/11/88). Does a CD if we're not really CD'ed anywhere deliberately; i.e. CD'ed to root of boot disk by default. It also copies the Workbench's or another CLI's command path if we have no path. And it fills in your pr_WindowPtr if your current window is on a custom screen. Intended for use in Shell-Startup scripts for use with PopCLI, DMouse, and other programs that can start up a CLI in a non-CLI environment, e.g. MyMenu. Public domain. Do anything you want with it, as long as you don't do it in the middle of the street and frighten the horses. 1/16/89: oops! Made it not waste a Lock (and forget to UnLock!) when it's not going to do anything. Added fancier error message. Next day: made it default to present assignment of SYS:, rather than original boot disk. Made it set WARN code when it acts, so that Shell- Startup can know that it has to run PATH. Decided not to try to remove need for saying CD "" to fix the prompt afterwards, because you have to do that anyway with a Workbench launched Shell that doesn't need FixCD. 9/28/89: added path copying, changed name from FixCD to FixPathCD. Dublicating the Workbench's path is much quicker than using a Path command in response to a WARN return. Also added copying of argument string into SetName. NOTE that you don't allocate a new buffer for a new SetName; the one it's using is on the CLI's own stack. It's 88 bytes long. Wrote doc file FixPathCD.readme. 10/3/89: added feature to set pr_WindowPtr when current window is not on the Workbench screen. This is needed by the current version of CLImax. This feature will probably be removed here when CLImax is fixed. On second thought, this feature is useful with NewShell CON:S*/blah too. Also added thing so that if it can't find the Workbench's path it looks for a CLI's path. Changed the name to FixCLI. Then added #ifdef WINDOWPTR to control whether it has the WindowPtr feature or not. 11/21/90: recompiled with aztec C 5.0 (cleaned up some sloppy type mismatches); sized reduced by (gasp) 2.5 percent #endif #include #include #ifdef WINDOWPTR #include #include #include void FixWindowPtr(me) struct Process *me; { import long dos_packet(); /* a Manx convenience */ struct InfoData *ind; adr cont = me->pr_ConsoleTask; if (cont && (ind = NewP(struct InfoData))) { if (dos_packet(cont, ACTION_DISK_INFO, (long) ind >> 2)) { register struct Window *w = (adr) ind->id_VolumeNode; register struct Screen *s = w->WScreen; if ((s->Flags & SCREENTYPE) == CUSTOMSCREEN) me->pr_WindowPtr = (APTR) w; } Free(struct InfoData, ind); } } #endif BPTR FindPath(taskname) str taskname; { struct Process *teacher = (adr) FindTask(taskname); struct CommandLineInterface *teachcli; register BPTR *wext, *mext, *lastmext; BPTR newpath = 0; if (!teacher) return 0; lastmext = &newpath; if (!(teachcli = gbip(teacher->pr_CLI))) return 0; for (wext = gbip(teachcli->cli_CommandDir); wext; wext = gbip(*wext)) { if (!(mext = AllocP(3 * sizeof(BPTR)))) break; *lastmext = (long) (mext + 1) >> 2; lastmext = mext + 1; mext[2] = DupLock(wext[1]); mext[1] = 0; *mext = 3L * sizeof(BPTR); /* size for DOS memory freer */ } return newpath; } long _main(alen, aptr) long alen; char *aptr; { register struct Process *me = ThisProcess(); register BPTR newlock, out = Output(); str setname; struct CommandLineInterface *cle = gbip(me->pr_CLI); long ret = 0; #ifdef WINDOWPTR FixWindowPtr(me); #endif while (alen && aptr[alen - 1] <= ' ') aptr[--alen] = 0; if (*aptr == '"') { if (aptr[alen - 1] == '"') aptr[--alen] = 0; aptr++; } if (!me->pr_CurrentDir) { if (!alen) aptr = "SYS:"; if (!(newlock = RLock(aptr))) { Write(out, "\nFixCLI couldn't find directory \"", 33L); Write(out, aptr, alen); Write(out, "\".\n", 3L); me->pr_Result2 = ERROR_OBJECT_NOT_FOUND; return 10; /* failure */ } me->pr_CurrentDir = newlock; if (cle) { short len = strlen(aptr); if (len > 87) len = 87; /* setname buffer is 88 bytes */ setname = gbip(cle->cli_SetName); *setname = len; strncpy(setname + 1, aptr, len); } ret = 5; } if (cle && !cle->cli_CommandDir) { register BPTR path = FindPath("Workbench"); if (!path) path = FindPath("Initial CLI"); if (!path) path = FindPath("AmigaShell"); if (!path) path = FindPath("New CLI"); if (!path) path = FindPath("Background CLI"); cle->cli_CommandDir = path; ret = 5; } me->pr_Result2 = 0; return ret; }