Ejemplo n.º 1
0
static void update_tab_title_width(struct view *v, int tab_number)
{
	int w = tab_title_width(tab_number, buffer_filename(v->buffer));

	v->tt_width = w;
	v->tt_truncated_width = w;
}
Ejemplo n.º 2
0
static void print_horizontal_tab_title(struct view *v, int idx)
{
	int skip = v->tt_width - v->tt_truncated_width;
	const char *filename = buffer_filename(v->buffer);
	char buf[16];

	if (skip > 0) {
		filename += u_skip_chars(filename, &skip);
	}

	snprintf(buf, sizeof(buf), "%c%d%s",
		obuf.x == 0 && idx > 0 ? '<' : ' ',
		idx + 1,
		buffer_modified(v->buffer) ? "+" : ":");

	if (v == v->window->view)
		set_builtin_color(BC_ACTIVETAB);
	else
		set_builtin_color(BC_INACTIVETAB);
	buf_add_str(buf);
	buf_add_str(filename);
	if (obuf.x == obuf.width - 1 && idx < v->window->views.count - 1)
		buf_put_char('>');
	else
		buf_put_char(' ');
}
Ejemplo n.º 3
0
Archivo: io.c Proyecto: bobrippling/uvi
void dumpbuffer(buffer_t *b)
{
	char dump_postfix[] = "_dump_a";
	FILE *f;
	struct stat st;
	char *path, freepath = 0, *prefixletter;

	if(!b)
		return;

	path = dump_postfix;

	if(buffer_hasfilename(b)){
		char *const s = malloc(strlen(buffer_filename(b)) + strlen(dump_postfix) + 1);
		if(s){
			freepath = 1;
			strcpy(s, buffer_filename(b));
			strcat(s, dump_postfix);
			path = s;
		}
	}

	prefixletter = path + strlen(path) - 1;
	/*
	 * if file exists, increase dump prefix,
	 * else (and on stat error), save
	 */
	do
		if(stat(path, &st) == 0)
			/* exists */
			++*prefixletter;
		else
			break;
	while(*prefixletter < 'z');
	/* if it's 'z', the user should clean their freakin' directory */

	f = fopen(path, "w");

	if(freepath)
		free(path);

	if(f){
		buffer_dump(b, f);
		fclose(f);
	}
}
Ejemplo n.º 4
0
//This is a very important function. It writes all registered buffers, all variables and the command history to the directory specified in the first argument. Also, it generates eps-files from the switching histogram buffer and log-normalized escape rate buffer.
variable flux_write_all_data(opts o,interpreter *i)
{
    char *s;
    char *vars;
    FILE *f;
    char buffer[1024];
    variable v=init_variable();
    if (i->cast_string(&s,o,0))
    {
        sprintf(buffer,"mkdir \"./data/%s\"",s);
        system(buffer);
        sprintf(buffer,"./data/%s/history.ini",s);
        f=fopen(buffer,"w");
        if(f==NULL)
            return v;
        if (i->get_history()!=NULL)
            fwrite((void *)(i->get_history()),strlen((i->get_history()))+1,1,f);
        fclose(f);
        for(int x=0;x<n_buffers();x++)
        {
				if (buffer_filename(x)!=NULL && buffer_empty(x)==0)
				{
					sprintf(buffer,"write_buffer(%d,\"./data/%s/%s\");",x,s,buffer_filename(x));
					i->eval_str(buffer,1);
					sprintf(buffer,"plot_buffer(%d,\"./data/%s/%s.eps\");",x,s,buffer_filename(x));
					i->eval_str(buffer,1);
				}
        }
        sprintf(buffer,"./data/%s/vars.ini",s);
        f=fopen(buffer,"w");
        if(f==NULL)
            return v;
        vars=i->output_all_variables();
        fwrite((void *)vars,strlen(vars),1,f);
        fclose(f);
        free(vars);
    }
    return v;    
}
Ejemplo n.º 5
0
static void print_vertical_tab_title(struct view *v, int idx, int width)
{
	const char *orig_filename = buffer_filename(v->buffer);
	const char *filename = orig_filename;
	int max = options.tab_bar_max_components;
	char buf[16];
	int skip;

	snprintf(buf, sizeof(buf), "%2d%s", idx + 1, buffer_modified(v->buffer) ? "+" : " ");
	if (max) {
		int i, count = 1;

		for (i = 0; filename[i]; i++) {
			if (filename[i] == '/')
				count++;
		}
		// ignore first slash because it does not separate components
		if (filename[0] == '/')
			count--;

		if (count > max) {
			// skip possible first slash
			for (i = 1; ; i++) {
				if (filename[i] == '/' && --count == max) {
					i++;
					break;
				}
			}
			filename += i;
		}
	} else {
		skip = strlen(buf) + u_str_width(filename) - width + 1;
		if (skip > 0)
			filename += u_skip_chars(filename, &skip);
	}
	if (filename != orig_filename) {
		// filename was shortened. add "<<" symbol
		long i = strlen(buf);
		u_set_char(buf, &i, 0xab);
		buf[i] = 0;
	}

	if (v == v->window->view)
		set_builtin_color(BC_ACTIVETAB);
	else
		set_builtin_color(BC_INACTIVETAB);
	buf_add_str(buf);
	buf_add_str(filename);
	buf_clear_eol();
}
Ejemplo n.º 6
0
void update_term_title(struct buffer *b)
{
    static int term_type = -1;
    char title[1024];

    if (term_type == -1) {
        const char *term = getenv("TERM");

        term_type = 0;
        if (term) {
            if (strstr(term, "xterm") || strstr(term, "rxvt")) {
                term_type = 1;
            } else if (streq(term, "screen")) {
                term_type = 2;
            }
        }
    }

    // FIXME: title must not contain control characters
    snprintf(title, sizeof(title), "%s %c %s",
             buffer_filename(b),
             buffer_modified(b) ? '+' : '-',
             program);

    switch (term_type) {
    case 1:
        // xterm or compatible
        buf_escape("\033]2;");
        buf_escape(title);
        buf_escape("\007");
        break;
    case 2:
        // tmux or screen
        // NOTE: screen might need to be configured to get it working
        buf_escape("\033_");
        buf_escape(title);
        buf_escape("\033\\");
        break;
    }
}
Ejemplo n.º 7
0
void cmd_exit (char *cp)

{
  const char *bn, *fn, *ynanswer;
  Buffer *buffer;
  int prompt, saveflag, ynflag;
  String *ynstring;

  /* Check for -save qualifier - it inhibits deleting the journal file */

  saveflag = 0;
  if ((strncasecmp (cp, "-save", 5) == 0) && (cp[5] <= ' ')) {
    if ((journal_name == NULL) || (journal_name[0] == 0)) {
      outerr (0, "there is no journal file to save\n");
      return;
    }
    saveflag = 1;
    cp = skipspaces (cp + 5);
  }

  /* Maybe use a different name for main buffer */

  if (*cp != 0) buffer_setfile (main_buffer, cp);

  /* Don't bother if recovery mode, we want them to be able to do more.  They can re-type exit command */

  if (recover_file != NULL) {
    outerr (0, "EXIT command ignored in recovery mode\n");
    return;
  }

  /* Check for buffers that have filename of "" (opened -readonly) but were modified */

  prompt = 0;
  for (buffer = NULL; (buffer = buffer_next (buffer)) != NULL;) {
    fn = buffer_filename (buffer);
    if (fn == NULL) continue;
    if (fn[0] != 0) continue;
    if (buffer_dirty (buffer, -1)) {
      bn = buffer_name (buffer);
      if (!prompt) outerr (0, "\n");
      outerr (strlen (bn), "buffer %s was modified but has no output file\n", bn);
      prompt = 1;
    }
  }
  if (prompt) {
    do {
      ynstring = jnl_readprompt ("\r\n  do you still want to exit (yes or no)? ");
      if (ynstring == NULL) return;
      ynflag   = -1;
      ynanswer = string_getval (ynstring);
      if (strcasecmp (ynanswer, "no")  == 0) ynflag = 0;
      if (strcasecmp (ynanswer, "yes") == 0) ynflag = 1;
      string_delete (ynstring);
    } while (ynflag < 0);
    if (!ynflag) return;
  }

  /* Write the entire contents of all the buffers that have files and that have been modified to their respective files */

  for (buffer = NULL; (buffer = buffer_next (buffer)) != NULL;) {
    fn = buffer_filename (buffer);							/* get output filename */
    if (fn == NULL) continue;								/* if none, don't try to write */
    bn = buffer_name (buffer);								/* ok, write it out */
    if (!buffer_dirty (buffer, -1)) {
      outerr (strlen (fn) + strlen (bn), "not writing %s from =%s because it is unmodified\n", fn, bn);
      continue;
    }
    outerr (strlen (fn) + strlen (bn), "writing %s from =%s: ", fn, bn);
    if (!write_file (fn, buffer_first_line (buffer), buffer_last_line (buffer))) {
      outerr (strlen (fn), "output file %s not written, not exiting\n", fn);		/* if error, don't exit */
      return;
    }
    buffer_dirty (buffer, 0);
  }

  /* Write successful, maybe delete journal file and terminate process */

  jnl_close (!saveflag);
  output ();
  exit (0);
}
Ejemplo n.º 8
0
void cmd_show (char *cp)

{
  char c, curbf, dirty, *p;
  const char *fname, *name;
  int l, rf;
  Buffer *buffer;
  uLong lines;

  if (*cp == 0) goto usage;

  do {
    p = uptospace (cp);

    /* Show buffer info */

    if (strncasecmp ("buffers", cp, p - cp) == 0) {
      outfmt (0, "\nBuffers:\n");
      l = 0;
      for (buffer = NULL; (buffer = buffer_next (buffer)) != NULL;) {
        name  = buffer_name (buffer);
        if (strlen (name) > l) l = strlen (name);
      }
      for (buffer = NULL; (buffer = buffer_next (buffer)) != NULL;) {
        name  = buffer_name (buffer);
        fname = buffer_filename (buffer);
        lines = buffer_linecount (buffer);
        rf    = (buffer_getreadfile (buffer) != NULL);
        curbf = (buffer == cur_position.buffer) ? '>' : ' ';
        dirty = buffer_dirty (buffer, -1) ? '*' : ' ';
        outfmt (strlen (name) + 16, " %c %c %*.*s: %5u%c line%c", curbf, dirty, l, l, name, lines, rf ? '+' : ' ', (lines == 1) ? ' ' : 's');
        if (fname != NULL) outfmt (strlen (fname), " => %s", fname);
        if (buffer == main_buffer) outstr ("  (main buffer)");
        outchr ('\n');
      }
      continue;
    }

    /* Show info about files */

    if (strncasecmp ("files", cp, p - cp) == 0) {
      outfmt (0, "\nFiles:\n");
      outfmt (strlen (help_name),    "     Help: %s\n", help_name);
      outfmt (strlen (journal_name), "  Journal: %s\n", journal_name[0] == 0 ? "<none>" : journal_name);
      continue;
    }

    /* Show keypad definitions */

    if (strncasecmp ("keypad", cp, p - cp) == 0) {
      show_keypad ();
      continue;
    }
    goto usage;

  } while (*(cp = skipspaces (p)) != 0);
  return;

usage:
  outerr (0, "specify BUFFERS, FILES, KEYPAD\n");
}