From 6cb43717cbbe8380d2aeb382d2b6f350bab74494 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 8 Nov 2018 16:40:47 +0100 Subject: Improve loggers --- contactList.c | 20 ++++++++++++++++---- contactList.h | 2 +- contactList.o | Bin 0 -> 6320 bytes main.c | 9 +++++++++ sms.c | 22 +++++++++++----------- 5 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 contactList.o diff --git a/contactList.c b/contactList.c index b6d9385..642aa19 100644 --- a/contactList.c +++ b/contactList.c @@ -71,24 +71,30 @@ int fillContactList(char* filename) { free(contactList); } - if( !file ) + if( !file ) { + perror("Unable to read contact file"); return 1; + } int c = 0; int v = 0; while( (c = fgetc(file)) != EOF ) { if( c == ';' ) { v++; - if( v == 3) + if( v >= 3) { + fprintf(stderr, "Invalid format (contact file) : too many field"); return 2; // Invalid + } } if( c == '\n' ) { if( v == 2 ) { v = 0; nbContacts++; } - else // Pas assez + else {// Pas assez + fprintf(stderr, "Invalid format (contact file) : not enougth field"); return 2; // Invalid format + } } } if( v == 1 ) @@ -115,6 +121,7 @@ int fillContactList(char* filename) { display_nameLength = 0; break; default: + fprintf(stderr, "Invalid format (contact file)"); return 2; // Invalid } } else if( c == '\n' ) { @@ -126,23 +133,28 @@ int fillContactList(char* filename) { contactList[i].hasNewMessage = 0; contactList[i].conversation = NULL; } - else + else { + fprintf(stderr, "Invalid format (contact file)"); return 2; // Invalid format + } } else { if( v == 0) { contactList[i].name[nameLength++] = c; if( nameLength > (sizeof contactList[i].name -1) ) { + fprintf(stderr, "too long name ?"); return 3; } }else if( v == 1) { contactList[i].display_name[display_nameLength++] = c; if( display_nameLength > (sizeof contactList[i].display_name -1) ) { + fprintf(stderr, "too display name ?"); return 9; } } else { contactList[i].number[numberLength++] = c; if( numberLength > (sizeof contactList[i].number -1) ) { puts(contactList[i].number); + fprintf(stderr, "too long number ?"); return 27+i; } } diff --git a/contactList.h b/contactList.h index bb25ef2..43199a1 100644 --- a/contactList.h +++ b/contactList.h @@ -15,7 +15,7 @@ typedef struct contact { conversation* conversation; } contact ; -#define DEFAULT_CONTACT_FILENAME "/usr/share/sms/contact.csv" +#define DEFAULT_CONTACT_FILENAME "/var/spool/sms/contacts.csv" diff --git a/contactList.o b/contactList.o new file mode 100644 index 0000000..5fb4e69 Binary files /dev/null and b/contactList.o differ diff --git a/main.c b/main.c index d62615a..6a7e327 100644 --- a/main.c +++ b/main.c @@ -50,6 +50,7 @@ extern int firstSMSIndex; extern int canAugment; extern int showName; +#define DEBUG void fail_exit(const char *msg) { @@ -61,6 +62,10 @@ void fail_exit(const char *msg) { int main(int argc, char* argv[]){ +#ifdef DEBUG + freopen("/tmp/mesms.debug", "w", stderr); +#endif + /* Gestion des paramètres */ while (1) { int c; @@ -129,6 +134,7 @@ int main(int argc, char* argv[]){ } + fprintf(stderr, "test"); /* Initialisation */ @@ -162,14 +168,17 @@ int main(int argc, char* argv[]){ int r = 0; + fprintf(stderr, "test1"); if( r = fillContactList(DEFAULT_CONTACT_FILENAME) ) { return r; } if( r = loadConv() ) { return r; } + fprintf(stderr, "test2"); sortContacts(); + fprintf(stderr, "test3"); for(int i = 0 ; i < 9 ; i++) { init_pair( i+1, i, COLOR_BLACK); diff --git a/sms.c b/sms.c index 05e8c91..9bb4120 100644 --- a/sms.c +++ b/sms.c @@ -180,10 +180,10 @@ int listSMS(char* smsInboxDir, int inorout) { char filename[1024] =""; sprintf(filename, "%s/%s", smsInboxDir, dir->d_name); - int r = - readSMS(filename, inorout); - if( r ) + int r = readSMS(filename, inorout); + if( r ) { return 2; + } } } @@ -200,15 +200,16 @@ int listSMS(char* smsInboxDir, int inorout) { int loadConv(void) { - int r = - - listSMS("/var/spool/sms/inbox/", SMS_IN); - if( r ) + int r = listSMS("/var/spool/sms/inbox/", SMS_IN); + if( r ) { + fprintf(stderr, "Impossible de lire les SMS reçu"); return 1; - r = - listSMS("/var/spool/sms/sent/" , SMS_OUT); - if( r ) + } + r = listSMS("/var/spool/sms/sent/" , SMS_OUT); + if( r ) { + fprintf(stderr, "Impossible de lire les SMS envoyés"); return 2; + } for(int i = 0 ; i < nbConv ; i++) { contact* cntct = NULL; @@ -224,7 +225,6 @@ int loadConv(void) { } } - return 0; } -- cgit v1.2.3