Exemple #1
0
actuarial_table::actuarial_table(std::string const& filename, int table_number)
    :filename_       (filename)
    ,table_number_   (table_number)
    ,table_type_     (-1)
    ,min_age_        (-1)
    ,max_age_        (-1)
    ,select_period_  (-1)
    ,max_select_age_ (-1)
    ,table_offset_   (-1)
{
    if(table_number_ <= 0)
        {
        fatal_error()
            << "There is no table number "
            << table_number_
            << " in file '"
            << filename_
            << "'."
            << LMI_FLUSH
            ;
        }

    find_table();
    parse_table();
}
Exemple #2
0
static struct buffer parse_argument(struct buffer buff,
      struct argument *arg, const char **error)
{
   buff = chomp(buff);

   if (
         isalpha((int)buff.data[buff.offset])
         && !(
            peek(buff, "nil")
            || peek(buff, "true")
            || peek(buff, "false")
            || peek(buff, "b\"") || peek(buff, "b'") /* bin string prefix*/
            )
      )
   {
      arg->type = AT_FUNCTION;
      buff = parse_method_call(buff, &arg->a.invocation, error);
   }
   else if (peek(buff, "{"))
   {
      arg->type = AT_FUNCTION;
      buff = parse_table(buff, &arg->a.invocation, error);
   }
   else
   {
      arg->type = AT_VALUE;
      buff = parse_value(buff, &arg->a.value, error);
   }
   return buff;
}
Exemple #3
0
/* Create a task, set its name and run it. */
static int
run_task(struct lib_context *lc, struct raid_set *rs, char *table, int type, char *name)
{
	/*
	 * DM_UUID_LEN is defined in dm-ioctl.h as 129 characters;
	 * though not all 129 must be used (md uses just 16 from 
	 * a quick review of md.c. 
	 * We will be using: (len vol grp name)
	 */
	char uuid[DM_UUID_LEN];
	int ret;
	struct dm_task *dmt;

	_init_dm();
	ret = (dmt = dm_task_create(type)) && dm_task_set_name(dmt, name);
	if (ret && table)
		ret = parse_table(lc, dmt, table);

	if (ret) {
		if (DM_DEVICE_CREATE == type) {
			ret = dmraid_uuid(lc, rs, uuid, DM_UUID_LEN, name) &&
				dm_task_set_uuid(dmt, uuid) && dm_task_run(dmt);
		} else
			ret = dm_task_run(dmt);
	}

	_exit_dm(dmt);
	return ret;
}
int parse_request(client * c, cmd_table * table)
{
        unsigned char buffer[MAX_PACKET_SIZE] = {0};
        int           nb_read;
        int           ok;

        nb_read = packet_read(c->socket_tcp, buffer, MAX_PACKET_SIZE);
        if (nb_read <= 0)
        {
                trace(DBG_CONN, "Connection closed: read error.\n");
                return 0;
        }

        ok = parse_table(table, c, buffer);

        switch (ok)
        {
                case 3:  return 0;
                case 2:  break;
                case 1:  message_send(c->socket_tcp, PACKET_MSG_ACK, 1);   break;
                case 0:  message_send(c->socket_tcp, PACKET_MSG_NACK, 1);  break;
                case -1: message_send(c->socket_tcp, PACKET_MSG_ERROR, 1); break;
        }
        trace(DBG_RQST, "Request status: %d (read %d bytes).\n", ok, nb_read);

        return 1;
}
Exemple #5
0
parse_table parse_table::add_core(unsigned num, transition const * ts, expr const & a,
                                  unsigned priority, bool overload, buffer<action> & post_buffer) const {
    parse_table r(new cell(*m_ptr));
    if (num == 0) {
        list<action> postponed = to_list(post_buffer);
        if (!overload) {
            r.m_ptr->m_accept = to_list(accepting(priority, postponed, a));
        } else {
            auto new_accept   = filter(r.m_ptr->m_accept, [&](accepting const & p) {
                    return p.get_expr() != a || p.get_postponed() != postponed;
                });
            r.m_ptr->m_accept = insert(new_accept, priority, postponed, a);
        }
    } else {
        list<pair<action, parse_table>> const * it = r.m_ptr->m_children.find(ts->get_token());
        action const & ts_act = ts->get_action();
        action_kind k = ts_act.kind();
        if (k == action_kind::Exprs || k == action_kind::ScopedExpr)
            post_buffer.push_back(ts_act);
        list<pair<action, parse_table>> new_lst;
        if (it) {
            if (contains_equivalent_action(*it, ts_act)) {
                buffer<pair<action, parse_table>> tmp;
                to_buffer(*it, tmp);
                for (pair<action, parse_table> & p : tmp) {
                    if (p.first.is_equivalent(ts_act)) {
                        p.second = p.second.add_core(num-1, ts+1, a, priority, overload, post_buffer);
                        break;
                    }
                }
                new_lst = to_list(tmp);
            } else {
                // remove incompatible actions
                new_lst = filter(*it, [&](pair<action, parse_table> const & p) {
                        return p.first.is_compatible(ts_act);
                    });
                parse_table new_child = parse_table().add_core(num-1, ts+1, a, priority, overload, post_buffer);
                new_lst   = cons(mk_pair(ts_act, new_child), new_lst);
            }
        } else {
            parse_table new_child = parse_table().add_core(num-1, ts+1, a, priority, overload, post_buffer);
            new_lst   = to_list(mk_pair(ts_act, new_child));
        }
        r.m_ptr->m_children.insert(ts->get_token(), new_lst);
    }
    return r;
}
Exemple #6
0
/* parse_block • parsing of one block, returning next char to parse */
static void
parse_block(struct buf *ob, struct render *rndr, char *data, size_t size)
{
	size_t beg, end, i;
	char *txt_data;
	beg = 0;

	if (rndr->work.size > rndr->max_nesting)
		return;

	while (beg < size) {
		txt_data = data + beg;
		end = size - beg;

		if (data[beg] == '#')
			beg += parse_atxheader(ob, rndr, txt_data, end);

		else if (data[beg] == '<' && rndr->make.blockhtml &&
				(i = parse_htmlblock(ob, rndr, txt_data, end, 1)) != 0)
			beg += i;

		else if ((i = is_empty(txt_data, end)) != 0)
			beg += i;

		else if (is_hrule(txt_data, end)) {
			if (rndr->make.hrule)
				rndr->make.hrule(ob, rndr->make.opaque);

			while (beg < size && data[beg] != '\n')
				beg++;

			beg++;
		}

		else if ((rndr->ext_flags & MKDEXT_FENCED_CODE) != 0 &&
			(i = parse_fencedcode(ob, rndr, txt_data, end)) != 0)
			beg += i;

		else if ((rndr->ext_flags & MKDEXT_TABLES) != 0 &&
			(i = parse_table(ob, rndr, txt_data, end)) != 0)
			beg += i;

		else if (prefix_quote(txt_data, end))
			beg += parse_blockquote(ob, rndr, txt_data, end);

		else if (prefix_code(txt_data, end))
			beg += parse_blockcode(ob, rndr, txt_data, end);

		else if (prefix_uli(txt_data, end))
			beg += parse_list(ob, rndr, txt_data, end, 0);

		else if (prefix_oli(txt_data, end))
			beg += parse_list(ob, rndr, txt_data, end, MKD_LIST_ORDERED);

		else
			beg += parse_paragraph(ob, rndr, txt_data, end);
	}
}
Exemple #7
0
/* Handle a VTG (course over ground) message. */
static void handle_vtg(uint8_t *buf, uint8_t size){
	int32_t heading, speed;
	uint8_t ftable[15];
	if(9 != parse_table(buf, size, ftable, 15))goto error;
	if(*(buf + ftable[9]) != 'A')goto error;
	if(extract_decimal_precision(buf + ftable[1], 2, &heading))goto error;
	if(extract_decimal_precision(buf + ftable[7], 3, &speed))goto error;
	Data->gps_heading = heading;
	Data->gps_speed = speed;
	start_gps_valid_timer();
	return;
	
	error:
	/* Invalidate the gps track immediately, separately from the gps position,
	 * since the receiver can provide position information without giving a track. */
	Data->gps_track_valid = 0;
}
Exemple #8
0
void *libretrodb_query_compile(libretrodb_t *db,
      const char *query, size_t buff_len, const char **error)
{
   struct buffer buff;
   struct query *q = (struct query*)malloc(sizeof(struct query));

   if (!q)
      goto clean;

   memset(q, 0, sizeof(struct query));

   q->ref_count = 1;
   buff.data    = query;
   buff.len     = buff_len;
   buff.offset  = 0;
   *error       = NULL;

   buff = chomp(buff);

   if (peek(buff, "{"))
   {
      buff = parse_table(buff, &q->root, error);
      if (*error)
         goto clean;
   }
   else if (isalpha(buff.data[buff.offset]))
      buff = parse_method_call(buff, &q->root, error);

   buff = expect_eof(buff, error);
   if (*error)
      goto clean;

   if (!q->root.func)
   {
      raise_unexpected_eof(buff.offset, error);
      return NULL;
   }
   goto success;
clean:
   if (q)
      libretrodb_query_free(q);
success:
   return q;
}
Exemple #9
0
/*******************************************************************************
 * @fn     void process_packet( uint8_t* buffer, uint32_t size )
 * @brief  Process incoming serial packet
 * ****************************************************************************/
uint8_t process_packet( uint8_t* buffer, uint32_t size )
{
  uint8_t rssi_table[MAX_DEVICES+1][MAX_DEVICES+1];

  if( size < sizeof(rssi_table) )
  {
    printf( "Received packet smaller than RSSI table (%d)\r\n", size );
    return 0;
  }

  memcpy( rssi_table, buffer, sizeof(rssi_table) );

  parse_table( rssi_table );

  // Let the routing algorithm run
  pthread_mutex_unlock ( &mutex_route_start );

  return 1;
}
Exemple #10
0
static void
parse_group (xmlNodePtr node, InputPadGroup **pgroup)
{
    xmlNodePtr current;
    gboolean has_name = FALSE;
    gboolean has_table = FALSE;
    InputPadTable **ptable = &((*pgroup)->table);

    for (current = node; current; current = current->next) {
        if (current->type == XML_ELEMENT_NODE) {
            if (!g_strcmp0 ((char *) current->name, "name")) {
                if (current->children) {
                    get_content (current->children, &(*pgroup)->name, TRUE);
                    has_name = TRUE;
                } else {
                    g_error ("tag %s does not have child tags in the file %s",
                             (char *) current->name,
                             xml_file);
                }
            }
            if (!g_strcmp0 ((char *) current->name, "table")) {
                if (current->children) {
                    *ptable = g_new0 (InputPadTable, 1);
                    (*ptable)->priv = g_new0 (InputPadTablePrivate, 1);
                    (*ptable)->column = 15;
                    parse_table (current->children, ptable);
                    ptable = &((*ptable)->next);
                    has_table = TRUE;
                } else {
                    g_error ("tag %s does not have child tags in the file %s",
                             (char *) current->name,
                             xml_file);
                }
            }
        }
    }
    if (!has_name || !has_table ) {
        g_error ("tag %s does not find \"name\" or \"table\" tag in file %s",
                 node->parent ? node->parent->name ? (char *) node->parent->name : "(null)" : "(null)",
                 xml_file);
    }
}
Exemple #11
0
/* parse_block • parsing of one block, returning next char to parse */
static void
parse_block(struct buf *ob, struct render *rndr,
			char *data, size_t size) {
	size_t beg, end, i;
	char *txt_data;
	int has_table = (rndr->make.table && rndr->make.table_row
	    && rndr->make.table_cell);

	if (rndr->work.size > rndr->make.max_work_stack) {
		if (size) bufput(ob, data, size);
		return; }

	beg = 0;
	while (beg < size) {
		txt_data = data + beg;
		end = size - beg;
		if (data[beg] == '#')
			beg += parse_atxheader(ob, rndr, txt_data, end);
		else if (data[beg] == '<' && rndr->make.blockhtml
			&& (i = parse_htmlblock(ob, rndr, txt_data, end)) != 0)
			beg += i;
		else if ((i = is_empty(txt_data, end)) != 0)
			beg += i;
		else if (is_hrule(txt_data, end)) {
			if (rndr->make.hrule)
				rndr->make.hrule(ob, rndr->make.opaque);
			while (beg < size && data[beg] != '\n') beg += 1;
			beg += 1; }
		else if (prefix_quote(txt_data, end))
			beg += parse_blockquote(ob, rndr, txt_data, end);
		else if (prefix_code(txt_data, end))
			beg += parse_blockcode(ob, rndr, txt_data, end);
		else if (prefix_uli(txt_data, end))
			beg += parse_list(ob, rndr, txt_data, end, 0);
		else if (prefix_oli(txt_data, end))
			beg += parse_list(ob, rndr, txt_data, end,
						MKD_LIST_ORDERED);
		else if (has_table && is_tableline(txt_data, end))
			beg += parse_table(ob, rndr, txt_data, end);
		else
			beg += parse_paragraph(ob, rndr, txt_data, end); } }
Exemple #12
0
void MetaDataConfig::parse(Schema &reg)
{
    if (node_->name_.compare(_T("schema")))
        throw ParseError(String(_T("Unknown element '")) + node_->name_ + 
                _T("' found during parse of root element, 'schema' expected"));

    ElementTree::Elements::const_iterator child = node_->children_.begin(),
        cend = node_->children_.end();
    for (; child != cend; ++child) {
        if (!(*child)->name_.compare(_T("table"))) {
            Table::Ptr t = parse_table(*child);
            reg.add_table(t);
        } else if (!(*child)->name_.compare(_T("relation"))) {
            Relation::Ptr r = parse_relation(*child);
            if (shptr_get(r))
                reg.add_relation(r);
        } else
            throw ParseError(String(_T("Unknown element '")) + (*child)->name_ +
                    _T("' found during parse of element 'schema'"));
    }
}
Exemple #13
0
HTable table_read(const char *filename)
{
    long int len, pos;
    char *buf;
    HTable table;
    int res;

    buf = read_file(filename, &len);
    if (! buf) return NULL;

    pos = 0;
    table = table_create();
    res = parse_table(table, buf, &pos, 1);
    if (res)
    {
        table_free(table);
        table = NULL;
    }

    free(buf);
    return table;
}
Exemple #14
0
std::unique_ptr<rule_box> parser::parse_rule(const std::shared_ptr<const global_table_set>& gts, group_mem_protocol gmp)
{
    HC_LOG_TRACE("");
    std::string if_name;
    if (m_current_token.get_type() == TT_STRING || m_current_token.get_type() == TT_LEFT_BRACKET) {
        if (m_current_token.get_type() == TT_STRING) {
            if_name = m_current_token.get_string();
            get_next_token();
        }

        if (m_current_token.get_type() == TT_LEFT_BRACKET) {
            get_next_token();
            if (m_current_token.get_type() == TT_TABLE) {
                std::unique_ptr<rule_box> result(new rule_table(parse_table(gts, gmp, true)));
                return result;
            } else {
                std::unique_ptr<addr_match> group;
                std::unique_ptr<addr_match> source;
                group =  parse_rule_part(gmp);

                if (m_current_token.get_type() == TT_PIPE) {
                    get_next_token();
                    source = parse_rule_part(gmp);

                    if (m_current_token.get_type() == TT_RIGHT_BRACKET) {
                        std::unique_ptr<rule_box> result(new rule_addr(if_name, std::move(group), std::move(source)));
                        return result;
                    }
                }
            }
        }
    } else {
        return nullptr;
    }

    HC_LOG_ERROR("failed to parse line " << m_current_line << " unknown token " << get_token_type_name(m_current_token.get_type()) << " with value " << m_current_token.get_string() << " in this context");
    throw "failed to parse config file";
}
Exemple #15
0
/* Handle a GGA (GPS data) message. */
static void handle_gga(uint8_t *buf, uint8_t size){
	int64_t latitude, longitude;
	int32_t altitude;
	uint8_t ftable[15];
	if(14 != parse_table(buf, size, ftable, 15))return;
	
 	if(extract_lat(buf + ftable[2], &latitude))return;
	if(*(buf + ftable[3]) != 'N' && *(buf + ftable[3]) != 'S')return;
	if(*(buf + ftable[3]) == 'S')latitude = -latitude;
	
	if(extract_long(buf + ftable[4], &longitude))return;
	if(*(buf + ftable[5]) != 'W' && *(buf + ftable[5]) != 'E')return;
	if(*(buf + ftable[5]) == 'W')longitude = -longitude;
	
	if(*(buf + ftable[6]) == '0')return; /* No fix. */
	
	if(extract_decimal_precision(buf + ftable[9], 1, &altitude))return;
 	Data->latitude = latitude;
	Data->longitude = longitude;
	Data->altitude = altitude;
	Data->gps_pos_valid = 1;
	start_gps_valid_timer();
}
Exemple #16
0
static int add_field(HTable table, char *name, char *value, char *buf, long int *pos)
{
    int value_type;
    char *s;
    HTable tbl;

    value_type = get_value_type(value);
    switch (value_type)
    {
        case TYPE_INT:
            table_set_int(table, name, atoi(value));
            break;
        case TYPE_STRING:
            s = unescape_string(value);
            if (! s)
                return -1;
            table_set_str(table, name, s);
            free(s);
            break;
        case TYPE_FLOAT:
            table_set_double(table, name, atof(value));
            break;
        case TYPE_TABLE:
            tbl = table_create();
            if (table_set_table(table, name, tbl))
            {
                table_free(tbl);
                return -1;
            }
            if (parse_table(tbl, buf, pos, 0))
                return -1;
            break;
        default:
            return -1;
    }
    return 0;
}
Exemple #17
0
void parser::parse_interface_table_binding(
    std::string && instance_name
    , rb_interface_type interface_type
    , std::string && if_name
    , rb_interface_direction filter_direction
    , const std::shared_ptr<const global_table_set>& gts
    , group_mem_protocol gmp
    , const inst_def_set& ids)
{
    HC_LOG_TRACE("");
    auto error_notification = [&]() {
        HC_LOG_ERROR("failed to parse line " << m_current_line << " unknown token " << get_token_type_name(m_current_token.get_type()) << " with value " << m_current_token.get_string() << " in this context");
        throw "failed to parse config file";
    };

    rb_filter_type filter_type = FT_UNDEFINED;
    std::unique_ptr<table> filter_table;

    //pinstance split downstream tunD1 out whitelist table {tunU1(* | *)};
    if (m_current_token.get_type() == TT_WHITELIST) {
        filter_type = FT_WHITELIST;
    } else if (m_current_token.get_type() == TT_BLACKLIST) {
        filter_type = FT_BLACKLIST;
    } else {
        error_notification();
    }

    get_next_token();
    filter_table = parse_table(gts, gmp);

    if (m_current_token.get_type() != TT_NIL) {
        error_notification();
    }

    auto instance_it = ids.find(instance_name);
    if (instance_it != ids.end()) {
        std::unique_ptr<rule_binding> rb(new rule_binding(instance_name, interface_type, if_name, filter_direction, filter_type, std::move(filter_table)));

        std::shared_ptr<interface> interf = nullptr;

        if (interface_type == IT_UPSTREAM) {
            auto interface_it = std::find((*instance_it)->m_upstreams.begin(), (*instance_it)->m_upstreams.end(), std::make_shared<interface>(if_name));
            if (interface_it != (*instance_it)->m_upstreams.end()) {
                interf = *interface_it;
            } else {
                HC_LOG_ERROR("failed to parse line " << m_current_line << " upstream interface " << if_name << " not defined");
                throw "failed to parse config file";
            }
        } else if (interface_type == IT_DOWNSTREAM) {
            auto interface_it = std::find((*instance_it)->m_downstreams.begin(), (*instance_it)->m_downstreams.end(), std::make_shared<interface>(if_name));
            if (interface_it != (*instance_it)->m_downstreams.end()) {
                interf = *interface_it;
            } else {
                HC_LOG_ERROR("failed to parse line " << m_current_line << " downstream interface " << if_name << " not not defined");
                throw "failed to parse config file";
            }
        } else {
            HC_LOG_ERROR("failed to parse line " << m_current_line << " interface tpye not defined");
            throw "failed to parse config file";
        }

        if (filter_direction == ID_IN) {
            if (interf->m_input_filter == nullptr) {
                interf->m_input_filter = std::move(rb);
                return;
            } else {
                HC_LOG_ERROR("failed to parse line " << m_current_line << " input filter for interface " << if_name << " already defined");
                throw "failed to parse config file";
            }
        } else if (filter_direction == ID_OUT) {
            if (interf->m_output_filter == nullptr) {
                interf->m_output_filter = std::move(rb);
                return;
            } else {
                HC_LOG_ERROR("failed to parse line " << m_current_line << " output filter for interface " << if_name << " already defined");
                throw "failed to parse config file";
            }
        } else {
            HC_LOG_ERROR("failed to parse line " << m_current_line << " rule direction not defined");
            throw "failed to parse config file";
        }
    } else {
        HC_LOG_ERROR("failed to parse line " << m_current_line << " proxy instance " << m_current_token.get_string() << " not defined");
        throw "failed to parse config file";
    }
}
Exemple #18
0
/* attempts to read verity metadata from `f->fd' position `offset'; if in r/w
   mode, rewrites the metadata if it had errors */
int verity_parse_header(fec_handle *f, uint64_t offset)
{
    check(f);
    check(f->data_size > VERITY_METADATA_SIZE);

    if (offset > f->data_size - VERITY_METADATA_SIZE) {
        debug("failed to read verity header: offset %" PRIu64 " is too far",
            offset);
        return -1;
    }

    verity_info *v = &f->verity;
    uint64_t errors = f->errors;

    if (!raw_pread(f, &v->header, sizeof(v->header), offset)) {
        error("failed to read verity header: %s", strerror(errno));
        return -1;
    }

    /* use raw data to check for the alternative magic, because it will
       be error corrected to VERITY_MAGIC otherwise */
    if (v->header.magic == VERITY_MAGIC_DISABLE) {
        /* this value is not used by us, but can be used by a caller to
           decide whether dm-verity should be enabled */
        v->disabled = true;
    }

    if (fec_pread(f, &v->ecc_header, sizeof(v->ecc_header), offset) !=
            sizeof(v->ecc_header)) {
        warn("failed to read verity header: %s", strerror(errno));
        return -1;
    }

    if (validate_header(f, &v->header, offset)) {
        /* raw verity header is invalid; this could be due to corruption, or
           due to missing verity metadata */

        if (validate_header(f, &v->ecc_header, offset)) {
            return -1; /* either way, we cannot recover */
        }

        /* report mismatching fields */
        if (!v->disabled && v->header.magic != v->ecc_header.magic) {
            warn("corrected verity header magic");
            v->header.magic = v->ecc_header.magic;
        }

        if (v->header.version != v->ecc_header.version) {
            warn("corrected verity header version");
            v->header.version = v->ecc_header.version;
        }

        if (v->header.length != v->ecc_header.length) {
            warn("corrected verity header length");
            v->header.length = v->ecc_header.length;
        }

        if (memcmp(v->header.signature, v->ecc_header.signature,
                sizeof(v->header.signature))) {
            warn("corrected verity header signature");
            /* we have no way of knowing which signature is correct, if either
               of them is */
        }
    }

    v->metadata_start = offset;

    if (parse_table(f, offset + sizeof(v->header), v->header.length,
            false) == -1 &&
        parse_table(f, offset + sizeof(v->header), v->header.length,
            true)  == -1) {
        return -1;
    }

    /* if we corrected something while parsing metadata and we are in r/w
       mode, rewrite the corrected metadata */
    if (f->mode & O_RDWR && f->errors > errors &&
            rewrite_metadata(f, offset) < 0) {
        warn("failed to rewrite verity metadata: %s", strerror(errno));
    }

    if (v->metadata_start < v->hash_start) {
        f->data_size = v->metadata_start;
    } else {
        f->data_size = v->hash_start;
    }

    return 0;
}
Exemple #19
0
static int
parse_item(lua_State* L, const char** p_format, va_list* p_va,
           int value_index, BOOL in_tablep, BOOL* p_optionalp)
{
	const char* format = *p_format;

L_RETRY:
	format = STRSKIP(format, WHITESPACES);
	switch (*format) {
	default:
		lua_pushfstring(L, "format item `%c(%d)' is not valid",
		                SANITIZE_CHAR(*format), *format);
		return FAILURE;
	case 'n': CONVERT_NUMBER(L, *p_va, value_index, lua_Number); break;
	case 'b': CONVERT_NUMBER(L, *p_va, value_index, char); break;
	case 'h': CONVERT_NUMBER(L, *p_va, value_index, short); break;
	case 'i': CONVERT_NUMBER(L, *p_va, value_index, int); break;
	case 'l': CONVERT_NUMBER(L, *p_va, value_index, long); break;
	case 'B': CONVERT_NUMBER(L, *p_va, value_index, unsigned char); break;
	case 'H': CONVERT_NUMBER(L, *p_va, value_index, unsigned short); break;
	case 'I': CONVERT_NUMBER(L, *p_va, value_index, unsigned int); break;
	case 'L': CONVERT_NUMBER(L, *p_va, value_index, unsigned long); break;
	case 's':
		CHECK_TYPE(L, value_index, LUA_TSTRING);
		/* FALLTHRU */
	case 'z': {
		const char** string;
		size_t* length = NULL;

		string = va_arg(*p_va, const char**);
		if (*(format+1) == '#') {
			length = va_arg(*p_va, size_t*);
			format++;
		}

		if (lua_isstring(L, value_index)) {
			*string = lua_tolstring(L, value_index, length);
		} else if (!lua_toboolean(L, value_index)) {  /*nil-or-false?*/
			*string = NULL;
			if (length != NULL)
				*length = 0;
		} else {
			lua_pushfstring(L,
			  "type mismatch (expected %s/nil/false, but got %s)",
			  lua_typename(L, LUA_TSTRING),
			  luaL_typename(L, value_index));
			return FAILURE;
		}
		} break;
	case 'Q': {
		BOOL* p_boolean;

		p_boolean = va_arg(*p_va, BOOL*);
		*p_boolean = lua_toboolean(L, value_index);
		} break;
	case 'u': /* FALLTHRU */
	case 'U': {
		void** userdata;

		CHECK_TYPE(L, value_index,
		           ((*format == 'U') ? LUA_TUSERDATA
		                             : LUA_TLIGHTUSERDATA));
		userdata = va_arg(*p_va, void**);
		*userdata = lua_touserdata(L, value_index);
		} break;
	case 'O': {
		int* index;

		if (in_tablep) {
			lua_pushstring(L,
			  "format item `O' is not available in `{...}");
			return FAILURE;
		}

		if (*(format+1) == '/') {
			int type;

			switch (*(format+2)) {
			default:
				lua_pushfstring(L,
				  "type `%c(%d)' for `O/<type>' is not valid",
				  SANITIZE_CHAR(*(format+2)), *(format+2));
				return FAILURE;
			case 'N': type = LUA_TNIL; break;
			case 'n': type = LUA_TNUMBER; break;
			case 's': type = LUA_TSTRING; break;
			case 'f': type = LUA_TFUNCTION; break;
			case 'Q': type = LUA_TBOOLEAN; break;
			case 'u': type = LUA_TLIGHTUSERDATA; break;
			case 'U': type = LUA_TUSERDATA; break;
			case 't': type = LUA_TTABLE; break;
			case 'T': type = LUA_TTHREAD; break;
			}
			CHECK_TYPE(L, value_index, type);
			format += 2;
		}

		index = va_arg(*p_va, int*);
		*index = value_index;
		} break;
	case '{':
		CHECK_TYPE(L, value_index, LUA_TTABLE);
		format++;
		if (parse_table(L, &format, p_va, value_index) != SUCCESS)
			return FAILURE;
		break;
	case '|':
		if (in_tablep) {
			lua_pushstring(L,
			  "optional argument `|' is not available in `{...}");
			return FAILURE;
		}
		*p_optionalp = TRUE;
		format++;
		goto L_RETRY;
	}
Exemple #20
0
static int mk_parse_table(lua_State * L) {
    int nargs = lua_gettop(L);
    bool nud  = nargs == 0 || lua_toboolean(L, 1);
    return push_parse_table(L, parse_table(nud));
}
int main(int argc, char *argv[])
{
   char *pname;
   char *file = NULL;
   char *maxidstr = NULL;
   int ignore_errors = FALSE;
   Acr_byte_order byte_order = ACR_UNKNOWN_ENDIAN;
   Acr_VR_encoding_type vr_encoding = UNKNOWN_VR_ENCODING;
   FILE *fp;
   Acr_File *afp;
   Acr_Group group_list;
   Acr_Status status;
   char *status_string;
   int maxid;
   char *ptr;
   int iarg, argcounter;
   char *arg;
   char *usage = "Usage: %s [-h] [-i] [-b] [-l] [-e] [-t <table>] [<file> [<max group>]]\n";

   /* Check arguments */
   pname = argv[0];
   argcounter = 0;
   for (iarg=1; iarg < argc; iarg++) {
      arg = argv[iarg];
      if ((arg[0] == '-') && (arg[1] != '\0')) {
         if (arg[2] != '\0') {
            (void) fprintf(stderr, "Unrecognized option %s\n", arg);
            exit(EXIT_FAILURE);
         }
         switch (arg[1]) {
         case 't':
             if (iarg < argc - 1) {
                 parse_table(argv[++iarg]);
                 _acr_name_proc = get_name;
                 break;
             }
             /* Fall through */
         case 'h':
            (void) fprintf(stderr, "Options:\n");
            (void) fprintf(stderr, "   -h:\tPrint this message\n");
            (void) fprintf(stderr, "   -t <table>:\tUse table to decode element names\n");
            (void) fprintf(stderr, "   -i:\tIgnore protocol errors\n");
            (void) fprintf(stderr, "   -b:\tAssume big-endian data\n");
            (void) fprintf(stderr, "   -l:\tAssume little-endian data\n");
            (void) fprintf(stderr, "   -e:\tAssume explicit VR encoding\n\n");
            (void) fprintf(stderr, usage, pname);
            exit(EXIT_FAILURE);
            break;
         case 'i':
            ignore_errors = TRUE;
            break;
         case 'l':
            byte_order = ACR_LITTLE_ENDIAN;
            break;
         case 'b':
            byte_order = ACR_BIG_ENDIAN;
            break;
         case 'e':
            vr_encoding = ACR_EXPLICIT_VR;
            break;
         default:
            (void) fprintf(stderr, "Unrecognized option %s\n", arg);
            exit(EXIT_FAILURE);
         }
      }
      else {
         switch (argcounter) {
         case 0:
            file = arg; break;
         case 1:
            maxidstr = arg; break;
         default:
            (void) fprintf(stderr, usage, pname);
            exit(EXIT_FAILURE);
         }
         argcounter++;
      }
   }

   /* Open input file */
   if ((file != NULL) && (strcmp(file, "-") != 0)) {
      fp = fopen(file, "r");
      if (fp == NULL) {
         (void) fprintf(stderr, "%s: Error opening file %s\n",
                        pname, file);
         exit(EXIT_FAILURE);
      }
   }
   else {
      fp = stdin;
   }

   /* Look for max group id */
   if (maxidstr != NULL) {
      maxid = strtol(maxidstr, &ptr, 0);
      if (ptr == maxidstr) {
         (void) fprintf(stderr, "%s: Error in max group id (%s)\n", 
                        pname, maxidstr);
         exit(EXIT_FAILURE);
      }
   }
   else {
      maxid = 0;
   }

   /* Connect to input stream */
   afp=acr_file_initialize(fp, 0, acr_stdio_read);
   acr_set_ignore_errors(afp, ignore_errors);
   (void) acr_test_dicom_file(afp);
   if (byte_order != ACR_UNKNOWN_ENDIAN) {
      acr_set_byte_order(afp, byte_order);
   }
   if (vr_encoding != UNKNOWN_VR_ENCODING) {
      acr_set_vr_encoding(afp, vr_encoding);
   }

   /* Read in group list */
   status = acr_input_group_list(afp, &group_list, maxid);

   /* Free the afp */
   acr_file_free(afp);

   /* Dump the values */
   acr_dump_group_list(stdout, group_list);

   /* Print status information */
   if ((status != ACR_END_OF_INPUT) && (status != ACR_OK)) {
      status_string = acr_status_string(status);
      (void) fprintf(stderr, "Finished with status '%s'\n", status_string);
   }

   exit(EXIT_SUCCESS);
}
Exemple #22
0
void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, void *f)
{
	struct part *p = f;
	int border, cellsp, vcellpd, cellpd, align;
	int frame, rules, width, wf;
	struct rgb bgcolor;
	struct table *t;
	char *al;
	int cye;
	int x;
	int i;
	/*int llm = last_link_to_move;*/
	struct s_e *bad_html;
	int bad_html_n;
	struct node *n, *nn;
	int cpd_pass, cpd_width, cpd_last;
	/*if (!p->data) {
		debug("nested tables not supported");
		return;
	}*/
	table_level++;
	memcpy(&bgcolor, &par_format.bgcolor, sizeof(struct rgb));
	get_bgcolor(attr, &bgcolor);
	if ((border = get_num(attr, "border")) == -1) border = has_attr(attr, "border") || has_attr(attr, "rules") || has_attr(attr, "frame");
	/*if (!border) border = 1;*/

	if ((cellsp = get_num(attr, "cellspacing")) == -1) cellsp = 1;
	if ((cellpd = get_num(attr, "cellpadding")) == -1) {
		vcellpd = 0;
		cellpd = !!border;
	} else {
		vcellpd = cellpd >= HTML_CHAR_HEIGHT / 2 + 1;
		cellpd = cellpd >= HTML_CHAR_WIDTH / 2 + 1;
	}
	if (!border) cellsp = 0;
	else if (!cellsp) cellsp = 1;
	if (border > 2) border = 2;
	if (cellsp > 2) cellsp = 2;
	align = par_format.align;
	if (align == AL_NO || align == AL_BLOCK) align = AL_LEFT;
	if ((al = get_attr_val(attr, "align"))) {
		if (!strcasecmp(al, "left")) align = AL_LEFT;
		if (!strcasecmp(al, "center")) align = AL_CENTER;
		if (!strcasecmp(al, "right")) align = AL_RIGHT;
		mem_free(al);
	}
	frame = F_BOX;
	if ((al = get_attr_val(attr, "frame"))) {
		if (!strcasecmp(al, "void")) frame = F_VOID;
		if (!strcasecmp(al, "above")) frame = F_ABOVE;
		if (!strcasecmp(al, "below")) frame = F_BELOW;
		if (!strcasecmp(al, "hsides")) frame = F_HSIDES;
		if (!strcasecmp(al, "vsides")) frame = F_VSIDES;
		if (!strcasecmp(al, "lhs")) frame = F_LHS;
		if (!strcasecmp(al, "rhs")) frame = F_RHS;
		if (!strcasecmp(al, "box")) frame = F_BOX;
		if (!strcasecmp(al, "border")) frame = F_BOX;
		mem_free(al);
	}
	rules = border ? R_ALL : R_NONE;
	if ((al = get_attr_val(attr, "rules"))) {
		if (!strcasecmp(al, "none")) rules = R_NONE;
		if (!strcasecmp(al, "groups")) rules = R_GROUPS;
		if (!strcasecmp(al, "rows")) rules = R_ROWS;
		if (!strcasecmp(al, "cols")) rules = R_COLS;
		if (!strcasecmp(al, "all")) rules = R_ALL;
		mem_free(al);
	}
	if (!border) frame = F_VOID;
	wf = 0;
	if ((width = get_width(attr, "width", p->data || p->xp)) == -1) {
		width = par_format.width - par_format.leftmargin - par_format.rightmargin;
		if (width < 0) width = 0;
		wf = 1;
	}
	if (!(t = parse_table(html, eof, end, &bgcolor, p->data || p->xp, &bad_html, &bad_html_n))) {
		mem_free(bad_html);
		goto ret0;
	}
	for (i = 0; i < bad_html_n; i++) {
		while (bad_html[i].s < bad_html[i].e && WHITECHAR(*bad_html[i].s)) bad_html[i].s++;
		while (bad_html[i].s < bad_html[i].e && WHITECHAR(bad_html[i].e[-1])) bad_html[i].e--;
		if (bad_html[i].s < bad_html[i].e) parse_html(bad_html[i].s, bad_html[i].e, put_chars_f, line_break_f, special_f, p, NULL);
	}
	mem_free(bad_html);
	html_stack_dup();
	html_top.dontkill = 1;
	par_format.align = AL_LEFT;
	t->p = p;
	t->border = border;
	t->cellpd = cellpd;
	t->vcellpd = vcellpd;
	t->cellsp = cellsp;
	t->frame = frame;
	t->rules = rules;
	t->width = width;
	t->wf = wf;
	cpd_pass = 0;
	cpd_last = t->cellpd;
	cpd_width = 0;	/* not needed, but let the warning go away */
	again:
	get_cell_widths(t);
	if (get_column_widths(t)) goto ret2;
	get_table_width(t);
	if (!p->data && !p->xp) {
		if (!wf && t->max_t > width) t->max_t = width;
		if (t->max_t < t->min_t) t->max_t = t->min_t;
		if (t->max_t + par_format.leftmargin + par_format.rightmargin > p->xmax) p->xmax = t->max_t + par_format.leftmargin + par_format.rightmargin;
		if (t->min_t + par_format.leftmargin + par_format.rightmargin > p->x) p->x = t->min_t + par_format.leftmargin + par_format.rightmargin;
		goto ret2;
	}
	if (!cpd_pass && t->min_t > width && t->cellpd) {
		t->cellpd = 0;
		cpd_pass = 1;
		cpd_width = t->min_t;
		goto again;
	}
	if (cpd_pass == 1 && t->min_t > cpd_width) {
		t->cellpd = cpd_last;
		cpd_pass = 2;
		goto again;
	}
	/*debug("%d %d %d", t->min_t, t->max_t, width);*/
	if (t->min_t >= width) distribute_widths(t, t->min_t);
	else if (t->max_t < width && wf) distribute_widths(t, t->max_t);
	else distribute_widths(t, width);
	if (!p->data && p->xp == 1) {
		int ww = t->rw + par_format.leftmargin + par_format.rightmargin;
		if (ww > par_format.width) ww = par_format.width;
		if (ww < t->rw) ww = t->rw;
		if (ww > p->x) p->x = ww;
		p->cy += t->rh;
		goto ret2;
	}
#ifdef HTML_TABLE_2ND_PASS
	check_table_widths(t);
#endif
	x = par_format.leftmargin;
	if (align == AL_CENTER) x = (par_format.width + par_format.leftmargin - par_format.rightmargin - t->rw) / 2;
	if (align == AL_RIGHT) x = par_format.width - par_format.rightmargin - t->rw;
	if (x + t->rw > par_format.width) x = par_format.width - t->rw;
	if (x < 0) x = 0;
	/*display_table(t, x, p->cy, &cye);*/
	get_table_heights(t);
	if (!p->data) {
		if (t->rw + par_format.leftmargin + par_format.rightmargin > p->x) p->x = t->rw + par_format.leftmargin + par_format.rightmargin;
		p->cy += t->rh;
		goto ret2;
	}
	n = p->data->nodes.next;
	n->yw = p->yp - n->y + p->cy;
	display_complicated_table(t, x, p->cy, &cye);
	display_table_frames(t, x, p->cy);
	nn = mem_alloc(sizeof(struct node));
	nn->x = n->x;
	nn->y = p->yp + cye;
	nn->xw = n->xw;
	add_to_list(p->data->nodes, nn);
	/*sdbg(p->data);*/
	/*for (y = p->cy; y < cye; y++) {
		last_link_to_move = llm;
		align_line(p, y);
	}*/
	/*if (p->cy + t->rh != cye) internal("size does not match; 1:%d, 2:%d", p->cy + t->rh, cye);*/
	p->cy = cye;
	p->cx = -1;

	ret2:
	p->link_num = t->link_num;
	if (p->cy > p->y) p->y = p->cy;
	/*ret1:*/
	free_table(t);
	kill_html_stack_item(&html_top);
	ret0:
	/*ret:*/
	table_level--;
	if (!table_level) free_table_cache();
}
Exemple #23
0
std::unique_ptr<table> parser::parse_table(const std::shared_ptr<const global_table_set>& gts, group_mem_protocol gmp)
{
    return parse_table(gts, gmp, false);
}