Category : C Source Code
Archive   : MEWELDT.ZIP
Filename : DESKAUX.C

 
Output of file : DESKAUX.C contained in archive : MEWELDT.ZIP
/*===========================================================================*/
/* */
/* File : VOLUME.C */
/* */
/* Purpose : Routines to get and modify a disk's volume label. */
/* */
/* History : */
/* */
/* (C) Copyright 1989 Marc Adler/Magma Systems All Rights Reserved */
/*===========================================================================*/

#ifdef TC
/* File attribute constants */
#define _A_NORMAL 0x00
#define _A_RDONLY 0x01
#define _A_HIDDEN 0x02
#define _A_SYSTEM 0x04
#define _A_VOLID 0x08
#define _A_SUBDIR 0x10
#define _A_ARCH 0x20

#define _dos_findfirst(spec, mask, fi) findfirst(spec, fi, mask)
#define _dos_findnext(fi) findnext(fi)
#define wr_time ff_ftime
#define wr_date ff_fdate
#define name ff_name
#define attrib ff_attrib
#define ffblk find_t

#define _dos_setdrive(d,n) setdisk((d) - 1)
#endif


#include
#include
#include
#include
#include
#include
#include "window.h"
#include "keys.h"
#include "rc.h"

#include "desktop.h"

#undef FP_OFF
#undef FP_SEG
#define FP_OFF(fp) ((unsigned)(fp))
#define FP_SEG(fp) ((unsigned)((unsigned long)(char far *) (fp) >> 16))

#define SET_DOSINT_AND_BUFFER(inter, buf) \
{ r.h.ah = inter; r.x.dx = FP_OFF(buf); sregs.ds = FP_SEG(buf); }


#pragma pack(1)
typedef struct xfcb
{
unsigned char ff;
char reserved[5];
char attr;
char iDrive;
char name[11];
char filler[25];
} XFCB;


char *GetVolumeName(char *szVolName)
{
struct find_t fileinfo;

if (_dos_findfirst("*.*", _A_VOLID, &fileinfo) == 0)
return strcpy(szVolName, fileinfo.name);
else
{
szVolName[0] = '\0';
return (char *) 0;
}
}

int ChangeVolumeName(char *szVolName)
{
union REGS r;
struct SREGS sregs;

char tmpBuf[64];
char *ptmpBuf = tmpBuf;
XFCB xfcb;
XFCB *pxfcb = &xfcb;
int len;

xfcb.ff = 0xFF;
xfcb.attr = 0x08;
xfcb.iDrive = 0; /* default drive */
strcpy(xfcb.name, "*.*");
memset(xfcb.name + 3, ' ', 8);
memset(xfcb.reserved, 0, 5);
memset(xfcb.filler, 0, 25);

/*
Set DTA to scrap buffer
*/
SET_DOSINT_AND_BUFFER(0x1A, ptmpBuf);
intdosx(&r, &r, &sregs);

/*
Search using extended FCB's
*/
SET_DOSINT_AND_BUFFER(0x11, pxfcb);
intdosx(&r, &r, &sregs);

if (r.h.al != 0xFF)
{
/*
A volume label exists. Change it.
*/
if (r.h.al == 0)
{
strncpy(tmpBuf + 25, szVolName, 11);
if ((len = strlen(szVolName)) < 11)
memset(tmpBuf + 25 + len, ' ', 11-len);
/*
Rename file function
*/
SET_DOSINT_AND_BUFFER(0x17, ptmpBuf);
intdosx(&r, &r, &sregs);
if (r.h.al == 0)
return 0;
}
}

strncpy(xfcb.name, szVolName, 11);
if ((len = strlen(szVolName)) < 11)
memset(xfcb.name + len, ' ', 11-len);
memset(xfcb.reserved, 0, 5);
memset(xfcb.filler, 0, 25);
SET_DOSINT_AND_BUFFER(0x16, pxfcb);
intdosx(&r, &r, &sregs);
return r.h.al;
}


RenameFiles(char *szFrom, char *szTo)
{
BOOL isDir = IsaDirectory(szTo);
char to[MAXPATHLEN];
char *s;
int rc;
struct find_t fileinfo;

if (_dos_findfirst(szFrom, (_A_NORMAL | _A_RDONLY), &fileinfo) == 0)
{
do
{
if (isDir)
{
strcpy(to, szTo);
if (szTo[1] == ':' && szTo[2]) /* not just a drive designator */
strcat(to, "\\");
strcat(to, fileinfo.name);
rc = rename(fileinfo.name, to);
}
else
rc = rename(fileinfo.name, szTo);

if (rc != 0)
{
MessageBox("Error in renaming files", fileinfo.name, to, "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
}

} while (_dos_findnext(&fileinfo) == 0);
}
}



CopyFiles(char *szFrom, char *szTo)
{
BOOL isDir = IsaDirectory(szTo);
char to[MAXPATHLEN];
char *s;
int rc;
struct find_t fileinfo;

if (_dos_findfirst(szFrom, (_A_NORMAL | _A_RDONLY), &fileinfo) == 0)
{
do
{
strcpy(to, szTo);
if (isDir)
{
if (szTo[1] == ':' && szTo[2]) /* not just a drive designator */
strcat(to, "\\");
strcat(to, fileinfo.name);
}
rc = _CopyFile(fileinfo.name, to);

if (rc == -1)
{
MessageBox("Error in opening files", fileinfo.name, to, "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
}
else if (rc == -2)
{
MessageBox("Error in writing file", to, "Disk may be full.", "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
}

} while (_dos_findnext(&fileinfo) == 0);
}
}


_CopyFile(char *szFrom, char *szTo)
{
int fdFrom, fdTo;
char buf[512];
int n;

if ((fdFrom = open(szFrom, O_RDONLY | O_BINARY)) < 0)
return -1;

if ((fdTo = open(szTo, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY
,S_IREAD | S_IWRITE)) < 0)
{
close(fdFrom);
return -1;
}

while ((n = read(fdFrom, buf, sizeof(buf))) > 0)
if (write(fdTo, buf, n) != n)
{
close(fdFrom);
close(fdTo);
return -2;
}

close(fdFrom);
close(fdTo);

return 0;
}


DeleteFiles(char *szFile)
{
struct find_t fileinfo;

if (_dos_findfirst(szFile, (_A_NORMAL | _A_RDONLY), &fileinfo) == 0)
{
do
{
if (unlink(fileinfo.name) != 0)
{
MessageBox("Error in deleting file", fileinfo.name, NULL, "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
}
} while (_dos_findnext(&fileinfo) == 0);
}
}


int IsaDirectory(char *szFileName)
{
struct find_t fileinfo;
if (szFileName[1] == ':' && !szFileName[2]) /* C: */
return TRUE;
if (_dos_findfirst(szFileName, 0xFF, &fileinfo) == 0)
return (fileinfo.attrib & _A_SUBDIR);
else
return FALSE; /* doesn't exist yet */
}




#ifdef TEST

main(int argc, char **argv)
{
char vol[64];

printf("The current volume name is [%s]\n", GetVolumeName(vol));

printf("What would you like to name this volume?");
if (gets(vol) && *vol)
{
ChangeVolumeName(vol);
printf("The current volume name is [%s]\n", GetVolumeName(vol));
}
}

#endif



  3 Responses to “Category : C Source Code
Archive   : MEWELDT.ZIP
Filename : DESKAUX.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/