1 /*******************************************************
3 * a56 - a DSP56001 assembler
5 * Written by Quinn C. Jensen
8 *******************************************************\
11 * Copyright (C) 2008 Robert Millan <rmh@aybabtu.com>
12 * Copyright (C) 2012 Thorsten Alteholz <debian@alteholz.de>
14 * This file is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published
16 * by the Free Software Foundation, either version 3 of the License,
17 * or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see
26 * <http://www.gnu.org/licenses/>.
28 * This file incorporates work covered by the following copyright and
31 * Copyright (C) 1990-1994 Quinn C. Jensen
33 * Permission to use, copy, modify, distribute, and sell this software
34 * and its documentation for any purpose is hereby granted without fee,
35 * provided that the above copyright notice appear in all copies and
36 * that both that copyright notice and this permission notice appear
37 * in supporting documentation. The author makes no representations
38 * about the suitability of this software for any purpose. It is
39 * provided "as is" without express or implied warranty.
42 static char *Copyright = "Copyright (C) 1990-1994 Quinn C. Jensen";
45 * subs.c - Some subroutines for the assembler.
58 if(strcmp(file, "-") == 0)
60 else if ((fp = fopen(file, "r")) == NULL) {
67 FILE *open_write(file)
71 if ((fp = fopen(file, "w")) == NULL) {
78 FILE *open_append(file)
82 if ((fp = fopen(file, "a")) == NULL) {
89 fatal(c, a1, a2, a3, a4, a5, a6, a7, a8)
90 char *c, *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
92 fprintf(stderr, c, a1, a2, a3, a4, a5, a6, a7, a8);
99 char tabbuf[MAX_BUF], *untabn();
100 char *untab(s) /* expand tabs in s */
103 return untabn(s, TABS);
106 char *untabn(s, stops) /* expand tabs in s */
112 /* copy input string into buffer to scan while input string is modified */
114 register char *b = tabbuf;
116 strncpy(b, s, MAX_BUF);
118 /* iterate until the copy of the input string is depleted */
124 while ((++s - o) % stops);
131 /* null terminate the resultant string */
141 char *p = (char *)malloc(size);
143 fatal("alloc: insufficient virtual memory to allocate %d bytes\n",
149 ((c) >= 'a' ? (c) - 'a' + 10 : ((c) >= 'A' ? (c) - 'A' + 10 : (c) - '0'))
151 #define valid(c) ((c) >= '0' && (c) <= '9' || \
152 (c) >= 'A' && (c) <= 'Z' || \
153 (c) >= 'a' && (c) <= 'z')
155 a56_strtol(s, p, base)
156 register char *s, **p;
159 register long result = 0;
160 register int sign = 0;
162 while(*s == ' ' || *s == '\t')
171 register int dig = ascii2n(*s);
182 return sign ? -result : result;