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