Esempio n. 1
0
void PrintUsage(bool fSummaryUsage)
{
    size_t width = GetConsoleWidth();
    const char* psz = fSummaryUsage ? stunclient_lite_text : stunclient_text;

    // save some margin space
    if (width > 2)
    {
        width -= 2;
    }

    PrettyPrint(psz, width);
}
Esempio n. 2
0
/*
 * start of mainline
 */
int main( int argc, char *argv[] )
{
    int i,ch;

#ifndef __QNX__
    maxwidth = GetConsoleWidth();
#else
    maxwidth = LINE_WIDTH;              /* for now */
#endif

    maxwidth /= COLUMN_WIDTH;

    for( ;; ) {
        ch = GetOpt( &argc, argv, "dfr", usageMsg );
        if( ch == -1 ) {
            break;
        }
        switch( ch ) {
        case 'd':
            directories_only = 1;
            break;
        case 'f':
            files_only = 1;
            break;
        case 'r':
            separate_read_only = 1;
            break;
        }
    }

    if( directories_only && files_only ) {
        directories_only = files_only = 0;
    }
    if( argc == 1 ) {
        DoLC( "." );
    } else {
        for( i=1;i<argc;i++ ) {
            printf("%s:\n",argv[i]);
            DoLC( argv[i] );
        }
    }
    return( 0 );
} /* main */
Esempio n. 3
0
int main( int argc, char *argv[] )
{
    int         i;
    FILE        *f;
    int         rxflag;
    int         buff_stdin;
    int         ch;

    screenHeight = GetConsoleHeight();
    screenWidth = GetConsoleWidth();

    workBuff = MemAlloc( BUFF_SIZE );
    buff_stdin = 1;
    rxflag = 0;

    for( ;; ) {
        ch = GetOpt( &argc, argv, "#cftXp:n:", usageMsg );
        if( ch == -1 ) {
            break;
        }
        switch( ch ) {
        case 'c':
            clearScreen = 1;
            break;
        case 'f':
            foldLines = 0;
            break;
        case 't':
            buff_stdin = 0;
            break;
        case 'n':
            screenHeight = atoi( OptArg )+1;
            break;
        case 'p':
            promptString = strdup( OptArg );
            break;
        case '#':
            startLine = atol( OptArg )-1;
            break;
        case 'X':
            rxflag = 1;
            break;
        }
    }

    argv = ExpandArgv( &argc, argv, rxflag );

    lineCount = screenHeight-1;

    if( argc == 1 ) {
        if( buff_stdin ) {
            f = tmpfile();
            if( f == NULL ) {
                exit( 1 );
            }
            setmode( fileno( f ), O_BINARY );
            for( ;; ) {
                i = fread( workBuff, 1, BUFF_SIZE, stdin );
                if( fwrite( workBuff, 1, i, f ) != i ) {
                    exit( 1 );
                }
                if( feof( stdin ) ) {
                    break;
                }
            }
            fflush( f );
            doMore( "*stdin*", f );
        } else {
            doMore( "*stdin*", stdin );
        }
    } else {
        for( i=1;i<argc;i++ ) {
            f = fopen( argv[i],"rb" );
            if( f == NULL ) {
                printf( "Error opening \"%s\"\n", argv[i] );
            } else {
                if( argc > 2 ) {
                    printf( "\n%s:\n", FNameLower( argv[i] ) );
                }
                doMore( argv[i], f );
            }
        }
    }
    return( 0 );
}
Esempio n. 4
0
// Display the help of the candidate list
void PrintCandidateHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *candidate_list, UINT left_space)
{
	UINT console_width;
	UINT max_keyword_width;
	LIST *o;
	UINT i;
	wchar_t *tmpbuf;
	UINT tmpbuf_size;
	char *left_space_array;
	char *max_space_array;
	// Validate arguments
	if (c == NULL || candidate_list == NULL)
	{
		return;
	}

	// Get the width of the screen
	console_width = GetConsoleWidth(c) - 1;

	tmpbuf_size = sizeof(wchar_t) * (console_width + 32);
	tmpbuf = Malloc(tmpbuf_size);

	left_space_array = MakeCharArray(' ', left_space);

	// Sort and enlist the command name
	// no need to sort the parameter name
	o = NewListFast(cmd_name == NULL ? CompareCandidateStr : NULL);

	max_keyword_width = 0;

	for (i = 0;i < candidate_list->NumTokens;i++)
	{
		UINT keyword_width;

		// Get the width of each keyword
		Insert(o, candidate_list->Token[i]);

		keyword_width = StrWidth(candidate_list->Token[i]);
		if (cmd_name != NULL)
		{
			if (candidate_list->Token[i][0] != '[')
			{
				keyword_width += 1;
			}
			else
			{
				keyword_width -= 2;
			}
		}

		max_keyword_width = MAX(max_keyword_width, keyword_width);
	}

	max_space_array = MakeCharArray(' ', max_keyword_width);

	// Display the candidate
	for (i = 0;i < LIST_NUM(o);i++)
	{
		char tmp[128];
		char *name = LIST_DATA(o, i);
		UNI_TOKEN_LIST *t;
		wchar_t *help;
		UINT j;
		UINT keyword_start_width = left_space;
		UINT descript_start_width = left_space + max_keyword_width + 1;
		UINT descript_width;
		char *space;

		if (console_width >= (descript_start_width + 5))
		{
			descript_width = console_width - descript_start_width - 3;
		}
		else
		{
			descript_width = 2;
		}

		// Generate the name
		if (cmd_name != NULL && name[0] != '[')
		{
			// Prepend a "/" in the case of a parameter
			Format(tmp, sizeof(tmp), "/%s", name);
		}
		else
		{
			// Use the characters as it is in the case of a command name
			if (cmd_name == NULL)
			{
				StrCpy(tmp, sizeof(tmp), name);
			}
			else
			{
				StrCpy(tmp, sizeof(tmp), name + 1);
				if (StrLen(tmp) >= 1)
				{
					tmp[StrLen(tmp) - 1] = 0;
				}
			}
		}

		// Get the help string
		if (cmd_name == NULL)
		{
			GetCommandHelpStr(name, &help, NULL, NULL);
		}
		else
		{
			GetCommandParamHelpStr(cmd_name, name, &help);
		}

		space = MakeCharArray(' ', max_keyword_width - StrWidth(name) - (cmd_name == NULL ? 0 : (name[0] != '[' ? 1 : -2)));

		t = SeparateStringByWidth(help, descript_width);

		for (j = 0;j < t->NumTokens;j++)
		{
			if (j == 0)
			{
				UniFormat(tmpbuf, tmpbuf_size, L"%S%S%S - %s",
					left_space_array, tmp, space, t->Token[j]);
			}
			else
			{
				UniFormat(tmpbuf, tmpbuf_size, L"%S%S   %s",
					left_space_array, max_space_array, t->Token[j]);
			}

			c->Write(c, tmpbuf);
		}

		Free(space);

		UniFreeToken(t);
	}

	ReleaseList(o);

	Free(max_space_array);
	Free(tmpbuf);
	Free(left_space_array);
}
Esempio n. 5
0
// Display the help for the command
void PrintCmdHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *param_list)
{
	wchar_t tmp[MAX_SIZE];
	wchar_t *buf;
	UINT buf_size;
	wchar_t *description, *args, *help;
	UNI_TOKEN_LIST *t;
	UINT width;
	UINT i;
	char *space;
	// Validate arguments
	if (c == NULL || cmd_name == NULL || param_list == NULL)
	{
		return;
	}

	width = GetConsoleWidth(c) - 2;

	buf_size = sizeof(wchar_t) * (width + 32);
	buf = Malloc(buf_size);

	GetCommandHelpStr(cmd_name, &description, &args, &help);

	space = MakeCharArray(' ', 2);

	// Title
	UniFormat(tmp, sizeof(tmp), _UU("CMD_HELP_TITLE"), cmd_name);
	c->Write(c, tmp);
	c->Write(c, L"");

	// Purpose
	c->Write(c, _UU("CMD_HELP_DESCRIPTION"));
	t = SeparateStringByWidth(description, width - 2);
	for (i = 0;i < t->NumTokens;i++)
	{
		UniFormat(buf, buf_size, L"%S%s", space, t->Token[i]);
		c->Write(c, buf);
	}
	UniFreeToken(t);
	c->Write(c, L"");

	// Description
	c->Write(c, _UU("CMD_HELP_HELP"));
	t = SeparateStringByWidth(help, width - 2);
	for (i = 0;i < t->NumTokens;i++)
	{
		UniFormat(buf, buf_size, L"%S%s", space, t->Token[i]);
		c->Write(c, buf);
	}
	UniFreeToken(t);
	c->Write(c, L"");

	// Usage
	c->Write(c, _UU("CMD_HELP_USAGE"));
	t = SeparateStringByWidth(args, width - 2);
	for (i = 0;i < t->NumTokens;i++)
	{
		UniFormat(buf, buf_size, L"%S%s", space, t->Token[i]);
		c->Write(c, buf);
	}
	UniFreeToken(t);

	// Arguments
	if (param_list->NumTokens >= 1)
	{
		c->Write(c, L"");
		c->Write(c, _UU("CMD_HELP_ARGS"));
		PrintCandidateHelp(c, cmd_name, param_list, 2);
	}

	Free(space);

	Free(buf);
}