📄 cmdline.cpp
字号:
#include <iostream.h>
#include <string.h>
#include "cmdLine.h"
void showHelp(void){
cout<<"===PL/0编译器==="<<endl<<endl
<<"Usage: pl0 [/l] [/c] [source] [destination]"<<endl<<endl
<<"source\t\t要编译的文件"<<endl
<<"destination\t编译输出的文件名"<<endl
<<"/l\t\t输出文件中给出行号"<<endl
<<"/c\t\t输出文件中给出列 号"<<endl;
}
bool parseCmdLine(int argc,char *argv[],CmdLine& cl){
bool rtn=true;
int file=2;
bool haveSwitch=false;
for(int i=1;i<argc;++i){
if('/' != argv[i][0] && '-' != argv[i][0] ){
if( false == haveSwitch ){
switch(file){
case 2:
strcpy(cl.inFileName,argv[i]);
--file;
break;
case 1:
strcpy(cl.outFileName,argv[i]);
--file;
break;
default:
cout<<"多余的文件名参数:"<<argv[i]<<endl;
rtn=false;
}
}else{
if(!strcmp(argv[i], "l" ))
cl.showLineNum=true;
else if(!strcmp(argv[i], "c" ))
cl.showColNum=true;
else{
cout<<"11参数格式不正确 - \""<<argv[i] <<"\"."<<endl;
rtn=false;
}
haveSwitch=false;
}
}else if( !strcmp(argv[i], "/" ) || !strcmp(argv[i], "-" ) ){
haveSwitch=true;
}else {
if(!strcmp(argv[i], "/l" ) ) cl.showLineNum=true;
else if(!strcmp(argv[i],"/c") ) cl.showColNum=true;
else{
cout<<"22参数格式不正确 - \""<<argv[i]+1 <<"\"."<<endl;
rtn=false;
}
haveSwitch=false;
}
}
if(file>0){
cout<<"文件的参数不够。"<<endl;
rtn=false;
}
return rtn;
}
CmdLine::CmdLine()
:showLineNum(false),
showColNum(false)
{
inFileName[0]=0;
outFileName[0]=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -