#include "glulxa.h"

/* Is this an opcode? */
/* If yes, return true, with the number of the opcode in temp */
int IsOpCode(char * buf, opcode **temp)
{
  (*temp) = NULL;

  for ((*temp) = opcodes;
       (((*temp) != NULL)&&(strcmp((*temp)->name,buf)!= 0));
       (*temp) = (*temp)->next);

  if ((*temp) == NULL)
    return 0;
  
  return 1;
}

/* Is this a label? */
/* if yes, return true, with the number of the label in temp or */
/* NEW_LABEL for a new one */
int IsLabel(char * buf, label ** thislabel)
{
  (*thislabel) = NULL;

  if (buf[0] != '.' && buf[0] != ':')
    return 0;

  if (!labeltable) return 1;

  for ((*thislabel) = labeltable;
       (((*thislabel) != NULL)&&(strcmp((*thislabel)->name,buf)!= 0));
       (*thislabel) = (*thislabel)->next);

  return 1;
}

int IsString(char * buf)
{
  if ((buf[0] == '\'') || (buf[0] == '\"')) return 1;

  return 0;
}

int IsHex (char * buf)
{
  if ((buf[0] == '0') && (buf[1] == 'x')) return 1;
  return 0;
}

long ParseNumber (char * buf, long * result)
{
  char fstring[4] = "%ld";

  if (IsHex(buf))
  {
    fstring[2] = 'x';
    buf = buf + 2;
  }

  if ((sscanf (buf, fstring, result)) == 0)
    return 0;
  else
    return 1;
}
  
    
      
