165 |
|
|
166 |
/* Print len bytes from str into mach->outbuf */ |
/* Print len bytes from str into mach->outbuf */ |
167 |
static void |
static void |
168 |
print_string (struct mh_machine *mach, size_t width, char *str, size_t len) |
print_string (struct mh_machine *mach, size_t width, char *str, size_t fmtlen) |
169 |
{ |
{ |
170 |
size_t rest; |
size_t rest, len; |
171 |
|
|
172 |
if (!str) |
if (!str) |
173 |
{ |
str = ""; |
|
str = ""; |
|
|
len = 0; |
|
|
} |
|
174 |
|
|
|
rest = strlen (str); |
|
|
if (len > rest) |
|
|
len = rest; |
|
175 |
if (!width) |
if (!width) |
176 |
width = mach->width; |
width = mach->width; |
177 |
rest = mach->width - mach->ind; |
len = strlen (str); |
178 |
|
rest = width - mach->ind; |
179 |
if (len > rest) |
if (len > rest) |
180 |
len = rest; |
{ |
181 |
|
if (fmtlen >= len) |
182 |
|
fmtlen = rest; |
183 |
|
len = rest; |
184 |
|
} |
185 |
|
|
186 |
|
if (fmtlen < len) |
187 |
|
len = fmtlen; |
188 |
|
|
189 |
memcpy (mach->outbuf + mach->ind, str, len); |
memcpy (mach->outbuf + mach->ind, str, len); |
190 |
mach->ind += len; |
mach->ind += len; |
191 |
|
|
192 |
|
if (fmtlen > len) |
193 |
|
{ |
194 |
|
fmtlen -= len; |
195 |
|
memset (mach->outbuf + mach->ind, ' ', fmtlen); |
196 |
|
mach->ind += fmtlen; |
197 |
|
} |
198 |
} |
} |
199 |
|
|
200 |
static void |
static void |