Beispiel #1
0
INT CommandHistory (LPTSTR param)
{
	LPTSTR tmp;
	INT tmp_int;
	LPHIST_ENTRY h_tmp;
	TCHAR szBuffer[2048];

	tmp=_tcschr(param,_T('/'));

	if (tmp)
	{
		param=tmp;
		switch (_totupper(param[1]))
		{
			case _T('F'):/*delete history*/
				CleanHistory();InitHistory();
				break;

			case _T('R'):/*read history from standard in*/
				//hIn=GetStdHandle (STD_INPUT_HANDLE);

				for(;;)
				{
					ConInString(szBuffer,sizeof(szBuffer)/sizeof(TCHAR));
					if (*szBuffer!=_T('\0'))
						History(0,szBuffer);
					else
						break;
				}
				break;

			case _T('A'):/*add an antry*/
				History(0,param+2);
				break;

			case _T('S'):/*set history size*/
				if ((tmp_int=_ttoi(param+2)))
					set_size(tmp_int);
				break;

			default:
				return 1;
		}
	}
	else
	{
		for (h_tmp = Top->prev; h_tmp != Bottom; h_tmp = h_tmp->prev)
			ConErrPuts(h_tmp->string);
	}
	return 0;
}
Beispiel #2
0
INT cmd_time (LPTSTR param)
{
	LPTSTR *arg;
	INT    argc;
	INT    i;
	INT    nTimeString = -1;

	if (!_tcsncmp (param, _T("/?"), 2))
	{
		ConOutResPaging(TRUE,STRING_TIME_HELP1);
		return 0;
	}

  nErrorLevel = 0;

	/* build parameter array */
	arg = split (param, &argc, FALSE, FALSE);

	/* check for options */
	for (i = 0; i < argc; i++)
	{
		if (_tcsicmp (arg[i], _T("/t")) == 0)
		{
			/* Display current time in short format */
			SYSTEMTIME st;
			TCHAR szTime[20];
			GetLocalTime(&st);
			FormatTime(szTime, &st);
			ConOutPuts(szTime);
			freep(arg);
			return 0;
		}

		if ((*arg[i] != _T('/')) && (nTimeString == -1))
			nTimeString = i;
	}

	if (nTimeString == -1)
	{
		ConOutResPrintf(STRING_LOCALE_HELP1);
		ConOutPrintf(_T(": %s\n"), GetTimeString());
	}

	while (1)
	{
		if (nTimeString == -1)
		{
			TCHAR  s[40];

			ConOutResPuts(STRING_TIME_HELP2);

			ConInString (s, 40);

			TRACE ("\'%s\'\n", debugstr_aw(s));

			while (*s && s[_tcslen (s) - 1] < _T(' '))
				s[_tcslen(s) - 1] = _T('\0');

			if (ParseTime (s))
			{
				freep (arg);
				return 0;
			}
		}
		else
		{
			if (ParseTime (arg[nTimeString]))
			{
				freep (arg);
				return 0;
			}

			/* force input the next time around. */
			nTimeString = -1;
		}

		ConErrResPuts(STRING_TIME_ERROR1);
    nErrorLevel = 1;
	}

	freep (arg);

	return 0;
}
Beispiel #3
0
INT cmd_set (LPTSTR param)
{
	LPTSTR p;
	LPTSTR lpEnv;
	LPTSTR lpOutput;

	if ( !_tcsncmp (param, _T("/?"), 2) )
	{
		ConOutResPaging(TRUE,STRING_SET_HELP);
		return 0;
	}

	param = (LPTSTR)skip_ws(param);

	/* if no parameters, show the environment */
	if (param[0] == _T('\0'))
	{
		lpEnv = (LPTSTR)GetEnvironmentStrings ();
		if (lpEnv)
		{
			lpOutput = lpEnv;
			while (*lpOutput)
			{
				if (*lpOutput != _T('='))
					ConOutPuts(lpOutput);
				lpOutput += _tcslen(lpOutput) + 1;
			}
			FreeEnvironmentStrings (lpEnv);
		}

		return 0;
	}

	/* the /A does *NOT* have to be followed by a whitespace */
	if ( !_tcsnicmp (param, _T("/A"), 2) )
	{
		BOOL Success;
		StripQuotes(param);
		Success = seta_eval ( skip_ws(param+2) );
		if(!Success)
		{
			/*might seem random but this is what windows xp does */
			nErrorLevel = 9165;
		}
		return !Success;
	}

	if (!_tcsnicmp(param, _T("/P"), 2))
	{
		TCHAR value[1023];
		param = GetQuotedString((LPTSTR)skip_ws(param + 2));
		p = _tcschr(param, _T('='));
		if (!p)
		{
			ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
			nErrorLevel = 1;
			return 1;
		}

		*p++ = _T('\0');
		ConOutPrintf(_T("%s"), GetQuotedString(p));
		ConInString(value, 1023);

		if (!*value || !SetEnvironmentVariable(param, value))
		{
			nErrorLevel = 1;
			return 1;
		}
		return 0;
	}

	param = GetQuotedString(param);

	p = _tcschr (param, _T('='));
	if (p)
	{
		/* set or remove environment variable */
		if (p == param)
		{
			/* handle set =val case */
			ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT);
			nErrorLevel = 1;
			return 1;
		}

		*p++ = _T('\0');
		if (!SetEnvironmentVariable(param, *p ? p : NULL))
		{
			nErrorLevel = 1;
			return 1;
		}
	}
	else
	{
		/* display all environment variable with the given prefix */
		BOOL bFound = FALSE;

		while (_istspace(*param) || *param == _T(',') || *param == _T(';'))
			param++;

		p = _tcsrchr(param, _T(' '));
		if (!p)
			p = param + _tcslen(param);
		*p = _T('\0');

		lpEnv = GetEnvironmentStrings();
		if (lpEnv)
		{
			lpOutput = lpEnv;
			while (*lpOutput)
			{
				if (!_tcsnicmp(lpOutput, param, p - param))
				{
					ConOutPuts(lpOutput);
					bFound = TRUE;
				}
				lpOutput += _tcslen(lpOutput) + 1;
			}
			FreeEnvironmentStrings(lpEnv);
		}

		if (!bFound)
		{
			ConErrResPrintf (STRING_PATH_ERROR, param);
			nErrorLevel = 1;
			return 1;
		}
	}

	return 0;
}
Beispiel #4
0
INT cmd_date (LPTSTR param)
{
    LPTSTR *arg;
    INT    argc;
    INT    i;
    BOOL   bPrompt = TRUE;
    INT    nDateString = -1;

    if (!_tcsncmp (param, _T("/?"), 2))
    {
        ConOutResPaging(TRUE,STRING_DATE_HELP4);
        return 0;
    }

    nErrorLevel = 0;

    /* build parameter array */
    arg = split (param, &argc, FALSE, FALSE);

    /* check for options */
    for (i = 0; i < argc; i++)
    {
        if (_tcsicmp (arg[i], _T("/t")) == 0)
            bPrompt = FALSE;
        if ((*arg[i] != _T('/')) && (nDateString == -1))
            nDateString = i;
    }

    if (nDateString == -1)
        ConOutPrintf(_T("%s"), GetDateString());

    if (!bPrompt)
    {
        freep (arg);
        return 0;
    }

    if (nDateString == -1)
    {
        while (TRUE)  /* forever loop */
        {
            TCHAR s[40];

            PrintDateString ();
            ConInString (s, 40);
            TRACE ("\'%s\'\n", debugstr_aw(s));
            while (*s && s[_tcslen (s) - 1] < _T(' '))
                s[_tcslen (s) - 1] = _T('\0');
            if (ParseDate (s))
            {
                freep (arg);
                return 0;
            }
            ConErrResPuts(STRING_DATE_ERROR);
        }
    }
    else
    {
        if (!ParseDate (arg[nDateString]))
        {
            while (TRUE)  /* forever loop */
            {
                TCHAR s[40];
                ConErrResPuts(STRING_DATE_ERROR);

                PrintDateString ();
                ConInString (s, 40);

                while (*s && s[_tcslen (s) - 1] < _T(' '))
                    s[_tcslen (s) - 1] = _T('\0');
                if (ParseDate (s))
                {
                    freep (arg);
                    return 0;
                }
            }
        }
    }

    freep (arg);
    return 0;
}
Beispiel #5
0
INT cmd_label (LPTSTR param)
{
	TCHAR  szRootPath[] = _T("A:\\");
	TCHAR  szLabel[80];
	TCHAR  szOldLabel[80];
	DWORD  dwSerialNr;

	/* set empty label string */
	szLabel[0] = _T('\0');

	nErrorLevel = 0;

	/* print help */
	if (!_tcsncmp (param, _T("/?"), 2))
	{
		ConOutResPaging(TRUE,STRING_LABEL_HELP1);
		return 0;
	}

	/* get parameters */
	if (param[0] != _T('\0') && param[1] == _T(':'))
	{
		szRootPath[0] = (TCHAR)toupper(*param);
		param += 2;
		while (_istspace(*param))
			param++;
	}
	else
	{
		/* get label of current drive */
		TCHAR szCurPath[MAX_PATH];
		GetCurrentDirectory (MAX_PATH, szCurPath);
		szRootPath[0] = szCurPath[0];
	}

	_tcsncat(szLabel, param, 79);

	/* check root path */
	if (!IsValidPathName (szRootPath))
	{
		error_invalid_drive ();
		nErrorLevel = 1;
		return 1;
	}

	if (szLabel[0] == _T('\0'))
	{
		GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
		                     NULL, NULL, NULL, 0);

		/* print drive info */
		if (szOldLabel[0] != _T('\0'))
		{
			ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel);
		}
		else
		{
			ConOutResPrintf(STRING_LABEL_HELP3, _totupper(szRootPath[0]));
		}

		/* print the volume serial number */
		ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr));

		ConOutResPuts(STRING_LABEL_HELP5);

		ConInString(szLabel, 80);
	}

	if (!SetVolumeLabel(szRootPath, szLabel))
	{
		ConOutFormatMessage(GetLastError());
		nErrorLevel = 1;
		return 1;
	}

	return 0;
}