view anagram/guisupport/brt.cpp @ 8:ec2b657edf13

Add explicit lint-comment-style fallthrough annotations. GCC now assumes that if you don't have these you're making a mistake, which is annoying. XXX: This changeset updates the AG output files only (by hand) and is XXX: abusive - rebuilding them will erase the change. However, I need XXX: to get things to build before I can try to get AG to issue the XXX: annotations itself, so this seems like a reasonable expedient.
author David A. Holland
date Mon, 30 May 2022 23:51:43 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * 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 &param = *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;
}