Пример #1
0
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
static void cptinit (bool needContent)
{
  if (LCtxt == NULL) {
    if ((LCtxt = tmDesc(CLIPFILNAM, false)) == NULL) exc(E_CPFER);
    if (needContent) tmLoad(LCtxt);
    else   LCtxt->txstat |= TS_NEW;
           LCtxt->txstat |= (TS_FILE|TS_PERM);
} }
Пример #2
0
void audio_output::unpause()
{
    alSourcePlay(_source);
    if (alGetError() != AL_NO_ERROR)
    {
        throw exc(_("Cannot unpause OpenAL source playback."));
    }
}
Пример #3
0
void lequit()
{
    switch (KbCode) {
    case TE_SDOWN:
        LenterARGcomplete(TE_CR);
        exc(E_LEXIT);
    case TE_SUP:
        LenterARGcomplete(TE_RCR);
        exc(E_LEXIT);
    case TE_NPAGE:
    case TK_BREAK:
        LenterARGcomplete(0);
        exc(E_LEXIT);
    default:
        exc(E_NOCOM);
    }
}
Пример #4
0
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
static void laToggle (int option)
{
    if (leARGmode && (leOptFlags & option)) {
        laSetOption(option);
        redrawLwnd();
    }
    else exc(E_ATTR);
}
Пример #5
0
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
void LenterARG(tchar *buf, int *bufLen, /* buffer for argument & its length  */
               int promLen, /* len of prompt (in buffer already) */
               tchar **history, int *kbcode, /* place for history and return code */
               int do_on_CR,  int do_on_RCR, /* commands to execute on CR and RCR */
               int opt_flag)  /* allowed options (st/wc/re//ic/cs) */
{
    if (Atxt == NIL) {
        Atxt = TxNew(TRUE);
        Atxt->txstat |= TS_PERM+TS_PSEUDO;
    }
    TxEmpt(Ltxt = Atxt);
    Lwnd    = Twnd;
    Ly = Ty;
    leResARG    = buf;
    Lredit  = TRUE;
    Lxlm = Lxle = Lx = promLen;
    leResARGlen = bufLen;
    Lchange = FALSE;
    Lxrm = Lxre = MAXTXRM;
    leKBCode[0] = do_on_CR;
    leARGmode =  1;
    leKBCode[1] = do_on_RCR;
    leHistory = history;
    leRetCode   = kbcode;
    if (BlockMark) {
        if (BlockTy == Ty) {
            int len = Block1move(buf+promLen, MAXLPAC-promLen);
            *bufLen = Lx =       len+promLen;
            leARGmode++;
        }
        scblkoff();                                          // ^
    }                                                      // block selected =>
    Lleng = *bufLen;
    blktmov (buf,  Lebuf,         Lleng); //  copy the contents
    blktspac(Lebuf+Lleng, MAXLPAC-Lleng); // (only when 1-line)
    if (opt_flag) {                                        //  + always unselect
        switch (Lebuf[1] & AT_CHAR) {
        case 's':
            leOptMode = LeARG_STANDARD;
            break;
        case 'r':
            leOptMode = LeARG_REGEXP;
            break;
        case 'w':
            leOptMode = LeARG_WILDCARD;
            break;
        }
        leOptFlags = opt_flag;
        laSetOption(leOptMode);
        if ((Lebuf[4] & AT_CHAR) == 'i') laSetOption(LeARG_IGNORECASE);
    }
    else {
        leOptFlags = 0;
        leOptMode = LeARG_STANDARD;
    }
    redrawLwnd();
    exc(E_LENTER);
}
Пример #6
0
void video_output_qt::create_widget()
{
    _widget = new video_output_qt_widget(this, _format, _container_widget);
    if (!_widget->context()->isValid())
    {
        QMessageBox::critical(_widget, _("Error"), _("Cannot get valid OpenGL context."));
        std::exit(1);
    }
    if ((_format.doubleBuffer() && !_widget->format().doubleBuffer())
            || (_format.stereo() && !_widget->format().stereo()))
    {
        try
        {
            if (_format.stereo())
            {
                // Common failure: display does not support quad buffered stereo
                throw exc(_("The display does not support OpenGL stereo mode."));
            }
            else
            {
                // Should never happen
                throw exc(_("Cannot set OpenGL context format."));
            }
        }
        catch (std::exception &e)
        {
            QMessageBox::critical(_widget, _("Error"), e.what());
            std::exit(1);
        }
    }
    msg::dbg("OpenGL framebuffer: %d:%d:%d bits for R:G:B",
            _widget->format().redBufferSize(),
            _widget->format().greenBufferSize(),
            _widget->format().blueBufferSize());
    QGridLayout *container_layout = new QGridLayout();
    container_layout->addWidget(_widget, 0, 0);
    container_layout->setContentsMargins(0, 0, 0, 0);
    container_layout->setRowStretch(0, 1);
    container_layout->setColumnStretch(0, 1);
    delete _container_widget->layout();
    _container_widget->setLayout(container_layout);
    if (!_container_is_external)
        _container_widget->show();
    process_events();
}
Пример #7
0
 CommandOptionDependent::CommandOptionDependent(
    const CommandOption* parent,
    const CommandOption* child)
       : CommandOption(noArgument, metaType, 0, "", "")
 {
    if (NULL == parent)
    {
       InvalidParameter  exc("Invalid parent address");
       GPSTK_THROW(exc);
    }
    if (NULL == child)
    {
       InvalidParameter  exc("Invalid child address");
       GPSTK_THROW(exc);
    }
    requiree = parent;
    requirer = child;
 }
    /// Check to make sure headerList is empty
    /// @throw InvalidRequest if headerList is empty
 inline void chl(const std::string& req) throw(gpstk::InvalidRequest)
 {
    gpstk::InvalidRequest exc("Header list is empty attempting to"
                               " satisfy "+req+" request.");
    if (headerList.empty())
    {
       GPSTK_THROW(exc);
    }
 }
Пример #9
0
mutex::mutex(const mutex&) : _mutex(_mutex_initializer)
{
    // You cannot have multiple copies of the same mutex.
    // Instead, we create a new one. This allows easier use of mutexes in STL containers.
    int e = pthread_mutex_init(&_mutex, NULL);
    if (e != 0)
        throw exc(std::string(_("System function failed: "))
                + "pthread_mutex_init(): " + std::strerror(e), e);
}
Пример #10
0
condition::condition(const condition&) : _cond(_cond_initializer)
{
    // You cannot have multiple copies of the same condition.
    // Instead, we create a new one. This allows easier use of conditions in STL containers.
    int e = pthread_cond_init(&_cond, NULL);
    if (e != 0)
        throw exc(std::string(_("System function failed: "))
                + "pthread_cond_init(): " + std::strerror(e), e);
}
Пример #11
0
 void CommandOptionOneOf::addOption(CommandOption* opt)
 {
    if (NULL == opt)
    {
       InvalidParameter  exc("Invalid option address");
       GPSTK_THROW(exc);
    }
    optionVec.push_back(opt);
 }
Пример #12
0
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
static void tecutlin() /* Защита от случайного нажатия на F3 вместо F4: если */
{                      /* последнее запоминаемое было символы, откзатать (но */
  if (cpopen) {        /*                            только 1 раз, выполнить */
    if (cpnocl) { cpnocl = false; exc(E_LCUT); }  /*  затребованную операцию */
    else CSclose(); }                             /*   если user настаивает) */
  else   CPempty();
  clbuf[0] = CpSCH_NEW_LINE; int len = TxRead(Ttxt, clbuf+1);
  TxBottom(LCtxt);
  TxIL(LCtxt, clbuf, len+1); LCtxt->txstat |= TS_CHANGED; cpempt = false;
}
Пример #13
0
Файл: lirc.cpp Проект: 63n/bino
void lircclient::init()
{
    if (!_initialized)
    {
        int socket_flags;
        _socket = lirc_init(const_cast<char *>(_client_name.c_str()), msg::level() == msg::DBG ? 1 : 0);
        if (_socket == -1)
        {
            throw exc(_("Cannot initialize LIRC."));
        }
        if ((socket_flags = fcntl(_socket, F_GETFL)) < 0
                || fcntl(_socket, F_SETFL, socket_flags | O_NONBLOCK) < 0)
        {
            lirc_deinit();
            throw exc(_("Cannot set LIRC socket properties."));
        }
        if (_conf_files.size() == 0)
        {
            if (lirc_readconfig(NULL, &_config, NULL) != 0)
            {
                lirc_deinit();
                throw exc(_("Cannot read LIRC default configuration."));
            }
        }
        else
        {
            _config = NULL;
            for (size_t i = 0; i < _conf_files.size(); i++)
            {
                if (lirc_readconfig(const_cast<char *>(_conf_files[i].c_str()), &_config, NULL) != 0)
                {
                    if (_config)
                    {
                        lirc_freeconfig(_config);
                    }
                    lirc_deinit();
                    throw exc(str::asprintf(_("Cannot read LIRC configuration file %s."), _conf_files[i].c_str()));
                }
            }
        }
        _initialized = true;
    }
}
Пример #14
0
/*
 * INITIALIZE Shader Program
 *
 * This function reads in the source code for shaders, 
 * compiles each shader, and links the shaders into
 * a shader program.
 * ShaderException is thrown if an error occurs in any
 * of the previous steps.
 */
void shader::init() {
    QFile vertFile(vertSrcPath);
    QFile fragFile(fragSrcPath);
    
    // Test if Vertex File can be Opened
    if (!vertFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        ShaderException exc("Failed to Open Vertex Shader File");
        throw exc;
    }
    // Test if Fragment File can be Opened
    if (!fragFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        ShaderException exc("Failed to Open Fragment Shader File");
        throw exc;
    }
    
    // Get data from Vertex file and close
    QByteArray vertFileData = vertFile.readAll();
    vertFile.close();
    // Get data from Fragment file and close
    QByteArray fragFileData = fragFile.readAll();
    fragFile.close();
    
    // Nothing Read from Vertex Shader
    if (!vertFileData.data()) {
        ShaderException exc("Failed to Read Vertex Shader File");
        throw exc;
    }
    // Nothing Read from Fragment Shader
    if (!fragFileData.data()) {
        ShaderException exc("Failed to Read Fragment Shader File");
        throw exc;
    }

    // Otherwise, create shaders! //
    
    // Create Shaders //
    createShader(Vertex_Shader, vertexShader, vertFileData.data());
    createShader(Fragment_Shader, fragShader, fragFileData.data());
    
    // Create Program //
    createShaderProgram();
}
Пример #15
0
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
static void leconvert (int type) /* convert upper <-> lower case for letters */
{   /* and decimal <-> other bases for numbers  */
    int x0, x1, len;
    if (! Block1size(&x0, &x1)) x1 = (x0 = Lx) + 1;
    len = vipConvert(Lebuf+x0, x1-x0, type, lfbuf);
    if (len < 0) exc(E_ILCHAR);
    if (len < x1-x0) llmove(x0+len, Lxre, len+x0-x1, NIL);
    else if (len > x1-x0) llmove(x1,     Lxre, len+x0-x1, NIL);
    llmove(x0, Lx = x0+len, REPLACE, lfbuf);
    if (BlockMark) BlockTx = x0;
}
Пример #16
0
void thread::cancel()
{
    __wait_mutex.lock();
    int e = pthread_cancel(__thread_id);
    if (e != 0) {
        __wait_mutex.unlock();
        throw exc(std::string(_("System function failed: "))
                + "pthread_cancel(): " + std::strerror(e), e);
    }
    __wait_mutex.unlock();
}
Пример #17
0
bool xgl::CheckFBO(const GLenum target, const std::string &where)
{
    GLenum status = glCheckFramebufferStatusEXT(target);
    if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
    {
        std::string errstr;
        switch (status)
        {
            case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT";
                break;

            case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
                errstr = "GL_FRAMEBUFFER_UNSUPPORTED_EXT";
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT";
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT";
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT";
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT";
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT";
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
                errstr = "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT";
                break;

            case 0:
                errstr = "in glCheckFramebufferStatus";
                break;

            default:
                errstr = str::asprintf("0x%X", static_cast<unsigned int>(status));
                break;
        }
        std::string pfx = (where.length() > 0 ? where + ": " : "");
        throw exc(pfx + "OpenGL FBO error " + errstr);
        return false;
    }
    return true;
}
Пример #18
0
FunctionObject*
Curry::evaluate(Thread& t,
                FunctionObject* inObj,
                const Function::ArgumentVector& args,
                const vector<bool>& mask,
                bool dynamicDispatch)
{
    //
    //  Never do partial application on the result of a lambda
    //  expression (its too difficult to archive). Instead do partial
    //  evaluation. The good side is that there will never be more
    //  than one level of indirection in multiple-curried lambda
    //  expressions. the bad side is that there will be more overhead
    //  upfront.
    //

    Process*        p     = t.process();
    const Function* F     = inObj->function();
    const bool      apply = !F->isLambda();

    try
    {
        if (apply)
        {
            PartialApplicator evaluator(F, p, &t, args, mask, dynamicDispatch);

            const FunctionType* rt = evaluator.result()->type();
            FunctionObject* outObj = new FunctionObject(rt);
            outObj->setDependent(inObj);
            outObj->setFunction(evaluator.result());
            return outObj;
        }
        else
        {
            FunctionSpecializer evaluator(F, p, &t);
            evaluator.partiallyEvaluate(args, mask);

            const FunctionType* rt = evaluator.result()->type();
            FunctionObject* outObj = new FunctionObject(rt);
            outObj->setFunction(evaluator.result());
            return outObj;
        }
    }
    catch (Exception& e)
    {
        ProgramException exc(t);
        exc.message() = e.message();
        exc.message() += " during partial ";
        exc.message() += (apply ? "application" : "evaluation");
        exc.message() += " of ";
        exc.message() += F->name().c_str();
        throw exc;
    }
}
Пример #19
0
 static inline T _to(const std::string &s, const std::string &name)
 {
     std::istringstream is(s);
     T v;
     is >> v;
     if (is.fail() || !is.eof())
     {
         throw exc(std::string("cannot convert '") + sanitize(s) + "' to " + name, EINVAL);
     }
     return v;
 }
Пример #20
0
 static inline T _to(const std::string &s, const char *name)
 {
     std::istringstream is(s);
     T v;
     is >> v;
     if (is.fail() || !is.eof())
     {
         throw exc(str::asprintf(_("Cannot convert string to %s."), name), EINVAL);
     }
     return v;
 }
Пример #21
0
PicDetail::PicDetail(QWidget *parent) : QWidget(parent)
{
	pic = NULL;
	pic = new QLabel(this);
	this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);

	this->setGeometry(QApplication::desktop()->availableGeometry());
	QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Escape),this);
	connect(shortcut, SIGNAL(activated()), this, SIGNAL(exc()));
	setObjectName("PicDetail");
	setStyleSheet("QWidget#PicDetail{background-color:black}");
}
Пример #22
0
bool xgl::CheckError(const std::string &where)
{
    GLenum e = glGetError();
    if (e != GL_NO_ERROR)
    {
        std::string pfx = (where.length() > 0 ? where + ": " : "");
        throw exc(pfx + "OpenGL error " + str::asprintf("0x%04X", static_cast<unsigned int>(e)));
        // Don't use gluErrorString(e) here to avoid depending on libGLU just for this
        return false;
    }
    return true;
}
Пример #23
0
void thread::start()
{
    if (atomic::bool_compare_and_swap(&__running, false, true))
    {
        wait();
        int e = pthread_create(&__thread_id, NULL, __run, this);
        if (e != 0)
        {
            throw exc(std::string("Cannot create thread: ") + std::strerror(e), e);
        }
        __joinable = true;
    }
}
Пример #24
0
void thread::wait()
{
    __wait_mutex.lock();
    if (atomic::bool_compare_and_swap(&__joinable, true, false)) {
        int e = pthread_join(__thread_id, NULL);
        if (e != 0) {
            __wait_mutex.unlock();
            throw exc(std::string(_("System function failed: "))
                    + "pthread_join(): " + std::strerror(e), e);
        }
    }
    __wait_mutex.unlock();
}
Пример #25
0
void audio_output::set_source_parameters()
{
    float gain = dispatch::parameters().audio_volume();
    if (dispatch::parameters().audio_mute())
    {
        gain = 0.0f;
    }
    alSourcef(_source, AL_GAIN, gain);
    if (alGetError() != AL_NO_ERROR)
    {
        throw exc(_("Cannot set OpenAL audio volume."));
    }
}
Пример #26
0
void audio_output::stop()
{
    alSourceStop(_source);
    if (alGetError() != AL_NO_ERROR)
    {
        throw exc(_("Cannot stop OpenAL source playback."));
    }
    // flush all buffers and reset the state
    ALint processed_buffers;
    alGetSourcei(_source, AL_BUFFERS_PROCESSED, &processed_buffers);
    while (processed_buffers > 0)
    {
        ALuint buf = 0;
        alSourceUnqueueBuffers(_source, 1, &buf);
        if (alGetError() != AL_NO_ERROR)
        {
            throw exc(_("Cannot unqueue OpenAL source buffers."));
        }
        alGetSourcei(_source, AL_BUFFERS_PROCESSED, &processed_buffers);
    }
    _state = 0;
}
Пример #27
0
void thread::start(int priority)
{
    if (atomic::bool_compare_and_swap(&__running, false, true)) {
        wait();
        int e;
        pthread_attr_t priority_thread_attr;
        pthread_attr_t* thread_attr = NULL;
        if (priority != priority_default)
        {
            // Currently this means priority_min
            int policy, min_priority;
            struct sched_param param;
            e = pthread_attr_init(&priority_thread_attr);
            e = e || pthread_attr_getschedpolicy(&priority_thread_attr, &policy);
            if (e == 0) {
                min_priority = sched_get_priority_min(policy);
                if (min_priority == -1)
                    e = errno;
            }
            e = e || pthread_attr_getschedparam(&priority_thread_attr, &param);
            if (e == 0) {
                param.sched_priority = min_priority;
            }
            e = e || pthread_attr_setschedparam(&priority_thread_attr, &param);
            if (e != 0) {
                throw exc(std::string(_("System function failed: "))
                        + "pthread_attr_*(): " + std::strerror(e), e);
            }
            thread_attr = &priority_thread_attr;
        }
        e = pthread_create(&__thread_id, thread_attr, __run, this);
        if (e != 0) {
            throw exc(std::string(_("System function failed: "))
                    + "pthread_create(): " + std::strerror(e), e);
        }
        __joinable = true;
    }
}
Пример #28
0
void thread::wait()
{
    __wait_mutex.lock();
    if (atomic::bool_compare_and_swap(&__joinable, true, false))
    {
        int e = pthread_join(__thread_id, NULL);
        if (e != 0)
        {
            __wait_mutex.unlock();
            throw exc(std::string("Cannot join with thread: ") + std::strerror(e), e);
        }
    }
    __wait_mutex.unlock();
}
Пример #29
0
   void PackedNavBits::addUnsignedDouble( const double value, const int numBits,
                                          const int power2 ) 
      throw(InvalidParameter)
   {
      uint64_t out = (uint64_t) ScaleValue(value, power2);
      uint64_t test = pow(static_cast<double>(2),numBits) - 1;
      if ( out > test )
      {
         InvalidParameter exc("Scaled value too large for specifed bit length");
         GPSTK_THROW(exc);
      }

      addUint64_t( out, numBits ); 
   } 
Пример #30
0
/*---------------------------------------------------------------------------*/
static void pasteFromLCtxt (bool in_Ttxt) /* paste into Ttxt or current line */
{
  int len = TxRead(LCtxt, clbuf); TxDown(LCtxt);  if (!len) return;
  char *clpos = clbuf;
  if (clbuf[0] == CpSCH_NEW_LINE) { clpos++; len--;
    if (in_Ttxt) {
      if (Lwnd) ExitLEmode();
      TxSetY(Ttxt, Ty);
      TxIL  (Ttxt, clpos, len); Ttxt->txstat |= TS_CHANGED; return;
  } }
       if (Lx <  Lxle) exc(E_EDTBEG);
  else if (Lx >= Lxre) exc(E_EDTEND);
  else {
    TxSetY(Ttxt, Ty);                 //  Have to take care of inserting empty
    if (in_Ttxt && qTxBottom(Ttxt)) { // line at the end-of-text (usually this
      if (Lwnd)   ExitLEmode();       // is done by LeCommand automatically),
      TxSetY(Ttxt, Ty); teIL();       // make sure to position in Ttxt first!
    }
    if (Lwnd == NULL) EnterLEmode();                  // inserting one-by-one
    cclen = aftotc(clpos, len, ccbuf);                // to enable slow undo
    for (int i = 0; i < cclen; i++) leLLCE(ccbuf[i]); // inside the line and
    cclen = 0;                        Lchange = TRUE; // cleanup in leARGmode
} }