<commit_before>/* glulxdump.c: Glulx game file decompiler.
    Designed by <NAME> <<EMAIL>>
    http://eblong.com/zarf/glulx/index.html
*/

/* This program is very much a cheap hack. It is *not* a generic,
   neutral decompiler for any Glulx file in existence. It assumes
   that the Glulx file was generated by Glulx-Inform. (This, of
   course, is how it is able to display objects; there *are* no
   objects in the Glulx spec, but this program understands the
   tables that Inform generates.)

   We are making the following Inform-specific assumptions:

   1. ROM contains only the header, functions, and strings, plus
   some padding. (In that order.)
   2. All the functions and strings are in ROM, not RAM.
   3. When disassembling the contents of a function, a C0, C1,
   E0, or E1 byte signals the start of a new object. (This will be
   true unless we add opcodes that start with those bytes. Which
   may happen someday. In fact, an opcode such as add (10) could
   be represented as C0000010, which would also violate this
   assumption, but Inform does not do this.)
   4. The first object begins at the start of RAM.
   5. Objects contain seven bytes worth of attributes. (This is
   currently hardwired in Inform, but can be changed easily by
   changing a #define and recompiling.)
   6. Dictionary words are nine characters long, and have three
   two-byte fields appended.
   7. Probably other stuff I forgot.

   This whole situation could be improved by adding a "layout
   convention" field, at the start of ROM, which could contain
   compiler-specific information about how to decompile the file.
   Maybe someday.
*/

#include <stdio.h>
#include <stdlib.h>
#include "glk.h"

#include "opcodes.h"

/* We define our own TRUE and FALSE and NULL, because ANSI
    is a strange world. */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif

#define Read4(ptr)    \
  ( (glui32)(((unsigned char *)(ptr))[0] << 24)  \
  | (glui32)(((unsigned char *)(ptr))[1] << 16)  \
  | (glui32)(((unsigned char *)(ptr))[2] << 8)   \
  | (glui32)(((unsigned char *)(ptr))[3]))
#define Read2(ptr)    \
  ( (glui32)(((unsigned char *)(ptr))[0] << 8)  \<commit_msg>Update headers to be a little more modern, and include string.h. Also remove the dependency on glk.h.<commit_after>/* glulxdump.c: Glulx game file decompiler.
    Designed by <NAME> <<EMAIL>>
    http://eblong.com/zarf/glulx/index.html
*/

/* This program is very much a cheap hack. It is *not* a generic,
   neutral decompiler for any Glulx file in existence. It assumes
   that the Glulx file was generated by Glulx-Inform. (This, of
   course, is how it is able to display objects; there *are* no
   objects in the Glulx spec, but this program understands the
   tables that Inform generates.)

   We are making the following Inform-specific assumptions:

   1. ROM contains only the header, functions, and strings, plus
   some padding. (In that order.)
   2. All the functions and strings are in ROM, not RAM.
   3. When disassembling the contents of a function, a C0, C1,
   E0, or E1 byte signals the start of a new object. (This will be
   true unless we add opcodes that start with those bytes. Which
   may happen someday. In fact, an opcode such as add (10) could
   be represented as C0000010, which would also violate this
   assumption, but Inform does not do this.)
   4. The first object begins at the start of RAM.
   5. Objects contain seven bytes worth of attributes. (This is
   currently hardwired in Inform, but can be changed easily by
   changing a #define and recompiling.)
   6. Dictionary words are nine characters long, and have three
   two-byte fields appended.
   7. Probably other stuff I forgot.

   This whole situation could be improved by adding a "layout
   convention" field, at the start of ROM, which could contain
   compiler-specific information about how to decompile the file.
   Maybe someday.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* If your system doesn't have stdint.h, you'll have to edit the typedefs
   below to make unsigned and signed 32-bit integers. */
#include <stdint.h>
typedef uint32_t glui32;
typedef int32_t glsi32;

#include "opcodes.h"

/* We define our own TRUE and FALSE and NULL, because ANSI
    is a strange world. */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif

#define Read4(ptr)    \
  ( (glui32)(((unsigned char *)(ptr))[0] << 24)  \
  | (glui32)(((unsigned char *)(ptr))[1] << 16)  \
  | (glui32)(((unsigned char *)(ptr))[2] << 8)   \
  | (glui32)(((unsigned char *)(ptr))[3]))
#define Read2(ptr)    \
  ( (glui32)(((unsigned char *)(ptr))[0] << 8)  \
{'fraction_non_alphanumeric': 0.09611322348964935, 'fraction_numerical': 0.021546261089987327, 'mean_word_length': 3.396471680594243, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1241458', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1446, 'n_words': 674}