Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add "foreach" loops to TH1. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
3316b29225dc6048a8accf9a3466f47f |
| User & Date: | drh 2021-01-26 13:50:48.794 |
Context
|
2021-01-26
| ||
| 15:27 | Enhance 'fossil branch list' to accept a GLOB argument and show only matching branches. ... (check-in: 6a5cdecddc user: danield tags: trunk) | |
| 13:50 | Add "foreach" loops to TH1. ... (check-in: 3316b29225 user: drh tags: trunk) | |
| 13:45 | Added link to "git checkout" koan from the gitusers doc. ... (check-in: 57d9b020b8 user: wyoung tags: trunk) | |
Changes
Changes to src/th_lang.c.
| ︙ | ︙ | |||
160 161 162 163 164 165 166 167 168 169 170 171 172 173 | if( rc==TH_BREAK ) rc = TH_OK; return rc; } /* ** TH Syntax: ** ** list ?arg1 ?arg2? ...? */ static int list_command( Th_Interp *interp, void *ctx, int argc, | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
if( rc==TH_BREAK ) rc = TH_OK;
return rc;
}
/*
** TH Syntax:
**
** foreach VARLIST LIST SCRIPT
*/
static int foreach_command(
Th_Interp *interp,
void *ctx,
int argc,
const char **argv,
int *argl
){
int rc;
char **azVar = 0;
int *anVar;
int nVar;
char **azValue = 0;
int *anValue;
int nValue;
int ii, jj;
if( argc!=4 ){
return Th_WrongNumArgs(interp, "foreach varlist list script");
}
rc = Th_SplitList(interp, argv[1], argl[1], &azVar, &anVar, &nVar);
if( rc ) return rc;
rc = Th_SplitList(interp, argv[2], argl[2], &azValue, &anValue, &nValue);
for(ii=0; rc==TH_OK && ii<=nValue-nVar; ii+=nVar){
for(jj=0; jj<nVar; jj++){
Th_SetVar(interp, azVar[jj], anVar[jj], azValue[ii+jj], anValue[ii+jj]);
}
rc = eval_loopbody(interp, argv[3], argl[3]);
}
if( rc==TH_BREAK ) rc = TH_OK;
Th_Free(interp, azVar);
Th_Free(interp, azValue);
return rc;
}
/*
** TH Syntax:
**
** list ?arg1 ?arg2? ...?
*/
static int list_command(
Th_Interp *interp,
void *ctx,
int argc,
|
| ︙ | ︙ | |||
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
Th_CommandProc xProc;
void *pContext;
} aCommand[] = {
{"array", array_command, 0},
{"catch", catch_command, 0},
{"expr", expr_command, 0},
{"for", for_command, 0},
{"if", if_command, 0},
{"info", info_command, 0},
{"lindex", lindex_command, 0},
{"list", list_command, 0},
{"llength", llength_command, 0},
{"lsearch", lsearch_command, 0},
{"proc", proc_command, 0},
| > | 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 |
Th_CommandProc xProc;
void *pContext;
} aCommand[] = {
{"array", array_command, 0},
{"catch", catch_command, 0},
{"expr", expr_command, 0},
{"for", for_command, 0},
{"foreach", foreach_command, 0},
{"if", if_command, 0},
{"info", info_command, 0},
{"lindex", lindex_command, 0},
{"list", list_command, 0},
{"llength", llength_command, 0},
{"lsearch", lsearch_command, 0},
{"proc", proc_command, 0},
|
| ︙ | ︙ |
Changes to www/th1.md.
| ︙ | ︙ | |||
121 122 123 124 125 126 127 128 129 130 131 132 133 134 | * array names VARNAME * break * catch SCRIPT ?VARIABLE? * continue * error ?STRING? * expr EXPR * for INIT-SCRIPT TEST-EXPR NEXT-SCRIPT BODY-SCRIPT * if EXPR SCRIPT (elseif EXPR SCRIPT)* ?else SCRIPT? * info commands * info exists VARNAME * info vars * lindex LIST INDEX * list ARG ... * llength LIST | > | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | * array names VARNAME * break * catch SCRIPT ?VARIABLE? * continue * error ?STRING? * expr EXPR * for INIT-SCRIPT TEST-EXPR NEXT-SCRIPT BODY-SCRIPT * foreach VARIABLE-LIST VALUE-LIST BODY-SCRIPT * if EXPR SCRIPT (elseif EXPR SCRIPT)* ?else SCRIPT? * info commands * info exists VARNAME * info vars * lindex LIST INDEX * list ARG ... * llength LIST |
| ︙ | ︙ |