]> mj.ucw.cz Git - paperjam.git/blob - jam.h
6fa314ceaa77308aa01b66cae6fb943054a81287
[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_DOUBLE,
19   AT_DIMEN,
20   AT_TYPE_MASK = 0xffff,
21   AT_MANDATORY = 0x10000,
22   AT_POSITIONAL = 0x20000,
23 };
24
25 struct arg_def {
26   const char *name;
27   uint type;
28 };
29
30 class arg_val {
31 public:
32   virtual bool given() { return false; }
33   explicit virtual operator double() { abort(); }
34   explicit virtual operator string() { abort(); }
35   double double_default(double def) { return given() ? (double) *this : def; }
36   const string string_default(const string def) { return given() ? (string) *this : def; }
37   virtual string dump() { return "<undef>"; }
38 };
39
40 struct page_out {
41 };
42
43 struct page {
44   double width;
45   double height;
46   void render(page_out *out, pdf_matrix xform);
47 };
48
49 struct cmd_exec {
50 };
51
52 struct cmd_def {
53   const char *name;
54   const arg_def *arg_defs;
55   bool has_pipeline;
56   cmd_exec *(*constructor)(cmd *cmd);
57 };
58
59 struct cmd {
60   const cmd_def *def;
61   vector<arg_val *> args;
62   pipeline *pipe;
63   cmd_exec *exec;
64 };
65
66 struct pipeline_selector {
67   int from;
68   int to;
69 };
70
71 struct pipeline_branch {
72   vector<pipeline_selector> selectors;
73   list<cmd *> commands;
74 };
75
76 struct pipeline {
77   vector<pipeline_branch *> branches;
78 };
79
80 // parse.cc
81
82 void parse(const char *in, list<cmd *> *cmds);
83
84 // cmds.cc
85
86 extern const cmd_def cmd_table[];