Beispiel #1
0
//!
//!
//!
//! @param[in] key
//! @param[in] val
//!
//! @pre
//!
//! @post
//!
static void set_global_parameter(char *key, char *val)
{
    if (strcmp(key, "debug") == 0) {
        print_debug = parse_boolean(val);
        set_debug(print_debug);
    } else if (strcmp(key, "argv") == 0) {
        print_argv = parse_boolean(val);
    } else if (strcmp(key, "work") == 0) {
        set_work_dir(val);
    } else if (strcmp(key, "work_size") == 0) {
        set_work_limit(parse_bytes(val));
    } else if (strcmp(key, "cache") == 0) {
        set_cache_dir(val);
    } else if (strcmp(key, "cache_size") == 0) {
        set_cache_limit(parse_bytes(val));
    } else if (strcmp(key, "purge_cache") == 0) {
        purge_cache = parse_boolean(val);
    } else if (strcmp(key, "cloud_cert") == 0) {
        euca_strncpy(cloud_cert_path, val, sizeof(cloud_cert_path));
    } else if (strcmp(key, "service_key") == 0) {
        euca_strncpy(service_key_path, val, sizeof(service_key_path));
    } else {
        err("unknown global parameter '%s'", key);
    }
    LOGINFO("GLOBAL: %s=%s\n", key, val);
}
Beispiel #2
0
/*
 * Goto a new directory
 */
static void goto_filedir(char *new_dir, int absolut)
{
  if (strcmp(new_dir, "..") == 0) {
    if (strcmp(work_dir, "/")) {
      char *sp = strrchr(work_dir, '/');
      *sp = (char)0;
      if (strlen(work_dir) == 0)
        strcpy(work_dir, "/");
    } else {
      file_tell(_("Can't back up!"));
      return;
    }
  } else if (!absolut) {
    int new_len = strlen(work_dir) + 1;	/* + '/' */
    if ((new_len += strlen(new_dir) + 1) > min_len) {
      min_len = new_len;
      work_dir = set_work_dir(work_dir, min_len);
    }
    if (strcmp(work_dir, "/") != 0)
      strcat(work_dir, "/");
    strcat(work_dir, new_dir);
  } else {
    int new_len = 1;
    if (*new_dir != '/')
      new_len += strlen(homedir) + 1;
    new_len += strlen(new_dir);
    if (min_len < new_len)
      min_len = new_len;

    work_dir = set_work_dir(work_dir, min_len);

    if (*new_dir == '/')
      strncpy(work_dir, new_dir, min_len);
    else
      snprintf(work_dir, min_len, "%s/%s", homedir, new_dir);
  }
  new_filedir(global_dirdat, 1);
}
Beispiel #3
0
//!
//!
//!
//! @param[in] key
//! @param[in] val
//!
//! @pre
//!
//! @post
//!
static void set_global_parameter(char *key, char *val)
{
    if (strcmp(key, "debug") == 0) {
        print_debug = parse_boolean(val);
        set_debug(print_debug);
    } else if (strcmp(key, "argv") == 0) {
        print_argv = parse_boolean(val);
    } else if (strcmp(key, "work") == 0) {
        set_work_dir(val);
    } else if (strcmp(key, "work_size") == 0) {
        set_work_limit(parse_bytes(val));
    } else if (strcmp(key, "cache") == 0) {
        set_cache_dir(val);
    } else if (strcmp(key, "cache_size") == 0) {
        set_cache_limit(parse_bytes(val));
    } else {
        err("unknown global parameter '%s'", key);
    }
    LOGINFO("GLOBAL: %s=%s\n", key, val);
}
Beispiel #4
0
/*
 * Initialize new file directory.
 *
 * Sets the current working directory.  Non-0 return = no change.
 */
static int new_filedir(GETSDIR_ENTRY *dirdat, int flushit)
{
  static size_t dp_len = 0;
  static char cwd_str_fmt[BUFSIZ] = "";
  size_t new_dp_len, fmt_len;
  char disp_dir[80];
  int initial_y = (76 - (WHAT_NR_OPTIONS * WHAT_WIDTH >= 76
                   ? 74 : WHAT_NR_OPTIONS * WHAT_WIDTH)) / 2;
  size_t i;
  char * new_prev_dir;

  cur      =  0;
  ocur     =  0;
  subm     =  SUBM_OKAY;
  quit     =  0;
  top      =  0;
  c        =  0;
  pgud     =  0;
  first    =  1;
  min_len  =  1;
  dprev    = -1;
  tag_cnt  =  0;

  /*
   * get last directory
   */
  work_dir = down_loading ? d_work_dir : u_work_dir;

  /*
   * init working directory to default?
   */
  if (work_dir == NULL) {
    char *s = down_loading? P_DOWNDIR : P_UPDIR;
    min_len = 1;

    if (*s != '/')
      min_len += strlen(homedir) + 1;
    min_len += strlen(s);
    if (min_len < BUFSIZ)
      min_len = BUFSIZ;

    work_dir = set_work_dir(NULL, min_len);

    if (*s == '/')
      strncpy(work_dir, s, min_len);
    else
      snprintf(work_dir, min_len, "%s/%s", homedir, s);
  }
  /* lop-off trailing "/" for consistency */
  if (strlen(work_dir) > 1 && work_dir[strlen(work_dir) - 1] == '/')
    work_dir[strlen(work_dir) - 1] = (char)0;

  /* get the current working directory, which will become the prev_dir, on success */
  new_prev_dir = getcwd(NULL, BUFSIZ);
  if (!new_prev_dir)
    return -1;

  if (!access(work_dir, R_OK | X_OK) && !chdir(work_dir)) {
    /* was able to change to new working directory */
    free(prev_dir);
    prev_dir = new_prev_dir;
  }
  else {
    /* Could not change to the new working directory */
    mc_wbell();
    werror(
        _("Could not change to directory %s (%s)"), 
        work_dir,
        strerror(errno));

    /* restore the previous working directory */
    free(work_dir);
    work_dir = set_work_dir(new_prev_dir, strlen(new_prev_dir));
  }

  /* All right, draw the file directory! */

  if (flushit) {
    dirflush = 0;
    mc_winclr(main_w);
    mc_wredraw(main_w, 1);
  }

  mc_wcursor(main_w, CNORMAL);

  {
    char *s;

    if (down_loading) {
      if (how_many < 0)
        s = _("Select one or more files for download");
      else if (how_many)
	s = _("Select a file for download");
      else
	s = _("Select a directory for download");
    } else {
      if (how_many < 0)
        s = _("Select one or more files for upload");
      else if (how_many)
	s = _("Select a file for upload");
      else
	s = _("Select a directory for upload");
    }
    snprintf(file_title, sizeof(file_title), "%s", s);
  }

  mc_wtitle(main_w, TMID, file_title);
  if ((new_dp_len = strlen(work_dir)) > dp_len) {
    dp_len = new_dp_len;
    snprintf(cwd_str_fmt, sizeof(cwd_str_fmt),
             _("Directory: %%-%ds"), (int)dp_len);
  }
  new_dp_len = mbslen (work_dir);
  if (new_dp_len + (fmt_len = mbslen(cwd_str_fmt)) > 75) {
    size_t i;
    char *tmp_dir = work_dir;

    /* We want the last 73 characters */
    for (i = 0; 73 + i < new_dp_len + fmt_len; i++) {
      wchar_t wc;

      tmp_dir += one_mbtowc(&wc, work_dir, MB_LEN_MAX);
    }
    snprintf(disp_dir, sizeof(disp_dir), "...%s", tmp_dir);
    snprintf(cwd_str, sizeof(cwd_str), cwd_str_fmt, disp_dir);
  } else
    snprintf(cwd_str, sizeof(cwd_str), cwd_str_fmt, work_dir);

  mc_wlocate(main_w, 0, 0);
  mc_wputs(main_w, cwd_str);

  for (i = 0; i < WHAT_NR_OPTIONS; i++) {
    const char *str, *c;
    size_t j;

    str = _(what[i]);
    c = str;
    for (j = 0; j < WHAT_WIDTH - 1 && *c != 0; j++) {
      wchar_t wc;
      c += one_mbtowc (&wc, c, MB_LEN_MAX);
    }
    what_lens[i] = c - str;
    j = WHAT_WIDTH - j; /* Characters left for padding */
    what_padding[i][1] = j / 2; /* Rounding down */
    what_padding[i][0] = j - what_padding[i][1]; /* >= 1 */
  }
  mc_wlocate(dsub, initial_y, 0);
  for (i = 0; i < WHAT_NR_OPTIONS; i++)
    horiz_draw(i, mc_wgetattr(dsub), mc_wgetattr(dsub));

  mc_wsetregion(main_w, 1, main_w->ys - FILE_MWTR);
  main_w->doscroll = 0;

  /* old dir to discard? */
  free(dirdat);
  dirdat = NULL;

  /* get sorted directory */
  if ((nrents = getsdir(".", wc_str,
                        GETSDIR_PARNT|GETSDIR_NSORT|GETSDIR_DIRSF,
                        0, &dirdat, &longest)) < 0) {
    /* we really want to announce the error here!!! */
    mc_wclose(main_w, 1);
    mc_wclose(dsub, 1);
    free(dirdat);
    dirdat = NULL;
    return -1;
  }

  global_dirdat = dirdat; // Hmm...

  prdir(main_w, top, top, dirdat, longest);
  mc_wlocate(main_w, initial_y, main_w->ys - FILE_MWTR);
  mc_wputs(main_w, _("( Escape to exit, Space to tag )"));
  dhili(subm);
  /* this really needs to go in dhili !!!*/
  mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
  if (flushit) {
    dirflush = 1;
    mc_wredraw(dsub, 1);
  }

  return 0;
}