示例#1
0
static void free_code(struct Code *code)
{
    if (code->next)
        free_code(code->next);
    if (code->type == MACRO_CODE) {
        if (code->u.m.args)
            free_code(code->u.m.args);
    }
    free(code);
}
示例#2
0
static void free_sets(struct TestSet *set)
{
    if (set->next)
        free_sets(set->next);
    if (set->deps)
        free_deps(set->deps);
    if (set->setup)
        free_code(set->setup);
    if (set->teardown)
        free_code(set->teardown);
    if (set->tests)
        free_cases(set->tests);
    if (set->code)
        free_code(set->code);
    free(set);
}
示例#3
0
文件: main.c 项目: emctoo/schemer
// -- 
int main(void) {
	/* 
	bool b = any_of('c', "abc");
	printf("%d\n", b);
	*/ 
	/*
	char *s1 = "adaeda ; a;k;j;";
	char *s2 = "abcde ;";
	int len = strspn(s1, s2);
	printf("%d\n", len);
	*/ 
	// printf("%d\n", isalpha('3'));
    code_t *code = load_code("./code.scm");
    // printf("%s", code->code);

    identifier_t *id = alloc_identifier();
    int iter = 0;
    extract_identifier(code, iter, id);
    dealloc_identifier(id);

    free_code(code);
    return 0;

	return 0;
}
示例#4
0
static void free_cases(struct TestCase *test)
{
    if (test->next)
        free_cases(test->next);
    if (test->code)
        free_code(test->code);
    free(test);
}
示例#5
0
文件: huffman.c 项目: kingfree/haut
static void free_encoder(symcode *sc)
{
    unsigned long i;
    for (i = 0; i < MAX_SYMBOLS; ++i) {
        code *p = (*sc)[i];
        if (p)
            free_code(p);
    }
    free(sc);
}
示例#6
0
int main(void) {
    code_t *code = load_code("./code.scm");
    printf("%s", code->code);

    string_t *str = alloc_string();
    extract_string(code, 0, str);
    printf("%s", str->contents);
    dealloc_string(str);

    free_code(code);
    return 0;
}
示例#7
0
static struct Code *parse_fortran(struct TestFile *tf, int *need_array_it)
{
    struct Code *code = NEW0(struct Code);
    char *start = tf->read_pos, *tok, *save_pos;
    enum MacroType mtype;
    size_t len;

    code->type = FORTRAN_CODE;
    code->lineno = tf->lineno;

    // read lines until a recognized end sequence appears
    while (tf->read_pos < tf->file_end) {
        // look for end sequence
        save_pos = tf->read_pos;
        tok = next_token(tf, &len);
        assert(tok != NULL);
        if (is_test_token(tok, len) ||
            (same_token("end", 3, tok, len) && next_is_test_end_token(tf))) {
            break;
        } else if (tf->read_pos == tf->file_end) {
            break;
        } else { // not found, this is fortran
            tf->read_pos = save_pos;
        }

        if (find_macro(tf, &mtype, need_array_it)) {
            //  record initial fortran code
            code->u.c.str = start;
            code->u.c.len = tf->read_pos - start;
            // parse the macro
            tf->read_pos = tf->next_pos;
            code->next = parse_macro(tf, mtype, need_array_it);
            // parse_macro recurses to parse more code, so just return here
            if (!code->next)
                goto error;
            return code;
        } else {
            next_line(tf);
        }
    }
    if (tf->line_pos < tf->file_end) { // found non-fortran code
        // record bounds of fortran code
        code->u.c.str = start;
        code->u.c.len = tf->line_pos - start;
        tf->next_pos = tf->read_pos = tf->line_pos;
        return code;
    }
    syntax_error(tf);
 error:
    free_code(code);
    return NULL;
}
示例#8
0
static void
free_encoder(SymbolEncoder *pSE)
{
    unsigned long i;
    for(i = 0; i < MAX_SYMBOLS; ++i)
    {
        huffman_code *p = (*pSE)[i];
        if(p)
            free_code(p);
    }

    free(pSE);
}
示例#9
0
static struct Code *parse_support(struct TestFile *tf, const char *kind)
{
    struct Code *code = NULL;

    if (expect_eol(tf))
        goto err;

    code = parse_fortran(tf, NULL);
    if (!code)
        goto err;

    if (parse_end_sequence(tf, kind, NULL, 0))
        goto err;

    return code;
 err:
    if (code)
        free_code(code);
    return NULL;
}
示例#10
0
static struct Code *
parse_macro(struct TestFile *tf, enum MacroType mtype, int *need_array_it)
{
    struct Code *code = NEW0(struct Code);
    int error = 0;

    code->type = MACRO_CODE;
    code->lineno = tf->lineno;
    code->u.m.type = mtype;
    code->u.m.args = parse_macro_args(tf, &error);
    if (error)
        goto cleanup;
    if (code->u.m.args) {
        tf->read_pos = tf->next_pos + 1;
        code->next = parse_fortran(tf, need_array_it);
        if (code->next)
            return code;
    }
    fail(tf, tf->read_pos, "expected macro argument");
 cleanup:
    free_code(code);
    return NULL;
}
示例#11
0
文件: main.c 项目: vidarh/ACE
int dothehardpart( void )
{
  int len, c, n=0;
  int faux_pas= 0;
  long codesize= 0;

  /* initialize globals */

  numsyms= numlines= 0;

  /* begin scanning the input stream */

  c= fgetc(fin);

  if(c != 0xf5)
  {
    warn("Hmmm... this doesn't look like an AmigaBASIC binary.\n"
         "My output will probably look a bit funny.  Proceed, for a laugh.");
  }

  if( feof(fin) || ferror(fin) )
  { warn("unexpected end of input -- no code, no symbols");
    return 1;
  }

  /* read the code segment */

  do {

    /* Stefan Reisner thought that AmigaBASIC encodes the length of a line
     * in a 2 byte word prefix.  This is not the whole truth...
     * I've experienced that the first byte holds a flag (e.g. 0x80 indicates
     * a line number) and only the second byte encodes the length.
     */

    c= fgetc(fin); /* flags */

    if( len= fgetc(fin) )
    {
      codesize += len;
      len-= 2;

      if( !feof(fin) && !ferror(fin) )
        n= read_line(fin,len,c);
    }

  } while( len && n == len && !ferror(fin) && !feof(fin) );

  if( len )
  {
    if( n != len || ferror(fin) )
    {
      warn("I'm confused; after having read the code segment, I still seem\n"
           "to want to go on.  In fact I just wanted to read another %d bytes\n"
           "when a serious problem interrupted me.  I'll try to forget about this.",len);
    }

    if( feof(fin) )
    {
      warn("Uh, oh.  I suspect there was a null missing at the end of the code segment,\n"
           "causing me to read past where I should stop.\n"
           "I'll forget about the symbols now.  Proceed, with fingers crossed.");
    }
  }
  else if( feof(fin) || ferror(fin) ) /* and len <= 0 */
    warn("This seems to be a funny program.  The input ended without any symbol definitions.\n");

  /* read the symbols */

  if( !ferror(fin) && !feof(fin) )
  {
    int ok= 1;

#ifdef DEBUG
    if(debuglevel >= 1)
      fprintf(stderr,"skipping a '\\x%02x' character\n",fgetc(fin));
    else
#endif
      (void)fgetc(fin);  /* skip null byte */

    if( (codesize & 1) == 0 )
    {
#ifdef DEBUG
      if(debuglevel >= 1)
        fprintf(stderr,"skipping another '\\x%02x' character\n",fgetc(fin));
      else
#endif
      (void)fgetc(fin);
    }

    if( feof(fin) || ferror(fin) )
    {
      warn("I was just about to read the symbols when I reached the end of file.\n"
           "Maybe we have a BASIC program without symbols?  We'll see...");
    }

    else do {
      len= fgetc(fin);

      if( !feof(fin) )
        ok= read_sym(fin, len, numsyms++);

    } while( ok && !feof(fin) && !ferror(fin) );

    if( !ok )
    {
      warn("After having read %ld %s I couldn't get another %d bytes.\n"
           "Maybe there is not enough free store?  I'll better stop reading symbols!",
           numsyms-1, (numsyms-1 == 1) ? "symbol": "symbols");
    }
  }

#ifdef DEBUG
    if(debuglevel >= 1)
      fprintf(stderr,"expanding %ld lines of code w/ %d symbols\n",numlines,numsyms);
#endif

  expand_code();

  /* we _must_ call these to become re-entrant */

  free_symbols();
  free_code();

  return faux_pas;
}