2 * declarations common to
3 * - simple test program
12 #include <sys/types.h>
15 typedef struct ParseState ParseState;
16 typedef struct CmdInfo CmdInfo;
17 typedef struct Client Client;
19 extern const char *progname;
21 /*---------- types ----------*/
23 typedef unsigned char Byte;
25 #define COMMAND_ENCODED_MAX 16
26 #define NMRA_PACKET_MAX ((COMMAND_ENCODED_MAX*7 - 14) / 8)
29 Byte d[NMRA_PACKET_MAX];
33 typedef struct PicInsn {
34 Byte d[COMMAND_ENCODED_MAX];
38 /*---------- from parseutils.c ----------*/
41 Client *cl; /* used only by multiplexer */
47 void vbadcmd(ParseState *ps, const char *fmt, va_list al)
48 __attribute__((format(printf,2,0)));
49 void badcmd(ParseState *ps, const char *fmt, ...)
50 __attribute__((format(printf,2,3)));
52 int lstrstrcmp(const char *a, int la, const char *b);
53 int thiswordstrcmp(ParseState *ps, const char *b);
55 int ps_word(ParseState *ps);
56 int ps_needword(ParseState *ps);
57 int ps_needhextoend(ParseState *ps, Byte *dbuf, int *len_io);
58 int ps_neednumber(ParseState *ps, long *r, long min, long max, const char *wh);
59 int ps_neednoargs(ParseState *ps);
61 /*---------- macro for table lookups, with help from parseutils.c ----------*/
63 #define some_lookup(ps, infos) \
64 ((const typeof(infos[0])*) \
65 any_lookup((ps),(infos),sizeof((infos)[0])))
67 #define some_needword_lookup_counted(ps, infos, ninfos, what) \
68 ((const typeof(infos[0])*) \
69 any_needword_lookup((ps), \
70 (infos), (ninfos), sizeof((infos)[0]), \
73 #define some_needword_lookup(ps, infos, what) \
74 ((const typeof(infos[0])*) \
75 any_needword_lookup((ps),(infos),INT_MAX,sizeof((infos)[0]),(what)))
77 const void *any_lookup(ParseState *ps,
78 const void *infos, int ninfsmax, size_t infosz);
79 const void *any_needword_lookup(ParseState *ps, const void *infos,
80 int ninfsmax, size_t sz, const char *what);
82 /*---------- from client.c ----------*/
86 void (*fn)(ParseState *ps, const CmdInfo *ci);
90 void stdin_client(void);
92 extern const CmdInfo toplevel_cmds[]; /* defined in commands.c*/
94 /*---------- from utils.c ----------*/
96 void vdie(const char *fmt, int ev, va_list al)
97 __attribute__((noreturn,format(printf,1,0)));
98 void die(const char *fmt, ...) __attribute__((noreturn,format(printf,1,2)));
99 void diee(const char *fmt, ...) __attribute__((noreturn,format(printf,1,2)));
100 void diem(void) __attribute__((noreturn));
103 void die_vprintf_hook(const char *fmt, va_list al)
104 __attribute__((format(printf,1,0)));
106 void *mmalloc(size_t sz);
107 void *mrealloc(void *old, size_t sz);
108 char *mstrdupl(const char *s, int l);
109 char *mstrdup(const char *s);
110 void mgettimeofday(struct timeval *tv);
112 void mrename(const char *old, const char *new);
114 void badusage(const char *why);
116 #define massert(x) ((x) ? (void)0 : diem())
118 /*---------- from serialio.c ----------*/
120 void serial_open(const char *device);
121 void serial_transmit_now(const Byte *command, int length);
123 extern int serial_fd, serial_fudge_delay;
125 /*---------- nmra parsing, nmra.c et al ----------*/
127 typedef struct NmraParseEncodeCaller NmraParseEncodeCaller;
128 void nmra_parse_encode(Nmra *out, const char *arg, int argl,
129 int argc, NmraParseEncodeCaller *pec);
130 /* will call back to these, supplied by caller: */
131 unsigned long nmra_argnumber(NmraParseEncodeCaller *pec, int argi);
132 void nmra_problem(NmraParseEncodeCaller *pec, const char *problem);
134 void nmra_addchecksum(Nmra *packet);
135 void nmra_encodeforpic(const Nmra *packet, PicInsn *pi_out);
138 #define ARRAY_SIZE(a) (sizeof((a))/sizeof(*(a)))
139 #define ARRAY_END(a) ((a) + ARRAY_SIZE((a)))