int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
				   PSTR cmdLine, int showCmd)
{
	SetupConsole();

	// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	InitDirect3DApp theApp(hInstance);
	
	if( !theApp.Init() )
		return 0;
	
	return theApp.Run();
}
示例#2
0
// execute a command with a DOS command processor; see CPEXEC_xxx for return values
int CConsolePipe::Execute(LPCTSTR pszCommand) {
	assert(pszCommand && *pszCommand);

	// for (running) reusable command processors, send this as another input
	if(m_hListenerThread) {
		if(CPF_REUSECMDPROC & m_dwFlags) {
			TString strCmd(pszCommand);
            assert(strCmd.find(_T('\n')) == TString::npos);
			strCmd += _T("\r\n");

			/* WINDOWS APPLICATIONS
				* If one tries to launch a windows proggy (e.g. notepad) most of the time nowt
				* happens first time round. If a second newline is keyed then the window appears.
				* I have checked with the task manager and sure enough the process exist from the
				* first time, only it is invisible! I haven't got a clue why this happens; perhaps
				* it's the SW_HIDE passed in the original CreateProcess, but that is required @@@
				*/
			SendChildInput(strCmd.c_str());
			return CPEXEC_OK; // can't tell if it is busy...
			// moreover, if cmd is busy with a proggy that accepts input, our command will be lost
		}
	}

	assert(NULL == m_hChildProcess);
	assert(INVALID_HANDLE_VALUE == m_hInputWrite);
	assert(INVALID_HANDLE_VALUE == m_hOutputRead);
	if(m_hListenerThread)
		return CPEXEC_MISC_ERROR;
	if(pszCommand==0 || *pszCommand == 0)
		return CPEXEC_COMMAND_ERROR;

	// for 9x we need a console for THIS process to be inherited by the child
	// this circumvents the ugly stub processes recommended by Q150956
	// ADDENDUM: ok for NT too in the end, since I want to be able to send Ctrl-C events
	if(!IsConsoleAttached()) {
		if(!SetupConsole()) {
#ifdef _DEBUG
			ATLTRACE(_T("MINI-assert: can't create console window\n"));
#endif
			return CPEXEC_MISC_ERROR;
		}
	}

	// execution with redirection follows guidelines from:
	// Q190351 - HOWTO: Spawn Console Processes with Redirected Standard Handles

	HANDLE loadzaHandles[5]; // for EZ cleanup
    int i;
	for(i = 0; i < sizeof(loadzaHandles)/sizeof(loadzaHandles[0]); i++)
		loadzaHandles[i] = INVALID_HANDLE_VALUE;
#if 0 // that's the array correspondence, in order
    HANDLE hOutputReadTmp, hOutputWrite;
    HANDLE hInputWriteTmp, hInputRead;
    HANDLE hErrorWrite;
#endif
    SECURITY_ATTRIBUTES sa;

    // Set up the security attributes struct.
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;

	int status;
	HANDLE hProc = GetCurrentProcess();
    // Create the child output pipe, default buffer size
	if(CreatePipe(&loadzaHandles[0], &loadzaHandles[1], &sa, 0) &&

    // Create a duplicate of the output write handle for the std error
    // write handle. This is necessary in case the child application
    // closes one of its std output handles. (you don't say! :)
		DuplicateHandle(hProc, loadzaHandles[1],
                        hProc, &loadzaHandles[4], 0,
                        TRUE, DUPLICATE_SAME_ACCESS) &&

	// Create the child input pipe.
		CreatePipe(&loadzaHandles[3], &loadzaHandles[2], &sa, 0) &&

	// Create new output read handle and the input write handles. Set
    // the Properties to FALSE. Otherwise, the child inherits the
    // properties and, as a result, non-closeable handles to the pipes
    // are created.
		DuplicateHandle(hProc, loadzaHandles[0],
                        hProc,
                        &m_hOutputRead, // Address of new handle.
                        0, FALSE, // Make it uninheritable.
                        DUPLICATE_SAME_ACCESS) &&

		DuplicateHandle(hProc, loadzaHandles[2],
                        hProc,
                        &m_hInputWrite, // Address of new handle.
                        0, FALSE, // Make it uninheritable.
                        DUPLICATE_SAME_ACCESS))
	{
		// Close inheritable copies of the handles you do not want to be inherited.
		CloseHandle(loadzaHandles[0]);  loadzaHandles[0] = INVALID_HANDLE_VALUE;
		CloseHandle(loadzaHandles[2]);  loadzaHandles[2] = INVALID_HANDLE_VALUE;

		if(LaunchRedirected(pszCommand, loadzaHandles[1], loadzaHandles[3], loadzaHandles[4]))
		{
			// Close pipe handles (do not continue to modify the parent).
			// You need to make sure that no handles to the write end of the
			// output pipe are maintained in this process or else the pipe will
			// not close when the child process exits and the ReadFile will hang.
			for(i = 0; i < sizeof(loadzaHandles)/sizeof(loadzaHandles[0]); i++) {
				if(loadzaHandles[i] != INVALID_HANDLE_VALUE) {
					CloseHandle(loadzaHandles[i]);
					loadzaHandles[i] = INVALID_HANDLE_VALUE;
				}
			}
			// now all's left are the handles to the pipe ends we use for communication
			// i.e. m_hOutputRead (receive stdout) & m_hInputWrite (specify stdin)

			// create thread that monitors for printfs
			// since it don't uses CRT, a plain creation is sufficient
			DWORD ThreadId;
			m_hListenerThread = ::CreateThread(NULL, 0, ListenerThreadProc,
				(LPVOID)this, 0, &ThreadId);
			if(m_hListenerThread)
				status = CPEXEC_OK;
			else
				status = CPEXEC_MISC_ERROR; // rare
		}
		else
			status = CPEXEC_COMMAND_ERROR;
	}
	else
		status = CPEXEC_MISC_ERROR;

	// cleanup in case of errors
	for(i = 0; i < sizeof(loadzaHandles)/sizeof(loadzaHandles[0]); i++) {
		if(loadzaHandles[i] != INVALID_HANDLE_VALUE)
			CloseHandle(loadzaHandles[i]);
	}

	if(CPEXEC_OK != status) {
#ifdef _DEBUG
		ATLTRACE(_T("MINI-assert: can't launch redirected child (%d)\n"), status);
#endif
		assert(!m_hListenerThread);
		Cleanup();
		// now this object is ready for another Execute() attempt or destruction
	}

	// if this didn't succeed, clients should delete this object
	// for CPEXEC_MISC_ERROR try a non-posh alternative like CreateProcess/ShellExecute
	return status;
}
示例#3
0
/**
**  The main program: initialise, parse options and arguments.
**
**  @param argc  Number of arguments.
**  @param argv  Vector of arguments.
*/
int stratagusMain(int argc, char **argv)
{
#ifdef USE_BEOS
	//  Parse arguments for BeOS
	beos_init(argc, argv);
#endif
#ifdef USE_WIN32
	SetUnhandledExceptionFilter(CreateDumpFile);
#endif
#if defined(USE_WIN32) && ! defined(REDIRECT_OUTPUT)
	SetupConsole();
#endif
	//  Setup some defaults.
#ifndef MAC_BUNDLE
	StratagusLibPath = ".";
#else
	freopen("/tmp/stdout.txt", "w", stdout);
	freopen("/tmp/stderr.txt", "w", stderr);
	// Look for the specified data set inside the application bundle
	// This should be a subdir of the Resources directory
	CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
												 CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL);
	CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,  kCFURLPOSIXPathStyle);
	const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
	Assert(pathPtr);
	StratagusLibPath = pathPtr;
#endif

#ifdef USE_PHYSFS
	if (PHYSFS_init(argv[0])) {
		PHYSFS_mount(PHYSFS_DATAFILE, "/", 0);
	}
#endif

#ifdef USE_STACKTRACE
	try {
#endif
	Parameters &parameters = Parameters::Instance;
	parameters.SetDefaultValues();
	parameters.SetLocalPlayerNameFromEnv();

#ifdef REDIRECT_OUTPUT
	RedirectOutput();
#endif

	if (argc > 0) {
		parameters.applicationName = argv[0];
	}

	// FIXME: Parse options before or after scripts?
	ParseCommandLine(argc, argv, parameters);
	// Init the random number generator.
	InitSyncRand();

	makedir(parameters.GetUserDirectory().c_str(), 0777);

	// Init Lua and register lua functions!
	InitLua();
	LuaRegisterModules();

	// Initialise AI module
	InitAiModule();

	LoadCcl(parameters.luaStartFilename, parameters.luaScriptArguments);

	PrintHeader();
	PrintLicense();

	// Setup video display
	InitVideo();

	// Setup sound card
	if (!InitSound()) {
		InitMusic();
	}

#ifndef DEBUG			// For debug it's better not to have:
	srand(time(NULL));	// Random counter = random each start
#endif

	//  Show title screens.
	SetDefaultTextColors(FontYellow, FontWhite);
	LoadFonts();
	SetClipping(0, 0, Video.Width - 1, Video.Height - 1);
	Video.ClearScreen();
	ShowTitleScreens();

	// Init player data
	ThisPlayer = NULL;
	//Don't clear the Players structure as it would erase the allowed units.
	// memset(Players, 0, sizeof(Players));
	NumPlayers = 0;

	UnitManager.Init();	// Units memory management
	PreMenuSetup();		// Load everything needed for menus

	MenuLoop();

	Exit(0);
#ifdef USE_STACKTRACE
	} catch (const std::exception &e) {
		fprintf(stderr, "Stratagus crashed!\n");
		//Wyrmgus start
//		fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Wargus/stratagus/issues\n");
		fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Andrettin/Wyrmgus/issues\n");
		//Wyrmgus end
		fprintf(stderr, "and tell us what caused this bug to occur.\n");
		fprintf(stderr, " === exception state traceback === \n");
		fprintf(stderr, "%s", e.what());
		exit(1);
	}
#endif
	return 0;
}
int EditAttributes (FILES *f) {

  char  *buf;
  USHORT len = (vio.col * 7) * 2,curpos = 0;
  char   nattr = (1 << 4) | (7 | 8);
  char   sattr = 8;
  int    ret = 0,x,key;
  BOOL   okay = TRUE;
  char   attrs[5] = "----";

  if(!f)
    return -1;
  buf = malloc(len);
  if(!buf)
    return -1;

  ThreadMsg(" ");

  VioReadCellStr(buf,&len,(vio.row / 2) - 1,0,0);

  VioWrtCharStrAtt("ÚÄ Attributes: Ä¿",17,(vio.row / 2) - 1,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Readonly: [ ] ³",17,vio.row / 2,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Hidden:   [ ] ³",17,(vio.row / 2) + 1,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ System:   [ ] ³",17,(vio.row / 2) + 2,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Archived: [ ] ³",17,(vio.row / 2) + 3,
                   34,&nattr,0);
  VioWrtCharStrAtt("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ",17,(vio.row / 2) + 4,
                   34,&nattr,0);
  VioWrtNAttr(&sattr,1,vio.row / 2,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 1,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 2,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 3,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 4,51,0);
  VioWrtNAttr(&sattr,16,(vio.row / 2) + 5,36,0);
  if(f->attrFile & FILE_READONLY)
    attrs[0] = 'x';
  if(f->attrFile & FILE_HIDDEN)
    attrs[1] = 'x';
  if(f->attrFile & FILE_SYSTEM)
    attrs[2] = 'x';
  if(f->attrFile & FILE_ARCHIVED)
    attrs[3] = 'x';
  for(x = 0;x < 4;x++)
    VioWrtCharStr(attrs + x,1,x + (vio.row / 2),47,0);
  VioSetCurPos(curpos + (vio.row / 2),47,0);
  ShowCursor(FALSE);
  while(okay) {
    VioWrtCharStr(attrs + curpos,1,curpos + (vio.row / 2),47,0);
    VioSetCurPos(curpos + (vio.row / 2),47,0);
    key = get_ch(-1);
    switch(key) {
      case 256:
        break;

      case 45 | 256:
      case 61 | 256:
      case '\x1b':  /* abort */
        okay = FALSE;
        ret = -1;
        break;

      case '\r':      /* process */
        okay = FALSE;
        {
          FILESTATUS3 fs3;

          if(!DosQueryPathInfo(f->filename,FIL_STANDARD,&fs3,sizeof(fs3))) {
            fs3.attrFile &= (~FILE_DIRECTORY);
            if(attrs[0] == 'x')
              fs3.attrFile |= FILE_READONLY;
            else
              fs3.attrFile &= (~FILE_READONLY);
            if(attrs[1] == 'x')
              fs3.attrFile |= FILE_HIDDEN;
            else
              fs3.attrFile &= (~FILE_HIDDEN);
            if(attrs[2] == 'x')
              fs3.attrFile |= FILE_SYSTEM;
            else
              fs3.attrFile &= (~FILE_SYSTEM);
            if(attrs[3] == 'x')
              fs3.attrFile |= FILE_ARCHIVED;
            else
              fs3.attrFile &= (~FILE_ARCHIVED);
            if(DosSetPathInfo(f->filename,FIL_STANDARD,&fs3,sizeof(fs3),
                              DSPI_WRTTHRU))
              DosBeep(50,100);
            else
              ret = 1;
          }
          else
            DosBeep(50,100);
        }
        break;

      case 72 | 256:  /* up */
        curpos--;
        if(curpos > 3)
          curpos = 3;
        break;

      case 'x':
      case 'X':
      case '+':
        attrs[curpos] = 'x';
        break;

      case '-':
        attrs[curpos] = '-';
        break;

      case ' ':       /* toggle */
        attrs[curpos] = (attrs[curpos] == 'x') ? '-' : 'x';
        VioWrtCharStr(attrs + curpos,1,curpos + (vio.row / 2),47,0);
        /* intentional fallthru */
      case 80 | 256:  /* down */
        curpos++;
        if(curpos > 3)
          curpos = 0;
        break;
    }
  }

  ShowCursor(TRUE);
  VioWrtCellStr(buf,len,(vio.row / 2) - 1,0,0);
  free(buf);
  SetupConsole();
  ThreadMsg(NULL);
  return ret;
}
int EnterLine (char *buf,ULONG len,USHORT y,char *filename,
               char **choices,int numc,int start) {

  ULONG         pos = 0,c,nm,numchars = 0,tpos,wl;
  APIRET        rc;
  int           key,attr = ((7 << 4) << 8) | ' ',ret = 0;
  BOOL          okay = TRUE,insert = TRUE,lasttab = FALSE;
  char         *sav,*k = NULL,*p;
  static char   keybuf[1026];
  USHORT        t;
  FILEFINDBUF3  fb3;
  HDIR          hdir = HDIR_CREATE;

  wl = 0;

  sav = malloc(vio.col * 2);
  if(!sav) {
    DosBeep(50,100);
    *buf = 0;
    return -1;
  }

  ThreadMsg(" ");

  t = vio.col * 2;
  VioReadCellStr(sav,&t,y,0,0);
  VioWrtNCell((char *)&attr,vio.col,y,0,0);
  ShowCursor(FALSE);
  VioSetCurPos(y,0,0);

  for(c = 0;c < len - 1;c++) {          /* find end of default string */
    if(!buf[c])
      break;
  }
  pos = c;
  for(;c < len - 1;c++)                 /* space-pad remainder of buf */
    buf[c] = ' ';

  while(okay) {
    /* assure buffer is null terminated (cluck, cluck) */
    buf[len - 1] = 0;

    /* assure pos hasn't gone past our limit */
    if(pos > len - 1)
      pos = len - 1;

    /* set left side of entry field */
    if(pos < wl)
      wl = pos;
    if(pos >= wl + vio.col)
      wl = (pos - vio.col) + 1;

    /* set cursor position */
    VioSetCurPos(y,pos - wl,0);

    /* display buf */
    tpos = min(vio.col,len - wl); /* max length of displayable text */
    VioWrtCharStr(buf + wl,tpos,y,0,0); /* show text */
    if(tpos < vio.col)                  /* space-pad? */
      VioWrtNChar(" ",vio.col - tpos,y,tpos,0);

    if(k && *k)   /* "macros" waiting to be entered? */
      key = *k++; /* yep, skip keyboard input */
    else {        /* nope, go to the keyboard */
      k = NULL;   /* clear macro pointer */
      key = get_ch(-1);
    }

    switch(key) {
      case 256:       /* shiftstate changed -- ignore */
        break;

      case '\r':      /* accept input */
        okay = FALSE;
        break;

      case 45 | 256:
      case 61 | 256:
      case '\x1b':    /* Escape -- exit editor */
        memset(buf,' ',len - 1);
        buf[len - 1] = 0;
        okay = FALSE;
        ret = -1;
        break;

      case '\b':
        if(pos) {
          pos--;
          memmove(buf + pos,buf + (pos + 1),len - (pos + 1));
          buf[len - 2] = ' ';
        }
        lasttab = FALSE;
        break;

      case 25:          /* ctrl+y -- clear input */
        VioWrtNCell((char *)&attr,vio.col,y,0,0);
        memset(buf,' ',len - 1);
        buf[len - 1] = 0;
        wl = pos = 0;
        lasttab = FALSE;
        break;

      case 59 | 256:    /* F1 -- insert directory */
        k = directory;
        lasttab = FALSE;
        break;

      case 60 | 256:    /* F2 -- insert filename */
        if(filename)
          k = filename;
        lasttab = FALSE;
        break;

      case 62 | 256:    /* F4 -- insert target */
        k = target;
        lasttab = FALSE;
        break;

      case 15:          /* shift+tab */
        if(hdir != (HDIR)HDIR_CREATE) {
          DosFindClose(hdir);
          hdir = HDIR_CREATE;
          lasttab = FALSE;
        }
        /* intentional fallthru */
      case 9:           /* tab -- auto-complete */
        if(!pos || pos >= len - 1)
          break;
        if(lasttab && numchars) {
          lasttab = FALSE;
          for(tpos = 0;tpos < numchars;tpos++)
            keybuf[tpos] = '\b';
          keybuf[tpos++] = '\01';
          keybuf[tpos] = 0;
          numchars = 0;
          k = keybuf;
          break;
        }
        else {
          if(hdir != (HDIR)HDIR_CREATE)
            DosFindClose(hdir);
          hdir = HDIR_CREATE;
        }
        /* intentional fallthru */
      case 1:           /* cheat! */
        k = NULL;
        if(!pos || pos >= len - 1)
          break;
        tpos = pos - 1;
        while(tpos && buf[tpos] != ' ')
          tpos--;
        if(buf[tpos] == ' ')
          tpos++;
        strcpy(keybuf,buf + tpos);
        tpos = 0;
        while(keybuf[tpos] && keybuf[tpos] != ' ')
          tpos++;
        keybuf[tpos] = 0;
        lstrip(rstrip(keybuf));
        if(*keybuf) {
          strcat(keybuf,"*");
          nm = 1;
          if(hdir == (HDIR)HDIR_CREATE)
            rc = DosFindFirst(keybuf,
                              &hdir,
                              FILE_NORMAL    | FILE_HIDDEN   | FILE_SYSTEM |
                              FILE_DIRECTORY | FILE_ARCHIVED | FILE_READONLY,
                              &fb3,
                              sizeof(fb3),
                              &nm,
                              FIL_STANDARD);
          else
            rc = DosFindNext(hdir,&fb3,sizeof(fb3),&nm);
          if(!rc) {
            while((fb3.attrFile & FILE_DIRECTORY) &&
                  (*fb3.achName == '.' && (!fb3.achName[1] ||
                                           (fb3.achName[1] == '.' &&
                                            !fb3.achName[2])))) {
              nm = 1;
              if(DosFindNext(hdir,&fb3,sizeof(fb3),&nm)) {
                DosFindClose(hdir);
                hdir = HDIR_CREATE;
                *fb3.achName = 0;
                break;
              }
            }
            if(*fb3.achName) {
              keybuf[strlen(keybuf) - 1] = 0;
              p = strchr(keybuf,'\\');
              if(p)
                p++;
              else
                p = keybuf;
              tpos = 0;
              while(*p && fb3.achName[tpos] &&
                    toupper(*p) == toupper(fb3.achName[tpos])) {
                p++;
                tpos++;
              }
              if(fb3.achName[tpos]) {
                strcpy(keybuf,fb3.achName + tpos);
                numchars = strlen(keybuf);
                lasttab = TRUE;
                k = keybuf;
              }
              else if(hdir != (HDIR)HDIR_CREATE) {
                DosFindClose(hdir);
                hdir = HDIR_CREATE;
              }
            }
          }
          else if(hdir != (HDIR)HDIR_CREATE) {
            DosBeep(50,50);
            DosFindClose(hdir);
            hdir = HDIR_CREATE;
          }
        }
        break;

      case 83 | 256:    /* delete */
        memmove(buf + pos,buf + (pos + 1),len - (pos + 1));
        buf[len - 2] = ' ';
        lasttab = FALSE;
        break;

      case 82 | 256:    /* insert */
        insert = (insert) ? FALSE : TRUE;
        break;

      case 71 | 256:    /* home */
        wl = pos = 0;
        lasttab = FALSE;
        break;

      case 79 | 256:    /* end */
        pos = len - 2;
        while(pos && buf[pos] == ' ')
          pos--;
        if(pos && buf[pos] != ' ')
          pos++;
        lasttab = FALSE;
        break;

      case 75 | 256:    /* left */
        if(pos)
          pos--;
        lasttab = FALSE;
        break;

      case 77 | 256:    /* right */
        if(pos < len - 1)
          pos++;
        lasttab = FALSE;
        break;

      case 72 | 256:    /* up */
        lasttab = FALSE;
        if(choices) {
          if(choices[start]) {
            VioWrtNCell((char *)&attr,vio.col,y,0,0);
            memset(buf,' ',len - 1);
            buf[len - 1] = 0;
            wl = pos = 0;
            k = choices[start];
            start++;
            while(start < numc && !choices[start])
              start++;
            if(start > (numc - 1))
              start = 0;
            if(!choices[start]) {
              while(start < numc && !choices[start])
                start++;
            }
            if(start > (numc - 1))
              start = 0;
          }
        }
        break;

      case 80 | 256:    /* down */
        lasttab = FALSE;
        if(choices) {
          if(choices[start]) {
            VioWrtNCell((char *)&attr,vio.col,y,0,0);
            memset(buf,' ',len - 1);
            buf[len - 1] = 0;
            wl = pos = 0;
            k = choices[start];
            start--;
            while(start >= 0 && !choices[start])
              start--;
            if(start < 0)
              start = numc - 1;
            if(!choices[start]) {
              while(start >= 0 && !choices[start])
                start--;
            }
            if(start < 0)
              start = numc - 1;
          }
        }
        break;

      case 115 | 256:   /* ctrl+left */
        while(pos && buf[pos] == ' ')
          pos--;
        while(pos && buf[pos] != ' ')
          pos--;
        lasttab = FALSE;
        break;

      case 116 | 256:   /* ctrl + right */
        while(pos < len - 1 && buf[pos] == ' ')
          pos++;
        while(pos < len - 1 && buf[pos] != ' ')
          pos++;
        lasttab = FALSE;
        break;

      default:
        if(pos < len - 1 && !(key & 256) && !iscntrl(key)) {
          if(insert) {
            if(pos < len - 2) {
              memmove(buf + (pos + 1),buf + pos,len - (pos + 2));
              buf[len - 2] = ' ';
            }
            buf[pos] = (char)key;
          }
          else
            buf[pos] = (char)key;
          pos++;
        }
        else if(pos >= len - 1)
          DosBeep(250,25);
        break;
    }
  }

  if(hdir != (HDIR)HDIR_CREATE)
    DosFindClose(hdir);

  ShowCursor(TRUE);
  VioWrtCellStr(sav,vio.col * 2,y,0,0);
  free(sav);
  SetupConsole();

  ThreadMsg(NULL);

  buf[len - 1] = 0;
  lstrip(rstrip(buf));
  return (ret) ? ret : strlen(buf);
}
示例#6
0
void StateMain::Setup()
{
	Vector3f limMin = Vector3f(-10.0f, -5.0f, 0.0f);
	Vector3f limMax = Vector3f(10.0f, 5.0f, 0.0f);
	GLint aPos = m_pProgramManager->Program("basicProgram1")->GetAttribute("attributePosition");


	// INTERPOLATION LINES
	//

	// initialize points vao
	glGenVertexArrays(1, &vaoLines);
	glError("StateMain::Setup()", "glGenVertexArrays() vaoLines");

	glBindVertexArray(vaoLines);
	glError("StateMain::Setup()", "glBindVertexArray() vaoLines");

	// line coordinates
	linesInterpolation = new line3[sizeof(line3) * nLines];
	line3 *p = linesInterpolation;

	/*
	p->v0 = Vector3f(limMin.x, limMin.y, limMin.z);		p->v1 = Vector3f(limMin.x, limMax.y, limMax.z);		p++;
	p->v0 = Vector3f(limMin.x, limMax.y, limMax.z);		p->v1 = Vector3f(limMax.x, limMax.y, limMin.z);		p++;
	p->v0 = Vector3f(limMax.x, limMax.y, limMin.z);		p->v1 = Vector3f(limMax.x + 3.0f, limMin.y, limMax.z);
	*/
	p->v0 = Vector3f(limMin.x, limMin.y, 0.0f);		p->v1 = Vector3f(limMin.x, limMax.y, 0.0f);		p++;
	p->v0 = Vector3f(limMin.x, limMax.y, 0.0f);		p->v1 = Vector3f(limMax.x, limMax.y, 0.0f);		p++;
	p->v0 = Vector3f(limMax.x, limMax.y, 0.0f);		p->v1 = Vector3f(limMax.x, limMin.y, 0.0f);

	// init vbo
	glGenBuffers(1, &vboLines);
	glError("StateMain::Setup()", "glGenBuffers() vboLines");

	glBindBuffer(GL_ARRAY_BUFFER, vboLines);
	glError("StateMain::Setup()", "glBindBuffer() vboLines");

	glBufferData(GL_ARRAY_BUFFER, sizeof(line3) * nLines, linesInterpolation, GL_DYNAMIC_DRAW);

	glEnableVertexAttribArray(aPos);
	glVertexAttribPointer(aPos, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
	glDisableVertexAttribArray(aPos);


	// INTERPOLATION POINTS
	//
	glPointSize(3.0f);

	// initialize points vao
	glGenVertexArrays(1, &vaoPoints);
	glError("StateMain::Setup()", "glGenVertexArrays() vaoPoints");

	glBindVertexArray(vaoPoints);
	glError("StateMain::Setup()", "glBindVertexArray() vaoPoints");

	// point coordinates
	pointsInterpolation = new Vector3f[nLines];
	pointsInterpolation[0] = LERP3(0.5, linesInterpolation[0]);
	pointsInterpolation[1] = LERP3(0.5, linesInterpolation[1]);

	// init vbo
	glGenBuffers(1, &vboPoints);
	glError("StateMain::Setup()", "glGenBuffers() vboPoints");

	glBindBuffer(GL_ARRAY_BUFFER, vboPoints);
	glError("StateMain::Setup()", "glBindBuffer() vboPoints");

	glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3f) * nLines, pointsInterpolation, GL_DYNAMIC_DRAW);

	glEnableVertexAttribArray(aPos);
	glVertexAttribPointer(aPos, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
	glDisableVertexAttribArray(aPos);


	// TRACE POINTS
	//

	// initialize points2 vao
	glGenVertexArrays(1, &vaoPoints2);
	glError("StateMain::Setup()", "glGenVertexArrays() vaoPoints2");

	glBindVertexArray(vaoPoints2);
	glError("StateMain::Setup()", "glBindVertexArray() vaoPoints2");

	// trace point coordinates
	pointsTrace = new Vector3f[nTrace];
	for (int i = 0; i < nTrace; i++)
	{
		float t = (float)i / 60.0f;
		pointsTrace[i] = LERP3(t,
			LERP3(t, LERP3(t, linesInterpolation[0]), LERP3(t, linesInterpolation[1])),
			LERP3(t, LERP3(t, linesInterpolation[1]), LERP3(t, linesInterpolation[2])));
	}

	// init vbo
	glGenBuffers(1, &vboPoints2);
	glError("StateMain::Setup()", "glGenBuffers() vboPoints2");

	glBindBuffer(GL_ARRAY_BUFFER, vboPoints2);
	glError("StateMain::Setup()", "glBindBuffer() vboPoints2");

	glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3f) * nTrace, pointsTrace, GL_STATIC_DRAW);

	glEnableVertexAttribArray(aPos);
	glVertexAttribPointer(aPos, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
	glDisableVertexAttribArray(aPos);


	SetupConsole();


} // end StateMain::Setup()
示例#7
0
文件: win32.c 项目: Raj64742/ns2
int APIENTRY
WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszCmdLine,
    int nCmdShow)
{
    char *p;
    WSADATA WSAdata;
    int retcode;

    setlocale(LC_ALL, "C");

    /* XXX
     * initialize our socket interface plus the tcl 7.5 socket
     * interface (since they redefine some routines we call).
     * eventually we should just call the tcl sockets but at
     * the moment that's hard to set up since they only support
     * tcp in the notifier.
     */
    if (WSAStartup(MAKEWORD (1, 1), &WSAdata)) {
    	perror("Windows Sockets init failed");
	abort();
    }
/*    TclHasSockets(NULL);

    TkWinXInit(hInstance); */

    /*
     * Increase the application queue size from default value of 8.
     * At the default value, cross application SendMessage of WM_KILLFOCUS
     * will fail because the handler will not be able to do a PostMessage!
     * This is only needed for Windows 3.x, since NT dynamically expands
     * the queue.
     */
    SetMessageQueue(64);

    GetModuleFileName(NULL, argv0, 255);
    p = argv0;
    __progname = strrchr(p, '/');
    if (__progname != NULL) {
	__progname++;
    }
    else {
	__progname = strrchr(p, '\\');
	if (__progname != NULL) {
	    __progname++;
	} else {
	    __progname = p;
	}
    }

    if (__argc>1) {            
            SetupConsole();
    }

    retcode=main(__argc, (const char**)__argv);
    if (retcode!=0) {
            assert(FALSE);      /* don't die without letting user know why */
    }
    return retcode;
}