/******************************************* Helper function for concat system, opens two files and sends them to concat function Pre: args contains the number of strings in argv, argv[2] contains the file to be combined with stdin,outfile contains the file to write combined files to Post: outfile contains the combined marcXML files, Return EXIT_FAILURE for any problem *******************************************/ static int combineFiles(int args, char *argv[], FILE *outfile){ XmElem *top1 = openXmElemTree( stdin ); if (top1 == NULL){ fprintf(stderr, "\nError, could not open file on stdin\n"); return (EXIT_FAILURE); } FILE *marcXMLfp1 = fopen (argv[2], "r"); if (marcXMLfp1 == NULL){ fprintf(stderr, "\nError, could not open file \"%s\"\n",argv[2] ); return EXIT_FAILURE; } XmElem *top2 = openXmElemTree( marcXMLfp1 ); if (top2 == NULL){ return(EXIT_FAILURE); } fclose (marcXMLfp1); int returnVal = concat( top1, top2, outfile ); mxCleanElem (top1); mxCleanElem (top2); return returnVal; }
int main(int args, char *argv[]){ int option = checkArgs(args, argv); int returnVal = 0; switch (option){ case 1:{ //-review XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = review(top, stdout); mxCleanElem (top); break; } case 2:{ //-cat returnVal = combineFiles(args, argv, stdout); break; } case 3:{ //-keep XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = selects(top, KEEP, argv[2], stdout); mxCleanElem(top); break; } case 4:{ //-discard XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = selects(top, DISCARD, argv[2], stdout); mxCleanElem(top); break; } case 5:{ //-lib XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = libFormat(top, stdout); mxCleanElem(top); break; } case 6:{ //-bib XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = bibFormat(top, stdout); mxCleanElem(top); break; } default://invalid command return EXIT_FAILURE; } return returnVal; }
PyObject * Mx_term ( PyObject * self, PyObject * args ){ if ( NULL != top) mxCleanElem( top ); if ( NULL != top2 ) mxCleanElem( top2 ); if ( NULL != schemaPtr ) mxTerm( schemaPtr ); return Py_BuildValue ( "i", 1 );}