Example #1
0
// Parses the given box file string into a page_number, utf8_str, and
// bounding_box. Returns true on a successful parse.
// The box file is assumed to contain box definitions, one per line, of the
// following format for blob-level boxes:
//   <UTF8 str> <left> <bottom> <right> <top> <page id>
// and for word/line-level boxes:
//   WordStr <left> <bottom> <right> <top> <page id> #<space-delimited word str>
// See applyybox.cpp for more information.
bool ParseBoxFileStr(const char* boxfile_str, int* page_number,
                     STRING* utf8_str, TBOX* bounding_box) {
  *bounding_box = TBOX();       // Initialize it to empty.
  *utf8_str = "";
  char uch[kBoxReadBufSize];
  const char *buffptr = boxfile_str;
  // Read the unichar without messing up on Tibetan.
  // According to issue 253 the utf-8 surrogates 85 and A0 are treated
  // as whitespace by sscanf, so it is more reliable to just find
  // ascii space and tab.
  int uch_len = 0;
  // Skip unicode file designation, if present.
  const unsigned char *ubuf = reinterpret_cast<const unsigned char*>(buffptr);
  if (ubuf[0] == 0xef && ubuf[1] == 0xbb && ubuf[2] == 0xbf)
      buffptr += 3;
  // Allow a single blank as the UTF-8 string. Check for empty string and
  // then blindly eat the first character.
  if (*buffptr == '\0') return false;
  do {
    uch[uch_len++] = *buffptr++;
  } while (*buffptr != '\0' && *buffptr != ' ' && *buffptr != '\t' &&
           uch_len < kBoxReadBufSize - 1);
  uch[uch_len] = '\0';
  if (*buffptr != '\0') ++buffptr;
  int x_min, y_min, x_max, y_max;
  *page_number = 0;
  int count = sscanf(buffptr, "%d %d %d %d %d",
                 &x_min, &y_min, &x_max, &y_max, page_number);
  if (count != 5 && count != 4) {
    tprintf("Bad box coordinates in boxfile string! %s\n", ubuf);
    return false;
  }
  // Test for long space-delimited string label.
  if (strcmp(uch, kMultiBlobLabelCode) == 0 &&
      (buffptr = strchr(buffptr, '#')) != NULL) {
    strncpy(uch, buffptr + 1, kBoxReadBufSize - 1);
    uch[kBoxReadBufSize - 1] = '\0';  // Prevent buffer overrun.
    chomp_string(uch);
    uch_len = strlen(uch);
  }
  // Validate UTF8 by making unichars with it.
  int used = 0;
  while (used < uch_len) {
    UNICHAR ch(uch + used, uch_len - used);
    int new_used = ch.utf8_len();
    if (new_used == 0) {
      tprintf("Bad UTF-8 str %s starts with 0x%02x at col %d\n",
              uch + used, uch[used], used + 1);
      return false;
    }
    used += new_used;
  }
  *utf8_str = uch;
  if (x_min > x_max) Swap(&x_min, &x_max);
  if (y_min > y_max) Swap(&y_min, &y_max);
  bounding_box->set_to_given_coords(x_min, y_min, x_max, y_max);
  return true;  // Successfully read a box.
}
Example #2
0
void InventoryDAOMySQL::deleteInventory(Inventory &inventory)
{
    MySQLManager::ConnectionHolder ch(MySQLManager::getInstance());
    std::unique_ptr<sql::PreparedStatement> ps(ch.conn->prepareStatement(DELETE_INVENTORY));

    ps->setInt(1, inventory.getId());

    ps->execute();
}
// 0 if success , 1 if multi the same id
JCode JLoginHash::add(JID userid,const QByteArray& extra)
{
    if(s_data.contains(userid)) return 1;
    QCryptographicHash ch(QCryptographicHash::Md5);
    ch.addData(extra);
    ch.addData(QTime::currentTime().toString().toAscii());
    s_data.insert(userid,ch.result().left(8));
    return 0;
}
Example #4
0
size_t CFileUtils::file_copy(const char* src_filename, int dst_fd) throw (CSyscallException)
{
    int src_fd = open(src_filename, O_RDONLY);
    if (-1 == src_fd)
        THROW_SYSCALL_EXCEPTION(NULL, errno, "open");

    sys::CloseHelper<int> ch(src_fd);
    return file_copy(src_fd, dst_fd);
}
Example #5
0
uint32_t CFileUtils::crc32_file(const char* filepath) throw (CSyscallException)
{
    int fd = open(filepath, O_RDONLY);
    if (-1 == fd)
        THROW_SYSCALL_EXCEPTION(NULL, errno, "open");

    sys::CloseHelper<int> ch(fd);
    return crc32_file(fd);
}
Example #6
0
size_t CFileUtils::file_copy(int src_fd, const char* dst_filename) throw (CSyscallException)
{    
    int dst_fd = open(dst_filename, O_WRONLY|O_CREAT|O_EXCL);
    if (-1 == src_fd)
        THROW_SYSCALL_EXCEPTION(NULL, errno, "open");

    sys::CloseHelper<int> ch(dst_fd);
    return file_copy(src_fd, dst_fd);
}
Example #7
0
off_t CFileUtils::get_file_size(const char* filepath) throw (CSyscallException)
{
    int fd = open(filepath, O_RDONLY);
    if (-1 == fd)
        THROW_SYSCALL_EXCEPTION(NULL, errno, "fstat");

    sys::CloseHelper<int> ch(fd);
    return get_file_size(fd);
}
Example #8
0
//------------------------------------------------------------------------
// Admin Listener
bool AdminListener::eventAccept(const accept_type& param)
{
	pw::chif_create_type cparam;
	cparam.fd = param.fd;
	cparam.poller = getIoPoller();
	cparam.ssl = param.ssl;
	AdminChannel* ch(new AdminChannel(cparam));
	return nullptr not_eq ch;
}
Example #9
0
int inbyte (void )
{
	while (ch () == 0) {
		if (feof (input))
			return (0);
		preprocess ();
	}
	return (gch ());
}
Example #10
0
void VendorDAOMySQL::deleteVendor(Vendor &vendor)
{
    MySQLManager::ConnectionHolder ch(MySQLManager::getInstance());
    std::unique_ptr<sql::PreparedStatement> ps(ch.conn->prepareStatement(DELETE_VENDOR));

    ps->setInt(1, vendor.getId());

    ps->execute();
}
Example #11
0
void Significance(TString tag=""){
  // Loading files
  TChain ch("ntp1");
  ch.Add("AWG82/ntuples/SP-1235-BSemiExcl-Run2-R22d-v06/*");
  ch.Add("AWG82/ntuples/SP-1235-BSemiExcl-Run4-R22d-v06/*");
  ch.Add("AWG82/ntuples/SP-1237-BSemiExcl-Run2-R22d-v06/*");
  ch.Add("AWG82/ntuples/SP-1237-BSemiExcl-Run4-R22d-v06/*");

  int entries = ch.GetEntries();
  TCut MMiss = "candPMiss>.2";
  TCut Q2 = "candQ2>4";
  TCut ee1 = "candType<3&&candEExtra<.2";
  TCut ee2 = "candType==3&&candEExtra<.15";
  TCut ee3 = "candType==4&&candEExtra<.3";
  TCut ee = (ee1||ee2||ee3);
  TCut basic = ee+MMiss+Q2;

  TString D0names[]={"K^- \\pi^+","K^-\\pi^+\\pi^0","K^-\\pi^+\\pi^+\\pi^-",
		     "K_S^0\\,\\pi^+\\pi^-","K_S^0\\,\\pi^+\\pi^-\\pi^0",
		     "K_S^0\\,K_S^0","K_S^0\\,\\pi^0","\\pi^+\\pi^-","K^+K^-"};
  TString Dplusnames[]={"K^-\\pi^+\\pi^+","K^-\\pi^+\\pi^+\\pi^0","K_S^0\\,\\pi^+",
			"K_S^0\\,\\pi^+\\pi^0","K_S^0\\,\\pi^+\\pi^+\\pi^-",
			"K^+K^-\\pi^+","K_S^0\\,K^+"};
  fstream tex;
  tex.open("mycode/tables/Significance"+tag+".txt",fstream::out);
  tex<<"\\begin{tabular}{|l|ccc||l|ccc|}"<<endl<<"\\hline"<<endl;
  tex<<"$\\mathbf{D^{(*)0}}$ & $S$ & B & $\\frac{S}{S+B}$(\\%) & ";
  tex<<"$\\mathbf{D^{(*)+}}$ & $S$ & B & $\\frac{S}{S+B}$(\\%)\\\\"<<endl;
  tex<<"\\hline \\hline"<<endl;

  double S=0,B=0;
  for(int i=1; i<10;i++){
    TString tS = "(MCType==5||MCType==6)&&candType<3&&candDType=="; tS+=i;
    TString tB = "(MCType==0||MCType>6)&&candType<3&&candDType==";tB+=i;
    TCut cutS(tS), cutB(tB);
    S = ch.GetEntries(basic+cutS);
    B = ch.GetEntries(basic+cutB);
    int puri = S/(S+B)*100;
    tex<<D0names[i-1]<<" & "<<S<<" & "<<B<<" & "<<puri<<" & ";
    if(i<8){
      tS = "(MCType==11||MCType==12)&&(candType==3||(candType==4&&candDstarType==5))&&candDType=="; 
      tB = "(MCType<7||MCType>12)&&(candType==3||(candType==4&&candDstarType==5))&&candDType==";
      tS+=i; tB+=i;
      TCut cutS(tS), cutB(tB);
      S = ch.GetEntries(basic+cutS);
      B = ch.GetEntries(basic+cutB);
      puri = S/(S+B)*100;
      tex<<Dplusnames[i-1]<<" & "<<S<<" & "<<B<<" & "<<puri<<" \\\\"<<endl;  
    } else {
      tex<<" & & & \\\\"<<endl;
    }
    cout<<"DMode "<<i<<" has S "<<S<<", S/sqrt(S+B) "<<round(S/sqrt(S+B));
    cout<<" and S/(S+B) "<<round(S/(S+B))<<endl;
  }
  tex<<"\\hline \\end{tabular}"<<endl<<endl;
}
Example #12
0
void OAuth::output(QNetworkRequest *req, const QString& cmd, const HSTREntry& addBody) const {
	Q_ASSERT(!_cs_key.isEmpty() && !_cs_secret.isEmpty());
	// OAuthヘッダを生成
	HSTREntry ent;
	ent[OAUTH::ENT::TIMESTAMP] = _geneTimeStamp();
	ent[OAUTH::ENT::NONCE] = _geneNonce();
	ent[OAUTH::ENT::VERSION] = OAUTH::_1_0;
	ent[OAUTH::ENT::SIG_METHOD] = OAUTH::HMAC_SHA1;
	ent[OAUTH::ENT::CS_KEY] = _cs_key;
	if(!_token.isEmpty())
		ent[OAUTH::ENT::TOKEN] = _token;
	else
		ent[OAUTH::ENT::CALLBACK] = "oob";
	if(!_veliID.isEmpty())
		ent[OAUTH::ENT::VERIFIER] = _veliID;
	// ソートの為に配列へ書き出し
	HSTRMapV sv;
	for(auto itr=ent.cbegin() ; itr!=ent.cend() ; itr++)
		sv.push_back(qMakePair(itr.key(), itr.value()));

	// add query items (for GET)
	if(cmd == "GET") {
		QUrlQuery q(req->url());
		auto qil = q.queryItems();
		for(auto qi : qil)
			sv.push_back(HSTRPair(qi.first, qi.second));
	} else if(cmd == "POST") {
		// 本体ノードがあればそれも加味
		// add body items (for POST)
		for(auto itr=addBody.cbegin() ; itr!=addBody.cend() ; itr++)
			sv.push_back(HSTRPair(itr.key(), itr.value()));
	} else {
		Q_ASSERT(false);
	}

	// 署名を計算
	SHA1DG dg;
	_calcSHA1(dg, sv, req->url(), cmd);

	// :base64変換
	QByteArray dg64 = QByteArray((const char*)dg, 20).toBase64();
	// :url(OAuth)変換
	char tc[64];
	UrlEncode_OAUTH(tc, sizeof(tc), dg64.data(), dg64.size());
	// 署名を付加
	ent.insert(OAUTH::ENT::SIGNATURE, tc);

	// Requestへ追加
	QString ss(OAUTH::OAUTH);
	QChar ch(' ');
	for(auto itr=ent.cbegin() ; itr!=ent.cend() ; itr++) {
		ss += QString("%1%2=\"%3\"").arg(ch).arg(itr.key()).arg(itr.value());
		ch = ',';
	}
	req->setRawHeader(ToBA(OAUTH::AUTHZ), ToBA(ss));
}
Example #13
0
/**
 * \brief Decrypts a 32-bit word using Acorn128.
 *
 * \param state The state for the Acorn128 cipher.
 * \param ciphertext The ciphertext word.
 *
 * \return The plaintext word.
 */
static inline uint32_t acornDecrypt32(Acorn128State *state, uint32_t ciphertext)
{
    // Extract out various sub-parts of the state as 32-bit words.
    #define s_extract_32(name, shift) \
        ((state->name##_l >> (shift)) | \
         (((uint32_t)(state->name##_h)) << (32 - (shift))))
    uint32_t s244 = s_extract_32(s6, 14);
    uint32_t s235 = s_extract_32(s6, 5);
    uint32_t s196 = s_extract_32(s5, 3);
    uint32_t s160 = s_extract_32(s4, 6);
    uint32_t s111 = s_extract_32(s3, 4);
    uint32_t s66  = s_extract_32(s2, 5);
    uint32_t s23  = s_extract_32(s1, 23);
    uint32_t s12  = s_extract_32(s1, 12);

    // Update the LFSR's.
    uint32_t s7_l = state->s7 ^ s235 ^ state->s6_l;
    state->s6_l ^= s196 ^ state->s5_l;
    state->s5_l ^= s160 ^ state->s4_l;
    state->s4_l ^= s111 ^ state->s3_l;
    state->s3_l ^= s66  ^ state->s2_l;
    state->s2_l ^= s23  ^ state->s1_l;

    // Generate the next 32 keystream bits and decrypt the ciphertext.
    // k = S[12] ^ S[154] ^ maj(S[235], S[61], S[193])
    //                    ^  ch(S[230], S[111], S[66])
    uint32_t ks = s12 ^ state->s4_l ^
                  maj(s235, state->s2_l, state->s5_l) ^
                  ch(state->s6_l, s111, s66);
    uint32_t plaintext = ciphertext ^ ks;

    // Generate the next 32 non-linear feedback bits.
    // f = S[0] ^ ~S[107] ^ maj(S[244], S[23], S[160])
    //                    ^ (ca & S[196]) ^ (cb & ks)
    // f ^= plaintext
    // Note: ca will always be 1 and cb will always be 0.
    uint32_t f = state->s1_l ^ (~state->s3_l) ^ maj(s244, s23, s160) ^ s196;
    f ^= plaintext;

    // Shift the state downwards by 32 bits.
    #define s_shift_32(name1, name2, shift) \
        (state->name1##_l = state->name1##_h | (state->name2##_l << (shift)), \
         state->name1##_h = (state->name2##_l >> (32 - (shift))))
    s7_l ^= (f << 4);
    state->s7 = (uint8_t)(f >> 28);
    s_shift_32(s1, s2, 29);
    s_shift_32(s2, s3, 14);
    s_shift_32(s3, s4, 15);
    s_shift_32(s4, s5, 7);
    s_shift_32(s5, s6, 5);
    state->s6_l = state->s6_h | (s7_l << 27);
    state->s6_h = s7_l >> 5;

    // Return the plaintext word to the caller.
    return plaintext;
}
Example #14
0
const vmime::charset posixHandler::getLocaleCharset() const
{
	const PLockHelper lock;

	const char* prevLocale = ::setlocale(LC_ALL, "");
	vmime::charset ch(::nl_langinfo(CODESET));
	::setlocale(LC_ALL, prevLocale);

	return (ch);
}
Example #15
0
 void create_cluster() {
   Attribute::register_class_names(get_column_names());
   Record * r = make_quuxalot_record();
   ClusterHead ch(r, 0.9953);
   RecordPList rl = get_record_list();
   cBlocking_Operation_By_Coauthors  blocker_coauthor = get_blocker_coathor();
   Cluster::set_reference_patent_tree_pointer( blocker_coauthor.get_patent_tree());
   Cluster * c = new Cluster(ch, rl);
   delete c;
 }
Example #16
0
File: crt1.c Project: sng7ca/ygg
void cls(void)
{
	register unsigned short cr, newcr;

	cr = getcr();
	newcr = cr % 80;
	crtmv(0, cr - newcr, newcr);
	crtset(newcr, ch(' '), 80 * 25 - newcr);
	mvcr(newcr);
}
Example #17
0
void VendorDAOMySQL::updateVendor(const Vendor &vendor)
{
    MySQLManager::ConnectionHolder ch(MySQLManager::getInstance());
    std::unique_ptr<sql::PreparedStatement> ps(ch.conn->prepareStatement(UPDATE_VENDOR));

    ps->setString(1, vendor.getName());
    ps->setInt(2, vendor.getId());

    ps->executeUpdate();
}
Example #18
0
QString Task::classClass()
{
    XClassHint hint;
    if(XGetClassHint(qt_xdisplay(), _win, &hint)) {
  QString ch( hint.res_class );
  XFree( hint.res_name );
  XFree( hint.res_class );
  return ch;
    }
    return QString::null;
}
Example #19
0
main()
{
    int t;
    scanf("%d\n",&t);
    while(t--)
    {
        gets(s);
        printf("%c\n",ch());
    }
    return 0;
}
Example #20
0
void uniphier_ld4_bcu_init(const struct uniphier_board_data *bd)
{
	int shift;

	writel(0x44444444, BCSCR0); /* 0x20000000-0x3fffffff: ASM bus */
	writel(0x11111111, BCSCR2); /* 0x80000000-0x9fffffff: IPPC/IPPD-bus */
	writel(0x11111111, BCSCR3); /* 0xa0000000-0xbfffffff: IPPC/IPPD-bus */
	writel(0x11111111, BCSCR4); /* 0xc0000000-0xdfffffff: IPPC/IPPD-bus */
	writel(0x11111111, BCSCR5); /* 0xe0000000-0Xffffffff: IPPC/IPPD-bus */

	/* Specify DDR channel */
	shift = bd->dram_ch[0].size / 0x04000000 * 4;
	writel(ch(shift), BCIPPCCHR2); /* 0x80000000-0x9fffffff */

	shift -= 32;
	writel(ch(shift), BCIPPCCHR3); /* 0xa0000000-0xbfffffff */

	shift -= 32;
	writel(ch(shift), BCIPPCCHR4); /* 0xc0000000-0xdfffffff */
}
Example #21
0
void makeRandomPolygon() {
  int n = 3 + rand() % 100; // between 3 and 12 points

  Polygon poly;
  for(int i = 0; i < n; ++i) {
    int XX = rand() % 100;
    int YY = rand() % 100;
    poly.push_back(Point(XX, YY));
  }
  ConvexHull ch(poly);
}
Example #22
0
long long ch(long long a,long long b){
	if (a==1)return b;
	long long g,i;
	i=ceill(b/(double)a);
	a=a*i-b;
	b*=i;
	g=gcd(a,b);
	a/=g;
	b/=g;
	return ch(a,b);
}
Example #23
0
bool Scheduler::handle_schedule(schedules::target_object item) {
	try {
		std::string response;
		nscapi::core_helper ch(get_core(), get_id());
		if (!ch.simple_query(item->command.c_str(), item->arguments, response)) {
			NSC_LOG_ERROR("Failed to execute: " + item->command);
			if (item->channel.empty()) {
				NSC_LOG_ERROR_WA("No channel specified for ", item->get_alias());
				return true;
			}
			nscapi::protobuf::functions::create_simple_submit_request(item->channel, item->command, NSCAPI::query_return_codes::returnUNKNOWN, "Command was not found: " + item->command, "", response);
			std::string result;
			get_core()->submit_message(item->channel, response, result);
			return true;
		}
		Plugin::QueryResponseMessage resp_msg;
		resp_msg.ParseFromString(response);
		Plugin::QueryResponseMessage resp_msg_send;
		resp_msg_send.mutable_header()->CopyFrom(resp_msg.header());
		BOOST_FOREACH(const Plugin::QueryResponseMessage::Response &p, resp_msg.payload()) {
			if (nscapi::report::matches(item->report, nscapi::protobuf::functions::gbp_to_nagios_status(p.result())))
				resp_msg_send.add_payload()->CopyFrom(p);
		}
		if (resp_msg_send.payload_size() > 0) {
			if (item->channel.empty()) {
				NSC_LOG_ERROR_STD("No channel specified for " + item->get_alias() + " mssage will not be sent.");
				return true;
			}
			nscapi::protobuf::functions::make_submit_from_query(response, item->channel, item->get_alias(), item->target_id, item->source_id);
			std::string result;
			if (!get_core()->submit_message(item->channel, response, result)) {
				NSC_LOG_ERROR_STD("Failed to submit: " + item->get_alias());
				return true;
			}
			std::string error;
			if (!nscapi::protobuf::functions::parse_simple_submit_response(result, error)) {
				NSC_LOG_ERROR_STD("Failed to submit " + item->get_alias() + ": " + error);
				return true;
			}
		} else {
			NSC_DEBUG_MSG("Filter not matched for: " + item->get_alias() + " so nothing is reported");
		}
		return true;
	} catch (nscapi::nscapi_exception &e) {
		NSC_LOG_ERROR_EXR("Failed to register command: ", e);
		return false;
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("Exception: ", e);
		return false;
	} catch (...) {
		NSC_LOG_ERROR_EX(item->get_alias());
		return false;
	}
}
Example #24
0
Polygon convex_hull(vector<Point> ps) {
  int n = ps.size(), k = 0;
  sort(begin(ps), end(ps), comp);
  Polygon ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  ch.resize(k - 1);
  return ch;
}
Example #25
0
int check_h()
{
    int i,flg=0;
    for(i=0; i<E; i++)
    {
        h(i)=H3(en(i,0)-1,0)-H3(en(i,1)-1,0);
        qc(i)=c(i)*(h(i)+Hd(i));
        if(ch(i)==1)
        {
            Re=ro*qc(i)*D(i)/(A(i)*mu);
            f(i)=.094*pow(K(i),0.225)+0.53*K(i)+88*pow(K(i),0.44)*pow(fabs(Re),(-1.62*pow(K(i),0.134)));
            hc(i)=f(i)*L(i)*pow(qc(i),2)/(2*g*D(i)*pow(A(i),2))+k(i)*pow(qc(i),2)/(2*g*pow(A(i),2));
        }
        else if (ch(i)==2 && qc(i)>0)
        {
            hc(i)=pow((qc(i)/A(i)),2)/(2*g)-Hd(i);
        }
        else if(ch(i)==2 && qc(i)<0)
        {
            hc(i)=-pow((qc(i)/A(i)),2)/(2*g)-Hd(i);
        }
        else if(ch(i)==3)
        {
            hc(i)=k(i)*pow((qc(i)/A(i)),2)/(2*g)*pow((100.0/o(i)),(2*n(i)));
        }
        cc(i)=fabs(qc(i)/(hc(i)+Hd(i)));
        err(i)=fabs(fabs(hc(i))-fabs(h(i)))/fabs(h(i))*100;
        qDebug()<<"hc "<<hc(i)<<"h "<<h(i)<<"D "<<D(i)<<"f "<<f(i)<<"L "<<L(i)<<"A "<<A(i);
        if(err(i)<rangep)
        {
            flg++;
        }
        if(hc(i)!=hc(i))
        {
            qDebug()<<"Inside break for NaN";
            stop=1;
        }
    }
    qDebug()<<"flg "<< flg;
return flg;
}
Example #26
0
void InventoryDAOMySQL::updateInventory(const Inventory &inventory)
{
    MySQLManager::ConnectionHolder ch(MySQLManager::getInstance());
    std::unique_ptr<sql::PreparedStatement> ps(ch.conn->prepareStatement(UPDATE_INVENTORY));

    ps->setInt(1, inventory.getUserId());
    ps->setInt(2, inventory.getFoodId());
    ps->setString(3, inventory.getUseBy());
    ps->setInt(4, inventory.getId());

    ps->executeUpdate();
}
Example #27
0
VP ConvexHull(VP ps) {
  int n = ps.size();
  int k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  ch.resize(k - 1);
  return ch;
}
int main(int argc, char **argv) 
{
  std::string str;
  int ret;

  // connection to the robot
  ArTcpConnection con;
  // the robot
  ArRobot robot;
  
  // ake the joydrive object, which also creates its own thread
  Joydrive joyd(&robot);
  
  // the connection handler
  ConnHandler ch(&robot, &joyd);

  // init aria, which will make a dedicated signal handling thread
  Aria::init(Aria::SIGHANDLE_THREAD);

  // open the connection with default args, exit if it fails
  if ((ret = con.open()) != 0)
  {
    str = con.getOpenMessage(ret);
    printf("Open failed: %s\n", str.c_str());
    Aria::shutdown();
    return 1;
  }


  // set the connection on the robot
  robot.setDeviceConnection(&con);

  // run the robot in its own thread
  robot.runAsync(false);
  
  // have the robot connect asyncronously (so its loop is still running)
  // if this fails it means that the robot isn't running in its own thread
  if (!robot.asyncConnect())
  {
    printf(
    "asyncConnect failed because robot is not running in its own thread.\n");
    Aria::shutdown();
    return 1;
  }

  // now we just wait for the robot to be done running
  printf("Waiting for the robot's run to exit.\n");
  robot.waitForRunExit();
  // then we exit
  printf("exiting main\n");
  Aria::exit(0);  // exit program
  return 0;
}
Example #29
0
asmfunc ()
{
	char	c;

	needbrack ("(");
	if (!match (quote)) {
		error ("Missing opening \" in asm call");
		return;
	}
	do {
		while (ch () != '"') {
			if (ch () == 0)
				break;
			c = gch();
			outbyte (c == '\\' ? spechar() : c);
		}
		gch ();
	} while (match (quote));
	needbrack (")");
	ns ();
}
Example #30
0
/**
 * compares two string both must be zero ended, otherwise no match found
 * advances line pointer only if match found
 * it assumes that an alphanumeric (including underscore) comparison
 * is being made and guarantees that all of the token in the source line is
 * scanned in the process
 * @param lit
 * @param len
 * @return 
 */
int amatch(char *lit, int len) {
    int k;

    blanks();
    if ((k = astreq (line + lptr, lit, len)) != 0) {
        lptr = lptr + k;
        while (alphanumeric (ch ()))
            inbyte ();
        return (1);
    }
    return (0);
}