chiark / gitweb /
860409e41a99ea0e6a7a06f3ed4b756344f6c3fe
[ypp-sc-tools.main.git] / yarrg / rscommon.h
1 #ifndef RSCOMMON_H
2 #define RSCOMMON_H
3
4 #include <sqlite3.h>
5
6 #define DEBUG_FLAG_LIST                         \
7    DF(sql)                                      \
8    DF(sql2)                                     \
9    DF(value)                                    \
10    DF(lp)
11 #define debug stdout
12
13 #include "common.h"
14
15
16 #define SQL_MUST( call ) ({                                              \
17     /* `call' is an expression returning result, using  const char *sqe; \
18      * chk1 and chk2 are blocks using sqe and  int sqr; */               \
19     const char *sql_must_call_string= #call;                             \
20     int sqr;                                                             \
21     if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string);    \
22     sqr= (call);                                                         \
23     if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr);                    \
24     if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string);          \
25   })                                                                     \
26
27 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
28
29 #define SQL_STEP(ssh) (sql_step_wrap((ssh), #ssh, __FILE__, __LINE__))
30 int sql_step_wrap(sqlite3_stmt *ssh, const char *ssh_string,
31                   const char *file, int line);
32
33 int sql_single_int(const char *stmt);
34
35 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
36 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
37
38 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
39 void sql_bind(sqlite3_stmt *ss, int index, int value,
40               const char *ss_what, const char *val_what);
41
42 #define MAX_ROUTELEN 20
43
44 extern sqlite3 *db;
45
46 void setup(void);
47 double value_route(int nislands, const int *islands);
48 void setup_value(void);
49 void setup_commods(void);
50
51 extern double max_mass, max_volu, max_capi;
52 extern double distance_loss_factor_per_league;
53
54 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e8)
55
56 #endif /*RSCOMMON_H*/