269{
270 char *output;
271 char *outstart;
272
273
274 output =
lwalloc(maxlength + 4);
275 output[0] = '\0';
276
277
278 if (truncdirection == 0)
279 {
280
281 if (endpos - startpos < maxlength)
282 {
283 outstart =
str + startpos;
284 strncat(output, outstart, endpos - startpos + 1);
285 }
286 else
287 {
288 if (maxlength >= 3)
289 {
290
291 outstart =
str + endpos + 1 - maxlength + 3;
292 strncat(output, "...", 4);
293 strncat(output, outstart, maxlength - 3);
294 }
295 else
296 {
297
298 strncat(output, "...", 4);
299 }
300 }
301 }
302
303
304 if (truncdirection == 1)
305 {
306
307 if (endpos - startpos < maxlength)
308 {
309 outstart =
str + startpos;
310 strncat(output, outstart, endpos - startpos + 1);
311 }
312 else
313 {
314 if (maxlength >= 3)
315 {
316
317 outstart =
str + startpos;
318 strncat(output, outstart, maxlength - 3);
319 strncat(output, "...", 4);
320 }
321 else
322 {
323
324 strncat(output, "...", 4);
325 }
326 }
327 }
328
329 return output;
330}
void * lwalloc(size_t size)