Ejemplo n.º 1
0
void
sleeping(int sig)
{
    char i;

    sig++;
    i = nox;
    nox = 1;
    statusbar(NULL);
    nox = i;

    if (idletime >= 0)
	idletime++;

    if (idletime == 2)
	(void) mono_change_online(who_am_i(NULL), "", 6);

    if (idletime == 5)		/* if been idle for 5 minutes, put in wholist */
	(void) mono_change_online(who_am_i(NULL), "", 2);

#ifndef CLIENTSRC

    if ((idletime % TIMEOUT) == 0) {
	IFSYSOP {
	    cprintf("\n\007\1f\1wBEEP! Idle Admin are bad for the BBS!\nLog out!\1a\n");
	}
	else {
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: sgh/aos
int main(void) {
	float angle = 0;
	int y;
	y = 100;
	UGui& gui = *UGui::instance();
	Drawable mainscreen(0 ,0, 320, 240);
	Drawable statusbar(0 ,0, 320, 30);
	Cross bladeview(0,30,320,120);
	Drawable mainfall(0,150,100,70);
	Drawable mast(105,150,110,70);
	Drawable rotation(220,150,100,70);
	Drawable quickmenu(0,220,320,20);
	

// 	Drawable menu(20 ,y-30, 200, 50);

	gtkfb_init();

	printf("sizeof Drawable: %lu\n", sizeof(Drawable));


	statusbar.setBG(0x555555);
	bladeview.setBG(0xFFFFFF);
	quickmenu.setBG(0x555555);

	mainfall.setBG(0x550000);
	mast.setBG(0x005500);
	rotation.setBG(0x000055);

// 	menu.setBG(0x005555);

	mainscreen.addChild(statusbar);
	mainscreen.addChild(bladeview);
	mainscreen.addChild(mainfall);
	mainscreen.addChild(mast);
	mainscreen.addChild(rotation);
	mainscreen.addChild(quickmenu);
	
// 	mainscreen.addChild(menu);

	gui.addRoot(mainscreen);
// 	gui.addRoot(menu);
	gui.eventLoop();

	for (;;) {
		int ch = getchar();

		switch (ch) {
			case 'A': mainfall.setBG(0xFF0000); break;
			case 'a': mainfall.setBG(0x550000); break;
			case 'B': mast.setBG(0x00FF00); break;
			case 'b': mast.setBG(0x005500); break;
			case 'C': rotation.setBG(0x0000FF); break;
			case 'c': rotation.setBG(0x000055); break;
			case 'f': rotation.focus(); break;
		}
		gui.eventLoop();
	}
}
void MainWindow::startApp(){
    QString app_name = startAppDialogTextLineEdit->text();
    QString app_arguments = ( startAppDialogWithTestability->isChecked() ) ? "-testability" : "";
    QString cmd = activeDevice + " start_application " + app_name + " " + app_arguments;

    //qDebug() << "Executing app" + cmd;

    if ( !executeTDriverCommand( commandStartApplication, cmd)) {
        statusbar(tr("Error: Failed to start application."), 1000 );
        disconnectExclusiveSUT();
    }
    else {
        startAppDialog->hide();
        statusbar(tr("Applicaton started, refreshing..."), 1000 );
        sendAppListRequest(true);
    }
    startAppDialog->close();
}
Ejemplo n.º 4
0
Archivo: search.c Proyecto: ris21/yoda
/* Search for a string. */
void do_search(void)
{
    linestruct *fileptr = openfile->current;
    size_t fileptr_x = openfile->current_x;
    size_t pww_save = openfile->placewewant;
    int i;
    bool didfind;

    i = search_init(FALSE, FALSE);

    if (i == -1)
	/* Cancel, Go to Line, blank search string, or regcomp() failed. */
	search_replace_abort();
    else if (i == -2)
	/* Replace. */
	do_replace();
#if !defined(NANO_TINY) || defined(HAVE_REGEX_H)
    else if (i == 1)
	/* Case Sensitive, Backwards, or Regexp search toggle. */
	do_search();
#endif

    if (i != 0)
	return;

    /* If answer is now "", copy last_search into answer. */
    if (*answer == '\0')
	answer = mallocstrcpy(answer, last_search);
    else
	last_search = mallocstrcpy(last_search, answer);

#ifndef DISABLE_HISTORIES
    /* If answer is not "", add this search string to the search history
     * list. */
    if (answer[0] != '\0')
	update_history(&search_history, answer);
#endif

    findnextstr_wrap_reset();
    didfind = findnextstr(
#ifndef DISABLE_SPELLER
	FALSE,
#endif
	openfile->current, openfile->current_x, answer, NULL);

    /* If we found something, and we're back at the exact same spot where
     * we started searching, then this is the only occurrence. */
    if (fileptr == openfile->current && fileptr_x ==
	openfile->current_x && didfind) {
	    statusbar(_("This is the only occurrence"));
    }

    openfile->placewewant = xplustabs();
    edit_redraw(fileptr, pww_save);
    search_replace_abort();
}
Ejemplo n.º 5
0
Archivo: search.c Proyecto: ris21/yoda
/* Search for the last string without prompting. */
void do_research(void)
{
    linestruct *fileptr = openfile->current;
    size_t fileptr_x = openfile->current_x;
    size_t pww_save = openfile->placewewant;
    bool didfind;

    focusing = TRUE;

#ifndef DISABLE_HISTORIES
    /* If nothing was searched for yet during this run of nano, but
     * there is a search history, take the most recent item. */
    if (last_search[0] == '\0' && searchbot->prev != NULL)
	last_search = mallocstrcpy(last_search, searchbot->prev->data);
#endif

    if (last_search[0] != '\0') {
#ifdef HAVE_REGEX_H
	/* Since answer is "", use last_search! */
	if (ISSET(USE_REGEXP) && !regexp_init(last_search))
	    return;
#endif

	findnextstr_wrap_reset();
	didfind = findnextstr(
#ifndef DISABLE_SPELLER
		FALSE,
#endif
		openfile->current, openfile->current_x, last_search, NULL);

	/* If we found something, and we're back at the exact same spot
	 * where we started searching, then this is the only occurrence. */
	if (fileptr == openfile->current && fileptr_x ==
		openfile->current_x && didfind) {
		statusbar(_("This is the only occurrence"));
	}
    } else
	statusbar(_("No current search pattern"));

    openfile->placewewant = xplustabs();
    edit_redraw(fileptr, pww_save);
    search_replace_abort();
}
Ejemplo n.º 6
0
/* Indicate on the statusbar that the string at str was not found by the
 * last search. */
void not_found_msg(const char *str)
{
    char *disp;
    int numchars;

    assert(str != NULL);

    disp = display_string(str, 0, (COLS / 2) + 1, FALSE);
    numchars = actual_x(disp, mbstrnlen(disp, COLS / 2));

    statusbar(_("\"%.*s%s\" not found"), numchars, disp,
	(disp[numchars] == '\0') ? "" : "...");

    free(disp);
}
Ejemplo n.º 7
0
char
prepare_link (struct eventState *pes)
{
  if (isFileLink (pes->p))
    {
      sprintf (pes->text_holder, "%.*s", link_length (pes->p), pes->p);

      pes->link_text = 0;
      if (pes->first_time)
	pes->hidden = 1;

      statusbar (NULL);
      return 1;
    }

  return 0;
}
Ejemplo n.º 8
0
/* Mark the current file as modified if it isn't already, and then
 * update the titlebar to display the file's new status. */
void set_modified(void)
{
	if (!openfile->modified) {
		openfile->modified = true;
		titlebar(NULL);
		if (ISSET(LOCKING)) {
			if (openfile->filename == "") {
				/* Don't bother with a lockfile if there isn't an actual file open */
				return;
			} else if (openfile->lock_filename == "") {
				/* Translators: Try to keep this at most 80 characters. */
				statusbar(_("Warning: Modifying a file which is not locked, check directory permission?"));
			} else {
				write_lockfile(openfile->lock_filename, get_full_path(openfile->filename), true);
			}
		}
	}
}
Ejemplo n.º 9
0
/* If constant is true, we display the current cursor position only if
 * disable_cursorpos is false.  Otherwise, we display it
 * unconditionally and set disable_cursorpos to false.  If constant is
 * true and disable_cursorpos is true, we also set disable_cursorpos to
 * false, so that we leave the current statusbar alone this time, and
 * display the current cursor position next time. */
void do_cursorpos(bool constant)
{
	filestruct *f;
	char c;
	size_t i, cur_xpt = xplustabs() + 1;
	size_t cur_lenpt = strlenpt(openfile->current->data) + 1;
	int linepct, colpct, charpct;

	assert(openfile->fileage != NULL && openfile->current != NULL);

	f = openfile->current->next;
	c = openfile->current->data[openfile->current_x];

	openfile->current->next = NULL;
	openfile->current->data[openfile->current_x] = '\0';

	i = get_totsize(openfile->fileage, openfile->current);

	openfile->current->data[openfile->current_x] = c;
	openfile->current->next = f;

	if (constant && disable_cursorpos) {
		disable_cursorpos = false;
		return;
	}

	/* Display the current cursor position on the statusbar, and set
	 * disable_cursorpos to false. */
	linepct = 100 * openfile->current->lineno / openfile->filebot->lineno;
	colpct = 100 * cur_xpt / cur_lenpt;
	charpct = (openfile->totsize == 0) ? 0 : 100 * i / openfile->totsize;

	statusbar(
	    _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
	    (long)openfile->current->lineno,
	    (long)openfile->filebot->lineno, linepct,
	    (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct,
	    (unsigned long)i, (unsigned long)openfile->totsize, charpct);

	disable_cursorpos = false;
}
Ejemplo n.º 10
0
main()
{
  char current_time[50];
  char hostname[10];
  char battery_remain[4];
  char status_string[100];

  launch_statusbar();

  for (;;sleep(1)) {
    host(hostname);
    datetime(current_time);
    battery_status(battery_remain);

    status(status_string, hostname, battery_remain, current_time);
    statusbar(status_string);
  }

  close_statusbar();

  return 0;
}
Ejemplo n.º 11
0
void handler() {
	process_keys();
	update_projectiles();
	update_animations();
	step_monsters();

	game.player.light->update_flicker();
	process_sight();
	draw_lights(game.fov_light, &game.map.block, game.map.lights);
	{
		lightsource *k = game.map.lights.head();
		for (; k; k = k->next()) {
			k->update_flicker();
			draw_light(game.fov_light, &game.map.block, k);
		}
	}

	u32 keys = keysHeld();
	u32 down = keysDown();
	touchPosition touch = touchReadXY();
	if (down & KEY_TOUCH && keys & KEY_R && touch.px != 0 && touch.py != 0) {
		luxel *l = torch.buf.luxat(torch.buf.scroll.x + touch.px/8, torch.buf.scroll.y + touch.py/8);
		iprintf("c:%d,%d,%d v:%d, low:%d\n", l->lr, l->lg, l->lb, l->lval, torch.get_low_luminance());
	}

	refresh(&game.map.block);

	if (game.player.hp <= 0) {
		playerdeath();
		game.player.clear();
		new_game();
	}

	if (game.cooldown <= 0) game.player.regenerate();

	statusbar();
}
Ejemplo n.º 12
0
/* Look for needle, starting at (current, current_x).  begin is the line
 * where we first started searching, at column begin_x.  The return
 * value specifies whether we found anything.  If we did, set needle_len
 * to the length of the string we found if it isn't NULL. */
bool findnextstr(
#ifndef DISABLE_SPELLER
	bool whole_word_only,
#endif
	const filestruct *begin, size_t begin_x,
	const char *needle, size_t *needle_len)
{
    size_t found_len;
	/* The length of the match we find. */
    size_t current_x_find = 0;
	/* The location in the current line of the match we find. */
    ssize_t current_y_find = openfile->current_y;
    filestruct *fileptr = openfile->current;
    const char *rev_start = fileptr->data, *found = NULL;
    time_t lastkbcheck = time(NULL);

    /* rev_start might end up 1 character before the start or after the
     * end of the line.  This won't be a problem because strstrwrapper()
     * will return immediately and say that no match was found, and
     * rev_start will be properly set when the search continues on the
     * previous or next line. */
    rev_start +=
#ifndef NANO_TINY
	ISSET(BACKWARDS_SEARCH) ?
	((openfile->current_x == 0) ? -1 : move_mbleft(fileptr->data, openfile->current_x)) :
#endif
	move_mbright(fileptr->data, openfile->current_x);

    /* Look for needle in the current line we're searching. */
    enable_nodelay();
    while (TRUE) {
	if (time(NULL) - lastkbcheck > 1) {
	    int input = parse_kbinput(edit);

	    lastkbcheck = time(NULL);

	    if (input && func_from_key(&input) == do_cancel) {
		statusbar(_("Cancelled"));
		return FALSE;
	    }
	}

	found = strstrwrapper(fileptr->data, needle, rev_start);

	/* We've found a potential match. */
	if (found != NULL) {
#ifndef DISABLE_SPELLER
	    bool found_whole = FALSE;
		/* Is this potential match a whole word? */
#endif

	    /* Set found_len to the length of the potential match. */
	    found_len =
#ifdef HAVE_REGEX_H
		ISSET(USE_REGEXP) ?
		regmatches[0].rm_eo - regmatches[0].rm_so :
#endif
		strlen(needle);

#ifndef DISABLE_SPELLER
	    /* If we're searching for whole words, see if this potential
	     * match is a whole word. */
	    if (whole_word_only) {
		char *word = mallocstrncpy(NULL, found, found_len + 1);
		word[found_len] = '\0';

		found_whole = is_whole_word(found - fileptr->data,
			fileptr->data, word);
		free(word);
	    }

	    /* If we're searching for whole words and this potential
	     * match isn't a whole word, continue searching. */
	    if (!whole_word_only || found_whole)
#endif
		break;
	}

	if (search_last_line) {
	    /* We've finished processing the file, so get out. */
	    not_found_msg(needle);
	    disable_nodelay();
	    return FALSE;
	}

	/* Move to the previous or next line in the file. */
#ifndef NANO_TINY
	if (ISSET(BACKWARDS_SEARCH)) {
	    fileptr = fileptr->prev;
	    current_y_find--;
	} else {
#endif
	    fileptr = fileptr->next;
	    current_y_find++;
#ifndef NANO_TINY
	}
#endif

	if (fileptr == NULL) {
	    /* We've reached the start or end of the buffer, so wrap around. */
#ifndef NANO_TINY
	    if (ISSET(BACKWARDS_SEARCH)) {
		fileptr = openfile->filebot;
		current_y_find = editwinrows - 1;
	    } else {
#endif
		fileptr = openfile->fileage;
		current_y_find = 0;
#ifndef NANO_TINY
	    }
#endif
	    statusbar(_("Search Wrapped"));
	}

	if (fileptr == begin)
	    /* We've reached the original starting line. */
	    search_last_line = TRUE;

	rev_start = fileptr->data;
#ifndef NANO_TINY
	if (ISSET(BACKWARDS_SEARCH))
	    rev_start += strlen(fileptr->data);
#endif
    }

    /* We found an instance. */
    current_x_find = found - fileptr->data;

    /* Ensure we haven't wrapped around again! */
    if (search_last_line &&
#ifndef NANO_TINY
	((!ISSET(BACKWARDS_SEARCH) && current_x_find > begin_x) ||
	(ISSET(BACKWARDS_SEARCH) && current_x_find < begin_x))
#else
	current_x_find > begin_x
#endif
	) {
	not_found_msg(needle);
	disable_nodelay();
	return FALSE;
    }

    disable_nodelay();
    /* We've definitely found something. */
    openfile->current = fileptr;
    openfile->current_x = current_x_find;
    openfile->placewewant = xplustabs();
    openfile->current_y = current_y_find;

    /* needle_len holds the length of needle. */
    if (needle_len != NULL)
	*needle_len = found_len;

    return TRUE;
}
Ejemplo n.º 13
0
/* Set up the system variables for a search or replace.  If use_answer
 * is TRUE, only set backupstring to answer.  Return -2 to run the
 * opposite program (search -> replace, replace -> search), return -1 if
 * the search should be canceled (due to Cancel, a blank search string,
 * Go to Line, or a failed regcomp()), return 0 on success, and return 1
 * on rerun calling program.
 *
 * replacing is TRUE if we call from do_replace(), and FALSE if called
 * from do_search(). */
int search_init(bool replacing, bool use_answer)
{
    int i = 0;
    char *buf;
    static char *backupstring = NULL;
	/* The search string we'll be using. */

    /* If backupstring doesn't exist, initialize it to "". */
    if (backupstring == NULL)
	backupstring = mallocstrcpy(NULL, "");

    /* If use_answer is TRUE, set backupstring to answer and get out. */
    if (use_answer) {
	backupstring = mallocstrcpy(backupstring, answer);
	return 0;
    }

    /* We display the search prompt below.  If the user types a partial
     * search string and then Replace or a toggle, we will return to
     * do_search() or do_replace() and be called again.  In that case,
     * we should put the same search string back up. */

    focusing = TRUE;

    if (last_search[0] != '\0') {
	char *disp = display_string(last_search, 0, COLS / 3, FALSE);

	buf = charalloc(strlen(disp) + 7);
	/* We use (COLS / 3) here because we need to see more on the line. */
	sprintf(buf, " [%s%s]", disp,
		(strlenpt(last_search) > COLS / 3) ? "..." : "");
	free(disp);
    } else
	buf = mallocstrcpy(NULL, "");

    /* This is now one simple call.  It just does a lot. */
    i = do_prompt(FALSE,
#ifndef DISABLE_TABCOMP
	TRUE,
#endif
	replacing ? MREPLACE : MWHEREIS, backupstring,
#ifndef DISABLE_HISTORIES
	&search_history,
#endif
	/* TRANSLATORS: This is the main search prompt. */
	edit_refresh, "%s%s%s%s%s%s", _("Search"),
#ifndef NANO_TINY
	/* TRANSLATORS: The next three strings are modifiers of the search prompt. */
	ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") :
#endif
	"",
#ifdef HAVE_REGEX_H
	ISSET(USE_REGEXP) ? _(" [Regexp]") :
#endif
	"",
#ifndef NANO_TINY
	ISSET(BACKWARDS_SEARCH) ? _(" [Backwards]") :
#endif
	"", replacing ?
#ifndef NANO_TINY
	/* TRANSLATORS: The next two strings are modifiers of the search prompt. */
	openfile->mark_set ? _(" (to replace) in selection") :
#endif
	_(" (to replace)") : "", buf);

    fflush(stderr);

    /* Release buf now that we don't need it anymore. */
    free(buf);

    free(backupstring);
    backupstring = NULL;

    /* Cancel any search, or just return with no previous search. */
    if (i == -1 || (i < 0 && *last_search == '\0') || (!replacing &&
	i == 0 && *answer == '\0')) {
	statusbar(_("Cancelled"));
	return -1;
    } else {
	functionptrtype func = func_from_key(&i);

	if (i == -2 || i == 0 ) {
#ifdef HAVE_REGEX_H
		/* Use last_search if answer is an empty string, or
		 * answer if it isn't. */
		if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ?
			last_search : answer))
		    return -1;
#endif
		;
#ifndef NANO_TINY
	} else if (func == case_sens_void) {
		TOGGLE(CASE_SENSITIVE);
		backupstring = mallocstrcpy(backupstring, answer);
		return 1;
	} else if (func == backwards_void) {
		TOGGLE(BACKWARDS_SEARCH);
		backupstring = mallocstrcpy(backupstring, answer);
		return 1;
#endif
#ifdef HAVE_REGEX_H
	} else if (func == regexp_void) {
		TOGGLE(USE_REGEXP);
		backupstring = mallocstrcpy(backupstring, answer);
		return 1;
#endif
	} else if (func == do_replace || func == flip_replace_void) {
		backupstring = mallocstrcpy(backupstring, answer);
		return -2;	/* Call the opposite search function. */
	} else if (func == do_gotolinecolumn_void) {
		do_gotolinecolumn(openfile->current->lineno,
			openfile->placewewant + 1, TRUE, TRUE);
				/* Put answer up on the statusbar and
				 * fall through. */
		return 3;
	} else {
		return -1;
	}
    }

    return 0;
}
Ejemplo n.º 14
0
Archivo: browser.c Proyecto: ris21/yoda
/* Our main file browser function.  path is the tilde-expanded path we
 * start browsing from. */
char *do_browser(char *path, DIR *dir)
{
    char *retval = NULL;
    int kbinput;
    bool old_const_update = ISSET(CONST_UPDATE);
    char *prev_dir = NULL;
	/* The directory we were in before backing up to "..". */
    char *ans = NULL;
	/* The last answer the user typed at the statusbar prompt. */
    size_t old_selected;
	/* The selected file we had before the current selected file. */
    functionptrtype func;
	/* The function of the key the user typed in. */

    curs_set(0);
    blank_statusbar();
    bottombars(MBROWSER);
    wnoutrefresh(bottomwin);

    UNSET(CONST_UPDATE);

    ans = mallocstrcpy(NULL, "");

  change_browser_directory:
	/* We go here after we select a new directory. */

    /* Start with no key pressed. */
    kbinput = ERR;

    path = mallocstrassn(path, get_full_path(path));

    /* Save the current path in order to be used later. */
    path_save = path;

    assert(path != NULL && path[strlen(path) - 1] == '/');

    /* Get the file list, and set longest and width in the process. */
    browser_init(path, dir);

    assert(filelist != NULL);

    /* Sort the file list. */
    qsort(filelist, filelist_len, sizeof(char *), diralphasort);

    /* If prev_dir isn't NULL, select the directory saved in it, and
     * then blow it away. */
    if (prev_dir != NULL) {
	browser_select_dirname(prev_dir);

	free(prev_dir);
	prev_dir = NULL;
    /* Otherwise, select the first file or directory in the list. */
    } else
	selected = 0;

    old_selected = (size_t)-1;

    titlebar(path);

    while (TRUE) {
	struct stat st;
	int i;
	size_t fileline = selected / width;
		/* The line number the selected file is on. */
	char *new_path;
		/* The path we switch to at the "Go to Directory"
		 * prompt. */

	/* Display the file list if we don't have a key, or if the
	 * selected file has changed, and set width in the process. */
	if (kbinput == ERR || old_selected != selected)
	    browser_refresh();

	old_selected = selected;

	kbinput = get_kbinput(edit);

#ifndef NANO_TINY
	if (kbinput == KEY_WINCH) {
	    kbinput = ERR;
	    curs_set(0);
	    continue;
	}
#endif

#ifndef DISABLE_MOUSE
	if (kbinput == KEY_MOUSE) {
	    int mouse_x, mouse_y;

	    /* We can click on the edit window to select a
	     * filename. */
	    if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0 &&
		wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
		/* longest is the width of each column.  There
		 * are two spaces between each column. */
		selected = (fileline / editwinrows) *
				(editwinrows * width) + (mouse_y *
				width) + (mouse_x / (longest + 2));

		/* If they clicked beyond the end of a row,
		 * select the last filename in that row. */
		if (mouse_x > width * (longest + 2))
		    selected--;

		/* If we're off the screen, select the last filename. */
		if (selected > filelist_len - 1)
		    selected = filelist_len - 1;

		/* If we selected the same filename as last time,
		 * put back the Enter key so that it's read in. */
		if (old_selected == selected)
		    unget_kbinput(sc_seq_or(do_enter_void, 0), FALSE, FALSE);
	    }
	}
#endif /* !DISABLE_MOUSE */

	func = parse_browser_input(&kbinput);

	if (func == total_refresh) {
	    total_redraw();
	} else if (func == do_help_void) {
#ifndef DISABLE_HELP
	    do_help_void();
	    /* Perhaps the window dimensions have changed. */
	    browser_refresh();
	    curs_set(0);
#else
	    nano_disabled_msg();
#endif
	} else if (func == do_search) {
	    /* Search for a filename. */
	    curs_set(1);
	    do_filesearch();
	    curs_set(0);
	} else if (func == do_research) {
	    /* Search for another filename. */
	    do_fileresearch();
	} else if (func == do_page_up) {
	    if (selected >= (editwinrows + fileline % editwinrows) * width)
		selected -= (editwinrows + fileline % editwinrows) * width;
	    else
		selected = 0;
	} else if (func == do_page_down) {
	    selected += (editwinrows - fileline % editwinrows) * width;
	    if (selected > filelist_len - 1)
		selected = filelist_len - 1;
	} else if (func == do_first_file) {
	    selected = 0;
	} else if (func == do_last_file) {
	    selected = filelist_len - 1;
	} else if (func == goto_dir_void) {
	    /* Go to a specific directory. */
	    curs_set(1);
	    i = do_prompt(TRUE,
#ifndef DISABLE_TABCOMP
			FALSE,
#endif
			MGOTODIR, ans,
#ifndef DISABLE_HISTORIES
			NULL,
#endif
			/* TRANSLATORS: This is a prompt. */
			browser_refresh, _("Go To Directory"));

	    curs_set(0);
	    bottombars(MBROWSER);

	    /* If the directory begins with a newline (i.e. an
	     * encoded null), treat it as though it's blank. */
	    if (i < 0 || *answer == '\n') {
		/* We canceled.  Indicate that on the statusbar, and
		* blank out ans, since we're done with it. */
		statusbar(_("Cancelled"));
		ans = mallocstrcpy(ans, "");
		continue;
	    } else if (i != 0) {
		/* Put back the "Go to Directory" key and save
		 * answer in ans, so that the file list is displayed
		 * again, the prompt is displayed again, and what we
		 * typed before at the prompt is displayed again. */
		unget_kbinput(sc_seq_or(do_gotolinecolumn_void, 0), FALSE, FALSE);
		ans = mallocstrcpy(ans, answer);
		continue;
	    }

	    /* We have a directory.  Blank out ans, since we're done
	     * with it. */
	    ans = mallocstrcpy(ans, "");

	    /* Convert newlines to nulls, just before we go to the
	     * directory. */
	    sunder(answer);
	    align(&answer);

	    new_path = real_dir_from_tilde(answer);

	    if (new_path[0] != '/') {
		new_path = charealloc(new_path, strlen(path) +
				strlen(answer) + 1);
		sprintf(new_path, "%s%s", path, answer);
	    }

#ifndef DISABLE_OPERATINGDIR
	    if (check_operating_dir(new_path, FALSE)) {
		statusbar(_("Can't go outside of %s in restricted mode"),
				operating_dir);
		free(new_path);
		continue;
	    }
#endif

	    dir = opendir(new_path);
	    if (dir == NULL) {
		/* We can't open this directory for some reason.
		* Complain. */
		statusbar(_("Error reading %s: %s"), answer,
				strerror(errno));
		beep();
		free(new_path);
		continue;
	    }

	    /* Start over again with the new path value. */
	    free(path);
	    path = new_path;
	    goto change_browser_directory;
	} else if (func == do_up_void) {
	    if (selected >= width)
		selected -= width;
	} else if (func == do_down_void) {
	    if (selected + width <= filelist_len - 1)
		selected += width;
	} else if (func == do_left) {
	    if (selected > 0)
		selected--;
	} else if (func == do_right) {
	    if (selected < filelist_len - 1)
		selected++;
	} else if (func == do_enter_void) {
	    /* We can't move up from "/". */
	    if (strcmp(filelist[selected], "/..") == 0) {
		statusbar(_("Can't move up a directory"));
		beep();
		continue;
	    }

#ifndef DISABLE_OPERATINGDIR
	    /* Note: The selected file can be outside the operating
	     * directory if it's ".." or if it's a symlink to a
	     * directory outside the operating directory. */
	    if (check_operating_dir(filelist[selected], FALSE)) {
		statusbar(_("Can't go outside of %s in restricted mode"),
				operating_dir);
		beep();
		continue;
	    }
#endif

	    if (stat(filelist[selected], &st) == -1) {
		/* We can't open this file for some reason.
		 * Complain. */
		 statusbar(_("Error reading %s: %s"),
				filelist[selected], strerror(errno));
		 beep();
		 continue;
	    }

	    if (!S_ISDIR(st.st_mode)) {
		/* We've successfully opened a file, we're done, so
		 * get out. */
		retval = mallocstrcpy(NULL, filelist[selected]);
		break;
	    } else if (strcmp(tail(filelist[selected]), "..") == 0)
		/* We've successfully opened the parent directory,
		 * save the current directory in prev_dir, so that
		 * we can easily return to it by hitting Enter. */
		prev_dir = mallocstrcpy(NULL, striponedir(filelist[selected]));

	    dir = opendir(filelist[selected]);
	    if (dir == NULL) {
		/* We can't open this directory for some reason.
		 * Complain. */
		statusbar(_("Error reading %s: %s"),
				filelist[selected], strerror(errno));
		beep();
		continue;
	    }

	    path = mallocstrcpy(path, filelist[selected]);

	    /* Start over again with the new path value. */
	    goto change_browser_directory;
	} else if (func == do_exit) {
	    /* Exit from the file browser. */
	    break;
	}
    }
    titlebar(NULL);
    edit_refresh();
    curs_set(1);
    if (old_const_update)
	SET(CONST_UPDATE);

    free(path);
    free(ans);

    free_chararray(filelist, filelist_len);
    filelist = NULL;
    filelist_len = 0;

    return retval;
}
Ejemplo n.º 15
0
Archivo: search.c Proyecto: ris21/yoda
/* Go to the specified line and column, or ask for them if interactive
 * is TRUE.  Save the x-coordinate and y-coordinate if save_pos is TRUE.
 * Update the screen afterwards if allow_update is TRUE.  Note that both
 * the line and column numbers should be one-based. */
void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
	bool interactive, bool save_pos, bool allow_update)
{
    if (interactive) {
	char *ans = mallocstrcpy(NULL, answer);
	functionptrtype func;

	/* Ask for the line and column. */
	int i = do_prompt(FALSE,
#ifndef DISABLE_TABCOMP
		TRUE,
#endif
		MGOTOLINE, use_answer ? ans : "",
#ifndef DISABLE_HISTORIES
		NULL,
#endif
		/* TRANSLATORS: This is a prompt. */
		edit_refresh, _("Enter line number, column number"));

	free(ans);

	/* Cancel, or Enter with blank string. */
	if (i < 0) {
	    statusbar(_("Cancelled"));
	    display_main_list();
	    return;
	}

	func = func_from_key(&i);

	if (func == gototext_void) {
	    /* Keep answer up on the statusbar. */
	    search_init(TRUE, TRUE);

	    do_search();
	    return;
	}

	/* Do a bounds check.  Display a warning on an out-of-bounds
	 * line or column number only if we hit Enter at the statusbar
	 * prompt. */
	if (!parse_line_column(answer, &line, &column) || line < 1 ||
		column < 1) {
	    if (i == 0)
		statusbar(_("Invalid line or column number"));
	    display_main_list();
	    return;
	}
    } else {
	if (line < 1)
	    line = openfile->current->lineno;

	if (column < 1)
	    column = openfile->placewewant + 1;
    }

    for (openfile->current = openfile->fileage;
	openfile->current != openfile->filebot && line > 1; line--)
	openfile->current = openfile->current->next;

    openfile->current_x = actual_x(openfile->current->data, column - 1);
    openfile->placewewant = column - 1;

    /* Put the top line of the edit window in range of the current line.
     * If save_pos is TRUE, don't change the cursor position when doing
     * it. */
    edit_update(save_pos ? NONE : CENTER);

    /* If allow_update is TRUE, update the screen. */
    if (allow_update) {
	edit_refresh();
	display_main_list();
    }
}
Ejemplo n.º 16
0
Archivo: search.c Proyecto: ris21/yoda
/* Replace a string. */
void do_replace(void)
{
    linestruct *edittop_save, *begin;
    size_t begin_x, pww_save;
    ssize_t numreplaced;
    int i;

    if (ISSET(VIEW_MODE)) {
	print_view_warning();
	search_replace_abort();
	return;
    }

    i = search_init(TRUE, FALSE);
    if (i == -1) {
	/* Cancel, Go to Line, blank search string, or regcomp() failed. */
	search_replace_abort();
	return;
    } else if (i == -2) {
	/* No Replace. */
	do_search();
	return;
    } else if (i == 1)
	/* Case Sensitive, Backwards, or Regexp search toggle. */
	do_replace();

    if (i != 0)
	return;

    /* If answer is not "", add answer to the search history list and
     * copy answer into last_search. */
    if (answer[0] != '\0') {
#ifndef DISABLE_HISTORIES
	update_history(&search_history, answer);
#endif
	last_search = mallocstrcpy(last_search, answer);
    }

    last_replace = mallocstrcpy(last_replace, "");

    i = do_prompt(FALSE,
#ifndef DISABLE_TABCOMP
	TRUE,
#endif
	MREPLACEWITH, last_replace,
#ifndef DISABLE_HISTORIES
	&replace_history,
#endif
	/* TRANSLATORS: This is a prompt. */
	edit_refresh, _("Replace with"));

#ifndef DISABLE_HISTORIES
    /* If the replace string is not "", add it to the replace history list. */
    if (i == 0)
	update_history(&replace_history, answer);
#endif

    if (i != 0 && i != -2) {
	if (i == -1) {		/* Cancel. */
	    if (last_replace[0] != '\0')
		answer = mallocstrcpy(answer, last_replace);
	    statusbar(_("Cancelled"));
	}
	search_replace_abort();
	return;
    }

    last_replace = mallocstrcpy(last_replace, answer);

    /* Save where we are. */
    edittop_save = openfile->edittop;
    begin = openfile->current;
    begin_x = openfile->current_x;
    pww_save = openfile->placewewant;

    numreplaced = do_replace_loop(
#ifndef DISABLE_SPELLER
	FALSE,
#endif
	NULL, begin, &begin_x, last_search);

    /* Restore where we were. */
    openfile->edittop = edittop_save;
    openfile->current = begin;
    openfile->current_x = begin_x;
    openfile->placewewant = pww_save;

    edit_refresh();

    if (numreplaced >= 0)
	statusbar(P_("Replaced %lu occurrence",
		"Replaced %lu occurrences", (unsigned long)numreplaced),
		(unsigned long)numreplaced);

    search_replace_abort();
}
Ejemplo n.º 17
0
void
displayProcess (struct eventState *pes)
{
  long i, k = 0, ch, line = 0, len = 0;
  char link_started, bold_started, it_started;
  char *link_reference;
  char str[2 * LEN + 3], col[LEN + 1], tmp[LEN + 1];

  if (pes->force_redraw == 1 || pes->check_mouse == 1)
    {
      pes->p = pes->top;
      pes->link_under_mouse = 0;
      /* The following bit checks for formatting and links started above
         the top of the screen (before pes->top in the text buffer)
         RP 11-mar-04 */
      bold_started = checkAboveTop (pes, "<b>", "</b>");
      it_started = checkAboveTop (pes, "<i>", "</i>");
      link_started = checkAboveTop (pes, "<a href=", "</a>");
      if (link_started)
	{
	  link_reference = pes->p;
	  while (strncmp (link_reference, "<a href=", 8))
	    {
	      link_reference--;
	      if (link_reference == pes->body_start)
		break;
	    }
	  link_reference += 8;
	  if (*link_reference == '"')
	    link_reference++;
	}

      while (1)
	{
	  if (*pes->p == '\n' || len == LEN || pes->p == pes->body_end)
	    {
	      if (*pes->p != '\n' && pes->p != pes->body_end)
		while (*pes->p != '\n' && pes->p != pes->body_end)
		  pes->p++;

	      if (*pes->p == '\n' && pes->p != pes->body_end)
		pes->p++;

	      while (len != LEN)
		{
		  tmp[(size_t) len] = ' ';
		  col[(size_t) len] = TEXT_COLOR;
		  len++;
		}

	      if (pes->force_redraw)
		{
		  int j;
		  for (i = 0, j = 0; i < LEN; i++)
		    {
		      str[j++] = tmp[i];
		      str[j++] = col[i];
		    }
		  load_window (X + 2, Y + 1 + line, LEN, 1, str);
		}

	      line++;
	      len = 0;

	      if (pes->p == pes->body_end || line == N)
		{
		  if (line != N)
		    clear_window (TEXT_COLOR, X + 2, Y + 1 + line, LEN,
				  N - line);

		  break;
		}

	      continue;
	    }

	  if (*pes->p == '\r')
	    {
	      pes->p++;
	      continue;
	    }

	  if (*pes->p == '<' && (pes->p[1] >= 'A' && pes->p[1] <= 'Z' ||
				 pes->p[1] >= 'a' && pes->p[1] <= 'z' ||
				 pes->p[1] == '/' || pes->p[1] == '!'))
	    {
	      if (link_started == 0 && (pes->p[1] == 'a' || pes->p[1] == 'A'))
		{
		  /* modified for help 5.0.2 so that links without href= in them
		     e.g <A NAME="..."> are not accidentally loaded. - RP */
		  char *closearrow;
		  closearrow = strchr (pes->p, '>');
		  *closearrow = 0;
		  link_reference = strstr (pes->p, "href=");
		  *closearrow = '>';

		  if (link_reference)
		    {
		      link_reference += 5;
		      if (*link_reference == '\"')
			link_reference++;

		      link_started = 1;
		    }
		}
	      else if (link_started == 1 && strncmp (pes->p, "</a>", 4) == 0)
		link_started = 0;
	      else if (bold_started == 0 && strncmp (pes->p, "<b>", 3) == 0)
		bold_started = 1;
	      else if (bold_started == 1 && strncmp (pes->p, "</b>", 4) == 0)
		bold_started = 0;
	      else if (it_started == 0 && strncmp (pes->p, "<i>", 3) == 0)
		it_started = 1;
	      else if (it_started == 1 && strncmp (pes->p, "</i>", 4) == 0)
		it_started = 0;

	      while (*pes->p != '>' && pes->p != pes->body_end)
		pes->p++;

	      if (*pes->p == '>')
		pes->p++;
	    }
	  else
	    {
	      /* Translate some &-escape codes. */
	      ch = *pes->p;
	      if (*pes->p == '&')
		ch = ampSubs (pes);

	      tmp[len] = (ch != '\t') ? ch : ' ';

	      col[len] = link_started ? LINK_COLOR : TEXT_COLOR &&
		bold_started ? BOLD_COLOR : TEXT_COLOR &&
		it_started ? ITALIC_COLOR : TEXT_COLOR;

	      if (link_started && link_reference == pes->clink)
		col[len] = LINK_HIGHLIGHTED_COLOR;

	      if (line == mline && len == mpos && link_started
		  && pes->check_mouse == 1)
		pes->link_under_mouse = link_reference;

	      len++;

	      if (ch != '\t' || len % 8 == 0)
		pes->p++;
	    }
	}

      if (pes->force_redraw == 1)
	{
	  pes->bottom = pes->p;
	  for (i = 0; i < BARLEN; i++)
	    {
	      write_char (BORDER_BOX_COLOR, BARX, BARY + i, ((i != pes->barpos) && (pes->maxtop != 0)) ? BarBlock1 : BarBlock2);	/* modified RP */
	    }
	  pes->old_top = pes->top;
	  pes->force_redraw = 0;
	}
    }

  /* The following has lines of code in this function were modified
     to show the link selected by the tab key for those users without
     mice - RP. */
  if (pes->link_under_mouse && pes->link_priority == LP_MOUSE)
    pes->p = pes->link_under_mouse;
  else if (pes->clink)
    pes->p = pes->clink;

  if (pes->clink || pes->link_under_mouse)
    {
      k = strchr (pes->p, '\"') - pes->p;
      if (k < 0 || k > LEN - 12)
	k = LEN - 12;

      sprintf (pes->text_holder, "%.*s", (int) k, pes->p);
      statusbar (pes->text_holder);
      *pes->text_holder = 0;
    }
  else
    statusbar (NULL);		/* 11--mar-04 */

  pes->p = pes->link_text;
}				/* end displayProcess. */
Ejemplo n.º 18
0
Archivo: search.c Proyecto: ris21/yoda
/* Search for a match to the bracket at the current cursor position, if
 * there is one. */
void do_find_bracket(void)
{
    linestruct *current_save;
    size_t current_x_save, pww_save;
    const char *ch;
	/* The location in matchbrackets of the bracket at the current
	 * cursor position. */
    int ch_len;
	/* The length of ch in bytes. */
    const char *wanted_ch;
	/* The location in matchbrackets of the bracket complementing
	 * the bracket at the current cursor position. */
    int wanted_ch_len;
	/* The length of wanted_ch in bytes. */
    char *bracket_set;
	/* The pair of characters in ch and wanted_ch. */
    size_t i;
	/* Generic loop variable. */
    size_t matchhalf;
	/* The number of single-byte characters in one half of
	 * matchbrackets. */
    size_t mbmatchhalf;
	/* The number of multibyte characters in one half of
	 * matchbrackets. */
    size_t count = 1;
	/* The initial bracket count. */
    bool reverse;
	/* The direction we search. */
    char *found_ch;
	/* The character we find. */

    assert(mbstrlen(matchbrackets) % 2 == 0);

    ch = openfile->current->data + openfile->current_x;

    if (ch == '\0' || (ch = mbstrchr(matchbrackets, ch)) == NULL) {
	statusbar(_("Not a bracket"));
	return;
    }

    /* Save where we are. */
    current_save = openfile->current;
    current_x_save = openfile->current_x;
    pww_save = openfile->placewewant;

    /* If we're on an opening bracket, which must be in the first half
     * of matchbrackets, we want to search forwards for a closing
     * bracket.  If we're on a closing bracket, which must be in the
     * second half of matchbrackets, we want to search backwards for an
     * opening bracket. */
    matchhalf = 0;
    mbmatchhalf = mbstrlen(matchbrackets) / 2;

    for (i = 0; i < mbmatchhalf; i++)
	matchhalf += parse_mbchar(matchbrackets + matchhalf, NULL,
		NULL);

    reverse = ((ch - matchbrackets) >= matchhalf);

    /* If we're on an opening bracket, set wanted_ch to the character
     * that's matchhalf characters after ch.  If we're on a closing
     * bracket, set wanted_ch to the character that's matchhalf
     * characters before ch. */
    wanted_ch = ch;

    while (mbmatchhalf > 0) {
	if (reverse)
	    wanted_ch = matchbrackets + move_mbleft(matchbrackets,
		wanted_ch - matchbrackets);
	else
	    wanted_ch += move_mbright(wanted_ch, 0);

	mbmatchhalf--;
    }

    ch_len = parse_mbchar(ch, NULL, NULL);
    wanted_ch_len = parse_mbchar(wanted_ch, NULL, NULL);

    /* Fill bracket_set in with the values of ch and wanted_ch. */
    bracket_set = charalloc((mb_cur_max() * 2) + 1);
    strncpy(bracket_set, ch, ch_len);
    strncpy(bracket_set + ch_len, wanted_ch, wanted_ch_len);
    null_at(&bracket_set, ch_len + wanted_ch_len);

    found_ch = charalloc(mb_cur_max() + 1);

    while (TRUE) {
	if (find_bracket_match(reverse, bracket_set)) {
	    /* If we found an identical bracket, increment count.  If we
	     * found a complementary bracket, decrement it. */
	    parse_mbchar(openfile->current->data + openfile->current_x,
		found_ch, NULL);
	    count += (strncmp(found_ch, ch, ch_len) == 0) ? 1 : -1;

	    /* If count is zero, we've found a matching bracket.  Update
	     * the screen and get out. */
	    if (count == 0) {
		edit_redraw(current_save, pww_save);
		break;
	    }
	} else {
	    /* We didn't find either an opening or closing bracket.
	     * Indicate this, restore where we were, and get out. */
	    statusbar(_("No matching bracket"));
	    openfile->current = current_save;
	    openfile->current_x = current_x_save;
	    openfile->placewewant = pww_save;
	    break;
	}
    }

    /* Clean up. */
    free(bracket_set);
    free(found_ch);
}
Ejemplo n.º 19
0
/* Our main file browser function.  path is the tilde-expanded path we
 * start browsing from. */
std::string do_browser(std::string path, DIR *dir)
{
	std::string retval;
	bool old_const_update = ISSET(CONST_UPDATE);
	std::string prev_dir;
	/* The directory we were in before backing up to "..". */
	std::string ans;
	/* The last answer the user typed at the statusbar prompt. */
	size_t old_selected;
	/* The selected file we had before the current selected file. */

	curs_set(0);
	blank_statusbar();
	bottombars(MBROWSER);
	wnoutrefresh(bottomwin);

	UNSET(CONST_UPDATE);

change_browser_directory:
	/* We go here after we select a new directory. */

	path = get_full_path(path);

	assert(path.length() > 0 && path.back() == '/');

	/* Get the file list, and set longest and width in the process. */
	browser_init(path, dir);

	/* Sort the file list. */
	std::sort(filelist.begin(), filelist.end(), sort_directories);

	/* If prev_dir isn't empty, select the directory saved in it, and then blow it away. */
	if (prev_dir != "") {
		browser_select_filename(prev_dir);

		prev_dir = "";
		/* Otherwise, select the first file or directory in the list. */
	} else {
		selected = 0;
	}

	old_selected = (size_t)-1;

	titlebar(path);

	Key *kbinput = nullptr;

	while (true) {
		struct stat st;
		size_t fileline = selected / width;
		/* The line number the selected file is on. */
		std::string new_path;
		/* The path we switch to at the "Go to Directory" prompt. */

		if (kbinput) {
			delete kbinput;
			kbinput = nullptr;
		}

		/* Display the file list if we don't have a key, or if the
		 * selected file has changed, and set width in the process. */
		if (old_selected != selected) {
			browser_refresh();
		}

		old_selected = selected;

		// Deal with the keyboard input
		kbinput = new Key(get_kbinput(edit));

		auto func = func_from_key(*kbinput);

		if (func == total_refresh) {
			total_redraw();
		} else if (func == do_help_void) {
			do_help_void();
			curs_set(0);
			/* Search for a filename. */
		} else if (func == do_search) {
			curs_set(1);
			do_filesearch();
			curs_set(0);
			/* Search for another filename. */
		} else if (func == do_research) {
			do_fileresearch();
		} else if (func == do_page_up) {
			if (selected >= (editwinrows + fileline % editwinrows) * width) {
				selected -= (editwinrows + fileline % editwinrows) * width;
			} else {
				selected = 0;
			}
		} else if (func == do_page_down) {
			selected += (editwinrows - fileline % editwinrows) * width;
			if (selected > filelist.size() - 1) {
				selected = filelist.size() - 1;
			}
		} else if (func == do_first_file) {
			selected = 0;
		} else if (func == do_last_file) {
			selected = filelist.size() - 1;
		} else if (func == goto_dir_void) {
			/* Go to a specific directory. */
			curs_set(1);

			std::shared_ptr<Key> key;
			PromptResult i = do_prompt(true,
			              false,
			              MGOTODIR, key, ans.c_str(),
			              NULL,
			              browser_refresh, _("Go To Directory"));

			curs_set(0);
			bottombars(MBROWSER);

			/* If the directory begins with a newline (i.e. an
			 * encoded null), treat it as though it's blank. */
			if (i == PROMPT_ABORTED || i == PROMPT_BLANK_STRING || answer.front() == '\n') {
				/* We canceled.  Indicate that on the statusbar, and
				 * blank out ans, since we're done with it. */
				statusbar(_("Cancelled"));
				ans = "";
				func = nullptr;
				continue;
			} else if (i != PROMPT_ENTER_PRESSED) {
				/* Put back the "Go to Directory" key and save
				 * answer in ans, so that the file list is displayed
				 * again, the prompt is displayed again, and what we
				 * typed before at the prompt is displayed again. */
				ans = answer;
				func = goto_dir_void;
				continue;
			}

			/* We have a directory.  Blank out ans, since we're done with it. */
			ans = "";

			/* Convert newlines to nulls, just before we go to the directory. */
			sunder(answer);

			new_path = real_dir_from_tilde(answer);

			if (new_path == "") {
				new_path = path + answer;
			}

			dir = opendir(new_path);
			if (dir == NULL) {
				/* We can't open this directory for some reason. Complain. */
				statusbar(_("Error reading %s: %s"), answer.c_str(), strerror(errno));
				beep();
				func = nullptr;
				continue;
			}

			/* Start over again with the new path value. */
			path = new_path;
			goto change_browser_directory;
		} else if (func == do_up_void) {
			if (selected >= width) {
				selected -= width;
			}
		} else if (func == do_left) {
			if (selected > 0) {
				selected--;
			}
		} else if (func == do_down_void) {
			if (selected + width <= filelist.size() - 1) {
				selected += width;
			}
		} else if (func == do_right) {
			if (selected < filelist.size() - 1) {
				selected++;
			}
		} else if (func == do_enter_void) {
			/* We can't move up from "/". */
			if (filelist[selected] == "/..") {
				statusbar(_("Can't move up a directory"));
				beep();
				func = nullptr;
				continue;
			}

			if (stat(filelist[selected], &st) == -1) {
				/* We can't open this file for some reason. Complain. */
				statusbar(_("Error reading %s: %s"), filelist[selected].c_str(), strerror(errno));
				beep();
				func = nullptr;
				continue;
			}

			if (!S_ISDIR(st.st_mode)) {
				/* We've successfully opened a file, we're done, so get out. */
				retval = filelist[selected];
				func = nullptr;
				break;
			} else if (tail(filelist[selected]) == "..") {
				/* We've successfully opened the parent directory,
				 * save the current directory in prev_dir, so that
				  * we can easily return to it by hitting Enter. */
				prev_dir = striponedir(filelist[selected]);
			}

			dir = opendir(filelist[selected].c_str());
			if (dir == NULL) {
				/* We can't open this directory for some reason. Complain. */
				statusbar(_("Error reading %s: %s"), filelist[selected].c_str(), strerror(errno));
				beep();
				func = nullptr;
				continue;
			}

			path = filelist[selected];

			/* Start over again with the new path value. */
			goto change_browser_directory;
		} else if (func == do_exit) {
			/* Exit from the file browser. */
			break;
		}
		func = nullptr;
	}
	if (kbinput) {
		delete kbinput;
	}
	titlebar(NULL);
	edit_refresh();
	curs_set(1);
	if (old_const_update) {
		SET(CONST_UPDATE);
	}

	filelist.clear();

	return retval;
}
Ejemplo n.º 20
0
int
html_view_internal (struct eventState *pes, char *base_dir, char *home_page)
{
  int i;

  if (pes->link_text != 0)
    {
      statusbar (hcatStatusLooking);
      if (*pes->link_text == '#')
	{
	  char *anchor;

	  if (strnicmp (pes->link_text + 1, HTMLHELP_INTERNAL_SEARCHLINK,
			strlen (HTMLHELP_INTERNAL_SEARCHLINK)) == 0)
	    {
	      /* Internal search engine link */
	      anchor = pes->body_start + atoi (pes->link_text +
					       strlen
					       (HTMLHELP_INTERNAL_SEARCHLINK)
					       + 1);
	    }
	  else
	    {
	      sprintf (pes->text_holder, "<a name=\"%.*s\"",
		       link_length (pes->link_text + 1), pes->link_text + 1);
	      anchor = strstr (pes->body_start, pes->text_holder);
	    }

	  if (anchor)
	    {
	      /* Locate start of line. */
	      while (anchor != pes->body_start && *anchor != '\n')
		anchor--;

	      if (*anchor == '\n')
		anchor++;

	      /* Move to this line, just near top of screen */
         if (!pes->first_time)
            addBookmark(pes);
	      pes->seek_base = anchor;
	      pes->seek_cnt = -1;
         pes->clink = 0; /* RP - Added 5.3.2 */
	      pes->link_text = 0;
	      *pes->text_holder = 0;
	      statusbar (NULL);
	      return NAVIGATE_DONT;
	    }
	  else
	    {
	      int triedasfile = 0;
         int tryexact = 1;
	      sprintf (pes->text_holder, "%.*s",
		       link_length (pes->link_text + 1), pes->link_text + 1);
	      strlwr (pes->text_holder);
		   write_string (TEXT_COLOR, X + strlen(hcatStatusLooking) + 3, TY,
				                       hcatStatusEscape);
	      do
		{

		  pes->p = pes->body_start;
		  while ((pes->p = strstr (pes->p, "<a")) != 0)
		    {
		      static struct event ev;
		      get_event (&ev, EV_KEY | EV_NONBLOCK);
		      if (ev.ev_type == EV_KEY && ev.key == 27)
			{
			  pes->link_text = 0;
           show_error(hcatUserAborted);
			  return NAVIGATE_DONT;
			}

		      pes->p = strchr (pes->p, '>');
		      if (pes->p)
			{
			  ++(pes->p);
			  if ((strnicmp(pes->p, pes->text_holder,
			                        strlen (pes->text_holder)) == 0) &&
                (pes->p[strlen(pes->text_holder)] == '<' || !tryexact))
			    {
			      while (pes->p != pes->body_start &&
				     strncmp (pes->p, "<a", 2))
				pes->p--;

			      pes->p = strstr (pes->p, "href=");
			      if (pes->p != 0)
				{
				  pes->p += 6;
				  if (*pes->p == '\"')
				    pes->p++;

				  if (*pes->p == '#')
				    break;

				  if (prepare_link (pes))
				    {
                  if (tryexact == 0)
                     show_error(hcatNoExactFound);
				      return NAVIGATE_LINK;
				    }
				}
			    }
			}
		    }
		  if (triedasfile == 0)
		    {
		      int undostrcat = strlen (base_dir);
		      if (base_dir[strlen (base_dir) - 1] != '\\'
			  && base_dir[0] != 0)
			strcat (base_dir, "\\");
		      strcat (base_dir, pes->text_holder);
		      if (checkForFile (base_dir))
			{
			  /* Didn't work */
			  base_dir[undostrcat] = '\0';
			}
		      else
			{
			  if (pes->first_time)
			    pes->hidden = 1;
			  get_home_page (home_page, base_dir);
			  get_base_dir (base_dir, base_dir);
			  return NAVIGATE_HOME;
			}
		      triedasfile = 1;
		    }
		  else
		    {
            /* don't try to match end with the < */
            if (tryexact)
            {
               tryexact = 0;
            }
            else
            {
		         pes->p = pes->text_holder + strlen (pes->text_holder) - 1;
		         if (*pes->p > 'a')
			         --(*pes->p);
		         else
			         *pes->p = 0;
            }
		    }
		}
	      while (*(pes->text_holder) != 0);
	    }
     statusbar (NULL);

	  sprintf (pes->text_holder, "%s '%.*s'", hcatCouldntFind,
		   link_length (pes->link_text + 1), pes->link_text + 1);
	  show_error (pes->text_holder);
	  pes->link_text = 0;
	  *(pes->text_holder) = 0;
	  return NAVIGATE_DONT;
	}
      else if (prepare_link (pes))
	return NAVIGATE_LINK;

      pes->link_text = 0;
    }

  if (pes->first_time)
  {
     drawmenu();
     save_window (X, Y, W, H, pes->screen_buf);
     pes->first_time = 0;
  }

  if (pes->seek_cnt != 0)
    {
      if (pes->seek_cnt <= 0)
	{
	  i = -pes->seek_cnt;
	  pes->p = pes->seek_base - 1;
	  if (*pes->p == '\n')
	    pes->p--;

	  for (; (pes->p != pes->body_start); pes->p--)
	    if (*pes->p == '\n')
	      {
		i--;
		if (i == 0)
		  {
		    pes->p++;
		    break;
		  }
	      }
	  pes->top = pes->p;
	}
      else if (pes->seek_cnt > 0)
	{
	  i = pes->seek_cnt;
	  pes->p = pes->seek_base;
	  for (; pes->p != pes->body_end; pes->p++)
	    if (*pes->p == '\n')
	      {
		i--;
		if (i == 0)
		  {
		    pes->p++;
		    break;
		  }
	      }

	  if (pes->p == pes->body_end)
	    {
	      pes->seek_base = pes->body_end - 1;
	      pes->seek_cnt = -1;
	      return NAVIGATE_DONT;
	    }

	  pes->top = pes->p;
	}
      pes->seek_cnt = 0;
    }

  if (pes->maxtop != 0)
    pes->barpos = ((pes->top - pes->body_start) * BARLEN) / pes->maxtop;
  else
    pes->barpos = BARLEN - 1;

  if (pes->barpos >= BARLEN || pes->barpos < 0)	/* <0 fix - RP */
    pes->barpos = BARLEN - 1;

  if (pes->bar_hooked)
    {
      pes->seek_base = pes->top;
      if (pes->forced_barpos == 0)
	{
	  pes->top = pes->body_start;
	  pes->barpos = 0;
	}
      else if (pes->forced_barpos == BARLEN - 1
	       && pes->barpos != pes->forced_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_base = pes->body_end;
	  pes->seek_cnt = -N;
	  return NAVIGATE_DONT;
	}
      else if (pes->forced_barpos < pes->barpos
	       && pes->forced_barpos < pes->old_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_cnt = -1;
	  return NAVIGATE_DONT;
	}
      else if (pes->forced_barpos > pes->barpos
	       && pes->forced_barpos > pes->old_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_cnt = +1;
	  return NAVIGATE_DONT;
	}
    }

  pes->old_barpos = pes->barpos;
  if (pes->top != pes->old_top)
    pes->force_redraw = 1;

  /* ------ Display processing ------------------------------------ */
  displayProcess (pes);

  /* ------ Event processing -------------------------------------- */
  return processEvents (pes);
}
Ejemplo n.º 21
0
void EventManager::fireStatusbarEvent(const StatusbarEvent& event)
{
    emit statusbar(event);
}