checkc.c

来自「一个程序拿来对一个C文件做基本的语法检查」· C语言 代码 · 共 72 行

C
72
字号
#include <stdio.h>#include <string.h>#include "Stack.h"#define cMAX_BUFFER_SIZE   1024int main(int argc, char *argv[]){    FILE *fp;    BYTE aBuffer[cMAX_BUFFER_SIZE];	BYTE *pTmp, *pEnd;	UINT32 dwByteRead, line = 1;    TOKEN token, preferToken = NONE;    if(2 != argc){       printf("Bad command format!\n");       printf("checkc <sourcefile> \n");       return 1;    }    if(NULL == (fp = fopen(argv[1], "r"))){        printf("The source file doesn\'t exist or have no permission to access it.\n");        return 2;    }    while(!feof(fp)){		memset(aBuffer, 0, cMAX_BUFFER_SIZE);        dwByteRead = fread(aBuffer, 1, cMAX_BUFFER_SIZE, fp);		pTmp = &aBuffer[0];		pEnd = pTmp + dwByteRead;		while(NONE != (token = GetNextToken(&pTmp, pEnd, preferToken))){			if(Newline == token)
				line++;

			if(isTokenMatchTop(token)){				pop();
				preferToken = NONE;
			}			else{
				switch(token){
					case SingleQuotation:
					case DoubleQuotation:
						push(token, line);
						preferToken = token;
						break;
					case LeftCommentLine:
						push(token, line);
						preferToken = RightCommentLine;
						break;
					case DoubleSlashComment:
						push(token, line);
						preferToken = Newline;
						break;
					case Newline:
						break;
					default:						push(token, line);						preferToken = NONE;
						break;
				}			}		}    }    fclose(fp);        PrintError();
	return 0; }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?