home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
376_01
/
os2tool.000
/
DISKFREE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-27
|
3KB
|
138 lines
/*
* DISKFREE.C - Output the amount of free storage on a disk.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 7.12.1990
*/
static char *VERSION = "Version 1.1, Copyright (c) Martti Ylikoski, 1990,1991" ;
/*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <param.h>
#include <paramstd.h>
#define INCL_DOS
#define INCL_DOSFILEMGR
#include <os2.h>
static char *progname ;
extern unsigned long pflags ;
static int diskfree(USHORT usDisk) ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 0,
"R", &ParamSetReport, 1,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 0,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
int main(int argc, char *argv[])
{
USHORT ret, usDisk ;
ULONG ulDrives ;
int i, j ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if (pflags & PA_HELP)
{
printf("%s- display the amount of free space on a disk.\n", progname) ;
puts(VERSION) ;
puts("Usage: diskfree [/H | /?] [/R] [drive(s)]") ;
puts("Where,") ;
puts(" /R = Report /H,/? = Help");
return( 1 ) ;
}
if ( argc == 1 )
{
if (( ret = DosQCurDisk(&usDisk, &ulDrives)) != 0)
{
fprintf(stderr,"%s: error in DosQCurDir ...\nExiting ...\n", progname) ;
return( 1 ) ;
}
}
if (argc == 1)
diskfree(usDisk) ;
else
for (i = 1 ; i <argc ; i++)
{
usDisk = toupper( (int) argv[i][0] ) - 'A' + 1 ;
diskfree(usDisk) ;
}
return( 0 ) ;
}
static int diskfree(USHORT usDisk)
{
FSALLOCATE fsallocate ;
char p1[24], p2[24], p3[24] ;
int i, j ;
USHORT ret;
ULONG freedisk ;
ULONG totaldisk ;
if (( ret = DosQFSInfo(usDisk, 1, (PBYTE) &fsallocate, sizeof(fsallocate))) != 0)
{
fprintf(stderr,"%s: error in DosQFSInfo ...\nExiting ...\n", progname) ;
return( 1 ) ;
}
freedisk = fsallocate.cUnitAvail * fsallocate.cSectorUnit * fsallocate.cbSector ;
totaldisk = fsallocate.cUnit * fsallocate.cSectorUnit * fsallocate.cbSector ;
sprintf(p1, "%lu", freedisk) ;
sprintf(p3, "%lu", totaldisk) ;
strrev(p1) ;
strrev(p3) ;
for (i=0, j = 0; i < strlen(p1) ; i++, j++)
{
if (i%3 == 0 && i != 0)
{
p2[j] = ',' ;
j++;
}
p2[j] = p1[i] ;
}
p2[j] = '\0' ;
strrev(p2) ;
for (i=0, j = 0; i < strlen(p3) ; i++, j++)
{
if (i%3 == 0 && i != 0)
{
p1[j] = ',' ;
j++;
}
p1[j] = p3[i] ;
}
p1[j] = '\0' ;
strrev(p1) ;
strcpy(p3,p1) ;
if (pflags & PA_REPORT)
printf("[DISKFREE]\nFreedisk=%ld\nTotaldisk=%ld\ndrive=%c:\n", freedisk, totaldisk, usDisk+'A'-1) ;
else
printf("\n%c: %s bytes free of %s bytes available.\n", usDisk+'A'-1, p2, p3 ) ;
}