📄 cmpfull.c
字号:
/******************************************************************
Update by qiyan 2001-02-19
This file is to cmp file full=on.
input : cmp file.
output: 1 , 0 or -1
Input file format__________________________________________________
#
#
[switch]
full = on
#
#
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
/*************************************************************
Function: Trim()
删除字符串前后的空格
*************************************************************/
void trim(char * str, char * output)
{ char ret[120];
int len;
strcpy(ret ,str);
while (ret[0] == ' ')
{
strcpy(ret, &ret[1]); //去前面的空格
};
len = strlen(ret);
while(ret[len-1]==' ') //去后面的空格
{
ret[len-1]='\0';
len = strlen(ret);
};
strcpy(output, ret);
return;
}
/*************************************************************
Function: ProfileString()
从控制文件filename中,读取heading标题下,key项目的值。
*************************************************************/
void ProfileString(char * filename, char * heading, char * key, char * value)
{
FILE * fp;
char file[80];
char sValue[120];
char filestr[120],tmpstr[120];
int len = 120;
char * sp;
strcpy(sValue, "");
strcpy(file, filename);
if((fp = fopen(file, "r+")) ==NULL) {
printf("\nCan't open cmpfull file:%s\n", file);
exit;
}
do
{
if (fgets(filestr,120,fp)==NULL) break; //读控制文件的一行到filestr
if (filestr ==NULL) break;
trim(filestr, tmpstr); //去掉首尾空格
strcpy(filestr, tmpstr);
if (filestr[0] == '[' ) { //标题行
if (strstr(filestr, heading)!=NULL){ //且正好是heading所指标题行
do{
if (fgets(filestr,120,fp)==NULL) break ; //下一行
if ((filestr ==NULL)||(filestr[0] == '[')) break;
trim(filestr, tmpstr); //去掉首尾空格
strcpy(filestr, tmpstr);
if ((sp=strstr(filestr, key))!=NULL){
if (sp -filestr ==0 ) { //找到相关key
sp = strchr(filestr, '=');
if (sp != NULL ) { //找到了key值
strcpy(sValue, sp+1);
//sValue还可能包含回车符,也必须去掉
fclose(fp);
sp = strchr(sValue, '\n');
if (sp !=NULL) {
sValue[sp-sValue]='\0';
}
trim(sValue, sValue);
strcpy(value ,sValue);
return;
}
}
}
}while (filestr != NULL && filestr[0] != '[');
}
}
} while (filestr != NULL);
fclose(fp);
sp = strchr(sValue, '\n');
if (sp !=NULL) {
sValue[sp-sValue]='\0';
}
trim(sValue, sValue);
strcpy(value ,sValue);
}
int main(int argc,char **argv){
char full_sw[10];
char control[80];
int prog_debug = 0;
if (argc!=2)
{
printf("\nUsage : load <CMP FILE>\n") ;
return -1;
}
strcpy(control, argv[1]);
//读取配置文件
ProfileString(control, "switch", "full", full_sw);
// 决定返回值 ******************************************************
if (strcmp(full_sw, "on")==0) {
return(1);
}
else{
return(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -