| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | filter.c |
13 Mar 96 04:33, andrew clarke wrote to Paul Edwards:
> Why not write a filter to convert the "hard-wrapped" text
generated by
> EMACS to proper paragraphs that Msged can handle. You could even add
> it to the Msged code. And release it to the public domain. How about
> it? :-)
The following program is a text filter that will read text in from standard
input and attempt to convert "hard-returns" to paragraphs, and
output to standard output, while taking into consideration quoted lines
beginning with the quote ' character.
Putting "~~" (sans quotes) at the beginning of a line, eg.
~~
Don't touch me, I want the formatting of this text left alone!
Don't touch me, I want the formatting of this text left alone!
Don't touch me, I want the formatting of this text left alone!
~~
before and after a selection of text will tell the program to copy standard
input to standard output verbatim, without filtering. (The "~~"
is not sent to standard output.) Users of the timEd message reader who use
an external editor should find this feature familiar.
It's a bit of a five-minute hack, but with a bit of luck (and probably a
bit of modification) it should work for you. Have fun.
/*
* FILTER.C - Filter to attempt to convert text with hard-returns to text in
* paragraph form.
*
* For more information send FidoNet netmail to Andrew Clarke at 3:635/727.4
* (or in the Australian PUBLIC_DOMAIN conference) or Internet e-mail at
* randy{at}empire.bbs.net.au.
*
* Written 1996 by Andrew Clarke in about 5 minutes and released to the
* public domain.
*
*/
#include
#include
#include
int main(void)
{
char quote[11], tmp[300];
int addtext, retforce;
addtext = retforce = 0;
while (1) {
if (fgets(tmp, 300, stdin) == NULL)
break;
if (*(tmp + strlen(tmp) - 1) == '\n')
*(tmp + strlen(tmp) - 1) = '\0';
if (!retforce) {
if (strcmp(tmp, "~~") == 0) {
retforce = 1;
printf("\n");
} else {
if (addtext)
putchar(' ');
strncpy(quote, tmp, 11);
quote[10] = '\0';
if (*tmp && !strchr(quote, '>') &&
strlen(tmp) > 60) {
printf("%s", tmp);
addtext = 1;
} else {
printf("%s\n", tmp);
addtext = 0;
}
}
} else {
if (strcmp(tmp, "~~") == 0)
retforce = 0;
if (addtext) {
printf("\n");
addtext = 0;
}
if (strcmp(tmp, "~~") != 0)
printf("%s\n", tmp);
}
}
return 0;
}
Sorry of that's all a bit vague. :-) Just read the code and try it out on
one of your messages.
Regards
Andrew
--- Msgedsq/2 3.30
* Origin: This one HAS to be original X (3:635/727.4{at}fidonet)SEEN-BY: 50/99 78/0 635/309 503 544 727 640/230 711/401 410 413 430 808 809 SEEN-BY: 711/934 712/610 713/888 800/1 7877/2809 @PATH: 635/727 544 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.