
#include "../src/bfunc.h"

#ifndef min
#define min(i,j) ((i)<(j)?(i):(j))
#endif


ftocstr(ds, dl, ss, sl)
    char *ds, *ss;      /* dst, src ptrs */
    int dl;             /* dst max len */
    int sl;             /* src len */
{
    char *p;

    for (p = ss + sl; --p >= ss && *p == ' '; ) ;
    sl = p - ss + 1;
    dl--;
    ds[0] = 0;
    if (sl > dl)
        return 1;
    strncat(ds, ss, min(sl, dl));
    return 0;
}


ctofstr(ds, dl, ss)
	char *ds;		/* dest space */
	int dl;			/* max dest length */
	char *ss;		/* src string (0-term) */
{
	int sl = strlen(ss);

	if (dl <= sl)
		BCOPY(ss, ds, dl);

	else {
		BCOPY(ss, ds, sl);
		dl -= sl;
		ds += sl;
		while (dl-- > 0)
			*ds++ = ' ';
	}
	return 0;
}


