TheGNUGeneralPublicLicenseisoftenshippedwithGNUsoftware,and isgenerallykeptinafilecalledCOPYINGorLICENSE.Ifyoudonot haveacopyofthelicense,writetotheFreeSoftwareFoundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA. */ #define READLINE_LIBRARY
#ifdefined (HAVE_CONFIG_H) # include "config_readline.h" #endif
#ifdefined (HAVE_UNISTD_H) # include <unistd.h> /* for _POSIX_VERSION */ #endif/* HAVE_UNISTD_H */
#ifdefined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif/* HAVE_STDLIB_H */
#include <stdio.h> #include <ctype.h>
/* System-specific feature definitions and include files. */ #include"rldefs.h" #include"rlmbutil.h"
#ifdefined (TIOCSTAT_IN_SYS_IOCTL) # include <sys/ioctl.h> #endif/* TIOCSTAT_IN_SYS_IOCTL */
/* Some standard library routines. */ #include"readline.h"
#include"rlprivate.h" #include"xmalloc.h"
/* Declared here so it can be shared between the readline and history
libraries. */ #ifdefined (HANDLE_MULTIBYTE) int rl_byte_oriented = 0; #else int rl_byte_oriented = 1; #endif
memset(&ps, 0, sizeof (mbstate_t)); if (seed < 0)
seed = 0; if (count <= 0) return seed;
point = seed + _rl_adjust_point (string, seed, &ps); /* if this is true, means that seed was not pointed character
started byte. So correct the point and consume count */ if (seed < point)
count--;
while (count > 0)
{
tmp = mbrtowc (&wc, string+point, strlen(string + point), &ps); if (MB_INVALIDCH ((size_t)tmp))
{ /* invalid bytes. asume a byte represents a character */
point++;
count--; /* reset states. */
memset(&ps, 0, sizeof(mbstate_t));
} elseif (MB_NULLWCH (tmp)) break; /* found wide '\0' */ else
{ /* valid bytes */
point += tmp; if (find_non_zero)
{ if (wcwidth (wc) == 0) continue; else
count--;
} else
count--;
}
}
if (find_non_zero)
{
tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps); while (tmp > 0 && wcwidth (wc) == 0)
{
point += tmp;
tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps); if (MB_NULLWCH (tmp) || MB_INVALIDCH (tmp)) break;
}
}
return point;
}
staticint
_rl_find_prev_mbchar_internal (string, seed, find_non_zero) char *string; int seed, find_non_zero;
{
mbstate_t ps; int prev, non_zero_prev, point, length;
size_t tmp; wchar_t wc;
prev = non_zero_prev = point = 0; while (point < seed)
{
tmp = mbrtowc (&wc, string + point, length - point, &ps); if (MB_INVALIDCH ((size_t)tmp))
{ /* in this case, bytes are invalid or shorted to compose multibytechar,soassumethatthefirstbyterepresents
a single character anyway. */
tmp = 1; /* clear the state of the byte sequence, because
in this case effect of mbstate is undefined */
memset(&ps, 0, sizeof (mbstate_t));
/* Since we're assuming that this byte represents a single
non-zero-width character, don't forget about it. */
prev = point;
} elseif (MB_NULLWCH (tmp)) break; /* Found '\0' char. Can this happen? */ else
{ if (find_non_zero)
{ if (wcwidth (wc) != 0)
prev = point;
} else
prev = point;
}
point += tmp;
}
return prev;
}
/* return the number of bytes parsed from the multibyte sequence starting atsrc,ifanon-L'\0'widecharacterwasrecognized.Itreturns0, ifaL'\0'widecharacterwasrecognized.Itreturns(size_t)(-1), ifaninvalidmultibytesequencewasencountered.Itreturns(size_t)(-2)
if it couldn't parse a complete multibyte character. */ int
_rl_get_char_len (src, ps) char *src;
mbstate_t *ps;
{
size_t tmp;
tmp = mbrlen((constchar *)src, (size_t)strlen (src), ps); if (tmp == (size_t)(-2))
{ /* shorted to compose multibyte char */ if (ps)
memset (ps, 0, sizeof(mbstate_t)); return -2;
} elseif (tmp == (size_t)(-1))
{ /* invalid to compose multibyte char */ /* initialize the conversion state */ if (ps)
memset (ps, 0, sizeof(mbstate_t)); return -1;
} elseif (tmp == (size_t)0) return0; else return (int)tmp;
}
/* compare the specified two characters. If the characters matched,
return 1. Otherwise return 0. */ int
_rl_compare_chars (buf1, pos1, ps1, buf2, pos2, ps2) char *buf1; int pos1;
mbstate_t *ps1; char *buf2; int pos2;
mbstate_t *ps2;
{ int i, w1, w2;
for (i = 1; i < w1; i++) if (buf1[pos1+i] != buf2[pos2+i]) return0;
return1;
}
/* adjust pointed byte and find mbstate of the point of string. adjustedpointwillbepoint<=adjusted_point,andreturns differencesofthebyte(adjusted_point-point). ifpointisinvalied(point<0||morethanstringlength),
it returns -1 */ int
_rl_adjust_point(string, point, ps) char *string; int point;
mbstate_t *ps;
{
size_t tmp = 0; int length; int pos = 0;
length = strlen(string); if (point < 0) return -1; if (length < point) return -1;
while (pos < point)
{
tmp = mbrlen (string + pos, length - pos, ps); if (MB_INVALIDCH ((size_t)tmp))
{ /* in this case, bytes are invalid or shorted to compose multibytechar,soassumethatthefirstbyterepresents
a single character anyway. */
pos++; /* clear the state of the byte sequence, because
in this case effect of mbstate is undefined */ if (ps)
memset (ps, 0, sizeof (mbstate_t));
} elseif (MB_NULLWCH (tmp))
pos++; else
pos += tmp;
}
return (pos - point);
}
int
_rl_is_mbchar_matched (string, seed, end, mbchar, length) char *string; int seed, end; char *mbchar; int length;
{ int i;
if ((end - seed) < length) return0;
for (i = 0; i < length; i++) if (string[seed + i] != mbchar[i]) return0; return1;
}
wchar_t
_rl_char_value (buf, ind) char *buf; int ind;
{
size_t tmp; wchar_t wc;
mbstate_t ps; int l;
if (MB_LEN_MAX == 1 || rl_byte_oriented) return ((wchar_t) buf[ind]);
l = strlen (buf); if (ind >= l - 1) return ((wchar_t) buf[ind]);
memset (&ps, 0, sizeof (mbstate_t));
tmp = mbrtowc (&wc, buf + ind, l - ind, &ps); if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp)) return ((wchar_t) buf[ind]); return wc;
} #endif/* HANDLE_MULTIBYTE */
/* Find next `count' characters started byte point of the specified seed. IfflagsisMB_FIND_NONZERO,welookfornon-zero-widthmultibyte
characters. */ #undef _rl_find_next_mbchar int
_rl_find_next_mbchar (string, seed, count, flags) char *string __attribute__((unused)); int seed, count, flags __attribute__((unused));
{ #ifdefined (HANDLE_MULTIBYTE) return _rl_find_next_mbchar_internal (string, seed, count, flags); #else return (seed + count); #endif
}
/* Find previous character started byte point of the specified seed. Returnedpointwillbepoint<=seed.IfflagsisMB_FIND_NONZERO,
we look for non-zero-width multibyte characters. */ #undef _rl_find_prev_mbchar int
_rl_find_prev_mbchar (string, seed, flags) char *string __attribute__((unused)); int seed, flags __attribute__((unused));
{ #ifdefined (HANDLE_MULTIBYTE) return _rl_find_prev_mbchar_internal (string, seed, flags); #else return ((seed == 0) ? seed : seed - 1); #endif
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.