Esempio n. 1
0
// Requires:
// Modifies:
// Effects: probably runs the program
int main(int argc, char * argv[]) {
  // desync with stdio
  std::ios_base::sync_with_stdio(false);
  //
  std::string problem_type = get_cmd_args(argc, argv);
  Pokemon_Yellow pokemon_yellow(problem_type);
  pokemon_yellow.solve_problem();
  std::ostringstream oss;
  std::ostream & out = oss;
  // std::ostream & out = std::cout;
  out << std::setprecision(2) << std::fixed;
  pokemon_yellow.print_answer(out);
  std::cout << oss.str();
  return 0;
}
Esempio n. 2
0
int WINAPI
WinMain(
    HINSTANCE	hInstance,
    HINSTANCE	hPrevInst,
    LPSTR	lpszCmdLine,
    int		nCmdShow)
{
    int		argc;
    char	**argv;
    char	*tofree;
    char	prog[256];

    /*
     * Ron: added full path name so that the $VIM variable will get set to our
     * startup path (so the .vimrc file can be found w/o a VIM env. var.)
     * Remove the ".exe" extension, and find the 1st non-space.
     */
    GetModuleFileName(hInstance, prog, 255);
    if (*prog != NUL)
	exe_name = FullName_save((char_u *)prog, FALSE);

    /* Separate the command line into arguments. */
    argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
    if (argc == 0)
    {
	/* Error message? */
	return 0;
    }

    pSaveInst = SaveInst;
    pmain = VimMain;
    pSaveInst(hInstance);
    pmain(argc, argv);

    free(argv);
    if (tofree != NULL)
	free(tofree);

    return 0;
}
Esempio n. 3
0
/*ARGSUSED*/
    int WINAPI
WinMain(
    HINSTANCE	hInstance,
    HINSTANCE	hPrevInst,
    LPSTR	lpszCmdLine,
    int		nCmdShow)
{
    int		argc = 0;
    char	**argv;
    char	*tofree;
    char	prog[256];
#ifdef VIMDLL
    char	*p;
    HANDLE	hLib;
#endif

    /* Ron: added full path name so that the $VIM variable will get set to our
     * startup path (so the .vimrc file can be found w/o a VIM env. var.) */
    GetModuleFileName(NULL, prog, 255);

    argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
    if (argc == 0)
    {
	MessageBox(0, "Could not allocate memory for command line.",
							      "VIM Error", 0);
	return 0;
    }

#ifdef DYNAMIC_GETTEXT
    /* Initialize gettext library */
    dyn_libintl_init(NULL);
#endif

#ifdef VIMDLL
    // LoadLibrary - get name of dll to load in here:
    p = strrchr(prog, '\\');
    if (p != NULL)
    {
# ifdef DEBUG
	strcpy(p+1, "vim32d.dll");
# else
	strcpy(p+1, "vim32.dll");
# endif
    }
    hLib = LoadLibrary(prog);
    if (hLib == NULL)
    {
	MessageBox(0, _("Could not load vim32.dll!"), _("VIM Error"), 0);
	goto errout;
    }
    // fix up the function pointers
# ifdef FEAT_GUI
    pSaveInst = GetProcAddress(hLib, (LPCSTR)2);
# endif
    pmain = GetProcAddress(hLib, (LPCSTR)1);
    if (pmain == NULL)
    {
	MessageBox(0, _("Could not fix up function pointers to the DLL!"),
							    _("VIM Error"),0);
	goto errout;
    }
#else
# ifdef FEAT_GUI
    pSaveInst = SaveInst;
# endif
    pmain =
# if defined(FEAT_GUI_W32)
    //&& defined(__MINGW32__)
	VimMain
# else
	main
# endif
	;
#endif
#ifdef FEAT_GUI
    pSaveInst(
#ifdef __MINGW32__
	    GetModuleHandle(NULL)
#else
	    hInstance
#endif
	    );
#endif
    pmain(argc, argv);

#ifdef VIMDLL
    FreeLibrary(hLib);
errout:
#endif
    free(argv);
    if (tofree != NULL)
	free(tofree);
#ifdef FEAT_MBYTE
    free_cmd_argsW();
#endif

    return 0;
}
Esempio n. 4
0
/* Determines current position in the command line.  Returns:
 *  - 0, if not inside an argument;
 *  - 1, if next character should be skipped (XXX: what does it mean?);
 *  - 2, if inside escaped argument;
 *  - 3, if inside single quoted argument;
 *  - 4, if inside double quoted argument;
 *  - 5, if inside regexp quoted argument. */
TSTATIC int
line_pos(const char begin[], const char end[], char sep, int rquoting)
{
	int state;
	int count;
	enum { BEGIN, NO_QUOTING, S_QUOTING, D_QUOTING, R_QUOTING };

	const char *args = get_cmd_args(begin);
	if(args >= end)
	{
		return 0;
	}
	if(args == NULL)
	{
		count = 0;
	}
	else
	{
		begin = args;
		count = 1;
	}

	state = BEGIN;
	while(begin != end)
	{
		switch(state)
		{
			case BEGIN:
				if(sep == ' ' && *begin == '\'')
					state = S_QUOTING;
				else if(sep == ' ' && *begin == '"')
					state = D_QUOTING;
				else if(sep == ' ' && *begin == '/' && rquoting)
					state = R_QUOTING;
				else if(*begin == '&' && begin == end - 1)
					state = BEGIN;
				else if(*begin != sep)
					state = NO_QUOTING;
				break;
			case NO_QUOTING:
				if(*begin == sep)
				{
					state = BEGIN;
					count++;
				}
				else if(*begin == '\'')
				{
					state = S_QUOTING;
				}
				else if(*begin == '"')
				{
					state = D_QUOTING;
				}
				else if(*begin == '\\')
				{
					begin++;
					if(begin == end)
						return 1;
				}
				break;
			case S_QUOTING:
				if(*begin == '\'')
					state = BEGIN;
				break;
			case D_QUOTING:
				if(*begin == '"')
				{
					state = BEGIN;
				}
				else if(*begin == '\\')
				{
					begin++;
					if(begin == end)
						return 1;
				}
				break;
			case R_QUOTING:
				if(*begin == '/')
				{
					state = BEGIN;
				}
				else if(*begin == '\\')
				{
					begin++;
					if(begin == end)
						return 1;
				}
				break;
		}
		begin++;
	}
	if(state == NO_QUOTING)
	{
		if(sep == ' ')
		{
			/* First element is not an argument. */
			return (count > 0) ? 2 : 0;
		}
		else if(count > 0 && count < 3)
		{
			return 2;
		}
	}
	else if(state != BEGIN)
	{
		/* "Error": no closing quote. */
		switch(state)
		{
			case S_QUOTING: return 3;
			case D_QUOTING: return 4;
			case R_QUOTING: return 5;

			default:
				assert(0 && "Unexpected state.");
				break;
		}
	}
	else if(sep != ' ' && count > 0 && *end != sep)
		return 2;

	return 0;
}