예제 #1
0
int main(int argc, char *argv[])
{
  int ch;
  int f_flag = 0;
  char *filename = "data";
  ToxWindow* a;

  int i = 0;
  for (i = 0; i < argc; ++i) {
    if (argv[i] == NULL)
      break;
    else if (argv[i][0] == '-') {
      if (argv[i][1] == 'f') {
        if (argv[i + 1] != NULL)
          filename = argv[i + 1];
        else
          f_flag = -1;
      }
    }
  }

  init_term();
  init_tox();
  load_data(filename);
  init_windows();
  init_window_status();

  if (f_flag == -1) {
    attron(COLOR_PAIR(3) | A_BOLD);
    wprintw(prompt->window, "You passed '-f' without giving an argument!\n"
                            "defaulting to 'data' for a keyfile...\n");
    attroff(COLOR_PAIR(3) | A_BOLD);
  }
  
  while(true) {
    /* Update tox */
    do_tox();

    /* Draw */
    a = &windows[active_window];
    prepare_window(a->window);
    a->blink = false;
    draw_bar();
    a->onDraw(a);

    /* Handle input */
    ch = getch();
    if (ch == '\t' || ch == KEY_BTAB)
      set_active_window(ch);
    else if (ch != ERR)
      a->onKey(a, ch);
  }
  return 0;
}
예제 #2
0
int main(int argc, char *argv[])
{
  char *user_config_dir = get_user_config_dir();
  char *DATA_FILE;
  int config_err = create_user_config_dir(user_config_dir);
  if(config_err) {
    DATA_FILE = "data";
  } else {
    DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
    strcpy(DATA_FILE, user_config_dir);
    strcat(DATA_FILE, CONFIGDIR);
    strcat(DATA_FILE, "data");
  }
  free(user_config_dir);

  /* This is broken */
  int f_loadfromfile = 1;
  int f_flag = 0;
  int i = 0;
  for (i = 0; i < argc; ++i) {
    if (argv[i] == NULL)
      break;
    else if (argv[i][0] == '-') {
      if (argv[i][1] == 'f') {
        if (argv[i + 1] != NULL)
          DATA_FILE = strdup(argv[i + 1]);
        else
          f_flag = -1;
      } else if (argv[i][1] == 'n') {
          f_loadfromfile = 0;
      }
    }
  }

  init_term();
  Messenger *m = init_tox();
  ToxWindow * prompt = init_windows(m);
  init_window_status();

  if(f_loadfromfile)
    load_data(m, DATA_FILE);
  free(DATA_FILE);

  if (f_flag == -1) {
    attron(COLOR_PAIR(3) | A_BOLD);
    wprintw(prompt->window, "You passed '-f' without giving an argument.\n"
                            "defaulting to 'data' for a keyfile...\n");
    attroff(COLOR_PAIR(3) | A_BOLD);
  }

  if(config_err) {
    attron(COLOR_PAIR(3) | A_BOLD);
    wprintw(prompt->window, "Unable to determine configuration directory.\n"
                            "defaulting to 'data' for a keyfile...\n");
    attroff(COLOR_PAIR(3) | A_BOLD);
  }
  while(true) {
    /* Update tox */
    do_tox(m, prompt);

    /* Draw */
    draw_active_window(m);
  }
  cleanupMessenger(m);
  return 0;
}