Indents now match the rest of the code. Minor bugfixes. Remove junk.
authorDavid Griffith <dave@661.org>
Fri, 25 Oct 2013 02:26:13 +0000 (19:26 -0700)
committerDavid Griffith <dave@661.org>
Fri, 25 Oct 2013 02:26:13 +0000 (19:26 -0700)
Bracket sugar.

src/dumb/dumb_init.c
src/dumb/dumb_input.c
src/dumb/dumb_output.c
src/dumb/dumb_pic.c

index 623b7e16ae2a2b7f1a9b5aad46f9477feb1d4877..e6a8f008726647fcb45023a517dcd80163282ce2 100644 (file)
@@ -24,39 +24,6 @@ Syntax: dfrotz [options] story-file\n\
   -p   plain ASCII output only \t -w # screen width\n\
   -P   alter piracy opcode     \t -x   expand abbreviations g/x/z"
 
-/*
-static char usage[] = "\
-\n\
-FROTZ V2.32 - interpreter for all Infocom games. Complies with standard\n\
-1.0 of Graham Nelson's specification. Written by Stefan Jokisch in 1995-7.\n\
-\n\
-DUMB-FROTZ V2.32R1 - port for all platforms.  Somewhat complies with standard\n\
-9899 of ISO's specification.  Written by Alembic Petrofsky in 1997-8.\n\
-\n\
-Syntax: frotz [options] story-file [graphics-file]\n\
-\n\
-  -a      watch attribute setting\n\
-  -A      watch attribute testing\n\
-  -h #    screen height\n\
-  -i      ignore runtime errors\n\
-  -I #    interpreter number to report to game\n\
-  -o      watch object movement\n\
-  -O      watch object locating\n\
-  -p      alter piracy opcode\n\
-  -P      transliterate latin1 to plain ASCII\n\
-  -R xxx  do runtime setting \\xxx before starting\n\
-            (this option can be used multiple times)\n\
-  -s #    random number seed value\n\
-  -S #    transcript width\n\
-  -t      set Tandy bit\n\
-  -u #    slots for multiple undo\n\
-  -w #    screen width\n\
-  -x      expand abbreviations g/x/z\n\
-\n\
-While running, enter \"\\help\" to list the runtime escape sequences.\n\
-";
-*/
-
 
 /* A unix-like getopt, but with the names changed to avoid any problems.  */
 static int zoptind = 1;
@@ -64,7 +31,7 @@ static int zoptopt = 0;
 static char *zoptarg = NULL;
 static int zgetopt (int argc, char *argv[], const char *options)
 {
-    static pos = 1;
+    static int pos = 1;
     const char *p;
     if (zoptind >= argc || argv[zoptind][0] != '-' || argv[zoptind][1] == 0)
        return EOF;
@@ -76,7 +43,7 @@ static int zgetopt (int argc, char *argv[], const char *options)
     if (zoptopt == ':' || p == NULL) {
        fputs ("illegal option -- ", stderr);
        goto error;
-    } else if (p[1] == ':')
+    } else if (p[1] == ':') {
        if (zoptind >= argc) {
            fputs ("option requires an argument -- ", stderr);
            goto error;
@@ -86,6 +53,7 @@ static int zgetopt (int argc, char *argv[], const char *options)
                zoptarg += pos;
            pos = 1; zoptind++;
        }
+    }
     return zoptopt;
 error:
     fputc (zoptopt, stderr);
@@ -142,6 +110,7 @@ void os_process_arguments(int argc, char *argv[])
            "\t     %d = report all errors     %d = exit after any error\n\n",
            ERR_DEFAULT_REPORT_MODE, ERR_REPORT_NEVER,
            ERR_REPORT_ONCE, ERR_REPORT_ALWAYS, ERR_REPORT_FATAL);
+       printf("While running, enter \"\\help\" to list the runtime escape sequences\n\n");
        exit(1);
     }
 /*
@@ -152,50 +121,50 @@ void os_process_arguments(int argc, char *argv[])
 */
     f_setup.story_file = argv[zoptind++];
     if (zoptind < argc)
-      graphics_filename = argv[zoptind++];
+       graphics_filename = argv[zoptind++];
 
 }
 
 void os_init_screen(void)
 {
-  if (h_version == V3 && user_tandy_bit)
-      h_config |= CONFIG_TANDY;
-
-  if (h_version >= V5 && f_setup.undo_slots == 0)
-      h_flags &= ~UNDO_FLAG;
-
-  h_screen_rows = user_screen_height;
-  h_screen_cols = user_screen_width;
-
-  if (user_interpreter_number > 0)
-    h_interpreter_number = user_interpreter_number;
-  else {
-    /* Use ms-dos for v6 (because that's what most people have the
-     * graphics files for), but don't use it for v5 (or Beyond Zork
-     * will try to use funky characters).  */
-    h_interpreter_number = h_version == 6 ? INTERP_MSDOS : INTERP_DEC_20;
-  }
-  h_interpreter_version = 'F';
-
-  dumb_init_input();
-  dumb_init_output();
-  dumb_init_pictures(graphics_filename);
+    if (h_version == V3 && user_tandy_bit)
+       h_config |= CONFIG_TANDY;
+
+    if (h_version >= V5 && f_setup.undo_slots == 0)
+       h_flags &= ~UNDO_FLAG;
+
+    h_screen_rows = user_screen_height;
+    h_screen_cols = user_screen_width;
+
+    if (user_interpreter_number > 0)
+       h_interpreter_number = user_interpreter_number;
+    else {
+       /* Use ms-dos for v6 (because that's what most people have the
+       * graphics files for), but don't use it for v5 (or Beyond Zork
+       * will try to use funky characters).  */
+       h_interpreter_number = h_version == 6 ? INTERP_MSDOS : INTERP_DEC_20;
+    }
+    h_interpreter_version = 'F';
+
+    dumb_init_input();
+    dumb_init_output();
+    dumb_init_pictures(graphics_filename);
 }
 
 int os_random_seed (void)
 {
-  if (user_random_seed == -1)
-    /* Use the epoch as seed value */
-    return (time(0) & 0x7fff);
-  else return user_random_seed;
+    if (user_random_seed == -1)
+       /* Use the epoch as seed value */
+       return (time(0) & 0x7fff);
+    else return user_random_seed;
 }
 
 void os_restart_game (int stage) {}
 
 void os_fatal (const char *s, ...)
 {
-  fprintf(stderr, "\nFatal error: %s\n", s);
-  exit(1);
+    fprintf(stderr, "\nFatal error: %s\n", s);
+    exit(1);
 }
 
 FILE *os_load_story(void)
index 5f83f49c757b185fbd78c1c017b9fad1d22343fc..7238ba3710ac02d6378ac5dc2ac4ddf99edf2a85 100644 (file)
@@ -57,23 +57,23 @@ static float speed = 1;
 static bool do_more_prompts = TRUE;
 
 enum input_type {
-  INPUT_CHAR,
-  INPUT_LINE,
-  INPUT_LINE_CONTINUED,
+    INPUT_CHAR,
+    INPUT_LINE,
+    INPUT_LINE_CONTINUED,
 };
 
 /* get a character.  Exit with no fuss on EOF.  */
 static int xgetchar(void)
 {
-  int c = getchar();
-  if (c == EOF) {
-    if (feof(stdin)) {
-      fprintf(stderr, "\nEOT\n");
-      exit(0);
+    int c = getchar();
+    if (c == EOF) {
+       if (feof(stdin)) {
+           fprintf(stderr, "\nEOT\n");
+           exit(0);
+       }
+       os_fatal(strerror(errno));
     }
-    os_fatal(strerror(errno));
-  }
-  return c;
+    return c;
 }
 
 /* Read one line, including the newline, into s.  Safely avoids buffer
@@ -81,18 +81,20 @@ static int xgetchar(void)
  * other places where I'm not so careful).  */
 static void dumb_getline(char *s)
 {
-  int c;
-  char *p = s;
-  while (p < s + INPUT_BUFFER_SIZE - 1)
-    if ((*p++ = xgetchar()) == '\n') {
-      *p = '\0';
-      return;
+    int c;
+    char *p = s;
+    while (p < s + INPUT_BUFFER_SIZE - 1) {
+       if ((*p++ = xgetchar()) == '\n') {
+           *p = '\0';
+           return;
+       }
     }
-  p[-1] = '\n';
-  p[0] = '\0';
-  while ((c = xgetchar()) != '\n')
-    ;
-  printf("Line too long, truncated to %s\n", s - INPUT_BUFFER_SIZE);
+
+    p[-1] = '\n';
+    p[0] = '\0';
+    while ((c = xgetchar()) != '\n')
+       ;
+    printf("Line too long, truncated to %s\n", s - INPUT_BUFFER_SIZE);
 }
 
 /* Translate in place all the escape characters in s.  */
@@ -144,36 +146,36 @@ static int time_ahead = 0;
  * (because the user is further ahead than the timeout).  */
 static bool check_timeout(int timeout)
 {
-  if ((timeout == 0) || (timeout > time_ahead))
-    time_ahead = 0;
-  else
-    time_ahead -= timeout;
-  return time_ahead != 0;
+    if ((timeout == 0) || (timeout > time_ahead))
+       time_ahead = 0;
+    else
+       time_ahead -= timeout;
+    return time_ahead != 0;
 }
 
 /* If val is '0' or '1', set *var accordingly, otherwise toggle it.  */
 static void toggle(bool *var, char val)
 {
-  *var = val == '1' || (val != '0' && !*var);
+    *var = val == '1' || (val != '0' && !*var);
 }
 
 /* Handle input-related user settings and call dumb_output_handle_setting.  */
 bool dumb_handle_setting(const char *setting, bool show_cursor, bool startup)
 {
-  if (!strncmp(setting, "sf", 2)) {
-    speed = atof(&setting[2]);
-    printf("Speed Factor %g\n", speed);
-  } else if (!strncmp(setting, "mp", 2)) {
-    toggle(&do_more_prompts, setting[2]);
-    printf("More prompts %s\n", do_more_prompts ? "ON" : "OFF");
-  } else {
-    if (!strcmp(setting, "set")) {
-      printf("Speed Factor %g\n", speed);
-      printf("More Prompts %s\n", do_more_prompts ? "ON" : "OFF");
+    if (!strncmp(setting, "sf", 2)) {
+       speed = atof(&setting[2]);
+       printf("Speed Factor %g\n", speed);
+    } else if (!strncmp(setting, "mp", 2)) {
+       toggle(&do_more_prompts, setting[2]);
+       printf("More prompts %s\n", do_more_prompts ? "ON" : "OFF");
+    } else {
+       if (!strcmp(setting, "set")) {
+           printf("Speed Factor %g\n", speed);
+           printf("More Prompts %s\n", do_more_prompts ? "ON" : "OFF");
+       }
+       return dumb_output_handle_setting(setting, show_cursor, startup);
     }
-    return dumb_output_handle_setting(setting, show_cursor, startup);
-  }
-  return TRUE;
+    return TRUE;
 }
 
 /* Read a line, processing commands (lines that start with a backslash
@@ -260,6 +262,7 @@ static bool dumb_read_line(char *s, char *prompt, bool show_cursor,
          int i;
          for (i = 0; (i < h_screen_rows - 2) && *next_page; i++)
            next_page = strchr(next_page, '\n') + 1;
+         /* next_page - current_page is width */
          printf("%.*s", next_page - current_page, current_page);
          current_page = next_page;
          if (!*current_page)
@@ -425,4 +428,5 @@ void dumb_init_input(void)
 zword os_read_mouse(void)
 {
        /* NOT IMPLEMENTED */
+    return 0;
 }
index 2460e2cf8619644b449ba6da391f3f098a9d227c..0227464ab849cf0785839a5835af35a5f1bd4635 100644 (file)
@@ -69,49 +69,49 @@ static cell *dumb_row(int r) {return screen_data + r * h_screen_cols;}
 
 static char *dumb_changes_row(int r)
 {
-  return screen_changes + r * h_screen_cols;
+    return screen_changes + r * h_screen_cols;
 }
 
 int os_char_width (zchar z)
 {
-  if (plain_ascii && z >= ZC_LATIN1_MIN && z <= ZC_LATIN1_MAX) {
-    char *p = latin1_to_ascii + 4 * (z - ZC_LATIN1_MIN);
-    return strchr(p, ' ') - p;
-  }
-  return 1;
+    if (plain_ascii && z >= ZC_LATIN1_MIN && z <= ZC_LATIN1_MAX) {
+       char *p = latin1_to_ascii + 4 * (z - ZC_LATIN1_MIN);
+       return strchr(p, ' ') - p;
+    }
+    return 1;
 }
 
 int os_string_width (const zchar *s)
 {
-  int width = 0;
-  zchar c;
-
-  while ((c = *s++) != 0)
-    if (c == ZC_NEW_STYLE || c == ZC_NEW_FONT)
-      s++;
-    else
-      width += os_char_width(c);
-
-  return width;
+    int width = 0;
+    zchar c;
+
+    while ((c = *s++) != 0) {
+       if (c == ZC_NEW_STYLE || c == ZC_NEW_FONT)
+           s++;
+       else
+           width += os_char_width(c);
+    }
+    return width;
 }
 
 void os_set_cursor(int row, int col)
 {
-  cursor_row = row - 1; cursor_col = col - 1;
-  if (cursor_row >= h_screen_rows)
-    cursor_row = h_screen_rows - 1;
+    cursor_row = row - 1; cursor_col = col - 1;
+    if (cursor_row >= h_screen_rows)
+       cursor_row = h_screen_rows - 1;
 }
 
 /* Set a cell and update screen_changes.  */
 static void dumb_set_cell(int row, int col, cell c)
 {
-  dumb_changes_row(row)[col] = (c != dumb_row(row)[col]);
-  dumb_row(row)[col] = c;
+    dumb_changes_row(row)[col] = (c != dumb_row(row)[col]);
+    dumb_row(row)[col] = c;
 }
 
 void dumb_set_picture_cell(int row, int col, char c)
 {
-  dumb_set_cell(row, col, make_cell(PICTURE_STYLE, c));
+    dumb_set_cell(row, col, make_cell(PICTURE_STYLE, c));
 }
 
 /* Copy a cell and copy its changedness state.
@@ -119,33 +119,34 @@ void dumb_set_picture_cell(int row, int col, char c)
 static void dumb_copy_cell(int dest_row, int dest_col,
                           int src_row, int src_col)
 {
-  dumb_row(dest_row)[dest_col] = dumb_row(src_row)[src_col];
-  dumb_changes_row(dest_row)[dest_col] = dumb_changes_row(src_row)[src_col];
+    dumb_row(dest_row)[dest_col] = dumb_row(src_row)[src_col];
+    dumb_changes_row(dest_row)[dest_col] = dumb_changes_row(src_row)[src_col];
 }
 
 void os_set_text_style(int x)
 {
-  current_style = x & REVERSE_STYLE;
+    current_style = x & REVERSE_STYLE;
 }
 
 /* put a character in the cell at the cursor and advance the cursor.  */
 static void dumb_display_char(char c)
 {
-  dumb_set_cell(cursor_row, cursor_col, make_cell(current_style, c));
-  if (++cursor_col == h_screen_cols)
-    if (cursor_row == h_screen_rows - 1)
-      cursor_col--;
-    else {
-      cursor_row++;
-      cursor_col = 0;
+    dumb_set_cell(cursor_row, cursor_col, make_cell(current_style, c));
+    if (++cursor_col == h_screen_cols) {
+       if (cursor_row == h_screen_rows - 1)
+           cursor_col--;
+       else {
+           cursor_row++;
+           cursor_col = 0;
+       }
     }
 }
 
 void dumb_display_user_input(char *s)
 {
-  /* copy to screen without marking it as a change.  */
-  while (*s)
-    dumb_row(cursor_row)[cursor_col++] = make_cell(0, *s++);
+    /* copy to screen without marking it as a change.  */
+    while (*s)
+       dumb_row(cursor_row)[cursor_col++] = make_cell(0, *s++);
 }
 
 void dumb_discard_old_input(int num_chars)
@@ -153,30 +154,31 @@ void dumb_discard_old_input(int num_chars)
   /* Weird discard stuff.  Grep spec for 'pain in my butt'.  */
   /* The old characters should be on the screen just before the cursor.
    * Erase them.  */
-  cursor_col -= num_chars;
-  if (cursor_col < 0)
-    cursor_col = 0;
-  os_erase_area(cursor_row + 1, cursor_col + 1,
-               cursor_row + 1, cursor_col + num_chars, -1);
+    cursor_col -= num_chars;
+
+    if (cursor_col < 0)
+       cursor_col = 0;
+    os_erase_area(cursor_row + 1, cursor_col + 1,
+       cursor_row + 1, cursor_col + num_chars, -1);
 }
 
 void os_display_char (zchar c)
 {
-  if (c >= ZC_LATIN1_MIN && c <= ZC_LATIN1_MAX) {
-    if (plain_ascii) {
-      char *ptr = latin1_to_ascii + 4 * (c - ZC_LATIN1_MIN);
-      do
-       dumb_display_char(*ptr++);
-      while (*ptr != ' ');
-    } else
-      dumb_display_char(c);
-  } else if (c >= 32 && c <= 126) {
-    dumb_display_char(c);
-  } else if (c == ZC_GAP) {
-    dumb_display_char(' '); dumb_display_char(' ');
-  } else if (c == ZC_INDENT) {
-    dumb_display_char(' '); dumb_display_char(' '); dumb_display_char(' ');
-  }
+    if (c >= ZC_LATIN1_MIN && c <= ZC_LATIN1_MAX) {
+       if (plain_ascii) {
+           char *ptr = latin1_to_ascii + 4 * (c - ZC_LATIN1_MIN);
+           do
+               dumb_display_char(*ptr++);
+           while (*ptr != ' ');
+       } else
+           dumb_display_char(c);
+    } else if (c >= 32 && c <= 126) {
+       dumb_display_char(c);
+    } else if (c == ZC_GAP) {
+       dumb_display_char(' '); dumb_display_char(' ');
+    } else if (c == ZC_INDENT) {
+       dumb_display_char(' '); dumb_display_char(' '); dumb_display_char(' ');
+    }
   return;
 }
 
@@ -184,48 +186,54 @@ void os_display_char (zchar c)
 /* Haxor your boxor? */
 void os_display_string (const zchar *s)
 {
-  zchar c;
-
-  while ((c = *s++) != 0)
-    if (c == ZC_NEW_FONT)
-      s++;
-    else if (c == ZC_NEW_STYLE)
-      os_set_text_style(*s++);
-    else {
-     os_display_char (c);
-     }
+    zchar c;
+
+    while ((c = *s++) != 0) {
+       if (c == ZC_NEW_FONT)
+           s++;
+       else if (c == ZC_NEW_STYLE)
+           os_set_text_style(*s++);
+       else {
+           os_display_char (c);
+       }
+    }
 }
 
 void os_erase_area (int top, int left, int bottom, int right, int win)
 {
-  int row, col;
-  top--; left--; bottom--; right--;
-  for (row = top; row <= bottom; row++)
-    for (col = left; col <= right; col++)
-      dumb_set_cell(row, col, make_cell(current_style, ' '));
+    int row, col;
+    top--; left--; bottom--; right--;
+    for (row = top; row <= bottom; row++) {
+       for (col = left; col <= right; col++)
+           dumb_set_cell(row, col, make_cell(current_style, ' '));
+    }
 }
 
 void os_scroll_area (int top, int left, int bottom, int right, int units)
 {
-  int row, col;
-  top--; left--; bottom--; right--;
-  if (units > 0) {
-    for (row = top; row <= bottom - units; row++)
-      for (col = left; col <= right; col++)
-       dumb_copy_cell(row, col, row + units, col);
-    os_erase_area(bottom - units + 2, left + 1, bottom + 1, right + 1, -1 );
-  } else if (units < 0) {
-    for (row = bottom; row >= top - units; row--)
-      for (col = left; col <= right; col++)
-       dumb_copy_cell(row, col, row + units, col);
-    os_erase_area(top + 1, left + 1, top - units, right + 1 , -1);
-  }
+    int row, col;
+
+    top--; left--; bottom--; right--;
+
+    if (units > 0) {
+       for (row = top; row <= bottom - units; row++) {
+           for (col = left; col <= right; col++)
+               dumb_copy_cell(row, col, row + units, col);
+       }
+       os_erase_area(bottom - units + 2, left + 1, bottom + 1, right + 1, -1 );
+    } else if (units < 0) {
+       for (row = bottom; row >= top - units; row--) {
+           for (col = left; col <= right; col++)
+               dumb_copy_cell(row, col, row + units, col);
+       }
+       os_erase_area(top + 1, left + 1, top - units, right + 1 , -1);
+    }
 }
 
 int os_font_data(int font, int *height, int *width)
 {
     if (font == TEXT_FONT) {
-      *height = 1; *width = 1; return 1;
+       *height = 1; *width = 1; return 1;
     }
     return 0;
 }
@@ -236,87 +244,89 @@ void os_set_font (int x) {}
 /* Print a cell to stdout.  */
 static void show_cell(cell cel)
 {
-  char c = cell_char(cel);
-  switch (cell_style(cel)) {
-  case 0:
-    putchar(c);
-    break;
-  case PICTURE_STYLE:
-    putchar(show_pictures ? c : ' ');
-    break;
-  case REVERSE_STYLE:
-    if (c == ' ')
-      putchar(rv_blank_char);
-    else
-      switch (rv_mode) {
-      case RV_NONE: putchar(c); break;
-      case RV_CAPS: putchar(toupper(c)); break;
-      case RV_UNDERLINE: putchar('_'); putchar('\b'); putchar(c); break;
-      case RV_DOUBLESTRIKE: putchar(c); putchar('\b'); putchar(c); break;
-      }
-    break;
-  }
+    char c = cell_char(cel);
+    switch (cell_style(cel)) {
+    case 0:
+       putchar(c);
+       break;
+    case PICTURE_STYLE:
+       putchar(show_pictures ? c : ' ');
+       break;
+    case REVERSE_STYLE:
+       if (c == ' ')
+           putchar(rv_blank_char);
+       else
+           switch (rv_mode) {
+           case RV_NONE: putchar(c); break;
+           case RV_CAPS: putchar(toupper(c)); break;
+           case RV_UNDERLINE: putchar('_'); putchar('\b'); putchar(c); break;
+           case RV_DOUBLESTRIKE: putchar(c); putchar('\b'); putchar(c); break;
+           }
+       break;
+    }
 }
 
 static bool will_print_blank(cell c)
 {
-  return (((cell_style(c) == PICTURE_STYLE) && !show_pictures)
-         || ((cell_char(c) == ' ')
-             && ((cell_style(c) != REVERSE_STYLE) || (rv_blank_char == ' '))));
+    return (((cell_style(c) == PICTURE_STYLE) && !show_pictures)
+       || ((cell_char(c) == ' ')
+        && ((cell_style(c) != REVERSE_STYLE)
+       || (rv_blank_char == ' '))));
 }
 
 static void show_line_prefix(int row, char c)
 {
-  if (show_line_numbers)
-    printf((row == -1) ? ".." : "%02d", (row + 1) % 100);
-  if (show_line_types)
-    putchar(c);
-  /* Add a separator char (unless there's nothing to separate).  */
-  if (show_line_numbers || show_line_types)
-    putchar(' ');
+    if (show_line_numbers)
+       printf((row == -1) ? ".." : "%02d", (row + 1) % 100);
+    if (show_line_types)
+       putchar(c);
+    /* Add a separator char (unless there's nothing to separate).  */
+    if (show_line_numbers || show_line_types)
+       putchar(' ');
 }
 
 /* Print a row to stdout.  */
 static void show_row(int r)
 {
-  if (r == -1) {
-    show_line_prefix(-1, '.');
-  } else {
-    int c, last;
-    show_line_prefix(r, (r == cursor_row) ? ']' : ' ');
-    /* Don't print spaces at end of line.  */
-    /* (Saves bandwidth and printhead wear.)  */
-    /* TODO: compress spaces to tabs.  */
-    for (last = h_screen_cols - 1; last >= 0; last--)
-      if (!will_print_blank(dumb_row(r)[last]))
-         break;
-    for (c = 0; c <= last; c++)
-      show_cell(dumb_row(r)[c]);
-  }
-  putchar('\n');
+    if (r == -1) {
+       show_line_prefix(-1, '.');
+    } else {
+       int c, last;
+       show_line_prefix(r, (r == cursor_row) ? ']' : ' ');
+       /* Don't print spaces at end of line.  */
+       /* (Saves bandwidth and printhead wear.)  */
+       /* TODO: compress spaces to tabs.  */
+       for (last = h_screen_cols - 1; last >= 0; last--)
+           if (!will_print_blank(dumb_row(r)[last]))
+               break;
+       for (c = 0; c <= last; c++)
+           show_cell(dumb_row(r)[c]);
+    }
+    putchar('\n');
 }
 
 /* Print the part of the cursor row before the cursor.  */
 void dumb_show_prompt(bool show_cursor, char line_type)
 {
-  int i;
-  show_line_prefix(show_cursor ? cursor_row : -1, line_type);
-  if (show_cursor)
-    for (i = 0; i < cursor_col; i++)
-      show_cell(dumb_row(cursor_row)[i]);
+    int i;
+    show_line_prefix(show_cursor ? cursor_row : -1, line_type);
+    if (show_cursor) {
+       for (i = 0; i < cursor_col; i++)
+           show_cell(dumb_row(cursor_row)[i]);
+    }
 }
 
 static void mark_all_unchanged(void)
 {
-  memset(screen_changes, 0, screen_cells);
+    memset(screen_changes, 0, screen_cells);
 }
 
 /* Check if a cell is a blank or will display as one.
  * (Used to help decide if contents are worth printing.)  */
 static bool is_blank(cell c)
 {
-  return ((cell_char(c) == ' ')
-         || ((cell_style(c) == PICTURE_STYLE) && !show_pictures));
+    return ((cell_char(c) == ' ')
+       || ((cell_style(c) == PICTURE_STYLE) && !show_pictures));
 }
 
 /* Show the current screen contents, or what's changed since the last
@@ -328,94 +338,94 @@ static bool is_blank(cell c)
  * line just below it).  */
 void dumb_show_screen(bool show_cursor)
 {
-  int r, c, first, last;
-  char changed_rows[0x100];
+    int r, c, first, last;
+    char changed_rows[0x100];
+
+    /* Easy case */
+    if (compression_mode == COMPRESSION_NONE) {
+       for (r = hide_lines; r < h_screen_rows; r++)
+           show_row(r);
+       mark_all_unchanged();
+       return;
+    }
 
-  /* Easy case */
-  if (compression_mode == COMPRESSION_NONE) {
-    for (r = hide_lines; r < h_screen_rows; r++)
-      show_row(r);
-    mark_all_unchanged();
-    return;
-  }
-
-  /* Check which rows changed, and where the first and last change is.  */
-  first = last = -1;
-  memset(changed_rows, 0, h_screen_rows);
-  for (r = hide_lines; r < h_screen_rows; r++) {
-    for (c = 0; c < h_screen_cols; c++)
-      if (dumb_changes_row(r)[c] && !is_blank(dumb_row(r)[c]))
-       break;
-    changed_rows[r] = (c != h_screen_cols);
-    if (changed_rows[r]) {
-      first = (first != -1) ? first : r;
-      last = r;
+    /* Check which rows changed, and where the first and last change is.  */
+    first = last = -1;
+    memset(changed_rows, 0, h_screen_rows);
+    for (r = hide_lines; r < h_screen_rows; r++) {
+       for (c = 0; c < h_screen_cols; c++)
+           if (dumb_changes_row(r)[c] && !is_blank(dumb_row(r)[c]))
+               break;
+       changed_rows[r] = (c != h_screen_cols);
+       if (changed_rows[r]) {
+           first = (first != -1) ? first : r;
+           last = r;
+       }
     }
-  }
 
-  if (first == -1)
-    return;
+    if (first == -1)
+       return;
 
-  /* The show_cursor rule described above */
-  if (show_cursor && (cursor_row == last)) {
-    for (c = cursor_col; c < h_screen_cols; c++)
-      if (!is_blank(dumb_row(last)[c]))
-       break;
-    if (c == h_screen_cols)
-      last--;
-  }
-
-  /* Display the appropriate rows.  */
-  if (compression_mode == COMPRESSION_MAX) {
-    for (r = first; r <= last; r++)
-      if (changed_rows[r])
-       show_row(r);
-  } else {
-    /* COMPRESSION_SPANS */
-    for (r = first; r <= last; r++) {
-      if (changed_rows[r] || changed_rows[r + 1])
-       show_row(r);
-      else {
-       while (!changed_rows[r + 1])
-         r++;
-       show_row(-1);
-      }
+    /* The show_cursor rule described above */
+    if (show_cursor && (cursor_row == last)) {
+       for (c = cursor_col; c < h_screen_cols; c++)
+           if (!is_blank(dumb_row(last)[c]))
+               break;
+       if (c == h_screen_cols)
+           last--;
+    }
+
+    /* Display the appropriate rows.  */
+    if (compression_mode == COMPRESSION_MAX) {
+       for (r = first; r <= last; r++)
+           if (changed_rows[r])
+               show_row(r);
+    } else {
+       /* COMPRESSION_SPANS */
+       for (r = first; r <= last; r++) {
+           if (changed_rows[r] || changed_rows[r + 1])
+               show_row(r);
+           else {
+               while (!changed_rows[r + 1])
+                   r++;
+               show_row(-1);
+           }
+       }
+       if (show_cursor && (cursor_row > last + 1))
+           show_row((cursor_row == last + 2) ? (last + 1) : -1);
     }
-    if (show_cursor && (cursor_row > last + 1))
-      show_row((cursor_row == last + 2) ? (last + 1) : -1);
-  }
 
-  mark_all_unchanged();
+    mark_all_unchanged();
 }
 
 /* Unconditionally show whole screen.  For \s user command.  */
 void dumb_dump_screen(void)
 {
-  int r;
-  for (r = 0; r < h_screen_height; r++)
-    show_row(r);
+    int r;
+    for (r = 0; r < h_screen_height; r++)
+       show_row(r);
 }
 
 /* Called when it's time for a more prompt but user has them turned off.  */
 void dumb_elide_more_prompt(void)
 {
-  dumb_show_screen(FALSE);
-  if (compression_mode == COMPRESSION_SPANS && hide_lines == 0) {
-    show_row(-1);
-  }
+    dumb_show_screen(FALSE);
+    if (compression_mode == COMPRESSION_SPANS && hide_lines == 0) {
+       show_row(-1);
+    }
 }
 
 void os_reset_screen(void)
 {
-  dumb_show_screen(FALSE);
+    dumb_show_screen(FALSE);
 }
 
 void os_beep (int volume)
 {
-  if (visual_bell)
-    printf("[%s-PITCHED BEEP]\n", (volume == 1) ? "HIGH" : "LOW");
-  else
-    putchar('\a'); /* so much for dumb.  */
+    if (visual_bell)
+       printf("[%s-PITCHED BEEP]\n", (volume == 1) ? "HIGH" : "LOW");
+    else
+       putchar('\a'); /* so much for dumb.  */
 }
 
 
@@ -430,106 +440,103 @@ void os_stop_sample (int a) {}
 /* if val is '0' or '1', set *var accordingly, else toggle it.  */
 static void toggle(bool *var, char val)
 {
-  *var = val == '1' || (val != '0' && !*var);
+    *var = val == '1' || (val != '0' && !*var);
 }
 
 bool dumb_output_handle_setting(const char *setting, bool show_cursor,
                                bool startup)
 {
-  char *p;
-  int i;
-
-  if (!strncmp(setting, "pb", 2)) {
-    toggle(&show_pictures, setting[2]);
-    printf("Picture outlines display %s\n", show_pictures ? "ON" : "OFF");
-    if (startup)
-      return TRUE;
-    for (i = 0; i < screen_cells; i++)
-      screen_changes[i] = (cell_style(screen_data[i]) == PICTURE_STYLE);
-    dumb_show_screen(show_cursor);
-
-  } else if (!strncmp(setting, "vb", 2)) {
-    toggle(&visual_bell, setting[2]);
-    printf("Visual bell %s\n", visual_bell ? "ON" : "OFF");
-    os_beep(1); os_beep(2);
-
-  } else if (!strncmp(setting, "ln", 2)) {
-    toggle(&show_line_numbers, setting[2]);
-    printf("Line numbering %s\n", show_line_numbers ? "ON" : "OFF");
-
-  } else if (!strncmp(setting, "lt", 2)) {
-    toggle(&show_line_types, setting[2]);
-    printf("Line-type display %s\n", show_line_types ? "ON" : "OFF");
-
-  } else if (*setting == 'c') {
-    switch (setting[1]) {
-    case 'm': compression_mode = COMPRESSION_MAX; break;
-    case 's': compression_mode = COMPRESSION_SPANS; break;
-    case 'n': compression_mode = COMPRESSION_NONE; break;
-    case 'h': hide_lines = atoi(&setting[2]); break;
-    default: return FALSE;
-    }
-    printf("Compression mode %s, hiding top %d lines\n",
-          compression_names[compression_mode], hide_lines);
-
-  } else if (*setting == 'r') {
-    switch (setting[1]) {
-    case 'n': rv_mode = RV_NONE; break;
-    case 'o': rv_mode = RV_DOUBLESTRIKE; break;
-    case 'u': rv_mode = RV_UNDERLINE; break;
-    case 'c': rv_mode = RV_CAPS; break;
-    case 'b': rv_blank_char = setting[2] ? setting[2] : ' '; break;
-    default: return FALSE;
-    }
-    printf("Reverse-video mode %s, blanks reverse to '%c': ",
-          rv_names[rv_mode], rv_blank_char);
-    for (p = "sample reverse text"; *p; p++)
-      show_cell(make_cell(REVERSE_STYLE, *p));
-    putchar('\n');
-    for (i = 0; i < screen_cells; i++)
-      screen_changes[i] = (cell_style(screen_data[i]) == REVERSE_STYLE);
-    dumb_show_screen(show_cursor);
-
-  } else if (!strcmp(setting, "set")) {
-    printf("Compression Mode %s, hiding top %d lines\n",
-          compression_names[compression_mode], hide_lines);
-    printf("Picture Boxes display %s\n", show_pictures ? "ON" : "OFF");
-    printf("Visual Bell %s\n", visual_bell ? "ON" : "OFF");
-    os_beep(1); os_beep(2);
-    printf("Line Numbering %s\n", show_line_numbers ? "ON" : "OFF");
-    printf("Line-Type display %s\n", show_line_types ? "ON" : "OFF");
-    printf("Reverse-Video mode %s, Blanks reverse to '%c': ",
-          rv_names[rv_mode], rv_blank_char);
-    for (p = "sample reverse text"; *p; p++)
-      show_cell(make_cell(REVERSE_STYLE, *p));
-    putchar('\n');
-  } else
-    return FALSE;
-  return TRUE;
+    char *p;
+    int i;
+
+    if (!strncmp(setting, "pb", 2)) {
+       toggle(&show_pictures, setting[2]);
+       printf("Picture outlines display %s\n", show_pictures ? "ON" : "OFF");
+       if (startup)
+           return TRUE;
+       for (i = 0; i < screen_cells; i++)
+           screen_changes[i] = (cell_style(screen_data[i]) == PICTURE_STYLE);
+       dumb_show_screen(show_cursor);
+    } else if (!strncmp(setting, "vb", 2)) {
+       toggle(&visual_bell, setting[2]);
+       printf("Visual bell %s\n", visual_bell ? "ON" : "OFF");
+       os_beep(1); os_beep(2);
+    } else if (!strncmp(setting, "ln", 2)) {
+       toggle(&show_line_numbers, setting[2]);
+       printf("Line numbering %s\n", show_line_numbers ? "ON" : "OFF");
+    } else if (!strncmp(setting, "lt", 2)) {
+       toggle(&show_line_types, setting[2]);
+       printf("Line-type display %s\n", show_line_types ? "ON" : "OFF");
+
+    } else if (*setting == 'c') {
+       switch (setting[1]) {
+       case 'm': compression_mode = COMPRESSION_MAX; break;
+       case 's': compression_mode = COMPRESSION_SPANS; break;
+       case 'n': compression_mode = COMPRESSION_NONE; break;
+       case 'h': hide_lines = atoi(&setting[2]); break;
+       default: return FALSE;
+       }
+       printf("Compression mode %s, hiding top %d lines\n",
+           compression_names[compression_mode], hide_lines);
+    } else if (*setting == 'r') {
+       switch (setting[1]) {
+       case 'n': rv_mode = RV_NONE; break;
+       case 'o': rv_mode = RV_DOUBLESTRIKE; break;
+       case 'u': rv_mode = RV_UNDERLINE; break;
+       case 'c': rv_mode = RV_CAPS; break;
+       case 'b': rv_blank_char = setting[2] ? setting[2] : ' '; break;
+       default: return FALSE;
+       }
+       printf("Reverse-video mode %s, blanks reverse to '%c': ",
+           rv_names[rv_mode], rv_blank_char);
+
+       for (p = "sample reverse text"; *p; p++)
+           show_cell(make_cell(REVERSE_STYLE, *p));
+       putchar('\n');
+       for (i = 0; i < screen_cells; i++)
+           screen_changes[i] = (cell_style(screen_data[i]) == REVERSE_STYLE);
+       dumb_show_screen(show_cursor);
+    } else if (!strcmp(setting, "set")) {
+
+       printf("Compression Mode %s, hiding top %d lines\n",
+           compression_names[compression_mode], hide_lines);
+       printf("Picture Boxes display %s\n", show_pictures ? "ON" : "OFF");
+       printf("Visual Bell %s\n", visual_bell ? "ON" : "OFF");
+       os_beep(1); os_beep(2);
+       printf("Line Numbering %s\n", show_line_numbers ? "ON" : "OFF");
+       printf("Line-Type display %s\n", show_line_types ? "ON" : "OFF");
+       printf("Reverse-Video mode %s, Blanks reverse to '%c': ",
+           rv_names[rv_mode], rv_blank_char);
+       for (p = "sample reverse text"; *p; p++)
+           show_cell(make_cell(REVERSE_STYLE, *p));
+       putchar('\n');
+    } else
+       return FALSE;
+    return TRUE;
 }
 
 void dumb_init_output(void)
 {
-  if (h_version == V3) {
-    h_config |= CONFIG_SPLITSCREEN;
-    h_flags &= ~OLD_SOUND_FLAG;
-  }
+    if (h_version == V3) {
+       h_config |= CONFIG_SPLITSCREEN;
+       h_flags &= ~OLD_SOUND_FLAG;
+    }
 
-  if (h_version >= V5) {
-    h_flags &= ~SOUND_FLAG;
-  }
+    if (h_version >= V5) {
+       h_flags &= ~SOUND_FLAG;
+    }
 
-  h_screen_height = h_screen_rows;
-  h_screen_width = h_screen_cols;
-  screen_cells = h_screen_rows * h_screen_cols;
+    h_screen_height = h_screen_rows;
+    h_screen_width = h_screen_cols;
+    screen_cells = h_screen_rows * h_screen_cols;
 
-  h_font_width = 1; h_font_height = 1;
+    h_font_width = 1; h_font_height = 1;
 
-  if (show_line_types == -1)
-    show_line_types = h_version > 3;
+    if (show_line_types == -1)
+       show_line_types = h_version > 3;
 
-  screen_data = malloc(screen_cells * sizeof(cell));
-  screen_changes = malloc(screen_cells);
-  os_erase_area(1, 1, h_screen_rows, h_screen_cols, -2);
-  memset(screen_changes, 0, screen_cells);
+    screen_data = malloc(screen_cells * sizeof(cell));
+    screen_changes = malloc(screen_cells);
+    os_erase_area(1, 1, h_screen_rows, h_screen_cols, -2);
+    memset(screen_changes, 0, screen_cells);
 }
index c309522c003b731ae4b6a566a075d52c5b6e64f6..2071a5c18d3ecb2f88cb87880159ed70d13e3266 100644 (file)
@@ -19,135 +19,135 @@ f_setup_t f_setup;
 #define PIC_HEADER_HEIGHT 4
 
 static struct {
-  int z_num;
-  int width;
-  int height;
-  int orig_width;
-  int orig_height;
+    int z_num;
+    int width;
+    int height;
+    int orig_width;
+    int orig_height;
 } *pict_info;
 static int num_pictures = 0;
 
 static unsigned char lookupb(unsigned char *p, int n) {return p[n];}
 static unsigned short lookupw(unsigned char *p, int n)
 {
-  return (p[n + 1] << 8) | p[n];
+    return (p[n + 1] << 8) | p[n];
 }
 
 void dumb_init_pictures (char *filename)
 {
-  FILE *file = NULL;
-  int success = FALSE;
-  unsigned char gheader[16];
-  unsigned char *raw_info = NULL;
-  int i, entry_size, flags;
-  float x_scaler, y_scaler;
-
-  do {
-    if ((h_version != V6)
-       || !filename
-       || ((file = fopen (filename, "rb")) == NULL)
-       || (fread(&gheader, sizeof (gheader), 1, file) != 1))
-      break;
-
-    num_pictures = lookupw(gheader, PIC_FILE_HEADER_NUM_IMAGES);
-    entry_size = lookupb(gheader, PIC_FILE_HEADER_ENTRY_SIZE);
-    flags = lookupb(gheader, PIC_FILE_HEADER_FLAGS);
-
-    raw_info = malloc(num_pictures * entry_size);
-
-    if (fread(raw_info, num_pictures * entry_size, 1, file) != 1)
-      break;
-
-    pict_info = malloc((num_pictures + 1) * sizeof(*pict_info));
-    pict_info[0].z_num = 0;
-    pict_info[0].height = num_pictures;
-    pict_info[0].width = lookupw(gheader, PIC_FILE_HEADER_VERSION);
-
-    y_scaler = h_screen_rows / 200.0;
-    x_scaler = h_screen_cols / ((flags & 0x08) ? 640.0 : 320.0);
-
-    /* Copy and scale.  */
-    for (i = 1; i <= num_pictures; i++) {
-      unsigned char *p = raw_info + entry_size * (i - 1);
-      pict_info[i].z_num = lookupw(p, PIC_HEADER_NUMBER);
-      pict_info[i].orig_height = lookupw(p, PIC_HEADER_HEIGHT);
-      pict_info[i].orig_width = lookupw(p, PIC_HEADER_WIDTH);
-      pict_info[i].height = pict_info[i].orig_height * y_scaler + .5;
-      pict_info[i].width = pict_info[i].orig_width * x_scaler + .5;
-    }
-    success = TRUE;
-  } while (0);
-  if (file)
-    fclose(file);
-  if (raw_info)
-    free(raw_info);
-  if (success)
-    h_config |= CONFIG_PICTURES;
-  else
-    {
-      h_flags &= ~GRAPHICS_FLAG;
-      if (filename)
-       fprintf(stderr, "Warning: could not read graphics file %s\n", filename);
-    }
+    FILE *file = NULL;
+    int success = FALSE;
+    unsigned char gheader[16];
+    unsigned char *raw_info = NULL;
+    int i, entry_size, flags;
+    float x_scaler, y_scaler;
+
+    do {
+       if ((h_version != V6)
+           || !filename
+           || ((file = fopen (filename, "rb")) == NULL)
+           || (fread(&gheader, sizeof (gheader), 1, file) != 1))
+           break;
+
+       num_pictures = lookupw(gheader, PIC_FILE_HEADER_NUM_IMAGES);
+       entry_size = lookupb(gheader, PIC_FILE_HEADER_ENTRY_SIZE);
+       flags = lookupb(gheader, PIC_FILE_HEADER_FLAGS);
+
+       raw_info = malloc(num_pictures * entry_size);
+
+       if (fread(raw_info, num_pictures * entry_size, 1, file) != 1)
+           break;
+
+       pict_info = malloc((num_pictures + 1) * sizeof(*pict_info));
+       pict_info[0].z_num = 0;
+       pict_info[0].height = num_pictures;
+       pict_info[0].width = lookupw(gheader, PIC_FILE_HEADER_VERSION);
+
+       y_scaler = h_screen_rows / 200.0;
+       x_scaler = h_screen_cols / ((flags & 0x08) ? 640.0 : 320.0);
+
+       /* Copy and scale.  */
+       for (i = 1; i <= num_pictures; i++) {
+           unsigned char *p = raw_info + entry_size * (i - 1);
+           pict_info[i].z_num = lookupw(p, PIC_HEADER_NUMBER);
+           pict_info[i].orig_height = lookupw(p, PIC_HEADER_HEIGHT);
+           pict_info[i].orig_width = lookupw(p, PIC_HEADER_WIDTH);
+           pict_info[i].height = pict_info[i].orig_height * y_scaler + .5;
+           pict_info[i].width = pict_info[i].orig_width * x_scaler + .5;
+       }
+       success = TRUE;
+    } while (0);
+
+       if (file)
+           fclose(file);
+       if (raw_info)
+           free(raw_info);
+       if (success)
+           h_config |= CONFIG_PICTURES;
+       else {
+           h_flags &= ~GRAPHICS_FLAG;
+           if (filename)
+               fprintf(stderr, "Warning: could not read graphics file %s\n", filename);
+       }
 }
 
 /* Convert a Z picture number to an index into pict_info.  */
 static int z_num_to_index(int n)
 {
-  int i;
-  for (i = 0; i <= num_pictures; i++)
-    if (pict_info[i].z_num == n)
-      return i;
-  return -1;
+    int i;
+    for (i = 0; i <= num_pictures; i++)
+       if (pict_info[i].z_num == n)
+           return i;
+    return -1;
 }
 
 bool os_picture_data(int num, int *height, int *width)
 {
-  int index;
+    int index;
 
-  *height = 0;
-  *width = 0;
+    *height = 0;
+    *width = 0;
 
-  if (!pict_info)
-    return FALSE;
+    if (!pict_info)
+       return FALSE;
 
-  if ((index = z_num_to_index(num)) == -1)
-    return FALSE;
+    if ((index = z_num_to_index(num)) == -1)
+       return FALSE;
 
-  *height = pict_info[index].height;
-  *width = pict_info[index].width;
+    *height = pict_info[index].height;
+    *width = pict_info[index].width;
 
-  return TRUE;
+    return TRUE;
 }
 
 void os_draw_picture (int num, int row, int col)
 {
-  int width, height, r, c;
-  if (!os_picture_data(num, &height, &width) || !width || !height)
-    return;
-  col--, row--;
-  /* Draw corners */
-  dumb_set_picture_cell(row, col, '+');
-  dumb_set_picture_cell(row, col + width - 1, '+');
-  dumb_set_picture_cell(row + height - 1, col, '+');
-  dumb_set_picture_cell(row + height - 1, col + width - 1, '+');
-  /* sides */
-  for (c = col + 1; c < col + width - 1; c++) {
-    dumb_set_picture_cell(row, c, '-');
-    dumb_set_picture_cell(row + height - 1, c, '-');
-  }
-  for (r = row + 1; r < row + height - 1; r++) {
-    dumb_set_picture_cell(r, col, '|');
-    dumb_set_picture_cell(r, col + width - 1, '|');
-  }
-  /* body, but for last line */
-  for (r = row + 1; r < row + height - 2; r++)
-    for (c = col + 1; c < col + width - 1; c++)
-      dumb_set_picture_cell(r, c, ':');
-  /* Last line of body, including picture number.  */
-  if (height >= 3)
-    for (c = col + width - 2; c > col; c--, (num /= 10))
-      dumb_set_picture_cell(row + height - 2, c, num ? (num % 10 + '0') : ':');
+    int width, height, r, c;
+    if (!os_picture_data(num, &height, &width) || !width || !height)
+       return;
+    col--, row--;
+    /* Draw corners */
+    dumb_set_picture_cell(row, col, '+');
+    dumb_set_picture_cell(row, col + width - 1, '+');
+    dumb_set_picture_cell(row + height - 1, col, '+');
+    dumb_set_picture_cell(row + height - 1, col + width - 1, '+');
+    /* sides */
+    for (c = col + 1; c < col + width - 1; c++) {
+       dumb_set_picture_cell(row, c, '-');
+       dumb_set_picture_cell(row + height - 1, c, '-');
+    }
+    for (r = row + 1; r < row + height - 1; r++) {
+       dumb_set_picture_cell(r, col, '|');
+       dumb_set_picture_cell(r, col + width - 1, '|');
+    }
+    /* body, but for last line */
+    for (r = row + 1; r < row + height - 2; r++)
+       for (c = col + 1; c < col + width - 1; c++)
+           dumb_set_picture_cell(r, c, ':');
+    /* Last line of body, including picture number.  */
+    if (height >= 3)
+       for (c = col + width - 2; c > col; c--, (num /= 10))
+           dumb_set_picture_cell(row + height - 2, c, num ? (num % 10 + '0') : ':');
 }
 
 int os_peek_colour (void) {return BLACK_COLOUR; }