コード例 #1
0
ファイル: sprintf.c プロジェクト: JFLarvoire/SysToolsLib
extern int _vsnprintf(char *pszOutput, size_t uSize, const char *pszFormat, va_list pArgs)
    {
    int *pparms;	    // Pointer to the optional arguments following the format
    char c;
    char cFill;
    char szTempBuf[80];
    char far *lpszTemp;
    char *pszOutput0 = pszOutput;
    int iRequested;	    // Requested width for an output field
    int iAvailable;	    // Number of characters available for output
    int iLong;		    // TRUE if the %l modifier has been provided

    pparms = (int *)pArgs;

    while (c = *(pszFormat++))
	{
	if (c == '%')	  // If c is the format escape character.
	    {
	    cFill = ' ';   // Default filler for the left side of output fields
	    if (*pszFormat == '0')
		{
		cFill = '0';		// Optional filler
		pszFormat += 1; 	// Skip the 0
		}

	    if (*pszFormat == '*')	// If variable length format
		{
		iRequested = *(pparms++); // Get the size from the argument list
		pszFormat += 1; 	  // Skip the *
		}
	    else			// Else fixed length format
		{
		// Convert the field size to an int, and advance past the size in format.
		pszFormat += stcd_i(pszFormat, &iRequested);
		}

	    iLong = FALSE;
test_format:
	    switch (*(pszFormat++))    // The next char is the format ID.
		{
		case 'd':
		    if (!iLong)
			iAvailable = stci_d(szTempBuf, *(pparms++)); // Convert int to string
		    else
			iAvailable = stcli_d(szTempBuf, *(((long *)pparms)++)); // Convert int to string
		    pszOutput += strcpyform(pszOutput, szTempBuf, iRequested, iAvailable, cFill);
		    break;
		case 'u':
		    iAvailable = stcu_d(szTempBuf, *(pparms++)); // Convert uint to string
		    pszOutput += strcpyform(pszOutput, szTempBuf, iRequested, iAvailable, cFill);
		    break;
		case 'p':
		    if (iLong)
			pszOutput += sprintf(pszOutput, "%04X:", pparms[1]);
		    pszOutput += sprintf(pszOutput, "%04X", pparms[0]);
		    pparms += iLong+1;
		    break;
		case 'x':   // Incompatible! Processed as %X to save space.
		case 'X':
		    if (!iLong)
			iAvailable = stci_h(szTempBuf, *(pparms++)); // Convert uint to hex. string
		    else
			iAvailable = stcli_h(szTempBuf, *(((long *)pparms)++)); // Convert uint to hex. string
		    pszOutput += strcpyform(pszOutput, szTempBuf, iRequested, iAvailable, cFill);
		    break;
		case 's':
		    if (!iLong)
			lpszTemp = *(((char **)pparms)++);		 // Pointer on the given string
		    else
			lpszTemp = *(((char far **)pparms)++);		 // Pointer on the given string
		    pszOutput += strcpyform(pszOutput, lpszTemp, iRequested, fstrlen(lpszTemp), cFill);
		    break;
		case 'c':
		    *pparms &= 0x00FF;	 // Make sure the char is followed by a NUL.
		    pszOutput += strcpyform(pszOutput, (char *)(pparms++), iRequested, 1, ' ');
		    break;
		case '%':
		    *(pszOutput++) = '%';
		    break;
		case 'l':
		case 'F':
		    iLong = TRUE;
		    goto test_format;	 // Ignore long integer specifications
		default:    // Unsupported format. Just output question marks
		    pszOutput += strcpyform(pszOutput, "", iRequested, 0, '?');
		    break;
		}
	    }
	else		  // Else c is a normal character
	    {
	    *(pszOutput++) = c;  // Just copy it to the output
	    }
	}
    *pszOutput = '\0';
    return pszOutput - pszOutput0;   // Number of characters written
    }
コード例 #2
0
/*get:	This function gets information about the current picture/playlist*/
void rGet(char *p)
{
   p++;

   /*The picture's filename*/
   if(stricmp(p,"name")==0)
      strcpy(arexxBuf,picFilename);

   /*The picture width*/
   else if(stricmp(p,"width")==0)
      stcu_d(arexxBuf,prevScreen->Width);

   /*The height*/
   else if(stricmp(p,"height")==0)
      stcu_d(arexxBuf,prevScreen->Height);

   /*The number of bitplanes*/
   else if(stricmp(p,"depth")==0)
      stcu_d(arexxBuf,prevScreen->BitMap.Depth);

   /*The viewmodes of the picture (HAM, HIRES, LACE, etc.*/
   else if(stricmp(p,"viewmodes")==0)
      stci_h(arexxBuf,prevScreen->ViewPort.Modes);

   else if(stricmp(p,"specialmodes")==0)
      switch(specialModes)
      {
	 case NORMAL:
	    strcpy(arexxBuf,"NONE");
	    break;
	 case SHAM:
	    strcpy(arexxBuf,"SHAM");
	    break;
	 case MACROPAINT:
	    strcpy(arexxBuf,"MACROPAINT");
	    break;
      }

   /*The time left to display this picture*/
   else if(stricmp(p,"timeleft")==0)
      stcu_d(arexxBuf,ticksRemaining);

   /*The time to display each picture*/
   else if(stricmp(p,"timeperpicture")==0)
      stcu_d(arexxBuf,ticks);

   /*The version number and date of this program*/
   else if(stricmp(p,"version")==0)
      strcpy(arexxBuf,&version[12]);

   /*The name of the playlist, or '?NONE?' if there is no playlist*/
   else if(stricmp(p,"playlistname")==0)
      if(playListFilename==NULL)
	 strcpy(arexxBuf,"?NONE?");
      else
	 strcpy(arexxBuf,playListFilename);

   /*Returns 'TRUE' if the user specified 'loop' on the command line, 'FALSE'*/
   /*if he didn't*/
   else if(stricmp(p,"looping")==0)
      if(loop)
	 strcpy(arexxBuf,"TRUE");
      else
	 strcpy(arexxBuf,"FALSE");

   /*Returns 'TRUE' if the user specified 'print' on the command line,*/
   /*FALSE if she didn't*/
   else if(stricmp(p,"printpictures")==0)
      if(printPics)
	 strcpy(arexxBuf,"TRUE");
      else
	 strcpy(arexxBuf,"FALSE");

   else if(stricmp(p,"cyclerate")==0)
      if(numCycleColors!=0)
	 stcu_d(arexxBuf,rate);
      else
	 strcpy(arexxBuf,"-VOID-");

   else if(stricmp(p,"cyclestatus")==0)
      if(cycle)
	 strcpy(arexxBuf,"CYCLING");
      else
	 if(numCycleColors!=0)
	    strcpy(arexxBuf,"CYCLINGPAUSED");
	 else
	    strcpy(arexxBuf,"NOCYCLING");

   /*Otherwise, we don't understand, so return an error*/
   else
   {
      errorNum=100;
      strcpy(arexxBuf,"ERROR");
   }
}