/*********************************************************/ #if 0 we want to do the following: sub MakePtag{ my ($fixme)=@_; # take in our parameters $fixme='

'.$fixme; # Prepend a

tag to our string $fixme=~s|(\r\n)|

|g; # replace all \r\n with <\p>

$fixme.='

'; # Append closing

tag return $fixme; } #endif char* make_p_tag(char* str){ int len = 0; int cr = 0; /* this will tell you if we found \r */ char *s = str; char *newstr, *s2; /* s#\r\n#

#, increases len by 5 (7-2)*/ while(*s != '\0'){ /* while we have more data */ ++len; if(*s == '\r'){ cr = 1; /* we found one */ } else if(*s == '\n' && cr){ /* we found \n and \r in the prev step */ cr = 0; /* forget we found a \r */ len += 5; } else { cr = 0; /* also forget we found an isolated \r*/ } ++s; } s = str; s2 = newstr = calloc(len+8, sizeof(char)); strcpy(s2,"

"); s2 += 3; while(*s != '\0'){ *s2 = *s; /* copy this char to the output string */ if(*s == '\r'){ cr = 1; /* mark that we put a \r */ } else if(*s == '\n' && cr){ /* now we placed \r\n */ cr = 0; strcpy(s2-1,"

"); /* put

*/ s2 += 5; /* and advance */ } else { cr = 0; /* forget it */ } ++s; ++s2; } strcpy(s2,"

"); /* put terminating

*/ s2+=4; *s2 = '\0'; return newstr; }