@verb #555:"_reboot_consumer" this none this rxdo #789 @program #555:"_reboot_consumer" this none this caller == this || raise(E_PERM) {pagehead, pagetail} = args pagetext = pagekeys = {} at_least_one_topic = 0 producer_task = this._reboot_task state = 0 "0 - intro" "1 - matching keys" "2 - text" while (1) if ($code_utils:task_valid(producer_task)) while (!this._reboot_buffer) "Wait for the producer to put some stuff on the buffer." "This rarely happens since the producer is faster than the consumer." suspend(1) $code_utils:task_valid(producer_task) || (this._reboot_buffer = {"***NEW: EOF"}) endwhile else "The producer died! Bail!" this._reboot_buffer = {"***NEW: EOF"} endif line = this._reboot_buffer[1] this._reboot_buffer = listdelete(this._reboot_buffer, 1) $command_utils:suspend_if_needed() if (index(line, "***NEW:") == 1) if (pagetext = this:trimwhite(pagetext)) _pagehead = pagehead for y in [1..length(pagehead)] _pagehead[y] = strsub(_pagehead[y], "*title*", pagetitle) _pagehead[y] = strsub(_pagehead[y], "*filename*", pagename) endfor _pagetail = pagetail for y in [1..length(pagetail)] _pagetail[y] = strsub(_pagetail[y], "*title*", pagetitle) _pagetail[y] = strsub(_pagetail[y], "*filename*", pagename) endfor pagetext[1] == "" || (pagetext = {@_pagehead, @pagetext}) pagetext[$] == "" || (pagetext = {@pagetext, @_pagetail}) this._reboot_thing:filewrite(pagename, pagetext) this._reboot_thing:filesetaccess(pagename, "r") this._reboot_db = {@this._reboot_db, {pagekeys, pagename, pagetitle}} at_least_one_topic = 1 elseif (state != 0) this:jabber("WARNING! No content in this state. Not creating this file.") endif if (line == "***NEW: EOF") "The only way out of this while loop." if ($code_utils:task_valid(producer_task)) if (!at_least_one_topic) this:jabber("WARNING! This database file has no topics.") endif resume(producer_task) else this:jabber("ERROR! Database reboot was terminated.") endif return endif pagetext = pagekeys = {} if (state == 1) this:jabber("WARNING! Two '***NEW:' tags in a row?") endif state = 1 words = $string_utils:explode(line[8..$]) if (length(words) < 2) this:jabber("WARNING! Invalid '***NEW:' tag. Must include filename and title.") state = 0 endif pagename = words[1] pagetitle = $string_utils:from_list(words[2..$], " ") this:jabber("... ", $su:left(pagename, 25), pagetitle) if (index(pagename, ".htm") <= 1) this:jabber("WARNING! This page's filename doesn't include '.htm'") endif if ($file_utils:trans_to(pagename) != pagename) this:jabber("WARNING! This page's filename includes illegal characters (", @$file_utils.trans_from, ")") endif if (listiassoc(pagename, this._reboot_db, 2)) this:jabber("WARNING! Duplicate filename, skipping this file.") state = 0 endif elseif (state == 1) if (!line) state = 2 else if (!(keys = this:decode(line))) this:jabber("WARNING! \"", line, "\" could not be parsed as a template.") else pagekeys = {@pagekeys, @keys} endif pagetext = {@pagetext, tostr("")} endif elseif (state == 2) pagetext = {@pagetext, line} endif endwhile "Last modified by Dax (#789) on Fri May 29 14:32:43 1998 EDT." .