aboutsummaryrefslogtreecommitdiff
path: root/src/input.l
blob: 02dd4994c8fe0df235e83f9ac7e24326e080690c (plain)
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
%{
/*
   This file is part of Ellinika project.
   Copyright (C) 2004 Sergey Poznyakoff

   Ellinika 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.

   Ellinika 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 Ellinika; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "trans.h"
#include "gram.h"
#include <string.h>
	
char *file_name = NULL;
int input_line = 1;

void set_location();
#define isws(c) ((c)==' ' || (c)=='\t') 
%}

MWS [ \t]*
WS [ \t]+
%%
#.*\n                          {
	printf("<!-- %*.*s -->\n",yyleng-2,yyleng-2,yytext+1);
	input_line++; }
^[nN][oO][dD][eE]              return NODE;
^[pP][oO][sS]                  return POS;
^[eE][nN][dD]{MWS}             return END;
^[mM][eE][aA][nN][iI][nN][gG]  return MEANING;
^[aA][lL][iI][aA][sS]          return ALIAS;
^[aA][nN][tT]                  return ANT; 
^[tT][oO][pP][iI][cC]          return TOPIC;
^[fF][oO][rR][mM][sS]          return FORMS;
^[xX][rR][eE][fF]              return XREF;
^[lL][iI][nN][eE]{WS}\"[^\"]+\"{WS}[0-9]+\n  set_location();
\n                             input_line++; 
{WS}[^\n]+\n                   {
	char *p, *q;

	for (p = yytext + yyleng - 1; p > yytext && isspace(*p); p--)
		;
	p[1] = 0;
	input_line++;
	yylval.string = yytext+1;
	return STRING;
}
.                              { fprintf (stderr, "%s:%d: stray character %c\n",
					  file_name, input_line, yytext[0]);
                                  exit(1); }
				  
%%


void
set_location()
{
	char *start = strchr(yytext+1, '"');
	char *p = strchr(start+1, '"');
	int len = p-start-1;
	free(file_name);
	file_name = emalloc(len+1);
	memcpy(file_name, start+1, len);
	file_name[len] = 0;
	for (p++; p < yytext+yyleng && isws (*p); p++)
		;
	input_line = strtoul (p, NULL, 0);
}

char *m4_cmdline;
#define DEFAULT_INCLUDE "dict.m4"

void
make_m4_args (char *m4_bin, RAD_LIST *include_list)
{
	int i, n;
	size_t len;

	len = strlen(m4_bin);
	for (i = 0; i < list_count(include_list); i++) 
		len += 3 + strlen(list_item(include_list, i));
	len += 1+strlen(DEFAULT_INCLUDE);
	len++;
	m4_cmdline = emalloc(len);
	n = sprintf(m4_cmdline, "%s ", m4_bin);
	for (i = 0; i < list_count(include_list); i++) 
		n += sprintf(m4_cmdline+n, "-I%s ", list_item(include_list, i));
	n += sprintf(m4_cmdline+n, "%s", DEFAULT_INCLUDE);
	m4_cmdline[n] = 0;
}

void
open_input(int argc, char **argv)
{
	char *inv;
	int i, n, len = 0;

	for (i = 0; i < argc; i++)
		len += 1 + strlen(argv[i]);

	inv = emalloc(strlen(m4_cmdline) + len + 1);
	n = sprintf(inv, "%s", m4_cmdline);
	for (i = 0; i < argc; i++)
		n += sprintf(inv+n, " %s", argv[i]);
	inv[n] = 0;
	yyin = popen(inv, "r");
	if (!yyin) {
		fprintf(stderr, "cannot execute ");
		perror(inv);
		exit(1);
	}
	free(inv);
}

int
yywrap()
{
	if (file_name)
		pclose(yyin);
	return 1;
}
		

Return to:

Send suggestions and report system problems to the System administrator.