📄 public.c
字号:
/********************************************************************/
/* */
/* File Name : public.c */
/* Description : include public functions used in processes Gather,*/
/* Monitor, Standard. */
/* Progrmmer: : public */
/* Create Date : 11 Dec. 2001 */
/* Last Update : */
/* Programming Language : C */
/* compiler : cc */
/* Memory Model : small */
/* */
/* Assumptions : */
/* */
/* */
/* I/O specification */
/* Input Parameter : NO */
/* */
/* Ouput Parameter : NO */
/* */
/* Calling Format : */
/* */
/* Library : */
/* Remarks */
/* */
/* Modification History: */
/* Programmer : */
/* Date : */
/* Amendments : */
/* */
/********************************************************************/
#include "public.h"
#include "ourlib.h"
#include "monitor.h"
/********************************************************************/
/* */
/* Function Name : prune */
/* Function : get rid of the blank characters at the head of*/
/* and the end of the string */
/* */
/* */
/* Input : the string which is to be pruned */
/* Parameter */
/* */
/* Output : the string have been pruned */
/* Parameter */
/* */
/* Onput : NO */
/* Parameter */
/* */
/* Return values : the string have been pruned */
/* Modification History: */
/* Programmer : lht */
/* Date : 2001/11/16 */
/* Amendments : the define of the function */
/* */
/********************************************************************/
char *prune(const char *acp_string)
{
/*declare and define the parameters of the function*/
char lcz_return[LEN];
int li_loop = 0;
int li_len = 0;
int li_temp = 0;
memset(lcz_return, 0x00, sizeof(lcz_return));
/*get rid of the blank at the head of the string*/
li_len = strlen(acp_string);
for (li_loop = 0; li_loop < li_len; li_loop++)
{
li_temp = isspace(acp_string[li_loop]);
if (0 == li_temp)
{
break;
}
}
strcpy(lcz_return, &acp_string[li_loop]);
/*get rid of the blank at the end of the string*/
li_len = 0;
li_len = strlen(lcz_return);
for (li_loop = li_len - 1; li_loop > 0; li_loop--)
{
li_temp = isspace(lcz_return[li_loop]);
if (0 != li_temp)
{
lcz_return[li_loop] = 0x00;
}
else
{
break;
}
}
/*return the result string*/
return(lcz_return);
}//end of function prune
/********************************************************************/
/* */
/* Function Name : find_index */
/* Function : get the index of the given character */
/* */
/* */
/* Input : the string and the character */
/* Parameter */
/* */
/* Output : */
/* Parameter */
/* */
/* Onput : NIL */
/* Parameter */
/* */
/* Return values : the index of the character in the string */
/* */
/********************************************************************/
int find_index(const char *acp_string, /*string in which find the charater*/
char ac_char /*character appointed to find*/
)
{
/*initialize of the function*/
int li_index = 0; /*index will been returned*/
int li_loop = 0; /*loop_for counter*/
int li_length = 0; /*length of input string*/
/*get the length of input string*/
li_length = strlen(acp_string);
/*find the given char in the string*/
for (li_loop = 0; li_loop < li_length; li_loop ++)
{
if (ac_char == acp_string[li_loop])
{
break;
}
}
/*return the index of the char in the string*/
li_index = li_loop;
return(li_index);
}
/********************************************************************/
/* */
/* Function Name : read_para */
/* Description : The function read the parameters from the given */
/* file with full path. */
/* Progrmmer: : lht */
/* Create Date : 13 Nov. 2001 */
/* Last Update : */
/* Programming Language : C */
/* compiler : cc */
/* Memory Model : small */
/* */
/* Assumptions : The parameters_file has placed into a given path. */
/* */
/* I/O specification */
/* Input Parameter:*ai_error :set 0 before the function be invoked */
/* *ai_count :set 0 before the function be invoked */
/* acza_read_para :set NULL before be invoked */
/* acz_file_name :name of the parameter_file */
/* acz_para_type :type of the parameter */
/* acz_para_name :name of the parameter */
/* */
/* Ouput Parameter :*ai_error : */
/* set 0 when success. */
/* -101 -- "Parameter file name error";*/
/* -102 -- "Parameter type error!"; */
/* -103 -- "Parameter name error!"; */
/* -104 -- "Open parameter file error";*/
/* *ai_count :set 0 indicate no needed parameter in*/
/* the parameter file; */
/* nozero indicate the number of the */
/* readed parameter. */
/* NOTICE: ai_count base 1. */
/* */
/* Calling Format: int counter; */
/* int error=0; */
/* char para[LEN][LEN]; */
/* read_para(&error, &count, para, "gather.ini", */
/* "interval","interval",); */
/* */
/* Library : NO */
/* Remarks */
/* */
/* Modification History: */
/* Programmer : yiwu */
/* Date : 2002/07/30 */
/* Amendments : the define of the function */
/* */
/********************************************************************/
void read_para( int *aip_error, /*type of ERROR*/
int *aip_count, /*number of the parameters*/
char acza_read_para[][LEN], /*the result arry*/
FILE *lh_para, /*parameter file point*/
char *acz_para_type, /*type of the parameter*/
char *acz_para_name /*name of the parameter*/
)
{
/*declare and define the parameters of the function*/
char lcz_line_buf[LEN]; /*save one line_string readed from file*/
char lcz_left[LEN]; /*left substring of '='*/
char lcz_right[LEN]; /*left substring of '='*/
char lcz_full_type[LEN]; /*'['+para_type+']'*/
char lcz_temp[LEN]; /*temp string*/
int li_index = 0; /*index of the char in string*/
int li_temp = 0; /*temp int in the function*/
int li_count = 0; /*count of the parameter readed*/
memset(lcz_line_buf, 0x00, sizeof(lcz_line_buf));
memset(lcz_left, 0x00, sizeof(lcz_left));
memset(lcz_right, 0x00, sizeof(lcz_right));
memset(lcz_full_type, 0x00, sizeof(lcz_full_type));
memset(lcz_temp, 0x00, sizeof(lcz_temp));
if( NULL == lh_para )
{
*aip_error = 101;
return;
}
/*judge the parameter of the function*/
li_temp = 0;
li_temp = strlen(acz_para_type);
if (NULL == acz_para_type || 0 == li_temp)
{
*aip_error = 102; /*error = -102 lack acz_para_type*/
return;
}
li_temp = 0;
li_temp = strlen(acz_para_name);
if (NULL == acz_para_name || 0 == li_temp)
{
*aip_error = 103; /*error = -103 lack acz_para_name*/
return;
}
/*locate the pointer to the begin of the stream*/
fseek(lh_para, 0L, SEEK_SET);
/*set the full parameter type with "[para_type]"*/
sprintf( lcz_full_type, "[%s]", acz_para_type);
/*loop:read para_file,locate the "para_type"*/
while (!feof(lh_para))
{
/*read one line from file into line_buffer*/
memset(lcz_line_buf, 0x00, sizeof(lcz_line_buf));
fgets(lcz_line_buf, sizeof(lcz_line_buf), lh_para);
/*prune the blank characters in the string */
memset(lcz_temp, 0x00, sizeof(lcz_temp));
strcpy(lcz_temp, prune(lcz_line_buf));
memset(lcz_line_buf, 0x00, sizeof(lcz_line_buf));
strcpy(lcz_line_buf, lcz_temp);
/* check para type */
li_temp = 0;
li_temp = strncmp(lcz_line_buf, lcz_full_type, strlen(lcz_full_type));
if (0 == li_temp)
{
li_count ++;
break;
}
}/*end of while:locate "[para_type]" */
/* check para type in para_file */
if( li_count != 1 )
{
err_msg( "no para type in file.\n" );
*aip_error = 104; /*error = -103 lack acz_para_name*/
return;
}
li_count = 0;
/*loop:locate the "para_name" in the para_file*/
while (!feof(lh_para))
{
/*read one line from file into line_buffer*/
memset(lcz_line_buf, 0x00, sizeof(lcz_line_buf));
fgets(lcz_line_buf, sizeof(lcz_line_buf), lh_para);
/*prune the blank in the substring*/
memset(lcz_temp, 0x00, sizeof(lcz_temp));
strcpy(lcz_temp, prune(lcz_line_buf));
memset(lcz_line_buf, 0x00, sizeof(lcz_line_buf));
strcpy(lcz_line_buf, lcz_temp);
/*if the line_buf is NULL,then continue*/
li_temp = 0;
li_temp = strlen(lcz_line_buf);
if (0 == li_temp)
{
continue;
}
/*find '#' in the line_buffer*/
if ( lcz_line_buf[0] == '#')
{
continue;
}
/*find '[' in the line_buffer*/
if (strchr(lcz_line_buf, '['))
{
break;
}
/*locate '=' in the line_buffer*/
li_index = find_index(lcz_line_buf, '=');
/*if not finded the char, the index equal to the length of the string*/
li_temp = 0;
li_temp = strlen(lcz_line_buf);
if (li_index == li_temp)
{
continue;
}
/*get the left substring*/
memset(lcz_left, 0x00, sizeof(lcz_left));
strncpy(lcz_left, lcz_line_buf, li_index);
memset(lcz_temp, 0x00, sizeof(lcz_temp));
strcpy(lcz_temp, prune(lcz_left));
memset(lcz_left, 0x00, sizeof(lcz_left));
strcpy(lcz_left, lcz_temp);
/*find "para_name" in the left substring*/
li_temp = strcmp(lcz_left, acz_para_name);
if (0 == li_temp)
{
/*get the right substring*/
memset(lcz_right, 0x00, sizeof(lcz_right));
strcpy(lcz_right, &(lcz_line_buf[li_index+1]));
memset(lcz_temp, 0x00, sizeof(lcz_temp));
strcpy(lcz_temp, prune(lcz_right));
memset(lcz_right, 0x00, sizeof(lcz_right));
strcpy(lcz_right, lcz_temp);
/*save the para_string into the arry*/
memset(acza_read_para[li_count], 0x00,
sizeof(acza_read_para[li_count]));
strcpy(acza_read_para[li_count], lcz_right);
li_count++;
}/*end of if:find "para_name"*/
}/*end of while:locate the "para_name"*/
/*close the para_file*/
*aip_count = li_count;
*aip_error = 0;
return;
}/*end of function read_para*/
/********************************************************************/
/* */
/* Function Name : get_para_info */
/* Description : The function read the simple special */
/* parameters from the parameter file */
/* Progrmmer : genius.xuyong */
/* Create Date : 15 Aug 2002 */
/* Last Update : */
/* Programming Language : C */
/* compiler : cc */
/* Memory Model : small */
/* */
/* Assumptions : The parameters_file has placed into a given path. */
/* */
/* I/O specification */
/* Input Parameter : acz_para_type : type of the parameter */
/* acz_para : name of the parameter */
/* acz_value : addr of need return */
/* Ouput Parameter : acz_value : value of the parameter */
/* Library : NO */
/* Sample : get_para_info( "device", \ */
/* "device", \ */
/* lcz_device \ */
/* ); */
/* the result is lcz_device get "AAA" */
/* Remarks */
/* */
/* Modification History: */
/********************************************************************/
int get_para_info( FILE* ah_file,
char* acz_paratype, \
char* acz_para, \
char* acz_value \
)
{
char lcza_para[LEN][LEN];
int li_return;
int li_error;
int li_count;
/*Call the function,get local device*/
read_para(&li_return, /*type of ERROR*/
&li_count, /*number of the parameters*/
lcza_para, /*the result arry*/
ah_file, /*parameter file*/
acz_paratype, /*type of the parameter*/
acz_para /*name of the parameter*/
);
if ( 0 == li_return )
{
strcpy(acz_value,lcza_para[0]);
}
return ( 0 );
}
/********************************************************************/
/* */
/* Function Name : get_para_array */
/* Description : The function read the multi-special */
/* parameters from the parameter file */
/* Progrmmer : genius.xuyong */
/* Create Date : 15 Aug 2002 */
/* Last Update : */
/* Programming Language : C */
/* compiler : cc */
/* Memory Model : small */
/* */
/* Assumptions : The parameters_file has placed into a given path. */
/* */
/* I/O specification */
/* Input Parameter : acz_para_type : type of the parameter */
/* acz_para : name of the parameter */
/* acz_value : addr of need return */
/* Ouput Parameter : acz_value : value of the parameter */
/* Library : NO */
/* Sample : get_para_array( "processes", \ */
/* "process", \ */
/* lcza_process \ */
/* ); */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -