view table.c @ 2:ec2f8f6f1dc9

Cleanup pass #1: Get rid of some ancient K&R-isms.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Feb 2015 20:28:57 +0200
parents 4410c9c7750d
children a2a81589380d
line wrap: on
line source

/*\
 *  dxa v0.1.1 -- symbolic 65xx disassembler
 *
 *  Copyright (C) 1993, 1994 Marko M\"akel\"a
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Contacting the author:
 *
 *   Via Internet E-mail:
 *      <Marko.Makela@FTP.FUNET.FI>
 *
 *   Via Snail Mail:
 *      Marko M\"akel\"a
 *      Sillitie 10 A
 *      FIN-01480 VANTAA
 *      Finland
\*/

/* table.c */
#define _TABLE_C_

#include <stdlib.h>
#include "proto.h"

static unsigned int firstunused = 0;


table *FindNextEntryType (table *entry, unsigned char andmask,
                          unsigned char eormask)
{
  if (!scantable) return NULL;

  if (!entry || entry >= &scantable[entrycount])
    entry = scantable;
  else if (++entry >= &scantable[entrycount])
    return NULL;

  for (; entry < &scantable[entrycount]; entry++)
    if (entry->type && !((entry->type & andmask) ^ eormask))
      return entry;

  return NULL;
}


table *FindNextEntryTypeParent (table *entry, ADDR_T parent,
                            unsigned char andmask, unsigned char eormask)
{
  if (!scantable) return NULL;


  if (!entry || entry >= &scantable[entrycount])
    entry = scantable;
  else if (++entry >= &scantable[entrycount])
    return NULL;

  for (; entry < &scantable[entrycount]; entry++)
    if (entry->parent == parent && entry->type &&
        !((entry->type & andmask) ^ eormask))
      return entry;

  return NULL;
}


table *FindNextEntry (table *entry, ADDR_T address,
                      unsigned char andmask, unsigned char eormask)
{
  if (!scantable) return NULL;

  if (!entry || entry >= &scantable[entrycount])
    entry = scantable;
  else if (++entry >= &scantable[entrycount])
    return NULL;

  for (; entry < &scantable[entrycount]; entry++)
    if (entry->address == address && entry->type &&
        !((entry->type & andmask) ^ eormask))
      return entry;

  return NULL;
}


void AddEntry (ADDR_T address, ADDR_T parent, unsigned char type)
{
  if (firstunused < entrycount) {
    scantable[firstunused].address = address;
    scantable[firstunused].parent = parent;
    scantable[firstunused].type = type;

    while (++firstunused < entrycount && scantable[firstunused].type);
  }
  else {
    scantable = scantable ?
      realloc (scantable, (entrycount + 1) * sizeof *scantable) :
      malloc (sizeof *scantable);

    scantable[entrycount].address = address;
    scantable[entrycount].parent = parent;
    scantable[entrycount].type = type;

    firstunused = ++entrycount;
  }
}


void DeleteEntry (table *entry)
{
  entry -> type = TBL_DELETED;

  if (firstunused > entry - scantable)
    firstunused = entry - scantable;
}