Exemple #1
0
bool UmcConsole::RunCmdLine()
{
	apt_bool_t running = true;
	char cmdline[1024];
	apr_size_t i;
	do 
	{
		printf(">");
		memset(&cmdline, 0, sizeof(cmdline));
		for(i = 0; i < sizeof(cmdline); i++) 
		{
			cmdline[i] = (char) getchar();
			if(cmdline[i] == '\n') 
			{
				cmdline[i] = '\0';
				break;
			}
		}
		if(*cmdline) 
		{
			running = ProcessCmdLine(cmdline);
		}
	}
	while(running != 0);
	return true;
}
Exemple #2
0
/*****************************************************************************
 * Name       : WinMain
 * Description: Main windows entry point
 * Parameters : hInstance
 *              hPrev
 *              szCmdLine
 *              nShow
 * Returns    : Program exit code
 */
int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
{
    LOG(LOG_FILE, 0, 0, "winecfg\n");
    if (ProcessCmdLine(szCmdLine)) {
        return 0;
    }

    if (initialize(hInstance) != 0) {
        WINE_ERR("initialization failed, aborting\n");
        LOG(LOG_FILE, 0, 0, "initialization failed, aborting\n");
        ExitProcess(1);
    }
    
    /*
     * The next 9 lines should be all that is needed
     * for the Wine Configuration property sheet
     */
    InitCommonControls ();
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (doPropertySheet (hInstance, NULL) > 0) {
	    WINE_TRACE("OK\n");
    } else {
	    WINE_TRACE("Cancel\n");
    }
    CoUninitialize(); 
    ExitProcess (0);

    return 0;
}
Exemple #3
0
WORD KappaDevelopment(LPSTR lpszCmdLine, int cmdShow, BOOL bMulti)
{
    MSG msg;

    /* Process cmdLine */
    KppLoadUserDLLs(hInstKappa, bMulti);

#ifndef RUNTIME
    ProcessCmdLine(lpszCmdLine, bMulti);
#else
    if (!ProcessCmdLine(lpszCmdLine, bMulti))
    {
        HWND hWndSession = KpsGetMainSessionWindow();
        
        if (!IsZoomed(hWndSession) && !IsIconic(hWndSession))
            ShowWindow(hWndSession, cmdShow);
        KppSetAppChanged(FALSE);
    }
#endif
    
    InitObjectBrowser();

    Catch((LPCATCHBUF) initial_catch);

    while (GetMessage(&msg, NULL, 0, 0)) {
        HWND hWnd = GetActiveWindow();

#ifndef RUNTIME
        if (hWnd == hWndInterpret)
            hWnd = hWndKAL;
#endif
            
        if (!TranslateAccelerator(hWnd, hAccelTable, &msg))
        {
            /* Don't translate on interpreter window. Otherwise, *
             * <CR> gets translated as well                      */

            TranslateMessage(&msg);
            if (KpsIsASessionWindow(hWnd) || hWnd == hWndBrowser)
                KpiIsButtonKeyMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return msg.wParam;
}
Exemple #4
0
/**
  Execute the passed in file like a series of commands. The ; can be used on
  a single line to indicate multiple commands per line. The Ascii text file 
  can contain any number of lines. The following line termination forms are 
  supported:
    LF   : Unix, Mac OS X*, BeOS
    CR+LF: MS-DOS*, Microsoft Windows*
    CR   : Commodore, Apple II, and really Mac OS
    LF+CR: for simplicity and completeness 

  Argv[0] - "script"
  Argv[1] - Device Name:path for the file to load

  script fv1:\script.txt

  @param  Argc   Number of command arguments in Argv
  @param  Argv   Array of strings that represent the parsed command line. 
                 Argv[0] is the command name

  @return EFI_SUCCESS

**/
EFI_STATUS
EblScriptCmd (
  IN UINTN  Argc,
  IN CHAR8  **Argv
  )
{
  EFI_STATUS                    Status;
  EFI_OPEN_FILE                 *File;
  VOID                          *Address;
  UINTN                         Size;
  CHAR8                         *Ptr;
  CHAR8                         *ScanPtr;
  UINTN                         CmdLineSize;
  
  

  if (Argc < 2) {
    // file name required
    return EFI_SUCCESS;
  }

  File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);
  if (File == NULL) {
    AsciiPrint ("  %a is not a valid path\n", Argv[1]);
    return EFI_SUCCESS;
  }

  Status = EfiReadAllocatePool (File, &Address, &Size);
  if (!EFI_ERROR (Status)) {
    // Loop through each line in the text file
    for (Ptr = (CHAR8 *)Address; (Ptr < (((CHAR8 *)Address) + Size)) && !EFI_ERROR (Status); Ptr += CmdLineSize) {
      for (CmdLineSize = 0, ScanPtr = Ptr; ; CmdLineSize++, ScanPtr++) {
        // look for the end of the line
        if ((*ScanPtr == EBL_CR) || (*ScanPtr == EBL_LF)) {
          // convert to NULL as this is what input routine would do
          *ScanPtr = 0;
          if ((*(ScanPtr + 1) == EBL_CR) || (*(ScanPtr + 1) == EBL_LF)) {
            // if its a set get the 2nd EOL char
            CmdLineSize++;
            *(ScanPtr + 1) = 0;
          }
          CmdLineSize++;
          break;
        }
        
      }

      Status = ProcessCmdLine (Ptr, CmdLineSize);
    }
  
    FreePool (Address);
  }
 
  EfiClose (File);
  return Status;
}
int main(int argc, char* argv[])
	{
	PrintHello();

	if (ProcessCmdLine(argc, argv) != 0)
		return -1;

	OpenUsbDevice();

	if (dwRC == USBIO_ERR_SUCCESS)
		{
		GetDeviceDescriptor();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		GetConfigurationDescriptor();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		GetStringDescriptor();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		SetConfiguration();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		// In order to give the USB device-side program (t_usb)
		// enough time after getting configured to carry out
		// some device tests, we wait here for a short while
		// before proceeding:
		Delay(2000);
		GetConfigurationInfo();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		OpenPipes();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		ExchangeVersions();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		DoTransfers();
		}
	if (dwRC == USBIO_ERR_SUCCESS)
		{
		ClosePipes();
		}

	CloseUsbDevice();

	return 0;
	}
Exemple #6
0
int APIENTRY wWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPWSTR    lpCmdLine,
                      int       nCmdShow)
{
    MSG msg;
    HACCEL hAccel;

    UNREFERENCED_PARAMETER(hPrevInstance);

    if (ProcessCmdLine(lpCmdLine))
    {
        return 0;
    }

    /* Initialize global strings */
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);

   
    switch (GetUserDefaultUILanguage())
  {
    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
      SetProcessDefaultLayout(LAYOUT_RTL);
      break;

    default:
      break;
  }
    /* Store instance handle in our global variable */
    hInst = hInstance;

    /* Perform application initialization */
    if (!InitInstance(hInstance, nCmdShow))
    {
        return 0;
    }
    hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(ID_ACCEL));

    /* Main message loop */
    while (GetMessageW(&msg, NULL, 0, 0))
    {
        if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg) &&
            !TranslateChildTabMessage(&msg))
        {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }

    ExitInstance(hInstance);
    return (int)msg.wParam;
}
Exemple #7
0
int APIENTRY wWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPWSTR    lpCmdLine,
                      int       nCmdShow)
{
    MSG msg;
    HACCEL hAccel;

    UNREFERENCED_PARAMETER(hPrevInstance);

    if (ProcessCmdLine(lpCmdLine))
    {
        return 0;
    }

    /* Initialize global strings */
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
    LoadString(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);

    /* Store instance handle in our global variable */
    hInst = hInstance;

    /* Perform application initialization */
    if (!InitInstance(hInstance, nCmdShow))
    {
        return FALSE;
    }
    hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));

    /* Main message loop */
    while (GetMessage(&msg, (HWND)NULL, 0, 0))
    {
        if (!TranslateAccelerator(hFrameWnd, hAccel, &msg)
                && !TranslateChildTabMessage(&msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    ExitInstance(hInstance);
    return (int) msg.wParam;
}
Exemple #8
0
int WlibMainLine( char *argv[] )
{
    int     retcode;

    InitCmdLine();          // JBS 99/07/09 reset options for each use
    if( !setjmp( Env ) ) {
        ProcessCmdLine( argv );
        ProcessCommands();
        retcode = EXIT_SUCCESS;
    } else {
        retcode = EXIT_FAILURE;
    }
    if( !setjmp( Env ) ) {
        ResetInputLibs();
        ResetFileTab();
        ResetCmdLine();
        ResetLibIo();
        ResetMem();
    } else {
        retcode = EXIT_FAILURE;
    }
    return( retcode );
}
Exemple #9
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    MSG msg;
    HACCEL hAccel;

    if (ProcessCmdLine(lpCmdLine)) {
        return 0;
    }

    /* Initialize global strings */
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
    LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, COUNT_OF(g_pszDefaultValueName));

    /* Store instance handle in our global variable */
    hInst = hInstance;

    /* Perform application initialization */
    if (!InitInstance(hInstance, nCmdShow)) {
        return FALSE;
    }
    hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));

    /* Main message loop */
    while (GetMessageW(&msg, NULL, 0, 0)) {
        if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
                && !TranslateChildTabMessage(&msg)) {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }
    ExitInstance();
    return msg.wParam;
}
Exemple #10
0
int 
main ( int argc, char* argv[] ){

	NodeObj Main = NewNode();

	SetPropInt(Main, "State", Starting);

	TimeUpdate();

	DebugPrint ( "Entering Main", __FILE__, __LINE__, PROG_FLOW);

	ProcessCmdLine(Main, argc, argv);

	Init(Main);

	InstallObjects();

	LoadDefaultApp(Main);

	DebugPrint ( "Entering Main Loop.", __FILE__, __LINE__, PROG_FLOW);

	while(IsRunning(Main)){
		MainLoop(Main);
		// improvement: get delay from next scheduled item, min of 10 usecs
		usleep(10);
	}

	DebugPrint ( "No more tasks scheduled, cleaning up and exiting", __FILE__, __LINE__, PROG_FLOW);

	if (GetValueInt(GetPropNode(Main, "PrintNodes"))) {
		DebugPrint ( "Dumping Main Node on exit because -p was passed on command line.\n", __FILE__, __LINE__, PROG_FLOW);
		PrintNode(Main);
	}

	return 0;
}
Exemple #11
0
/**
  Embedded Boot Loader (EBL) - A simple EFI command line application for embedded
  devices. PcdEmbeddedAutomaticBootCommand is a complied in command line that
  gets executed automatically. The ; separator allows multiple commands
  for each command line.

  @param  ImageHandle   EFI ImageHandle for this application.
  @param  SystemTable   EFI system table

  @return EFI status of the application

**/
EFI_STATUS
EFIAPI
EdkBootLoaderEntry (
  IN EFI_HANDLE                            ImageHandle,
  IN EFI_SYSTEM_TABLE                      *SystemTable
  )
{
  EFI_STATUS  Status;
  CHAR8       CmdLine[MAX_CMD_LINE];
  CHAR16      *CommandLineVariable = NULL;
  CHAR16      *CommandLineVariableName = L"default-cmdline";
  UINTN       CommandLineVariableSize = 0;
  EFI_GUID    VendorGuid;

  // Initialize tables of commands
  EblInitializeCmdTable ();
  EblInitializeDeviceCmd ();
  EblInitializemdHwDebugCmds ();
  EblInitializemdHwIoDebugCmds ();
  EblInitializeDirCmd ();
  EblInitializeHobCmd ();
  EblInitializeScriptCmd ();
  EblInitializeExternalCmd ();
  EblInitializeNetworkCmd();
  EblInitializeVariableCmds ();

  if (gST->ConOut == NULL) {
    DEBUG((EFI_D_ERROR,"Error: No Console Output\n"));
    return EFI_NOT_READY;
  }

  // Disable the 5 minute EFI watchdog time so we don't get automatically reset
  gBS->SetWatchdogTimer (0, 0, 0, NULL);

  if (FeaturePcdGet (PcdEmbeddedMacBoot)) {
    // A MAC will boot in graphics mode, so turn it back to text here
    // This protocol was removed from edk2. It is only an edk thing. We need to make our own copy.
    // DisableQuietBoot ();

    // Enable the biggest output screen size possible
    gST->ConOut->SetMode (gST->ConOut, (UINTN)gST->ConOut->Mode->MaxMode - 1);

  }

  // Save current screen mode
  gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &gScreenColumns, &gScreenRows);

  EblPrintStartupBanner ();

  // Parse command line and handle commands separated by ;
  // The loop prints the prompt gets user input and saves history

  // Look for a variable with a default command line, otherwise use the Pcd
  ZeroMem(&VendorGuid, sizeof(EFI_GUID));

  Status = gRT->GetVariable(CommandLineVariableName, &VendorGuid, NULL, &CommandLineVariableSize, CommandLineVariable);
  if (Status == EFI_BUFFER_TOO_SMALL) {
    CommandLineVariable = AllocatePool(CommandLineVariableSize);

    Status = gRT->GetVariable(CommandLineVariableName, &VendorGuid, NULL, &CommandLineVariableSize, CommandLineVariable);
    if (!EFI_ERROR(Status)) {
      UnicodeStrToAsciiStrS (CommandLineVariable, CmdLine, MAX_CMD_LINE);
    }

    FreePool(CommandLineVariable);
  }

  if (EFI_ERROR(Status)) {
    AsciiStrCpyS (CmdLine, MAX_CMD_LINE, (CHAR8 *)PcdGetPtr (PcdEmbeddedAutomaticBootCommand));
  }

  for (;;) {
    Status = ProcessCmdLine (CmdLine, MAX_CMD_LINE);
    if (Status == EFI_ABORTED) {
      // if a command returns EFI_ABORTED then exit the EBL
      EblShutdownExternalCmdTable ();
      return EFI_SUCCESS;
    }

    // get the command line from the user
    EblPrompt ();
    GetCmd (CmdLine, MAX_CMD_LINE);
    SetCmdHistory (CmdLine);

    if (FeaturePcdGet (PcdEmbeddedProbeRemovable)) {
      // Probe removable media devices to see if media has been inserted or removed.
      EblProbeRemovableMedia ();
    }
  }
}
Exemple #12
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine,
                   int nShow)
{
    /* Structure with the data and settings for the application */
    /* data is: hwnd, lpdi, joy[], num_joy, cur_joy, chosen_joy, poll_time, axes_max, axes_min, buffered */
    struct JoystickData data =
    { NULL, NULL, NULL, 0, 0, 0, 0, 1000, -1000, FALSE };
    HRESULT hr;

    hr = DirectInput8Create(GetModuleHandleA(NULL), DIRECTINPUT_VERSION,
                            &IID_IDirectInput8A, (void **)&data.di, NULL);

    if (FAILED(hr)) {
        printf("Failed to initialize DirectInput: 0x%08x\n", hr);
        return 1;
    }

    /* First count how many joysticks are there */
    hr = IDirectInput8_EnumDevices(data.di, DI8DEVCLASS_GAMECTRL,
                                   EnumCallback, &data, DIEDFL_ATTACHEDONLY);
    data.joysticks = malloc(sizeof(struct Joystick) * data.num_joysticks);

    /* Get all the joysticks */
    hr = IDirectInput8_EnumDevices(data.di, DI8DEVCLASS_GAMECTRL,
                                   EnumCallback, &data, DIEDFL_ATTACHEDONLY);

    /* Get settings from the command line */
    ProcessCmdLine(&data, szCmdLine);

    /* Apply settings for all joysticks */
    for (data.cur_joystick = 0; data.cur_joystick < data.num_joysticks;
            data.cur_joystick++) {
        IDirectInputDevice8_EnumObjects(data.joysticks[data.cur_joystick].
                                        device, EnumObjectsCallback, &data,
                                        DIDFT_AXIS | DIDFT_BUTTON);
    }

    printf("Found %d joysticks.\n", data.num_joysticks);

    /* Default case just lists the joysticks */
    if (data.poll_time == 0) {

        int i = 0;
        for (i = 0; i < data.num_joysticks; i++)
            printf("%d: %s\n", i, data.joysticks[i].instance.tszInstanceName);
    }
    else {

        /* If we'll poll the joystick for input */
        if (data.num_joysticks > 0) {

            if (data.chosen_joystick >= data.num_joysticks
                    || data.chosen_joystick < 0) {
                printf("Joystick '%d' is not connected\n",
                       data.chosen_joystick);
                exit(1);
            }

            WaitForInput(&data);
        }
    }
    return 0;
}
int
LauncherMain(int argc, wchar_t* argv[])
{
  // Make sure that the launcher process itself has image load policies set
  if (IsWin10AnniversaryUpdateOrLater()) {
    const DynamicallyLinkedFunctionPtr<decltype(&SetProcessMitigationPolicy)>
      pSetProcessMitigationPolicy(L"kernel32.dll", "SetProcessMitigationPolicy");
    if (pSetProcessMitigationPolicy) {
      PROCESS_MITIGATION_IMAGE_LOAD_POLICY imgLoadPol = {};
      imgLoadPol.PreferSystem32Images = 1;

      DebugOnly<BOOL> setOk = pSetProcessMitigationPolicy(ProcessImageLoadPolicy,
                                                          &imgLoadPol,
                                                          sizeof(imgLoadPol));
      MOZ_ASSERT(setOk);
    }
  }

  if (!SetArgv0ToFullBinaryPath(argv)) {
    ShowError();
    return 1;
  }

  LauncherFlags flags = ProcessCmdLine(argc, argv);

  nsAutoHandle mediumIlToken;
  Maybe<ElevationState> elevationState = GetElevationState(flags, mediumIlToken);
  if (!elevationState) {
    return 1;
  }

  // If we're elevated, we should relaunch ourselves as a normal user.
  // Note that we only call LaunchUnelevated when we don't need to wait for the
  // browser process.
  if (elevationState.value() == ElevationState::eElevated &&
      !(flags & (LauncherFlags::eWaitForBrowser | LauncherFlags::eNoDeelevate)) &&
      !mediumIlToken.get()) {
    return !LaunchUnelevated(argc, argv);
  }

  // Now proceed with setting up the parameters for process creation
  UniquePtr<wchar_t[]> cmdLine(MakeCommandLine(argc, argv));
  if (!cmdLine) {
    return 1;
  }

  const Maybe<bool> isSafeMode = IsSafeModeRequested(argc, argv,
                                                     SafeModeFlag::NoKeyPressCheck);
  if (!isSafeMode) {
    ShowError(ERROR_INVALID_PARAMETER);
    return 1;
  }

  ProcThreadAttributes attrs;
  SetMitigationPolicies(attrs, isSafeMode.value());

  HANDLE stdHandles[] = {
    ::GetStdHandle(STD_INPUT_HANDLE),
    ::GetStdHandle(STD_OUTPUT_HANDLE),
    ::GetStdHandle(STD_ERROR_HANDLE)
  };

  attrs.AddInheritableHandles(stdHandles);

  DWORD creationFlags = CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT;

  STARTUPINFOEXW siex;
  Maybe<bool> attrsOk = attrs.AssignTo(siex);
  if (!attrsOk) {
    ShowError();
    return 1;
  }

  BOOL inheritHandles = FALSE;

  if (attrsOk.value()) {
    creationFlags |= EXTENDED_STARTUPINFO_PRESENT;

    if (attrs.HasInheritableHandles()) {
      siex.StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
      siex.StartupInfo.hStdInput = stdHandles[0];
      siex.StartupInfo.hStdOutput = stdHandles[1];
      siex.StartupInfo.hStdError = stdHandles[2];

      // Since attrsOk == true, we have successfully set the handle inheritance
      // whitelist policy, so only the handles added to attrs will be inherited.
      inheritHandles = TRUE;
    }
  }

  PROCESS_INFORMATION pi = {};
  BOOL createOk;

  if (mediumIlToken.get()) {
    createOk = ::CreateProcessAsUserW(mediumIlToken.get(), argv[0], cmdLine.get(),
                                      nullptr, nullptr, inheritHandles,
                                      creationFlags, nullptr, nullptr,
                                      &siex.StartupInfo, &pi);
  } else {
    createOk = ::CreateProcessW(argv[0], cmdLine.get(), nullptr, nullptr,
                                inheritHandles, creationFlags, nullptr, nullptr,
                                &siex.StartupInfo, &pi);
  }

  if (!createOk) {
    ShowError();
    return 1;
  }

  nsAutoHandle process(pi.hProcess);
  nsAutoHandle mainThread(pi.hThread);

  if (!PostCreationSetup(process.get(), mainThread.get(), isSafeMode.value()) ||
      ::ResumeThread(mainThread.get()) == static_cast<DWORD>(-1)) {
    ShowError();
    ::TerminateProcess(process.get(), 1);
    return 1;
  }

  if (flags & LauncherFlags::eWaitForBrowser) {
    DWORD exitCode;
    if (::WaitForSingleObject(process.get(), INFINITE) == WAIT_OBJECT_0 &&
        ::GetExitCodeProcess(process.get(), &exitCode)) {
      // Propagate the browser process's exit code as our exit code.
      return static_cast<int>(exitCode);
    }
  } else {
    const DWORD timeout = ::IsDebuggerPresent() ? INFINITE :
                          kWaitForInputIdleTimeoutMS;

    // Keep the current process around until the callback process has created
    // its message queue, to avoid the launched process's windows being forced
    // into the background.
    mozilla::WaitForInputIdle(process.get(), timeout);
  }

  return 0;
}
Exemple #14
0
BOOL KappaCommand(HWND hWnd, unsigned message, WORD wParam, long lParam)
{
    char stCommand[RET_BUFFER_LEN];

    switch (message) {
      case IDM_NEW:
          if (in_wait_for_input)
              return FALSE;
#ifndef RUNTIME
          if (lpKALView && (*lpKALView->Terminate)())
          {
              PostMessage(hWndKappa, WM_COMMAND, IDM_NEW, 0L);
              return FALSE;
          }
#endif
          KppNewApplication(hInstKappa);

#ifdef RUNTIME
          if (!IsWindowVisible(hWnd) && !KppGetCompiledKALInit())
              ShowWindow(hWnd, SW_SHOWNORMAL);
#endif
          break;

      case IDM_NEWLOAD:
          if (in_wait_for_input)
              return FALSE;
          if (LOWORD(lParam))
              KppSetAppChanged(FALSE);
          if (KppNewApplication(hInstKappa) && lParam)
          {
              GlobalGetAtomName(HIWORD(lParam), stCommand, RET_BUFFER_LEN);
                
#ifdef RUNTIME
              {
                  BOOL bNoShow = ProcessCmdLine(stCommand, 
                                                KppIsMultiEnabled());

                  if (!IsWindowVisible(hWnd) && !bNoShow)
                      ShowWindow(hWnd, SW_SHOWNORMAL);
              }
#else
              ProcessCmdLine(stCommand, KppIsMultiEnabled());
#endif
                    
              GlobalDeleteAtom(HIWORD(lParam));
          }
          break;

      case IDM_OPEN:
          OpenApplication(hWnd);
          break;

#ifndef LIMITED
      case IDM_SAVE:
          SaveApplication(hWnd, SAVE_MODE);
          break;

      case IDM_SAVEAS:
          SaveApplicationAs(hWnd);
          break;
#endif
          
      case IDM_SETUPPRINT:
          ConfigurePrinter();
          break;

      case IDM_EXIT:
          if (in_wait_for_input)
              return FALSE;
                
#ifdef RUNTIME
          if (hWnd != KpsGetMainSessionWindow())
          {
              ATOMID idWind = KpsGetWidgetFromWindow(hWnd);
                
              if (idWind)
                  kpc_hide_window(idWind, hWnd);
              break;
          }
#endif
          /* Postpone closing down until all DDE messages have *
           * been processed.                                   */
          if (KppDDEPendingQCB())
          {
              WaitForInputCB();
              PostMessage(hWnd, WM_COMMAND, message, lParam);
              return FALSE;
          }

#ifndef RUNTIME
          if (lpKALView && (*lpKALView->Terminate)())
          {
              PostMessage(hWnd, WM_COMMAND, IDM_EXIT, 0L);
              return FALSE;
          }
#endif
          if (lParam == kEXIT_NOPROMPT)
              MarkAppAsUnmodifiedCB();
          return KappaClose(hWnd);

      case IDM_ABOUT:
          KappaAbout(hWnd);
          break;
          
#ifndef RUNTIME
      case IDM_HELP:
          KppDoWindowHelp(hWndKappa, "d_main");
          break;
#endif

      case IDM_ONLINEHELP:
      {
          HANDLE hKapHelp = GetModuleHandle("KAPHELP");
          LPHELPFN lpfnKappaHelp = 
              (LPHELPFN) GetProcAddress(hKapHelp, "KppKappaHelp");
          
          if (lpfnKappaHelp)
              (*lpfnKappaHelp)(hWndKappa, hInstKappa);
          break;
      }

#ifndef RUNTIME
      case IDM_UNDO:
      case IDM_CUT:
      case IDM_COPY:
      case IDM_PASTE:
      case IDM_CLEAR:
          EditControlCommand(hWnd, hWndComment, message, wParam, lParam);
          break;

      case IDM_RESET:
          ClearEditWindow(hWndInterpret);
          SendMessage(hWndInterpret, IDG_UPDATEINDEX, 1, 0L);
          break;

      case IDM_KTOOLS:
#ifdef EDITORS
          KappaKToolsMode(bKToolsMode != TRUE, SW_SHOWNORMAL);
#endif
          break;
#endif
        
      case IDM_BROWSER:
          KappaBrowserMode(bBrowserMode != TRUE, SW_SHOWNORMAL);
          break;

#ifndef RUNTIME
#ifdef INFERENCE
      case IDM_INFERENCE:
          KappaInferenceMode(bInferenceMode != TRUE, SW_SHOWNORMAL);
          break;

      case IDM_RULEREL:
          KappaRuleRelMode(!bRuleRelMode, SW_SHOWNORMAL);
          break;

      case IDM_TRACE:
          KappaTraceMode(bTraceMode != TRUE, SW_SHOWNORMAL);
          break;
#endif

      case IDM_EDITORS:
          AllEditorWnds();
          break;

      case IDM_KAL:
          KappaInterpMode(!bInterpMode, SW_SHOWNORMAL);
          break;

      case IDM_FINDER:
          KappaFinderMode(!bFinderMode, SW_SHOWNORMAL);
          break;

      case IDM_KALVIEW:
          if (lpKALView)
              (*lpKALView->KALView)(!lpKALView->bKALViewMode,
                                    SW_SHOWNORMAL, 
                                    hWndKappa, hInstKappa, kalviewIcon);
          break;

      case IDM_SESSION:
          KpsAllSessionWnd();
          break;
          
      case IDM_COMMENT:
          bCommentShown = !bCommentShown;
          ShowComment(hWnd, bCommentShown);
          break;
#endif
          
      case IDM_ENTERDEBUGGER:
          DebugBreak();
          break;

      default:
          break;
    }

    return TRUE;
}
Exemple #15
0
void
main(int argc, char **argv)
{
    FILE *table_h, *srv_h, *xg_h, *clt_h, *mak_h;
    int i, j;
    rpcArgs args;
    char *name, *ifName;
    char *serverName = NULL;
    char *ipFileName = NULL;
    char *outputDir = NULL;
    int sign_no = 0, start_no, srv_no;

    ProcessCmdLine(argc, argv, &serverName, &ipFileName, &outputDir);

    /* open input file */
    table_h = fopen(ipFileName, "r");
    MEM_CHK(table_h, "main: Unable to open input file\n");

    srv_no = 1;
    start_no = sign_no;

    /*
     * open the first set of output files
     */

    name = GetName(serverName, srv_no);

    srv_h = OpenOutFile(outputDir, name, "Srv.c");
    xg_h = OpenOutFile(outputDir, name, ".xg");
    clt_h = OpenOutFile(outputDir, name, "Clt.c");
    mak_h = OpenOutFile(outputDir, name, ".mak");

    WriteXGHeader(serverName, xg_h, srv_no);
    WriteServHeader(srv_h, serverName, srv_no);
    WriteCltHeader(serverName, srv_no, clt_h);
    WriteMake(serverName, srv_no, mak_h);

    ifName = name;

    /* read the table */
    while (fscanf(table_h, "%d", &(args.argCount)) != EOF) {

	/* increment signature number 8.3 format-- only 10^7 dif sign */
	sign_no++;
	if (sign_no > 1.0e+7)
	    FATAL("Max no: of signatures overflow\n");

	/* allocate for the arg struct */
	args.argDescr =
	    (arg_tuple *) calloc(args.argCount, sizeof(arg_tuple));
	MEM_CHK(args.argDescr, "main: Out of memory -- args.argDescr\n");

	/* pick out the dirs and the types */
	for (i = 0; i < args.argCount; i++) {
	    if (!fscanf
		(table_h, " ( %s %s )", args.argDescr[i].direction,
		 args.argDescr[i].type)) {
		FATAL("main: Incorrect input file format\n");
	    }
	}

	/*
	 * switch files when we hit TESTS_PER_FILE
	 */
	if (sign_no - start_no >= TESTS_PER_FILE) {
	    /*
	     * Finish up the current files
	     */
	    WriteServTrailer(srv_h);
	    WriteCltTrailer(serverName, start_no, sign_no, clt_h);
	    fclose(xg_h);
	    fclose(srv_h);
	    fclose(clt_h);
	    fclose(mak_h);

	    /*
	     * Open the next set of output files
	     */

	    srv_no++;
	    free(ifName);
	    name = GetName(serverName, srv_no);

	    srv_h = OpenOutFile(outputDir, name, "Srv.c");
	    xg_h = OpenOutFile(outputDir, name, ".xg");
	    clt_h = OpenOutFile(outputDir, name, "Clt.c");
	    mak_h = OpenOutFile(outputDir, name, ".mak");
	    WriteXGHeader(serverName, xg_h, srv_no);
	    WriteServHeader(srv_h, serverName, srv_no);
	    WriteCltHeader(serverName, srv_no, clt_h);
	    WriteMake(serverName, srv_no, mak_h);

	    start_no = sign_no;
	    ifName = name;
	}

	/* initialize parameter values */
	for (i = 0; i < args.argCount; i++) {
	    for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++) {
		args.argDescr[i].inValue[j] = NULL;
		args.argDescr[i].inValue2[j] = NULL;
		args.argDescr[i].outValue[j] = NULL;
		args.argDescr[i].outValue2[j] = NULL;
	    }
	}
	GenParamValues(&args);

	/* write rpc desc into body of the interface */
	WriteXG(&args, xg_h, serverName, sign_no);

	/* write the rpc into the manager file */
	WriteServC(&args, srv_h, serverName, sign_no);

	/* write out ITL test */
	WriteClt(&args, serverName, sign_no, clt_h);

	/* free saved values */
	for (i = 0; i < args.argCount; i++) {
	    for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++) {
		if (args.argDescr[i].inValue[j])
		    free(args.argDescr[i].inValue[j]);
		if (args.argDescr[i].inValue2[j])
		    free(args.argDescr[i].inValue2[j]);
		if (args.argDescr[i].outValue[j])
		    free(args.argDescr[i].outValue[j]);
		if (args.argDescr[i].outValue2[j])
		    free(args.argDescr[i].outValue2[j]);
	    }
	}
	free(args.argDescr);
    }

    WriteServTrailer(srv_h);
    WriteCltTrailer(serverName, start_no, (sign_no + 1), clt_h);

    fclose(clt_h);

    fclose(table_h);
    fclose(xg_h);
    fclose(srv_h);
    fclose(mak_h);

    /*
     * create 1 makefile that drives all the rest
     */

    mak_h = OpenOutFile(outputDir, "Makefile", "");
    fprintf(mak_h, "\ntest:all\ntests:all\nall:\n");
    fprintf(mak_h, "%s", platform[8]);
    for (i = 1; i <= srv_no; i++)
	fprintf(mak_h, "\t%s %s%d.mak %s\n", platform[0], serverName, i,
		platform[5]);
    fprintf(mak_h, "\nclean:\n");
    for (i = 1; i <= srv_no; i++)
	fprintf(mak_h, "\t%s %s%d.mak clean\n", platform[0], serverName, i);
    fclose(mak_h);

    exit(0);
}
Exemple #16
0
int regdump(int argc, char* argv[])
{
    char Buffer[500];

    if (argc > 1) {
//      if (0 == _tcsstr(argv[1], _T("HKLM"))) {
        if (strstr(argv[1], "help")) {
            usage(argv[0]);
        } else if (strstr(argv[1], "HKCR")) {
            RegKeyPrint('1');
        } else if (strstr(argv[1], "HKCU")) {
            RegKeyPrint('2');
        } else if (strstr(argv[1], "HKLM")) {
            RegKeyPrint('3');
        } else if (strstr(argv[1], "HKU")) {
            RegKeyPrint('4');
        } else if (strstr(argv[1], "HKCC")) {
            RegKeyPrint('5');
        } else if (strstr(argv[1], "HKRR")) {
            RegKeyPrint('6');
        } else {
            dprintf("started with argc = %d, argv[1] = %s (unknown?)\n", argc, argv[1]);
        }
        return 0;
    }
    show_menu();
    while (1) {
        GetInput(Buffer, sizeof(Buffer));
        switch (toupper(Buffer[0])) {
        case '0':
            return(0);
        case '1':
            strcpy(Buffer, default_cmd_line1);
            goto doit;
        case '2':
            strcpy(Buffer, default_cmd_line2);
            goto doit;
        case '3':
            strcpy(Buffer, default_cmd_line3);
            goto doit;
        case '4':
            strcpy(Buffer, default_cmd_line4);
            goto doit;
        case '5':
            strcpy(Buffer, default_cmd_line5);
            goto doit;
        case '6':
            strcpy(Buffer, default_cmd_line6);
            goto doit;
        case '7':
            strcpy(Buffer, default_cmd_line7);
            goto doit;
        case '8':
            strcpy(Buffer, default_cmd_line8);
            goto doit;
        case '9':
            strcpy(Buffer, default_cmd_line9);
            goto doit;
        case 'A':
        case 'B':
        case 'C':
        case 'D':
        case 'E':
        case 'F':
            RegKeyPrint(toupper(Buffer[0]) - 'A' + 1);
            break;
        default: doit:
            if (!ProcessCmdLine(Buffer)) {
                dprintf("invalid input.\n");
                show_menu();
            } else {
                dprintf("done.\n");
            }
            break;
        }
    }
    return 0;
}
int
main(int argc, char *argv[])
{
    int         i, oldumask;

    argcGlobal = argc;
    argvGlobal = argv;

    configfilename = NULL;

    /* init stuff */
    ProcessCmdLine(argc, argv);

    /*
     * Do this first thing, to get any options that only take effect at
     * startup time.  It is read again each time the server resets.
     */
    if (ReadConfigFile(configfilename) != FSSuccess) {
	FatalError("couldn't read config file\n");
    }
    InitErrors();

    /* make sure at least world write access is disabled */
    if (((oldumask = umask(022)) & 002) == 002)
	(void)umask(oldumask);

    SetDaemonState();
    SetUserId();

    while (1) {
	serverGeneration++;
	OsInit();
	if (serverGeneration == 1) {
	    /* do first time init */
	    CreateSockets(OldListenCount, OldListen);
	    InitProcVectors();
	    clients = (ClientPtr *) fsalloc(MAXCLIENTS * sizeof(ClientPtr));
	    if (!clients)
		FatalError("couldn't create client array\n");
	    for (i = MINCLIENT; i < MAXCLIENTS; i++)
		clients[i] = NullClient;
	    /* make serverClient */
	    serverClient = (ClientPtr) fsalloc(sizeof(ClientRec));
	    if (!serverClient)
		FatalError("couldn't create server client\n");
	}
	ResetSockets();

	/* init per-cycle stuff */
	InitClient(serverClient, SERVER_CLIENT, (pointer) 0);

	clients[SERVER_CLIENT] = serverClient;
	currentMaxClients = MINCLIENT;
	currentClient = serverClient;

	if (!InitClientResources(serverClient))
	    FatalError("couldn't init server resources\n");

	InitAtoms();
	InitFonts();
	SetConfigValues();
	if (!create_connection_block())
	    FatalError("couldn't create connection block\n");

#ifdef DEBUG
	fprintf(stderr, "Entering Dispatch loop\n");
#endif

	Dispatch();

#ifdef DEBUG
	fprintf(stderr, "Leaving Dispatch loop\n");
#endif

	/* clean up per-cycle stuff */
	if ((dispatchException & DE_TERMINATE) || drone_server)
	    break;
	fsfree(ConnectionInfo);
	/* note that we're parsing it again, for each time the server resets */
	if (ReadConfigFile(configfilename) != FSSuccess)
	    FatalError("couldn't read config file\n");
    }

    CloseSockets();
    CloseErrors();
    exit(0);
}
void CMetronomeDlg_RegPersist::LoadSettings(LPCTSTR preset_name)
{
    TCHAR    stringbuf[MAX_BPMEASURE + 1];
    DWORD    dwType, dwSize;
    RECT    window_rect;

    HKEY hkey = OpenKey(preset_name, false);

    if(hkey)
    {
        // Load the beats per minute
        dwType = REG_DWORD;
        dwSize = sizeof(m_BPMinute);
        m_BPMinute = 120;
        RegQueryValueEx(hkey, _T("BPMinute"), 0, &dwType, (PBYTE)&m_BPMinute, &dwSize);


		// BHB - Don't keep separate hotkey settings for each preset; I think hotkeys should be global
		if (preset_name == NULL) {
			unsigned long HotKeyVKeyTEMPO_UP = 0; unsigned long HotKeyFlagTEMPO_UP = 0;
			unsigned long HotKeyVKeyTEMPO_DN = 0; unsigned long HotKeyFlagTEMPO_DN = 0;
			unsigned long HotKeyVKeyPLAY = 0; unsigned long HotKeyFlagPLAY = 0;
			unsigned long HotKeyVKeySTRAIGHT = 0; unsigned long HotKeyFlagSTRAIGHT = 0;
			unsigned long HotKeyVKeySIMPLE = 0; unsigned long HotKeyFlagSIMPLE = 0;
			unsigned long HotKeyVKeyTAP = 0; unsigned long HotKeyFlagTAP = 0;
			RegQueryValueEx(hkey, _T("HotKeyVKeyTEMPO_UP"), 0, &dwType, (PBYTE)&HotKeyVKeyTEMPO_UP, &dwSize); RegQueryValueEx(hkey, _T("HotKeyFlagTEMPO_UP"), 0, &dwType, (PBYTE)&HotKeyFlagTEMPO_UP, &dwSize); RegisterHotKey(m_hWnd, CHotKeyDlg::e_TEMPO_UP, HotKeyFlagTEMPO_UP, HotKeyVKeyTEMPO_UP); m_autopHotKeyDlg->SetHotKeyTEMPO_UP(HotKeyFlagTEMPO_UP, HotKeyVKeyTEMPO_UP);
			RegQueryValueEx(hkey, _T("HotKeyVKeyTEMPO_DN"), 0, &dwType, (PBYTE)&HotKeyVKeyTEMPO_DN, &dwSize); RegQueryValueEx(hkey, _T("HotKeyFlagTEMPO_DN"), 0, &dwType, (PBYTE)&HotKeyFlagTEMPO_DN, &dwSize); RegisterHotKey(m_hWnd, CHotKeyDlg::e_TEMPO_DN, HotKeyFlagTEMPO_DN, HotKeyVKeyTEMPO_DN); m_autopHotKeyDlg->SetHotKeyTEMPO_DN(HotKeyFlagTEMPO_DN, HotKeyVKeyTEMPO_DN);
			RegQueryValueEx(hkey, _T("HotKeyVKeyPLAY"), 0, &dwType, (PBYTE)&HotKeyVKeyPLAY, &dwSize); RegQueryValueEx(hkey, _T("HotKeyFlagPLAY"), 0, &dwType, (PBYTE)&HotKeyFlagPLAY, &dwSize); RegisterHotKey(m_hWnd, CHotKeyDlg::e_PLAY, HotKeyFlagPLAY, HotKeyVKeyPLAY); m_autopHotKeyDlg->SetHotKeyPLAY(HotKeyFlagPLAY, HotKeyVKeyPLAY);
			RegQueryValueEx(hkey, _T("HotKeyVKeySTRAIGHT"), 0, &dwType, (PBYTE)&HotKeyVKeySTRAIGHT, &dwSize); RegQueryValueEx(hkey, _T("HotKeyFlagSTRAIGHT"), 0, &dwType, (PBYTE)&HotKeyFlagSTRAIGHT, &dwSize); RegisterHotKey(m_hWnd, CHotKeyDlg::e_STRAIGHT, HotKeyFlagSTRAIGHT, HotKeyVKeySTRAIGHT); m_autopHotKeyDlg->SetHotKeySTRAIGHT(HotKeyFlagSTRAIGHT, HotKeyVKeySTRAIGHT);
			RegQueryValueEx(hkey, _T("HotKeyVKeySIMPLE"), 0, &dwType, (PBYTE)&HotKeyVKeySIMPLE, &dwSize); RegQueryValueEx(hkey, _T("HotKeyFlagSIMPLE"), 0, &dwType, (PBYTE)&HotKeyFlagSIMPLE, &dwSize); RegisterHotKey(m_hWnd, CHotKeyDlg::e_SIMPLE, HotKeyFlagSIMPLE, HotKeyVKeySIMPLE); m_autopHotKeyDlg->SetHotKeySIMPLE(HotKeyFlagSIMPLE, HotKeyVKeySIMPLE);
			RegQueryValueEx(hkey, _T("HotKeyVKeyTAP"), 0, &dwType, (PBYTE)&HotKeyVKeyTAP, &dwSize); RegQueryValueEx(hkey, _T("HotKeyFlagTAP"), 0, &dwType, (PBYTE)&HotKeyFlagTAP, &dwSize); RegisterHotKey(m_hWnd, CHotKeyDlg::e_TAP, HotKeyFlagTAP, HotKeyVKeyTAP); m_autopHotKeyDlg->SetHotKeyTAP(HotKeyFlagTAP, HotKeyVKeyTAP);
		}
        _itot(m_BPMinute, stringbuf, 10);
        ::SetWindowText(GET_HWND(IDC_BPMINUTE_EDIT), stringbuf);
 		// BHB: Bugfix - Tempo slider should update whenever BPMinute changes
		::SendMessage(GET_HWND(IDC_BPMINUTE_SLIDER), TBM_SETPOS, TRUE, BPMToSlider(m_BPMinute)); // BHB
        OnKillfocusBpminuteEdit();

        // Load the beats per measure
        dwType = REG_DWORD;
        dwSize = sizeof(m_BPMeasure);
        m_BPMeasure = 4;
        RegQueryValueEx(hkey, _T("BPMeasure"), 0, &dwType, (PBYTE)&m_BPMeasure, &dwSize);

        _itot(m_BPMeasure, stringbuf, 10);
        ::SetWindowText(GET_HWND(IDC_BPMEASURE_EDIT), stringbuf);
        
        for(char i = 0; i < MAX_SOUNDS; i++)
        {
            // Load which midi voices to use
            dwSize = sizeof(int);
            TCHAR soundname[] = _T("Sound x");
            soundname[6] = '0' + i;
            m_midi_instrument[i] = s_DefaultInstruments[i];
            RegQueryValueEx(hkey, soundname, 0, &dwType, (PBYTE )&(m_midi_instrument[i]), &dwSize);

            if (m_midi_instrument[i] < 65536)
                ::SendMessage(m_SoundCombo[i], CB_SETCURSEL, MidiToAlpha[m_midi_instrument[i]&0xFFFF], 0);
            else
                ::SendMessage(m_SoundCombo[i], CB_SETCURSEL, GM1_TRACK10_NUM_VOICES+m_midi_instrument[i]-65536, 0);

            // Load the volume of the voices
            dwSize = sizeof(int);
            TCHAR volname[] = _T("Volume x");
            volname[7] = '0' + i;
            m_midi_volume[i] = 127;
            RegQueryValueEx(hkey, volname, 0, &dwType, (PBYTE )&(m_midi_volume[i]), &dwSize);

            ::SendMessage(m_VolumeSlider[i], TBM_SETPOS, TRUE, m_midi_volume[i]);

            // Load the size of the blinker display for the voices
            dwSize = sizeof(int);
            TCHAR blinkname[] = _T("Blinker x");
            blinkname[8] = '0' + i;
            // Only load a default value if this is a startup load
            if(preset_name == NULL)
                m_blink_size[i] = MAX_SOUNDS - 1;  // Make it the biggest dot
            RegQueryValueEx(hkey, blinkname, 0, &dwType, (PBYTE )&(m_blink_size[i]), &dwSize);

            ::SendMessage(m_BlinkerSlider[i], TBM_SETPOS, TRUE, m_blink_size[i]);
            m_autopBlinkerSliderDisplay[i]->SetState(m_blink_size[i]);
        }

        // Load the custom measure string
        dwType = REG_SZ;
        dwSize = MAX_BPMEASURE + 1;
		// BHB - default to my rock beat example (former value was "31212012121")
		_tcscpy(stringbuf, _T("[2*](35)0(34)0(35)5(34)0"));
		RegQueryValueEx(hkey, _T("Custom Measure"), 0, &dwType, (PBYTE)stringbuf, &dwSize);
        ::SetWindowText(*m_autopGroupEdit.get(), stringbuf);
        
        // Load which mode to use (plain, measure, or custom)
        dwType = REG_DWORD;
        dwSize = sizeof(m_MetronomeStyle);
        m_MetronomeStyle = metPlain;
        RegQueryValueEx(hkey, _T("Metronome Style"), 0, &dwType, (PBYTE )&m_MetronomeStyle, &dwSize);

        if(m_MetronomeStyle == metPlain) 
        {
            ::SendMessage(GET_HWND(IDC_RADIO_PLAIN  ), BM_SETCHECK, BST_CHECKED  , 0);
            ::SendMessage(GET_HWND(IDC_RADIO_MEASURE), BM_SETCHECK, BST_UNCHECKED, 0);
            ::SendMessage(GET_HWND(IDC_RADIO_GROUP  ), BM_SETCHECK, BST_UNCHECKED, 0);
            OnRadioPlain(0,0);
        }
        else if(m_MetronomeStyle == metMeasure)
        {
            ::SendMessage(GET_HWND(IDC_RADIO_PLAIN  ), BM_SETCHECK, BST_UNCHECKED, 0);
            ::SendMessage(GET_HWND(IDC_RADIO_MEASURE), BM_SETCHECK, BST_CHECKED  , 0);
            ::SendMessage(GET_HWND(IDC_RADIO_GROUP  ), BM_SETCHECK, BST_UNCHECKED, 0);
            OnRadioMeasure(0,0);
        }
        else
        {
            ::SendMessage(GET_HWND(IDC_RADIO_PLAIN  ), BM_SETCHECK, BST_UNCHECKED, 0);
            ::SendMessage(GET_HWND(IDC_RADIO_MEASURE), BM_SETCHECK, BST_UNCHECKED, 0);
            ::SendMessage(GET_HWND(IDC_RADIO_GROUP  ), BM_SETCHECK, BST_CHECKED  , 0);
            OnRadioGroup(0,0);
        }

        // Load the blinking state
        dwType = REG_DWORD;
        dwSize = sizeof(m_blinking);
        m_blinking = true;
        RegQueryValueEx(hkey, _T("Blinking"), 0, &dwType, (PBYTE)&m_blinking, &dwSize);

        ::SendMessage(GET_HWND(IDC_BLINK_CHECK), BM_SETCHECK, m_blinking?BST_CHECKED:BST_UNCHECKED, 0);
        OnBlinkCheck(0,0);

        // If this is the main call to load settings (not one to load a
        // preset), then load all the preset names and set the preset
        // combo box to have the correct one selected
        if(preset_name == NULL)
        {
			// Master volume
			DWORD iMasterVolume = 100;
			RegQueryValueEx(hkey, _T("MasterVolume"), 0, &dwType, (PBYTE)&iMasterVolume, &dwSize);
			::SendMessage(GET_HWND(IDC_MASTERVOLUME_SLIDER), TBM_SETPOS, TRUE, iMasterVolume); // BHB
			m_MasterVolume = iMasterVolume / 100.0f;

            // load the presets
            int a = 0;
            unsigned long StringBufLength = sizeof(stringbuf)/sizeof(stringbuf[0]);
            while(ERROR_SUCCESS == RegEnumKeyEx(hkey, a, stringbuf, &StringBufLength, NULL, NULL, NULL, NULL))
            {
                ::SendMessage(GET_HWND(IDC_PRESET_COMBO), CB_ADDSTRING, 0, (long)(LPCTSTR)stringbuf);
                StringBufLength = sizeof(stringbuf)/sizeof(stringbuf[0]); //Need to reset stringbuf length (was overwritten by RegEnumKeyEx
                a++;
            }

            // Load the index of the preset that's currently selected
            // and select it
            dwType = REG_DWORD;
            dwSize = sizeof(DWORD);
            int preset_num = 0;
            RegQueryValueEx(hkey, _T("Preset"), 0, &dwType, (PBYTE)&preset_num, &dwSize);

            ::SendMessage(GET_HWND(IDC_PRESET_COMBO), CB_SETCURSEL, preset_num, 0);
            if(preset_num != -1)
            {
                ::EnableWindow(GET_HWND(IDC_DELETE_PRESET_BUTTON), TRUE);
                ::EnableWindow(GET_HWND(IDC_SAVE_PRESET_BUTTON), FALSE);
            }
            else
            {
                ::EnableWindow(GET_HWND(IDC_DELETE_PRESET_BUTTON), FALSE);
                ::EnableWindow(GET_HWND(IDC_SAVE_PRESET_BUTTON), TRUE);
            }

			ProcessCmdLine();	// BHB -- Adjust settings based on any command line options

            // Save the dimensions/location of the window
            dwType = REG_DWORD;
            dwSize = sizeof(LONG);

            GetWindowRect(m_hWnd, &window_rect); // so we have some default values

            RegQueryValueEx(hkey, _T("WindowTop"),    0, &dwType, (PBYTE)&window_rect.top,    &dwSize);

            RegQueryValueEx(hkey, _T("WindowBottom"), 0, &dwType, (PBYTE)&window_rect.bottom, &dwSize);

            RegQueryValueEx(hkey, _T("WindowLeft"),   0, &dwType, (PBYTE)&window_rect.left,   &dwSize);

            RegQueryValueEx(hkey, _T("WindowRight"),  0, &dwType, (PBYTE)&window_rect.right,  &dwSize);

            // If the window is off the screen then fix the problem
            if (window_rect.left   >= GetSystemMetrics(SM_CXSCREEN) || 
                window_rect.top    >= GetSystemMetrics(SM_CYSCREEN) ||
                window_rect.right  <  0 ||
                window_rect.bottom <  0)
            {
                // Move the window to the upper left corner of the screen
                window_rect.bottom -= window_rect.top;
                window_rect.right  -= window_rect.left;
                window_rect.top     = 0;
                window_rect.left    = 0;
            }

            MoveWindow(m_hWnd, window_rect.left, window_rect.top, window_rect.right-window_rect.left, window_rect.bottom-window_rect.top, TRUE);
        }

        // Close the regisry now that we're done
        RegCloseKey(hkey);
    }
}