Fossil SCM

Add -width option to the search command.

mistachkin 2014-01-09 21:10 trunk
Commit e4a6159ba38c085c5ecfb5048dceec6413cae44c
1 file changed +16 -4
+16 -4
--- src/search.c
+++ src/search.c
@@ -167,21 +167,23 @@
167167
168168
/*
169169
** Testing the search function.
170170
**
171171
** COMMAND: search*
172
-** %fossil search [-all|-a] [-limit|-n #] pattern...
172
+** %fossil search [-all|-a] [-limit|-n #] [-width|-W #] pattern...
173173
**
174174
** Search for timeline entries matching all words
175175
** provided on the command line. Whole-word matches
176176
** scope more highly than partial matches.
177177
**
178178
** Outputs, by default, some top-N fraction of the
179179
** results. The -all option can be used to output
180180
** all matches, regardless of their search score.
181
-** -limit can be used to limit the number of entries
182
-** returned.
181
+** The -limit option can be used to limit the number
182
+** of entries returned. The -width option can be
183
+** used to set the output width used when printing
184
+** matches.
183185
*/
184186
void search_cmd(void){
185187
Search *p;
186188
Blob pattern;
187189
int i;
@@ -190,12 +192,22 @@
190192
int iBest;
191193
char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
192194
off the end of the
193195
results. */
194196
char const * zLimit = find_option("limit","n",1);
197
+ const char *zWidth = find_option("width","W",1);
195198
int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching
196199
lines/entries to list */
200
+ int width;
201
+ if( zWidth ){
202
+ width = atoi(zWidth);
203
+ if( (width!=0) && (width<=20) ){
204
+ fossil_fatal("--width|-W value must be >20 or 0");
205
+ }
206
+ }else{
207
+ width = 79;
208
+ }
197209
198210
db_must_be_within_tree();
199211
if( g.argc<2 ) return;
200212
blob_init(&pattern, g.argv[2], -1);
201213
for(i=3; i<g.argc; i++){
@@ -224,8 +236,8 @@
224236
blob_appendf(&sql,"AND x>%d ", iBest/3);
225237
}
226238
blob_append(&sql, "ORDER BY x DESC, date DESC ", -1);
227239
db_prepare(&q, blob_str(&sql));
228240
blob_reset(&sql);
229
- print_timeline(&q, nLimit, 79, 0);
241
+ print_timeline(&q, nLimit, width, 0);
230242
db_finalize(&q);
231243
}
232244
--- src/search.c
+++ src/search.c
@@ -167,21 +167,23 @@
167
168 /*
169 ** Testing the search function.
170 **
171 ** COMMAND: search*
172 ** %fossil search [-all|-a] [-limit|-n #] pattern...
173 **
174 ** Search for timeline entries matching all words
175 ** provided on the command line. Whole-word matches
176 ** scope more highly than partial matches.
177 **
178 ** Outputs, by default, some top-N fraction of the
179 ** results. The -all option can be used to output
180 ** all matches, regardless of their search score.
181 ** -limit can be used to limit the number of entries
182 ** returned.
 
 
183 */
184 void search_cmd(void){
185 Search *p;
186 Blob pattern;
187 int i;
@@ -190,12 +192,22 @@
190 int iBest;
191 char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
192 off the end of the
193 results. */
194 char const * zLimit = find_option("limit","n",1);
 
195 int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching
196 lines/entries to list */
 
 
 
 
 
 
 
 
 
197
198 db_must_be_within_tree();
199 if( g.argc<2 ) return;
200 blob_init(&pattern, g.argv[2], -1);
201 for(i=3; i<g.argc; i++){
@@ -224,8 +236,8 @@
224 blob_appendf(&sql,"AND x>%d ", iBest/3);
225 }
226 blob_append(&sql, "ORDER BY x DESC, date DESC ", -1);
227 db_prepare(&q, blob_str(&sql));
228 blob_reset(&sql);
229 print_timeline(&q, nLimit, 79, 0);
230 db_finalize(&q);
231 }
232
--- src/search.c
+++ src/search.c
@@ -167,21 +167,23 @@
167
168 /*
169 ** Testing the search function.
170 **
171 ** COMMAND: search*
172 ** %fossil search [-all|-a] [-limit|-n #] [-width|-W #] pattern...
173 **
174 ** Search for timeline entries matching all words
175 ** provided on the command line. Whole-word matches
176 ** scope more highly than partial matches.
177 **
178 ** Outputs, by default, some top-N fraction of the
179 ** results. The -all option can be used to output
180 ** all matches, regardless of their search score.
181 ** The -limit option can be used to limit the number
182 ** of entries returned. The -width option can be
183 ** used to set the output width used when printing
184 ** matches.
185 */
186 void search_cmd(void){
187 Search *p;
188 Blob pattern;
189 int i;
@@ -190,12 +192,22 @@
192 int iBest;
193 char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop
194 off the end of the
195 results. */
196 char const * zLimit = find_option("limit","n",1);
197 const char *zWidth = find_option("width","W",1);
198 int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching
199 lines/entries to list */
200 int width;
201 if( zWidth ){
202 width = atoi(zWidth);
203 if( (width!=0) && (width<=20) ){
204 fossil_fatal("--width|-W value must be >20 or 0");
205 }
206 }else{
207 width = 79;
208 }
209
210 db_must_be_within_tree();
211 if( g.argc<2 ) return;
212 blob_init(&pattern, g.argv[2], -1);
213 for(i=3; i<g.argc; i++){
@@ -224,8 +236,8 @@
236 blob_appendf(&sql,"AND x>%d ", iBest/3);
237 }
238 blob_append(&sql, "ORDER BY x DESC, date DESC ", -1);
239 db_prepare(&q, blob_str(&sql));
240 blob_reset(&sql);
241 print_timeline(&q, nLimit, width, 0);
242 db_finalize(&q);
243 }
244

Keyboard Shortcuts

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