delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/04/12/18:49:24

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Ralf Habacker" <Ralf DOT Habacker AT freenet DOT de>
To: <cygwin AT cygwin DOT com>
Cc: "Max Bowsher" <maxb AT ukf DOT net>, "Gerrit P. Haase" <gp AT familiehaase DOT de>
Subject: RE: new setup md5 check
Date: Sun, 13 Apr 2003 00:49:06 +0200
Message-ID: <003201c30145$b9247010$605d07d5@BRAMSCHE>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
In-Reply-To: <006901c300fb$4b7c1440$f658893e@pomello>
Importance: Normal
X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

------=_NextPart_000_0033_01C30156.7CAD4010
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

> Gerrit P. Haase wrote:
> > Hallo,
> >
> > why is the MD5 check performed every time?
>
> A good question.
>
> > Because in the five minutes from now on, my packages
> > may be corrupted?
> >
> > How can I get rid of it?
>
> There is a command line option to disable: -5
>
But what about starting setup directly from http://www.cygwin.com/setup.exe or
refering through a link from another website like the kde-cygwin project does ?
This does not work.

There may be a possibility (1) to use an url like
http://www.cygwin.com/setup.exe?option=... but this require, that some cgi or
other server based scripting language does some tricks in choosing different
setup.exe's online or patching the delivered delivered setup.exe online. A
simpler way (2) would be using different setup.exe's with prefined options[1]
like http://www.cygwin.com/setup-5.exe or
http://www.cygwin.com/setup-<other_option>.exe but this require patched
setup.exe versions on the server.

In the last week I had send a prelimary patch to Robert Collins privat for
checking if this is usable , which allow exactly [1], but until now I haven't
heard anything about the useness of this.
Anyway, I have added this patch to this mail. Perhaps someone find is useful. A
short howto (for details see the appended mail):

	1. export the configuration from setup.exe
		./setup-config.exe -r setup.exe >setup.config

	2. edit the configuration file
		Example:

		CustomConfig (Structure version: 2) {
			mirror_url=http://xyz/mirrors.lst
			root_dir=\test
			show_splash_screen=0
			show_chooser_screen=0
			....
		}

	3a. import the configuration into setup.exe
		./setup-config.exe -w setup.exe <setup.config

or

	3a. create a different setup.exe with this configuration
		cp setup.exe setup-<option>.exe
		./setup-config.exe -w setup-<option>.exe <setup.config

Cheers
Ralf


------=_NextPart_000_0033_01C30156.7CAD4010
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment

From: "Ralf Habacker" <Ralf DOT Habacker AT freenet DOT de>
To: "Robert Collins" <rbcollins AT cygwin DOT com>
Subject: proposal of setup custom configurations features 
Date: Mon, 7 Apr 2003 13:23:42 +0200
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_002F_01C30156.7C965CB0"
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Disposition-Notification-To: "Ralf Habacker" <Ralf DOT Habacker AT freenet DOT de>
Importance: Normal
X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

This is a multi-part message in MIME format.

------=_NextPart_000_002F_01C30156.7C965CB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi Robert,

for a special use of the cygwin setup tool, there is the need for several
project related customized setup.exe.

Some examples for this are the default 'root_dir', the default location of the
mirrors.lst files and some unwanted setting pages like the splash screen,
network setting page and so one. I does not like to recompile the setup.exe
every time the configuration is changed, so I've implemented a feature called
"custom configuration", which allows patching a already compiled setup.exe to
customized some major settings.

I'm sending this proposal to you personal before sending it to the cygwin
mailing list because I like to hear, if such a feature would be nice or not.
I would be glad to hear your comments and suggestions. Some notes of the
implementation are mentioned below.

Thanks

Ralf

from customconfig.h
" setup customisation support allows generating a partially customized version
of
  setup.exe through a special helper application named 'setup-config.exe', which
  reads the activated customizable parameters or patches the setup.exe binary to
  change the customizable parameters.

  Customizable parameters could be added to an application through the
  CUSTOM_CONFIG_PARAMS(instance_name) macro, which defines an object named
  'instance_name' of the  CustomConfigParams structure.

	Refering to customizable settings is done by referening the object members of
global object.
	For example:

	#ifdef CUSTOM_CONFIG_SUPPORT
     	extern CustomConfigParams ccParams;
			set_root_dir (String (windir) + ccParams.root_dir);
	#else
      set_root_dir (String (windir) + "\\cygwin");
	#endif


	Adding additional parameters is done by adding/patching some lines to the file
'customconfig.h'.

	1. Add a member to the 'CustomConfigParams' structure
	2. Add a default value to the 'CUSTOM_CONFIG_PARAMS' macro
	3. Add a printing statement to the 'CUSTOM_CONFIG_PRINT_ITEMS' macro
	4. Add a parsing statement to the 'CUSTOM_CONFIG_SCAN_ITEMS' macro
	5. Increment the value of the CCP_VERSION macro to reflect the structure
changes
	6. Recompile setup.exe and setup-config.exe

	configuring setup.exe
	=====================
	Configuring setup.exe is done via the helper tool setup-config.exe.

	1. export the configuration from setup.exe
		./setup-config.exe -r >setup.config

	2. edit the configuration file
		Example:

		CustomConfig (Structure version: 2) {
			mirror_url=http://w2kserver01/fm
			root_dir=\test
			show_splash_screen=0
			show_chooser_screen=0
		}

	3. import the configuration into setup.exe
		./setup-config.exe -w <setup.config

------=_NextPart_000_002F_01C30156.7C965CB0
Content-Type: application/octet-stream;
	name="patch_custom_config.dif"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="patch_custom_config.dif"

Index: Makefile.am=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/cygwin-apps/setup/Makefile.am,v=0A=
retrieving revision 2.27=0A=
diff -u -3 -p -B -r2.27 Makefile.am=0A=
--- Makefile.am	10 Mar 2003 15:47:53 -0000	2.27=0A=
+++ Makefile.am	7 Apr 2003 08:41:49 -0000=0A=
@@ -36,6 +36,7 @@ INCLUDES	=3D -I$(srcdir)/bz2lib -I$(srcdir=0A=
 =0A=
 noinst_PROGRAMS =3D \=0A=
   setup \=0A=
+  setup-config \=0A=
   @INILINT@=0A=
 =0A=
 EXTRA_PROGRAMS =3D inilint=0A=
@@ -286,6 +287,9 @@ setup_version.c : $(srcdir)/ChangeLog Ma=0A=
         echo 'static const char version_store[] =3D VERSION_PREFIX " =
'$$V'";';\=0A=
         echo 'const char *version =3D version_store + sizeof =
(VERSION_PREFIX);') > version.tmp;\=0A=
 	mv version.tmp setup_version.c=0A=
+=0A=
+setup_config_SOURCES =3D customconfig.cc =0A=
+setup_config_CXXFLAGS =3D -DTEST =0A=
 =0A=
 %.o: %.rc=0A=
 	$(WINDRES) --preprocessor "$(CC) -E -xc-header -DRC_INVOKED" =
--include-dir $(srcdir) -o $@ $<=0A=
Index: main.cc=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/cygwin-apps/setup/main.cc,v=0A=
retrieving revision 2.25=0A=
diff -u -3 -p -B -r2.25 main.cc=0A=
--- main.cc	28 Feb 2003 23:42:09 -0000	2.25=0A=
+++ main.cc	7 Apr 2003 08:41:49 -0000=0A=
@@ -46,6 +46,8 @@ static const char *cvsid =3D=0A=
 #include "proppage.h"=0A=
 #include "propsheet.h"=0A=
 =0A=
+#include "customconfig.h"=0A=
+=0A=
 // Page class headers=0A=
 #include "splash.h"=0A=
 #include "AntiVirus.h"=0A=
@@ -61,6 +63,10 @@ static const char *cvsid =3D=0A=
 #include "getopt++/GetOption.h"=0A=
 #include "getopt++/BoolOption.h"=0A=
 =0A=
+#ifdef CUSTOM_CONFIG_SUPPORT=0A=
+CUSTOM_CONFIG_PARAMS(ccParams);=0A=
+#endif =0A=
+=0A=
 int next_dialog;=0A=
 =0A=
 HINSTANCE hinstance;=0A=
@@ -343,7 +349,10 @@ main (int argc, char **argv)=0A=
   Window::SetAppInstance (hinstance);=0A=
 =0A=
   // Create pages=0A=
-  Splash.Create ();=0A=
+#ifdef CUSTOM_CONFIG_SUPPORT=0A=
+	if (ccParams.show_splash_screen)=0A=
+#endif =0A=
+	  Splash.Create ();=0A=
   AntiVirus.Create ();=0A=
   Source.Create ();=0A=
   Root.Create ();=0A=
@@ -355,13 +364,19 @@ main (int argc, char **argv)=0A=
   Desktop.Create ();=0A=
 =0A=
   // Add pages to sheet=0A=
-  MainWindow.AddPage (&Splash);=0A=
+#ifdef CUSTOM_CONFIG_SUPPORT=0A=
+	if (ccParams.show_splash_screen)=0A=
+#endif =0A=
+  	MainWindow.AddPage (&Splash);=0A=
   MainWindow.AddPage (&AntiVirus);=0A=
   MainWindow.AddPage (&Source);=0A=
   MainWindow.AddPage (&Root);=0A=
   MainWindow.AddPage (&LocalDir);=0A=
   MainWindow.AddPage (&Net);=0A=
   MainWindow.AddPage (&Site);=0A=
+#ifdef CUSTOM_CONFIG_SUPPORT=0A=
+	if (ccParams.show_chooser_screen)=0A=
+#endif =0A=
   MainWindow.AddPage (&Chooser);=0A=
   MainWindow.AddPage (&Progress);=0A=
   MainWindow.AddPage (&Desktop);=0A=
Index: site.cc=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/cygwin-apps/setup/site.cc,v=0A=
retrieving revision 2.25=0A=
diff -u -3 -p -B -r2.25 site.cc=0A=
--- site.cc	10 Mar 2003 08:50:16 -0000	2.25=0A=
+++ site.cc	7 Apr 2003 08:41:49 -0000=0A=
@@ -37,6 +37,7 @@ static const char *cvsid =3D=0A=
 #include "LogSingleton.h"=0A=
 #include "io_stream.h"=0A=
 #include "site.h"=0A=
+#include "customconfig.h"=0A=
 =0A=
 #include "port.h"=0A=
 =0A=
@@ -173,8 +174,13 @@ get_site_list (HINSTANCE h, HWND owner)=0A=
 {=0A=
   char mirror_url[1000];=0A=
 =0A=
+#if CUSTOM_CONFIG_SUPPORT=0A=
+	extern CustomConfigParams ccParams;=0A=
+  strcpy(mirror_url,ccParams.mirror_url);=0A=
+#else =0A=
   if (LoadString (h, IDS_MIRROR_LST, mirror_url, sizeof (mirror_url)) =
<=3D 0)=0A=
     return 1;=0A=
+#endif =0A=
   char *bol, *eol, *nl, *theString;=0A=
   {=0A=
   String mirrors =3D get_url_to_string (mirror_url, owner);=0A=
Index: mount.cc=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/cygwin-apps/setup/mount.cc,v=0A=
retrieving revision 2.15=0A=
diff -u -3 -p -B -r2.15 mount.cc=0A=
--- mount.cc	15 Jan 2003 22:06:22 -0000	2.15=0A=
+++ mount.cc	7 Apr 2003 08:41:49 -0000=0A=
@@ -22,7 +22,7 @@ static const char *cvsid =3D "\n%%% $Id: m=0A=
 #endif=0A=
 =0A=
 #include "win32.h"=0A=
-=0A=
+#include "customconfig.h" =0A=
 #include <stdio.h>=0A=
 #include <stdlib.h>=0A=
 =0A=
@@ -440,7 +440,12 @@ read_mounts ()=0A=
       root_scope =3D (is_admin ())? IDC_ROOT_SYSTEM : IDC_ROOT_USER;=0A=
       GetWindowsDirectory (windir, sizeof (windir));=0A=
       windir[2] =3D 0;=0A=
+#ifdef CUSTOM_CONFIG_SUPPORT=0A=
+     	extern CustomConfigParams ccParams;=0A=
+			set_root_dir (String (windir) + ccParams.root_dir);=0A=
+#else =0A=
       set_root_dir (String (windir) + "\\cygwin");=0A=
+#endif =0A=
       m++;=0A=
     }=0A=
 }=0A=
--- /dev/null	2003-04-07 10:09:56.000000000 +0200=0A=
+++ customconfig.h	2003-04-07 10:00:37.000000000 +0200=0A=
@@ -0,0 +1,93 @@=0A=
+/*
+ * Copyright (c) 2003, Ralf Habacker.
+ *
+ *     This program 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.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by Ralf Habacker <ralf DOT habacker AT freenet DOT de>
+ *
+ */
+
+/*=20
+  setup customisation support allows generating a partially customized =
version of=20
+  setup.exe through a special helper application named =
'setup-config.exe', which=20
+  reads the activated customizable parameters or patches the setup.exe =
binary to=20
+  change the customizable parameters.=20
+    =20
+  Customizable parameters could be added to an application through the=20
+  CUSTOM_CONFIG_PARAMS(instance_name) macro, which defines an instance =
named=20
+  'instance_name' of the  CustomConfigParams object.=20
+
+   									=20
+ */
+
+#ifndef _CUSTOMCONFIG_H_
+#define _CUSTOMCONFIG_H_
+
+// enable custom configuration support=20
+#define CUSTOM_CONFIG_SUPPORT	1=20
+
+//
+// structure definitions=20
+//=20
+//=20
+
+typedef struct {
+	long magic1,magic2;
+	long version;=20
+	char mirror_url[512];
+	char root_dir[512];
+	bool show_splash_screen;
+	bool show_chooser_screen;
+	// --- add lines ----=20
+} CustomConfigParams;=20
+
+
+
+//
+// default value definitions=20
+//=20
+#define CCP_MAGIC1 0x12345678
+#define CCP_MAGIC2 0x87654321
+#define CCP_VERSION 2
+
+//
+// use this macro for defining a CustomConfigParams instance=20
+//
+#define CUSTOM_CONFIG_PARAMS(name) 									\
+CustomConfigParams name =3D {					                \
+	CCP_MAGIC1,CCP_MAGIC2,                            \
+	CCP_VERSION,                                      \
+	"http://sources.redhat.com/cygwin/mirrors.lst", /* mirror_url[512]    =
*/ \
+	"\\cygwin", 																		/* root_dir[512]	    */ \
+	true,                                           /* show_splash_screen =
*/ \
+	true,                                           /* show_chooser_screen =
*/ \
+};=20
+
+//
+// fragment for printing item list=20
+//=20
+#define CUSTOM_CONFIG_PRINT_ITEMS(f,name) 																\
+		fprintf(f,"CustomConfig (Structure version: %d) {\n",name->version); 	=
\
+		fprintf(f,"mirror_url=3D%s\n",name->mirror_url); 												\
+		fprintf(f,"root_dir=3D%s\n",name->root_dir);		 												\
+		fprintf(f,"show_splash_screen=3D%d\n",name->show_splash_screen ); 			=
\
+		fprintf(f,"show_chooser_screen=3D%d\n",name->show_chooser_screen ); 		=
\
+		fprintf(f,"}\n");=20
+
+//
+// fragement for parsing the items from input stream=20
+//=20
+#define CUSTOM_CONFIG_SCAN_ITEMS(f,name) 																							\
+		ret =3D fscanf(f,"CustomConfig (Structure version: %d) =
{\n",&(name)->version);			\
+		ret =3D fscanf(f,"mirror_url=3D%s\n",&(name)->mirror_url);												=
		\
+		ret =3D fscanf(f,"root_dir=3D%s\n",&(name)->root_dir);																=
\
+		ret =3D =
fscanf(f,"show_splash_screen=3D%d\n",&(name)->show_splash_screen );						=
\
+		ret =3D =
fscanf(f,"show_chooser_screen=3D%d\n",&(name)->show_chooser_screen );				=
	=09
+
+#endif /* _CUSTOMCONFIG_H_ */
--- /dev/null	2003-04-07 10:10:00.000000000 +0200=0A=
+++ customconfig.cc	2003-04-06 21:27:58.000000000 +0200=0A=
@@ -0,0 +1,222 @@=0A=
+/*
+ * Copyright (c) 2003, Ralf Habacker.
+ *
+ *     This program 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.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by Ralf Habacker <ralf DOT habacker AT freenet DOT de>
+ *
+ */
+#if 0
+static const char *cvsid =3D
+  "\n%%% $Id:$\n";
+#endif
+
+#include <stdio.h>
+#include <windows.h>
+
+#include "customconfig.h"=20
+
+
+
+class CustomConfig {
+  public:
+  	CustomConfig(char *s,bool verboseMode =3D false);
+//  	~CustomConfig();
+  	bool Print(FILE *f);=20
+  	bool Set(FILE *f);=20
+  	bool Set(CustomConfigParams &Params);
+  	protected:=20
+	  	void *mapFile(bool writable);=20
+	  	void unmapFile();=20
+	  	CustomConfigParams *searchParams(void *lpFileBase);
+  		int Error;=20
+  	private:
+  		char filename[1024];=20
+  		HANDLE hfile;
+  		HANDLE hfilemapping;=20
+  		bool verbose;=20
+};
+
+
+CustomConfig::CustomConfig(char *s,bool verboseMode)
+{
+	strcpy(filename,s);=20
+	verbose =3D verboseMode;
+}
+
+/*=20
+CustomConfig::~CustomConfig()
+{
+}
+*/
+void *CustomConfig::mapFile(bool writeable)
+{
+	// open image=20
+  hfile =3D CreateFile(filename, writeable ? GENERIC_READ | =
GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, =
FILE_ATTRIBUTE_NORMAL,0);
+	if (hfile =3D=3D INVALID_HANDLE_VALUE) {
+		Error =3D 1;
+		return 0;=20
+	}
+
+  HANDLE hfilemapping =3D CreateFileMapping(hfile, NULL, writeable ? =
PAGE_READWRITE : PAGE_READONLY , 0, 0,  NULL);
+  if (hfilemapping =3D=3D 0)
+    {
+      CloseHandle(hfile);
+      Error =3D 2;
+      return 0;
+    }
+
+  void *lpFileBase =3D MapViewOfFile(hfilemapping, writeable ? =
FILE_MAP_WRITE : FILE_MAP_READ,0, 0, 0);
+  if (lpFileBase =3D=3D 0)
+    {
+      CloseHandle(hfilemapping);
+      CloseHandle(hfile);
+      Error =3D 3;
+      return 0;
+    }
+   return lpFileBase;
+}
+
+void CustomConfig::unmapFile()
+{
+	// FIXME: check valid handles=20
+	CloseHandle(hfilemapping);
+  CloseHandle(hfile);
+}
+
+CustomConfigParams *CustomConfig::searchParams(void *lpFileBase)
+{
+	if (lpFileBase =3D=3D 0)
+		return (CustomConfigParams *)0;=20
+	=09
+	PIMAGE_DOS_HEADER dosheader =3D (PIMAGE_DOS_HEADER)lpFileBase;=20
+	PIMAGE_NT_HEADERS ntheader =3D (PIMAGE_NT_HEADERS) ((char *)dosheader =
+ dosheader->e_lfanew);
+	int lpFileSize =3D ntheader->OptionalHeader.SizeOfImage;
+=09
+	// search structure and write params if found in image=20
+	for (long *p =3D (long *)lpFileBase ; p < (long =
*)((int)lpFileBase+lpFileSize); p++) {
+		if (*p =3D=3D CCP_MAGIC1) {
+			if (*(p+1) =3D=3D CCP_MAGIC2)=20
+				return (CustomConfigParams *)p;
+		}
+	}
+	return (CustomConfigParams *)0;=20
+}
+
+
+bool CustomConfig::Print(FILE *f)=20
+{
+	CustomConfigParams *curParams =3D searchParams(mapFile(false));=20
+	if (curParams) {
+		CUSTOM_CONFIG_PRINT_ITEMS(f,curParams);
+		unmapFile();
+		return true;=20
+	}
+	else {
+		fprintf(stderr,"setup-config: could not find config structure in =
'%s'\n",filename);=20
+		return false;=20
+	}
+}
+
+bool CustomConfig::Set(CustomConfigParams &Params)=20
+{
+	char temp[1024];
+
+	CustomConfigParams *curParams =3D searchParams(mapFile(true));=20
+	if (curParams) {
+		*curParams =3D Params;=20
+		unmapFile();
+		return true;=20
+	}				=09
+	else {
+		fprintf(stderr,"setup-config: could not find config structure in =
'%s'\n",filename);=20
+		return false;=20
+	}
+}
+
+bool CustomConfig::Set(FILE *f)=20
+{
+	// default values=20
+	CUSTOM_CONFIG_PARAMS(ccParams);
+	int version;
+	char buf[1024];=20
+	int ret;=20
+	CustomConfigParams newParams =3D ccParams;=20
+
+	// scan input=20
+	if (verbose) {
+		fprintf(stderr,"parsing input data\n");=20
+		fflush(stderr);=20
+	}
+=09
+	// read the config file 	=09
+	CUSTOM_CONFIG_SCAN_ITEMS(f,&newParams);
+
+	// check version matching for the readed input file=20
+	if (ccParams.version !=3D newParams.version ) {
+		fprintf(stderr,"setup-config: version mismatch error =
(setup-config=3D%d =
input-file=3D%d)\n",ccParams.version,newParams.version);=20
+		exit(1);
+	}
+
+	if (verbose) {
+		fprintf(stderr,"reading binary '%s'\n",filename);=20
+		fflush(stderr);=20
+	}
+
+	// read setup configuration from binary=20
+	CustomConfigParams *curParams =3D searchParams(mapFile(true));=20
+	if (!curParams) {
+		fprintf(stderr,"setup-config: could not find config structure in =
'%s'\n",filename);=20
+		exit(1);
+	}
+
+	// check version matching between our application and the targeted =
binary=20
+	if (curParams->version !=3D ccParams.version) {
+		fprintf(stderr,"setup-config: version mismatch error (setup=3D%d =
setup-config=3D%d)\n",curParams->version,ccParams.version);=20
+		exit(1);
+	}	=09
+
+=09
+	if (verbose) {
+		fprintf(stderr,"setup new configuration\n");=20
+		fflush(stderr);=20
+	}
+	// set new configuration=20
+	*curParams =3D newParams;=20
+
+	if (verbose) {
+		fprintf(stderr,"write back configuration in binary\n");=20
+		fflush(stderr);=20
+	}
+	unmapFile();
+	return true;=20
+}
+
+#ifdef TEST
+int main(int argc,char **argv)
+{
+	char *name;=20
+	bool verbose =3D true;=20
+=09
+	if (argc =3D=3D 3)=20
+		name =3D argv[2];=20
+	else=20
+		name =3D "setup.exe";
+	if (argc > 1) {
+		CustomConfig test(name,verbose);=20
+		if (strcmp(argv[1],"-r") =3D=3D 0)
+			test.Print(stdout);=20
+		if (strcmp(argv[1],"-w") =3D=3D 0) {
+			test.Set(stdin);=20
+			if (verbose)=20
+				test.Print(stdout);=20
+		}
+	}
+} =09
+#endif=20

------=_NextPart_000_002F_01C30156.7C965CB0--


------=_NextPart_000_0033_01C30156.7CAD4010
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_0033_01C30156.7CAD4010--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019