From c13efcdb6467abcf08a7d9f7278ba21cbc8728b8 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Mon, 16 Dec 2013 19:42:52 -0800 Subject: [PATCH] Random cleanup and marking stuff static --- Makefile | 4 --- src/curses/ux_audio.c | 1 + src/curses/ux_blorb.c | 72 ++++++++++++++++++++----------------- src/curses/ux_blorb.h | 18 ---------- src/curses/ux_frotz.h | 7 ---- src/curses/ux_init.c | 84 +++++++++++++++++++++++++++++++++---------- 6 files changed, 107 insertions(+), 79 deletions(-) diff --git a/Makefile b/Makefile index 490c46d..9d32466 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,6 @@ CC = gcc # These are handy for debugging. OPTS = -O2 -g -Wall - # Define where you want Frotz installed (typically /usr/local). # PREFIX = /usr/local @@ -116,9 +115,6 @@ DUMB_OBJECT = $(DUMB_DIR)/dumb_init.o \ $(DUMB_DIR)/dumb_output.o \ $(DUMB_DIR)/dumb_pic.o - -# Blorb file handling -# BLORB_DIR = $(SRCDIR)/blorb BLORB_TARGET = $(SRCDIR)/blorblib.a BLORB_OBJECT = $(BLORB_DIR)/blorblib.o diff --git a/src/curses/ux_audio.c b/src/curses/ux_audio.c index 7fd28d8..5801e81 100644 --- a/src/curses/ux_audio.c +++ b/src/curses/ux_audio.c @@ -100,6 +100,7 @@ void os_start_sample (int number, int volume, int repeats, zword eos) { bb_result_t resource; + if (blorb_map == NULL) return; if (bb_err_None != bb_load_resource(blorb_map, bb_method_FilePos, &resource, bb_ID_Snd, number)) return; diff --git a/src/curses/ux_blorb.c b/src/curses/ux_blorb.c index 0ffc051..23d914c 100644 --- a/src/curses/ux_blorb.c +++ b/src/curses/ux_blorb.c @@ -44,32 +44,14 @@ FILE *blorb_fp; bb_result_t blorb_res; bb_map_t *blorb_map; -/* - * isblorb - * - * Returns 1 if this file is a Blorb file, 0 if not. - * - * FIXME Is there a potential endian problem here? - */ -static int isblorb(FILE *fp) -{ - char mybuf[4]; - - if (fp == NULL) - return 0; - - fread(mybuf, 1, 4, fp); - if (strncmp(mybuf, "FORM", 4)) - return 0; - - fseek(fp, 4, SEEK_CUR); - fread(mybuf, 1, 4, fp); - - if (strncmp(mybuf, "IFRS", 4)) - return 0; +/* uint32 *findchunk(uint32 *data, char *chunkID, int length); */ +static char *findchunk(char *pstart, char *fourcc, int n); +static unsigned short ReadShort(const unsigned char *bytes); +static unsigned long ReadLong(const unsigned char *bytes); +static double ReadExtended(const unsigned char *bytes); +static int isblorb(FILE *); - return 1; -} +#define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0) /* @@ -93,10 +75,7 @@ bb_err_t ux_blorb_init(char *filename) bb_err_t blorb_err; -/* blorb_map = NULL; - blorb_res = NULL; -*/ if ((fp = fopen(filename, "rb")) == NULL) return bb_err_Read; @@ -174,7 +153,36 @@ void ux_stop_blorb(void) blorb_fp = NULL; } -char *findchunk(char *data, char *string, int length) + + +/* + * isblorb + * + * Returns 1 if this file is a Blorb file, 0 if not. + * + * FIXME Is there a potential endian problem here? + */ +static int isblorb(FILE *fp) +{ + char mybuf[4]; + + if (fp == NULL) + return 0; + + fread(mybuf, 1, 4, fp); + if (strncmp(mybuf, "FORM", 4)) + return 0; + + fseek(fp, 4, SEEK_CUR); + fread(mybuf, 1, 4, fp); + + if (strncmp(mybuf, "IFRS", 4)) + return 0; + + return 1; +} + +static char *findchunk(char *data, char *string, int length) { char *mydata = data+12; while (TRUE) { @@ -188,7 +196,7 @@ char *findchunk(char *data, char *string, int length) } -unsigned short ReadShort(const unsigned char *bytes) +static unsigned short ReadShort(const unsigned char *bytes) { return (unsigned short)( ((unsigned short)(bytes[0] & 0xFF) << 8) | @@ -196,7 +204,7 @@ unsigned short ReadShort(const unsigned char *bytes) } -unsigned long ReadLong(const unsigned char *bytes) +static unsigned long ReadLong(const unsigned char *bytes) { return (unsigned long)( ((unsigned long)(bytes[0] & 0xFF) << 24) | @@ -206,7 +214,7 @@ unsigned long ReadLong(const unsigned char *bytes) } -double ReadExtended(const unsigned char *bytes) +static double ReadExtended(const unsigned char *bytes) { double f; int expon; diff --git a/src/curses/ux_blorb.h b/src/curses/ux_blorb.h index de3bc48..ffde5aa 100644 --- a/src/curses/ux_blorb.h +++ b/src/curses/ux_blorb.h @@ -10,12 +10,6 @@ typedef struct sampledata_struct { double rate; } sampledata_t; -/* -typedef struct blorb_data_struct { - bb_map_t map; - bb_result_t result; -} blorb_data_t; -*/ /* * The bb_result_t struct lacks a few members that would make things a @@ -32,18 +26,6 @@ typedef struct { } myresource; -int sf_getresource( int num, int ispic, int method, myresource * res); -void sf_freeresource( myresource *res); - -/* uint32 *findchunk(uint32 *data, char *chunkID, int length); */ -char *findchunk(char *pstart, char *fourcc, int n); -unsigned short ReadShort(const unsigned char *bytes); -unsigned long ReadLong(const unsigned char *bytes); -double ReadExtended(const unsigned char *bytes); - -#define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0) - - diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index a313a51..5127353 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -91,15 +91,8 @@ void unix_save_screen(int); /* ux_screen.c */ void unix_do_scrollback(void); /* ux_screen.c */ - -int getconfig(char *); -int geterrmode(char *); -int getcolor(char *); -int getbool(char *); -FILE *pathopen(const char *, const char *, const char *, char *); void sigwinch_handler(int); void sigint_handler(int); -void redraw(void); #ifdef NO_MEMMOVE diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index f2ffcd0..6045bea 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -32,7 +32,7 @@ #include /* We will use our own private getopt functions. */ -#include "getopt.h" +//#include "getopt.h" #ifdef USE_NCURSES_H #include @@ -73,6 +73,18 @@ char stripped_story_name[FILENAME_MAX+1]; char semi_stripped_story_name[FILENAME_MAX+1]; */ +static int zgetopt (int, char **, const char *); +static int zoptind = 1; +static int zoptopt = 0; +static char *zoptarg = NULL; + +static int getconfig(char *); +static int getbool(char *); +static int getcolor(char *); +static int geterrmode(char *); +static void redraw(void); +static FILE *pathopen(const char *, const char *, const char *, char *); + /* * os_fatal * @@ -196,22 +208,22 @@ void os_process_arguments (int argc, char *argv[]) /* Parse the options */ do { - c = getopt(argc, argv, "aAb:c:def:Fh:il:oOpPQqr:s:S:tu:w:xZ:"); + c = zgetopt(argc, argv, "aAb:c:def:Fh:il:oOpPQqr:s:S:tu:w:xZ:"); switch(c) { case 'a': f_setup.attribute_assignment = 1; break; case 'A': f_setup.attribute_testing = 1; break; - case 'b': u_setup.background_color = atoi(optarg); + case 'b': u_setup.background_color = atoi(zoptarg); u_setup.force_color = 1; u_setup.disable_color = 0; if ((u_setup.background_color < 2) || (u_setup.background_color > 9)) u_setup.background_color = -1; break; - case 'c': f_setup.context_lines = atoi(optarg); break; + case 'c': f_setup.context_lines = atoi(zoptarg); break; case 'd': u_setup.disable_color = 1; break; case 'e': f_setup.sound = 1; break; - case 'f': u_setup.foreground_color = getcolor(optarg); + case 'f': u_setup.foreground_color = getcolor(zoptarg); u_setup.force_color = 1; u_setup.disable_color = 0; if ((u_setup.foreground_color < 2) || @@ -223,23 +235,23 @@ void os_process_arguments (int argc, char *argv[]) case 'F': u_setup.force_color = 1; u_setup.disable_color = 0; break; - case 'h': u_setup.screen_height = atoi(optarg); break; + case 'h': u_setup.screen_height = atoi(zoptarg); break; case 'i': f_setup.ignore_errors = 1; break; - case 'l': f_setup.left_margin = atoi(optarg); break; + case 'l': f_setup.left_margin = atoi(zoptarg); break; case 'o': f_setup.object_movement = 1; break; case 'O': f_setup.object_locating = 1; break; case 'p': u_setup.plain_ascii = 1; break; case 'P': f_setup.piracy = 1; break; case 'q': f_setup.sound = 0; break; case 'Q': f_setup.save_quetzal = 0; break; - case 'r': f_setup.right_margin = atoi(optarg); break; - case 's': u_setup.random_seed = atoi(optarg); break; - case 'S': f_setup.script_cols = atoi(optarg); break; + case 'r': f_setup.right_margin = atoi(zoptarg); break; + case 's': u_setup.random_seed = atoi(zoptarg); break; + case 'S': f_setup.script_cols = atoi(zoptarg); break; case 't': u_setup.tandy_bit = 1; break; - case 'u': f_setup.undo_slots = atoi(optarg); break; - case 'w': u_setup.screen_width = atoi(optarg); break; + case 'u': f_setup.undo_slots = atoi(zoptarg); break; + case 'w': u_setup.screen_width = atoi(zoptarg); break; case 'x': f_setup.expand_abbreviations = 1; break; - case 'Z': f_setup.err_report_mode = atoi(optarg); + case 'Z': f_setup.err_report_mode = atoi(zoptarg); if ((f_setup.err_report_mode < ERR_REPORT_NEVER) || (f_setup.err_report_mode > ERR_REPORT_FATAL)) f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE; @@ -548,7 +560,7 @@ FILE *os_load_story(void) * */ -FILE *pathopen(const char *name, const char *p, const char *mode, char *fullname) +static FILE *pathopen(const char *name, const char *p, const char *mode, char *fullname) { FILE *fp; char buf[FILENAME_MAX + 1]; @@ -588,7 +600,7 @@ FILE *pathopen(const char *name, const char *p, const char *mode, char *fullname * compile targets to have those two tools installed. * */ -int getconfig(char *configfile) +static int getconfig(char *configfile) { FILE *fp; @@ -740,7 +752,7 @@ int getconfig(char *configfile) * Otherwise return FALSE. * */ -int getbool(char *value) +static int getbool(char *value) { int num; @@ -768,7 +780,7 @@ int getbool(char *value) * corresponding to the color macros defined in frotz.h. * */ -int getcolor(char *value) +static int getcolor(char *value) { int num; @@ -814,7 +826,7 @@ int getcolor(char *value) * defined in ux_frotz.h related to the error reporting mode. * */ -int geterrmode(char *value) +static int geterrmode(char *value) { int num; @@ -922,3 +934,39 @@ void os_init_setup(void) } +/* A unix-like getopt, but with the names changed to avoid any problems. +*/ +static int zgetopt (int argc, char *argv[], const char *options) +{ + static int pos = 1; + const char *p; + if (zoptind >= argc || argv[zoptind][0] != '-' || argv[zoptind][1] == 0) + return EOF; + zoptopt = argv[zoptind][pos++]; + zoptarg = NULL; + if (argv[zoptind][pos] == 0) { + pos = 1; + zoptind++; + } + p = strchr (options, zoptopt); + if (zoptopt == ':' || p == NULL) { + fputs ("illegal option -- ", stderr); + goto error; + } else if (p[1] == ':') { + if (zoptind >= argc) { + fputs ("option requires an argument -- ", stderr); + goto error; + } else { + zoptarg = argv[zoptind]; + if (pos != 1) + zoptarg += pos; + pos = 1; zoptind++; + } + } + return zoptopt; +error: + fputc (zoptopt, stderr); + fputc ('\n', stderr); + return '?'; +}/* zgetopt */ + -- 2.34.1