#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include "xmalloc.h"
#define yycheck po_hash_yycheck
-#line 101 "po-hash-gen.y"
+#line 102 "po-hash-gen.y"
typedef union
{
char *string;
size_t number;
} YYSTYPE;
-#line 110 "po-hash-gen.y"
+#line 111 "po-hash-gen.y"
-static const char *cur;
-
-
-void yyerror PARAMS ((char *));
-int yylex PARAMS ((void));
-
-
-int
-po_hash (s)
- const char *s;
-{
- extern int yyparse PARAMS ((void));
-
- cur = s;
- return yyparse ();
-}
+/* Forward declarations, to avoid gcc warnings. */
+void yyerror (char *);
+int yylex (void);
void
-yyerror (s)
- char *s;
+yyerror (char *s)
{
/* Do nothing, the grammar is used as a recogniser. */
}
#if YYDEBUG != 0
static const short yyrline[] = { 0,
- 141, 142, 146, 152, 158, 164, 170
+ 128, 129, 133, 139, 145, 151, 157
};
#endif
switch (yyn) {
case 3:
-#line 147 "po-hash-gen.y"
+#line 134 "po-hash-gen.y"
{
/* GNU style */
po_callback_comment_filepos (yyvsp[-2].string, yyvsp[0].number);
;
break;}
case 4:
-#line 153 "po-hash-gen.y"
+#line 140 "po-hash-gen.y"
{
/* GNU style, without line number (e.g. from Pascal .rst) */
po_callback_comment_filepos (yyvsp[0].string, (size_t)(-1));
;
break;}
case 5:
-#line 159 "po-hash-gen.y"
+#line 146 "po-hash-gen.y"
{
/* SunOS style */
po_callback_comment_filepos (yyvsp[-4].string, yyvsp[0].number);
;
break;}
case 6:
-#line 165 "po-hash-gen.y"
+#line 152 "po-hash-gen.y"
{
/* Solaris style */
po_callback_comment_filepos (yyvsp[-5].string, yyvsp[0].number);
;
break;}
case 7:
-#line 171 "po-hash-gen.y"
+#line 158 "po-hash-gen.y"
{
/* GNU style, but STRING is `file'. Esoteric, but it
happened. */
}
return 1;
}
-#line 178 "po-hash-gen.y"
+#line 165 "po-hash-gen.y"
+/* Current position in the pseudo-comment line. */
+static const char *cur;
+
+/* The NUMBER token must only be recognized after colon. So we have to
+ remember whether the last token was a colon. */
+static bool last_was_colon;
+
+/* Returns the next token from the current pseudo-comment line. */
int
yylex ()
{
static char *buf;
static size_t bufmax;
- size_t bufpos;
- size_t n;
- int c;
+
+ bool look_for_number = last_was_colon;
+ last_was_colon = false;
for (;;)
{
- c = *cur++;
+ int c = *cur++;
switch (c)
{
case 0:
break;
case ':':
+ last_was_colon = true;
return COLON;
case ',':
case '7':
case '8':
case '9':
- /* Accumulate a number. */
- n = 0;
- for (;;)
+ if (look_for_number)
{
- n = n * 10 + c - '0';
- c = *cur++;
- switch (c)
+ /* Accumulate a number. */
+ size_t n = 0;
+
+ for (;;)
{
- default:
+ n = n * 10 + c - '0';
+ c = *cur++;
+ switch (c)
+ {
+ default:
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ continue;
+ }
break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- continue;
}
- break;
+ --cur;
+ yylval.number = n;
+ return NUMBER;
}
- --cur;
- yylval.number = n;
- return NUMBER;
+ /* FALLTHROUGH */
default:
/* Accumulate a string. */
- bufpos = 0;
- for (;;)
- {
- if (bufpos >= bufmax)
- {
- bufmax += 100;
- buf = xrealloc (buf, bufmax);
- }
- buf[bufpos++] = c;
-
- c = *cur++;
- switch (c)
- {
- default:
- continue;
-
- case 0:
- case ':':
- case ',':
- case ' ':
- case '\t':
- --cur;
- break;
- }
- break;
- }
-
- if (bufpos >= bufmax)
- {
- bufmax += 100;
- buf = xrealloc (buf, bufmax);
- }
- buf[bufpos] = 0;
-
- if (strcmp (buf, "file") == 0 || strcmp (buf, "File") == 0)
- return FILE_KEYWORD;
- if (strcmp (buf, "line") == 0)
- return LINE_KEYWORD;
- if (strcmp (buf, "number") == 0)
- return NUMBER_KEYWORD;
- yylval.string = xstrdup (buf);
- return STRING;
+ {
+ size_t bufpos;
+
+ bufpos = 0;
+ for (;;)
+ {
+ if (bufpos >= bufmax)
+ {
+ bufmax += 100;
+ buf = xrealloc (buf, bufmax);
+ }
+ buf[bufpos++] = c;
+
+ c = *cur++;
+ switch (c)
+ {
+ default:
+ continue;
+
+ case 0:
+ case ':':
+ case ',':
+ case ' ':
+ case '\t':
+ --cur;
+ break;
+ }
+ break;
+ }
+
+ if (bufpos >= bufmax)
+ {
+ bufmax += 100;
+ buf = xrealloc (buf, bufmax);
+ }
+ buf[bufpos] = 0;
+
+ if (strcmp (buf, "file") == 0 || strcmp (buf, "File") == 0)
+ return FILE_KEYWORD;
+ if (strcmp (buf, "line") == 0)
+ return LINE_KEYWORD;
+ if (strcmp (buf, "number") == 0)
+ return NUMBER_KEYWORD;
+ yylval.string = xstrdup (buf);
+ return STRING;
+ }
}
}
}
+
+
+/* Analyze whether the string (a pseudo-comment line) contains file names
+ and line numbers. */
+int
+po_hash (const char *s)
+{
+ cur = s;
+ last_was_colon = false;
+ return yyparse ();
+}
} java_keyword;
-/* Prototypes for local functions. Needed to ensure compiler checking of
- function argument counts despite of K&R C function definition syntax. */
-static char_buf *create_char_buf PARAMS ((void));
-static void append_char_buf PARAMS ((char_buf *b, int c));
-static char *get_string PARAMS ((char_buf *b));
-static void destroy_charbuf PARAMS ((char_buf *b));
-static void update_line_no PARAMS ((int c));
-static void strip_ending_spaces PARAMS ((char *str));
-static char *append_strings PARAMS ((char *a, char *b));
-static inline bool isplus PARAMS ((char *s));
-static inline bool isdot PARAMS ((char *s));
-static char *translate_esc PARAMS ((char *s));
-static object_list * object_list_alloc PARAMS ((void));
-static void object_list_destroy PARAMS ((object_list *list));
-static int get_num_objects PARAMS ((const object_list *list));
-static void * get_object PARAMS ((const object_list *list, int i));
-static void add_object PARAMS ((object_list *list, void *object));
-static java_keyword * alloc_keyword PARAMS ((const char *keyword,
- int arg1, int arg2));
-static bool tailcmp PARAMS ((const char *s1, const char *s2));
-static bool do_compare PARAMS ((const char *s1, const char *s2));
-static java_keyword *is_keyword PARAMS ((const char *s));
-static void free_global PARAMS ((void));
-
-
#define INITIAL_CHARBUF_SIZE 500
#define CHARBUF_GROWTH 100
static char_buf *
}
static void
-append_char_buf (b, c)
- char_buf *b;
- int c;
+append_char_buf (char_buf *b, int c)
{
if (b->len >= b->maxlen - 1)
{
}
static char *
-get_string (b)
- char_buf *b;
+get_string (char_buf *b)
{
return xstrdup (b->data);
}
static void
-destroy_charbuf (b)
- char_buf *b;
+destroy_charbuf (char_buf *b)
{
free (b->data);
free (b);
}
static void
-update_line_no (c)
- int c;
+update_line_no (int c)
{
if (c == '\n')
parser_global->line_no++;
}
static void
-strip_ending_spaces (str)
- char *str;
+strip_ending_spaces (char *str)
{
int len = strlen (str);
len--;
str[len] = '\0';
}
-#line 590 "x-java.c-tmp"
+#line 559 "x-java.c-tmp"
/* Macros after this point can all be overridden by user definitions in
* section 1.
register char *yy_cp, *yy_bp;
register int yy_act;
-#line 186 "./x-java.l"
+#line 155 "./x-java.l"
-#line 744 "x-java.c-tmp"
+#line 713 "x-java.c-tmp"
if ( yy_init )
{
case 1:
YY_RULE_SETUP
-#line 188 "./x-java.l"
+#line 157 "./x-java.l"
{
int c;
int last;
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 211 "./x-java.l"
+#line 180 "./x-java.l"
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 212 "./x-java.l"
+#line 181 "./x-java.l"
{
int c;
char *str;
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 227 "./x-java.l"
+#line 196 "./x-java.l"
{
parser_global->word = yytext;
return JAVA_WORD;
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 232 "./x-java.l"
+#line 201 "./x-java.l"
{
parser_global->flow = yytext;
return JAVA_FLOW;
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 237 "./x-java.l"
+#line 206 "./x-java.l"
{
parser_global->operator = yytext;
return JAVA_OPERATOR;
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 242 "./x-java.l"
+#line 211 "./x-java.l"
/* ignore whitespace */
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 244 "./x-java.l"
+#line 213 "./x-java.l"
{
parser_global->comment = xstrdup (yytext + 2);
return JAVA_COMMENT;
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 248 "./x-java.l"
+#line 217 "./x-java.l"
parser_global->line_no++;
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 249 "./x-java.l"
+#line 218 "./x-java.l"
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 250 "./x-java.l"
+#line 219 "./x-java.l"
YY_BREAK
case YY_STATE_EOF(INITIAL):
-#line 251 "./x-java.l"
+#line 220 "./x-java.l"
return -1;
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 252 "./x-java.l"
+#line 221 "./x-java.l"
ECHO;
YY_BREAK
-#line 937 "x-java.c-tmp"
+#line 906 "x-java.c-tmp"
case YY_END_OF_BUFFER:
{
return 0;
}
#endif
-#line 252 "./x-java.l"
+#line 221 "./x-java.l"
static char *
-append_strings (a, b)
- char *a;
- char *b;
+append_strings (char *a, char *b)
{
int total_size = strlen (a) + strlen (b) + 1;
char *new_string = (char *) xmalloc (total_size);
}
static inline bool
-isplus (s)
- char *s;
+isplus (char *s)
{
return *s == '+';
}
static inline bool
-isdot (s)
- char *s;
+isdot (char *s)
{
return *s == '.';
}
static char *
-translate_esc (s)
- char *s;
+translate_esc (char *s)
{
char *n = (char *) xmalloc (strlen (s) + 1);
size_t i;
}
static void
-object_list_destroy (list)
- object_list *list;
+object_list_destroy (object_list *list)
{
free (list->objects);
free (list);
}
static int
-get_num_objects (list)
- const object_list *list;
+get_num_objects (const object_list *list)
{
return list->num_obj;
}
static void *
-get_object (list, i)
- const object_list *list;
- int i;
+get_object (const object_list *list, int i)
{
return list->objects[i];
}
static void
-add_object (list, object)
- object_list *list;
- void *object;
+add_object (object_list *list, void *object)
{
if (list->num_obj + 1 >= list->max_num_obj)
{
static java_keyword *
-alloc_keyword (keyword, arg1, arg2)
- const char *keyword;
- int arg1;
- int arg2;
+alloc_keyword (const char *keyword, int arg1, int arg2)
{
java_keyword *jk = xmalloc (sizeof (java_keyword));
jk->keyword = xstrdup (keyword);
* Backwards substring match.
*/
static bool
-tailcmp (s1, s2)
- const char *s1;
- const char *s2;
+tailcmp (const char *s1, const char *s2)
{
int len1 = strlen (s1);
int len2 = strlen (s2);
* true substring match is used.
*/
static bool
-do_compare (s1, s2)
- const char *s1;
- const char *s2;
+do_compare (const char *s1, const char *s2)
{
if (substring_match)
return strstr (s1, s2) != NULL;
* Check if a string is a keyword or not.
*/
static java_keyword *
-is_keyword (s)
- const char *s;
+is_keyword (const char *s)
{
int i;
int num_keywords = get_num_objects (java_keywords);
* Add a keyword to the list of possible keywords.
*/
void
-x_java_keyword (keyword)
- const char *keyword;
+x_java_keyword (const char *keyword)
{
const char *keyword_end;
int arg1;
* Main java keyword extract function.
*/
void
-extract_java (f, real_filename, logical_filename, mdlp)
- FILE *f;
- const char *real_filename;
- const char *logical_filename;
- msgdomain_list_ty *mdlp;
+extract_java (FILE *f,
+ const char *real_filename, const char *logical_filename,
+ msgdomain_list_ty *mdlp)
{
char *logical_file_name = xstrdup (logical_filename);
int token;