File: main.c

package info (click to toggle)
gambc 3.0-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 14,928 kB
  • ctags: 5,931
  • sloc: ansic: 295,198; lisp: 33,097; perl: 1,730; makefile: 760; sed: 448; sh: 215
file content (172 lines) | stat: -rwxr-xr-x 4,894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* file: "main.c" */

/* Copyright (C) 1994-1998 by Marc Feeley, All Rights Reserved. */

/* This is the driver of the Gambit-C system */

#define ___INCLUDED_FROM_MAIN
#define ___VERSION 21
#include "gambit.h"

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


___HIDDEN void usage_err ___P((char **argv),(argv)
char **argv;)
{
  fprintf (stderr, "Usage: %s [-:OPT,OPT...] ...\n", argv[0]);
  fprintf (stderr, "  where OPT can be one of:\n");
  fprintf (stderr, "    kSTACK_CACHE_SIZE_IN_KILOBYTES\n");
  fprintf (stderr, "    mMIN_HEAP_SIZE_IN_KILOBYTES\n");
  fprintf (stderr, "    hMAX_HEAP_SIZE_IN_KILOBYTES\n");
  fprintf (stderr, "    lPERCENT_LIVE_AFTER_GC\n");
  fprintf (stderr, "    s\n");
  fprintf (stderr, "    d[level]\n");
  fprintf (stderr, "    t\n");
  fprintf (stderr, "    u\n");
  fprintf (stderr, "    c\n");
  fprintf (stderr, "    1\n");
  fprintf (stderr, "    8\n");
  exit (1);
}


___EXP_FUNC(int,___main)
  ___P((int argc,
        char **argv,
        ___mod_or_lnk (*linker)(___global_state_struct*)),
       (argc, argv, linker)
int argc;
char **argv;
___mod_or_lnk (*linker)();)
{
  unsigned long stack_cache_len, min_heap_len, max_heap_len;
  int live_percent;
  int default_io_encoding;
  int standard;
  int debug_level;
  int force_tty;
  int force_unbuffered_io;

  /* handle arguments to runtime */

  stack_cache_len = 0;
  min_heap_len = 0;
  max_heap_len = 0;
  live_percent = 0;
  default_io_encoding = ___DEFAULT_IO_ENCODING;
  standard = 0;
  debug_level = 0;
  force_tty = 0;
  force_unbuffered_io = 0;

  if (argc > 1)
    {
      char *s, *arg = argv[1];
      if (*arg++ == '-' && *arg++ == ':')
        {
          do
            {
              s = arg++;
              switch (*s)
                {
                case 'm':
                case 'h':
                case 'k':
                case 'l':
                case 'd':
                  {
                    char temp;
                    int argval;
                    while (*arg >= '0' && *arg <= '9') arg++;
                    temp = *arg;
                    *arg = '\0';
                    if (arg == s+1 && *s == 'd')
                      argval = 1;
                    else
                      argval = atoi (s+1);
                    *arg = temp;
                    switch (*s)
                      {
                      case 'k': stack_cache_len = (unsigned long)argval<<10;
                                break;
                      case 'm': min_heap_len = (unsigned long)argval<<10;
                                break;
                      case 'h': max_heap_len = (unsigned long)argval<<10;
                                break;
                      case 'l': live_percent = argval;
                                break;
                      case 'd': debug_level = argval;
                                break;
                      }
                    break;
                  }
                case 's':
                  standard = 1;
                  break;
                case 't':
                  force_tty = 1;
                  break;
                case 'u':
                  force_unbuffered_io = 1;
                  break;
                case 'c':
                  default_io_encoding = ___IO_CHAR_ENCODING;
                  break;
                case '1':
                  default_io_encoding = ___IO_LATIN1_ENCODING;
                  break;
                case '8':
                  default_io_encoding = ___IO_UTF8_ENCODING;
                  break;
                default:
                  usage_err (argv);
                }
            }
          while (*arg++ == ',');
          if (*--arg != '\0')
            usage_err (argv);
          argv[1] = argv[0];
          argc--;
          argv++;
        }
    }

#ifdef FORCE_MAX_HEAP
  if (max_heap_len == 0 || max_heap_len > FORCE_MAX_HEAP<<10)
    max_heap_len = FORCE_MAX_HEAP<<10;
#endif

  /* Setup program, run it and perform any cleanup necessary. */

  {
    ___setup_params_struct setup_params;

    setup_params.argc                = argc;
    setup_params.argv                = argv;
    setup_params.stack_cache         = stack_cache_len;
    setup_params.min_heap            = min_heap_len;
    setup_params.max_heap            = max_heap_len;
    setup_params.live_percent        = live_percent;
    setup_params.gc_hook             = 0;
    setup_params.fatal_error         = 0;
    setup_params.standard            = standard;
    setup_params.debug_level         = debug_level;
    setup_params.default_io_encoding = default_io_encoding;
    setup_params.force_tty           = force_tty;
    setup_params.force_unbuffered_io = force_unbuffered_io;
    setup_params.linker              = linker;

    ___setup (&setup_params);

    ___cleanup ();
  }

  /* Exit program. */

  exit (0);

  return 0; /* satisfy some compilers */
}