aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-11-11 15:11:04 +0100
committerache <ache@ache.one>2017-11-11 15:11:04 +0100
commit76f7b2136ba7ed8adec5f343550065e05bb733bc (patch)
tree5ab7ee675146d6d300d622c8d2784aefae89c874 /main.c
parentTodo list of the project (diff)
Number to contact option
Diffstat (limited to 'main.c')
-rw-r--r--main.c26
1 files changed, 24 insertions, 2 deletions
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;
}