diff options
Diffstat (limited to 'booki.c')
| -rw-r--r-- | booki.c | 27 | 
1 files changed, 11 insertions, 16 deletions
| @@ -10,7 +10,6 @@  #define EDIT_FILE "tmp.toml"  #define MAX_SEARCH_OPTS 5 -#define MAX_BOOKS 5000  // STRUCTS  struct es { @@ -36,7 +35,7 @@ struct Book {      //struct es translators[MAX_TRANSLATORS];  }; -struct Book* init_book(struct Book* book) { +void init_book(struct Book* book) {      book->id = 0;      book->title = default_es;      book->author = default_es; @@ -48,9 +47,6 @@ struct Book* init_book(struct Book* book) {      for (int i = 0; i < 5; i++)          book->on[i] = default_es;      book->published = 0; - -    //book_count++; -    return book;  }  int PARSE_LINE = 1; @@ -482,13 +478,12 @@ char** search(int argc, char* argv[], char* booki_file) {          output = fopen(EDIT_FILE, "w");      // book loop -    struct Book books[MAX_BOOKS];      int book_count = 0; -    struct Book* book; +    struct Book book;      char* cur_data = data;      while ((cur_data = next_book(cur_data)) != NULL) { -        book = init_book(&(books[book_count])); -        parse_book(cur_data, book); +        init_book(&book); +        parse_book(cur_data, &book);          char* field;          int i; @@ -498,23 +493,23 @@ char** search(int argc, char* argv[], char* booki_file) {              // compare fields              if (ATTR_MATCH(field, "title")) { -                if (!regex_match(search_opts.args[i], book->title)) +                if (!regex_match(search_opts.args[i], book.title))                      break;              } else if (ATTR_MATCH(field, "author")) { -                if (!regex_match(search_opts.args[i], book->author)) +                if (!regex_match(search_opts.args[i], book.author))                      break;              } else if (ATTR_MATCH(field, "language")) { -                if (!regex_match(search_opts.args[i], book->language)) +                if (!regex_match(search_opts.args[i], book.language))                      break;              } else if (ATTR_MATCH(field, "on")) {                  int cnt = 0; -                struct es tmp = book->on[cnt]; +                struct es tmp = book.on[cnt];                  bool match = false;                  while (tmp.len != 0) {                      if (regex_match(search_opts.args[i], tmp))                          match = true;                      cnt++; -                    tmp = book->on[cnt]; +                    tmp = book.on[cnt];                  }                  if (!match)                      break; @@ -528,9 +523,9 @@ char** search(int argc, char* argv[], char* booki_file) {          if (match) {              if (search_opts.edit) -                write_book(*book, output); +                write_book(book, output);              else -                print_book(*book, search_opts.show); +                print_book(book, search_opts.show);              book_count++;          }      } | 
