home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / input.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  7KB  |  227 lines

  1. /* ---------------------------------------------------------------------- */
  2. /*                   Copyright (C) 1991 by Natürlich!                     */
  3. /*                      This file is copyrighted!                         */
  4. /*                Refer to the documentation for details.                 */
  5. /* ---------------------------------------------------------------------- */
  6. #define _TO_UPPER_
  7. #include "defines.h"
  8. #include "nasm.h"
  9. #undef DEBUG 
  10. #include "debug.h"
  11. #include <setjmp.h>
  12. #include NMALLOC_H
  13. #include "buffer.h"
  14. #ifndef NULL
  15. # define NULL  ((void *) 0)
  16. #endif
  17.  
  18. #if __NSTDC__
  19. extern int     (*gettoken)( void);
  20. #else
  21. extern int     (*gettoken)();
  22. #endif
  23.  
  24. #if STATISTICS
  25. extern long    _mused;
  26. #endif
  27. extern byte    c;
  28. extern int     freshflag;     /* might not be really needed here */
  29. extern jmp_buf   eof_panic;
  30. void  dummy()  { }
  31.                                     /* if we are in a string */
  32. static byte  zero[16] = { 0, 0, 0, 0, '"' };
  33. static buffer nil_buffer =
  34. {
  35.    0, 0,
  36.    (byte huge *) zero, (byte huge *) zero,
  37.    NULL,
  38.    NULL,
  39.    16L, 16L,
  40.    0,
  41.    0,
  42.    0, BUF_AUX,
  43.    (void (*)(buffer *)) dummy,         /* **-PORT #1-** */
  44.    (void (*)(buffer *)) dummy,         /* **-PORT #1-** */
  45.    (int  (*)(void))     nilexer        /* **-PORT #1-** */
  46. };
  47.  
  48.  
  49. buffer huge  *bp = &nil_buffer,
  50.        huge  *hp;
  51.  
  52. #if ! VERSION
  53. void kill_buffer( hp)
  54. register buffer huge  *hp;
  55. {
  56.     hp = bp;                   /* get buffer to be freed           */
  57.     if( bp = bp->before)       /* New buffer is the one before     */
  58.     {
  59.        if( (hp->type ^ bp->type) & BUF_TYPEMASK)
  60.           freshflag = 1;
  61.        bp->next = 0;           /* of course only if there was one  */
  62.        gettoken = (int (*)(void)) bp->get;  /* new input routine */
  63.     }                          /* **-PORT #1-** 1 line up          */
  64.     (*hp->done)(hp);           /* Call cleanup action (almost OO)  */
  65.     if( hp->type & BUF_FREE)   /* dynamic buffer struct ? then     */
  66.        nfree( (void huge *) hp); /* Remove buffer struct           */
  67. }
  68. #endif
  69.  
  70. #if ! DEBUG
  71. /* ---------------------------------------------------------- */
  72. /* Don't let a PASCALler near this (ain't thaaat bad, though) */
  73. /* These routines only work for ASM65. The method is somewhat */
  74. /* objectoriented, but will fail, when the buffer element size*/
  75. /* differs (as it does with ASM65). So how come it worx ??    */
  76. /* ---------------------------------------------------------- */
  77. byte  input()
  78. {
  79.    register buffer huge *P = bp;
  80.  
  81.    if( P->remain--)                    /* Something left ?        */
  82.       return( *P->p++);                /* then return that        */
  83.    (*P->multi.fill)( P);               /* try refilling           */
  84.    if( P->remain--)                    /* Something left ?        */
  85.       return( *P->p++);                /* then return that        */
  86.    kill_buffer(hp);                    /* Install new buffer      */
  87.    return( '\n');                      /* LF for safety           */
  88. }
  89. #else
  90.  
  91. #define xreturn( val)               \
  92. {                                   \
  93.    byte  foo = (val);      \
  94.                                     \
  95.    IMESS("Returning '%c'", foo, 1); \
  96.    LEAVE();                         \
  97.    return( foo);                    \
  98. }
  99.  
  100. byte  input()
  101. {
  102.    int   val;
  103.  
  104.    ENTER("input");
  105.    if( bp->remain--)                    /* Something left ?        */
  106.       xreturn( *bp->p++);               /* then return that        */
  107.    MESS("Trying to fill buffer...");
  108.    (*bp->multi.fill)( bp);              /* try refilling           */
  109.    if( bp->remain--)                    /* Something left ?        */
  110.       xreturn( *bp->p++);               /* then return that        */
  111.    MESS("Trying to kill buffer...");
  112.    dump_buffer( bp);
  113.    kill_buffer(hp);                     /* Install new buffer      */
  114.    xreturn( '\n');                      /* LF for safety           */
  115. }
  116. #endif
  117.  
  118.  
  119. /* Just to convert lower case to upper case ... */
  120. byte  _uptable[] =
  121. {
  122.    0x00,0x01,0x02,0x03,  0x04,0x05,0x06,0x07,
  123.    0x08,0x09,0x0A,0x0B,  0x0C,0x0D,0x0E,0x0F,     /* 0x00 */
  124.    0x10,0x11,0x12,0x13,  0x14,0x15,0x16,0x17,
  125.    0x18,0x19,0x1A,0x1B,  0x1C,0x1D,0x1E,0x1F,     /* 0x10 */
  126.    0x20,0x21,0x22,0x23,  0x24,0x25,0x26,0x27,
  127.    0x28,0x29,0x2A,0x2B,  0x2C,0x2D,0x2E,0x2F,     /* 0x20 */
  128.    0x30,0x31,0x32,0x33,  0x34,0x35,0x36,0x37,
  129.    0x38,0x39,0x3A,0x3B,  0x3C,0x3D,0x3E,0x3F,     /* 0x30 */
  130.  
  131.    0x40,0x41,0x42,0x43,  0x44,0x45,0x46,0x47,
  132.    0x48,0x49,0x4A,0x4B,  0x4C,0x4D,0x4E,0x4F,     /* 0x40 */
  133.    0x50,0x51,0x52,0x53,  0x54,0x55,0x56,0x57,
  134.    0x58,0x59,0x5A,0x5B,  0x5C,0x5D,0x5E,0x5F,     /* 0x50 */
  135.    0x40,0x41,0x42,0x43,  0x44,0x45,0x46,0x47,
  136.    0x48,0x49,0x4A,0x4B,  0x4C,0x4D,0x4E,0x4F,     /* 0x40 */
  137.    0x50,0x51,0x52,0x53,  0x54,0x55,0x56,0x57,
  138.    0x58,0x59,0x5A,0x7B,  0x7C,0x7D,0x7E,0x7F,     /* 0x70 */
  139.  
  140.    0x80,0x81,0x82,0x83,  0x84,0x85,0x86,0x87,
  141.    0x88,0x89,0x8A,0x8B,  0x8C,0x8D,0x8E,0x8F,     /* 0x80 */
  142.    0x90,0x91,0x92,0x93,  0x94,0x95,0x96,0x97,
  143.    0x98,0x99,0x9A,0x9B,  0x9C,0x9D,0x9E,0x9F,     /* 0x90 */
  144.    0xA0,0xA1,0xA2,0xA3,  0xA4,0xA5,0xA6,0xA7,
  145.    0xA8,0xA9,0xAA,0xAB,  0xAC,0xAD,0xAE,0xAF,     /* 0xA0 */
  146.    0xB0,0xB1,0xB2,0xB3,  0xB4,0xB5,0xB6,0xB7,
  147.    0xB8,0xB9,0xBA,0xBB,  0xBC,0xBD,0xBE,0xBF,     /* 0xB0 */
  148.  
  149.    0xC0,0xC1,0xC2,0xC3,  0xC4,0xC5,0xC6,0xC7,
  150.    0xC8,0xC9,0xCA,0xCB,  0xCC,0xCD,0xCE,0xCF,     /* 0xC0 */
  151.    0xD0,0xD1,0xD2,0xD3,  0xD4,0xD5,0xD6,0xD7,
  152.    0xD8,0xD9,0xDA,0xDB,  0xDC,0xDD,0xDE,0xDF,     /* 0xD0 */
  153.    0xE0,0xE1,0xE2,0xE3,  0xE4,0xE5,0xE6,0xE7,
  154.    0xE8,0xE9,0xEA,0xEB,  0xEC,0xED,0xEE,0xEF,     /* 0xE0 */
  155.    0xF0,0xF1,0xF2,0xF3,  0xF4,0xF5,0xF6,0xF7,
  156.    0xF8,0xF9,0xFA,0xFB,  0xFC,0xFD,0xFE,0xFF,     /* 0xF0 */
  157. };
  158.  
  159. #if VERSION
  160. byte _input()
  161. {
  162.    register buffer huge *P = bp;
  163.  
  164.    (*P->multi.fill)( P);               /* try refilling           */
  165.    if( P->remain--)                    /* Something left ?        */
  166.       return( *P->p++);                /* then return that        */
  167.    kill_buffer(hp);                    /* Install new buffer      */
  168.    return( '\n');                      /* LF for safety           */
  169. }
  170. #endif
  171.  
  172. byte  uinput() { return( _uptable[ input()]); }
  173.  
  174. /* ------------------------------------------------------------ */
  175. /* very much unfortunate is the interplay between us and yacc   */
  176. /* when it comes to doing includes. Gives me the wish to dump   */
  177. /* Yacc and write something myself...                           */
  178. /* ------------------------------------------------------------ */
  179. static int     btok;
  180. static lword   bval;
  181. extern lword   yylval;
  182.  
  183. static buffer sfi =
  184. {
  185.    0, 0,
  186.    (byte *) &btok, (byte *) &btok,
  187.    NULL,
  188.    NULL,
  189.    1L, 1L,
  190.    0,
  191.    0,
  192.    0, BUF_AUX | BUF_TOKEN,
  193.    (void (*)(buffer *)) dummy,         /* **-PORT #1-** */
  194.    (void (*)(buffer *)) dummy,         /* **-PORT #1-** */
  195.    (int  (*)(void))     lexer          /* **-PORT #1-** */
  196. };
  197.  
  198.  
  199.  
  200. get_sfi()
  201. {
  202.    ENTER("get_sfi");
  203.    (bp = bp->before)->next = 0;
  204.    gettoken = (int (*)(void)) bp->get; /* **-PORT #1-** */
  205.    yylval   = bval;
  206.    LEAVE();
  207.    return( btok);
  208. }
  209.  
  210.  
  211. void  fix_include( tok, val)
  212. int      tok;
  213. lword    val;
  214. {
  215.    ENTER("fix_include");
  216.    btok       = tok;
  217.    bval       = val;
  218.    sfi.name   = bp->name;
  219.    sfi.line   = bp->line;
  220.    sfi.before = bp;
  221.    sfi.next   = 0;
  222.    bp         = bp->next = &sfi;
  223.    gettoken   = get_sfi;
  224.    LEAVE();
  225. }
  226.  
  227.