Fossil SCM

Refactored th1 argv_xxx to (argv xxx). Added th1_argv.wiki doc.

stephan 2012-07-14 21:13 th1-query-api
Commit 615ee71798931eec18ef34a64b3ac2c019f9b216
+19 -5
--- src/th_main.c
+++ src/th_main.c
@@ -724,18 +724,32 @@
724724
}
725725
Th_ToInt(interp, zVal, strlen(zVal), &val);
726726
Th_SetResultInt( interp, val );
727727
return TH_OK;
728728
}
729
+
730
+static int argvTopLevelCmd(
731
+ Th_Interp *interp,
732
+ void *ctx,
733
+ int argc,
734
+ const char **argv,
735
+ int *argl
736
+){
737
+ static Th_SubCommand aSub[] = {
738
+ {"len", argvArgcCmd},
739
+ {"at", argvGetAtCmd},
740
+ {"getstr", argvFindOptionStringCmd},
741
+ {"getbool", argvFindOptionBoolCmd},
742
+ {"getint", argvFindOptionIntCmd},
743
+ {0, 0}
744
+ };
745
+ Th_CallSubCommand2( interp, ctx, argc, argv, argl, aSub );
746
+}
729747
730748
int th_register_argv(Th_Interp *interp){
731749
static Th_Command_Reg aCommand[] = {
732
- {"argv_len", argvArgcCmd, 0},
733
- {"argv_at", argvGetAtCmd, 0},
734
- {"argv_getstr", argvFindOptionStringCmd, 0},
735
- {"argv_getbool", argvFindOptionBoolCmd, 0},
736
- {"argv_getint", argvFindOptionIntCmd, 0},
750
+ {"argv", argvTopLevelCmd, 0 },
737751
{0, 0, 0}
738752
};
739753
Th_register_commands( interp, aCommand );
740754
}
741755
742756
--- src/th_main.c
+++ src/th_main.c
@@ -724,18 +724,32 @@
724 }
725 Th_ToInt(interp, zVal, strlen(zVal), &val);
726 Th_SetResultInt( interp, val );
727 return TH_OK;
728 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
730 int th_register_argv(Th_Interp *interp){
731 static Th_Command_Reg aCommand[] = {
732 {"argv_len", argvArgcCmd, 0},
733 {"argv_at", argvGetAtCmd, 0},
734 {"argv_getstr", argvFindOptionStringCmd, 0},
735 {"argv_getbool", argvFindOptionBoolCmd, 0},
736 {"argv_getint", argvFindOptionIntCmd, 0},
737 {0, 0, 0}
738 };
739 Th_register_commands( interp, aCommand );
740 }
741
742
--- src/th_main.c
+++ src/th_main.c
@@ -724,18 +724,32 @@
724 }
725 Th_ToInt(interp, zVal, strlen(zVal), &val);
726 Th_SetResultInt( interp, val );
727 return TH_OK;
728 }
729
730 static int argvTopLevelCmd(
731 Th_Interp *interp,
732 void *ctx,
733 int argc,
734 const char **argv,
735 int *argl
736 ){
737 static Th_SubCommand aSub[] = {
738 {"len", argvArgcCmd},
739 {"at", argvGetAtCmd},
740 {"getstr", argvFindOptionStringCmd},
741 {"getbool", argvFindOptionBoolCmd},
742 {"getint", argvFindOptionIntCmd},
743 {0, 0}
744 };
745 Th_CallSubCommand2( interp, ctx, argc, argv, argl, aSub );
746 }
747
748 int th_register_argv(Th_Interp *interp){
749 static Th_Command_Reg aCommand[] = {
750 {"argv", argvTopLevelCmd, 0 },
 
 
 
 
751 {0, 0, 0}
752 };
753 Th_register_commands( interp, aCommand );
754 }
755
756
--- test/th1-query-api-1.th1
+++ test/th1-query-api-1.th1
@@ -113,26 +113,26 @@
113113
for {set i 0} {$i < [llength $consts]} {incr i} {
114114
set x [lindex $consts $i]
115115
puts \$$x = [expr \$$x] "\n"
116116
}
117117
118
-set ARGC [argv_len]
118
+set ARGC [argv len]
119119
puts ARGC = $ARGC "\n"
120120
for {set i 0} {$i < $ARGC} {incr i} {
121
- puts "argv_at $i = " [argv_at $i] \n
121
+ puts "argv at $i = " [argv at $i] \n
122122
}
123123
124124
set magicDefault hi
125
-set optA [argv_getstr AA a $magicDefault]
126
-puts "argv_getstr AA = " $optA \n
125
+set optA [argv getstr AA a $magicDefault]
126
+puts "argv getstr AA = " $optA \n
127127
128
-set optA [argv_getbool BB b 0]
129
-puts "argv_getbool BB = " $optA \n
128
+set optA [argv getbool BB b 0]
129
+puts "argv getbool BB = " $optA \n
130130
131131
set exception 0
132132
catch {
133
- argv_getint noSuchOptionAndNoDefault
133
+ argv getint noSuchOptionAndNoDefault
134134
} exception
135135
puts exception = $exception "\n"
136136
137137
enable_output 1
138138
139139
140140
ADDED www/th1_argv.wiki
--- test/th1-query-api-1.th1
+++ test/th1-query-api-1.th1
@@ -113,26 +113,26 @@
113 for {set i 0} {$i < [llength $consts]} {incr i} {
114 set x [lindex $consts $i]
115 puts \$$x = [expr \$$x] "\n"
116 }
117
118 set ARGC [argv_len]
119 puts ARGC = $ARGC "\n"
120 for {set i 0} {$i < $ARGC} {incr i} {
121 puts "argv_at $i = " [argv_at $i] \n
122 }
123
124 set magicDefault hi
125 set optA [argv_getstr AA a $magicDefault]
126 puts "argv_getstr AA = " $optA \n
127
128 set optA [argv_getbool BB b 0]
129 puts "argv_getbool BB = " $optA \n
130
131 set exception 0
132 catch {
133 argv_getint noSuchOptionAndNoDefault
134 } exception
135 puts exception = $exception "\n"
136
137 enable_output 1
138
139
140 DDED www/th1_argv.wiki
--- test/th1-query-api-1.th1
+++ test/th1-query-api-1.th1
@@ -113,26 +113,26 @@
113 for {set i 0} {$i < [llength $consts]} {incr i} {
114 set x [lindex $consts $i]
115 puts \$$x = [expr \$$x] "\n"
116 }
117
118 set ARGC [argv len]
119 puts ARGC = $ARGC "\n"
120 for {set i 0} {$i < $ARGC} {incr i} {
121 puts "argv at $i = " [argv at $i] \n
122 }
123
124 set magicDefault hi
125 set optA [argv getstr AA a $magicDefault]
126 puts "argv getstr AA = " $optA \n
127
128 set optA [argv getbool BB b 0]
129 puts "argv getbool BB = " $optA \n
130
131 set exception 0
132 catch {
133 argv getint noSuchOptionAndNoDefault
134 } exception
135 puts exception = $exception "\n"
136
137 enable_output 1
138
139
140 DDED www/th1_argv.wiki
--- a/www/th1_argv.wiki
+++ b/www/th1_argv.wiki
@@ -0,0 +1,58 @@
1
+<h1>TH1 "argv" API</h1>
2
+
3
+The "argv" API provides features for accessing command-line argdoesn't really
4
+know about).
5
+
6
+Example usage:
7
+
8
+<nowiki><pre>
9
+&lt;th1>
10
+set argc [argv len]
11
+set appName [argv at 0]
12
+# Fetch --foo|-f argument:
13
+set foo [argv geThe various subcommands are described below...
14
+
15
+<h2>len</h2>
16
+
17
+Returns the number of arguments.
18
+
19
+<nowiki><pre>
20
+set argc [argv len]
21
+</pre></nowiki>
22
+
23
+
24
+<h2>at</h2>
25
+
26
+Fetches the argument at the given indextrue" if the are set arg [argv at 3]
27
+</pre></nowiki>
28
+
29
+
30
+<h2>getstrment #0.
31
+
32
+<h2>getstr|string</h2>
33
+
34
+Searches for a CLI/GET/POST parameter. In CLI this function has soThis function has some non-intuitive behaviour
35
+ernals: once a it is removed
36
+from the internal arguments ction will never
37
+s. CLI boolean flags
38
+have no explicit value, and are "true" if the are set at all.
39
+
40
+<nowiki><pre>
41
+set doSomething [argv bool "do-something" "D" 0]
42
+</pre></nowiki>
43
+
44
+<h2>getint|int</h2>
45
+
46
+Works almost like <tt>getstr</tt> but searches for integer flags.
47
+
48
+
49
+<nowiki><pre>
50
+set limit [argv int "limit" "L" 10]
51
+</pre></nowiki>
52
+getbool "do-something" "D" 0]
53
+</h2>
54
+
55
+Works almost like <tt>geinteger flags.
56
+
57
+
58
+<noget
--- a/www/th1_argv.wiki
+++ b/www/th1_argv.wiki
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/th1_argv.wiki
+++ b/www/th1_argv.wiki
@@ -0,0 +1,58 @@
1 <h1>TH1 "argv" API</h1>
2
3 The "argv" API provides features for accessing command-line argdoesn't really
4 know about).
5
6 Example usage:
7
8 <nowiki><pre>
9 &lt;th1>
10 set argc [argv len]
11 set appName [argv at 0]
12 # Fetch --foo|-f argument:
13 set foo [argv geThe various subcommands are described below...
14
15 <h2>len</h2>
16
17 Returns the number of arguments.
18
19 <nowiki><pre>
20 set argc [argv len]
21 </pre></nowiki>
22
23
24 <h2>at</h2>
25
26 Fetches the argument at the given indextrue" if the are set arg [argv at 3]
27 </pre></nowiki>
28
29
30 <h2>getstrment #0.
31
32 <h2>getstr|string</h2>
33
34 Searches for a CLI/GET/POST parameter. In CLI this function has soThis function has some non-intuitive behaviour
35 ernals: once a it is removed
36 from the internal arguments ction will never
37 s. CLI boolean flags
38 have no explicit value, and are "true" if the are set at all.
39
40 <nowiki><pre>
41 set doSomething [argv bool "do-something" "D" 0]
42 </pre></nowiki>
43
44 <h2>getint|int</h2>
45
46 Works almost like <tt>getstr</tt> but searches for integer flags.
47
48
49 <nowiki><pre>
50 set limit [argv int "limit" "L" 10]
51 </pre></nowiki>
52 getbool "do-something" "D" 0]
53 </h2>
54
55 Works almost like <tt>geinteger flags.
56
57
58 <noget

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button