aboutsummaryrefslogtreecommitdiff
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
parentTodo list of the project (diff)
Number to contact option
-rw-r--r--contactList.c13
-rw-r--r--contactList.h8
-rw-r--r--main.c26
-rw-r--r--main.h1
4 files changed, 46 insertions, 2 deletions
diff --git a/contactList.c b/contactList.c
index 85369a9..dd655ca 100644
--- a/contactList.c
+++ b/contactList.c
@@ -25,6 +25,19 @@ void selectPreviousContact(void) {
clearContactListW();
}
+int findContact(const char* number, contact** out) {
+ if( !number || !out )
+ return 1;
+
+ for(int i = 0 ; i < nbContacts ; i++) {
+ if( !strcmp(number, contactList[i].number) ) {
+ *out = contactList+i;
+ return 0;
+ }
+ }
+ return 2;
+}
+
void clearContactListW(void) {
for(int i = firstConctactShow; i < h_menuContact && i < nbContacts; i++) {
move(y_menuContact+i,x_menuContact);
diff --git a/contactList.h b/contactList.h
index 12d69ed..5857c2f 100644
--- a/contactList.h
+++ b/contactList.h
@@ -12,6 +12,7 @@ typedef struct contact {
int hasNewMessage;
} contact ;
+#define DEFAULT_CONTACT_FILENAME "/usr/share/sms/contact.csv"
@@ -24,6 +25,13 @@ int fillContactList(char* cvs_file_in);
// Return: 0 if success, >0 if error
int writeContactList(char* cvs_file_in);
+// Find a contact
+// Params: A SIM Number
+// Return: 0 if success, >0 otherwise
+int findContact(const char*, contact**);
+
+
+
// Add a contact
// Params: A contact struct
// Return: 0 if success, >0 otherwise
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;
}
diff --git a/main.h b/main.h
index b0ff58c..cd7dfec 100644
--- a/main.h
+++ b/main.h
@@ -30,6 +30,7 @@ void fail_exit(const char *msg);
+
// Checks errors for (most) ncurses functions. CHECK(fn, x, y, z) is a checked
// version of fn(x, y, z).
#define CHECK(fn, ...) \