Ejemplo n.º 1
0
Archivo: dbpack.c Proyecto: braddr/cold
static Method *unpack_method(cBuf *buf, Long *buf_pos)
{
    Int     i, j, n;
    Method *method;
    Int     name;

    /* Read in the name.  If this is -1, it was a marker for a blank entry. */
    name = read_ident(buf, buf_pos);
    if (name == NOT_AN_IDENT)
	return NULL;

    method = EMALLOC(Method, 1);

    method->name = name;
    method->m_access = read_long(buf, buf_pos);
    method->m_flags = read_long(buf, buf_pos);
    method->native = read_long(buf, buf_pos);
    method->refs = 1;

    method->num_args = read_long(buf, buf_pos);
    if (method->num_args) {
	method->argnames = TMALLOC(Int, method->num_args);
	for (i = 0; i < method->num_args; i++) {
	    method->argnames[i] = read_long(buf, buf_pos);
        }
    }
    method->rest = read_long(buf, buf_pos);

    method->num_vars = read_long(buf, buf_pos);
    if (method->num_vars) {
	method->varnames = TMALLOC(Int, method->num_vars);
	for (i = 0; i < method->num_vars; i++) {
	    method->varnames[i] = read_long(buf, buf_pos);
        }
    }

    method->num_opcodes = read_long(buf, buf_pos);
    method->opcodes = TMALLOC(Long, method->num_opcodes);
    for (i = 0; i < method->num_opcodes; i++)
	method->opcodes[i] = read_long(buf, buf_pos);

    method->num_error_lists = read_long(buf, buf_pos);
    if (method->num_error_lists) {
	method->error_lists = TMALLOC(Error_list, method->num_error_lists);
	for (i = 0; i < method->num_error_lists; i++) {
	    n = read_long(buf, buf_pos);
	    method->error_lists[i].num_errors = n;
	    method->error_lists[i].error_ids = TMALLOC(Int, n);
	    for (j = 0; j < n; j++)
		method->error_lists[i].error_ids[j] = read_ident(buf, buf_pos);
	}
    }

    return method;
}
Ejemplo n.º 2
0
extern void do_set (void)
{
   char *mac;
   char c;
   char temp[64];

   mac = read_ident();
   if (! mac)
   {
      err_head();
      fprintf(stderr, "@set: missing/illegal macro name\n");
      return ;
   }
   if (! in_false_if())
   {
      char *cp;
      c = getnonspace();
      if (c != '(')
      {
         err_head();
         fprintf(stderr, "@set must have ()s\n");
         Push(c);
         return ;
      }
      os_sprintf(temp, "%d", eval_expr(0, 1));
      undef(mac);
      cp = copyofstr(temp);
      check_os_malloc(cp);
      define(mac, -1, (unsigned char *) cp, DEF_DEFINE);
   }
   os_free(mac);
}
Ejemplo n.º 3
0
Archivo: dbpack.c Proyecto: braddr/cold
void unpack_object(cBuf *buf, Long *buf_pos, Obj *obj)
{
    obj->parents = unpack_list(buf, buf_pos);
    obj->children = unpack_list(buf, buf_pos);
    unpack_vars(buf, buf_pos, obj);
    unpack_methods(buf, buf_pos, obj);
    obj->objname = read_ident(buf, buf_pos);
}
Ejemplo n.º 4
0
void unpack_handled (cBuf *buf, Long *buf_pos, cData *d)
{
    HandledFrob *h=TMALLOC(HandledFrob, 1);

    h->cclass = read_long(buf, buf_pos);
    unpack_data (buf, buf_pos, &h->rep);
    h->handler = read_ident(buf, buf_pos);
    d->u.instance = (void*) h;
}
Ejemplo n.º 5
0
Archivo: dbpack.c Proyecto: braddr/cold
static void unpack_idents(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;

    obj->methods->idents_size = read_long(buf, buf_pos);
    obj->methods->num_idents = read_long(buf, buf_pos);
    obj->methods->idents = EMALLOC(Ident_entry, obj->methods->idents_size);
    for (i = 0; i < obj->methods->num_idents; i++) {
	obj->methods->idents[i].id = read_ident(buf, buf_pos);
	if (obj->methods->idents[i].id != NOT_AN_IDENT)
	    obj->methods->idents[i].refs = read_long(buf, buf_pos);
    }
}
Ejemplo n.º 6
0
Archivo: dbpack.c Proyecto: braddr/cold
static void unpack_vars(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;

    obj->vars.size = read_long(buf, buf_pos);
    obj->vars.blanks = read_long(buf, buf_pos);

    obj->vars.hashtab = EMALLOC(Int, obj->vars.size);
    obj->vars.tab = EMALLOC(Var, obj->vars.size);

    for (i = 0; i < obj->vars.size; i++) {
	obj->vars.hashtab[i] = read_long(buf, buf_pos);
	obj->vars.tab[i].name = read_ident(buf, buf_pos);
	if (obj->vars.tab[i].name != NOT_AN_IDENT) {
	    obj->vars.tab[i].cclass = read_long(buf, buf_pos);
	    unpack_data(buf, buf_pos, &obj->vars.tab[i].val);
	}
	obj->vars.tab[i].next = read_long(buf, buf_pos);
    }

}
Ejemplo n.º 7
0
extern void do_undef (int sharp)
{
   char *mac;

   if (! in_false_if())
   {
      mac = read_ident();
      if (! mac)
      {
         err_head();
         fprintf(stderr, "missing/illegal macro name\n");
      }
      else
      {
         undef (mac);
      }
   }
   if (sharp)
   {
      flush_sharp_line();
   }
}
Ejemplo n.º 8
0
void do_ifndef (int sharp)
{
   char *w;

#ifdef DEBUG_IF

   if (debugging)
   {
      outputc('<');
      outputc(sharp ? '#' : '@');
      outputs("ifndef: ");
      // fflush(outfile);
   }
#endif
   if (in_false_if())
   {
      n_skipped_ifs ++;
#ifdef DEBUG_IF

      if (debugging)
      {
         outputs("in-false, skipped>");
         // fflush(outfile);
      }
#endif

   }
   else
   {
      w = read_ident();
      if (! w)
      {
#ifdef DEBUG_IF
         if (debugging)
         {
            outputs("no ident ");
            // fflush(outfile);
         }
#endif
         iftrue();
      }
      else
      {
#ifdef DEBUG_IF
         if (debugging)
         {
            outputs(w);
            outputc(' ');
            // fflush(outfile);
         }
#endif
         if (find_def(w))
         {
            iffalse();
         }
         else
         {
            iftrue();
         }
         os_free(w);
      }
#ifdef DEBUG_IF
      if (debugging)
      {
         outputc('>');
         // fflush(outfile);
      }
#endif

   }
   if (sharp)
   {
      flush_sharp_line();
   }
}
Ejemplo n.º 9
0
/* flags: only XML_IGNORE_CASE is handled */
void css_parse_style_sheet(CSSStyleSheet *s, CSSParseState *b)
{
    char value[1024];
    char tag[64];
    char tag_id[64];
    char *q;
    int ch, media, val, last_tree_op, i;
    CSSStyleSheetEntry *e, **first_eprops;
    CSSSimpleSelector ss2, *ss = &ss2, *last_ss, *ss1;
    CSSProperty *props;

    ch = bgetc(b);
    media = CSS_MEDIA_ALL;
    for (;;) {
redo:
        first_eprops = s->plast_entry;
        bskip_spaces(b, &ch);
        if (ch == EOF)
            break;
        /* eat inserted HTML comments for compatible STYLE tag parsing */
        if (ch == '<') {
            beat(b, &ch, "<!--");
            goto redo;
        } else if (ch == '-') {
            beat(b, &ch, "-->");
            goto redo;
        }

        /* handle '@media { ... }' */
        if (ch == '@') {
            ch = bgetc(b);
            read_ident(b, &ch, tag, sizeof(tag));
            switch (css_get_enum(tag, "media,page")) {
            case 0:
                /* @media */
                media = 0;
                for (;;) {
                    bskip_spaces(b, &ch);
                    read_ident(b, &ch, tag, sizeof(tag));
                    val = css_get_enum(tag, "tty,screen,print,tv,speech,all");
                    if (val < 0 || val == 5)
                        media = CSS_MEDIA_ALL;
                    else
                        media |= (1 << val);
                    bskip_spaces(b, &ch);
                    if (ch == ',') {
                        ch = bgetc(b);
                    } else if (ch == '{' || ch == EOF) {
                        ch = bgetc(b);
                        break;
                    }
                }
                goto redo;
            case 1:
                /* @page */
                bskip_spaces(b, &ch);
                if (ch != '{') {
                    read_ident(b, &ch, tag_id, sizeof(tag_id));
                    bskip_spaces(b, &ch);
                }
                memset(ss, 0, sizeof(CSSSimpleSelector));
                ss->tag = css_new_ident("@page");
                if (tag_id[0] != '\0')
                    ss->tag_id = css_new_ident(tag_id);
                add_style_entry(s, ss, media);
                goto parse_props;
            default:
                css_error1(b, "unrecognized css directive '@%s'", tag);
                break;
            }
        } else if (ch == '}') {
            /* XXX: end of media, should unstack */
            ch = bgetc(b);
            goto redo;
        }

        /* parse a selector list */
        for (;;) {
            /* parse simple selectors with operations */
            last_ss = NULL;
            last_tree_op = CSS_TREE_OP_NONE;
            for (;;) {
                int tree_op;
                bskip_spaces(b, &ch);
                parse_simple_selector(ss, b, &ch);
                bskip_spaces(b, &ch);
                ss->tree_op = last_tree_op;
                ss->next = last_ss;
                if (ch == '+') {
                    tree_op = CSS_TREE_OP_PRECEEDED;
                    ch = bgetc(b);
                    goto add_tree;
                } else if (ch == '>') {
                    tree_op = CSS_TREE_OP_CHILD;
                    ch = bgetc(b);
                    goto add_tree;
                } else if (isalpha(ch)) {
                    tree_op = CSS_TREE_OP_DESCENDANT;
add_tree:
                    ss1 = malloc(sizeof(CSSSimpleSelector));
                    if (ss1) {
                        memcpy(ss1, ss, sizeof(CSSSimpleSelector));
                        last_ss = ss1;
                    }
                    last_tree_op = tree_op;
                } else {
                    /* other char: exit */
                    break;
                }
            }
            add_style_entry(s, ss, media);

            /* get next selector, if present */
            if (ch != ',')
                break;
            ch = bgetc(b);
        }
parse_props:
        /* expect start of properties */
        if (ch != '{')
            break;
        ch = bgetc(b);

        q = value;
        while (ch != '}' && ch != EOF) {
            if ((q - value) < (int)sizeof(value) - 1)
                *q++ = ch;
            ch = bgetc(b);
        }
        *q = '\0';

        if (ch == '}')
            ch = bgetc(b);

        /* the properties are extracted, now add them to each tag */
        /* XXX: should locate entries first, then add, to avoid adding
           duplicate entries */
        /* XXX: should put font properties first to avoid em/ex units
           problems, but it would still not be sufficient. */
        props = css_parse_properties(b, value);
        i = 0;
        for (e = *first_eprops; e != NULL; e = e->next) {
            if (i == 0)
                e->props = props;
            else
                e->props = dup_properties(props);
            i++;
        }
    }
#ifdef DEBUG
    css_dump_style_sheet(s);
#endif
}
Ejemplo n.º 10
0
static void parse_simple_selector(CSSSimpleSelector *ss, CSSParseState *b,
                                  int *ch_ptr)
{
    char value[1024];
    char tag[64];
    char tag_id[64];
    char attribute[64];
    int ch, pclass, val;
    CSSStyleSheetAttributeEntry *first_attr, **last_attr;

    ch = *ch_ptr;

    /* read the tag */
    first_attr = NULL;
    last_attr = &first_attr;
    tag[0] = '\0';
    tag_id[0] = '\0';
    pclass = 0;
    read_ident(b, &ch, tag, sizeof(tag));
    if (b->ignore_case)
        css_strtolower(tag, sizeof(tag));

    /* read '.class', '[xxx]', ':pseudo-class' */
    for (;;) {
        bskip_spaces(b, &ch);
        if (ch == '.') {
            /* read the class and add it as an attribute */
            ch = bgetc(b);
            read_ident(b, &ch, value, sizeof(value));
            add_attribute(&last_attr, CSS_ID_class, CSS_ATTR_OP_EQUAL, value);
        } else if (ch == '#') {
            /* read the id */
            ch = bgetc(b);
            read_ident(b, &ch, tag_id, sizeof(tag_id));
        } else if (ch == '[') {
            /* read the attribute */
            int op;
            ch = bgetc(b);
            read_ident(b, &ch, attribute, sizeof(attribute));
            if (b->ignore_case)
                css_strtolower(attribute, sizeof(attribute));

            switch (ch) {
            case '~':
                op = CSS_ATTR_OP_IN_LIST;
                ch = bgetc(b);
                goto get_value;
            case '=':
                op = CSS_ATTR_OP_EQUAL;
                goto get_value;
            case '|':
                op = CSS_ATTR_OP_IN_HLIST;
                ch = bgetc(b);
get_value:
                ch = bgetc(b);
                if (ch == '\"' || ch == '\'') {
                    read_string(b, &ch, value, sizeof(value));
                } else {
                    read_ident(b, &ch, value, sizeof(value));
                }
                break;
            case ']':
                op = CSS_ATTR_OP_SET;
                value[0] = '\0';
                break;
            default:
                dprintf("op: incorrect char '%c'\n", ch);
                return; /* cannot do more */
            }
            if (ch == ']')
                ch = bgetc(b);
            add_attribute(&last_attr, css_new_ident(attribute), op, value);
        } else if (ch == ':') {
            ch = bgetc(b);
            read_ident(b, &ch, value, sizeof(value));
            val = css_get_enum(value, "first-child,link,visited,active,hover,focus,first-line,first-letter,before,after");
            if (val >= 0)
                pclass |= 1 << val;
        } else {
            break;
        }
    }
    memset(ss, 0, sizeof(CSSSimpleSelector));
    if (tag[0] == '\0') {
        ss->tag = CSS_ID_ALL;
    } else {
        ss->tag = css_new_ident(tag);
    }
    if (tag_id[0] != '\0') {
        /* XXX: not fully correct, but good enough for now */
        add_attribute(&last_attr, CSS_ID_id, CSS_ATTR_OP_EQUAL, value);
        /* we also add the id, just in case we use it in the futur */
        ss->tag_id = css_new_ident(tag_id);
    }
    ss->attrs = first_attr;
    ss->pclasses = pclass;

    *ch_ptr = ch;
}
Ejemplo n.º 11
0
Archivo: dbpack.c Proyecto: braddr/cold
void unpack_data(cBuf *buf, Long *buf_pos, cData *data)
{
    data->type = read_long(buf, buf_pos);
    switch (data->type) {

        case INTEGER:
            data->u.val = read_long(buf, buf_pos);
            break;

        case FLOAT:
            data->u.fval = read_float(buf, buf_pos);
            break;

        case STRING:
            data->u.str = string_unpack(buf, buf_pos);
            break;

        case OBJNUM:
            data->u.objnum = read_long(buf, buf_pos);
            break;

        case LIST:
            data->u.list = unpack_list(buf, buf_pos);
            break;

        case SYMBOL:
            data->u.symbol = read_ident(buf, buf_pos);
            break;

        case T_ERROR:
            data->u.error = read_ident(buf, buf_pos);
            break;

        case FROB:
            data->u.frob = TMALLOC(cFrob, 1);
            data->u.frob->cclass = read_long(buf, buf_pos);
            unpack_data(buf, buf_pos, &data->u.frob->rep);
            break;

        case DICT:
            data->u.dict = unpack_dict(buf, buf_pos);
            break;

        case BUFFER: {
            Int len;

            len = read_long(buf, buf_pos);
            data->u.buffer = buffer_new(len);
            data->u.buffer->len = len;
            MEMCPY(data->u.buffer->s, &(buf->s[*buf_pos]), len);
            (*buf_pos) += len;
            break;
        }

#ifdef USE_PARENT_OBJS
        case OBJECT:
            break;
#endif

        default: {
            INSTANCE_RECORD(data->type, r);
            r->unpack(buf, buf_pos, data);
        }
    }
}
Ejemplo n.º 12
0
Archivo: lex.c Proyecto: zoncoen/8ccc
static Token *read_token_int(void)
{
    int c = getc_nonspace();
    switch (c) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            return read_number(c);
        case '"':
            return read_string();
        case '\'':
            return read_char();
        case 'a':
        case 'b':
        case 'c':
        case 'd':
        case 'e':
        case 'f':
        case 'g':
        case 'h':
        case 'i':
        case 'j':
        case 'k':
        case 'l':
        case 'm':
        case 'n':
        case 'o':
        case 'p':
        case 'q':
        case 'r':
        case 's':
        case 't':
        case 'u':
        case 'v':
        case 'w':
        case 'x':
        case 'y':
        case 'z':
        case 'A':
        case 'B':
        case 'C':
        case 'D':
        case 'E':
        case 'F':
        case 'G':
        case 'H':
        case 'I':
        case 'J':
        case 'K':
        case 'L':
        case 'M':
        case 'N':
        case 'O':
        case 'P':
        case 'Q':
        case 'R':
        case 'S':
        case 'T':
        case 'U':
        case 'V':
        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
        case '_':
            return read_ident(c);
        case '/':
        case '=':
        case '*':
        case '+':
        case '-':
        case '(':
        case ')':
        case ',':
        case ';':
            return make_punct(c);
        case EOF:
            return NULL;
        default:
            error("Unexpected character: '%c'", c);
    }
}
Ejemplo n.º 13
0
static Token *read_token_int(void) {
  int c = getc_nonspace();
  switch (c) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      return read_number(c);
    case 'a':
    case 'b':
    case 'c':
    case 'd':
    case 'e':
    case 'f':
    case 'g':
    case 'h':
    case 'i':
    case 'j':
    case 'k':
    case 'l':
    case 'm':
    case 'n':
    case 'o':
    case 'p':
    case 'q':
    case 'r':
    case 's':
    case 't':
    case 'u':
    case 'v':
    case 'w':
    case 'x':
    case 'y':
    case 'z':
    case 'A':
    case 'B':
    case 'C':
    case 'D':
    case 'E':
    case 'F':
    case 'G':
    case 'H':
    case 'I':
    case 'J':
    case 'K':
    case 'L':
    case 'M':
    case 'N':
    case 'O':
    case 'P':
    case 'Q':
    case 'R':
    case 'S':
    case 'T':
    case 'U':
    case 'V':
    case 'W':
    case 'X':
    case 'Y':
    case 'Z':
    case '_':
      return read_ident(c);
    case '*':
    case '/':
    case '(':
    case ')':
    case ',':
    case ';':
    case '[':
    case ']':
    case '{':
    case '}':
    case '<':
    case '>':
    case '!':
    case '?':
    case ':':
    case '.':
      return make_punct(c);
    case '-':
      c = getc(stdin);
      if (c == '-') return make_punct(PUNCT_DEC);
      if (c == '>') return make_punct(PUNCT_ARROW);
      ungetc(c, stdin);
      return make_punct('-');
    case '=':
      return read_rep('=', '=', PUNCT_EQ);
    case '+':
      return read_rep('+', '+', PUNCT_INC);
    case '&':
      return read_rep('&', '&', PUNCT_LOGAND);
    case '|':
      return read_rep('|', '|', PUNCT_LOGOR);
    case '"':
      return read_string();
    case '\'':
      return read_char();
    case EOF:
      return NULL;
    default:
      error("Unexpected character: '%c'", c);
  }
}
Ejemplo n.º 14
0
static EORB_CPP_node *read_expr_10 (void)
{
   char c;
   char *w;
   EORB_CPP_node *n;

#ifdef DEBUG_EXPR

   if (debugging)
   {
      outputs("~E10:");
   }
#endif
   while (1)
   {
      c = getnhsexpand();
      switch (c)
      {
         case '-':
         case '~':
         case '!':
#ifdef DEBUG_EXPR

            if (debugging)
            {
               outputc(c);
            }
#endif
            n = read_expr_10();
#ifdef DEBUG_EXPR

            if (debugging)
            {
               outputs("~");
            }
#endif
            return (newnode(0, c, n));
            break;
         case 'd':
            Push(c);
            input_mark();
            w = read_ident();
            if (strcmp(w, "defined") == 0)
            {
               c = getnonspace();
               if (c == '(')
               {
                  char *id;
                  id = read_ident();
                  if (id)
                  {
                     c = getnonspace();
                     if (c == ')')
                     {
                        input_unmark();
#ifdef DEBUG_EXPR

                        if (debugging)
                        {
                           outputs("ifdef");
                        }
#endif
                        return (newname(id));
                     }
                  }
               }
               else if (isbsymchar(c))
               {
                  char *id;
                  Push(c);
                  id = read_ident();
                  if (id)
                  {
                     input_unmark();
#ifdef DEBUG_EXPR

                     if (debugging)
                     {
                        outputs("ifdef");
                     }
#endif
                     return (newname(id));
                  }
               }
            }
            input_recover();
            n = read_expr_11();
#ifdef DEBUG_EXPR

            if (debugging)
            {
               outputs("~");
            }
#endif
            return (n);
            break;
         default:
            Push(c);
            n = read_expr_11();
#ifdef DEBUG_EXPR

            if (debugging)
            {
               outputs("~");
            }
#endif
            return (n);
            break;
      }
   }
}
Ejemplo n.º 15
0
static EORB_CPP_node *read_expr_11 (void)
{
   char c;

#ifdef DEBUG_EXPR

   if (debugging)
   {
      outputs("~E11:");
   }
#endif
   while (1)
   {
      c = getnhsexpand();
      if (c == '(')
      {
         EORB_CPP_node *n;
#ifdef DEBUG_EXPR

         if (debugging)
         {
            outputs("()");
         }
#endif
         n = read_expr_();
         c = getnhsexpand();
         if (c != ')')
         {
            err_head();
            fprintf(stderr, "expression syntax error -- missing ) supplied\n");
            Push(c);
         }
#ifdef DEBUG_EXPR
         if (debugging)
         {
            outputs("~");
         }
#endif
         return (n);
      }
      else if (isdigit((int) c))
      {
         int base;
         static char digits[] = "0123456789abcdefABCDEF";
         static char values[] =
            "\0\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17\12\13\14\15\16\17";
         char *d;
         int v;
#ifdef DEBUG_EXPR

         if (debugging)
         {
            outputs("N");
         }
#endif
         base = 10;
         if (c == '0')
         {
            base = 8;
            c = Get();
            if ((c == 'x') || (c == 'X'))
            {
               base = 16;
               c = Get();
            }
         }
         v = 0;
         while (1)
         {
            d = strchr(digits, c);
            if (d == 0)
            {
               Push(c);
#ifdef DEBUG_EXPR

               if (debugging)
               {
                  outputd(v);
                  outputs("~");
               }
#endif
               return (newleaf(v));
            }
            else if (values[d -digits] >= base)
            {
               err_head();
               fprintf(stderr, "warning: illegal %sdigit `%c'\n",
                       (base == 16) ? "hex " : (base == 8) ? "octal " : "", c);
            }
            v = (v * base) + values[d - digits];
            c = Get();
         }
      }
      else if (c == '\'')
      {
         int i;
         int j;
         int n;
         i = 0;
         n = 0;
         while (1)
         {
            j = get_quote_char();
            if (j < 0)
            {
               break;
            }
            i = (i << 8) | j;
            n ++;
         }
         if (n > 4)
         {
            err_head();
            fprintf(stderr, "warning: too many characters in character constant\n");
         }
         return (newleaf(i));
      }
      else if ((c == '\n') && !sharp)
      {}
      else
      {
         char *id;
         if (complain)
         {
            err_head();
            fprintf(stderr, "expression syntax error -- number expected\n");
         }
         if (isbsymchar(c))
         {
            Push(c);
            id = read_ident();
         }
         else
         {
            id = 0;
         }
#ifdef DEBUG_EXPR
         if (debugging)
         {
            outputs("0(");
            outputc(c);
            outputs(":");
            outputs(id ? id : "(none)");
            outputs(")~");
         }
#endif
         if (id)
         {
            os_free(id);
         }
         return (newleaf(0));
      }
   }
}