1 |
jpye |
1800 |
/* ASCEND modelling environment |
2 |
|
|
Copyright (C) 2008 Carnegie Mellon University |
3 |
|
|
|
4 |
|
|
This program is free software; you can redistribute it and/or modify |
5 |
|
|
it under the terms of the GNU General Public License as published by |
6 |
|
|
the Free Software Foundation; either version 2, or (at your option) |
7 |
|
|
any later version. |
8 |
|
|
|
9 |
|
|
This program is distributed in the hope that it will be useful, |
10 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
|
|
GNU General Public License for more details. |
13 |
|
|
|
14 |
|
|
You should have received a copy of the GNU General Public License |
15 |
|
|
along with this program; if not, write to the Free Software |
16 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, |
17 |
|
|
Boston, MA 02111-1307, USA. |
18 |
|
|
*//** @file |
19 |
|
|
Query function(s) for the NOTES database in notate.h |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "notequery.h" |
23 |
|
|
#include "notate.h" |
24 |
|
|
#include "symtab.h" |
25 |
|
|
#include <utilities/error.h> |
26 |
|
|
|
27 |
|
|
const char *notes_get_for_variable(symchar *dbid |
28 |
|
|
, const struct TypeDescription *t |
29 |
|
|
, const symchar *varname |
30 |
|
|
, const symchar *notetype |
31 |
|
|
){ |
32 |
|
|
struct gl_list_t *noteslist; |
33 |
|
|
|
34 |
|
|
struct gl_list_t *types = GetAncestorNames(t); |
35 |
|
|
struct gl_list_t *langs = gl_create(1); |
36 |
|
|
struct gl_list_t *ids = gl_create(1); |
37 |
|
|
|
38 |
|
|
int i; |
39 |
|
|
for(i=1; i<=gl_length(types); ++i){ |
40 |
|
|
CONSOLE_DEBUG("ancestor %d: %s",i,SCP((symchar *)gl_fetch(types,i))); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
symchar *inl = AddSymbol("inline"); |
44 |
|
|
gl_append_ptr(langs,(VOIDPTR)inl); |
45 |
|
|
|
46 |
|
|
gl_append_ptr(ids,(VOIDPTR)varname); |
47 |
|
|
|
48 |
|
|
noteslist = GetNotesList(dbid,types,langs,ids,NOTESWILDLIST,NOTESWILDLIST); |
49 |
|
|
|
50 |
jpye |
1925 |
gl_destroy(types); |
51 |
|
|
gl_destroy(langs); |
52 |
|
|
gl_destroy(ids); |
53 |
|
|
|
54 |
jpye |
1800 |
CONSOLE_DEBUG("noteslist = %ld items",gl_length(noteslist)); |
55 |
|
|
|
56 |
|
|
if(gl_length(noteslist)==0){ |
57 |
|
|
CONSOLE_DEBUG("empty notes list returned"); |
58 |
|
|
return NULL; |
59 |
|
|
} |
60 |
|
|
struct Note *n = (struct Note *)gl_fetch(noteslist,1); |
61 |
|
|
|
62 |
|
|
CONSOLE_DEBUG("note ID = %s, lang = %s",SCP(GetNoteId(n)),SCP(GetNoteLanguage(n))); |
63 |
|
|
|
64 |
|
|
CONSOLE_DEBUG("note text = %s",BraceCharString(GetNoteText(n))); |
65 |
|
|
|
66 |
|
|
return BraceCharString(GetNoteText(n)); |
67 |
|
|
} |
68 |
|
|
|
69 |
jpye |
1925 |
struct gl_list_t *notes_get_vars_with_notetype( |
70 |
|
|
symchar *dbid |
71 |
|
|
, const struct TypeDescription *t |
72 |
|
|
, const symchar *notetype |
73 |
|
|
){ |
74 |
|
|
int i; |
75 |
|
|
struct gl_list_t *noteslist; |
76 |
|
|
struct gl_list_t *refinednoteslist = gl_create(1); |
77 |
|
|
|
78 |
|
|
struct gl_list_t *types = GetAncestorNames(t); |
79 |
|
|
struct gl_list_t *langs = gl_create(1); |
80 |
|
|
struct gl_list_t *ids = gl_create(1); |
81 |
|
|
#if 0 |
82 |
|
|
CONSOLE_DEBUG("type '%s' has %ld ancestor types",SCP(GetName(t)),gl_length(types)); |
83 |
|
|
for(i=1; i<=gl_length(types); ++i){ |
84 |
|
|
CONSOLE_DEBUG("ancestor %d: %s",i,SCP((symchar *)gl_fetch(types,i))); |
85 |
|
|
} |
86 |
|
|
#endif |
87 |
|
|
|
88 |
|
|
/*CONSOLE_DEBUG("Looking for notes of type '%s'",SCP(notetype));*/ |
89 |
|
|
gl_append_ptr(langs,(VOIDPTR)notetype); |
90 |
|
|
|
91 |
|
|
/* create a new list with our top-level type at the start */ |
92 |
|
|
struct gl_list_t *typesall = gl_create(1); |
93 |
|
|
gl_append_ptr(typesall,(VOIDPTR)t); |
94 |
|
|
for(i=1;i<=gl_length(types);++i){ |
95 |
|
|
//CONSOLE_DEBUG("Appending '%s' to typesall",SCP(GetName((struct TypeDescription *)gl_fetch(types,i)))); |
96 |
|
|
gl_append_ptr(typesall,gl_fetch(types,i)); |
97 |
|
|
} |
98 |
|
|
/* CONSOLE_DEBUG("length of types = %ld, typesall = %ld",gl_length(types), gl_length(typesall));*/ |
99 |
|
|
|
100 |
|
|
gl_destroy(types); |
101 |
|
|
|
102 |
|
|
noteslist = GetNotesList(dbid,typesall,langs,NOTESWILDLIST,NOTESWILDLIST,NOTESWILDLIST); |
103 |
|
|
|
104 |
|
|
gl_destroy(typesall); |
105 |
|
|
gl_destroy(langs); |
106 |
|
|
|
107 |
|
|
/*CONSOLE_DEBUG("noteslist = %ld items",gl_length(noteslist));*/ |
108 |
|
|
|
109 |
|
|
const symchar *lastid = NULL; |
110 |
|
|
for(i=1; i<=gl_length(noteslist); ++i){ |
111 |
|
|
struct Note *n = (struct Note *)gl_fetch(noteslist,i); |
112 |
|
|
/* CONSOLE_DEBUG("note ID = %s, lastid = %s",GetNoteId(n),lastid); */ |
113 |
|
|
if(!lastid || lastid != GetNoteId(n)){ |
114 |
|
|
gl_append_ptr(refinednoteslist,(VOIDPTR)n); |
115 |
|
|
lastid = GetNoteId(n); |
116 |
|
|
} |
117 |
|
|
} |
118 |
|
|
gl_destroy(noteslist); |
119 |
|
|
|
120 |
|
|
if(gl_length(refinednoteslist)==0){ |
121 |
|
|
gl_destroy(refinednoteslist); |
122 |
|
|
/* CONSOLE_DEBUG("empty notes list returned"); */ |
123 |
|
|
return NULL; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
return refinednoteslist; |
127 |
|
|
} |
128 |
|
|
|