Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / gperf / src / main.cc
1 /* Driver program for the Gen_Perf hash function generator
2    Copyright (C) 1989-1998, 2000 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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA.  */
20
21 /* Simple driver program for the Gen_Perf.hash function generator.
22    Most of the hard work is done in class Gen_Perf and its class methods. */
23
24 #include "config.h"
25 #include <sys/types.h>
26 #if LARGE_STACK_ARRAYS && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
27 #ifdef HAVE_SYS_TIME_H
28 #include <sys/time.h>
29 #endif
30 #ifdef HAVE_SYS_RESOURCE_H
31 #include <sys/resource.h>
32 #endif
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36 #endif
37
38 #include <stdio.h>
39 #include "options.h"
40 #include "gen-perf.h"
41 #include "trace.h"
42
43 int
44 main (int argc, char *argv[])
45 {
46   T (Trace t ("main");)
47
48 #if LARGE_STACK_ARRAYS && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) && defined(RLIMIT_STACK)
49   /* Get rid of any avoidable limit on stack size.  */
50   {
51     struct rlimit rlim;
52     if (getrlimit (RLIMIT_STACK, &rlim) == 0)
53       if (rlim.rlim_cur < rlim.rlim_max)
54         {
55           rlim.rlim_cur = rlim.rlim_max;
56           setrlimit (RLIMIT_STACK, &rlim);
57         }
58   }
59 #endif /* RLIMIT_STACK */
60
61   /* Sets the Options. */
62   option (argc, argv);
63
64   /* Initializes the key word list. */
65   Gen_Perf generate_table;
66
67   /* Generates and prints the Gen_Perf hash table. */
68   int status = generate_table ();
69
70   /* Check for write error on stdout. */
71   if (fflush (stdout) || ferror (stdout))
72     status = 1;
73
74   /* Don't use exit() here, it skips the destructors. */
75   return status;
76 }