コード例 #1
0
ファイル: IGCParser.cpp プロジェクト: Advi42/XCSoar
static int
ParseTwoDigits(const char *p)
{
  if (!IsDigitASCII(p[0]) || !IsDigitASCII(p[1]))
    return -1;

  return (p[0] - '0') * 10 + (p[1] - '0');
}
コード例 #2
0
ファイル: ButtonLabel.cpp プロジェクト: damianob/xcsoar
static bool
OnlyDigitsAndPunctuation(const TCHAR *s)
{
  while (*s) {
    if (!(IsDigitASCII(*s) || _istpunct(*s)))
      return false;
    s++;
  }
  return true;
}
コード例 #3
0
ファイル: IGCParser.cpp プロジェクト: Advi42/XCSoar
/**
 * Parse an unsigned integer from the given string range
 * (null-termination is not necessary).
 *
 * @param p the string
 * @param end the end of the string
 * @return the result, or -1 on error
 */
static int
ParseUnsigned(const char *p, const char *end)
{
  unsigned value = 0;

  for (; p < end; ++p) {
    if (!IsDigitASCII(*p))
      return -1;

    value = value * 10 + (*p - '0');
  }

  return value;
}
コード例 #4
0
ファイル: CharUtil.hpp プロジェクト: Advi42/XCSoar
constexpr
static inline bool
IsAlphaNumericASCII(char ch)
{
  return IsAlphaASCII(ch) || IsDigitASCII(ch);
}
コード例 #5
0
ファイル: Main.hpp プロジェクト: ThomasXBMC/XCSoar
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine2,
        int nCmdShow)
#endif
{
#if defined(ENABLE_CMDLINE) || defined(ENABLE_MAIN_WINDOW)
#ifdef WIN32
  Args args(GetCommandLine(), USAGE);
#else
  Args args(argc, argv, USAGE);
#endif
#ifdef ENABLE_MAIN_WINDOW
  PixelSize window_size{640, 480};
  const char *a = args.PeekNext();
  if (a != nullptr && a[0] == '-' && IsDigitASCII(a[1])) {
    args.GetNext();
    char *p;
    window_size.cx = ParseUnsigned(a + 1, &p);
    if (*p != 'x' && *p != 'X')
      args.UsageError();
    a = p;
    window_size.cy = ParseUnsigned(a + 1, &p);
    if (*p != '\0')
      args.UsageError();
  }
#endif
#ifdef ENABLE_CMDLINE
  ParseCommandLine(args);
#endif
  args.ExpectEnd();
#endif

#if defined(ENABLE_RESOURCE_LOADER) && defined(USE_GDI)
  ResourceLoader::Init(hInstance);
#endif

#ifdef ENABLE_SCREEN
#ifndef ENABLE_MAIN_WINDOW
  constexpr PixelSize window_size{800, 600};
#endif

  ScreenGlobalInit screen_init;
  Layout::Initialize(window_size);
  InitialiseFonts();
#endif

#ifdef ENABLE_DIALOG
  dialog_settings.SetDefaults();
#endif

#ifdef ENABLE_LOOK
  look = new Look();
  look->Initialise(normal_font);

  {
    UISettings ui_settings;
    ui_settings.SetDefaults();
    look->InitialiseConfigured(ui_settings,
                               normal_font, bold_font,
                               100);
  }

  dialog_look = &look->dialog;
  button_look = &dialog_look->button;
#elif defined(ENABLE_DIALOG_LOOK)
  dialog_look = new DialogLook();
  dialog_look->Initialise();
  button_look = &dialog_look->button;
#elif defined(ENABLE_BUTTON_LOOK)
  button_look = new ButtonLook();
  button_look->Initialise(bold_font);
#endif

#ifdef ENABLE_DATA_PATH
  InitialiseDataPath();
#endif

#ifdef ENABLE_PROFILE
  Profile::SetFiles(_T(""));
  Profile::Load();
#endif

#ifdef ENABLE_MAIN_WINDOW
  main_window.Create(_T("Test"), window_size);
  main_window.Show();
#endif

  Main();

#ifdef ENABLE_MAIN_WINDOW
  main_window.Destroy();
#endif

#ifdef ENABLE_DATA_PATH
  DeinitialiseDataPath();
#endif

#ifdef ENABLE_LOOK
  delete look;
#elif defined(ENABLE_DIALOG_LOOK)
  delete dialog_look;
#elif defined(ENABLE_BUTTON_LOOK)
  delete button_look;
#endif

#ifdef ENABLE_SCREEN
  DeinitialiseFonts();
#endif

  return 0;
}
コード例 #6
0
ファイル: AllInput.cpp プロジェクト: DRIZO/xcsoar
bool
AllLinuxInputDevices::CheckName(const char *name)
{
  return memcmp(name, "event", 5) == 0 && IsDigitASCII(name[5]);
}
コード例 #7
0
ファイル: AirspaceParser.cpp プロジェクト: Adrien81/XCSoar
static void
ReadAltitude(const TCHAR *buffer, AirspaceAltitude &altitude)
{
  Unit unit = Unit::FEET;
  enum { MSL, AGL, SFC, FL, STD, UNLIMITED } type = MSL;
  fixed value = fixed(0);

  const TCHAR *p = buffer;
  while (true) {
    while (*p == _T(' '))
      ++p;

    if (IsDigitASCII(*p)) {
      TCHAR *endptr;
      value = fixed(ParseDouble(p, &endptr));
      p = endptr;
    } else if (StringIsEqualIgnoreCase(p, _T("GND"), 3) ||
               StringIsEqualIgnoreCase(p, _T("AGL"), 3)) {
      type = AGL;
      p += 3;
    } else if (StringIsEqualIgnoreCase(p, _T("SFC"), 3)) {
      type = SFC;
      p += 3;
    } else if (StringIsEqualIgnoreCase(p, _T("FL"), 2)) {
      type = FL;
      p += 2;
    } else if (*p == _T('F') || *p == _T('f')) {
      unit = Unit::FEET;
      ++p;

      if (*p == _T('T') || *p == _T('t'))
        ++p;
    } else if (StringIsEqualIgnoreCase(p, _T("MSL"), 3)) {
      type = MSL;
      p += 3;
    } else if (*p == _T('M') || *p == _T('m')) {
      unit = Unit::METER;
      ++p;
    } else if (StringIsEqualIgnoreCase(p, _T("STD"), 3)) {
      type = STD;
      p += 3;
    } else if (StringIsEqualIgnoreCase(p, _T("UNL"), 3)) {
      type = UNLIMITED;
      p += 3;
    } else if (*p == _T('\0'))
      break;
    else
      ++p;
  }

  switch (type) {
  case FL:
    altitude.reference = AltitudeReference::STD;
    altitude.flight_level = value;
    return;

  case UNLIMITED:
    altitude.reference = AltitudeReference::MSL;
    altitude.altitude = fixed(50000);
    return;

  case SFC:
    altitude.reference = AltitudeReference::AGL;
    altitude.altitude_above_terrain = fixed(-1);
    return;

  default:
    break;
  }

  // For MSL, AGL and STD we convert the altitude to meters
  value = Units::ToSysUnit(value, unit);
  switch (type) {
  case MSL:
    altitude.reference = AltitudeReference::MSL;
    altitude.altitude = value;
    return;

  case AGL:
    altitude.reference = AltitudeReference::AGL;
    altitude.altitude_above_terrain = value;
    return;

  case STD:
    altitude.reference = AltitudeReference::STD;
    altitude.flight_level = Units::ToUserUnit(value, Unit::FLIGHT_LEVEL);
    return;

  default:
    break;
  }
}
コード例 #8
0
ファイル: TTYKeyboard.cpp プロジェクト: ThomasXBMC/XCSoar
inline void
TTYKeyboard::HandleInputByte(char ch)
{
  switch (ch) {
  case 0x03:
    /* user has pressed Ctrl-C */
    input_state = InputState::NONE;
    queue.Push(Event::CLOSE);
    return;

  case ' ':
    input_state = InputState::NONE;
    queue.PushKeyPress(ch);
    return;

  case 0x0d:
    input_state = InputState::NONE;
    queue.PushKeyPress(KEY_RETURN);
    return;

  case 0x1b:
    if (input_state == InputState::ESCAPE)
      queue.PushKeyPress(KEY_ESCAPE);
    else
      input_state = InputState::ESCAPE;
    return;
  }

  switch (input_state) {
  case InputState::NONE:
    break;

  case InputState::ESCAPE:
    if (ch == '[')
      input_state = InputState::ESCAPE_BRACKET;
    else
      input_state = InputState::NONE;
    return;

  case InputState::ESCAPE_BRACKET:
    input_state = InputState::NONE;
    switch (ch) {
    case 'A':
      queue.PushKeyPress(KEY_UP);
      break;

    case 'B':
      queue.PushKeyPress(KEY_DOWN);
      break;

    case 'C':
      queue.PushKeyPress(KEY_RIGHT);
      break;

    case 'D':
      queue.PushKeyPress(KEY_LEFT);
      break;

    case '[':
      input_state = InputState::ESCAPE_BRACKET2;
      break;

    default:
      if (ch >= '0' && ch <= '9') {
        input_state = InputState::ESCAPE_NUMBER;
        input_number = ch - '0';
      } else
        input_state = InputState::NONE;
    }

    return;

  case InputState::ESCAPE_BRACKET2:
    switch (ch) {
    case 'A':
      queue.PushKeyPress(KEY_F1);
      break;

    case 'B':
      queue.PushKeyPress(KEY_F2);
      break;

    case 'C':
      queue.PushKeyPress(KEY_F3);
      break;

    case 'D':
      queue.PushKeyPress(KEY_F4);
      break;

    case 'E':
      queue.PushKeyPress(KEY_F5);
      break;

    default:
      input_state = InputState::NONE;
    }

    return;

  case InputState::ESCAPE_NUMBER:
    if (IsDigitASCII(ch))
      input_number = input_number * 10 + ch - '0';
    else {
      input_state = InputState::NONE;
      if (ch == '~') {
        if (input_number >= 11 && input_number <= 16)
          queue.PushKeyPress(KEY_F1 + input_number - 11);
        else if (input_number >= 17 && input_number <= 21)
          queue.PushKeyPress(KEY_F6 + input_number - 17);
        else if (input_number >= 23 && input_number <= 24)
          queue.PushKeyPress(KEY_F11 + input_number - 23);
      }
    }

    return;
  }

  if (IsAlphaNumericASCII(ch)) {
      queue.PushKeyPress(ch);
      return;
  }
}