diff options
author | Paweł Kołodziejski | 2004-05-01 06:35:06 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2004-05-01 06:35:06 +0000 |
commit | e8cb50e17fc15270ee493f8c1b1623c20e47071e (patch) | |
tree | 9de6ce2f4cf71468b4097978b7972765bcd0bfb4 | |
parent | 1ecf43aabeeed953b1c7a16eb715ac155398171d (diff) | |
download | scummvm-rg350-e8cb50e17fc15270ee493f8c1b1623c20e47071e.tar.gz scummvm-rg350-e8cb50e17fc15270ee493f8c1b1623c20e47071e.tar.bz2 scummvm-rg350-e8cb50e17fc15270ee493f8c1b1623c20e47071e.zip |
indent
svn-id: r13690
-rw-r--r-- | saga/console.cpp | 171 | ||||
-rw-r--r-- | saga/console.h | 27 | ||||
-rw-r--r-- | saga/console_mod.h | 12 | ||||
-rw-r--r-- | saga/cvar.cpp | 246 | ||||
-rw-r--r-- | saga/cvar.h | 20 | ||||
-rw-r--r-- | saga/cvar_mod.h | 54 |
6 files changed, 121 insertions, 409 deletions
diff --git a/saga/console.cpp b/saga/console.cpp index de4b66af12..d001846664 100644 --- a/saga/console.cpp +++ b/saga/console.cpp @@ -20,34 +20,22 @@ * $Header$ * */ -/* - Description: - - Console module - Notes: -*/ +// Console module #include "reinherit.h" -/* - Uses the following modules: -\*--------------------------------------------------------------------------*/ #include "font_mod.h" #include "cvar_mod.h" #include "events_mod.h" #include "gfx_mod.h" -/* - Begin module -\*--------------------------------------------------------------------------*/ #include "console_mod.h" #include "console.h" namespace Saga { static R_CONSOLEINFO ConInfo = { - 0, R_CON_DEFAULTPOS, R_CON_DEFAULTLINES, @@ -67,31 +55,19 @@ static R_CON_SCROLLBACK ConHistory; static int CV_ConResize = R_CON_DEFAULTPOS; static int CV_ConDroptime = R_CON_DROPTIME; -int CON_Register(void) -{ - - CVAR_Register_I(&CV_ConResize, "con_h", - NULL, R_CVAR_NONE, 12, R_CON_DEFAULTPOS); - - CVAR_Register_I(&CV_ConDroptime, "con_droptime", - NULL, R_CVAR_NONE, 0, 5000); - - CVAR_Register_I(&ConInfo.line_max, "con_lines", - NULL, R_CVAR_NONE, 5, 5000); - +int CON_Register() { + CVAR_Register_I(&CV_ConResize, "con_h", NULL, R_CVAR_NONE, 12, R_CON_DEFAULTPOS); + CVAR_Register_I(&CV_ConDroptime, "con_droptime", NULL, R_CVAR_NONE, 0, 5000); + CVAR_Register_I(&ConInfo.line_max, "con_lines", NULL, R_CVAR_NONE, 5, 5000); return R_SUCCESS; } -int CON_Init(void) -{ +int CON_Init() { return R_SUCCESS; } -int CON_Shutdown(void) -{ - - R_printf(R_STDOUT, - "CON_Shutdown(): Deleting console scrollback and command history.\n"); +int CON_Shutdown() { + R_printf(R_STDOUT, "CON_Shutdown(): Deleting console scrollback and command history.\n"); CON_DeleteScroll(&ConScrollback); CON_DeleteScroll(&ConHistory); @@ -99,8 +75,7 @@ int CON_Shutdown(void) return R_SUCCESS; } -int CON_Activate(void) -{ +int CON_Activate() { R_EVENT con_event; if (ConInfo.active) { @@ -120,8 +95,7 @@ int CON_Activate(void) return R_SUCCESS; } -int CON_Deactivate(void) -{ +int CON_Deactivate() { R_EVENT con_event; if (!ConInfo.active) { @@ -139,26 +113,20 @@ int CON_Deactivate(void) return R_SUCCESS; } -int CON_IsActive(void) -{ - +int CON_IsActive(void) { return ConInfo.active; } -int CON_Type(int in_char) -/****************************************************************************\ - Responsible for processing character input to the console and maintaining - the console input buffer. - Input buffer is processed by EXPR_Parse on enter. - High ASCII characters are ignored. -\****************************************************************************/ -{ - +// Responsible for processing character input to the console and maintaining +// the console input buffer. +// Input buffer is processed by EXPR_Parse on enter. +// High ASCII characters are ignored. +int CON_Type(int in_char) { int input_pos = ConInfo.input_pos; const char *expr; int expr_len; int result; - /*char *lvalue; */ + //char *lvalue; char *rvalue = NULL; R_CVAR_P con_cvar = NULL; @@ -167,27 +135,22 @@ int CON_Type(int in_char) const char *err_str; if (ConInfo.y_pos != ConInfo.y_max) { - /* Ignore keypress until console fully down */ + // Ignore keypress until console fully down return R_SUCCESS; } if ((in_char > 127) || (!in_char)) { - /* Ignore non-ascii codes */ + // Ignore non-ascii codes return R_SUCCESS; } switch (in_char) { - case '\r': - expr = ConInfo.input_buf; CON_Print("> %s", ConInfo.input_buf); - expr_len = strlen(ConInfo.input_buf); result = EXPR_Parse(&expr, &expr_len, &con_cvar, &rvalue); - CON_AddLine(&ConHistory, ConInfo.hist_max, ConInfo.input_buf); - memset(ConInfo.input_buf, 0, R_CON_INPUTBUF_LEN); ConInfo.input_pos = 0; ConInfo.hist_pos = 0; @@ -208,18 +171,14 @@ int CON_Type(int in_char) CVAR_GetError(&err_str); CON_Print("Illegal assignment: %s.", err_str); } - break; - case '\b': ConInfo.input_buf[input_pos] = 0; - if (input_pos > 0) { ConInfo.input_pos--; ConInfo.input_buf[ConInfo.input_pos] = 0; } break; - default: if (input_pos < R_CON_INPUTBUF_LEN) { ConInfo.input_buf[input_pos] = (char)in_char; @@ -234,19 +193,13 @@ int CON_Type(int in_char) return R_SUCCESS; } -int CON_Draw(R_SURFACE * ds) -{ - +int CON_Draw(R_SURFACE *ds) { int line_y; - R_CONSOLE_LINE *walk_ptr; R_CONSOLE_LINE *start_ptr; - int txt_fgcolor; int txt_shcolor; - R_RECT fill_rect; - int i; if (!ConInfo.active) { @@ -260,27 +213,18 @@ int CON_Draw(R_SURFACE * ds) fill_rect.top = 0; fill_rect.left = 0; - fill_rect.bottom = ConInfo.y_pos; fill_rect.right = ds->buf_w - 1; GFX_DrawRect(ds, &fill_rect, SYSGFX_MatchColor(R_CONSOLE_BGCOLOR)); - txt_fgcolor = SYSGFX_MatchColor(R_CONSOLE_TXTCOLOR); txt_shcolor = SYSGFX_MatchColor(R_CONSOLE_TXTSHADOW); - FONT_Draw(SMALL_FONT_ID, - ds, - ">", 1, - 2, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW); - - FONT_Draw(SMALL_FONT_ID, - ds, - ConInfo.input_buf, strlen(ConInfo.input_buf), - 10, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW); + FONT_Draw(SMALL_FONT_ID, ds, ">", 1, 2, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW); + FONT_Draw(SMALL_FONT_ID, ds, ConInfo.input_buf, strlen(ConInfo.input_buf), + 10, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW); line_y = ConInfo.y_pos - (R_CON_INPUT_H + R_CON_LINE_H); - start_ptr = ConScrollback.head; for (i = 0; i < ConInfo.line_pos; i++) { @@ -292,15 +236,8 @@ int CON_Draw(R_SURFACE * ds) } for (walk_ptr = start_ptr; walk_ptr; walk_ptr = walk_ptr->next) { - - FONT_Draw(SMALL_FONT_ID, - ds, - walk_ptr->str_p, - walk_ptr->str_len, - 2, line_y, txt_fgcolor, txt_shcolor, FONT_SHADOW); - + FONT_Draw(SMALL_FONT_ID, ds, walk_ptr->str_p, walk_ptr->str_len, 2, line_y, txt_fgcolor, txt_shcolor, FONT_SHADOW); line_y -= R_CON_LINE_H; - if (line_y < -R_CON_LINE_H) break; } @@ -308,29 +245,21 @@ int CON_Draw(R_SURFACE * ds) return R_SUCCESS; } -int CON_Print(const char *fmt_str, ...) -{ - +int CON_Print(const char *fmt_str, ...) { char vsstr_p[R_CON_PRINTFLIMIT + 1]; va_list argptr; int ret_val; va_start(argptr, fmt_str); - ret_val = vsprintf(vsstr_p, fmt_str, argptr); - CON_AddLine(&ConScrollback, ConInfo.line_max, vsstr_p); - va_end(argptr); - ConInfo.line_pos = 0; return ret_val; } -int CON_CmdUp(void) -{ - +int CON_CmdUp() { R_CONSOLE_LINE *start_ptr = ConHistory.head; int i; @@ -354,15 +283,12 @@ int CON_CmdUp(void) strcpy(ConInfo.input_buf, start_ptr->str_p); ConInfo.input_pos = start_ptr->str_len - 1; - R_printf(R_STDOUT, "History pos: %d/%d", ConInfo.hist_pos, - ConHistory.lines); + R_printf(R_STDOUT, "History pos: %d/%d", ConInfo.hist_pos, ConHistory.lines); return R_SUCCESS; } -int CON_CmdDown(void) -{ - +int CON_CmdDown(void) { R_CONSOLE_LINE *start_ptr = ConHistory.head; int i; @@ -396,11 +322,8 @@ int CON_CmdDown(void) return R_SUCCESS; } -int CON_PageUp(void) -{ - +int CON_PageUp() { int n_lines; - n_lines = (ConInfo.y_max - R_CON_INPUT_H) / R_CON_LINE_H; if (ConInfo.line_pos < (ConScrollback.lines - n_lines)) { @@ -408,15 +331,11 @@ int CON_PageUp(void) } R_printf(R_STDOUT, "Line pos: %d", ConInfo.line_pos); - return R_SUCCESS; } -int CON_PageDown(void) -{ - +int CON_PageDown() { int n_lines; - n_lines = (ConInfo.y_max - R_CON_INPUT_H) / R_CON_LINE_H; if (ConInfo.line_pos > n_lines) { @@ -428,9 +347,7 @@ int CON_PageDown(void) return R_SUCCESS; } -int CON_DropConsole(double percent) -{ - +int CON_DropConsole(double percent) { R_SURFACE *back_buf; if (percent > 1.0) { @@ -439,15 +356,12 @@ int CON_DropConsole(double percent) back_buf = SYSGFX_GetBackBuffer(); CON_SetDropPos(percent); - CON_Draw(back_buf); return R_SUCCESS; } -int CON_RaiseConsole(double percent) -{ - +int CON_RaiseConsole(double percent) { R_SURFACE *back_buf; if (percent >= 1.0) { @@ -456,17 +370,13 @@ int CON_RaiseConsole(double percent) } back_buf = SYSGFX_GetBackBuffer(); - CON_SetDropPos(1.0 - percent); - CON_Draw(back_buf); return R_SUCCESS; } -static int CON_SetDropPos(double percent) -{ - +static int CON_SetDropPos(double percent) { double exp_percent; if (percent > 1.0) @@ -475,16 +385,12 @@ static int CON_SetDropPos(double percent) percent = 0.0; exp_percent = percent * percent; - ConInfo.y_pos = (int)(ConInfo.y_max * exp_percent); return R_SUCCESS; } -static int -CON_AddLine(R_CON_SCROLLBACK * scroll, int line_max, const char *constr_p) -{ - +static int CON_AddLine(R_CON_SCROLLBACK *scroll, int line_max, const char *constr_p) { int constr_len; char *newstr_p; R_CONSOLE_LINE *newline_p; @@ -492,7 +398,6 @@ CON_AddLine(R_CON_SCROLLBACK * scroll, int line_max, const char *constr_p) int i; constr_len = strlen(constr_p) + 1; - newstr_p = (char *)malloc(constr_len); if (newstr_p == NULL) { return R_MEM; @@ -531,9 +436,7 @@ CON_AddLine(R_CON_SCROLLBACK * scroll, int line_max, const char *constr_p) return R_SUCCESS; } -static int CON_DeleteLine(R_CON_SCROLLBACK * scroll) -{ - +static int CON_DeleteLine(R_CON_SCROLLBACK *scroll) { R_CONSOLE_LINE *temp_p = scroll->tail; if (temp_p->prev == NULL) { @@ -552,9 +455,7 @@ static int CON_DeleteLine(R_CON_SCROLLBACK * scroll) return R_SUCCESS; } -static int CON_DeleteScroll(R_CON_SCROLLBACK * scroll) -{ - +static int CON_DeleteScroll(R_CON_SCROLLBACK * scroll) { R_CONSOLE_LINE *walk_ptr; R_CONSOLE_LINE *temp_ptr; diff --git a/saga/console.h b/saga/console.h index 02560edb80..c2fb5ad24c 100644 --- a/saga/console.h +++ b/saga/console.h @@ -20,13 +20,8 @@ * $Header$ * */ -/* - Description: - - Console module header file - Notes: -*/ + // Console module header file #ifndef SAGA_CONSOLE_H_ #define SAGA_CONSOLE_H_ @@ -40,7 +35,6 @@ namespace Saga { #define R_CONSOLE_TXTSHADOW 0x00202020UL struct R_CONSOLEINFO { - int active; int y_max; int line_max; @@ -52,33 +46,24 @@ struct R_CONSOLEINFO { int prompt_w; char input_buf[R_CON_INPUTBUF_LEN + 1]; int input_pos; - }; struct R_CONSOLE_LINE { - R_CONSOLE_LINE *next; R_CONSOLE_LINE *prev; char *str_p; int str_len; - }; struct R_CON_SCROLLBACK { - R_CONSOLE_LINE *head; R_CONSOLE_LINE *tail; int lines; - }; -static int -CON_AddLine(R_CON_SCROLLBACK * scroll, int line_max, const char *constr_p); - -static int CON_DeleteLine(R_CON_SCROLLBACK * scroll); - -static int CON_DeleteScroll(R_CON_SCROLLBACK * scroll); - +static int CON_AddLine(R_CON_SCROLLBACK *scroll, int line_max, const char *constr_p); +static int CON_DeleteLine(R_CON_SCROLLBACK *scroll); +static int CON_DeleteScroll(R_CON_SCROLLBACK *scroll); static int CON_SetDropPos(double percent); #define R_CON_DEFAULTPOS 136 @@ -91,6 +76,4 @@ static int CON_SetDropPos(double percent); } // End of namespace Saga -#endif /* R_CONSOLE_H_ */ - -/* end "r_console.h" */ +#endif diff --git a/saga/console_mod.h b/saga/console_mod.h index 62ec7efd48..3395c89b8c 100644 --- a/saga/console_mod.h +++ b/saga/console_mod.h @@ -20,13 +20,8 @@ * $Header$ * */ -/* - Description: - - Console module public header file - Notes: -*/ +// Console module public header file #ifndef SAGA_CONSOLE_MOD_H_ #define SAGA_CONSOLE_MOD_H_ @@ -42,7 +37,7 @@ int CON_Deactivate(void); int CON_IsActive(void); int CON_Type(int in_char); -int CON_Draw(R_SURFACE * ds); +int CON_Draw(R_SURFACE *ds); int CON_Print(const char *fmt_str, ...); int CON_CmdUp(void); @@ -55,5 +50,4 @@ int CON_RaiseConsole(double percent); } // End of namespace Saga -#endif /* R_CONSOLE_MOD_H_ */ -/* end "r_console_mod.h" */ +#endif diff --git a/saga/cvar.cpp b/saga/cvar.cpp index fddaddd8ee..6e7a4a2df0 100644 --- a/saga/cvar.cpp +++ b/saga/cvar.cpp @@ -20,27 +20,17 @@ * $Header$ * */ -/* - Description: - - Configuration Variable Module - Notes: -*/ +// Configuration Variable Module + #include "reinherit.h" #include <limits.h> #include <stddef.h> -/* - Uses the following modules: -\*--------------------------------------------------------------------------*/ #include "console_mod.h" -/* - Begin module -\*--------------------------------------------------------------------------*/ #include "cvar_mod.h" #include "cvar.h" @@ -49,7 +39,6 @@ namespace Saga { R_CVAR *CVHashTbl[R_CVAR_HASHLEN]; static const char *CVAR_ErrMsg[] = { - "No Error", "Not implememented.", "Memory allocation failed", @@ -65,7 +54,6 @@ static const char *CVAR_ErrMsg[] = { }; enum CVAR_Errors { - CVERR_NONE, CVERR_NOTIMPL, CVERR_MEM, @@ -82,23 +70,13 @@ enum CVAR_Errors { static enum CVAR_Errors CVAR_ErrorState; -int CVAR_GetError(const char **err_str) -/****************************************************************************\ - Returns the appropriate cvar error string -\****************************************************************************/ -{ - +//Returns the appropriate cvar error string +int CVAR_GetError(const char **err_str) { *err_str = CVAR_ErrMsg[CVAR_ErrorState]; - return CVAR_ErrorState; } - -int CVAR_Shutdown(void) -/****************************************************************************\ - Frees the cvar hash table -\****************************************************************************/ -{ - +// Frees the cvar hash table +int CVAR_Shutdown() { R_CVAR *walk_ptr; R_CVAR *temp_ptr; int i; @@ -106,9 +84,7 @@ int CVAR_Shutdown(void) R_printf(R_STDOUT, "CVAR_Shutdown(): Deleting cvar hash table.\n"); for (i = 0; i < R_CVAR_HASHLEN; i++) { - for (walk_ptr = CVHashTbl[i]; walk_ptr; walk_ptr = temp_ptr) { - temp_ptr = walk_ptr->next; free(walk_ptr); } @@ -117,13 +93,9 @@ int CVAR_Shutdown(void) return R_SUCCESS; } -unsigned int CVAR_HashString(const char *str) -/****************************************************************************\ - Returns hash index for string 'str'. - Cannot fail. -\****************************************************************************/ -{ - +// Returns hash index for string 'str'. +// Cannot fail. +unsigned int CVAR_HashString(const char *str) { unsigned int index; for (index = 0; *str != '\0'; str++) { @@ -133,13 +105,9 @@ unsigned int CVAR_HashString(const char *str) return index % R_CVAR_HASHLEN; } -int CVAR_Add(int index, R_CVAR * cvar) -/****************************************************************************\ - Adds a copy of the given cvar into the hash table. - Returns R_SUCCESS if cvar was added, R_MEM if allocation failed. -\****************************************************************************/ -{ - +// Adds a copy of the given cvar into the hash table. +// Returns R_SUCCESS if cvar was added, R_MEM if allocation failed. +int CVAR_Add(int index, R_CVAR *cvar) { R_CVAR *new_cvar; R_CVAR *temp_ptr; @@ -165,14 +133,10 @@ int CVAR_Add(int index, R_CVAR * cvar) return R_SUCCESS; } -int CVAR_Exec(R_CVAR_P cvar_func, char *r_value) -/****************************************************************************\ - Attempts to execute the specified console function with the given argument - string. - Returns R_FAILURE if cvar_func is not a valid console function -\****************************************************************************/ -{ - +// Attempts to execute the specified console function with the given argument +// string. +// Returns R_FAILURE if cvar_func is not a valid console function +int CVAR_Exec(R_CVAR_P cvar_func, char *r_value) { int cf_argc = 0; char **cf_argv = NULL; int max_args; @@ -199,7 +163,7 @@ int CVAR_Exec(R_CVAR_P cvar_func, char *r_value) return R_FAILURE; } - /* Call function */ + // Call function (cvar_func->t.func.func_p) (cf_argc, cf_argv); if (cf_argv) @@ -208,13 +172,9 @@ int CVAR_Exec(R_CVAR_P cvar_func, char *r_value) return R_SUCCESS; } -int CVAR_SetValue(R_CVAR_P cvar, char *r_value) -/****************************************************************************\ - Attempts to assign the value contained in the string 'r_value' to cvar. - Returns R_FAILURE if there was an error parsing 'r_value' -\****************************************************************************/ -{ - +// Attempts to assign the value contained in the string 'r_value' to cvar. +// Returns R_FAILURE if there was an error parsing 'r_value' +int CVAR_SetValue(R_CVAR_P cvar, char *r_value) { long int int_param; unsigned long uint16_param; @@ -230,44 +190,38 @@ int CVAR_SetValue(R_CVAR_P cvar, char *r_value) } switch (cvar->type) { - case R_CVAR_INT: - int_param = strtol(r_value, &end_p, 10); - if ((int_param == LONG_MIN) || (int_param == LONG_MAX)) { CVAR_ErrorState = CVERR_PARSEOVERFLOW; return R_FAILURE; } - scan_len = end_p - r_value; if (int_param == 0) { if (!scan_len || r_value[scan_len - 1] != '0') { - /* strtol() returned 0, but string isn't "0". Invalid. */ + // strtol() returned 0, but string isn't "0". Invalid. CVAR_ErrorState = CVERR_INVALID; return R_FAILURE; } } if (scan_len != r_value_len) { - /* Entire string wasn't converted...Invalid */ + // Entire string wasn't converted...Invalid CVAR_ErrorState = CVERR_INVALID; return R_FAILURE; } if ((int_param < CV_INTMIN) || (int_param > CV_INTMAX)) { - /* Overflows destination type */ + // Overflows destination type CVAR_ErrorState = CVERR_DESTOVERFLOW; return R_FAILURE; } - /* Ignore bounds if equal */ + // Ignore bounds if equal if (cvar->t.i.lbound != cvar->t.i.ubound) { - - if ((int_param < cvar->t.i.lbound) || - (int_param > cvar->t.i.ubound)) { - /* Value is outside of cvar bounds */ + if ((int_param < cvar->t.i.lbound) || (int_param > cvar->t.i.ubound)) { + // Value is outside of cvar bounds CVAR_ErrorState = CVERR_BOUND; return R_FAILURE; } @@ -280,76 +234,62 @@ int CVAR_SetValue(R_CVAR_P cvar, char *r_value) #endif break; - case R_CVAR_UINT: - if (*r_value == '-') { CVAR_ErrorState = CVERR_SIGN; return R_FAILURE; } uint16_param = strtoul(r_value, &end_p, 10); - if (uint16_param == ULONG_MAX) { CVAR_ErrorState = CVERR_PARSEOVERFLOW; return R_FAILURE; } scan_len = end_p - r_value; - if (uint16_param == 0) { - if (!scan_len || r_value[scan_len - 1] != '0') { - /* strtol() returned 0, but string isn't "0". Invalid. */ + // strtol() returned 0, but string isn't "0". Invalid. CVAR_ErrorState = CVERR_INVALID; return R_FAILURE; } } if (scan_len != r_value_len) { - /* Entire string wasn't converted...Invalid */ + // Entire string wasn't converted...Invalid CVAR_ErrorState = CVERR_INVALID; return R_FAILURE; } if (uint16_param > CV_UINTMAX) { - /* Overflows destination type */ + // Overflows destination type CVAR_ErrorState = CVERR_DESTOVERFLOW; return R_FAILURE; } - /* Ignore bounds if equal */ + // Ignore bounds if equal if (cvar->t.ui.lbound != cvar->t.ui.ubound) { - - if ((uint16_param < cvar->t.ui.lbound) || - (uint16_param > cvar->t.ui.ubound)) { - /* Value is outside cvar bounds */ + if ((uint16_param < cvar->t.ui.lbound) || (uint16_param > cvar->t.ui.ubound)) { + // Value is outside cvar bounds CVAR_ErrorState = CVERR_BOUND; return R_FAILURE; } } *(cvar->t.ui.var_p) = (cv_uint16_t) uint16_param; - #ifdef R_CVAR_TRACE printf("Set cvar to value %lu.\n", uint16_param); #endif - break; - case R_CVAR_FLOAT: - CVAR_ErrorState = CVERR_NOTIMPL; return R_FAILURE; break; - case R_CVAR_STRING: - if (strrchr(r_value, '\"') != NULL) { CVAR_ErrorState = CVERR_STRING; return R_FAILURE; } - strncpy(cvar->t.s.var_str, r_value, cvar->t.s.ubound); if (cvar->t.s.ubound < r_value_len) { cvar->t.s.var_str[cvar->t.s.ubound] = 0; @@ -357,69 +297,48 @@ int CVAR_SetValue(R_CVAR_P cvar, char *r_value) #ifdef R_CVAR_TRACE printf("Set cvar to value \"%s\".\n", cvar->t.s.var_str); #endif - break; - default: - CVAR_ErrorState = CVERR_TYPE; return R_FAILURE; break; } - CVAR_ErrorState = CVERR_NONE; return R_SUCCESS; } -R_CVAR_P CVAR_Find(const char *var_str) -/****************************************************************************\ - Given a cvar name this function returns a pointer to the appropriate - cvar structure or NULL if no match was found. -\****************************************************************************/ -{ - +// Given a cvar name this function returns a pointer to the appropriate +// cvar structure or NULL if no match was found. +R_CVAR_P CVAR_Find(const char *var_str) { R_CVAR *walk_ptr; int hash; hash = CVAR_HashString(var_str); - #ifdef R_CVAR_TRACE printf("Performing lookup on hash bucket %d.\n", hash); #endif - walk_ptr = CVHashTbl[hash]; - while (walk_ptr != NULL) { - if (strcmp(var_str, walk_ptr->name) == 0) { return walk_ptr; } - walk_ptr = walk_ptr->next; } return NULL; } -int CVAR_IsFunc(R_CVAR_P cvar_func) -{ - +int CVAR_IsFunc(R_CVAR_P cvar_func) { if (cvar_func->type == R_CVAR_FUNC) return 1; else return 0; } -int -CVAR_RegisterFunc(cv_func_t func, - const char *func_name, - const char *func_argstr, uint16 flags, int min_args, int max_args) -/****************************************************************************\ - Registers a console function 'cvar' - (could think of a better place to put these...?) -\****************************************************************************/ -{ - +// Registers a console function 'cvar' +// (could think of a better place to put these...?) +int CVAR_RegisterFunc(cv_func_t func, const char *func_name, + const char *func_argstr, uint16 flags, int min_args, int max_args) { R_CVAR new_cvar; int hash; @@ -427,7 +346,6 @@ CVAR_RegisterFunc(cv_func_t func, new_cvar.type = R_CVAR_FUNC; new_cvar.section = NULL; new_cvar.flags = flags; - new_cvar.t.func.func_p = func; new_cvar.t.func.func_argstr = func_argstr; new_cvar.t.func.min_args = min_args; @@ -441,14 +359,9 @@ CVAR_RegisterFunc(cv_func_t func, return CVAR_Add(hash, &new_cvar); } -int -CVAR_Register_I(cv_int_t * var_p, - const char *var_name, - const char *section, uint16 flags, cv_int_t lbound, cv_int_t ubound) -/****************************************************************************\ - Registers an integer type cvar. -\****************************************************************************/ -{ +// Registers an integer type cvar. +int CVAR_Register_I(cv_int_t * var_p, const char *var_name, + const char *section, uint16 flags, cv_int_t lbound, cv_int_t ubound) { R_CVAR new_cvar; int hash; @@ -457,12 +370,9 @@ CVAR_Register_I(cv_int_t * var_p, new_cvar.type = R_CVAR_INT; new_cvar.section = section; new_cvar.flags = flags; - new_cvar.t.i.var_p = var_p; - new_cvar.t.i.lbound = lbound; new_cvar.t.i.ubound = ubound; - hash = CVAR_HashString(var_name); #ifdef R_CVAR_TRACE @@ -472,15 +382,9 @@ CVAR_Register_I(cv_int_t * var_p, return CVAR_Add(hash, &new_cvar); } -int -CVAR_Register_UI(cv_uint16_t * var_p, - const char *var_name, - const char *section, uint16 flags, cv_uint16_t lbound, cv_uint16_t ubound) -/****************************************************************************\ - Registers an unsigned integer type cvar. -\****************************************************************************/ -{ - +// Registers an unsigned integer type cvar. +int CVAR_Register_UI(cv_uint16_t * var_p, const char *var_name, + const char *section, uint16 flags, cv_uint16_t lbound, cv_uint16_t ubound) { R_CVAR new_cvar; int hash; @@ -488,12 +392,9 @@ CVAR_Register_UI(cv_uint16_t * var_p, new_cvar.type = R_CVAR_UINT; new_cvar.section = section; new_cvar.flags = flags; - new_cvar.t.ui.var_p = var_p; - new_cvar.t.ui.lbound = lbound; new_cvar.t.ui.ubound = ubound; - hash = CVAR_HashString(var_name); #ifdef R_CVAR_TRACE @@ -503,15 +404,9 @@ CVAR_Register_UI(cv_uint16_t * var_p, return CVAR_Add(hash, &new_cvar); } -int -CVAR_Register_F(cv_float_t * var_p, - const char *var_name, - const char *section, uint16 flags, cv_float_t lbound, cv_float_t ubound) -/****************************************************************************\ - Registers a floating point type cvar. -\****************************************************************************/ -{ - +// Registers a floating point type cvar. +int CVAR_Register_F(cv_float_t * var_p, const char *var_name, + const char *section, uint16 flags, cv_float_t lbound, cv_float_t ubound) { R_CVAR new_cvar; int hash; @@ -519,12 +414,9 @@ CVAR_Register_F(cv_float_t * var_p, new_cvar.type = R_CVAR_FLOAT; new_cvar.section = section; new_cvar.flags = flags; - new_cvar.t.f.var_p = var_p; - new_cvar.t.f.lbound = lbound; new_cvar.t.f.ubound = ubound; - hash = CVAR_HashString(var_name); #ifdef R_CVAR_TRACE @@ -534,15 +426,9 @@ CVAR_Register_F(cv_float_t * var_p, return CVAR_Add(hash, &new_cvar); } -int -CVAR_Register_S(cv_char_t * var_str, - const char *var_name, const char *section, uint16 flags, int ubound) -/****************************************************************************\ - Registers a string type cvar. Storage must be provided in var_p for 'ubound' - characters plus 1 for NUL char. -\****************************************************************************/ -{ - +// Registers a string type cvar. Storage must be provided in var_p for 'ubound' +// characters plus 1 for NUL char. +int CVAR_Register_S(cv_char_t * var_str, const char *var_name, const char *section, uint16 flags, int ubound) { R_CVAR new_cvar; int hash; @@ -550,10 +436,8 @@ CVAR_Register_S(cv_char_t * var_str, new_cvar.type = R_CVAR_STRING; new_cvar.section = section; new_cvar.flags = flags; - new_cvar.t.s.var_str = var_str; new_cvar.t.s.ubound = ubound; - hash = CVAR_HashString(var_name); #ifdef R_CVAR_TRACE @@ -563,41 +447,31 @@ CVAR_Register_S(cv_char_t * var_str, return CVAR_Add(hash, &new_cvar); } -int CVAR_Print(R_CVAR_P con_cvar) -/****************************************************************************\ - Displays the value and type of the given cvar to the console. -\****************************************************************************/ -{ - +// Displays the value and type of the given cvar to the console. +int CVAR_Print(R_CVAR_P con_cvar) { switch (con_cvar->type) { case R_CVAR_INT: - CON_Print("\"%s\"(i) = %d", - con_cvar->name, *(con_cvar->t.i.var_p)); + CON_Print("\"%s\"(i) = %d", con_cvar->name, *(con_cvar->t.i.var_p)); break; case R_CVAR_UINT: - CON_Print("\"%s\"(ui) = %u", - con_cvar->name, *(con_cvar->t.ui.var_p)); + CON_Print("\"%s\"(ui) = %u", con_cvar->name, *(con_cvar->t.ui.var_p)); break; case R_CVAR_FLOAT: - CON_Print("\"%s\"(ui) = %f", - con_cvar->name, *(con_cvar->t.f.var_p)); + CON_Print("\"%s\"(ui) = %f", con_cvar->name, *(con_cvar->t.f.var_p)); break; case R_CVAR_STRING: - CON_Print("\"%s\"(s) = \"%s\"", con_cvar->name, - con_cvar->t.s.var_str); + CON_Print("\"%s\"(s) = \"%s\"", con_cvar->name, con_cvar->t.s.var_str); break; case R_CVAR_FUNC: if (con_cvar->t.func.func_argstr) { - CON_Print("\"%s\"(func) Args: %s", con_cvar->name, - con_cvar->t.func.func_argstr); + CON_Print("\"%s\"(func) Args: %s", con_cvar->name, con_cvar->t.func.func_argstr); } else { - CON_Print("\"%s\"(func) No arguments.", - con_cvar->name); + CON_Print("\"%s\"(func) No arguments.", con_cvar->name); } break; diff --git a/saga/cvar.h b/saga/cvar.h index b87f36c71f..806885edd1 100644 --- a/saga/cvar.h +++ b/saga/cvar.h @@ -20,13 +20,8 @@ * $Header$ * */ -/* - Description: - - Configuration Variable Module - Notes: -*/ +// Configuration Variable Module #ifndef SAGA_CVAR_H_ #define SAGA_CVAR_H_ @@ -36,15 +31,12 @@ namespace Saga { #define R_CVAR_HASHLEN 32 struct R_SUBCVAR_INT { - cv_int_t *var_p; cv_int_t ubound; cv_int_t lbound; - }; struct R_SUBCVAR_UINT { - cv_uint16_t *var_p; cv_uint16_t ubound; cv_uint16_t lbound; @@ -52,31 +44,24 @@ struct R_SUBCVAR_UINT { }; struct R_SUBCVAR_FLOAT { - cv_float_t *var_p; cv_float_t ubound; cv_float_t lbound; - }; struct R_SUBCVAR_STRING { - cv_char_t *var_str; int ubound; - }; struct R_SUBCVAR_FUNC { - cv_func_t func_p; const char *func_argstr; int min_args; int max_args; - }; typedef struct R_CVAR_tag { - int type; const char *name; const char *section; @@ -96,5 +81,4 @@ typedef struct R_CVAR_tag { } // End of namespace Saga -#endif /* R_CVAR_H_ */ -/* end "r_cvar.h" */ +#endif diff --git a/saga/cvar_mod.h b/saga/cvar_mod.h index 04b0e07560..ddeaf3d40b 100644 --- a/saga/cvar_mod.h +++ b/saga/cvar_mod.h @@ -20,20 +20,15 @@ * $Header$ * */ -/* - Description: - - Configuration variable module public header file - Notes: -*/ +// Configuration variable module public header file #ifndef SAGA_CVAR_MOD_H_ #define SAGA_CVAR_MOD_H_ namespace Saga { -/* Modify these to change base cvar types */ +// Modify these to change base cvar types #define CV_INTMAX INT_MAX #define CV_INTMIN INT_MIN @@ -45,10 +40,9 @@ typedef char cv_char_t; typedef void (*cv_func_t) (int cv_argc, char *cv_argv[]); /******************************************/ -typedef struct R_CVAR_tag *R_CVAR_P; /* opaque typedef */ +typedef struct R_CVAR_tag *R_CVAR_P; // opaque typedef typedef enum R_CVAR_TYPES_tag { - R_CVAR_INVALID, R_CVAR_INT, R_CVAR_UINT, @@ -58,7 +52,6 @@ typedef enum R_CVAR_TYPES_tag { } R_CVAR_TYPES; typedef enum R_CVAR_FLAGS_tag { - R_CVAR_NONE, R_CVAR_READONLY, R_CVAR_LBOUND, @@ -69,44 +62,27 @@ typedef enum R_CVAR_FLAGS_tag { #define R_CVAR_BOUNDED ( R_CVAR_LBOUND | R_CVAR_UBOUND ) -int CVAR_Shutdown(void); +int CVAR_Shutdown(); R_CVAR_P CVAR_Find(const char *var_str); int CVAR_SetValue(R_CVAR_P cvar, char *r_value); int CVAR_Print(R_CVAR_P con_cvar); int CVAR_GetError(const char **err_str); int CVAR_IsFunc(R_CVAR_P cvar_func); int CVAR_Exec(R_CVAR_P cvar_func, char *r_value); - -int -CVAR_RegisterFunc(cv_func_t func, - const char *func_name, - const char *func_argstr, uint16 flags, int min_args, int max_args); - -int CVAR_Register_I(cv_int_t * var_p, - const char *var_name, - const char *section, uint16 flags, cv_int_t lbound, cv_int_t ubound); - -int CVAR_Register_UI(cv_uint16_t * var_p, - const char *var_name, - const char *section, uint16 flags, cv_uint16_t lbound, cv_uint16_t ubound); - -int CVAR_Register_F(cv_float_t * var_p, - const char *var_name, - const char *section, uint16 flags, cv_float_t lbound, cv_float_t ubound); - -int CVAR_Register_S(cv_char_t * var_str, - const char *var_name, const char *section, uint16 flags, int ubound); - -int EXPR_Parse(const char **exp_pp, int *len, R_CVAR_P * expr_cvar, - char **rvalue); - +int CVAR_RegisterFunc(cv_func_t func, const char *func_name, + const char *func_argstr, uint16 flags, int min_args, int max_args); +int CVAR_Register_I(cv_int_t * var_p, const char *var_name, + const char *section, uint16 flags, cv_int_t lbound, cv_int_t ubound); +int CVAR_Register_UI(cv_uint16_t * var_p, const char *var_name, + const char *section, uint16 flags, cv_uint16_t lbound, cv_uint16_t ubound); +int CVAR_Register_F(cv_float_t * var_p, const char *var_name, + const char *section, uint16 flags, cv_float_t lbound, cv_float_t ubound); +int CVAR_Register_S(cv_char_t * var_str, const char *var_name, const char *section, uint16 flags, int ubound); +int EXPR_Parse(const char **exp_pp, int *len, R_CVAR_P * expr_cvar, char **rvalue); char *EXPR_ReadString(const char **string_p, int *len, int term_char); - int EXPR_GetError(const char **err_str); - int EXPR_GetArgs(char *cmd_str, char ***expr_argv); } // End of namespace Saga -#endif /* R_CVAR_MOD_H_ */ -/* end r_cvar_mod.h_ */ +#endif |