Example #1
0
/*
 * Replace a single character with the next input character.
 * A funny kind of insert.
 */
void 
vrep(register int cnt)
{
	register int i, c;

	if (cnt > strlen(cursor)) {
		beep();
		return;
	}
	showmode('r');
	i = column(cursor + cnt - 1);
	vcursat(cursor);
	doomed = i - cindent();
	if (!vglobp) {
		c = getesc();
		if (c == 0) {
			showmode(0);
			vfixcurs();
			return;
		}
		ungetkey(c);
	}
	CP(vutmp, linebuf);
	if (FIXUNDO)
		vundkind = VCHNG;
	wcursor = cursor;
	for (i = 0; i < cnt; i++)
		wcursor += skipright(cursor, wcursor);
	vUD1 = cursor; vUD2 = wcursor;
	CP(cursor, wcursor);
	prepapp();
	vappend('r', cnt, 0);
	*lastcp++ = INS[0];
	setLAST();
}
Example #2
0
void Fl_Tool_Button::draw()
{
    Fl_String saved_l;
    Fl_Image *saved_im = image();

    TbShowMode sm = showmode();
    if(sm==SHOW_DEFAULT) sm = default_showmode();

    if(sm==SHOW_AUTO) {
        if(image()) sm = SHOW_IMAGE;
        else        sm = SHOW_TEXT;
    }

    if(!(sm&SHOW_IMAGE))
        image(0);
    else {
        if(m_bar->tb_size() == Fl_Tool_Bar::TB_SIZE_SMALL && small) {
            image(small);
        } else if(m_bar->tb_size() == Fl_Tool_Bar::TB_SIZE_BIG && big) {
            image(big);
        }
    }
    if(!(sm&SHOW_TEXT)) {
        saved_l = label();
        label("");
    }

    Fl_Button::draw();

    image(saved_im);
    if(!saved_l.empty()) {
        label(saved_l);
    }
}
Example #3
0
void Fl_Tool_Button::layout()
{
    TbShowMode sm = showmode();
    if(sm==SHOW_DEFAULT) sm = default_showmode();

    if(sm==SHOW_AUTO) {
        if(image()) sm = SHOW_IMAGE;
        else        sm = SHOW_TEXT;
    }

    int bw, bh;
    m_bar->get_icon_size(m_bar->tb_size(), bw, bh);

    // Create/free big and small images
    if(image() && sm&SHOW_IMAGE)
    {
        if(m_bar->tb_size() == Fl_Tool_Bar::TB_SIZE_SMALL)
        {
            if(small && (small->width()!=bw || small->height()!=bh)) {
                if(small!=image()) delete small;
                small = 0;
            }
            if(!small) {
                if(image()->width()==bw && image()->height()==bh)
                    small = image();
                else
                    small = image()->scale(bw, bh);
            }
        } else {
            if(big && (big->width()!=bw || big->height()!=bh)) {
                if(big!=image()) delete big;
                big = 0;
            }
            if(!big) {
                if(image()->width()==bw && image()->height()==bh)
                    big = image();
                else
                    big = image()->scale(bw, bh);
            }
        }
    }

    Fl_Button::layout();
}
Example #4
0
void Fl_Tool_Button::preferred_size(int &w, int &h) const
{
    TbTextPos tp = textpos();
    if(tp==POS_DEFAULT) tp = default_textpos();

    TbShowMode sm = showmode();
    if(sm==SHOW_DEFAULT) sm = default_showmode();

    if(sm==SHOW_AUTO) {
        if(image()) sm = SHOW_IMAGE;
        else        sm = SHOW_TEXT;
    }

    int H=0, W=0;
    if(sm&SHOW_TEXT) {
        measure_label(W, H);
    }

    if(sm&SHOW_IMAGE) {
        int bw, bh;
        m_bar->get_icon_size(m_bar->tb_size(), bw, bh);

        if(tp == POS_RIGHT) W += bw;
        else                H += bh;

        if(W < bw) W = bw;
        if(H < bh) H = bh;
    }

    W += box()->dw() + 4;
    H += box()->dh() + 4;

    if(W < H) W = H;

    w = W;
    h = H;
}
Example #5
0
int fbset_main(int argc, char **argv)
#endif
{
	struct fb_var_screeninfo var, varset;
	int fh, i;
	char *fbdev = DEFAULTFBDEV;
	char *modefile = DEFAULTFBMODE;
	char *thisarg, *mode = NULL;

	memset(&varset, 0xFF, sizeof(varset));

	/* parse cmd args.... why do they have to make things so difficult? */
	argv++;
	argc--;
	for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
		for (i = 0; g_cmdoptions[i].name[0]; i++) {
			if (strcmp(thisarg, g_cmdoptions[i].name))
				continue;
			if (argc-1 < g_cmdoptions[i].param_count)
				bb_show_usage();

			switch (g_cmdoptions[i].code) {
			case CMD_FB:
				fbdev = argv[1];
				break;
			case CMD_DB:
				modefile = argv[1];
				break;
			case CMD_GEOMETRY:
				varset.xres = xatou32(argv[1]);
				varset.yres = xatou32(argv[2]);
				varset.xres_virtual = xatou32(argv[3]);
				varset.yres_virtual = xatou32(argv[4]);
				varset.bits_per_pixel = xatou32(argv[5]);
				break;
			case CMD_TIMING:
				varset.pixclock = xatou32(argv[1]);
				varset.left_margin = xatou32(argv[2]);
				varset.right_margin = xatou32(argv[3]);
				varset.upper_margin = xatou32(argv[4]);
				varset.lower_margin = xatou32(argv[5]);
				varset.hsync_len = xatou32(argv[6]);
				varset.vsync_len = xatou32(argv[7]);
				break;
			case CMD_ALL:
				g_options |= OPT_ALL;
				break;
			case CMD_CHANGE:
				g_options |= OPT_CHANGE;
				break;
#ifdef CONFIG_FEATURE_FBSET_FANCY
			case CMD_XRES:
				varset.xres = xatou32(argv[1]);
				break;
			case CMD_YRES:
				varset.yres = xatou32(argv[1]);
				break;
			case CMD_DEPTH:
				varset.bits_per_pixel = xatou32(argv[1]);
				break;
#endif
			}
			argc -= g_cmdoptions[i].param_count;
			argv += g_cmdoptions[i].param_count;
			break;
		}
		if (!g_cmdoptions[i].name[0]) {
			if (argc != 1)
				bb_show_usage();
			mode = *argv;
			g_options |= OPT_READMODE;
		}
	}

	fh = xopen(fbdev, O_RDONLY);
	if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
		bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "GE");
	if (g_options & OPT_READMODE) {
		if (!readmode(&var, modefile, mode)) {
			bb_error_msg_and_die("unknown video mode '%s'", mode);
		}
	}

	setmode(&var, &varset);
	if (g_options & OPT_CHANGE) {
		if (g_options & OPT_ALL)
			var.activate = FB_ACTIVATE_ALL;
		if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
			bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "PU");
	}
	showmode(&var);
	/* Don't close the file, as exiting will take care of that */
	/* close(fh); */

	return EXIT_SUCCESS;
}
Example #6
0
void
vappend(int ch, int cnt, int indent)
/*	int ch;		/\* mjm: char --> int */
{
	register int i = 0;
	register char *gcursor;
	bool escape;
	int repcnt, savedoomed;
	short oldhold = hold;
#ifdef	SIGWINCH
	sigset_t set, oset;
#endif

	/*
	 * Before a move in hardopen when the line is dirty
	 * or we are in the middle of the printed representation,
	 * we retype the line to the left of the cursor so the
	 * insert looks clean.
	 */
	if (ch != 'o' && state == HARDOPEN && (rubble || !ateopr())) {
		rubble = 1;
		gcursor = cursor;
		i = *gcursor;
		*gcursor = ' ';
		wcursor = gcursor;
		vmove(0);
		*gcursor = i;
	}
	vaifirst = indent == 0;

	showmode(ch);

	/*
	 * Handle replace character by (eventually)
	 * limiting the number of input characters allowed
	 * in the vgetline routine.
	 */
	if (ch == 'r')
		repcnt = 2;
	else
		repcnt = 0;

	/*
	 * If an autoindent is specified, then
	 * generate a mixture of blanks to tabs to implement
	 * it and place the cursor after the indent.
	 * Text read by the vgetline routine will be placed in genbuf,
	 * so the indent is generated there.
	 */
	if (value(AUTOINDENT) && indent != 0) {
		gcursor = genindent(indent);
		*gcursor = 0;
		vgotoCL(qcolumn(cursor + skipright(cursor, linebuf), genbuf));
	} else {
		gcursor = genbuf;
		*gcursor = 0;
		if (ch == 'o')
			vfixcurs();
	}

	/*
	 * Prepare for undo.  Pointers delimit inserted portion of line.
	 */
	vUA1 = vUA2 = cursor;

	/*
	 * If we are not in a repeated command and a ^@ comes in
	 * then this means the previous inserted text.
	 * If there is none or it was too long to be saved,
	 * then beep() and also arrange to undo any damage done
	 * so far (e.g. if we are a change.)
	 */
	if ((vglobp && *vglobp == 0) || peekbr()) {
		if ((INS[0] & (QUOTE|TRIM)) == OVERBUF) {
			beep();
			if (!splitw)
				ungetkey('u');
			doomed = 0;
			hold = oldhold;
			showmode(0);
			return;
		}
		/*
		 * Unread input from INS.
		 * An escape will be generated at end of string.
		 * Hold off n^^2 type update on dumb terminals.
		 */
		vglobp = INS;
		hold |= HOLDQIK;
	} else if (vglobp == 0)
		/*
		 * Not a repeated command, get
		 * a new inserted text for repeat.
		 */
		INS[0] = 0;

	/*
	 * For wrapmargin to hack away second space after a '.'
	 * when the first space caused a line break we keep
	 * track that this happened in gobblebl, which says
	 * to gobble up a blank silently.
	 */
	gobblebl = 0;

#ifdef	SIGWINCH
	sigemptyset(&set);
	sigaddset(&set, SIGWINCH);
	sigprocmask(SIG_BLOCK, &set, &oset);
#endif
	/*
	 * Text gathering loop.
	 * New text goes into genbuf starting at gcursor.
	 * cursor preserves place in linebuf where text will eventually go.
	 */
	if (*cursor == 0 || state == CRTOPEN)
		hold |= HOLDROL;
	for (;;) {
		if (ch == 'r' && repcnt == 0)
			escape = 0;
		else {
			gcursor = vgetline(repcnt, gcursor, &escape, ch);

			/*
			 * After an append, stick information
			 * about the ^D's and ^^D's and 0^D's in
			 * the repeated text buffer so repeated
			 * inserts of stuff indented with ^D as backtab's
			 * can work.
			 */
			if (HADUP)
				addc('^');
			else if (HADZERO)
				addc('0');
			while (CDCNT > 0)
#ifndef	BIT8
				addc('\204'), CDCNT--;
#else
				addc(OVERBUF), CDCNT--;
#endif
			
			if (gobbled)
				addc(' ');
			addtext(ogcursor);
		}
		repcnt = 0;

		/*
		 * Smash the generated and preexisting indents together
		 * and generate one cleanly made out of tabs and spaces
		 * if we are using autoindent.
		 */
		if (!vaifirst && value(AUTOINDENT)) {
			i = fixindent(indent);
			if (!HADUP)
				indent = i;
			gcursor = strend(genbuf);
		}

		/*
		 * Limit the repetition count based on maximum
		 * possible line length; do output implied
		 * by further count (> 1) and cons up the new line
		 * in linebuf.
		 */
		cnt = vmaxrep(ch, cnt);
		CP(gcursor + skipright(ogcursor, gcursor), cursor);
		do {
			CP(cursor, genbuf);
			if (cnt > 1) {
				int oldhold = hold;

				Outchar = vinschar;
				hold |= HOLDQIK;
				ex_printf("%s", genbuf);
				hold = oldhold;
				Outchar = vputchar;
			}
			cursor += gcursor - genbuf;
		} while (--cnt > 0);
		endim();
		vUA2 = cursor;
		if (escape != '\n')
			CP(cursor, gcursor + skipright(ogcursor, gcursor));

		/*
		 * If doomed characters remain, clobber them,
		 * and reopen the line to get the display exact.
		 */
		if (state != HARDOPEN) {
			DEPTH(vcline) = 0;
			savedoomed = doomed;
			if (doomed > 0) {
				register int cind = cindent();

				physdc(cind, cind + doomed);
				doomed = 0;
			}
			i = vreopen(LINE(vcline), lineDOT(), vcline);
#ifdef TRACE
			if (trace)
				fprintf(trace, "restoring doomed from %d to %d\n", doomed, savedoomed);
#endif
			if (ch == 'R')
				doomed = savedoomed;
		}

		/*
		 * All done unless we are continuing on to another line.
		 */
		if (escape != '\n')
			break;

		/*
		 * Set up for the new line.
		 * First save the current line, then construct a new
		 * first image for the continuation line consisting
		 * of any new autoindent plus the pushed ahead text.
		 */
		showmode(0);
		killU();
		addc(gobblebl ? ' ' : '\n');
		vsave();
		cnt = 1;
		if (value(AUTOINDENT)) {
#ifdef LISPCODE
			if (value(LISP))
				indent = lindent(dot + 1);
			else
#endif
			     if (!HADUP && vaifirst)
				indent = whitecnt(linebuf);
			vaifirst = 0;
			strcLIN(vpastwh(gcursor + 1));
			gcursor = genindent(indent);
			*gcursor = 0;
			if (gcursor + strlen(linebuf) > &genbuf[LBSIZE - 2])
				gcursor = genbuf;
			CP(gcursor, linebuf);
		} else {
			CP(genbuf, gcursor + skipright(ogcursor, gcursor));
			gcursor = genbuf;
		}

		/*
		 * If we started out as a single line operation and are now
		 * turning into a multi-line change, then we had better yank
		 * out dot before it changes so that undo will work
		 * correctly later.
		 */
		if (FIXUNDO && vundkind == VCHNG) {
			vremote(1, yank, 0);
			undap1--;
		}

		/*
		 * Now do the append of the new line in the buffer,
		 * and update the display.  If slowopen
		 * we don't do very much.
		 */
		vdoappend(genbuf);
		vundkind = VMANYINS;
		vcline++;
		if (state != VISUAL)
			vshow(dot, NOLINE);
		else {
			i += LINE(vcline - 1);
			vopen(dot, i);
			if (value(SLOWOPEN))
				vscrap();
			else
				vsync1(LINE(vcline));
		}
		strcLIN(gcursor);
		*gcursor = 0;
		cursor = linebuf;
		vgotoCL(qcolumn(cursor + skipleft(ogcursor, cursor), genbuf));
		showmode(ch);
	}

	/*
	 * All done with insertion, position the cursor
	 * and sync the screen.
	 */
	showmode(0);
	hold = oldhold;
	if (cursor > linebuf)
		cursor += skipleft(linebuf, cursor);
	if (state != HARDOPEN)
		vsyncCL();
	else if (cursor > linebuf)
		back1();
	doomed = 0;
	wcursor = cursor;
	vmove(0);
#ifdef	SIGWINCH
	sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
}
Example #7
0
int fbset_main(int argc, char **argv)
{
	enum {
		OPT_CHANGE   = (1 << 0),
		OPT_SHOW     = (1 << 1),
		OPT_READMODE = (1 << 2),
		OPT_ALL      = (1 << 9),
	};
	struct fb_var_screeninfo var, varset;
	int fh, i;
	unsigned options = 0;

	const char *fbdev = DEFAULTFBDEV;
	const char *modefile = DEFAULTFBMODE;
	char *thisarg, *mode = NULL;

	memset(&varset, 0xff, sizeof(varset));

	/* parse cmd args.... why do they have to make things so difficult? */
	argv++;
	argc--;
	for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) {
		if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
			if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0)
				continue;
			if (argc <= g_cmdoptions[i].param_count)
				bb_show_usage();

			switch (g_cmdoptions[i].code) {
			case CMD_FB:
				fbdev = argv[1];
				break;
			case CMD_DB:
				modefile = argv[1];
				break;
			case CMD_ALL:
				options |= OPT_ALL;
				break;
			case CMD_SHOW:
				options |= OPT_SHOW;
				break;
			case CMD_GEOMETRY:
				varset.xres = xatou32(argv[1]);
				varset.yres = xatou32(argv[2]);
				varset.xres_virtual = xatou32(argv[3]);
				varset.yres_virtual = xatou32(argv[4]);
				varset.bits_per_pixel = xatou32(argv[5]);
				break;
			case CMD_TIMING:
				varset.pixclock = xatou32(argv[1]);
				varset.left_margin = xatou32(argv[2]);
				varset.right_margin = xatou32(argv[3]);
				varset.upper_margin = xatou32(argv[4]);
				varset.lower_margin = xatou32(argv[5]);
				varset.hsync_len = xatou32(argv[6]);
				varset.vsync_len = xatou32(argv[7]);
				break;
#if ENABLE_FEATURE_FBSET_FANCY
			case CMD_XRES:
				varset.xres = xatou32(argv[1]);
				break;
			case CMD_YRES:
				varset.yres = xatou32(argv[1]);
				break;
			case CMD_DEPTH:
				varset.bits_per_pixel = xatou32(argv[1]);
				break;
#endif
			}
			switch (g_cmdoptions[i].code) {
			case CMD_FB:
			case CMD_DB:
			case CMD_ALL:
			case CMD_SHOW:
				break;
			default:
				options |= OPT_CHANGE; /* the other commands imply changes */
			}
			argc -= g_cmdoptions[i].param_count;
			argv += g_cmdoptions[i].param_count;
			goto contin;
		}
		if (argc != 1)
			bb_show_usage();
		mode = *argv;
		options |= OPT_READMODE;
 contin: ;
	}

	fh = xopen(fbdev, O_RDONLY);
	xioctl(fh, FBIOGET_VSCREENINFO, &var);
	if (options & OPT_READMODE) {
#if !ENABLE_FEATURE_FBSET_READMODE
		bb_show_usage();
#else
		if (!read_mode_db(&var, modefile, mode)) {
			bb_error_msg_and_die("unknown video mode '%s'", mode);
		}
#endif
	}

	if (options & OPT_CHANGE) {
		setmode(&var, &varset);
		if (options & OPT_ALL)
			var.activate = FB_ACTIVATE_ALL;
		xioctl(fh, FBIOPUT_VSCREENINFO, &var);
	}
	if (options == 0 || options & OPT_SHOW)
		showmode(&var);
	/* Don't close the file, as exiting will take care of that */
	/* close(fh); */

	return EXIT_SUCCESS;
}
Example #8
0
int fbset_main(int argc, char **argv)
{
	enum {
		OPT_CHANGE   = (1 << 0),
		OPT_SHOW     = (1 << 1),
		OPT_READMODE = (1 << 2),
		OPT_ALL      = (1 << 3),
	};
	struct fb_var_screeninfo var_old, var_set;
	int fh, i;
	unsigned options = 0;

	const char *fbdev = DEFAULTFBDEV;
	const char *modefile = DEFAULTFBMODE;
	char *thisarg;
	char *mode = mode; /* for compiler */

	memset(&var_set, 0xff, sizeof(var_set)); /* set all to -1 */

	/* parse cmd args.... why do they have to make things so difficult? */
	argv++;
	argc--;
	for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) {
		if (thisarg[0] != '-') {
			if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1)
				bb_show_usage();
			mode = thisarg;
			options |= OPT_READMODE;
			goto contin;
		}
		for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
			if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0)
				continue;
			if (argc <= g_cmdoptions[i].param_count)
				bb_show_usage();

			switch (g_cmdoptions[i].code) {
			case CMD_FB:
				fbdev = argv[1];
				break;
			case CMD_DB:
				modefile = argv[1];
				break;
			case CMD_ALL:
				options |= OPT_ALL;
				break;
			case CMD_SHOW:
				options |= OPT_SHOW;
				break;
			case CMD_GEOMETRY:
				var_set.xres = xatou32(argv[1]);
				var_set.yres = xatou32(argv[2]);
				var_set.xres_virtual = xatou32(argv[3]);
				var_set.yres_virtual = xatou32(argv[4]);
				var_set.bits_per_pixel = xatou32(argv[5]);
				break;
			case CMD_TIMING:
				var_set.pixclock = xatou32(argv[1]);
				var_set.left_margin = xatou32(argv[2]);
				var_set.right_margin = xatou32(argv[3]);
				var_set.upper_margin = xatou32(argv[4]);
				var_set.lower_margin = xatou32(argv[5]);
				var_set.hsync_len = xatou32(argv[6]);
				var_set.vsync_len = xatou32(argv[7]);
				break;
			case CMD_ACCEL:
				break;
			case CMD_HSYNC:
				var_set.sync |= FB_SYNC_HOR_HIGH_ACT;
				break;
			case CMD_VSYNC:
				var_set.sync |= FB_SYNC_VERT_HIGH_ACT;
				break;
#if ENABLE_FEATURE_FBSET_FANCY
			case CMD_XRES:
				var_set.xres = xatou32(argv[1]);
				break;
			case CMD_YRES:
				var_set.yres = xatou32(argv[1]);
				break;
			case CMD_DEPTH:
				var_set.bits_per_pixel = xatou32(argv[1]);
				break;
#endif
			}
			switch (g_cmdoptions[i].code) {
			case CMD_FB:
			case CMD_DB:
			case CMD_ALL:
			case CMD_SHOW:
				break;
			default:
				/* other commands imply changes */
				options |= OPT_CHANGE;
			}
			argc -= g_cmdoptions[i].param_count;
			argv += g_cmdoptions[i].param_count;
			goto contin;
		}
		bb_show_usage();
 contin: ;
	}

	fh = xopen(fbdev, O_RDONLY);
	xioctl(fh, FBIOGET_VSCREENINFO, &var_old);

	if (options & OPT_READMODE) {
#if ENABLE_FEATURE_FBSET_READMODE
		if (!read_mode_db(&var_old, modefile, mode)) {
			bb_error_msg_and_die("unknown video mode '%s'", mode);
		}
		options |= OPT_CHANGE;
#endif
	}

	if (options & OPT_CHANGE) {
		copy_changed_values(&var_old, &var_set);
		if (options & OPT_ALL)
			var_old.activate = FB_ACTIVATE_ALL;
		xioctl(fh, FBIOPUT_VSCREENINFO, &var_old);
	}

	if (options == 0 || (options & OPT_SHOW))
		showmode(&var_old);

	if (ENABLE_FEATURE_CLEAN_UP)
		close(fh);

	return EXIT_SUCCESS;
}