#include #include #include #include #include /* Author: Ruud Harmsen, 30 November 2024. Copyrighted in principle, but please do with it whatever you will. This is a filter (stdin to stdout) that transforms a poem of the form Quasi-Alexandrinos (see https://rudhar.com/lingtics/intrlnga/poesia/quasalex.htm from a raw but easy to handle text form, like: word1 word2 -- word3 word4 word5 to the HTML required to make it look good in a browser, like: word1 word2 – word3 word4 word5 */ static char sep[] = "--"; char linebuf[512]; int main (void) { char *p, *p1, *p2, *p3, *p4; setlocale(LC_ALL, "C"); while (fgets(linebuf, sizeof linebuf, stdin)) { /* comment? */ for (p1 = linebuf; *p1 && isspace(*p1); p1++) ; if (*p1 == '#') printf("%s", linebuf); /* normal line, one of three? */ else if ((p = strstr(linebuf, sep)) != NULL) { for (p1 = linebuf; p1 < p && isspace(*p1); p1++) ; for (p2 = p; p2 > linebuf && isspace(p2[-1]); p2--) ; for (p3 = p + strlen(sep); *p3 && isspace(*p3); p3++) ; for (p4 = p + strlen(p); p4 > p3 && isspace(p4[-1]); p4--) ; printf(" %.*s – %.*s\n", p2 - p1, p1, p4 - p3, p3); } /* fourth line? */ else { for (p1 = linebuf; *p1 && isspace(*p1); p1++) ; for (p2 = linebuf + strlen(linebuf); p2 > linebuf && isspace(p2[-1]); p2--) ; if (*p1) printf(" %.*s\n", p2 - p1, p1); else printf("  \n\n"); } } return 0; }