mirror of
https://github.com/bspeice/libcvautomation
synced 2024-12-04 13:58:11 -05: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;
|
||||
tolerance = INT_MAX;
|
||||
|
||||
int returnCode = 1;
|
||||
|
||||
/* Start getopt */
|
||||
while (1)
|
||||
{
|
||||
@ -119,9 +121,18 @@ int main( int argc, char** argv )
|
||||
returnPoint = xte_commandString( display, optarg, mouseButton, searchMethod, tolerance );
|
||||
|
||||
if (returnPoint.x != -1 && returnPoint.y != -1)
|
||||
{
|
||||
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);
|
||||
returnCode = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
@ -144,7 +155,7 @@ int main( int argc, char** argv )
|
||||
if ( display != NULL )
|
||||
XCloseDisplay( display );
|
||||
|
||||
return 0;
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -160,6 +171,8 @@ Libcvautomation version: %s\n\
|
||||
cva-input -s <command_string>\n\
|
||||
\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\
|
||||
Usage: \n\
|
||||
\n\
|
||||
@ -228,6 +241,7 @@ void checkXTEEnabled ( Display *display )
|
||||
* \date 7/18/2012
|
||||
* \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.
|
||||
* The return code is 1 if there are no commands given, or if all commands fail. It is 0 otherwise.
|
||||
* \section example Example Usage:
|
||||
* Click the mouse:
|
||||
*
|
||||
|
@ -48,9 +48,7 @@ int main( int argc, char** argv )
|
||||
int useX = 0; /* bool useX = false; */
|
||||
Bool useCenter = False;
|
||||
char *xDisplayLocation;
|
||||
Display *display;
|
||||
/* This line to suppress a compiler warning */
|
||||
display = NULL;
|
||||
Display *display = NULL;
|
||||
|
||||
/* Set the default display */
|
||||
xDisplayLocation = "";
|
||||
@ -59,6 +57,8 @@ int main( int argc, char** argv )
|
||||
basic_list *list_head, *list_curr, *list_prev;
|
||||
list_head = list_curr = list_prev = NULL;
|
||||
|
||||
int returnCode = 1;
|
||||
|
||||
/* Start getopt */
|
||||
while (1)
|
||||
{
|
||||
@ -187,9 +187,12 @@ int main( int argc, char** argv )
|
||||
result_point = matchSubImage_location( root_location, sub_location, search_method, tolerance );
|
||||
|
||||
if ( result_point.x != -1 && result_point.y != -1 )
|
||||
{
|
||||
/* Output the match location */
|
||||
printf ("%s%s%i%s%i\n", list_curr->fileName, separator,
|
||||
result_point.x, separator, result_point.y );
|
||||
returnCode = 0;
|
||||
}
|
||||
|
||||
/* With the way we allocate the list, we ensure that we always
|
||||
* have at least one element past the end of the list.
|
||||
@ -207,7 +210,7 @@ int main( int argc, char** argv )
|
||||
if (useX)
|
||||
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\
|
||||
\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\
|
||||
1 for one match, etc.\n\
|
||||
The return code is 0 for at least one successful match, and 1 otherwise.\n\
|
||||
\n\
|
||||
Usage: \n\
|
||||
\n\
|
||||
@ -274,7 +276,7 @@ If you have any questions, comments, concerns, email <%s>\n", LIBCVAUTOMATION_VE
|
||||
* \author Bradlee Speice <bspeice@uncc.edu>
|
||||
* \date 7/18/2012
|
||||
* \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:
|
||||
* 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,
|
||||
* 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;
|
||||
resultPoint.x = -1;
|
||||
resultPoint.y = -1;
|
||||
@ -803,6 +810,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
||||
sscanf( s_commandString, "mouseclick %i", &mouseButton );
|
||||
|
||||
xte_clickMouse( displayLocation, mouseButton );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
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 );
|
||||
|
||||
xte_hoverMouseXY( displayLocation, xLocation, yLocation );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
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 );
|
||||
|
||||
xte_hoverMouseRXY( displayLocation, xIncrement, yIncrement );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
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 );
|
||||
|
||||
free(fileName);
|
||||
|
||||
return resultPoint;
|
||||
}
|
||||
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 );
|
||||
|
||||
free(fileName);
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
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 );
|
||||
|
||||
free(fileName);
|
||||
|
||||
return resultPoint;
|
||||
}
|
||||
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 );
|
||||
|
||||
free(fileName);
|
||||
|
||||
return resultPoint;
|
||||
}
|
||||
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 );
|
||||
|
||||
xte_mouseDown( displayLocation, mouseButton );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
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 );
|
||||
|
||||
xte_mouseUp( displayLocation, mouseButton );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "mousejiggle" ))
|
||||
{
|
||||
xte_mouseJiggle( displayLocation );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "mousescrollu" ))
|
||||
{
|
||||
xte_mouseScrollUp( displayLocation );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "mousescrolld" ))
|
||||
{
|
||||
xte_mouseScrollDown( displayLocation );
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "keyclick" ))
|
||||
{
|
||||
@ -902,6 +921,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
||||
xte_clickKey( displayLocation, key );
|
||||
|
||||
free(key);
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "keydown" ))
|
||||
{
|
||||
@ -912,6 +933,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
||||
xte_keyDown( displayLocation, key );
|
||||
|
||||
free(key);
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "keyup" ))
|
||||
{
|
||||
@ -922,6 +945,8 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
||||
xte_keyUp( displayLocation, key );
|
||||
|
||||
free(key);
|
||||
|
||||
resultPoint.x = resultPoint.y = -2;
|
||||
}
|
||||
else if (IS_CMD( s_commandString, "keystring" ))
|
||||
{
|
||||
@ -932,8 +957,12 @@ cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int
|
||||
xte_clickKeyStr( displayLocation, 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user