// Copyright status: this file is in the public domain. #include #include #include #include #include "lx.h" extern const char *__progname; static const char *defaults_string = "\ *Foreground: white\n\ *Background: black\n\ *BorderColor: white\n\ *BorderWidth: 1\n\ *BorderMargin: 0\n\ *Colours*Board: #b80\n\ *Colours*Lines: #000\n\ *Colours*Black: #000\n\ *Colours*White: #fff\n\ *Colours*Mark: #f00\n\ *Mag: 35\n\ *PieceSize: 80%\n\ *LineSize: 5%\n\ *StarSize: 10%\n\ "; typedef struct bqv BQV; typedef struct qv QV; struct bqv { LX_BOUNDQUARK *v; int a; } ; struct qv { LX_QUARK *v; int a; } ; static LX_DB *db; #define Cisspace(x) isspace((unsigned char)(x)) static void dump_value(const void *data, int len, FILE *to, int dq) { const unsigned char *dp; unsigned char c; int i; dp = data; for (i=0;i 126) && (c < 160))) { if ((i+1 < len) && (dp[i+1] >= '0') && (dp[i+1] <= '9')) { fprintf(to,"\\%03o",c); } else { fprintf(to,"\\%o",c); } } else { putc(c,to); } break; } } } static void print_value(const void *data, int len) { putchar('"'); dump_value(data,len,stdout,1); putchar('"'); } static int dump_db_1(void *cookie __attribute__((__unused__)), const LX_BOUNDQUARK *bqv, int nbq, const LX_DBVAL *val) { int i; for (i=0;is,val->l,stdout,0); putchar('\n'); return(0); } static void dump_db(LX_DB *db) { lx_db_map(db,&dump_db_1,0); } static void setup_db(void) { LX_DB *db2; int ec; char *str; char *home; char hostname[256]; int i; ec = 0; db = lx_db_from_string(defaults_string,-1,LX_DB_IGNORE_ERR|LX_DB_ERR_COUNT,&ec); if (!db || ec) { fprintf(stderr,"%s: invalid defaults string (error count = %d)\n",__progname,ec); exit(1); } printf("From string:\n"); dump_db(db); home = getenv("HOME"); if (home) { for (i=1;i>=0;i--) { switch (i) { case 1: str = malloc(strlen(home)+1+10+1); sprintf(str,"%s/.Xdefaults",home); break; case 0: gethostname(&hostname[0],(sizeof(hostname)/sizeof(hostname[0]))-1); hostname[(sizeof(hostname)/sizeof(hostname[0]))-1] = '\0'; str = malloc(strlen(home)+1+11+strlen(&hostname[0])+1); sprintf(str,"%s/.Xdefaults-%s",home,&hostname[0]); break; default: abort(); break; } ec = 0; db2 = lx_db_from_file(str,LX_DB_IGNORE_ERR|LX_DB_ERR_COUNT,&ec); if (db2) { if (ec) { fprintf(stderr,"%s: %s: invalid defaults file (error count = %d)\n",__progname,str,ec); } else { printf("From %s:\n",str); dump_db(db); lx_db_merge(db,db2); } lx_db_done(db2); } free(str); } } } int main(void); int main(void) { LX_QUARK nv[2]; LX_QUARK cv[2]; LX_DBVAL v; setup_db(); dump_db(db); if ( (lx_rm_q_string("xsgf.borderColor",-1,&nv[0],2) != 2) || (lx_rm_q_string("Game.BorderColor",-1,&cv[0],2) != 2) ) { printf("query quark strings: length wrong\n"); exit(1); } v = lx_db_query(db,&nv[0],&cv[0],2); if (v.l < 0) { printf("Query failed\n"); } else { printf("Query returned %d: ",v.l); print_value(v.s,v.l); putchar('\n'); } return(0); }