9511_project03

project 3 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README LICENSE
source/main.c (2149B)
   1 #include "../include/cla.h"
   2 #include "../include/user.h"
   3 #include "../include/load.h"
   4 #include "../include/utils.h"
   5 #include "../include/status.h"
   6 #include "../include/vector.h"
   7 
   8 int main (int argc, char *argv[])
   9 {
  10     status_t st;
  11     cla_t cla;
  12     ADT_Vector_t *v;
  13 
  14     /* Asigna memoria a cla (c.l.a.: "command line arguments") */
  15     if((st = cla_create(&cla)) != OK) {
  16         show_status(st);
  17         return st;
  18     }
  19 
  20     /* Valida que los argumentos sean correctos y asigna valores a cla */
  21     if((st = validate_arguments(argc, argv, cla)) != OK) {
  22         show_status(st);
  23         cla_destroy(cla);
  24         return st;
  25     }
  26 
  27     /* Crea un vector */
  28     if((st = ADT_Vector_create(&v)) != OK) {
  29         show_status(st);
  30         cla_destroy(cla);
  31         return st;
  32     }
  33 
  34     /* Setea el comparador a ADT_Vector */    
  35     if((st = ADT_Vector_set_comparator(v, user_equals)) != OK) {
  36         show_status(st);
  37         cla_destroy(cla);
  38         ADT_Vector_destroy(&v);
  39         return st;
  40     }
  41 
  42     /* Carga el vector con los usuarios del archivo de entrada */
  43     if((st = load_users_to_vector(&v, cla)) != OK) {
  44         show_status(st);
  45         cla_destroy(cla);
  46         ADT_Vector_destroy(&v);
  47         return st;
  48     }
  49 
  50     /* Ordena el vector con los usuarios */
  51     if((st = ADT_Vector_sort(v, user_comparator_credits_maxmin)) != OK) {
  52         show_status(st);
  53         cla_destroy(cla);
  54         ADT_Vector_destroy(&v);
  55         return st;
  56     }
  57 
  58     /* Setea el impresor e imprime ADT_Vector segĂșn el argumento ingresado */
  59     if(!strcmp(cla->fmt, STR_FMT_CSV)) {
  60         if((st = ADT_Vector_set_printer(v, user_print_as_csv)) != OK) {
  61             show_status(st);
  62             cla_destroy(cla);
  63             ADT_Vector_destroy(&v);
  64             return st;
  65         }
  66         /* E imprime el vector con los usuarios */
  67         if((st = ADT_Vector_export_as_csv(v, cla->fo)) != OK) {
  68             show_status(st);
  69             cla_destroy(cla);
  70             ADT_Vector_destroy(&v);
  71             return st;
  72         }
  73     }
  74     else if(!strcmp(cla->fmt, STR_FMT_XML)) {
  75         if((st = ADT_Vector_set_printer(v, user_print_as_xml)) != OK) {
  76             show_status(st);
  77             cla_destroy(cla);
  78             ADT_Vector_destroy(&v);
  79             return st;
  80         }
  81         if((st = ADT_Vector_export_as_xml(v, cla->fo)) != OK) {
  82             show_status(st);
  83             cla_destroy(cla);
  84             ADT_Vector_destroy(&v);
  85             return st;
  86         }
  87     }
  88     show_status(st);
  89     cla_destroy(cla);
  90     ADT_Vector_destroy(&v);
  91     return OK;
  92 }