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 |
jpye |
1926 |
#include "cmpfunc.h" |
26 |
jpye |
1800 |
#include <utilities/error.h> |
27 |
|
|
|
28 |
|
|
const char *notes_get_for_variable(symchar *dbid |
29 |
|
|
, const struct TypeDescription *t |
30 |
|
|
, const symchar *varname |
31 |
|
|
, const symchar *notetype |
32 |
|
|
){ |
33 |
|
|
struct gl_list_t *noteslist; |
34 |
|
|
|
35 |
|
|
struct gl_list_t *types = GetAncestorNames(t); |
36 |
|
|
struct gl_list_t *langs = gl_create(1); |
37 |
|
|
struct gl_list_t *ids = gl_create(1); |
38 |
|
|
|
39 |
|
|
int i; |
40 |
|
|
for(i=1; i<=gl_length(types); ++i){ |
41 |
|
|
CONSOLE_DEBUG("ancestor %d: %s",i,SCP((symchar *)gl_fetch(types,i))); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
symchar *inl = AddSymbol("inline"); |
45 |
|
|
gl_append_ptr(langs,(VOIDPTR)inl); |
46 |
|
|
|
47 |
|
|
gl_append_ptr(ids,(VOIDPTR)varname); |
48 |
|
|
|
49 |
|
|
noteslist = GetNotesList(dbid,types,langs,ids,NOTESWILDLIST,NOTESWILDLIST); |
50 |
|
|
|
51 |
jpye |
1925 |
gl_destroy(types); |
52 |
|
|
gl_destroy(langs); |
53 |
|
|
gl_destroy(ids); |
54 |
|
|
|
55 |
jpye |
1800 |
CONSOLE_DEBUG("noteslist = %ld items",gl_length(noteslist)); |
56 |
|
|
|
57 |
|
|
if(gl_length(noteslist)==0){ |
58 |
|
|
CONSOLE_DEBUG("empty notes list returned"); |
59 |
|
|
return NULL; |
60 |
|
|
} |
61 |
|
|
struct Note *n = (struct Note *)gl_fetch(noteslist,1); |
62 |
|
|
|
63 |
|
|
CONSOLE_DEBUG("note ID = %s, lang = %s",SCP(GetNoteId(n)),SCP(GetNoteLanguage(n))); |
64 |
|
|
|
65 |
|
|
CONSOLE_DEBUG("note text = %s",BraceCharString(GetNoteText(n))); |
66 |
|
|
|
67 |
|
|
return BraceCharString(GetNoteText(n)); |
68 |
|
|
} |
69 |
|
|
|
70 |
jpye |
1925 |
struct gl_list_t *notes_get_vars_with_notetype( |
71 |
|
|
symchar *dbid |
72 |
|
|
, const struct TypeDescription *t |
73 |
|
|
, const symchar *notetype |
74 |
|
|
){ |
75 |
|
|
int i; |
76 |
|
|
struct gl_list_t *noteslist; |
77 |
jpye |
1926 |
struct gl_list_t *refinednoteslist; |
78 |
jpye |
1925 |
|
79 |
|
|
struct gl_list_t *types = GetAncestorNames(t); |
80 |
|
|
struct gl_list_t *langs = gl_create(1); |
81 |
jpye |
1926 |
|
82 |
jpye |
1925 |
#if 0 |
83 |
|
|
CONSOLE_DEBUG("type '%s' has %ld ancestor types",SCP(GetName(t)),gl_length(types)); |
84 |
|
|
for(i=1; i<=gl_length(types); ++i){ |
85 |
|
|
CONSOLE_DEBUG("ancestor %d: %s",i,SCP((symchar *)gl_fetch(types,i))); |
86 |
|
|
} |
87 |
|
|
#endif |
88 |
|
|
|
89 |
|
|
/*CONSOLE_DEBUG("Looking for notes of type '%s'",SCP(notetype));*/ |
90 |
|
|
gl_append_ptr(langs,(VOIDPTR)notetype); |
91 |
|
|
|
92 |
|
|
/* create a new list with our top-level type at the start */ |
93 |
jpye |
1926 |
struct gl_list_t *typesall = gl_create(1 + gl_length(types)); |
94 |
jpye |
1925 |
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 |
jpye |
1926 |
gl_append_ptr(typesall,(VOIDPTR)GetName(t)); |
99 |
|
|
/* CONSOLE_DEBUG("length of types = %ld, typesall = %ld",gl_length(types), gl_length(typesall)); */ |
100 |
jpye |
1925 |
|
101 |
|
|
gl_destroy(types); |
102 |
|
|
|
103 |
jpye |
1926 |
#if 0 |
104 |
|
|
for(i=1;i<=gl_length(typesall);++i){ |
105 |
|
|
struct TypeDescription *t; |
106 |
|
|
CONSOLE_DEBUG("typesall[%d] = '%s'",i,SCP((symchar *)gl_fetch(typesall,i))); |
107 |
|
|
} |
108 |
|
|
#endif |
109 |
|
|
|
110 |
jpye |
1925 |
noteslist = GetNotesList(dbid,typesall,langs,NOTESWILDLIST,NOTESWILDLIST,NOTESWILDLIST); |
111 |
|
|
|
112 |
|
|
gl_destroy(typesall); |
113 |
|
|
gl_destroy(langs); |
114 |
|
|
|
115 |
jpye |
1926 |
/* CONSOLE_DEBUG("noteslist = %ld items",gl_length(noteslist)); */ |
116 |
jpye |
1925 |
|
117 |
jpye |
1926 |
refinednoteslist = gl_create(gl_length(noteslist)); |
118 |
|
|
|
119 |
jpye |
1925 |
const symchar *lastid = NULL; |
120 |
jpye |
1926 |
/* CONSOLE_DEBUG("refinednotes list has %ld elements",gl_length(refinednoteslist)); */ |
121 |
jpye |
1925 |
for(i=1; i<=gl_length(noteslist); ++i){ |
122 |
|
|
struct Note *n = (struct Note *)gl_fetch(noteslist,i); |
123 |
jpye |
1926 |
if(GetNoteId(n)==NULL)continue; |
124 |
|
|
|
125 |
|
|
gl_append_ptr(refinednoteslist,(VOIDPTR)n); |
126 |
|
|
lastid = GetNoteId(n); |
127 |
jpye |
1925 |
} |
128 |
|
|
gl_destroy(noteslist); |
129 |
|
|
|
130 |
|
|
if(gl_length(refinednoteslist)==0){ |
131 |
|
|
gl_destroy(refinednoteslist); |
132 |
jpye |
1926 |
CONSOLE_DEBUG("empty notes list returned"); |
133 |
jpye |
1925 |
return NULL; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
return refinednoteslist; |
137 |
|
|
} |
138 |
|
|
|