Exemplo n.º 1
0
static bool
similar_sgr(char *a, char *b)
{
    bool result = FALSE;
    if (a != 0 && b != 0) {
	int csi_a = is_csi(a);
	int csi_b = is_csi(b);
	size_t len_a;
	size_t len_b;

	TR(TRACE_DATABASE, ("similar_sgr:\n\t%s\n\t%s",
			    _nc_visbuf2(1, a),
			    _nc_visbuf2(2, b)));
	if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) {
	    a += csi_a;
	    b += csi_b;
	    if (*a != *b) {
		a = skip_zero(a);
		b = skip_zero(b);
	    }
	}
	len_a = strlen(a);
	len_b = strlen(b);
	if (len_a && len_b) {
	    if (len_a > len_b)
		result = (strncmp(a, b, len_b) == 0);
	    else
		result = (strncmp(a, b, len_a) == 0);
	}
	TR(TRACE_DATABASE, ("...similar_sgr: %d\n\t%s\n\t%s", result,
			    _nc_visbuf2(1, a),
			    _nc_visbuf2(2, b)));
    }
    return result;
}
Exemplo n.º 2
0
vsscanf(const char *str, const char *format, va_list ap)
{
#if HAVE_VFSCANF || HAVE__DOSCAN
    /*
     * This code should work on anything descended from AT&T SVr1.
     */
    FILE strbuf;

    strbuf._flag = _IOREAD;
    strbuf._ptr = strbuf._base = (unsigned char *) str;
    strbuf._cnt = strlen(str);
    strbuf._file = _NFILE;

#if HAVE_VFSCANF
    return (vfscanf(&strbuf, format, ap));
#else
    return (_doscan(&strbuf, format, ap));
#endif
#else
    static int can_convert = -1;

    int assigned = 0;
    int consumed = 0;

    T((T_CALLED("vsscanf(%s,%s,...)"),
       _nc_visbuf2(1, str),
       _nc_visbuf2(2, format)));

    /*
     * This relies on having a working "%n" format conversion.  Check if it
     * works.  Only very old C libraries do not support it.
     *
     * FIXME: move this check into the configure script.
     */
    if (can_convert < 0) {
	int check1;
	int check2;
	if (sscanf("123", "%d%n", &check1, &check2) > 0
	    && check1 == 123
	    && check2 == 3) {
	    can_convert = 1;
	} else {
	    can_convert = 0;
	}
    }

    if (can_convert) {
	size_t len_fmt = strlen(format) + 32;
	char *my_fmt = malloc(len_fmt);
	ChunkType chunk, ctest;
	OtherType other, otest;
	ScanState state;
	unsigned n;
	int eaten;
	void *pointer;

	if (my_fmt != 0) {
	    /*
	     * Split the original format into chunks, adding a "%n" to the end
	     * of each (except of course if it used %n), and use that
	     * information to decide where to start scanning the next chunk.
	     *
	     * FIXME:  does %n count bytes or characters?  If the latter, this
	     * will require further work for multibyte strings.
	     */
	    while (*format != '\0') {
		/* find a chunk */
		state = sUnknown;
		chunk = cUnknown;
		other = oUnknown;
		pointer = 0;
		for (n = 0; format[n] != 0 && state != sFinal; ++n) {
		    my_fmt[n] = format[n];
		    switch (state) {
		    case sUnknown:
			if (format[n] == '%')
			    state = sPercent;
			break;
		    case sPercent:
			if (format[n] == '%') {
			    state = sUnknown;
			} else if (format[n] == L_SQUARE) {
			    state = sLeft;
			} else {
			    state = sNormal;
			    --n;
			}
			break;
		    case sLeft:
			state = sRange;
			if (format[n] == '^') {
			    ++n;
			    my_fmt[n] = format[n];
			}
			break;
		    case sRange:
			if (format[n] == R_SQUARE) {
			    state = sFinal;
			    chunk = cRange;
			}
			break;
		    case sNormal:
			if (format[n] == '*') {
			    state = sUnknown;
			} else {
			    if ((ctest = final_ch(format[n], other)) != cUnknown) {
				state = sFinal;
				chunk = ctest;
			    } else if ((otest = other_ch(format[n])) != oUnknown) {
				other = otest;
			    } else if (isalpha(UChar(format[n]))) {
				state = sFinal;
				chunk = cError;
			    }
			}
			break;
		    case sFinal:
			break;
		    }
		}
		my_fmt[n] = '\0';
		format += n;

		if (chunk == cUnknown
		    || chunk == cError) {
		    if (assigned == 0)
			assigned = EOF;
		    break;
		}

		/* add %n, if the format was not that */
		if (chunk != cAssigned) {
		    strlcat(my_fmt, "%n", len_fmt);
		}

		switch (chunk) {
		case cAssigned:
		    strlcat(my_fmt, "%n", len_fmt);
		    pointer = &eaten;
		    break;
		case cInt:
		    pointer = va_arg(ap, int *);
		    break;
		case cShort:
		    pointer = va_arg(ap, short *);
		    break;
		case cFloat:
		    pointer = va_arg(ap, float *);
		    break;
		case cDouble:
		    pointer = va_arg(ap, double *);
		    break;
		case cLong:
		    pointer = va_arg(ap, long *);
		    break;
		case cPointer:
		    pointer = va_arg(ap, void *);
		    break;
		case cChar:
		case cRange:
		case cString:
		    pointer = va_arg(ap, char *);
		    break;
		case cError:
		case cUnknown:
		    break;
		}
		/* do the conversion */
		T(("...converting chunk #%d type %d(%s,%s)",
		   assigned + 1, chunk,
		   _nc_visbuf2(1, str + consumed),
		   _nc_visbuf2(2, my_fmt)));
		if (sscanf(str + consumed, my_fmt, pointer, &eaten) > 0)
		    consumed += eaten;
		else
		    break;
		++assigned;
	    }
	    free(my_fmt);
	}
    }
    returnCode(assigned);
#endif
}
Exemplo n.º 3
0
_nc_visbuf(const char *buf)
{
    return _nc_visbuf2(0, buf);
}
Exemplo n.º 4
0
NCURSES_EXPORT(int) (addstr) (const char * z)
{
	T((T_CALLED("addstr(%s)"), _nc_visbuf2(0,z)));
	returnCode(waddnstr(stdscr,(z),-1));
}
Exemplo n.º 5
0
_nc_varargs(const char *fmt, va_list ap)
{
    static char dummy[] = "";

    char buffer[BUFSIZ];
    const char *param;
    int n;

    if (fmt == 0 || *fmt == '\0')
	return dummy;
    if (MyLength == 0)
	MyBuffer = typeMalloc(char, MyLength = BUFSIZ);
    if (MyBuffer == 0)
	return dummy;
    *MyBuffer = '\0';

    while (*fmt != '\0') {
	if (*fmt == '%') {
	    char *pval = 0;	/* avoid const-cast */
	    const char *sval = "";
	    double fval = 0.0;
	    int done = FALSE;
	    int ival = 0;
	    int type = 0;
	    ARGTYPE parm[MAX_PARMS];
	    int parms = 0;
	    ARGTYPE used = atUnknown;

	    while (*++fmt != '\0' && !done) {

		if (*fmt == '*') {
		    VA_INT(int);
		    if (parms < MAX_PARMS)
			parm[parms++] = atInteger;
		} else if (isalpha(UChar(*fmt))) {
		    done = TRUE;
		    switch (*fmt) {
		    case 'Z':	/* FALLTHRU */
		    case 'h':	/* FALLTHRU */
		    case 'l':	/* FALLTHRU */
			done = FALSE;
			type = *fmt;
			break;
		    case 'i':	/* FALLTHRU */
		    case 'd':	/* FALLTHRU */
		    case 'u':	/* FALLTHRU */
		    case 'x':	/* FALLTHRU */
		    case 'X':	/* FALLTHRU */
			if (type == 'l')
			    VA_INT(long);
			else if (type == 'Z')
			    VA_INT(size_t);
			else
			    VA_INT(int);
			used = atInteger;
			break;
		    case 'f':	/* FALLTHRU */
		    case 'e':	/* FALLTHRU */
		    case 'E':	/* FALLTHRU */
		    case 'g':	/* FALLTHRU */
		    case 'G':	/* FALLTHRU */
			VA_FLT(double);
			used = atFloat;
			break;
		    case 'c':
			VA_INT(int);
			used = atInteger;
			break;
		    case 's':
			VA_STR(const char *);
			used = atString;
			break;
		    case 'p':
			VA_PTR(void *);
			used = atPoint;
			break;
		    case 'n':
			VA_PTR(int *);
			used = atPoint;
			break;
		    default:
			break;
		    }
		} else if (*fmt == '%') {
		    done = TRUE;
		}
		if (used != atUnknown && parms < MAX_PARMS) {
		    parm[parms++] = used;
		    for (n = 0; n < parms; ++n) {
			used = parm[n];
			param = buffer;
			switch (used) {
			case atInteger:
			    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
					"%d", ival);
			    break;
			case atFloat:
			    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
					"%f", fval);
			    break;
			case atPoint:
			    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
					"%p", pval);
			    break;
			case atString:
			    param = _nc_visbuf2(1, sval);
			    break;
			case atUnknown:
			default:
			    _nc_STRCPY(buffer, "?", sizeof(buffer));
			    break;
			}
			MyLength += strlen(param) + 2;
			MyBuffer = typeRealloc(char, MyLength, MyBuffer);
			_nc_SPRINTF(MyBuffer + strlen(MyBuffer),
				    _nc_SLIMIT(MyLength - strlen(MyBuffer))
				    ", %s", param);
		    }
		}
		used = atUnknown;
	    }
	} else {
Exemplo n.º 6
0
NCURSES_EXPORT(int) (winstr) (WINDOW * a1, char * z)
{
	T((T_CALLED("winstr(%p,%s)"), (const void *)a1, _nc_visbuf2(1,z))); returnCode(winnstr(a1, z, -1));
}
Exemplo n.º 7
0
NCURSES_EXPORT(int) (addnstr) (const char * a1, int z)
{
	T((T_CALLED("addnstr(%s,%d)"), _nc_visbuf2(0,a1), z));
	returnCode(waddnstr(stdscr,(a1),(z)));
}
Exemplo n.º 8
0
NCURSES_EXPORT(int) (mvwinstr) (WINDOW * a1, int a2, int a3, char * z)
{
	T((T_CALLED("mvwinstr(%p,%d,%d,%s)"), (const void *)a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winnstr(a1, z, -1)));
}
Exemplo n.º 9
0
NCURSES_EXPORT(int) (vw_scanw) (WINDOW * a1, char * a2, va_list z)
{
	T((T_CALLED("vw_scanw(%p,%s,%s)"), (const void *)a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwscanw(a1, a2, z));
}
Exemplo n.º 10
0
NCURSES_EXPORT(int) (mvwgetnstr) (WINDOW * a1, int a2, int a3, char * a4, int z)
{
	T((T_CALLED("mvwgetnstr(%p,%d,%d,%s,%d)"), (const void *)a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wgetnstr(a1,a4,z)));
}
Exemplo n.º 11
0
NCURSES_EXPORT(int) (mvinstr) (int a1, int a2, char * z)
{
	T((T_CALLED("mvinstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winnstr(stdscr, z, -1)));
}
Exemplo n.º 12
0
NCURSES_EXPORT(int) (mvinsnstr) (int a1, int a2, const char * a3, int z)
{
	T((T_CALLED("mvinsnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsnstr(stdscr,a3,z)));
}
Exemplo n.º 13
0
NCURSES_EXPORT(int) (instr) (char * z)
{
	T((T_CALLED("instr(%s)"), _nc_visbuf2(0,z))); returnCode(winnstr(stdscr, z, -1));
}
Exemplo n.º 14
0
NCURSES_EXPORT(int) (getnstr) (char * a1, int z)
{
	T((T_CALLED("getnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(wgetnstr(stdscr, a1, z));
}