File: kmfl_compiler.c

package info (click to toggle)
kmflcomp 0.9.10-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,760 kB
  • ctags: 1,007
  • sloc: sh: 11,352; ansic: 1,740; yacc: 493; lex: 342; makefile: 56
file content (131 lines) | stat: -rw-r--r-- 2,828 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
/* kmfl_compiler.c
 * Copyright (C) 2005  SIL International
 *
 * This file is part of KMFL compiler.
 *
 * KMFL compiler is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KMFL compiler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KMFL compiler; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */
const char * VERSION= "0.9.10";

#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/stat.h>
#include <setjmp.h>

#ifdef _WIN32
	#include <io.h>
	#include <conio.h>
	#include "getopt.h"
	#define strcasecmp	_stricmp
	#define rindex strrchr
	#define seek _lseek
	#define DIRDELIM	'\\'
	char *GetInputFile(void);
#else
	#include <getopt.h>
	#include <sys/types.h>
	#include <unistd.h>
	#define O_BINARY 	0
	#define DIRDELIM	'/'
#endif

#include <fcntl.h>
#include <kmflcomp.h>
const char * usagemsg=
"usage: kmflcomp [OPTION...] file\n" \
" -d     debug\n" \
" -f     force compilation\n" \
" -h     print this help message\n" \
" -V     verbose\n" \
" -v     print program version\n" \
" -y     yydebug\n";

void usage(void)
{
	fprintf(stderr, "kmflcomp version %s\n", VERSION);
	fprintf(stderr, "%s", usagemsg);
	exit(1);
}

int main(int argc, char *argv[]) 
{
	int opt,nopt=0;
	void * keyboard_buffer;
	unsigned long keyboard_buffer_size;
	int errcode;
    char *fname="(stdin)";

	while((opt=getopt(argc,argv,"dfhVvy"))!=EOF) 
	{
		switch (opt) 
		{
		case 'd':
			opt_debug=1;
			break;
		case 'f':
			opt_force=1;
			break;
		case 'h':
			usage();
			break;
		case 'V':
			opt_verbose = 1;
			break;
		case 'v':
			fprintf(stderr, "kmflcomp version %s\n", VERSION);
			exit(0);
		case 'y':
			yydebug = 1;
			break;
		}
		nopt++;
	}

	if(argc > nopt+1)
		fname=argv[argc-1];
	else
		usage();

#ifdef _WIN32
	else if(!(fname=GetInputFile())) exit(0);
#endif

	// Set warnings level
	if(opt_verbose) 
	   errlimit = warnlimit = 1000;
	   
	errcode = setjmp(fatal_error_buf);
	
    if (errcode == 0)
    {
        keyboard_buffer_size = compile_keyboard_to_buffer(fname, &keyboard_buffer);
    
        write_keyboard(fname, keyboard_buffer, keyboard_buffer_size);
        free(keyboard_buffer);
    
#ifdef _WIN32	
	   if(opt_debug) getch();
#endif	

	   exit(errcount);
    } else {
        exit(errcode);
    }
}