📄 io.c
字号:
/* File io.c: 2.1 (83/03/20,16:02:07) */
/*% cc -O -c %
*
*/
#include <stdio.h>
#include <string.h>
#include "defs.h"
#include "data.h"
#include "headers.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) {
char *p;
p = s;
while (*s)
s++;
s--;
s--;
*s = '\0';
strcpy(module, p);
*s++ = '.';
*s++ = 's';
*s++ = '9';
*s++ = '0';
*s++ = '\0';
}
/*
* remove NL from filenames
*
*/
void fixname(char *s) {
while (*s && *s++ != EOL)
;
if (!*s)
return;
*(--s) = 0;
}
/*
* check that filename is "*.c"
*/
int checkname(char *s) {
while (*s)
s++;
if (*(--s) != 'c')
return (NO);
if (*(--s) != '.')
return (NO);
return (YES);
}
void kill() {
lptr = 0;
line[lptr] = 0;
}
void xinline() {
int k;
FILE *unit;
while (1) {
if (feof(input))
return;
if ((unit = input2) == NULL) {
unit = input;
InInclude = FALSE;
}
kill();
while ((k = fgetc(unit)) != EOF) {
if ((k == EOL) | (lptr >= LINEMAX))
break;
line[lptr++] = k;
}
line[lptr] = 0;
StructIsIndexed = FALSE;
PointerFlag = Indexing = StructureOffset = 0;
if (!InInclude)
LineNum++;
if (k <= 0)
if (input2 != NULL) {
input2 = inclstk[--inclsp];
fclose(unit);
}
if (lptr) {
if (ctext) {
if (iflag || inclsp == 0) {
comment();
outstr(line);
nl();
}
}
lptr = 0;
return;
}
}
}
char inbyte() {
while (ch() == 0) {
if (feof(input))
return (0);
preprocess ();
}
return (gch());
}
char inchar() {
if (ch() == 0)
xinline();
if (feof(input))
return (0);
return (gch());
}
char gch() {
if (ch() == 0)
return (0);
else
return (line[lptr++] & 127);
}
char nch() {
if (ch() == 0)
return (0);
else
return (line[lptr + 1] & 127);
}
// Backup to the previous name
void prevname(void) {
while (lptr && ch() != '(')
lptr--;
lptr--;
if (lptr && ch() == ' ') {
do {
lptr--;
} while (lptr && ch() == ' ');
}
while (lptr && ch() != ' ')
lptr--;
while (ch() == ' ' || ch() == '*')
lptr++;
}
// Return TRUE if line is not terminated by a ')' followed by a ';'
int nosemi(void) {
int i, j;
i = lptr;
j = 0;
while (ch()) {
if (ch() == '(')
j++;
if (ch() == ')') {
if (--j == 0) {
lptr++;
break;
}
}
lptr++;
}
while (ch() == ' ')
lptr++;
if (ch() == ';') {
lptr = i;
return (0);
}
else {
lptr = i;
return (1);
}
}
char ch() {
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++]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -