]>
git.saurik.com Git - apple/boot.git/blob - i386/nasm/nasmlib.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* nasmlib.c library routines for the Netwide Assembler
27 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
28 * Julian Hall. All rights reserved. The software is
29 * redistributable under the licence given in the file "Licence"
30 * distributed in the NASM archive.
41 static efunc nasm_malloc_error
;
47 void nasm_set_malloc_error (efunc error
) {
48 nasm_malloc_error
= error
;
50 logfp
= fopen ("malloc.log", "w");
51 setvbuf (logfp
, NULL
, _IOLBF
, BUFSIZ
);
52 fprintf (logfp
, "null pointer is %p\n", NULL
);
57 void *nasm_malloc_log (char *file
, int line
, size_t size
)
59 void *nasm_malloc (size_t size
)
62 void *p
= malloc(size
);
64 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
67 fprintf(logfp
, "%s %d malloc(%ld) returns %p\n",
68 file
, line
, (long)size
, p
);
74 void *nasm_realloc_log (char *file
, int line
, void *q
, size_t size
)
76 void *nasm_realloc (void *q
, size_t size
)
79 void *p
= q
? realloc(q
, size
) : malloc(size
);
81 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
84 fprintf(logfp
, "%s %d realloc(%p,%ld) returns %p\n",
85 file
, line
, q
, (long)size
, p
);
87 fprintf(logfp
, "%s %d malloc(%ld) returns %p\n",
88 file
, line
, (long)size
, p
);
94 void nasm_free_log (char *file
, int line
, void *q
)
96 void nasm_free (void *q
)
102 fprintf(logfp
, "%s %d free(%p)\n",
109 char *nasm_strdup_log (char *file
, int line
, char *s
)
111 char *nasm_strdup (char *s
)
115 int size
= strlen(s
)+1;
119 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
122 fprintf(logfp
, "%s %d strdup(%ld) returns %p\n",
123 file
, line
, (long)size
, p
);
130 char *nasm_strndup_log (char *file
, int line
, char *s
, size_t len
)
132 char *nasm_strndup (char *s
, size_t len
)
140 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
143 fprintf(logfp
, "%s %d strndup(%ld) returns %p\n",
144 file
, line
, (long)size
, p
);
151 int nasm_stricmp (char *s1
, char *s2
) {
152 while (*s1
&& toupper(*s1
) == toupper(*s2
))
156 else if (toupper(*s1
) < toupper(*s2
))
162 int nasm_strnicmp (char *s1
, char *s2
, int n
) {
163 while (n
> 0 && *s1
&& toupper(*s1
) == toupper(*s2
))
165 if ((!*s1
&& !*s2
) || n
==0)
167 else if (toupper(*s1
) < toupper(*s2
))
173 #define lib_isnumchar(c) ( isalnum(c) || (c) == '$')
174 #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
176 long readnum (char *str
, int *error
) {
179 unsigned long result
, checklimit
;
184 while (isspace(*r
)) r
++; /* find start of number */
187 while (lib_isnumchar(*q
)) q
++; /* find end of number */
190 * If it begins 0x, 0X or $, or ends in H, it's in hex. if it
191 * ends in Q, it's octal. if it ends in B, it's binary.
192 * Otherwise, it's ordinary decimal.
194 if (*r
=='0' && (r
[1]=='x' || r
[1]=='X'))
198 else if (q
[-1]=='H' || q
[-1]=='h')
200 else if (q
[-1]=='Q' || q
[-1]=='q')
202 else if (q
[-1]=='B' || q
[-1]=='b')
208 * If this number has been found for us by something other than
209 * the ordinary scanners, then it might be malformed by having
210 * nothing between the prefix and the suffix. Check this case
219 * `checklimit' must be 2**32 / radix. We can't do that in
220 * 32-bit arithmetic, which we're (probably) using, so we
221 * cheat: since we know that all radices we use are even, we
222 * can divide 2**31 by radix/2 instead.
224 checklimit
= 0x80000000UL
/ (radix
>>1);
227 while (*r
&& r
< q
) {
228 if (*r
<'0' || (*r
>'9' && *r
<'A') || numvalue(*r
)>=radix
) {
232 if (result
>= checklimit
)
234 result
= radix
* result
+ numvalue(*r
);
239 nasm_malloc_error (ERR_WARNING
| ERR_PASS1
| ERR_WARN_NOV
,
240 "numeric constant %s does not fit in 32 bits",
246 static long next_seg
;
248 void seg_init(void) {
252 long seg_alloc(void) {
253 return (next_seg
+= 2) - 2;
256 void fwriteshort (int data
, FILE *fp
) {
257 fputc ((int) (data
& 255), fp
);
258 fputc ((int) ((data
>> 8) & 255), fp
);
261 void fwritelong (long data
, FILE *fp
) {
262 fputc ((int) (data
& 255), fp
);
263 fputc ((int) ((data
>> 8) & 255), fp
);
264 fputc ((int) ((data
>> 16) & 255), fp
);
265 fputc ((int) ((data
>> 24) & 255), fp
);
268 void standard_extension (char *inname
, char *outname
, char *extension
,
272 if (*outname
) /* file name already exists, */
273 return; /* so do nothing */
276 while (*q
) *p
++ = *q
++; /* copy, and find end of string */
277 *p
= '\0'; /* terminate it */
278 while (p
> outname
&& *--p
!= '.');/* find final period (or whatever) */
279 if (*p
!= '.') while (*p
) p
++; /* go back to end if none found */
280 if (!strcmp(p
, extension
)) { /* is the extension already there? */
282 error(ERR_WARNING
| ERR_NOFILE
,
283 "file name already ends in `%s': "
284 "output will be in `nasm.out'",
287 error(ERR_WARNING
| ERR_NOFILE
,
288 "file name already has no extension: "
289 "output will be in `nasm.out'");
290 strcpy(outname
, "nasm.out");
292 strcpy(p
, extension
);
295 #define RAA_BLKSIZE 4096 /* this many longs allocated at once */
296 #define RAA_LAYERSIZE 1024 /* this many _pointers_ allocated */
298 typedef struct RAA RAA
;
299 typedef union RAA_UNION RAA_UNION
;
300 typedef struct RAA_LEAF RAA_LEAF
;
301 typedef struct RAA_BRANCH RAA_BRANCH
;
305 * Number of layers below this one to get to the real data. 0
306 * means this structure is a leaf, holding RAA_BLKSIZE real
307 * data items; 1 and above mean it's a branch, holding
308 * RAA_LAYERSIZE pointers to the next level branch or leaf
313 * Number of real data items spanned by one position in the
314 * `data' array at this level. This number is 1, trivially, for
315 * a leaf (level 0): for a level 1 branch it should be
316 * RAA_BLKSIZE, and for a level 2 branch it's
317 * RAA_LAYERSIZE*RAA_BLKSIZE.
322 long data
[RAA_BLKSIZE
];
325 struct RAA
*data
[RAA_LAYERSIZE
];
330 #define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
331 #define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
333 #define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
335 static struct RAA
*real_raa_init (int layers
) {
339 r
= nasm_malloc (LEAFSIZ
);
340 memset (r
->u
.l
.data
, 0, sizeof(r
->u
.l
.data
));
344 r
= nasm_malloc (BRANCHSIZ
);
345 memset (r
->u
.b
.data
, 0, sizeof(r
->u
.b
.data
));
347 r
->stepsize
= RAA_BLKSIZE
;
349 r
->stepsize
*= RAA_LAYERSIZE
;
354 struct RAA
*raa_init (void) {
355 return real_raa_init (0);
358 void raa_free (struct RAA
*r
) {
363 for (p
= r
->u
.b
.data
; p
- r
->u
.b
.data
< RAA_LAYERSIZE
; p
++)
369 long raa_read (struct RAA
*r
, long posn
) {
370 if (posn
> r
->stepsize
* LAYERSIZ(r
))
372 while (r
->layers
> 0) {
374 l
= ldiv (posn
, r
->stepsize
);
375 r
= r
->u
.b
.data
[l
.quot
];
377 if (!r
) /* better check this */
380 return r
->u
.l
.data
[posn
];
383 struct RAA
*raa_write (struct RAA
*r
, long posn
, long value
) {
387 nasm_malloc_error (ERR_PANIC
, "negative position in raa_write");
389 while (r
->stepsize
* LAYERSIZ(r
) < posn
) {
391 * Must go up a layer.
395 s
= nasm_malloc (BRANCHSIZ
);
396 memset (s
->u
.b
.data
, 0, sizeof(r
->u
.b
.data
));
397 s
->layers
= r
->layers
+ 1;
398 s
->stepsize
= RAA_LAYERSIZE
* r
->stepsize
;
405 while (r
->layers
> 0) {
408 l
= ldiv (posn
, r
->stepsize
);
409 s
= &r
->u
.b
.data
[l
.quot
];
411 *s
= real_raa_init (r
->layers
- 1);
416 r
->u
.l
.data
[posn
] = value
;
421 #define SAA_MAXLEN 8192
425 * members `end' and `elem_len' are only valid in first link in
426 * list; `rptr' and `rpos' are used for reading
428 struct SAA
*next
, *end
, *rptr
;
429 long elem_len
, length
, posn
, start
, rpos
;
433 struct SAA
*saa_init (long elem_len
) {
436 if (elem_len
> SAA_MAXLEN
)
437 nasm_malloc_error (ERR_PANIC
| ERR_NOFILE
, "SAA with huge elements");
439 s
= nasm_malloc (sizeof(struct SAA
));
440 s
->posn
= s
->start
= 0L;
441 s
->elem_len
= elem_len
;
442 s
->length
= SAA_MAXLEN
- (SAA_MAXLEN
% elem_len
);
443 s
->data
= nasm_malloc (s
->length
);
450 void saa_free (struct SAA
*s
) {
461 void *saa_wstruct (struct SAA
*s
) {
464 if (s
->end
->length
- s
->end
->posn
< s
->elem_len
) {
465 s
->end
->next
= nasm_malloc (sizeof(struct SAA
));
466 s
->end
->next
->start
= s
->end
->start
+ s
->end
->posn
;
467 s
->end
= s
->end
->next
;
468 s
->end
->length
= s
->length
;
471 s
->end
->data
= nasm_malloc (s
->length
);
474 p
= s
->end
->data
+ s
->end
->posn
;
475 s
->end
->posn
+= s
->elem_len
;
479 void saa_wbytes (struct SAA
*s
, void *data
, long len
) {
483 long l
= s
->end
->length
- s
->end
->posn
;
488 memcpy (s
->end
->data
+ s
->end
->posn
, d
, l
);
491 memset (s
->end
->data
+ s
->end
->posn
, 0, l
);
496 s
->end
->next
= nasm_malloc (sizeof(struct SAA
));
497 s
->end
->next
->start
= s
->end
->start
+ s
->end
->posn
;
498 s
->end
= s
->end
->next
;
499 s
->end
->length
= s
->length
;
502 s
->end
->data
= nasm_malloc (s
->length
);
507 void saa_rewind (struct SAA
*s
) {
512 void *saa_rstruct (struct SAA
*s
) {
518 if (s
->rptr
->posn
- s
->rpos
< s
->elem_len
) {
519 s
->rptr
= s
->rptr
->next
;
521 return NULL
; /* end of array */
525 p
= s
->rptr
->data
+ s
->rpos
;
526 s
->rpos
+= s
->elem_len
;
530 void *saa_rbytes (struct SAA
*s
, long *len
) {
536 p
= s
->rptr
->data
+ s
->rpos
;
537 *len
= s
->rptr
->posn
- s
->rpos
;
538 s
->rptr
= s
->rptr
->next
;
543 void saa_rnbytes (struct SAA
*s
, void *data
, long len
) {
552 l
= s
->rptr
->posn
- s
->rpos
;
556 memcpy (d
, s
->rptr
->data
+ s
->rpos
, l
);
562 s
->rptr
= s
->rptr
->next
;
568 void saa_fread (struct SAA
*s
, long posn
, void *data
, long len
) {
573 if (!s
->rptr
|| posn
> s
->rptr
->start
+ s
->rpos
)
575 while (posn
>= s
->rptr
->start
+ s
->rptr
->posn
) {
576 s
->rptr
= s
->rptr
->next
;
578 return; /* what else can we do?! */
582 pos
= posn
- s
->rptr
->start
;
584 long l
= s
->rptr
->posn
- pos
;
587 memcpy (cdata
, s
->rptr
->data
+pos
, l
);
597 void saa_fwrite (struct SAA
*s
, long posn
, void *data
, long len
) {
602 if (!s
->rptr
|| posn
> s
->rptr
->start
+ s
->rpos
)
604 while (posn
>= s
->rptr
->start
+ s
->rptr
->posn
) {
605 s
->rptr
= s
->rptr
->next
;
607 return; /* what else can we do?! */
611 pos
= posn
- s
->rptr
->start
;
613 long l
= s
->rptr
->posn
- pos
;
616 memcpy (s
->rptr
->data
+pos
, cdata
, l
);
626 void saa_fpwrite (struct SAA
*s
, FILE *fp
) {
631 while ( (data
= saa_rbytes (s
, &len
)) )
632 fwrite (data
, 1, len
, fp
);
636 * Register, instruction, condition-code and prefix keywords used
640 static char *special_names
[] = {
641 "byte", "dword", "far", "long", "near", "nosplit", "qword",
642 "short", "to", "tword", "word"
644 static char *prefix_names
[] = {
645 "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
646 "repnz", "repz", "times"
651 * Standard scanner routine used by parser.c and some output
652 * formats. It keeps a succession of temporary-storage strings in
653 * stdscan_tempstorage, which can be cleared using stdscan_reset.
655 static char **stdscan_tempstorage
= NULL
;
656 static int stdscan_tempsize
= 0, stdscan_templen
= 0;
657 #define STDSCAN_TEMP_DELTA 256
659 static void stdscan_pop(void) {
660 nasm_free (stdscan_tempstorage
[--stdscan_templen
]);
663 void stdscan_reset(void) {
664 while (stdscan_templen
> 0)
668 static char *stdscan_copy(char *p
, int len
) {
671 text
= nasm_malloc(len
+1);
672 strncpy (text
, p
, len
);
675 if (stdscan_templen
>= stdscan_tempsize
) {
676 stdscan_tempsize
+= STDSCAN_TEMP_DELTA
;
677 stdscan_tempstorage
= nasm_realloc(stdscan_tempstorage
,
678 stdscan_tempsize
*sizeof(char *));
680 stdscan_tempstorage
[stdscan_templen
++] = text
;
685 char *stdscan_bufptr
= NULL
;
686 int stdscan (void *private_data
, struct tokenval
*tv
) {
687 char ourcopy
[256], *r
, *s
;
689 while (isspace(*stdscan_bufptr
)) stdscan_bufptr
++;
690 if (!*stdscan_bufptr
)
691 return tv
->t_type
= 0;
693 /* we have a token; either an id, a number or a char */
694 if (isidstart(*stdscan_bufptr
) ||
695 (*stdscan_bufptr
== '$' && isidstart(stdscan_bufptr
[1]))) {
696 /* now we've got an identifier */
700 if (*stdscan_bufptr
== '$') {
705 r
= stdscan_bufptr
++;
706 while (isidchar(*stdscan_bufptr
)) stdscan_bufptr
++;
707 tv
->t_charptr
= stdscan_copy(r
, stdscan_bufptr
- r
);
709 for (s
=tv
->t_charptr
, r
=ourcopy
; *s
; s
++)
713 return tv
->t_type
= TOKEN_ID
;/* bypass all other checks */
714 /* right, so we have an identifier sitting in temp storage. now,
715 * is it actually a register or instruction name, or what? */
716 if ((tv
->t_integer
=bsi(ourcopy
, reg_names
,
717 elements(reg_names
)))>=0) {
718 tv
->t_integer
+= EXPR_REG_START
;
719 return tv
->t_type
= TOKEN_REG
;
720 } else if ((tv
->t_integer
=bsi(ourcopy
, insn_names
,
721 elements(insn_names
)))>=0) {
722 return tv
->t_type
= TOKEN_INSN
;
724 for (i
=0; i
<(int)elements(icn
); i
++)
725 if (!strncmp(ourcopy
, icn
[i
], strlen(icn
[i
]))) {
726 char *p
= ourcopy
+ strlen(icn
[i
]);
727 tv
->t_integer
= ico
[i
];
728 if ((tv
->t_inttwo
=bsi(p
, conditions
,
729 elements(conditions
)))>=0)
730 return tv
->t_type
= TOKEN_INSN
;
732 if ((tv
->t_integer
=bsi(ourcopy
, prefix_names
,
733 elements(prefix_names
)))>=0) {
734 tv
->t_integer
+= PREFIX_ENUM_START
;
735 return tv
->t_type
= TOKEN_PREFIX
;
737 if ((tv
->t_integer
=bsi(ourcopy
, special_names
,
738 elements(special_names
)))>=0)
739 return tv
->t_type
= TOKEN_SPECIAL
;
740 if (!strcmp(ourcopy
, "seg"))
741 return tv
->t_type
= TOKEN_SEG
;
742 if (!strcmp(ourcopy
, "wrt"))
743 return tv
->t_type
= TOKEN_WRT
;
744 return tv
->t_type
= TOKEN_ID
;
745 } else if (*stdscan_bufptr
== '$' && !isnumchar(stdscan_bufptr
[1])) {
747 * It's a $ sign with no following hex number; this must
748 * mean it's a Here token ($), evaluating to the current
749 * assembly location, or a Base token ($$), evaluating to
750 * the base of the current segment.
753 if (*stdscan_bufptr
== '$') {
755 return tv
->t_type
= TOKEN_BASE
;
757 return tv
->t_type
= TOKEN_HERE
;
758 } else if (isnumstart(*stdscan_bufptr
)) { /* now we've got a number */
761 r
= stdscan_bufptr
++;
762 while (isnumchar(*stdscan_bufptr
))
765 if (*stdscan_bufptr
== '.') {
767 * a floating point constant
770 while (isnumchar(*stdscan_bufptr
)) {
773 tv
->t_charptr
= stdscan_copy(r
, stdscan_bufptr
- r
);
774 return tv
->t_type
= TOKEN_FLOAT
;
776 r
= stdscan_copy(r
, stdscan_bufptr
- r
);
777 tv
->t_integer
= readnum(r
, &rn_error
);
780 return tv
->t_type
= TOKEN_ERRNUM
;/* some malformation occurred */
781 tv
->t_charptr
= NULL
;
782 return tv
->t_type
= TOKEN_NUM
;
783 } else if (*stdscan_bufptr
== '\'' ||
784 *stdscan_bufptr
== '"') {/* a char constant */
785 char quote
= *stdscan_bufptr
++, *r
;
786 r
= tv
->t_charptr
= stdscan_bufptr
;
787 while (*stdscan_bufptr
&& *stdscan_bufptr
!= quote
) stdscan_bufptr
++;
788 tv
->t_inttwo
= stdscan_bufptr
- r
; /* store full version */
789 if (!*stdscan_bufptr
)
790 return tv
->t_type
= TOKEN_ERRNUM
; /* unmatched quotes */
792 r
= stdscan_bufptr
++; /* skip over final quote */
793 while (quote
!= *--r
) {
794 tv
->t_integer
= (tv
->t_integer
<<8) + (unsigned char) *r
;
796 return tv
->t_type
= TOKEN_NUM
;
797 } else if (*stdscan_bufptr
== ';') { /* a comment has happened - stay */
798 return tv
->t_type
= 0;
799 } else if (stdscan_bufptr
[0] == '>' && stdscan_bufptr
[1] == '>') {
801 return tv
->t_type
= TOKEN_SHR
;
802 } else if (stdscan_bufptr
[0] == '<' && stdscan_bufptr
[1] == '<') {
804 return tv
->t_type
= TOKEN_SHL
;
805 } else if (stdscan_bufptr
[0] == '/' && stdscan_bufptr
[1] == '/') {
807 return tv
->t_type
= TOKEN_SDIV
;
808 } else if (stdscan_bufptr
[0] == '%' && stdscan_bufptr
[1] == '%') {
810 return tv
->t_type
= TOKEN_SMOD
;
811 } else if (stdscan_bufptr
[0] == '=' && stdscan_bufptr
[1] == '=') {
813 return tv
->t_type
= TOKEN_EQ
;
814 } else if (stdscan_bufptr
[0] == '<' && stdscan_bufptr
[1] == '>') {
816 return tv
->t_type
= TOKEN_NE
;
817 } else if (stdscan_bufptr
[0] == '!' && stdscan_bufptr
[1] == '=') {
819 return tv
->t_type
= TOKEN_NE
;
820 } else if (stdscan_bufptr
[0] == '<' && stdscan_bufptr
[1] == '=') {
822 return tv
->t_type
= TOKEN_LE
;
823 } else if (stdscan_bufptr
[0] == '>' && stdscan_bufptr
[1] == '=') {
825 return tv
->t_type
= TOKEN_GE
;
826 } else if (stdscan_bufptr
[0] == '&' && stdscan_bufptr
[1] == '&') {
828 return tv
->t_type
= TOKEN_DBL_AND
;
829 } else if (stdscan_bufptr
[0] == '^' && stdscan_bufptr
[1] == '^') {
831 return tv
->t_type
= TOKEN_DBL_XOR
;
832 } else if (stdscan_bufptr
[0] == '|' && stdscan_bufptr
[1] == '|') {
834 return tv
->t_type
= TOKEN_DBL_OR
;
835 } else /* just an ordinary char */
836 return tv
->t_type
= (unsigned char) (*stdscan_bufptr
++);
840 * Return TRUE if the argument is a simple scalar. (Or a far-
841 * absolute, which counts.)
843 int is_simple (expr
*vect
) {
844 while (vect
->type
&& !vect
->value
)
848 if (vect
->type
!= EXPR_SIMPLE
)
852 } while (vect
->type
&& !vect
->value
);
853 if (vect
->type
&& vect
->type
< EXPR_SEGBASE
+SEG_ABS
) return 0;
858 * Return TRUE if the argument is a simple scalar, _NOT_ a far-
861 int is_really_simple (expr
*vect
) {
862 while (vect
->type
&& !vect
->value
)
866 if (vect
->type
!= EXPR_SIMPLE
)
870 } while (vect
->type
&& !vect
->value
);
871 if (vect
->type
) return 0;
876 * Return TRUE if the argument is relocatable (i.e. a simple
877 * scalar, plus at most one segment-base, plus possibly a WRT).
879 int is_reloc (expr
*vect
) {
880 while (vect
->type
&& !vect
->value
) /* skip initial value-0 terms */
882 if (!vect
->type
) /* trivially return TRUE if nothing */
883 return 1; /* is present apart from value-0s */
884 if (vect
->type
< EXPR_SIMPLE
) /* FALSE if a register is present */
886 if (vect
->type
== EXPR_SIMPLE
) { /* skip over a pure number term... */
889 } while (vect
->type
&& !vect
->value
);
890 if (!vect
->type
) /* ...returning TRUE if that's all */
893 if (vect
->type
== EXPR_WRT
) { /* skip over a WRT term... */
896 } while (vect
->type
&& !vect
->value
);
897 if (!vect
->type
) /* ...returning TRUE if that's all */
900 if (vect
->value
!= 0 && vect
->value
!= 1)
901 return 0; /* segment base multiplier non-unity */
902 do { /* skip over _one_ seg-base term... */
904 } while (vect
->type
&& !vect
->value
);
905 if (!vect
->type
) /* ...returning TRUE if that's all */
907 return 0; /* And return FALSE if there's more */
911 * Return TRUE if the argument contains an `unknown' part.
913 int is_unknown(expr
*vect
) {
914 while (vect
->type
&& vect
->type
< EXPR_UNKNOWN
)
916 return (vect
->type
== EXPR_UNKNOWN
);
920 * Return TRUE if the argument contains nothing but an `unknown'
923 int is_just_unknown(expr
*vect
) {
924 while (vect
->type
&& !vect
->value
)
926 return (vect
->type
== EXPR_UNKNOWN
);
930 * Return the scalar part of a relocatable vector. (Including
931 * simple scalar vectors - those qualify as relocatable.)
933 long reloc_value (expr
*vect
) {
934 while (vect
->type
&& !vect
->value
)
936 if (!vect
->type
) return 0;
937 if (vect
->type
== EXPR_SIMPLE
)
944 * Return the segment number of a relocatable vector, or NO_SEG for
947 long reloc_seg (expr
*vect
) {
948 while (vect
->type
&& (vect
->type
== EXPR_WRT
|| !vect
->value
))
950 if (vect
->type
== EXPR_SIMPLE
) {
953 } while (vect
->type
&& (vect
->type
== EXPR_WRT
|| !vect
->value
));
958 return vect
->type
- EXPR_SEGBASE
;
962 * Return the WRT segment number of a relocatable vector, or NO_SEG
963 * if no WRT part is present.
965 long reloc_wrt (expr
*vect
) {
966 while (vect
->type
&& vect
->type
< EXPR_WRT
)
968 if (vect
->type
== EXPR_WRT
) {
977 int bsi (char *string
, char **array
, int size
) {
978 int i
= -1, j
= size
; /* always, i < index < j */
981 int l
= strcmp(string
, array
[k
]);
982 if (l
<0) /* it's in the first half */
984 else if (l
>0) /* it's in the second half */
986 else /* we've got it :) */
989 return -1; /* we haven't got it :( */