]> mj.ucw.cz Git - paperjam.git/blob - jam.h
b384ddde38a8d3cff2736dec4153a9df0cdad7a6
[paperjam.git] / jam.h
1 #include <vector>
2 #include <list>
3
4 using namespace std;
5
6 #include "pdf-tools.h"
7
8 typedef unsigned int uint;
9
10 #define NONRET __attribute__((noreturn))
11 #define UNUSED __attribute__((unused))
12
13 struct pipeline;
14 struct cmd;
15
16 enum arg_type {
17   AT_STRING,
18   AT_INT,
19   AT_DOUBLE,
20   AT_DIMEN,
21   AT_TYPE_MASK = 0xffff,
22   AT_MANDATORY = 0x10000,
23   AT_POSITIONAL = 0x20000,
24 };
25
26 struct arg_def {
27   const char *name;
28   uint type;
29 };
30
31 class arg_val {
32 public:
33   virtual bool given() { return false; }
34   virtual int as_int(int def) { return def; }
35   virtual double as_double(double def) { return def; }
36   virtual const string as_string(const string def) { return def; }
37   virtual string dump() { return "<undef>"; }
38 };
39
40 struct page_out {
41   QPDFObjectHandle resources;
42   QPDFObjectHandle xobjects;
43   string contents;
44   int res_cnt;
45   string new_resource(const string type);
46 };
47
48 struct page {
49   int index;
50   double width;
51   double height;
52   virtual void render(page_out *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
53   page(double _w=0, double _h=0) : width(_w), height(_h) { }
54 };
55
56 struct cmd_exec {
57   virtual vector<page *> process(vector <page *> &pages UNUSED) { abort(); }
58 };
59
60 struct cmd_def {
61   const char *name;
62   const arg_def *arg_defs;
63   bool has_pipeline;
64   cmd_exec *(*constructor)(cmd *cmd);
65 };
66
67 struct cmd {
68   const cmd_def *def;
69   vector<arg_val *> args;
70   pipeline *pipe;
71   cmd_exec *exec;
72 };
73
74 struct pipeline_selector {
75   int from;
76   int to;
77 };
78
79 struct pipeline_branch {
80   vector<pipeline_selector> selectors;
81   list<cmd *> commands;
82 };
83
84 struct pipeline {
85   vector<pipeline_branch *> branches;
86 };
87
88 // parse.cc
89
90 void parse(const char *in, list<cmd *> &cmds);
91
92 // cmds.cc
93
94 extern const cmd_def cmd_table[];