Home » Archimedes archive » Acorn User » AU 1996-Xmas.adf » Features » Arcade/!Popcorn/c/FindSymbol

Arcade/!Popcorn/c/FindSymbol

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1996-Xmas.adf » Features
Filename: Arcade/!Popcorn/c/FindSymbol
Read OK:
File size: 0411 bytes
Load address: 0000
Exec address: 0000
Duplicates

There is 1 duplicate copy of this file in the archive:

File contents
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "Popcorn:h.Popcorn"

char   			symbol_table_filename[255];
char			*symbol_table = NULL;
int			st_length = 0;

object_handler Popcorn_FindSymbol(char *name)
{
  FILE           *st_handle;
  char		 *cmp;
  int		 namelen = strlen(name);
  object_handler return_func;

  if (symbol_table == NULL)
  {
    st_handle = fopen(symbol_table_filename, "rb");
    if (st_handle == NULL)
      return(NULL);
    fseek(st_handle, 0, 2); /* End of file */
    st_length = (int) ftell(st_handle);
    symbol_table = malloc(st_length);
    rewind(st_handle);
    fread(symbol_table, 1, st_length, st_handle);
    fclose(st_handle);
  }

  cmp = symbol_table;
  while (memcmp(cmp, name, namelen) != 0 && cmp != (symbol_table+st_length) )
  {
    while (*cmp >= 32)
      cmp++;
    cmp++;
  }

  if (cmp == (symbol_table + st_length))
    return(NULL);

  while (*cmp != 32)
    cmp++;
  while (*cmp == 32)
    cmp++;

  sscanf(cmp, "%x\n", (void*) &return_func);
  return(return_func);
}
00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 6c 69 62  |#include <stdlib|
00000010  2e 68 3e 0a 23 69 6e 63  6c 75 64 65 20 3c 73 74  |.h>.#include <st|
00000020  64 69 6f 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |dio.h>.#include |
00000030  3c 73 74 72 69 6e 67 2e  68 3e 0a 0a 23 69 6e 63  |<string.h>..#inc|
00000040  6c 75 64 65 20 22 50 6f  70 63 6f 72 6e 3a 68 2e  |lude "Popcorn:h.|
00000050  50 6f 70 63 6f 72 6e 22  0a 0a 63 68 61 72 20 20  |Popcorn"..char  |
00000060  20 09 09 09 73 79 6d 62  6f 6c 5f 74 61 62 6c 65  | ...symbol_table|
00000070  5f 66 69 6c 65 6e 61 6d  65 5b 32 35 35 5d 3b 0a  |_filename[255];.|
00000080  63 68 61 72 09 09 09 2a  73 79 6d 62 6f 6c 5f 74  |char...*symbol_t|
00000090  61 62 6c 65 20 3d 20 4e  55 4c 4c 3b 0a 69 6e 74  |able = NULL;.int|
000000a0  09 09 09 73 74 5f 6c 65  6e 67 74 68 20 3d 20 30  |...st_length = 0|
000000b0  3b 0a 0a 6f 62 6a 65 63  74 5f 68 61 6e 64 6c 65  |;..object_handle|
000000c0  72 20 50 6f 70 63 6f 72  6e 5f 46 69 6e 64 53 79  |r Popcorn_FindSy|
000000d0  6d 62 6f 6c 28 63 68 61  72 20 2a 6e 61 6d 65 29  |mbol(char *name)|
000000e0  0a 7b 0a 20 20 46 49 4c  45 20 20 20 20 20 20 20  |.{.  FILE       |
000000f0  20 20 20 20 2a 73 74 5f  68 61 6e 64 6c 65 3b 0a  |    *st_handle;.|
00000100  20 20 63 68 61 72 09 09  20 2a 63 6d 70 3b 0a 20  |  char.. *cmp;. |
00000110  20 69 6e 74 09 09 20 6e  61 6d 65 6c 65 6e 20 3d  | int.. namelen =|
00000120  20 73 74 72 6c 65 6e 28  6e 61 6d 65 29 3b 0a 20  | strlen(name);. |
00000130  20 6f 62 6a 65 63 74 5f  68 61 6e 64 6c 65 72 20  | object_handler |
00000140  72 65 74 75 72 6e 5f 66  75 6e 63 3b 0a 0a 20 20  |return_func;..  |
00000150  69 66 20 28 73 79 6d 62  6f 6c 5f 74 61 62 6c 65  |if (symbol_table|
00000160  20 3d 3d 20 4e 55 4c 4c  29 0a 20 20 7b 0a 20 20  | == NULL).  {.  |
00000170  20 20 73 74 5f 68 61 6e  64 6c 65 20 3d 20 66 6f  |  st_handle = fo|
00000180  70 65 6e 28 73 79 6d 62  6f 6c 5f 74 61 62 6c 65  |pen(symbol_table|
00000190  5f 66 69 6c 65 6e 61 6d  65 2c 20 22 72 62 22 29  |_filename, "rb")|
000001a0  3b 0a 20 20 20 20 69 66  20 28 73 74 5f 68 61 6e  |;.    if (st_han|
000001b0  64 6c 65 20 3d 3d 20 4e  55 4c 4c 29 0a 20 20 20  |dle == NULL).   |
000001c0  20 20 20 72 65 74 75 72  6e 28 4e 55 4c 4c 29 3b  |   return(NULL);|
000001d0  0a 20 20 20 20 66 73 65  65 6b 28 73 74 5f 68 61  |.    fseek(st_ha|
000001e0  6e 64 6c 65 2c 20 30 2c  20 32 29 3b 20 2f 2a 20  |ndle, 0, 2); /* |
000001f0  45 6e 64 20 6f 66 20 66  69 6c 65 20 2a 2f 0a 20  |End of file */. |
00000200  20 20 20 73 74 5f 6c 65  6e 67 74 68 20 3d 20 28  |   st_length = (|
00000210  69 6e 74 29 20 66 74 65  6c 6c 28 73 74 5f 68 61  |int) ftell(st_ha|
00000220  6e 64 6c 65 29 3b 0a 20  20 20 20 73 79 6d 62 6f  |ndle);.    symbo|
00000230  6c 5f 74 61 62 6c 65 20  3d 20 6d 61 6c 6c 6f 63  |l_table = malloc|
00000240  28 73 74 5f 6c 65 6e 67  74 68 29 3b 0a 20 20 20  |(st_length);.   |
00000250  20 72 65 77 69 6e 64 28  73 74 5f 68 61 6e 64 6c  | rewind(st_handl|
00000260  65 29 3b 0a 20 20 20 20  66 72 65 61 64 28 73 79  |e);.    fread(sy|
00000270  6d 62 6f 6c 5f 74 61 62  6c 65 2c 20 31 2c 20 73  |mbol_table, 1, s|
00000280  74 5f 6c 65 6e 67 74 68  2c 20 73 74 5f 68 61 6e  |t_length, st_han|
00000290  64 6c 65 29 3b 0a 20 20  20 20 66 63 6c 6f 73 65  |dle);.    fclose|
000002a0  28 73 74 5f 68 61 6e 64  6c 65 29 3b 0a 20 20 7d  |(st_handle);.  }|
000002b0  0a 0a 20 20 63 6d 70 20  3d 20 73 79 6d 62 6f 6c  |..  cmp = symbol|
000002c0  5f 74 61 62 6c 65 3b 0a  20 20 77 68 69 6c 65 20  |_table;.  while |
000002d0  28 6d 65 6d 63 6d 70 28  63 6d 70 2c 20 6e 61 6d  |(memcmp(cmp, nam|
000002e0  65 2c 20 6e 61 6d 65 6c  65 6e 29 20 21 3d 20 30  |e, namelen) != 0|
000002f0  20 26 26 20 63 6d 70 20  21 3d 20 28 73 79 6d 62  | && cmp != (symb|
00000300  6f 6c 5f 74 61 62 6c 65  2b 73 74 5f 6c 65 6e 67  |ol_table+st_leng|
00000310  74 68 29 20 29 0a 20 20  7b 0a 20 20 20 20 77 68  |th) ).  {.    wh|
00000320  69 6c 65 20 28 2a 63 6d  70 20 3e 3d 20 33 32 29  |ile (*cmp >= 32)|
00000330  0a 20 20 20 20 20 20 63  6d 70 2b 2b 3b 0a 20 20  |.      cmp++;.  |
00000340  20 20 63 6d 70 2b 2b 3b  0a 20 20 7d 0a 0a 20 20  |  cmp++;.  }..  |
00000350  69 66 20 28 63 6d 70 20  3d 3d 20 28 73 79 6d 62  |if (cmp == (symb|
00000360  6f 6c 5f 74 61 62 6c 65  20 2b 20 73 74 5f 6c 65  |ol_table + st_le|
00000370  6e 67 74 68 29 29 0a 20  20 20 20 72 65 74 75 72  |ngth)).    retur|
00000380  6e 28 4e 55 4c 4c 29 3b  0a 0a 20 20 77 68 69 6c  |n(NULL);..  whil|
00000390  65 20 28 2a 63 6d 70 20  21 3d 20 33 32 29 0a 20  |e (*cmp != 32). |
000003a0  20 20 20 63 6d 70 2b 2b  3b 0a 20 20 77 68 69 6c  |   cmp++;.  whil|
000003b0  65 20 28 2a 63 6d 70 20  3d 3d 20 33 32 29 0a 20  |e (*cmp == 32). |
000003c0  20 20 20 63 6d 70 2b 2b  3b 0a 0a 20 20 73 73 63  |   cmp++;..  ssc|
000003d0  61 6e 66 28 63 6d 70 2c  20 22 25 78 5c 6e 22 2c  |anf(cmp, "%x\n",|
000003e0  20 28 76 6f 69 64 2a 29  20 26 72 65 74 75 72 6e  | (void*) &return|
000003f0  5f 66 75 6e 63 29 3b 0a  20 20 72 65 74 75 72 6e  |_func);.  return|
00000400  28 72 65 74 75 72 6e 5f  66 75 6e 63 29 3b 0a 7d  |(return_func);.}|
00000410  0a                                                |.|
00000411