Thought better about suddenly changing the .mag file format with

new properties, so created a "property compat" setting and made
it TRUE by default.  This makes magic print all properties as
type "string" on output into a .mag file.  Which is fine, since
it converts all values to the right type on input anyway.  The
only thing that backwards-compatibility mode prevents is user-
defined properties that are not strings.  That is a very rare case
and can be done by turning off comptability mode.  Some time in
the future compatibility mode can be changed to be default false,
but there's probably no real need to do so.
This commit is contained in:
R. Timothy Edwards 2026-02-18 16:17:03 -05:00
parent 00c0208f18
commit 9ab7b77dc4
5 changed files with 96 additions and 21 deletions

View File

@ -2296,6 +2296,8 @@ parsepositions:
editDef->cd_flags |= (CDMODIFIED | CDGETNEWSTAMP);
}
#define PROPERTY_TYPE_COMPAT 4 /* Last entry in cmdPropertyType */
/*
* ----------------------------------------------------------------------------
*
@ -2335,9 +2337,11 @@ CmdDoProperty(
int printPropertiesFunc(); /* Forward declaration */
/* These should match the property codes in database.h.in */
/* These should match the property codes in database.h.in, except
* for "compat" which must come at the end.
*/
static const char * const cmdPropertyType[] = {
"string", "integer", "dimension", "double", NULL
"string", "integer", "dimension", "double", "compat", NULL
};
/* If a property type is given, parse it and then strip it from
@ -2348,8 +2352,11 @@ CmdDoProperty(
proptype = Lookup(cmd->tx_argv[argstart], cmdPropertyType);
if (proptype >= 0)
{
locargc--;
argstart++;
if (proptype != PROPERTY_TYPE_COMPAT)
{
locargc--;
argstart++;
}
}
else
proptype = PROPERTY_TYPE_STRING; /* default */
@ -2373,6 +2380,19 @@ CmdDoProperty(
else if (locargc == 2)
{
/* If the property type was "compat", then give the state of the
* compatibility flag and return.
*/
if (proptype == PROPERTY_TYPE_COMPAT)
{
#ifdef MAGIC_WRAPPER
Tcl_SetObjResult(magicinterp, Tcl_NewBooleanObj(DBPropCompat));
#else
TxPrintf("%s\n", (DBPropCompat == TRUE) ? "True" : "False");
#endif
return;
}
/* print the value of the indicated property */
proprec = (PropertyRecord *)DBPropGet(def, cmd->tx_argv[argstart], &propfound);
if (propfound)
@ -2469,6 +2489,25 @@ CmdDoProperty(
}
else if (locargc >= 3)
{
/* If the property type was "compat", then set the state of the
* compatibility flag and return.
*/
if (proptype == PROPERTY_TYPE_COMPAT)
{
int idx;
static const char * const cmdPropYesNo[] = {
"disable", "no", "false", "off", "0",
"enable", "yes", "true", "on", "1", 0 };
idx = Lookup(cmd->tx_argv[2], cmdPropYesNo);
if (idx < 0)
{
TxError("Unknown property compat option \"%s\"\n", cmd->tx_argv[2]);
return;
}
DBPropCompat = (idx <= 4) ? FALSE : TRUE;
return;
}
/* Catch the following known reserved keywords and cast them to the
* expected property type. If any property type was already given
* to the command, it is overridden. This ensures that the reserved

View File

@ -2508,7 +2508,8 @@ dbReadProperties(cellDef, line, len, f, scalen, scaled)
/* handled as a dimension to avoid parsing the string */
/* value every time the coordinates are needed. */
if (!strcmp(propertyname, "FIXED_BBOX"))
if ((!strcmp(propertyname, "FIXED_BBOX")) ||
(!strcmp(propertyname, "OBS_BBOX")))
{
Rect locbbox;
@ -2546,7 +2547,8 @@ dbReadProperties(cellDef, line, len, f, scalen, scaled)
locbbox.r_xtop /= scaled;
locbbox.r_ytop /= scaled;
}
cellDef->cd_flags |= CDFIXEDBBOX;
if (propertyname[0] == 'F')
cellDef->cd_flags |= CDFIXEDBBOX;
proprec = (PropertyRecord *)mallocMagic(
sizeof(PropertyRecord) + 2 * sizeof(int));
@ -4090,20 +4092,32 @@ dbWritePropFunc(key, proprec, cdata)
int i;
char newvalue[20];
switch (proprec->prop_type)
/* In "compatibility" mode, always write "string" to the output.
* this has no adverse effects other than marginally slower
* read-in of .mag files with properties, but it keeps the .mag
* file format compatible with earlier versions of magic.
*/
if (DBPropCompat)
{
case PROPERTY_TYPE_STRING:
FPUTSR(f, "string ");
break;
case PROPERTY_TYPE_INTEGER:
FPUTSR(f, "integer ");
break;
case PROPERTY_TYPE_DIMENSION:
FPUTSR(f, "dimension ");
break;
case PROPERTY_TYPE_DOUBLE:
FPUTSR(f, "double ");
break;
FPUTSR(f, "string ");
}
else
{
switch (proprec->prop_type)
{
case PROPERTY_TYPE_STRING:
FPUTSR(f, "string ");
break;
case PROPERTY_TYPE_INTEGER:
FPUTSR(f, "integer ");
break;
case PROPERTY_TYPE_DIMENSION:
FPUTSR(f, "dimension ");
break;
case PROPERTY_TYPE_DOUBLE:
FPUTSR(f, "double ");
break;
}
}
FPUTSR(f, key);

View File

@ -32,6 +32,16 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include "database/database.h"
#include "utils/malloc.h"
/* Global variable */
bool DBPropCompat = TRUE; /* If TRUE, then always save properties to
* .mag files as type "string" for backwards
* compatibility. If FALSE, then properties
* are saved to the .mag file along with their
* type. Regardless of the setting, properties
* which are reserved keywords are converted
* to the best internal representation on input.
*/
/* ----------------------------------------------------------------------------
*

View File

@ -1046,6 +1046,7 @@ extern int DBLambda[2];
/* -------------------- Exported magic file suffix -------------------- */
extern char *DBSuffix; /* Suffix appended to all Magic cell names */
extern bool DBPropCompat; /* Backwards-compatible properties */
/* -------------------- User Interface Stuff -------------------------- */

View File

@ -25,7 +25,9 @@ Attach a "property" (string key and value pair) to the edit cell
<H3>Usage:</H3>
<BLOCKQUOTE>
<B>property</B> [<I>type</I>] [<I>key</I> [<I>value</I>]] <BR><BR>
<B>property</B> [<I>type</I>] [<I>key</I> [<I>value</I>]] <BR>
or
<B>property</B> [<B>compat</B>] [<B>true</B>|<B>false</B>] <BR><BR>
<BLOCKQUOTE>
where <I>key</I> and <I>value</I> are any text strings. <BR>
<I>type</I> may be one of <B>string</B>, <B>integer</B>,
@ -52,7 +54,16 @@ Attach a "property" (string key and value pair) to the edit cell
By default, properties are interpreted as verbatim string values,
with exceptions for the reserved types (see below). To force the
values of the property to be interpreted as a specific type, use
the <I>type</I> option.
the <I>type</I> option. <P>
The <B>property compat</B> setting determines how properties are
written out to a .mag file. The default setting is <B>true</B>
(backwards compatibility mode), which writes all properties as
type "<TT>string</TT>". Properties which are reserved names
(see below) will be converted to the best type when reading the
.mag file. However, if the user wants to create a property that
is handled differently than a string (namely, to be a dimensional
value that scales), then comptability mode should be turned off. <P>
</BLOCKQUOTE>
<BLOCKQUOTE>