Exemple #1
0
//--------------------------------------------------------------------------
static void load_symbols(const char *file)
{
  free_syms();
  if ( file == NULL )
    return;
  char cfgpath[QMAXPATH];
  const char *rfile = getsysfile(cfgpath, sizeof(cfgpath), file, CFG_SUBDIR);
  if ( rfile == NULL )
  {
NOFILE:
//    warning("Can't open %s, symbol definitions are not loaded", file);
    return;
  }
  FILE *fp = fopenRT(rfile);
  if ( fp == NULL )
    goto NOFILE;
  int ln = 0;
  char line[MAXSTR];
  while ( qfgets(line, sizeof(line), fp) )
  {
    ln++;
    line[strlen(line)-1] = '\0';
    trim(line);
    if ( line[0] == ';' || line[0] == ' ' || line[0] == '\0' ) continue;
    char word[MAXSTR];
    int addr;
    if ( sscanf(line, "%s %i", word, &addr) != 2 )
    {
      warning("%s: syntax error at line %d", file, ln);
      break;
    }
    int i;
    for ( i=0; i < numsyms; i++)
    {
      if ( syms[i].address == addr && strcmp(syms[i].name, word) != 0 )
      {
        warning("%s: duplicate address %#x at line %d", file, addr, ln);
        break;
      }
    }
    if ( i != numsyms ) break;
    syms = qrealloc_array<sym_t>(syms, numsyms + 1);
    if ( syms == NULL ) nomem("h8/500 symbols");
    syms[numsyms].address = addr;
    syms[numsyms].name = qstrdup(word);
    numsyms++;
  }
  qfclose(fp);
}
Exemple #2
0
 //--------------------------------------------------------------------------
 PyObject *gets(int size)
 {
   do
   {
     char *buf = (char *) malloc(size + 5);
     if ( buf == NULL )
       break;
     PYW_GIL_CHECK_LOCKED_SCOPE();
     char *p;
     Py_BEGIN_ALLOW_THREADS;
     p = qfgets(buf, size, fp);
     Py_END_ALLOW_THREADS;
     if ( p == NULL )
     {
       free(buf);
       break;
     }
     PyObject *ret = PyString_FromString(buf);
     free(buf);
     return ret;
   } while ( false );
   Py_RETURN_NONE;
 }