=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/cvt.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/less/cvt.c 2014/04/25 13:38:21 1.3 +++ src/usr.bin/less/cvt.c 2015/11/05 22:08:44 1.4 @@ -6,6 +6,10 @@ * * For more information, see the README file. */ +/* + * Modified for use with illumos. + * Copyright 2014 Garrett D'Amore + */ /* * Routines to convert text in various ways. Used by search. @@ -19,14 +23,12 @@ /* * Get the length of a buffer needed to convert a string. */ - public int -cvt_length(len, ops) - int len; - int ops; +int +cvt_length(int len) { if (utf_mode) /* - * Just copying a string in UTF-8 mode can cause it to grow + * Just copying a string in UTF-8 mode can cause it to grow * in length. * Four output bytes for one input byte is the worst case. */ @@ -37,12 +39,11 @@ /* * Allocate a chpos array for use by cvt_text. */ - public int * -cvt_alloc_chpos(len) - int len; +int * +cvt_alloc_chpos(int len) { int i; - int *chpos = (int *) ecalloc(sizeof(int), len); + int *chpos = ecalloc(sizeof (int), len); /* Initialize all entries to an invalid position. */ for (i = 0; i < len; i++) chpos[i] = -1; @@ -54,18 +55,13 @@ * Returns converted text in odst. The original offset of each * odst character (when it was in osrc) is returned in the chpos array. */ - public void -cvt_text(odst, osrc, chpos, lenp, ops) - char *odst; - char *osrc; - int *chpos; - int *lenp; - int ops; +void +cvt_text(char *odst, char *osrc, int *chpos, int *lenp, int ops) { char *dst; char *edst = odst; char *src; - register char *src_end; + char *src_end; LWCHAR ch; if (lenp != NULL) @@ -73,35 +69,27 @@ else src_end = osrc + strlen(osrc); - for (src = osrc, dst = odst; src < src_end; ) - { + for (src = osrc, dst = odst; src < src_end; ) { int src_pos = src - osrc; int dst_pos = dst - odst; ch = step_char(&src, +1, src_end); - if ((ops & CVT_BS) && ch == '\b' && dst > odst) - { + if ((ops & CVT_BS) && ch == '\b' && dst > odst) { /* Delete backspace and preceding char. */ do { dst--; } while (dst > odst && - !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); - } else if ((ops & CVT_ANSI) && IS_CSI_START(ch)) - { + !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); + } else if ((ops & CVT_ANSI) && IS_CSI_START(ch)) { /* Skip to end of ANSI escape sequence. */ src++; /* skip the CSI start char */ while (src < src_end) if (!is_ansi_middle(*src++)) break; - } else - { + } else { /* Just copy the char to the destination buffer. */ if ((ops & CVT_TO_LC) && IS_UPPER(ch)) ch = TO_LOWER(ch); -#if !SMALL put_wchar(&dst, ch); -#else - *dst++ = (char)ch; -#endif /* !SMALL */ /* Record the original position of the char. */ if (chpos != NULL) chpos[dst_pos] = src_pos; @@ -114,5 +102,4 @@ *edst = '\0'; if (lenp != NULL) *lenp = edst - odst; - /* FIXME: why was this here? if (chpos != NULL) chpos[dst - odst] = src - osrc; */ }