Esempio n. 1
0
 XXXX ()
 {
    dMatrix s;
    dFloat m = 2.0f;
    for (int i = 0; i < 3; i ++)
    {
       for (int j = 0; j < 3; j ++)
       {
          s[i][j] = m;
          m += (i + 1) + j;
       }
    }
    s.m_posit = dVector (1, 2, 3, 1);
    dMatrix matrix;
    dVector scale;
    dMatrix stretch;
    s.PolarDecomposition (matrix, scale, stretch);
    dMatrix s1 (matrix, scale, stretch);
    dMatrix xxx (dPitchMatrix (30.0f * 3.14159f / 180.0f) * dRollMatrix (30.0f * 3.14159f / 180.0f));
    dMatrix xxxx (GetIdentityMatrix());
    xxx[0] = xxx[0].Scale (-1.0f);
    dFloat mmm = (xxx[0] * xxx[1]) % xxx[2];
    xxxx[0][0] = 3.0f;
    xxxx[1][1] = 3.0f;
    xxxx[2][2] = 4.0f;
    dMatrix xxx2 (xxx * xxxx);
    mmm = (xxx2[0] * xxx2[1]) % xxx2[2];
    xxx2.PolarDecomposition (matrix, scale, stretch);
    s1 = dMatrix (matrix, scale, stretch);
    s1 = dMatrix (matrix, scale, stretch);
 }
Esempio n. 2
0
int
main (void)
{
  foo ();
  xxx ();
  return 0;
}
    void async_metadata_client::handle_get_metadata(rpc_result<metadata_response> response) {
      if(response.ec) {
        _client.close();
        _connect_retry_timer.expires_from_now(_current_retry_timeout);
        _connect_retry_timer.async_wait(boost::bind(&async_metadata_client::handle_connect_retry_timer, this, boost::asio::placeholders::error));
      } else {
        csi::spinlock::scoped_lock xxx(_spinlock);
        _metadata = response;

        for(std::vector<csi::kafka::broker_data>::const_iterator i = _metadata->brokers.begin(); i != _metadata->brokers.end(); ++i) {
          _broker2brokers[i->node_id] = *i;
        };

        // any changes to broker list?
        bool changed = false;

        changed = _metadata->brokers.size() != _known_brokers.size();

        if(!changed) {
          // see if we find all existing brokers in new list
          for(std::vector<csi::kafka::broker_data>::const_iterator i = _metadata->brokers.begin(); i != _metadata->brokers.end(); ++i) {
            bool found = false;
            for(std::vector<broker_address>::const_iterator j = _known_brokers.begin(); j != _known_brokers.end(); ++j) {
              if(i->host_name == j->host_name && i->port == j->port) {
                found = true;
                break;
              }
            }
            if(!found) {
              changed = true;
              break;
            }
          }
        }

        if(changed) {
          std::string broker_list_str;
          _known_brokers.clear();
          for(std::vector<csi::kafka::broker_data>::const_iterator i = _metadata->brokers.begin(); i != _metadata->brokers.end(); ++i) {
            if(broker_list_str.size() == 0) // first
              broker_list_str += i->host_name + ":" + std::to_string(i->port);
            else
              broker_list_str += ", " + i->host_name + ":" + std::to_string(i->port);
            _known_brokers.push_back(broker_address(i->host_name, i->port));
          }
          BOOST_LOG_TRIVIAL(info) << "known brokers changed { " << broker_list_str << " }";
          _next_broker = _known_brokers.begin();
        }

        /*
        if(_connect_cb) {
          _connect_cb(response.ec.ec1);
          _connect_cb = NULL;
        }
        */

        _metadata_timer.expires_from_now(_metadata_timeout);
        _metadata_timer.async_wait(boost::bind(&async_metadata_client::handle_get_metadata_timer, this, boost::asio::placeholders::error));
      }
    }
void CDialogEditGridColours::OnGridSelect(wxGridRangeSelectEvent &e)
{
  bool bSkip = true;
  if(!m_nInSelect)
  {
    CIncrementer xxx(m_nInSelect);
    if(e.Selecting())
    {
      wxGrid *pGrid = (wxGrid *) e.GetEventObject();
      int nRow = pGrid->GetGridCursorRow();
      pGrid->ClearSelection();
      pGrid->SetGridCursor(nRow,0);
/*
      int nTop = e.GetTopRow();
      int nBot = e.GetBottomRow();
      if(nTop != nBot)
      {
        int nRow = pGrid->GetGridCursorRow();
        pGrid->ClearSelection();
        pGrid->SetGridCursor(nRow,0);
      }
*/
    }
  }
  e.Skip(bSkip);
}
Esempio n. 5
0
void displayGizmo(PixelImage* image, Matrix4 m) {
    int w2 = image->getWidth()/2;
    int h2 = image->getHeight()/2;
    
    Vector3 ooo(0,0,0);
    Vector3 xxx(50,0,0);
    Vector3 yyy(0,50,0);
    Vector3 zzz(0,0,50);

    ooo *= m;
    xxx *= m;
    yyy *= m;
    zzz *= m;

    ooo.x += w2; ooo.y = h2-ooo.y;
    xxx.x += w2; xxx.y = h2-xxx.y;
    yyy.x += w2; yyy.y = h2-yyy.y;
    zzz.x += w2; zzz.y = h2-zzz.y;

    DoubleColor cx = {1, 0, 0, 1};
    DoubleColor cy = {0, 1, 0, 1};
    DoubleColor cz = {0, 0, 1, 1};

    d2d::Line lx; lx.beg = ooo.view(); lx.end = xxx.view(); lx.col = cx;
    d2d::Line ly; ly.beg = ooo.view(); ly.end = yyy.view(); ly.col = cy;
    d2d::Line lz; lz.beg = ooo.view(); lz.end = zzz.view(); lz.col = cz;

    d2d::lineDotsAdapt(image, &lx, 1.0);
    d2d::lineDotsAdapt(image, &ly, 1.0);
    d2d::lineDotsAdapt(image, &lz, 1.0);
}
Esempio n. 6
0
void testroute_run(void) {
	static int dest_pnt_list[] = {24, 0};//{24, 32, 8, 0, 8, 32, 24, 0, 
									//14, 16, 18, 8, 4, 16, 28, 32, 18, 14, 0, 4, 16, 28, 24, 0};
	static int dest_pnt_index = 0;
	while (1) {
	
		if (!control_can_interrupt()) continue; // 正在转弯抓角就不用再走下去了,反正控不了
		// 更新边点号
        if (!graph_is_edge_point(cur_point) 
				&& is_on_edge()) {
			cur_point = get_next_point(head_direction, cur_point);
			nobeep();
		}
		
		_Bool interrupt = xxx(&dian, &last_, &xxx);
		// 先看看前面有没有人,有就停着
		if (scan_infront() 
			&& !graph_is_corner_point(cur_point)) {
			yesbeep(); // beep!!
			execute_command(C_BREAK);
			continue;
		}
		else {
			//nobeep();
		}
		
		if (graph_get_point_number(cur_point) == dest_pnt_list[dest_pnt_index]) {
			dest_pnt_index = (dest_pnt_index + 1) % 2;
		}
		
		curcmd = __move_to(dest_pnt_list[dest_pnt_index], D_NONE);
		execute_command(curcmd);
	}
}
Esempio n. 7
0
int
main(int, char *[])
{
    more::print(std::cout, "%1 %2\n", "hello", std::string("world"));
    more::print(std::cout, "0x%1\n", more::flags<std::ios::hex>(3735928559U));
    more::print(std::cout, "%1\n", std::thread::id());

    char buffer[4] = { 'a', 'a', 'a', 'a' };

    more::bprint(buffer,4, "%1!", 42);
    std::cout << buffer << std::endl;

#ifdef PERFORMANCE_TEST
    std::string xxx("world");

    std::cout << "performance test: " << std::flush;

    auto tstart = std::chrono::system_clock::now();
    char tmp[1024];

    for(int i=0; i < 10000000; i++)
    {
        // sprintf(tmp, "%s %s %d\n", "hello", xxx.c_str(), 19230983);
        // more::bprint(tmp,1024,"%1 %2 %3\n", "hello", xxx, 19230983);
        more::sprint("%1 %2 %3\n", "hello", xxx, 19230983);
        // boost::format("%1% %2% %3%\n") % "hello" % xxx % 19230983;
    }

    auto diff = std::chrono::system_clock::now() - tstart;

    std::cout << static_cast<double>(static_cast<std::chrono::microseconds>(diff).count())/1000000 << " sec." << std::endl;
#endif
    return 0;
}
 static DbPvProviderFactoryPtr create(
     DbPvProviderPtr const &channelProvider)
 {
     DbPvProviderFactoryPtr xxx(
         new DbPvProviderFactory(channelProvider));
     registerChannelProviderFactory(xxx);
     return xxx;
 }
 static LocalChannelProviderFactoryPtr create(
     ChannelProviderLocalPtr const &channelProvider)
 {
     LocalChannelProviderFactoryPtr xxx(
         new LocalChannelProviderFactory(channelProvider));
     registerChannelProviderFactory(xxx);
     return xxx;
 }
Esempio n. 10
0
int main(void)
{
  derived xxx(8,9);

  cout << xxx.base2::xxx << " " << xxx.base3::xxx << " " << sizeof(xxx) << endl;

  return 0;
}
Esempio n. 11
0
  /* CURLOPT_OPENSOCKETFUNCTION */
  curl_socket_t http_client::opensocket_cb(curlsocktype purpose, struct curl_sockaddr *address) {
    /* IPV4 */
    if(purpose == CURLSOCKTYPE_IPCXN && address->family == AF_INET) {
      /* create a tcp socket object */
      boost::asio::ip::tcp::socket *tcp_socket = new boost::asio::ip::tcp::socket(_io_service);

      /* open it and get the native handle*/
      boost::system::error_code ec;
      tcp_socket->open(boost::asio::ip::tcp::v4(), ec);

      if(ec) {
        BOOST_LOG_TRIVIAL(error) << this << ", " << BOOST_CURRENT_FUNCTION << ", open failed, socket: " << ec << ", (" << ec.message() << ")";
        delete tcp_socket;
        return CURL_SOCKET_BAD;
      }

      curl_socket_t sockfd = tcp_socket->native_handle();
      /* save it for monitoring */
      {
        csi::spinlock::scoped_lock xxx(_spinlock);
        _socket_map.insert(std::pair<curl_socket_t, boost::asio::ip::tcp::socket *>(sockfd, tcp_socket));
      }
      BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << " open ok, socket: " << sockfd;
      return sockfd;
    }

    //// IPV6
    //if (purpose == CURLSOCKTYPE_IPCXN && address->family == AF_INET6)
    //{
    //    /* create a tcp socket object */
    //    boost::asio::ip::tcp::socket *tcp_socket = new boost::asio::ip::tcp::socket(_io_service);

    //    /* open it and get the native handle*/
    //    boost::system::error_code ec;
    //    tcp_socket->open(boost::asio::ip::tcp::v6(), ec);

    //    if (ec)
    //    {
    //        BOOST_LOG_TRIVIAL(error) << this << ", " << BOOST_CURRENT_FUNCTION << ", open failed, socket: " << ec << ", (" << ec.message() << ")";
    //        delete tcp_socket;
    //        return CURL_SOCKET_BAD;
    //    }

    //    curl_socket_t sockfd = tcp_socket->native_handle();
    //    /* save it for monitoring */
    //    {
    //        csi::spinlock::scoped_lock xxx(_spinlock);
    //        _socket_map.insert(std::pair<curl_socket_t, boost::asio::ip::tcp::socket *>(sockfd, tcp_socket));
    //    }
    //    BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << " open ok, socket: " << sockfd;
    //    return sockfd;
    //}

    BOOST_LOG_TRIVIAL(error) << "http_client::opensocket_cb unsupported address family";
    return CURL_SOCKET_BAD;
  }
Esempio n. 12
0
void *ndbd_malloc(size_t size)
{
  void *p = NdbMem_Allocate(size);
  if (p)
  {
    g_allocated_memory += size;

    ndbd_alloc_touch_mem(p, size, 0);

#ifdef TRACE_MALLOC
    {
      size_t s_m, s_k, s_b;
      xxx(size, &s_m, &s_k, &s_b);
      fprintf(stderr, "%p malloc(%um %uk %ub)", p, s_m, s_k, s_b);
      xxx(g_allocated_memory, &s_m, &s_k, &s_b);
      fprintf(stderr, "\t\ttotal(%um %uk %ub)\n", s_m, s_k, s_b);
    }
#endif
  }
  return p;
}
Esempio n. 13
0
void couter( int fd )
{
    std::cout << "CAN READ!\n";
    char buff[ 1024 ];
    int n = unistd::read( fd, buff, 2 );
    if ( n <= 0 )
    {
        std::cout << "DAMN!!!\n";
        return;
    }
    std::string xxx( buff, n );
    std::cout << xxx;
}
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT("Compiler_Features_21_Test"));

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("Compiler Feature 21 Test does compile and run.\n")));

  int retval = xxx();

  ACE_END_TEST;

  return retval;
}
Esempio n. 15
0
bool QueryDataSource::loadBlock(__int64 startRow, offset_t startOffset)
{
    MemoryBuffer temp;

    //enter scope....>
    {
        Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
        Owned<IWorkUnit> wu = factory->updateWorkUnit(browseWuid);
        Owned<IWUResult> lower = wu->updateVariableByName(LOWER_LIMIT_ID);
        lower->setResultInt(startOffset);
        lower->setResultStatus(ResultStatusSupplied);

        Owned<IWUResult> dataResult = wu->updateResultBySequence(0);
        dataResult->setResultRaw(0, NULL, ResultFormatRaw);
        dataResult->setResultStatus(ResultStatusUndefined);
        wu->clearExceptions();
        if (wu->getState() != WUStateUnknown)
            wu->setState(WUStateCompiled);

        //Owned<IWUResult> count = wu->updateVariableByName(RECORD_LIMIT_ID);
        //count->setResultInt64(fetchSize);
    }

    //Resubmit the query...
    submitWorkUnit(browseWuid, username, password);
    WUState finalState = waitForWorkUnitToComplete(browseWuid, -1, true);
    if(!((finalState == WUStateCompleted) || (finalState == WUStateWait)))
        return false;

    //Now extract the results...
    Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
    Owned<IConstWorkUnit> wu = factory->openWorkUnit(browseWuid, false);
    Owned<IConstWUResult> dataResult = wu->getResultBySequence(0);
    MemoryBuffer2IDataVal xxx(temp);
    dataResult->getResultRaw(xxx, NULL, NULL);

    if (temp.length() == 0)
        return false;

    RowBlock * rows;
    if (returnedMeta->isFixedSize())
        rows = new FilePosFixedRowBlock(temp, startRow, startOffset, returnedMeta->fixedSize());
    else
        rows = new FilePosVariableRowBlock(temp, startRow, startOffset, returnedMeta, true);
    cache.addRowsOwn(rows);
    return true;
}
Esempio n. 16
0
void
MIKTEXCALLBACK
PostScript::ConvertToEPSThread (/*[in]*/ void * pv)
{
  MIKTEX_ASSERT (pv != 0);
  ThreadArg * pArg = reinterpret_cast<ThreadArg*>(pv);
  MIKTEX_ASSERT (pArg->pFileIn != 0 && pArg->pFileOut != 0);
  auto_ptr<ThreadArg> xxx (pArg);
#if 0
  bmeps_cfg ("c");
  int rc = bmeps_run(pArg->pFileOut, pArg->pFileIn, pArg->pathFile.GetBuffer());
  if (rc == 0)
  {
    // FIXME
  }
#endif
}
Esempio n. 17
0
  /* CURLOPT_CLOSESOCKETFUNCTION */
  int http_client::closesocket_cb(curl_socket_t item) {
    BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", socket: " << item;
    {
      csi::spinlock::scoped_lock xxx(_spinlock);
      std::map<curl_socket_t, boost::asio::ip::tcp::socket*>::iterator it = _socket_map.find(item);
      if(it != _socket_map.end()) {
        boost::system::error_code ec;
        it->second->cancel(ec);
        it->second->close(ec);
        boost::asio::ip::tcp::socket* s = it->second;

        //curl_multi_assign(_multi, it->first, NULL); // we need to remove this at once since curl likes to reuse sockets 
        _socket_map.erase(it);
        _io_service.post([this, s]() {
          BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", socket: " << s;
          delete s; // must be deleted after operations on socket completed. therefore the _io_service.post
        });
      }
    }
    return 0;
  }
Esempio n. 18
0
bool FullWorkUnitDataSource::init()
{
    bool ok = WorkUnitDataSource::init();
    if (ok)
    {
        MemoryBuffer temp;
        MemoryBuffer2IDataVal xxx(temp);

        //Nasty.  Single sets are represented as the same way as datasets (with an extra flag for all)
        //however need to represent as a single row containing a set, which has a different format.
        if (wuResult->isResultScalar() && returnedMeta->isSingleSet())
        {
            temp.append(wuResult->getResultIsAll());
            temp.append((size32_t)wuResult->getResultRawSize(0, 0));
        }
        wuResult->getResultRaw(xxx, NULL, NULL);

        if (returnedMeta->isFixedSize())
            rows.setown(new FixedRowBlock(temp, 0, 0, returnedMeta->fixedSize()));
        else
            rows.setown(new VariableRowBlock(temp, 0, 0, returnedRecordSize, true));
    }
    return ok;
}
Esempio n. 19
0
bool PagedWorkUnitDataSource::loadBlock(__int64 startRow, offset_t startOffset)
{
    MemoryBuffer temp;
    MemoryBuffer2IDataVal xxx(temp); 
    RowBlock * rows;
    if (returnedMeta->isFixedSize())
    {
        unsigned fixedSize = returnedMeta->fixedSize();
        unsigned readSize = (WU_BLOCK_SIZE / fixedSize) * fixedSize;
        wuResult->getResultRaw(xxx, startOffset, readSize, NULL, NULL);
        if (temp.length() == 0)
            return false;
        rows = new FixedRowBlock(temp, startRow, startOffset, fixedSize);
    }
    else
    {
        wuResult->getResultRaw(xxx, startOffset, WU_BLOCK_SIZE, NULL, NULL);
        if (temp.length() == 0)
            return false;
        rows = new VariableRowBlock(temp, startRow, startOffset, returnedRecordSize, startOffset + temp.length() == totalSize);
    }
    cache.addRowsOwn(rows);
    return true;
}
int main(int argc, char *argv[])
{
    t38_non_ecm_buffer_state_t buffer;
    logging_state_t logging;
    uint8_t buf[1024];
    int bit;
    int n;
    int log_bits;
    int i;

    log_bits = (argc > 1);
    printf("T.38 non-ECM rate adapting buffer tests.\n");
    span_log_init(&logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(&logging, "Buffer");

    printf("1 - Impose no minimum for the bits per row\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 0);
    n = 0;
    bit_no = 0;
    /* We should get ones until the buffers recognises an EOL */
    printf("    We should get ones here\n");
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 1);
    printf("    We should change to zeros here\n");
    xxx(&buffer, &logging, log_bits, i, 0);
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 0);
    printf("    We should get the first row here\n");
    xxx(&buffer, &logging, log_bits, i, -1);
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 0);
    printf("    We should get the second row here\n");
    xxx(&buffer, &logging, log_bits, i, -1);
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 0);
    printf("    We should get the third row here\n");
    xxx(&buffer, &logging, log_bits, i, -1);
    printf("    Done\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("2 - Impose no minimum for the bits per row, different alignment\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 0);
    n = 0;
    memset(buf, 0, sizeof(buf));
    /* The first one in this should be seen as the first EOL */
    memset(buf + 10, 0x55, 10);
    /* EOL 2 */
    buf[25] = 0x20;
    /* EOL 3 */
    memset(buf + 30, 0x55, 10);
    /* EOL 4 */
    buf[45] = 0x10;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (;;)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n, bit);
        n++;
        if (bit == SIG_STATUS_END_OF_DATA)
        {
            if (n != 337)
            {
                printf("Tests failed\n");
                exit(2);
            }
            break;
        }
        if (n >= 18  &&  n <= 96)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n >= 178  &&  n <= 256)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n == 139  ||  n == 300)
        {
            if (bit != 1)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else
        {
            if (bit != 0)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
    }
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("3 - Demand a fairly high minimum for the bits per row\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 400);
    n = 0;
    memset(buf, 0, sizeof(buf));
    /* The first one in this should be seen as the first EOL */
    memset(buf + 10, 0x55, 10);
    /* EOL 2 */
    buf[25] = 0x08;
    /* EOL 3 */
    memset(buf + 30, 0x55, 10);
    /* EOL 4 */
    buf[45] = 0x04;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (;;)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n, bit);
        n++;
        if (bit == SIG_STATUS_END_OF_DATA)
        {
            if (n != 1273)
            {
                printf("Tests failed\n");
                exit(2);
            }
            break;
        }
        if (n >= 18  &&  n <= 96)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n >= 834  &&  n <= 912)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n == 429  ||  n == 1238)
        {
            if (bit != 1)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else
        {
            if (bit != 0)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
    }
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("4 - Take some time to get to the first row of the image, output ahead\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 400);
    n = 0;
    /* Get some initial bits from an empty buffer. These should be ones */
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones OK\n");
    /* Now put some zeros into the buffer, but no EOL. We should continue
       getting ones out. */
    memset(buf, 0, sizeof(buf));
    t38_non_ecm_buffer_inject(&buffer, buf, 20);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Continuing initial ones OK\n");
    /* Now add a one, to make an EOL. We should see the zeros come out. */
    buf[0] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 1);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 0)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    First EOL caused zeros to output OK\n");
    /* Now add another line. We should see the first line come out. This means just the
       23rd bit from now will be a one. */
    buf[0] = 0x00;
    buf[4] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 5);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if ((i == 23  &&  bit == 0)  ||  (i != 23  &&  bit != 0))
        {
            printf("Tests failed (%d)\n", i);
            exit(2);
        }
    }
    printf("    Second EOL caused the first row to output OK\n");
    /* Now inject an RTC - 6 EOLs */
    memset(buf, 0, sizeof(buf));
    /* T.4 1D style */
    for (i = 10;  i < 19;  i += 3)
    {
        buf[i] = 0x00;
        buf[i + 1] = 0x10;
        buf[i + 2] = 0x01;
    }
    /* T.4 2D style */
    buf[25 + 0] = 0x00;
    buf[25 + 1] = 0x18;
    buf[25 + 2] = 0x00;
    buf[25 + 3] = 0xC0;
    buf[25 + 4] = 0x06;
    buf[25 + 5] = 0x00;
    buf[25 + 6] = 0x30;
    buf[25 + 7] = 0x01;
    buf[25 + 8] = 0x80;
    buf[25 + 9] = 0x0C;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (i == 7
            ||
            i == 400 + 11 + 0*12
            ||
            i == 400 + 11 + 1*12
            ||
            i == 400 + 11 + 2*12
            ||
            i == 400 + 11 + 3*12
            ||
            i == 400 + 11 + 4*12
            ||
            i == 400 + 11 + 5*12
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13 + 1)
        {
            if (bit == 0)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
        else
        {
            if (bit == 1)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
    }
    printf("    RTC output OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("5 - Take some time to get to the first row of the image, output behind\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 400);
    n = 0;
    /* Inject some ones. */
    memset(buf, 0xFF, 100);
    t38_non_ecm_buffer_inject(&buffer, buf, 100);
    /* Inject some zeros */
    memset(buf, 0, sizeof(buf));
    t38_non_ecm_buffer_inject(&buffer, buf, 100);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones OK\n");
    /* Now add a one, to make an EOL. We should see the zeros come out. */
    buf[0] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 1);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 0)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    First EOL caused zeros to output OK\n");
    /* Now add another line. We should see the first line come out. This means just the
       23rd bit from now will be a one. */
    buf[0] = 0x00;
    buf[4] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 5);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if ((i == 23  &&  bit == 0)  ||  (i != 23  &&  bit != 0))
        {
            printf("Tests failed (%d)\n", i);
            exit(2);
        }
    }
    printf("    Second EOL caused the first row to output OK\n");
    /* Now inject an RTC - 6 EOLs */
    memset(buf, 0, sizeof(buf));
    /* T.4 1D style */
    for (i = 10;  i < 19;  i += 3)
    {
        buf[i] = 0x00;
        buf[i + 1] = 0x10;
        buf[i + 2] = 0x01;
    }
    /* T.4 2D style */
    buf[25 + 0] = 0x00;
    buf[25 + 1] = 0x18;
    buf[25 + 2] = 0x00;
    buf[25 + 3] = 0xC0;
    buf[25 + 4] = 0x06;
    buf[25 + 5] = 0x00;
    buf[25 + 6] = 0x30;
    buf[25 + 7] = 0x01;
    buf[25 + 8] = 0x80;
    buf[25 + 9] = 0x0C;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (i == 7
            ||
            i == 400 + 11 + 0*12
            ||
            i == 400 + 11 + 1*12
            ||
            i == 400 + 11 + 2*12
            ||
            i == 400 + 11 + 3*12
            ||
            i == 400 + 11 + 4*12
            ||
            i == 400 + 11 + 5*12
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13 + 1)
        {
            if (bit == 0)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
        else
        {
            if (bit == 1)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
    }
    printf("    RTC output OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("6 - TCF without leading ones\n");
    t38_non_ecm_buffer_init(&buffer, FALSE, 400);
    n = 0;
    /* Get some initial bits from an empty buffer. These should be ones */
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones from an empty TCF buffer OK\n");
    /* Now send some TCF through, and see that it comes out */
    memset(buf, 0x00, sizeof(buf));
    t38_non_ecm_buffer_inject(&buffer, buf, 500);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 500*8;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 0)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Passthrough of TCF OK\n");
    /* Check the right number of bits was buffered */
    bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
    if (log_bits)
        printf("Rx bit %d - %d\n", n++, bit);
    if (bit != SIG_STATUS_END_OF_DATA)
    {
        printf("Tests failed\n");
        exit(2);
    }
    printf("    End of data seen OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("7 - TCF with leading ones\n");
    t38_non_ecm_buffer_init(&buffer, FALSE, 400);
    n = 0;
    /* Get some initial bits from an empty buffer. These should be ones */
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones from an empty TCF buffer OK\n");
    
    /* Now send some initial ones, and see that we continue to get all ones
       as the stuffing. */
    memset(buf, 0xFF, 500);
    t38_non_ecm_buffer_inject(&buffer, buf, 500);
    for (i = 0;  i < 500*8;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Sustaining ones OK\n");

    /* Now send some initial ones, and some TCF through, and see that only
       the TCF comes out */
    memset(buf, 0x00, sizeof(buf));
    memset(buf, 0xFF, 100);
    /* End the ones mid byte */
    buf[100] = 0xF0;
    t38_non_ecm_buffer_inject(&buffer, buf, 500);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 400*8;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if ((i < 4  &&  bit == 0)  ||  (i >= 4  &&  bit != 0))
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Passthrough of TCF OK\n");
    /* Check the right number of bits was buffered */
    bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
    if (log_bits)
        printf("Rx bit %d - %d\n", n++, bit);
    if (bit != SIG_STATUS_END_OF_DATA)
    {
        printf("Tests failed\n");
        exit(2);
    }
    printf("    End of data seen OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("Tests passed\n");
    return  0;
}
Esempio n. 21
0
File: uri01.c Progetto: DeadZen/qse
static int test_main (int argc, qse_char_t* argv[])
{
	static const qse_wchar_t* wcs[] =
	{
		QSE_WT("http://www.google.com"),
		QSE_WT("http://www.google.com:80"),
		QSE_WT("http://[email protected]:80"),
		QSE_WT("http://*****:*****@www.google.com:80"),
		QSE_WT("http://*****:*****@www.google.com:80/"),
		QSE_WT("http://*****:*****@www.google.com:80/?#"),
		QSE_WT("http://*****:*****@www.google.com:80/abcdef/ghi?kkk=23#fragment"),
		QSE_WT("http://*****:*****@www.google.com:80/abcdef/ghi#fragment#fragment"),
		QSE_WT("http://*****:*****@[email protected]:80/abcdef/ghi#fragment#fragment"),
		QSE_WT("http://@@@@@abc:def@[email protected]:80/abcdef/ghi#fragment#fragment")
	};

	qse_size_t i;
	qse_uri_t uri;

	for (i = 0; i < QSE_COUNTOF(wcs); i++)
	{
		qse_printf (QSE_T("[%ls] => "), wcs[i]);
		if (qse_wcstouri (wcs[i], &uri, 0) <= -1)
		{
			qse_printf (QSE_T("[ERROR]"));
		}
		else
		{
			xxx (uri.scheme.ptr, uri.scheme.len);
			xxx (uri.auth.user.ptr, uri.auth.user.len);
			xxx (uri.auth.pass.ptr, uri.auth.pass.len);
			xxx (uri.host.ptr, uri.host.len);
			xxx (uri.port.ptr, uri.port.len);
			xxx (uri.path.ptr, uri.path.len);
			xxx (uri.query.ptr, uri.query.len);
			xxx (uri.frag.ptr, uri.frag.len);
		}
		qse_printf (QSE_T("\n"));
	}

	qse_printf (QSE_T("================================================\n"));

	for (i = 0; i < QSE_COUNTOF(wcs); i++)
	{
		qse_printf (QSE_T("[%ls] => "), wcs[i]);
		if (qse_wcstouri (wcs[i], &uri, QSE_WCSTOURI_NOQUERY | QSE_WCSTOURI_NOAUTH) <= -1)
		{
			qse_printf (QSE_T("[ERROR]"));
		}
		else
		{
			xxx (uri.scheme.ptr, uri.scheme.len);
			xxx (uri.auth.user.ptr, uri.auth.user.len);
			xxx (uri.auth.pass.ptr, uri.auth.pass.len);
			xxx (uri.host.ptr, uri.host.len);
			xxx (uri.port.ptr, uri.port.len);
			xxx (uri.path.ptr, uri.path.len);
			xxx (uri.query.ptr, uri.query.len);
			xxx (uri.frag.ptr, uri.frag.len);
		}
		qse_printf (QSE_T("\n"));
	}

	qse_printf (QSE_T("================================================\n"));

	for (i = 0; i < QSE_COUNTOF(wcs); i++)
	{
		qse_printf (QSE_T("[%ls] => "), wcs[i]);
		if (qse_wcstouri (wcs[i], &uri, QSE_WCSTOURI_NOQUERY | QSE_WCSTOURI_NOAUTH | QSE_WCSTOURI_NOFRAG) <= -1)
		{
			qse_printf (QSE_T("[ERROR]"));
		}
		else
		{
			xxx (uri.scheme.ptr, uri.scheme.len);
			xxx (uri.auth.user.ptr, uri.auth.user.len);
			xxx (uri.auth.pass.ptr, uri.auth.pass.len);
			xxx (uri.host.ptr, uri.host.len);
			xxx (uri.port.ptr, uri.port.len);
			xxx (uri.path.ptr, uri.path.len);
			xxx (uri.query.ptr, uri.query.len);
			xxx (uri.frag.ptr, uri.frag.len);
		}
		qse_printf (QSE_T("\n"));
	}

	qse_printf (QSE_T("================================================\n"));
	return 0;
}
Esempio n. 22
0
void
restore(char *fname)
{
    FILE *fp = { NULL };	/* 未初期化変数の使用の警告除去のため NULL で初期化 */
    struct rogue_time saved_time, mod_time;
    char buf[4];
    char tbuf[40];
    int new_file_id, saved_file_id;

#if !defined( ORIGINAL )
    if (org_dir && *org_dir) {
	chdir(org_dir);
    }
#endif /* ORIGINAL */

    if (((new_file_id = md_get_file_id(fname)) == -1) ||
	((fp = fopen(fname, "rb")) == NULL)) {
#if defined( JAPAN )
	clean_up("ファイルがオープンできませんでした。");
#else /* not JAPAN */
	clean_up("Cannot open file");
#endif /* not JAPAN */
    }
    if (md_link_count(fname) > 1) {
#if defined( JAPAN )
	clean_up("ファイルはリンクされています。");
#else /* not JAPAN */
	clean_up("File has link");
#endif /* not JAPAN */
    }
    (void) xxx(1);
    r_read(fp, (char *) &detect_monster, sizeof(detect_monster));
    r_read(fp, (char *) &cur_level, sizeof(cur_level));
    r_read(fp, (char *) &max_level, sizeof(max_level));
    read_string(hunger_str, fp);

    (void) strcpy(tbuf, login_name);
    read_string(login_name, fp);
    if (strcmp(tbuf, login_name)) {
#if defined( JAPAN )
	clean_up("セーブファイルの持ち主が違います。");
#else /* not JAPAN */
	clean_up("You're not the original player");
#endif /* not JAPAN */
    }

    r_read(fp, (char *) &party_room, sizeof(party_room));
    r_read(fp, (char *) &party_counter, sizeof(party_counter));
    read_pack(&level_monsters, fp, 0);
    read_pack(&level_objects, fp, 0);
    r_read(fp, (char *) &saved_file_id, sizeof(saved_file_id));
    if (new_file_id != saved_file_id) {
#if defined( JAPAN )
	clean_up("これは元のセーブファイルではありません。");
#else /* not JAPAN */
	clean_up("Sorry, saved game is not in the same file");
#endif /* not JAPAN */
    }
    rw_dungeon(fp, 0);
    r_read(fp, (char *) &foods, sizeof(foods));
    r_read(fp, (char *) &rogue, sizeof(fighter));
    read_pack(&rogue.pack, fp, 1);
    rw_id(id_potions, fp, POTIONS, 0);
    rw_id(id_scrolls, fp, SCROLS, 0);
    rw_id(id_wands, fp, WANDS, 0);
    rw_id(id_rings, fp, RINGS, 0);
    r_read(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    r_read(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    r_read(fp, (char *) &cur_room, sizeof(cur_room));
    rw_rooms(fp, 0);
    r_read(fp, (char *) &being_held, sizeof(being_held));
    r_read(fp, (char *) &bear_trap, sizeof(bear_trap));
    r_read(fp, (char *) &halluc, sizeof(halluc));
    r_read(fp, (char *) &blind, sizeof(blind));
    r_read(fp, (char *) &confused, sizeof(confused));
    r_read(fp, (char *) &levitate, sizeof(levitate));
    r_read(fp, (char *) &haste_self, sizeof(haste_self));
    r_read(fp, (char *) &see_invisible, sizeof(see_invisible));
    r_read(fp, (char *) &detect_monster, sizeof(detect_monster));
    r_read(fp, (char *) &wizard, sizeof(wizard));
    r_read(fp, (char *) &score_only, sizeof(score_only));
    r_read(fp, (char *) &m_moves, sizeof(m_moves));
    r_read(fp, (char *) &saved_time, sizeof(saved_time));

    if (fread(buf, sizeof(char), 1, fp) > 0) {
	clear();
#if defined( JAPAN )
	clean_up("ファイル中によけいな文字があります。");
#else /* JAPAN */
	clean_up("Extra characters in file");
#endif /* JAPAN */
    }

    md_gfmt(fname, &mod_time);	/* get file modification time */

    if (has_been_touched(&saved_time, &mod_time)) {
	clear();
#if defined( JAPAN )
	clean_up("ファイルが変更されています。");
#else /* not JAPAN */
	clean_up("Sorry, file has been touched");
#endif /* not JAPAN */
    }
    fclose(fp);
    if ((!wizard) && !md_df(fname)) {
#if defined( JAPAN )
	clean_up("ファイルを消すことができません。");
#else /* not JAPAN */
	clean_up("Cannot delete file");
#endif /* not JAPAN */
    }
    msg_cleared = 0;
    ring_stats(0);

#if !defined( ORIGINAL )
    if (game_dir && *game_dir) {
	chdir(game_dir);
    }
#endif /* not ORIGINAL */
}
Esempio n. 23
0
void
save_game(void)
{
    char fname[64];

#if defined( JAPAN )
    if (!get_input_line("セーブするファイル名は?", save_file, fname,
			"ゲームのセーブを中止しました。", 0, 1)) {
#else /* not JAPAN */
    if (!get_input_line("File name?", save_file, fname,
			"Game not saved", 0, 1)) {
#endif /* not JAPAN */
	return;
    }
    check_message();
    message(fname, 0);
    save_into_file(fname);
}

void
save_into_file(char *sfile)
{
    FILE *fp;
    int file_id;
    char name_buffer[80];
    char *hptr;
    struct rogue_time rt_buf;

#if !defined( ORIGINAL )
    if (org_dir && *org_dir) {
	chdir(org_dir);
    }
#endif /* not ORIGINAL */
    if (sfile[0] == '~') {
	if ((hptr = md_ghome())) {
	    (void) strcpy(name_buffer, hptr);
	    (void) strcat(name_buffer, sfile + 1);
	    sfile = name_buffer;
	}
    }
    if (((fp = fopen(sfile, "wb")) == NULL) ||
	((file_id = md_get_file_id(sfile)) == -1)) {
#if defined( JAPAN )
	message("セーブファイルにアクセスできません。", 0);
#else /* not JAPAN */
	message("Problem accessing the save file", 0);
#endif /* not JAPAN */
	goto err_return;
    }
    md_ignore_signals();
    write_failed = 0;
    (void) xxx(1);
    r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    r_write(fp, (char *) &cur_level, sizeof(cur_level));
    r_write(fp, (char *) &max_level, sizeof(max_level));
    write_string(hunger_str, fp);
    write_string(login_name, fp);
    r_write(fp, (char *) &party_room, sizeof(party_room));
    r_write(fp, (char *) &party_counter, sizeof(party_counter));
    write_pack(&level_monsters, fp);
    write_pack(&level_objects, fp);
    r_write(fp, (char *) &file_id, sizeof(file_id));
    rw_dungeon(fp, 1);
    r_write(fp, (char *) &foods, sizeof(foods));
    r_write(fp, (char *) &rogue, sizeof(fighter));
    write_pack(&rogue.pack, fp);
    rw_id(id_potions, fp, POTIONS, 1);
    rw_id(id_scrolls, fp, SCROLS, 1);
    rw_id(id_wands, fp, WANDS, 1);
    rw_id(id_rings, fp, RINGS, 1);
    r_write(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    r_write(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    r_write(fp, (char *) &cur_room, sizeof(cur_room));
    rw_rooms(fp, 1);
    r_write(fp, (char *) &being_held, sizeof(being_held));
    r_write(fp, (char *) &bear_trap, sizeof(bear_trap));
    r_write(fp, (char *) &halluc, sizeof(halluc));
    r_write(fp, (char *) &blind, sizeof(blind));
    r_write(fp, (char *) &confused, sizeof(confused));
    r_write(fp, (char *) &levitate, sizeof(levitate));
    r_write(fp, (char *) &haste_self, sizeof(haste_self));
    r_write(fp, (char *) &see_invisible, sizeof(see_invisible));
    r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    r_write(fp, (char *) &wizard, sizeof(wizard));
    r_write(fp, (char *) &score_only, sizeof(score_only));
    r_write(fp, (char *) &m_moves, sizeof(m_moves));
    md_gct(&rt_buf);
    rt_buf.second += 10;	/* allow for some processing time */
    r_write(fp, (char *) &rt_buf, sizeof(rt_buf));
    fclose(fp);

    if (write_failed) {
	(void) md_df(sfile);	/* delete file */
    } else {
	clean_up("");
    }

err_return:
    ;
#if !defined( ORIGINAL )
    if (game_dir && *game_dir) {
	chdir(game_dir);
    }
#endif /* not ORIGINAL */
}
Esempio n. 24
0
int main(int argc, char *argv[]) {
    int opt = 0;
    int on = -1, off = -1, status = -1, json = -1;

    //Specifying the expected options
    static struct option long_options[] = {
        {"on",     no_argument, 0, 'o' },
        {"off",    no_argument, 0, 'f' },
        {"status", no_argument, 0, 's' },
        {"json",   no_argument, 0, 'j' },
        {0,                  0, 0,   0 }
    };

    int long_index = 0;
    while ( (opt = getopt_long(argc, argv,"ofsj", long_options, &long_index)) != -1) {
        switch (opt) {
        case 'o' : 
            on = 0;
            break;
        case 'f' : 
            off = 0;
            break;
        case 's' : 
            status = 0; 
            break;
        case 'j' : 
            json = 0;
            break;
        default: print_usage(argv[0]); 
            exit(EXIT_FAILURE);
        }
    }


    if (on == 0) {
        char *cmd = "iplug set on";
        if (json == 0) {
            obj = json_object_new_object();
            json_object_object_add(obj, "cmd", json_object_new_string(cmd));
            xxx(1);
            printf("%s", json_object_to_json_string(obj));
            json_object_put(obj);
        } else {
            printf("%s\n", cmd);
            xxx(0);
        }
        return 0;
    }

    if (off == 0) {
        char *cmd = "iplug set off";
        if (json == 0) {
            obj = json_object_new_object();
            json_object_object_add(obj, "cmd", json_object_new_string(cmd));
            printf("%s", json_object_to_json_string(obj));
            json_object_put(obj);
        } else {
            printf("%s\n", cmd);
        }
        return 0;
    }

    if (status == 0) {
        char *cmd = "iplug get current status";
        if (json == 0) {
            obj = json_object_new_object();
            json_object_object_add(obj, "cmd", json_object_new_string(cmd));
            printf("%s", json_object_to_json_string(obj));
            json_object_put(obj);
        } else {
            printf("%s\n", cmd);
        }
        return 0;
    }

    print_usage(argv[0]);

    return 0;
}
Esempio n. 25
0
int __xeno_user_init (void)
{ xxx(0,0); }
Esempio n. 26
0
int main() {
  bar(12,1);
  xxx(12,1);
}
int main(int argc, char *argv[])
{



uint16_t port;
	
		
 



	if (argc > 1)	
		
		port = atoi(argv[1]);
	else 	
		port = 5000;





	int sock1,sock2,sock3;
	struct sockaddr_in server_addr1,server_addr2,server_addr3;
	int numbytes1,numbytes2,numbytes3;
	struct hostent *host;
	char send_data[4096];

	int datasize = 10;
	

	memset (send_data,89,datasize);
	send_data[datasize]='\0';

	//host= (struct hostent *) gethostbyname((char *)"127.0.0.1");


	if ((sock1 = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
	{
		perror("socket");
		exit(1);
	}

	if ((sock2 = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
		{
			perror("socket");
			exit(1);
		}

	if ((sock3 = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
		{
			perror("socket");
			exit(1);
		}

	

	
	printf("MY DEST PORT BEFORE AND AFTER\n%d, %d",port, htons(port));
	server_addr1.sin_family = AF_INET;
	server_addr1.sin_port = htons(port);

	server_addr2.sin_family = AF_INET;
	server_addr2.sin_port = htons(port);

	server_addr3.sin_family = AF_INET;
	server_addr3.sin_port = htons(port);


	server_addr1.sin_addr.s_addr = xxx(127,0,0,1);
	server_addr2.sin_addr.s_addr = xxx(127,0,0,1);
	server_addr3.sin_addr.s_addr = xxx(127,0,0,1);
//	server_addr.sin_addr.s_addr = xxx(172,31,54,87);

//	server_addr.sin_addr.s_addr = xxx(127,0,0,1);

	server_addr1.sin_addr.s_addr = htonl(server_addr1.sin_addr.s_addr);
	server_addr2.sin_addr.s_addr = htonl(server_addr2.sin_addr.s_addr);
	server_addr3.sin_addr.s_addr = htonl(server_addr3.sin_addr.s_addr);
	//server_addr.sin_addr.s_addr = INADDR_LOOPBACK;
	bzero(&(server_addr1.sin_zero),8);
	bzero(&(server_addr2.sin_zero),8);
	bzero(&(server_addr3.sin_zero),8);


//	  while (1)		{		}


	if ( connect(sock1, (struct sockaddr *)&server_addr1 , sizeof(struct sockaddr)) == -1       )
	{
		perror("socket");
		exit(1);
	}

	if ( connect(sock2, (struct sockaddr *)&server_addr2 , sizeof(struct sockaddr)) == -1)
		{
			perror("socket");
			exit(1);
		}

	if ( connect(sock3, (struct sockaddr *)&server_addr3 , sizeof(struct sockaddr)) == -1)
		{
			perror("socket");
			exit(1);
		}

 
	int i =0 ;
	   while ( i < 100)
	   {
		 sleep (1);	 /** sleep for one second */
		//	usleep (100);	  /** sleep 1000 MicroSecond = 1 Milli-Second */
			
			i = i+1; 

		//    printf("Type Something (q or Q to quit):");
			  // gets(send_data);
			
		/*
			    if ((strcmp(send_data , "q") == 0) || strcmp(send_data , "Q") == 0)
				{

				}
			    else
				{   */
			//	if (i % 100 ==0 )

			      numbytes1= send(sock1, send_data, strlen(send_data) , 0);
			//	 numbytes2= send(sock2, send_data, strlen(send_data) , 0);

			//	 numbytes3= send(sock3, send_data, strlen(send_data) , 0);

				printf("\n %d....packet #  %d ",numbytes1,i);	     	
			//	printf("\n %d....packet #  %d ",numbytes2,i);	     	
			//	printf("\n %d....packet #  %d ",numbytes3,i);	     	
			//	}
			//fflush(stdout);
	   }





}
int main()
{



	int sock;
	struct sockaddr_in server_addr;
	int numbytes;
	struct hostent *host;
	char send_data[4096];

	int datasize = 10;
	

	memset (send_data,89,datasize);
	send_data[datasize]='\0';

	//host= (struct hostent *) gethostbyname((char *)"127.0.0.1");


	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
	{
		perror("socket");
		exit(1);
	}


	int port =5002;
	printf("MY DEST PORT BEFORE AND AFTER\n%d, %d",port, htons(port));
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(port);

//	server_addr.sin_addr.s_addr = xxx(192,168,1,2);
//	server_addr.sin_addr.s_addr = xxx(172,31,54,87);

	server_addr.sin_addr.s_addr = xxx(127,0,0,1);

	server_addr.sin_addr.s_addr = htonl(server_addr.sin_addr.s_addr);


	//server_addr.sin_addr.s_addr = INADDR_LOOPBACK;
	bzero(&(server_addr.sin_zero),8);

//sock = socket(AF_INET, SOCK_DGRAM, 0);
//sock = socket(AF_INET, SOCK_DGRAM, 0);
//sock = socket(AF_INET, SOCK_DGRAM, 0);


/**	  while (1)
*		{
*
*
*		}
*/

 
	int i =0 ;
	   while ( i < 100)
	   {
		 sleep (1);	 /** sleep for one second */
		//	usleep (100);	  /** sleep 1000 MicroSecond = 1 Milli-Second */
			
			i = i+1; 

		//    printf("Type Something (q or Q to quit):");
			  // gets(send_data);
			
		/*
			    if ((strcmp(send_data , "q") == 0) || strcmp(send_data , "Q") == 0)
				{

				}
			    else
				{   */
			//	if (i % 100 ==0 )

			      numbytes= sendto(sock, send_data, strlen(send_data) , 0,
				      (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
				printf("\n %d....packet #  %d ",numbytes,i);	     	
			//	}
			//fflush(stdout);
	   }





}
Esempio n. 29
0
  int http_client::sock_cb(CURL *e, curl_socket_t s, int what, void* per_socket_user_data) {
    if(what == CURL_POLL_REMOVE) {
      call_context* context = NULL;
      curl_easy_getinfo(e, CURLINFO_PRIVATE, &context);
      assert(context);
      if(!context) {
        BOOST_LOG_TRIVIAL(warning) << this << ", " << BOOST_CURRENT_FUNCTION << ", CURL_POLL_REMOVE, socket: " << s << " - no context, skipping";
        return 0;
      }
      
      long http_result = 0;
      CURLcode curl_res = curl_easy_getinfo(e, CURLINFO_RESPONSE_CODE, &http_result);
      if(curl_res == CURLE_OK)
        context->_http_result = (csi::http::status_type) http_result;
      else
        context->_http_result = (csi::http::status_type) 0;

      context->_end_ts = std::chrono::steady_clock::now();
      context->_curl_done = true;
      context->_transport_ok = (http_result > 0);

      BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", CURL_POLL_REMOVE, socket: " << s << ", http : " << to_string(context->_method) << " " << context->uri() << " res = " << http_result << " " << context->milliseconds() << " ms";
      call_context::handle h(context->curl_handle());

      if(context->_callback)
        context->_callback(h);

      context->curl_stop();
      curl_easy_setopt(context->_curl_easy, CURLOPT_PRIVATE, NULL);
      //curl_multi_assign(_multi, s, NULL);
      _io_service.post(boost::bind(&http_client::_poll_remove, this, h));
      return 0;
    }

    boost::asio::ip::tcp::socket* tcp_socket = (boost::asio::ip::tcp::socket*) per_socket_user_data;
    call_context* context = NULL;
    curl_easy_getinfo(e, CURLINFO_PRIVATE, &context);
    assert(context);
    if(!tcp_socket) {
      //we try to find the data in our own mapping
      //if we find it - register this to curl so we dont have to do this every time.
      {
        csi::spinlock::scoped_lock xxx(_spinlock);
        std::map<curl_socket_t, boost::asio::ip::tcp::socket *>::iterator it = _socket_map.find(s);
        if(it != _socket_map.end()) {
          tcp_socket = it->second;
          curl_multi_assign(_multi, s, tcp_socket);
        }
      }

      if(!tcp_socket) {
        BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", socket: " << s << " is a c - ares socket, ignoring";
        return 0;
      }
    }

    switch(what) {
    case CURL_POLL_IN:
    BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", CURL_POLL_IN, socket: " << s;
    tcp_socket->async_read_some(boost::asio::null_buffers(), boost::bind(&http_client::socket_rx_cb, this, boost::asio::placeholders::error, tcp_socket, context->curl_handle()));
    break;
    case CURL_POLL_OUT:
    BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", CURL_POLL_OUT, socket: " << s;
    tcp_socket->async_write_some(boost::asio::null_buffers(), boost::bind(&http_client::socket_tx_cb, this, boost::asio::placeholders::error, tcp_socket, context->curl_handle()));
    break;
    case CURL_POLL_INOUT:
    BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION << ", CURL_POLL_INOUT, socket: " << s;
    tcp_socket->async_read_some(boost::asio::null_buffers(), boost::bind(&http_client::socket_rx_cb, this, boost::asio::placeholders::error, tcp_socket, context->curl_handle()));
    tcp_socket->async_write_some(boost::asio::null_buffers(), boost::bind(&http_client::socket_tx_cb, this, boost::asio::placeholders::error, tcp_socket, context->curl_handle()));
    break;
    case CURL_POLL_REMOVE:
    // should never happen - handled above
    break;
    };
    return 0;
  }
Esempio n. 30
0
int main(int argc, char *argv[])
{

#ifdef HAVE_MPI
  MPI_Init(&argc, &argv);
  // define an Epetra communicator
  Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
  Epetra_SerialComm Comm;
#endif

  // check number of processes
  if (Comm.NumProc() != 1) {
    if (Comm.MyPID() == 0)
      cerr << "*ERR* can be used only with one process" << endl;
#ifdef HAVE_MPI
    MPI_Finalize();
#endif
    exit(EXIT_SUCCESS);
  }

  // process 0 will read an HB matrix, and store it
  // in the MSR format given by the arrays bindx and val
  int N_global;
  int N_nonzeros;
  double * val = NULL;
  int * bindx = NULL;
  double * x = NULL, * b = NULL, * xexact = NULL;

  FILE* fp = fopen("../HBMatrices/fidap005.rua", "r");
  if (fp == 0)
  {
    cerr << "Matrix file not available" << endl;
#ifdef HAVE_MPI
    MPI_Finalize();
#endif
    exit(EXIT_SUCCESS);
  }
  fclose(fp);

  Trilinos_Util_read_hb("../HBMatrices/fidap005.rua", 0,
      &N_global, &N_nonzeros,
      &val, &bindx,
      &x, &b, &xexact);

  // assign all the elements to process 0
  // (this code can run ONLY with one process, extensions to more
  // processes will require functions to handle update of ghost nodes)
  Epetra_Map Map(N_global,0,Comm);

  MSRMatrix A(Map,bindx,val);

  // define two vectors
  Epetra_Vector xxx(Map);
  Epetra_Vector yyy(Map);

  xxx.Random();

  A.Apply(xxx,yyy);

  cout << yyy;

  double norm2;
  yyy.Norm2(&norm2);

  cout << norm2 << endl;

  // free memory allocated by Trilinos_Util_read_hb
  if (val != NULL) free((void*)val);
  if (bindx != NULL) free((void*)bindx);
  if (x != NULL) free((void*)x);
  if (b != NULL) free((void*)b);
  if (xexact != NULL) free((void*)xexact);;

#ifdef HAVE_MPI
  MPI_Finalize();
#endif

  return(EXIT_SUCCESS);

} /* main */