File: po-gram.lex

package info (click to toggle)
potool 0.4-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 136 kB
  • ctags: 60
  • sloc: ansic: 327; yacc: 160; sh: 95; makefile: 74
file content (110 lines) | stat: -rw-r--r-- 2,041 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
%option noyywrap
%option yylineno

%{
/*
 * potool is a program aiding editing of po files
 * Copyright (C) 1999-2000 Zbigniew Chyla
 *
 * see LICENSE for licensing info
 */
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "i18n.h"
#include "po-gram.h"
#include "po.tab.h"

static YY_BUFFER_STATE buf_state = (YY_BUFFER_STATE) 0;
static FILE *buf_file = NULL;

void po_scan_open_file(gchar *fn)
{
	if ( buf_state != (YY_BUFFER_STATE) 0 ) {
		g_error(_("Trying to scan two files!"));
	}
	if ( (buf_file = fopen(fn, "r")) == NULL ) {
		g_error(_("Can't open input file: %s\n"), fn);
	}
	buf_state = yy_create_buffer(buf_file, YY_BUF_SIZE);
	yy_switch_to_buffer(buf_state);
}

void po_scan_close_file(void)
{
	if ( buf_state == (YY_BUFFER_STATE) 0 ) {
		g_error(_("Can't delete input buffer!"));
	}
	buf_state = NULL;
	buf_file = NULL;
	yy_delete_buffer(buf_state);
}


%}

%%
"msgid"             { return MSGID; }
"msgstr"            { return MSGSTR; }
\"(\\.|[^\\"])*\"   {
	int l = strlen(yytext);
	char *s = g_malloc(l - 2 + 1);

	if ( l > 2 ) {
		(void) g_memmove(s, yytext+1, l - 2);
	}
	s[l - 2] = '\0';
	polval.strval = s;
	return STRING;
}
"#:".*"\n"          {
	int l = strlen(yytext);
	char *s = g_malloc(l - 3 + 1);

	if ( l > 3 ) {
		(void) g_memmove(s, yytext+2, l - 3);
	}
	s[l - 3] = '\0';
	polval.strval = s;
	return COMMENT_POS;
}
"#,".*"\n"          {
	int l = strlen(yytext);
	char *s = g_malloc(l - 3 + 1);

	if ( l > 3 ) {
		(void) g_memmove(s, yytext+2, l - 3);
	}
	s[l - 3] = '\0';
	polval.strval = s;
	return COMMENT_SPECIAL;
}

"# ".*"\n"          {
	int l = strlen(yytext);
	char *s = g_malloc(l - 3 + 1);

	if ( l > 3 ) {
		(void) g_memmove(s, yytext+2, l - 3);
	}
	s[l - 3] = '\0';
	polval.strval = s;
	return COMMENT_STD;
}

"#".*"\n"     {
	int l = strlen(yytext);
	char *s = g_malloc(l - 2 + 1);

	if ( l > 2 ) {
		(void) g_memmove(s, yytext + 1, l - 2);
	}
	s[l - 2] = '\0';
	polval.strval = s;
	return COMMENT_RESERVED;
}

[ \t\v\f\n]         { ; }
.                   { return INVALID; }

%%