/* ** Reads the contents of script with the given file name (expected .rpt extension and located in ./scripts) ** Returns the contents of the script in a string ** Returns NULL if error occurs ** ** Arguments: ** file_name - the name of the file whose contents will be read (expected .rpt extension and located in ./scripts) */ char * readFileIntoStringWrapper(char * file_name){ int size = strlen(SCRIPTS_LOCATION) + strlen(file_name) + strlen(FILE_EXT) + 1; char * file = malloc(size * sizeof(char)); if(file == NULL){ perror("malloc"); return NULL; } strcpy(file, SCRIPTS_LOCATION); strcat(file, file_name); strcat(file, FILE_EXT); long int num_bytes = countBytesInFile(file); if(num_bytes == -1){ free(file); return NULL; } char * file_str = malloc(num_bytes + 1); if(file_str == NULL){ perror("malloc"); free(file); return NULL; } int read = readFileIntoString(file_str, file, num_bytes); if(read == -1){ fprintf(stderr, "Failed to read file into string"); free(file); free(file_str); return NULL; } free(file); return file_str; }
int main (int argc, char *argv[]) { const int SIZE = 4096; if( argc != 3 ) { usage( argv[0] ); exit(1); } char jobString[SIZE]; char machineString[SIZE]; readFileIntoString( argv[2], machineString, SIZE ); readFileIntoString( argv[1], jobString, SIZE ); classad::ClassAd *jobAd, *machineAd; classad::ClassAdParser parser; ClassAdAnalyzer analyzer; string buffer; string start = ATTR_START; // Get the job ad if( !( jobAd = parser.ParseClassAd( jobString ) ) ) { cerr << "error parsing job ad\n" << endl; exit(1); } // Get the machine ad if( !( machineAd = parser.ParseClassAd( machineString ) ) ) { cerr << "error parsing machine ad\n" << endl; exit(1); } // Do analysis if( !( analyzer.AnalyzeExprToBuffer( machineAd, jobAd, start, buffer ) ) ) { cerr << "error analyzing expression\n" << endl; exit(1); } cout << buffer; }
std::string readFileIntoString(const std::string& filename) { std::string result; readFileIntoString(filename, result); return result; }