Пример #1
0
int
main(int argc, char *argv[])
{
    wctype_t t;
    int i, j;
    struct {
        const char *name;
        int (*func)(wint_t);
    } cls[] = {
        { "alnum", iswalnum },
        { "alpha", iswalpha },
        { "blank", iswblank },
        { "cntrl", iswcntrl },
        { "digit", iswdigit },
        { "graph", iswgraph },
        { "lower", iswlower },
        { "print", iswprint },
        { "punct", iswpunct },
        { "space", iswspace },
        { "upper", iswupper },
        { "xdigit", iswxdigit }
    };

    printf("1..2\n");

    /*
     * C/POSIX locale.
     */
    for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) {
        t = wctype(cls[i].name);
        assert(t != 0);
        for (j = 0; j < 256; j++)
            assert(cls[i].func(j) == iswctype(j, t));
    }
    t = wctype("elephant");
    assert(t == 0);
    for (i = 0; i < 256; i++)
        assert(iswctype(i, t) == 0);

    /*
     * Japanese (EUC) locale.
     */
    assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
    for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) {
        t = wctype(cls[i].name);
        assert(t != 0);
        for (j = 0; j < 65536; j++)
            assert(cls[i].func(j) == iswctype(j, t));
    }
    t = wctype("elephant");
    assert(t == 0);
    for (i = 0; i < 65536; i++)
        assert(iswctype(i, t) == 0);

    printf("ok 1 - iswctype()\n");
    printf("ok 2 - wctype()\n");

    return (0);
}
Пример #2
0
static int match_bracket(const char *p, int k, int kfold)
{
	wchar_t wc;
	int inv = 0;
	p++;
	if (*p=='^' || *p=='!') {
		inv = 1;
		p++;
	}
	if (*p==']') {
		if (k==']') return !inv;
		p++;
	} else if (*p=='-') {
		if (k=='-') return !inv;
		p++;
	}
	wc = p[-1];
	for (; *p != ']'; p++) {
		if (p[0]=='-' && p[1]!=']') {
			wchar_t wc2;
			int l = mbtowc(&wc2, p+1, 4);
			if (l < 0) return 0;
			if (wc <= wc2)
				if ((unsigned)k-wc <= wc2-wc ||
				    (unsigned)kfold-wc <= wc2-wc)
					return !inv;
			p += l-1;
			continue;
		}
		if (p[0]=='[' && (p[1]==':' || p[1]=='.' || p[1]=='=')) {
			const char *p0 = p+2;
			int z = p[1];
			p+=3;
			while (p[-1]!=z || p[0]!=']') p++;
			if (z == ':' && p-1-p0 < 16) {
				char buf[16];
				memcpy(buf, p0, p-1-p0);
				buf[p-1-p0] = 0;
				if (iswctype(k, wctype(buf)) ||
				    iswctype(kfold, wctype(buf)))
					return !inv;
			}
			continue;
		}
		if (*p < 128U) {
			wc = (unsigned char)*p;
		} else {
			int l = mbtowc(&wc, p, 4);
			if (l < 0) return 0;
			p += l-1;
		}
		if (wc==k || wc==kfold) return !inv;
	}
	return inv;
}
Пример #3
0
/* We have to convert the wide character string in a multibyte string.  But
   we know that the character class names consist of alphanumeric characters
   from the portable character set, and since the wide character encoding
   for a member of the portable character set is the same code point as
   its single-byte encoding, we can use a simplified method to convert the
   string to a multibyte character string.  */
static wctype_t
is_char_class (const wchar_t *wcs)
{
  char s[CHAR_CLASS_MAX_LENGTH + 1];
  char *cp = s;

  do
    {
      /* Test for a printable character from the portable character set.  */
#  ifdef _LIBC
      if (*wcs < 0x20 || *wcs > 0x7e
          || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60)
        return (wctype_t) 0;
#  else
      switch (*wcs)
        {
        case L' ': case L'!': case L'"': case L'#': case L'%':
        case L'&': case L'\'': case L'(': case L')': case L'*':
        case L'+': case L',': case L'-': case L'.': case L'/':
        case L'0': case L'1': case L'2': case L'3': case L'4':
        case L'5': case L'6': case L'7': case L'8': case L'9':
        case L':': case L';': case L'<': case L'=': case L'>':
        case L'?':
        case L'A': case L'B': case L'C': case L'D': case L'E':
        case L'F': case L'G': case L'H': case L'I': case L'J':
        case L'K': case L'L': case L'M': case L'N': case L'O':
        case L'P': case L'Q': case L'R': case L'S': case L'T':
        case L'U': case L'V': case L'W': case L'X': case L'Y':
        case L'Z':
        case L'[': case L'\\': case L']': case L'^': case L'_':
        case L'a': case L'b': case L'c': case L'd': case L'e':
        case L'f': case L'g': case L'h': case L'i': case L'j':
        case L'k': case L'l': case L'm': case L'n': case L'o':
        case L'p': case L'q': case L'r': case L's': case L't':
        case L'u': case L'v': case L'w': case L'x': case L'y':
        case L'z': case L'{': case L'|': case L'}': case L'~':
          break;
        default:
          return (wctype_t) 0;
        }
#  endif

      /* Avoid overrunning the buffer.  */
      if (cp == s + CHAR_CLASS_MAX_LENGTH)
        return (wctype_t) 0;

      *cp++ = (char) *wcs++;
    }
  while (*wcs != L'\0');

  *cp = '\0';

#  ifdef _LIBC
  return __wctype (s);
#  else
  return wctype (s);
#  endif
}
Пример #4
0
void testValues() {
    f = 2;
    wctype_t result;

    char buf[] = "";
    //@ assert \valid(buf+(0..\block_length(buf)-1));
    //@ assert \exists integer x; buf[x] == '\0';
    wctype(buf);

    //@ assert f == 2;
    //@ assert vacuous: \false;
}
Пример #5
0
int
_reg_iswblank(wint_t wc)
{
	static int	initialized;
	static wctype_t	wt;

	if (!initialized)
	{
		initialized = 1;
		wt = wctype("blank");
	}
	return iswctype(wc, wt);
}
Пример #6
0
// -----------------------------------------------------------------------------
//Function Name :testwctype17
//API Tested :wctype
//TestCase Description:wctype returns ->0 as property descriptor as the name
//parameter passed is invalid one. 
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype17L()
    {
	wctype_t type;
	  
	type = wctype("kkkkit");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrNone;
		}
	  
	return KErrGeneral;
	  
    }
Пример #7
0
static void
genclass(STR *s)
{

	if ((s->cclass = wctype(s->str)) == 0)
		errx(1, "unknown class %s", s->str);
	s->cnt = 0;
	s->lastch = -1;		/* incremented before check in next() */
	if (strcmp(s->str, "upper") == 0)
		s->state = CCLASS_UPPER;
	else if (strcmp(s->str, "lower") == 0)
		s->state = CCLASS_LOWER;
	else
		s->state = CCLASS;
}
Пример #8
0
// -----------------------------------------------------------------------------
//Function Name :testwctype13
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype13L()
    {
	wctype_t type;
	  
	type = wctype("upper");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrGeneral;
		}
	  
	if(iswctype((wint_t)L'K',type))
		{
	  	return KErrNone;
		}

    return KErrGeneral;
    }
Пример #9
0
// -----------------------------------------------------------------------------
//Function Name :testwctype10
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.(negative test case)
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype10L()
    {
	wctype_t type;
	  
	type = wctype("lower");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrGeneral;
		}
	  
	if(iswctype(L'K',type))
		{
	  	return KErrGeneral;
		}
	  
	return KErrNone;	
		
    }
Пример #10
0
// -----------------------------------------------------------------------------
//Function Name :testwctype16
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype16L()
    {
	wctype_t type;
	  
	type = wctype("xdigit");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrGeneral;
		}
	  
	if(iswctype(6,type))
		{
	  	return KErrGeneral;
		}
	  
	return KErrNone;	
	
    }
Пример #11
0
// -----------------------------------------------------------------------------
//Function Name :testwctype12
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype12L()
    {
	wctype_t type;
	  
	type = wctype("punct");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrGeneral;
		}
	  
	if(iswctype(L'k',type))
		{
	  	return KErrGeneral;
		}
	  
	return KErrNone;	
	
    }
Пример #12
0
// -----------------------------------------------------------------------------
//Function Name :testwctype5
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype5L()
    {
	wctype_t type;
	  
	type = wctype("blank");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrGeneral;
		}
	  
	if(iswctype(L' ',type))
		{
	    return KErrNone;	
		}
			
	return KErrGeneral;
    
    }
Пример #13
0
// -----------------------------------------------------------------------------
//Function Name :testwctype4
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.(negative test case)
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype4L()
    {
	wctype_t type;
	  
	type = wctype("alpha");
	  
	if(type == (wctype_t)0)
		{
		return KErrGeneral;
		}
	  
	if(iswctype(L'5',type))
		{
	  	return KErrGeneral;
		}
	  
	return KErrNone;	
		
    }
Пример #14
0
// -----------------------------------------------------------------------------
//Function Name :testwctype2
//API Tested :wctype
//TestCase Description:wctype returns -> property descriptor if name is valid
//this prop desc can be used by iswctype function to test the wide char passed
// to it is of type returned by the wctype fun.
// -----------------------------------------------------------------------------
TInt CTestLibcwchar::testwctype2L()
    {
	wctype_t type;
	  
	type = wctype("alnum");
	  
	if(type == (wctype_t)0)
		{
	  	return KErrGeneral;
		}
	  
	if(iswctype((wint_t)L'6',type))
		{
	    return KErrNone;	
		}
			
	return KErrGeneral;
    
    }
Пример #15
0
regclass_t
regclass(const char* s, char** e)
{
	register Ctype_t*	cp;
	register int		c;
	register size_t		n;
	register const char*	t;

	if (c = *s++)
	{
		for (t = s; *t && (*t != c || *(t + 1) != ']'); t++);
		if (*t != c)
			return 0;
		n = t - s;
		for (cp = ctypes; cp; cp = cp->next)
			if (n == cp->size && strneq(s, cp->name, n))
				goto found;
		for (cp = ctype; cp < &ctype[elementsof(ctype)]; cp++)
		{
#if _lib_wctype
			if (!cp->size && (cp->name = (const char*)memdup(s, n + 1)))
			{
				*((char*)cp->name + n) = 0;
				/* mvs.390 needs the (char*) cast -- barf */
				if (!(cp->wtype = wctype((char*)cp->name)))
				{
					free((char*)cp->name);
					return 0;
				}
				cp->size = n;
				goto found;
			}
#endif
			if (n == cp->size && strneq(s, cp->name, n))
				goto found;
		}
	}
	return 0;
 found:
	if (e)
		*e = (char*)t + 2;
	return cp->ctype;
}
Пример #16
0
/*
 * See if a character matches a character class, starting at the first colon
 * of "[:class:]".
 * If a valid character class is recognized, a pointer to the next character
 * after the final closing bracket is stored into *end, otherwise a null
 * pointer is stored into *end.
 */
static int
match_charclass(const char *p, wchar_t chr, const char **end)
{
	char name[20];
	const char *nameend;
	wctype_t cclass;

	*end = NULL;
	p++;
	nameend = strstr(p, ":]");
	if (nameend == NULL || nameend - p >= sizeof(name) || nameend == p)
		return 0;
	memcpy(name, p, nameend - p);
	name[nameend - p] = '\0';
	*end = nameend + 2;
	cclass = wctype(name);
	/* An unknown class matches nothing but is valid nevertheless. */
	if (cclass == 0)
		return 0;
	return iswctype(chr, cclass);
}
Пример #17
0
int main()
{
    wctype_t wct_kanji, wct_kata, wct_hira  /* , ... */ ;

    if ( setlocale( LC_CTYPE, "ja_JP.UTF-8" ) == NULL)
        fputws(L"Unable to set the locale.\n", stderr);

    if (( wct_kata = wctype( "jkata" ) ) == 0 )
    {   wprintf( L"The locale doesn't support the wide-character type "
                  "string \"jkata\".\n" ); 
        return -1;
    }
    /* ... */
    wchar_t wc = fgetwc( stdin );
    if ( iswctype( wc, wct_kata ) )          // Mainly 0xFF66 − 0xFF9F.
        wprintf( L"%lc is a katakana character.\n", wc );
    else
        wprintf( L"%lc is a not katakana character.\n", wc );

    return 0;
}
Пример #18
0
void wctype_check_functions(wint_t i, wctype_t t, wctrans_t tr, locale_t l)
{
    (void)iswalnum(i);
    (void)iswalnum_l(i, l);
    (void)iswalpha(i);
    (void)iswalpha_l(i, l);
    (void)iswblank(i);
    (void)iswblank_l(i, l);
    (void)iswcntrl(i);
    (void)iswcntrl_l(i, l);
    (void)iswctype(i, t);
    (void)iswctype_l(i, t, l);
    (void)iswdigit(i);
    (void)iswdigit_l(i, l);
    (void)iswgraph(i);
    (void)iswgraph_l(i, l);
    (void)iswlower(i);
    (void)iswlower_l(i, l);
    (void)iswprint(i);
    (void)iswprint_l(i, l);
    (void)iswpunct(i);
    (void)iswpunct_l(i, l);
    (void)iswspace(i);
    (void)iswspace_l(i, l);
    (void)iswupper(i);
    (void)iswupper_l(i, l);
    (void)iswxdigit(i);
    (void)iswxdigit_l(i, l);
    (void)towctrans(i, tr);
    (void)towctrans_l(i, tr, l);
    (void)towlower(i);
    (void)towlower_l(i, l);
    (void)towupper(i);
    (void)towupper_l(i, l);
    (void)wctrans((const char *)1234);
    (void)wctrans_l((const char *)1234, l);
    (void)wctype((const char *)1234);
    (void)wctype_l((const char *)1234, l);
}
Пример #19
0
/* Note: Using wctype()/iswctype() may seem odd, but that way we can avoid
 * hardcoded character class lists.
 */
static int sub_bracket( const char *p, int c )
{
    const char      *s = p;
    char            sname[CCL_NAME_MAX + 1];
    int             i;
    int             type;

    switch( *++p ) {
    case ':':
        ++p;
        for( i = 0; i < CCL_NAME_MAX; i++ ) {
            if( !isalpha(*p ) )
                break;
            sname[i] = *p++;
        }
        sname[i] = '\0';
        if( *p++ != ':' )
            return( 0 );
        if( *p++ != ']' )
            return( 0 );
        type = wctype( sname );
        if( type ) {
            int     rc;

            rc = p - s;
            return( iswctype( c, type ) ? rc : -rc );
        }
        return( 0 );
    case '=':
        return( 0 );
    case '.':
        return( 0 );
    default:
        return( 0 );
    }
}
Пример #20
0
 /*
    Returns whether we should save our changes or not.

    Edits an existing an entry. This routine is far to big, and handles
    everything, from movement between fields, and editing fields, even
    painting the screen.

 */
int
edit_entry(dbrecord * entry, const char *operationDesc, const char *entryDesc)
{
	int *len;
	int col0;
	wchar_t *line=NULL;
	char tbuf[MAXSCREENWIDTH];
	int code = 0;
	wchar_t ch;
	dbbuffer tmp;
	register int i, j, row, col;
    initHeading() ;
	/* Where is "column zero"? To right of longest field name.  */
	col0 = idx.idx_maxlen + 2;

	 clear();		/* Clear the screen.                            */
    initEntryLine() ;
    paintHeading(operationDesc) ;
	/* get max col TODO: change this when sigwhinch */
    /* first time: allocat wchar fulldbdir name
       fulldbdir is a static.*/
	for (row = STARTROW; row < (idx.idx_nlines+STARTROW); row++) { 
		/* print field names.                                   */
		mvaddwstr(row, 0, idx.idx_lines[row-STARTROW]);
	}
	/* Allocate some space in a temporary entry, and copy entry */
	/* to be edited into it.  This way they can abort the edit. */
	/* Here we need to allocate some extra space so we can edit */

	for (i = STARTROW; i < (idx.idx_nlines+STARTROW); i++) {
        int k = i-STARTROW ;
		if (entry->db_lens[k] == 0) {
			/* Allocate memory for this line.                   */
            size_t linelen = (MAXSCREENWIDTH * sizeof(wchar_t));
			tmp.db_lines[k] =
                 (wchar_t *) ymalloc(linelen,
                    "edit_entry","tmp.db_lines[k]" );
            memset(tmp.db_lines[k],0,linelen);
			tmp.db_lens[k] = 0;
		} else {
			/* Copy and print the line from the entry.          */
			tmp.db_lines[k] =
			    wcsFromUnicode_alloc((size_t *) & tmp.db_lens[k],
						 entry->db_lines[k],
						 (int32_t) entry->db_lens[k]);
			if (tmp.db_lines[k] == NULL) {
                yerror( YICU_CONV_ERR ,"edit_entry->wcsFromUnicode_alloc", "tmp.db_lines[k]", YX_EXTERNAL_CAUSE ) ;
			}
			/* reallocates more space to maximum linebuffer size. */
			tmp.db_lines[k] =
			    (wchar_t *) yrealloc(tmp.db_lines[k], (size_t)
						(MAXSCREENWIDTH * sizeof(wchar_t)),"edit_entry","tmp.db_lines[k]");
		}

		move(i, col0);
		clrtoeol();
		if (tmp.db_lens[k] > 0) {
			addwstr(tmp.db_lines[k]);
		}
	}			/* *could* have factored out the index code.              */
	col = col0;
	row = STARTROW;		/* row er hvilke rad i recorden (felt). */

	move(row, col);
	refresh();
	/* Editing entry. We provide basic EMACS-style cntrl chars. */
	while ((code = get_wch(&ch)) != EOF) {
		/* Get the current line and line length.                */
		line = tmp.db_lines[row-STARTROW];
		/* f.p. *len = &tmp.db_lens[row]; */
		len = &tmp.db_lens[row-STARTROW];
		switch (ch) {
		case CTRL('a'):	/* beginning of line            */
			col = col0;
			break;
		case KEY_LEFT:
		case CTRL('b'):	/* back character               */
			if (col > col0)
				col--;
			break;
		case CTRL('d'):	/* delete character             */
			if (col == (col0 + (int)wcslen(line))) {
				col--;
			} else if (*len) {
				/* Calculate position of character in string.   */
				int l = col - col0;

				/* Shuffle the string to the "left".            */
				while (l < *len) {
					line[l] = line[l + 1];
					l++;
				}
				*len -= 1;
				/* Delete the character on the screen.          */
				delch();
                if (col== (col0 + (int)wcslen(line)) ) {
                    --col ;
                }
			}

			break;
		case CTRL('e'):	/* end of line                  */
			col = col0 + *len;
			break;
		case KEY_RIGHT:
		case CTRL('f'):	/* forward character            */
			if ((col - col0) < *len)
				col++;
			break;
		case KEY_BACKSPACE:
		case CTRL('h'):	/* backspace delete             */
		case '\177':
			if (*len && ((col - 1) >= col0)) {
				/* Calculate position of character to delete.   */
				int l = col - col0 - 1;
				if (l < 0)
					break;
				/* Shuffle string "left".                        */
				while (l < *len) {
					line[l] = line[l + 1];
					l++;
				}

				*len -= 1;

				/* Delete the character from the screen.        */
				move(row, --col);
				delch();
			}
			break;
		case CTRL('k'):	/* kill line                    */
			if (len) {
                
			    int l = col - col0;

				line[l] = (wchar_t) '\0';
				*len = l;

				clrtoeol();
			}
			break;
		case CTRL('l'):	/* redraw screen                */
			wrefresh(curscr);
			break;
		case KEY_DOWN:
		case CTRL('n'):	/* next line                    */
			/* Wrap around to the top if necessary.             */
			if (++row >= (idx.idx_nlines+STARTROW))
				row = STARTROW; 
			/* If nothing in this column, move to nearest       */
			/* non-empty column.                                */
			if ((col - col0) > tmp.db_lens[row-STARTROW])
				col = col0 + tmp.db_lens[row-STARTROW];
			line[*len] = (wchar_t) '\0';
			break;
		case KEY_UP:
		case CTRL('p'):	/* previous line                */
			/* Wrap around if necessary.                        */
			if (--row < STARTROW)
				row = (idx.idx_nlines+STARTROW) - 1;

			/* If nothing in this column, move to nearest       */
			/* on-empty column.                                 */
			if ((col - col0) > tmp.db_lens[row-STARTROW])
				col = col0 + tmp.db_lens[row-STARTROW];
			line[*len] = (wchar_t) '\0';
			break;
		case CTRL('['):	/* save entry:  ESC or something...  */
			if (line[*len] != (wchar_t) '\0')
				line[*len] = (wchar_t) '\0';
			sprintf(tbuf, "Save %s entry in database (y/n)? ", entryDesc);
			ch = prompt_char(idx.idx_nlines + 2+ STARTROW, 0, tbuf, "yYnN");

			/* See what they said.                              */
			switch (ch) {
			case '\n':	/* never mind                       */
				move(idx.idx_nlines + 2, 0);
				clrtoeol();
				break;
			case 'Y':	/* save entry                       */
			case 'y':
				/* Copy the temporary entry into the real entry. */
				/* if there isn't anything to copy, then the entry db gets the value
				   NULL, and length 0 */
				for (i = 0; i < idx.idx_nlines; i++) {

					/* remove old contents in entry             */
					if (entry->db_lens[i] > 0) {
						free(entry->db_lines[i]);
						entry->db_lines[i] = NULL;
						entry->db_lens[i] = 0;
					} 
                    
                    if (tmp.db_lens[i] > 0) {
                        entry->db_lens[i]=tmp.db_lens[i] ;
						entry->db_lines[i] =
						    unicodeFromWcs_alloc((size_t *) &entry->db_lens[i],tmp.db_lines[i]);

					    if (entry->db_lines[i] == NULL) {
                            yerror( YICU_CONV_ERR ,"edit_entry->unicodeFromWcs_alloc", "entry->db_lines[i]", YX_EXTERNAL_CAUSE ) ;
                        }
                    } /* had a dangling else bug here ? */
					free(tmp.db_lines[i]);
                    tmp.db_lines[i] = NULL ;
				    tmp.db_lens[i] = 0;
				}
				return (1);
			case 'N':	/* don't save entry                 */
			case 'n':
				/* Free temporary memory.                       */
				for (i = 0; i < idx.idx_nlines; i++) {
					tmp.db_lens[i] = 0;
					free(tmp.db_lines[i]);
					tmp.db_lines[i] = NULL;
				}
				return (0);
			}
			break;
		case '\r':	/* return the string            */
		case '\n':	/* go to next line                  */
			/* Wrap around if necessary.                        */
			if (++row >= (idx.idx_nlines+STARTROW))
				row = STARTROW;
			col = col0;
			break;
		default:	/* something else                   */
			/* User's kill character: accepted to del line too. */
			if (ch == KEY_DL) {
				move(row, col0);
				clrtoeol();
				col = col0;

				*line = (wchar_t) '\0';
				*len = 0;
			} else if (code != KEY_CODE_YES) {
				/* If it's a printable character, insert it into */
				/* the string.                                  */
				if (iswctype(ch, wctype("print"))) {
					if (col == (COLS - 1)) {
						beep();
						break;
					}
					/* Calculate character position.            */
					i = col - col0;

					/* If necessary, move string * to "right"   */
					/* to insert the character.                 */
					if (i < *len) {
						for (j = *len; j >= i; j--)
							line[j + 1] = line[j];
					}

					line[i] = ch;
					*len += 1;
					col++;

					/* Insert the character on the screen.       */
					InsWch((chtype) ch);

				}
			}
			break;
		}

		/* Move to the current row/column.                       */
		move(row, col);
		refresh();
	}
	return (0);
}
Пример #21
0
void runSuccess() {
    char buf[] = "";
    //@ assert \valid(buf+(0..\block_length(buf)-1));
    //@ assert \exists integer x; buf[x] == '\0';
    wctype(buf);
}
Пример #22
0
int main( void )
{
    TESTCASE( iswctype(L'a', wctype("alpha")));
    TESTCASE( iswctype(L'z', wctype("alpha")));
    TESTCASE( iswctype(L'E', wctype("alpha")));
    TESTCASE(!iswctype(L'3', wctype("alpha")));
    TESTCASE(!iswctype(L';', wctype("alpha")));

    TESTCASE( iswctype(L'a', wctype("alnum")));
    TESTCASE( iswctype(L'3', wctype("alnum")));
    TESTCASE(!iswctype(L';', wctype("alnum")));

    TESTCASE( iswctype(L' ',  wctype("blank")));
    TESTCASE( iswctype(L'\t', wctype("blank")));
    TESTCASE(!iswctype(L'\n', wctype("blank")));
    TESTCASE(!iswctype(L';',  wctype("blank")));

    TESTCASE( iswctype(L'\0', wctype("cntrl")));
    TESTCASE( iswctype(L'\n', wctype("cntrl")));
    TESTCASE( iswctype(L'\v', wctype("cntrl")));
    TESTCASE(!iswctype(L'\t', wctype("cntrl")));
    TESTCASE(!iswctype(L'a',  wctype("cntrl")));

    TESTCASE( iswctype(L'0',  wctype("digit")));
    TESTCASE( iswctype(L'1',  wctype("digit")));
    TESTCASE( iswctype(L'2',  wctype("digit")));
    TESTCASE( iswctype(L'3',  wctype("digit")));
    TESTCASE( iswctype(L'4',  wctype("digit")));
    TESTCASE( iswctype(L'5',  wctype("digit")));
    TESTCASE( iswctype(L'6',  wctype("digit")));
    TESTCASE( iswctype(L'7',  wctype("digit")));
    TESTCASE( iswctype(L'8',  wctype("digit")));
    TESTCASE( iswctype(L'9',  wctype("digit")));
    TESTCASE(!iswctype(L'X',  wctype("digit")));
    TESTCASE(!iswctype(L'?',  wctype("digit")));

    TESTCASE( iswctype(L'a',  wctype("graph")));
    TESTCASE( iswctype(L'z',  wctype("graph")));
    TESTCASE( iswctype(L'E',  wctype("graph")));
    TESTCASE( iswctype(L'E',  wctype("graph")));
    TESTCASE(!iswctype(L' ',  wctype("graph")));
    TESTCASE(!iswctype(L'\t', wctype("graph")));
    TESTCASE(!iswctype(L'\n', wctype("graph")));

    TESTCASE( iswctype(L'a',  wctype("lower")));
    TESTCASE( iswctype(L'e',  wctype("lower")));
    TESTCASE( iswctype(L'z',  wctype("lower")));
    TESTCASE(!iswctype(L'A',  wctype("lower")));
    TESTCASE(!iswctype(L'E',  wctype("lower")));
    TESTCASE(!iswctype(L'Z',  wctype("lower")));

    TESTCASE(!iswctype(L'a',  wctype("upper")));
    TESTCASE(!iswctype(L'e',  wctype("upper")));
    TESTCASE(!iswctype(L'z',  wctype("upper")));
    TESTCASE( iswctype(L'A',  wctype("upper")));
    TESTCASE( iswctype(L'E',  wctype("upper")));
    TESTCASE( iswctype(L'Z',  wctype("upper")));

    TESTCASE( iswctype(L'Z',  wctype("print")));
    TESTCASE( iswctype(L'a',  wctype("print")));
    TESTCASE( iswctype(L';',  wctype("print")));
    TESTCASE( iswctype(L'\t', wctype("print")));
    TESTCASE(!iswctype(L'\0', wctype("print")));

    TESTCASE( iswctype(L';',  wctype("punct")));
    TESTCASE( iswctype(L'.',  wctype("punct")));
    TESTCASE( iswctype(L'?',  wctype("punct")));
    TESTCASE(!iswctype(L' ',  wctype("punct")));
    TESTCASE(!iswctype(L'Z',  wctype("punct")));

    TESTCASE( iswctype(L' ',  wctype("space")));
    TESTCASE( iswctype(L'\t', wctype("space")));

    TESTCASE( iswctype(L'0',  wctype("xdigit")));
    TESTCASE( iswctype(L'1',  wctype("xdigit")));
    TESTCASE( iswctype(L'2',  wctype("xdigit")));
    TESTCASE( iswctype(L'3',  wctype("xdigit")));
    TESTCASE( iswctype(L'4',  wctype("xdigit")));
    TESTCASE( iswctype(L'5',  wctype("xdigit")));
    TESTCASE( iswctype(L'6',  wctype("xdigit")));
    TESTCASE( iswctype(L'7',  wctype("xdigit")));
    TESTCASE( iswctype(L'8',  wctype("xdigit")));
    TESTCASE( iswctype(L'9',  wctype("xdigit")));
    TESTCASE( iswctype(L'a',  wctype("xdigit")));
    TESTCASE( iswctype(L'b',  wctype("xdigit")));
    TESTCASE( iswctype(L'c',  wctype("xdigit")));
    TESTCASE( iswctype(L'd',  wctype("xdigit")));
    TESTCASE( iswctype(L'e',  wctype("xdigit")));
    TESTCASE( iswctype(L'f',  wctype("xdigit")));
    TESTCASE( iswctype(L'A',  wctype("xdigit")));
    TESTCASE( iswctype(L'B',  wctype("xdigit")));
    TESTCASE( iswctype(L'C',  wctype("xdigit")));
    TESTCASE( iswctype(L'D',  wctype("xdigit")));
    TESTCASE( iswctype(L'E',  wctype("xdigit")));
    TESTCASE( iswctype(L'F',  wctype("xdigit")));
    TESTCASE(!iswctype(L'g',  wctype("xdigit")));
    TESTCASE(!iswctype(L'G',  wctype("xdigit")));
    TESTCASE(!iswctype(L'x',  wctype("xdigit")));
    TESTCASE(!iswctype(L'X',  wctype("xdigit")));
    TESTCASE(!iswctype(L' ',  wctype("xdigit")));

    return TEST_RESULTS;
}
Пример #23
0
void runFailure() {
    wctype(NULL);
}
Пример #24
0
int
main(int argc, char **argv)
{
	int	j;
	struct inserts *psave;
	int c;
	int	initsize;
	char	*cmdname, **initlist;
	char	*arg;
	char	*next;

	/* initialization */
	blank = wctype("blank");
	n_inserts = 0;
	psave = saveargv;
	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D 		*/
#define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't 		*/
#endif
	(void) textdomain(TEXT_DOMAIN);
	if (init_yes() < 0) {
		ermsg(_(ERR_MSG_INIT_YES), strerror(errno));
		exit(1);
	}

	parseargs(argc, argv);

	/* handling all of xargs arguments:				*/
	while ((c = getopt(mac, mav, "0tpe:E:I:i:L:l:n:s:x")) != EOF) {
		switch (c) {
		case '0':
			ZERO = TRUE;
			break;

		case 't':	/* -t: turn trace mode on		*/
			TRACE = TRUE;
			break;

		case 'p':	/* -p: turn on prompt mode.		*/
			if ((PROMPT = open("/dev/tty", O_RDONLY)) == -1) {
				PERR("can't read from tty for -p");
			} else {
				TRACE = TRUE;
			}
			break;

		case 'e':
			/*
			 * -e[eofstr]: set/disable end-of-file.
			 * N.B. that an argument *isn't* required here; but
			 * parseargs forced an argument if not was given.  The
			 * forced argument is the default...
			 */
			LEOF = optarg; /* can be empty */
			break;

		case 'E':
			/*
			 * -E eofstr: change end-of-file string.
			 * eofstr *is* required here, but can be empty:
			 */
			LEOF = optarg;
			break;

		case 'I':
			/* -I replstr: Insert mode. replstr *is* required. */
			INSERT = PER_LINE = LEGAL = TRUE;
			N_ARGS = 0;
			INSPAT = optarg;
			if (*optarg == '\0') {
				ermsg(_("Option requires an argument: -%c\n"),
				    c);
			}
			break;

		case 'i':
			/*
			 * -i [replstr]: insert mode, with *optional* replstr.
			 * N.B. that an argument *isn't* required here; if
			 * it's not given, then the string INSPAT_STR will
			 * be assumed.
			 *
			 * Since getopts(3C) doesn't handle the case of an
			 * optional variable argument at all, we have to
			 * parse this by hand:
			 */

			INSERT = PER_LINE = LEGAL = TRUE;
			N_ARGS = 0;
			if ((optarg != NULL) && (*optarg != '\0')) {
				INSPAT = optarg;
			} else {
				/*
				 * here, there is no next argument. so
				 * we reset INSPAT to the INSPAT_STR.
				 * we *have* to do this, as -i/I may have
				 * been given previously, and XCU4 requires
				 * that only "the last one specified takes
				 * effect".
				 */
				INSPAT = INSPAT_STR;
			}
			break;

		case 'L':
			/*
			 * -L number: # of times cmd is executed
			 * number *is* required here:
			 */
			PER_LINE = TRUE;
			N_ARGS = 0;
			INSERT = FALSE;
			if ((PER_LINE = atoi(optarg)) <= 0) {
				ermsg(_("#lines must be positive int: %s\n"),
				    optarg);
			}
			break;

		case 'l':
			/*
			 * -l [number]: # of times cmd is executed
			 * N.B. that an argument *isn't* required here; if
			 * it's not given, then 1 is assumed.
			 *
			 * parseargs handles the optional arg processing.
			 */

			PER_LINE = LEGAL = TRUE;  /* initialization	*/
			N_ARGS = 0;
			INSERT = FALSE;

			if ((optarg != NULL) && (*optarg != '\0')) {
				if ((PER_LINE = atoi(optarg)) <= 0)
					PER_LINE = 1;
			}
			break;

		case 'n':	/* -n number: # stdin args		*/
			/*
			 * -n number: # stdin args.
			 * number *is* required here:
			 */
			if ((N_ARGS = atoi(optarg)) <= 0) {
				ermsg(_("#args must be positive int: %s\n"),
				    optarg);
			} else {
				LEGAL = DASHX || N_ARGS == 1;
				INSERT = PER_LINE = FALSE;
			}
			break;

		case 's':	/* -s size: set max size of each arg list */
			BUFLIM = atoi(optarg);
			if (BUFLIM > BUFSIZE || BUFLIM <= 0) {
				ermsg(_("0 < max-cmd-line-size <= %d: %s\n"),
				    BUFSIZE, optarg);
			}
			break;

		case 'x':	/* -x: terminate if args > size limit	*/
			DASHX = LEGAL = TRUE;
			break;

		default:
			/*
			 * bad argument. complain and get ready to die.
			 */
			usage();
			exit(2);
			break;
		}
	}

	/*
	 * if anything called ermsg(), something screwed up, so
	 * we exit early.
	 */
	if (OK == FALSE) {
		usage();
		exit(2);
	}

	/*
	 * we're finished handling xargs's options, so now pick up
	 * the command name (if any), and it's options.
	 */


	mac -= optind;	/* dec arg count by what we've processed 	*/
	mav += optind;	/* inc to current mav				*/

	if (mac <= 0) {	/* if there're no more args to process,	*/
		cmdname = "/usr/bin/echo";	/* our default command	*/
		*ARGV++ = addarg(cmdname);	/* use the default cmd.	*/
	} else {	/* otherwise keep parsing rest of the string.	*/
		/*
		 * note that we can't use getopts(3C), and *must* parse
		 * this by hand, as we don't know apriori what options the
		 * command will take.
		 */
		cmdname = *mav;	/* get the command name	*/


		/* pick up the remaining args from the command line:	*/
		while ((OK == TRUE) && (mac-- > 0)) {
			/*
			 * while we haven't crapped out, and there's
			 * work to do:
			 */
			if (INSERT && ! ERR) {
				if (strstr(*mav, INSPAT) != NULL) {
					if (++n_inserts > MAXINSERTS) {
						ermsg(_("too many args "
						    "with %s\n"), INSPAT);
						ERR = TRUE;
					}
					psave->p_ARGV = ARGV;
					(psave++)->p_skel = *mav;
				}
			}
			*ARGV++ = addarg(*mav++);
		}
	}

	/* pick up args from standard input */

	initlist = ARGV;
	initsize = linesize;
	lastarg[0] = '\0';

	while (OK) {
		N_args = 0;
		N_lines = 0;
		ARGV = initlist;
		linesize = initsize;
		next = argbuf;

		while (MORE || (lastarg[0] != '\0')) {
			int l;

			if (*lastarg != '\0') {
				arg = strcpy(next, lastarg);
				*lastarg = '\0';
			} else if ((arg = getarg(next)) == NULL) {
				break;
			}

			l = strlen(arg) + 1;
			linesize += l;
			next += l;

			/* Inserts are handled specially later. */
			if ((n_inserts == 0) && (linesize >= BUFLIM)) {
				/*
				 * Legal indicates hard fail if the list is
				 * truncated due to size.  So fail, or if we
				 * cannot create any list because it would be
				 * too big.
				 */
				if (LEGAL || N_args == 0) {
					EMSG(LIST2LONG);
					exit(2);
					/* NOTREACHED */
				}

				/*
				 * Otherwise just save argument for later.
				 */
				(void) strcpy(lastarg, arg);
				break;
			}

			*ARGV++ = arg;

			N_args++;

			if ((PER_LINE && N_lines >= PER_LINE) ||
			    (N_ARGS && (N_args) >= N_ARGS)) {
				break;
			}


			if ((ARGV - arglist) == MAXARGS) {
				break;
			}
		}

		*ARGV = NULL;
		if (N_args == 0) {
			/* Reached the end with no more work. */
			exit(exitstat);
		}

		/* insert arg if requested */

		if (!ERR && INSERT) {

			p_ibuf = ins_buf;
			ARGV--;
			j = ibufsize = 0;
			for (psave = saveargv; ++j <= n_inserts; ++psave) {
				addibuf(psave);
				if (ERR)
					break;
			}
		}
		*ARGV = NULL;

		if (n_inserts > 0) {
			/*
			 * if we've done any insertions, re-calculate the
			 * linesize. bomb out if we've exceeded our length.
			 */
			linesize = 0;
			for (ARGV = arglist; *ARGV != NULL; ARGV++) {
				linesize += strlen(*ARGV) + 1;
			}
			if (linesize >= BUFLIM) {
				EMSG(LIST2LONG);
				exit(2);
				/* NOTREACHED */
			}
		}

		/* exec command */

		if (!ERR) {
			if (!MORE &&
			    (PER_LINE && N_lines == 0 || N_ARGS && N_args == 0))
				exit(exitstat);
			OK = TRUE;
			j = TRACE ? echoargs() : TRUE;
			if (j) {
				/*
				 * for xcu4, all invocations of cmdname must
				 * return 0, in order for us to return 0.
				 * so if we have a non-zero status here,
				 * quit immediately.
				 */
				exitstat |= lcall(cmdname, arglist);
			}
		}
	}

	if (OK)
		return (exitstat);

	/*
	 * if exitstat was set, to match XCU4 complience,
	 * return that value, otherwise, return 1.
	 */
	return (exitstat ? exitstat : 1);
}
Пример #25
0
wctype_t __wctype_l(const char* s, locale_t l) {
  return wctype(s);
}
Пример #26
0
/* TODO: all length calculations of the string must be rebuilt.
 *
 * BUG:
 *          Når jeg står på slutten av linjen så blir cursor pos
 *          justert mot venstre selv om jeg ikke sletter noe.
 *
 * */
void
prompt_str(int row, int col, const char *promptstr, wchar_t * answer)
{
	wchar_t *line = answer;

	int len, col0;

	/* struct sgttyb _tty ; */
	register int code, i, j;

	/* Converts  the promptstr to a  wide version.              */
	wchar_t *wpromptstr = mbstowcs_alloc(promptstr);

	if (wpromptstr == NULL) {
        yerror( YMBS_WCS_ERR,"prompt_str->mbstowcs_alloc", "wpromptstr", YX_EXTERNAL_CAUSE ) ;
    }

	wchar_t ch;

	/* Print the wide prompt at (row,col).                          */
	mvaddwstr(row, col, wpromptstr);

	refresh();

	/* Calc "column zero", which is at right end of prompt.     */
	col += wcslen(wpromptstr);
	col0 = col;
	mvaddwstr(row, col, answer);
    len = wcslen(answer) ;
    col += len ; 
	/* Read chars till we get what we want. Useris allowed      */
	/* basic EMACS-style line editing.                          */
	while ((code = get_wch(&ch)) != EOF) {
		switch (ch) {
		case CTRL('a'):	/* beginning of line            */
			col = col0;
			break;
		case KEY_LEFT:
		case CTRL('b'):	/* back character               */
			if (col > col0)
				col--;
			break;
		case CTRL('d'):	/* delete character             */
			/*
			 * If there's stuff in the string,
			 * delete this character.
			 */
			if (col == (col0 + (int)wcslen(line))) {
				col--;
			} else if (len) {
				/* Calc string pos of char to delete.           */
				i = col - col0;

				/* Shuffle the string "left" one place.         */
				while (i < len) {
					line[i] = line[i + 1];
					i++;
				}

				/* Delete char on the screen.                   */
				len -= 1;
				delch();	/* prob ok that isn't wide. */
                if (col== (col0 + (int)wcslen(line)) ) {
                    --col ;
                }
			}

			break;
		case CTRL('e'):	/* end of line                  */
			col = col0 + len;
			break;
		case KEY_RIGHT:
		case CTRL('f'):	/* forward character            */
			if ((col - col0) < len)
				col++;
			break;
		case KEY_BACKSPACE:
		case CTRL('h'):	/* backspace delete */
		case '\177':
			/* If stuff in the string, delete char.             */
			if (len && ((col - 1) >= col0)) {
				/* Calc pos in string of char to delete         */
				int l = col - col0 - 1;
				if (l < 0)
					break;
				/* Shuffle the string "left" one place.         */
				while (l < len) {
					line[l] = line[l + 1];
					l++;
				}

				len -= 1;
				/* Delete the character on the screen.          */
				move(row, --col);
				delch();
			}
			break;
		case CTRL('k'):	/* kill line                    */
			/* Clear the string.                                */
			if (len) {
				i = col - col0;

				line[i] = '\0';
				len = i;

				clrtoeol();
			}
			break;
		case CTRL('l'):	/* redraw screen                */
			wrefresh(curscr);
			break;
		case KEY_ENTER:
		case '\r':	/* return the string            */
		case '\n':	/* return the string            */
			line[len] = '\0';
			return;
		default:	/* regular character            */
			if (ch == KEY_DL) {
				move(row, col0);
				clrtoeol();
				col = col0;

				*line = '\0';
				len = 0;
			} else if (code != KEY_CODE_YES) {
				if (iswctype(ch, wctype("print"))) {
					if (col == (COLS - 1)) {
						beep();
						break;
					}
					/* Calculate position of char in string.    */
					i = col - col0;

					/* If we have to, move string "right" one   */
					/* place to insert the character.           */
					if (i < len) {
						for (j = len; j >= i; j--)
							line[j + 1] = line[j];
					}
					line[i] = ch;
					len += 1;
					col++;

					/* Insert the character on the screen.      */
					InsWch((chtype) ch);
					/* ins_wch(&ch); */
				}
			}
			break;
		}

		/* Move the cursor.                                     */
		move(row, col);
		refresh();
	}
}
Пример #27
0
static int
do_test (void)
{
  wctype_t wct;
  wchar_t buf[1000];
  int result = 1;

  setlocale (LC_ALL, "");
  wprintf (L"locale = %s\n", setlocale (LC_CTYPE, NULL));

  wct = wctype ("jhira");
  if (wct == 0)
    error (EXIT_FAILURE, 0, "jhira: no such character class");

  if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
    {
      int n;

      wprintf (L"buf[] = \"%ls\"\n", buf);

      result = 0;

      for (n = 0; buf[n] != L'\0'; ++n)
	{
	  wprintf (L"jhira(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
		   iswctype (buf[n], wct));
	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
	}
    }

  wct = wctype ("jkata");
  if (wct == 0)
    error (EXIT_FAILURE, 0, "jkata: no such character class");

  if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
    {
      int n;

      wprintf (L"buf[] = \"%ls\"\n", buf);

      result = 0;

      for (n = 0; buf[n] != L'\0'; ++n)
	{
	  wprintf (L"jkata(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
		   iswctype (buf[n], wct));
	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
	}
    }

  wct = wctype ("jdigit");
  if (wct == 0)
    error (EXIT_FAILURE, 0, "jdigit: no such character class");

  if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
    {
      int n;

      wprintf (L"buf[] = \"%ls\"\n", buf);

      result = 0;

      for (n = 0; buf[n] != L'\0'; ++n)
	{
	  wprintf (L"jdigit(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
		   iswctype (buf[n], wct));
	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
	}
    }

  wct = wctype ("jspace");
  if (wct == 0)
    error (EXIT_FAILURE, 0, "jspace: no such character class");

  if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
    {
      int n;

      wprintf (L"buf[] = \"%ls\"\n", buf);

      result = 0;

      for (n = 0; buf[n] != L'\0'; ++n)
	{
	  wprintf (L"jspace(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
		   iswctype (buf[n], wct));
	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
	}
    }

  wct = wctype ("jkanji");
  if (wct == 0)
    error (EXIT_FAILURE, 0, "jkanji: no such character class");

  if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
    {
      int n;

      wprintf (L"buf[] = \"%ls\"\n", buf);

      result = 0;

      for (n = 0; buf[n] != L'\0'; ++n)
	{
	  wprintf (L"jkanji(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
		   iswctype (buf[n], wct));
	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
	}
    }

  return result;
}
Пример #28
0
int main( void )
{
    TESTCASE(wctype("")   == 0);
    TESTCASE_NOREG(wctype(NULL) == 0); // mingw libc crashes on this

    TESTCASE(wctype("alpha")  != 0);
    TESTCASE(wctype("alnum")  != 0);
    TESTCASE(wctype("blank")  != 0);
    TESTCASE(wctype("cntrl")  != 0);
    TESTCASE(wctype("digit")  != 0);
    TESTCASE(wctype("graph")  != 0);
    TESTCASE(wctype("lower")  != 0);
    TESTCASE(wctype("print")  != 0);
    TESTCASE(wctype("punct")  != 0);
    TESTCASE(wctype("space")  != 0);
    TESTCASE(wctype("upper")  != 0);
    TESTCASE(wctype("xdigit") != 0);

    TESTCASE_NOREG(wctype("alpha")  == _PDCLIB_CTYPE_ALPHA);
    TESTCASE_NOREG(wctype("alnum")  == (_PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_DIGIT));
    TESTCASE_NOREG(wctype("blank")  == _PDCLIB_CTYPE_BLANK);
    TESTCASE_NOREG(wctype("cntrl")  == _PDCLIB_CTYPE_CNTRL);
    TESTCASE_NOREG(wctype("digit")  == _PDCLIB_CTYPE_DIGIT);
    TESTCASE_NOREG(wctype("graph")  == _PDCLIB_CTYPE_GRAPH);
    TESTCASE_NOREG(wctype("lower")  == _PDCLIB_CTYPE_LOWER);
    TESTCASE_NOREG(wctype("print")  == (_PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_SPACE));
    TESTCASE_NOREG(wctype("punct")  == _PDCLIB_CTYPE_PUNCT);
    TESTCASE_NOREG(wctype("space")  == _PDCLIB_CTYPE_SPACE);
    TESTCASE_NOREG(wctype("upper")  == _PDCLIB_CTYPE_UPPER);
    TESTCASE_NOREG(wctype("xdigit") == _PDCLIB_CTYPE_XDIGT);
    return TEST_RESULTS;
}
Пример #29
0
int
iswblank (wint_t wc)
{
    return iswctype(wc, wctype("blank"));
}
Пример #30
0
int
main (int argc, char *argv[])
{
  int result = 0;
  wctype_t bit_alnum = wctype ("alnum");
  wctype_t bit_alpha = wctype ("alpha");
  wctype_t bit_cntrl = wctype ("cntrl");
  wctype_t bit_digit = wctype ("digit");
  wctype_t bit_graph = wctype ("graph");
  wctype_t bit_lower = wctype ("lower");
  wctype_t bit_print = wctype ("print");
  wctype_t bit_punct = wctype ("punct");
  wctype_t bit_space = wctype ("space");
  wctype_t bit_upper = wctype ("upper");
  wctype_t bit_xdigit = wctype ("xdigit");
  int ch;

  if (wctype ("does not exist") != 0)
    {
      puts ("wctype return value != 0 for non existing property");
      result = 1;
    }

  for (ch = 0; ch < 256; ++ch)
    {
#define TEST(test) \
      do								      \
	{								      \
	  if ((is##test (ch) == 0) != (iswctype (ch, bit_##test) == 0))	      \
	    {								      \
	      printf ("`iswctype' class `%s' test "			      \
		      "for character \\%o failed\n", #test, ch);	      \
	      result = 1;						      \
	    }								      \
	  if ((is##test (ch) == 0) != (isw##test (ch) == 0))		      \
	    {								      \
	      printf ("`isw%s' test for character \\%o failed\n",	      \
		      #test, ch);					      \
	      result = 1;						      \
	    }								      \
	 }								      \
      while (0)

      TEST (alnum);
      TEST (alpha);
      TEST (cntrl);
      TEST (digit);
      TEST (graph);
      TEST (lower);
      TEST (print);
      TEST (punct);
      TEST (space);
      TEST (upper);
      TEST (xdigit);
    }

  if (result == 0)
    puts ("All test successful!");
  return result;
}