basic fmt program using fmtc - tttml - converters for a simpler syntax than markdown HTML git clone git://bitreich.org/tttml git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/tttml DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit dfd29d4237158b9699334bbab6d22e4285e4a8a4 DIR parent b9898661168d039dc96cb69c093089fde465cbbe HTML Author: Josuah Demangeon <mail@josuah.net> Date: Thu, 31 May 2018 23:36:36 +0200 basic fmt program using fmtc Diffstat: A a.out | 0 A a.out.core | 0 A t | 70 +++++++++++++++++++++++++++++++ M tttml-gopher.1 | 27 +++++++++++++++++++-------- A tttml.c | 73 +++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 8 deletions(-) --- DIR diff --git a/a.out b/a.out Binary files differ. DIR diff --git a/a.out.core b/a.out.core Binary files differ. DIR diff --git a/t b/t @@ -0,0 +1,69 @@ + TTTML(5) File Formats Manual TTTML(5) + NAME tttml - simpler markup syntax than markdown SYNOPSIS file.md + DESCRIPTION The tttml format is a very simple format for writiing text + that look good enough to be published without conversion. It lacks the + markdown recursive syntax (such as recursive lists anb quotes) which + also remove markdown ambiguities. Each block of text is separated from + anotherone by an empty line. paragraph Any + non-special block of text: First paragraph of text. + Second paragraph of text. title Block that ends by a line with only + `=': Title can therefore have multiple lines if required + although it is not advised. + ====================================================== heading + Block that ends with a line with only `-': Heading can also + have multiple lines + ------------------------------------------------------ subheading + Block with a single line with at least 3 leading `#' characters + starting at subheading and going down the outline (subheading, + subsubheading ...) every time an additionnal `#' is added: + ### Subheading #### Subsubheading ##### + Subsubsubheading tag Block that start with a tag line: + *tagline with asterisks and a column*: Body of the tag block + that can span over multiple lines like regular paragraphs. + list Block that start with a dash: - List item. The + following lines might not have leading space. + - Note that multi-paragraph lists are not handled quote Block that + has a leading `>' on every line: > Mail-style quoting. Note + that nested quotes > are not handled. literal + Block that has a leading tab on every line: Nothing + gets interpreted in these blocks. They get printed + as-is. They may contain extra tabs. + link Block that start with a label line and eventual subsequent + description lines: [label]: git://josuah.net/git/tttml + git repository for the tttml set of tools [label2]: + /url/without/description.txt SEE ALSO smu(1), simple markup - markdown + like syntax: https://github.com/Gottox/smu AUTHORS Josuah + Demangeon <mail@josuah.net> OpenBSD 6.3 April 19, 2018 + OpenBSD 6.3 + ------------------------------------------------------------------------------ + TTTML-FMT(1) General Commands Manual + TTTML-FMT(1) NAME tttml-fmt - format/pretty-print a tttml file + SYNOPSIS tttml-fmt [file...] DESCRIPTION The tttml-fmt utility + reformat a tttml(5) and print valid format to stdout. Most + markdown documents can be converted to tttml(5) with if they do not have + recursive elents such as nested lists or nested quotes. o The + paragraphs are being filled to 80 columns, o The empty lines are + set as apropriate o The blocks merged together are separated, + such as lists without separating blank spaces. o The + title and heading horizontal lines are expanded to 80 columns. + o The tags with the tagline merged with the paragraph are separated + on their own line. SEE ALSO tttml-gopher(1), smu(1), tttml(5), simple + tttml - markdown like syntax: https://github.com/Gottox/smu AUTHORS + Josuah Demangeon <mail@josuah.net> OpenBSD 6.3 April 19, + 2018 OpenBSD 6.3 + ------------------------------------------------------------------------------ + TTTML-GOPHER(1) General Commands Manual + TTTML-GOPHER(1) NAME tttml-gopher - generate a gophermap from a tttml + file SYNOPSIS tttml-gopher host port [file...] DESCRIPTION The + tttml-gopher utility convert file to a gophermap format, simply by + converting all link entries, converting tabs into spaces and printing the + rest. host and port is used to set the host in links that do not have a + host, such as /path/to/file.txt o All URI starting with a `/' and + ending with a `/' are printed using the `1' entry type o + All URI starting with a `/' and not ending with a `/' are printed + using the `0' o All URI starting with `0', `1', `7', `8', `9', + `a', `g', `h' or `I' followed by a `/' and all "gopher://" URI + are printed using the corresponding entry type. o + All other URI are printed using the `h' entry type AUTHORS Josuah + Demangeon <mail@josuah.net> OpenBSD 6.3 April 19, 2018 + OpenBSD 6.3 +\ No newline at end of file DIR diff --git a/tttml-gopher.1 b/tttml-gopher.1 @@ -90,17 +90,28 @@ entry type .\" For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only. .\" .Sh ERRORS .\" For sections 2, 3, 4, and 9 errno settings only. -.\" .Sh SEE ALSO -.\" .Xr foobar 1 -.\" .Sh STANDARDS -.\" .Sh HISTORY +. +. +.Sh SEE ALSO +. +.Xr tttml-fmt 1 +. +.Sh STANDARDS +. +.Rs +.%A Anklesari +.%A McCahill +.%A Lindner +.%A Johnson +.%A Torrey +.%A Alberti +.%D March 1993 +.%T The Internet Gopher Protocol +.%R RFC 1436 +.Re . . .Sh AUTHORS . .An Josuah Demangeon .Aq Mt mail@josuah.net -. -. -.\" .Sh CAVEATS -.\" .Sh BUGS DIR diff --git a/tttml.c b/tttml.c @@ -0,0 +1,73 @@ +#include <string.h> +#include <stdio.h> +#include <ctype.h> + +#define WORD_MAX 1024 +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + +/* + * Put the character c to stdout, and if the line is too long, insert + * a newline. If c == EOF, flush the last word out of fmtc's static + * buffer. + * + * It preserve the double space after a punctuation mark [.!?] if any. + */ +int +fmtc(char c, char *prefix, int max) +{ + static int pos = 0, nspaces = 0, wlen = 0, was_space = 1, was_punct = 0, first = 1; + static char word[WORD_MAX], *w = word; + + if (c != ' ' && c != '\n' && c != EOF) { + if (wlen + 1 < WORD_MAX) { + *w++ = c; + wlen++; + } + was_space = 0; + was_punct = !!strchr(".!?", c); + + } else { + if (!was_space) { + was_space = 1; + + if (pos + nspaces + wlen > max) { + pos = strlen(prefix); + fputc('\n', stdout); + fputs(prefix, stdout); + } else if (!first) { + pos += nspaces; + while (nspaces-- > 0) + fputc(' ', stdout); + } + + pos += wlen; + word[wlen] = '\0'; + fputs(word, stdout); + + w = word; + wlen = 0; + nspaces = 1; + } else { + nspaces = was_punct ? 2 : 1; + } + + if (c == EOF) + fputc('\n', stdout); + + first = 0; + } + + return c; +} + +int +main(void) +{ + int c; + char *prefix; + + prefix = " |"; + + fputs(prefix, stdout); + while (fmtc(fgetc(stdin), prefix, 80) != EOF); +}