conv.c (82725ba9bf1fd59746a4006a06f24d4d61d142f2) conv.c (6bb764934cb9199e5f82503ebcd57f47743c4679)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 42 unchanged lines hidden (view full) ---

51conv_c(PR *pr, u_char *p, size_t bufsize)
52{
53 char buf[10];
54 char const *str;
55 wchar_t wc;
56 size_t clen, oclen;
57 int converr, pad, width;
58 u_char peekbuf[MB_LEN_MAX];
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 42 unchanged lines hidden (view full) ---

51conv_c(PR *pr, u_char *p, size_t bufsize)
52{
53 char buf[10];
54 char const *str;
55 wchar_t wc;
56 size_t clen, oclen;
57 int converr, pad, width;
58 u_char peekbuf[MB_LEN_MAX];
59 u_char *op;
59
60 if (pr->mbleft > 0) {
61 str = "**";
62 pr->mbleft--;
63 goto strpr;
64 }
65
66 switch(*p) {

--- 35 unchanged lines hidden (view full) ---

102 oclen = 0;
103retry:
104 clen = mbrtowc(&wc, p, bufsize, &pr->mbstate);
105 if (clen == 0)
106 clen = 1;
107 else if (clen == (size_t)-1 || (clen == (size_t)-2 &&
108 p == peekbuf)) {
109 memset(&pr->mbstate, 0, sizeof(pr->mbstate));
60
61 if (pr->mbleft > 0) {
62 str = "**";
63 pr->mbleft--;
64 goto strpr;
65 }
66
67 switch(*p) {

--- 35 unchanged lines hidden (view full) ---

103 oclen = 0;
104retry:
105 clen = mbrtowc(&wc, p, bufsize, &pr->mbstate);
106 if (clen == 0)
107 clen = 1;
108 else if (clen == (size_t)-1 || (clen == (size_t)-2 &&
109 p == peekbuf)) {
110 memset(&pr->mbstate, 0, sizeof(pr->mbstate));
111 if (p == peekbuf) {
112 /*
113 * We peeked ahead, but that didn't help --
114 * we either got an illegal sequence or still
115 * can't complete; restore original character.
116 */
117 oclen = 0;
118 p = op;
119 }
110 wc = *p;
111 clen = 1;
112 converr = 1;
113 } else if (clen == (size_t)-2) {
114 /*
115 * Incomplete character; peek ahead and see if we
116 * can complete it.
117 */
118 oclen = bufsize;
120 wc = *p;
121 clen = 1;
122 converr = 1;
123 } else if (clen == (size_t)-2) {
124 /*
125 * Incomplete character; peek ahead and see if we
126 * can complete it.
127 */
128 oclen = bufsize;
129 op = p;
119 bufsize = peek(p = peekbuf, MB_CUR_MAX);
120 goto retry;
121 }
122 clen += oclen;
123 } else {
124 wc = *p;
125 clen = 1;
126 }
127 if (!converr && iswprint(wc)) {
128 if (!odmode) {
129 *pr->cchar = 'c';
130 (void)printf(pr->fmt, (int)wc);
130 bufsize = peek(p = peekbuf, MB_CUR_MAX);
131 goto retry;
132 }
133 clen += oclen;
134 } else {
135 wc = *p;
136 clen = 1;
137 }
138 if (!converr && iswprint(wc)) {
139 if (!odmode) {
140 *pr->cchar = 'c';
141 (void)printf(pr->fmt, (int)wc);
131 } else {
142 } else {
132 *pr->cchar = 'C';
133 assert(strcmp(pr->fmt, "%3C") == 0);
134 width = wcwidth(wc);
135 assert(width >= 0);
136 pad = 3 - width;
137 if (pad < 0)
138 pad = 0;
139 (void)printf("%*s%C", pad, "", wc);

--- 41 unchanged lines hidden ---
143 *pr->cchar = 'C';
144 assert(strcmp(pr->fmt, "%3C") == 0);
145 width = wcwidth(wc);
146 assert(width >= 0);
147 pad = 3 - width;
148 if (pad < 0)
149 pad = 0;
150 (void)printf("%*s%C", pad, "", wc);

--- 41 unchanged lines hidden ---