Exemplo n.º 1
0
int
main(int argc, char **argv)
{
  int ch;
  USER_OPTIONS *my_options;
  struct file_element *current;

  my_options = malloc(sizeof(USER_OPTIONS));
  memset(my_options, 0, sizeof(USER_OPTIONS));
  my_options->head = malloc(sizeof(struct file_element));
  memset(my_options->head, 0, sizeof(struct file_element));
  current = my_options->head;

  while ((ch = getopt(argc, argv, "a:mvhL")) != -1) {

    switch(ch) {

    case 'a':
      current->filename = malloc(FILENAME_MAX + 1);
      memset(current->filename, 0, FILENAME_MAX + 1);
      strncpy(current->filename, optarg, FILENAME_MAX);
      current->next = malloc(sizeof(struct file_element));
      memset(current->next, 0, sizeof(struct file_element));
      current = current->next;
      break;

    case 'v':
      about();
      break;

    case 'm':
      my_options->maint_mode = MAINT_YES;
      break;

    case 'L':
      show_categories();
      break;

    case '?':
    case 'h':
    default:
      usage();
      /* NOTREACHED */
    }

  }

  argc -= optind;
  argv += optind;

  gtk_init(&argc, &argv);

  create_gtk_ui(my_options);

  return(0);

}
Exemplo n.º 2
0
/**
 * Function reads console params and calls appropriate functions.
 * 
 */
int main(int agrc, char * agrv[])
{
  int i, j, limit=50, desc=0;
  char sort_by[COL_TITLE_LEN] = "date";
  struct category category_to_add;
  struct task task_to_add;
  
  DIR* dir = opendir("..");
  struct dirent* dent;
  FILE* fptr;  
  
  regex_t et_schedule;  
  regcomp(&et_schedule, "^et_.*$", 0);    
  
  
  for(i=1;i<agrc;i++)
  {
    if(strcmp(agrv[i], "-f") == 0)
    {
      if(i+1 < agrc)
	      set_output_format(agrv[i+1]);
    }
  }
  for(i=1;i<agrc;i++)
  {
    if(strcmp(agrv[i], "-a") == 0)
    {
      for(j=1;j<agrc;j++)
      {
        if(strcmp(agrv[j], "-c") == 0)
        {
          get_category_values(agrc, agrv, &category_to_add);
          throw_errors();
          add_category(&category_to_add);
          throw_errors();
          return 0;
        } else if(strcmp(agrv[j], "-t") == 0)
        {
          get_task_values(agrc, agrv, &task_to_add);
          throw_errors();
          add_task(&task_to_add);
          throw_errors();
          return 0;
        }
      }
    } else if(strcmp(agrv[i], "-ac") == 0 || strcmp(agrv[i], "-ca") == 0) {
      get_category_values(agrc, agrv, &category_to_add);
      throw_errors();
      add_category(&category_to_add);
      throw_errors();
      return 0;
    } else if(strcmp(agrv[i], "-at") == 0 || strcmp(agrv[i], "-ta") == 0) {
      get_task_values(agrc, agrv, &task_to_add);
      throw_errors();
      add_task(&task_to_add);
      throw_errors();
      return 0;
    }
  }
  for(i=1;i<agrc;i++)
  {
    if(strcmp(agrv[i], "-c") == 0)
    {
      show_categories();
      throw_errors();
    } else if(strcmp(agrv[i], "-t") == 0)
    {
      if(i+1 < agrc && agrv[i+1][0] != '-')
      {
        /*GET sql info about the task*/
        dir = opendir("/home/hafron/.pal/");
        if(dir)
        {
          while((dent=readdir(dir)))
          {
            if( ! regexec(&et_schedule, dent->d_name, 0, NULL, 0) )
            {
              puts(dent->d_name);
              if(fptr = fopen(dent->d_name,"r"))
              {  
                fclose(fptr) ;
              } else
              {
                error("CANNOT_OPEN_SCHEDULE_FILE");
                throw_errors();
              }
            }
          }
          closedir(dir);
        } else
        {
          error("CANNOT_OPEN_PAL_DIRECTORY");
          throw_errors();
        }
      } else
      {
        for(j=1;j<agrc;j++)
        {
          if(strcmp(agrv[j], "-l") == 0)
          {
            if(j+1 < agrc && agrv[j+1][0] != '-')
              limit = atoi(agrv[j+1]);
          } else if(strcmp(agrv[j], "-d") == 0)
          {
            desc = 1;
          } else if(strcmp(agrv[j], "-s") == 0)
          {
            if(j+1 < agrc && agrv[j+1][0] != '-')
              strncpy(sort_by, agrv[j+1], COL_TITLE_LEN);
          }
        }

        show_tasks(limit, sort_by, desc);
      }
      throw_errors();
    }
  }
  return 0;
}