home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / hlsrc / hlbench.c < prev    next >
C/C++ Source or Header  |  1988-09-09  |  10KB  |  377 lines

  1. /*+
  2.     Name:       HLBENCH.C
  3.     Author:     Kent J. Quirk
  4.         (c) Copyright 1988 Ziff Communications Co.
  5.     Date:       April 1988
  6.     Abstract:    This program is the menu driver for the benchmarks.
  7.     History:    09-Sep-88   kjq     Version 1.00
  8. -*/
  9.  
  10. #include <stdio.h>
  11. #include <malloc.h>
  12. #include <process.h>
  13. #include <graph.h>
  14. #include <conio.h>
  15. #include <string.h>
  16. #include <errno.h>
  17.  
  18. #include "winmenu.h"
  19.  
  20. extern int errno;
  21. extern char *sys_errlist[];
  22.  
  23. #define hbound(a) (sizeof(a)/sizeof(a[0]))
  24.  
  25. char file_rename[40];
  26.  
  27. char *menu[] = {            /* text for the main menu */
  28.     "Text Scrolling -- DOS/BIOS/C",
  29.     "Text Windows -- direct video access",
  30.     "Graphics Video -- lines, fills, graphs",
  31.     "CPU Speed -- Sort test",
  32.     "Floating Point -- FFT",
  33.     "Disk Speed -- Database test",
  34.     "Run all above tests",
  35.     "Display and compare results",
  36.     "Describe this machine",
  37.     "Save data file", 
  38.     "Return to DOS",
  39.     "About these benchmarks",
  40.     NULL
  41. };
  42.  
  43. #define S_EXECUTABLE    1    /* option flags for the various items */
  44. #define S_OPTION        2
  45. #define S_SHOW_RESULTS  4
  46. #define S_GROUP_TEST    8
  47. #define S_ANALYZE      16
  48. #define S_RUN_ALL      32
  49. #define S_QUIT           64
  50. #define S_HELP          128
  51. #define S_RENAME      256
  52. #define S_DESCR       512
  53.  
  54. typedef struct Prog {        /* structure to define option flags */
  55.     char *program, *options;
  56.     int status;
  57. } PROG;
  58.  
  59. PROG prog[] = {         /* the order of these must agree w/menu */
  60.     {"hltext",   "-F%s -P1",  S_EXECUTABLE | S_GROUP_TEST | S_SHOW_RESULTS },
  61.     {"hlwindow", "-F%s -P2",  S_EXECUTABLE | S_GROUP_TEST | S_SHOW_RESULTS },
  62.     {"hlgraph",  "-F%s -P3",  S_EXECUTABLE | S_GROUP_TEST | S_SHOW_RESULTS },
  63.     {"hlsort",   "-F%s -P4",  S_EXECUTABLE | S_GROUP_TEST | S_SHOW_RESULTS },
  64.     {"hlfloat",  "-F%s -P5",  S_EXECUTABLE | S_GROUP_TEST | S_SHOW_RESULTS },
  65.     {"hldisk",   "-F%s -P6",  S_EXECUTABLE | S_GROUP_TEST | S_SHOW_RESULTS },
  66.     { NULL,       NULL,       S_OPTION     | S_RUN_ALL },
  67.     {"hlanalyz", "-F%s -S%s", S_EXECUTABLE | S_ANALYZE },
  68.     {"hldesc",     "-F%s -P0",  S_EXECUTABLE | S_DESCR},
  69.     { NULL,      NULL,       S_OPTION       | S_RENAME },
  70.     { NULL,       NULL,       S_OPTION     | S_QUIT },
  71.     { NULL,      NULL,       S_OPTION       | S_HELP },
  72.     { NULL,       NULL }
  73. };
  74.  
  75. /**** u s a g e ****
  76.     Abstract:    Prints brief usage info and exits
  77.     Parameters: None
  78.     Returns:    Never
  79. ****************************/
  80. void usage()
  81. {
  82.     printf("This program controls the PC Tech Journal Benchmark Suite.\n");
  83.     printf("Type HLBENCH to run the benchmarks.  If you specify a filename\n");
  84.     printf("on the command line, that file is used for the benchmark data.\n");
  85.     printf("If you specify a second filename, it is used as the name of the\n");
  86.     printf("cross-reference file.  These filenames default to CURRENT and\n");
  87.     printf("the filename specified in XREF.TXT.\n");
  88.     printf("Examples:  HLBENCH\n");
  89.     printf("           HLBENCH MODEL80         [name this test MODEL80]\n");
  90.     printf("           HLBENCH MODEL80 MODEL60 [compare MODEL80 to MODEL60]\n");
  91.     exit(1);
  92. }
  93.  
  94. /**** t e x t _ d i s p l a y ****
  95.     Abstract:    Given a filename of a screen image file, this copies its
  96.         contents to the video buffer.
  97.     Parameters: char *fname - the filename containing the data
  98.     Returns:    Returns non-zero if unable to display text file.
  99. ****************************/
  100. int text_display(char *fname)
  101. {
  102.     FILE *f;
  103.  
  104.     if ((f = fopen(fname, "rb")) == NULL)
  105.     return(-1);
  106.     fill_screen(f);
  107.     fclose(f);
  108.     return(0);
  109. }
  110.  
  111. /**** h e l p ****
  112.     Abstract:    Displays scrollable help text in a window.  The user can
  113.         scroll it with up/down/pgup/pgdn.  Esc/Enter returns and
  114.         takes away the window.
  115.     Parameters: The filename containing the help text, the maximum number
  116.         of lines in that file.
  117.     Returns:    Nothing.
  118. ****************************/
  119. void help(char *fname, int nlines, char *title)
  120. {
  121.     FILE *f;
  122.     int linecnt = 0;
  123.     char buf[100], *bp;
  124.     char **lines;
  125.     int i;
  126.     
  127.     if ((f = fopen(fname, "r")) == NULL)
  128.     {
  129.     sprintf(buf, "Unable to find help file %s.", fname);
  130.     pop_error(buf);
  131.     return;
  132.     }
  133.     
  134.     lines = calloc(nlines+1, sizeof(char *));
  135.     
  136.     while ((bp = fgets(buf, sizeof(buf), f)) != NULL)
  137.     {
  138.     for (i=strlen(bp)-1; i < 60; i++)
  139.         bp[i] = ' ';        /* pad it */
  140.     bp[60] = 0;            /* trim it */
  141.     if (linecnt >= nlines)
  142.         break;
  143.     lines[linecnt++] = strdup(bp);
  144.     }
  145.                 /* \x18 is uparrow, \x19 is downarrow */
  146.     scroll_menu(lines, title, "Use \x18 \x19 PgUp PgDn; press ESC to exit", 
  147.         5, 10, 17, 0);
  148.     while (linecnt--)
  149.     free(lines[linecnt]);
  150.     free(lines);
  151. }
  152.  
  153. /**** m a i n ****
  154.     Abstract:    The main driver for HLBENCH.
  155.     Parameters: The usual.
  156.     Returns:    Errorlevel 0.
  157. ****************************/
  158. int main(argc, argv)
  159. int argc;
  160. char *argv[];
  161. {
  162.     int sel = 0;
  163.     int retval;
  164.     int i;
  165.     int analyzer = 0;
  166.     int run_all = 0;
  167.     char cmdbuf[32];
  168.     char *fname = NULL;
  169.     char *secname = NULL;
  170.     WINDOW *w = NULL, *wbase;
  171.     
  172.     for (i=1; i<argc; i++)        /* process all arguments */
  173.     {
  174.     if (argv[i][0] == '-')        /* switches */
  175.     {
  176.         switch(argv[i][1]) {
  177.         case '?':
  178.         usage();
  179.         break;
  180.         default:
  181.         printf("Invalid argument '%s'\n", argv[i]);
  182.         usage();
  183.         break;
  184.         }
  185.     }
  186.     else                /* just text */
  187.     {
  188.         if (fname == NULL)
  189.         fname = argv[i];
  190.         else if (secname == NULL)
  191.         secname = argv[i];
  192.         else
  193.         {     
  194.         printf("Too many filenames specified!\n");
  195.         usage();
  196.         }
  197.     }
  198.     }
  199.     if (fname == NULL)
  200.     {     
  201.     fname = "CURRENT.TIM";
  202.     unlink(fname);
  203.     }
  204.     if (secname == NULL)
  205.     {
  206.     FILE *f;
  207.     char buf[20];
  208.     if ((f = fopen("XREF.TXT", "r")) == NULL)
  209.     {
  210.         strcpy(buf, "IBMAT339.TIM");
  211.         if ((f = fopen("XREF.TXT", "w")) != NULL)
  212.         {
  213.         fprintf(f, "%s\n", buf);
  214.         fclose(f);
  215.         }
  216.     }
  217.     else
  218.     {    
  219.         fgets(buf, sizeof(buf), f);
  220.         buf[strlen(buf)-1] = 0;
  221.         fclose(f);
  222.     }
  223.     secname = strdup(buf);
  224.     }
  225.     
  226.     for (i=0; i<hbound(prog); i++)        /* find analyzer */
  227.     {     
  228.     if (prog[i].status & S_ANALYZE)
  229.         analyzer = i;
  230.     if (prog[i].status & S_RUN_ALL)
  231.         run_all = i;
  232.     }
  233.     
  234.     wbase = open_window(1, 1, 25, 80, 7);
  235.     
  236.     /* display startup screen */
  237.     if ((retval = spawnlp(P_WAIT, "hlstart", "hlstart", NULL)) == 1)
  238.     {
  239.     text_display("hlstart.sct");
  240.     if (xgetch() == ESC)
  241.     {
  242.         close_window(wbase);
  243.         return(0);
  244.     }
  245.     }
  246.     else if (retval == 2)
  247.     {
  248.     close_window(wbase);
  249.     return(0);
  250.     }
  251.  
  252.     text_display("HLBENCH.SCT");
  253.     sel = run_all;
  254.     while ((sel = do_menu(menu, "Benchmark Main Menu", 
  255.     "Press Enter to select, ESC to return", sel)) != -1)
  256.     {
  257.     if (prog[sel].status & S_EXECUTABLE)
  258.     {
  259.         if (!(prog[sel].status & (S_ANALYZE | S_DESCR)))
  260.         w = open_window(1, 1, 25, 80, 7);
  261.         
  262.         sprintf(cmdbuf, prog[sel].options, fname, secname);
  263.         retval = spawnlp(P_WAIT, prog[sel].program,
  264.             prog[sel].program, cmdbuf, "-B", NULL);
  265.         
  266.         if (w != NULL)        /* if we opened the window */
  267.         {     
  268.         close_window(w);
  269.         w = NULL;
  270.         }
  271.         
  272.         if (retval != -1)
  273.         {
  274.         if (prog[sel].status & S_SHOW_RESULTS)
  275.         {
  276.             sprintf(cmdbuf, "-P%d -F%s -S%s", sel+1, fname, secname);
  277.             retval = spawnlp(P_WAIT, prog[analyzer].program,
  278.             prog[analyzer].program, cmdbuf, NULL);
  279.         }
  280.         }
  281.         else
  282.         {
  283.         char buf[80];
  284.         
  285.         strcpy(buf, sys_errlist[errno]);
  286.         strcat(buf, " -- couldn't run program.");
  287.         pop_error(buf);
  288.         }
  289.     }
  290.     else if (prog[sel].status & S_HELP)    /* display help file */
  291.     {    
  292.         help("hlhelp.txt", 500, "About these benchmarks");
  293.     }
  294.     else if (prog[sel].status & S_RENAME)    /* rename data file */
  295.     {   
  296.         if (stricmp(fname, "CURRENT.TIM") == 0)
  297.         cmdbuf[0] = 0;
  298.         else
  299.         strcpy(cmdbuf, fname);
  300.         
  301.         w = open_window(11, 22, 13, 58, 7);
  302.         _settextposition(12, 23);
  303.         _outtext("Enter data file name: ");
  304.         for(;;)
  305.         {
  306.         if (edit_line(cmdbuf, 12, 12, 46) == ESC)
  307.             break;
  308.         else
  309.         {
  310.             if (strchr(cmdbuf, '.') != NULL)    /* if extension */
  311.             *(strchr(cmdbuf, '.')) = 0;    /* replace it */
  312.             strcat(cmdbuf, ".tim");
  313.             
  314.             if (rename(fname, cmdbuf))
  315.             {
  316.             int c;
  317.             
  318.             if (errno == ENOENT)        /* no CURRENT yet */
  319.             {
  320.                 fname = strdup(cmdbuf);
  321.                 break;
  322.             }
  323.             
  324.             c = pop_error("A file with that name exists -- use it anyway? (Y/N)");
  325.             if ((c == 'Y') || (c == 'y'))
  326.             {
  327.                 if (unlink(cmdbuf))
  328.                 {
  329.                 pop_error("Can't delete the existing file.  Try another name.");
  330.                 continue;        /* try again */
  331.                 }
  332.                 if (rename(fname, cmdbuf))
  333.                 {
  334.                 pop_error("Can't use that name.  Try another one.");
  335.                 continue;        /* try again */
  336.                 }
  337.                 else
  338.                 {
  339.                 fname = strdup(cmdbuf);
  340.                 break;            /* rename complete */
  341.                 }
  342.             }
  343.             continue;            /* try again */
  344.             }
  345.             fname = strdup(cmdbuf);
  346.             break;                /* rename worked */
  347.         }
  348.         }
  349.         close_window(w);
  350.         w = NULL;
  351.     }
  352.     else if (prog[sel].status & S_QUIT)    /* Die */
  353.     {
  354.         close_window(wbase);
  355.         return(0);
  356.     }
  357.     else if (prog[sel].status & S_RUN_ALL)
  358.     {
  359.         w = open_window(1, 1, 25, 80, 7);
  360.         for (i=0; i<hbound(prog); i++)
  361.         {
  362.         if (prog[i].status & S_GROUP_TEST)
  363.         {
  364.             sprintf(cmdbuf, prog[i].options, fname, secname);
  365.             retval = spawnlp(P_WAIT, prog[i].program,
  366.             prog[i].program, cmdbuf, "-A", NULL);
  367.         }
  368.         }
  369.         close_window(w);
  370.         w = NULL;
  371.         sel = analyzer;
  372.     }
  373.     }
  374.     close_window(wbase);
  375.     return(0);
  376. }
  377.