1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/*
* This source code is part of hsc, a html-preprocessor,
* Copyright (C) 1995-1998 Thomas Aglassinger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
* hsclib/idref.c
*
* functions for id-references
*
* updated: 14-Oct-1996
* created: 12-Apr-1995
*
*/
#include "hsclib/inc_base.h"
#include <stdarg.h>
#include "ugly/ustrlist.h"
#include "hscprj/document.h"
#define NOEXTERN_HSCLIB_ID_H
#include "hsclib/idref.h"
#if DEBUG_ID
#define DIHP(x) if ( hp->debug ) x
#define DI(x) x
#else
#define DIHP(x) /* nufin */
#define DI(x) /* nufin */
#endif
/* hsc_msg_unknown_id: warning about unknown id-refrence */
VOID hsc_msg_unknown_id(HSCPRC * hp, STRPTR filename, STRPTR id)
{
if (filename)
hsc_message(hp, MSG_UNKN_ID, "unknown id `%s#%s'",
filename, id);
else
hsc_message(hp, MSG_UNKN_ID, "unknown id %q", id);
}
/* macros for local compare-callbacks */
#define cmp_idname cmp_string_node
#define cmp_idref cmp_string_node
#define cmp_id_local cmp_string_node
/*
*
* new- and del-methodes
*
*/
/*
* del/new_idref
*/
/* del_idref: remove referenced id */
VOID del_idref(APTR data)
{
IDREF *idref = (IDREF *) data;
ufreestr(idref->name);
del_infilepos(idref->fpos);
ufree(idref);
}
/* new_id_local: create new reference to local id */
static IDREF *new_idref(STRPTR id, INFILEPOS * fpos)
{
IDREF *newid = (IDREF *) umalloc(sizeof(IDREF));
newid->name = strclone(id);
newid->fpos = fpos;
return (newid);
}
VOID prt_idref(FILE * stream, APTR data)
{
IDREF *idref = (IDREF *) data;
INFILEPOS *fpos = idref->fpos;
fprintf(stream, "`%s' at (%lu,%lu)\n",
idref->name, ifp_get_y(fpos), ifp_get_x(fpos));
}
/*
* add_local_iddef
*
* define a new local ID that can be refered to
*/
BOOL add_local_iddef(HSCPRC * hp, STRPTR id)
{
INFILEPOS *fpos = new_infilepos(hp->inpf);
HSCIDD *iddef = find_iddef(hp->project->document, id);
DIHP(fprintf(stderr, DHL "add ref to id `%s' at `%s' (%lu,%lu)\n",
id, ifp_get_fname(fpos),
ifp_get_y(fpos), ifp_get_x(fpos)));
/* check for duplicate definition */
if (iddef)
{
/* duplicate definition */
DIHP(fprintf(stderr, DHL " duplicate definition\n"));
hsc_message(hp, MSG_REDEFINE_ID,
"local id %q already declared", id);
set_infilepos(hp->inpf, iddef->fpos);
hsc_message(hp, MSG_REDEFINE_ID,
"(location of previous declaration)");
set_infilepos(hp->inpf, fpos);
del_infilepos(fpos);
}
else
{
/* remember new local id */
iddef = app_iddef(hp->project->document, id);
iddef->caller = fpos2caller(fpos);
iddef->fpos = fpos;
DIHP(fprintf(stderr, DHL " append to local iddefs\n"));
}
return (TRUE);
}
/*
* check_id_local
*
* append id to idref-list so it as checked when
* check_all_local_idref() is called
*/
VOID add_local_idref(HSCPRC * hp, STRPTR id)
{
INFILEPOS *fpos = new_infilepos(hp->inpf);
DIHP(fprintf(stderr, DHL " check id: `#%s' (local)\n", id));
DIHP(fprintf(stderr, DHL " append to idref\n"));
app_dlnode(hp->idrefs, new_idref(id, fpos));
}
/*
* check_local_idref
*/
static BOOL check_local_idref(HSCPRC * hp, IDREF * idref)
{
HSCIDD *iddef = find_iddef(hp->project->document, idref->name);
BOOL found = FALSE;
if (iddef)
{
found = TRUE;
DIHP(fprintf(stderr, DHL " local id ok: `%s'\n", idref->name));
}
else
{
DIHP(
{
INFILEPOS * fpos = idref->fpos;
fprintf(stderr, DHL " local id unknown: `%s' (%lu,%lu)\n",
idref->name, ifp_get_y(fpos), ifp_get_x(fpos));
}
);
set_infilepos(hp->inpf, idref->fpos);
hsc_msg_unknown_id(hp, NULL, idref->name);
}
return (found);
}
/*
* check_all_local_idref
*/
BOOL check_all_local_idref(HSCPRC * hp)
{
BOOL ok = TRUE;
DLNODE *nd = NULL;
INFILEPOS *infpos = new_infilepos(hp->inpf);
DIHP(fprintf(stderr, DHL "check local IDs\n"));
DIHP(
{
fprintf(stderr, DHL " local IDs defined:\n");
fprintf_dllist(stderr, hp->project->document->iddefs, prt_iddef);
fprintf(stderr, DHL " local IDs referenced:\n");
fprintf_dllist(stderr, hp->idrefs, prt_idref);
}
);
nd = dll_first(hp->idrefs);
while (nd)
{
check_local_idref(hp, ((IDREF *) nd->data));
nd = dln_next(nd);
}
set_infilepos(hp->inpf, infpos);
del_infilepos(infpos);
return (ok);
}
|