Esempio n. 1
0
void SimpleConsole::OutputChar( int ch )
{
	outbyte(0xE9,ch);	//for bochs
	if(ch=='\t')
	{
		do{
			OutputChar(' ');
		}while( (cursorX-1)%4 );
		return;
	}
	if(ch=='\n')
	{
		NextLine();
	}
	else if( ch == 8 )
	{
		OutputChar( charStyle, cursorY, --cursorX );
	}
	else if ( isprint((unsigned char)ch) )
	{
		OutputChar( charStyle | ch, cursorY, cursorX++ );
	}
	if(cursorX >= width )
	{
		NextLine();
	}
	MoveCursor();
}
Esempio n. 2
0
local void PutNL( void )
{
#if !defined( __UNIX__ )
    if( !UnixStyle )
        OutputChar( '\r' );
#endif
    OutputChar( '\n' );
}
Esempio n. 3
0
//---------------------------------------------------------------------------
void CShowVGAMode(void)
{
    Gotoxy(6, _SHOW_NUM_POS_Y, BYTE_DISPLAY);
    CShowNumber1(stModeInfo.IHWidth, 0);
    OutputChar('X');
    CShowNumber1(stModeInfo.IVHeight, 0);
    OutputChar('X');
    CShowNumber1((stModeInfo.IVFreq/10), 0);
    OutputChar('H');
    OutputChar('Z');
    OutputChar(' ');
}
Esempio n. 4
0
local void OutputString( char *p, char *record )
{
    char        *r;
    unsigned    col;
    unsigned    space;
    char        numstr[30];

    for( ; *p != '\0';++p ) {
        if( *p == '%' ) {
            ++p;
            switch( *p ) {
            case 's':
                col = 0;
                for( r = record; *r != '\0' && !( *r == '\r' && *( r + 1 ) == '\0' );++r ) {
                    if( *r != '\t' || TabStop == 0 ) {
                        OutputChar( *r );
                        ++col;
                    } else {
                        space = ( col + TabStop ) - ( ( col + TabStop ) % TabStop );
                        while( col < space ) {
                            OutputChar( ' ' );
                            ++col;
                        }
                    }
                }
                break;
            case 'n':
                PutNL();
                break;
            case '#':
                sprintf( numstr, "%u", OutNum );
                for( col = 0; col < strlen( numstr ); ++col ) {
                    OutputChar( numstr[col] );
                }
                break;
            case '+':
                ++OutNum;
                break;
            case '-':
                --OutNum;
                break;
            default:
                OutputChar( *p );
                break;
            }
        } else {
            OutputChar( *p );
        }
    }
}
Esempio n. 5
0
static void FormatUFloatScientific (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos, double value, int iPrecision, unsigned int Flags, bool bUpperCase, bool bRemoveZeroes)
{
  double dSci = value > 0.0 ? value : -value;
  int exp = 0;

  if (dSci != 0.0)
  {
    while (dSci >= 10.0)
    {
      dSci /= 10.0;
      exp++;
    }

    while (dSci < 1.0)
    {
      dSci *= 10.0;
      exp--;
    }
  }

  if (WouldRoundToTen (value, iPrecision))
  {
    dSci /= 10.0;
    exp++;
  }

  if (FormatUFloat (szOutputBuffer, uiBufferSize, uiWritePos, dSci, iPrecision, Flags, bRemoveZeroes))
  {
  }

  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, bUpperCase ? 'E' : 'e');
  OutputInt (szOutputBuffer, uiBufferSize, uiWritePos, exp, 0, 3, sprintfFlags::ForceZeroSign, 10);
}
Esempio n. 6
0
//---------------------------------------------------------------------------
void CShowHDMIMode(void)
{
	WORD ucLen;
	WORD IHWidth_Tmp,IVHeight_Tmp;

	IHWidth_Tmp  = stModeInfo.IHWidth;
	IVHeight_Tmp = stModeInfo.IVHeight;

	CScalerPageSelect(_PAGE2);
	CScalerGetDataPortByte(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_VCR_50, 1, pData, _NON_AUTOINC);
	stModeInfo.IVHeight = HDMI_V_Height;

	if((pData[0]&0x0F) == 0x01)			// 2 times
		stModeInfo.IHWidth = HDMI_H_Width*2;
	else if((pData[0]&0x0F) == 0x03)	// 4 times
		stModeInfo.IHWidth = HDMI_H_Width*4;
	else
        stModeInfo.IHWidth = HDMI_H_Width;

	ucLen = stModeInfo.IVHeight;
	CScalerRead(_IPV_ACT_LEN_H_1A, 1, pData, _AUTOINC);

	if (pData[0] & _BIT5)
		ucLen = stModeInfo.IVHeight*2;

	if (GET_INTERLACE_MODE())
    {
		if(stModeInfo.IVFreq>=598 && stModeInfo.IVFreq<=599)			//60Hz
			stModeInfo.IVFreq += 2;
		else if(stModeInfo.IVFreq>=498 && stModeInfo.IVFreq<=499)	//50Hz
			stModeInfo.IVFreq += 2;
	}

    Gotoxy(6, _SHOW_NUM_POS_Y, BYTE_DISPLAY);
    CShowNumber1(stModeInfo.IHWidth, 0);
    OutputChar('X');
    CShowNumber1(ucLen, 0);
    OutputChar('X');
    CShowNumber1(stModeInfo.IVFreq/10, 0);
    OutputChar('H');
    OutputChar('Z');
    OutputChar(' ');

	stModeInfo.IHWidth  = IHWidth_Tmp;
	stModeInfo.IVHeight = IVHeight_Tmp;
}
Esempio n. 7
0
static void OutputReverseString (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos, const char* szString, int iStringLength)
{
  while (iStringLength > 0)
  {
    --iStringLength;

    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, szString[iStringLength]);
  }
}
Esempio n. 8
0
static void OutputNullPtr (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos)
{
  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '(');
  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, 'n');
  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, 'u');
  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, 'l');
  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, 'l');
  OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, ')');
}
Esempio n. 9
0
static void OutputIntSign (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos, long long int value, unsigned int Flags, int iBase, bool bUpperCase, int iPrecision)
{
  if (value < 0)
    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '-');
  else
  if (Flags & sprintfFlags::ForceSign)
  {
    if (value > 0)
      OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '+');
    else
      OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, ' ');
  }
  else
  if (Flags & sprintfFlags::BlankSign)
    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, ' ');
  else
  if (Flags & sprintfFlags::ForceZeroSign)
    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '+');

  if (Flags & sprintfFlags::Hash)
  {
    // With precision set to 'zero', nothing shall be printed if the value is zero
    if ((value == 0) && (iPrecision == 0))
      return;

    // in octal mode, print a '0' in front of it
    if (iBase == 8)
      OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '0');

    // in hexadezimal mode, print a '0x' or '0X' in front of it
    if (iBase == 16)
    {
      OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '0');

      if (bUpperCase)
        OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, 'X');
      else
        OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, 'x');
    }
  }
}
Esempio n. 10
0
static void OutputString (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos, const char* szString, unsigned int Flags, int iMinSize, int iMaxSize)
{
  if (!szString)
  {
    OutputNullPtr (szOutputBuffer, uiBufferSize, uiWritePos);
    return;
  }

  int iLen = 0;

  // if the string is supposed to be right-justified
  if (((Flags & sprintfFlags::LeftJustify) == 0) && (iMinSize > 0))
  {
    // get the string length
    while (szString[iLen] != '\0')
      ++iLen;

    if ((iMaxSize >= 0) && (iLen > iMaxSize))
      iLen = iMaxSize;

    // output as much padding as necessary
    OutputPaddingByFlags (szOutputBuffer, uiBufferSize, uiWritePos, iMinSize - iLen, Flags);
  }

  // a negative max size will have no effect (disabled)
  iLen = 0;
  while ((szString[iLen] != '\0') && (iMaxSize != 0))
  {
    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, szString[iLen]);
    --iMaxSize;
    ++iLen;
  }

  // if the text is supposed to be left justified, add required padding
  if (((Flags & sprintfFlags::LeftJustify) != 0) && (iMinSize > 0))
    OutputPadding (szOutputBuffer, uiBufferSize, uiWritePos, iMinSize - iLen, ' ');
}
Esempio n. 11
0
//-----------------------------------------------------------------------
void CDrawMuteState(void)
{           
    COsdFxDisableOsd();
    SetOSDDouble(0x03);
    SetOsdMap(tUserMenuOsdMap);
                
    // Init OSD Ram
    OSDClear(0,_MAINMENU_HEIGHT, 0, 31, 0x8C, BYTE_ATTRIB);
    OSDClear(0,_MAINMENU_HEIGHT, 0, 31, 0x00, BYTE_DISPLAY);
    OSDClear(0,_MAINMENU_HEIGHT, 0, 31, 0x40, BYTE_COLOR);
                
    COsdFxCodeWrite(ucCloseAllWindow);  
    OSDPosition(4 * 12, 2 * 18, 40, 1, 0x03);
    if (GET_AUDIO_MUTE()) // Mute on 
       COsdLoad1BitFont(FntMute, 0x10, 6, tFntVolumeCharWidth);
    else
       COsdLoad1BitFont(FntVolume, 0x10, 6, tFntVolumeCharWidth);  
                               
    // Display Volume/Mute icon
    Gotoxy(0, 0, BYTE_DISPLAY);
    OutputChar(0x10);
    OutputChar(0x11);
    OutputChar(0x12);
    Gotoxy(0, 1, BYTE_DISPLAY);
    OutputChar(0x13);
    OutputChar(0x14);
    OutputChar(0x15);

    COsdFxEnableOsd();
    bOSDTimeOut  = 0;
 //   ucAudioState = 1;
    if (GET_AUDIO_MUTE()) // Mute on  
    {
       	CTimerCancelTimerEvent(COsdDispOsdTimerEvent);
    }
    else
    {
       CTimerReactiveTimerEvent(SEC(5), COsdDispOsdTimerEvent);
    } 
}
Esempio n. 12
0
void curses_drawwindow(WINDOW *win)
{
    int i,j,w,drawx,drawy;
    unsigned tmp;

    int miny = 99999;
    int maxy = -99999;

    for (j=0; j<win->height; j++)
    {
        if (win->line[j].touched)
        {
            if(j<miny) {
                miny=j;
            }
            if(j>maxy) {
                maxy=j;
            }


            win->line[j].touched=false;

            for (i=0,w=0; w<win->width; i++,w++)
            {
                drawx=((win->x+w)*fontwidth);
                drawy=((win->y+j)*fontheight);//-j;
                if (((drawx+fontwidth)<=WindowWidth) && ((drawy+fontheight)<=WindowHeight))
                {
                    const char* utf8str = win->line[j].chars+i;
                    int len = ANY_LENGTH;
                    tmp = UTF8_getch(&utf8str, &len);
                    int FG = win->line[j].FG[w];
                    int BG = win->line[j].BG[w];
                    FillRectDIB(drawx,drawy,fontwidth,fontheight,BG);

                    if ( tmp != UNKNOWN_UNICODE){
                        int cw = mk_wcwidth((wchar_t)tmp);
                        len = ANY_LENGTH-len;
                        if(cw>1)
                        {
                            FillRectDIB(drawx+fontwidth*(cw-1),drawy,fontwidth,fontheight,BG);
                            w+=cw-1;
                        }
                        if(len>1)
                        {
                            i+=len-1;
                        }
                        if(0!=tmp) {
                            OutputChar(tmp, drawx,drawy,FG);
                        }
                    } else {
                        switch ((unsigned char)win->line[j].chars[i]) {
                        case LINE_OXOX_C://box bottom/top side (horizontal line)
                            HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                            break;
                        case LINE_XOXO_C://box left/right side (vertical line)
                            VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                            break;
                        case LINE_OXXO_C://box top left
                            HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                            break;
                        case LINE_OOXX_C://box top right
                            HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                            break;
                        case LINE_XOOX_C://box bottom right
                            HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                            break;
                        case LINE_XXOO_C://box bottom left
                            HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                            break;
                        case LINE_XXOX_C://box bottom north T (left, right, up)
                            HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight,2,FG);
                            break;
                        case LINE_XXXO_C://box bottom east T (up, right, down)
                            VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                            HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                            break;
                        case LINE_OXXX_C://box bottom south T (left, right, down)
                            HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                            break;
                        case LINE_XXXX_C://box X (left down up right)
                            HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                            VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                            break;
                        case LINE_XOXX_C://box bottom east T (left, down, up)
                            VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                            HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                            break;
                        default:
                            break;
                        }//switch (tmp)
                    }
                }//(tmp < 0)
            }//for (i=0;i<_windows[w].width;i++)
        }
    }// for (j=0;j<_windows[w].height;j++)
    win->draw=false;                //We drew the window, mark it as so

    if(maxy>=0)
    {
        int tx=win->x, ty=win->y+miny, tw=win->width, th=maxy-miny+1;
        int maxw=WindowWidth/fontwidth, maxh=WindowHeight/fontheight;
        if(tw+tx>maxw) {
            tw= maxw-tx;
        }
        if(th+ty>maxh) {
            th= maxh-ty;
        }
        SDL_UpdateRect(screen, tx*fontwidth, ty*fontheight, tw*fontwidth, th*fontheight);
    }
}
Esempio n. 13
0
void curses_drawwindow(WINDOW *win)
{
    int i,j,w,drawx,drawy;
    unsigned tmp;

    SDL_Rect update_rect;
    update_rect.x = win->x * fontwidth;
    update_rect.w = win->width * fontwidth;
    update_rect.y = 9999; // default value
    update_rect.h = 9999; // default value

    int jr = 0;

    for (j=0; j<win->height; j++){
        if (win->line[j].touched)
        {
            if (update_rect.y == 9999)
            {
                update_rect.y = (win->y+j)*fontheight;
                jr=j;
            }
            update_rect.h = (j-jr+1)*fontheight;

            needupdate = true;

            win->line[j].touched=false;

            for (i=0,w=0; w<win->width; i++,w++){
                drawx=((win->x+w)*fontwidth);
                drawy=((win->y+j)*fontheight);//-j;
                if (((drawx+fontwidth)<=WindowWidth) && ((drawy+fontheight)<=WindowHeight)){
                const char* utf8str = win->line[j].chars+i;
                int len = ANY_LENGTH;
                tmp = UTF8_getch(&utf8str, &len);
                int FG = win->line[j].FG[w];
                int BG = win->line[j].BG[w];
                FillRectDIB(drawx,drawy,fontwidth,fontheight,BG);

                if ( tmp != UNKNOWN_UNICODE){
                    int cw = mk_wcwidth(tmp);
                    len = ANY_LENGTH-len;
                    if(cw>1)
                    {
                        FillRectDIB(drawx+fontwidth*(cw-1),drawy,fontwidth,fontheight,BG);
                        w+=cw-1;
                    }
                    if(len>1)
                    {
                        i+=len-1;
                    }
                    if(tmp) OutputChar(tmp, drawx,drawy,FG);
                } else {
                    switch ((unsigned char)win->line[j].chars[i]) {
                    case LINE_OXOX_C://box bottom/top side (horizontal line)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        break;
                    case LINE_XOXO_C://box left/right side (vertical line)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        break;
                    case LINE_OXXO_C://box top left
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case LINE_OOXX_C://box top right
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case LINE_XOOX_C://box bottom right
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                        break;
                    case LINE_XXOO_C://box bottom left
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                        break;
                    case LINE_XXOX_C://box bottom north T (left, right, up)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight,2,FG);
                        break;
                    case LINE_XXXO_C://box bottom east T (up, right, down)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        break;
                    case LINE_OXXX_C://box bottom south T (left, right, down)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case LINE_XXXX_C://box X (left down up right)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        break;
                    case LINE_XOXX_C://box bottom east T (left, down, up)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        break;
                    default:
                        break;
                    }
                    };//switch (tmp)
                }//(tmp < 0)
            };//for (i=0;i<_windows[w].width;i++)
        }
    };// for (j=0;j<_windows[w].height;j++)
    win->draw=false;                //We drew the window, mark it as so

    if (g && win == g->w_terrain && use_tiles)
    {
        update_rect.y = win->y*tilecontext->tile_height;
        update_rect.h = win->height*tilecontext->tile_height;
        update_rect.x = win->y*tilecontext->tile_width;
        update_rect.w = win->width*tilecontext->tile_width;
        //GfxDraw(thegame, win->x*fontwidth, win->y*fontheight, thegame->terrain_view_x, thegame->terrain_view_y, win->width*fontwidth, win->height*fontheight);
        tilecontext->draw(win->x * fontwidth, win->y * fontheight, g->ter_view_x, g->ter_view_y, tilecontext->terrain_term_x * fontwidth, tilecontext->terrain_term_y * fontheight);
    }
//*/
    if (update_rect.y != 9999)
    {
        SDL_UpdateRect(screen, update_rect.x, update_rect.y, update_rect.w, update_rect.h);
    }
    if (needupdate) try_update();
}
Esempio n. 14
0
static void OutputPadding (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos, int iPadding, char cPad)
{
  for (int i = 0; i < iPadding; ++i)
    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, cPad);
}
Esempio n. 15
0
static bool FormatUFloat (char* szOutputBuffer, unsigned int uiBufferSize, unsigned int& uiWritePos, double value, int iPrecision, unsigned int Flags, bool bRemoveZeroes)
{
  if (value < 0)
    value = - value;

  bool bRoundedUp = false;

  long long int uiIntPart = (long long int) value;

  char szFraction[128];
  int iFractionDigits = 0;

  double dRemainder = value - (double) uiIntPart;

  // make sure we don't write outside our buffer
  if (iPrecision > 64)
    iPrecision = 64;

  // When no precision is given a maximum of 6 fractional digits is written
  // However, all trailing zeros will be removed again, to shorten the number as much as possible
  const bool bRemoveTrailingZeros = bRemoveZeroes || (iPrecision < 0);
    
  if (iPrecision < 0)
    iPrecision = 6;

  for (int i = 0; i < iPrecision; ++i)
  {
    dRemainder *= 10.0f;
    long long int digit = (long long int) dRemainder;

    char cDigit = '0' + (char) (digit);
    szFraction[iFractionDigits++] = cDigit;

    dRemainder -= (double) digit;
  }

  // zero terminate the string
  szFraction[iFractionDigits] = '\0';

  // if the NEXT (not written digit) is 5 or larger, round the whole number up
  if (dRemainder >= 0.5)
  {
    if (RoundUpDigits (szFraction, iFractionDigits))
    {
      bRoundedUp = true;
      ++uiIntPart;
    }
  }

  if (bRemoveTrailingZeros)
    RemoveTrailingZeros (szFraction, iFractionDigits);


  {
    char szBuffer[128];
    int iNumDigits = 0;

    // for a 32 Bit Integer one needs at most 10 digits
    // for a 64 Bit Integer one needs at most 20 digits
    // However, FormatUInt allows to add extra padding, so make the buffer a bit larger
    FormatUInt (szBuffer, iNumDigits, uiIntPart, 10, false, 1);

    OutputReverseString (szOutputBuffer, uiBufferSize, uiWritePos, szBuffer, iNumDigits);
  }

  // if there is any fractional digit, or the user specifically requested it,
  // add the '.'
  if ((iFractionDigits > 0) || (Flags & sprintfFlags::Hash))
    OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '.');
    
  OutputString (szOutputBuffer, uiBufferSize, uiWritePos, szFraction, 0, 0, -1);

  return bRoundedUp;
}
Esempio n. 16
0
void curses_drawwindow(WINDOW *win)
{
    int i,j,w,drawx,drawy;
    unsigned tmp;

    for (j=0; j<win->height; j++){
        if (win->line[j].touched)
        {
            needupdate = true;

            win->line[j].touched=false;

            for (i=0,w=0; w<win->width; i++,w++){
                drawx=((win->x+w)*fontwidth);
                drawy=((win->y+j)*fontheight);//-j;
                if (((drawx+fontwidth)<=WindowWidth) && ((drawy+fontheight)<=WindowHeight)){
				const char* utf8str = win->line[j].chars+i;
				int len = ANY_LENGTH;
                tmp = UTF8_getch(&utf8str, &len);
                int FG = win->line[j].FG[w];
                int BG = win->line[j].BG[w];
                FillRectDIB(drawx,drawy,fontwidth,fontheight,BG);

                if ( tmp != UNKNOWN_UNICODE){
					int cw = mk_wcwidth((wchar_t)tmp);
					len = ANY_LENGTH-len;
					if(cw>1) 
					{
						FillRectDIB(drawx+fontwidth*(cw-1),drawy,fontwidth,fontheight,BG);
						w+=cw-1;
					}
					if(len>1)
					{
						i+=len-1;
					}
                    if(tmp) OutputChar(tmp, drawx,drawy,FG);
                } else {
                    switch ((unsigned char)win->line[j].chars[i]) {
                    case LINE_OXOX_C://box bottom/top side (horizontal line)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        break;
                    case LINE_XOXO_C://box left/right side (vertical line)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        break;
                    case LINE_OXXO_C://box top left
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case LINE_OOXX_C://box top right
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case LINE_XOOX_C://box bottom right
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                        break;
                    case LINE_XXOO_C://box bottom left
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                        break;
                    case LINE_XXOX_C://box bottom north T (left, right, up)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight,2,FG);
                        break;
                    case LINE_XXXO_C://box bottom east T (up, right, down)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        break;
                    case LINE_OXXX_C://box bottom south T (left, right, down)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case LINE_XXXX_C://box X (left down up right)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        break;
                    case LINE_XOXX_C://box bottom east T (left, down, up)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        break;
                    default:
                        break;
                    }
                    };//switch (tmp)
                }//(tmp < 0)
            };//for (i=0;i<_windows[w].width;i++)
        }
    };// for (j=0;j<_windows[w].height;j++)
    win->draw=false;                //We drew the window, mark it as so

    if (needupdate) try_update();
}
Esempio n. 17
0
int ezStringUtils::vsnprintf(char* szOutputBuffer, unsigned int uiBufferSize, const char* szFormat, va_list args0)
{
  va_list args;
  va_copy(args, args0);

  EZ_ASSERT(ezUnicodeUtils::IsValidUtf8(szFormat), "The sprintf format string must be valid Utf8.");

  // make sure the last character is a \0
  if ((szOutputBuffer) && (uiBufferSize > 0))
    szOutputBuffer[uiBufferSize - 1] = '\0';

  unsigned int uiReadPos = 0;
  unsigned int uiWritePos = 0;
  bool bError = false;

  while (szFormat[uiReadPos] != '\0')
  {
    const char c = szFormat[uiReadPos];

    ++uiReadPos;

    // if c is not %, just print it out and be done with it
    if (c != '%')
    {
      OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, c);
      continue;
    }

    // otherwise parse the formatting string to find out what has to be done
    char cNext = szFormat[uiReadPos];

    // *** parse the format string ***

    // first read the flags (as many as there are)
    unsigned int Flags = ReadFlags (szFormat, uiReadPos, cNext);
    // read the width of the field
    int iWidth = ReadWidth (szFormat, uiReadPos, cNext);
    // read the precision specifier
    int iPrecision = ReadPrecision (szFormat, uiReadPos, cNext);
    // read the input data 'length' (short / int / long it, float / double)
    const sprintfLength::Enum Length = ReadLength (szFormat, uiReadPos, cNext);
    // read the 'specifier' type
    const char cSpecifier = ReadSpecifier (szFormat, uiReadPos, cNext, bError);

    if (bError)
    {
      snprintf (szOutputBuffer, uiBufferSize, "Error in formatting string at position %u ('%c').", uiReadPos, cSpecifier);
      va_end(args);
      return -1;
    }

    // if 'width' was specified as '*', read it from an extra parameter
    if (iWidth < 0)
      iWidth = va_arg (args, int);

    // if 'precision' was specified as '*', read it from an extra parameter
    if (iPrecision == -2)
      iPrecision = va_arg (args, int);

    // % Sign
    if (cSpecifier == '%')
    {
      OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '%');
      continue;
    }

    // Nothing: Writes the current write position back to an int pointer
    if (cSpecifier == 'n')
    {
      int* p = va_arg (args, int*);
      if (p) 
        *p = (int) uiWritePos;
        
      continue;
    }

    // String
    if (cSpecifier == 's')
    {
      const char* s = va_arg (args, const char*);
      OutputString (szOutputBuffer, uiBufferSize, uiWritePos, s, Flags, iWidth, iPrecision);
      continue;
    }

    // Character
    if (cSpecifier == 'c')
    {
      char c2 = va_arg (args, int);
      char s[2] = {c2, 0};
      OutputString (szOutputBuffer, uiBufferSize, uiWritePos, s, Flags, iWidth, iPrecision);
      continue;
    }
Esempio n. 18
0
void DrawWindow(WINDOW *win)
{
    int i,j,drawx,drawy;
    char tmp;

    for (j=0; j<win->height; j++){
        if (win->line[j].touched)
        {
            needupdate = true;

            win->line[j].touched=false;

            for (i=0; i<win->width; i++){
                drawx=((win->x+i)*fontwidth);
                drawy=((win->y+j)*fontheight);//-j;
                if (((drawx+fontwidth)<=WindowWidth) && ((drawy+fontheight)<=WindowHeight)){
                tmp = win->line[j].chars[i];
                int FG = win->line[j].FG[i];
                int BG = win->line[j].BG[i];
                FillRectDIB(drawx,drawy,fontwidth,fontheight,BG);

                if ( tmp > 0){
                    OutputChar(tmp, drawx,drawy,1,FG);
                //    }     //and this line too.
                } else if (  tmp < 0 ) {
                    switch (tmp) {
                    case -60://box bottom/top side (horizontal line)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        break;
                    case -77://box left/right side (vertical line)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        break;
                    case -38://box top left
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case -65://box top right
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case -39://box bottom right
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                        break;
                    case -64://box bottom left
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight+1,2,FG);
                        break;
                    case -63://box bottom north T (left, right, up)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+halfheight,2,FG);
                        break;
                    case -61://box bottom east T (up, right, down)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        HorzLineDIB(drawx+halfwidth,drawy+halfheight,drawx+fontwidth,1,FG);
                        break;
                    case -62://box bottom south T (left, right, down)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy+halfheight,drawy+fontheight,2,FG);
                        break;
                    case -59://box X (left down up right)
                        HorzLineDIB(drawx,drawy+halfheight,drawx+fontwidth,1,FG);
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        break;
                    case -76://box bottom east T (left, down, up)
                        VertLineDIB(drawx+halfwidth,drawy,drawy+fontheight,2,FG);
                        HorzLineDIB(drawx,drawy+halfheight,drawx+halfwidth,1,FG);
                        break;
                    default:
                        // SetTextColor(DC,_windows[w].line[j].chars[i].color.FG);
                        // TextOut(DC,drawx,drawy,&tmp,1);
                        break;
                    }
                    };//switch (tmp)
                }//(tmp < 0)
            };//for (i=0;i<_windows[w].width;i++)
        }
    };// for (j=0;j<_windows[w].height;j++)
    win->draw=false;                //We drew the window, mark it as so

    if (needupdate) try_update();
}
Esempio n. 19
0
// Serves a page by interpreting command codes, processing script commands,
// and handling variable substitution. Any variables provided in the override_list
// will take precedence over variables of the same name defined in the page. 
int ServePageWithOverride(char *page, int page_size, PageVar *override_list) {
  // Initialize varlist
  PageVar *varlist = calloc(sizeof(PageVar), 1);
  VerifyPointerOrTerminate(varlist, "VarList initialization");
  in_a_box = 0;
  cgc_memset(line, '\0', sizeof(line));
  line_length = 0;
  
  #ifdef PATCHED
  if (page == NULL) {
    goto error;
  }
  #endif

  while ((*page != '\0')&&(page < page + page_size)) {
    if (*page == '~') {
      // Command character, process command
      page++;
      switch (*page) {
        case 't': {
          for (int i=0; i<4; i++) {
            OutputChar(' ');
          }
          break;
        }
        case 'n': {
          FlushOutput();
          break;
        }
        case '[': {
          OutputChar('[');
          break;
        }
        case ']': {
          OutputChar(']');
          break;
        }
        case '~': {
          OutputChar('~');
          break;
        }
        case '#': {
          OutputChar('#');
          break;
        }
        default: {
          printf("ERROR: Invalid control code\n");
          goto error;
        }
      }
      page++;
    } else if (*page == '[') {
      // Script tag, find closing tag and process script
      char *close = ++page;
      while (*close != ']' && *close != '\0') close++;
      if (*close == '\0') {
        goto error;
      }
      // Process script commands
      if (strncmp(page, "line", cgc_strlen("line")) == 0) {
        page += cgc_strlen("line");
        if (*page != ':') {
          goto error;
        }
        char c = *(++page);
        if (*(++page) != ':') {
          goto error;
        }
        int length = atoi(++page);
        for (int i = 0; i < length; i++) {
          OutputChar(c);
        }
        page = close + 1;
      } else if (strncmp(page, "var", cgc_strlen("var")) == 0) {
        AddPageVar(varlist, page);
        page = close + 1;
      } else if (strncmp(page, "box", cgc_strlen("box")) == 0) {
        in_a_box = 1;
        FlushOutput();
        for (int i = 0; i < 80; i++) {
          putc('*');
        }
        printf("\n");
        page += 4;
      } 
    } else if (*page == ']') {
      page++;
      if (in_a_box) {
        in_a_box = 0;
        FlushOutput();
        for (int i = 0; i < 80; i++) {
          putc('*');
        }
        printf("\n");
      } else {
        goto error;
      }
    } else if (*page == '#') {
      // Variable substitution
      char *end = ++page;
      while (*end != '\0' && *end != '#') { end++; }
      if (*end != '#') {
        goto error;
      }
      PageVar *var = NULL;
      // Check for overridden variables
      if (override_list != NULL) {
        var = GetPageVar(override_list, page, end);
      }
      // Fall back to default values if override doesn't exist
      if (var == NULL) {
        var = GetPageVar(varlist, page, end);
      }
      // If a value has been found, output it
      if (var != NULL) {
        OutputStr(var->value);
      }
      page = end + 1;
    } else {
      // Normal character, send to output
      OutputChar(*page);
      page++;
    }
  }
  if (line_length != 0) {
    FlushOutput();
  }
  DestroyVarList(varlist);
  DestroyVarList(override_list);
  return 0;

error:
  printf("ERROR: Invalid syntax\n");
  DestroyVarList(varlist);
  DestroyVarList(override_list);
  return -1;
}