void CommandExecutor::PrintHelp() const {
	std::map<std::string, bool> printed;

	Lab3::out << BeginBox(GameStream::SUCCESS_COLOR);
	Lab3::out << Alignment::CENTER << "The following commands can currently be used" << std::endl;
	Lab3::out << Delimiter();
	std::vector<std::string> commandStrings;
	for(Commandable* commandable : _commandables){
		for(auto iter : commandable->GetCommandMap()){
			std::vector<Commandable::Command> commands = iter.second;
			for(Commandable::Command& command : commands){
				if(command.UsableInState(_state)){
					std::string desc = command.Description();
					if(printed[desc]){
						continue;
					}
					std::stringstream ss;
					ss << COLOR(iter.first, YELLOW) << " - ";
					ss << desc;
					commandStrings.push_back(ss.str());
					printed[desc] = true;
					break;
				} 
			}
		}
	}

	std::sort(commandStrings.begin(), commandStrings.end());
	for(auto& s : commandStrings)
		Lab3::out << s << std::endl;

	Lab3::out << EndBox();
}
Esempio n. 2
0
/*ARGSUSED*/
Object Read_Char (Object port, int chr, int konst) {
    int c, str;
    FILE *f;
    char buf[10], *p = buf;

    f = PORT(port)->file;
    str = PORT(port)->flags & P_STRING;
    Reader_Getc;
    if (c == EOF)
        Reader_Sharp_Eof;
    *p++ = c;
    while (1) {
        Reader_Getc;
        if (c == EOF)
            Reader_Sharp_Eof;
        if (Whitespace (c) || Delimiter (c))
            break;
        if (p == buf+9)
            Reader_Error (port, "syntax error in character constant");
        *p++ = c;
    }
    Reader_Ungetc;
    if (p == buf+1)
        return Make_Char (*buf);
    *p = '\0';
    if (p == buf+3) {
        for (c = 0, p = buf; p < buf+3 && Octal (*p); p++)
            c = c << 3 | (*p - '0');
        if (p == buf+3)
            return Make_Char (c);
    }
    for (p = buf; *p; p++)
        if (isupper (*p))
            *p = tolower (*p);
    if (strcmp (buf, "space") == 0)
        return Make_Char (' ');
    if (strcmp (buf, "newline") == 0)
        return Make_Char ('\n');
    if (strcmp (buf, "return") == 0)
        return Make_Char ('\r');
    if (strcmp (buf, "tab") == 0)
        return Make_Char ('\t');
    if (strcmp (buf, "formfeed") == 0)
        return Make_Char ('\f');
    if (strcmp (buf, "backspace") == 0)
        return Make_Char ('\b');
    Reader_Error (port, "syntax error in character constant");
    /*NOTREACHED*/
}
Esempio n. 3
0
void TStrings::SetDelimitedText(const UnicodeString & Value)
{
  BeginUpdate();
  SCOPE_EXIT
  {
    EndUpdate();
  };
  Clear();
  rde::vector<UnicodeString> Lines;
  UnicodeString Delimiter(UnicodeString(GetDelimiter()) + L'\n');
  tokenize(Value, Lines, Delimiter, true);
  for (size_t Index = 0; Index < Lines.size(); Index++)
  {
    Add(Lines[Index]);
  }
}
Esempio n. 4
0
void WLex::PutValue(String &str)
{
    if(!IsEol())
    {
	putc(Delimiter(), m_File);
    }
    else
    {
	m_bEOL = false;
    }
    for(int i = 0; i < int(str.length()); ++i)
    {
	if(IsSpecial(str[i]))
	{
	    putc('\\', m_File);
	}
	putc(str[i], m_File);
    }
}
Esempio n. 5
0
/*ARGSUSED*/
Object Read_Radix (Object port, int chr, int konst) {
    int c, str;
    FILE *f;
    Object ret;

    Read_Reset ();
    f = PORT(port)->file;
    str = PORT(port)->flags & P_STRING;
    Read_Store ('#'); Read_Store (chr);
    while (1) {
        Reader_Getc;
        if (c == EOF)
            Reader_Sharp_Eof;
        if (Whitespace (c) || Delimiter (c))
            break;
        Read_Store (c);
    }
    Reader_Ungetc;
    Read_Store ('\0');
    ret = Parse_Number (port, Read_Buf, 10);
    if (Nullp (ret))
        Reader_Error (port, "radix not followed by a valid number");
    return ret;
}
Esempio n. 6
0
/**
 \param dirs List to contain the sub directories in the path
 \param files List to contain the files in the path
 \param path Path to look for dirs in
 \param wildcard Optional wildcard
 \return true if any files or dirs were in the path
 \note The list will be cleared by the function
 */
SHVBool SHVDir::GetDirContent(SHVFileList& dirs, SHVFileList& files, const SHVStringC path, const SHVStringC wildcard)
{
SHVBool retVal(SHVBool::True);
SHVString fileName;
SHVStringC wc(wildcard.GetBufferConst());

	if (wc.IsNull())
	{
		wc = WildcardAll();
	}

	dirs.RemoveAll();
	files.RemoveAll();

	fileName.Format(_S("%s%s%s"),
		path.GetSafeBuffer(),
		path.Right(1) == Delimiter() ? _S("") : Delimiter().GetSafeBuffer(),
		wc.GetSafeBuffer());

#if defined(__SHIVA_WIN32)
WIN32_FIND_DATAW lpData;
int num;
HANDLE handle = ::FindFirstFileW(fileName.AsStr16C().GetSafeBufferWin32(), &lpData);

	num = lpData.dwFileAttributes;	// what we're doing here is isolating the bit
	num >>= 4;						// that tells us if the handle points to a 
	num &= 0x00000001;				// directory

	if(handle != INVALID_HANDLE_VALUE)
	{
		if(num != 1)
		{
# if __SHVSTRINGDEFAULT == 16
			files.AddTail((SHVWChar*)lpData.cFileName);
# else
			files.AddTail(SHVString16C((SHVWChar*)lpData.cFileName).ToStrT());
# endif
		}
		else if (SHVStringC(_S(".")).Compare((SHVTChar*)lpData.cFileName))
		{
# if __SHVSTRINGDEFAULT == 16
			dirs.AddTail((SHVWChar*)lpData.cFileName);
# else
			dirs.AddTail(SHVString16C((SHVWChar*)lpData.cFileName).ToStrT());
# endif
		}
	}

	while(handle != INVALID_HANDLE_VALUE)
	{
		if(::FindNextFileW(handle, &lpData) )
		{
			num = lpData.dwFileAttributes;	// what we're doing here is isolating the bit
			num >>= 4;						// that tells us if the handle points to a 
			num &= 0x00000001;				// directory

			if(num != 1)
			{
# if __SHVSTRINGDEFAULT == 16
				files.AddTail((SHVWChar*)lpData.cFileName);
# else
				files.AddTail(SHVString16C((SHVWChar*)lpData.cFileName).ToStrT());
# endif
			}
			else if (SHVStringC(_S("..")).Compare((SHVTChar*)lpData.cFileName))
			{
# if __SHVSTRINGDEFAULT == 16
				dirs.AddTail((SHVWChar*)lpData.cFileName);
# else
				dirs.AddTail(SHVString16C((SHVWChar*)lpData.cFileName).ToStrT());
# endif
			}
		}
		else
			break;
Esempio n. 7
0
Object Read_Special (Object port, int konst) {
    Object ret;
    register int c, str;
    register FILE *f;

#define READ_QUOTE(sym) \
    ( ret = Read_Atom (port, konst),\
      konst ? (ret = Const_Cons (ret, Null), Const_Cons (sym, ret))\
           : (ret = Cons (ret, Null), Cons (sym, ret)))

    f = PORT(port)->file;
    str = PORT(port)->flags & P_STRING;
again:
    Reader_Getc;
    switch (c) {
    case EOF:
eof:
        Reader_Tweak_Stream;
        Reader_Error (port, "premature end of file");
    case ';':
        if (Skip_Comment (port) == EOF)
            goto eof;
        goto again;
    case ']':
    case ')':
        SET(ret, T_Special, c);
        return ret;
    case '[':
    case '(':
        return Read_Sequence (port, 0, konst, c);
    case '\'':
        return READ_QUOTE(Sym_Quote);
    case '`':
        return READ_QUOTE(Sym_Quasiquote);
    case ',':
        Reader_Getc;
        if (c == EOF)
            goto eof;
        if (c == '@') {
            return READ_QUOTE(Sym_Unquote_Splicing);
        } else {
            Reader_Ungetc;
            return READ_QUOTE(Sym_Unquote);
        }
    case '"':
        return Read_String (port, konst);
    case '#':
        ret = Read_Sharp (port, konst);
        if (TYPE(ret) == T_Special)
            goto again;
        return ret;
    default:
        if (Whitespace (c))
            goto again;
        Read_Reset ();
        if (c == '.') {
            Reader_Getc;
            if (c == EOF)
                goto eof;
            if (Whitespace (c)) {
                Reader_Ungetc;
                SET(ret, T_Special, '.');
                return ret;
            }
            Read_Store ('.');
        }
        while (!Whitespace (c) && !Delimiter (c) && c != EOF) {
            if (c == '\\') {
                Reader_Getc;
                if (c == EOF)
                    break;
            }
            Read_Store (c);
            Reader_Getc;
        }
        Read_Store ('\0');
        if (c != EOF)
            Reader_Ungetc;
        ret = Parse_Number (port, Read_Buf, 10);
        if (Nullp (ret))
            ret = Intern (Read_Buf);
        return ret;
    }
    /*NOTREACHED*/
}