Fossil

Check-in [3b25f80e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:moved th1 argv funcs into their own registration unit. Renamed argv_getat to argv_at.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | th1-query-api
Files: files | file ages | folders
SHA1:3b25f80edd84de7c16494d3572aac5a49b925724
User & Date: stephan 2012-07-14 13:51:14
Context
2012-07-14
14:02
Refactored Th_ToXXX() to live on top of Th_TryXXX() to simplify some downstream code. check-in: 75540722 user: stephan tags: th1-query-api
13:51
moved th1 argv funcs into their own registration unit. Renamed argv_getat to argv_at. check-in: 3b25f80e user: stephan tags: th1-query-api
13:43
Refactored th1 function registration code to be reusable across modules. check-in: e923b4a6 user: stephan tags: th1-query-api
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th.h.

181
182
183
184
185
186
187

188
189
190
191
192
193
194
char *th_strdup(Th_Interp *interp, const char *z, int n);

/*
** Interfaces to register the language extensions.
*/
int th_register_language(Th_Interp *interp);            /* th_lang.c */
int th_register_sqlite(Th_Interp *interp);              /* th_main.c */

int th_register_vfs(Th_Interp *interp);                 /* th_vfs.c */
int th_register_testvfs(Th_Interp *interp);             /* th_testvfs.c */
int th_register_tcl(Th_Interp *interp, void *pContext); /* th_tcl.c */

/*
** General purpose hash table from th_lang.c.
*/







>







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
char *th_strdup(Th_Interp *interp, const char *z, int n);

/*
** Interfaces to register the language extensions.
*/
int th_register_language(Th_Interp *interp);            /* th_lang.c */
int th_register_sqlite(Th_Interp *interp);              /* th_main.c */
int th_register_argv(Th_Interp *interp);                /* th_main.c */
int th_register_vfs(Th_Interp *interp);                 /* th_vfs.c */
int th_register_testvfs(Th_Interp *interp);             /* th_testvfs.c */
int th_register_tcl(Th_Interp *interp, void *pContext); /* th_tcl.c */

/*
** General purpose hash table from th_lang.c.
*/

Changes to src/th_main.c.

708
709
710
711
712
713
714













715
716
717
718
719
720
721
....
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
....
1401
1402
1403
1404
1405
1406
1407



1408
1409
1410
1411
1412
1413
1414
....
1578
1579
1580
1581
1582
1583
1584

1585

1586
1587
1588
      return TH_ERROR;
    }
  }
  Th_ToInt(interp, zVal, strlen(zVal), &val);
  Th_SetResultInt( interp, val );
  return TH_OK;  
}













#endif
/* end TH_USE_ARGV */

#ifdef TH_USE_SQLITE
/*
** TH Syntax:
**
................................................................................
    {"htmlize",       htmlizeCmd,           0},
    {"date",          dateCmd,              0},
    {"html",          putsCmd,     &puts_Html},
    {"puts",          putsCmd,   &puts_Normal},
    {"wiki",          wikiCmd,              0},
    {"repository",    repositoryCmd,        0},

#ifdef TH_USE_ARGV
    {"argv_len",      argvArgcCmd,             0},
    {"argv_getat",    argvGetAtCmd,            0},
    {"argv_getstr",   argvFindOptionStringCmd, 0},
    {"argv_getbool",  argvFindOptionBoolCmd,   0},
    {"argv_getint",   argvFindOptionIntCmd,    0},
#endif

    {0, 0, 0}
  };
  if( g.interp==0 ){
    int i;
    if(g.cgiOutput){
      vtab.out.f = Th_output_f_cgi_content;
    }else{
................................................................................
    if( getenv("TH1_ENABLE_TCL")!=0 || db_get_boolean("tcl", 0) ){
      th_register_tcl(g.interp, &g.tcl);  /* Tcl integration commands. */
    }
#endif
#ifdef TH_USE_SQLITE
    th_register_sqlite(g.interp);
#endif



    Th_register_commands( g.interp, aCommand );
  }
}

/*
** Store a string value in a variable in the interpreter.
*/
................................................................................
  Blob in;
  if( g.argc<3 ){
    usage("FILE");
    assert(0 && "usage() does not return");
  }
  blob_zero(&in);
  db_open_config(0); /* Needed for global "tcl" setting. */

  db_find_and_open_repository(OPEN_ANY_SCHEMA,0) /* for query_xxx tests. */;

  blob_read_from_file(&in, g.argv[2]);
  Th_Render(blob_str(&in));
}







>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<







 







>
>
>







 







>
|
>



708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
....
1385
1386
1387
1388
1389
1390
1391








1392
1393
1394
1395
1396
1397
1398
....
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
....
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
      return TH_ERROR;
    }
  }
  Th_ToInt(interp, zVal, strlen(zVal), &val);
  Th_SetResultInt( interp, val );
  return TH_OK;  
}

int th_register_argv(Th_Interp *interp){
  static Th_Command_Reg aCommand[] = {
    {"argv_len",      argvArgcCmd,             0},
    {"argv_at",       argvGetAtCmd,            0},
    {"argv_getstr",   argvFindOptionStringCmd, 0},
    {"argv_getbool",  argvFindOptionBoolCmd,   0},
    {"argv_getint",   argvFindOptionIntCmd,    0},
    {0, 0, 0}
  };
  Th_register_commands( interp, aCommand );
}

#endif
/* end TH_USE_ARGV */

#ifdef TH_USE_SQLITE
/*
** TH Syntax:
**
................................................................................
    {"htmlize",       htmlizeCmd,           0},
    {"date",          dateCmd,              0},
    {"html",          putsCmd,     &puts_Html},
    {"puts",          putsCmd,   &puts_Normal},
    {"wiki",          wikiCmd,              0},
    {"repository",    repositoryCmd,        0},









    {0, 0, 0}
  };
  if( g.interp==0 ){
    int i;
    if(g.cgiOutput){
      vtab.out.f = Th_output_f_cgi_content;
    }else{
................................................................................
    if( getenv("TH1_ENABLE_TCL")!=0 || db_get_boolean("tcl", 0) ){
      th_register_tcl(g.interp, &g.tcl);  /* Tcl integration commands. */
    }
#endif
#ifdef TH_USE_SQLITE
    th_register_sqlite(g.interp);
#endif
#ifdef TH_USE_ARGV
    th_register_argv(g.interp);
#endif
    Th_register_commands( g.interp, aCommand );
  }
}

/*
** Store a string value in a variable in the interpreter.
*/
................................................................................
  Blob in;
  if( g.argc<3 ){
    usage("FILE");
    assert(0 && "usage() does not return");
  }
  blob_zero(&in);
  db_open_config(0); /* Needed for global "tcl" setting. */
#ifdef TH_USE_SQLITE
  db_find_and_open_repository(OPEN_ANY_SCHEMA,0) /* for query_xxx API. */;
#endif
  blob_read_from_file(&in, g.argv[2]);
  Th_Render(blob_str(&in));
}

Changes to test/th1-query-api-1.th1.

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    set x [lindex $consts $i]
    puts \$$x = [expr \$$x] "\n"
}

set ARGC [argv_len]
puts ARGC = $ARGC "\n"
for {set i 0} {$i < $ARGC} {incr i} {
    puts "argv_getat $i = " [argv_getat $i] \n
}

set magicDefault hi
set optA [argv_getstr AA a $magicDefault]
puts "argv_getstr AA = " $optA \n

set optA [argv_getbool BB b 0]







|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    set x [lindex $consts $i]
    puts \$$x = [expr \$$x] "\n"
}

set ARGC [argv_len]
puts ARGC = $ARGC "\n"
for {set i 0} {$i < $ARGC} {incr i} {
    puts "argv_at $i = " [argv_at $i] \n
}

set magicDefault hi
set optA [argv_getstr AA a $magicDefault]
puts "argv_getstr AA = " $optA \n

set optA [argv_getbool BB b 0]