Ejemplo n.º 1
0
const string_ref *
hstcpcli::get_next_row()
{
  if (num_flds == 0) {
    DBG(fprintf(stderr, "GNR NF 0\n"));
    return 0;
  }
  if (flds.size() < num_flds) {
    flds.resize(num_flds);
  }
  char *start = readbuf.begin() + cur_row_offset;
  char *const finish = readbuf.begin() + response_end_offset - 1;
  if (start >= finish) { /* start[0] == nl */
    DBG(fprintf(stderr, "GNR FIN 0 %p %p\n", start, finish));
    return 0;
  }
  for (size_t i = 0; i < num_flds; ++i) {
    skip_one(start, finish);
    char *const fld_begin = start;
    read_token(start, finish);
    char *const fld_end = start;
    char *wp = fld_begin;
    if (is_null_expression(fld_begin, fld_end)) {
      /* null */
      flds[i] = string_ref();
    } else {
      unescape_string(wp, fld_begin, fld_end); /* in-place */
      flds[i] = string_ref(fld_begin, wp);
    }
  }
  cur_row_offset = start - readbuf.begin();
  return &flds[0];
}
Ejemplo n.º 2
0
const string_ref *
hstcpcli::get_next_row_from_result(hstresult& result)
{
  if (result.num_flds == 0 || result.flds.elements < result.num_flds) {
    DBG(fprintf(stderr, "GNR NF 0\n"));
    return 0;
  }
  char *start = result.readbuf.begin() + result.cur_row_offset;
  char *const finish = result.readbuf.begin() + result.response_end_offset - 1;
  if (start >= finish) { /* start[0] == nl */
    DBG(fprintf(stderr, "GNR FIN 0 %p %p\n", start, finish));
    return 0;
  }
  for (size_t i = 0; i < result.num_flds; ++i) {
    skip_one(start, finish);
    char *const fld_begin = start;
    read_token(start, finish);
    char *const fld_end = start;
    char *wp = fld_begin;
    if (is_null_expression(fld_begin, fld_end)) {
      /* null */
      ((string_ref *) result.flds.buffer)[i] = string_ref();
    } else {
      unescape_string(wp, fld_begin, fld_end); /* in-place */
      ((string_ref *) result.flds.buffer)[i] = string_ref(fld_begin, wp);
    }
  }
  result.cur_row_offset = start - result.readbuf.begin();
  return (string_ref *) result.flds.buffer;
}
Ejemplo n.º 3
0
string_ref SrcFile::get_line (int id) {
  id--;
  if (id < 0 || id >= (int)lines.size()) {
    return string_ref();
  }
  return lines[id];
}
Ejemplo n.º 4
0
int
smtp_client::body(const string_ref& bdy, posix_error_callback& ec)
{
  impl_type& ir = *impl;
  string_buffer& work = ir.work;
  smtp_escape_body(work, bdy);
  string_ref req = string_ref(work.begin(), work.end());
  int r = smtp_command_1(ir.conn, req, ir.response, ec);
  work.reset(4000);
  return r;
}
Ejemplo n.º 5
0
/*-
 *-----------------------------------------------------------------------
 * Targ_NewGN  --
 *	Create and initialize a new graph node
 *
 * Results:
 *	An initialized graph node with the name field filled with a copy
 *	of the passed name
 *
 * Side Effects:
 *	None.
 *-----------------------------------------------------------------------
 */
GNode *
Targ_NewGN (string_t name)	/* the name to stick in the new node */
{
    register GNode *gn;
    extern string_t fname;	/* from parse.c */

    gn = (GNode *) emalloc (sizeof (GNode));
    gn->name = string_ref(name);
    gn->path = (string_t) 0;
    if (fname != NULL)
	gn->makefilename = string_ref(fname);
    else
	gn->makefilename = NULL;
    if (name->data[0] == '-' && name->data[1] == 'l') {
	gn->type = OP_LIB;
    } else {
	gn->type = 0;
    }
    gn->unmade =    	0;
    gn->make = 	    	FALSE;
    gn->made = 	    	UNMADE;
    gn->childMade = 	FALSE;
    gn->mtime = gn->cmtime = 0;
    gn->iParents =  	Lst_Init();
    gn->cohorts =   	Lst_Init();
    gn->parents =   	Lst_Init();
    gn->children =  	Lst_Init();
    Hash_InitTable(&gn->childHT, 0);
    gn->successors = 	Lst_Init();
    gn->preds =     	Lst_Init();
    gn->context =   	Lst_Init();
    gn->contextExtras = 0;
    gn->commands =  	Lst_Init();

    return (gn);
}
Ejemplo n.º 6
0
bool SrcFile::load(void) {
  if (loaded) {
    return true;
  }
  int err;

  int fid = open (file_name.c_str(), O_RDONLY);
  dl_passert (fid >= 0, dl_pstr ("failed to open file [%s]", file_name.c_str()));

  struct stat buf;
  err = fstat (fid, &buf);
  dl_passert (err >= 0, "fstat failed");

  dl_assert (buf.st_size < 100000000, dl_pstr ("file [%s] is too big [%lu]\n", file_name.c_str(), buf.st_size));
  int file_size = (int)buf.st_size;
  int prefix_size = (int)prefix.size();
  int text_size = file_size + prefix_size;
  text = string (text_size, ' ');
  std::copy (prefix.begin(), prefix.end(), text.begin());
  err = (int)read (fid, &text[0] + prefix_size, file_size);
  dl_assert (err >= 0, "read failed");

  for (int i = 0; i < text_size; i++) {
    if (likely (text[i] == 0)) {
      kphp_warning (dl_pstr ("symbol with code zero was replaced by space in file [%s] at [%d]", file_name.c_str(), i - prefix_size));
      text[i] = ' ';
    }
  }

  for (int i = prefix_size, prev_i = prefix_size; i <= text_size; i++) {
    if (text[i] == '\n') {
      lines.push_back (string_ref (&text[prev_i], &text[i]));
      prev_i = i + 1;
    }
  }

  loaded = true;
  close (fid);

  return true;
}
Ejemplo n.º 7
0
void syntax_highlight_actions::mark_text(parse_iterator first,
        parse_iterator last)
{
    marked_text = string_ref(first.base(), last.base());
}
Ejemplo n.º 8
0
 inline bool operator>(string_ref const& x, std::string const& y)
 {
     return x > string_ref(y);
 }
Ejemplo n.º 9
0
string_ref
smtp_client::get_buffer() const
{
  const string_buffer& bufref = impl->conn.get_buffer();
  return string_ref(bufref.begin(), bufref.end());
}
Ejemplo n.º 10
0
 string_ref encoded_qbk_value_impl::get_quickbook() const
     { return string_ref(begin_, end_); }
Ejemplo n.º 11
0
 void operator()(T* v, typename boost::enable_if< boost::is_arithmetic<T> >::type* = 0)
 {
     parse_number(string_ref(PQgetvalue(res_, current_, fetch_col_), PQgetlength(res_, current_, fetch_col_)), *v);
 }
Ejemplo n.º 12
0
void
basic_url_base::parse_impl (string_ref s, boost::system::error_code& ec)
{
    joyent::http_parser_url p;

    value_type const* const data (s.data());
    
    int const error (joyent::http_parser_parse_url (
        data, s.size(), false, &p));

    if (error)
    {
        ec = boost::system::error_code (
            boost::system::errc::invalid_argument,
            boost::system::generic_category());
        return;
    }

    if ((p.field_set & (1<<joyent::UF_SCHEMA)) != 0)
    {
        m_scheme = string_ref (
            data + p.field_data [joyent::UF_SCHEMA].off,
                p.field_data [joyent::UF_SCHEMA].len);
    }
    else
    {
        m_scheme = string_ref {};
    }

    if ((p.field_set & (1<<joyent::UF_HOST)) != 0)
    {
        m_host = string_ref (
            data + p.field_data [joyent::UF_HOST].off,
                p.field_data [joyent::UF_HOST].len);
    }
    else
    {
        m_host = string_ref {};
    }

    if ((p.field_set & (1<<joyent::UF_PORT)) != 0)
    {
        m_port = p.port;
        m_port_string = string_ref (
            data + p.field_data [joyent::UF_PORT].off,
                p.field_data [joyent::UF_PORT].len);
    }
    else
    {
        m_port = 0;
        m_port_string = string_ref {};
    }

    if ((p.field_set & (1<<joyent::UF_PATH)) != 0)
    {
        m_path = string_ref (
            data + p.field_data [joyent::UF_PATH].off,
                p.field_data [joyent::UF_PATH].len);
    }
    else
    {
        m_path = string_ref {};
    }

    if ((p.field_set & (1<<joyent::UF_QUERY)) != 0)
    {
        m_query = string_ref (
            data + p.field_data [joyent::UF_QUERY].off,
                p.field_data [joyent::UF_QUERY].len);
    }
    else
    {
        m_query = string_ref {};
    }

    if ((p.field_set & (1<<joyent::UF_FRAGMENT)) != 0)
    {
        m_fragment = string_ref (
            data + p.field_data [joyent::UF_FRAGMENT].off,
                p.field_data [joyent::UF_FRAGMENT].len);
    }
    else
    {
        m_fragment = string_ref {};
    }

    if ((p.field_set & (1<<joyent::UF_USERINFO)) != 0)
    {
        m_userinfo = string_ref (
            data + p.field_data [joyent::UF_USERINFO].off,
                p.field_data [joyent::UF_USERINFO].len);
    }
    else
    {
        m_userinfo = string_ref {};
    }
}
Ejemplo n.º 13
0
void
basic_url_base::parse_impl (string_ref s, boost::system::error_code& ec)
{
    joyent::http_parser_url p;

    value_type const* const data (s.data());
    
    int const error (joyent::http_parser_parse_url (
        data, s.size(), false, &p));

    if (error)
    {
        ec = boost::system::error_code (
            boost::system::errc::invalid_argument,
            boost::system::generic_category());
        return;
    }

    if ((p.field_set & (1<<joyent::uf_schema)) != 0)
    {
        m_scheme = string_ref (
            data + p.field_data [joyent::uf_schema].off,
                p.field_data [joyent::uf_schema].len);
    }
    else
    {
        m_scheme = string_ref {};
    }

    if ((p.field_set & (1<<joyent::uf_host)) != 0)
    {
        m_host = string_ref (
            data + p.field_data [joyent::uf_host].off,
                p.field_data [joyent::uf_host].len);
    }
    else
    {
        m_host = string_ref {};
    }

    if ((p.field_set & (1<<joyent::uf_port)) != 0)
    {
        m_port = p.port;
        m_port_string = string_ref (
            data + p.field_data [joyent::uf_port].off,
                p.field_data [joyent::uf_port].len);
    }
    else
    {
        m_port = 0;
        m_port_string = string_ref {};
    }

    if ((p.field_set & (1<<joyent::uf_path)) != 0)
    {
        m_path = string_ref (
            data + p.field_data [joyent::uf_path].off,
                p.field_data [joyent::uf_path].len);
    }
    else
    {
        m_path = string_ref {};
    }

    if ((p.field_set & (1<<joyent::uf_query)) != 0)
    {
        m_query = string_ref (
            data + p.field_data [joyent::uf_query].off,
                p.field_data [joyent::uf_query].len);
    }
    else
    {
        m_query = string_ref {};
    }

    if ((p.field_set & (1<<joyent::uf_fragment)) != 0)
    {
        m_fragment = string_ref (
            data + p.field_data [joyent::uf_fragment].off,
                p.field_data [joyent::uf_fragment].len);
    }
    else
    {
        m_fragment = string_ref {};
    }

    if ((p.field_set & (1<<joyent::uf_userinfo)) != 0)
    {
        m_userinfo = string_ref (
            data + p.field_data [joyent::uf_userinfo].off,
                p.field_data [joyent::uf_userinfo].len);
    }
    else
    {
        m_userinfo = string_ref {};
    }
}