📄 input.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include <string.h>
#define MAXLINE 512
#define BUFSIZE 4096
int lineno = 0;
long bsize = -1;
FILE* file = NULL;
unsigned char* cp = NULL;
unsigned char* limit = NULL;
unsigned char* line = NULL;
unsigned char buffer[MAXLINE + 1 + BUFSIZE + 1] = {0};
int fillbuf(void);
void nextline(void);
void inputInit(void);
void nextline() {
do {
if (cp >= limit) {
fillbuf();
if (cp >= limit)
cp = limit;
if (cp == limit)
return;
} else
lineno++;
for (line = cp; *cp==' ' || *cp=='\t'; cp++)
;
} while (*cp == '\n' && cp == limit);
if (*cp == '#') {
//resynch(); //预处理
//for(; *cp != '\n' && cp < limit; ++cp);
//nextline();
printf("don't support the preprocess now!!!! sorry\r\n");
exit(0);
}
}
void inputInit() {
limit = cp = &buffer[MAXLINE+1];
bsize = -1;
lineno = 0;
fillbuf();
if (cp >= limit)
cp = limit;
nextline();
}
int fillbuf()
{
if (bsize == 0)
return 0;
if (cp >= limit)
cp = &buffer[MAXLINE+1];
else {
int n = limit - cp;
unsigned char *s = &buffer[MAXLINE+1] - n;
assert(s >= buffer);
line = s - (cp - line);
while (cp < limit)
*s++ = *cp++;
cp = &buffer[MAXLINE+1] - n;
}
assert(file);//assue that file has been initialized
//bsize = fread(file, &buffer[MAXLINE+1], BUFSIZE);
bsize = fread ((void*)&buffer[MAXLINE +1], 1, BUFSIZE, file);
if (bsize < 0) {
printf("read error\n");
exit(1);
}
limit = &buffer[MAXLINE+1+bsize];
*limit = '\n';
return bsize;
}
void display()
{
char* disp = NULL;
int n = limit - cp;
if(n == 0) {
printf("the display content is empty\r\n");
return ;
}
disp = (char*)malloc(n+1);
memcpy(disp, cp, n);
disp[n] = '\0';
printf("%s", disp);
free(disp);
cp += n;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -