home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / cperf-2.1 / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-11  |  2.6 KB  |  97 lines

  1. /* Driver program for the Perfect hash function generator.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  4.  
  5. This file is part of GNU GPERF.
  6.  
  7. GNU GPERF is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU GPERF is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU GPERF; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Simple driver program for the Perfect.hash function generator.
  22.    Most of the hard work is done in class Perfect and its class methods. */
  23.  
  24. #include <stdio.h>
  25. #include <sys/types.h>
  26. #include <time.h>
  27. #include "stderr.h"
  28. #include "options.h"
  29. #include "perfect.h"
  30.  
  31. /* Calls the appropriate intialization routines for each
  32.    ADT.  Note that certain initialization routines require
  33.    initialization *after* certain values are computed.  Therefore,
  34.    they cannot be called here. */
  35.    
  36. static void 
  37. init_all (argc, argv)
  38.      int argc;
  39.      char *argv[];
  40. {
  41. #ifdef RLIMIT_STACK
  42.   /* Get rid of any avoidable limit on stack size.  */
  43.   {
  44.     struct rlimit rlim;
  45.  
  46.     /* Set the stack limit huge so that alloca does not fail. */
  47.     getrlimit (RLIMIT_STACK, &rlim);
  48.     rlim.rlim_cur = rlim.rlim_max;
  49.     setrlimit (RLIMIT_STACK, &rlim);
  50.   }
  51. #endif /* RLIMIT_STACK */
  52.  
  53.   options_init (argc, argv);    
  54.   key_list_init ();
  55.   perfect_init ();              
  56. }
  57.  
  58. /* Calls appropriate destruction routines for each ADT.  These
  59.    routines print diagnostics if the debugging option is enabled. */
  60.  
  61. static void
  62. destroy_all ()
  63. {
  64.   options_destroy ();
  65.   key_list_destroy ();
  66.   perfect_destroy ();
  67. }
  68.  
  69. /* Driver for perfect hash function generation. */
  70.  
  71. int
  72. main (argc, argv)
  73.      int argc;
  74.      char *argv[];
  75. {
  76.   struct tm *tm;
  77.   time_t     clock; 
  78.   int        status;
  79.  
  80.   time (&clock);
  81.   tm = localtime (&clock);
  82.  
  83.   fprintf (stderr, "/* starting time is %d:%d:%d */\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
  84.   /* Sets the options. */
  85.   init_all (argc, argv);
  86.  
  87.   /* Generates the perfect hash table.
  88.      Also prints generated code neatly to the output. */
  89.   status = perfect_generate ();
  90.   destroy_all ();
  91.  
  92.   time (&clock);
  93.   tm = localtime (&clock);
  94.   fprintf (stderr, "/* ending time is %d:%d:%d */\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
  95.   return status;
  96. }
  97.