コード例 #1
0
ファイル: stat.c プロジェクト: frasten/table-compiler
Code write_stat(Pnode p)
{
    /*
         WRITE_STAT
            /
           /
        N_SPECIFIER --> expr
             /
            /
        [expr-filename]
     */
    Value format;
    int op;
    Schema exprschema;
    Code code = expr(p->child->brother, &exprschema);

    if (p->child->child != NULL)
    {
        // Con specifier
        code = appcode(code, specifier(p->child));
        op = T_FPRINT;
    }
    else
    {
        // Senza specifier
        op = T_PRINT;
    }
    format.sval = get_format(&exprschema);
    free_schema(exprschema.next);
    return concode(
        code,
        makecode1(op, format),
        endcode()
        );
}
コード例 #2
0
ファイル: stat.c プロジェクト: frasten/table-compiler
Code tuple_const(Pnode p, Pschema s)
{
    Pschema schema;
    // Scorro tutti gli elementi della tupla
    Code result = endcode();
    Pnode elem;
    for (elem = p->child; elem != NULL; elem = elem->brother)
    {
        Code elemcode;
        switch (elem->type)
        {
            case N_INTCONST:
            case N_BOOLCONST:
                elemcode = makecode1(T_IATTR, elem->value); break;
            case N_STRCONST:
                elemcode = makecode1(T_SATTR, elem->value); break;
            default: noderror(elem);
        }
        if (result.head == NULL)
            result = elemcode;
        else
            result = appcode(result, elemcode);
    }

    // Type checking
    schema = tuple_to_schema(p);
    if (!type_equal(schema, s))
        semerror(p, "Incompatible tuples in table constant");
    free_schema(schema);

    return result;
}
コード例 #3
0
ファイル: stat.c プロジェクト: frasten/table-compiler
Code assign_stat(Pnode p)
{
    Psymbol symbol;
    Code exprcode;
    Schema exprschema;
/*
    assign_stat
        /
       /
      ID ---> expr
 */

    // Semantica: Carico gli schemi di ID e expr
    symbol = lookup(valname(p->child));
    if (symbol == NULL)
        semerror(p->child, "Undefined identifier in assignment");

    exprcode = expr(p->child->brother, &exprschema);

    // Type checking:
    if (!type_equal(symbol->schema, &exprschema))
        semerror(p->child->brother, "Incompatible types in assignment");

    if (exprschema.next != NULL)
        free_schema(exprschema.next);

    Value v1; v1.ival = symbol->oid;
    return concode(
        exprcode,
        makecode1(T_STO, v1),
        endcode());
}
コード例 #4
0
ファイル: instructions.c プロジェクト: nzaghen/ymachine
void free_schema(Pschema schema){
    Pschema p = schema;
    while (p != NULL){
        if(p->child != NULL){
            free_schema(p->child);
        }
        Pschema temp = p;
        p = p->brother;
        freemem((char *)temp, sizeof(Schema));
    }
}
コード例 #5
0
ファイル: symtab.c プロジェクト: frasten/table-compiler
void eliminate(char *name)
{
    int index;
    Psymbol psymb, prec;

    index = hash_function(name);
    prec = psymb = symtab[index];
    while(psymb != NULL)
    {
        if(psymb->schema->name == name)
        {
            if(psymb == prec)
                symtab[index] = psymb->next;
            else
                prec->next = psymb->next;
            free_schema(psymb->schema);
            freemem(psymb, (int)sizeof(Symbol));
            return;
        }
        prec = psymb;
        psymb = psymb->next;
    }
    syserror("No name to be removed from symbol table");
}
コード例 #6
0
ファイル: instructions.c プロジェクト: nzaghen/ymachine
void exec_rd(char* format, int pretty, FILE *in_file){
    Pschema s = parse_schema(format);
    input_schema(s, NULL, 0, pretty, in_file);
    free_schema(last_parsed_format);
}
コード例 #7
0
ファイル: instructions.c プロジェクト: nzaghen/ymachine
void exec_wr(char* format, int pretty, FILE *out){
    Pschema s = parse_schema(format);
    Odescr *op = top_tstack();
    print_instance(op->inst.sval, s, NULL, 0, op->mode, pretty, out); // use the raw instance information
    free_schema(last_parsed_format);
}
コード例 #8
0
ファイル: dbfilter-cidr.c プロジェクト: therealchash/db
int
main(int argc, char **argv) {
  // Parse options.
  static struct option long_options[] = {
    {"help", no_argument, NULL, 'h'},
    {NULL, 0, NULL, 0}
  };
  const char *options = "h";
  char opt;
  while ((opt = getopt_long(argc, argv, options, long_options, NULL)) != -1) {
    switch (opt) {
      case 'h':
        usage(argv[0], EXIT_SUCCESS);
        break;
      default:
        perr(argv[0], "unrecognized option '%c'\n", opt);
        usage(argv[0], EXIT_FAILURE);
        break;
    }
  }

  int nargs = argc - optind;
  if (nargs == 0 || nargs % 2 != 0) {
    // Expected at least one column name, ACL path pair.
    perr(argv[0], "missing required arguments\n");
    exit(EXIT_FAILURE);
  }

  // Parse the input #db header and replay it.
  char *header = read_header(stdin);
  schema_t schema;
  if (parse_header(header, &schema) != 0) {
    perr(argv[0], "error parsing #db header\n");
    exit(EXIT_FAILURE);
  }
  printf("%s\n", header);

  int i;

  // Initialize ACLs.
  acls_t acls = {calloc(sizeof (netacl_t *), schema.ncols), 0};
  for (i = optind; i < argc; i += 2) {
    char *name = argv[i];
    char *acl_path = argv[i+1];

    column_t *column = get_column(&schema, name);
    if (!column) {
      fprintf(stderr, "column '%s' is not present\n", name);
      exit(EXIT_FAILURE);
    }

    // Determine the maximum column index for which an ACL exists, so that we
    // can short circuit tokenization later.
    acls.size = MAX(column->index, acls.size);

    int ret;
    netacl_t *acl = malloc(sizeof (netacl_t));
    if ((ret = netacl_from_path(acl_path, acl)) != 0) {
      fprintf(stderr, "could not initialize ACL from path '%s'\n", acl_path);
      exit(EXIT_FAILURE);
    }

    acls.acls[column->index - 1] = acl;
  }

  // Apply the ACLs to the input data.
  filter(&acls);

#ifdef DEBUG
  // Free things.
  for (i = 0; i < acls.size; i++) {
    if (acls.acls[i]) {
      netacl_destroy(acls.acls[i]);
    }
  }
  free(acls.acls);
  free_schema(&schema);
  free(header);
#endif

  return 0;
}