From 446e47937737980f6757134b77267bd83a69f066 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 5 Feb 2019 19:16:42 +0100 Subject: Add config file management --- contactList.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'contactList.c') diff --git a/contactList.c b/contactList.c index d817120..a5c7107 100644 --- a/contactList.c +++ b/contactList.c @@ -1,6 +1,7 @@ #include #include -#include"contactList.h" +#define _GNU_SOURCE +#include "contactList.h" contact* contactList; size_t nbContacts; @@ -70,7 +71,7 @@ int fillContactList(char* filename) { if( contactList ) { free(contactList); } - + if( !file ) { perror("Unable to read contact file"); return 1; @@ -82,7 +83,7 @@ int fillContactList(char* filename) { if( c == ';' ) { v++; if( v >= 3) { - fprintf(stderr, "Invalid format (contact file) : too many field"); + perror("Invalid format (contact file) : too many field"); return 2; // Invalid } } @@ -91,8 +92,8 @@ int fillContactList(char* filename) { v = 0; nbContacts++; } - else {// Pas assez - fprintf(stderr, "Invalid format (contact file) : not enougth field"); + else {// Not enougth + perror("Invalid format (contact file) : not enougth field"); return 2; // Invalid format } } @@ -141,20 +142,26 @@ int fillContactList(char* filename) { if( v == 0) { contactList[i].name[nameLength++] = c; if( nameLength > (sizeof contactList[i].name -1) ) { +#ifdef DEBUG fprintf(stderr, "too long name ?"); +#endif return 3; } }else if( v == 1) { contactList[i].display_name[display_nameLength++] = c; if( display_nameLength > (sizeof contactList[i].display_name -1) ) { +#ifdef DEBUG fprintf(stderr, "too display name ?"); +#endif return 9; } } else { contactList[i].number[numberLength++] = c; if( numberLength > (sizeof contactList[i].number -1) ) { puts(contactList[i].number); +#ifdef DEBUG fprintf(stderr, "too long number ?"); +#endif return 27+i; } } -- cgit v1.2.3