Exemplo n.º 1
0
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
    }
Exemplo n.º 2
0
/*
 * This routine initializes an ARexx port for your process
 * This should only be done once per process.  You must call it
 * with a valid application name and you must use the handle it
 * returns in all other calls...
 *
 * NOTE:  The AppName should not have spaces in it...
 *        Example AppNames:  "MyWord" or "FastCalc" etc...
 *        The name *MUST* be less that 16 characters...
 *        If it is not, it will be trimmed...
 *        The name will also be UPPER-CASED...
 *
 * NOTE:  The Default file name extension, if NULL will be
 *        "rexx"  (the "." is automatic)
 */
AREXXCONTEXT
InitARexx(char *AppName,char *Extension)
{
    register	AREXXCONTEXT	RexxContext=NULL;
    register	short		loop;
    register	short		count;
    register	char		*tmp;

    if (RexxContext=AllocMem(sizeof(struct ARexxContext),
			     MEMF_PUBLIC|MEMF_CLEAR))
    {
	if (RexxContext->arc_RexxSysBase=OpenLibrary("rexxsyslib.library",
						     NULL))
	{
	    /*
	     * Set up the extension...
	     */
	    if (!Extension) Extension="rexx";
	    tmp=RexxContext->Extension;
	    for (loop=0;(loop<7)&&(Extension[loop]);loop++)
	    {
		*tmp++=Extension[loop];
	    }
	    *tmp='\0';

	    /*
	     * Set up a port name...
	     */
	    tmp=RexxContext->PortName;
	    for (loop=0;(loop<16)&&(AppName[loop]);loop++)
	    {
		*tmp++=toupper(AppName[loop]);
	    }
	    *tmp='\0';


	    /* We need to make a unique port name... */
	    Forbid();
	    for (count=1,RexxContext->ARexxPort=(VOID *)1;
		 RexxContext->ARexxPort;count++)
	    {
		stci_d(tmp,count);
		RexxContext->ARexxPort=
		    FindPort(RexxContext->PortName);
	    }

	    RexxContext->ARexxPort=CreatePort(
		RexxContext->PortName,NULL);
	    Permit();
	    
	    /*
	     * Set up the last error RVI name...
	     *
	     * This is <appname>.LASTERROR
	     */
	    strcpy(RexxContext->ErrorName,RexxContext->PortName);
	    strcat(RexxContext->ErrorName,".LASTERROR");
	}

	if (	(!(RexxContext->arc_RexxSysBase))
		||	(!(RexxContext->ARexxPort))	)
	{
	    FreeARexx(RexxContext);
	    RexxContext=NULL;
	}
    }
    return(RexxContext);
}