// file: $(NEDC_NFC)/util/cpp/nedc_edf_print_header/nedc_edf_print_header.cc // // Revision History: // // 20220512 (JP): renamed the utility // 20200520 (JP): refactored the code // 20160212 (SL): modified to use the Cmdl class // 20140214 (JP): upgraded to use the new I/O in the EDF class // 20131129 (JP): initial version // // local include files // #include #include // define the help and usage messages // #define NEDC_USAGE \ "$NEDC_NFC/util/cpp/nedc_edf_print_header/nedc_edf_print_header.usage" #define NEDC_HELP \ "$NEDC_NFC/util/cpp/nedc_edf_print_header/nedc_edf_print_header.help" // main: nedc_edf_print_header // // This is a driver program that reads EDF files, either using // file lists or direct files, and processes them. // int main(int argc, const char** argv) { // declare local variables // char efname[Itgl::MAX_LSTR_LENGTH]; char ffname[Itgl::MAX_LSTR_LENGTH]; // create the required objects // Dbgl dbgl(Dbgl::NONE); Cmdl cmdl(NEDC_USAGE, NEDC_HELP); Edf edf; // parse the command line: // note that if help or usage are set, it won't return from // this function call. // cmdl.parse_args(argc, argv); // check the number of arguments // if (argc == 1) { cmdl.display_usage(stdout); } // retrieve the file list // VectorString args; if (cmdl.get_value(args, (char*)Cmdl::ARG_ARGS) == false) { fprintf(stdout, "Error: %s (line: %d) %s: error getting args\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); cmdl.display_usage(stdout); } // display an informational message // fprintf(stdout, "beginning argument processing...\n"); // main processing loop: loop over all input filenames // long num_files_att = 0; long num_files_proc = 0; for (long i = 0; i < (long)args.size(); i++) { // convert the String object to a C character string // char* fname = (char*)args[i].c_str(); cmdl.expand_filename(efname, fname); // if it is an edf file, process it // if (edf.is_edf(efname)) { num_files_att++; fprintf(stdout, " %6ld: %s\n", num_files_att, efname); if (edf.print_header(efname, (FILE*)stdout) == true) { num_files_proc++; } edf.cleanup(); } // else: treat it as a file list // else { // display an informational message // if (dbgl > Dbgl::NONE) { fprintf(stdout, "%s (line: %d) %s: opening list (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, fname); } // open the list // FILE* fp = fopen(fname, "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "Error: %s (line: %d) %s: %s (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, "error opening file list", fname); exit(EXIT_FAILURE); } // loop over all files // while (fscanf(fp, "%s", ffname) == 1) { // if it is an edf file, process it // cmdl.expand_filename(efname, ffname); if (edf.is_edf(efname)) { num_files_att++; fprintf(stdout, " %6ld: %s\n", num_files_att, efname); if (edf.print_header(efname, (FILE*)stdout) == true) { num_files_proc++; } edf.cleanup(); } // else: unknown // else { fprintf(stdout, "Error: %s (line: %d) %s: %s (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, "error opening file list", ffname); } } // close the list // fclose(fp); } } // display the results // fprintf(stdout, "processed %ld out of %ld files successfully\n", num_files_proc, num_files_att); // exit gracefully // exit(EXIT_SUCCESS); } // // end of file