23
23
#include <strings.h>
24
24
#include <errno.h>
25
25
#include <ctype.h>
26
+ #include <stdarg.h>
26
27
27
28
#include "xdo.h"
28
29
#include "xdotool.h"
@@ -39,6 +40,8 @@ int window_get_arg(context_t *context, int min_arg, int window_arg_pos,
39
40
const char * * window_arg );
40
41
int window_is_valid (context_t * context , const char * window_arg );
41
42
int is_command (char * cmd );
43
+ void xdotool_debug (context_t * context , const char * format , ...);
44
+ void xdotool_output (context_t * context , const char * format , ...);
42
45
43
46
void consume_args (context_t * context , int argc ) {
44
47
if (argc > context -> argc ) {
@@ -514,6 +517,9 @@ int context_execute(context_t *context) {
514
517
if (!strcasecmp (dispatch [i ].name , cmd )) {
515
518
cmd_found = 1 ;
516
519
optind = 0 ;
520
+ if (context -> debug ) {
521
+ fprintf (stderr , "command: %s\n" , cmd );
522
+ }
517
523
ret = dispatch [i ].func (context );
518
524
}
519
525
}
@@ -543,10 +549,29 @@ int cmd_help(context_t *context) {
543
549
}
544
550
545
551
int cmd_version (context_t * context ) {
546
- printf ( "xdotool version %s\n " , xdo_version ());
552
+ xdotool_output ( context , "xdotool version %s" , xdo_version ());
547
553
if (context != NULL ) {
548
554
consume_args (context , 1 );
549
555
}
550
556
551
557
return 0 ;
552
558
}
559
+
560
+ void xdotool_debug (context_t * context , const char * format , ...) {
561
+ va_list args ;
562
+
563
+ va_start (args , format );
564
+ if (context -> debug ) {
565
+ vfprintf (stderr , format , args );
566
+ fprintf (stderr , "\n" );
567
+ }
568
+ } /* xdotool_debug */
569
+
570
+ void xdotool_output (context_t * context , const char * format , ...) {
571
+ va_list args ;
572
+
573
+ va_start (args , format );
574
+ vfprintf (stdout , format , args );
575
+ fprintf (stdout , "\n" );
576
+ fflush (stdout );
577
+ } /* xdotool_output */
0 commit comments