mirror of
https://github.com/bspeice/libcvautomation
synced 2025-04-21 00:41:29 -04:00
Fix return codes actually doing what they're documented to
This commit is contained in:
parent
06804d6528
commit
a33d97a2a6
@ -43,6 +43,8 @@ int main( int argc, char** argv )
|
|||||||
searchMethod = 0;
|
searchMethod = 0;
|
||||||
tolerance = INT_MAX;
|
tolerance = INT_MAX;
|
||||||
|
|
||||||
|
int returnCode = 1;
|
||||||
|
|
||||||
/* Start getopt */
|
/* Start getopt */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -119,9 +121,18 @@ int main( int argc, char** argv )
|
|||||||
returnPoint = xte_commandString( display, optarg, mouseButton, searchMethod, tolerance );
|
returnPoint = xte_commandString( display, optarg, mouseButton, searchMethod, tolerance );
|
||||||
|
|
||||||
if (returnPoint.x != -1 && returnPoint.y != -1)
|
if (returnPoint.x != -1 && returnPoint.y != -1)
|
||||||
|
{
|
||||||
printf("%s%s%i%s%i\n", optarg, separator, returnPoint.x, separator, returnPoint.y);
|
printf("%s%s%i%s%i\n", optarg, separator, returnPoint.x, separator, returnPoint.y);
|
||||||
else
|
returnCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (returnPoint.x == -2 && returnPoint.y == -2)
|
||||||
|
{
|
||||||
|
/* Not an error, just that the command didn't use returnPoint */
|
||||||
printf("%s\n", optarg);
|
printf("%s\n", optarg);
|
||||||
|
returnCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
@ -144,7 +155,7 @@ int main( int argc, char** argv )
|
|||||||
if ( display != NULL )
|
if ( display != NULL )
|
||||||
XCloseDisplay( display );
|
XCloseDisplay( display );
|
||||||
|
|
||||||
return 0;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -160,6 +171,8 @@ Libcvautomation version: %s\n\
|
|||||||
cva-input -s <command_string>\n\
|
cva-input -s <command_string>\n\
|
||||||
\n\
|
\n\
|
||||||
The cva-input program demonstrates the XTest section of libcvautomation.\n\
|
The cva-input program demonstrates the XTest section of libcvautomation.\n\
|
||||||
|
The return code is 1 if there are no commands given, or if all commands fail.\n\
|
||||||
|
It is 0 otherwise.\n\
|
||||||
\n\
|
\n\
|
||||||
Usage: \n\
|
Usage: \n\
|
||||||
\n\
|
\n\
|
||||||
@ -228,6 +241,7 @@ void checkXTEEnabled ( Display *display )
|
|||||||
* \date 7/18/2012
|
* \date 7/18/2012
|
||||||
* \section usage Usage:
|
* \section usage Usage:
|
||||||
* This program works kind of like a mini-language. All options are parsed left-to-right, and executed right there. Thus, specifying "--display" at different places in the options will cause this program to use the most recent given display.
|
* This program works kind of like a mini-language. All options are parsed left-to-right, and executed right there. Thus, specifying "--display" at different places in the options will cause this program to use the most recent given display.
|
||||||
|
* The return code is 1 if there are no commands given, or if all commands fail. It is 0 otherwise.
|
||||||
* \section example Example Usage:
|
* \section example Example Usage:
|
||||||
* Click the mouse:
|
* Click the mouse:
|
||||||
*
|
*
|
||||||
|
@ -48,9 +48,7 @@ int main( int argc, char** argv )
|
|||||||
int useX = 0; /* bool useX = false; */
|
int useX = 0; /* bool useX = false; */
|
||||||
Bool useCenter = False;
|
Bool useCenter = False;
|
||||||
char *xDisplayLocation;
|
char *xDisplayLocation;
|
||||||
Display *display;
|
Display *display = NULL;
|
||||||
/* This line to suppress a compiler warning */
|
|
||||||
display = NULL;
|
|
||||||
|
|
||||||
/* Set the default display */
|
/* Set the default display */
|
||||||
xDisplayLocation = "";
|
xDisplayLocation = "";
|
||||||
@ -59,6 +57,8 @@ int main( int argc, char** argv )
|
|||||||
basic_list *list_head, *list_curr, *list_prev;
|
basic_list *list_head, *list_curr, *list_prev;
|
||||||
list_head = list_curr = list_prev = NULL;
|
list_head = list_curr = list_prev = NULL;
|
||||||
|
|
||||||
|
int returnCode = 1;
|
||||||
|
|
||||||
/* Start getopt */
|
/* Start getopt */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -187,9 +187,12 @@ int main( int argc, char** argv )
|
|||||||
result_point = matchSubImage_location( root_location, sub_location, search_method, tolerance );
|
result_point = matchSubImage_location( root_location, sub_location, search_method, tolerance );
|
||||||
|
|
||||||
if ( result_point.x != -1 && result_point.y != -1 )
|
if ( result_point.x != -1 && result_point.y != -1 )
|
||||||
|
{
|
||||||
/* Output the match location */
|
/* Output the match location */
|
||||||
printf ("%s%s%i%s%i\n", list_curr->fileName, separator,
|
printf ("%s%s%i%s%i\n", list_curr->fileName, separator,
|
||||||
result_point.x, separator, result_point.y );
|
result_point.x, separator, result_point.y );
|
||||||
|
returnCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* With the way we allocate the list, we ensure that we always
|
/* With the way we allocate the list, we ensure that we always
|
||||||
* have at least one element past the end of the list.
|
* have at least one element past the end of the list.
|
||||||
@ -207,7 +210,7 @@ int main( int argc, char** argv )
|
|||||||
if (useX)
|
if (useX)
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
|
|
||||||
return 0;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -224,8 +227,7 @@ cva-match -r <root_image> -s <sub_image> \n\
|
|||||||
cva-match -s <sub_image> -x \n\
|
cva-match -s <sub_image> -x \n\
|
||||||
\n\
|
\n\
|
||||||
This program uses OpenCV in order to recognize an image within an image.\n\
|
This program uses OpenCV in order to recognize an image within an image.\n\
|
||||||
The return code is how many matches were found - return 0 for no matches,\n\
|
The return code is 0 for at least one successful match, and 1 otherwise.\n\
|
||||||
1 for one match, etc.\n\
|
|
||||||
\n\
|
\n\
|
||||||
Usage: \n\
|
Usage: \n\
|
||||||
\n\
|
\n\
|
||||||
@ -274,7 +276,7 @@ If you have any questions, comments, concerns, email <%s>\n", LIBCVAUTOMATION_VE
|
|||||||
* \author Bradlee Speice <bspeice@uncc.edu>
|
* \author Bradlee Speice <bspeice@uncc.edu>
|
||||||
* \date 7/18/2012
|
* \date 7/18/2012
|
||||||
* \section usage Usage:
|
* \section usage Usage:
|
||||||
* This program uses OpenCV in order to recognize an image within an image. The return code is how many matches were found - return 0 for no matches, 1 for one match, etc.
|
* This program uses OpenCV in order to recognize an image within an image. The return code is 0 for at least one successful match, and 1 otherwise.
|
||||||
*
|
*
|
||||||
* \section example Example Usage:
|
* \section example Example Usage:
|
||||||
* Match two images against the root X11 window:
|
* Match two images against the root X11 window:
|
||||||
|
@ -781,6 +781,13 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
/* Note that most of the functions don't need mouseButton, searchMethod, or tolerance,
|
/* Note that most of the functions don't need mouseButton, searchMethod, or tolerance,
|
||||||
* but they're here to make sure that they're available if needed. */
|
* but they're here to make sure that they're available if needed. */
|
||||||
|
|
||||||
|
/* The returns also bear a bit of instruction.
|
||||||
|
* A return of (0,0) or up is a success
|
||||||
|
* A return of (-1,-1) is an error
|
||||||
|
* A return of (-2,-2) indicates that the command didn't need to use the point -
|
||||||
|
* This helps differentiate between errors and functions like keyclick that
|
||||||
|
* don't use the resultPoint. */
|
||||||
|
|
||||||
cvaPoint resultPoint;
|
cvaPoint resultPoint;
|
||||||
resultPoint.x = -1;
|
resultPoint.x = -1;
|
||||||
resultPoint.y = -1;
|
resultPoint.y = -1;
|
||||||
@ -803,6 +810,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
sscanf( s_commandString, "mouseclick %i", &mouseButton );
|
sscanf( s_commandString, "mouseclick %i", &mouseButton );
|
||||||
|
|
||||||
xte_clickMouse( displayLocation, mouseButton );
|
xte_clickMouse( displayLocation, mouseButton );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mousexy" ))
|
else if (IS_CMD( s_commandString, "mousexy" ))
|
||||||
{
|
{
|
||||||
@ -810,6 +819,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
sscanf( s_commandString, "mousexy %i %i", &xLocation, &yLocation );
|
sscanf( s_commandString, "mousexy %i %i", &xLocation, &yLocation );
|
||||||
|
|
||||||
xte_hoverMouseXY( displayLocation, xLocation, yLocation );
|
xte_hoverMouseXY( displayLocation, xLocation, yLocation );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mouserxy" ))
|
else if (IS_CMD( s_commandString, "mouserxy" ))
|
||||||
{
|
{
|
||||||
@ -817,6 +828,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
sscanf( s_commandString, "mouserxy %i %i", &xIncrement, &yIncrement );
|
sscanf( s_commandString, "mouserxy %i %i", &xIncrement, &yIncrement );
|
||||||
|
|
||||||
xte_hoverMouseRXY( displayLocation, xIncrement, yIncrement );
|
xte_hoverMouseRXY( displayLocation, xIncrement, yIncrement );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mouseimage" ))
|
else if (IS_CMD( s_commandString, "mouseimage" ))
|
||||||
{
|
{
|
||||||
@ -828,8 +841,6 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
resultPoint = xte_hoverMouseImage_location( displayLocation, fileName, searchMethod, tolerance );
|
resultPoint = xte_hoverMouseImage_location( displayLocation, fileName, searchMethod, tolerance );
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
|
|
||||||
return resultPoint;
|
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "cmouseimage" ))
|
else if (IS_CMD( s_commandString, "cmouseimage" ))
|
||||||
{
|
{
|
||||||
@ -840,6 +851,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
xte_hoverMouseImage_location_center( displayLocation, fileName, searchMethod, tolerance );
|
xte_hoverMouseImage_location_center( displayLocation, fileName, searchMethod, tolerance );
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "imouseclick" ))
|
else if (IS_CMD( s_commandString, "imouseclick" ))
|
||||||
{
|
{
|
||||||
@ -851,8 +864,6 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
resultPoint = xte_clickMouseImage_location( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
resultPoint = xte_clickMouseImage_location( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
|
|
||||||
return resultPoint;
|
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "icmouseclick" ))
|
else if (IS_CMD( s_commandString, "icmouseclick" ))
|
||||||
{
|
{
|
||||||
@ -864,8 +875,6 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
resultPoint = xte_clickMouseImage_location_center( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
resultPoint = xte_clickMouseImage_location_center( displayLocation, fileName, mouseButton, searchMethod, tolerance );
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
|
|
||||||
return resultPoint;
|
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mousedown" ))
|
else if (IS_CMD( s_commandString, "mousedown" ))
|
||||||
{
|
{
|
||||||
@ -873,6 +882,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
sscanf( s_commandString, "mousedown %i", &mouseButton );
|
sscanf( s_commandString, "mousedown %i", &mouseButton );
|
||||||
|
|
||||||
xte_mouseDown( displayLocation, mouseButton );
|
xte_mouseDown( displayLocation, mouseButton );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mouseup" ))
|
else if (IS_CMD( s_commandString, "mouseup" ))
|
||||||
{
|
{
|
||||||
@ -880,18 +891,26 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
sscanf( s_commandString, "mouseup %i", &mouseButton );
|
sscanf( s_commandString, "mouseup %i", &mouseButton );
|
||||||
|
|
||||||
xte_mouseUp( displayLocation, mouseButton );
|
xte_mouseUp( displayLocation, mouseButton );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mousejiggle" ))
|
else if (IS_CMD( s_commandString, "mousejiggle" ))
|
||||||
{
|
{
|
||||||
xte_mouseJiggle( displayLocation );
|
xte_mouseJiggle( displayLocation );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mousescrollu" ))
|
else if (IS_CMD( s_commandString, "mousescrollu" ))
|
||||||
{
|
{
|
||||||
xte_mouseScrollUp( displayLocation );
|
xte_mouseScrollUp( displayLocation );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "mousescrolld" ))
|
else if (IS_CMD( s_commandString, "mousescrolld" ))
|
||||||
{
|
{
|
||||||
xte_mouseScrollDown( displayLocation );
|
xte_mouseScrollDown( displayLocation );
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "keyclick" ))
|
else if (IS_CMD( s_commandString, "keyclick" ))
|
||||||
{
|
{
|
||||||
@ -902,6 +921,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
xte_clickKey( displayLocation, key );
|
xte_clickKey( displayLocation, key );
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "keydown" ))
|
else if (IS_CMD( s_commandString, "keydown" ))
|
||||||
{
|
{
|
||||||
@ -912,6 +933,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
xte_keyDown( displayLocation, key );
|
xte_keyDown( displayLocation, key );
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "keyup" ))
|
else if (IS_CMD( s_commandString, "keyup" ))
|
||||||
{
|
{
|
||||||
@ -922,6 +945,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
xte_keyUp( displayLocation, key );
|
xte_keyUp( displayLocation, key );
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
else if (IS_CMD( s_commandString, "keystring" ))
|
else if (IS_CMD( s_commandString, "keystring" ))
|
||||||
{
|
{
|
||||||
@ -932,8 +957,12 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
|||||||
xte_clickKeyStr( displayLocation, keyString );
|
xte_clickKeyStr( displayLocation, keyString );
|
||||||
|
|
||||||
free(keyString);
|
free(keyString);
|
||||||
|
|
||||||
|
resultPoint.x = resultPoint.y = -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Note that we will return (-1,-1) implicitly
|
||||||
|
* if we don't recognize the argument */
|
||||||
return resultPoint;
|
return resultPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user