From 6b7cdeb9ef9ffb149d8dc38b17a55ebe503e31e7 Mon Sep 17 00:00:00 2001
From: dscho <dscho>
Date: Fri, 7 Feb 2003 11:53:43 +0000
Subject: moved files to contrib/ and examples/

---
 CHANGES                |   1 +
 example.c              | 330 -------------------------------------------------
 example.dsp            |  93 --------------
 examples/example.c     | 330 +++++++++++++++++++++++++++++++++++++++++++++++++
 examples/example.dsp   |  93 ++++++++++++++
 examples/fontsel.c     |  71 +++++++++++
 examples/pnmshow.c     |  81 ++++++++++++
 examples/pnmshow24.c   |  90 ++++++++++++++
 examples/storepasswd.c |  46 +++++++
 examples/vncev.c       | 120 ++++++++++++++++++
 fontsel.c              |  71 -----------
 pnmshow.c              |  81 ------------
 pnmshow24.c            |  90 --------------
 storepasswd.c          |  46 -------
 vncev.c                | 120 ------------------
 15 files changed, 832 insertions(+), 831 deletions(-)
 delete mode 100644 example.c
 delete mode 100644 example.dsp
 create mode 100644 examples/example.c
 create mode 100644 examples/example.dsp
 create mode 100644 examples/fontsel.c
 create mode 100644 examples/pnmshow.c
 create mode 100644 examples/pnmshow24.c
 create mode 100644 examples/storepasswd.c
 create mode 100644 examples/vncev.c
 delete mode 100644 fontsel.c
 delete mode 100644 pnmshow.c
 delete mode 100644 pnmshow24.c
 delete mode 100644 storepasswd.c
 delete mode 100644 vncev.c

diff --git a/CHANGES b/CHANGES
index d0ad1ce..7952bef 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,4 @@
+   moved appropriate files to contrib/ and examples/ respectively
    fixed long standing cargs bug
    Even better x11vnc from Karl J. Runge! (supports different kbd layouts of
 	client/server)
diff --git a/example.c b/example.c
deleted file mode 100644
index 62295c3..0000000
--- a/example.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * 
- * This is an example of how to use libvncserver.
- * 
- * libvncserver example
- * Copyright (C) 2001 Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
- * 
- *  This is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This software is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this software; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
- *  USA.
- */
-
-#ifdef WIN32
-#define sleep Sleep
-#else
-#include <unistd.h>
-#endif
-
-#ifdef __IRIX__
-#include <netdb.h>
-#endif
-
-#include "rfb.h"
-#include "keysym.h"
-
-const int bpp=4;
-int maxx=800, maxy=600;
-/* TODO: odd maxx doesn't work (vncviewer bug) */
-
-/* This initializes a nice (?) background */
-
-void initBuffer(unsigned char* buffer)
-{
-  int i,j;
-  for(j=0;j<maxy;++j) {
-    for(i=0;i<maxx;++i) {
-      buffer[(j*maxx+i)*bpp+0]=(i+j)*128/(maxx+maxy); /* red */
-      buffer[(j*maxx+i)*bpp+1]=i*128/maxx; /* green */
-      buffer[(j*maxx+i)*bpp+2]=j*256/maxy; /* blue */
-    }
-    buffer[j*maxx*bpp+0]=0xff;
-    buffer[j*maxx*bpp+1]=0xff;
-    buffer[j*maxx*bpp+2]=0xff;
-    buffer[j*maxx*bpp+3]=0xff;
-  }
-}
-
-/* Here we create a structure so that every client has it's own pointer */
-
-typedef struct ClientData {
-  Bool oldButton;
-  int oldx,oldy;
-} ClientData;
-
-void clientgone(rfbClientPtr cl)
-{
-  free(cl->clientData);
-}
-
-enum rfbNewClientAction newclient(rfbClientPtr cl)
-{
-  cl->clientData = (void*)calloc(sizeof(ClientData),1);
-  cl->clientGoneHook = clientgone;
-  return RFB_CLIENT_ACCEPT;
-}
-
-/* switch to new framebuffer contents */
-
-void newframebuffer(rfbScreenInfoPtr screen, int width, int height)
-{
-  unsigned char *oldfb, *newfb;
-
-  maxx = width;
-  maxy = height;
-  oldfb = (unsigned char*)screen->frameBuffer;
-  newfb = (unsigned char*)malloc(maxx * maxy * bpp);
-  initBuffer(newfb);
-  rfbNewFramebuffer(screen, (char*)newfb, maxx, maxy, 8, 3, bpp);
-  free(oldfb);
-
-  /*** FIXME: Re-install cursor. ***/
-}
-
-/* aux function to draw a line */
-
-void drawline(unsigned char* buffer,int rowstride,int bpp,int x1,int y1,int x2,int y2)
-{
-  int i,j;
-  i=x1-x2; j=y1-y2;
-  if(i==0 && j==0) {
-     for(i=0;i<bpp;i++)
-       buffer[y1*rowstride+x1*bpp+i]=0xff;
-     return;
-  }
-  if(i<0) i=-i;
-  if(j<0) j=-j;
-  if(i<j) {
-    if(y1>y2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
-    if(y2==y1) { if(y2>0) y1--; else y2++; }
-    for(j=y1;j<=y2;j++)
-      for(i=0;i<bpp;i++)
-	buffer[j*rowstride+(x1+(j-y1)*(x2-x1)/(y2-y1))*bpp+i]=0xff;
-  } else {
-    if(x1>x2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
-    for(i=x1;i<=x2;i++)
-      for(j=0;j<bpp;j++)
-	buffer[(y1+(i-x1)*(y2-y1)/(x2-x1))*rowstride+i*bpp+j]=0xff;
-  }
-}
-    
-/* Here the pointer events are handled */
-
-void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
-{
-   ClientData* cd=cl->clientData;
-
-   if(cl->screen->cursorIsDrawn)
-     rfbUndrawCursor(cl->screen);
-
-   if(x>=0 && y>=0 && x<maxx && y<maxy) {
-      if(buttonMask) {
-	 int i,j,x1,x2,y1,y2;
-
-	 if(cd->oldButton==buttonMask) { /* draw a line */
-	    drawline((unsigned char*)cl->screen->frameBuffer,cl->screen->paddedWidthInBytes,bpp,
-		     x,y,cd->oldx,cd->oldy);
-	    rfbMarkRectAsModified(cl->screen,x,y,cd->oldx,cd->oldy);
-	 } else { /* draw a point (diameter depends on button) */
-	    int w=cl->screen->paddedWidthInBytes;
-	    x1=x-buttonMask; if(x1<0) x1=0;
-	    x2=x+buttonMask; if(x2>maxx) x2=maxx;
-	    y1=y-buttonMask; if(y1<0) y1=0;
-	    y2=y+buttonMask; if(y2>maxy) y2=maxy;
-
-	    for(i=x1*bpp;i<x2*bpp;i++)
-	      for(j=y1;j<y2;j++)
-		cl->screen->frameBuffer[j*w+i]=(char)0xff;
-	    rfbMarkRectAsModified(cl->screen,x1,y1,x2-1,y2-1);
-	 }
-
-	 /* we could get a selection like that:
-	  rfbGotXCutText(cl->screen,"Hallo",5);
-	  */
-      } else
-	cd->oldButton=0;
-
-      cd->oldx=x; cd->oldy=y; cd->oldButton=buttonMask;
-   }
-   defaultPtrAddEvent(buttonMask,x,y,cl);
-}
-
-/* aux function to draw a character to x, y */
-
-#include "radon.h"
-
-/* Here the key events are handled */
-
-void dokey(Bool down,KeySym key,rfbClientPtr cl)
-{
-  if(down) {
-    if(key==XK_Escape)
-      rfbCloseClient(cl);
-    else if(key==XK_Page_Up) {
-      if(cl->screen->cursorIsDrawn)
-	rfbUndrawCursor(cl->screen);
-      initBuffer((unsigned char*)cl->screen->frameBuffer);
-      rfbMarkRectAsModified(cl->screen,0,0,maxx,maxy);
-    } else if (key == XK_Up) {
-      if (maxx < 1024) {
-        if (maxx < 800) {
-          newframebuffer(cl->screen, 800, 600);
-        } else {
-          newframebuffer(cl->screen, 1024, 768);
-        }
-      }
-    } else if(key==XK_Down) {
-      if (maxx > 640) {
-        if (maxx > 800) {
-          newframebuffer(cl->screen, 800, 600);
-        } else {
-          newframebuffer(cl->screen, 640, 480);
-        }
-      }
-    } else if(key>=' ' && key<0x100) {
-      ClientData* cd=cl->clientData;
-      int x1=cd->oldx,y1=cd->oldy,x2,y2;
-      if(cl->screen->cursorIsDrawn)
-	rfbUndrawCursor(cl->screen);
-      cd->oldx+=rfbDrawChar(cl->screen,&radonFont,cd->oldx,cd->oldy,(char)key,0x00ffffff);
-      rfbFontBBox(&radonFont,(char)key,&x1,&y1,&x2,&y2);
-      rfbMarkRectAsModified(cl->screen,x1,y1,x2-1,y2-1);
-    }
-  }
-}
-
-/* Example for an XCursor (foreground/background only) */
-
-int exampleXCursorWidth=9,exampleXCursorHeight=7;
-char exampleXCursor[]=
-  "         "
-  " xx   xx "
-  "  xx xx  "
-  "   xxx   "
-  "  xx xx  "
-  " xx   xx "
-  "         ";
-
-/* Example for a rich cursor (full-colour) */
-
-void MakeRichCursor(rfbScreenInfoPtr rfbScreen)
-{
-  int i,j,w=32,h=32;
-  rfbCursorPtr c = rfbScreen->cursor;
-  char bitmap[]=
-    "                                "
-    "              xxxxxx            "
-    "       xxxxxxxxxxxxxxxxx        "
-    "      xxxxxxxxxxxxxxxxxxxxxx    "
-    "    xxxxx  xxxxxxxx  xxxxxxxx   "
-    "   xxxxxxxxxxxxxxxxxxxxxxxxxxx  "
-    "  xxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
-    "  xxxxx   xxxxxxxxxxx   xxxxxxx "
-    "  xxxx     xxxxxxxxx     xxxxxx "
-    "  xxxxx   xxxxxxxxxxx   xxxxxxx "
-    " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
-    " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
-    " xxxxxxxxxxxx  xxxxxxxxxxxxxxx  "
-    " xxxxxxxxxxxxxxxxxxxxxxxxxxxx   "
-    " xxxxxxxxxxxxxxxxxxxxxxxxxxxx   "
-    " xxxxxxxxxxx   xxxxxxxxxxxxxx   "
-    " xxxxxxxxxx     xxxxxxxxxxxx    "
-    "  xxxxxxxxx      xxxxxxxxx      "
-    "   xxxxxxxxxx   xxxxxxxxx       "
-    "      xxxxxxxxxxxxxxxxxxx       "
-    "       xxxxxxxxxxxxxxxxxxx      "
-    "         xxxxxxxxxxxxxxxxxxx    "
-    "             xxxxxxxxxxxxxxxxx  "
-    "                xxxxxxxxxxxxxxx "
-    "   xxxx           xxxxxxxxxxxxx "
-    "  xx   x            xxxxxxxxxxx "
-    "  xxx               xxxxxxxxxxx "
-    "  xxxx             xxxxxxxxxxx  "
-    "   xxxxxx       xxxxxxxxxxxx    "
-    "    xxxxxxxxxxxxxxxxxxxxxx      "
-    "      xxxxxxxxxxxxxxxx          "
-    "                                ";
-  c=rfbScreen->cursor = rfbMakeXCursor(w,h,bitmap,bitmap);
-  c->xhot = 16; c->yhot = 24;
-
-  c->richSource = malloc(w*h*bpp);
-  for(j=0;j<h;j++) {
-    for(i=0;i<w;i++) {
-      c->richSource[j*w*bpp+i*bpp+0]=i*0xff/w;
-      c->richSource[j*w*bpp+i*bpp+1]=(i+j)*0xff/(w+h);
-      c->richSource[j*w*bpp+i*bpp+2]=j*0xff/h;
-      c->richSource[j*w*bpp+i*bpp+3]=0;
-    }
-  }
-}
-
-/* Initialization */
-
-int main(int argc,char** argv)
-{
-  rfbScreenInfoPtr rfbScreen =
-    rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
-  rfbScreen->desktopName = "LibVNCServer Example";
-  rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
-  rfbScreen->rfbAlwaysShared = TRUE;
-  rfbScreen->ptrAddEvent = doptr;
-  rfbScreen->kbdAddEvent = dokey;
-  rfbScreen->newClientHook = newclient;
-  rfbScreen->httpDir = "./classes";
-  rfbScreen->httpEnableProxyConnect = TRUE;
-
-  initBuffer((unsigned char*)rfbScreen->frameBuffer);
-  rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff);
-
-  /* This call creates a mask and then a cursor: */
-  /* rfbScreen->defaultCursor =
-       rfbMakeXCursor(exampleCursorWidth,exampleCursorHeight,exampleCursor,0);
-  */
-
-  MakeRichCursor(rfbScreen);
-
-  /* initialize the server */
-  rfbInitServer(rfbScreen);
-
-#define USE_OWN_LOOP
-#ifdef USE_OWN_LOOP
-  {
-    int i;
-    for(i=0;;i++) {
-      fprintf(stderr,"%d\r",i);
-      rfbProcessEvents(rfbScreen,100000);
-    }
-  }
-#else
-
-#ifndef BACKGROUND_LOOP_TEST
-  /* this is the blocking event loop, i.e. it never returns */
-  /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */
-  rfbRunEventLoop(rfbScreen,40000,FALSE);
-#elif !defined(HAVE_PTHREADS)
-#error "I need pthreads for that."
-#endif
-
-  /* this is the non-blocking event loop; a background thread is started */
-  rfbRunEventLoop(rfbScreen,-1,TRUE);
-  /* now we could do some cool things like rendering in idle time */
-  while(1) sleep(5); /* render(); */
-#endif
-
-  rfbFreeCursor(rfbScreen->cursor);
-  free(rfbScreen->frameBuffer);
-  rfbScreenCleanup(rfbScreen);
-
-  return(0);
-}
diff --git a/example.dsp b/example.dsp
deleted file mode 100644
index 16788cb..0000000
--- a/example.dsp
+++ /dev/null
@@ -1,93 +0,0 @@
-# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** NICHT BEARBEITEN **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=example - Win32 Debug
-!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
-!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
-!MESSAGE 
-!MESSAGE NMAKE /f "example.mak".
-!MESSAGE 
-!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
-!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
-!MESSAGE 
-!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Debug"
-!MESSAGE 
-!MESSAGE Für die Konfiguration stehen zur Auswahl:
-!MESSAGE 
-!MESSAGE "example - Win32 Release" (basierend auf  "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 Debug" (basierend auf  "Win32 (x86) Console Application")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "example - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "zlib" /I "libjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib zlib.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"msvcrt.lib"
-
-!ELSEIF  "$(CFG)" == "example - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "zlib" /I "libjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib zlib.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept
-
-!ENDIF 
-
-# Begin Target
-
-# Name "example - Win32 Release"
-# Name "example - Win32 Debug"
-# Begin Group "Sources"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\example.c
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/examples/example.c b/examples/example.c
new file mode 100644
index 0000000..62295c3
--- /dev/null
+++ b/examples/example.c
@@ -0,0 +1,330 @@
+/*
+ * 
+ * This is an example of how to use libvncserver.
+ * 
+ * libvncserver example
+ * Copyright (C) 2001 Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
+ * 
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#ifdef WIN32
+#define sleep Sleep
+#else
+#include <unistd.h>
+#endif
+
+#ifdef __IRIX__
+#include <netdb.h>
+#endif
+
+#include "rfb.h"
+#include "keysym.h"
+
+const int bpp=4;
+int maxx=800, maxy=600;
+/* TODO: odd maxx doesn't work (vncviewer bug) */
+
+/* This initializes a nice (?) background */
+
+void initBuffer(unsigned char* buffer)
+{
+  int i,j;
+  for(j=0;j<maxy;++j) {
+    for(i=0;i<maxx;++i) {
+      buffer[(j*maxx+i)*bpp+0]=(i+j)*128/(maxx+maxy); /* red */
+      buffer[(j*maxx+i)*bpp+1]=i*128/maxx; /* green */
+      buffer[(j*maxx+i)*bpp+2]=j*256/maxy; /* blue */
+    }
+    buffer[j*maxx*bpp+0]=0xff;
+    buffer[j*maxx*bpp+1]=0xff;
+    buffer[j*maxx*bpp+2]=0xff;
+    buffer[j*maxx*bpp+3]=0xff;
+  }
+}
+
+/* Here we create a structure so that every client has it's own pointer */
+
+typedef struct ClientData {
+  Bool oldButton;
+  int oldx,oldy;
+} ClientData;
+
+void clientgone(rfbClientPtr cl)
+{
+  free(cl->clientData);
+}
+
+enum rfbNewClientAction newclient(rfbClientPtr cl)
+{
+  cl->clientData = (void*)calloc(sizeof(ClientData),1);
+  cl->clientGoneHook = clientgone;
+  return RFB_CLIENT_ACCEPT;
+}
+
+/* switch to new framebuffer contents */
+
+void newframebuffer(rfbScreenInfoPtr screen, int width, int height)
+{
+  unsigned char *oldfb, *newfb;
+
+  maxx = width;
+  maxy = height;
+  oldfb = (unsigned char*)screen->frameBuffer;
+  newfb = (unsigned char*)malloc(maxx * maxy * bpp);
+  initBuffer(newfb);
+  rfbNewFramebuffer(screen, (char*)newfb, maxx, maxy, 8, 3, bpp);
+  free(oldfb);
+
+  /*** FIXME: Re-install cursor. ***/
+}
+
+/* aux function to draw a line */
+
+void drawline(unsigned char* buffer,int rowstride,int bpp,int x1,int y1,int x2,int y2)
+{
+  int i,j;
+  i=x1-x2; j=y1-y2;
+  if(i==0 && j==0) {
+     for(i=0;i<bpp;i++)
+       buffer[y1*rowstride+x1*bpp+i]=0xff;
+     return;
+  }
+  if(i<0) i=-i;
+  if(j<0) j=-j;
+  if(i<j) {
+    if(y1>y2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
+    if(y2==y1) { if(y2>0) y1--; else y2++; }
+    for(j=y1;j<=y2;j++)
+      for(i=0;i<bpp;i++)
+	buffer[j*rowstride+(x1+(j-y1)*(x2-x1)/(y2-y1))*bpp+i]=0xff;
+  } else {
+    if(x1>x2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
+    for(i=x1;i<=x2;i++)
+      for(j=0;j<bpp;j++)
+	buffer[(y1+(i-x1)*(y2-y1)/(x2-x1))*rowstride+i*bpp+j]=0xff;
+  }
+}
+    
+/* Here the pointer events are handled */
+
+void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
+{
+   ClientData* cd=cl->clientData;
+
+   if(cl->screen->cursorIsDrawn)
+     rfbUndrawCursor(cl->screen);
+
+   if(x>=0 && y>=0 && x<maxx && y<maxy) {
+      if(buttonMask) {
+	 int i,j,x1,x2,y1,y2;
+
+	 if(cd->oldButton==buttonMask) { /* draw a line */
+	    drawline((unsigned char*)cl->screen->frameBuffer,cl->screen->paddedWidthInBytes,bpp,
+		     x,y,cd->oldx,cd->oldy);
+	    rfbMarkRectAsModified(cl->screen,x,y,cd->oldx,cd->oldy);
+	 } else { /* draw a point (diameter depends on button) */
+	    int w=cl->screen->paddedWidthInBytes;
+	    x1=x-buttonMask; if(x1<0) x1=0;
+	    x2=x+buttonMask; if(x2>maxx) x2=maxx;
+	    y1=y-buttonMask; if(y1<0) y1=0;
+	    y2=y+buttonMask; if(y2>maxy) y2=maxy;
+
+	    for(i=x1*bpp;i<x2*bpp;i++)
+	      for(j=y1;j<y2;j++)
+		cl->screen->frameBuffer[j*w+i]=(char)0xff;
+	    rfbMarkRectAsModified(cl->screen,x1,y1,x2-1,y2-1);
+	 }
+
+	 /* we could get a selection like that:
+	  rfbGotXCutText(cl->screen,"Hallo",5);
+	  */
+      } else
+	cd->oldButton=0;
+
+      cd->oldx=x; cd->oldy=y; cd->oldButton=buttonMask;
+   }
+   defaultPtrAddEvent(buttonMask,x,y,cl);
+}
+
+/* aux function to draw a character to x, y */
+
+#include "radon.h"
+
+/* Here the key events are handled */
+
+void dokey(Bool down,KeySym key,rfbClientPtr cl)
+{
+  if(down) {
+    if(key==XK_Escape)
+      rfbCloseClient(cl);
+    else if(key==XK_Page_Up) {
+      if(cl->screen->cursorIsDrawn)
+	rfbUndrawCursor(cl->screen);
+      initBuffer((unsigned char*)cl->screen->frameBuffer);
+      rfbMarkRectAsModified(cl->screen,0,0,maxx,maxy);
+    } else if (key == XK_Up) {
+      if (maxx < 1024) {
+        if (maxx < 800) {
+          newframebuffer(cl->screen, 800, 600);
+        } else {
+          newframebuffer(cl->screen, 1024, 768);
+        }
+      }
+    } else if(key==XK_Down) {
+      if (maxx > 640) {
+        if (maxx > 800) {
+          newframebuffer(cl->screen, 800, 600);
+        } else {
+          newframebuffer(cl->screen, 640, 480);
+        }
+      }
+    } else if(key>=' ' && key<0x100) {
+      ClientData* cd=cl->clientData;
+      int x1=cd->oldx,y1=cd->oldy,x2,y2;
+      if(cl->screen->cursorIsDrawn)
+	rfbUndrawCursor(cl->screen);
+      cd->oldx+=rfbDrawChar(cl->screen,&radonFont,cd->oldx,cd->oldy,(char)key,0x00ffffff);
+      rfbFontBBox(&radonFont,(char)key,&x1,&y1,&x2,&y2);
+      rfbMarkRectAsModified(cl->screen,x1,y1,x2-1,y2-1);
+    }
+  }
+}
+
+/* Example for an XCursor (foreground/background only) */
+
+int exampleXCursorWidth=9,exampleXCursorHeight=7;
+char exampleXCursor[]=
+  "         "
+  " xx   xx "
+  "  xx xx  "
+  "   xxx   "
+  "  xx xx  "
+  " xx   xx "
+  "         ";
+
+/* Example for a rich cursor (full-colour) */
+
+void MakeRichCursor(rfbScreenInfoPtr rfbScreen)
+{
+  int i,j,w=32,h=32;
+  rfbCursorPtr c = rfbScreen->cursor;
+  char bitmap[]=
+    "                                "
+    "              xxxxxx            "
+    "       xxxxxxxxxxxxxxxxx        "
+    "      xxxxxxxxxxxxxxxxxxxxxx    "
+    "    xxxxx  xxxxxxxx  xxxxxxxx   "
+    "   xxxxxxxxxxxxxxxxxxxxxxxxxxx  "
+    "  xxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
+    "  xxxxx   xxxxxxxxxxx   xxxxxxx "
+    "  xxxx     xxxxxxxxx     xxxxxx "
+    "  xxxxx   xxxxxxxxxxx   xxxxxxx "
+    " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
+    " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
+    " xxxxxxxxxxxx  xxxxxxxxxxxxxxx  "
+    " xxxxxxxxxxxxxxxxxxxxxxxxxxxx   "
+    " xxxxxxxxxxxxxxxxxxxxxxxxxxxx   "
+    " xxxxxxxxxxx   xxxxxxxxxxxxxx   "
+    " xxxxxxxxxx     xxxxxxxxxxxx    "
+    "  xxxxxxxxx      xxxxxxxxx      "
+    "   xxxxxxxxxx   xxxxxxxxx       "
+    "      xxxxxxxxxxxxxxxxxxx       "
+    "       xxxxxxxxxxxxxxxxxxx      "
+    "         xxxxxxxxxxxxxxxxxxx    "
+    "             xxxxxxxxxxxxxxxxx  "
+    "                xxxxxxxxxxxxxxx "
+    "   xxxx           xxxxxxxxxxxxx "
+    "  xx   x            xxxxxxxxxxx "
+    "  xxx               xxxxxxxxxxx "
+    "  xxxx             xxxxxxxxxxx  "
+    "   xxxxxx       xxxxxxxxxxxx    "
+    "    xxxxxxxxxxxxxxxxxxxxxx      "
+    "      xxxxxxxxxxxxxxxx          "
+    "                                ";
+  c=rfbScreen->cursor = rfbMakeXCursor(w,h,bitmap,bitmap);
+  c->xhot = 16; c->yhot = 24;
+
+  c->richSource = malloc(w*h*bpp);
+  for(j=0;j<h;j++) {
+    for(i=0;i<w;i++) {
+      c->richSource[j*w*bpp+i*bpp+0]=i*0xff/w;
+      c->richSource[j*w*bpp+i*bpp+1]=(i+j)*0xff/(w+h);
+      c->richSource[j*w*bpp+i*bpp+2]=j*0xff/h;
+      c->richSource[j*w*bpp+i*bpp+3]=0;
+    }
+  }
+}
+
+/* Initialization */
+
+int main(int argc,char** argv)
+{
+  rfbScreenInfoPtr rfbScreen =
+    rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
+  rfbScreen->desktopName = "LibVNCServer Example";
+  rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
+  rfbScreen->rfbAlwaysShared = TRUE;
+  rfbScreen->ptrAddEvent = doptr;
+  rfbScreen->kbdAddEvent = dokey;
+  rfbScreen->newClientHook = newclient;
+  rfbScreen->httpDir = "./classes";
+  rfbScreen->httpEnableProxyConnect = TRUE;
+
+  initBuffer((unsigned char*)rfbScreen->frameBuffer);
+  rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff);
+
+  /* This call creates a mask and then a cursor: */
+  /* rfbScreen->defaultCursor =
+       rfbMakeXCursor(exampleCursorWidth,exampleCursorHeight,exampleCursor,0);
+  */
+
+  MakeRichCursor(rfbScreen);
+
+  /* initialize the server */
+  rfbInitServer(rfbScreen);
+
+#define USE_OWN_LOOP
+#ifdef USE_OWN_LOOP
+  {
+    int i;
+    for(i=0;;i++) {
+      fprintf(stderr,"%d\r",i);
+      rfbProcessEvents(rfbScreen,100000);
+    }
+  }
+#else
+
+#ifndef BACKGROUND_LOOP_TEST
+  /* this is the blocking event loop, i.e. it never returns */
+  /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */
+  rfbRunEventLoop(rfbScreen,40000,FALSE);
+#elif !defined(HAVE_PTHREADS)
+#error "I need pthreads for that."
+#endif
+
+  /* this is the non-blocking event loop; a background thread is started */
+  rfbRunEventLoop(rfbScreen,-1,TRUE);
+  /* now we could do some cool things like rendering in idle time */
+  while(1) sleep(5); /* render(); */
+#endif
+
+  rfbFreeCursor(rfbScreen->cursor);
+  free(rfbScreen->frameBuffer);
+  rfbScreenCleanup(rfbScreen);
+
+  return(0);
+}
diff --git a/examples/example.dsp b/examples/example.dsp
new file mode 100644
index 0000000..16788cb
--- /dev/null
+++ b/examples/example.dsp
@@ -0,0 +1,93 @@
+# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=example - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE 
+!MESSAGE NMAKE /f "example.mak".
+!MESSAGE 
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE 
+!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Debug"
+!MESSAGE 
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE 
+!MESSAGE "example - Win32 Release" (basierend auf  "Win32 (x86) Console Application")
+!MESSAGE "example - Win32 Debug" (basierend auf  "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "example - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "zlib" /I "libjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib zlib.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"msvcrt.lib"
+
+!ELSEIF  "$(CFG)" == "example - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "zlib" /I "libjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib zlib.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "example - Win32 Release"
+# Name "example - Win32 Debug"
+# Begin Group "Sources"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\example.c
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/examples/fontsel.c b/examples/fontsel.c
new file mode 100644
index 0000000..100db81
--- /dev/null
+++ b/examples/fontsel.c
@@ -0,0 +1,71 @@
+#include "rfb.h"
+
+#define FONTDIR "/usr/lib/kbd/consolefonts/"
+#define DEFAULTFONT FONTDIR "default8x16"
+
+char *fontlist[50]={
+"8x16alt", "b.fnt", "c.fnt", "default8x16", "m.fnt", "ml.fnt", "mod_d.fnt",
+"mod_s.fnt", "mr.fnt", "mu.fnt", "r.fnt", "rl.fnt", "ro.fnt", "s.fnt",
+"sc.fnt", "scrawl_s.fnt", "scrawl_w.fnt", "sd.fnt", "t.fnt",
+  0
+};
+
+rfbScreenInfoPtr rfbScreen = 0;
+rfbFontDataPtr curFont = 0;
+void showFont(int index)
+{
+  char buffer[1024];
+
+  if(!rfbScreen) return;
+
+  if(curFont)
+    rfbFreeFont(curFont);
+
+  strcpy(buffer,FONTDIR);
+  strcat(buffer,fontlist[index]);
+  curFont = rfbLoadConsoleFont(buffer);
+
+  rfbFillRect(rfbScreen,210,30-20,210+10*16,30-20+256*20/16,0xb77797);
+  if(curFont) {
+    int i,j;
+    for(j=0;j<256;j+=16)
+      for(i=0;i<16;i++)
+	rfbDrawCharWithClip(rfbScreen,curFont,210+10*i,30+j*20/16,j+i,
+			    0,0,640,480,0xffffff,0x000000);
+  }
+}
+
+int main(int argc,char** argv)
+{
+  rfbFontDataPtr font;
+  rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3);
+  int i,j;
+
+  s->frameBuffer=(char*)malloc(640*480*3);
+  rfbInitServer(s);
+
+  for(j=0;j<480;j++)
+    for(i=0;i<640;i++) {
+      s->frameBuffer[(j*640+i)*3+0]=j*256/480;
+      s->frameBuffer[(j*640+i)*3+1]=i*256/640;
+      s->frameBuffer[(j*640+i)*3+2]=(i+j)*256/(480+640);
+    }
+
+  rfbScreen = s;
+  font=rfbLoadConsoleFont(DEFAULTFONT);
+  if(!font) {
+    fprintf(stderr,"Couldn't find %s\n",DEFAULTFONT);
+    exit(1);
+  }
+  
+  for(j=0;j<0;j++)
+    rfbProcessEvents(s,900000);
+
+  i = rfbSelectBox(s,font,fontlist,10,20,200,300,0xffdfdf,0x602040,2,showFont);
+  fprintf(stderr,"Selection: %d: %s\n",i,(i>=0)?fontlist[i]:"cancelled");
+
+  rfbFreeFont(font);
+
+  return(0);
+}
+
diff --git a/examples/pnmshow.c b/examples/pnmshow.c
new file mode 100644
index 0000000..0a5f47b
--- /dev/null
+++ b/examples/pnmshow.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include "rfb.h"
+#include "keysym.h"
+
+void HandleKey(Bool down,KeySym key,rfbClientPtr cl)
+{
+  if(down && (key==XK_Escape || key=='q' || key=='Q'))
+    rfbCloseClient(cl);
+}
+
+int main(int argc,char** argv)
+{
+  FILE* in=stdin;
+  int i,j,k,width,height,paddedWidth;
+  char buffer[1024];
+  rfbScreenInfoPtr rfbScreen;
+
+  if(argc>1) {
+    in=fopen(argv[1],"rb");
+    if(!in) {
+      printf("Couldn't find file %s.\n",argv[1]);
+      exit(1);
+    }
+  }
+
+  fgets(buffer,1024,in);
+  if(strncmp(buffer,"P6",2)) {
+    printf("Not a ppm.\n");
+    exit(2);
+  }
+
+  /* skip comments */
+  do {
+    fgets(buffer,1024,in);
+  } while(buffer[0]=='#');
+
+  /* get width & height */
+  sscanf(buffer,"%d %d",&width,&height);
+  fprintf(stderr,"Got width %d and height %d.\n",width,height);
+  fgets(buffer,1024,in);
+
+  /* vncviewers have problems with widths which are no multiple of 4. */
+  paddedWidth = width;
+  if(width&3)
+    paddedWidth+=4-(width&3);
+
+  /* initialize data for vnc server */
+  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,4);
+  if(argc>1)
+    rfbScreen->desktopName = argv[1];
+  else
+    rfbScreen->desktopName = "Picture";
+  rfbScreen->rfbAlwaysShared = TRUE;
+  rfbScreen->kbdAddEvent = HandleKey;
+
+  /* enable http */
+  rfbScreen->httpDir = "./classes";
+
+  /* allocate picture and read it */
+  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*4*height);
+  fread(rfbScreen->frameBuffer,width*3,height,in);
+  fclose(in);
+
+  /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
+  for(j=height-1;j>=0;j--) {
+    for(i=width-1;i>=0;i--)
+      for(k=2;k>=0;k--)
+	rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]=
+	  rfbScreen->frameBuffer[(j*width+i)*3+k];
+    for(i=width*4;i<paddedWidth*4;i++)
+      rfbScreen->frameBuffer[j*paddedWidth*4+i]=0;
+  }
+
+  /* initialize server */
+  rfbInitServer(rfbScreen);
+
+  /* run event loop */
+  rfbRunEventLoop(rfbScreen,40000,FALSE);
+
+  return(0);
+}
diff --git a/examples/pnmshow24.c b/examples/pnmshow24.c
new file mode 100644
index 0000000..e096c7f
--- /dev/null
+++ b/examples/pnmshow24.c
@@ -0,0 +1,90 @@
+#ifndef ALLOW24BPP
+#error "I need the ALLOW24BPP flag to work"
+#endif
+
+#include <stdio.h>
+#include "rfb.h"
+#include "keysym.h"
+
+void HandleKey(Bool down,KeySym key,rfbClientPtr cl)
+{
+  if(down && (key==XK_Escape || key=='q' || key=='Q'))
+    rfbCloseClient(cl);
+}
+
+int main(int argc,char** argv)
+{
+  FILE* in=stdin;
+  int j,width,height,paddedWidth;
+  char buffer[1024];
+  rfbScreenInfoPtr rfbScreen;
+
+  if(argc>1) {
+    in=fopen(argv[1],"rb");
+    if(!in) {
+      printf("Couldn't find file %s.\n",argv[1]);
+      exit(1);
+    }
+  }
+
+  fgets(buffer,1024,in);
+  if(strncmp(buffer,"P6",2)) {
+    printf("Not a ppm.\n");
+    exit(2);
+  }
+
+  /* skip comments */
+  do {
+    fgets(buffer,1024,in);
+  } while(buffer[0]=='#');
+
+  /* get width & height */
+  sscanf(buffer,"%d %d",&width,&height);
+  fprintf(stderr,"Got width %d and height %d.\n",width,height);
+  fgets(buffer,1024,in);
+
+  /* vncviewers have problems with widths which are no multiple of 4. */
+  paddedWidth = width;
+
+  /* if your vncviewer doesn't have problems with a width
+     which is not a multiple of 4, you can comment this. */
+  if(width&3)
+    paddedWidth+=4-(width&3);
+
+  /* initialize data for vnc server */
+  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
+  if(argc>1)
+    rfbScreen->desktopName = argv[1];
+  else
+    rfbScreen->desktopName = "Picture";
+  rfbScreen->rfbAlwaysShared = TRUE;
+  rfbScreen->kbdAddEvent = HandleKey;
+
+  /* enable http */
+  rfbScreen->httpDir = "./classes";
+
+  /* allocate picture and read it */
+  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
+  fread(rfbScreen->frameBuffer,width*3,height,in);
+  fclose(in);
+
+  /* pad to paddedWidth */
+  if(width != paddedWidth) {
+    int padCount = 3*(paddedWidth - width);
+    for(j=height-1;j>=0;j--) {
+      memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
+	      rfbScreen->frameBuffer+3*width*j,
+	      3*width);
+      memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
+	     0,padCount);
+    }
+  }
+
+  /* initialize server */
+  rfbInitServer(rfbScreen);
+
+  /* run event loop */
+  rfbRunEventLoop(rfbScreen,40000,FALSE);
+
+  return(0);
+}
diff --git a/examples/storepasswd.c b/examples/storepasswd.c
new file mode 100644
index 0000000..1470e4d
--- /dev/null
+++ b/examples/storepasswd.c
@@ -0,0 +1,46 @@
+/*
+ *  OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
+ *  Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.  
+ *  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include "rfb.h"
+
+void usage(void)
+{
+    printf("\nusage:  storepasswd <password> <filename>\n\n");
+
+    printf("Stores a password in encrypted format.\n");
+    printf("The resulting file can be used with the -rfbauth argument to OSXvnc.\n\n");
+    exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+    if (argc != 3) 
+        usage();
+
+    if (vncEncryptAndStorePasswd(argv[1], argv[2]) != 0) {
+        printf("storing password failed.\n");
+        return 1;
+    } else {
+        printf("storing password succeeded.\n");
+        return 0;
+    }
+}
diff --git a/examples/vncev.c b/examples/vncev.c
new file mode 100644
index 0000000..8116815
--- /dev/null
+++ b/examples/vncev.c
@@ -0,0 +1,120 @@
+/* This program is a simple server to show events coming from the client */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include "rfb.h"
+#include "default8x16.h"
+
+char f[640*480];
+char* keys[0x400];
+
+int hex2number(unsigned char c)
+{
+   if(c>'f') return(-1);
+   else if(c>'F')
+     return(10+c-'a');
+   else if(c>'9')
+     return(10+c-'A');
+   else
+     return(c-'0');
+}
+
+void read_keys()
+{
+   int i,j,k;
+   char buffer[1024];
+   FILE* keysyms=fopen("keysym.h","r");
+
+   memset(keys,0,0x400*sizeof(char*));
+   
+   if(!keysyms)
+     return;
+   
+   while(!feof(keysyms)) {
+      fgets(buffer,1024,keysyms);
+      if(!strncmp(buffer,"#define XK_",strlen("#define XK_"))) {
+	 for(i=strlen("#define XK_");buffer[i] && buffer[i]!=' '
+	     && buffer[i]!='\t';i++);
+	 if(buffer[i]==0) /* don't support wrapped lines */
+	   continue;
+	 buffer[i]=0;
+	 for(i++;buffer[i] && buffer[i]!='0';i++);
+	 if(buffer[i]==0 || buffer[i+1]!='x') continue;
+	 for(j=0,i+=2;(k=hex2number(buffer[i]))>=0;i++)
+	   j=j*16+k;
+	 if(keys[j&0x3ff]) {
+	    char* x=malloc(1+strlen(keys[j&0x3ff])+1+strlen(buffer+strlen("#define ")));
+	    strcpy(x,keys[j&0x3ff]);
+	    strcat(x,",");
+	    strcat(x,buffer+strlen("#define "));
+	    free(keys[j&0x3ff]);
+	    keys[j&0x3ff]=x;
+	 } else
+	   keys[j&0x3ff] = strdup(buffer+strlen("#define "));
+      }
+      
+   }
+   fclose(keysyms);
+}
+
+int lineHeight=16,lineY=480-16;
+void output(rfbScreenInfoPtr s,char* line)
+{
+   rfbDoCopyRect(s,0,0,640,480-lineHeight,0,-lineHeight);
+   rfbDrawString(s,&default8x16Font,10,lineY,line,0x01);
+   fprintf(stderr,"%s\n",line);
+}
+
+void dokey(Bool down,KeySym k,rfbClientPtr cl)
+{
+   char buffer[1024+32];
+   
+   sprintf(buffer,"%s: %s (0x%x)",
+	   down?"down":"up",keys[k&0x3ff]?keys[k&0x3ff]:"",(unsigned int)k);
+   output(cl->screen,buffer);
+}
+
+void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
+{
+   char buffer[1024];
+   if(buttonMask) {
+      sprintf(buffer,"Ptr: mouse button mask 0x%x at %d,%d",buttonMask,x,y);
+      output(cl->screen,buffer);
+   }
+   
+}
+
+enum rfbNewClientAction newclient(rfbClientPtr cl)
+{
+   char buffer[1024];
+   struct sockaddr_in addr;
+   unsigned int len=sizeof(addr),ip;
+   
+   getpeername(cl->sock,(struct sockaddr*)&addr,&len);
+   ip=ntohl(addr.sin_addr.s_addr);
+   sprintf(buffer,"Client connected from ip %d.%d.%d.%d",
+	   (ip>>24)&0xff,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff);
+   output(cl->screen,buffer);
+   return RFB_CLIENT_ACCEPT;
+}
+
+int main(int argc,char** argv)
+{
+   rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,1,1);
+   s->colourMap.is16=FALSE;
+   s->colourMap.count=2;
+   s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0";
+   s->rfbServerFormat.trueColour=FALSE;
+   s->frameBuffer=f;
+   s->kbdAddEvent=dokey;
+   s->ptrAddEvent=doptr;
+   s->newClientHook=newclient;
+   
+   memset(f,0,640*480);
+   read_keys();
+   rfbInitServer(s);
+   
+   while(1) {
+      rfbProcessEvents(s,999999);
+   }
+}
diff --git a/fontsel.c b/fontsel.c
deleted file mode 100644
index 100db81..0000000
--- a/fontsel.c
+++ /dev/null
@@ -1,71 +0,0 @@
-#include "rfb.h"
-
-#define FONTDIR "/usr/lib/kbd/consolefonts/"
-#define DEFAULTFONT FONTDIR "default8x16"
-
-char *fontlist[50]={
-"8x16alt", "b.fnt", "c.fnt", "default8x16", "m.fnt", "ml.fnt", "mod_d.fnt",
-"mod_s.fnt", "mr.fnt", "mu.fnt", "r.fnt", "rl.fnt", "ro.fnt", "s.fnt",
-"sc.fnt", "scrawl_s.fnt", "scrawl_w.fnt", "sd.fnt", "t.fnt",
-  0
-};
-
-rfbScreenInfoPtr rfbScreen = 0;
-rfbFontDataPtr curFont = 0;
-void showFont(int index)
-{
-  char buffer[1024];
-
-  if(!rfbScreen) return;
-
-  if(curFont)
-    rfbFreeFont(curFont);
-
-  strcpy(buffer,FONTDIR);
-  strcat(buffer,fontlist[index]);
-  curFont = rfbLoadConsoleFont(buffer);
-
-  rfbFillRect(rfbScreen,210,30-20,210+10*16,30-20+256*20/16,0xb77797);
-  if(curFont) {
-    int i,j;
-    for(j=0;j<256;j+=16)
-      for(i=0;i<16;i++)
-	rfbDrawCharWithClip(rfbScreen,curFont,210+10*i,30+j*20/16,j+i,
-			    0,0,640,480,0xffffff,0x000000);
-  }
-}
-
-int main(int argc,char** argv)
-{
-  rfbFontDataPtr font;
-  rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3);
-  int i,j;
-
-  s->frameBuffer=(char*)malloc(640*480*3);
-  rfbInitServer(s);
-
-  for(j=0;j<480;j++)
-    for(i=0;i<640;i++) {
-      s->frameBuffer[(j*640+i)*3+0]=j*256/480;
-      s->frameBuffer[(j*640+i)*3+1]=i*256/640;
-      s->frameBuffer[(j*640+i)*3+2]=(i+j)*256/(480+640);
-    }
-
-  rfbScreen = s;
-  font=rfbLoadConsoleFont(DEFAULTFONT);
-  if(!font) {
-    fprintf(stderr,"Couldn't find %s\n",DEFAULTFONT);
-    exit(1);
-  }
-  
-  for(j=0;j<0;j++)
-    rfbProcessEvents(s,900000);
-
-  i = rfbSelectBox(s,font,fontlist,10,20,200,300,0xffdfdf,0x602040,2,showFont);
-  fprintf(stderr,"Selection: %d: %s\n",i,(i>=0)?fontlist[i]:"cancelled");
-
-  rfbFreeFont(font);
-
-  return(0);
-}
-
diff --git a/pnmshow.c b/pnmshow.c
deleted file mode 100644
index 0a5f47b..0000000
--- a/pnmshow.c
+++ /dev/null
@@ -1,81 +0,0 @@
-#include <stdio.h>
-#include "rfb.h"
-#include "keysym.h"
-
-void HandleKey(Bool down,KeySym key,rfbClientPtr cl)
-{
-  if(down && (key==XK_Escape || key=='q' || key=='Q'))
-    rfbCloseClient(cl);
-}
-
-int main(int argc,char** argv)
-{
-  FILE* in=stdin;
-  int i,j,k,width,height,paddedWidth;
-  char buffer[1024];
-  rfbScreenInfoPtr rfbScreen;
-
-  if(argc>1) {
-    in=fopen(argv[1],"rb");
-    if(!in) {
-      printf("Couldn't find file %s.\n",argv[1]);
-      exit(1);
-    }
-  }
-
-  fgets(buffer,1024,in);
-  if(strncmp(buffer,"P6",2)) {
-    printf("Not a ppm.\n");
-    exit(2);
-  }
-
-  /* skip comments */
-  do {
-    fgets(buffer,1024,in);
-  } while(buffer[0]=='#');
-
-  /* get width & height */
-  sscanf(buffer,"%d %d",&width,&height);
-  fprintf(stderr,"Got width %d and height %d.\n",width,height);
-  fgets(buffer,1024,in);
-
-  /* vncviewers have problems with widths which are no multiple of 4. */
-  paddedWidth = width;
-  if(width&3)
-    paddedWidth+=4-(width&3);
-
-  /* initialize data for vnc server */
-  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,4);
-  if(argc>1)
-    rfbScreen->desktopName = argv[1];
-  else
-    rfbScreen->desktopName = "Picture";
-  rfbScreen->rfbAlwaysShared = TRUE;
-  rfbScreen->kbdAddEvent = HandleKey;
-
-  /* enable http */
-  rfbScreen->httpDir = "./classes";
-
-  /* allocate picture and read it */
-  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*4*height);
-  fread(rfbScreen->frameBuffer,width*3,height,in);
-  fclose(in);
-
-  /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
-  for(j=height-1;j>=0;j--) {
-    for(i=width-1;i>=0;i--)
-      for(k=2;k>=0;k--)
-	rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]=
-	  rfbScreen->frameBuffer[(j*width+i)*3+k];
-    for(i=width*4;i<paddedWidth*4;i++)
-      rfbScreen->frameBuffer[j*paddedWidth*4+i]=0;
-  }
-
-  /* initialize server */
-  rfbInitServer(rfbScreen);
-
-  /* run event loop */
-  rfbRunEventLoop(rfbScreen,40000,FALSE);
-
-  return(0);
-}
diff --git a/pnmshow24.c b/pnmshow24.c
deleted file mode 100644
index e096c7f..0000000
--- a/pnmshow24.c
+++ /dev/null
@@ -1,90 +0,0 @@
-#ifndef ALLOW24BPP
-#error "I need the ALLOW24BPP flag to work"
-#endif
-
-#include <stdio.h>
-#include "rfb.h"
-#include "keysym.h"
-
-void HandleKey(Bool down,KeySym key,rfbClientPtr cl)
-{
-  if(down && (key==XK_Escape || key=='q' || key=='Q'))
-    rfbCloseClient(cl);
-}
-
-int main(int argc,char** argv)
-{
-  FILE* in=stdin;
-  int j,width,height,paddedWidth;
-  char buffer[1024];
-  rfbScreenInfoPtr rfbScreen;
-
-  if(argc>1) {
-    in=fopen(argv[1],"rb");
-    if(!in) {
-      printf("Couldn't find file %s.\n",argv[1]);
-      exit(1);
-    }
-  }
-
-  fgets(buffer,1024,in);
-  if(strncmp(buffer,"P6",2)) {
-    printf("Not a ppm.\n");
-    exit(2);
-  }
-
-  /* skip comments */
-  do {
-    fgets(buffer,1024,in);
-  } while(buffer[0]=='#');
-
-  /* get width & height */
-  sscanf(buffer,"%d %d",&width,&height);
-  fprintf(stderr,"Got width %d and height %d.\n",width,height);
-  fgets(buffer,1024,in);
-
-  /* vncviewers have problems with widths which are no multiple of 4. */
-  paddedWidth = width;
-
-  /* if your vncviewer doesn't have problems with a width
-     which is not a multiple of 4, you can comment this. */
-  if(width&3)
-    paddedWidth+=4-(width&3);
-
-  /* initialize data for vnc server */
-  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
-  if(argc>1)
-    rfbScreen->desktopName = argv[1];
-  else
-    rfbScreen->desktopName = "Picture";
-  rfbScreen->rfbAlwaysShared = TRUE;
-  rfbScreen->kbdAddEvent = HandleKey;
-
-  /* enable http */
-  rfbScreen->httpDir = "./classes";
-
-  /* allocate picture and read it */
-  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
-  fread(rfbScreen->frameBuffer,width*3,height,in);
-  fclose(in);
-
-  /* pad to paddedWidth */
-  if(width != paddedWidth) {
-    int padCount = 3*(paddedWidth - width);
-    for(j=height-1;j>=0;j--) {
-      memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
-	      rfbScreen->frameBuffer+3*width*j,
-	      3*width);
-      memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
-	     0,padCount);
-    }
-  }
-
-  /* initialize server */
-  rfbInitServer(rfbScreen);
-
-  /* run event loop */
-  rfbRunEventLoop(rfbScreen,40000,FALSE);
-
-  return(0);
-}
diff --git a/storepasswd.c b/storepasswd.c
deleted file mode 100644
index 1470e4d..0000000
--- a/storepasswd.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- *  OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
- *  Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.  
- *  All Rights Reserved.
- *
- *  This is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This software is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this software; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
- *  USA.
- */
-
-#include <stdio.h>
-#include "rfb.h"
-
-void usage(void)
-{
-    printf("\nusage:  storepasswd <password> <filename>\n\n");
-
-    printf("Stores a password in encrypted format.\n");
-    printf("The resulting file can be used with the -rfbauth argument to OSXvnc.\n\n");
-    exit(1);
-}
-
-int main(int argc, char *argv[])
-{
-    if (argc != 3) 
-        usage();
-
-    if (vncEncryptAndStorePasswd(argv[1], argv[2]) != 0) {
-        printf("storing password failed.\n");
-        return 1;
-    } else {
-        printf("storing password succeeded.\n");
-        return 0;
-    }
-}
diff --git a/vncev.c b/vncev.c
deleted file mode 100644
index 8116815..0000000
--- a/vncev.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/* This program is a simple server to show events coming from the client */
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include "rfb.h"
-#include "default8x16.h"
-
-char f[640*480];
-char* keys[0x400];
-
-int hex2number(unsigned char c)
-{
-   if(c>'f') return(-1);
-   else if(c>'F')
-     return(10+c-'a');
-   else if(c>'9')
-     return(10+c-'A');
-   else
-     return(c-'0');
-}
-
-void read_keys()
-{
-   int i,j,k;
-   char buffer[1024];
-   FILE* keysyms=fopen("keysym.h","r");
-
-   memset(keys,0,0x400*sizeof(char*));
-   
-   if(!keysyms)
-     return;
-   
-   while(!feof(keysyms)) {
-      fgets(buffer,1024,keysyms);
-      if(!strncmp(buffer,"#define XK_",strlen("#define XK_"))) {
-	 for(i=strlen("#define XK_");buffer[i] && buffer[i]!=' '
-	     && buffer[i]!='\t';i++);
-	 if(buffer[i]==0) /* don't support wrapped lines */
-	   continue;
-	 buffer[i]=0;
-	 for(i++;buffer[i] && buffer[i]!='0';i++);
-	 if(buffer[i]==0 || buffer[i+1]!='x') continue;
-	 for(j=0,i+=2;(k=hex2number(buffer[i]))>=0;i++)
-	   j=j*16+k;
-	 if(keys[j&0x3ff]) {
-	    char* x=malloc(1+strlen(keys[j&0x3ff])+1+strlen(buffer+strlen("#define ")));
-	    strcpy(x,keys[j&0x3ff]);
-	    strcat(x,",");
-	    strcat(x,buffer+strlen("#define "));
-	    free(keys[j&0x3ff]);
-	    keys[j&0x3ff]=x;
-	 } else
-	   keys[j&0x3ff] = strdup(buffer+strlen("#define "));
-      }
-      
-   }
-   fclose(keysyms);
-}
-
-int lineHeight=16,lineY=480-16;
-void output(rfbScreenInfoPtr s,char* line)
-{
-   rfbDoCopyRect(s,0,0,640,480-lineHeight,0,-lineHeight);
-   rfbDrawString(s,&default8x16Font,10,lineY,line,0x01);
-   fprintf(stderr,"%s\n",line);
-}
-
-void dokey(Bool down,KeySym k,rfbClientPtr cl)
-{
-   char buffer[1024+32];
-   
-   sprintf(buffer,"%s: %s (0x%x)",
-	   down?"down":"up",keys[k&0x3ff]?keys[k&0x3ff]:"",(unsigned int)k);
-   output(cl->screen,buffer);
-}
-
-void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
-{
-   char buffer[1024];
-   if(buttonMask) {
-      sprintf(buffer,"Ptr: mouse button mask 0x%x at %d,%d",buttonMask,x,y);
-      output(cl->screen,buffer);
-   }
-   
-}
-
-enum rfbNewClientAction newclient(rfbClientPtr cl)
-{
-   char buffer[1024];
-   struct sockaddr_in addr;
-   unsigned int len=sizeof(addr),ip;
-   
-   getpeername(cl->sock,(struct sockaddr*)&addr,&len);
-   ip=ntohl(addr.sin_addr.s_addr);
-   sprintf(buffer,"Client connected from ip %d.%d.%d.%d",
-	   (ip>>24)&0xff,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff);
-   output(cl->screen,buffer);
-   return RFB_CLIENT_ACCEPT;
-}
-
-int main(int argc,char** argv)
-{
-   rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,1,1);
-   s->colourMap.is16=FALSE;
-   s->colourMap.count=2;
-   s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0";
-   s->rfbServerFormat.trueColour=FALSE;
-   s->frameBuffer=f;
-   s->kbdAddEvent=dokey;
-   s->ptrAddEvent=doptr;
-   s->newClientHook=newclient;
-   
-   memset(f,0,640*480);
-   read_keys();
-   rfbInitServer(s);
-   
-   while(1) {
-      rfbProcessEvents(s,999999);
-   }
-}
-- 
cgit v1.2.3

