File: main.c

package info (click to toggle)
mawk 1.3.4.20260129-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,244 kB
  • sloc: ansic: 19,998; sh: 4,627; yacc: 1,182; awk: 903; makefile: 301
file content (107 lines) | stat: -rw-r--r-- 2,012 bytes parent folder | download | duplicates (3)
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
/********************************************
main.c
copyright 2009-2017,2024, Thomas E. Dickey
copyright 1991-1995,2014, Michael D. Brennan

This is a source file for mawk, an implementation of
the AWK programming language.

Mawk is distributed without warranty under the terms of
the GNU General Public License, version 2, 1991.
********************************************/

/*
 * $MawkId: main.c,v 1.35 2024/12/14 12:53:14 tom Exp $
 */

#define Visible_CELL

#include <mawk.h>
#include <bi_vars.h>
#include <init.h>
#include <code.h>
#include <files.h>

#ifdef LOCALE
#include <locale.h>
#endif

short mawk_state;		/* 0 is compiling */
int exit_code;

#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
int ignore_unused;
#endif

#ifdef LOCALE
char decimal_dot;
#endif

int
main(int argc, char **argv)
{
#ifdef LOCALE
    setlocale(LC_CTYPE, "");
    setlocale(LC_NUMERIC, "C");
#endif
    initialize(argc, argv);
#ifdef LOCALE
    {
	struct lconv *data;

	decimal_dot = '\0';	/* only set to nonzero if not POSIX '.' */
	setlocale(LC_NUMERIC, "");
	data = localeconv();
	if (data != NULL
	    && data->decimal_point != NULL
	    && strlen(data->decimal_point) == 1) {
	    decimal_dot = data->decimal_point[0];
	} else {
	    /* back out of this if we cannot handle it */
	    setlocale(LC_NUMERIC, "C");
	}
	if (decimal_dot == '.')
	    decimal_dot = 0;
    }
#endif

    parse();

    mawk_state = EXECUTION;
    execute(execution_start, NULL, NULL);
    /* never returns */
    return 0;
}

void
mawk_exit(int x)
{
    TRACE(("mawk_exit(%d)\n", x));
#ifdef  HAVE_REAL_PIPES
    close_out_pipes();		/* actually closes all output */
#else
#ifdef  HAVE_FAKE_PIPES
    close_fake_pipes();
#endif
#endif

#ifdef NO_LEAKS
    code_leaks();
    scan_leaks();
    cell_leaks();
    re_leaks();
    rexp_leaks();
    bi_vars_leaks();
    hash_leaks();
    array_leaks();
    files_leaks();
    fin_leaks();
    field_leaks();
    zmalloc_leaks();
#if OPT_TRACE > 0
    trace_leaks();
#endif
#endif

    exit(x);
}