formating

svn-id: r38692
This commit is contained in:
Paweł Kołodziejski 2009-02-21 12:42:06 +00:00
parent 7e2bc28184
commit c0b2ec8dd2
2 changed files with 82 additions and 119 deletions

View File

@ -29,7 +29,7 @@
namespace Sci {
/* #define SCRIPT_DEBUG */
// #define SCRIPT_DEBUG
#define END Script_None
@ -107,21 +107,21 @@ void script_adjust_opcode_formats(int res_version) {
}
}
int
script_find_selector(EngineState *s, const char *selectorname) {
int script_find_selector(EngineState *s, const char *selectorname) {
int i;
for (i = 0; i < s->selector_names_nr; i++)
if (strcmp(selectorname, s->selector_names[i]) == 0)
return i;
sciprintf("Warning: Could not map '%s' to any selector", selectorname);
return -1;
}
#define FIND_SELECTOR(_slc_, _slcstr_) map->_slc_ = script_find_selector(s, _slcstr_);
void
script_map_selectors(EngineState *s, selector_map_t *map) {
void script_map_selectors(EngineState *s, selector_map_t *map) {
map->init = script_find_selector(s, "init");
map->play = script_find_selector(s, "play");
FIND_SELECTOR(replay, "replay");
@ -210,10 +210,10 @@ script_map_selectors(EngineState *s, selector_map_t *map) {
FIND_SELECTOR(points, "points");
}
int
sci_hexdump(byte *data, int length, int offsetplus) {
int sci_hexdump(byte *data, int length, int offsetplus) {
char tempstr[40];
int i;
for (i = 0; i < length; i += 8) {
int j;
@ -223,21 +223,20 @@ sci_hexdump(byte *data, int length, int offsetplus) {
for (j = 0; j < MIN(8, length - i); j++) {
int thechar;
thechar = data[i+j];
sprintf(tempstr + 31 + j, "%c",
((thechar < ' ') || (thechar > 127)) ? '.' : thechar);
sprintf(tempstr + 31 + j, "%c", ((thechar < ' ') || (thechar > 127)) ? '.' : thechar);
}
for (j = 0; j < 38; j++)
if (!tempstr[j])
tempstr[j] = ' '; /* get rid of sprintf's \0s */
tempstr[j] = ' '; // get rid of sprintf's \0s
sciprintf("%s\n", tempstr);
}
return 0;
}
static void
script_dump_object(char *data, int seeker, int objsize, char **snames, int snames_nr) {
static void script_dump_object(char *data, int seeker, int objsize, char **snames, int snames_nr) {
int selectors, overloads, selectorsize;
int species = getInt16((unsigned char *) data + 8 + seeker);
int superclass = getInt16((unsigned char *) data + 10 + seeker);
@ -247,7 +246,7 @@ script_dump_object(char *data, int seeker, int objsize, char **snames, int sname
sciprintf("Object\n");
sci_hexdump((unsigned char *) data + seeker, objsize - 4, seeker);
/*-4 because the size includes the two-word header */
//-4 because the size includes the two-word header
sciprintf("Name: %s\n", namepos ? ((char *)(data + namepos)) : "<unknown>");
sciprintf("Superclass: %x\n", superclass);
@ -255,20 +254,17 @@ script_dump_object(char *data, int seeker, int objsize, char **snames, int sname
sciprintf("-info-:%x\n", getInt16((unsigned char *) data + 12 + seeker) & 0xffff);
sciprintf("Function area offset: %x\n", getInt16((unsigned char *) data + seeker + 4));
sciprintf("Selectors [%x]:\n",
selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
sciprintf("Selectors [%x]:\n", selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
seeker += 8;
while (selectors--) {
sciprintf(" [#%03x] = 0x%x\n", i++, getInt16((unsigned char *) data + seeker) & 0xffff);
sciprintf(" [#%03x] = 0x%x\n", i++, getInt16((unsigned char *)data + seeker) & 0xffff);
seeker += 2;
}
sciprintf("Overridden functions: %x\n", selectors =
overloads = getInt16((unsigned char *) data + seeker));
sciprintf("Overridden functions: %x\n", selectors = overloads = getInt16((unsigned char *)data + seeker));
seeker += 2;
@ -276,16 +272,14 @@ script_dump_object(char *data, int seeker, int objsize, char **snames, int sname
while (overloads--) {
int selector = getInt16((unsigned char *) data + (seeker));
sciprintf(" [%03x] %s: @", selector & 0xffff,
(snames && selector >= 0 && selector < snames_nr) ? snames[selector] : "<?>");
sciprintf("%04x\n", getInt16((unsigned char *) data + seeker + selectors*2 + 2) & 0xffff);
sciprintf(" [%03x] %s: @", selector & 0xffff, (snames && selector >= 0 && selector < snames_nr) ? snames[selector] : "<?>");
sciprintf("%04x\n", getInt16((unsigned char *)data + seeker + selectors*2 + 2) & 0xffff);
seeker += 2;
}
}
static void
script_dump_class(char *data, int seeker, int objsize, char **snames, int snames_nr) {
static void script_dump_class(char *data, int seeker, int objsize, char **snames, int snames_nr) {
int selectors, overloads, selectorsize;
int species = getInt16((unsigned char *) data + 8 + seeker);
int superclass = getInt16((unsigned char *) data + 10 + seeker);
@ -298,11 +292,10 @@ script_dump_class(char *data, int seeker, int objsize, char **snames, int snames
sciprintf("Name: %s\n", namepos ? ((char *)data + namepos) : "<unknown>");
sciprintf("Superclass: %x\n", superclass);
sciprintf("Species: %x\n", species);
sciprintf("-info-:%x\n", getInt16((unsigned char *) data + 12 + seeker) & 0xffff);
sciprintf("-info-:%x\n", getInt16((unsigned char *)data + 12 + seeker) & 0xffff);
sciprintf("Function area offset: %x\n", getInt16((unsigned char *) data + seeker + 4));
sciprintf("Selectors [%x]:\n",
selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
sciprintf("Function area offset: %x\n", getInt16((unsigned char *)data + seeker + 4));
sciprintf("Selectors [%x]:\n", selectors = (selectorsize = getInt16((unsigned char *)data + seeker + 6)));
seeker += 8;
selectorsize <<= 1;
@ -310,35 +303,30 @@ script_dump_class(char *data, int seeker, int objsize, char **snames, int snames
while (selectors--) {
int selector = getInt16((unsigned char *) data + (seeker) + selectorsize);
sciprintf(" [%03x] %s = 0x%x\n", 0xffff & selector,
(snames && selector >= 0 && selector < snames_nr) ? snames[selector] : "<?>",
getInt16((unsigned char *) data + seeker) & 0xffff);
sciprintf(" [%03x] %s = 0x%x\n", 0xffff & selector, (snames && selector >= 0 && selector < snames_nr) ? snames[selector] : "<?>",
getInt16((unsigned char *)data + seeker) & 0xffff);
seeker += 2;
}
seeker += selectorsize;
sciprintf("Overloaded functions: %x\n", selectors =
overloads = getInt16((unsigned char *) data + seeker));
sciprintf("Overloaded functions: %x\n", selectors = overloads = getInt16((unsigned char *)data + seeker));
seeker += 2;
while (overloads--) {
int selector = getInt16((unsigned char *) data + (seeker));
int selector = getInt16((unsigned char *)data + (seeker));
error("selector=%d; snames_nr =%d\n", selector, snames_nr);
sciprintf(" [%03x] %s: @", selector & 0xffff,
(snames && selector >= 0 && selector < snames_nr) ?
sciprintf(" [%03x] %s: @", selector & 0xffff, (snames && selector >= 0 && selector < snames_nr) ?
snames[selector] : "<?>");
sciprintf("%04x\n", getInt16((unsigned char *) data + seeker + selectors*2 + 2) & 0xffff);
sciprintf("%04x\n", getInt16((unsigned char *)data + seeker + selectors * 2 + 2) & 0xffff);
seeker += 2;
}
}
void
script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snames_nr) {
void script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snames_nr) {
int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned int _seeker = 0;
resource_t *script = scir_find_resource(resmgr, sci_script, res_no, 0);
@ -361,7 +349,7 @@ script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snames_nr
sciprintf("End of script object (#0) encountered.\n");
sciprintf("Classes: %i, Objects: %i, Export: %i,\n Var: %i (all base 10)",
objectctr[6], objectctr[1], objectctr[7], objectctr[10]);
/*vocabulary_free_snames(snames);*/
//vocabulary_free_snames(snames);
vocab_free_words(words, word_count);
return;
}
@ -378,7 +366,7 @@ script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snames_nr
switch (objtype) {
case sci_obj_object:
script_dump_object((char *) script->data, seeker, objsize, snames, snames_nr);
script_dump_object((char *)script->data, seeker, objsize, snames, snames_nr);
break;
case sci_obj_code: {
@ -448,19 +436,19 @@ script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snames_nr
sciprintf("Strings\n");
while (script->data [seeker]) {
sciprintf("%04x: %s\n", seeker, script->data + seeker);
seeker += strlen((char *) script->data + seeker) + 1;
seeker += strlen((char *)script->data + seeker) + 1;
}
seeker++; /* the ending zero byte */
seeker++; // the ending zero byte
};
break;
case sci_obj_class:
script_dump_class((char *) script->data, seeker, objsize, snames, snames_nr);
script_dump_class((char *)script->data, seeker, objsize, snames, snames_nr);
break;
case sci_obj_exports: {
sciprintf("Exports\n");
sci_hexdump((unsigned char *) script->data + seeker, objsize - 4, seeker);
sci_hexdump((unsigned char *)script->data + seeker, objsize - 4, seeker);
};
break;
@ -491,7 +479,7 @@ script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snames_nr
sciprintf("Script ends without terminator\n");
/*vocabulary_free_snames(snames);*/
//vocabulary_free_snames(snames);
}
} // End of namespace Sci

View File

@ -87,8 +87,8 @@ namespace Sci {
# include <kos/thread.h>
#endif
int script_debug_flag = 0; /* Defaulting to running mode */
int sci_debug_flags = 0; /* Special flags */
int script_debug_flag = 0; // Defaulting to running mode
int sci_debug_flags = 0; // Special flags
#ifndef con_file
# define con_file 0
@ -108,12 +108,9 @@ int sci_ffs(int _mask) {
return retval;
}
//******************* Debug functions *******************
/******************** Debug functions ********************/
/* Functions for internal macro use */
// Functions for internal macro use
void _SCIkvprintf(FILE *file, const char *format, va_list args);
void _SCIkprintf(FILE *file, const char *format, ...) GCC_PRINTF(2, 3);
@ -138,7 +135,7 @@ void _SCIGNUkdebug(const char *funcname, EngineState *s, const char *file, int l
va_list xargs;
int error = ((area == SCIkWARNING_NR) || (area == SCIkERROR_NR));
if (error || (s->debug_mode & (1 << area))) { /* Is debugging enabled for this area? */
if (error || (s->debug_mode & (1 << area))) { // Is debugging enabled for this area?
fprintf(stderr, "FSCI: ");
@ -160,8 +157,7 @@ void _SCIGNUkdebug(const char *funcname, EngineState *s, const char *file, int l
#if defined(HAVE_GETTIMEOFDAY)
void
sci_gettime(long *seconds, long *useconds) {
void sci_gettime(long *seconds, long *useconds) {
struct timeval tv;
assert(!gettimeofday(&tv, NULL));
@ -195,26 +191,19 @@ void sci_gettime(long *seconds, long *useconds) {
#endif
void
sci_get_current_time(GTimeVal *val) {
void sci_get_current_time(GTimeVal *val) {
long foo, bar;
sci_gettime(&foo, &bar);
val->tv_sec = foo;
val->tv_usec = bar;
}
/************* Directory entities *************/
#if defined(WIN32)
/******** Dir: Win32 CODE ********/
void
sci_init_dir(sci_dir_t *dir) {
void sci_init_dir(sci_dir_t *dir) {
dir->search = -1;
}
char *
sci_find_first(sci_dir_t *dir, const char *mask) {
char *sci_find_first(sci_dir_t *dir, const char *mask) {
dir->search = _findfirst(mask, &(dir->fileinfo));
if (dir->search != -1) {
@ -255,8 +244,7 @@ sci_find_first(sci_dir_t *dir, const char *mask) {
return NULL;
}
char *
sci_find_next(sci_dir_t *dir) {
char *sci_find_next(sci_dir_t *dir) {
if (dir->search == -1)
return NULL;
@ -276,25 +264,21 @@ sci_find_next(sci_dir_t *dir) {
return dir->fileinfo.name;
}
void
sci_finish_find(sci_dir_t *dir) {
void sci_finish_find(sci_dir_t *dir) {
if (dir->search != -1) {
_findclose(dir->search);
dir->search = -1;
}
}
#else /* !WIN32 */
/******** Dir: UNIX CODE ********/
#else
void
sci_init_dir(sci_dir_t *dir) {
void sci_init_dir(sci_dir_t *dir) {
dir->dir = NULL;
dir->mask_copy = NULL;
}
char *
sci_find_first(sci_dir_t *dir, const char *mask) {
char *sci_find_first(sci_dir_t *dir, const char *mask) {
if (dir->dir)
closedir(dir->dir);
@ -313,8 +297,7 @@ sci_find_first(sci_dir_t *dir, const char *mask) {
#warning "File searches will not be case-insensitive!"
#endif
char *
sci_find_next(sci_dir_t *dir) {
char *sci_find_next(sci_dir_t *dir) {
struct dirent *match;
while ((match = readdir(dir->dir))) {
@ -326,11 +309,11 @@ sci_find_next(sci_dir_t *dir) {
}
sci_finish_find(dir);
return NULL;
}
void
sci_finish_find(sci_dir_t *dir) {
void sci_finish_find(sci_dir_t *dir) {
if (dir->dir) {
closedir(dir->dir);
dir->dir = NULL;
@ -339,19 +322,14 @@ sci_finish_find(sci_dir_t *dir) {
}
}
#endif /* !WIN32 */
#endif
/************* /Directory entities *************/
int
sci_mkpath(const char *path) {
int sci_mkpath(const char *path) {
const char *path_position = path;
char *next_separator = NULL;
if (chdir(G_DIR_SEPARATOR_S)) { /* Go to root */
sciprintf("Error: Could not change to root directory '%s'",
G_DIR_SEPARATOR_S);
if (chdir(G_DIR_SEPARATOR_S)) { // Go to root
sciprintf("Error: Could not change to root directory '%s'", G_DIR_SEPARATOR_S);
return -1;
}
@ -363,11 +341,10 @@ sci_mkpath(const char *path) {
if (next_separator)
*next_separator = 0;
if (*path_position) { /* Unless we're at the first slash... */
if (*path_position) { // Unless we're at the first slash...
if (chdir(path_position)) {
if (scimkdir(path_position, 0700) || chdir(path_position)) {
sciprintf("Error: Could not create subdirectory '%s' in",
path_position);
sciprintf("Error: Could not create subdirectory '%s' in", path_position);
if (next_separator)
*next_separator = G_DIR_SEPARATOR_S[0];
sciprintf(" '%s'", path);
@ -382,37 +359,33 @@ sci_mkpath(const char *path) {
return 0;
}
/*-- Yielding to the scheduler --*/
//-- Yielding to the scheduler --
#ifdef HAVE_SCHED_YIELD
# include <sched.h>
void
sci_sched_yield(void) {
void sci_sched_yield(void) {
sched_yield();
}
#elif defined (__DC__)
void
sci_sched_yield() {
void sci_sched_yield() {
thd_pass();
}
#elif defined (WIN32)
void
sci_sched_yield() {
void sci_sched_yield() {
sleep(1);
}
#else
void
sci_sched_yield() {
void sci_sched_yield() {
}
#endif /* !HAVE_SCHED_YIELD */
#endif
/* Returns the case-sensitive filename of a file.
@ -422,8 +395,8 @@ sci_sched_yield() {
** Returns : (char *) Case-sensitive filename of the file.
*/
Common::String _fcaseseek(const char *fname) {
/* Expects *dir to be uninitialized and the caller to
** free it afterwards */
// Expects *dir to be uninitialized and the caller to
// free it afterwards */
if (strchr(fname, G_DIR_SEPARATOR)) {
error("_fcaseseek() does not support subdirs\n");
@ -439,10 +412,10 @@ Common::String _fcaseseek(const char *fname) {
if (name.equalsIgnoreCase(fname))
return name;
}
return Common::String();
}
FILE *sci_fopen(const char *fname, const char *mode) {
Common::String name = _fcaseseek(fname);
FILE *file = NULL;
@ -464,8 +437,7 @@ int sci_open(const char *fname, int flags) {
return file;
}
char *
sci_getcwd(void) {
char *sci_getcwd() {
int size = 0;
char *cwd = NULL;
@ -479,18 +451,17 @@ sci_getcwd(void) {
}
error("Could not determine current working directory");
return NULL;
}
#ifdef __DC__
int
sci_fd_size(int fd) {
int sci_fd_size(int fd) {
return fs_total(fd);
}
int
sci_file_size(const char *fname) {
int sci_file_size(const char *fname) {
int fd = fs_open(fname, O_RDONLY);
int retval = -1;
@ -504,17 +475,21 @@ sci_file_size(const char *fname) {
#else
int
sci_fd_size(int fd) {
int sci_fd_size(int fd) {
struct stat fd_stat;
if (fstat(fd, &fd_stat)) return -1;
if (fstat(fd, &fd_stat))
return -1;
return fd_stat.st_size;
}
int
sci_file_size(const char *fname) {
int sci_file_size(const char *fname) {
struct stat fn_stat;
if (stat(fname, &fn_stat)) return -1;
if (stat(fname, &fn_stat))
return -1;
return fn_stat.st_size;
}
@ -534,7 +509,7 @@ int is_print_str(char *str) {
str++;
}
return ((float) printable / (float) len >= 0.5);
return ((float)printable / (float)len >= 0.5);
}
} // End of namespace Sci