mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-21 19:21:47 +00:00
Allow pragmas to have arguments
It does mean only one pragma per line, but that's not such a big deal.
This commit is contained in:
parent
91f5023681
commit
7bfa0f7a92
3 changed files with 65 additions and 12 deletions
|
@ -35,7 +35,8 @@
|
||||||
*/
|
*/
|
||||||
///@{
|
///@{
|
||||||
|
|
||||||
void pragma (const char *id);
|
void pragma_process (void);
|
||||||
|
void pragma_add_arg (const char *id);
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,25 @@
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/alloc.h"
|
||||||
#include "QF/pr_comp.h"
|
#include "QF/pr_comp.h"
|
||||||
|
|
||||||
#include "diagnostic.h"
|
#include "diagnostic.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "pragma.h"
|
#include "pragma.h"
|
||||||
|
#include "strpool.h"
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
|
|
||||||
|
typedef struct pragma_arg_s {
|
||||||
|
struct pragma_arg_s *next;
|
||||||
|
const char *arg;
|
||||||
|
} pragma_arg_t;
|
||||||
|
|
||||||
|
static pragma_arg_t *pragma_args_freelist;
|
||||||
|
static pragma_arg_t *pragma_args;
|
||||||
|
static pragma_arg_t **pragma_args_tail = &pragma_args;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_traditional (int traditional)
|
set_traditional (int traditional)
|
||||||
{
|
{
|
||||||
|
@ -73,20 +84,58 @@ set_traditional (int traditional)
|
||||||
opcode_init (); // reset the opcode table
|
opcode_init (); // reset the opcode table
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
pragma (const char *id)
|
set_bug (pragma_arg_t *args)
|
||||||
{
|
{
|
||||||
|
if (!args) {
|
||||||
|
warning (0, "missing bug flag");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const char *flag = args->arg;
|
||||||
|
if (!strcmp (flag, "none")) {
|
||||||
|
options.bug.silent = true;
|
||||||
|
} else if (!strcmp (flag, "!none")) {
|
||||||
|
options.bug.silent = false;
|
||||||
|
} else if (!strcmp (flag, "die")) {
|
||||||
|
options.bug.promote = true;
|
||||||
|
} else if (!strcmp (flag, "!die")) {
|
||||||
|
options.bug.promote = false;
|
||||||
|
}
|
||||||
|
if (args->next) {
|
||||||
|
warning (0, "pragma bug: ignoring extra arguments");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pragma_process ()
|
||||||
|
{
|
||||||
|
if (!pragma_args) {
|
||||||
|
warning (0, "empty pragma");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const char *id = pragma_args->arg;
|
||||||
if (!strcmp (id, "traditional")) {
|
if (!strcmp (id, "traditional")) {
|
||||||
set_traditional (2);
|
set_traditional (2);
|
||||||
return;
|
} else if (!strcmp (id, "extended")) {
|
||||||
}
|
|
||||||
if (!strcmp (id, "extended")) {
|
|
||||||
set_traditional (1);
|
set_traditional (1);
|
||||||
return;
|
} else if (!strcmp (id, "advanced")) {
|
||||||
}
|
|
||||||
if (!strcmp (id, "advanced")) {
|
|
||||||
set_traditional (0);
|
set_traditional (0);
|
||||||
return;
|
} else if (!strcmp (id, "bug")) {
|
||||||
|
set_bug (pragma_args->next);
|
||||||
|
} else {
|
||||||
|
warning (0, "unknown pragma: '%s'", id);
|
||||||
}
|
}
|
||||||
warning (0, "unknown pragma: %s", id);
|
*pragma_args_tail = pragma_args_freelist;
|
||||||
|
pragma_args_tail = &pragma_args;
|
||||||
|
pragma_args = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pragma_add_arg (const char *id)
|
||||||
|
{
|
||||||
|
pragma_arg_t *arg;
|
||||||
|
ALLOC (16, pragma_arg_t, pragma_args, arg);
|
||||||
|
arg->arg = save_string (id);
|
||||||
|
*pragma_args_tail = arg;
|
||||||
|
pragma_args_tail = &arg->next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,9 +272,12 @@ STRING \"(\\.|[^"\\])*\"
|
||||||
write_frame_macros (s);
|
write_frame_macros (s);
|
||||||
BEGIN (GRAB_OTHER); // ignore rest of line
|
BEGIN (GRAB_OTHER); // ignore rest of line
|
||||||
}
|
}
|
||||||
<PRAGMA>{ID} { pragma (yytext); }
|
<PRAGMA>{ID} { pragma_add_arg (yytext); }
|
||||||
|
|
||||||
<*>\r*\n {
|
<*>\r*\n {
|
||||||
|
if (YY_START == PRAGMA) {
|
||||||
|
pragma_process ();
|
||||||
|
}
|
||||||
pr.source_line++;
|
pr.source_line++;
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue