home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
messroms.de
/
2007-01-13_www.messroms.de.zip
/
VZ200
/
TOOLS
/
ZCCSRC.ZIP
/
scc
/
io.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-03-01
|
2KB
|
182 lines
/* File io.c: 2.1 (83/03/20,16:02:07) */
/*% cc -O -c %
*
*/
#include <stdio.h>
#include "defs.h"
#include "data.h"
#include "proto.h"
/*
* open input file
*/
int openin(char *p)
{
strcpy(fname, p);
fixname(fname);
if (!checkname(fname))
return (NO);
if ((input = fopen(fname, "r")) == NULL)
{
pl("Open failure\n");
return (NO);
}
kill();
return (YES);
}
/*
* open output file
*/
int openout(void)
{
outfname(fname);
if ((output = fopen(fname, "w")) == NULL)
{
pl("Open failure");
return (NO);
}
kill();
return (YES);
}
/*
* change input filename to output filename
*/
void outfname(char *s)
{
while (*s)
s++;
s[-1] = 'a';
*s++ = 's';
*s++ = 'm';
*s = '\0';
}
/*
* remove NL from filenames
*/
void fixname(char *s)
{
while (*s && *s++ != EOL) ;
if (!*s)
return;
*(--s) = 0;
}
/*
* check that filename is "*.c" or "*.i"
*/
int checkname(char *s)
{
while (*s)
s++;
if (*--s != 'c' && *s != 'i')
return (NO);
if (*--s != '.')
return (NO);
return (YES);
}
void kill(void)
{
lptr = 0;
line[lptr] = 0;
}
void xinline(void)
{
int k;
FILE *unit;
for (;;)
{
if (feof(input))
return;
if ((unit = input2) == NULL)
unit = input;
kill();
while ((k = fgetc(unit)) != EOF)
{
if ((k == EOL) | (lptr >= LINEMAX))
break;
line[lptr++] = k;
}
line[lptr] = 0;
if (k <= 0)
if (input2 != NULL)
{
input2 = inclstk[--inclsp];
fclose(unit);
}
if (lptr)
{
if ((ctext) & (cmode))
{
comment();
outstr(line);
nl();
}
lptr = 0;
return;
}
}
}
int inbyte(void)
{
while (ch() == 0)
{
if (feof(input))
return (0);
preprocess();
}
return (gch());
}
int inchar(void)
{
if (ch() == 0)
xinline();
if (feof(input))
return (0);
return (gch());
}
int gch(void)
{
if (ch() == 0)
return (0);
else
return (line[lptr++] & 127);
}
int nch(void)
{
if (ch() == 0)
return (0);
else
return (line[lptr + 1] & 127);
}
int ch(void)
{
return (line[lptr] & 127);
}
/*
* print a carriage return and a string only to console
*
*/
void pl(char *str)
{
int k;
k = 0;
putchar(EOL);
while (str[k])
putchar(str[k++]);
}