#include <stdlib.h>
#include <string.h>
#include "strdup_crsp.h"

char *strdup_crsp(char const *p)
{
	unsigned i, l = 0;
	for (i=l=0; p[i]; ++i, ++l)
		if (p[i] == '\n' && p[i+1])
			l += 3;

	char *q = malloc(1+l);
	if (q)
	{
		for (i=l=0; p[i]; i++)
		{
			if (p[i] == '\n' && p[i+1])
			{
				q[l++]='\r';
				q[l++]='\n';
				q[l++]=' ';
				q[l++]=' ';
			}
			else
				q[l++]=p[i];
		}
		q[l]=0;
	}
	return q;
}
