home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
UTILITY
/
TYPEW.ZIP
/
TYPEW.C
< prev
next >
Wrap
Text File
|
1994-04-22
|
4KB
|
194 lines
/*
* This program is a MS-DOS TYPE command replacement (sorta) to display
* text files with embeded WWIV Heart Codes with the appropriate colors.
*
* Version 0 -=- Charles R. Grosvenor Jr. -=- February 12, 1994
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <conio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
char *format( char *fmt, ... ); /* format multiple parameters into */
/* a single string */
void myputs(char *string, int count);
int pausekey(void);
int check_exist(char *s);
int print_file(char *print_filename);
char *format( char *fmt, ... )
/*
* Purpose : Format a list of parameters into a single string
*
* Revision: Level 0 -=- Dan Walters
*/
{
va_list v;
static char s[512];
va_start( v, fmt );
vsprintf( s, fmt, v );
va_end( v );
return( s );
}
int check_exist(char *s)
{
int f;
f=open(s,O_RDONLY | O_BINARY);
if (f>0)
{
close(f);
return(1);
}
else
return(0);
}
int pausekey(void)
/* Name : pausekey
/* Dependicies: none
/* Purpose : IF a SPACE is hit, returns a 1, otherwise a 0 is returned
/* Revision : October 17, 1993 -=- Charles R. Grosvenor Jr. -=- Level 0
*/
{
int return_value=0;
myputs("0[1PAUSE0, 2SPACE TO ABORT0, 1any other key continues0]",0);
if (getch()==' ')
{
return_value=1;
}
cprintf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
myputs(" ",0);
cprintf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
return(return_value);
}
void myputs(char *string, int count)
/* display a string with embedded color codes */
{
int loop=0, actual_loop=0;
while ( (string[loop]!='\0') && ( (actual_loop<=count) || (count<=0) ) )
{ if (string[loop]=='')
{
loop++;
switch(string[loop])
{
case '0' : textattr(WHITE + (BLACK<<4)); break;
case '1' : textattr(LIGHTCYAN + (BLACK<<4)); break;
case '2' : textattr(YELLOW + (BLACK<<4)); break;
case '3' : textattr(LIGHTMAGENTA + (BLACK<<4)); break;
case '4' : textattr(WHITE + (BLUE<<4)); break;
case '5' : textattr(GREEN + (BLACK<<4)); break;
case '6' : textattr(RED + (BLACK<<4) + BLINK); break;
case '7' : textattr(BLUE + (BLACK<<4)); break;
default : textattr(WHITE + (BLACK<<4)); break;
}
loop++;
}
else if (string[loop]=='\t')
{
cprintf(" ");
loop++;
actual_loop+=5;
}
else {
cprintf("%c",string[loop]);
loop++;
actual_loop++;
}
}
}
int print_file(char *print_filename)
/* Name : print_file
/* Dependicies: myputs, pauskey
/* Purpose : Display a heart code embeded text file, pausing every 22
* lines or so.
/* Revision : October 17, 1993 -=- Charles R. Grosvenor Jr. -=- Level 0
*/
{
FILE *print_file;
char print_line[241];
int line_count=0, stop_file=0;
if (check_exist(print_filename))
{
if ((print_file=fopen(print_filename, "r")) == NULL)
{
myputs("6Unable to open output file for display0\r\n\r\n",0);
}
else
{
line_count=0;
while ( (!feof(print_file)) && (!stop_file) )
{
fgets(print_line,240,print_file);
if (print_line[strlen(print_line)-1]=='\n')
{
strcat(print_line, "\r");
}
myputs(print_line,0);
line_count++;
if (line_count>22)
{
if (pausekey())
{
stop_file=1;
}
else
{
line_count=0;
}
}
}
fclose(print_file);
}
return(0);
}
else
{
return(1);
}
}
void main(int argc, char **argv)
{
while (argc)
{
if (argv[argc])
{
myputs(format("\r\n1Displaying File0:2 %s0\n\r\n\r",argv[argc]),0);
if (check_exist(argv[argc]))
{
print_file(argv[argc--]);
}
else
{
myputs("6That file was not able to be displayed0\n\r",0);
argc--;
}
}
else
{
argc--;
}
}
myputs("\r\n1All specified files displayed0\r\n",0);
}