示例#1
0
文件: lua.c 项目: mylxiaoyi/fcitx
static void* LuaCallCommand(void* arg, FcitxModuleFunctionArg args) {
    LuaModule *luamodule = (LuaModule *)arg;
    UT_array *result = InputCommand(luamodule, (const char *)args.args[0]);
    if (result) {
        FcitxInputState* input = FcitxInstanceGetInputState(GetFcitx(luamodule));
        LuaResultItem *p = NULL;
        while ((p = (LuaResultItem *)utarray_next(result, p))) {
            FcitxCandidateWord candWord;
            if (args.args[1] && args.args[2]) {
                candWord.callback = args.args[1];
                candWord.owner = args.args[2];
            }
            else {
                candWord.callback = LuaGetCandWord;
                candWord.owner = luamodule;
            }
            candWord.priv = p->help ? strdup(p->help) : NULL;
            if (p->help || p->tip) {
                asprintf(&candWord.strExtra, "%s%s%s", p->help ? p->help : "", p->help && p->tip ? " " : "", p->tip ? p->tip : "");
            } else {
                candWord.strExtra = NULL;
            }
            candWord.strWord = strdup(p->result);
            candWord.wordType = MSG_TIPS;
            candWord.extraType = MSG_CODE;
            FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord);
        }
        utarray_free(result);
    }
    return NULL;
}
示例#2
0
文件: shell.cpp 项目: 0x90sled/dosbox
void DOS_Shell::Run(void) {
	char input_line[CMD_MAXLINE] = {0};
	std::string line;
	if (cmd->FindStringRemainBegin("/C",line)) {
		strcpy(input_line,line.c_str());
		char* sep = strpbrk(input_line,"\r\n"); //GTA installer
		if (sep) *sep = 0;
		DOS_Shell temp;
		temp.echo = echo;
		temp.ParseLine(input_line);		//for *.exe *.com  |*.bat creates the bf needed by runinternal;
		temp.RunInternal();				// exits when no bf is found.
		return;
	}
	/* Start a normal shell and check for a first command init */
	WriteOut(MSG_Get("SHELL_STARTUP_BEGIN"),VERSION);
#if C_DEBUG
	WriteOut(MSG_Get("SHELL_STARTUP_DEBUG"));
#endif
	if (machine == MCH_CGA) WriteOut(MSG_Get("SHELL_STARTUP_CGA"));
	if (machine == MCH_HERC) WriteOut(MSG_Get("SHELL_STARTUP_HERC"));
	WriteOut(MSG_Get("SHELL_STARTUP_END"));

	if (cmd->FindString("/INIT",line,true)) {
		strcpy(input_line,line.c_str());
		line.erase();
		ParseLine(input_line);
	}
	do {
		if (bf){
			if(bf->ReadLine(input_line)) {
				if (echo) {
					if (input_line[0]!='@') {
						ShowPrompt();
						WriteOut_NoParsing(input_line);
						WriteOut_NoParsing("\n");
					};
				};
				ParseLine(input_line);
				if (echo) WriteOut("\n");
			}
		} else {
			//locnet, exit shell loop without exception
			if (loadf->abort == 2) {
				loadf->abort = 3;
				exit = true;
				break;
			}
			if (echo) ShowPrompt();
			InputCommand(input_line);
			ParseLine(input_line);
			if (echo && !bf) WriteOut_NoParsing("\n");
		}
	} while (!exit);
}
示例#3
0
DWORD CMMControlThread::StartThread()
{
	try
	{
		InputCommand();

		/*DebugLog("Command Input");
		std::string strInput = "start 1";
		SetCommand(strInput);*/
	}
	catch (std::exception &e) {
		ErrorLog("%s", e.what());
	}

	return E_RET_SUCCESS;
}
示例#4
0
/* command */
static PyObject *
engine_command(PyObject *self, PyObject *args)
{

    char *command;    
    
    if (!PyArg_ParseTuple(args, "s", &command))
        return NULL;

    InputCommand(command);
    if (verbose)
    {
        printf("-> gshogi builtin:%s\n", command);
    }    
    
    Py_RETURN_NONE;   
           
}
示例#5
0
void Play(tGame * game)
{	
	int legal;

	tScan scan;
	tCommand command;
	command.undo.can_undo = FALSE;
	command.undo.undo_error = FALSE;
	command.undo.lastboard.rows = game->visualboard.rows; 
	command.undo.lastboard.columns = game->visualboard.columns;
	CreateBoard(&command.undo.lastboard);;

	do
	{
		PrintAll(game, &command);
		
		do
		{	
			if ((legal = InputCommand(&scan)))
			{	
				if((legal = LegalCommand(&scan, &command)))
					if (command.command_ref < 5) /*All commands but quit or undo*/
						legal = LegalParams(game, &command, &scan);
			}

		if (!legal)
			printf("%s%s%s\n", KERR, COMMAND_ERR, KDEF);

		} while (!legal);

		ExecCommand(game, &command);
		CheckGameState(game);
	} while(game->gamestate == GAMESTATE_DEFAULT);

	PrintResult(game);

	freeBoard(game->hiddenboard.board, game->hiddenboard.rows);
	freeBoard(game->visualboard.board, game->hiddenboard.rows);
	return;
}
示例#6
0
文件: shell.cpp 项目: KitoHo/iDOS
void DOS_Shell::Run(void) {
	char input_line[CMD_MAXLINE] = {0};
	std::string line;
	if (cmd->FindStringRemain("/C",line)) {
		strcpy(input_line,line.c_str());
		char* sep = strpbrk(input_line,"\r\n"); //GTA installer
		if (sep) *sep = 0;
		DOS_Shell temp;
		temp.echo = echo;
		temp.ParseLine(input_line);		//for *.exe *.com  |*.bat creates the bf needed by runinternal;
		temp.RunInternal();				// exits when no bf is found.
		return;
	}
	/* Start a normal shell and check for a first command init */
	WriteOut(MSG_Get("SHELL_STARTUP_BEGIN"),VERSION);
#if C_DEBUG
	WriteOut(MSG_Get("SHELL_STARTUP_DEBUG"));
#endif
	if (machine == MCH_CGA) WriteOut(MSG_Get("SHELL_STARTUP_CGA"));
	if (machine == MCH_HERC) WriteOut(MSG_Get("SHELL_STARTUP_HERC"));
	WriteOut(MSG_Get("SHELL_STARTUP_END"));

#ifdef IPHONEOS                        
    if (automount_path[0]) {
        char *p = (char*)automount_path;
        char *endp = p;
        char disk = 'c';
        LOG_MSG("DOS_Shell::Run Auto Mount");
        
        while (endp) {
            for (p = endp; *endp && *endp != ';'; endp++)
                ;
            if (*endp == ';') {
                *endp = 0; 
                endp++;
            } else {
                endp=0;
            }
            if (strlen(p) <= 0) break;
            sprintf(input_line, "mount %c \"%s\"",disk, p);
            ParseLine(input_line);
            disk++;
        }
        if (disk > 'c') {
            sprintf(input_line, "c:");
            ParseLine(input_line);
        }
    }
#endif       
    
	if (cmd->FindString("/INIT",line,true)) {
		strcpy(input_line,line.c_str());
		line.erase();
		ParseLine(input_line);
	}
	do {
		if (bf){
			if(bf->ReadLine(input_line)) {
				if (echo) {
					if (input_line[0]!='@') {
						ShowPrompt();
						WriteOut_NoParsing(input_line);
						WriteOut_NoParsing("\n");
					};
				};
				ParseLine(input_line);
				if (echo) WriteOut("\n");
			}
#ifdef IPHONEOS                        
        } else if (automount_path[0]) {
            automount_path[0] = 0;
            if (echo && !bf) WriteOut_NoParsing("\n");
            sprintf(input_line, "cls");
            ParseLine(input_line);
#endif                    
		} else {
			if (echo) ShowPrompt();
#ifdef IPHONEOS
            dospad_command_line_ready=1;
#endif
			InputCommand(input_line);
#ifdef IPHONEOS
            dospad_add_history(input_line);
            dospad_command_line_ready=0;
            if (dospad_should_launch_game)
            {
                // Make sure we can access the new installed files
                Bit8u drive = DOS_GetDefaultDrive();
                if (Drives[drive]) {
                    Drives[drive]->EmptyCache();
                }                
                FILE *fp=fopen(dospad_launch_config, "r");
                if (fp != NULL)
                {
                    char buf[256];
                    int sectionLength = strlen(dospad_launch_section);
                    while (fgets(buf, 256, fp))
                    {
                        if (strncmp(buf, dospad_launch_section, sectionLength) == 0)
                        {
                            while (fgets(buf, 256, fp))
                            {
                                if (buf[0] == '[') break;
                                if (buf[0] == '#') continue;
                                ParseLine(buf);
                            }
                        }
                    }
                    fclose(fp);
                }
                dospad_should_launch_game = 0;
                sprintf(input_line,"cls");
                dospad_launch_done();
            }
#endif
			ParseLine(input_line);
			if (echo && !bf) WriteOut_NoParsing("\n");
		}
	} while (!exit);
}
示例#7
0
void DOS_Shell::Run(void) {
	char input_line[CMD_MAXLINE] = {0};
	std::string line;
	if (cmd->FindStringRemain("/C",line)) {
		strcpy(input_line,line.c_str());
		char* sep = strpbrk(input_line,"\r\n"); //GTA installer
		if (sep) *sep = 0;
		DOS_Shell temp;
		temp.echo = echo;
		temp.ParseLine(input_line);		//for *.exe *.com  |*.bat creates the bf needed by runinternal;
		temp.RunInternal();				// exits when no bf is found.
		return;
	}
	/* Start a normal shell and check for a first command init */
    //--Modified 2012-08-19 by Alun Bestor to allow selective overriding of the startup messages.
    if (boxer_shouldDisplayStartupMessages())
    {
        WriteOut(MSG_Get("SHELL_STARTUP_BEGIN"),VERSION);
    #if C_DEBUG
        WriteOut(MSG_Get("SHELL_STARTUP_DEBUG"));
    #endif
        if (machine == MCH_CGA) WriteOut(MSG_Get("SHELL_STARTUP_CGA"));
        if (machine == MCH_HERC) WriteOut(MSG_Get("SHELL_STARTUP_HERC"));
        WriteOut(MSG_Get("SHELL_STARTUP_END"));
    }
    //--End of modifications
    
	if (cmd->FindString("/INIT",line,true)) {
		//--Added 2009-12-13 by Alun Bestor to let Boxer monitor the autoexec process
		boxer_autoexecDidStart();
		
		strcpy(input_line,line.c_str());
		line.erase();
		ParseLine(input_line);
		
		boxer_autoexecDidFinish();
		//--End of modifications
	}
	do {
        //--Added 2012-08-19 by Alun Bestor to let Boxer insert its own commands into batch processing.
        if (boxer_hasPendingCommands())
        {
            boxer_executeNextPendingCommand();
        }
		else if (bf){
        //--End of modifications
            if(bf->ReadLine(input_line)) {
				if (echo) {
					if (input_line[0]!='@') {
						ShowPrompt();
						WriteOut_NoParsing(input_line);
						WriteOut_NoParsing("\n");
					};
				};
				ParseLine(input_line);
				if (echo) WriteOut("\n");
			}
		} else {
            //--Added 2009-11-29 by Alun Bestor as a hook for detecting when control has returned to the DOS prompt. 
            boxer_didReturnToShell();
            //--End of modifications
            
			if (echo) ShowPrompt();
			InputCommand(input_line);
            
            //--Added 2012-08-19 by Alun Bestor to let Boxer interrupt the command input with its own commands.
            if (boxer_shellShouldContinue() && !boxer_hasPendingCommands())
            {
                //--End of modifications
                ParseLine(input_line);
                if (echo && !bf) WriteOut_NoParsing("\n");
            }
		}
	} while (boxer_shellShouldContinue() && !exit);
}
示例#8
0
文件: main.c 项目: ynaoto/gnushogi
int
main (int argc, char **argv)
{
    /*
     * Process command-line arguments.
     */

    /* Get rid of the program name. */

    argc--;
    argv++;

    /* CHECKME: get rid of the '+' syntax? */

    while ((argc > 0) && ((argv[0][0] == '-') || (argv[0][0] == '+')))
    {
        switch (argv[0][1])
        {
        case 'a':
            /* Need the "+" syntax here... */
            ahead = ((argv[0][0] == '-') ? false : true);
            break;


        case 'b':
            argc--;
            argv++;

            if (argc > 0)
            {
                bookfile = argv[0];
#ifdef BINBOOK
                binbookfile = NULL;
#endif
            }

            break;

#ifdef BINBOOK
        case 'B':
            argc--;
            argv++;

            if (argc > 0)
                binbookfile = argv[0];

            break;
#endif

        case 'C':
            /* Curses interface. */
            display_type = DISPLAY_CURSES;

            break;


        case 'h':
            /* Need the "+" syntax here... */
            hash = ((argv[0][0] == '-') ? false : true);
            break;


        case 'l':
            argc--;
            argv++;

            if (argc > 0)
                Lang = argv[0];

            break;


        case 'L':
            argc--;
            argv++;

            if (argc > 0)
                strcpy(listfile, argv[0]);
            break;


        case 's':
            argc--;
            argv++;

            if (argc > 0)
                strcpy(savefile, argv[0]);

            break;


        case 'P':
            argc--;
            argv++;

            if (argc > 0)
                bookmaxply = atoi(argv[0]);

            break;


        case 'R':
            /* Raw text interface. */
            display_type = DISPLAY_RAW;

            break;


        case 'S':
            argc--;
            argv++;

            if (argc > 0)
                booksize = atoi(argv[0]);
            break;

#if ttblsz
        case 'r':
            argc--;
            argv++;

            if (argc > 0)
                rehash = atoi(argv[0]);

            if (rehash > MAXrehash)
                rehash = MAXrehash;

            break;


        case 'T':
            argc--;
            argv++;

            if (argc > 0)
                ttblsize = atoi(argv[0]);

            if ((ttblsize <= MINTTABLE))
                ttblsize = (MINTTABLE) + 1;

            break;

#ifdef HASHFILE
        case 'c':   /* Create or test persistent transposition table. */
            argc--;
            argv++;

            if (argc > 0)
                filesz = atoi(argv[0]);
            else
                filesz = vfilesz;

            if ((filesz > 0) && (filesz < 24))
                filesz = (1 << filesz) - 1 + MAXrehash;
            else
                filesz = filesz + MAXrehash;

            if ((hashfile = fopen(HASHFILE, RWA_ACC)) == NULL)
                hashfile = fopen(HASHFILE, WA_ACC);

            if (hashfile != NULL)
            {
                long j;
                struct fileentry n;

                printf(CP[66]);
                n.f = n.t = 0;
                n.flags = 0;
                n.depth = 0;
                n.sh = n.sl = 0;

                for (j = 0; j < filesz + 1; j++)
                    fwrite(&n, sizeof(struct fileentry), 1, hashfile);

                fclose(hashfile);
            }
            else
            {
                printf(CP[50], HASHFILE);
            }

            return 0;


        case 't':   /* Create or test persistent transposition table. */
            hashfile = fopen(HASHFILE, RWA_ACC);

            if (hashfile)
            {
                fseek(hashfile, 0L, SEEK_END);
                filesz = (ftell(hashfile) / (sizeof(struct fileentry))) - 1;
            }

            if (hashfile != NULL)
            {
                long i, j;
                int nr[MAXDEPTH];
                struct fileentry n;

                printf(CP[49]);

                for (i = 0; i < MAXDEPTH; i++)
                    nr[i] = 0;

                fseek(hashfile, 0L, SEEK_END);
                i = ftell(hashfile) / (sizeof(struct fileentry));
                fseek(hashfile, 0L, SEEK_SET);

                for (j = 0; j < i + 1; j++)
                {
                    fread(&n, sizeof(struct fileentry), 1, hashfile);

                    if (n.depth > MAXDEPTH)
                    {
                        printf("ERROR\n");
                        exit(1);
                    }

                    if (n.depth)
                    {
                        nr[n.depth]++;
                        nr[0]++;
                    }
                }

                printf(CP[109], nr[0], i);

                for (j = 1; j < MAXDEPTH; j++)
                    printf("%d ", nr[j]);

                printf("\n");
            }

            return 0;


#endif /* HASHFILE */
#endif /* ttblsz */

        case 'v':
            fprintf(stderr, CP[102], version, patchlevel);
            exit(1);


        case 'X':
            /* X interface. */
            display_type = DISPLAY_X;

            break;


        case 'x':
            argc--;
            argv++;

            if (argc > 0)
                xwin = argv[0];

            break;


        default:
            fprintf(stderr, CP[113]);
            exit(1);
        }

        argc--;
        argv++;
    }

    if (argc == 2)
    {
        char *p;

        MaxResponseTime = 100L * strtol(argv[1], &p, 10);

        if (*p == ':')
        {
            MaxResponseTime = 60L * MaxResponseTime +
                100L * strtol(++p, (char **) NULL, 10);
        }

        TCflag    = false;
        TCmoves   = 0;
        TCminutes = 0;
        TCseconds = 0;
    }

    if (argc >= 3)
    {
        char *p;

        if (argc > 9)
        {
            printf("%s\n", CP[220]);
            exit(1);
        }

        TCmoves   = atoi(argv[1]);
        TCminutes = (short)strtol(argv[2], &p, 10);

        if (*p == ':')
            TCseconds = (short)strtol(p + 1, (char **) NULL, 10);
        else
            TCseconds = 0;

        TCflag = true;
        argc -= 3;
        argv += 3;

        while (argc > 1)
        {
            XCmoves[XC]   = atoi(argv[0]);
            XCminutes[XC] = (short)strtol(argv[1], &p, 10);

            if (*p == ':')
                XCseconds[XC] = (short)strtol(p + 1, (char **) NULL, 10);
            else
                XCseconds[XC] = 0;

            if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC]))
                XC++;
            else
            {
                printf("%s\n", CP[220]);
                exit(1);
            }

            argc -= 2;
            argv += 2;
        }

        if (argc)
        {
            /*
             * If we got here, there are unknown arguments, so issue
             * an error message and quit.
             */

            printf("%s\n", CP[233]);
            print_arglist(argc, argv);
            exit(1);
        }
    }

    if (InitMain() != 0)
        exit(1);

    while (!flag.quit)
    {
        oppptr = (oppptr + 1) % MINGAMEIN;

        if (flag.bothsides && !flag.mate)
            SelectMove(opponent, FOREGROUND_MODE);
        else
            InputCommand(NULL);

        if (opponent == white)
        {
            if (flag.gamein || TCadd)
            {
                TimeCalc();
            }
            else if (TimeControl.moves[opponent] == 0)
            {
                if (XC)
                {
                    if (XCmore < XC)
                    {
                        TCmoves   = XCmoves[XCmore];
                        TCminutes = XCminutes[XCmore];
                        TCseconds = XCseconds[XCmore];
                        XCmore++;
                    }
                }

                SetTimeControl();
            }
        }

        compptr = (compptr + 1) % MINGAMEIN;

        if (!(flag.quit || flag.mate || flag.force))
        {
#ifdef INTERRUPT_TEST
            printf("starting search...\n");
#endif
            SelectMove(computer, FOREGROUND_MODE);

            if (computer == white)
            {
                if (flag.gamein)
                {
                    TimeCalc();
                }
                else if (TimeControl.moves[computer] == 0)
                {
                    if (XC)
                    {
                        if (XCmore < XC)
                        {
                            TCmoves = XCmoves[XCmore];
                            TCminutes = XCminutes[XCmore];
                            TCseconds = XCseconds[XCmore];
                            XCmore++;
                        }
                    }

                    SetTimeControl();
                }
            }
        }
    }

    ExitMain();

    return 0;
}