Rev 14165 | Rev 14711 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 14165 | Rev 14664 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | * the Free Software Foundation; either version 2 of the License, or |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
6 | * (at your option) any later version. |
7 | * |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
11 | * GNU General Public License for more details. |
12 | * |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Line 2038... | Line 2038... | ||
2038 | *find_word_end(p2)=0; |
2038 | *find_word_end(p2)=0; |
2039 | mystrncpy(p,p2,MAX_LINELEN); |
2039 | mystrncpy(p,p2,MAX_LINELEN); |
2040 | } |
2040 | } |
2041 | 2041 | ||
2042 | /* internal */ |
2042 | /* internal */ |
2043 | void _embraced(char buf[], void (app)(char *p)) |
2043 | static void _embraced(char buf[], void (app)(char *p)) |
2044 | { |
2044 | { |
2045 | char *p1, *p2, buf2[MAX_LINELEN+1]; |
2045 | char *p1, *p2, buf2[MAX_LINELEN+1]; |
2046 | for(p1=strchr(buf,'{'); p1; p1=strchr(p1,'{')) { |
2046 | for(p1=strchr(buf,'{'); p1; p1=strchr(p1,'{')) { |
2047 | p2=find_matching(p1+1,'}'); |
2047 | p2=find_matching(p1+1,'}'); |
2048 | if(p2==NULL) module_error("unmatched_parentheses"); |
2048 | if(p2==NULL) module_error("unmatched_parentheses"); |
2049 | *p2=0; mystrncpy(buf2,p1+1,sizeof(buf2)); app(buf2); |
2049 | *p2=0; mystrncpy(buf2,p1+1,sizeof(buf2)); app(buf2); |
2050 | string_modify(buf,p1,p2+1,buf2); |
2050 | string_modify(buf,p1,p2+1,buf2); |
- | 2051 | } |
|
- | 2052 | } |
|
- | 2053 | ||
- | 2054 | static void _embraced_tree(char buf[]) |
|
- | 2055 | { |
|
- | 2056 | char *p1, *p2, buf2[MAX_LINELEN+1]; |
|
- | 2057 | int nb, index; |
|
- | 2058 | for (p1=strchr(buf,'{'); p1; p1=strchr(buf,'{')){ |
|
- | 2059 | p2=find_matching(p1+1,'}'); |
|
- | 2060 | if(p2==NULL) module_error("unmatched_parentheses"); |
|
- | 2061 | *p2=0; nb=itemnum(p1+1); *p2='}'; index=(random()%nb)+1; |
|
- | 2062 | for (p1=strchr(buf,'{'); p1; p1=strchr(p1,'{')){ |
|
- | 2063 | p2=find_matching(p1+1,'}'); |
|
- | 2064 | if(p2==NULL) module_error("unmatched_parentheses"); |
|
- | 2065 | *p2=0; fnd_item(p1+1,index,buf2); |
|
- | 2066 | string_modify(buf,p1,p2+1,buf2); |
|
- | 2067 | p1+=strlen(buf2); |
|
- | 2068 | } |
|
2051 | } |
2069 | } |
2052 | } |
2070 | } |
2053 | 2071 | ||
2054 | /* embraced operations */ |
2072 | /* embraced operations */ |
2055 | void calc_embraced(char *p) |
2073 | void calc_embraced(char *p) |
Line 2062... | Line 2080... | ||
2062 | mystrncpy(buf,p2,sizeof(buf)); substit(buf); |
2080 | mystrncpy(buf,p2,sizeof(buf)); substit(buf); |
2063 | if(p1>p) ovlstrcpy(p,p1); |
2081 | if(p1>p) ovlstrcpy(p,p1); |
2064 | substit(p); |
2082 | substit(p); |
2065 | if(strcmp(p,"randitem")==0) {_embraced(buf,calc_randitem); goto end;} |
2083 | if(strcmp(p,"randitem")==0) {_embraced(buf,calc_randitem); goto end;} |
2066 | if(strcmp(p,"randrow")==0) {_embraced(buf,calc_randrow); goto end;} |
2084 | if(strcmp(p,"randrow")==0) {_embraced(buf,calc_randrow); goto end;} |
- | 2085 | if(strcmp(p,"linkedranditem")==0) {_embraced_tree(buf); goto end;} |
|
2067 | if(strcmp(p,"extract")==0) { |
2086 | if(strcmp(p,"extract")==0) { |
2068 | p1=strchr(buf,'{'); |
2087 | p1=strchr(buf,'{'); |
2069 | if(p1!=NULL) { |
2088 | if(p1!=NULL) { |
2070 | p2=find_matching(++p1,'}'); |
2089 | p2=find_matching(++p1,'}'); |
2071 | if(p2!=NULL) { |
2090 | if(p2!=NULL) { |
Line 2304... | Line 2323... | ||
2304 | {"select", 1, calc_select}, |
2323 | {"select", 1, calc_select}, |
2305 | {"sh", 0, calc_sh}, |
2324 | {"sh", 0, calc_sh}, |
2306 | {"shuffle", 0, calc_randperm}, |
2325 | {"shuffle", 0, calc_randperm}, |
2307 | {"singlespace", 0, singlespace}, |
2326 | {"singlespace", 0, singlespace}, |
2308 | {"slashsubst", 0, slashsubst}, |
2327 | {"slashsubst", 0, slashsubst}, |
2309 | {"solve", |
2328 | {"solve", 1, calc_solve}, |
2310 | {"sort", |
2329 | {"sort", 1, calc_sort}, |
2311 | /* {"sql", |
2330 | /* {"sql", 0, calc_sql}, */ |
2312 | {"staticinstex", 1, calc_instexst}, |
2331 | {"staticinstex", 1, calc_instexst}, |
2313 | {"stinstex", 1, calc_instexst}, |
2332 | {"stinstex", 1, calc_instexst}, |
2314 | {"subst", |
2333 | {"subst", 0, calc_subst}, |
2315 | {"substit", 0, calc_subst}, |
2334 | {"substit", 0, calc_subst}, |
2316 | {"substitute", 0, calc_subst}, |
2335 | {"substitute", 0, calc_subst}, |
2317 | {"sum", |
2336 | {"sum", 1, calc_sum}, |
2318 | {"system", 0, calc_sh}, |
2337 | {"system", 0, calc_sh}, |
2319 | {"texmath", 0, texmath}, |
2338 | {"texmath", 0, texmath}, |
2320 | {"text", |
2339 | {"text", 1, text}, |
2321 | {"tohex", |
2340 | {"tohex", 0, calc_hex}, |
2322 | {"tolower", 0, calc_tolower}, |
2341 | {"tolower", 0, calc_tolower}, |
2323 | {"toupper", 0, calc_toupper}, |
2342 | {"toupper", 0, calc_toupper}, |
2324 | {"translate", 1, calc_translate}, |
2343 | {"translate", 1, calc_translate}, |
2325 | {"trim", |
2344 | {"trim", 0, calc_trim}, |
2326 | {"unhttp", 0, calc_unhttp}, |
2345 | {"unhttp", 0, calc_unhttp}, |
2327 | {"upper", |
2346 | {"upper", 0, calc_toupper}, |
2328 | {"uppercase", 0, calc_toupper}, |
2347 | {"uppercase", 0, calc_toupper}, |
2329 | {"values", 1, calc_values}, |
2348 | {"values", 1, calc_values}, |
2330 | {"varlist", 0, mathvarlist}, |
2349 | {"varlist", 0, mathvarlist}, |
2331 | {"word", |
2350 | {"word", 1, calc_wordof}, |
2332 | {"wordcnt", 0, |
2351 | {"wordcnt", 0, calc_wordnum}, |
2333 | {"wordcount", 0, |
2352 | {"wordcount", 0,calc_wordnum}, |
2334 | {"wordno", 0, |
2353 | {"wordno", 0, calc_wordnum}, |
2335 | {"wordnum", 0, |
2354 | {"wordnum", 0, calc_wordnum}, |
2336 | {"words", |
2355 | {"words", 1, calc_wordof}, |
2337 | {"words2items", 0, |
2356 | {"words2items", 0, words2items}, |
2338 | {"words2lines", 0, |
2357 | {"words2lines", 0, words2lines}, |
2339 | {"words2list", 0, |
2358 | {"words2list", 0, words2items}, |
2340 | {"wordstoitems", 0, |
2359 | {"wordstoitems", 0,words2items}, |
2341 | {"wordstolines", 0, |
2360 | {"wordstolines", 0,words2lines}, |
2342 | {"wordstolist", 0, |
2361 | {"wordstolist", 0, words2items} |
2343 | }; |
2362 | }; |
2344 | int CALC_FN_NO=(sizeof(calc_routine)/sizeof(calc_routine[0])); |
2363 | int CALC_FN_NO=(sizeof(calc_routine)/sizeof(calc_routine[0])); |