]> mj.ucw.cz Git - paperjam.git/blobdiff - jam.h
Arg reform
[paperjam.git] / jam.h
diff --git a/jam.h b/jam.h
index f5ff88a3b4f71a640ea8338e796ed22944fd785e..dddaa81fb3e669416b527d44a12fdc0fd73c7c9c 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -1,25 +1,23 @@
 #include <vector>
 #include <list>
 
+using namespace std;
+
 #include "pdf-tools.h"
 
 typedef unsigned int uint;
 
 #define NONRET __attribute__((noreturn))
+#define UNUSED __attribute__((unused))
 
 struct pipeline;
-
-union arg_val {
-  string *s;
-  double d;
-  pipeline *p;
-};
+struct cmd;
 
 enum arg_type {
   AT_STRING,
+  AT_INT,
   AT_DOUBLE,
   AT_DIMEN,
-  AT_PIPELINE,                 // Pipeline has an empty name
   AT_TYPE_MASK = 0xffff,
   AT_MANDATORY = 0x10000,
   AT_POSITIONAL = 0x20000,
@@ -30,27 +28,47 @@ struct arg_def {
   uint type;
 };
 
+class arg_val {
+public:
+  virtual bool given() { return false; }
+  int as_int(int def) { return def; }
+  double as_double(double def) { return def; }
+  const string as_string(const string def) { return def; }
+  virtual string dump() { return "<undef>"; }
+};
+
 struct page_out {
+  QPDFObjectHandle resources;
+  QPDFObjectHandle xobjects;
+  string contents;
+  int res_cnt;
+  string new_resource(const string type);
 };
 
 struct page {
+  int index;
   double width;
   double height;
-  void render(page_out *out, pdf_matrix xform);
-};
-
-struct cmd {
+  virtual void render(page_out *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
+  page(double _w=0, double _h=0) : width(_w), height(_h) { }
 };
 
-struct cmd_args {
-  vector<arg_val> arg;
-  vector<bool> arg_given;
+struct cmd_exec {
+  virtual vector<page *> process(vector <page *> &pages UNUSED) { abort(); }
 };
 
 struct cmd_def {
   const char *name;
   const arg_def *arg_defs;
-  cmd (*constructor)(cmd_args *args);
+  bool has_pipeline;
+  cmd_exec *(*constructor)(cmd *cmd);
+};
+
+struct cmd {
+  const cmd_def *def;
+  vector<arg_val *> args;
+  pipeline *pipe;
+  cmd_exec *exec;
 };
 
 struct pipeline_selector {
@@ -60,9 +78,17 @@ struct pipeline_selector {
 
 struct pipeline_branch {
   vector<pipeline_selector> selectors;
-  list<cmd> commands;
+  list<cmd *> commands;
 };
 
 struct pipeline {
   vector<pipeline_branch *> branches;
 };
+
+// parse.cc
+
+void parse(const char *in, list<cmd *> &cmds);
+
+// cmds.cc
+
+extern const cmd_def cmd_table[];