home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
system_utils
/
general
/
movesys
/
movesys.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-10
|
11KB
|
385 lines
/* This program will reassign all the standard assigned names to be the proper
usual directories on a new disk. The names are:
C: DEVS: FONTS: L: LIBS: S: and SYS:
This program will assign SYS: to the given volume and each of the other
names to the directory of SYS: with that same name (C: = SYS:c etc).
It's called MoveSys. Hard disk users can put it in their Startup-Sequence
to ease the transition from the floppy boot disk (or RAD:) to the hard
disk. Non-hard-disk users can use it to switch from one bootable
application disk to another without getting "please insert volume
Workbench1.3" or the like all the time. For Aztec C. If you want
flexibility, customize the source code. Usage:
MoveSys name: ; where name is a volume name or drive name
You can even MoveSys to a directory, if the appropriate subdirectories
are present there. Like, MoveSys dh0:Workbench or something. I
personally do this; it keeps my HD's root directory uncluttered.
By Paul Kienitz, 12/10/88. Public domain. For Aztec C only; do not
compile with the +m flag. The result is "pure" and can be made resident.
1/17/89: Ooops! Had to add DosAllocate, because unassigning a node I
created without that could cause bad craziness. I should put DosAllocate
into AssignDev, though it's probably not needed if I fix the bug in
detecting whether a node it's deleting is one it made, which I think
somebody already did.
4/14/89: Stripped down internally (no stdio, for instance) to reduce size
and make "pure". Added IoErr code return.
5/4/90: Added option to make it CD to the new SYS: if the argument line
begins with the word "cd" before the pathname. Example: movesys cd dh0:
8/28/90: Made a version usable from Workbench; assigns to a disk or
drawer given as a Workbench arg. The #define flag BENCH activates this
feature. Also made it make no change if the new SYS: has none of the
correct subdirectories. (One out of six is enough for success.) Added
fancier internal help message to cli version. Made it set the cli setname
to a copy of the argument name you use CD.
11/21/90: Adapted for Aztec C 5.0; size reduced by 2.5% -- enough to save
one disk block under the Fast File System
ADD LATER? arguments after volume name to be exceptions or additions to
the built-in list of assignments?
*/
#include <exec/exec.h>
#include <libraries/dosextens.h>
#include <libraries/filehandler.h>
#include <Paul.h> /* defines null, adr, str, bool, bip, gbip, AllocXX ... */
#ifdef BENCH
#include <workbench/startup.h>
#include <workbench/workbench.h>
#endif
typedef struct DeviceNode den;
typedef BPTR lock;
#define HowMany 6
char *dames[HowMany] = {"C", "DEVS", "FONTS", "L", "LIBS", "S"};
char *dears[HowMany] = {"SYS:c", "SYS:devs", "SYS:fonts", "SYS:l",
"SYS:libs", "SYS:s"};
/* SYS: gets assigned to the volume named in the command line argument (or
workbench message argument someday), and then each name in dames gets
assigned to the corresponding directory name in dears. You can change
dears to e.g. assign C: to RAM:C or whatever, or add more names to each,
incrementing HowMany to match. */
/* the only global variables are unchanging, e.g. library bases */
extern struct DosLibrary *DOSBase;
void *IntuitionBase, *IconBase;
struct DosInfo *infoo; /* contains the root of the dev list */
typedef struct global {
BPTR out;
bool cd, slasher;
#ifdef BENCH
bool conopen, confail, bench;
struct WBStartup *wbs;
#endif
} *glob;
#ifdef put
#undef put
#endif /* shouldn't be needed but sometimes is */
void put(s, g) str s; glob g;
{
#ifdef BENCH
if (g->bench && !g->out && !g->confail) {
g->out = ThisProcess()->pr_COS
= NOpen("RAW:30/20/590/105/MoveSys error ");
if (g->out) {
g->conopen = true;
Write(g->out, "\007\007", 2L); /* DisplayBeep twice */
} else g->confail = true;
}
#endif
if (g->out) Write(g->out, s, (long) strlen(s));
}
/* Allocate a block of memory the way the Dos does, with size (rounded up to
the nearest multiple of four) in the longword below the address returned */
adr DosAllocate(size) int size;
{
long longlen = (size + 7) & ~3L;
long *dosalloc = AllocPZ(longlen);
if (!dosalloc) return null;
*dosalloc = longlen;
return dosalloc + 1;
}
void DosFree(a) long *a;
{
FreeMem(a - 1, a[-1]);
}
den *MakeNewAssignNode(name) str name; /* do this within a Forbid */
{
den *foo = DosAllocate(sizeof(den));
int len = strlen(name);
str nom;
if (!foo) return null;
if (!(nom = DosAllocate(len + 2))) { /* room for length byte AND */
DosFree(foo); /* nul, like existing nodes */
return null;
}
foo->dn_Name = (long) nom >> 2;
foo->dn_Type = 1L;
nom[0] = len;
strcpy(nom + 1, name); /* leave the nul on the end */
foo->dn_Next = infoo->di_DevInfo; /* put new node at top of list */
infoo->di_DevInfo = (long) foo >> 2;
return foo;
}
bool Match(s, b) str s; BSTR b;
{
str bee = bip(char, b);
short len = strlen(s);
short i;
if (bee[0] != len) return false;
for (i = 0; i < len; i++)
if (toupper(s[i]) != toupper(bee[i + 1]))
return false;
return true;
}
den *FindDNode(name) str name;
{
den *goob;
for (goob = gbip(infoo->di_DevInfo); goob; goob = gbip(goob->dn_Next))
if (goob->dn_Type == 1 && Match(name, goob->dn_Name))
return goob;
return null;
}
lock ReAssign(name, lok, g) str name; lock lok; glob g;
{
den *where;
lock old;
Forbid();
where = FindDNode(name);
if (!where) where = MakeNewAssignNode(name);
if (!where) {
Permit();
put("Couldn't find or create device node for \"", g);
put(name, g);
put("\".\nOut of memory, I guess.\n", g);
return (lock) 0;
}
old = where->dn_Lock;
where->dn_Lock = lok;
where->dn_Task = bip(struct FileLock, lok)->fl_Task;
Permit();
return old ? old : (lock) ~0;
}
#ifdef BENCH
void BenchExit(g) glob g;
{
long buf;
if (g->conopen) {
put("\n (press any key to erase window) ", g);
Read(g->out, &buf, 1L); /* Read(Output() ...) ?!? yes! */
Close(g->out);
}
Forbid();
ReplyMsg(g->wbs);
Exit(0L);
}
#endif
lock GetArg(app, alen, g) str *app; long alen; glob g;
{
lock syl = (lock) 0;
long hair = 0;
struct Process *me = ThisProcess();
#ifdef BENCH
if (g->bench) {
struct MsgPort *myface = &me->pr_MsgPort;
struct DiskObject *me = null, *it = null;
struct WBArg *a0, *a1;
*app = null;
WaitPort(myface);
g->wbs = (adr) GetMsg(myface);
a0 = g->wbs->sm_ArgList;
a1 = a0 + 1;
if (g->wbs->sm_NumArgs == 2) {
if (!*a0->wa_Name) syl = DupLock(a0->wa_Lock);
else if (!*a1->wa_Name) syl = DupLock(a1->wa_Lock);
}
if (!syl) {
put(
"To use MoveSys from workbench, you must click the\n"
"MoveSys icon and then shift-double-click a DISK or\n"
"DRAWER icon. Or click the disk or drawer first, and\n"
"then shift-double-click the MoveSys icon. The disk or\n"
"drawer should contain subdirectories named c, s, l,\n"
"libs, devs, and fonts. MoveSys will assign SYS: to that\n"
"disk or drawer and assignC:, S:, L:, LIBS:, DEVS:, and\n"
"FONTS: to the subdirectories with the same names.\n", g);
BenchExit(g);
}
} else
#endif
{
do
(*app)[--alen] = 0;
while (alen > 0 && (*app)[alen - 1] <= ' ');
g->slasher = alen > 0 && (*app)[alen - 1] != '/'
&& (*app)[alen - 1] != ':';
while (alen && **app <= ' ')
(*app)++, alen--;
if (tolower(**app) == 'c' && tolower((*app)[1]) == 'd' &&
(*app)[2] <= ' ' && alen >= 3) {
*app += 3;
alen -= 3;
g->cd = true;
while (alen && **app <= ' ')
(*app)++, alen--;
}
if (**app == '"') {
if ((*app)[alen - 1] == '"') (*app)[alen - 1] = 0;
(*app)++;
}
if (alen && !(alen == 1 && **app == '?')) {
syl = RLock(*app);
if (!syl) {
hair = me->pr_Result2; /* set by Lock */
put(*app, g);
put(" not found.\n", g);
me->pr_Result2 = hair;
Exit(10L);
}
} else {
#ifdef BENCH
put(
"\nYou must name a drive, volume, or directory to move SYS:\n"
"to. And that disk or drawer should have subdirectories\n"
"named c, s, l, libs, devs, and fonts. MoveSys will reassign\n"
"SYS: to the named disk or directory and reassign C:, S:, L:,\n"
"LIBS:, DEVS:, and FONTS: to the subdirectories with the\n"
"same names. You can also cause it to CD to the new SYS: by\n"
"using the word CD between the MoveSys command and the name\n"
"of the new SYS:. Example --\n\n 1> MoveSys cd dh0:\n\n", g);
#else
put("You must name a disk or directory to move SYS: to.\n", g);
#endif
me->pr_Result2 = ERROR_LINE_TOO_LONG;
Exit(10L);
}
}
return syl;
}
long _main(alen, aptr) long alen; str aptr;
{
lock syl, L;
short f;
long hair = 0, turn = 0;
bool oneokay = false;
struct Process *me = ThisProcess();
lock oldsys, oldsub;
struct global g;
g.out = me->pr_COS;
g.cd = g.slasher = false;
#ifdef BENCH
g.conopen = g.confail = false;
g.bench = !me->pr_CLI;
#endif
infoo = bip(struct DosInfo,
((struct RootNode *) DOSBase->dl_Root)->rn_Info);
syl = GetArg(&aptr, alen, &g);
if (!(oldsys = ReAssign("SYS", syl, &g))) {
turn = 10;
hair = ERROR_NO_FREE_STORE;
} else {
for (f = 0; f < HowMany; f++) {
L = RLock(dears[f]);
if (!L) {
turn = 5;
hair = me->pr_Result2; /* set by Lock */
put(aptr, &g);
if (g.slasher) put("/", &g);
put(dears[f] + 4, &g);
put(" not found.\n", &g);
} else {
if (!(oldsub = ReAssign(dames[f], L))) {
turn = 10;
hair = ERROR_NO_FREE_STORE;
break;
} else
if (~oldsub) UnLock(oldsub);
oneokay = true;
}
}
if (!oneokay) {
if (~oldsys) oldsys = ReAssign("SYS", oldsys, &g);
put("\n None of the correct subdirectories are present!\n", &g);
hair = ERROR_OBJECT_NOT_FOUND;
turn = 10;
} else if (g.cd) {
short len = strlen(aptr);
str setname;
struct CommandLineInterface *cli = gbip(me->pr_CLI);
L = CurrentDir(DupLock(syl));
if (L) UnLock(L);
if (len > 87) len = 87; /* setname buffer is 88 bytes */
if (cli) {
setname = gbip(cli->cli_SetName);
*setname = len;
strncpy(setname + 1, aptr, len);
}
}
if (~oldsys) UnLock(oldsys);
}
#ifdef BENCH
if (g.bench) BenchExit(&g);
#endif
me->pr_Result2 = hair;
return turn;
}