Mercurial > ~dholland > hg > ag > index.cgi
diff anagram/guisupport/brt.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/guisupport/brt.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,157 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1993-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * brt.cpp + */ + +#include "assert.h" +#include "brt.h" +#include "configparam.h" +#include "dc.h" +#include "dict.h" +#include "help.h" +#include "stacks.h" + +//#define INCLUDE_LOGGING +#include "log.h" + + +help_index_dc::help_index_dc(void) + : dc("Help Topics") +{ + LOGSECTION("help_index_dc::help_index_dc"); + + unsigned ntopics = helpindex_num(); + LOGV(ntopics); + + unsigned dw = 0; + for (unsigned i=0; i<ntopics; i++) { + unsigned sw = strlen(helpindex_get(i)); + if (sw > dw) { + dw = sw; + } + } + + des->d_size = cint(dw, ntopics); + + syntax_dependent = 0; + LOGS("All done"); +} + +AgString help_index_dc::findHelpTopic(void) { + return helpindex_get(des->c_loc_doc.y); +} + +void help_index_dc::getLine(unsigned ln) const { + const char *s = helpindex_get(ln); + sss(s); +} + +static int param_table_tabs[3] = {24,0}; + +void param_table_dc::getLine(unsigned ln) const { + LOGSECTION("param_table_dc::getLine"); + ConfigParam ¶m = *ConfigParam::table[ln]; + LOGV(ln) LCV(param.name); + ssprintf("%s\t%s", param.name, param.asString().pointer()); + //sss(ConfigParam::table[ln]->asString().pointer()); +} + +param_table_dc::param_table_dc(void) + : dc("Configuration Parameters") +{ + LOGSECTION("param_table_dc::param_table_dc"); + + int n = ConfigParam::paramCount; + int i = 1; + int sl, cw; + + cw = 0; + while (i < n) { + sl = strlen(ConfigParam::table[i++]->asString().pointer()); + if (sl > cw) { + cw = sl; + } + } + + param_table_tabs[0] = cw + 2; + tab_stops = param_table_tabs; + columnHeadTitle = "Parameter\tValue"; + + des->d_size = cint(2*cw + 1, n); + syntax_dependent = 1; +} + +AgString param_table_dc::findHelpTopic(void) { + LOGSECTION("param_table_dc::findHelpTopic"); + int i; + int length; + + getLine(des->c_loc_doc.y); + LOGV(des->c_loc_doc.y) LCV(string_base); + length = strlen(string_base); + for (i = 0; string_base[i] == ' '; i++); + //title = &string_base[i]; + for (i = length; string_base[--i] != '\t'; ) { + /* Nothing to do */ + } + + string_base[i] = 0; + AgString topic = string_base; + rcs(); + LOGV(topic); + return topic; +} + + + +// text_window_dc + +void text_window_dc::getLine(unsigned ln) const { + char *ptr = text.pointer(); + unsigned k = 0; + char c; + assert(text.exists()); + while (k < ln) { + ptr = 1+strchr(ptr, '\n'); + k++; + } + ics(); + while (1) { + c = *ptr++; + if (c == '\n' || c== 0) { + break; + } + acs(c); + } +} + +text_window_dc::text_window_dc(AgString title, AgString text_arg) + : dc(title) +{ + int dw, dp; + char *p, *base = text_arg.pointer(); + + text = text_arg; + dw = 0; + dp = 0; + while (1) { + int w; + + p = strchr(base, '\n'); + if (p == NULL) { + break; + } + dp++; + w = (int)(p - base); + if (w > dw) { + dw = w; + } + base = p+1; + } + des->d_size = cint(dw, dp); + syntax_dependent = 0; +} +