🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #2665

Re: Anybody know how to do this stuff?

#2665
From: Peter da Silva
Date: Mon, 11 Dec 1989 05:43
179 lines
5179 bytes
Here it is, as promised. You can scan the device list with this code, and do
all sorts of fun stuff. Make SKSH the first program to support wildcarding
the device name!

: This archive contains the following files...
: 'mounted.c'
: 'readme'
: To extract them, run the following through /bin/sh
echo x - mounted.c
sed 's/^X//' > mounted.c << '//END'
X/* MOUNTED -- is a disk mounted?
X *
X * Copyright 1987 by Peter da Silva.
X *
X * This code may be freely distributed provided this notice is
X * retained. It may be hacked, munged, and incorporated in commercial
X * software if you want, so long as you credit me for it.
X */
X#include <stdio.h>
X#include <ctype.h>
X#include <libraries/dosextens.h>
X
Xstruct DosLibrary *DosLibrary;
X
X/* hack BPTRS */
X
X#define toAPTR(b) ((b)<<2)
X#define toBPTR(a) ((a)>>2)
X
X#define VOLUMES 16 /* If you have more than 16 drives, tough luck :-> */
Xchar volumes[VOLUMES][33];
Xint nvols;
X
Xmain(ac, av)
Xint ac;
Xchar **av;
X{
X	GetVolumes();
X	if(ac==0) wbmain(); /* I think this should work with Lattice */
X	else if(ac==1) dumpvols();
X	else if(ac==2 && av[1][0] != '?')
X		exit(mounted(av[1])?0:5); /* Code 5 is warn */
X	else {
X		/* should loop & return success only if all work. */
X		printf("MOUNTED Copyright (c) 1987 by Peter da Silva.\n");
X		printf("Usage: mounted [volumename]\n");
X		printf("Returns error code 5 is volume is not mounted.\n");
X		exit(10); /* code 10 is error. maybe Should be 20 (fatal). */
X	}
X	exit(0);
X}
X
XGetVolumes() /* who'se out there */
X{
X	struct RootNode *root;
X	struct DosInfo *info;
X	struct DeviceList *list;
X
X	DosLibrary = OpenLibrary("dos.library", 0);
X	if(!DosLibrary) {
X		printf("Can't open dos.library\n");
X		exit(2);
X	}
X	nvols = 0;
X
X	/* The following 3 lines caused me some worry, but they worked
X	   first time. Thank you C=Amiga. */
X	root = DosLibrary -> dl_Root;
X	info = toAPTR(root->rn_Info);
X	list = toAPTR(info->di_DevInfo);
X	while(list) {
X		if(list->dl_Type == DLT_VOLUME && /* is it a device? */
X		   list->dl_Task != 0) { /* Ignore unmounted devices */
X			char *ptr;
X			int count;
X			ptr = toAPTR((BPTR)list->dl_Name);
X			count = *ptr++;
X			if(count > 16) /* Should be a CONSTANT */
X				count = 16;
X			strncpy(volumes[nvols], ptr, count);
X			volumes[nvols][count] = 0;
X			nvols++;
X		}
X		list = toAPTR(list->dl_Next);
X	}
X	CloseLibrary(DosLibrary);
X}
X
Xwbmain(dummy) /* if run from workbench, just list mounted volumes */
X{
X	FILE *fp;
X	if(!(fp = fopen("CON:160/50/320/100/Mounted volumes.")))
X		return;
X	fdumpvols(fp);
X	sleep(10);
X	fclose(fp);
X}
X
Xsleep(n) /* This should have been provided by Aztec, for god's sake. */
X{
X	Delay(50*n);
X}
X
Xdumpvols()
X{
X	fdumpvols(stdout);
X}
X
Xfdumpvols(fp)
XFILE *fp;
X{
X	int i;
X	for(i = 0; i < nvols; i++)
X		printf("%s\n", volumes[i]);
X}
X
Xmounted(name) /* The biggee */
Xchar *name;
X{
X	int i;
X	for(i = 0; i < nvols; i++)
X		if(streq(volumes[i], name))
X			return 1;
X	return 0;
X}
X
Xstreq(s1, s2)
Xchar *s1, *s2;
X{
X	normalise(s1);
X	normalise(s2);
X	return strcmp(s1, s2)==0;
X}
X
Xnormalise(s)
Xchar *s;
X{
X	int i;
X	for(i = 0; s[i]; i++)
X		if(isupper(s[i]))
X			s[i] = tolower(s[i]);
X		else if(s[i]==':') {
X			s[i] = 0;
X			break;
X		}
X}
//END
echo x - readme
sed 's/^X//' > readme << '//END'
XMOUNTED is a quick little program I wrote to tell if a disk is mounted
Xor not. It's intended to be used in startup-sequences to conditionally
Xexecute programs from df1. For example, mine includes:
X
Xmounted playit
Xif not warn
X    run playit:play playit:bachfugue.smus playit:
Xendif
X
XSo if I start up with the disk "playit" in df1: it plays a bach fugue
Xduring loading. This program illustrates how to deal with BPTRs in a
Xwell behaved way, and how to get hold of the device list. It's full
Xof magic numbers and inefficient code, and including stdio bloats it
Xup to 8K. A little tidying up can probably get it down quite a bit. But
Xit fits nicely in *my* c: directory and I'm arrogant enough to think
XI have better things to do. It's a good idea to have the AmigaDOS
Xmanual open to pages 266-269 while you're checking out the code.
XIt's written for Aztec V3.40a with the +P option set, so it should run 
Xjust fine with Lattice.
X
X		-- Peter da Silva.
X		-- Author of the fantastic screen hack "Workbench Lander".
X		-- And incredibly modest guy.
//END
: end of archive.
exit 0
-- 
Peter "Have you hugged your wolf today" da Silva <peter@sugar.hackercorp.com>
`-_-'
 'U`  "I haven't lost my mind, it's backed up on tape somewhere"
Technical Details
Message-ID: <4731@sugar.hackercorp.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nuchat!sugar!peter
References: <13920020@hpfelg.HP.COM> <13920027@hpfelg.HP.COM> <4730@sugar.hackercorp.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nuchat!sugar!peter
From: peter@sugar.hackercorp.com (Peter da Silva)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Anybody know how to do this stuff?
Message-ID: <4731@sugar.hackercorp.com>
Date: 11 Dec 89 05:43:15 GMT
References: <13920020@hpfelg.HP.COM> <13920027@hpfelg.HP.COM> <4730@sugar.hackercorp.com>
Reply-To: peter@sugar.hackercorp.com (Peter da Silva)
Organization: Sugar Land Unix - Houston
Lines: 179