Ejemplo n.º 1
0
static char *
SkipBlanks(char *src)
{
    while (isspace(CharOf(*src)))
	src++;
    return (src);
}
Ejemplo n.º 2
0
static int
color_code(const char *s, const char **t)
{
    int result = 0;
    const char *base = s;

    if (*s != 0) {
	for (;;) {
	    while ((*s != '\0') && strchr("RUBI", *s) != 0)
		++s;
	    if (*s == '\0') {
		result = 1;
		break;
	    } else if (*s++ == 'C') {
		if (isxdigit(CharOf(*s))) {
		    if (*(++s) == 0) {
			result = 1;
		    }
		}
	    } else {
		break;
	    }
	}
	if (result && FltOptions('c')) {
	    *t = base;
	}
    }
    return result;
}
Ejemplo n.º 3
0
static void
formatAscii(char *dst, unsigned value)
{
    switch (value) {
    case '\\':
	sprintf(dst, "\\\\");
	break;
    case '\b':
	sprintf(dst, "\\b");
	break;
    case '\n':
	sprintf(dst, "\\n");
	break;
    case '\r':
	sprintf(dst, "\\r");
	break;
    case '\t':
	sprintf(dst, "\\t");
	break;
    default:
	if (E2A(value) < 32 || (E2A(value) >= 127 && E2A(value) < 160))
	    sprintf(dst, "\\%03o", value);
	else
	    sprintf(dst, "%c", CharOf(value));
	break;
    }
}
Ejemplo n.º 4
0
static void drawCDKButtonText (CDKBUTTON * button)
{
   int boxWidth = button->boxWidth;
   int i;

   /* Draw in the message. */

   for (i = 0; i < boxWidth - 2 * BorderOf(button); i++)
   {
      chtype c;
      int pos = button->infoPos;
      int len = button->infoLen;

      if (i >= pos && (i - pos) < len)
	 c = button->info[i - pos];
      else
	 c = ' ';

      if (HasFocusObj (button))
      {
	 c = A_REVERSE | CharOf(c);
      }

      mvwaddch (button->win, BorderOf(button), i + BorderOf(button), c);
   }
}
Ejemplo n.º 5
0
/*
 * Resequence the numbers after a insertion/deletion.
 */
static void resequence (CDKSCROLL *scrollp)
{
    if (scrollp->numbers)
    {
        int j, k;
        for (j = 0; j < scrollp->listSize; ++j)
        {
            char source[80];
            chtype *target = scrollp->item[j];

            sprintf (source, NUMBER_FMT, j + 1, "");

            for (k = 0; source[k] != 0; ++k)
            {
                /* handle deletions that change the length of number */
                if (source[k] == '.' && CharOf (target[k]) != '.')
                {
                    int k2 = k;
                    while ((target[k2] = target[k2 + 1]) != 0)
                        ++k2;
                    scrollp->itemLen[j] -= 1;
                }
                target[k] &= A_ATTRIBUTES;
                target[k] |= (chtype)(unsigned char)source[k];
            }
        }
    }
}
Ejemplo n.º 6
0
String
x_skip_blanks(String s)
{
    while (isspace(CharOf(*s)))
	++s;
    return s;
}
Ejemplo n.º 7
0
static char *
SkipBlanks(char *s)
{
    while (isspace(CharOf(*s))) {
	flt_putc(*s++);
    }
    return s;
}
Ejemplo n.º 8
0
static NCURSES_INLINE chtype
_my_render(WINDOW *win, chtype ch)
{
    NCURSES_CH_T wch;
    SetChar2(wch, ch);
    wch = _nc_render(win, wch);
    return CharOf(wch) | AttrOf(wch);
}
Ejemplo n.º 9
0
_nc_wchstrlen(const cchar_t *s)
{
    int result = 0;
    while (CharOf(s[result]) != L'\0') {
	result++;
    }
    return result;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: hharte/vttest
char *
skip_xdigits(char *src)
{
  char *base = src;
  while (*src != '\0' && isxdigit(CharOf(*src)))
    src++;
  return (base == src) ? 0 : src;
}
Ejemplo n.º 11
0
_nc_build_wch(WINDOW *win, ARG_CH_T ch)
{
    char *buffer = WINDOW_EXT(win, addch_work);
    int len;
    int x = win->_curx;
    int y = win->_cury;
    mbstate_t state;
    wchar_t result;

    if ((WINDOW_EXT(win, addch_used) != 0) &&
	(WINDOW_EXT(win, addch_x) != x ||
	 WINDOW_EXT(win, addch_y) != y)) {
	/* discard the incomplete multibyte character */
	WINDOW_EXT(win, addch_used) = 0;
	TR(TRACE_VIRTPUT,
	   ("Alert discarded multibyte on move (%d,%d) -> (%d,%d)",
	    WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x),
	    y, x));
    }
    WINDOW_EXT(win, addch_x) = x;
    WINDOW_EXT(win, addch_y) = y;

    init_mb(state);
    buffer[WINDOW_EXT(win, addch_used)] = CharOf(CHDEREF(ch));
    WINDOW_EXT(win, addch_used) += 1;
    buffer[WINDOW_EXT(win, addch_used)] = '\0';
    if ((len = mbrtowc(&result,
		       buffer,
		       WINDOW_EXT(win, addch_used), &state)) > 0) {
	attr_t attrs = AttrOf(CHDEREF(ch));
	SetChar(CHDEREF(ch), result, attrs);
	WINDOW_EXT(win, addch_used) = 0;
    } else {
	if (len == -1) {
	    /*
	     * An error occurred.  We could either discard everything,
	     * or assume that the error was in the previous input.
	     * Try the latter.
	     */
	    TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error"));
	    buffer[0] = CharOf(CHDEREF(ch));
	    WINDOW_EXT(win, addch_used) = 1;
	}
    }
    return len;
}
Ejemplo n.º 12
0
int
ci_compare(const char *a, const char *b)
{
    int ch1, ch2, cmp;

    for (;;) {
	ch1 = CharOf(*a++);
	ch2 = CharOf(*b++);
	if (islower(ch1))
	    ch1 = toupper(ch1);
	if (islower(ch2))
	    ch2 = toupper(ch2);
	cmp = ch1 - ch2;
	if (cmp != 0 || ch1 == EOS || ch2 == EOS)
	    return cmp;
    }
}
Ejemplo n.º 13
0
Archivo: main.c Proyecto: hharte/vttest
const char *
skip_digits_2(const char *src)
{
  const char *base = src;
  while (*src != '\0' && isdigit(CharOf(*src)))
    src++;
  return (base == src) ? 0 : src;
}
Ejemplo n.º 14
0
static
#if !USE_WIDEC_SUPPORT		/* cannot be inline if it is recursive */
NCURSES_INLINE
#endif
int
waddch_literal(WINDOW *win, NCURSES_CH_T ch)
{
    int x;
    int y;
    struct ldat *line;

    x = win->_curx;
    y = win->_cury;

    CHECK_POSITION(win, x, y);

    ch = render_char(win, ch);

    line = win->_line + y;

    CHANGED_CELL(line, x);

    /*
     * Build up multibyte characters until we have a wide-character.
     */
    if_WIDEC({
	if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
	    int len = _nc_build_wch(win, CHREF(ch));

	    if (len >= -1) {
		/* handle EILSEQ */
		if (is8bits(CharOf(ch))) {
		    const char *s = unctrl((chtype) CharOf(ch));
		    if (s[1] != 0) {
			return waddstr(win, s);
		    }
		}
		if (len == -1)
		    return waddch(win, ' ');
	    } else {
		return OK;
	    }
	}
    });
Ejemplo n.º 15
0
static size_t
TrimBlanks(char *src)
{
    size_t len = strlen(src);

    while (len != 0
	   && isspace(CharOf(src[len - 1])))
	src[--len] = 0;
    return (len);
}
Ejemplo n.º 16
0
winch(WINDOW *win)
{
    T((T_CALLED("winch(%p)"), win));
    if (win != 0) {
	returnChar(CharOf(win->_line[win->_cury].text[win->_curx]) |
		   AttrOf(win->_line[win->_cury].text[win->_curx]));
    } else {
	returnChar(0);
    }
}
Ejemplo n.º 17
0
/*
 *	int last_char()
 *
 *	Returns the final nonblank character on the current input buffer
 */
static int
last_char(void)
{
    size_t len = strlen(bufptr);
    while (len--) {
	if (!isspace(CharOf(bufptr[len])))
	    return bufptr[len];
    }
    return 0;
}
Ejemplo n.º 18
0
/*
 * Check if the cursor is on a valid edit-position.  This must be one of
 * the non-blank cells in the field.
 */
static int validEditPosition(CDKUSCALE *widget, int newPosition)
{
    chtype ch;
    if (newPosition <= 0 || newPosition >= widget->fieldWidth)
        return FALSE;
    if (moveToEditPosition(widget, newPosition) == ERR)
        return FALSE;
    ch = winch(widget->fieldWin);
    if (CharOf(ch) != ' ')
        return TRUE;
    if (newPosition > 1)
    {
        /* don't use recursion - only one level is wanted */
        if (moveToEditPosition(widget, newPosition - 1) == ERR)
            return FALSE;
        ch = winch(widget->fieldWin);
        return CharOf(ch) != ' ';
    }
    return FALSE;
}
Ejemplo n.º 19
0
/* remaining nonblanks on the line are unexpected */
static char *
SkipError(char *s)
{
    char *base = s;
    size_t len = strlen(s);

    while (len > 0 && isspace(CharOf(s[len - 1])))
	len--;
    flt_puts(base, (int) len, Error_attr);
    return SkipBlanks(base + len);
}
Ejemplo n.º 20
0
/*
 * Parse numeric parameters which have the operator as a prefix rather than a
 * suffix as in ANSI format.
 *
 *  #             0
 *  #1            1
 *  #1;           1
 *  "1;2;640;480  4
 *  #1;2;0;0;0    5
 */
static void
parse_prefixedtype_params(ANSI *params, const char **string)
{
    const char *cp = *string;
    ParmType nparam = 0;
    int last_empty = 1;

    memset(params, 0, sizeof(*params));
    params->a_final = CharOf(*cp);
    if (*cp != '\0')
	cp++;

    while (*cp != '\0') {
	Char ch = CharOf(*cp);

	if (isdigit(ch)) {
	    last_empty = 0;
	    if (nparam < NPARAM) {
		params->a_param[nparam] =
		    (ParmType) ((params->a_param[nparam] * 10)
				+ (ch - '0'));
	    }
	} else if (ch == ';') {
	    last_empty = 1;
	    nparam++;
	} else if (ch == ' ' || ch == '\r' || ch == '\n') {
	    /* EMPTY */ ;
	} else {
	    break;
	}
	cp++;
    }

    *string = cp;
    if (!last_empty)
	nparam++;
    if (nparam > NPARAM)
	params->a_nparam = NPARAM;
    else
	params->a_nparam = nparam;
}
Ejemplo n.º 21
0
/*
 * Perform an editing function for the field.
 */
static bool performEdit(CDKFSLIDER *widget, chtype input)
{
   bool result = FALSE;
   bool modify = TRUE;
   int base = widget->fieldWidth;
   int need = formattedSize(widget, widget->current);
   char *temp = (char *)malloc(need + 5);
   char *data = temp;
   char test;
   int col = need - widget->fieldEdit;
   double value;
#define SCANF_FMT "%lg%c"

   if (temp != 0)
   {
      int adj = (col < 0) ? (-col) : 0;
      if (adj)
      {
	 memset(temp, ' ', adj);
	 temp += adj;
      }
      wmove(widget->fieldWin, 0, base);
      winnstr(widget->fieldWin, temp, need);
      strcpy(temp + need, " ");
      if (isChar(input))	/* replace the char at the cursor */
      {
	 temp[col] = CharOf(input);
      }
      else if (input == KEY_BACKSPACE)	/* delete the char before the cursor */
      {
	 modify = removeChar(temp, col - 1);
      }
      else if (input == KEY_DC)	/* delete the char at the cursor */
      {
	 modify = removeChar(temp, col);
      }
      else
      {
	 modify = FALSE;
      }
      if (modify
       && sscanf(temp, SCANF_FMT, &value, &test) == 2
       && test == ' '
       && value >= widget->low
       && value <= widget->high)
      {
	 setCDKFSliderValue(widget, value);
	 result = TRUE;
      }
      free(data);
   }
   return result;
}
Ejemplo n.º 22
0
/*
 * Encode a string into hexadecimal, returning the encoded string.
 * The caller must free the result.
 */
char *
x_encode_hex(const char *source)
{
    size_t need = (strlen(source) * 2) + 1;
    char *result = malloc(need);

    if (result != 0) {
	unsigned j, k;
	for (j = k = 0; source[j] != '\0'; ++j) {
	    sprintf(result + k, "%02X", CharOf(source[j]));
	    k += 2;
	}
    }
    return result;
}
Ejemplo n.º 23
0
wunctrl(cchar_t *wc)
{
    static wchar_t str[CCHARW_MAX + 1], *sp;

    if (Charable(*wc)) {
	const char *p = unctrl((unsigned) _nc_to_char((wint_t) CharOf(*wc)));

	for (sp = str; *p; ++p) {
	    *sp++ = _nc_to_widechar(*p);
	}
	*sp = 0;
	return str;
    } else
	return wc->chars;
}
Ejemplo n.º 24
0
/*
 * Perform an editing function for the field.
 */
static bool performEdit(CDKUSCALE *widget, chtype input)
{
    bool result = FALSE;
    bool modify = TRUE;
    int base = 0;
    int need  = widget->fieldWidth;
    char *temp = (char *)malloc(need + 2);
    char test;
    int col = need - widget->fieldEdit - 1;
    unsigned value;
#define SCANF_FMT "%u%c"

    if (temp != 0)
    {
        wmove(widget->fieldWin, 0, base);
        winnstr(widget->fieldWin, temp, need);
        strcpy(temp + need, " ");
        if (isChar(input))	/* replace the char at the cursor */
        {
            temp[col] = CharOf(input);
        }
        else if (input == KEY_BACKSPACE)	/* delete the char before the cursor */
        {
            modify = removeChar(temp, col - 1);
        }
        else if (input == KEY_DC)	/* delete the char at the cursor */
        {
            modify = removeChar(temp, col);
        }
        else
        {
            modify = FALSE;
        }
        if (modify
                && sscanf(temp, SCANF_FMT, &value, &test) == 2
                && test == ' '
                && value >= widget->low
                && value <= widget->high)
        {
            setCDKUScaleValue(widget, value);
            result = TRUE;
        }
        free(temp);
    }
    return result;
}
Ejemplo n.º 25
0
NCURSES_SP_NAME(wunctrl) (NCURSES_SP_DCLx cchar_t *wc)
{
    static wchar_t str[CCHARW_MAX + 1], *wsp;

    if (Charable(*wc)) {
	const char *p =
	NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx
				 (unsigned) _nc_to_char((wint_t)CharOf(*wc)));

	for (wsp = str; *p; ++p) {
	    *wsp++ = (wchar_t) _nc_to_widechar(*p);
	}
	*wsp = 0;
	return str;
    } else
	return wc->chars;
}
Ejemplo n.º 26
0
winchnstr(WINDOW *win, chtype *str, int n)
{
    int i = 0;

    T((T_CALLED("winchnstr(%p,%p,%d)"), (void *) win, (void *) str, n));

    if (!str)
	returnCode(0);

    if (win) {
	for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++)
	    str[i] =
		(chtype) CharOf(win->_line[win->_cury].text[win->_curx + i]) |
		AttrOf(win->_line[win->_cury].text[win->_curx + i]);
    }
    str[i] = (chtype) 0;

    returnCode(i);
}
Ejemplo n.º 27
0
Archivo: main.c Proyecto: hharte/vttest
int
scanto(const char *str, int *pos, int toc)
{
  char c;
  int result = 0;

  while (toc != (c = str[(*pos)])) {
    *pos += 1;
    if (isdigit(CharOf(c)))
      result = result * 10 + c - '0';
    else
      break;
  }
  if (c == toc) {
    *pos += 1;  /* point past delimiter */
    return (result);
  }
  return (0);
}
Ejemplo n.º 28
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static char * Only_Padding(
|                                    WINDOW *w,
|                                    int len,
|                                    int pad)
|   
|   Description   :  Test if 'length' cells starting at the current position
|                    contain a padding character.
|
|   Return Values :  true if only padding cells are found
+--------------------------------------------------------------------------*/
NCURSES_INLINE static bool
Only_Padding(WINDOW *w, int len, int pad)
{
  bool result = TRUE;
  int y, x, j;
  FIELD_CELL cell;

  getyx(w, y, x);
  for (j = 0; j < len; ++j)
    {
      if (wmove(w, y, x + j) != ERR)
	{
#if USE_WIDEC_SUPPORT
	  if (win_wch(w, &cell) != ERR)
	    {
	      if ((chtype)CharOf(cell) != ChCharOf(pad)
		  || cell.chars[1] != 0)
		{
		  result = FALSE;
		  break;
		}
	    }
#else
	  cell = winch(w);
	  if (ChCharOf(cell) != ChCharOf(pad))
	    {
	      result = FALSE;
	      break;
	    }
#endif
	}
      else
	{
	  /* if an error, return true: no non-padding text found */
	  break;
	}
    }
  /* no need to reset the cursor position; caller does this */
  return result;
}
Ejemplo n.º 29
0
NCURSES_SP_NAME(wunctrl) (NCURSES_SP_DCLx cchar_t *wc)
{
    static wchar_t str[CCHARW_MAX + 1], *wsp;
    wchar_t *result;

    if (wc == 0) {
	result = 0;
    } else if (SP_PARM != 0 && Charable(*wc)) {
	const char *p =
	NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx
				 (unsigned) _nc_to_char((wint_t)CharOf(*wc)));

	for (wsp = str; *p; ++p) {
	    *wsp++ = (wchar_t) _nc_to_widechar(*p);
	}
	*wsp = 0;
	result = str;
    } else {
	result = wc->chars;
    }
    return result;
}
Ejemplo n.º 30
0
_tracedump(const char *name, WINDOW *win)
{
    static char *buf = 0;
    static size_t used = 0;

    int i, j, n, width;

    /* compute narrowest possible display width */
    for (width = i = 0; i <= win->_maxy; ++i) {
	n = 0;
	for (j = 0; j <= win->_maxx; ++j)
	    if (CharOf(win->_line[i].text[j]) != L(' ')
		|| AttrOf(win->_line[i].text[j]) != A_NORMAL)
		n = j;

	if (n > width)
	    width = n;
    }
    if (width < win->_maxx)
	++width;
    if (++width + 1 > (int) used) {
	used = 2 * (width + 1);
	buf = typeRealloc(char, used, buf);
    }