[PATCH 1/3] xvfb: reorganize command line argument processing in separate procedures
Tiago Vignatti
tiago.vignatti at nokia.com
Thu Apr 8 07:34:12 PDT 2010
Just code organization. The semantics are the same.
I left intentionally global variables there, which will make sense on the
next commit.
Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
---
hw/vfb/InitOutput.c | 233 ++++++++++++++++++++++++++++++++------------------
1 files changed, 149 insertions(+), 84 deletions(-)
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index e7dd1d9..75ba9a4 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -116,6 +116,15 @@ static char needswap = 0;
static int lastScreen = -1;
static Bool Render = TRUE;
+static int vfbScreenNum;
+static int vfbWidth;
+static int vfbHeight;
+static int vfbDepth;
+static int vfbPixdepth;
+static Pixel vfbBlackpix;
+static Pixel vfbWhitePix;
+static unsigned int vfbLinebias;
+
#define swapcopy16(_dst, _src) \
if (needswap) { CARD16 _s = _src; cpswaps(_s, _dst); } \
else _dst = _src;
@@ -265,6 +274,141 @@ ddxUseMsg(void)
#endif
}
+static int
+vfbProcessScreen(void)
+{
+ if (vfbScreenNum < 0 || vfbScreenNum >= MAXSCREENS)
+ {
+ ErrorF("Invalid screen number %d\n", vfbScreenNum);
+ UseMsg();
+ FatalError("Invalid screen number %d passed to -screen\n",
+ vfbScreenNum);
+ }
+ vfbScreens[vfbScreenNum].width = vfbWidth;
+ vfbScreens[vfbScreenNum].height = vfbHeight;
+ vfbScreens[vfbScreenNum].depth = vfbDepth;
+
+ if (vfbScreenNum >= vfbNumScreens)
+ vfbNumScreens = vfbScreenNum + 1;
+ lastScreen = vfbScreenNum;
+ return 3;
+}
+
+static int
+vfbGetScreen(char *argv[], int i)
+{
+ vfbScreenNum = atoi(argv[i+1]);
+
+ if (3 != sscanf(argv[i+2], "%dx%dx%d", &vfbWidth, &vfbHeight, &vfbDepth))
+ {
+ ErrorF("Invalid screen configuration %s\n", argv[i+2]);
+ UseMsg();
+ FatalError("Invalid screen configuration %s for -screen %d\n",
+ argv[i+2], vfbScreenNum);
+ }
+
+ return vfbProcessScreen();
+}
+
+static int
+vfbProcessPixdepths(void)
+{
+ vfbPixmapDepths[vfbPixdepth] = TRUE;
+ return 2;
+}
+
+static int
+vfbGetPixdepths(int argc, char *argv[], int i)
+{
+ while ((++i < argc) && (vfbPixdepth = atoi(argv[i])) != 0)
+ {
+ if (vfbPixdepth < 0 || vfbPixdepth > 32)
+ {
+ ErrorF("Invalid pixmap depth %d\n", vfbPixdepth);
+ UseMsg();
+ FatalError("Invalid pixmap depth %d passed to -pixdepths\n",
+ vfbPixdepth);
+ }
+ return vfbProcessPixdepths();
+ }
+ return 1;
+}
+
+static int
+vfbProcessBlackpixel(void)
+{
+ if (-1 == lastScreen)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].blackPixel = vfbBlackpix;
+ }
+ }
+ else
+ {
+ vfbScreens[lastScreen].blackPixel = vfbBlackpix;
+ }
+ return 2;
+}
+
+static int
+vfbGetBlackpixel(char *argv[], int i)
+{
+ vfbBlackpix = atoi(argv[++i]);
+ return vfbProcessBlackpixel();
+}
+
+static int
+vfbProcessWhitepixel(void)
+{
+ if (-1 == lastScreen)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].whitePixel = vfbWhitePix;
+ }
+ }
+ else
+ {
+ vfbScreens[lastScreen].whitePixel = vfbWhitePix;
+ }
+ return 2;
+}
+
+static int
+vfbGetWhitepixel(char *argv[], int i)
+{
+ vfbWhitePix = atoi(argv[++i]);
+ return vfbProcessWhitepixel();
+}
+
+static int
+vfbProcessLinebias(void)
+{
+ if (-1 == lastScreen)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].lineBias = vfbLinebias;
+ }
+ }
+ else
+ {
+ vfbScreens[lastScreen].lineBias = vfbLinebias;
+ }
+ return 2;
+}
+
+static int
+vfbGetLinebias(char *argv[], int i)
+{
+ vfbLinebias = atoi(argv[++i]);
+ return vfbProcessLinebias();
+}
+
int
ddxProcessArgument(int argc, char *argv[], int i)
{
@@ -286,51 +430,14 @@ ddxProcessArgument(int argc, char *argv[], int i)
if (strcmp (argv[i], "-screen") == 0) /* -screen n WxHxD */
{
- int screenNum;
CHECK_FOR_REQUIRED_ARGUMENTS(2);
- screenNum = atoi(argv[i+1]);
- if (screenNum < 0 || screenNum >= MAXSCREENS)
- {
- ErrorF("Invalid screen number %d\n", screenNum);
- UseMsg();
- FatalError("Invalid screen number %d passed to -screen\n",
- screenNum);
- }
- if (3 != sscanf(argv[i+2], "%dx%dx%d",
- &vfbScreens[screenNum].width,
- &vfbScreens[screenNum].height,
- &vfbScreens[screenNum].depth))
- {
- ErrorF("Invalid screen configuration %s\n", argv[i+2]);
- UseMsg();
- FatalError("Invalid screen configuration %s for -screen %d\n",
- argv[i+2], screenNum);
- }
-
- if (screenNum >= vfbNumScreens)
- vfbNumScreens = screenNum + 1;
- lastScreen = screenNum;
- return 3;
+ return vfbGetScreen(argv, i);
}
if (strcmp (argv[i], "-pixdepths") == 0) /* -pixdepths list-of-depth */
{
- int depth, ret = 1;
-
CHECK_FOR_REQUIRED_ARGUMENTS(1);
- while ((++i < argc) && (depth = atoi(argv[i])) != 0)
- {
- if (depth < 0 || depth > 32)
- {
- ErrorF("Invalid pixmap depth %d\n", depth);
- UseMsg();
- FatalError("Invalid pixmap depth %d passed to -pixdepths\n",
- depth);
- }
- vfbPixmapDepths[depth] = TRUE;
- ret++;
- }
- return ret;
+ return vfbGetPixdepths(argc, argv, i);
}
if (strcmp (argv[i], "+render") == 0) /* +render */
@@ -350,62 +457,20 @@ ddxProcessArgument(int argc, char *argv[], int i)
if (strcmp (argv[i], "-blackpixel") == 0) /* -blackpixel n */
{
- Pixel pix;
CHECK_FOR_REQUIRED_ARGUMENTS(1);
- pix = atoi(argv[++i]);
- if (-1 == lastScreen)
- {
- int i;
- for (i = 0; i < MAXSCREENS; i++)
- {
- vfbScreens[i].blackPixel = pix;
- }
- }
- else
- {
- vfbScreens[lastScreen].blackPixel = pix;
- }
- return 2;
+ return vfbGetBlackpixel(argv, i);
}
if (strcmp (argv[i], "-whitepixel") == 0) /* -whitepixel n */
{
- Pixel pix;
CHECK_FOR_REQUIRED_ARGUMENTS(1);
- pix = atoi(argv[++i]);
- if (-1 == lastScreen)
- {
- int i;
- for (i = 0; i < MAXSCREENS; i++)
- {
- vfbScreens[i].whitePixel = pix;
- }
- }
- else
- {
- vfbScreens[lastScreen].whitePixel = pix;
- }
- return 2;
+ return vfbGetWhitepixel(argv, i);
}
if (strcmp (argv[i], "-linebias") == 0) /* -linebias n */
{
- unsigned int linebias;
CHECK_FOR_REQUIRED_ARGUMENTS(1);
- linebias = atoi(argv[++i]);
- if (-1 == lastScreen)
- {
- int i;
- for (i = 0; i < MAXSCREENS; i++)
- {
- vfbScreens[i].lineBias = linebias;
- }
- }
- else
- {
- vfbScreens[lastScreen].lineBias = linebias;
- }
- return 2;
+ return vfbGetLinebias(argv, i);
}
#ifdef HAS_MMAP
--
1.6.0.4
More information about the xorg-devel
mailing list