Example #1
0
void FunctionOverrides::parseOverridesInFile(const char* fileName)
{
    if (!fileName)
        return;
    
    FILE* file = fopen(fileName, "r");
    if (!file)
        FAIL_WITH_ERROR(IO_ERROR, ("Failed to open file ", fileName, ". Did you add the file-read-data entitlement to WebProcess.sb?\n"));

    char* line;
    char buffer[BUFSIZ];
    while ((line = fgets(buffer, sizeof(buffer), file))) {
        if (strstr(line, "//") == line)
            continue;

        if (line[0] == '\n' || line[0] == '\0')
            continue;

        size_t keywordLength;
        
        keywordLength = sizeof("override") - 1;
        String keyStr = parseClause("override", keywordLength, file, line, buffer, sizeof(buffer));

        line = fgets(buffer, sizeof(buffer), file);

        keywordLength = sizeof("with") - 1;
        String valueStr = parseClause("with", keywordLength, file, line, buffer, sizeof(buffer));

        m_entries.add(keyStr, valueStr);
    }
    
    int result = fclose(file);
    if (result)
        dataLogF("Failed to close file %s: %s\n", fileName, strerror(errno));
}
Example #2
0
/******************************************************************************
 * Parse the DIMACS file that contains the CNF
 * -- fill in the sat_state data structure with initialized spaces in memory
 ******************************************************************************/
void parseDIMACS(FILE* cnf_file, SatState * sat_state){

	char * line = NULL;
	size_t len = 0;
	ssize_t read;

	unsigned long clausecounter = 0; // index of clauses starts with 0 to m-1
	while((read = getline(&line, &len, cnf_file)) != -1){

		// ignore anything starts with a c or % (comment line)
		// remove the line[0] == ' '  because some clause lines start with ' '
		if (line[0] == 'c' || line[0] == '%'  || line[0] == '0' || line[0] == '\n') continue;

		// end of file
		//if (len == 0)

		// parse the line that starts with p (problem line  p cnf <number of variables n> <number of clauses m>)
		if((line)[0] == 'p'){
			parseProblemLine(line, sat_state);
#ifdef DEBUG
			printf("number of clauses: %ld, number of variables: %ld\n", sat_state->num_clauses_in_delta, sat_state->num_variables_in_cnf);
#endif
		}
		else
		{
			// read the CNF
			sat_state->delta[clausecounter].cindex = clausecounter + 1;
			unsigned long vars = parseClause(sat_state, line, &sat_state->delta[clausecounter++]);
#ifdef DEBUG
			printf("Number of variables: %ld\n", vars);
#endif

		}
	}

#ifdef TEST_C2D
	print_DIMACS(sat_state);
#endif

//	if(line)
//		free(line);

}