Пример #1
0
void
DJManageDaemonsDescription(
    BOOLEAN bStart,
    PSTR *description,
    LWException **exc
    )
{
    BOOLEAN bFileExists = TRUE;
    LWException *innerExc = NULL;
    StringBuffer buffer;
    PSTR daemonDescription = NULL;

    LW_CLEANUP_CTERR(exc, CTStringBufferConstruct(&buffer));

    LW_CLEANUP_CTERR(exc, CTCheckFileExists(PWGRD, &bFileExists));
    if(bFileExists && bStart)
    {
        LW_CLEANUP_CTERR(exc, CTStringBufferAppend(&buffer, "Shutdown pwgrd because it only handles usernames up to 8 characters long. This is done by running '/sbin/init.d/pwgr stop' and setting PWGR=0 in "PWGRD"."));
    }

    *description = CTStringBufferFreeze(&buffer);

cleanup:
    CT_SAFE_FREE_STRING(daemonDescription);
    LW_HANDLE(&innerExc);
    CTStringBufferDestroy(&buffer);
}
Пример #2
0
DWORD CTWordWrap(PCSTR input, PSTR *output, int tabWidth, int columns)
{
    DWORD ceError = ERROR_SUCCESS;
    StringBuffer result;
    int pos = 0;
    int start;
    int column;
    int i;
    int previousIndent = -1;
    int nextIndent;

    memset(&result, 0, sizeof(result));

    while(input[pos] != '\0')
    {
        int indentColumns;
        int lastWhite = 0;
        start = pos;
        column = 0;
        while(input[pos] == ' ' || input[pos] == '\t')
        {
            column += CharLen(input[pos], tabWidth);
            pos++;
        }
        indentColumns = column;
        nextIndent = NextLineIndent(input + pos, tabWidth);
        if(indentColumns > 0 && (nextIndent == indentColumns ||
                previousIndent == indentColumns))
        {
            //The line following this one is indented the same amount. If this
            //line wraps, we'll indent it an extra tab to differentiate the
            //two lines.
            indentColumns += tabWidth;
        }
        if(input[pos] == '\r' && input[pos] == '\n')
        {
            //Blank lines don't have indents
            previousIndent = -1;
        }
        else
            previousIndent = column;

        for(i = 0; i < column; i++)
        {
            ceError = CTStringBufferAppendLength(&result, " ", 1);
            CLEANUP_ON_DWORD(ceError);
        }
        start = pos;
        while(input[pos] != '\n' && input[pos] != '\r' && input[pos] != '\0')
        {
            if(input[pos] == '\f')
            {
                //This marks how far to indent the text
                ceError = CTStringBufferAppendLength(&result, input + start, pos - start);
                CLEANUP_ON_DWORD(ceError);
                indentColumns = column;
                pos++;
                start = pos;
            }
            if(column + CharLen(input[pos], tabWidth) > columns && columns != -1)
            {
                //Wrap the line

                //If there was any white space in this line, break it there,
                //otherwise break it in the middle of the word
                if(lastWhite > start)
                    pos = lastWhite;
                //First the text in this line
                ceError = CTStringBufferAppendLength(&result, input + start, pos - start);
                CLEANUP_ON_DWORD(ceError);
                //Now add the newline
                ceError = CTStringBufferAppendLength(&result, "\n", 1);
                CLEANUP_ON_DWORD(ceError);
                //Finally the indent for the new line
                for(column = 0; column < indentColumns; column++)
                {
                    ceError = CTStringBufferAppendLength(&result, " ", 1);
                    CLEANUP_ON_DWORD(ceError);
                }
     
                //Skip any whitespace
                while(input[pos] == ' ' || input[pos] == '\t')
                {
                    pos++;
                }
                start = pos;
                continue;
            }
            if(isspace((int)input[pos]))
                lastWhite = pos;
            if(input[pos] == '\t')
            {
                //First add the text before the tab
                ceError = CTStringBufferAppendLength(&result, input + start, pos - start);
                CLEANUP_ON_DWORD(ceError);
                //Now expand the tab into spaces
                for(i = 0; i < tabWidth; i++)
                {
                    ceError = CTStringBufferAppendLength(&result, " ", 1);
                    CLEANUP_ON_DWORD(ceError);
                }
                start = pos + 1;
            }
            column += CharLen(input[pos], tabWidth);
            pos++;
        }
        if(input[pos] == '\n')
            pos++;
        if(input[pos] == '\r')
            pos++;
        //Copy the line
        ceError = CTStringBufferAppendLength(&result, input + start, pos - start);
        CLEANUP_ON_DWORD(ceError);
    }
    ceError = CTStringBufferAppendLength(&result, "\0", 1);
    CLEANUP_ON_DWORD(ceError);

    *output = result.data;
    result.data = NULL;

cleanup:
    CTStringBufferDestroy(&result);
    return ceError;
}