int read_list(char *basepath, const char *filename) {
    size_t len = 0;
    FILE *f = NULL;
    char * line = NULL;

    int confLidas, revsLidas, confsRej, revsRej;
    confLidas = 0;
    revsLidas = 0;
    confsRej = 0;
    revsRej = 0;
    int naut = 0;

    char *absolute = NULL;
    absolute = (char *) malloc(sizeof (char) *(strlen(basepath) + strlen(filename)));
    strcat(absolute, basepath);
    strcat(absolute, filename);

    initTA();

    f = fopen(absolute, "r");

    if (f != NULL) {
        line = (char *) calloc(MAX_CHAR, sizeof (char));
        line = fgets(line, MAX_CHAR, f);

        min_pag = atoi(line);
        do {
            line = (char *) calloc(MAX_CHAR, sizeof (char));
            line = fgets(line, MAX_CHAR, f);

            if (line != NULL) {
                len = strlen(line);
                if (line[len - 1] == '\n')
                    line[len - 1] = '\0';
                absolute = (char *) malloc(sizeof (char) * (strlen(basepath) + len));
                clear_str(absolute, strlen(basepath) + len);
                strcat(absolute, basepath);
                strcat(absolute, line);

                if (line[0] == 'c')
                    confLidas += readC(absolute, &confsRej);
                if (line[0] == 'j')
                    revsLidas += readJ(absolute, &revsRej);
            }

        } while (line != NULL && line != "" && !feof(f));
        fclose(f);
    }

    if (absolute != NULL) {
        free(absolute);
        absolute = NULL;
    }
    free(line);

    logStats(confLidas, revsLidas, confsRej, revsRej);

    return 0;
}
Esempio n. 2
0
	void iobFile::readStr( char **str )
	{
		unsigned int len;
		readUI( len );
		//printf( "iobFile::readStr len=%u\n", len );
		if (len > (1<<22)) return;
		*str = (char*) malloc( len+1 );
		if (!*str) return;
		for (unsigned int i=0; i<len; i++)
			readC( (*str)[i] );
		(*str)[len] = 0;
	}
Esempio n. 3
0
int readByte(){
	data[dataIndex] = readC();
	return 0;
}