コード例 #1
0
int test_sz(int n, TCHAR value[i]) {
  printf("=== test %i ===\n", n);
  int ret = 0;
  TCHAR empty[4096];
  memset(empty, 0xCC, sizeof(empty));
  buffer_t buffer((LPBYTE)empty, sizeof(empty));
  valueList_t v = ParseValues(buffer_t((LPBYTE)value, sizeof(TCHAR)*i), REG_SZ);
  if (memcmp(v.begin()->p, value, (i + 1) * sizeof(TCHAR))) {
    printf("list: got ?? expected %S [%i]\n", value, (i + 1) * sizeof(TCHAR));
    ++ret;
  }
  MakeMultiSzRegString(buffer, v);
  if (buffer.cbBytes != sizeof(TCHAR) * (i + 1)) {
    printf("got %i bytes, expected %i\n", buffer.cbBytes, sizeof(TCHAR) * (i + 1));
    ++ret;
  }
  if (memcmp(empty, value, (i + 1) * sizeof(TCHAR))) {
    printf("got ?? expected %S [%i]\n", value, (i + 1) * sizeof(TCHAR));
    ++ret;
  }
  if (ret) {
    for (int i = 0; i < 30; ++i) {
      printf("%02x ", ((char*)empty)[i]& 0xFF);
    }
    printf("\n");
    for (int i = 0; i < 30; ++i) {
      printf("%2c ", (((char*)empty)[i] ? ((char*)empty)[i] : ' '));
    }
    printf("\n");
  }
  return ret;
}
コード例 #2
0
ファイル: ProcFS.cpp プロジェクト: cosql/ds2
bool ProcFS::ReadUptime(Uptime &uptime) {
  FILE *fp = OpenFILE("uptime");
  if (fp == nullptr)
    return false;

  ParseValues(fp, 1024, ' ', false,
              [&](size_t index, char const *value) -> bool {
    char *end;

    switch (index) {
    case UPTIME_F_RUN_TIME:
      uptime.run_time.tv_sec = strtoll(value, &end, 0);
      if (*end++ == '.') {
        uptime.run_time.tv_nsec = strtoll(end, nullptr, 0) * 10000000;
      }
      break;

    case UPTIME_F_IDLE_TIME:
      uptime.idle_time.tv_sec = strtoll(value, &end, 0);
      if (*end++ == '.') {
        uptime.idle_time.tv_nsec = strtoll(end, nullptr, 0) * 10000000;
      }
      break;
    }

    return true;
  });

  std::fclose(fp);
  return true;
}
コード例 #3
0
ファイル: rab_equipped_entity.cpp プロジェクト: hoelzl/argos3
 void CRABEquippedEntity::Init(TConfigurationNode& t_tree) {
    try {
       /*
        * Init entity.
        * Here we explicitly avoid to call CPositionalEntity::Init() because that
        * would also initialize position and orientation, which, instead, must
        * be calculated from reference entity and offsets.
        */
       CEntity::Init(t_tree);
       /* Get offsets */
       GetNodeAttributeOrDefault(t_tree, "pos_offset", m_cPosOffset, m_cPosOffset);
       std::string strRotOffset;
       GetNodeAttributeOrDefault(t_tree, "rot_offset", strRotOffset, strRotOffset);
       if(strRotOffset != "") {
          CDegrees cRotOffsetEuler[3];
          ParseValues(strRotOffset, 3, cRotOffsetEuler, ',');
          m_cRotOffset.FromEulerAngles(ToRadians(cRotOffsetEuler[0]),
                                       ToRadians(cRotOffsetEuler[1]),
                                       ToRadians(cRotOffsetEuler[2]));
       }
       /* Parse and look up the anchor */
       std::string strAnchorId;
       GetNodeAttribute(t_tree, "anchor", strAnchorId);
       /*
        * NOTE: here we get a reference to the embodied entity
        * This line works under the assumption that:
        * 1. the RABEquippedEntity has a parent;
        * 2. the parent has a child whose id is "body"
        * 3. the "body" is an embodied entity
        * If any of the above is false, this line will bomb out.
        */
       m_pcEntityBody = &GetParent().GetComponent<CEmbodiedEntity>("body");
       m_psAnchor = &m_pcEntityBody->GetAnchor(strAnchorId);
       /* Get message size */
       size_t unMsgSize;
       GetNodeAttribute(t_tree, "msg_size", unMsgSize);
       m_cData.Resize(unMsgSize);
       /* Get transmission range */
       GetNodeAttribute(t_tree, "range", m_fRange);
       /* Set init position and orientation */
       Update();
       SetInitPosition(GetPosition());
       SetInitOrientation(GetOrientation());
    }
    catch(CARGoSException& ex) {
       THROW_ARGOSEXCEPTION_NESTED("Error initializing a range and bearing entity \"" << GetId() << "\"", ex);
    }
 }
コード例 #4
0
ファイル: XMLADMData.cpp プロジェクト: Dysonics/bbcat-fileio
/*--------------------------------------------------------------------------------*/
ADMObject *XMLADMData::Parse(const std::string& type, void *userdata)
{
  ADMHEADER header;
  ADMObject *obj;

  ParseHeader(header, type, userdata);

  // delete any existing object of the same ID UNLESS it's an ADMAudioTrack
  if ((obj = Create(type, header.id, header.name, (type != ADMAudioTrack::Type))) != NULL)
  {
    ParseValues(obj, userdata);
    PostParse(obj, userdata);

    obj->SetValues();
  }

  return obj;
}
コード例 #5
0
int test_multi(int n, TCHAR *data, DWORD dataLen, TCHAR** ref, int refLen) {
  printf("=== test %i ===\n", n);
  int ret = 0;
  TCHAR empty[4096];
  memset(empty, 0xCC, sizeof(empty));
  buffer_t buffer((LPBYTE)empty, sizeof(empty));
  valueList_t v = ParseValues(buffer_t((LPBYTE)data, dataLen), REG_MULTI_SZ);
  MakeMultiSzRegString(buffer, v);
  if (v.size() != refLen) {
    printf("got %i items, expected %i\n", v.size(), refLen);
    ++ret;
  }
  int i = 0;
  for (valueList_t::const_iterator it = v.begin();
       i < refLen && it != v.end();
       ++it, ++i)
  {
    if (_tcscmp(it->p, ref[i])) {
      printf("got mismatch at position %i\n", i);
      ++ret;
    }
  }
  if (memcmp(empty, data, dataLen)) {
    printf("mismatch in raw buffer\n");
    ++ret;
  }
  if (ret) {
    for (int i = 0; i < dataLen + 2; ++i) {
      printf("%02x ", ((char*)empty)[i]& 0xFF);
    }
    printf("\n");
    for (int i = 0; i < dataLen + 2; ++i) {
      printf("%2c ", (((char*)empty)[i] ? ((char*)empty)[i] : ' '));
    }
    printf("\n");
  }
  return ret;
}
コード例 #6
0
ファイル: ProcFS.cpp プロジェクト: cosql/ds2
bool ProcFS::ReadStat(pid_t pid, pid_t tid, Stat &stat) {
  FILE *fp = OpenFILE(pid, tid, "stat");
  if (fp == nullptr)
    return false;

  //
  // The complicated logic about the comm field is brought
  // to you to the insane way of Linux to `encode' that field,
  // an evil executable may contains ')' in its name and
  // break the parsing.
  //
  std::string comm;
  size_t field_index = STAT_F_PID;
  bool may_end_comm = false;

  ParseValues(fp, 1024, ' ', true, [&](size_t, char const *value) -> bool {
    if (field_index == STAT_F_TCOMM) {
      //
      // Is this really the end?
      //
      if (may_end_comm && value[strlen(value) - 2] != ')') {
        //
        // Yes, save the "tcomm" field, and advance field index.
        //
        comm = comm.substr(0, comm.rfind(')'));
        strncpy(stat.tcomm, comm.c_str(), sizeof(stat.tcomm));
        field_index++;
      } else {
        if (!may_end_comm) {
          value++; // strip the initial '('
        }
        comm += value;
        //
        // Assume it is not the end.
        //
        may_end_comm = true;
        //
        // We'll process the next item to know if this was
        // really the end of the comm.
        //
        return true;
      }
    }

    switch (field_index++) {
    case STAT_F_STATE:
      stat.state = value[0];
      break;
    case STAT_F_PID:
      stat.pid = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_PPID:
      stat.ppid = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_PGRP:
      stat.pgrp = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_SID:
      stat.sid = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_TTY_NR:
      stat.tty_nr = std::strtoul(value, nullptr, 0);
      break;
    case STAT_F_TTY_PGRP:
      stat.tty_pgrp = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_FLAGS:
      stat.flags = strtoull(value, nullptr, 0);
      break;
    case STAT_F_MIN_FLT:
      stat.min_flt = strtoull(value, nullptr, 0);
      break;
    case STAT_F_CMIN_FLT:
      stat.cmin_flt = strtoull(value, nullptr, 0);
      break;
    case STAT_F_MAJ_FLT:
      stat.maj_flt = strtoull(value, nullptr, 0);
      break;
    case STAT_F_CMAJ_FLT:
      stat.cmaj_flt = strtoull(value, nullptr, 0);
      break;
    case STAT_F_UTIME:
      stat.utime = strtoull(value, nullptr, 0);
      break;
    case STAT_F_STIME:
      stat.stime = strtoull(value, nullptr, 0);
      break;
    case STAT_F_CUTIME:
      stat.cutime = strtoull(value, nullptr, 0);
      break;
    case STAT_F_CSTIME:
      stat.cstime = strtoull(value, nullptr, 0);
      break;
    case STAT_F_PRIORITY:
      stat.priority = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_NICE:
      stat.nice = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_NUM_THREADS:
      stat.num_threads = std::strtoul(value, nullptr, 0);
      break;
    case STAT_F_START_TIME:
      stat.start_time = strtoull(value, nullptr, 0);
      break;
    case STAT_F_VSIZE:
      stat.vsize = strtoull(value, nullptr, 0);
      break;
    case STAT_F_RSS:
      stat.rss = strtoull(value, nullptr, 0);
      break;
    case STAT_F_RSSLIM:
      stat.rsslim = strtoull(value, nullptr, 0);
      break;
    case STAT_F_START_CODE:
      stat.start_code = strtoull(value, nullptr, 0);
      break;
    case STAT_F_END_CODE:
      stat.end_code = strtoull(value, nullptr, 0);
      break;
    case STAT_F_START_STACK:
      stat.start_stack = strtoull(value, nullptr, 0);
      break;
    case STAT_F_ESP:
      stat.esp = strtoull(value, nullptr, 0);
      break;
    case STAT_F_EIP:
      stat.eip = strtoull(value, nullptr, 0);
      break;
    case STAT_F_PENDING:
      stat.pending = strtoull(value, nullptr, 0);
      break;
    case STAT_F_BLOCKED:
      stat.blocked = strtoull(value, nullptr, 0);
      break;
    case STAT_F_SIGIGN:
      stat.sigign = strtoull(value, nullptr, 0);
      break;
    case STAT_F_SIGCATCH:
      stat.sigcatch = strtoull(value, nullptr, 0);
      break;
    case STAT_F_WCHAN:
      stat.wchan = strtoull(value, nullptr, 0);
      break;
    case STAT_F_EXIT_SIGNAL:
      stat.exit_signal = std::strtoul(value, nullptr, 0);
      break;
    case STAT_F_TASK_CPU:
      stat.task_cpu = std::strtoul(value, nullptr, 0);
      break;
    case STAT_F_RT_PRIORITY:
      stat.rt_priority = std::strtol(value, nullptr, 0);
      break;
    case STAT_F_POLICY:
      stat.policy = std::strtoul(value, nullptr, 0);
      break;
    case STAT_F_BLKIO_TICKS:
      stat.blkio_ticks = strtoull(value, nullptr, 0);
      break;
    case STAT_F_GTIME:
      stat.gtime = strtoull(value, nullptr, 0);
      break;
    case STAT_F_CGTIME:
      stat.cgtime = strtoull(value, nullptr, 0);
      break;
    case STAT_F_START_DATA:
      stat.start_data = strtoull(value, nullptr, 0);
      break;
    case STAT_F_END_DATA:
      stat.end_data = strtoull(value, nullptr, 0);
      break;
    case STAT_F_START_BRK:
      stat.start_brk = strtoull(value, nullptr, 0);
      break;
    default:
      break;
    }
    return true;
  });

  std::fclose(fp);
  return true;
}
コード例 #7
0
ファイル: XMLTags.cpp プロジェクト: AllenChow/vudroid
void
lt_XMLTags::init(XMLByteStream &xmlbs)
{
  if(!get_count())
  {
    G_THROW( ERR_MSG("XMLTags.no_GP") );
  }
  GPList<lt_XMLTags> level;
  GUTF8String tag,raw(xmlbs.gets(0,'<',false));
  int linesread=xmlbs.get_lines_read();
  if(!isspaces(raw))
  {
    G_THROW( (ERR_MSG("XMLTags.raw_string") "\t")+raw);
  }
  GUTF8String encoding;
  for(int len;(len=(tag=xmlbs.gets(0,'>',true)).length());)
  {
    if(tag[len-1] != '>')
    {
      G_THROW((ERR_MSG("XMLTags.bad_tag") "\t")+tag);
    }
    switch(tag[1])
    {
      case '?':
      {
        while(len < 4 || tag.substr(len-2,len) != "?>")
        {
          GUTF8String cont(xmlbs.gets(0,'>',true));
          if(!cont.length())
          { 
            G_THROW( (ERR_MSG("XMLTags.bad_PI") "\t")+tag);
          }
          len=((tag+=cont).length());
        }
        char const *n;
        GUTF8String xtag = tag.substr(2,-1);
        GUTF8String xname = tagtoname(xtag,n);
        if(xname.downcase() == "xml")
        {
          ParseValues(n,args);
          for(GPosition pos=args;pos;++pos)
          {
            if(args.key(pos) == "encoding")
            {
              const GUTF8String e=args[pos].upcase();
              if(e != encoding)
              {
                xmlbs.set_encoding((encoding=e));
              }
            }
          }
        }
        break;
      }
      case '!':
      {
        if(tag[2] == '-' && tag[3] == '-')
        {
          while((len < 7) ||
            (tag.substr(len-3,-1) != "-->"))
          {
            GUTF8String cont(xmlbs.gets(0,'>',true));
            if(!cont.length())
            { 
              GUTF8String mesg;
              mesg.format( ERR_MSG("XMLTags.bad_comment") "\t%s",(const char *)tag);
              G_THROW(mesg);
            }
            len=((tag+=cont).length());
          }
        }
        break;
      }
      case '/':
      {
        GUTF8String xname=tagtoname(tag.substr(2,-1));
        GPosition last=level.lastpos();
        if(last)
        {
          if(level[last]->name != xname)
          {
            G_THROW( (ERR_MSG("XMLTags.unmatched_end") "\t")
              +level[last]->name+("\t"+GUTF8String(level[last]->get_Line()))
              +("\t"+xname)+("\t"+GUTF8String(linesread+1)));
          }
          level.del(last);
        }else
        {
          G_THROW( ERR_MSG("XMLTags.bad_form") );
        }
        break;
      }
      default:
      {
        GPosition last=level.lastpos();
        GP<lt_XMLTags> t;
        if(last)
        {
          t=new lt_XMLTags(tag.substr(1,len-1));
          level[last]->addtag(t);
          if(tag[len-2] != '/')
          {
            level.append(t);
          }
        }else if(tag[len-2] != '/')
        {
          char const *n;
          GUTF8String xtag = tag.substr(1,-1); 
          name=tagtoname(xtag, n);
          ParseValues(n,args);
          t=this;
          level.append(t);
        }else
        {
          G_THROW( ERR_MSG("XMLTags.no_body") );
        }
        t->set_Line(linesread+1);
        break;
      }
    }
    if((raw=xmlbs.gets(0,'<',false))[0])
    { 
      linesread=xmlbs.get_lines_read();
      GPosition last=level.lastpos();
      if(last)
      {
        level[last]->addraw(raw);
      }else if(!isspaces(raw))
      {
        G_THROW(( ERR_MSG("XMLTags.raw_string") "\t")+raw);
      }
    }
  }
}
コード例 #8
0
ファイル: XMLTags.cpp プロジェクト: AllenChow/vudroid
lt_XMLTags::lt_XMLTags(const char n[]) : startline(0)
{
  char const *t;
  name=tagtoname(n,t);
  ParseValues(t,args);
}