X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Frscommon.h;h=d068fa02ba25a040eae556ebb3b278519f67a76e;hb=22f2c2e0c21461f4a5e78b9735bf6395cb7a367f;hp=871ee02e7e5cc494b82f71f8f95fac5e13483ee7;hpb=92f152ea77c2603539ab8d232a31cb7456f2ecb9;p=ypp-sc-tools.db-live.git diff --git a/yarrg/rscommon.h b/yarrg/rscommon.h index 871ee02..d068fa0 100644 --- a/yarrg/rscommon.h +++ b/yarrg/rscommon.h @@ -3,10 +3,54 @@ #include +#define DEBUG_FLAG_LIST \ + DF(sql) \ + DF(sql2) \ + DF(value) \ + DF(lp) +#define debug stdout + #include "common.h" -extern struct sqlite *db; -void value_route(int nislands, const int *islands); +#define SQL_MUST( call ) ({ \ + /* `call' is an expression returning result, using const char *sqe; \ + * chk1 and chk2 are blocks using sqe and int sqr; */ \ + const char *sql_must_call_string= #call; \ + int sqr; \ + if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string); \ + sqr= (call); \ + if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr); \ + if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string); \ + }) \ + +void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET; + +#define SQL_STEP(ssh) (sql_step_wrap((ssh), #ssh, __FILE__, __LINE__)) +int sql_step_wrap(sqlite3_stmt *ssh, const char *ssh_string, + const char *file, int line); + +int sql_single_int(const char *stmt); + +#define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss)) +sqlite3_stmt *sql_prepare(const char *stmt, const char *what); + +#define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value)) +void sql_bind(sqlite3_stmt *ss, int index, int value, + const char *ss_what, const char *val_what); + +#define MAX_ROUTELEN 20 + +extern sqlite3 *db; + +void setup(void); +double value_route(int nislands, const int *islands); +void setup_value(void); +void setup_commods(void); + +extern double max_mass, max_volu, max_capi; +extern double distance_loss_factor_per_league; + +#define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8) #endif /*RSCOMMON_H*/