X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Frsmain.c;h=fa52f81fb6481924da98b1407a477dace851450e;hb=9e57f1e2a73c8e8d69ee616672681bee29694afe;hp=2fc2bdfaeb7819bae3a3993155eb19ecaa99e23c;hpb=2204eb5e3fb843a426dbc0858fa91ce72d63cc73;p=ypp-sc-tools.db-test.git diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index 2fc2bdf..fa52f81 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -2,11 +2,19 @@ #include "rscommon.h" +#include + int o_quiet= 0; double max_mass=-1, max_volu=-1, max_capi=-1; double distance_loss_factor_per_league; int max_dist= -1; +FILE *debug_file; +FILE *output; + +DEBUG_DEFINE_SOME_DEBUGF(tableau,tabdebugf); + + #define CTR(x) int ctr_##x; COUNTER_LIST #undef CTR @@ -14,13 +22,15 @@ int max_dist= -1; static PotentialResult ****results; /* results[start_isle_ix][finalisle][midisle]-> */ +static pid_t debugoutpid; + int main(int argc, const char **argv) { const char *arg; + int i; #ifndef debug_flags debug_flags= ~( dbg_sql2 ); #endif - sysassert( !setvbuf(debug,0,_IOLBF,0) ); for (;;) { arg= *++argv; @@ -35,6 +45,35 @@ int main(int argc, const char **argv) { } } + if (debug_flags) { + /* glpk insists on writing stuff to stdout, and it does buffering, + * so we route all our debug through it this too */ + int realstdout; + sysassert( (realstdout= dup(1)) > 2 ); + sysassert( output= fdopen(realstdout,"w") ); + + int pfd[2]; + sysassert(! pipe(pfd) ); + sysassert( (debugoutpid= fork()) >=0 ); + if (!debugoutpid) { + sysassert( dup2(pfd[0],0)==0 ); + sysassert( dup2(2,1)==1 ); + sysassert(! close(pfd[0]) ); + sysassert(! close(pfd[1]) ); + sysassert(! execlp("cat","cat",(char*)0) ); + } + sysassert( dup2(pfd[1],1)==1 ); + sysassert(! close(pfd[0]) ); + sysassert(! close(pfd[1]) ); + + debug_file= stdout; + } else { + output= stdout; + debug_file= stderr; + } + + sysassert( !setvbuf(debug,0,_IOLBF,0) ); + max_mass= atof(*argv++); max_volu= atof(*argv++); max_capi= atof(*argv++); @@ -47,7 +86,9 @@ int main(int argc, const char **argv) { setup_value(); setup_search(); - fprintf(stderr,"setup complete, starting search\n"); + for (i=0; iabsolute < 100) fprintf(stderr,"| ."); - else fprintf(stderr,"|%3d",(int)(result->absolute / 100)); - fprintf(stderr," "); - if (result->perleague < 10) fprintf(stderr," ."); - else fprintf(stderr,"%3d",(int)(result->perleague / 10)); + tabdebugf("|%5d",(int)(result->absolute)); + tabdebugf(" "); + tabdebugf("%4d",(int)(result->perleague)); } } - fprintf(stderr,"\n"); + tabdebugf("\n"); } } + + int pos; +#define OUT(absperl) \ + fprintf(output,"\n================== " #absperl " ==================\n"); \ + for (pos=0; pospr; \ + if (!pr) continue; \ + const int *const ports= pr->absperl##_ports; \ + int nports; \ + for (nports=0; nports=0; nports++); \ + int finisle= ports[nports-1]; int finarch= isle2arch(finisle); \ + int midarch= route2midarch(ports,nports); \ + fprintf(output, \ + " @%2d #%2d | start%3d mid%d f%d:%3d | %5d %5d %4d |", \ + pos, nhighscores_##absperl - 1 - pos, \ + ports[0], midarch, finarch,finisle, \ + (int)hs->value, (int)pr->absolute, (int)pr->perleague); \ + for (i=0; i