summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2012-08-26 21:45:45 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2012-10-02 22:16:09 -0700
commit95a436f7efd7061a15e3be533c56e573aac2db92 (patch)
treec6d28a9dac6e96c8401e26d722c98ca12011016d
parent8b26ded773e1cd4890e93836692ecc9f136c5efd (diff)
Refactor error printing to use common functions
All errors currently recognized by xscope fall into two forms, with or without a 32-bit value to print as a bad value, so use common implementations for those two forms so we can stop duplicating that code for every new extension-defined error. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--print11.c150
-rw-r--r--print_render.c40
-rw-r--r--x11.h5
3 files changed, 49 insertions, 146 deletions
diff --git a/print11.c b/print11.c
index 7935b84..cf477e2 100644
--- a/print11.c
+++ b/print11.c
@@ -193,213 +193,141 @@ const char *REPLYHEADER = "..............REPLY";
/* Error Printing procedures */
+/* generic routine for printing common format error messages with a
+ labeled bad value in bytes 4-7. */
void
-RequestError(const unsigned char *buf)
+printErrorWithValue(const unsigned char *buf,
+ short FieldType, const char *desc)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Request */
+ PrintField(buf, 1, 1, ERROR, ERRORHEADER);
if (Verbose < 1)
return;
printfield(buf, 2, 2, CARD16, "sequence number");
+ PrintField(buf, 4, 4, FieldType, desc);
PrintField(buf, 8, 2, CARD16, "minor opcode");
PrintField(buf, 10, 1, CARD8, "major opcode");
}
+/* generic routine for printing common format error messages with
+ no additional information provided. */
void
-ValueError(const unsigned char *buf)
+printErrorNoValue(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Value */
+ PrintField(buf, 1, 1, ERROR, ERRORHEADER);
if (Verbose < 1)
return;
printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, INT32, "bad value");
+ /* 4 bytes unused */
PrintField(buf, 8, 2, CARD16, "minor opcode");
PrintField(buf, 10, 1, CARD8, "major opcode");
}
void
+RequestError(const unsigned char *buf)
+{
+ printErrorNoValue(buf);
+}
+
+void
+ValueError(const unsigned char *buf)
+{
+ printErrorWithValue(buf, INT32, "bad value");
+}
+
+void
WindowError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Window */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
PixmapError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Pixmap */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
AtomError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Atom */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad atom id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad atom id");
}
void
CursorError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Cursor */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
FontError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Font */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
MatchError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Match */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorNoValue(buf);
}
void
DrawableError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Drawable */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
AccessError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Access */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorNoValue(buf);
}
void
AllocError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Alloc */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorNoValue(buf);
}
void
ColormapError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Colormap */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
GContextError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* GContext */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
IDChoiceError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* IDChoice */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
void
NameError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Name */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorNoValue(buf);
}
void
LengthError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Length */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorNoValue(buf);
}
void
ImplementationError(const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Implementation */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorNoValue(buf);
}
void
UnknownError(const unsigned char *buf)
{
- PrintField(RBf, 1, 1, ERROR, ERRORHEADER);
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "bad resource id");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "bad resource id");
}
/* ************************************************************ */
diff --git a/print_render.c b/print_render.c
index 769fde5..60db37f 100644
--- a/print_render.c
+++ b/print_render.c
@@ -724,59 +724,29 @@ RenderCreateConicalGradient(FD fd, const unsigned char *buf)
void
RenderPictFormatError(FD fd, const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Request */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, PICTFORMAT, "format");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, PICTFORMAT, "format");
}
void
RenderPictureError(FD fd, const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Request */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, PICTURE, "picture");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, PICTURE, "picture");
}
void
RenderPictOpError(FD fd, const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Request */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, PICTOP, "pictop");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, PICTOP, "pictop");
}
void
RenderGlyphSetError(FD fd, const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Request */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, GLYPHSET, "glyphset");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, GLYPHSET, "glyphset");
}
void
RenderGlyphError(FD fd, const unsigned char *buf)
{
- PrintField(buf, 1, 1, ERROR, ERRORHEADER); /* Request */
- if (Verbose < 1)
- return;
- printfield(buf, 2, 2, CARD16, "sequence number");
- PrintField(buf, 4, 4, CARD32, "glyph");
- PrintField(buf, 8, 2, CARD16, "minor opcode");
- PrintField(buf, 10, 1, CARD8, "major opcode");
+ printErrorWithValue(buf, CARD32, "glyph");
}
diff --git a/x11.h b/x11.h
index 6cdf270..fa6cfef 100644
--- a/x11.h
+++ b/x11.h
@@ -656,4 +656,9 @@ uint32_t getreqlen(FD fd, const unsigned char *buf) {
/* Constant defined in Generic Event Protocol 1.0 for event type */
#define Event_Type_Generic 35
+/* Routines for printing the two common forms of error responses */
+extern void printErrorWithValue(const unsigned char *buf,
+ short FieldType, const char *desc);
+extern void printErrorNoValue(const unsigned char *buf);
+
#endif /* XSCOPE_X11_H */