Script_Parse

 

"Script_Parse()" is used to parse a command that use your keyword. This function is called by sliceO when a script command was entered in the program and that command start with the same key word as the one you registered. The same key word can be registered by multiple modules, so if the arguments of this command are not recognized by your module, you should return "0" so that sliceO will try other modules. If you return "1", it signal that you have recognized this command and acted on it.

 

The function receive 2 arguments: "nb_arg" and "pt_arg".

 

 

 

 

 

Syntax

 

extern "C" __declspec(dllexport) int  Script_Parse(

          int nb_arg,

          char *pt_arg[]

)

 

 

Parameters

 

nb_arg

nb_arg is the number of argument that the parser found for this command.

 

pt_arg

pt_arg is a pointer to an array of "nb_arg" arguments.

 

 

Return value

 

The function returns "1" if the command was understood, "0" if not and "-1" if an error occurred.

 

 

Remarks

 

This function is optional.

 

If the number of arguments is "0" or the first argument is either "help" or a question mark (?), then you should print a list of commands recognized by your module.

 

Frequently, the first or second arguments of a script command will be an action verb telling your parser what it should do.  If this verb is the second argument, then usually the first argument is a template matching one or multiple element to witch the action should be applied.

 

 

Requirements

 

Header:

          sliceO_include.hpp

 

 

Library:

          sliceO_Structures.lib

 

 

Example

 

The "snapshot" module use the syntax: "snapshot: [t_window] click [filename]".  "snapshot" is the registered key word for the snapshot module, "click" is the desired action, and the optional "t_window" is a template matching one or multiple windows that need to be saved to file.  SliceOmatic provide functions to help you transform the templates in list of matched elements.

 

...

 

// ----------------------------------------------------------------------------

//

//          Function:          Script_Parse

//

//          Parameters:          nb_arg (int)          number of arguments in the command.

//                              pt_arg (char **)          Vector of arguments that where

//                                                             following your key word on the command

//                                                             line.

//          Returns:          (int)                     1 if command was understood,

//                                                   0 otherwise

//                                                   -1 if there was an error

//

//          If the command line start with your key word, sliceO will call this

//          function with the rest of the command line as arguments.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int           Script_Parse( int nb_arg, char *pt_arg[] )

{

          if ( (nb_arg < 1)

            || ! strncmp( pt_arg[0], "help", 3)

            || ((nb_arg==1) && (! strcmp( pt_arg[0], "?"))) ) {

                    Error_Fct( hwnd, ERROR_CODE_THREAD, "------ Snapshot commands -------------" ) ;

                    Error_Fct( hwnd, ERROR_CODE_THREAD, "Snapshot: [t_window] click [file_name]" ) ;

                    return( 0 )  ;

          }

          

          // ====================================================================

          // ====================================================================

          // === cmd at pos 0 or 1

          // ====================================================================

          // ====================================================================

          char *cmd = NULL ;

          char *t_window = NULL ;

          char *file_name = NULL ;

 

          if ( (nb_arg > 1) && (! _strnicmp( pt_arg[1], "click", 3 )) ) {

              t_window = pt_arg[0] ;

              cmd = pt_arg[1] ;

              if ( nb_arg > 2 )

                    file_name = pt_arg[2] ;

          } else {

              cmd = pt_arg[0] ;

              if ( nb_arg > 1 )

                    file_name = pt_arg[1] ;

          }

 

          // --------------------------------------------------------------------

          // --- click ---

          // --------------------------------------------------------------------

          if ( ! _strnicmp( cmd, "click", 3 ) ) {

 

              if ( ! t_window )

                    Snapshot_Grab_Windows( NULL, file_name ) ;

 

              if ( t_window ) {

                    int max_wind = 10 ;

                    SliceO_Window *list[10] ;

                    int nb_wind = Fct_Match_Template_Window( t_window, max_wind, list ) ;

 

                    for ( int i=0; i < nb_wind; i++ )

                        Snapshot_Grab_Windows( list[i]->m_wind_draw, file_name ) ;

              }

 

              return( 1 )  ;

          }

 

          return( 0 ) ;

}

 

...

 

See also

 

Script_Parse