[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to m4/src/freeze.c,v
From: |
Eric Blake |
Subject: |
Changes to m4/src/freeze.c,v |
Date: |
Thu, 27 Jul 2006 13:29:33 +0000 |
CVSROOT: /sources/m4
Module name: m4
Changes by: Eric Blake <ericb> 06/07/27 13:29:32
Index: src/freeze.c
===================================================================
RCS file: /sources/m4/m4/src/freeze.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- src/freeze.c 13 Jul 2006 23:35:16 -0000 1.44
+++ src/freeze.c 27 Jul 2006 13:29:31 -0000 1.45
@@ -163,8 +163,8 @@
}
static void *
-dump_symbol_CB (m4_symbol_table *symtab, const char *symbol_name, m4_symbol
*symbol,
- void *userdata)
+dump_symbol_CB (m4_symbol_table *symtab, const char *symbol_name,
+ m4_symbol *symbol, void *userdata)
{
lt_dlhandle handle = SYMBOL_HANDLE (symbol);
const char *module_name = handle ? m4_get_module_name (handle) : NULL;
@@ -361,7 +361,7 @@
reload_frozen_state (m4 *context, const char *name)
{
FILE *file;
- int version = 0;
+ int version;
int character;
int operation;
char syntax;
@@ -416,6 +416,22 @@
} \
while (0)
+ /* Skip comments (`#' at beginning of line) and blank lines, setting
+ character to the next directive or to EOF. */
+
+#define GET_DIRECTIVE \
+ do \
+ { \
+ GET_CHARACTER; \
+ if (character == '#') \
+ { \
+ while (character != EOF && character != '\n') \
+ GET_CHARACTER; \
+ VALIDATE ('\n'); \
+ } \
+ } \
+ while (character == '\n')
+
file = m4_path_search (context, name, (char **)NULL);
if (file == NULL)
M4ERROR ((EXIT_FAILURE, errno, _("Cannot open %s"), name));
@@ -427,27 +443,53 @@
allocated[2] = 100;
string[2] = xmalloc ((size_t) allocated[2]);
- while (GET_CHARACTER, character != EOF)
- switch (character)
+ /* Validate format version. Accept both `1' (m4 1.3 and 1.4.x) and
+ `2' (m4 2.0). */
+ GET_DIRECTIVE;
+ VALIDATE ('V');
+ GET_CHARACTER;
+ GET_NUMBER (version);
+ switch (version)
{
- default:
- M4ERROR ((EXIT_FAILURE, 0, _("Ill-formed frozen file")));
-
- case '\n':
-
- /* Skip empty lines. */
+ case 2:
+ {
+ int ch;
+ /* Take care not to mix frozen state with startup state. */
+ for (ch = 256; --ch > 0;)
+ context->syntax->table[ch] = 0;
+ }
break;
-
- case '#':
-
- /* Comments are introduced by `#' at beginning of line, and are
- ignored. */
-
- while (character != EOF && character != '\n')
- GET_CHARACTER;
- VALIDATE ('\n');
+ case 1:
+ {
+ // sleep(100);
+ m4__module_open (context, "m4", NULL);
+ if (m4_get_no_gnu_extensions_opt (context))
+ m4__module_open (context, "traditional", NULL);
+ else
+ m4__module_open (context, "gnu", NULL);
+ }
break;
+ default:
+ if (version > 2)
+ M4ERROR ((EXIT_MISMATCH, 0,
+ "frozen file version %d greater than max supported of 2",
+ version));
+ else
+ M4ERROR ((EXIT_FAILURE, 0,
+ "ill-formed frozen file, version directive expected"));
+ }
+ VALIDATE ('\n');
+
+ GET_DIRECTIVE;
+ while (character != EOF)
+ {
+ switch (character)
+ {
+ default:
+ M4ERROR ((EXIT_FAILURE, 0,
+ _("ill-formed frozen file, unknown directive %c"),
+ character));
case 'F':
GET_CHARACTER;
@@ -459,21 +501,24 @@
GET_CHARACTER;
GET_NUMBER (number[1]);
- if ((character == ',') && (version > 1))
+ if (character == ',')
+ {
+ if (version > 1)
{
/* 'F' operator accepts an optional third argument for
format versions 2 or later. */
GET_CHARACTER;
GET_NUMBER (number[2]);
}
- else if (version > 1)
- {
- number[2] = 0;
+ else
+ /* 3 argument 'F' operations are invalid for format
+ version 1. */
+ M4ERROR ((EXIT_FAILURE, 0, _("\
+ill-formed frozen file, version 2 directive encountered")));
}
else
{
- /* 3 argument 'F' operations are invalid for format version 1. */
- M4ERROR ((EXIT_FAILURE, 0, _("Ill-formed frozen file")));
+ number[2] = 0;
}
VALIDATE ('\n');
@@ -483,19 +528,17 @@
GET_STRING (file, string[0], allocated[0], number[0]);
GET_STRING (file, string[1], allocated[1], number[1]);
- if ((number[2] > 0) && (version > 1))
GET_STRING (file, string[2], allocated[2], number[2]);
VALIDATE ('\n');
/* Enter a macro having a builtin function as a definition. */
{
- const m4_builtin *bp = NULL;
+ const m4_builtin *bp;
lt_dlhandle handle = 0;
if (number[2] > 0)
handle = m4__module_find (string[2]);
- if (handle)
bp = m4_builtin_find_by_name (handle, string[1]);
if (bp)
@@ -531,7 +574,8 @@
if (version < 2)
{
/* 'M' operator is not supported in format version 1. */
- M4ERROR ((EXIT_FAILURE, 0, _("Ill-formed frozen file")));
+ M4ERROR ((EXIT_FAILURE, 0, _("\
+ill-formed frozen file, version 2 directive encountered")));
}
GET_CHARACTER;
@@ -549,7 +593,8 @@
if (version < 2)
{
/* 'R' operator is not supported in format version 1. */
- M4ERROR ((EXIT_FAILURE, 0, _("Ill-formed frozen file")));
+ M4ERROR ((EXIT_FAILURE, 0, _("\
+ill-formed frozen file, version 2 directive encountered")));
}
GET_CHARACTER;
@@ -573,7 +618,8 @@
if (version < 2)
{
/* 'S' operator is not supported in format version 1. */
- M4ERROR ((EXIT_FAILURE, 0, _("Ill-formed frozen file")));
+ M4ERROR ((EXIT_FAILURE, 0, _("\
+ill-formed frozen file, version 2 directive encountered")));
}
GET_CHARACTER;
@@ -682,29 +728,31 @@
GET_CHARACTER;
GET_NUMBER (number[1]);
- if ((character == ',') && (version > 1))
+ if (character == ',')
+ {
+ if (version > 1)
{
/* 'T' operator accepts an optional third argument for
format versions 2 or later. */
GET_CHARACTER;
GET_NUMBER (number[2]);
}
- else if (version > 1)
- {
- number[2] = 0;
- }
else
{
- /* 3 argument 'T' operations are invalid for format version 1. */
- M4ERROR ((EXIT_FAILURE, 0, _("Ill-formed frozen file")));
+ /* 3 argument 'T' operations are invalid for format
+ version 1. */
+ M4ERROR ((EXIT_FAILURE, 0, _("\
+ill-formed frozen file, version 2 directive encountered")));
+ }
}
+ else
+ number[2] = 0;
VALIDATE ('\n');
/* Get string contents. */
GET_STRING (file, string[0], allocated[0], number[0]);
GET_STRING (file, string[1], allocated[1], number[1]);
- if ((number[2] > 0) && (version > 1))
GET_STRING (file, string[2], allocated[2], number[2]);
VALIDATE ('\n');
@@ -724,19 +772,8 @@
}
break;
- case 'V':
-
- /* Validate and save format version. Only `1' and `2'
- are acceptable for now. */
-
- GET_CHARACTER;
- version = character - '0';
- if ((version < 1) || (version > 2))
- issue_expect_message ('2');
- GET_CHARACTER;
- VALIDATE ('\n');
- break;
-
+ }
+ GET_DIRECTIVE;
}
free (string[0]);
@@ -749,4 +786,5 @@
#undef GET_NUMBER
#undef VALIDATE
#undef CHECK_ALLOCATION
+#undef GET_DIRECTIVE
}