예제 #1
0
void feed_file ( const char * filename){
    char phrase[1024], pinyin[1024];
    guint32 n_freq;
    FILE * infile = fopen(filename, "r");
    if ( NULL == infile ){
        fprintf(stderr, "Can't open file %s.\n", filename);
        exit(ENOENT);
    }
    while ( !feof(infile)){
	fscanf(infile, "%s", phrase);
	fscanf(infile, "%s", pinyin);
	fscanf(infile, "%u", &n_freq);
	if (feof(infile))
		break;
	feed_line(phrase, pinyin, n_freq);
    }
    fclose(infile);
}
예제 #2
0
파일: ihex.c 프로젝트: Murali8051/Aurava
int ihex_extract(FILE *in, binfile_imgcb_t cb, void *user_data)
{
	char buf[128];
	int lno = 0;
	address_t segment_offset = 0;

	rewind(in);
	while (fgets(buf, sizeof(buf), in)) {
		int len = strlen(buf);
		int i;
		uint8_t data[64];
		int nbytes;

		lno++;
		if (buf[0] != ':') {
			printc_err("ihex: line %d: invalid start "
				"marker\n", lno);
			continue;
		}

		/* Trim trailing whitespace */
		while (len && isspace(buf[len - 1]))
			len--;
		buf[len] = 0;

		/* Decode hex digits */
		nbytes = (len - 1) / 2;
		for (i = 0; i < nbytes; i++) {
			char d[] = {buf[i * 2 + 1], buf[i * 2 + 2], 0};

			data[i] = strtoul(d, NULL, 16);
		}

		/* Handle the line */
		if (feed_line(in, data, nbytes, cb, user_data,
			      &segment_offset) < 0) {
			printc_err("ihex: error on line %d\n", lno);
			return -1;
		}
	}

	return 0;
}