Esempio n. 1
0
static int cmd_ini_op(int argc, char *argv[])
{
	const char usage[] = { \
		" usage:\n" \
		" ini read sector key,read sector " \
	};
	
	if(argc < 4) {
		printf(usage);
		return 0;
	}
	
	char buffer[20];
	
	if (!strcmp(argv[1],"read")) {
		if (!read_profile_string(argv[2], argv[3], buffer, 20, "default_value", "test.ini"))
			printf("reaf failed!\r\n");
		else
			printf("%s\r\n",buffer);
	}
	
	if (!strcmp(argv[1],"write")) {
		if (!write_profile_string(argv[2], argv[3],  argv[4], "test.ini"))
			printf("reaf failed!\r\n");
	}

	return 0;
}
Esempio n. 2
0
int load_redis_conf(const char * buff)
{
	int retv;
	retv = read_profile_string("redis", "server", &g_server.server_addr, "localhost", buff);
	if (retv == FAIL) {
		zlog_error(logger, "redis server addr fetch failed");
		return FAIL;
	}
	zlog_debug(logger, "redis server addr: %s", g_server.server_addr);

	g_server.server_port = read_profile_int("redis", "port", 6379, buff);
	if (g_server.server_port == FAIL) {
		zlog_error(logger, "redis server port fetch failed");
		free(g_server.server_addr);
		return FAIL;
	}
	zlog_debug(logger, "redis server port: %d", g_server.server_port);

	g_server.db_choice = read_profile_int("redis", "db", 0, buff);
	if (g_server.db_choice == FAIL) {
		zlog_error(logger, "redis server db fetch failed");
		free(g_server.server_addr);
		return FAIL;
	}
	zlog_debug(logger, "redis db choice: %d", g_server.db_choice);

	g_server.timeout.tv_sec = 2;
	g_server.timeout.tv_usec = 0;
	g_server.conn = NULL;

	return OK;
}
Esempio n. 3
0
/**
*@brief readFile int value in initialization file\n
* retrieves int value from the specified section in an initialization file
*@param section [in] name of the section containing the key name
*@param key [in] name of the key pairs to value
*@param default_value [in] default value of result
*@param file [in] path of the initialization file
*@return profile int value,if readFile fail, return default value
*/
int read_profile_int(const char *section, const char *key, int default_value,
        const char *file) {
    char value[32] = {0};
    if (!read_profile_string(section, key, value, sizeof(value), NULL, file)) {
        return default_value;
    } else {
        return atoi(value);
    }
}
int LIniFileReadAndWrite::read_profile_int(const char *section, const char *key, int default_value)
{
	char value[32] = {0};
	if(!read_profile_string(section, key, value, sizeof(value), NULL))
	{
		return default_value;
	}
	else
	{
		return atoi(value);
	}
}
Uint32 mythStreamMapServer::TimerCallback(Uint32 interval)
{
	char filename[256] = { 0 };
	read_profile_string("config", "listtxt", filename, 256, "clients.txt", MYTH_INFORMATIONINI_FILE);
	string tmp = showAllClients();
	FILE* file = fopen(filename, "w");
	if (file){
		fprintf(file, tmp.c_str());
		fclose(file);
	}
	return interval;
}
Esempio n. 6
0
File: ps.c Progetto: iceant/mks
BOOL read_ini(char *client_path[], char *hostname[], int *port, char *username[], char* password[]){
	const char *file ="ps.ini";
	const char *section = "integrity";
	const char *client_path_key = "client_path";
	const char *hostname_key = "hostname";
	const char *port_key = "port";
	const char *username_key = "username";
	const char *password_key = "password";
	
	if(!read_profile_string(section, client_path_key, client_path, BUF_SIZE,"",file))
	{
		printf("read ini file fail\n");
		return -1;
	}
	
	if(!read_profile_string(section, hostname_key, hostname, BUF_SIZE,"",file))
	{
		printf("read ini file fail\n");
		return -1;
	}
	
	*port = read_profile_int(section,port_key,7001,file);
	
	if(!read_profile_string(section, username_key, username, BUF_SIZE,"",file))
	{
		printf("read ini file fail\n");
		return -1;
	}
	
	if(!read_profile_string(section, password_key, password, BUF_SIZE,"",file))
	{
		printf("read ini file fail\n");
		return -1;
	}
	
	return 0;
}
Esempio n. 7
0
int test_proc(void)
{
	const char *file ="myconfig.ini";
	const char *section = "student";
	const char *name_key = "name";
	const char *age_key = "age";
	char name[BUF_SIZE]={0};
	char buf[MAX_FILE_SIZE]={0};
	int age;
	int file_size;
	int i;
	
	//write name key value pair
	if(write_profile_string(section,name_key,"Tony",file))
	{
		printf("write name pair to ini file fail\n");
		return -1;
	}
	
	//write age key value pair
	if(write_profile_string(section,age_key,"20",file))
	{
		printf("write age pair to ini file fail\n");
		return -1;
	}
	
	printf("[%s]\n",section);
	//read string pair, test read string value
	if(read_profile_string(section, name_key, name, BUF_SIZE,"",file))
	{
		printf("read ini file fail\n");
		return -1;
	}
	else
	{
		printf("%s=%s\n",name_key,name);
	}

	//read age pair, test read int value.
	//if read fail, return default value
	age = read_profile_int(section,age_key,0,file);
	printf("%s=%d\n",age_key,age);
	
	return 0;
}
Esempio n. 8
0
/**
 * @brief	加载车牌识别参数
 */
void lpn_load_parameter(const char *parameter_file_name,
                        struct lpn_parameter *lpn_parameter)
{
        int  totalcount = 0;
        unsigned int  idx;
        int  m_charcount;
        char temp[255];
        int  i;

        int length;
        const char *path = parameter_file_name;
        memset(lpn_parameter, 0, sizeof(*lpn_parameter));

        length = read_profile_string("config", "gap", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->nCharGapWidth = atoi(temp);
                if ((lpn_parameter->nCharGapWidth == 0) ||
                                (lpn_parameter->nCharGapWidth >= 60)) {
                        lpn_parameter->nCharGapWidth = 45;
                }
        }

        lpn_parameter->LimitWidth = 120;
        length = read_profile_string("config", "LimitWidth", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->LimitWidth = atoi(temp);
                if (lpn_parameter->LimitWidth <= 0) {
                        lpn_parameter->LimitWidth = 120;
                }
        }

        if (lpn_parameter->LimitWidth < 80) {
                lpn_parameter->PlateRowTotal = 2;
        } else {
                lpn_parameter->PlateRowTotal = 3;
        }
        lpn_parameter->PlateRowTotalINI = lpn_parameter->PlateRowTotal;

        lpn_parameter->LimitHeight = 20;
        length = read_profile_string("config", "LimitHeight", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->LimitHeight = atoi(temp);
                if ((lpn_parameter->LimitHeight <= 0) ||
                                (lpn_parameter->LimitHeight >= 80)) {
                        lpn_parameter->LimitHeight = 20;
                }
        }

        lpn_parameter->MaxHeight = 65;
        length = read_profile_string("config", "MaxHeight", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MaxHeight = atoi(temp);
                if  (lpn_parameter->MaxHeight <= 0) {
                        lpn_parameter->MaxHeight = 65;
                }
        }

        lpn_parameter->MaxWidth = 400;
        length = read_profile_string("config", "MaxWidth", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MaxWidth = atoi(temp);
                if  (lpn_parameter->MaxWidth <= 0) {
                        lpn_parameter->MaxWidth = 400;
                }
        }

        lpn_parameter->ImageWidth = 1360;
        length = read_profile_string("config", "imagewidth", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->ImageWidth=atoi(temp);
        }

        lpn_parameter->ImageHeight = 1024;
        length = read_profile_string("config", "imageheight", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->ImageHeight = atoi(temp);
        }
        printf("image size : (%d,%d)\n",
               lpn_parameter->ImageWidth, lpn_parameter->ImageHeight);

        lpn_parameter->MaxCharGapWidth = 25;
        length = read_profile_string("config", "CharGap", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MaxCharGapWidth = atoi(temp);
                if  (lpn_parameter->MaxCharGapWidth <= 0) {
                        lpn_parameter->MaxCharGapWidth = 25;
                }
        }

        lpn_parameter->MinPlateLeft = 2;
        length = read_profile_string("config", "minleft", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MinPlateLeft = atoi(temp);
                if  (lpn_parameter->MinPlateLeft < 0) {
                        lpn_parameter->MinPlateLeft = 2;
                }
        }

        lpn_parameter->MaxPlateRight = 768;
        length = read_profile_string("config", "maxright", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MaxPlateRight = atoi(temp);
                if  (lpn_parameter->MaxPlateRight <= 0) {
                        lpn_parameter->MaxPlateRight = 768;
                }
        }

        lpn_parameter->MinPlateTop = 2;
        length = read_profile_string("config", "mintop", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MinPlateTop = atoi(temp);
                if  (lpn_parameter->MinPlateTop <= 0) {
                        lpn_parameter->MinPlateTop = 2;
                }
        }

        lpn_parameter->MaxPlateBottom = 576;
        length = read_profile_string("config", "maxbottom", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->MaxPlateBottom = atoi(temp);
                if  (lpn_parameter->MaxPlateBottom <=  0) {
                        lpn_parameter->MaxPlateBottom = 576;
                }
        }

        lpn_parameter->MaxPlateBottomINI = lpn_parameter->MaxPlateBottom;
        length = read_profile_string("config", "UseDefaultHZ", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->bUseDefaultHZ = atoi(temp);
        }

        length = read_profile_string("config", "tinymode", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->GL_TinyMode = atoi(temp);
        }

        length = read_profile_string("config", "ALpha", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->gl_alpha = atoi(temp);
                if (lpn_parameter->gl_alpha < 0.3) {
                        lpn_parameter->gl_alpha = 0.58;
                }
        }

        length = read_profile_string("config", "Gamma", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->gl_gamma = atoi(temp);
                if (lpn_parameter->gl_gamma < 0.5) {
                        lpn_parameter->gl_alpha = 0.6;
                }
        }

        lpn_parameter->ImageQuality = 16;
        lpn_parameter->bOutPutOnePlate = 1;

        length = read_profile_string("config", "OutOnlyOne", temp, 255, "1", path);
        if (length != 0) {
                int qa = atoi(temp);
                lpn_parameter->bOutPutOnePlate = (qa > 0);
        }

        lpn_parameter->GL_CareDigi = 0;
        length = read_profile_string("config", "caredigi", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->GL_CareDigi = atoi(temp)>0;
        }

        lpn_parameter->GL_LimitRatio = 80;
        length = read_profile_string("config", "LimitRatio", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->GL_LimitRatio = atoi(temp);
                if (lpn_parameter->GL_LimitRatio < 70) {
                        lpn_parameter->GL_LimitRatio = 70;
                } else if (lpn_parameter->GL_LimitRatio > 85) {
                        lpn_parameter->GL_LimitRatio = 85;
                }
        }

        lpn_parameter->GL_ABCRatio = 73;
        length = read_profile_string("config", "ABCRatio", temp, 255, "", path);
        if (length != 0) {
                lpn_parameter->GL_ABCRatio = atoi(temp);
                if (lpn_parameter->GL_ABCRatio < 70) {
                        lpn_parameter->GL_ABCRatio = 70;
                } else if (lpn_parameter->GL_ABCRatio>85) {
                        lpn_parameter->GL_ABCRatio = 85;
                }
        }

	length = read_profile_string("CHAR", "Default", temp, 255, "", path);
        if (length != 0) {
                strncpy(lpn_parameter->DefaultChar,temp,3);
        }

        memset(lpn_parameter->FilterString, 0, sizeof(lpn_parameter->FilterString));
        for (idx = 0; idx < (sizeof(lpn_parameter->FilterString) /
                                sizeof(lpn_parameter->FilterString[0])); idx++) {

                char ini_filter[20] = "";
                sprintf(ini_filter, "%s%d", "filter", idx);
                length = read_profile_string("Force", ini_filter, temp, 255, "", path);
                if (length != 0) {
                        unsigned int t = 0;
                        for (t = 1; t < (sizeof(lpn_parameter->FilterString) /
                                                sizeof(lpn_parameter->FilterString[0])); t++) {
                                strcpy(lpn_parameter->FilterString[t], temp);
                        }
                }
        }

        memset(lpn_parameter->ChangeABC, 0, sizeof(lpn_parameter->ChangeABC));
        for (idx = 0; idx < (sizeof(lpn_parameter->ChangeABC) /
                                sizeof(lpn_parameter->ChangeABC[0])); idx++) {

                char ini_change[20] = "";
                memset(ini_change,0,20);
                sprintf(ini_change, "%s%d", "change",idx+1);
                length = read_profile_string("Force", ini_change, temp, 255, "", path);
                if (length != 0) {
                        unsigned int t = 0;
                        for (t = 1; t < (sizeof(lpn_parameter->FilterString)
                                                / sizeof(lpn_parameter->FilterString[0])); t++) {
                                strcpy(lpn_parameter->ChangeABC[t], temp);
                        }
                }
        }

        length = read_profile_string("CHAR", "defaultabc", temp, 255, "", path);
        lpn_parameter->DefaultABC[0] = 'A';
        if (length != 0) {
                strncpy(lpn_parameter->DefaultABC,temp,2);
        }

        length = read_profile_string("Force", "chinese", temp, 255, "", path);
        if (length != 0) {
                strcpy(lpn_parameter->HZFilterString,temp);
        }

        length = read_profile_string("CHAR", "Count", temp, 255, "", path);
        if (length != 0) {
                int n = atoi(temp);
                if (n > 0) {
                        lpn_parameter->TempletCount = n;
                        memset(lpn_parameter->ocrHZ,0,250);

                        for (i = 0; i < n; i++) {
                                char tmp[20] = "";
                                sprintf(tmp,"%s%d","char",i);
                                memset(temp, 0, 255);
                                length = read_profile_string("CHAR", tmp, temp, 255, "", path);

                                if (length > 0) {
                                        sprintf(lpn_parameter->ocrHZ,"%s%s",
                                                lpn_parameter->ocrHZ,temp);
                                        if ((i >= 0 && i <= 31) || i >= 92 || i == 51) {
                                                sprintf(lpn_parameter->HZBufferLeft,"%s%s",
                                                        lpn_parameter->HZBufferLeft,temp);
                                        }
                                        if (i == 51 || i == 24 || i > 92 || i == 33) {
                                                sprintf(lpn_parameter->HZWhiteLPN,"%s%s",
                                                        lpn_parameter->HZWhiteLPN,temp);
                                        }
                                }

                                m_charcount = 0;
                                memset(temp,0,255);
                                length = read_profile_string("section",tmp, temp,255,"",path);
                                if (length != 0) {
                                        m_charcount=atoi(temp);
                                        lpn_parameter->charocrcount[i] = m_charcount;
                                        totalcount+=m_charcount;

                                }
                        }
                        lpn_parameter->allocrcount = totalcount;
                }
        }
}