MCPcopy Create free account
hub / github.com/NetHack/NetHack / mixed_to_utf8

Function mixed_to_utf8

src/utf8map.c:85–145  ·  view source on GitHub ↗

helper routine if a window port wants to embed any UTF-8 sequences for the glyph representation in the string in place of the \GNNNNNNNN reference */

Source from the content-addressed store, hash-verified

83 for the glyph representation in the string in place of the \GNNNNNNNN
84 reference */
85char *
86mixed_to_utf8(char *buf, size_t bufsz, const char *str, int *retflags)
87{
88 char *put = buf;
89 glyph_info glyphinfo = nul_glyphinfo;
90
91 if (!str)
92 return strcpy(buf, "");
93
94 while (*str && put < (buf + bufsz) - 1) {
95 if (*str == '\\') {
96 int dcount, so, ggv;
97 const char *save_str;
98
99 save_str = str++;
100 switch (*str) {
101 case 'G': /* glyph value \GXXXXNNNN*/
102 if ((dcount = decode_glyph(str + 1, &ggv))) {
103 str += (dcount + 1);
104 map_glyphinfo(0, 0, ggv, 0, &glyphinfo);
105 if (glyphinfo.gm.u && glyphinfo.gm.u->utf8str) {
106 uint8 *ucp = glyphinfo.gm.u->utf8str;
107
108 while (*ucp && put < (buf + bufsz) - 1)
109 *put++ = *ucp++;
110 if (retflags)
111 *retflags = 1;
112 } else {
113 so = glyphinfo.gm.sym.symidx;
114 *put++ = gs.showsyms[so];
115 if (retflags)
116 *retflags = 0;
117 }
118 /* 'str' is ready for the next loop iteration and
119 '*str' should not be copied at the end of this
120 iteration */
121 continue;
122 } else {
123 /* possible forgery - leave it the way it is */
124 str = save_str;
125 }
126 break;
127 case '\\':
128 break;
129 case '\0':
130 /* String ended with '\\'. This can happen when someone
131 names an object with a name ending with '\\', drops the
132 named object on the floor nearby and does a look at all
133 nearby objects. */
134 /* brh - should we perhaps not allow things to have names
135 that contain '\\' */
136 str = save_str;
137 break;
138 }
139 }
140 if (put < (buf + bufsz) - 1)
141 *put++ = *str++;
142 }

Callers 2

tty_putmixedFunction · 0.85
curses_putmixedFunction · 0.85

Calls 2

decode_glyphFunction · 0.85
map_glyphinfoFunction · 0.85

Tested by

no test coverage detected