First round of changes from Stas Sergeev.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index c8ac356eda049da1ea740374e472d98172f8773b..888b7ec4780b01333e7a04905a7dbef65e07d6c5 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -1,6 +1,7 @@
 #define INCLUDED       // Define externs here\r
-#include "sst.h"\r
 #include <ctype.h>\r
+#include <getopt.h>\r
+#include "sst.h"\r
 \r
 #ifndef SSTDOC\r
 #define SSTDOC "sst.doc"\r
@@ -189,6 +190,7 @@ static void makemoves(void) {
                        }\r
                        else prout("UNRECOGNIZED COMMAND.");\r
                }\r
+               commandhook(commands[i], TRUE);\r
                switch (i) { /* command switch */\r
                        case 0:                 // srscan\r
                                srscan(1);\r
@@ -215,7 +217,8 @@ static void makemoves(void) {
                                }\r
                                break;\r
                        case 6:                 // dock\r
-                               dock();\r
+                               dock(1);\r
+                                if (ididit) attack(0);\r
                                break;\r
                        case 7:                 // damages\r
                                dreprt();\r
@@ -313,6 +316,7 @@ static void makemoves(void) {
                                helpme();       // get help\r
                                break;\r
                }\r
+               commandhook(commands[i], FALSE);\r
                for (;;) {\r
                        if (alldone) break;             // Game has ended\r
 #ifdef DEBUG\r
@@ -344,20 +348,28 @@ static void makemoves(void) {
 \r
 \r
 int main(int argc, char **argv) {\r
-       int i;\r
+    int i, option, usecurses = TRUE;\r
        int hitme;\r
        char ch;\r
 \r
-       iostart();\r
+       while ((option = getopt(argc, argv, "t")) != -1) {\r
+           switch (option) {\r
+           case 't':\r
+               usecurses = FALSE;\r
+               break;\r
+           default:\r
+               fprintf(stderr, "usage: sst [-t] [startcommand...].\n");\r
+               exit(0);\r
+           }\r
+       }\r
+\r
+       iostart(usecurses);\r
        prelim(); \r
        line[0] = '\0';\r
-       if (argc > 1) {\r
-               while (--argc > 0) {\r
-                       strcat(line, *(++argv));\r
-                       strcat(line, " ");\r
-               }\r
+       for (i = optind; i < argc;  i++) {\r
+               strcat(line, argv[i]);\r
+               strcat(line, " ");\r
        }\r
-\r
        while (TRUE) { /* Play a game */\r
                setup(line[0] == '\0');\r
                if (alldone) {\r
@@ -400,6 +412,7 @@ void cramen(int i) {
                case IHBLANK: s = "Black hole"; break;\r
                case IHT: s = "Tholian"; break;\r
                case IHWEB: s = "Tholian web"; break;\r
+                case IHQUEST: s = "Stranger"; break;\r
                default: s = "Unknown??"; break;\r
        }\r
        proutn(s);\r
@@ -491,6 +504,7 @@ int scan(void) {
        }\r
        if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') {\r
                // treat as a number\r
+           i = 0;\r
            if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {\r
                linep = line; // Invalid numbers are ignored\r
                *linep = 0;\r
@@ -523,8 +537,6 @@ int ja(void) {
        }\r
 }\r
 \r
-double square(double i) { return i*i; }\r
-                                                                       \r
 void huh(void) {\r
        chew();\r
        skip(1);\r