home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
225_01
/
user2.c
< prev
next >
Wrap
Text File
|
1987-06-10
|
14KB
|
383 lines
/*-----------------------------------------------------------------*/
/* STANDARD HEADER FOR BDS C PROGRAMMES
------------------------------------
Programme: USER2.C
---------
Purpose: This programme will delete all inactive
------- entries from the directory and then re-write
the directory in (almost) alphabetical order.
Written: 11/05/86
-------
Amended: 06/11/86
-------
Version: 2.0
-------
Copyright 1986 - Cogar Computer Services Pty. Ltd. */
/*-----------------------------------------------------------------*/
#include <bdscio.h>
#include <pec.h>
/*-----------------------------------------------------------------*/
#define VERSION "2.0\0"
#define NAME "USER2\0"
/*-----------------------------------------------------------------*/
main(argc, argv) /* For Command Line processing */
int argc;
char *argv[];
{
/*-----------------------------------------------------------------*/
/* Space reserved for variables used in programme */
/*-----------------------------------------------------------------*/
int i, j, k, l;
char c;
int CPM; /* To check the CP/M Version number */
char DRIVE; /* The active drive */
char OLD_DRIVE; /* The starting drive No. */
char OLD_USER; /* The User No. at start of programme */
char FROM_USER; /* User area to take file from */
char TO_USER; /* User area to put file to */
char my_dma[128]; /* The dma buffer to use */
char my_file[15];
char filename[12];
char READING, FOUND, FLAG;
int FD; /* The file descriptor */
char out_buf[128];
char **skew_table;
int PHYS_SEC; /* The physical sector to read/write */
unsigned STORAGE; /* The size of the big buffer */
struct dpb *THIS; /* Disk parameter information */
int DIRECTORY; /* The directory track */
int SECTORS; /* Sectors per track */
int ENTRIES; /* The active entries in directory */
char *BIG_BUF, *infile;
/*-----------------------------------------------------------------*/
pec_clear(); /* Universal routine */
printf("%s - Version %s\n",NAME, VERSION);
printf("Copyright 1986 - Cogar Computer Services Pty.Ltd.\n");
printf("----------------------------------------------------------\n");
printf("This programme will copy a nominated programme to another\n");
printf("User Area, from the present User Area. At the same time\n");
printf("as it does this it will also 'clean up' the directory\n");
printf("tracks by removing any inactive (0xe5) entries, and will\n");
printf("then sort the active entries into (approximate) alphabetical\n");
printf("order.\n");
printf("----------------------------------------------------------\n");
/*-----------------------------------------------------------------*/
/* First check the CP/M Version in use. If it is less than
Version 2.0 then inform the user and terminate programme. */
/*-----------------------------------------------------------------*/
CPM = get_cpm(); /* Obtain the CP/M version and No. */
i = (CPM & 0xff) - 0x20; /* Mask off the MP/M bit */
if(i < 0) /* Must be less than V 2.0 */
{
printf("This programme requires at least V 2.x of CP/M.\n");
printf("Sorry but it won't run for you.\n");
exit();
}
/*-----------------------------------------------------------------*/
/* The CP/M Version is OK, so save the starting User No. and the
starting Drive No. in case either is changed later. */
/*-----------------------------------------------------------------*/
OLD_USER = user_id(0xff);
OLD_DRIVE = get_default() + 0x41;
/*-----------------------------------------------------------------*/
/* Now check the Command Line to see if anything was entered.
We are looking for the file name to transfer to another user
area and the drive code if the current drive isn't being used */
/*-----------------------------------------------------------------*/
if(argc != 2)
{
printf("You have to enter the FILE you wish to transfer.\n");
printf("The required style is -\n\n");
printf("\t\t[dr:]filename.type\n\n");
printf("where 'dr:' is the optional drive code. If you ");
printf("don't\n");
printf("specify a drive then the current drive is used\n");
infile = gets(my_file);
}
else if(argc == 2)
infile = argv[1];
up_str(infile); /* Make name upper case letters */
lines(2);
/*-----------------------------------------------------------------*/
/* Now check for the drive to be used. */
/*-----------------------------------------------------------------*/
if(infile[1] == ':') /* Then we have a drive code */
DRIVE = toupper(infile[0]);
else DRIVE = GET_DEFAULT() + 65;
/*-----------------------------------------------------------------*/
/* Check that the selected drive is available/on-line. If not
then terminate the programme. You may need to add a message
about what is going on if your version of CP/M doesn't do
this automatically, as mine does. */
/*-----------------------------------------------------------------*/
if(!(skew_table = seldsk(DRIVE)))
exit(); /* Must be something wrong */
if(select_dsk(DRIVE) != 0)
exit();
printf(" For Drive - %c\n", DRIVE);
printf(" -------------\n\n");
/*-----------------------------------------------------------------*/
/* The next job is to put the file name in the form which it will
appear in the directory. */
/*-----------------------------------------------------------------*/
setmem(&filename[0], 11, 0x20);
if(infile[1] != ':') /* No drive code given */
j = 0;
else j = 2; /* Drive code given */
for(i = 0; i < 11; i++)
{
if(infile[j] != '.' && i < 8)
{
filename[i] = infile[j];
j++;
}
else if(infile[j] == '.' && i < 8)
filename[i] = SPACE;
else if(i > 7)
{
j++;
if(isalnum(infile[j]))
filename[i] = infile[j];
else filename[i] = 0x20;
}
}
filename[i] = '\0';
printf("The parsed file name is ==> %s\n", filename);
/*-----------------------------------------------------------------*/
/* Everything appears to be OK, so now ask the user to nominate
the user area he/she wishes the file to be put into. */
/*-----------------------------------------------------------------*/
printf("Which User Area is the file now in - ");
scanf("%d", &FROM_USER);
lines(2);
printf("Which USER No. do you want this file to go to -\n");
THIS = dpb_adr();
scanf("%d", &TO_USER);
SECTORS = THIS->SPT;
TO_USER = TO_USER & 0xff;
if(TO_USER == FROM_USER)
{
printf("You can't copy to same User Area.");
exit();
}
lines(2);
/*-----------------------------------------------------------------*/
/* Now do some checking to see -
A. Whether the file exists in the first user area; and
B. Whether or not it already exists in the nominated
user area. */
/*-----------------------------------------------------------------*/
user_id(FROM_USER); /* Go to first User Area */
if((FD = open(infile,0)) == -1)
{
printf("Unable to find - %s\n", infile);
user_id(OLD_USER);
exit();
}
else printf("OK, have found - %s\n", infile);
close(FD);
user_id(TO_USER); /* Go to nominated user area for check */
if((FD = open(infile,0)) != -1)
{
printf("The file - %s already exists in User Area - %d\n", infile, TO_USER);
user_id(OLD_USER);
exit();
}
else printf("and it doesn't yet exist in User Area - %d\n\n", TO_USER);
close(FD);
user_id(FROM_USER); /* Return to first user area