home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
225_01
/
listfile.c
< prev
next >
Wrap
Text File
|
1987-06-10
|
12KB
|
309 lines
/*-----------------------------------------------------------------*/
/* FILE NAME: LISTFILE.C
---------
VERSION: 1.4
-------
WRITTEN: 6th July, 1986
-------
MODIFIED: 13th July, 1986
-------- 14th July, 1986
1st August, 1986 - Specify start page
28/11/86 for UTIL programme */
/* COPYRIGHT: Cogar Computer Services Pty. Ltd. */
/* --------- */
/* */
/* NOTE: This programme is specifically written for */
/* ---- BDS 'C' running under CP/M 2.2 and may need */
/* to be modified for other C's. */
/* */
/* PURPOSE: Will list a text file on the line printer */
/* ------- with page numbers and headings (the file name) */
/* with a standard page length of 60 printed */
/* lines. Note the equates may need to be */
/* changed if you are not using 66-line paper. */
/* */
/* FUNCTIONS: LISTC Found in DEFF3 */
/* --------- ENTAB */
/* */
/*-----------------------------------------------------------------*/
#include <bdscio.h> /* See note, above */
#include <pec.h> /* Required for this file */
/*-----------------------------------------------------------------*/
#define VERSION "1.4" /* The current Version No. */
/*-----------------------------------------------------------------*/
/* SPECIFIC CONSTANTS */
/*-----------------------------------------------------------------*/
#define SECTORS 64 /* Sectors in an 8K printer buffer */
#define PAGE_LENGTH 66 /* For US sized paper */
#define PAGE_TOP 5 /* No. of lines to leave after header */
#define PAGE_BOTTOM 10 /* No. of lines to skip after last line */
#define LINES PAGE_LENGTH-(PAGE_TOP+PAGE_BOTTOM) /* lines per page */
#define EOF 26 /* CP/M end of file (?) CONTROL-Z */
/*-----------------------------------------------------------------*/
int start_page; /* The page from which to print */
/*-----------------------------------------------------------------*/
main(argc, argv)
char *argv[];
int argc;
{
int i, j, k, n, page_no; /* counters */
int TAB_WIDTH;
TAB_WIDTH = 8; /* Normal tab size */
int c; /* for listing */
char dma[128]; /* The DMA buffer for BDOS functions */
char printer_buf[SECTORS*128]; /* The printer buffer */
char *list_char; /* Pointer to listing character */
char file_name[15];
char type[4]; /* To see what is the file type. */
int FD; /* The file descriptor */
int CPM; /* To check the CP/M Version number */
char DRIVE; /* The active drive */
char OLD_DRIVE; /* The drive at start of programme */
char OLD_USER; /* The User No. at start of programme */
char USER; /* The User No. for this programme */
/*-----------------------------------------------------------------*/
/* The programme starts here */
/*-----------------------------------------------------------------*/
pec_clear(); /* clear the screen */
header();
/*-----------------------------------------------------------------*/
/* 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 a file name was entered. */
/*-----------------------------------------------------------------*/
if(argc != 2) {
printf("We need to know the name of the file you want to\
list.\n");
printf("Give this in the form - \n\n");
printf(" [d:]filename\n\n");
printf("where 'd:' is an optional drive name and filename is\
specific.\n\n");
gets(file_name);
}
else strcpy(file_name, argv[1]);
up_str(file_name); /* Make sure is upper case */
if(file_name[1] == ':') /* Drive name given */
DRIVE = file_name[0];
else DRIVE = OLD_DRIVE;
/*-----------------------------------------------------------------*/
/* 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(select_dsk(DRIVE) != 0)
exit();
/*-----------------------------------------------------------------*/
/* A file name has been obtained but, as this programme is only */
/* ASCII files, we should at least check for things like "COM" */
/* and "CRL" and "HEX" files. Terminate the programme if any */
/* of these is found to have been specified. */
/*-----------------------------------------------------------------*/
i = j = 0;
while((c = file_name[i]) != '.' && i < 15)
i++;
i++; /* Skip over the period */
while(c != '\0' && i < 15)
{
type[j] = file_name[i];
i++;
j++;
}
if(!strcmp("COM",type))
message4(type);
else if(!strcmp("CRL",type))
message4(type);
else if(!strcmp("HEX",type))
message4(type);
else if(!strcmp("INT", type))
message4(type);
else if(!strcmp("OBJ", type))
message4(type);
else printf("\nWhat page will I start from - \n");
/*-----------------------------------------------------------------*/
/* Get the starting page No. */
/*-----------------------------------------------------------------*/
scanf("%d", &start_page);
line();
printf("Now listing - %s", file_name);
/*-----------------------------------------------------------------*/
/* Now open the nominated file */
/*-----------------------------------------------------------------*/
if((FD = open(file_name, 0)) == -1)
{
printf("\nUnable to open %s file.", file_name);
user_id(OLD_USER);
if(select_dsk(OLD_DRIVE) != 0)
printf("\nUnable to return to starting drive.");
exit();
}
else list_char = printer_buf; /* point to buffer */
/*-----------------------------------------------------------------*/
/* File has been opened, so print the page top */
/*-----------------------------------------------------------------*/
page_no = 1; /* Starting value */
if(page_no >= start_page)
put_top(file_name,page_no);
n = 0; /* Zero the line counter */
k = 0; /* Zero line-character counter */
list_char = printer_buf; /* Point to data to list */
while((i = read(FD,printer_buf,SECTORS)) != 0)
{
j = 0;