mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 22:31:05 +00:00
[util] Store source line in plist items
The first line of the parsed item is stored and can be retrieved using PL_Line. Line numbers not stored for dictionary keys yet. Will be 0 for any items generated by code rather than parsed from a file or string.
This commit is contained in:
parent
12a35f3912
commit
f6ea9e4d87
2 changed files with 27 additions and 5 deletions
|
@ -77,6 +77,14 @@ char *PL_WritePropertyList (plitem_t *pl);
|
|||
*/
|
||||
pltype_t PL_Type (plitem_t *item) __attribute__((pure));
|
||||
|
||||
/** Retrieve the line number of an object.
|
||||
|
||||
\param item The object
|
||||
\return the line number on which the object began, or 0 if not from a
|
||||
string
|
||||
*/
|
||||
int PL_Line (plitem_t *item) __attribute__((pure));
|
||||
|
||||
/** Retrieve a string from a string object.
|
||||
|
||||
\param string The string object
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
*/
|
||||
struct plitem_s {
|
||||
pltype_t type;
|
||||
int line;
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
@ -176,17 +177,18 @@ PL_NewData (void *data, size_t size)
|
|||
}
|
||||
|
||||
static plitem_t *
|
||||
new_string (char *str)
|
||||
new_string (char *str, int line)
|
||||
{
|
||||
plitem_t *item = PL_NewItem (QFString);
|
||||
item->data = str;
|
||||
item->line = line;
|
||||
return item;
|
||||
}
|
||||
|
||||
VISIBLE plitem_t *
|
||||
PL_NewString (const char *str)
|
||||
{
|
||||
return new_string (strdup (str));
|
||||
return new_string (strdup (str), 0);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
|
@ -688,6 +690,7 @@ PL_ParsePropertyListItem (pldata_t *pl)
|
|||
case '{':
|
||||
{
|
||||
item = PL_NewDictionary ();
|
||||
item->line = pl->line;
|
||||
|
||||
pl->pos++;
|
||||
|
||||
|
@ -767,6 +770,7 @@ PL_ParsePropertyListItem (pldata_t *pl)
|
|||
|
||||
case '(': {
|
||||
item = PL_NewArray ();
|
||||
item->line = pl->line;
|
||||
|
||||
pl->pos++;
|
||||
|
||||
|
@ -812,27 +816,31 @@ PL_ParsePropertyListItem (pldata_t *pl)
|
|||
if (!str) {
|
||||
return NULL;
|
||||
} else {
|
||||
return PL_NewData (str, len);
|
||||
item = PL_NewData (str, len);
|
||||
item->line = pl->line;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
case '"': {
|
||||
int line = pl->line;
|
||||
char *str = PL_ParseQuotedString (pl);
|
||||
|
||||
if (!str) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new_string (str);
|
||||
return new_string (str, line);
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
int line = pl->line;
|
||||
char *str = PL_ParseUnquotedString (pl);
|
||||
|
||||
if (!str) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new_string (str);
|
||||
return new_string (str, line);
|
||||
}
|
||||
}
|
||||
} // switch
|
||||
|
@ -1038,3 +1046,9 @@ PL_Type (plitem_t *item)
|
|||
{
|
||||
return item->type;
|
||||
}
|
||||
|
||||
VISIBLE int
|
||||
PL_Line (plitem_t *item)
|
||||
{
|
||||
return item->line;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue