Mercurial > projects > pwm
comparison cmd.c @ 37:e027dd4409c7
Handle empty fields correctly when filtering the list of entries
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Thu, 08 Aug 2019 10:31:06 +0200 |
parents | b5ebed168e59 |
children | 8b55f7b1c6b3 |
comparison
equal
deleted
inserted
replaced
36:f9501248b6bd | 37:e027dd4409c7 |
---|---|
424 char *errbuf; | 424 char *errbuf; |
425 size_t errbuf_size; | 425 size_t errbuf_size; |
426 struct pager *pager = NULL; | 426 struct pager *pager = NULL; |
427 union list_item **list = NULL; | 427 union list_item **list = NULL; |
428 size_t j; | 428 size_t j; |
429 const char *group; | |
430 const char *title; | |
431 const char *username; | |
432 const char *notes; | |
433 const char *url; | |
429 struct record *record; | 434 struct record *record; |
430 | 435 |
431 for (i = 1; i < argc; i++) { | 436 for (i = 1; i < argc; i++) { |
432 type = parse_arg(argv[i], field_namev, '~', &value); | 437 type = parse_arg(argv[i], field_namev, '~', &value); |
433 if ((type >= 0) && ((value == NULL) || (value[0] == '\0'))) { | 438 if ((type >= 0) && ((value == NULL) || (value[0] == '\0'))) { |
480 for (j = 0; list[j] != NULL; j++) { | 485 for (j = 0; list[j] != NULL; j++) { |
481 if (list[j]->any.type == ITEM_TYPE_GROUP) { | 486 if (list[j]->any.type == ITEM_TYPE_GROUP) { |
482 pager_printf(pager, "[%s]\n", list[j]->group.group); | 487 pager_printf(pager, "[%s]\n", list[j]->group.group); |
483 } else { | 488 } else { |
484 record = pwfile_get_record(ctx, list[j]->record.id); | 489 record = pwfile_get_record(ctx, list[j]->record.id); |
485 if (((group_re == NULL) || (regexec(group_re, | 490 group = (record->group != NULL) ? record->group : ""; |
486 record->group, 0, NULL, 0) == 0)) && | 491 title = (record->title != NULL) ? record->title : ""; |
487 ((title_re == NULL) || (regexec(title_re, | 492 username = (record->username != NULL) ? |
488 record->title, 0, NULL, 0) == 0)) && | 493 record->username : ""; |
489 ((username_re == NULL) || (regexec(username_re, | 494 notes = (record->notes != NULL) ? record->notes : ""; |
490 record->username, 0, NULL, 0) == 0)) && | 495 url = (record->url != NULL) ? record->url : ""; |
491 ((notes_re == NULL) || (regexec(notes_re, | 496 if (((group_re == NULL) || |
492 record->notes, 0, NULL, 0) == 0)) && | 497 (regexec(group_re, group, 0, NULL, 0) == 0)) && |
493 ((url_re == NULL) || (regexec(url_re, | 498 ((title_re == NULL) || |
494 record->url, 0, NULL, 0) == 0))) { | 499 (regexec(title_re, title, 0, NULL, 0) == 0)) && |
500 ((username_re == NULL) || | |
501 (regexec(username_re, username, 0, NULL, | |
502 0) == 0)) && | |
503 ((notes_re == NULL) || | |
504 (regexec(notes_re, notes, 0, NULL, 0) == 0)) && | |
505 ((url_re == NULL) || | |
506 (regexec(url_re, url, 0, NULL, 0) == 0))) { | |
495 pager_printf(pager, "%4u %s\n", | 507 pager_printf(pager, "%4u %s\n", |
496 list[j]->record.id, | 508 list[j]->record.id, |
497 (list[j]->record.title != NULL) ? | 509 (list[j]->record.title != NULL) ? |
498 list[j]->record.title : ""); | 510 list[j]->record.title : ""); |
499 } | 511 } |