view anagram/agcore/engdef.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 2006 David A. Holland. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * engdef.cpp - engine definition file
 *
 * This file obsoletes the external AnaGram.cgb file found
 * in older versions of AnaGram.
 */

#include <stdlib.h>
#include <string.h>
#include "port.h" // for OPTLINK

#include "engdef.h"

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


#include "engine.h"


static int OPTLINK cgtable_sort(const void *ventrya, const void *ventryb) {
  const cgentry *entrya = (const cgentry *)ventrya;
  const cgentry *entryb = (const cgentry *)ventryb;
  return strcmp(entrya->name, entryb->name);
}

static int OPTLINK cgtable_search(const void *vkey, const void *ventryb) {
  const char *key = (const char *)vkey;
  const cgentry *entryb = (const cgentry *)ventryb;
  return strcmp(key, entryb->name);
}

void engdef_init(void) {
  LOGSECTION("engdef_init");
  qsort(cgtable, cgtablenum, sizeof(cgtable[0]), cgtable_sort);
}

const char *engdef_get(const char *key) {
  const void *ventry;
  const cgentry *entry;
  ventry = bsearch(key, cgtable, cgtablenum, sizeof(cgtable[0]),
		   cgtable_search);
  if (!ventry) {
    //fprintf(stderr, "warning: cgb key <%s> not found\n", key);
    return "";
  }
  entry = (const cgentry *)ventry;
  return entry->data;
}