home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / yabbawhap / part02 / checkconf.c next >
C/C++ Source or Header  |  1991-10-09  |  9KB  |  296 lines

  1. /* Placed into the public domain by Daniel J. Bernstein. */
  2.  
  3. #include <stdio.h>
  4.  
  5. extern long atol();
  6.  
  7. static char introspiel[] = "\
  8. checkconf is a tool to help you configure yabba and whap for your system.\n\
  9. It lets you quickly experiment with options to see what effect they\n\
  10. will have on program size and to make sure that they are appropriate\n\
  11. for your system.\n\
  12. \n\
  13. You can give checkconf any of the following options: -DPTRS, -UPTRS,\n\
  14. -DBZERO, -UBZERO, -DMEMZERO, -UMEMZERO, -DZEROFILLED, -UZEROFILLED,\n\
  15. -DTYPE=short, -DTYPE=int, -DHASHTYPE=short, -DHASHTYPE=int,\n\
  16. -DHASHTYPE=TYPE, -DBITBUFSIZE=%%d, -DRESETNUM=%%d, -DRESETFUZZ=%%d,\n\
  17. -DNODEMAX=%%d, -DNODENUM=NODEMAX, -DNODENUM=%%d, -DMOD=%%d. Here %%d means\n\
  18. any number. These options override CCOPTS in the Makefile. The Makefile\n\
  19. contains more detailed information on each option.\n\
  20. \n\
  21. checkconf -H shows this help screen.\n\
  22. \n\
  23. Be sure to remake checkconf if you change the Makefile.\n\
  24. ";
  25.  
  26. #ifndef BITBUFSIZE
  27. #define BITBUFSIZE 1000
  28. #endif
  29. #ifndef RESETNUM
  30. #define RESETNUM 8192
  31. #endif
  32. #ifndef RESETFUZZ
  33. #define RESETFUZZ 30
  34. #endif
  35. #ifndef NODEMAX
  36. #define NODEMAX 65533
  37. #endif
  38. #ifndef TYPE
  39. #define TYPE short
  40. #endif
  41. #ifndef MOD
  42. #define MOD 65536
  43. #endif
  44.  
  45. unsigned long bitbufsize = BITBUFSIZE;
  46. unsigned long resetnum = RESETNUM;
  47. long resetfuzz = RESETFUZZ;
  48. unsigned long nodemax = NODEMAX;
  49. #ifndef NODENUM
  50. #define NODENUM NODEMAX
  51. unsigned long nodenum = 0;
  52. #else
  53. unsigned long nodenum = NODENUM;
  54. #endif
  55. unsigned long mod = MOD;
  56. #ifdef PTRS
  57. char ptrs = 'D';
  58. #else
  59. char ptrs = 'U';
  60. #endif
  61. #ifdef BZERO
  62. char cbzero = 'D';
  63. #else
  64. char cbzero = 'U';
  65. #endif
  66. #ifdef MEMZERO
  67. char cmemzero = 'D';
  68. #else
  69. char cmemzero = 'U';
  70. #endif
  71. #ifdef ZEROFILLED
  72. char zerofilled = 'D';
  73. #else
  74. char zerofilled = 'U';
  75. #endif
  76.  
  77. static int h[100];
  78.  
  79. main(argc,argv)
  80. int argc;
  81. char *argv[];
  82. {
  83.  int sshort = sizeof(short);
  84.  int sint = sizeof(int);
  85.  int slong = sizeof(long);
  86.  int sptr = sizeof(char *);
  87.  int st = sizeof(unsigned TYPE);
  88. #ifndef HASHTYPE
  89. #define HASHTYPE TYPE
  90.  int shasht = 0;
  91. #else
  92.  int shasht = sizeof(HASHTYPE);
  93. #endif
  94.  char *foo = 0;
  95.  int i;
  96.  int flag0;
  97.  char c;
  98.  int flagfill;
  99.  
  100.  while (*++argv)
  101.   {
  102.    if (!strcmp(*argv,"-DPTRS")) ptrs = 'D';
  103.    else if (!strcmp(*argv,"-UPTRS")) ptrs = 'U';
  104.    else if (!strcmp(*argv,"-DBZERO")) cbzero = 'D';
  105.    else if (!strcmp(*argv,"-UBZERO")) cbzero = 'U';
  106.    else if (!strcmp(*argv,"-DMEMZERO")) cmemzero = 'D';
  107.    else if (!strcmp(*argv,"-UMEMZERO")) cmemzero = 'U';
  108.    else if (!strcmp(*argv,"-DZEROFILLED")) zerofilled = 'D';
  109.    else if (!strcmp(*argv,"-UZEROFILLED")) zerofilled = 'U';
  110.    else if (!strcmp(*argv,"-DTYPE=short")) st = sshort;
  111.    else if (!strcmp(*argv,"-DTYPE=int")) st = sint;
  112.    else if (!strcmp(*argv,"-DHASHTYPE=short")) shasht = sshort;
  113.    else if (!strcmp(*argv,"-DHASHTYPE=int")) shasht = sint;
  114.    else if (!strcmp(*argv,"-DHASHTYPE=TYPE")) shasht = 0;
  115.    else if (!strncmp(*argv,"-DBITBUFSIZE=",13)) bitbufsize = atol(*argv + 13);
  116.    else if (!strncmp(*argv,"-DRESETNUM=",11)) resetnum = atol(*argv + 11);
  117.    else if (!strncmp(*argv,"-DRESETFUZZ=",12)) resetfuzz = atol(*argv + 12);
  118.    else if (!strncmp(*argv,"-DNODEMAX=",10)) nodemax = atol(*argv + 10);
  119.    else if (!strcmp(*argv,"-DNODENUM=NODEMAX")) nodenum = 0;
  120.    else if (!strncmp(*argv,"-DNODENUM=",10)) nodenum = atol(*argv + 10);
  121.    else if (!strncmp(*argv,"-DMOD=",6)) mod = atol(*argv + 6);
  122.    else if (!strcmp(*argv,"-H"))
  123.     {
  124.      fprintf(stderr,introspiel);
  125.      exit(1);
  126.     }
  127.    else
  128.     {
  129.      fprintf(stderr,
  130.          "checkconf: fatal: argument %s unrecognized. checkconf -H for help.\n"
  131.          ,*argv);
  132.      exit(1);
  133.     }
  134.   }
  135.  
  136.  if (shasht == 0)
  137.    shasht = st;
  138.  if (nodenum == 0)
  139.    nodenum = nodemax;
  140.  
  141.  flagfill = 1;
  142.  for (i = 0;i < sizeof(h) / sizeof(h[0]);i++)
  143.    if (h[i])
  144.      flagfill = 0;
  145.  
  146.  printf("\n");
  147.  printf("Sizes:  short %d  int %d  long %d  pointer %d\n",sshort,sint,slong,sptr);
  148.  printf("Internal representation of the NULL pointer:  ");
  149.  flag0 = 1;
  150.  for (i = 0;i < sptr;i++)
  151.   {
  152.    c = ((char *) (&foo))[i];
  153.    printf("%d ",c);
  154.    if (c)
  155.      flag0 = 0;
  156.   }
  157.  if (flag0)
  158.    printf("(all zeros)\n");
  159.  else
  160.    printf("(not all zeros)\n");
  161.  printf("\n");
  162.  
  163.  printf("major config: -%cPTRS  -DBITBUFSIZE=%ld  -DNODEMAX=%ld  -DMOD=%ld\n"
  164.     ,ptrs,bitbufsize,nodemax,mod
  165.     );
  166.  printf("type config: TYPE size %ld  HASHTYPE size %ld\n"
  167.     ,st
  168.     ,shasht
  169.     );
  170.  printf("minor config: -DRESETNUM=%ld  -DRESETFUZZ=%ld  -DNODENUM=%ld\n"
  171.     ,resetnum,resetfuzz,nodenum
  172.     );
  173.  printf("system config: -%cBZERO  %s-%cMEMZERO%s  -%cZEROFILLED\n"
  174.     ,cbzero
  175.     ,(cbzero == 'U' ? "" : "(")
  176.     ,cmemzero
  177.     ,(cbzero == 'U' ? "" : ", not relevant with -DBZERO)")
  178.     ,zerofilled
  179.     );
  180.  
  181. /* printf("\n"); */
  182.  printf("Array use:\n");
  183.  if (ptrs == 'D')
  184.    printf("  whap:   total %ld  huptrie data %ld hash %ld  bitbuf %ld\n"
  185.       ,2 * sptr * (nodemax + 1) + mod * sptr + (bitbufsize + 1) * 2 * st
  186.       ,2 * sptr * (nodemax + 1)
  187.       ,mod * sptr
  188.       ,(bitbufsize + 1) * 2 * st
  189.       );
  190.  else
  191.    printf("  whap:   total %ld  huptrie data %ld %ld hash %ld  bitbuf %ld\n"
  192.       ,2 * st * (nodemax + 1) + mod * st + (bitbufsize + 1) * 2 * st
  193.       ,st * (nodemax + 1)
  194.       ,st * (nodemax + 1)
  195.       ,mod * st
  196.       ,(bitbufsize + 1) * 2 * st
  197.       );
  198.  printf("  unwhap: total %ld  outarray %ld  outpos %ld\n"
  199.     ,nodemax + st * nodemax
  200.     ,nodemax
  201.     ,st * nodemax
  202.     );
  203.  
  204.  if (ptrs == 'D')
  205.    printf("  yabba:    tot %ld  ht d %ld %ld %ld h %ld  bb %ld\n"
  206.       ,2 * sptr * (nodemax + 1) + sptr * (nodemax + 1) + shasht * (nodemax + 2) + mod * sptr + (bitbufsize + 1) * 2 * st
  207.       ,2 * sptr * (nodemax + 1)
  208.       ,sptr * (nodemax + 1)
  209.       ,shasht * (nodemax + 2)
  210.       ,mod * sptr
  211.       ,(bitbufsize + 1) * 2 * st
  212.       );
  213.  else
  214.    printf("  yabba:    tot %ld  ht d %ld %ld %ld %ld h %ld  bb %ld\n"
  215.       ,st * (nodemax + 1) + st * (nodemax + 1) + st * (nodemax + 1) + shasht * (nodemax + 2) + mod * st + (bitbufsize + 1) * 2 * st
  216.       ,st * (nodemax + 1)
  217.       ,st * (nodemax + 1)
  218.       ,st * (nodemax + 1)
  219.       ,shasht * (nodemax + 2)
  220.       ,mod * st
  221.       ,(bitbufsize + 1) * 2 * st
  222.       );
  223.  
  224.  if (ptrs == 'D')
  225.    printf("  unyabba:  tot %ld  ht d %ld %ld %ld %ld h %ld\n"
  226.       ,2 * sptr * (nodemax + 1) + sptr * (nodemax + 1) + shasht * (nodemax + 2) + (nodemax + 1) + mod * sptr
  227.       ,2 * sptr * (nodemax + 1)
  228.       ,sptr * (nodemax + 1)
  229.       ,shasht * (nodemax + 2)
  230.       ,(nodemax + 1)
  231.       ,mod * sptr
  232.       );
  233.  else
  234.    printf("  unyabba:  tot %ld  ht d %ld %ld %ld %ld %ld h %ld\n"
  235.       ,st * (nodemax + 1) + st * (nodemax + 1) + st * (nodemax + 1) + shasht * (nodemax + 2) + (nodemax + 1) + mod * st
  236.       ,st * (nodemax + 1)
  237.       ,st * (nodemax + 1)
  238.       ,st * (nodemax + 1)
  239.       ,shasht * (nodemax + 2)
  240.       ,(nodemax + 1)
  241.       ,mod * st
  242.       );
  243.  
  244. #define MAX(foo) ((unsigned long) ((unsigned foo) (-1))) /*XXX*/
  245.  
  246.  printf("\n");
  247.  printf("Validity checks:\n");
  248.  if (mod & (mod - 1))
  249.  printf("MOD is a power of 2: FAILED!\n");
  250.  if ((nodenum < 512) || (nodenum > nodemax))
  251.  printf("NODENUM (default c-size) is between 512 and NODEMAX: FAILED!\n");
  252.  if ( ( (st == sshort) ? MAX(short)
  253.      : ( (st == sint) ? MAX(int) : MAX(TYPE) ) ) < nodemax + 2 )
  254.  printf("NODEMAX (maximum c-size) + 2 fits into TYPE: FAILED!\n");
  255.  if ( ( (shasht == sshort) ? MAX(short)
  256.      : ( (shasht == sint) ? MAX(int) : MAX(HASHTYPE) ) ) < mod - 1 )
  257.  printf("MOD - 1 fits into HASHTYPE: FAILED!\n");
  258.  if (MAX(int) < bitbufsize + 3)
  259.  printf("BITBUFSIZE + 3 fits into int: FAILED!\n");
  260.  if (ptrs == 'U')
  261.  if (!flag0)
  262.  if ((cbzero == 'D') || (cmemzero == 'D') || (zerofilled == 'D'))
  263.  printf("Under -DPTRS, if NULL isn't 0, must -UBZERO -UMEMZERO -UZEROFILLED: FAILED!\n");
  264.  
  265.  printf("\n");
  266.  printf("Range sanity checks:\n");
  267.  if (mod < 512) printf("MOD should be at least 512\n");
  268.  if (bitbufsize < 128) printf("BITBUFSIZE should be at least 128\n");
  269.  if (nodemax < 1024) printf("NODEMAX should be at least 1024\n");
  270.  if (resetnum < 3 * bitbufsize)
  271.    printf("RESETNUM should probably be at least BITBUFSIZE * 3\n");
  272.  if (((long)resetfuzz < -(long)(bitbufsize / 10))
  273.    ||(resetfuzz > bitbufsize / 10))
  274.    printf("RESETFUZZ should probably be at most BITBUFSIZE/10 in absolute value\n");
  275.  if (st > sint)
  276.    printf("TYPE should probably fit into an int\n");
  277.  if (shasht > sint)
  278.    printf("HASHTYPE should probably fit into an int\n");
  279.  
  280.  printf("\n");
  281.  printf("System requirements:\n");
  282.  if (cbzero == 'D')
  283.    printf("bzero() must be available\n");
  284.  else if (cmemzero == 'D')
  285.    printf("memset() must be available\n");
  286.  if (zerofilled == 'D')
  287.   {
  288.    printf("static arrays must be filled with null bytes upon entry to main()\n");
  289.    if (!flagfill)
  290.      printf("  wait! that doesn't seem to be true here...\n");
  291.   }
  292.  
  293.  printf("\n");
  294.  exit(0);
  295. }
  296.