aboutsummaryrefslogtreecommitdiff
path: root/src/wmap_parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wmap_parser.h')
-rw-r--r--src/wmap_parser.h164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/wmap_parser.h b/src/wmap_parser.h
new file mode 100644
index 0000000..fa4371b
--- /dev/null
+++ b/src/wmap_parser.h
@@ -0,0 +1,164 @@
+#ifndef WMAP_PARSER_H
+#define WMAP_PARSER_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#define WMAP_MAX_NAME_LEN 64
+#define WMAP_MAX_TEXT_LEN 256
+#define WMAP_MAX_COMPONENTS 1024
+#define WMAP_MAX_DEPENDENCIES 2048
+#define WMAP_MAX_NOTES 256
+#define WMAP_MAX_STAGES 4
+#define WMAP_MAX_GROUPS 128
+#define WMAP_MAX_GROUP_MEMBERS 32
+#define WMAP_MAX_INERTIAS 256
+#define WMAP_MAX_EVOLUTIONS 256
+
+#ifdef __mc68000__
+#define WMAP_68K_INLINE static
+#define WMAP_68K_FAST_CALL __attribute__((regparm(2)))
+#else
+#define WMAP_68K_INLINE static
+#define WMAP_68K_FAST_CALL
+#endif
+
+/* Public Types */
+
+typedef enum {
+ WMAP_SHAPE_NONE = 0,
+ WMAP_SHAPE_X,
+ WMAP_SHAPE_SQUARE,
+ WMAP_SHAPE_TRIANGLE,
+ WMAP_SHAPE_CIRCLE
+} wmap_shape_t;
+
+typedef enum {
+ WMAP_STAGE_I = 1,
+ WMAP_STAGE_II = 2,
+ WMAP_STAGE_III = 3,
+ WMAP_STAGE_IV = 4
+} wmap_stage_t;
+
+typedef struct {
+ char name[WMAP_MAX_NAME_LEN];
+ float x, y;
+ wmap_shape_t shape;
+} wmap_component_t;
+
+typedef struct {
+ char from[WMAP_MAX_NAME_LEN];
+ char to[WMAP_MAX_NAME_LEN];
+ int is_arrow;
+} wmap_dependency_t;
+
+typedef struct {
+ float x, y;
+ char text[WMAP_MAX_TEXT_LEN];
+} wmap_note_t;
+
+typedef struct {
+ wmap_stage_t stage;
+ float value;
+} wmap_stage_data_t;
+
+typedef struct {
+ char members[WMAP_MAX_GROUP_MEMBERS][WMAP_MAX_NAME_LEN];
+ int member_count;
+} wmap_group_t;
+
+typedef struct {
+ char name[WMAP_MAX_NAME_LEN];
+} wmap_inertia_t;
+
+typedef struct {
+ char name[WMAP_MAX_NAME_LEN];
+ float change;
+} wmap_evolution_t;
+
+typedef struct {
+ wmap_component_t components[WMAP_MAX_COMPONENTS];
+ wmap_dependency_t dependencies[WMAP_MAX_DEPENDENCIES];
+ wmap_note_t notes[WMAP_MAX_NOTES];
+ wmap_stage_data_t stages[WMAP_MAX_STAGES];
+ wmap_group_t groups[WMAP_MAX_GROUPS];
+ wmap_inertia_t inertias[WMAP_MAX_INERTIAS];
+ wmap_evolution_t evolutions[WMAP_MAX_EVOLUTIONS];
+
+ int component_count;
+ int dependency_count;
+ int note_count;
+ int stage_count;
+ int group_count;
+ int inertia_count;
+ int evolution_count;
+} wmap_map_t;
+
+/* Internal Types (needed for implementation) */
+
+typedef enum {
+ WMAP_TOKEN_EOF = 0,
+ WMAP_TOKEN_IDENTIFIER,
+ WMAP_TOKEN_NUMBER,
+ WMAP_TOKEN_LPAREN,
+ WMAP_TOKEN_RPAREN,
+ WMAP_TOKEN_LBRACKET,
+ WMAP_TOKEN_RBRACKET,
+ WMAP_TOKEN_COMMA,
+ WMAP_TOKEN_ARROW,
+ WMAP_TOKEN_DASH,
+ WMAP_TOKEN_PLUS,
+ WMAP_TOKEN_MINUS,
+ WMAP_TOKEN_NEWLINE,
+ WMAP_TOKEN_ERROR
+} wmap_token_type_t;
+
+typedef struct {
+ const char* input;
+ int pos;
+ int line;
+ int col;
+ wmap_token_type_t current_token;
+ char token_text[WMAP_MAX_NAME_LEN];
+ float token_number;
+} wmap_lexer_t;
+
+typedef struct {
+ wmap_lexer_t lexer;
+ wmap_map_t* map;
+ int error_count;
+} wmap_parser_t;
+
+/* Public API */
+
+/**
+ * Parse WMAP content from a string
+ * @param input The WMAP content as a null-terminated string
+ * @return Pointer to parsed map structure, or NULL on failure
+ */
+wmap_map_t* wmap_parse_string(const char* input);
+
+/**
+ * Parse WMAP content from a file
+ * @param filename Path to the WMAP file
+ * @return Pointer to parsed map structure, or NULL on failure
+ */
+wmap_map_t* wmap_parse_file(const char* filename);
+
+/**
+ * Free memory allocated for a parsed map
+ * @param map Pointer to the map structure to free
+ */
+void wmap_map_free(wmap_map_t* map);
+
+/**
+ * Validate input size and format before parsing
+ * @param input The input string to validate
+ * @param max_size Maximum allowed size in bytes
+ * @return 1 if valid, 0 if invalid
+ */
+int wmap_validate_input(const char* input, size_t max_size);
+
+#endif