// Test that our search finds example mates in one.
char*
TestMatesInTwo()
{
  char *fen;
  Game game;
  int i, dummyVal;
  Move actual, expected;
  uint64_t dummy = 0;

  StringBuilder builder = NewStringBuilder();

  for(i = 0; i < COUNT; i++) {
    fen = fens[i];
    expected = ParseMove(mates[i]);

    game = ParseFen(fen);
    actual = Search(&game, &dummy, &dummyVal, 3);    

    if(actual != expected) {
      AppendString(&builder, "Search failed mate-in-two for:-\n\n"
                   "%s\n"
                   "Expected move %s, engine selected %s.\n\n",
                   StringChessSet(&game.ChessSet), StringMove(expected), StringMove(actual));
    }
  }

  return builder.Length == 0 ? NULL : BuildString(&builder, true);
}
Exemple #2
0
   STR_String :: STR_String( )
   {

      pCharString = NULL ;
      BuildString( 0 , NULL ) ;

   } // End of function: STR  !Construct an empty string
Exemple #3
0
   STR_String :: STR_String( char * pStringParm )
   {

      pCharString = NULL ;
      BuildString( strlen( pStringParm ) , pStringParm ) ;

   } // End of function: STR  !Construct from a character string
Exemple #4
0
   STR_String :: STR_String( STR_String & string )
   {

      pCharString = NULL ;
      BuildString( string.Length , string.pCharString ) ;

   } // End of function: STR  !Construct from a string value
Exemple #5
0
char*
StringMoveHistory(MemorySlice *history, bool abbrev)
{
  Move move;
  Memory *curr;
  Side side = White;
  StringBuilder builder = NewStringBuilder();
  int fullMoveCount = 1;

  for(curr = history->Vals; curr != history->Curr; curr++) {
    move = curr->Move;

    if(abbrev) {
      AppendString(&builder, "%s ", StringMove(move));
    } else {
      switch(side) {
      case White:
        AppendString(&builder, "%d. %s",
                     fullMoveCount, StringMove(move));
        break;
      case Black:
        AppendString(&builder, " %s\n",
                     StringMove(move));

        fullMoveCount++;

        break;
      }
    }

    side = OPPOSITE(side);
  }

  return builder.Length == 0 ? NULL : BuildString(&builder, true);
}
Exemple #6
0
   STR_String STR_String :: operator = ( const STR_String & StringParm )
   {

      BuildString( StringParm.Length , StringParm.pCharString ) ;
      return * this ;

   } // End of function: STR  !Assign a string value to a string value
Exemple #7
0
int AutoCompData::BuildFieldList( const wxString& word, const wxString& path, int line, wxString& list ) const
{
   //wxASSERT( !path.IsEmpty() );
   wxASSERT( line >= 0 );

   // Find the right file...
   AutoCompPage* file = AutoCompPage::Find( path, m_Files );
   if ( !file )
      return 0;

   // TODO: Gotta add unnammed objects as well to make this 
   // work.  Maybe give them a special name... something easy
   // to skip over?  Maybe unnammed objects do not get merged?

   // Find the object that spans the least amount of lines.
   AutoCompClass* object, *found = NULL;
   int span, maxSpan = INT_MAX;
   const AutoCompClassArray& objects = file->GetObjects();
   for ( int i=0; i < objects.GetCount(); i++ )
   {
      object = objects[i];
      wxASSERT( object );

      // Are we within this one?
      span = object->GetLineSpan();
      if ( object->InLineSpan( line ) && span < maxSpan )
      {
         found = object;
         maxSpan = span;
      }
   }

   if ( !found )
      return 0;

   // Loop thru the base classes building a list of fields.
   wxArrayString fields;
   for ( ;; )
   {
      found = AutoCompClass::Find( found->GetBase(), m_Classes );
      if ( !found )
         break;

      found->BuildFieldList( fields );
   }

   // Gotta sort before i can find the word.
   fields.Sort( CmpStringNoCase );

   // If none of the fields start with the word
   // then skip out the string build and return
   // no results.
   if (  !word.IsEmpty() && 
         FindPartialWord( word, fields ) == wxNOT_FOUND )
      return 0;

   // Sort it and make a string out of it!
   BuildString( fields, &list );
   return fields.GetCount();
}
Exemple #8
0
void MatrixMarket( const SparseMatrix<T>& A, string basename="matrix" )
{
    EL_DEBUG_CSE
    
    string filename = basename + "." + FileExtension(MATRIX_MARKET);
    ofstream file( filename.c_str(), std::ios::binary );
    if( !file.is_open() )
        RuntimeError("Could not open ",filename);

    // Write the header
    // ================
    {
        ostringstream os;
        os << "%%MatrixMarket matrix coordinate ";
        if( IsComplex<T>::value )
            os << "complex "; 
        else
            os << "real ";
        os << "general\n";
        file << os.str();
    }
    
    // Write the size line
    // ===================
    const Int m = A.Height();
    const Int n = A.Width();
    const Int numNonzeros = A.NumEntries();
    file << BuildString(m," ",n," ",numNonzeros,"\n");
    
    // Write the entries
    // =================
    for( Int e=0; e<numNonzeros; ++e )
    {
        const Int i = A.Row(e);
        const Int j = A.Col(e);
        const T value = A.Value(e);
        if( IsComplex<T>::value )
        {
            file << 
              BuildString(i," ",j," ",RealPart(value)," ",ImagPart(value),"\n");
        }
        else
        {
            file << BuildString(i," ",j," ",RealPart(value),"\n");
        }
    }
}
Exemple #9
0
WEBC_CHAR *StringBuilder::MallocString(char *file, long line)
{
	WEBC_CHAR *str = (WEBC_CHAR *) WEBC_DEBUG_MALLOC(sizeof(WEBC_CHAR) * (GetStringLength() + 1), file, line,"MallocString", 0);
	if (str)
	{
		BuildString(str);
	}
	return str;
}
Exemple #10
0
char *
GetPassword(char *prompt)
{
    int fd;
    int nc;
    char buf[BUFSIZ];
    int done = 0;

    if (prompt == (char *)0)
	prompt = "";
    if ((pass = AllocString()) == (STRING *)0)
	OutOfMem();
    BuildString((char *)0, pass);

    if ((fd = open("/dev/tty", O_RDWR)) == -1) {
	Error("could not open `/dev/tty': %s", strerror(errno));
	return (char *)0;
    }

    C2Raw(fd);
    write(fd, prompt, strlen(prompt));
    while (!done) {
	int i;
	if ((nc = read(0, buf, sizeof(buf))) == 0)
	    break;
	for (i = 0; i < nc; ++i) {
	    if (buf[i] == 0x0d || buf[i] == 0x0a) {
		/* CR, NL */
		done = 1;
		break;
	    } else
		BuildStringChar(buf[i], pass);
	}
    }
    C2Normal(fd);
    /*
       {
       static STRING *c = (STRING *) 0;
       if ((c = AllocString()) == (STRING *) 0)
       OutOfMem();
       write(fd, "\n'", 2);
       if (pass->used) {
       FmtCtlStr(pass->string, pass->used - 1, c);
       write(fd, c->string, c->used - 1);
       }
       write(fd, "'\n", 2);
       }
     */
    write(fd, "\n", 1);
    close(fd);
    /* this way a (char*)0 is only returned on error */
    if (pass->string == (char *)0)
	return "";
    else
	return pass->string;
}
LPCTSTR DuiStringPool::Get( UINT uID )
{
    m_strTmp=_T("");
    if(HasKey(uID))
    {
        m_strTmp=GetKeyObject(uID);
        BuildString(m_strTmp);
    }
    return m_strTmp;
}
Exemple #12
0
   STR_String :: STR_String( STR_String * pStringParm )
   {

   #ifdef _DEBUG
      EXC_ASSERT( pStringParm != NULL ) ;
   #endif

      pCharString = NULL ;
      BuildString( pStringParm->Length , pStringParm->pCharString ) ;

   } // End of function: STR  !Construct from a pointed to string
Exemple #13
0
   STR_String STR_String :: operator = ( const char * const pStringParm )
   {

   #ifdef _DEBUG
      EXC_ASSERT( pStringParm != NULL ) ;
   #endif

      BuildString( strlen( pStringParm ) , pStringParm ) ;
      return * this ;

   } // End of function: STR  !Assign a character string
Exemple #14
0
   STR_String ::
             STR_String( int idString )
   {

      // Retrieve string from memory resident table

         pCharString = NULL ;

         if ( ( idString & STR_DOM ) == STR_MEM )
         {

            BuildString( idString & STR_ID ) ;

            return ;

         } // end selection: Retrieve string from memory resident table

      // Retrieve string from parameter base

         else if ( ( idString & STR_DOM ) == STR_PMB )
         {

            BuildString( STR_DomainNotImplemented & STR_ID ) ;

            return ;

         } // end selection: Retrieve string from parameter base

      // Domain not found


         int    lenStr = 0 ;
         char * pStr = FindStringEntry( STR_ErrorTableDomain & STR_ID , &lenStr ) ;

         EXC_ENFORCE( strlen( pStr ) < DIM_ERROR_BUFFER - 15 ) ;

         sprintf( errorBuffer , pStr , idString & STR_DOM ) ;

         BuildString( strlen( errorBuffer ) , errorBuffer ) ;

   } // End of function: STR  !Construct given an id of a string contained in a table
Exemple #15
0
   STR_String ::
             STR_String( int    LengthParm  ,
                         char * pStringParm  )
   {

   #ifdef _DEBUG
      EXC_ASSERT( ( 0 <= LengthParm ) && ( LengthParm < STR_MAX_LENGTH )) ;
   #endif

      pCharString = NULL ;
      BuildString( LengthParm , pStringParm ) ;

   } // End of function: STR  !Construct from a character string of a given length
Exemple #16
0
   void STR_String ::
            BuildString( int idString )
   {
      // AE: All strings in the memory resident string table are zero terminated.
      //     They also contain a length parameter.
      //     It is assumed that the memory resident table is well formed.
      //     This assumption is reasonable since the table is generated.

      int lenStr  = -1 ;
      char * pStr = FindStringEntry( idString , &lenStr ) ;

      BuildString( lenStr , pStr ) ;

   } // End of function: STR  $Build given an idString
Exemple #17
0
void
ClearPassword(void)
{
    if (pass == (STRING *)0 || pass->allocated == 0)
	return;

#if HAVE_MEMSET
    memset((void *)(pass->string), '\000', pass->allocated);
#else
    bzero((char *)(pass->string), pass->allocated);
#endif

    BuildString((char *)0, pass);
}
Exemple #18
0
void MatrixMarket( const Matrix<T>& A, string basename="matrix" )
{
    EL_DEBUG_CSE
    
    string filename = basename + "." + FileExtension(MATRIX_MARKET);
    ofstream file( filename.c_str(), std::ios::binary );
    if( !file.is_open() )
        RuntimeError("Could not open ",filename);

    // Write the header
    // ================
    {
        ostringstream os;
        os << "%%MatrixMarket matrix array ";
        if( IsComplex<T>::value )
            os << "complex "; 
        else
            os << "real ";
        os << "general\n";
        file << os.str();
    }
    
    // Write the size line
    // ===================
    const Int m = A.Height();
    const Int n = A.Width();
    file << BuildString(m," ",n,"\n");
    
    // Write the entries
    // =================
    for( Int j=0; j<n; ++j )
    {
        for( Int i=0; i<m; ++i )
        {
            ostringstream os;
            os << A.GetRealPart(i,j);
            if( IsComplex<T>::value )
                os << " " << A.GetImagPart(i,j);
            os << "\n";
            file << os.str();
        }
    }
}
Exemple #19
0
void CGLString::Render(int msg_type)
{
	// The first time we render this text, build the set of textured quads
	if (!mVertices) {
		BuildString(msg_type);
	} else if (msg_type&128) {
		unsigned char valr,valg,valb,vala;
		valr=valg=valb=0xFF;
		vala=(msg_type&127)*2;
		for (int i = 0; i < mNumberOfQuads; ++i) {
			mColors[i*4 + 0].r=mColors[i*4 + 1].r=mColors[i*4 + 2].r=mColors[i*4 + 3].r=valr;
			mColors[i*4 + 0].g=mColors[i*4 + 1].g=mColors[i*4 + 2].g=mColors[i*4 + 3].g=valg;
			mColors[i*4 + 0].b=mColors[i*4 + 1].b=mColors[i*4 + 2].b=mColors[i*4 + 3].b=valb;
			mColors[i*4 + 0].a=mColors[i*4 + 1].a=mColors[i*4 + 2].a=mColors[i*4 + 3].a=vala;
		}
	}
	
	// Enable texturing, bind the font's texture and set up blending
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, mFont->mTexId);
	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);    
	glEnableClientState(GL_COLOR_ARRAY);
	

	// Bind our vertex data
    glVertexPointer(2, GL_FLOAT, 0, mVertices);
	glTexCoordPointer(2, GL_FLOAT, 0, mUVs);
	glColorPointer(4, GL_UNSIGNED_BYTE, 0, mColors);

	// Draw the text
	glDrawElements(GL_TRIANGLES, 6 * mNumberOfQuads, GL_UNSIGNED_SHORT, mIndices);
	
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
}
Exemple #20
0
//--------------------------------------------------------------------------------
int CHL7PacOutThread::DoPACMessage(CPACSDatabase* pDB, long nMsgNo, long nMsgId)
	{
	GetIO()->Output(IOMASK_7|IOMASK_CONST, "CHL7PacOutThread::DoPACMessage entry");

	CString sOut;
	if(! BuildString(pDB, nMsgNo, nMsgId, sOut))
		{
		CString sTemp;
		sTemp.Format("Message %ld is empty", nMsgNo );
		GetIO()->Output(IOMASK_ERR|IOMASK_CONST, sTemp);
		return STATUS_MSG_ERROR;
		}

	LPTSTR pData = new char[sOut.GetLength() + 1];
	strcpy(pData, sOut);

	GetMonitorPtr()->PostThreadMessage(HL7_HL7MSG, (WPARAM) pData, 0);

	// get the response from the monitor
	MSG msg;
	::GetMessage(&msg, NULL, HL7_HL7MSG, HL7_HL7MSG);

	// check how many times the message has been sent
	if(nMsgNo != m_nLastMsgNo)
		{
		// no - so reset the counter
		m_nLastMsgNo = nMsgNo;
		m_nRetries = 0;
		}
	else
		{
		CHL7DBServerConfig config;
		m_nRetries++;

		if(m_nRetries >= config.GetMaxRetries())
			{
			// too many tries so just move on
			GetIO()->FormatOutput(IOMASK_ERR, "Message %ld sent %ld times without ACK", nMsgNo, m_nRetries );
			m_nRetries = 0;
			return STATUS_MSG_ERROR;
			}
		}

	if(msg.wParam == NULL )
		{
		GetIO()->FormatOutput(IOMASK_ERR, "wParam==NULL (Must be a socket error) lParam=%ld", msg.lParam);
		return STATUS_MSG_ERROR_RESEND;
		}

	CHL7Message* pMsg = (CHL7Message*) msg.wParam;

	// get the MSA segment
	CHL7Segment* pSeg = pMsg->GetSegment(1);

	if(pSeg == NULL)
		{
		GetIO()->Output(IOMASK_ERR|IOMASK_CONST, "pSeg == NULL");
		delete pMsg;
		return STATUS_MSG_ERROR_RESEND;
		}

	// look at the ACK/NACK character
	LPCTSTR pAck = pSeg->GetField(1);

	if(strlen(pAck) < 2)
		{
		GetIO()->Output(IOMASK_ERR|IOMASK_CONST, "strlen(pAck) < 2");
		delete pMsg;
		return STATUS_MSG_ERROR_RESEND;
		}

	if(pAck[1] != 'A')
		{
		GetIO()->Output(IOMASK_ERR|IOMASK_CONST, "pAck[1] != 'A'");
		delete pMsg;
		return STATUS_MSG_ERROR;
		}

	delete pMsg;
	GetIO()->Output(IOMASK_8|IOMASK_CONST, "CHL7PacOutThread::DoPACMessage ok exit");
	return STATUS_MSG_OK;
	}
Exemple #21
0
void Snapshot
( const Matrix<Int>& preimage,
  const Matrix<Real>& estimates,
  const Matrix<Int>& itCounts,
        Int numIts,
        bool deflate,
        SnapshotCtrl& snapCtrl )
{
    EL_DEBUG_CSE
    auto logMap = []( const Real& alpha ) { return Log(alpha); };
    if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 )
    {
        const bool numSave =
            ( snapCtrl.numSaveFreq > 0 &&
              snapCtrl.numSaveCount >= snapCtrl.numSaveFreq );
        const bool imgSave =
            ( snapCtrl.imgSaveFreq > 0 &&
              snapCtrl.imgSaveCount >= snapCtrl.imgSaveFreq );
        const bool imgDisp =
            ( snapCtrl.imgDispFreq > 0 &&
              snapCtrl.imgDispCount >= snapCtrl.imgDispFreq );
        Matrix<Real> invNorms, estMap;
        Matrix<Int> itCountsReord, itCountMap;
        if( numSave || imgSave || imgDisp )
        {
            invNorms = estimates;
            if( deflate )
                RestoreOrdering( preimage, invNorms );
            ReshapeIntoGrid
            ( snapCtrl.realSize, snapCtrl.imagSize, invNorms, estMap );
            if( snapCtrl.itCounts )
            {
                itCountsReord = itCounts;
                if( deflate )
                    RestoreOrdering( preimage, itCountsReord );
                ReshapeIntoGrid
                ( snapCtrl.realSize, snapCtrl.imagSize, itCountsReord,
                  itCountMap );
            }
        }
        if( numSave )
        {
            auto title = BuildString( snapCtrl.numBase, "_", numIts );
            Write( estMap, title, snapCtrl.numFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, title+"_counts", snapCtrl.numFormat );
            snapCtrl.numSaveCount = 0;
        }
        if( imgSave || imgDisp )
            EntrywiseMap( estMap, MakeFunction(logMap) );
        if( imgSave )
        {
            auto title = BuildString( snapCtrl.imgBase, "_", numIts );
            Write( estMap, title, snapCtrl.imgFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, title+"_counts", snapCtrl.imgFormat );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Write( estMap, title+"_discrete", snapCtrl.imgFormat );
            SetColorMap( colorMap );
            snapCtrl.imgSaveCount = 0;
        }
        if( imgDisp )
        {
            auto title = BuildString( snapCtrl.imgBase, "_", numIts );
            Display( estMap, title );
            if( snapCtrl.itCounts )
                Display( itCountMap, title+"_counts" );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Display( estMap, title+"_discrete" );
            SetColorMap( colorMap );
            snapCtrl.imgDispCount = 0;
        }
    }
}
Exemple #22
0
std::string Datum::AsString() const {
    if(Text.size() > 0)
        return Text;

    Text = BuildString();
    return Text; }
Exemple #23
0
ButtonLabel::Expanded
ButtonLabel::Expand(const TCHAR *text, TCHAR *buffer, size_t size)
{
  Expanded expanded;
  const TCHAR *dollar;

  if (text == nullptr || *text == _T('\0') || *text == _T(' ')) {
    expanded.visible = false;
    return expanded;
  } else if ((dollar = StringFind(text, '$')) == nullptr) {
    /* no macro, we can just translate the text */
    expanded.visible = true;
    expanded.enabled = true;
    const TCHAR *nl = StringFind(text, '\n');
    if (nl != nullptr && LacksAlphaASCII(nl + 1)) {
      /* Quick hack for skipping the translation for second line of a two line
         label with only digits and punctuation in the second line, e.g.
         for menu labels like "Config\n2/3" */

      /* copy the text up to the '\n' to a new buffer and translate it */
      TCHAR translatable[256];
      const TCHAR *translated = GetTextN(text, nl, translatable,
                                         ARRAY_SIZE(translatable));
      if (translated == nullptr) {
        /* buffer too small: keep it untranslated */
        expanded.text = text;
        return expanded;
      }

      /* concatenate the translated text and the part starting with '\n' */
      expanded.text = BuildString(buffer, size, translated, nl);
    } else
      expanded.text = gettext(text);
    return expanded;
  } else {
    const TCHAR *macros = dollar;
    /* backtrack until the first non-whitespace character, because we
       don't want to translate whitespace between the text and the
       macro */
    macros = StripRight(text, macros);

    TCHAR s[100];
    expanded.enabled = !ExpandMacros(text, s, ARRAY_SIZE(s));
    if (s[0] == _T('\0') || s[0] == _T(' ')) {
      expanded.visible = false;
      return expanded;
    }

    /* copy the text (without trailing whitespace) to a new buffer and
       translate it */
    TCHAR translatable[256];
    const TCHAR *translated = GetTextN(text, macros, translatable,
                                       ARRAY_SIZE(translatable));
    if (translated == nullptr) {
      /* buffer too small: fail */
      // TODO: find a more clever fallback
      expanded.visible = false;
      return expanded;
    }

    /* concatenate the translated text and the macro output */
    expanded.visible = true;
    expanded.text = BuildString(buffer, size, translated, s + (macros - text));
    return expanded;
  }
}
Exemple #24
0
/*
 * get a pty for the user
 *
 * this has been revamped rather heavily for 8.0.0.  i've taken ideas
 * from the xemacs and openssh distributions to get code that *should*
 * work on systems i have no access to.  thanks to those reference
 * packages, i think things are ok...hopefully it's true!
 */
static int
GetPseudoTTY(STRING *slave, int *slaveFD)
{
#if HAVE_OPENPTY
    int fd = -1;
    int sfd = -1;
    int opty = 0;
    char *pcName;
# if HAVE_SIGACTION
    sigset_t oldmask, newmask;
# else
    extern RETSIGTYPE FlagReapVirt(int);
# endif

# if HAVE_SIGACTION
    sigemptyset(&newmask);
    sigaddset(&newmask, SIGCHLD);
    if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
	Error("GetPseudoTTY(): sigprocmask(SIG_BLOCK): %s",
	      strerror(errno));
# else
    SimpleSignal(SIGCHLD, SIG_DFL);
# endif

    opty = openpty(&fd, &sfd, NULL, NULL, NULL);

# if HAVE_SIGACTION
    if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
	Error("GetPseudoTTY(): sigprocmask(SIG_SETMASK): %s",
	      strerror(errno));
# else
    SimpleSignal(SIGCHLD, FlagReapVirt);
# endif

    if (opty != 0) {
	if (fd >= 0)
	    close(fd);
	if (sfd >= 0)
	    close(sfd);
	return -1;
    }
    if ((char *)0 == (pcName = ttyname(sfd))) {
	close(fd);
	close(sfd);
	return -1;
    }
    BuildString((char *)0, slave);
    BuildString(pcName, slave);

    *slaveFD = sfd;
    return fd;
#else
# if (HAVE_PTSNAME && HAVE_GRANTPT && HAVE_UNLOCKPT) || defined(_AIX)
    int fd = -1;
    int sfd = -1;
    char *pcName;
#  if HAVE_SIGACTION
    sigset_t oldmask, newmask;
#  else
    extern RETSIGTYPE FlagReapVirt(int);
#  endif
    int c;
    /* clone list and idea stolen from xemacs distribution */
    static char *clones[] = {
	"/dev/ptmx",		/* Various systems */
	"/dev/ptm/clone",	/* HPUX */
	"/dev/ptc",		/* AIX */
	"/dev/ptmx_bsd",	/* Tru64 */
	(char *)0
    };

    /* try to find the pty allocator */
    for (c = 0; clones[c] != (char *)0; c++) {
	if ((fd = open(clones[c], O_RDWR, 0)) >= 0)
	    break;
    }
    if (fd < 0)
	return -1;

#  if HAVE_SIGACTION
    sigemptyset(&newmask);
    sigaddset(&newmask, SIGCHLD);
    if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
	Error("GetPseudoTTY(): sigprocmask(SIG_BLOCK): %s",
	      strerror(errno));
#  else
    SimpleSignal(SIGCHLD, SIG_DFL);
#  endif

#  if HAVE_GRANTPT
    grantpt(fd);		/* change permission of slave */
#  endif

#  if HAVE_SIGACTION
    if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
	Error("GetPseudoTTY(): sigprocmask(SIG_SETMASK): %s",
	      strerror(errno));
#  else
    SimpleSignal(SIGCHLD, FlagReapVirt);
#  endif

#  if HAVE_UNLOCKPT
    unlockpt(fd);		/* unlock slave */
#  endif

#  if defined(_AIX)
    if ((pcName = ttyname(fd)) == (char *)0) {
	close(fd);
	return -1;
    }
#  else
#   if HAVE_PTSNAME
    if ((pcName = ptsname(fd)) == (char *)0) {
	close(fd);
	return -1;
    }
#   else
    close(fd);
    return -1;
#   endif
#  endif

    /* go ahead and open the slave */
    if ((sfd = open(pcName, O_RDWR, 0)) < 0) {
	Error("GetPseudoTTY(): open(%s): %s", pcName, strerror(errno));
	close(fd);
	return -1;
    }

    BuildString((char *)0, slave);
    BuildString(pcName, slave);

    *slaveFD = sfd;
    return fd;
# else
    /*
     * Below is the string for finding /dev/ptyXX.  For each architecture we
     * leave some pty's world writable because we don't have source for
     * everything that uses pty's.  For the most part, we'll be trying to
     * make /dev/ptyq* the "free" pty's.
     */
    /* all the world's a vax ;-) */
    static char charone[] = "prstuvwxyzPQRSTUVWq";
    static char chartwo[] =
	"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static char acMaster[] = "/dev/ptyXX";
    static char acSlave[] = "/dev/ttyXX";
    static char *pcOne = charone, *pcTwo = chartwo;
    int fd, sfd, iLoop, iIndex = sizeof("/dev/pty") - 1;
    char *pcOld1;
    struct stat statBuf;

    iLoop = 0;
    pcOld1 = pcOne;
    for (;;) {
	if ('\000' == *++pcTwo) {
	    pcTwo = chartwo;
	    if ('\000' == *++pcOne) {
		pcOne = charone;
		if ((pcOld1 == pcOne && ++iLoop > 1) || (iLoop > 32))
		    return -1;
	    }
	}
	acMaster[iIndex] = *pcOne;
	acMaster[iIndex + 1] = *pcTwo;

	/*
	 * Remeber we are root - stat the file
	 * to see if it exists before we open it
	 * for read/write - if it doesn't we don't
	 * have any pty's left in the row
	 */
	if (-1 == stat(acMaster, &statBuf) ||
	    S_IFCHR != (statBuf.st_mode & S_IFMT)) {
	    pcTwo = "l";
	    continue;
	}

	if (0 > (fd = open(acMaster, O_RDWR | O_NONBLOCK, 0))) {
	    continue;
	}
	acSlave[iIndex] = *pcOne;
	acSlave[iIndex + 1] = *pcTwo;
	if (-1 == access(acSlave, F_OK)) {
	    close(fd);
	    continue;
	}
	break;
    }

    /* go ahead and open the slave */
    if ((sfd = open(acSlave, O_RDWR, 0)) < 0) {
	Error("GetPseudoTTY(): open(%s): %s", acSlave, strerror(errno));
	close(fd);
	return -1;
    }

    BuildString((char *)0, slave);
    BuildString(acSlave, slave);

    *slaveFD = sfd;
    return fd;
# endif/* (HAVE_PTSNAME && HAVE_GRANTPT && HAVE_UNLOCKPT) || defined(_AIX) */
#endif /* HAVE_OPENPTY */
}
Exemple #25
0
void CDigistring::OnPaint() 
{
	CRect rect;
	CDoubleRect CharRect;
	GetClientRect(&rect);

	CPaintDC dc(this); // device context for painting
	dc.SetBkColor(m_BackColor);
	CMyMemDC memDC(&dc, &rect);

	CBrush hBrushOff, hBrushOn;
	hBrushOff.CreateSolidBrush(m_OffColor);
	hBrushOn.CreateSolidBrush(m_OnColor);
	CBrush *pOldBrush = memDC.SelectObject(&hBrushOn);

		int r = int(GetRValue(m_OffColor) * 0.75 + GetRValue(m_BackColor) * 0.25);
		int g = int(GetGValue(m_OffColor) * 0.75 + GetGValue(m_BackColor) * 0.25);
		int b = int(GetBValue(m_OffColor) * 0.75 + GetBValue(m_BackColor) * 0.25);

	CPen OffPen(PS_SOLID | PS_ENDCAP_ROUND, 1, RGB(r,g,b));
		r = int(GetRValue(m_OnColor) * 0.75 + GetRValue(m_BackColor) * 0.25);
		g = int(GetGValue(m_OnColor) * 0.75 + GetGValue(m_BackColor) * 0.25);
		b = int(GetBValue(m_OnColor) * 0.75 + GetBValue(m_BackColor) * 0.25);
	CPen OnPen(PS_SOLID | PS_ENDCAP_ROUND, 1, RGB(r,g,b));
	CPen *pOldPen = memDC.SelectObject(&OffPen);

	int iTotWidth = 0;
	double dRelWidth, dRelHeight;
	// TODO: Add your message handler code here

	DigiCharVector::iterator CharIterator;

	// Calculate resizing factors...
	BuildString();
	for (CharIterator = m_CharVector.begin(); CharIterator != m_CharVector.end();
		CharIterator++)
	{
		iTotWidth += CharIterator->GetNormWidth();
	}
	dRelWidth = double(rect.Width()) / iTotWidth;
	dRelHeight = double(rect.Height()) / NORM_DIGIHEIGHT;

	// If proportional make offset for centered text
	if (m_DispStyle & DS_SZ_PROP)
	{
		if (dRelWidth < dRelHeight)
			dRelHeight = dRelWidth;
		else
			dRelWidth = dRelHeight;

		CharRect.left = (rect.Width() - dRelWidth * iTotWidth) / 2;
		CharRect.top = (rect.Height() - dRelHeight * NORM_DIGIHEIGHT) / 2; 
	}
	else
		CharRect.SetRectEmpty();

	// Draw all characters...
	for (CharIterator = m_CharVector.begin(); CharIterator != m_CharVector.end();
		CharIterator++)
	{
		CharRect.SetRect(CharRect.left, CharRect.top,
			CharRect.left + dRelWidth * CharIterator->GetNormWidth(), 
			CharRect.top  + dRelHeight * NORM_DIGIHEIGHT);

		CharIterator->Draw(&memDC, CharRect, &OffPen, &OnPen, &hBrushOff, &hBrushOn);

		CharRect.left += dRelWidth * CharIterator->GetNormWidth();
	}

	// Mama says: Clean up your mess!
	memDC.SelectObject(pOldPen);
	memDC.SelectObject(pOldBrush);
	OffPen.DeleteObject();
	OnPen.DeleteObject();
	hBrushOff.DeleteObject();
	hBrushOn.DeleteObject();
}
Exemple #26
0
void AutoCompData::Build( const AutoCompPageArray& files, AutoCompExports* exports )
{
   Clear();

   // Copy in the export data first... this ensures that
   // we overload exports if something in the scripts
   // has the same name.
   if ( exports )
   {
      m_Exports = new AutoCompExports( *exports );

      const AutoCompClassArray& classes = m_Exports->GetClasses();
      for ( int i=0; i < classes.GetCount(); i++ )
      {
         wxASSERT( classes[i] );
         wxASSERT( !FindClassOrObject( classes[i]->GetName() ) );
         m_Classes.Add( classes[i] );
      }

      const AutoCompFunctionArray& functions = m_Exports->GetFunctions();
      for ( int i=0; i < functions.GetCount(); i++ )
      {
         wxASSERT( functions[i] );
         wxASSERT( !AutoCompFunction::Find( functions[i]->GetName(), m_Functions ) );
         m_Functions.Add( functions[i] );
      }
   }

   // Make a copy of the files.
   for ( int i=0; i < files.GetCount(); i++ )
   {
      wxASSERT( files[i] );
      m_Files.Add( new AutoCompPage( *files[i] ) );
   }

   // Now we merge the objects and vars into our global
   // arrays... this allows for quickly finding data
   // without the need to dig thru pages.
   for ( int i=0; i < m_Files.GetCount(); i++ ) 
   {
      wxASSERT( m_Files[i] );

      MergeObjects( m_Files[i]->GetObjects() );
      MergeVars( m_Files[i]->GetVars() );
   }

   // Now do a pass merging functions so that they are properly
   // made into members of existing objects and classes or added
   // into new namespaces.
   for ( int i=0; i < m_Files.GetCount(); i++ ) 
   {
      wxASSERT( m_Files[i] );
      MergeFunctions( m_Files[i]->GetFunctions() );
   }

   // Now we build the string lists.
   wxString name;
   m_CompList.Empty();
   m_CompIndex.Empty();
   m_ClassList.Empty();
   m_ClassIndex.Empty();
   m_DatablockList.Empty();
   m_DatablockIndex.Empty();
   m_GlobalsList.Empty();
   m_GlobalsIndex.Empty();

   //
   // Grab all the global vars for autocomplete
   // triggered by entering a $.
   //
   m_TempArray.Empty();
   for ( int i=0; i < m_Vars.GetCount(); i++ )
   {
      wxASSERT( m_Vars[i]->IsGlobal() );

      name = m_Vars[i]->m_Name + IDENT_VAR;

      m_TempArray.Add( name );
   }

   BuildString( m_TempArray, &m_GlobalsList, &m_GlobalsIndex );

   //
   // Gather all the concrete datablock types for 
   // autocomplete when the type name is needed.
   //
   m_TempArray.Empty();
   for ( int i=0; i < m_Classes.GetCount(); i++ ) {

      if ( !m_Classes[i]->IsDatablock() || !m_Classes[i]->IsExport() )
         continue;

      name = m_Classes[i]->GetName() + IDENT_DATABLOCK;
      //if ( m_TempArray.Index( name, false ) ) {
         m_TempArray.Add( name );
      //}
   }

   BuildString( m_TempArray, &m_DatablockList, &m_DatablockIndex );

   //
   // Gather all the concrete class types for 
   // autocomplete when the type name is needed.
   //
   m_TempArray.Empty();
   for ( int i=0; i < m_Classes.GetCount(); i++ ) {

      if ( !m_Classes[i]->IsExport() )
         continue;

      name = m_Classes[i]->GetName() + IDENT_CLASS;
      m_TempArray.Add( name );
   }

   BuildString( m_TempArray, &m_ClassList, &m_ClassIndex );

   //
   // Gather all global general identifiers into the 
   // main autocomplete list...
   //
   // Objects (both types and instances)
   // Datablocks (both types and instances)
   // Namespaces
   // Global functions
   // TorqueScript Keywords
   //
   m_TempArray.Empty();
   for ( int i=0; i < m_Functions.GetCount(); i++ ) {

      name = m_Functions[i]->GetName() + IDENT_FUNCTION;
      //if ( m_TempArray.Index( name, false ) ) {
         m_TempArray.Add( name );
      //}
   }

   for ( int i=0; i < m_Classes.GetCount(); i++ ) {

      name = m_Classes[i]->GetName();
      if ( m_Classes[i]->IsDatablock() )
         name += IDENT_DATABLOCK;
      else
         name += IDENT_CLASS;

      //if ( m_TempArray.Index( name, false ) ) {
      m_TempArray.Add( name );
      //}
   }

   for ( int i=0; i < m_Objects.GetCount(); i++ ) 
   {
      name = m_Objects[i]->GetName();

      // Skip adding unnamed objects.
      if ( name.IsEmpty() )
         continue;

      if ( m_Objects[i]->IsNamespace() )
         name += IDENT_NAMESPACE;
      else if ( m_Objects[i]->IsDatablock() )
         name += ITYPE_DATABLOCKOBJECT;
      //else if ( objects[i]->IsDatablock() )
      //   name += IDENT_NAMESPACE;
      else
         name += IDENT_OBJECT;

      //if ( m_TempArray.Index( name, false ) ) {
         m_TempArray.Add( name );
      //}
   }

   // Add in the reserved words.
   m_TempArray.Add( "break?8" );
   m_TempArray.Add( "case?8" );
   m_TempArray.Add( "continue?8" );
   m_TempArray.Add( "datablock?8" );
   m_TempArray.Add( "default?8" );
   m_TempArray.Add( "else?8" );
   m_TempArray.Add( "false?8" );
   m_TempArray.Add( "for?8" );
   m_TempArray.Add( "function?8" );
   m_TempArray.Add( "if?8" );
   m_TempArray.Add( "local?8" );   
   m_TempArray.Add( "new?8" );
   m_TempArray.Add( "or?8" );
   m_TempArray.Add( "package?8" );
   m_TempArray.Add( "return?8" );
   m_TempArray.Add( "singleton?8" );  
   m_TempArray.Add( "switch?8" );
   m_TempArray.Add( "switch$?8" );
   m_TempArray.Add( "true?8" );
   m_TempArray.Add( "while?8" );

   BuildString( m_TempArray, &m_CompList, &m_CompIndex );
}