예제 #1
0
파일: msg_conf.cpp 프로젝트: Atemo/rathena
/*
 * Read txt file and store them into msg_table
 */
int _msg_config_read(const char* cfgName,int size, char ** msg_table)
{
	uint16 msg_number, msg_count = 0, line_num = 0;
	char line[1024], w1[8], w2[512];
	FILE *fp;
	static int called = 1;

	if ((fp = fopen(cfgName, "r")) == NULL) {
		ShowError("Messages file not found: %s\n", cfgName);
		return -1;
	}

	if ((--called) == 0)
		memset(msg_table, 0, sizeof (msg_table[0]) * size);

	while (fgets(line, sizeof (line), fp)) {
		line_num++;
		if (line[0] == '/' && line[1] == '/')
			continue;
		if (sscanf(line, "%7[^:]: %511[^\r\n]", w1, w2) != 2)
			continue;

		if (strcmpi(w1, "import") == 0)
			_msg_config_read(w2,size,msg_table);
		else {
			msg_number = atoi(w1);
			if (msg_number >= 0 && msg_number < size) {
				if (msg_table[msg_number] != NULL)
					aFree(msg_table[msg_number]);
				size_t len = strnlen(w2,sizeof(w2)) + 1;
				msg_table[msg_number] = (char *) aMalloc(len * sizeof (char));
				safestrncpy(msg_table[msg_number], w2, len);
				msg_count++;
			}
			else
				ShowWarning("Invalid message ID '%s' at line %d from '%s' file.\n",w1,line_num,cfgName);
		}
	}

	fclose(fp);
	ShowInfo("Done reading " CL_WHITE "'%d'" CL_RESET " messages in " CL_WHITE "'%s'" CL_RESET ".\n",msg_count,cfgName);

	return 0;
}
예제 #2
0
파일: msg_conf.c 프로젝트: yakiie/Emulador
/*==========================================
 * Read Message Data
 *------------------------------------------*/
int _msg_config_read(const char* cfgName,int size, char ** msg_table)
{
    int msg_number;
    char line[1024], w1[1024], w2[1024];
    FILE *fp;
    static int called = 1;

    if ((fp = fopen(cfgName, "r")) == NULL) {
	ShowError("Messages file not found: %s\n", cfgName);
	return 1;
    }

    if ((--called) == 0)
	memset(msg_table, 0, sizeof (msg_table[0]) * size);

    while (fgets(line, sizeof (line), fp)) {
	if (line[0] == '/' && line[1] == '/')
	    continue;
	if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
	    continue;

	if (strcmpi(w1, "import") == 0)
	    _msg_config_read(w2,size,msg_table);
	else {
	    msg_number = atoi(w1);
	    if (msg_number >= 0 && msg_number < size) {
		if (msg_table[msg_number] != NULL)
		    aFree(msg_table[msg_number]);
		msg_table[msg_number] = (char *) aMalloc((strlen(w2) + 1) * sizeof (char));
		strcpy(msg_table[msg_number], w2);
	    }
	}
    }

    fclose(fp);
    ShowInfo("Finished reading %s.\n",cfgName);

    return 0;
}
예제 #3
0
파일: login.cpp 프로젝트: AlmasB/rathena
/// Msg_conf tayloring
int login_msg_config_read(char *cfgName){
	return _msg_config_read(cfgName,LOGIN_MAX_MSG,msg_table);
}