From 9ab7b77dc45ac6f9e9bf7e0bad3cc5e6a0aa091e Mon Sep 17 00:00:00 2001 From: "R. Timothy Edwards" Date: Wed, 18 Feb 2026 16:17:03 -0500 Subject: [PATCH] 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. --- commands/CmdLQ.c | 47 ++++++++++++++++++++++++++++++++++++++---- database/DBio.c | 44 +++++++++++++++++++++++++-------------- database/DBprop.c | 10 +++++++++ database/database.h.in | 1 + doc/html/property.html | 15 ++++++++++++-- 5 files changed, 96 insertions(+), 21 deletions(-) diff --git a/commands/CmdLQ.c b/commands/CmdLQ.c index f815f6c5..a67bd2ed 100644 --- a/commands/CmdLQ.c +++ b/commands/CmdLQ.c @@ -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 diff --git a/database/DBio.c b/database/DBio.c index 3ac62654..f30c4546 100644 --- a/database/DBio.c +++ b/database/DBio.c @@ -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); diff --git a/database/DBprop.c b/database/DBprop.c index 5be3c6ca..f44ffecc 100644 --- a/database/DBprop.c +++ b/database/DBprop.c @@ -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. + */ /* ---------------------------------------------------------------------------- * diff --git a/database/database.h.in b/database/database.h.in index 07742730..45939459 100644 --- a/database/database.h.in +++ b/database/database.h.in @@ -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 -------------------------- */ diff --git a/doc/html/property.html b/doc/html/property.html index 4f4c0348..c7277e9f 100644 --- a/doc/html/property.html +++ b/doc/html/property.html @@ -25,7 +25,9 @@ Attach a "property" (string key and value pair) to the edit cell

Usage:

- property [type] [key [value]]

+ property [type] [key [value]]
+ or + property [compat] [true|false]

where key and value are any text strings.
type may be one of string, integer, @@ -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 type option. + the type option.

+ + The property compat setting determines how properties are + written out to a .mag file. The default setting is true + (backwards compatibility mode), which writes all properties as + type "string". 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.