static void runPass(const char *passName, void (*pass)(void), void (*check)(), char log_tag) { static struct timeval startTimeBetweenPasses; static struct timeval stopTimeBetweenPasses; static double timeBetweenPasses = -1.0; static double totalTime = 0.0; struct timeval startTime; struct timeval stopTime; struct timezone timezone; static bool performTiming = printPasses || (printPassesFile != NULL); if (performTiming) { gettimeofday(&stopTimeBetweenPasses, &timezone); if (timeBetweenPasses < 0.0) timeBetweenPasses = 0.0; else timeBetweenPasses += ((double)((stopTimeBetweenPasses.tv_sec*1e6+ stopTimeBetweenPasses.tv_usec) - (startTimeBetweenPasses.tv_sec*1e6+ startTimeBetweenPasses.tv_usec))) / 1e6; } if (strlen(fPrintStatistics) && strcmp(passName, "parse")) printStatistics("clean"); if (performTiming) { printPassTiming("%32s :", passName); gettimeofday(&startTime, &timezone); } (*pass)(); if (performTiming) { gettimeofday(&stopTime, &timezone); printPassTiming("%8.3f seconds", ((double)((stopTime.tv_sec*1e6+stopTime.tv_usec) - (startTime.tv_sec*1e6+startTime.tv_usec))) / 1e6); if (developer && printPasses) fprintf(stderr, " [%d]", lastNodeIDUsed()); printPassTiming("\n"); totalTime += ((double)((stopTime.tv_sec*1e6+stopTime.tv_usec) - (startTime.tv_sec*1e6+startTime.tv_usec))) / 1e6; if (!strcmp(passName, "makeBinary")) { printPassTiming("%32s :%8.3f seconds\n", "time between passes", timeBetweenPasses); printPassTiming("%32s :%8.3f seconds\n", "total time", totalTime+timeBetweenPasses); } } if (strlen(fPrintStatistics)) printStatistics(passName); if (fdump_html) { html_view(passName); } if (logging(log_tag)) dump_ast(passName, currentPassNo); if (performTiming) { gettimeofday(&startTimeBetweenPasses, &timezone); } considerExitingEndOfPass(); cleanAst(); (*check)(); // Run per-pass check function. //printPrimitiveCounts(passName); }
int main (int argc, char *argv[]) { /* These have been moved from global to local variables */ /* this reduces binary size and improves code structure. RP */ /* Also size of home_page and help_page reduced from 257. RP 11-mar-04 */ char home_page[20] = "index.htm"; char help_page[20] = "help.htm"; char base_dir[257]; char *showcommand = 0; char *oldscreen; int oldcursorx = wherex (), oldcursory = wherey (); int i; /* counter for loop */ int forcemono = 0, fancyscheme = 0; int AsciiExtendedChars = 1; int codepage = 0; cat = catopen("htmlhelp", 0); if (getenv ("HELPPATH") == NULL) { get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); /* default location */ if (lang_add(base_dir, home_page) != 0) { char testpath[257]; get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); /* bookshelf location */ strcpy(testpath, base_dir); strcat(testpath, home_page); if (checkForFile(testpath) != 0) { get_base_dir (base_dir, argv[0]); /* try same dir as exe */ strcpy(testpath, base_dir); strcat(testpath, home_page); if (checkForFile(testpath) != 0) { *base_dir = '\0'; /* try current dir */ strcpy(testpath, home_page); if (checkForFile(testpath) != 0) { get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); } } } } } else { strcpy (base_dir, getenv ("HELPPATH")); if (lang_add(base_dir, home_page) != 0) { strcpy (base_dir, getenv ("HELPPATH")); if (base_dir[0] != '\0') { if (base_dir[strlen(base_dir)-1] != '\\' && base_dir[strlen(base_dir)-1] != '/'); strcat (base_dir, "\\"); } } } if (getenv ("HELPCMD")) { if (strstr (getenv ("HELPCMD"), "/A")) AsciiExtendedChars = 0; if (strstr (getenv ("HELPCMD"), "/M")) forcemono = 1; if (strstr (getenv ("HELPCMD"), "/F1")) fancyscheme = 1; if (strstr (getenv ("HELPCMD"), "/F2")) fancyscheme = 2; } for (i = 1; i < argc; i++) { if (argv[i][0] == '/') { switch (argv[i][1]) { default: printf ("%s -- %s\n", hcatInvArg, argv[i] + 1); printf ("%s\n", hcatHowGetUsage); break; case '?': show_usage (); return 0; case 'a': case 'A': if (argv[i][2] == 0) AsciiExtendedChars = 0; break; case 'c': case 'C': codepage = atoi(argv[i]+2); if (codepage == 0) { printf("%s (/Cnnn)\n", hcatCodepagePlease); printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages); return 0; } break; case 'f': case 'F': fancyscheme = atoi(argv[i] + 2); if (fancyscheme < 1 || fancyscheme > 2) fancyscheme = 1; break; case 'h': case 'H': if (argv[i][2] == 0) /* Only put /h or /H */ { printf ("%s\n", hcatInvArg); printf ("%s\n", hcatHowGetUsage); return 0; } else { strncpy(help_page, argv[i] + 2, 14); } break; case 'l': case 'L': strcat (base_dir, argv[i] + 2); checkForFile (base_dir); get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); break; case 'm': case 'M': if (argv[i][2] == '\0') forcemono = 1; else { printf ("%s -- %s\n", hcatInvArg, argv[i] + 1); printf ("%s\n", hcatHowGetUsage); return 0; } break; case 'o': /* Override index file path/name */ case 'O': strcpy (base_dir, argv[i] + 2); if (lang_add(base_dir, home_page) != 0) { strcpy (base_dir, argv[i] + 2); checkForFile (base_dir); get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); } } } else if (showcommand == 0) { showcommand = malloc (strlen (argv[i]) + 11); if (!showcommand) { printf ("%s\n", hcatMemErr); return 0; } sprintf (showcommand, "#%s", argv[i]); } else { printf ("%s\n", hcat2ManyTopics); printf ("%s\n", hcatHowGetUsage); return 0; } } if (fancyscheme && forcemono) { printf ("%s\n", hcatFwithN); printf ("%s\n", hcatHowGetUsage); return 0; } /* detect (or force) the codepage to select UTF-8 and entity substition support */ if (selectCodepage(codepage) != codepage && codepage > 0) { printf("%s\n", hcatCodepageNotSupported); printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages); return 0; } /* initialise user interface */ conio_init (forcemono); if (forcemono == 0) { oldscreen = malloc (W * H * 2); if (oldscreen) save_window (X, Y, W, H, oldscreen); } if (MonoOrColor == COLOR_MODE && fancyscheme == 0) { TEXT_COLOR = C_TEXT_COLOR; BOLD_COLOR = C_BOLD_COLOR; ITALIC_COLOR = C_ITALIC_COLOR; BORDER_BOX_COLOR = C_BORDER_COLOR; BORDER_TEXT_COLOR = C_BORDER_TEXT_COLOR; LINK_COLOR = C_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = C_LINK_HIGHLIGHTED_COLOR; } else if (MonoOrColor == COLOR_MODE && fancyscheme == 1) { TEXT_COLOR = F1_TEXT_COLOR; BOLD_COLOR = F1_BOLD_COLOR; ITALIC_COLOR = F1_ITALIC_COLOR; BORDER_BOX_COLOR = F1_BORDER_COLOR; BORDER_TEXT_COLOR = F1_BORDER_TEXT_COLOR; LINK_COLOR = F1_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = F1_LINK_HIGHLIGHTED_COLOR; } else if (MonoOrColor == COLOR_MODE && fancyscheme == 2) { TEXT_COLOR = F2_TEXT_COLOR; BOLD_COLOR = F2_BOLD_COLOR; ITALIC_COLOR = F2_ITALIC_COLOR; BORDER_BOX_COLOR = F2_BORDER_COLOR; BORDER_TEXT_COLOR = F2_BORDER_TEXT_COLOR; LINK_COLOR = F2_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = F2_LINK_HIGHLIGHTED_COLOR; } else { TEXT_COLOR = M_TEXT_COLOR; BOLD_COLOR = M_BOLD_COLOR; ITALIC_COLOR = M_ITALIC_COLOR; BORDER_BOX_COLOR = M_BORDER_COLOR; BORDER_TEXT_COLOR = M_BORDER_TEXT_COLOR; LINK_COLOR = M_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = M_LINK_HIGHLIGHTED_COLOR; } if (AsciiExtendedChars == 0) { strcpy (Border22f, "+-+( )+-+"); strcpy (Border22if, "+-+( )+-+"); BarBlock1 = '.'; BarBlock2 = '#'; } show_mouse (); move_mouse (80, 25); drawmenu (); html_view (showcommand, base_dir, home_page, help_page); free (showcommand); hide_mouse (); if ((oldscreen != 0) && (forcemono == 0)) { load_window (X, Y, W, H, oldscreen); free (oldscreen); } conio_exit (); gotoxy (oldcursorx, oldcursory); return 0; }