- ablity to print/export only selected items
- new editor commands
- text filter update
+ - mutt query code cleanup
0.4.12
- added man page for abookrc (Alan Ford)
);
}
-static int
-mutt_query_name(char *str)
-{
- int i, j;
- char *tmp;
-
- for(i = 0, j = 0 ; i < items; i++) {
- tmp = strdup(database[i][NAME]);
- if( strstr( strupper(tmp), strupper(str) ) != NULL ) {
- if( !j )
- putchar('\n');
- muttq_print_item(i);
- j++;
- }
- free(tmp);
- }
-
- return j;
-}
-
-static int
-mutt_query_email(char *str)
-{
- int i, j, k;
- char *tmp, emails[MAX_EMAILS][MAX_EMAIL_LEN];
-
- for(i = 0, j = 0; i < items; i++) {
- split_emailstr(i, emails);
- for(k = 0; k < MAX_EMAILS; k++) {
- if( *emails[k] ) {
- tmp = strdup( emails[k] );
- if( strstr( strupper(tmp), strupper(str) ) != NULL ) {
- if( !j )
- putchar('\n');
- j++;
- if( options_get_int("mutt_return_all_emails") ) {
- muttq_print_item(i);
- free(tmp);
- break;
- } else
- printf("%s\t%s\n", emails[k],
- database[i][NAME]);
- }
- free(tmp);
- }
- }
- }
-
- return j;
-}
-
static void
mutt_query(char *str)
{
- int i;
-
init_mutt_query();
if( str == NULL || !strcasecmp(str, "all") ) {
+ struct db_enumerator e = init_db_enumerator(ENUM_ALL);
printf("All items\n");
- for(i = 0; i < items; i++)
- muttq_print_item(i);
+ db_enumerate_items(e)
+ muttq_print_item(e.item);
} else {
- if( !mutt_query_name(str) && !mutt_query_email(str) ) {
+ int search_fields[] = {NAME, EMAIL, NICK, -1};
+ int i;
+ if( (i = find_item(str, 0, search_fields)) < 0 ) {
printf("Not found\n");
quit_mutt_query(1);
}
+ putchar('\n');
+ while(i >= 0) {
+ muttq_print_item(i);
+ i = find_item(str, i+1, search_fields);
+ }
}
quit_mutt_query(0);
}
int
-find_item(char *str, int start)
+find_item(char *str, int start, int search_fields[])
{
int i;
char *findstr = NULL;
char *tmp = NULL;
int ret = -1; /* not found */
+ struct db_enumerator e = init_db_enumerator(ENUM_ALL);
- if(items < 1 || start < 0 || start >= LAST_ITEM)
+ if(list_is_empty() || !is_valid_item(start))
return -2; /* error */
findstr = strdup(str);
findstr = strupper(findstr);
- for( i = start; i < items; i++ ) {
- tmp = strdup(database[i][NAME]);
- if( strstr(strupper(tmp), findstr) != NULL ) {
- ret = i;
- goto out;
+ e.item = start - 1; /* must be "real start" - 1 */
+ db_enumerate_items(e) {
+ for( i = 0; search_fields[i] >= 0; i++ ) {
+ tmp = safe_strdup(database[e.item][search_fields[i]]);
+ if( tmp && strstr(strupper(tmp), findstr) ) {
+ ret = e.item;
+ goto out;
+ }
+ my_free(tmp);
}
- my_free(tmp);
}
out:
void sort_surname();
void sort_database();
char *get_surname(char *s);
-int find_item(char *str, int start);
+int find_item(char *str, int start, int search_fields[]);
int is_selected(int item);
int is_valid_item(int item);
{
int item;
static char findstr[81];
+ int search_fields[] = {NAME, EMAIL, NICK, -1};
if(next) {
if( !*findstr )
clear_statusline();
}
- if( (item = find_item(findstr, next ? curitem+1 : curitem)) >= 0 ) {
+ if( (item = find_item(findstr, next ? curitem+1 : curitem,
+ search_fields )) >= 0 ) {
curitem = item;
refresh_list();
}