mirror of
https://github.com/bspeice/libcvautomation
synced 2025-04-21 00:41:29 -04:00
Vastly improve error handling of xte_commandString
The best thing about this is that it doesn't break existing functionality Fix some bad input validation
This commit is contained in:
parent
005aa3a284
commit
325bfb0fb9
@ -874,8 +874,10 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
/* And now to test for all of our options */
|
/* And now to test for all of our options */
|
||||||
if (IS_CMD( s_commandString, "mouseclick" ))
|
if (IS_CMD( s_commandString, "mouseclick" ))
|
||||||
{
|
{
|
||||||
|
/* The integer argument is optional */
|
||||||
int mouseButton;
|
int mouseButton;
|
||||||
sscanf( s_commandString, "mouseclick %i", &mouseButton );
|
if (sscanf( s_commandString, "mouseclick %i", &mouseButton ) != 1)
|
||||||
|
mouseButton = 1;
|
||||||
|
|
||||||
xte_clickMouse( displayLocation, mouseButton );
|
xte_clickMouse( displayLocation, mouseButton );
|
||||||
|
|
||||||
@ -884,7 +886,13 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
else if (IS_CMD( s_commandString, "mousexy" ))
|
else if (IS_CMD( s_commandString, "mousexy" ))
|
||||||
{
|
{
|
||||||
int xLocation, yLocation;
|
int xLocation, yLocation;
|
||||||
sscanf( s_commandString, "mousexy %i %i", &xLocation, &yLocation );
|
if (sscanf( s_commandString, "mousexy %i %i", &xLocation, &yLocation ) != 2)
|
||||||
|
{
|
||||||
|
cvaPoint pointerLocation;
|
||||||
|
pointerLocation = xte_pointerLocation( displayLocation );
|
||||||
|
xLocation = pointerLocation.x;
|
||||||
|
yLocation = pointerLocation.y;
|
||||||
|
}
|
||||||
|
|
||||||
xte_hoverMouseXY( displayLocation, xLocation, yLocation );
|
xte_hoverMouseXY( displayLocation, xLocation, yLocation );
|
||||||
|
|
||||||
@ -893,7 +901,11 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
else if (IS_CMD( s_commandString, "mouserxy" ))
|
else if (IS_CMD( s_commandString, "mouserxy" ))
|
||||||
{
|
{
|
||||||
int xIncrement, yIncrement;
|
int xIncrement, yIncrement;
|
||||||
sscanf( s_commandString, "mouserxy %i %i", &xIncrement, &yIncrement );
|
if (sscanf( s_commandString, "mouserxy %i %i", &xIncrement, &yIncrement ) != 2)
|
||||||
|
{
|
||||||
|
xIncrement = 0;
|
||||||
|
yIncrement = 0;
|
||||||
|
}
|
||||||
|
|
||||||
xte_hoverMouseRXY( displayLocation, xIncrement, yIncrement );
|
xte_hoverMouseRXY( displayLocation, xIncrement, yIncrement );
|
||||||
|
|
||||||
@ -903,9 +915,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *fileName;
|
char *fileName;
|
||||||
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "mouseimage %s", fileName );
|
if (sscanf( s_commandString, "mouseimage %s", fileName ) == 1 )
|
||||||
|
resultPoint = xte_hoverMouseImage_location( displayLocation, fileName, searchMethod, tolerance );
|
||||||
resultPoint = xte_hoverMouseImage_location( displayLocation, fileName, searchMethod, tolerance );
|
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
}
|
}
|
||||||
@ -913,9 +924,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *fileName;
|
char *fileName;
|
||||||
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "cmouseimage %s", fileName );
|
if (sscanf( s_commandString, "cmouseimage %s", fileName ) == 1)
|
||||||
|
resultPoint = xte_hoverMouseImage_location_center( displayLocation, fileName, searchMethod, tolerance );
|
||||||
resultPoint = xte_hoverMouseImage_location_center( displayLocation, fileName, searchMethod, tolerance );
|
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
}
|
}
|
||||||
@ -923,9 +933,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *fileName;
|
char *fileName;
|
||||||
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "imouseclick %s", fileName );
|
if (sscanf( s_commandString, "imouseclick %s", fileName ) == 1)
|
||||||
|
resultPoint = xte_clickMouseImage_location( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
||||||
resultPoint = xte_clickMouseImage_location( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
}
|
}
|
||||||
@ -933,16 +942,17 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *fileName;
|
char *fileName;
|
||||||
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "icmouseclick %s", fileName );
|
if (sscanf( s_commandString, "icmouseclick %s", fileName ) == 1)
|
||||||
|
resultPoint = xte_clickMouseImage_location_center( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
||||||
resultPoint = xte_clickMouseImage_location_center( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mousedown" ))
|
else if (IS_CMD( s_commandString, "mousedown" ))
|
||||||
{
|
{
|
||||||
|
/* The integer argument is optional */
|
||||||
int mouseButton;
|
int mouseButton;
|
||||||
sscanf( s_commandString, "mousedown %i", &mouseButton );
|
if (sscanf( s_commandString, "mousedown %i", &mouseButton ) != 1)
|
||||||
|
mouseButton = 1;
|
||||||
|
|
||||||
xte_mouseDown( displayLocation, mouseButton );
|
xte_mouseDown( displayLocation, mouseButton );
|
||||||
|
|
||||||
@ -950,8 +960,10 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mouseup" ))
|
else if (IS_CMD( s_commandString, "mouseup" ))
|
||||||
{
|
{
|
||||||
|
/* The integer argument is optional */
|
||||||
int mouseButton;
|
int mouseButton;
|
||||||
sscanf( s_commandString, "mouseup %i", &mouseButton );
|
if (sscanf( s_commandString, "mouseup %i", &mouseButton ) != 1)
|
||||||
|
mouseButton = 1;
|
||||||
|
|
||||||
xte_mouseUp( displayLocation, mouseButton );
|
xte_mouseUp( displayLocation, mouseButton );
|
||||||
|
|
||||||
@ -979,9 +991,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
key = malloc(COMMAND_STR_LEN * sizeof(char));
|
key = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "keyclick %s", key );
|
if (sscanf( s_commandString, "keyclick %s", key ) == 1)
|
||||||
|
xte_clickKey( displayLocation, key );
|
||||||
xte_clickKey( displayLocation, key );
|
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
@ -991,9 +1002,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
key = malloc(COMMAND_STR_LEN * sizeof(char));
|
key = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "keydown %s", key );
|
if (sscanf( s_commandString, "keydown %s", key ) == 1)
|
||||||
|
xte_keyDown( displayLocation, key );
|
||||||
xte_keyDown( displayLocation, key );
|
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
@ -1003,9 +1013,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
key = malloc(COMMAND_STR_LEN * sizeof(char));
|
key = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "keyup %s", key );
|
if (sscanf( s_commandString, "keyup %s", key ) == 1)
|
||||||
|
xte_keyUp( displayLocation, key );
|
||||||
xte_keyUp( displayLocation, key );
|
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
@ -1015,9 +1024,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *keyString;
|
char *keyString;
|
||||||
keyString = malloc(COMMAND_STR_LEN * sizeof(char));
|
keyString = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "keystring %s", keyString );
|
if (sscanf( s_commandString, "keystring %s", keyString ) == 1)
|
||||||
|
xte_clickKeyStr( displayLocation, keyString );
|
||||||
xte_clickKeyStr( displayLocation, keyString );
|
|
||||||
|
|
||||||
free(keyString);
|
free(keyString);
|
||||||
|
|
||||||
@ -1027,9 +1035,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
{
|
{
|
||||||
char *fileName;
|
char *fileName;
|
||||||
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
fileName = malloc(COMMAND_STR_LEN * sizeof(char));
|
||||||
sscanf( s_commandString, "waitfor %s", fileName );
|
if (sscanf( s_commandString, "waitfor %s", fileName ) == 1)
|
||||||
|
resultPoint = xte_waitForImage_location( displayLocation, fileName, searchMethod, tolerance, timeout );
|
||||||
resultPoint = xte_waitForImage_location( displayLocation, fileName, searchMethod, tolerance, timeout );
|
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
}
|
}
|
||||||
|
@ -172,8 +172,7 @@ click_i ()
|
|||||||
for x in $@
|
for x in $@
|
||||||
do
|
do
|
||||||
|
|
||||||
waitfor "$x"
|
CVA_RETURN=`waitfor "$x"`
|
||||||
CVA_RETURN=$?
|
|
||||||
|
|
||||||
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
|
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
|
||||||
RETURN_CODE=$CVA_RETURN
|
RETURN_CODE=$CVA_RETURN
|
||||||
@ -357,8 +356,7 @@ hover_i ()
|
|||||||
do
|
do
|
||||||
for x in $@
|
for x in $@
|
||||||
do
|
do
|
||||||
waitfor "$x"
|
CVA_RETURN=`waitfor "$x"`
|
||||||
CVA_RETURN=$?
|
|
||||||
|
|
||||||
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
|
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
|
||||||
RETURN_CODE=$CVA_RETURN
|
RETURN_CODE=$CVA_RETURN
|
||||||
@ -543,7 +541,12 @@ waitfor ()
|
|||||||
eval '$CVAINPUT -t $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor $1" >> $OUTFILE'
|
eval '$CVAINPUT -t $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor $1" >> $OUTFILE'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $?
|
RETURN_CODE=$?
|
||||||
|
echo $RETURN_CODE
|
||||||
|
|
||||||
|
#We don't return here, but rather just pass the return code up -
|
||||||
|
#This makes sure that if the user sets errexit, we don't abort because
|
||||||
|
#multiple images were used, while still keeping the return code.
|
||||||
} # ---------- end of function waitfor ----------
|
} # ---------- end of function waitfor ----------
|
||||||
#--- FUNCTION ----------------------------------------------------------------
|
#--- FUNCTION ----------------------------------------------------------------
|
||||||
# NAME: notify
|
# NAME: notify
|
||||||
|
Loading…
Reference in New Issue
Block a user