-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinsert_id.c
More file actions
91 lines (81 loc) · 3.01 KB
/
insert_id.c
File metadata and controls
91 lines (81 loc) · 3.01 KB
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
/*
insert_id.c - Part of llf, a cross linker. Part of the macxx tool chain.
Copyright (C) 2008 David Shepperd
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h> /* get standard I/O definitions */
#include "token.h" /* define compile time constants */
#include "structs.h" /* define structures */
#include "header.h" /* get the common stuff */
/***************************************************************
*
* void insert_id(numeric_id,ptr_to_sym_struct)
* int32_t numeric_id;
* struct seg_struct *ptr_to_sym_struct;
*
* This routine inserts into the ID table at the offset spec'd by
* the first argument the symbol block pointer passed as the
* second argument. It will increase the size of the ID table
* if required.
*
* Routine returns void. To retrieve an ID from the table,
* use *(id_table[id_table_base+desired_id])
***************************************************************/
/* Global static variables */
struct ss_struct **id_table = 0; /* pointer to identifier table */
int32_t id_table_size=0; /* size of id_table in int's */
int32_t id_table_base=0; /* base for the current file */
int32_t tot_ids,max_idu;
/* Entry */
void insert_id( int32_t id, SS_struct *id_ptr)
{
struct ss_struct **st,*sp; /* st is pointer to pointer to ss_struct */
int32_t idx,kk;
idx = id+id_table_base;
if (idx >= id_table_size)
{
kk = (idx/1024+1)*1024;
if (id_table == 0)
{ /* first time, build an array */
if (kk < 28672/sizeof(char *))
kk = 28672/sizeof(char *);
id_table_size = kk;
id_table = (SS_struct **)MEM_calloc(id_table_size, sizeof(SS_struct **));
}
else
{
int old_sz;
old_sz = id_table_size;
id_table_size = kk;
id_table = (SS_struct **)MEM_realloc((char *)id_table, id_table_size*sizeof(SS_struct **));
while (old_sz<id_table_size)
id_table[old_sz++] = NULL;
}
}
if (idx > max_idu)
max_idu = idx;
st = id_table+idx;
sp = *st;
if ( sp )
{
if (sp == id_ptr)
{ /* reinsertion of the same ID */
return; /* is ok */
}
sprintf (emsg,"ID number %d redefined in %s\n\tPreviously defined to {%s} in file %s",
id,current_fnd->fn_buff,sp->ss_string,sp->ss_fnd->fn_buff);
err_msg(MSG_WARN,emsg);
}
tot_ids++;
*st = id_ptr;
return;
}