From 76f7b2136ba7ed8adec5f343550065e05bb733bc Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 11 Nov 2017 15:11:04 +0100 Subject: Number to contact option --- main.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index a75a553..965a45b 100644 --- a/main.c +++ b/main.c @@ -58,11 +58,12 @@ int main(int argc, char* argv[]){ static struct option optlv[] = { {"help", no_argument, 0, 'h' }, {"version", no_argument, 0, 'v' }, + {"contact", required_argument, 0, 'c' }, {NULL, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hv:", optlv, &optIndex); + c = getopt_long(argc, argv, "hvc:", optlv, &optIndex); if (c == -1) break; @@ -78,6 +79,27 @@ int main(int argc, char* argv[]){ return EXIT_SUCCESS; break; + case 'c': + if( optarg ) { + int r = 0; + if( r = fillContactList(DEFAULT_CONTACT_FILENAME) ) { + fprintf(stderr, "Erreur à la lecture de la liste des contacts"); + return r; + } + contact* contact = NULL; + + if( r = findContact(optarg, &contact) ) { + fprintf(stderr, "Numéro de téléphone inconnue"); + printf("%s",optarg); + return r; + } + printf("%s", contact->display_name); + return 0; + } else { + fprintf(stderr, "Numéro de téléphone manquant"); + } + break; + case '?': default: return EXIT_FAILURE; @@ -117,7 +139,7 @@ int main(int argc, char* argv[]){ init_readline(); int r = 0; - if( r = fillContactList("contact.csv") ) { + if( r = fillContactList(DEFAULT_CONTACT_FILENAME) ) { return r; } -- cgit v1.2.3