comparison anagram/agcore/engdef.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
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 2006 David A. Holland. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * engdef.cpp - engine definition file
7 *
8 * This file obsoletes the external AnaGram.cgb file found
9 * in older versions of AnaGram.
10 */
11
12 #include <stdlib.h>
13 #include <string.h>
14 #include "port.h" // for OPTLINK
15
16 #include "engdef.h"
17
18 //#define INCLUDE_LOGGING
19 #include "log.h"
20
21
22 #include "engine.h"
23
24
25 static int OPTLINK cgtable_sort(const void *ventrya, const void *ventryb) {
26 const cgentry *entrya = (const cgentry *)ventrya;
27 const cgentry *entryb = (const cgentry *)ventryb;
28 return strcmp(entrya->name, entryb->name);
29 }
30
31 static int OPTLINK cgtable_search(const void *vkey, const void *ventryb) {
32 const char *key = (const char *)vkey;
33 const cgentry *entryb = (const cgentry *)ventryb;
34 return strcmp(key, entryb->name);
35 }
36
37 void engdef_init(void) {
38 LOGSECTION("engdef_init");
39 qsort(cgtable, cgtablenum, sizeof(cgtable[0]), cgtable_sort);
40 }
41
42 const char *engdef_get(const char *key) {
43 const void *ventry;
44 const cgentry *entry;
45 ventry = bsearch(key, cgtable, cgtablenum, sizeof(cgtable[0]),
46 cgtable_search);
47 if (!ventry) {
48 //fprintf(stderr, "warning: cgb key <%s> not found\n", key);
49 return "";
50 }
51 entry = (const cgentry *)ventry;
52 return entry->data;
53 }