Exemplo n.º 1
0
static void spinbn_right_value(GuiSpinBtn *spin)
{
	GuiEntry *entry = GUI_ENTRY_DATA(spin->entry);
	echar buf[entry->nchar + 1];

	e_memcpy(buf, entry->chars, entry->nchar);
	buf[entry->nchar] = 0;

	spinbn_set_value(spin, e_atof(buf));
}
Exemplo n.º 2
0
static void spinbn_right_value(GuiSpinBtn *spin)
{
	GuiEntry *entry = GUI_ENTRY_DATA(spin->entry);
#ifdef linux
	echar buf[entry->nchar + 1];
#else
	echar buf[1024];
#endif

	e_memcpy(buf, entry->chars, entry->nchar);
	buf[entry->nchar] = 0;

	spinbn_set_value(spin, (efloat)e_atof(buf));
}
Exemplo n.º 3
0
/*
 * The seq command will print out a numeric sequence from 1, the default,
 * to a user specified upper limit by 1.  The lower bound and increment
 * maybe indicated by the user on the command line.  The sequence can
 * be either whole, the default, or decimal numbers.
 */
int
main(int argc, char *argv[])
{
	int c = 0, errflg = 0;
	int equalize = 0;
	double first = 1.0;
	double last = 0.0;
	double incr = 0.0;
	struct lconv *locale;
	char *fmt = NULL;
	const char *sep = "\n";
	const char *term = NULL;
	char pad = ZERO;

	/* Determine the locale's decimal point. */
	locale = localeconv();
	if (locale && locale->decimal_point && locale->decimal_point[0] != '\0')
		decimal_point = locale->decimal_point;

	/*
         * Process options, but handle negative numbers separately
         * least they trip up getopt(3).
         */
	while ((optind < argc) && !numeric(argv[optind]) &&
	    (c = getopt(argc, argv, "f:hs:t:w")) != -1) {

		switch (c) {
		case 'f':	/* format (plan9) */
			fmt = optarg;
			equalize = 0;
			break;
		case 's':	/* separator (GNU) */
			sep = unescape(optarg);
			break;
		case 't':	/* terminator (new) */
			term = unescape(optarg);
			break;
		case 'w':	/* equal width (plan9) */
			if (!fmt)
				if (equalize++)
					pad = SPACE;
			break;
		case 'h':	/* help (GNU) */
		default:
			errflg++;
			break;
		}
	}

	argc -= optind;
	argv += optind;
	if (argc < 1 || argc > 3)
		errflg++;

	if (errflg) {
		fprintf(stderr,
		    "usage: %s [-w] [-f format] [-s string] [-t string] [first [incr]] last\n",
		    getprogname());
		exit(1);
	}

	last = e_atof(argv[argc - 1]);

	if (argc > 1)
		first = e_atof(argv[0]);
	
	if (argc > 2) {
		incr = e_atof(argv[1]);
		/* Plan 9/GNU don't do zero */
		if (incr == 0.0)
			errx(1, "zero %screment", (first < last)? "in" : "de");
	}

	/* default is one for Plan 9/GNU work alike */
	if (incr == 0.0)
		incr = (first < last) ? 1.0 : -1.0;

	if (incr <= 0.0 && first < last)
		errx(1, "needs positive increment");

	if (incr >= 0.0 && first > last)
		errx(1, "needs negative decrement");

	if (fmt != NULL) {
		if (!valid_format(fmt))
			errx(1, "invalid format string: `%s'", fmt);
		fmt = unescape(fmt);
		/*
	         * XXX to be bug for bug compatible with Plan 9 add a
		 * newline if none found at the end of the format string.
		 */
	} else
		fmt = generate_format(first, incr, last, equalize, pad);

	if (incr > 0) {
		for (; first <= last; first += incr) {
			printf(fmt, first);
			fputs(sep, stdout);
		}
	} else {
		for (; first >= last; first += incr) {
			printf(fmt, first);
			fputs(sep, stdout);
		}
	}
	if (term != NULL)
		fputs(term, stdout);

	return (0);
}