shopping-list

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

main.c (1125B)


      1 /* what are we doing here:
      2  *
      3  * find file in $XDG_DOCUMENTS_HOME
      4  * if dont exist, create
      5  * read from it
      6  * functions: list $l, add $item [$list], delete $item [$list], new $list
      7  *
      8  * in each file: item name, price, hyperlink
      9  *
     10  * !! in each of the following find the file and error if not found !!
     11  *
     12  * new:
     13  *  create new file lol
     14  *
     15  * list:
     16  *  read and print in pretty manner
     17  *
     18  * add:
     19  *  append item name, price and hyperlink to file
     20  *
     21  * delete:
     22  *  delete certain item with $id
     23  *
     24  *
     25  */
     26 
     27 #include "functions.h"
     28 #include <stdio.h>
     29 
     30 /* simple macro to notify user then exit code
     31  * we might change this later for diff codes
     32  * so users get better error knowledge */
     33 
     34 #define BADARGS(x, str) puts(#str); return x;
     35 
     36 int main(int argc, char *argv[]) {
     37   if (argc < 2 || argc > 3) {
     38     BADARGS(1, "wrong # of args")
     39   } 
     40   switch (argv[1][0]) {
     41   case 'n':
     42     new_list(argv[2]);
     43     break;
     44 
     45   case 'l':
     46     list_items(argv[2]);
     47     break;
     48 
     49   case 'a':
     50     add_item(argv[2], argv[3]);
     51     break;
     52 
     53   case 'd':
     54     del_item(argv[2]);
     55     break;
     56 
     57   default:
     58       BADARGS(1, "incorrect argument")
     59 
     60   }
     61   return 0;
     62 }