diff --git a/bin/pikedoc2.pike b/bin/pikedoc2.pike index 03a2559ed7732fda1bcadf4a72888ced1a2ff8e4..05075ccd708f21db69731282979883a6ce6e5583 100755 --- a/bin/pikedoc2.pike +++ b/bin/pikedoc2.pike @@ -1,6 +1,6 @@ #!/usr/local/bin/pike /* - * $Id: pikedoc2.pike,v 1.1 1999/07/08 21:57:23 grubba Exp $ + * $Id: pikedoc2.pike,v 1.2 1999/07/09 17:10:06 grubba Exp $ * * Pike-doc extractor mk II * @@ -11,6 +11,70 @@ #if constant(spider) #endif /* constant(spider) */ +array(string) txt_to_wmml(array(string) lines) +{ + array(string) res = allocate(sizeof(lines)+1, ""); + + array(string) a = lines[0]/" "; + + if (!(< "METHOD", "FUNCTION" >)[a[0]]) { + werror(sprintf("%O\n" + "Not in txt format!\n", lines[0])); + return lines; + } + + if (sizeof(a) < 2) { + werror(sprintf("%O\n" + "Missing name\n", lines[0])); + return res; + } + + string type = lower_case(a[0]); + string name = a[1]; + + string title; + + if (sizeof(a) > 2) { + title = a[2..]*" "; + } + + if (title) { + res[0] = sprintf("<%s name=%O title=%O>", type, name, title); + } else { + res[0] = sprintf("<%s name=%O>", type, name); + } + + res[-1] = sprintf("</%s>\n", type); + + string current_container; + int i; + for (i=1; i < sizeof(lines); i++) { + if ((lines[i] != "") && (lines[i] == upper_case(lines[i]))) { + if (current_container) { + res[i-1] += sprintf("\n</man_%s>", current_container); + } + res[i] = sprintf("<man_%s>", current_container = lower_case(lines[i])); + } else { + if ((lines[i] != "") && (lines[i][0] == '\t')) { + // Remove initial tab. + res[i] = lines[i][1..]; + } else { + res[i] = lines[i]; + } + } + } + + if (current_container) { + if (res[-2] == "") { + res[-2] = sprintf("</man_%s>", current_container); + } else { + res[-2] += sprintf("\n</man_%s>", current_container); + } + } + + return res; +} + string _extract_pikedoc(string tag, mapping attrs, string contents, mapping res) { @@ -29,6 +93,15 @@ string _extract_pikedoc(string tag, mapping attrs, string contents, } } + switch(lower_case(attrs->type || "wmml")) { + case "wmml": + // No need to do anything. + break; + case "txt": + s = txt_to_wmml(s); + break; + } + res->res += s*"\n" + "\n"; return("");