//#include "stdafx.h" #include "parsestl.h" VOID PrintUsage(char *pcProgram) { fprintf(stderr, "Usage: %s file.stl\n", pcProgram); fprintf(stderr, "\n"); } /////////////////////////////////// // STL 1 Pass Parser CLEDSGeometry *ParseSTL(int argc, char* argv[]) { CHAR pcFileNameBuffer[256]; CHAR *pcInput; CHAR **ppc; UINT_32 i; LanguageType eInputLanguage; FLOAT fEps; BOOL bAnalyze; CHAR **ppcDirectories; UINT_32 uiDirectories; FILE *fpOutputSTLFile = NULL; ppcDirectories = NULL; uiDirectories = 0; eInputLanguage = ltSize; geOutputLanguage = ltSIF; fEps = -1.0; //(Negative epsilon replaced by value based on min edge length) strcpy(pcFileNameBuffer, ""); // This should really use getarg()! ppc = argv; i = (UINT_32)argc; i--; ppc++; while (i) { if (ppc[0][0] == '-') { switch (ppc[0][1]) { case 'a': bAnalyze = TRUE; break; default: fprintf(stderr,"Unknown flag: %c\n", ppc[0][1]); PrintUsage(argv[0]); // fprintf(stderr, gpcUsage, argv[0]); exit(1); } } else { strcpy(pcFileNameBuffer, ppc[0]); } i--; ppc++; } pcInput = new CHAR[strlen(pcFileNameBuffer)+1]; ASSERT( pcInput != NULL ); strcpy(pcInput, pcFileNameBuffer); //////////////////////////////////////////////////////////////////// if ( eInputLanguage == ltSize ) { // Check the file name to see what type of input file it is CHAR *pc; UINT_32 i; for ( i = strlen(pcInput); i > 0; i-- ) { if ( pcInput[i-1] == '.' ) { pc = &(pcInput[i]); if ( strncmp("stl", pc, strlen("stl")) == 0 ) { eInputLanguage = ltSTL; } break; } } if ( eInputLanguage == ltSize ) { fprintf(stderr,"Unknown input file extension\n"); PrintUsage(argv[0]); exit(1); } } //////////////////////////////////////////////////////////////// // Command Line has been parsed so let's read the input file // CParser *pCParser; VOID *pvAST; CLEDSGeometry *pCLEDSGeometry; pCParser = NULL; pvAST = NULL; /////////////////////////////////// // STL Parser // // BOOL bPrevPtrs = FALSE; pCParser = stl_InitParser(new CLEDS1stageParserSTL(bPrevPtrs), pcInput, ppcDirectories, uiDirectories); ASSERT( pCParser != NULL ); pvAST = pCParser->Parse(); if ( pvAST == NULL ) { fprintf(stderr, "Compilation halted because of syntax errors.\n"); exit(2); } pCLEDSGeometry = (CLEDSGeometry *)pvAST; return (pCLEDSGeometry); }