Example #1
0
/*
 *  stress_wcscoll()
 *	stress on wcscoll
 */
static void stress_wcscoll(
    const char *name,
    wchar_t *str1,
    const size_t len1,
    wchar_t *str2,
    const size_t len2)
{
    register size_t i;

    (void)len2;

    for (i = 1; i < len1; i++) {
        WCSCHK(name, 0 == wcscoll(str1, str1));
        WCSCHK(name, 0 == wcscoll(str2, str2));

        WCSCHK(name, 0 != wcscoll(str2, str1));
        WCSCHK(name, 0 != wcscoll(str1, str2));

        WCSCHK(name, 0 != wcscoll(str1 + i, str1));
        WCSCHK(name, 0 != wcscoll(str1, str1 + i));
        WCSCHK(name, 0 == wcscoll(str1 + i, str1 + i));

        WCSCHK(name, 0 != wcscoll(str1 + i, str2));
        WCSCHK(name, 0 != wcscoll(str2, str1 + i));
    }
}
Example #2
0
/*
 * Compare two wide-character strings
 */
static int
wide_str_coll(const wchar_t *s1, const wchar_t *s2)
{
	int ret = 0;

	errno = 0;
	ret = wcscoll(s1, s2);
	if (errno == EILSEQ) {
		errno = 0;
		ret = wcscmp(s1, s2);
		if (errno != 0) {
			for (size_t i = 0; ; ++i) {
				wchar_t c1 = s1[i];
				wchar_t c2 = s2[i];
				if (c1 == L'\0')
					return ((c2 == L'\0') ? 0 : -1);
				if (c2 == L'\0')
					return (+1);
				if (c1 == c2)
					continue;
				return ((int)(c1 - c2));
			}
		}
	}
	return (ret);
}
Example #3
0
int word_list_add(struct word_list *list, const wchar_t *word) {
    struct word_list *l2 = list;
    struct word_list *flunkey;
    struct word_list *new_word_list;
    int compare;
    flunkey = list;
    l2 = list->next;
    while (l2 != NULL) {
        compare = wcscoll(l2->word, word);
        if (compare < 0) {
            l2 = l2->next;
            flunkey = flunkey->next;
        }
        else if (compare > 0) {
            new_word_list = malloc(sizeof(word_list));
            wcscpy(new_word_list->word, word);
            new_word_list->next = l2;
            flunkey->next = new_word_list;
            return 1;
        }
        else {
            return 0;
        }
    }
    new_word_list = malloc(sizeof(word_list));
    wcscpy(new_word_list->word, word);
    new_word_list->next = NULL;
    flunkey->next = new_word_list;
    return 1;
}
Example #4
0
static TACommandVerdict wcscoll_cmd(TAThread thread, TAInputStream stream)
{
    wchar_t* ws1;
    wchar_t* ws2;
    int res;
    int save_errno;

    // Prepare
    ws1 = ta_wcsalign(readWString(&stream)); //align on copy
    ws2 = ta_wcsalign(readWString(&stream)); //align on copy

    START_TARGET_OPERATION(thread);

    // Execute
    errno = 0;
    res = wcscoll(ws1, ws2);
    save_errno = errno;

    END_TARGET_OPERATION(thread);

    // Response
    writeInt(thread, res);
    writeInt(thread, save_errno);

    sendResponse(thread);
    
    ta_dealloc_memory(ws1);
    ta_dealloc_memory(ws2);

    return taDefaultVerdict;
}
Example #5
0
static int
collate_range_cmp(wchar_t c1, wchar_t c2)
{
	static wchar_t s1[2], s2[2];

	s1[0] = c1;
	s2[0] = c2;
	return (wcscoll(s1, s2));
}
int CUnicodeString::Collate(LPCSTR lpsz)
{
	ASSERT(IsValidString(lpsz));
	DWORD dwszLen = strlen(lpsz);
	LPWSTR lpwsz = (LPWSTR)malloc((dwszLen + 1) * sizeof(WCHAR));
	lpwsz[dwszLen] = L'\0';
	MultiByteToWideChar(CP_ACP, 0, lpsz, dwszLen, lpwsz, dwszLen);
	int iRet = wcscoll(m_Buffer, lpwsz);
	free(lpwsz);
	return iRet;
}
Example #7
0
int
wcsicoll(const wchar_t *s1, const wchar_t *s2)
{
	wchar_t *p, line1[MAXLINELEN], line2[MAXLINELEN];

	for (p = line1; *s1; s1++)
		*p++ = towlower(*s1);
	*p = '\0';
	for (p = line2; *s2; s2++)
		*p++ = towlower(*s2);
	*p = '\0';
	return (wcscoll(line1, line2));
}
Example #8
0
int
globcharcoll(__Char c1, __Char c2, int cs)
{
#if defined(NLS) && defined(LC_COLLATE) && defined(HAVE_STRCOLL)
# if defined(WIDE_STRINGS)
    wchar_t s1[2], s2[2];

    if (c1 == c2)
	return (0);
    if (cs) {
	c1 = towlower(c1);
	c2 = towlower(c2);
    } else {
	/* This should not be here, but I'll rather leave it in than engage in
	   a LC_COLLATE flamewar about a shell I don't use... */
	if (iswlower(c1) && iswupper(c2))
	    return (1);
	if (iswupper(c1) && iswlower(c2))
	    return (-1);
    }
    s1[0] = c1;
    s2[0] = c2;
    s1[1] = s2[1] = '\0';
    return wcscoll(s1, s2);
# else /* not WIDE_STRINGS */
    char s1[2], s2[2];

    if (c1 == c2)
	return (0);
    /*
     * From kevin lyda <*****@*****.**>:
     * strcoll does not guarantee case sorting, so we pre-process now:
     */
    if (cs) {
	c1 = islower(c1) ? c1 : tolower(c1);
	c2 = islower(c2) ? c2 : tolower(c2);
    } else {
	if (islower(c1) && isupper(c2))
	    return (1);
	if (isupper(c1) && islower(c2))
	    return (-1);
    }
    s1[0] = c1;
    s2[0] = c2;
    s1[1] = s2[1] = '\0';
    return strcoll(s1, s2);
# endif
#else
    return (c1 - c2);
#endif
}
Example #9
0
static int
int_mbscoll(const char *s1, const char *s2, int icase)
{ size_t l1 = strlen(s1);
  size_t l2 = strlen(s2);
  wchar_t *w1;
  wchar_t *w2;
  int ml1, ml2;
  mbstate_t mbs;
  int rc;

#if HAVE_ALLOCA
  if ( l1 < 1024 && (w1 = alloca(sizeof(wchar_t)*(l1+1))) )
  { ml1 = FALSE;
  } else
#endif
  { w1 = PL_malloc_atomic(sizeof(wchar_t)*(l1+1));
    ml1 = TRUE;
  }
#if HAVE_ALLOCA
  if ( l2 < 1024 && (w2 = alloca(sizeof(wchar_t)*(l2+1))) )
  { ml2 = FALSE;
  } else
#endif
  { w2 = PL_malloc_atomic(sizeof(wchar_t)*(l2+1));
    ml2 = TRUE;
  }

  memset(&mbs, 0, sizeof(mbs));
  if ( mbsrtowcs(w1, &s1, l1+1, &mbs) == (size_t)-1 )
  { rc = -2;
    goto out;
  }
  if ( mbsrtowcs(w2, &s2, l2+1, &mbs) == (size_t)-1 )
  { rc = 2;
    goto out;
  }
  if ( icase )
  { wstolower(w1, l1);
    wstolower(w2, l2);
  }

  rc = wcscoll(w1, w2);

out:
  if ( ml1 ) PL_free(w1);
  if ( ml2 ) PL_free(w2);

  return rc;
}
Example #10
0
static int
mbscoll(const char *s1, const char *s2)
{
	wchar_t *w1, *w2;
	int ret;

	if (MB_CUR_MAX == 1)
		return (strcoll(s1, s2));
	if ((w1 = towcs(s1)) == NULL || (w2 = towcs(s2)) == NULL)
		err(1, NULL);	/* XXX */
	ret = wcscoll(w1, w2);
	free(w1);
	free(w2);
	return (ret);
}
Example #11
0
static int32_t
collate_range_cmp(char32_t c1, char32_t c2)
{
    typedef union _nulltermchar {
        uint64_t	force8;
        char32_t	char32[2];
        wchar_t		wchar[sizeof(uint64_t)/sizeof(wchar_t)];
    } _nulltermchar_t;

    _nulltermchar_t s1;
    _nulltermchar_t s2;
    s1.force8 = c1;
    s2.force8 = c2;

    return (wcscoll(s1.wchar, s2.wchar));
}
Example #12
0
File: main.c Project: kmieszala/C
void *wstaw_wierzcholek(struct wierzcholek *w,wchar_t *s){
  int wynik_porownania;
  if (w==NULL){
    
  
    w=nowy_wierzcholek(s);
  }
  else if((wynik_porownania = wcscoll(s,w->slowo)==0)){
      w->liczba_wystapien++;
    }
    else if(wynik_porownania<0){
	w->lewe_poddrzewo = wstaw_wierzcholek(w->lewe_poddrzewo,s);
      }
      else{
	w->prawe_poddrzewo = wstaw_wierzcholek(w->prawe_poddrzewo,s);
      }
  
      return w;
  
}
Example #13
0
int main()
{
    wchar_t *samples[ ] = { L"anejo", L"añeja",};

    setlocale( LC_COLLATE, "es_US.UTF-8" );
    
    int result = wcscoll( samples[0], samples[1] );

    wprintf( L"In the locale %s, ", setlocale( LC_COLLATE, NULL ));

    if ( result == 0 )
        wprintf( L"the wide strings \"%ls\" and \"%ls\" are alphabetically "
                 "equivalent.\n", samples[0], samples[1] );
    else if ( result < 0 )
        wprintf( L"the wide string \"%ls\" precedes \"%ls\" "
                 "alphabetically.\n", samples[0], samples[1] );
    else if ( result > 0 )
        wprintf( L"the wide string \"%ls\" comes after \"%ls\" "
                 "alphabetically.\n", samples[0], samples[1] );
    return 0;
}
Example #14
0
static PyObject*
PyLocale_strcoll(PyObject* self, PyObject* args)
{
    PyObject *os1, *os2, *result = NULL;
    wchar_t *ws1 = NULL, *ws2 = NULL;

    if (!PyArg_ParseTuple(args, "UU:strcoll", &os1, &os2))
        return NULL;
    /* Convert the unicode strings to wchar[]. */
    ws1 = PyUnicode_AsWideCharString(os1, NULL);
    if (ws1 == NULL)
        goto done;
    ws2 = PyUnicode_AsWideCharString(os2, NULL);
    if (ws2 == NULL)
        goto done;
    /* Collate the strings. */
    result = PyLong_FromLong(wcscoll(ws1, ws2));
  done:
    /* Deallocate everything. */
    if (ws1) PyMem_FREE(ws1);
    if (ws2) PyMem_FREE(ws2);
    return result;
}
static PyObject*
PyLocale_strcoll(PyObject* self, PyObject* args)
{
    PyObject *os1, *os2, *result = NULL;
    wchar_t *ws1 = NULL, *ws2 = NULL;
    Py_ssize_t len1, len2;
    
    if (!PyArg_ParseTuple(args, "UU:strcoll", &os1, &os2))
        return NULL;
    /* Convert the unicode strings to wchar[]. */
    len1 = PyUnicode_GET_SIZE(os1) + 1;
    ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
    if (!ws1) {
        PyErr_NoMemory();
        goto done;
    }
    if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)
        goto done;
    ws1[len1 - 1] = 0;
    len2 = PyUnicode_GET_SIZE(os2) + 1;
    ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t));
    if (!ws2) {
        PyErr_NoMemory();
        goto done;
    }
    if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)
        goto done;
    ws2[len2 - 1] = 0;
    /* Collate the strings. */
    result = PyLong_FromLong(wcscoll(ws1, ws2));
  done:
    /* Deallocate everything. */
    if (ws1) PyMem_FREE(ws1);
    if (ws2) PyMem_FREE(ws2);
    return result;
}
Example #16
0
gcc_pure gcc_nonnull_all
static inline int
StringCollate(const wchar_t *a, const wchar_t *b)
{
  return wcscoll(a, b);
}
int CCOMStringW::Collate(CCOMStringW &str) const
{
	ATLASSERT((const WCHAR* ) str != NULL);
	ATLASSERT(::IsBadStringPtrW((const WCHAR* ) str, -1) == 0);
	return wcscoll(m_pszString, (const WCHAR* ) str);	
}
Example #18
0
int CUnicodeString::Collate(LPCWSTR lpsz)
{
	ASSERT(IsValidString(lpsz));
	return wcscoll(m_Buffer, lpsz);
}
int CCOMStringW::Collate(const WCHAR*  lpsz) const
{
	ATLASSERT(lpsz != NULL);
	ATLASSERT(::IsBadStringPtrW(lpsz, -1) == 0);
	return wcscoll(m_pszString, lpsz);	
}
Example #20
0
int __wcscoll_l(const wchar_t *l, const wchar_t *r, locale_t locale)
{
    return wcscoll(l, r);
}
Example #21
0
/**
 Testuje dictionary_hints_word_without_ignores
 @param[in,out] state Środowisko
 */
static void dictionary_hints_word_without_ignores_test(void **state)
{
	(void)state;
	assert_int_equal(wcscoll(L"abc", dictionary_hints_word_without_ignores(L"^a^b^c^")), 0);
	assert_int_equal(wcscoll(L"", dictionary_hints_word_without_ignores(L"^^^")), 0);
}
Example #22
0
int
main(int argc, char *argv[])
{
	int comp, file1done = 0, file2done = 0, read1, read2;
	int ch, flag1, flag2, flag3, iflag;
	FILE *fp1, *fp2;
	const wchar_t *col1, *col2, *col3;
	wchar_t line1[MAXLINELEN], line2[MAXLINELEN];
	const wchar_t **p;

	flag1 = flag2 = flag3 = 1;
	iflag = 0;

	(void) setlocale(LC_ALL, "");

	while ((ch = getopt(argc, argv, "123i")) != -1)
		switch(ch) {
		case '1':
			flag1 = 0;
			break;
		case '2':
			flag2 = 0;
			break;
		case '3':
			flag3 = 0;
			break;
		case 'i':
			iflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 2 || !argv[0] || !argv[1])
		usage();

	fp1 = file(argv[0]);
	fp2 = file(argv[1]);

	/* for each column printed, add another tab offset */
	p = tabs;
	col1 = col2 = col3 = NULL;
	if (flag1)
		col1 = *p++;
	if (flag2)
		col2 = *p++;
	if (flag3)
		col3 = *p;

	for (read1 = read2 = 1;;) {
		/* read next line, check for EOF */
		if (read1) {
			file1done = !fgetws(line1, MAXLINELEN, fp1);
			if (file1done && ferror(fp1))
				err(1, "%s", argv[0]);
		}
		if (read2) {
			file2done = !fgetws(line2, MAXLINELEN, fp2);
			if (file2done && ferror(fp2))
				err(1, "%s", argv[1]);
		}

		/* if one file done, display the rest of the other file */
		if (file1done) {
			if (!file2done && col2)
				show(fp2, argv[1], col2, line2);
			break;
		}
		if (file2done) {
			if (!file1done && col1)
				show(fp1, argv[0], col1, line1);
			break;
		}

		/* lines are the same */
		if(iflag)
			comp = wcsicoll(line1, line2);
		else
			comp = wcscoll(line1, line2);

		if (!comp) {
			read1 = read2 = 1;
			if (col3)
				(void)printf("%ls%ls", col3, line1);
			continue;
		}

		/* lines are different */
		if (comp < 0) {
			read1 = 1;
			read2 = 0;
			if (col1)
				(void)printf("%ls%ls", col1, line1);
		} else {
			read1 = 0;
			read2 = 1;
			if (col2)
				(void)printf("%ls%ls", col2, line2);
		}
	}
	exit(0);
}
Example #23
0
static PyObject*
PyLocale_strcoll(PyObject* self, PyObject* args)
{
#if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)
    char *s1,*s2;
    
    if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
        return NULL;
    return PyInt_FromLong(strcoll(s1, s2));
#else
    PyObject *os1, *os2, *result = NULL;
    wchar_t *ws1 = NULL, *ws2 = NULL;
    int rel1 = 0, rel2 = 0, len1, len2;
    
    if (!PyArg_ParseTuple(args, "OO:strcoll", &os1, &os2))
        return NULL;
    /* If both arguments are byte strings, use strcoll.  */
    if (PyString_Check(os1) && PyString_Check(os2))
        return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
                                      PyString_AS_STRING(os2)));
    /* If neither argument is unicode, it's an error.  */
    if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
        PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
    }
    /* Convert the non-unicode argument to unicode. */
    if (!PyUnicode_Check(os1)) {
        os1 = PyUnicode_FromObject(os1);
        if (!os1)
            return NULL;
        rel1 = 1;
    }
    if (!PyUnicode_Check(os2)) {
        os2 = PyUnicode_FromObject(os2);
        if (!os2) {
            Py_DECREF(os1);
            return NULL;
        } 
        rel2 = 1;
    }
    /* Convert the unicode strings to wchar[]. */
    len1 = PyUnicode_GET_SIZE(os1) + 1;
    ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
    if (!ws1) {
        PyErr_NoMemory();
        goto done;
    }
    if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)
        goto done;
    ws1[len1 - 1] = 0;
    len2 = PyUnicode_GET_SIZE(os2) + 1;
    ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t));
    if (!ws2) {
        PyErr_NoMemory();
        goto done;
    }
    if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)
        goto done;
    ws2[len2 - 1] = 0;
    /* Collate the strings. */
    result = PyInt_FromLong(wcscoll(ws1, ws2));
  done:
    /* Deallocate everything. */
    if (ws1) PyMem_FREE(ws1);
    if (ws2) PyMem_FREE(ws2);
    if (rel1) {
        Py_DECREF(os1);
    }
    if (rel2) {
        Py_DECREF(os2);
    }
    return result;
#endif
}
Example #24
0
int
main(int argc, char *argv[])
{
	int comp, read1, read2;
	int ch, flag1, flag2, flag3;
	FILE *fp1, *fp2;
	const char *col1, *col2, *col3;
	size_t line1len, line2len;
	char *line1, *line2;
	ssize_t n1, n2;
	wchar_t *tline1, *tline2;
	const char **p;

	(void) setlocale(LC_ALL, "");

	flag1 = flag2 = flag3 = 1;

	while ((ch = getopt(argc, argv, "123i")) != -1)
		switch(ch) {
		case '1':
			flag1 = 0;
			break;
		case '2':
			flag2 = 0;
			break;
		case '3':
			flag3 = 0;
			break;
		case 'i':
			iflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 2)
		usage();

	fp1 = file(argv[0]);
	fp2 = file(argv[1]);

	/* for each column printed, add another tab offset */
	p = tabs;
	col1 = col2 = col3 = NULL;
	if (flag1)
		col1 = *p++;
	if (flag2)
		col2 = *p++;
	if (flag3)
		col3 = *p;

	line1len = line2len = 0;
	line1 = line2 = NULL;
	n1 = n2 = -1;

	for (read1 = read2 = 1;;) {
		/* read next line, check for EOF */
		if (read1) {
			n1 = getline(&line1, &line1len, fp1);
			if (n1 < 0 && ferror(fp1))
				err(1, "%s", argv[0]);
			if (n1 > 0 && line1[n1 - 1] == '\n')
				line1[n1 - 1] = '\0';

		}
		if (read2) {
			n2 = getline(&line2, &line2len, fp2);
			if (n2 < 0 && ferror(fp2))
				err(1, "%s", argv[1]);
			if (n2 > 0 && line2[n2 - 1] == '\n')
				line2[n2 - 1] = '\0';
		}

		/* if one file done, display the rest of the other file */
		if (n1 < 0) {
			if (n2 >= 0 && col2 != NULL)
				show(fp2, argv[1], col2, &line2, &line2len);
			break;
		}
		if (n2 < 0) {
			if (n1 >= 0 && col1 != NULL)
				show(fp1, argv[0], col1, &line1, &line1len);
			break;
		}

		tline2 = NULL;
		if ((tline1 = convert(line1)) != NULL)
			tline2 = convert(line2);
		if (tline1 == NULL || tline2 == NULL)
			comp = strcmp(line1, line2);
		else
			comp = wcscoll(tline1, tline2);
		if (tline1 != NULL)
			free(tline1);
		if (tline2 != NULL)
			free(tline2);

		/* lines are the same */
		if (!comp) {
			read1 = read2 = 1;
			if (col3 != NULL)
				(void)printf("%s%s\n", col3, line1);
			continue;
		}

		/* lines are different */
		if (comp < 0) {
			read1 = 1;
			read2 = 0;
			if (col1 != NULL)
				(void)printf("%s%s\n", col1, line1);
		} else {
			read1 = 0;
			read2 = 1;
			if (col2 != NULL)
				(void)printf("%s%s\n", col2, line2);
		}
	}
	exit(0);
}
Example #25
0
/**
 * Porównuje dwa stringi wchar_t zgodnie z zadanymi locale.
 * @return true wtw. argumenty są uporządkowane.
 * @param [in] l Pierwsza wartość.
 * @param [in] r Druga wartość.
 */
static
bool are_ordered(const wchar_t * const l, const wchar_t * const r)
{
    return wcscoll(l, r) <= 0;
}
Example #26
0
int
main (int argc, char *argv[])
{
	wchar_t *tprev, *tthis;
	FILE *ifp, *ofp;
	int ch, comp;
	size_t prevbuflen, thisbuflen, b1;
	char *prevline, *thisline, *p;
	const char *ifn;
	cap_rights_t rights;

	(void) setlocale(LC_ALL, "");

	obsolete(argv);
	while ((ch = getopt(argc, argv, "cdif:s:u")) != -1)
		switch (ch) {
		case 'c':
			cflag = 1;
			break;
		case 'd':
			dflag = 1;
			break;
		case 'i':
			iflag = 1;
			break;
		case 'f':
			numfields = strtol(optarg, &p, 10);
			if (numfields < 0 || *p)
				errx(1, "illegal field skip value: %s", optarg);
			break;
		case 's':
			numchars = strtol(optarg, &p, 10);
			if (numchars < 0 || *p)
				errx(1, "illegal character skip value: %s", optarg);
			break;
		case 'u':
			uflag = 1;
			break;
		case '?':
		default:
			usage();
		}

	argc -= optind;
	argv += optind;

	/* If no flags are set, default is -d -u. */
	if (cflag) {
		if (dflag || uflag)
			usage();
	} else if (!dflag && !uflag)
		dflag = uflag = 1;

	if (argc > 2)
		usage();

	ifp = stdin;
	ifn = "stdin";
	ofp = stdout;
	if (argc > 0 && strcmp(argv[0], "-") != 0)
		ifp = file(ifn = argv[0], "r");
	cap_rights_init(&rights, CAP_FSTAT, CAP_READ);
	if (cap_rights_limit(fileno(ifp), &rights) < 0 && errno != ENOSYS)
		err(1, "unable to limit rights for %s", ifn);
	cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE);
	if (argc > 1)
		ofp = file(argv[1], "w");
	else
		cap_rights_set(&rights, CAP_IOCTL);
	if (cap_rights_limit(fileno(ofp), &rights) < 0 && errno != ENOSYS) {
		err(1, "unable to limit rights for %s",
		    argc > 1 ? argv[1] : "stdout");
	}
	if (cap_rights_is_set(&rights, CAP_IOCTL)) {
		unsigned long cmd;

		cmd = TIOCGETA; /* required by isatty(3) in printf(3) */

		if (cap_ioctls_limit(fileno(ofp), &cmd, 1) < 0 &&
		    errno != ENOSYS) {
			err(1, "unable to limit ioctls for %s",
			    argc > 1 ? argv[1] : "stdout");
		}
	}

	strerror_init();
	if (cap_enter() < 0 && errno != ENOSYS)
		err(1, "unable to enter capability mode");

	prevbuflen = thisbuflen = 0;
	prevline = thisline = NULL;

	if (getline(&prevline, &prevbuflen, ifp) < 0) {
		if (ferror(ifp))
			err(1, "%s", ifn);
		exit(0);
	}
	tprev = convert(prevline);

	if (!cflag && uflag && dflag)
		show(ofp, prevline);

	tthis = NULL;
	while (getline(&thisline, &thisbuflen, ifp) >= 0) {
		if (tthis != NULL)
			free(tthis);
		tthis = convert(thisline);

		if (tthis == NULL && tprev == NULL)
			comp = inlcmp(thisline, prevline);
		else if (tthis == NULL || tprev == NULL)
			comp = 1;
		else
			comp = wcscoll(tthis, tprev);

		if (comp) {
			/* If different, print; set previous to new value. */
			if (cflag || !dflag || !uflag)
				show(ofp, prevline);
			p = prevline;
			b1 = prevbuflen;
			prevline = thisline;
			prevbuflen = thisbuflen;
			if (tprev != NULL)
				free(tprev);
			tprev = tthis;
			if (!cflag && uflag && dflag)
				show(ofp, prevline);
			thisline = p;
			thisbuflen = b1;
			tthis = NULL;
			repeats = 0;
		} else
			++repeats;
	}
	if (ferror(ifp))
		err(1, "%s", ifn);
	if (cflag || !dflag || !uflag)
		show(ofp, prevline);
	exit(0);
}
Example #27
0
File: eval.c Project: gvlx/gawk
static int
posix_compare(NODE *s1, NODE *s2)
{
    int ret = 0;
    char save1, save2;
    size_t l = 0;

    save1 = s1->stptr[s1->stlen];
    s1->stptr[s1->stlen] = '\0';

    save2 = s2->stptr[s2->stlen];
    s2->stptr[s2->stlen] = '\0';

    if (gawk_mb_cur_max == 1) {
        if (strlen(s1->stptr) == s1->stlen && strlen(s2->stptr) == s2->stlen)
            ret = strcoll(s1->stptr, s2->stptr);
        else {
            char b1[2], b2[2];
            char *p1, *p2;
            size_t i;

            if (s1->stlen < s2->stlen)
                l = s1->stlen;
            else
                l = s2->stlen;

            b1[1] = b2[1] = '\0';
            for (i = ret = 0, p1 = s1->stptr, p2 = s2->stptr;
                    ret == 0 && i < l;
                    p1++, p2++) {
                b1[0] = *p1;
                b2[0] = *p2;
                ret = strcoll(b1, b2);
            }
        }
        /*
         * Either worked through the strings or ret != 0.
         * In either case, ret will be the right thing to return.
         */
    }
#if MBS_SUPPORT
    else {
        /* Similar logic, using wide characters */
        (void) force_wstring(s1);
        (void) force_wstring(s2);

        if (wcslen(s1->wstptr) == s1->wstlen && wcslen(s2->wstptr) == s2->wstlen)
            ret = wcscoll(s1->wstptr, s2->wstptr);
        else {
            wchar_t b1[2], b2[2];
            wchar_t *p1, *p2;
            size_t i;

            if (s1->wstlen < s2->wstlen)
                l = s1->wstlen;
            else
                l = s2->wstlen;

            b1[1] = b2[1] = L'\0';
            for (i = ret = 0, p1 = s1->wstptr, p2 = s2->wstptr;
                    ret == 0 && i < l;
                    p1++, p2++) {
                b1[0] = *p1;
                b2[0] = *p2;
                ret = wcscoll(b1, b2);
            }
        }
        /*
         * Either worked through the strings or ret != 0.
         * In either case, ret will be the right thing to return.
         */
    }
#endif

    s1->stptr[s1->stlen] = save1;
    s2->stptr[s2->stlen] = save2;
    return ret;
}
Example #28
0
int main()
{
    mbstate_t mb = {0};
    size_t s = 0;
    tm tm = {0};
    wint_t w = 0;
    ::FILE* fp = 0;
    __darwin_va_list va;
    char* ns = 0;
    wchar_t* ws = 0;
    static_assert((std::is_same<decltype(fwprintf(fp, L"")), int>::value), "");
    static_assert((std::is_same<decltype(fwscanf(fp, L"")), int>::value), "");
    static_assert((std::is_same<decltype(swprintf(ws, s, L"")), int>::value), "");
    static_assert((std::is_same<decltype(swscanf(L"", L"")), int>::value), "");
    static_assert((std::is_same<decltype(vfwprintf(fp, L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vfwscanf(fp, L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vswprintf(ws, s, L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vswscanf(L"", L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vwprintf(L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vwscanf(L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(wprintf(L"")), int>::value), "");
    static_assert((std::is_same<decltype(wscanf(L"")), int>::value), "");
    static_assert((std::is_same<decltype(fgetwc(fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(fgetws(ws, 0, fp)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(fputwc(L' ', fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(fputws(L"", fp)), int>::value), "");
    static_assert((std::is_same<decltype(fwide(fp, 0)), int>::value), "");
    static_assert((std::is_same<decltype(getwc(fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(getwchar()), wint_t>::value), "");
    static_assert((std::is_same<decltype(putwc(L' ', fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(putwchar(L' ')), wint_t>::value), "");
    static_assert((std::is_same<decltype(ungetwc(L' ', fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(wcstod(L"", (wchar_t**)0)), double>::value), "");
    static_assert((std::is_same<decltype(wcstof(L"", (wchar_t**)0)), float>::value), "");
    static_assert((std::is_same<decltype(wcstold(L"", (wchar_t**)0)), long double>::value), "");
    static_assert((std::is_same<decltype(wcstol(L"", (wchar_t**)0, 0)), long>::value), "");
    static_assert((std::is_same<decltype(wcstoll(L"", (wchar_t**)0, 0)), long long>::value), "");
    static_assert((std::is_same<decltype(wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), "");
    static_assert((std::is_same<decltype(wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), "");
    static_assert((std::is_same<decltype(wcscpy(ws, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsncpy(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcscat(ws, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsncat(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcscmp(L"", L"")), int>::value), "");
    static_assert((std::is_same<decltype(wcscoll(L"", L"")), int>::value), "");
    static_assert((std::is_same<decltype(wcsncmp(L"", L"", s)), int>::value), "");
    static_assert((std::is_same<decltype(wcsxfrm(ws, L"", s)), size_t>::value), "");
    static_assert((std::is_same<decltype(wcschr((wchar_t*)0, L' ')), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcscspn(L"", L"")), size_t>::value), "");
    static_assert((std::is_same<decltype(wcslen(L"")), size_t>::value), "");
    static_assert((std::is_same<decltype(wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsspn(L"", L"")), size_t>::value), "");
    static_assert((std::is_same<decltype(wcsstr((wchar_t*)0, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemcmp(L"", L"", s)), int>::value), "");
    static_assert((std::is_same<decltype(wmemcpy(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemmove(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemset(ws, L' ', s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsftime(ws, s, L"", &tm)), size_t>::value), "");
    static_assert((std::is_same<decltype(btowc(0)), wint_t>::value), "");
    static_assert((std::is_same<decltype(wctob(w)), int>::value), "");
    static_assert((std::is_same<decltype(mbsinit(&mb)), int>::value), "");
    static_assert((std::is_same<decltype(mbrlen("", s, &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(mbrtowc(ws, "", s, &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(wcrtomb(ns, L' ', &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(mbsrtowcs(ws, (const char**)0, s, &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(wcsrtombs(ns, (const wchar_t**)0, s, &mb)), size_t>::value), "");
}
Example #29
0
/*
 * @implemented
 */
int CHString::Collate(LPCWSTR lpsz) const
{
    // Just call the deprecated function here - no matter we are null terminated
    // Did you read my statement about how safe is this implementation?
    return wcscoll(m_pchData, lpsz);
}
Example #30
0
int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t) {
  return wcscoll(ws1, ws2);
}