From 37a64e59abc15fedebb07a46ff7f9818b7239176 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sat, 29 Nov 2003 02:01:31 +0000 Subject: [PATCH] Change some error names, mark a few things static that should be. Instead of using a colon to specify a parent class in a GIB class definition, "extends" is now used. If no parent class is specified, it now defaults to Object. --- include/QF/gib.h | 2 +- libs/gib/gib_builtin.c | 59 ++++++++++++++++++++++++++-------------- libs/gib/gib_classes.c | 20 +++++++------- libs/gib/gib_execute.c | 2 +- libs/gib/gib_semantics.c | 4 +-- 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/include/QF/gib.h b/include/QF/gib.h index 255034ca1..8e5f3e921 100644 --- a/include/QF/gib.h +++ b/include/QF/gib.h @@ -178,7 +178,7 @@ extern char gib_null_string[]; #define GIB_Argd(x) ((x) < cbuf_active->args->argc ? cbuf_active->args->argv[(x)] : NULL) #define GIB_Argm(x) ((x) < cbuf_active->args->argc ? (gib_tree_t *)cbuf_active->args->argm[(x)] : NULL) -#define GIB_USAGE(x) (GIB_Error ("syntax", "%s: invalid syntax\nusage: %s %s", GIB_Argv(0), GIB_Argv(0), (x))) +#define GIB_USAGE(x) (GIB_Error ("SyntaxError", "%s: invalid syntax\nusage: %s %s", GIB_Argv(0), GIB_Argv(0), (x))) #define GIB_CanReturn() (GIB_DATA(cbuf_active)->waitret) diff --git a/libs/gib/gib_builtin.c b/libs/gib/gib_builtin.c index 092d2e808..5af853ca4 100644 --- a/libs/gib/gib_builtin.c +++ b/libs/gib/gib_builtin.c @@ -187,7 +187,7 @@ GIB_Function_f (void) if (!(program = GIB_Parse_Lines (GIB_Argv (GIB_Argc()-1), 0))) { // Error! - GIB_Error ("parse", "Parse error while defining function '%s'.", + GIB_Error ("ParseError", "Parse error while defining function '%s'.", GIB_Argv (1)); return; } @@ -394,11 +394,11 @@ GIB_Function_Export_f (void) GIB_USAGE ("function1 [function2 function3 ...]"); for (i = 1; i < GIB_Argc (); i++) { if (!(f = GIB_Function_Find (GIB_Argv (i)))) - GIB_Error ("function", "%s: function '%s' not found.", GIB_Argv (0), + GIB_Error ("UnknownFunctionError", "%s: function '%s' not found.", GIB_Argv (0), GIB_Argv (i)); else if (!f->exported) { if (Cmd_Exists (f->name)) { - GIB_Error ("export", + GIB_Error ("NameConflictError", "%s: A console command with the name '%s' already exists.", GIB_Argv (0), GIB_Argv (i)); return; @@ -570,7 +570,7 @@ GIB_Regex_Match_f (void) GIB_Regex_Compile (GIB_Argv (2), REG_EXTENDED | GIB_Regex_Translate_Options (GIB_Argv (3))))) - GIB_Error ("regex", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); + GIB_Error ("RegexError", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); else if (regexec (reg, GIB_Argv (1), 0, 0, GIB_Regex_Translate_Runtime_Options (GIB_Argv (3)))) GIB_Return ("0"); else @@ -597,7 +597,7 @@ GIB_Regex_Replace_f (void) GIB_Regex_Compile (GIB_Argv (2), REG_EXTENDED | GIB_Regex_Translate_Options (GIB_Argv (3))))) - GIB_Error ("regex", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); + GIB_Error ("RegexError", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); else if (strchr (GIB_Argv (3), 'g')) while (!regexec (reg, GIB_Argv (1) + ofs, 10, match, ofs > 0 ? REG_NOTBOL : 0) @@ -629,7 +629,7 @@ GIB_Regex_Extract_f (void) GIB_Regex_Compile (GIB_Argv (2), REG_EXTENDED | GIB_Regex_Translate_Options (GIB_Argv (3))))) - GIB_Error ("regex", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); + GIB_Error ("RegexError", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); else if (!regexec (reg, GIB_Argv (1), 32, match, GIB_Regex_Translate_Runtime_Options (GIB_Argv (3))) && match[0].rm_eo) { dsprintf (GIB_Return (0), "%lu", (unsigned long) match[0].rm_eo); for (i = 0; i < 32; i++) { @@ -742,9 +742,9 @@ GIB_Event_Register_f (void) if (GIB_Argc () != 3) GIB_USAGE ("event function"); else if (!(func = GIB_Function_Find (GIB_Argv (2))) && GIB_Argv (2)[0]) - GIB_Error ("function", "Function %s not found.", GIB_Argv (2)); + GIB_Error ("UnknownFunctionError", "Function %s not found.", GIB_Argv (2)); else if (GIB_Event_Register (GIB_Argv (1), func)) - GIB_Error ("event", "Event %s not found.", GIB_Argv (1)); + GIB_Error ("UnknownEventError", "Event %s not found.", GIB_Argv (1)); } /* File access */ @@ -792,7 +792,7 @@ GIB_File_Read_f (void) return; } if (!*GIB_Argv (1)) { - GIB_Error ("file", "%s: null filename provided", GIB_Argv (0)); + GIB_Error ("FileAccessError", "%s: null filename provided", GIB_Argv (0)); return; } @@ -808,7 +808,7 @@ GIB_File_Read_f (void) ret->str[len] = 0; Qclose (file); } else { - GIB_Error ("file", + GIB_Error ("FileAccessError", "%s: could not read %s: %s", GIB_Argv (0), path, strerror (errno)); return; @@ -825,7 +825,7 @@ GIB_File_Write_f (void) return; } if (!*GIB_Argv (1)) { - GIB_Error ("file", "%s: null filename provided", GIB_Argv (0)); + GIB_Error ("InvalidArgumentError", "%s: null filename provided", GIB_Argv (0)); return; } @@ -847,7 +847,7 @@ GIB_File_Find_f (void) return; } if (GIB_File_Transform_Path (GIB_Argd (1))) { - GIB_Error ("access", + GIB_Error ("FileAccessError", "%s: access to %s denied", GIB_Argv (0), GIB_Argv (1)); return; } @@ -882,19 +882,19 @@ GIB_File_Move_f (void) return; } if (GIB_File_Transform_Path (GIB_Argd (1))) { - GIB_Error ("access", + GIB_Error ("FileAccessError", "%s: access to %s denied", GIB_Argv (0), GIB_Argv (1)); return; } if (GIB_File_Transform_Path (GIB_Argd (2))) { - GIB_Error ("access", + GIB_Error ("FileAccessError", "%s: access to %s denied", GIB_Argv (0), GIB_Argv (2)); return; } path1 = GIB_Argv (1); path2 = GIB_Argv (2); if (QFS_Rename (path1, path2)) - GIB_Error ("file", "%s: could not move %s to %s: %s", GIB_Argv (0), + GIB_Error ("FileAccessError", "%s: could not move %s to %s: %s", GIB_Argv (0), path1, path2, strerror (errno)); } @@ -908,13 +908,13 @@ GIB_File_Delete_f (void) return; } if (GIB_File_Transform_Path (GIB_Argd (1))) { - GIB_Error ("access", + GIB_Error ("FileAccessError", "%s: access to %s denied", GIB_Argv (0), GIB_Argv (1)); return; } path = GIB_Argv (1); if (QFS_Remove (path)) - GIB_Error ("file", "%s: could not delete %s: %s", GIB_Argv (0), path, + GIB_Error ("FileAccessError", "%s: could not delete %s: %s", GIB_Argv (0), path, strerror (errno)); } @@ -955,12 +955,15 @@ GIB_Print_f (void) static void GIB_Class_f (void) { - if (GIB_Argc () == 5) + if (GIB_Object_Get (GIB_Argv(1))) { + GIB_Error ("ClassRedefinitionError", + "Class '%s' already exists", GIB_Argv(1)); + } else if (GIB_Argc () == 5) GIB_Classes_Build_Scripted (GIB_Argv(1), GIB_Argv(3), GIB_Argm (4)->children, GIB_DATA(cbuf_active)->script); else - GIB_Classes_Build_Scripted (GIB_Argv(1), NULL, + GIB_Classes_Build_Scripted (GIB_Argv(1), "Object", GIB_Argm (2)->children, GIB_DATA(cbuf_active)->script); } @@ -972,7 +975,7 @@ GIB_Emit_f (void) GIB_USAGE ("signal [arg1 arg2 ...]"); return; } else if (!GIB_DATA(cbuf_active)->reply.obj) { - GIB_Error ("emit", "Cannot emit signal in this context."); + GIB_Error ("InvalidContextError", "Cannot emit signal in this context."); return; } else { int i; @@ -1007,6 +1010,22 @@ GIB_Error_f (void) GIB_Error (GIB_Argv(1), "%s", GIB_Argv(2)); } +/* +static void +GIB_New_f (void) +{ + GIB_Object_t *classobj; + if (GIB_Argc() < 2) { + GIB_USAGE ("classname"); + } else if ( + !(class = GIB_Object_Get(GIB_Argv(1))) + || classobj->class->classobj != classobj) { + GIB_Error ("UnknownClassError", "Class '%s' does not exist", + GIB_Argv(1)); + } else { + GIB_Send (classobj, +*/ + static void GIB_bp1_f (void) { diff --git a/libs/gib/gib_classes.c b/libs/gib/gib_classes.c index 736ac5c4b..4ae54524f 100644 --- a/libs/gib/gib_classes.c +++ b/libs/gib/gib_classes.c @@ -226,7 +226,7 @@ Object_Destruct (void *data) return; } -gib_methodtab_t Object_methods[] = { +static gib_methodtab_t Object_methods[] = { {"retain", Object_Retain_f, NULL}, {"release", Object_Release_f, NULL}, {"init", Object_Init_f, NULL}, @@ -239,7 +239,7 @@ gib_methodtab_t Object_methods[] = { {NULL, NULL, NULL} }; -gib_methodtab_t Object_class_methods[] = { +static gib_methodtab_t Object_class_methods[] = { {"parent", Object_SuperClass_f, NULL}, {"children", Object_Class_Children_f, NULL}, {"new", Object_Class_New_f, NULL}, @@ -248,7 +248,7 @@ gib_methodtab_t Object_class_methods[] = { {NULL, NULL, NULL} }; -gib_classdesc_t Object_class = { +static gib_classdesc_t Object_class = { "Object", NULL, Object_Construct, NULL, Object_Destruct, @@ -335,16 +335,16 @@ Thread_Destruct (void *data) free (t); } -gib_methodtab_t Thread_methods[] = { +static gib_methodtab_t Thread_methods[] = { {"init", Thread_Init_f, NULL}, {NULL, NULL, NULL} }; -gib_methodtab_t Thread_class_methods[] = { +static gib_methodtab_t Thread_class_methods[] = { {NULL, NULL, NULL} }; -gib_classdesc_t Thread_class = { +static gib_classdesc_t Thread_class = { "Thread", "Object", Thread_Construct, NULL, Thread_Destruct, @@ -352,7 +352,7 @@ gib_classdesc_t Thread_class = { }; /* - Object hash class + Object Hash class Stores references to objects in a Hash */ @@ -489,18 +489,18 @@ ObjectHash_Remove_f (gib_object_t *obj, gib_method_t *method, void *data, return 0; } -gib_methodtab_t ObjectHash_methods[] = { +static gib_methodtab_t ObjectHash_methods[] = { {"insert", ObjectHash_Insert_f, NULL}, {"get", ObjectHash_Get_f, NULL}, {"remove", ObjectHash_Remove_f, NULL}, {NULL, NULL, NULL} }; -gib_methodtab_t ObjectHash_class_methods[] = { +static gib_methodtab_t ObjectHash_class_methods[] = { {NULL, NULL, NULL} }; -gib_classdesc_t ObjectHash_class = { +static gib_classdesc_t ObjectHash_class = { "ObjectHash", "Object", ObjectHash_Construct, NULL, ObjectHash_Destruct, diff --git a/libs/gib/gib_execute.c b/libs/gib/gib_execute.c index 1e3e27abc..89b80ae34 100644 --- a/libs/gib/gib_execute.c +++ b/libs/gib/gib_execute.c @@ -352,7 +352,7 @@ GIB_Execute (cbuf_t * cbuf) GIB_Execute_Generate_Composite (cbuf); if (Cmd_Command (cbuf->args)) GIB_Error ( - "command", + "UnknownCommandError", "No builtin, function, or console command " "named '%s' was found.", cbuf->args->argv[0]->str diff --git a/libs/gib/gib_semantics.c b/libs/gib/gib_semantics.c index 69b6472be..3a0169dce 100644 --- a/libs/gib/gib_semantics.c +++ b/libs/gib/gib_semantics.c @@ -42,13 +42,13 @@ GIB_Semantic_Validate_Class (gib_tree_t * tokens) if (!tokens->next || !tokens->next->next) { GIB_Parse_Error ("Malformed class definition; expected class " - "name, optional colon and parent class, and " + "name, optional 'extends' and parent class, and " "program block.", tokens->start); return -1; } if (tokens->next->next->delim == ' ' && !strcmp - (tokens->next->next->str, ":")) { + (tokens->next->next->str, "extends")) { if (!tokens->next->next->next) { GIB_Parse_Error ("Malformed class definition; " "expected parent class after "