view anagram/guisupport/charsdc.cpp @ 18:562c313f14f4

some minor updates for 2022
author David A. Holland
date Tue, 31 May 2022 02:03:50 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2000 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * charsdc.cpp - Character set display module
 */

#include "arrays.h"
#include "charsdc.h"
#include "csexp.h"
#include "data.h"
#include "dc.h"
#include "dict.h"
#include "stacks.h"
#include "symbol.h"
#include "token.h"
#include "tree.h"
#include "ut.h"
#include "ws.h"

//#define INCLUDE_LOGGING
#include "log.h"


#define PURE_MARKER '%'

static int partition_set_tabs[] = {5,0};

static void part_set_display(int pn) {
  int tn = map_part_number[pn].token_number;
  token_number_map *tp = &map_token_number[tn];
  int name, tree;

  ssprintf("P%03d\tT%03d", pn, tn);
  if (tn == 0) {
    return;
  }
  name = tp->token_name;
  if (name) {
    ass(": ");
    //ass(dict_str(tkn_dict, name));
    ass(Symbol(name)->string.pointer());
    if (tp->pure) {
      acs(PURE_MARKER);
    }
    return;
  }
  tree = tp->parse_tree;
  if (tree) {
    name = map_parse_tree[tree].token_name;
    if (name) {
      //ass(dict_str(tkn_dict,name));
      ass(Symbol(name)->string.pointer());
      if (tp->pure) {
	acs(PURE_MARKER);
      }
    }
  }
}

static int part_set_window_ok(int pn) {
  return pn > 0 && (unsigned)pn < part_dict->nsx;
}

dc_ref part_set_window(int pn){
  unsigned *list = lstptr(map_part_number[pn], chars);
  dc_ref window;

  AgString foot = AgString::format("P%03d", pn);
  //window = find_on_screen("Set Elements", foot);
  //if (window.exists()) return window;
  return dc_ref(new set_elements_dc(list, 
				    map_part_number[pn].size,foot.pointer()));
}


static int char_map_tabs[] = {5,8,14,0};

char_map_dc::char_map_dc(void)
  : dc("Character Map")
{
  tab_stops = char_map_tabs;
  columnHeadTitle = "Code\tChar\tSet\tToken";
  //des->c_size = cursor_bar_size;
  des->d_size.y = n_chars;
  //getWidth();
  //resize_window();
}

//extern int ersatz_tab;

void char_map_dc::getLine(unsigned ln) const {
  LOGSECTION("char_map_dc::getLine");
  char_number_map cm = map_char_number[ln];
  int name = map_char_number[ln].token_name;
  int tn = cm.token_number;
  extern int min_char_number;
  int ch = ln + min_char_number;
  int c = ch > 0 && ch < 255 ? ch : 32;

  LOGV(tn) LCV(name);
  LOGV(ch) LCV(c) LCV(cm.part_number);
  //ersatz_tab = 255;
  if (c == '\t') {
    c = 255;
  }
  ssprintf("%3d\t%c\tP%03d\tT%03d", ch, c, cm.part_number, tn);
  if (tn) {
    ass(": ");
    atkn(tn);
    return;
  }
  if (name) {
    apprintf("       %s", Symbol(name)->string.pointer());
    //apprintf("       %s", dict_str(tkn_dict, name));
    apprintf("       %s", Symbol(name)->string.pointer());
  }
}

int char_map_dc::set_elements_ok(unsigned ln) {
  return part_set_window_ok(map_char_number[ln].part_number);
}

dc_ref char_map_dc:: set_elements(unsigned ln) {
  return part_set_window(map_char_number[ln].part_number);
}

int char_map_dc::usage_ok(unsigned ln) {
  return token_usage_window_ok(map_char_number[ln].token_number);
}

dc_ref char_map_dc::usage(unsigned ln) {
  return token_usage_window(map_char_number[ln].token_number);
}

static int char_set_tabs[] = {6,12, 0};

void char_set_dc::getLine(unsigned ln) const {
  int pt;
  int tn;
  int name;

  ln++;
  ssprintf("C%03d:\t",ln);
  pt = map_char_set[ln].parse_tree;
  tn = map_parse_tree[pt].token_number;
  if (tn) {
    apprintf("T%03d:\t",tn);
    name = map_token_number[tn].token_name;
  }
  else {
    acs('\t');
    name = map_parse_tree[pt].token_name;
  }
  if (name) {
    //apprintf("%s = ", dict_str(tkn_dict,name));
    apprintf("%s = ", Symbol(name)->string.pointer());
  }
  //ass(node_string(map_parse_tree[pt].tree,4).pointer());
  ass(map_parse_tree[pt].expression->asString().pointer());
}

char_set_dc::char_set_dc(void)
  : dc("Character Sets")
{
  //des->c_size = cursor_bar_size;
  des->d_size.y = char_set_dict->nsx - 1;

  tab_stops = char_set_tabs;
  columnHeadTitle = "Set\tToken\tSet Representation";
  //getWidth();
  //resize_window();
}

int char_set_dc::set_elements_ok(unsigned ln) {
  return char_set_window_ok(ln+1);
}

dc_ref char_set_dc::set_elements(unsigned ln) {
  return char_set_window(ln+1);
}

dc_ref char_set_dc::partition_sets(unsigned ln) {
  return new partition_set_dc(ln+1, AgString::format("C%03d", ln));
}

int char_set_dc::usage_ok(unsigned ln) {
  int pt = map_char_set[ln+1].parse_tree;
  return token_usage_window_ok(map_parse_tree[pt].token_number);
}

dc_ref char_set_dc::usage(unsigned ln) {
  int pt = map_char_set[ln+1].parse_tree;
  return token_usage_window(map_parse_tree[pt].token_number);
}


partition_set_dc::partition_set_dc(unsigned csn, const AgString foot)
  : dc("Partition Sets", foot)
{
  char_set_number = csn;
  des->d_size.y = map_char_set[csn].nparts;

  tab_stops = partition_set_tabs;
  columnHeadTitle = "Set\tToken";
  //getWidth();
  //des->c_size = cursor_bar_size;
  //resize_window();
}

void partition_set_dc::getLine(unsigned ln) const {
  unsigned *parts = lstptr(map_char_set[char_set_number], part);
  part_set_display(parts[ln]);
}

dc_ref partition_set_dc:: set_elements(unsigned ln) {
  unsigned *parts = lstptr(map_char_set[char_set_number], part);
  return part_set_window(parts[ln]);
}


int partition_set_dc::usage_ok(unsigned ln) {
  unsigned *parts = lstptr(map_char_set[char_set_number], part);
  return token_usage_window_ok(map_part_number[parts[ln]].token_number);
}

dc_ref partition_set_dc::usage(unsigned ln) {
  unsigned *parts = lstptr(map_char_set[char_set_number], part);
  return token_usage_window(map_part_number[parts[ln]].token_number);
}

void partition_table_dc::getLine(unsigned ln) const {
  part_set_display(ln);
}

partition_table_dc::partition_table_dc(void)
  : dc("Partition Sets")
{
  //des->c_size = cursor_bar_size;
  des->d_size.y = part_dict->nsx;

  tab_stops = partition_set_tabs;
  columnHeadTitle = "Set\tToken";
  //getWidth();
  //resize_window();
}

dc_ref partition_table_dc::set_elements(unsigned ln) {
  return part_set_window(ln);
}

int partition_table_dc::usage_ok(unsigned ln) {
  return token_usage_window_ok(map_part_number[ln].token_number);
}

dc_ref partition_table_dc::usage(unsigned ln) {
  return token_usage_window(map_part_number[ln].token_number);
}

static int set_elements_tabs[] = {5,0};
void set_elements_dc::getLine(unsigned ln) const {
  int ch = list[ln];
  int c = ch > 0 && ch < 255 ? ch : 32;
  ssprintf("%3d\t%c", ch, c);
}

set_elements_dc::set_elements_dc(unsigned *l, unsigned n, char *foot)
  : dc("Set Elements", foot)
{
  list = l;
  tab_stops = set_elements_tabs;
  columnHeadTitle = "No.\tCharacter";
  //des->c_size = cursor_bar_size;
  des->d_size.y = n;
  //getWidth();
  //resize_window();
}