~aleteoryx/gloss

cb36f073844d5ebbd05ca30507acc17222ec8357 — Aleteoryx 3 months ago cebd9a4
cleanup debug statements
4 files changed, 11 insertions(+), 12 deletions(-)

A .gitignore
M README.md
M gloss.py
M markup.c
A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
/markup

M README.md => README.md +1 -0
@@ 7,6 7,7 @@ it is designed to maximize nonlinear browsing.
***

the central gloss.py script translates each .gls file in its input directory to a .html in its output.
to run it, you will need a python runtime and a C compiler. make sure to download the entire repo.

.gls files are composed of a names section, a set of blocks, and an optional "see also" section.


M gloss.py => gloss.py +4 -9
@@ 105,7 105,7 @@ def first_pass(slug, fp):
		elif block_type == 'quote':
			if line.startswith('>'):
				line = line[1:].strip()
			block_text += "\n" + line
			block_text += ' ' + line
		elif block_type == 'para':
			block_text += ' ' + line
	


@@ 124,25 124,21 @@ class Markup:

		if stat(self.cfile).st_mtime > stat(self.bfile).st_mtime:
			print("recompiling markup subsystem...")
			runcmd(['cc', self.cfile, '-DDEBUG', '-o', self.bfile, '-Wall'], check=True)
			runcmd(['cc', self.cfile, '-o', self.bfile, '-Wall'], check=True)
			print("recompiled!")
		
		self.proc = Popen([self.bfile, 'convert'], stdin=PIPE, stdout=PIPE, text=True)
	
	def process(self, text):
		print(f'{text=}')
		self.proc.stdin.write(text+"\n")
		self.proc.stdin.flush()

		segments = []
		while (line := self.proc.stdout.readline()) != '':
		while (line := self.proc.stdout.readline()) not in ('NEXT\n', ''):
			ty = line[0:4]
			if ty == 'NEXT':
				break

			length = int(line[5:9])
			ltext = line[12:12+length]
			print(f'{ltext=}')

			if ty == 'HTML':
				segments.append((ltext,))


@@ 152,8 148,7 @@ class Markup:
				segments.append(ltext)
			else:
				print(f'read in unknown type "{ty}" from markup subprocess', file=stderr)
		
		print(segments)

		return segments
			


M markup.c => markup.c +5 -3
@@ 74,7 74,8 @@ new_segment(int type, size_t length, const char *text)
	new->text = text;
	new->next = NULL;

	fprintf(stderr, "new_segment @ %p: %d / %zu / %.*s\n", new, type, length, (int)length, text);
	if (DEBUG)
		fprintf(stderr, "new_segment @ %p: %d / %zu / %.*s\n", new, type, length, (int)length, text);

	return new;
}


@@ 152,7 153,7 @@ segmentize(size_t length, const char *source)
{
	// p is the start of the most recent text segment
	const char *p = source, *i, *newi, *end = source + length;
	int in_italic = 0, in_escape = 0;
	int in_italic = 0;
	struct segment *head = new_segment(SEG_HEAD, 0, NULL), *ret;
	struct segment *tail = head;
	struct segment *italic_head, *italic_tail;


@@ 286,7 287,8 @@ convert()
	struct segment *seg;

	while((s = nextline()) != NULL){
		fprintf(stderr, "processing line: %s\n", s);
		if(DEBUG)
			fprintf(stderr, "processing line: %s\n", s);
		length = strlen(s);
		seg = segmentize(length, s);
		for(; seg != NULL; seg = seg->next)