if (argc - optind > 1)
printf ("Reading \"%s\":\n", r.file_name);
-
+
read_header (&r);
while ((rec_type = read_int (&r)) != 999)
{
fclose (r.file);
}
-
+
return 0;
}
case 37: return "CCE";
case 38: return "EDATE";
case 39: return "SDATE";
+ case 40: return "MTIME";
+ case 41: return "YMDHMS";
default: return "invalid";
}
}
if (has_variable_label == 1)
{
long long int offset = ftello (r->file);
- size_t len;
- char *label;
-
- len = read_int (r);
+ enum { MAX_LABEL_LEN = 65536 };
- /* Read up to 255 bytes of label. */
- label = xmalloc (len + 1);
- read_string (r, label, len + 1);
+ size_t len = read_int (r);
+ size_t read_len = MIN (MAX_LABEL_LEN, len);
+ char *label = xmalloc (read_len + 1);
+ read_string (r, label, read_len + 1);
printf("\t%08llx Variable label: \"%s\"\n", offset, label);
free (label);
}
number = text_tokenize (text, ' ');
- if (!strcmp (number, "11"))
+ if (!number)
+ sys_warn (r, "Missing label source value "
+ "following `E' at offset %zu in MRSETS record",
+ text_pos (text));
+ else if (!strcmp (number, "11"))
label_from_var_label = true;
else if (strcmp (number, "1"))
sys_warn (r, "Unexpected label source value `%s' "
const char *key;
int index;
- for (;;)
+ for (;;)
{
key = text_tokenize (text, '(');
if (key == NULL)
return true;
-
+
for (index = 1; ; index++)
{
/* Parse the value. */
const char *value = text_tokenize (text, '\n');
- if (value == NULL)
+ if (value == NULL)
{
sys_warn (r, "%s: Error parsing attribute value %s[%d]",
variable, key, index);
}
if (text_match (text, '/'))
- return true;
+ return true;
}
}
}
static void
-read_datafile_attributes (struct sfm_reader *r, size_t size, size_t count)
+read_datafile_attributes (struct sfm_reader *r, size_t size, size_t count)
{
struct text_record *text;
-
+
printf ("%08llx: datafile attributes\n", (long long int) ftello (r->file));
text = open_text_record (r, size * count);
read_attributes (r, text, "datafile");
}
static void
-read_variable_attributes (struct sfm_reader *r, size_t size, size_t count)
+read_variable_attributes (struct sfm_reader *r, size_t size, size_t count)
{
struct text_record *text;
-
+
printf ("%08llx: variable attributes\n", (long long int) ftello (r->file));
text = open_text_record (r, size * count);
- for (;;)
+ for (;;)
{
const char *variable = text_tokenize (text, ':');
if (variable == NULL || !read_attributes (r, text, variable))
- break;
+ break;
}
close_text_record (text);
}
}
static bool
-text_match (struct text_record *text, int c)
+text_match (struct text_record *text, int c)
{
- if (text->pos < text->size && text->buffer[text->pos] == c)
+ if (text->pos < text->size && text->buffer[text->pos] == c)
{
text->pos++;
return true;