home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nasm097s.zip / NASMLIB.H < prev    next >
C/C++ Source or Header  |  1997-10-01  |  5KB  |  173 lines

  1. /* nasmlib.c    header file for nasmlib.h
  2.  *
  3.  * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  4.  * Julian Hall. All rights reserved. The software is
  5.  * redistributable under the licence given in the file "Licence"
  6.  * distributed in the NASM archive.
  7.  */
  8.  
  9. #ifndef NASM_NASMLIB_H
  10. #define NASM_NASMLIB_H
  11.  
  12. /*
  13.  * If this is defined, the wrappers around malloc et al will
  14.  * transform into logging variants, which will cause NASM to create
  15.  * a file called `malloc.log' when run, and spew details of all its
  16.  * memory management into that. That can then be analysed to detect
  17.  * memory leaks and potentially other problems too.
  18.  */
  19. /* #define LOGALLOC */
  20.  
  21. /*
  22.  * Wrappers around malloc, realloc and free. nasm_malloc will
  23.  * fatal-error and die rather than return NULL; nasm_realloc will
  24.  * do likewise, and will also guarantee to work right on being
  25.  * passed a NULL pointer; nasm_free will do nothing if it is passed
  26.  * a NULL pointer.
  27.  */
  28. #ifdef NASM_NASM_H               /* need efunc defined for this */
  29. void nasm_set_malloc_error (efunc);
  30. #ifndef LOGALLOC
  31. void *nasm_malloc (size_t);
  32. void *nasm_realloc (void *, size_t);
  33. void nasm_free (void *);
  34. char *nasm_strdup (char *);
  35. char *nasm_strndup (char *, size_t);
  36. #else
  37. void *nasm_malloc_log (char *, int, size_t);
  38. void *nasm_realloc_log (char *, int, void *, size_t);
  39. void nasm_free_log (char *, int, void *);
  40. char *nasm_strdup_log (char *, int, char *);
  41. char *nasm_strndup_log (char *, int, char *, size_t);
  42. #define nasm_malloc(x) nasm_malloc_log(__FILE__,__LINE__,x)
  43. #define nasm_realloc(x,y) nasm_realloc_log(__FILE__,__LINE__,x,y)
  44. #define nasm_free(x) nasm_free_log(__FILE__,__LINE__,x)
  45. #define nasm_strdup(x) nasm_strdup_log(__FILE__,__LINE__,x)
  46. #define nasm_strndup(x,y) nasm_strndup_log(__FILE__,__LINE__,x,y)
  47. #endif
  48. #endif
  49.  
  50. /*
  51.  * ANSI doesn't guarantee the presence of `stricmp' or
  52.  * `strcasecmp'.
  53.  */
  54. int nasm_stricmp (char *, char *);
  55. int nasm_strnicmp (char *, char *, int);
  56.  
  57. /*
  58.  * Convert a string into a number, using NASM number rules. Sets
  59.  * `*error' to TRUE if an error occurs, and FALSE otherwise.
  60.  */
  61. long readnum(char *str, int *error);
  62.  
  63. /*
  64.  * seg_init: Initialise the segment-number allocator.
  65.  * seg_alloc: allocate a hitherto unused segment number.
  66.  */
  67. void seg_init(void);
  68. long seg_alloc(void);
  69.  
  70. /*
  71.  * many output formats will be able to make use of this: a standard
  72.  * function to add an extension to the name of the input file
  73.  */
  74. #ifdef NASM_NASM_H
  75. void standard_extension (char *inname, char *outname, char *extension,
  76.              efunc error);
  77. #endif
  78.  
  79. /*
  80.  * some handy macros that will probably be of use in more than one
  81.  * output format: convert integers into little-endian byte packed
  82.  * format in memory
  83.  */
  84.  
  85. #define WRITELONG(p,v) \
  86.   do { \
  87.     *(p)++ = (v) & 0xFF; \
  88.     *(p)++ = ((v) >> 8) & 0xFF; \
  89.     *(p)++ = ((v) >> 16) & 0xFF; \
  90.     *(p)++ = ((v) >> 24) & 0xFF; \
  91.   } while (0)
  92.  
  93. #define WRITESHORT(p,v) \
  94.   do { \
  95.     *(p)++ = (v) & 0xFF; \
  96.     *(p)++ = ((v) >> 8) & 0xFF; \
  97.   } while (0)
  98.  
  99. /*
  100.  * and routines to do the same thing to a file
  101.  */
  102. void fwriteshort (int data, FILE *fp);
  103. void fwritelong (long data, FILE *fp);
  104.  
  105. /*
  106.  * Routines to manage a dynamic random access array of longs which
  107.  * may grow in size to be more than the largest single malloc'able
  108.  * chunk.
  109.  */
  110.  
  111. struct RAA;
  112.  
  113. struct RAA *raa_init (void);
  114. void raa_free (struct RAA *);
  115. long raa_read (struct RAA *, long);
  116. struct RAA *raa_write (struct RAA *r, long posn, long value);
  117.  
  118. /*
  119.  * Routines to manage a dynamic sequential-access array, under the
  120.  * same restriction on maximum mallocable block. This array may be
  121.  * written to in two ways: a contiguous chunk can be reserved of a
  122.  * given size, and a pointer returned, or single-byte data may be
  123.  * written. The array can also be read back in the same two ways:
  124.  * as a series of big byte-data blocks or as a list of structures
  125.  * of a given size.
  126.  */
  127.  
  128. struct SAA;
  129.  
  130. struct SAA *saa_init (long elem_len);  /* 1 == byte */
  131. void saa_free (struct SAA *);
  132. void *saa_wstruct (struct SAA *);      /* return a structure of elem_len */
  133. void saa_wbytes (struct SAA *, void *, long);  /* write arbitrary bytes */
  134. void saa_rewind (struct SAA *);           /* for reading from beginning */
  135. void *saa_rstruct (struct SAA *);      /* return NULL on EOA */
  136. void *saa_rbytes (struct SAA *, long *);   /* return 0 on EOA */
  137. void saa_rnbytes (struct SAA *, void *, long); /* read a given no. of bytes */
  138. void saa_fread (struct SAA *s, long posn, void *p, long len);   /* fixup */
  139. void saa_fwrite (struct SAA *s, long posn, void *p, long len);   /* fixup */
  140. void saa_fpwrite (struct SAA *, FILE *);
  141.  
  142. #ifdef NASM_NASM_H
  143. /*
  144.  * Standard scanner.
  145.  */
  146. extern char *stdscan_bufptr;
  147. void stdscan_reset(void);
  148. int stdscan (void *private_data, struct tokenval *tv);
  149. #endif
  150.  
  151. #ifdef NASM_NASM_H
  152. /*
  153.  * Library routines to manipulate expression data types.
  154.  */
  155. int is_reloc(expr *);
  156. int is_simple(expr *);
  157. int is_really_simple (expr *);
  158. int is_unknown(expr *);
  159. int is_just_unknown(expr *);
  160. long reloc_value(expr *);
  161. long reloc_seg(expr *);
  162. long reloc_wrt(expr *);
  163. #endif
  164.  
  165. /*
  166.  * Binary search routine. Returns index into `array' of an entry
  167.  * matching `string', or <0 if no match. `array' is taken to
  168.  * contain `size' elements.
  169.  */
  170. int bsi (char *string, char **array, int size);
  171.  
  172. #endif
  173.