1
0
mirror of https://github.com/fachat/xa65.git synced 2024-06-25 17:29:35 +00:00
xa65/xa/src/xau.c

74 lines
1.9 KiB
C
Raw Normal View History

2011-12-16 22:04:51 +00:00
/* xa65 - 65xx/65816 cross-assembler and utility suite
*
2023-12-07 22:28:55 +00:00
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (fachat@web.de)
2011-12-16 22:04:51 +00:00
*
* Undefined label tracking module (also see xal.c)
*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include "xad.h"
#include "xau.h"
#include "xah.h"
#include "xal.h"
2023-11-19 20:24:38 +00:00
#undef DEBUG_UNDEF
2011-12-16 22:04:51 +00:00
int u_label(int labnr) {
int i;
2023-11-19 20:24:38 +00:00
#ifdef DEBUG_UNDEF
printf("u_label: %d\n",labnr);
#endif
2023-12-07 22:28:55 +00:00
if (!afile->ud.ulist) {
afile->ud.ulist = malloc(200 * sizeof(int));
if (afile->ud.ulist)
afile->ud.um = 200;
2011-12-16 22:04:51 +00:00
}
2023-12-07 22:28:55 +00:00
for (i = 0; i < afile->ud.un; i++) {
if (afile->ud.ulist[i] == labnr)
return i;
2011-12-16 22:04:51 +00:00
}
2023-12-07 22:28:55 +00:00
if (afile->ud.un >= afile->ud.um) {
afile->ud.um *= 1.5;
afile->ud.ulist = realloc(afile->ud.ulist, afile->ud.um * sizeof(int));
if (!afile->ud.ulist) {
fprintf(stderr, "Panic: No memory!\n");
exit(1);
}
2011-12-16 22:04:51 +00:00
}
afile->ud.ulist[afile->ud.un] = labnr;
return afile->ud.un++;
}
void u_write(FILE *fp) {
int i, d;
char *s;
2023-12-07 22:28:55 +00:00
/*printf("u_write: un=%d\n",afile->ud.un);*/
2011-12-16 22:04:51 +00:00
fputw(afile->ud.un, fp);
2023-12-07 22:28:55 +00:00
for (i = 0; i < afile->ud.un; i++) {
l_vget(afile->ud.ulist[i], &d, &s);
fprintf(fp, "%s", s);
fputc(0, fp);
2011-12-16 22:04:51 +00:00
}
free(afile->ud.ulist);
2023-12-07 22:28:55 +00:00
afile->ud.ulist = NULL;
2011-12-16 22:04:51 +00:00
afile->ud.um = afile->ud.un = 0;
}