]> mj.ucw.cz Git - umpf.git/blobdiff - umpf.h
fix many little bugs, release 0.1
[umpf.git] / umpf.h
diff --git a/umpf.h b/umpf.h
index b5b7df82d6d43b2f08765736077af9c6fd27ac5c..0d0697f6804d686a353559b41f6a83384f13afd5 100644 (file)
--- a/umpf.h
+++ b/umpf.h
@@ -1,9 +1,33 @@
+#include <setjmp.h>
 #include "lists.h"
 
+/* definitions of internal variables */
+#define INT_VAR_MAIL_LEN "MAIL_LEN"
+#define INT_VAR_LAST_EXIT "LAST_EXIT_CODE"
+#define INT_VAR_PIPE_RES "LAST_OUTPUT"
+
+/* umpf.c */
+jmp_buf env;
+
 /* cond.h */
 int yylex (void);
 void yyerror (char const *);
 
+enum keyword {
+       K_DISCARD,
+       K_COPY,
+       K_MAIL,
+       K_PIPE,
+       K_EMPTY,
+       K_FILTER
+};
+
+enum var_type {
+       VAR_HEADER,
+       VAR_INTERN,
+       VAR_USER
+};
+
 struct tree {
        enum {
                ST_IF,
@@ -53,8 +77,8 @@ struct tree {
                } leaf;
 
                struct {
-                       char* kw_left;
-                       char* kw_right; 
+                       enum keyword left;
+                       enum keyword right;
                        struct tree* s;
                } arrow;
 
@@ -73,62 +97,47 @@ struct tree* input_tree;
 #define CC(a,b) ((a<<8)|b)
 void* xmalloc(size_t size);
 void* xrealloc(void* buf, size_t size);
-char* xstrdup(char* s);
+char* xstrdup(const char* s);
 void __attribute__ ((noreturn)) die(char* msg, ...);
 void read_conf(char* filename);
 int line;
 FILE* conf;
 
-/* int.c */
-struct hlist {
-       struct node car;
-       char* name;
-       char* value;
-};
-
-struct email {
-       struct list* headers;
-       char* body;
-       int body_len;
-};
-
-struct action {
-       char* l;
-       char* r;
-       char* s;
-       struct email e;
-};
-
-/* ham.c */
-char* default_mailbox;
-
-struct list* current_headers;
-struct email* current_body;
-struct list* make_hlist(void);
-void print_headers(struct list* l);
-void do_action(struct action* a);
-struct email* get_body(void);
-
-/* lock.c */
-void save_gids(void);
-void close_mailbox(int fd, char* path, int is_default_mailbox);
-int open_mailbox(char* path, int is_default_mailbox);
-char* cat(char* l, char* r);
-
 /* code.c */
 #define BUFSIZE 4096 
+#define HASHSIZE 103
+#define MAGIC 19
+
 struct code {
        struct node car;
        enum {
-               SET,
-               JUMP,
-               JUMP_IF,
-               JUMP_UNLESS,
-               DELIVER,
-               CALL_EXT,
-               NOP,
-               CAT,
-               GT
+               OPC_SET,
+               OPC_JUMP,
+               OPC_JUMP_IF,
+               OPC_JUMP_UNLESS,
+               OPC_DELIVER,
+               OPC_NOP,
+               OPC_CAT,
+               OPC_GT,
+               OPC_LT,
+               OPC_LE,
+               OPC_GE,
+               OPC_EQ,
+               OPC_NEQ,
+               OPC_RE,
+               OPC_NRE,
+               OPC_AND,
+               OPC_OR,
+               OPC_XOR,
+               OPC_NOT,
+               OPC_PLUS,
+               OPC_MINUS,
+               OPC_MUL,
+               OPC_DIV,
+               OPC_PIPE,
+               OPC_MAIL,
+               OPC_FILTER,
+               OPC_DISCARD
        } opcode;
 
        union {
@@ -151,35 +160,96 @@ struct code {
                        int l;
                        int r;
                        int res; /* result */
-               } cat;
-               struct {
-               } nop;
+               } tpop;
                struct {
-                       int l;
-                       int r;
+                       int par;
                        int res; /* result */
-               } gt;
+               } dpop;
+               struct {
+                       int copy;
+                       int what;
+               } arrow;
+               struct {
+               } nop;
        } u;
 };
 
 struct variable {
        struct node car;
        char* name;
-       int varcode;    
+       int varcode;
+       enum var_type type;
+};
+
+struct vartab {
+       char* value;
+       int modif;
 };
 
 struct list input_code;
 struct list* var_hash;
 int current_varcode;
+int max_varcode;
 int temp_varcode_start;
-char** var_tab; 
+struct vartab* var_tab; 
 char** const_tab;
 int cur_const_n;
 int cur_const_s;
+char* empty;
 
 void init(void);
 void compile(struct tree* t, struct list* where);
-int find_var(char* name, struct list* hash);
+int find_var(char* name, enum var_type type, struct list* hash);
+struct variable* get_var_struct(char* name, enum var_type type, struct list* hash);
 int store_const(char* c);
 struct list* new_var_hash(void);
+int get_bucket_number(char* name);
 void print_code(void);
+
+/* int.c */
+struct hlist {
+       struct node car;
+       char* name;
+       char* value;
+       int have_var;
+};
+
+struct email {
+       struct list* headers;
+       char* body;
+       char* tmpfile;
+       int fd;
+       int body_len;
+};
+
+void save_current_headers(struct list* hash);
+void print_vars(struct list* hash);
+void interp(struct list* ins, struct list* hash);
+void free_string(char* c);
+void __attribute__ ((noreturn)) bye(int code, char* msg, ...);
+void set_cur_mail_length_var(int len, struct list* hash);
+
+/* ham.c */
+char* default_mailbox;
+int chars_written;
+int curr_email_len;
+char* fromline;
+
+struct list* current_headers;
+struct email* current_body;
+struct list* make_hlist(int fd);
+void new_header(char* buf, struct list* h);
+void print_headers(struct list* l);
+struct email* get_body(int fd);
+int deliver_local_email(char* folder, struct email* email);
+int write_email_to_fd(int fd, struct email* email);
+char* read_email(struct email* em);
+void open_email(void);
+
+/* lock.c */
+void save_gids(void);
+void close_mailbox(int fd, char* path, int is_default_mailbox);
+int open_mailbox(char* path, int is_default_mailbox);
+char* cat(char* l, char* r);
+
+