home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
152.lha
/
byter.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-04-26
|
6KB
|
220 lines
/* BYTER 2.0 7-7-88 Ed Holzknecht
*
* Byter is a program that will display the directory, the size of each
* file, and bytes and blocks free on all disk devices in the system,
* including VD0: and DH0:. The new addition to this version is
* that Byter is now compatible with WorkBench. By using extended selection
* (holding down the shift key while clicking on an icon), you can execute
* Byter. Hold down the shift key, click on a drawer or disk icon, and
* then double-click on the Byter icon.
*
* USAGE...byter <drive>. If <drive> is not specified, the current directory
* is the directory listed.
*
* Copyright (C) 1988 Ed Holzknecht. All rights reserved. This program
* is Freeware. If you can make it better, go for it; just keep my name
* on the original.
*
* This program may be included in Fred Fish and Amicus disks (if they want
* it) with the author's compliments. Please keep this notice intact!
*
* Note: Found out how to get rid of nasty requesters by looking at Charles
* McManis' 'Info' command in C. Thanks, Charles!
*
***************************************************************************/
#include <functions.h>
#include <exec/memory.h>
#include <workbench/startup.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#define print(str) Write(Output(), str, (LONG)strlen(str))
extern struct WBStartup *WBenchMsg;
struct DirData {
char filename[50];
LONG filesize;
} mydata[100];
char *device[5] = {"VD0:", "DH0:", "DF2:", "DF1:", "DF0:"};
char s[8];
void rtjust();
main(argc, argv)
int argc;
char *argv[];
{
struct Process *pro = NULL;
struct InfoData *myinfo = NULL;
struct FileLock *mylock =NULL;
void getdir();
LONG blocks, bytes, i = 0;
char *diskname, *sblocks, *sbytes, *itoa();
int end;
BOOL flag = 1;
APTR pnt;
if(argc == 0) {
if(WBenchMsg->sm_NumArgs == 1) {
exit(0);
}
diskname = WBenchMsg->sm_ArgList[1].wa_Name;
}
else if(argc == 1) diskname = "";
else if(argc == 2) diskname = argv[1];
else {
print("USAGE..byter <drive>\n");
exit(0);
}
getdir(diskname);
pro = (struct Process *)FindTask(NULL);
pnt = pro->pr_WindowPtr;
pro->pr_WindowPtr = (APTR) -1;
myinfo = (struct InfoData *)AllocMem((LONG)sizeof(struct InfoData), 0L);
while(i < 5) {
if(mylock = (struct FileLock *)Lock(device[i], ACCESS_READ)) {
Info(mylock, myinfo);
blocks = myinfo->id_NumBlocks - myinfo->id_NumBlocksUsed;
bytes = blocks * 512L;
sbytes = itoa(&bytes);
if(flag) {
print("DRIVE BYTES FREE BLOCKS FREE\n");
flag = 0;
}
print(device[i]); print("\t\t");
rtjust(sbytes, 9L);
print(sbytes);print("\t");
sblocks = itoa(&blocks);
rtjust(sblocks, 6L);
print(sblocks);print("\n");
}
if(mylock) UnLock(mylock);
i++;
}
if(WBenchMsg) {
print("\nHit <RETURN> to end!\0");
getchar();
}
if(myinfo) FreeMem(myinfo, ((LONG)(sizeof(struct InfoData))));
pro->pr_WindowPtr = pnt;
exit(0);
}
void getdir(name)
char *name;
{
void sort();
struct FileInfoBlock *myfib = NULL;
struct FileLock *myotherlock = NULL, *oldlock = NULL;
char *sfilesize;
LONG len, filecount, i = 0, colcount = 0, Enable_Abort = 0;
if(WBenchMsg) {
myotherlock = (struct FileLock *)WBenchMsg->sm_ArgList[1].wa_Lock;
oldlock = CurrentDir(myotherlock);
}
else
myotherlock = (struct FileLock *)Lock(name, ACCESS_READ);
myfib = (struct FileInfoBlock *)AllocMem((LONG)sizeof(struct FileInfoBlock), 0L);
if(!Examine(myotherlock, myfib))
exit(20);
Enable_Abort = 1;
while(ExNext(myotherlock, myfib) != 0L || IoErr() != ERROR_NO_MORE_ENTRIES) {
if(myfib -> fib_DirEntryType > 0L) {
print("\t");
print(myfib -> fib_FileName);
print(" (dir)\n");
}
else {
strcpy(mydata[i].filename, myfib -> fib_FileName);
mydata[i].filesize = myfib -> fib_Size;
i++;
}
}
sort(mydata, i);
for(filecount = 0;filecount < i;filecount++) {
print(mydata[filecount].filename);
len = strlen(mydata[filecount].filename);
for(;len < 25L; len++)
print(" ");
sfilesize = itoa(&mydata[filecount].filesize);
rtjust(sfilesize, 7L);
print(sfilesize);
print(" ");
if(colcount % 2L == 1L)
print("\n");
colcount++;
Chk_Abort();
}
colcount % 2L == 1L ? print("\n\n") : print("\n");
if(myotherlock && (!WBenchMsg)) {
if(oldlock)
myotherlock = CurrentDir(oldlock);
UnLock((struct FileLock *)myotherlock);
}
if(myfib) FreeMem(myfib, ((LONG)(sizeof(struct FileInfoBlock))));
}
char *itoa(n)
LONG *n;
{
LONG c, i, j, k;
k = 0;
do {
s[k++] = *n % 10L + '0';
} while ((*n /= 10L) > 0L);
s[k] = '\0';
for(i = 0, j = (LONG)strlen(s)-1L; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
return(s);
}
void rtjust(string, len)
char *string;
LONG len;
{
LONG x, y;
x = (LONG)strlen(string);
if(x >= len)
return;
for(y = len;y >= 0L;y--)
*(string+y) = (x < 0L) ? ' ' : *(string+x--);
}
void sort(mydata, count)
struct DirData mydata[];
LONG count;
{
LONG i, j, k, s, w;
char a[5];
struct DirData x;
a[0]=9L; a[1]=5L;a[2]=3L;a[3]=2L;a[4]=1L;
for(w=0; w<5; w++) {
k=a[w]; s= -k;
for(i=k; i<count; ++i) {
x = mydata[i];
j=i-k;
if(s==0) {
s= -k;
s++;
mydata[s] = x;
}
while((strcmp(&x.filename, mydata[j].filename)< 0) && j >= 0 && j <= count) {
mydata[j+k] = mydata[j];
j = j-k;
}
mydata[j + k] = x;
}
}
}