Пример #1
0
Файл: bio.c Проект: vnea/UPMC
/**
 * @fn struct buf *getblk(int dev, bc_daddr_t blkno)
 * Permet de récuperer un buffer en fonction d'un device et d'un numéro de bloc.
 * S'il n'existe pas dans la table de hachage des buffers précédemment alloués, un buffer est
 * retiré de la liste des buffers disponibles et alloué au device et au bloc correspondant
 * 
 * Assign a buffer for the given block. If the appropriate
 * block is already associated, return it; otherwise search
 * for the oldest non-busy buffer and reassign it.
 * @param dev : device (major+minor)
 * @param blkno : numéro de bloc
 * @return le buffer associé au device dev et de numéro de bloc blkno
 */
struct buf *getblk(int dev, bc_daddr_t blkno) {
    struct buf *bp;
    struct buf *dp;

    loop:
    dp = bhash(dev, blkno);

    // Error
    if (dp == NULL) {
    }

    for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) {
        if (bp->b_blkno != blkno || bp->b_dev != dev) {
            continue;
        }
        spl(BDINHB);
        if (bp->b_flags & B_BUSY) {
            bp->b_flags |= B_WANTED;
            tsleep(PRIBIO + 1, (caddr_t) bp);
            goto loop;
        }
        spl(NORMAL);
        notavail(bp);
        return bp;
    }

    spl(BDINHB);
    if (bfreelist.av_forw == &bfreelist) {
        bfreelist.b_flags |= B_WANTED;
        tsleep(PRIBIO + 1, (caddr_t) &bfreelist);
        goto loop;
    }
    spl(NORMAL);
    bp = bfreelist.av_forw;
    notavail(bp);

    if (bp->b_flags & B_DELWRI) {
        bp->b_flags |= B_ASYNC;
        bwrite(bp);
        goto loop;
    }

    bp->b_flags = B_BUSY;
    bp->b_back->b_forw = bp->b_forw;
    bp->b_forw->b_back = bp->b_back;
    bp->b_forw = dp->b_forw;
    bp->b_back = dp;
    dp->b_forw->b_back = bp;
    dp->b_forw = bp;
    bp->b_dev = dev;
    bp->b_blkno = blkno;

    return bp; 
}
Пример #2
0
LONG32 SnarlInterface::Notify(LPCSTR classId, LPCSTR title, LPCSTR text, LONG32 timeout, LPCSTR iconPath, LPCSTR iconBase64, SnarlEnums::MessagePriority priority, LPCSTR uid, LPCSTR callback, LPCSTR value)
{
    // notify?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>]
    //        [&title=<title>][&text=<text>][&timeout=<timeout>][&icon=<icon path>][&icon-base64=<MIME data>][&callback=<default callback>]
    //        [&priority=<priority>][&uid=<notification uid>][&value=<value>]

    SnarlParameterList<char> spl(12);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);
    
    spl.Add("id", classId);
    spl.Add("title", title);
    spl.Add("text", text);
    spl.Add("icon", iconPath);
    spl.Add("icon-base64", iconBase64);
    spl.Add("uid", uid);
    spl.Add("callback", callback);
    spl.Add("value", value);
    if (timeout != -1)  spl.Add("timeout", timeout);
    if (priority != SnarlEnums::PriorityUndefined) spl.Add("priority", priority); // -1 is a legal priority

    LONG32 request = DoRequest(Requests::NotifyA(), spl);
    lastMsgToken = (request > 0) ? request : 0;

    return request;
}
Пример #3
0
int main(int argc, char* argv[])
#endif
{
	FSUNUSED(argc);
	FSUNUSED(argv);

	try {
		vabamorf::speller spl(FSTSTR("et.dct"));

		for (size_t i = 0; words[i]; i++) {
			std::wcout << words[i] << L" -- ";
			if (spl.spell(words[i])) {
				std::wcout << L"OK\n";
			} else {
				std::wcout << L"Vigane, soovitan:";
				std::vector<std::wstring> suggs = spl.suggest(words[i]);
				for (size_t j = 0; j < suggs.size(); j++) {
					std::wcout << L" " << suggs[j];
				}
				std::wcout << L"\n";
			}
		}

	} catch (const vabamorf::exception &) {
		std::wcerr << L"Viga!\n";
	}
	return 0;
}
Пример #4
0
Foam::pointField Foam::polySplineEdge::intervening
(
    const pointField& otherknots,
    const label nbetweenKnots,
    const vector& fstend,
    const vector& sndend
)
{
    BSpline spl(knotlist(points_, start_, end_, otherknots), fstend, sndend);

    label nSize(nsize(otherknots.size(), nbetweenKnots));

    pointField ans(nSize);

    label N = spl.nKnots();
    scalar init = 1.0/(N - 1);
    scalar interval = (N - scalar(3))/N;
    interval /= otherknots.size() + 1;
    interval /= nbetweenKnots + 1;

    ans[0] = points_[start_];

    register scalar index(init);
    for (register label i=1; i<nSize-1; i++)
    {
        index += interval;
        ans[i] = spl.realPosition(index);
    }

    ans[nSize-1] = points_[end_];

    return ans;
}
Пример #5
0
//----------------------------------------------------------------------------------------------------------------------
// methode : pour debug
void Tracer::printBufferCmd(){
    dsp(F("Contenu du buffer de commandes :")); dspl( _nbrCommandes );
    for (int i = 0; i< _nbrCommandes; i++){
        sp( F("cmd : ") );sp( _bufferCommandes[i][0] );
        sp( F(", ") );spl(_bufferCommandes[i][1]);
    }
}
Пример #6
0
std::vector<std::string>
Base::getVarname( std::string &s)
{
  // There might be a varname specification or not.
  // no varname found: return true

  std::vector<std::string> names;
  std::string list;

  std::vector<std::string> tokens;
  tokens.push_back( ":v=" ) ;
  tokens.push_back( ":varname=" ) ;
  tokens.push_back( ":vname=" ) ;
  tokens.push_back( ":variable" ) ;

  bool isEmpty=true;
  size_t pos0=0;
  for( size_t i=0 ; i < tokens.size() ; ++i )
  {
    if( (pos0 = s.find( tokens[i] ) ) < std::string::npos )
      // e.g.: s: "...:vname=...:..." and tokens: ":vname=..."
      isEmpty=false;
    else if( s.substr(0,tokens[i].size()-1) == tokens[i].substr(1) )
      // e.g.: s: "vname=..." and tokens: "vname=..."
      isEmpty=false;
  }

  if( isEmpty )
    return names;

  // the assignment sign
  size_t pos1=s.find("=",pos0);
  if( pos1 == std::string::npos )
  {
     std::ostringstream ostr(std::ios::app);
     ostr << "Base::getVarname(): invalid assignment";

     exceptionError( ostr.str() );
     std::string note("E8: no rules for finding a variable name.");
     finally(8, note);
  }
  else
    ++pos1 ;

  // the end of the assignment
  size_t pos2=s.find(":",pos1);
  if( pos2 == std::string::npos )
     // the end of the string
     pos2=s.size();

  list=s.substr(pos1, pos2-pos1);

  // expand the list
  Split spl(list, ",");
  for( size_t i=0 ; i < spl.size() ; ++i)
      names.push_back( spl[i] ) ;

  return names;
}
Пример #7
0
Файл: bio.c Проект: vnea/UPMC
/**
 * @fn void notavail(struct buf *bp)
#include <callo.h> 
#include <sched.h> 

* Retire un buffer de la liste des buffers disponible et le marque à BUSY.
 * 
 * Unlink a buffer from the available list and mark it busy.
 * (internal interface)
 * @param bp : pointeur vers un buffer
 */
void notavail(struct buf *bp) {
  int s;
  s=splbio ();
  bp->av_back->av_forw = bp->av_forw;
  bp->av_forw->av_back = bp->av_back;
  bp->b_flags |= B_BUSY;
  spl(s);
}
Пример #8
0
LONG32 SnarlInterface::ClearClasses()
{
    // clearclasses?[token=app-sig=<signature>|token=<application token>][&password=<password>]

    SnarlParameterList<char> spl(2);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);

    return DoRequest(Requests::ClearClassesA(), spl);
}
Пример #9
0
LONG32 SnarlInterface::RemoveClass(LPCWSTR classId)
{
    SnarlParameterList<wchar_t> spl(3);
    spl.Add(L"token", appToken);
    spl.Add(L"password", szPasswordW);
    
    spl.Add(L"id", classId);

    return DoRequest(Requests::RemoveClassW(), spl);
}
Пример #10
0
LONG32 SnarlInterface::IsVisible(LONG32 msgToken)
{
    // isvisible?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>]

    SnarlParameterList<char> spl(2);
    spl.Add("token", msgToken);
    spl.Add("password", szPasswordA);

    return DoRequest(Requests::IsVisibleA(), spl);
}
Пример #11
0
//---------------------------------------------------------------------------------------------------------------------
qreal VSplinePath::GetLength() const
{
    qreal length = 0;
    for (qint32 i = 1; i <= Count(); ++i)
    {
        VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(), path.at(i-1).KAsm2(),
                path.at(i).KAsm1(), kCurve);
        length += spl.GetLength();
    }
    return length;
}
Пример #12
0
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VSplinePath::GetPoints() const
{
    QVector<QPointF> pathPoints;
    for (qint32 i = 1; i <= Count(); ++i)
    {
        VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(),
                path.at(i-1).KAsm2(), path.at(i).KAsm1(), this->kCurve);
        pathPoints += spl.GetPoints();
    }
    return pathPoints;
}
Пример #13
0
LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd)
{
    SnarlParameterList<wchar_t> spl(4);
    spl.Add(L"token", msgToken);
    spl.Add(L"password", szPasswordW);
    
    spl.Add(L"label", label);
    spl.Add(L"cmd", cmd);

    return DoRequest(Requests::AddActionW(), spl);
}
Пример #14
0
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VSplinePath::GetPath() const
{
    QPainterPath painterPath;
    for (qint32 i = 1; i <= Count(); ++i)
    {
        VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(),
                path.at(i-1).KAsm2(), path.at(i).KAsm1(), this->kCurve);
        painterPath.addPath(spl.GetPath());
    }
    return painterPath;
}
Пример #15
0
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VSplinePath::GetPath(PathDirection direction) const
{
    QPainterPath painterPath;
    for (qint32 i = 1; i <= Count(); ++i)
    {
        VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(),
                    d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve);
        painterPath.addPath(spl.GetPath(direction));
    }
    return painterPath;
}
Пример #16
0
LONG32 SnarlInterface::Unregister(LPCWSTR signature)
{
    SnarlParameterList<wchar_t> spl(2);
    spl.Add(L"app-sig", signature);
    spl.Add(L"password", szPasswordW);

    appToken = 0;
    lastMsgToken = 0;
    ClearPassword();

    return DoRequest(Requests::UnregisterW(), spl);
}
Пример #17
0
LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd)
{
    // addaction?[token=<notification token>|app-sig=<signature>&uid=<uid>][&password=<password>]&label=<label>&cmd=<command>

    SnarlParameterList<char> spl(4);
    spl.Add("token", msgToken);
    spl.Add("password", szPasswordA);
    
    spl.Add("label", label);
    spl.Add("cmd", cmd);

    return DoRequest(Requests::AddActionA(), spl);
}
Пример #18
0
LONG32 SnarlInterface::RemoveClass(LPCSTR classId)
{
    // remclass?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>|&all=<0|1>]

    SnarlParameterList<char> spl(3);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);
    
    spl.Add("id", classId);
    // instead of all, use ClearClasses

    return DoRequest(Requests::RemoveClassA(), spl);
}
Пример #19
0
int main()
{
    const int train_sample_count = 300;

//#define LEPIOTA
#ifdef LEPIOTA
    const char* filename = "../../../OpenCV_SVN/samples/c/agaricus-lepiota.data";
#else
    const char* filename = "../../../OpenCV_SVN/samples/c/waveform.data";
#endif

    CvDTree dtree;
    CvBoost boost;
    CvRTrees rtrees;
    CvERTrees ertrees;

    CvMLData data;

    CvTrainTestSplit spl( train_sample_count );
    
    data.read_csv( filename );

#ifdef LEPIOTA
    data.set_response_idx( 0 );     
#else
    data.set_response_idx( 21 );     
    data.change_var_type( 21, CV_VAR_CATEGORICAL );
#endif

    data.set_train_test_split( &spl );
    
    printf("======DTREE=====\n");
    dtree.train( &data, CvDTreeParams( 10, 2, 0, false, 16, 0, false, false, 0 ));
    print_result( dtree.calc_error( &data, CV_TRAIN_ERROR), dtree.calc_error( &data ), dtree.get_var_importance() );

#ifdef LEPIOTA
    printf("======BOOST=====\n");
    boost.train( &data, CvBoostParams(CvBoost::DISCRETE, 100, 0.95, 2, false, 0));
    print_result( boost.calc_error( &data, CV_TRAIN_ERROR ), boost.calc_error( &data ), 0 );
#endif

    printf("======RTREES=====\n");
    rtrees.train( &data, CvRTParams( 10, 2, 0, false, 16, 0, true, 0, 100, 0, CV_TERMCRIT_ITER ));
    print_result( rtrees.calc_error( &data, CV_TRAIN_ERROR), rtrees.calc_error( &data ), rtrees.get_var_importance() );

    printf("======ERTREES=====\n");
    ertrees.train( &data, CvRTParams( 10, 2, 0, false, 16, 0, true, 0, 100, 0, CV_TERMCRIT_ITER ));
    print_result( ertrees.calc_error( &data, CV_TRAIN_ERROR), ertrees.calc_error( &data ), ertrees.get_var_importance() );

    return 0;
}
Пример #20
0
//---------------------------------------------------------------------------------------------------------------------
VSpline VSplinePath::GetSpline(qint32 index) const
{
    if (Count()<1)
    {
        throw VException(tr("Not enough points to create the spline."));
    }
    if (index < 1 || index > Count())
    {
        throw VException(tr("This spline does not exist."));
    }
    VSpline spl(path.at(index-1).P(), path.at(index).P(), path.at(index-1).Angle2(), path.at(index).Angle1(),
            path.at(index-1).KAsm2(), path.at(index).KAsm1(), this->kCurve);
    return spl;
}
Пример #21
0
LONG32 SnarlInterface::Unregister(LPCSTR signature)
{
    // unregister?[app-sig=<signature>|token=<application token>][&password=<password>]

    SnarlParameterList<char> spl(2);
    spl.Add("app-sig", signature);
    spl.Add("password", szPasswordA);

    appToken = 0;
    lastMsgToken = 0;
    ClearPassword();

    return DoRequest(Requests::UnregisterA(), spl);
}
Пример #22
0
Файл: bio.c Проект: vnea/UPMC
/**
 * @fn void brelse(struct buf *bp)
 * Libere le buffer sans générer de E/S.
 *
 * Release the buffer, with no I/O implied.
 * @param bp : pointeur vers un buffer
 */
void brelse(struct buf *bp) {
    struct buf **backp;
    int flags; int s;
    
    if (bp->b_flags & B_WANTED) {
        twakeup((caddr_t) bp);
    }

    if (bfreelist.b_flags & B_WANTED) {
        twakeup(&bfreelist);
        bfreelist.b_flags &= ~B_WANTED;
    }
    
    s = splbio();
    spl(BDINHB);
    backp = &bfreelist.av_forw;
    (*backp)->av_forw = bp;
    bp->av_back = *backp;
    *backp = bp;
    bp->av_forw = &bfreelist;
    bp->b_flags &=~ (B_WANTED | B_BUSY | B_ASYNC);
    bfreelist.b_count++;
    spl(s);
}
Пример #23
0
int main()
{
  try
  {
	Game_screen spl(Point (100,100),800,600,"Flap God");
    
    return gui_main();
  }
  catch(exception& e)
  {
  	cerr << "error: " << e.what() << endl;
  }
  catch(...)
  {
  	cerr << "unknown error." << endl;
  }
}
Пример #24
0
LONG32 SnarlInterface::AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title, LPCWSTR text, LPCWSTR icon, LPCWSTR sound, LONG32 duration, LPCWSTR callback, bool enabled)
{
    SnarlParameterList<wchar_t> spl(11);
    spl.Add(L"token", appToken);
    spl.Add(L"password", szPasswordW);
    
    spl.Add(L"id", classId);
    spl.Add(L"name", name);
    spl.Add(L"enabled", enabled);
    spl.Add(L"callback", callback);
    spl.Add(L"title", title);
    spl.Add(L"text", text);
    spl.Add(L"icon", icon);
    spl.Add(L"sound", sound);
    if (duration != -1)	spl.Add(L"duration", duration);

    return DoRequest(Requests::AddClassW(), spl);
}
Пример #25
0
std::vector<std::string>
Base::getVarname( std::string &s, std::vector<std::string> &alias)
{
  // There might be a varname specification or not.
  // no varname found: return true
  // The reference 'alias' is special for operations,
  // e.g. v=x=var1,y=var2,... . If given, then var1 is the
  // variable returned via the vector and x,y,... are members
  // stored in alias.

  std::vector<std::string> list;
  std::vector<std::string> names;

  list = getVarname( s ) ;

  // expand the list
  for( size_t i=0 ; i < list.size() ; ++i)
  {
    Split spl(list[i], "=");

    if( spl.size() == 2 )
    {
      alias.push_back( spl[0] ) ;
      names.push_back( spl[1] ) ;
    }
    else if( spl.size() == 1 )
    {
      alias.push_back( "" ) ;
      names.push_back( spl[0] ) ;
    }
    else
    {
      std::ostringstream ostr(std::ios::app);
      ostr << "Base::getVarname(): invalid assignment\n";
      ostr << " of variable names." ;

      exceptionError( ostr.str() );
      std::string note("E9: invalid assignment of variable names.");
      finally(9, note);
    }
  }

  return names;
}
Пример #26
0
LONG32 SnarlInterface::Update(LONG32 msgToken, LPCWSTR classId, LPCWSTR title, LPCWSTR text, LONG32 timeout, LPCWSTR iconPath, LPCWSTR iconBase64, SnarlEnums::MessagePriority priority, LPCWSTR callback, LPCWSTR value)
{
    // Made from best guess - no documentation available yet
    SnarlParameterList<wchar_t> spl(11);
    spl.Add(L"token", msgToken);
    spl.Add(L"password", szPasswordW);

    spl.Add(L"id", classId);
    spl.Add(L"title", title);
    spl.Add(L"text", text);
    spl.Add(L"icon", iconPath);
    spl.Add(L"icon-base64", iconBase64);
    spl.Add(L"callback", callback);
    spl.Add(L"value", value);
    if (timeout != -1)  spl.Add(L"timeout", timeout);
    if (priority != SnarlEnums::PriorityUndefined) spl.Add(L"priority", priority); // -1 is a legal priority

    return DoRequest(Requests::UpdateW(), spl);
}
Пример #27
0
int CV_MLBaseTest::prepare_test_case( int test_case_idx )
{
    int trainSampleCount, respIdx;
    string varTypes;
    clear();

    string dataPath = ts->get_data_path();
    if ( dataPath.empty() )
    {
        ts->printf( CvTS::LOG, "data path is empty" );
        return CvTS::FAIL_INVALID_TEST_DATA;
    }

    string dataName = dataSetNames[test_case_idx],
        filename = dataPath + dataName + ".data";
    if ( data.read_csv( filename.c_str() ) != 0)
    {
        char msg[100];
        sprintf( msg, "file %s can not be read", filename.c_str() );
        ts->printf( CvTS::LOG, msg );
        return CvTS::FAIL_INVALID_TEST_DATA;
    }

    FileNode dataParamsNode = validationFS.getFirstTopLevelNode()["validation"][modelName][dataName]["data_params"];
    CV_DbgAssert( !dataParamsNode.empty() );

    CV_DbgAssert( !dataParamsNode["LS"].empty() );
    dataParamsNode["LS"] >> trainSampleCount;
    CvTrainTestSplit spl( trainSampleCount );
    data.set_train_test_split( &spl );

    CV_DbgAssert( !dataParamsNode["resp_idx"].empty() );
    dataParamsNode["resp_idx"] >> respIdx;
    data.set_response_idx( respIdx );

    CV_DbgAssert( !dataParamsNode["types"].empty() );
    dataParamsNode["types"] >> varTypes;
    data.set_var_types( varTypes.c_str() );

    return CvTS::OK;
}
Пример #28
0
LONG32 SnarlInterface::AddClass(LPCSTR classId, LPCSTR name, LPCSTR title, LPCSTR text, LPCSTR icon, LPCSTR sound, LONG32 duration, LPCSTR callback, bool enabled)
{
    // addclass?[app-sig=<signature>|token=<application token>][&password=<password>]&id=<class identifier>&name=<class name>[&enabled=<0|1>][&callback=<callback>]
    //          [&title=<title>][&text=<text>][&icon=<icon>][&sound=<sound>][&duration=<duration>]

    SnarlParameterList<char> spl(11);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);

    spl.Add("id", classId);
    spl.Add("name", name);
    spl.Add("enabled", enabled);
    spl.Add("callback", callback);
    spl.Add("title", title);
    spl.Add("text", text);
    spl.Add("icon", icon);
    spl.Add("sound", sound);
    if (duration != -1) spl.Add("duration", duration);

    return DoRequest(Requests::AddClassA(), spl);
}
Пример #29
0
UINT AviReader::run() {
  try {
    CAviFile aviFile(m_inFileName, false);
    FileNameSplitter spl(m_inFileName);
    const String dir = spl.getDrive() + spl.getDir();
    m_maxIndex = aviFile.getStreamInfo(). dwLength;
    HBITMAP bitmap;
    while((bitmap = aviFile.readFrame()) != NULL) {
      m_index++;
      if(isInterrupted()) {
        throwException(_T("Interrupted by user"));
      }
      const String fileName = FileNameSplitter::getChildName(dir, format(_T("out%05d.jpg"), m_index));
      writeAsJPG(bitmap, ByteOutputFile(fileName));
    }
  } catch(Exception e) {
    m_ok = false;
    m_msg = e.what();
  }
  return 0;
}
Пример #30
0
LONG32 SnarlInterface::Register(LPCWSTR signature, LPCWSTR name, LPCWSTR icon, LPCWSTR password, HWND hWndReplyTo, LONG32 msgReply, SnarlEnums::AppFlags flags)
{
    SnarlParameterList<wchar_t> spl(7);
    spl.Add(L"app-sig", signature);
    spl.Add(L"title", name);
    spl.Add(L"icon", icon);
    spl.Add(L"password", password);
    spl.Add(L"reply-to", hWndReplyTo);
    spl.Add(L"reply", msgReply);
    spl.Add(L"flags", flags);

    // If password was given, save and use in all other functions requiring password
    if (password != NULL && wcslen(password) > 0)
        SetPassword(password);

    LONG32 request = DoRequest(Requests::RegisterW(), spl);
    if (request > 0)
        appToken = request;

    return request;
}