On Wed, Mar 30, 2011 at 8:57 PM, Peter Hutterer
<peter.hutte...@who-t.net> wrote:
> On Wed, Mar 30, 2011 at 01:54:41PM -0700, Jason Gerecke wrote:
>> For many commands, improper arguments cause a silent failure. The
>> user is often given no indication if their command succeeded or
>> failed. I've tried to find all the silent "return;" statements and
>> provide some kind of warning message where possible.
>>
>> In some cases I've added in new checks to ensure that we have the
>> correct number of arguments. I've tried to make checks as pedantic
>> as possible, e.g. throwing errors about number of arguments even if
>> the function ignores arguments.
>>
>
> as a follow-up, it would be useful to have fprintf(stderr) replaced by an
> error() function.
>
I wholeheartedly agree, but was having trouble coming up with a good
error() function I liked.

>> Signed-off-by: Jason Gerecke <killert...@gmail.com>
>> ---
>>  tools/xsetwacom.c |   31 +++++++++++++++++++++++++++++++
>>  1 files changed, 31 insertions(+), 0 deletions(-)
>>
>> diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
>> index 41e4ced..337aa88 100644
>> --- a/tools/xsetwacom.c
>> +++ b/tools/xsetwacom.c
>> @@ -1234,7 +1234,10 @@ static void special_map_property(Display *dpy, 
>> XDevice *dev, Atom btnact_prop, i
>>                               &bytes_after, (unsigned char**)&btnact_data);
>>
>>       if (offset > btnact_nitems)
>> +     {
>> +             fprintf(stderr, "Invalid offset into %s property.\n", 
>> XGetAtomName(dpy, btnact_prop));
>>               return;
>> +     }
>>
>>       if (format == 8 && type == XA_INTEGER)
>>       {
>> @@ -1242,7 +1245,10 @@ static void special_map_property(Display *dpy, 
>> XDevice *dev, Atom btnact_prop, i
>>                * mappings. Convert to 32 bit Atom actions first.
>>                */
>>               if (convert_wheel_prop(dpy, dev, btnact_prop))
>> +             {
>> +                     fprintf(stderr, "Error creating wheel action.\n");
>>                       return;
>> +             }
>>
>>               XGetDeviceProperty(dpy, dev, btnact_prop, 0, 100, False,
>>                                  AnyPropertyType, &type, &format,
>> @@ -1347,6 +1353,12 @@ static void set_xydefault(Display *dpy, XDevice *dev, 
>> param_t* param, int argc,
>>       unsigned long nitems, bytes_after;
>>       long *ldata;
>>
>> +     if (argc != 0)
>> +     {
>> +             fprintf(stderr, "Incorrect number of arguments supplied.\n");
>> +             return;
>> +     }
>> +
>>       prop = XInternAtom(dpy, param->prop_name, True);
>>       if (!prop)
>>       {
>> @@ -1632,7 +1644,10 @@ static void get_mode(Display *dpy, XDevice *dev, 
>> param_t* param, int argc, char
>>       }
>>
>>       if (!ndevices) /* device id 0 is reserved and can't be our device */
>> +     {
>> +             fprintf(stderr, "Unable to locate device.\n");
>>               return;
>> +     }
>>
>>       TRACE("Getting mode for device %ld.\n", dev->device_id);
>>
>> @@ -1658,6 +1673,12 @@ static void get_rotate(Display *dpy, XDevice *dev, 
>> param_t* param, int argc, cha
>>       unsigned char* data;
>>       unsigned long nitems, bytes_after;
>>
>> +     if (argc != 0)
>> +     {
>> +             fprintf(stderr, "Incorrect number of arguments supplied.\n");
>> +             return;
>> +     }
>> +
>>       prop = XInternAtom(dpy, param->prop_name, True);
>>       if (!prop)
>>       {
>> @@ -1937,7 +1958,11 @@ static void _set_matrix_prop(Display *dpy, XDevice 
>> *dev, const float fmatrix[9])
>>                               &bytes_after, (unsigned char**)&data);
>>
>>       if (format != 32 || type != XInternAtom(dpy, "FLOAT", True))
>> +     {
>> +             fprintf(stderr, "Property for '%s' has unexpected type - this 
>> is a bug.\n",
>> +                     "Coordinate Transformation Matrix");
>
> this should use a define instead of typing the same property name twice..
>
Good call there.

>
>>               return;
>> +     }
>>
>>       XChangeDeviceProperty(dpy, dev, matrix_prop, type, format,
>>                             PropModeReplace, (unsigned char*)matrix, 9);
>> @@ -1954,6 +1979,12 @@ static void set_output(Display *dpy, XDevice *dev, 
>> param_t *param, int argc, cha
>>       XRROutputInfo *output_info;
>>       XRRCrtcInfo *crtc_info;
>>
>> +     if (argc != 1)
>> +     {
>> +             fprintf(stderr, "Incorrect number of arguments supplied.\n");
>> +             return;
>> +     }
>> +
>>       output_name = argv[0];
>>
>>       if (!XRRQueryExtension(dpy, &maj, &min)) /* using min/maj as dummy */
>> --
>> 1.7.4.1
>
>

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to