Random cleanup and marking stuff static
authorDavid Griffith <dave@661.org>
Tue, 17 Dec 2013 03:42:52 +0000 (19:42 -0800)
committerDavid Griffith <dave@661.org>
Tue, 17 Dec 2013 03:42:52 +0000 (19:42 -0800)
Makefile
src/curses/ux_audio.c
src/curses/ux_blorb.c
src/curses/ux_blorb.h
src/curses/ux_frotz.h
src/curses/ux_init.c

index 490c46d0da99db422576852a58f8cac56ebda96c..9d32466047da6d9685f880aec6db05903de5bb7f 100644 (file)
--- 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
index 7fd28d88915b08d5d29d36bbd1fbd6d159281c2f..5801e81fe98df0e65d7aee13a53f2f9c7308a93b 100644 (file)
@@ -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;
index 0ffc051d67445b8aa670d37131057b0cd40eac3b..23d914c940c2c9d3d0575bb38677ec79b3bd7919 100644 (file)
@@ -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;
index de3bc480632c0df80b5584b60f5efd04c7c8e2d5..ffde5aae21d3cdb0ad95ae803f91bd45a44dc637 100644 (file)
@@ -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)
-
-
 
 
 
index a313a516fffa25013c80f83b9a83a454f5b7052f..51273532c4ee535a1b437fa635d5961ac5e60eb9 100644 (file)
@@ -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
index f2ffcd016caaad64f509c6e5afaf697e0b9b7347..6045bea0c6d94af710c1cf53055dff4f7e57dd01 100644 (file)
@@ -32,7 +32,7 @@
 #include <libgen.h>
 
 /* We will use our own private getopt functions. */
-#include "getopt.h"
+//#include "getopt.h"
 
 #ifdef USE_NCURSES_H
 #include <ncurses.h>
@@ -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 */
+