DWORD       DllGameGetRdEventsConfiguration (MICROBUFFER     * pMsgOut,
                                             sql_context     ctx)
{
  CommMsgROLRdEventsConfigDef   * p_data_out;         // Output message pointer
  DWORD                         _idx_event;           // Event index
  DWORD                         NumEventsSaleAllowed; // Event index
  BYTE                          NumEvents;
  HorseEventsDBDef              * p_EventsList;
  char                          MsgText[MAX_LOG_MSG];
  char                          MsgText2[MAX_LOG_MSG];

  p_data_out = (CommMsgROLRdEventsConfigDef *) &pMsgOut->Data[0];

  // Initialize output message variables
  p_data_out->NumEvents = 0;

  // Lock the Events List array
  // LockEventsList ();

  NumEvents = 0;
  NumEventsSaleAllowed = 0;
  for ( _idx_event = 0; _idx_event < MAX_NUM_EVENTS; _idx_event++ )
  {
    // To easy read the code
    p_EventsList = &pEventsListDescriptor[_idx_event];

    // Check the opening date
    // Cero means "No Event Horses" mandatory record
    if ( p_EventsList->EventId > 0 )
    {
      p_data_out->EventsList[NumEvents].EventId = p_EventsList->EventId;
      sprintf(p_data_out->EventsList[NumEvents].EventDescription,  p_EventsList->EventDescription);
      p_data_out->EventsList[NumEvents].SaleAllowed = p_EventsList->SaleAllowed;
      // To know how many events are allowed to sale tickets
      if ( p_EventsList->SaleAllowed == 1)
        NumEventsSaleAllowed ++;
      NumEvents++;
    }
    p_data_out->NumEvents = NumEvents;
  }

  // Adjust Byte Count
  pMsgOut->ByteCount += sizeof (p_data_out->EventsList) * NumEvents;

  // Unlock the Events List array
  // UnLockEventsList ();

  // Detail Log
  GetCommandString(pMsgOut->Command, MsgText2);
  // Log message
  sprintf (MsgText, "Done %s (%d), Evt=%d, Alw=%d", 
                    MsgText2, 
                    sizeof(CommMsgROLRdEventsConfigDef) + sizeof(DBEventsConfigDef) * (NumEvents - 1),
                    NumEvents, 
                    NumEventsSaleAllowed);

  (void) Log_SendEvent_TG (LOG_SV_INFORMATION, 
                           MsgText, 
                           p_data_out->NumTerminal, 
                           0, 0, DLLGAME_GAME_NUMBER);

  return DB_SUCCESS;
} // DllGameGetRdEventsConfiguration
DWORD       DllGameGetRdRacesConfiguration (MICROBUFFER     * pMsgOut,
                                            sql_context     ctx)
{
  CommMsgROLRdRacesConfigDef    * p_data_out;       // Output message pointer
  DWORD                         _idx_instance;      // Instance index
  WORD                          _idx_race;    
  WORD                          _idx_race_list;
  WORD                          _idx_selected;
  time_t                        _current_date;      // Actual date
  BOOL                          _current_racing_day_defined;
  DWORD                         _ext_game_day;      // External racing day id
  DWORD                         _game_day;          // Internal racing day id
  DBRaceConfigDef               _race_list [MAX_NUM_RACES];       // Keep the temporary info of all the games on the racing day
  BYTE                          _num_races;                       // Number of races defined for the racing day
  BYTE                          _active_race_id;                  // First active race identifier                 
  BOOL                          _race_found;                      // Race found flag
  GameInstDBDef                 * p_gi;
  char                          _event_description [LEN_EVENT_DESCRIPTION + 1];
  char                          MsgText[MAX_LOG_MSG];
  char                          MsgText2[MAX_LOG_MSG];

  p_data_out = (CommMsgROLRdRacesConfigDef *) &pMsgOut->Data[0];

  // Initialize output message variables
  p_data_out->NumRaces = 0;
  p_data_out->ActiveRaceId = 0;
  memset (p_data_out->EventDescription, ' ', sizeof (p_data_out->EventDescription));

  // Lock the game instance array
  LockGameInst ();

  // Check first that there are entries in the game instance array
  if ( NumGameInsts <= 0 )
  {
    // Unlock the game instance array
    UnLockGameInst ();

    return DB_ERROR_GAMBLECLOSED;
  }

  // Set event description
  if ( RDBGetEventDescription (p_data_out->EventId, _event_description, ctx) == DB_SUCCESS )
  {
    memcpy (p_data_out->EventDescription, _event_description, strlen (_event_description));
  }

  _num_races = 0;
  _active_race_id = 0;
  memset (&_race_list, 0, sizeof (_race_list));

  _current_date = time (NULL);
  _current_racing_day_defined = FALSE;

  // TJG 19-SEP-2003
  // The terminal won't check the period of sales and it needs the whole list 
  // of races & games of the current racing day, regardless their sales period 
  // is opened or closed.
  //    - Determine first the current racing day
  //    - Build the whole list of races related to the racing day

  //    - Determine first the current racing day
  //      Browse the list of all defined instances.
  //      The list is ordered by: ClosingDate, ExtGameDayId, EventId, GameCode
  for ( _idx_instance = 0; _idx_instance < NumGameInsts; _idx_instance++ )
  {
    // To easy read the code
    p_gi = &pGameInstDescriptor[_idx_instance];

    // Check the opening date
    if ( p_gi->OpeningDate >= _current_date )
    {
      continue;
    }

    // Check closing date
    if ( p_gi->ClosingDate < _current_date )
    {
      continue;
    }

    // Check for the Event Id
    if ( p_gi->EventId != p_data_out->EventId )
    {
      continue;
    }

    // First instance found for the racing day
    if ( ! _current_racing_day_defined )
    {
      _game_day = p_gi->GameDayId;
      _ext_game_day = p_gi->ExtGameDayId;

      // Add the general message values
      p_data_out->ExtGameDayId = _ext_game_day;
      p_data_out->RacingDayDate = p_gi->CloseGameDayDate;

      _current_racing_day_defined = TRUE;

      break;
    }
  }

  // Exit if there is no opened racing day
  if ( ! _current_racing_day_defined )
  {
    // Unlock the game instance array
    UnLockGameInst ();

    return DB_ERROR_GAMBLECLOSED;
  }


  //    - Build the whole list of races related to the racing day
  //      Browse the list of all defined instances.
  //      The list is ordered by: ClosingDate, ExtGameDayId, EventId, GameCode
  for ( _idx_instance = 0; _idx_instance < NumGameInsts; _idx_instance++ )
  {
    // To easy read the code
    p_gi = &pGameInstDescriptor[_idx_instance];

    // Check for the Event Id
    if ( p_gi->EventId != p_data_out->EventId )
    {
      continue;
    }

    // Check we are handling the same gameday
    if ( p_gi->GameDayId != _game_day )
    {
      continue;
    }

    // Add the game instance's races to the race list
    for ( _idx_race = 0; _idx_race < CONST_ONLY_FIRST_RACE; _idx_race++ )
    {
      _race_found = FALSE;

      for ( _idx_race_list = 0; _idx_race_list < _num_races; _idx_race_list++ )
      {
        if ( _race_list[_idx_race_list].RaceId == p_gi->Races[_idx_race].RaceId )
        {
          _race_found = TRUE;

          break;
        }
      }
 
      // Add the race to the list only if it does not already exist 
      if ( ! _race_found )
      {
        _race_list[_num_races].RaceId          = p_gi->Races[_idx_race].RaceId;
        _race_list[_num_races].RaceDate        = p_gi->Races[_idx_race].RaceDateTime;
        _race_list[_num_races].RaceOpeningDate = p_gi->Races[_idx_race].RaceOpeningDate;
        _race_list[_num_races].RaceClosingDate = p_gi->Races[_idx_race].RaceClosingDate;
        _race_list[_num_races].NumHorses       = p_gi->Races[_idx_race].NumHorses;
      
        memcpy (&_race_list[_num_races].ScratchedHorses, 
                p_gi->Races[_idx_race].Horses.HorsesMask, 
                sizeof (TYPE_RACE));

        // RRT 06-OCT-2003
        // The first active race is now sent as part of the configuration message
        // The opening and closing date must be check in order to set the proper 
        // active Race.
        // Check the race opening and closing date
        if ( p_gi->Races[_idx_race].RaceOpeningDate <= _current_date )
        {
          if ( p_gi->Races[_idx_race].RaceClosingDate > _current_date )
          {
            // Check if the race status
            if ( p_gi->Races[_idx_race].ITSPStatus == ITSP_STATUS_OPEN )
            {
              if ( _active_race_id == 0 )
              {
                _active_race_id = p_gi->Races[_idx_race].RaceId;
              }
              else
              {
                if ( p_gi->Races[_idx_race].RaceId < _active_race_id )
                {
                  _active_race_id = p_gi->Races[_idx_race].RaceId;
                }
              }
            }
          } // if
        } // if

        // One more race
        _num_races++;
      } //if
    } //for
  } //for

//  // TJG 19-SEP-2003
//  // Exit if there is no opened racing day
//  This check was done above
//  if ( ! _current_racing_day_defined )
//  {
//    // Unlock the game instance array
//    UnLockGameInst ();
//
//    return DB_ERROR_GAMBLECLOSED;
//  }

  // Adjust Byte Count
  pMsgOut->ByteCount += sizeof (p_data_out->RaceList) * _num_races;

  // Copy the race list to the message reply. The list should be sorted per 
  // race number.
  p_data_out->NumRaces = _num_races;
  // Copy the active race into the output message.
  p_data_out->ActiveRaceId = _active_race_id;

  for ( _idx_race = 0; _idx_race < _num_races; _idx_race++ )
  {
    // Look for the lowest race number
    _idx_selected = 0;

    for ( _idx_race_list = 0; _idx_race_list < _num_races; _idx_race_list++ )
    {
      if ( _race_list[_idx_race_list].RaceId < _race_list[_idx_selected].RaceId )
      {
        _idx_selected = _idx_race_list;
      }
    }
  
    p_data_out->RaceList[_idx_race].RaceId          = _race_list[_idx_selected].RaceId;
    p_data_out->RaceList[_idx_race].RaceDate        = _race_list[_idx_selected].RaceDate;
    p_data_out->RaceList[_idx_race].RaceOpeningDate = _race_list[_idx_selected].RaceOpeningDate;
    p_data_out->RaceList[_idx_race].RaceClosingDate = _race_list[_idx_selected].RaceClosingDate;
    p_data_out->RaceList[_idx_race].NumHorses       = _race_list[_idx_selected].NumHorses;

    memcpy (&p_data_out->RaceList[_idx_race].ScratchedHorses, 
            _race_list[_idx_selected].ScratchedHorses, 
            sizeof (TYPE_RACE));

    // Set the race to a MAX (and impossible) value to not duplicate it
    _race_list[_idx_selected].RaceId = 255;
  }

  // Unlock the game instance array
  UnLockGameInst ();

  // Detail Log
  GetCommandString(pMsgOut->Command, MsgText2);
  sprintf (MsgText, "Done %s (%d), Evt=%d, Rc=%d", 
                    MsgText2, 
                    sizeof(CommMsgROLRdRacesConfigDef) + sizeof(DBRaceConfigDef) * (p_data_out->NumRaces - 1),
                    p_data_out->EventId, 
                    p_data_out->NumRaces);

  (void) Log_SendEvent_TG (LOG_SV_INFORMATION,
                           MsgText, 
                           p_data_out->NumTerminal, 
                           0, 0, DLLGAME_GAME_NUMBER);

  return DB_SUCCESS;
} // DllGameGetRdRacesConfiguration
DWORD       DllGameGetRdGamesConfiguration (MICROBUFFER     * pMsgOut,
                                            sql_context     ctx)
{
  CommMsgROLRdGamesConfigDef    * p_data_out;
  DWORD                         _idx_instance;  // Instance index
  WORD                          _idx_game;      // Game structure index
  WORD                          _idx_race;
  time_t                        _current_date;
  BOOL                          _current_racing_day_defined;
  DWORD                         _ext_game_day;
  DWORD                         _game_day;
  DBGameConfigDef               _game_list [HORSES_NUM_GAMES]; // Keep the temporary info of all the games on the racing day
  BYTE                          _num_games;
  BOOL                          _game_found;
  GameInstDBDef                 * p_gi;

  char                          MsgText[MAX_LOG_MSG];
  char                          MsgText2[MAX_LOG_MSG];

 
  p_data_out = (CommMsgROLRdGamesConfigDef *) &pMsgOut->Data[0];

  // Initialize output message variables
  p_data_out->NumGames = 0;

  // Lock the game instance array
  LockGameInst ();

  // Check first that there are entries in the game instance array
  if ( NumGameInsts <= 0 )
  {
    // Unlock the game instance array
    UnLockGameInst ();

    return DB_ERROR_GAMBLECLOSED;
  }

  _num_games = 0;
  memset (&_game_list, 0, sizeof (_game_list));

  _current_date = time (NULL);
  _current_racing_day_defined = FALSE;

  // TJG 19-SEP-2003
  // The terminal won't check the period of sales and it needs the whole list 
  // of races & games of the current racing day, regardless their sales period 
  // is opened or closed.
  //    - Determine first the current racing day
  //    - Build the whole list of races related to the racing day

  //    - Determine first the current racing day
  //      Browse the list of all defined instances.
  //      The list is ordered by: ClosingDate, ExtGameDayId, EventId, GameCode
  for ( _idx_instance = 0; _idx_instance < NumGameInsts; _idx_instance++ )
  {
    // To easy read the code
    p_gi = &pGameInstDescriptor[_idx_instance];

    // Check the opening date
    if ( p_gi->OpeningDate >= _current_date )
    {
      continue;
    }

    // Check closing date
    if ( p_gi->ClosingDate < _current_date )
    {
      continue;
    }

    // Check for the Event Id
    if ( p_gi->EventId != p_data_out->EventId )
    {
      continue;
    }

    // First instance found for the racing day
    if ( ! _current_racing_day_defined )
    {
      _game_day = p_gi->GameDayId;
      _ext_game_day = p_gi->ExtGameDayId;

      // Add the general message values
      p_data_out->ExtGameDayId = _ext_game_day;

      _current_racing_day_defined = TRUE;

      break;
    }
  }

  // Exit if there is no opened racing day
  if ( ! _current_racing_day_defined )
  {
    // Unlock the game instance array
    UnLockGameInst ();

    return DB_ERROR_GAMBLECLOSED;
  }


  //    - Build the whole list of races related to the racing day
  //      Browse the list of all defined instances.
  //      The list is ordered by: ClosingDate, ExtGameDayId, EventId, GameCode
  for ( _idx_instance = 0; _idx_instance < NumGameInsts; _idx_instance++ )
  {
    // To easy read the code
    p_gi = &pGameInstDescriptor[_idx_instance];

    // Check for the Event Id
    if ( p_gi->EventId != p_data_out->EventId )
    {
      continue;
    }

    // Check we are handling the same gameday
    if ( p_gi->GameDayId != _game_day )
    {
      continue;
    }

    // Check if is the same RaceId received
    if ( p_gi->Races[0].RaceId != p_data_out->RaceIdSelected )
    {
      continue;
    }

    _game_found = FALSE;

    // Browse the list of games to check if already exist
    for ( _idx_game = 0; _idx_game < _num_games; _idx_game++ )
    {
      if ( _game_list[_idx_game].SubGameCode == p_gi->SubGameCode )
      {
        _game_found = TRUE;

        break;
      }
    }

    // Ad the game to the list if it was not there
    if ( ! _game_found )
    {
      // Send it to terminal only if the pool has opened ITSP Status
      if (p_gi->ITSPStatus == ITSP_STATUS_OPEN)
      {
        _game_list[_num_games].SubGameCode         = p_gi->SubGameCode;
        _game_list[_num_games].Commission          = p_gi->SaleCommission;
        _game_list[_num_games].MinSimpleBetPrice   = (float) p_gi->SimpleBetPrice;
        _game_list[_num_games].MinWheelBoxBetPrice = (float) p_gi->MultipleBetPrice;
        _game_list[_num_games].MaxBetLinePrice     = (float) p_gi->MaxBetPrice;
        _game_list[_num_games].MaxTicketPrice      = (float) p_gi->MaxTicketPrice;

        // Clear the game races
        memset (_game_list[_num_games].GameRaces, 0, sizeof (_game_list[_num_games].GameRaces));

        // One more game
        _num_games++;
      }
    }

//    // Set the races related to this game
//    for ( _idx_race = 0; _idx_race < p_gi->NumRaces; _idx_race++ )

    // Set ONLY the first race related to this game
    for ( _idx_race = 0; _idx_race < CONST_ONLY_FIRST_RACE; _idx_race++ )
    {
      // Don't get confused by its name: SetRaceHorse sets/clears a bit in a
      // TYPE_RACE array (3 bytes mask array). GameRaces is also a 3 mask bytes 
      // array so we can use the same function

      SetRaceHorse ((WORD) (p_gi->Races[_idx_race].RaceId),
                    TRUE,
                    (TYPE_RACE *) _game_list[_idx_game].GameRaces);
    }
  }

//  // TJG 19-SEP-2003
//  // Exit if there is no opened racing day
//  This check was done above
//  if ( ! _current_racing_day_defined )
//  {
//    // Unlock the game instance array
//    UnLockGameInst ();
//
//    return DB_ERROR_GAMBLECLOSED;
//  }

  // Adjust byte count
  pMsgOut->ByteCount += sizeof (p_data_out->GameList) * _num_games;

  // Include the number of games
  p_data_out->NumGames = _num_games;

  // Browse the list of games to copy output message
  for ( _idx_game = 0; _idx_game < _num_games; _idx_game++ )
  {
    // Game exists for the racing day, include it on the output message
    p_data_out->GameList[_idx_game].SubGameCode         = _game_list[_idx_game].SubGameCode;
    p_data_out->GameList[_idx_game].Commission          = _game_list[_idx_game].Commission;
    p_data_out->GameList[_idx_game].MinSimpleBetPrice   = _game_list[_idx_game].MinSimpleBetPrice;
    p_data_out->GameList[_idx_game].MinWheelBoxBetPrice = _game_list[_idx_game].MinWheelBoxBetPrice;
    p_data_out->GameList[_idx_game].MaxBetLinePrice     = _game_list[_idx_game].MaxBetLinePrice;
    p_data_out->GameList[_idx_game].MaxTicketPrice      = _game_list[_idx_game].MaxTicketPrice;

    memcpy (&p_data_out->GameList[_idx_game].GameRaces, 
            _game_list[_idx_game].GameRaces, 
            sizeof (_game_list[_idx_game].GameRaces));
  }

  // Unlock the game instance array
  UnLockGameInst ();


  // Detail Log
  GetCommandString(pMsgOut->Command, MsgText2);
  sprintf (MsgText, "Done %s (%d), Evt=%d, Rc=%d, Gms=%d", 
                    MsgText2, 
                    sizeof(CommMsgROLRdGamesConfigDef) + sizeof(DBGameConfigDef) * (p_data_out->NumGames - 1),
                    p_data_out->EventId,
                    p_data_out->RaceIdSelected, 
                    p_data_out->NumGames);

  (void) Log_SendEvent_TG (LOG_SV_INFORMATION, 
                           MsgText, 
                           p_data_out->NumTerminal, 
                           0, 0, DLLGAME_GAME_NUMBER);

  return DB_SUCCESS;
} // DllGameGetRdGamesConfiguration
Exemple #4
0
long DoLoad ( HWND hMain, WORD LoadType)

{  OPENFILENAME ofn;
   extern HANDLE hInst;
   char File[256], FileTitle[256], Filter[256];
   UINT i, cbString;
   char Replace;

   File[0] = '\0';
   memset ( &ofn,0, sizeof (OPENFILENAME));

   /*---------------------------------------------+
   | Initialize Common Dialog based on File Type. |
   +---------------------------------------------*/
   switch ( LoadType )
   {  case IDM_FILE_LOAD:
      {  ofn.lpstrTitle = "Load CLIPS Constructs";
         if ((cbString = LoadString ( (HINSTANCE) hInst, IDS_RULES, Filter, sizeof (Filter))) == 0 )
            return 0L;
	 break;
      }

      case IDM_FILE_LBATCH:
      {  ofn.lpstrTitle = "Load CLIPS Batch File";
         if ((cbString = LoadString ( (HINSTANCE) hInst, IDS_BATCH, Filter, sizeof (Filter))) == 0 )
	    return 0L;
	 break;
      }

      case IDM_FILE_LBINARY:
      {  ofn.lpstrTitle = "Load CLIPS Binary File";
         if ((cbString = LoadString ( (HINSTANCE) hInst, IDS_BINARY, Filter, sizeof (Filter))) == 0 )
	    return 0L;
         break;
      }
   }

   Replace = Filter[cbString-1];

   for (i=0; Filter[i] != '\0'; i++)
      if ( Filter[i] == Replace)
         Filter[i] = '\0';

   ofn.lStructSize = sizeof ( OPENFILENAME );
   ofn.hwndOwner = hMain;
   ofn.lpstrFilter = Filter;
   ofn.nFilterIndex = 1;
   ofn.lpstrFile = File;
   ofn.nMaxFile = sizeof (File );
   ofn.lpstrFileTitle = FileTitle;
   ofn.nMaxFileTitle = sizeof (FileTitle);
   ofn.lpstrInitialDir = NULL;
   ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;


   /*--------------------+
   | Issue CLIPS Command |
   +--------------------*/
   if ( GetOpenFileName ( &ofn ) )
   {  int x, size;

      UpdateCursor(WAIT_CURSOR);
      /*-----------------+
      | Adjust Path Info |
      +-----------------*/
      size = strlen(ofn.lpstrFile );
      for ( x=0; x<size ; x++)
         if ( ofn.lpstrFile [x] == '\\' )
            ofn.lpstrFile [x] = '/';

      switch ( LoadType )
      {  case IDM_FILE_LOAD:
            SetCommandString("(load \"");  break;
         case IDM_FILE_LBATCH:
            SetCommandString("(batch \""); break;
         case IDM_FILE_LBINARY:
            SetCommandString("(bload \""); break;
      }
      AppendCommandString ( ofn.lpstrFile );
      AppendCommandString ( "\")\n");
      PrintCLIPS ( "stdout", GetCommandString());
      UpdateCursor ( ARROW_CURSOR );
      PrintPrompt();
   }
   return 0L;
}
Exemple #5
0
/*******************************************************************************
          Name:        CompletionDialogCallback
          Description: Called when Completion is selected form File menu
          Arguments:  w - menu item that was selected
                       client_data - dialog window or edit window
                       call_data - not used
          Returns:     None
*******************************************************************************/
void CompletionDialogCallback(
  Widget w,
  XtPointer client_data, 
  XtPointer call_data)
{
  int NumberOfMatches,i,length;
  Boolean tempFlag;
  struct symbolMatch *matches;
  XKeyboardControl value;
  char *commandString;
 
  /* ================================================== */
  /* Free the memory of completionString before assign  */
  /* it to the new string.                              */
  /* ================================================== */

  if(completionString != NULL)
   {
     free(completionString);
     completionString = NULL;
   }
  /* =========================================================== */
  /* Get the the uncompleted command string; if there is none    */
  /* sound the bell and exit, else determine if the last token   */
  /* of the string can be complete                               */
  /* =========================================================== */

  commandString = GetCommandString();
  if(commandString != NULL)
   {
    length = strlen(commandString);
    commandString = GetCommandCompletionString(commandString,length);
   }
  if(commandString == NULL)
   {
     XBell(XtDisplay(toplevel),100);
     return;
   }

  /* ============================================================ */
  /* Copy the command string to a global variable for later use.  */
  /* Global completionString has to be used here due to the       */
  /* limitation of the number of arguments could be passed in the */
  /* call back function of in X window  system.                   */
  /* ============================================================ */

  completionString = (char*)malloc(strlen(commandString) + 1);
  strcpy(completionString,commandString);

  /* ============================================================ */
  /* Find the match(es). If there is none, sound the bell and     */
  /* exit; else if there is one match complete the command; else  */
  /* if there are more than one display them                      */
  /* ============================================================ */

  matches = FindSymbolMatches(completionString,&NumberOfMatches,NULL);
  if(NumberOfMatches == 0)
   {
     XBell(XtDisplay(toplevel),100);
     return;
   }
  else if (NumberOfMatches == 1)
   {
      length = strlen(completionString);
      AppendCommandString(&(matches->match->contents[length]));
      PrintRouter("stdin",&(matches->match->contents[length]));
   }
  else
   {
      DisplayMatchedList(dialog_text,matches);
   }
}
Exemple #6
0
void SaveBinaryFile(
  HWND hMain)
  {  
   char File[256], FileTitle[256], Filter[256];
   UINT i;
   int cbString;
   char Replace;
   OPENFILENAME ofn;
   int x;
   size_t size;
   void *theEnv = GetCurrentEnvironment();

   File[0] = '\0';
   memset ( &ofn,0, sizeof (OPENFILENAME));
   ofn.lpstrTitle = "Save CLIPS File as Binary";
   if ((cbString = LoadString (GetWindowInstance(hMain), IDS_BINARY, Filter, sizeof (Filter))) == 0 )
      return;

   Replace = Filter[cbString-1];

   for (i=0; Filter[i] != '\0'; i++)
     if ( Filter[i] == Replace)
        Filter[i] = '\0';

   ofn.lStructSize = sizeof ( OPENFILENAME );
   ofn.hwndOwner = hMain;
   ofn.lpstrFilter = Filter;
   ofn.nFilterIndex = 1;
   ofn.lpstrFile = File;
   ofn.nMaxFile = sizeof (File );
   ofn.lpstrFileTitle = FileTitle;
   ofn.nMaxFileTitle = sizeof (FileTitle);
   ofn.lpstrInitialDir = NULL;
   ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;

   /*==========================*/
   /* Perform the file dialog. */
   /*==========================*/

   if (! GetSaveFileName(&ofn))
     { return; }

   /*==========================*/
   /* Adjust Path Information. */
   /*==========================*/
   
   size = strlen(ofn.lpstrFile);
   for (x = 0; x < (int) size; x++)
     {
      if (ofn.lpstrFile[x] == '\\')
        { ofn.lpstrFile[x] = '/'; }
     }

   /*======================*/
   /* Issue CLIPS Command. */
   /*======================*/
   
   ClearCommandFromDisplay(DialogWindow,theEnv);
   SetCommandString(theEnv,"(bsave \"");  
   AppendCommandString(theEnv,ofn.lpstrFile);
   AppendCommandString(theEnv,"\")\n");
   EnvPrintRouter(theEnv,WPROMPT,GetCommandString(theEnv));
  }
Exemple #7
0
void DoLoad( 
  HWND hMain, 
  WORD LoadType)
  {  
   OPENFILENAME ofn;
   char File[256], FileTitle[256], Filter[256];
   UINT i;
   int cbString;
   char Replace;
   int x;
   size_t size;
   void *theEnv = GetCurrentEnvironment();

   File[0] = '\0';
   memset(&ofn,0,sizeof(OPENFILENAME));

   /*==============================================*/
   /* Initialize Common Dialog based on File Type. */
   /*==============================================*/
   
   switch(LoadType)
     {  
      case ID_FILE_LOAD:
        ofn.lpstrTitle = "Load CLIPS Constructs";
        if ((cbString = LoadString(GetWindowInstance(hMain),IDS_RULES,Filter,sizeof(Filter))) == 0)
          { return; }
	    break;

      case ID_FILE_LOAD_BATCH:
        ofn.lpstrTitle = "Load CLIPS Batch File";
        if ((cbString = LoadString(GetWindowInstance(hMain),IDS_BATCH,Filter,sizeof(Filter))) == 0)
	      { return; }
	    break;
      
      case ID_FILE_LOAD_BINARY:
        ofn.lpstrTitle = "Load CLIPS Binary File";
        if ((cbString = LoadString(GetWindowInstance(hMain),IDS_BINARY,Filter,sizeof(Filter))) == 0)
	      { return; }
        break;
     }

   Replace = Filter[cbString-1];

   for (i = 0; Filter[i] != '\0'; i++)
     {
      if (Filter[i] == Replace)
        { Filter[i] = '\0'; }
     }

   ofn.lStructSize = sizeof ( OPENFILENAME );
   ofn.hwndOwner = hMain;
   ofn.lpstrFilter = Filter;
   ofn.nFilterIndex = 1;
   ofn.lpstrFile = File;
   ofn.nMaxFile = sizeof (File );
   ofn.lpstrFileTitle = FileTitle;
   ofn.nMaxFileTitle = sizeof (FileTitle);
   ofn.lpstrInitialDir = NULL;
   ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

   /*==========================*/
   /* Perform the file dialog. */
   /*==========================*/
   
   if (! GetOpenFileName(&ofn))
     { return; }
     
   /*==========================*/
   /* Adjust Path Information. */
   /*==========================*/
   
   size = strlen(ofn.lpstrFile);
   for (x = 0; x < (int) size; x++)
     {
      if (ofn.lpstrFile[x] == '\\')
        { ofn.lpstrFile[x] = '/'; }
     }

   ClearCommandFromDisplay(DialogWindow,theEnv);
   
   /*======================*/
   /* Issue CLIPS Command. */
   /*======================*/

   switch(LoadType)
     {  
      case ID_FILE_LOAD:
        SetCommandString(theEnv,"(load \"");  
        break;
         
      case ID_FILE_LOAD_BATCH:
        SetCommandString(theEnv,"(batch \""); 
        break;
       
      case ID_FILE_LOAD_BINARY:
        SetCommandString(theEnv,"(bload \"");
        break;
     }
      
   AppendCommandString(theEnv,ofn.lpstrFile );
   AppendCommandString(theEnv,"\")\n");
   EnvPrintRouter(theEnv,WPROMPT,GetCommandString(theEnv));
  }
Exemple #8
0
void OpenDribbleFile( 
  HWND hMain, 
  WORD wParam)
  {  
   OPENFILENAME ofn;
   char File[256], FileTitle[256], Filter[256];
   UINT i;
   int cbString;
   char Replace;
   int x;
   size_t size;
   void *theEnv = GetCurrentEnvironment();
   HMENU hMenu = GetMenu(hMain);

   if (! EnvDribbleActive(theEnv))
     {  
      sprintf(File,"dribble.txt");
      memset ( &ofn,0, sizeof (OPENFILENAME));
      ofn.lpstrTitle = "Select CLIPS Dribble File";
      
      if ((cbString = LoadString(GetWindowInstance(hMain),IDS_TEXT_FILES,Filter,sizeof(Filter))) == 0)
        { return; }

      Replace = Filter[cbString-1];
      for (i=0; Filter[i] != '\0'; i++)
        {
         if (Filter[i] == Replace)
           { Filter[i] = '\0'; }
        }

      ofn.lStructSize = sizeof (OPENFILENAME);
      ofn.hwndOwner = hMain;
      ofn.lpstrFilter = Filter;
      ofn.nFilterIndex = 1;
      ofn.lpstrFile = File;
      ofn.nMaxFile = sizeof (File );
      ofn.lpstrFileTitle = FileTitle;
      ofn.nMaxFileTitle = sizeof (FileTitle);
      ofn.lpstrInitialDir = NULL;
      ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
      
      /*==========================*/
      /* Perform the file dialog. */
      /*==========================*/
   
      if (! GetOpenFileName(&ofn))
        { return; }
        
      /*==========================*/
      /* Adjust Path Information. */
      /*==========================*/
   
      size = strlen(ofn.lpstrFile);
      for (x = 0; x < (int) size; x++)
        {
         if (ofn.lpstrFile[x] == '\\')
           { ofn.lpstrFile[x] = '/'; }
        }

      /*=====================================*/
      /* Issue the CLIPS dribble-on command. */
      /*=====================================*/

      ModifyMenu(hMenu,wParam,MF_BYCOMMAND,wParam,"Turn Dribble Off");
      ClearCommandFromDisplay(DialogWindow,theEnv);
      SetCommandString(theEnv,"(dribble-on \"");  
      AppendCommandString(theEnv,ofn.lpstrFile);
      AppendCommandString(theEnv,"\")\n");
      EnvPrintRouter(theEnv,WPROMPT,GetCommandString(theEnv));
     }
   else
     {  
      /*======================================*/
      /* Issue the CLIPS dribble-off command. */
      /*======================================*/

      ModifyMenu(hMenu,wParam,MF_BYCOMMAND,wParam,"Turn Dribble On...");  
      ClearCommandFromDisplay(DialogWindow,theEnv);
      SetCommandString(theEnv,"(dribble-off)\n");  
      EnvPrintRouter(theEnv,WPROMPT,GetCommandString(theEnv));
     }
  }
void clsCMM::ProcessPackage(ADDRESSEDPACKAGE *pPackage)
{
	if (pPackage->to != _HELICOPTER && pPackage->to != ID_ALL) return;				//drop packages not for this helicopter

	int nFrom = pPackage->from;

	char *package = pPackage->package.content;

	COMMAND cmd;
	cmd.code = (short &)package[0];

	if ( GetCommandString(cmd.code) != NULL ) {
		printf("[CMM] Command received %d(%s) from %d\n", cmd.code, GetCommandString(cmd.code), pPackage->from);

		char string[256];
		sprintf(string, "command received %d(%s) from %d", cmd.code, GetCommandString(cmd.code), pPackage->from);
		SendMessage(string);
	}

	switch (cmd.code) {
	case COMMAND_QUIT:
	case COMMAND_MAGTEST:
	case COMMAND_MAGSET:
	case COMMAND_HOVER:
	case COMMAND_FILTER:
	case COMMAND_TAKEOFF:
	case COMMAND_LAND:
	case COMMAND_ENGINEUP:
	case COMMAND_ENGINEDOWN:
	case COMMAND_EMERGENCY:
	case COMMAND_EMERGENCYGROUND:
	case COMMAND_NOTIFY:
	case COMMAND_NONOTIFY:
	case COMMAND_LEADERUPDATE:
	case COMMAND_COMPETITION:
		break;

	case COMMAND_LIFT:
	case COMMAND_DESCEND:
	case COMMAND_ENGINE:
		COPYDOUBLE(cmd.parameter, package+2);
		break;

	case COMMAND_HEADTO:
	case COMMAND_COORDINATE:
		::memcpy(cmd.parameter, package+2, 3*sizeof(double));
		break;

	case COMMAND_RUN:
	case COMMAND_PARA:
	case COMMAND_TEST:				//parameter is an integer
	case COMMAND_GPATH:
//		(int &)cmd.parameter[0] = (int &)package[2];
		COPYLONG(cmd.parameter, package+2);
		break;

	case COMMAND_FORMATION:		// parameter is the path number of the leader
//	case COMMAND_ATTACK:		// for later cooperative behavior usage
		(COOP_PKT &)cmd.parameter[0] = (COOP_PKT &)package[2]; //extract coop_pkt from CMM
		_net.ToggleNetStart();
		break;

	case COMMAND_STOPFORMATION:
		_coop.ResetConnectFlag();
		break;

	case COMMAND_PATH:
//		(int &)cmd.parameter[0] = (int &)package[2];				//path id
//		(int &)cmd.parameter[4] = (int &)package[6];			//tracking option
		COPYLONG(cmd.parameter, package+2);
		COPYLONG(cmd.parameter+4, package+6);
		break;

	case COMMAND_PATHA: {
		double nPoint;
//		COPYWORD(&nPoint, package+2);
		COPYDOUBLE(&nPoint, package+2);
		int npoint = (int)nPoint;
		LOCATION *pPoint = (LOCATION *)(package+10);

		::memcpy(cmd.parameter, package+2, sizeof(double));
		::memcpy(cmd.parameter+8, package+10, npoint*sizeof(LOCATION));

/*		//generate dynamic path
		LOCATION pos0;
		_state.GetCoordination(&pos0.longitude, &pos0.latitude, &pos0.altitude);
		_pathTmp.CreatePath(pPoint, nPoint, &_state.GetState(), &pos0);

		//set command to path tracking
		cmd.code = COMMAND_PATH;
		PUTLONG(cmd.parameter, -1);
		PUTLONG(cmd.parameter + 4, PATHTRACKING_FIXED);*/
		break;
	}

	case COMMAND_TRACK:
		::memcpy(cmd.parameter, package+2, 2*sizeof(int)+3*sizeof(double));
		break;

	case COMMAND_DYNAMICPATH:
	case COMMAND_DYNAMICPATHRESET:
		::memcpy(cmd.parameter, package+2, 5*sizeof(double));				//t,x,y,z,c
		break;

	case COMMAND_HFLY:				//parameter (u,v,h,r)
	case COMMAND_FLY:				//parameter (u,v,w,r)
	case COMMAND_HOLD:				//(x,y,z,c)
	case COMMAND_HOLDPI:
	case COMMAND_CFLY:				//(u,v,w,r)
	case COMMAND_TAKEOFFA:			//(x,y,z,c)
	case COMMAND_LANDA:				//(x,y,z,c)
		::memcpy(cmd.parameter, package+2, 4*sizeof(double));
		break;

	case COMMAND_CHIRP:
		::memcpy(cmd.parameter, package+2, sizeof(int)+4*sizeof(double));
		break;

	case COMMAND_PLAN:
//		(int &)cmd.parameter[0] = (int &)package[2];
		COPYLONG(cmd.parameter, package+2);
		printf("[CMM] Command plan, parameter %d\n", (int)GETLONG(package+2));
		break;

	case COMMAND_CAMRUN: break;
	case COMMAND_CAMSTOP: break;
	case COMMAND_CAMQUIT: break;
	case COMMAND_CAMTRACK:	break;

	case COMMAND_CAMVBS:
//		_state.EnableVision();
	case COMMAND_CAMTHOLD:
	    ::memcpy(cmd.parameter, package+2, sizeof(double));
		break;

	case COMMAND_COOP_PKT:	// coop pkts, futher decoding will be used in the clsCoop
		::memcpy(cmd.parameter, package+2, sizeof(COOP_PKT));
		break;

	case COMMAND_MODE:
		COPYLONG(cmd.parameter, package+2);
		printf("[CMM] Command mode, parameter %d\n", (int)GETLONG(package+2));
		break;

	case DATA_VICON: {
		SetViconFlag();
		_state.SetbMeasurementUpdate();
//		AccountCMMRecord(nFrom);
		VICON_DATA viconData;
		int nObjLen = GETLONG(package+12);
//		viconData.x = GETDOUBLE(package+16+nObjLen); viconData.y = GETDOUBLE(package+16+nObjLen+8); viconData.z = GETDOUBLE(package+16+nObjLen+16);
//		viconData.a = GETDOUBLE(package+16+nObjLen+24); viconData.b = GETDOUBLE(package+16+nObjLen+32); viconData.c = GETDOUBLE(package+16+nObjLen+40);
		memcpy(&viconData, package+16+nObjLen, sizeof(VICON_DATA));
		CollectViconData(viconData);
		return;
		break;
	}
	default:
		break;				//for unknown command only code is transfered
	}

	PutCommand(&cmd);
}
Exemple #10
0
void GetUserCmd ( 
  WORD wParam,      /* Key Code */
  BOOL ScreenOnly,  /* Send to Screen and or Command Buffer */
  int  InputSize)   /* Number of characters send to screen only */

  {
	extern int HorizScroll; /* Automatic Scrolling Enabled/Disabled */

	switch (wParam)
	  {
		extern SCREEN WinDialog;
		extern int UserInput;

		/*------------------+
		| Handle Back Space |
		+------------------*/

		case VK_BACK:
		  {
			/*-----------------------------------------------+
			| Init Values when sending to the command buffer |
			+-----------------------------------------------*/
			if (! ScreenOnly)
			  {
				HorizScroll = 1;
				if (GetCommandString() != NULL)
				  { InputSize = strlen(GetCommandString()); }
				else
				  { InputSize = 0; }
			  }

	 if (InputSize > 0 )
	 {
		 int size;

		 if (Terminal[WinDialog.LastLine] != NULL)
			{ size = strlen(Terminal[WinDialog.LastLine]); }
		 else
			{ size = 0; }

		 if (!ScreenOnly)
			 ExpandCommandString ('\b');

		 if (size > 0)
			 Terminal[WinDialog.LastLine][size - 1] = '\0';
		 else
		 {  int min, max;
			 extern int OldLine;

			 if ( Terminal[WinDialog.LastLine] != NULL )
			 {
		free(Terminal[WinDialog.LastLine]);
		Terminal[WinDialog.LastLine] = NULL;
	       }

			 WinDialog.LastLine --;
	       OldLine --;

	       if ( WinDialog.LastLine < 0 )
		  WinDialog.LastLine = DIALOG_SIZE;

	       GetScrollRange (WinDialog.hWnd, SB_VERT, &min, &max);
	       if ( WinDialog.NoLines < max && max < DIALOG_SIZE )
	       {  SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, max-1, FALSE );
		  SetScrollPos   ( WinDialog.hWnd, SB_VERT, max-1, FALSE );
	       }
	       InvalidateRect ( WinDialog.hWnd, NULL, TRUE );
		 }
		 SendToScreen();
	 }
	 break;
      }

      /*--------------------------+
      | Remove Special Keys (ALT) |
      +--------------------------*/
      case '\f':
      case VK_MENU:
	 break;


      /*----------------+
      | Handle Tab Keys |
      +----------------*/
      case '\t':
		{  if ( !ScreenOnly)
	 {  if ( GetCommandString() == NULL)
	       SetCommandString("   ");
	    else
	       AppendCommandString("   ");
	 }
	 PrintCLIPS ("stdout", "   " );
	 break;
      }


      /*---------------------+
      | Return / Newline Key |
      +---------------------*/
      case '\r':
      case '\n':
      {  wParam = (int)'\n';
	 if (GetScrollPos (WinDialog.hWnd, SB_HORZ) != 0)
	 {  SetScrollPos ( WinDialog.hWnd, SB_HORZ, 0, TRUE );
	    InvalidateRect(WinDialog.hWnd, NULL, FALSE);
	    SendMessage ( WinDialog.hWnd, WM_PAINT, 0, 0 );
	 }
      }

      /*---------------------+
      | All other characters |
      +---------------------*/
      default:
      {  char text[2];

	 text[0] = (char) wParam;
	 text[1] = '\0';

	 if(isprint ( text[0]) || isspace (text[0]))
	 {  /*----------------------------+
	    | Add to CLIPS Command Buffer |
		 +----------------------------*/

	    if (!ScreenOnly)
	    {  if ( GetCommandString() == NULL)
		  SetCommandString(text);
	       else
		  AppendCommandString(text);
		 }

		 PrintCLIPS ("stdout", text );
	 }
	 break;
		}
	}
	HorizScroll = 0;
}
Exemple #11
0
SkString SkDrawCommand::toString() {
    return SkString(GetCommandString(fDrawType));
}
Exemple #12
0
SkString SkDrawCommand::toString() const {
    return SkString(GetCommandString(fOpType));
}