From 6a1a59f90e8aa12ee50aaad0244a9f1ad1d85900 Mon Sep 17 00:00:00 2001
From: dscho <dscho>
Date: Mon, 22 Mar 2004 08:40:51 +0000
Subject: fix cargs.c: arguments were not correctly purged.

---
 ChangeLog        |  4 ++++
 cargs.c          | 23 +++++++++++------------
 test/Makefile.am |  2 +-
 test/cargstest.c | 29 +++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+), 13 deletions(-)
 create mode 100644 test/cargstest.c

diff --git a/ChangeLog b/ChangeLog
index 11ab03d..a4eda3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-03-22  Johannes E. Schindelin  <Johannes.Schindelin@gmx.de>
+	* fix cargs.c (hopefully for the last time):
+	  arguments were not correctly purged
+
 2004-03-15  Johannes E. Schindelin  <Johannes.Schindelin@gmx.de>
 	* fix libvncserver-config to again return a linker when
 	  called with --link
diff --git a/cargs.c b/cargs.c
index 22ce9ad..c26050e 100644
--- a/cargs.c
+++ b/cargs.c
@@ -46,7 +46,6 @@ void rfbPurgeArguments(int* argc,int* position,int count,char *argv[])
   if(amount)
     memmove(argv+(*position),argv+(*position)+count,sizeof(char*)*amount);
   (*argc)-=count;
-  (*position)--;
 }
 
 rfbBool 
@@ -127,11 +126,12 @@ rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[])
 	    }
             rfbScreen->progressiveSliceHeight = atoi(argv[++i]);
         } else {
-	    /* we just remove the processed arguments from the list */
-	    if(i != i1)
-	        rfbPurgeArguments(argc,&i1,i-i1,argv);
-        }
-	i1++;
+	    i++;
+	    i1=i;
+	    continue;
+	}
+	/* we just remove the processed arguments from the list */
+	rfbPurgeArguments(argc,&i1,i-i1+1,argv);
 	i=i1;
     }
     return TRUE;
@@ -157,12 +157,11 @@ rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[])
         } else if (strcmp(argv[i], "-height") == 0) {
                *height = atoi(argv[++i]);
         } else {
-	    /* we just remove the processed arguments from the list */
-	    if(i != i1)
-	    if(i != i1)
-	        rfbPurgeArguments(argc,&i1,i-i1,argv);
-        }
-	i1++;
+	    i++;
+	    i1=i;
+	    continue;
+	}
+	rfbPurgeArguments(argc,&i1,i-i1,argv);
 	i=i1;
     }
     return TRUE;
diff --git a/test/Makefile.am b/test/Makefile.am
index 8c04810..c250fe6 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,6 +1,6 @@
 CFLAGS=-I.. -g -Wall
 
-noinst_PROGRAMS=tight-1
+noinst_PROGRAMS=tight-1 cargstest
 
 LDADD = ../libvncserver.a ../libvncclient/libvncclient.a
 
diff --git a/test/cargstest.c b/test/cargstest.c
new file mode 100644
index 0000000..2eadce7
--- /dev/null
+++ b/test/cargstest.c
@@ -0,0 +1,29 @@
+#include <rfb/rfb.h>
+
+int main(int argc,char** argv)
+{
+	int fake_argc=6;
+	char* fake_argv[6]={
+		"dummy_program","-alwaysshared","-httpport","3002","-nothing","-dontdisconnect"
+	};
+	rfbScreenInfoPtr screen;
+	rfbBool ret=0;
+
+	screen = rfbGetScreen(&fake_argc,fake_argv,1024,768,8,3,1);
+#define CHECK(a,b) if(screen->a!=b) { fprintf(stderr,#a " is %d (should be " #b ")\n",screen->a); ret=1; }
+	CHECK(width,1024);
+	CHECK(height,768);
+	CHECK(rfbAlwaysShared,TRUE);
+	CHECK(httpPort,3002);
+	CHECK(rfbDontDisconnect,TRUE);
+	if(fake_argc!=2) {
+		fprintf(stderr,"fake_argc is %d (should be 2)\n",fake_argc);
+		ret=1;
+	}
+	if(strcmp(fake_argv[1],"-nothing")) {
+		fprintf(stderr,"fake_argv[1] is %s (should be -nothing)\n",fake_argv[1]);
+		ret=1;
+	}
+	return ret;
+}
+
-- 
cgit v1.2.3

