]> cygwin.com Git - cygwin-apps/setup.git/blob - ini.cc
Backout accidental commit
[cygwin-apps/setup.git] / ini.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* The purpose of this file is to get and parse the setup.ini file
17 from the mirror site. A few support routines for the bison and
18 flex parsers are provided also. We check to see if this setup.ini
19 is older than the one we used last time, and if so, warn the user. */
20
21 #if 0
22 static const char *cvsid =
23 "\n%%% $Id$\n";
24 #endif
25
26 #include "win32.h"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31
32 #include "ini.h"
33 #include "resource.h"
34 #include "concat.h"
35 #include "state.h"
36 #include "geturl.h"
37 #include "dialog.h"
38 #include "msg.h"
39 #include "log.h"
40 #include "version.h"
41 #include "mount.h"
42
43 #include "io_stream.h"
44
45 unsigned int setup_timestamp = 0;
46 char *setup_version = 0;
47
48 extern int yyparse ();
49 /*extern int yydebug;*/
50
51 static char *error_buf = 0;
52 static int error_count = 0;
53
54 void
55 do_ini (HINSTANCE h)
56 {
57 char *ini_file = get_url_to_string (concat (MIRROR_SITE, "/setup.ini", 0));
58 dismiss_url_status_dialog ();
59
60 if (!ini_file)
61 {
62 note (IDS_SETUPINI_MISSING, MIRROR_SITE);
63 next_dialog = IDD_SITE;
64 return;
65 }
66
67 package = NULL;
68 npackages = 0;
69 setup_timestamp = 0;
70 setup_version = 0;
71
72 ini_init (ini_file);
73
74 setup_timestamp = 0;
75 /*yydebug = 1; */
76
77 if (yyparse () || error_count > 0)
78 {
79 if (error_count == 1)
80 MessageBox (0, error_buf, "Parse Error", 0);
81 else
82 MessageBox (0, error_buf, "Parse Errors", 0);
83 }
84 else
85 {
86 /* save known-good setup.ini locally */
87 io_stream *inistream = io_stream::open ("file://setup.ini", "wb");
88 if (inistream)
89 {
90 inistream->write (ini_file, strlen (ini_file));
91 delete inistream;
92 }
93 }
94
95 if (get_root_dir ())
96 {
97 io_stream::mkpath_p (PATH_TO_DIR, "cygfile:///etc/setup");
98
99 unsigned int old_timestamp = 0;
100 io_stream *ots =
101 io_stream::open ("cygfile:///etc/setup/timestamp", "rt");
102 if (ots)
103 {
104 char temp[20];
105 memset (temp, '\0', 20);
106 if (ots->read (temp, 19))
107 sscanf (temp, "%u", &old_timestamp);
108 delete ots;
109 if (old_timestamp && setup_timestamp
110 && (old_timestamp > setup_timestamp))
111 {
112 int yn = yesno (IDS_OLD_SETUPINI);
113 if (yn == IDNO)
114 exit_setup (1);
115 }
116 }
117 if (setup_timestamp)
118 {
119 io_stream *nts =
120 io_stream::open ("cygfile:///etc/setup/timestamp", "wt");
121 if (nts)
122 {
123 char temp[20];
124 sprintf (temp, "%u", setup_timestamp);
125 nts->write (temp, strlen (temp));
126 delete nts;
127 }
128 }
129 }
130
131 msg ("setup_version is %s, our_version is %s", setup_version ? : "(null)",
132 version);
133 if (setup_version)
134 {
135 char *ini_version = canonicalize_version (setup_version);
136 char *our_version = canonicalize_version (version);
137 if (strcmp (our_version, ini_version) < 0)
138 note (IDS_OLD_SETUP_VERSION, version, setup_version);
139 }
140
141 next_dialog = IDD_CHOOSE;
142 }
143
144 extern int yylineno;
145
146 extern "C" int
147 yyerror (char *s, ...)
148 {
149 char buf[1000];
150 int len;
151 sprintf (buf, "setup.ini line %d: ", yylineno);
152 va_list args;
153 va_start (args, s);
154 vsprintf (buf + strlen (buf), s, args);
155 OutputDebugString (buf);
156 if (error_buf)
157 {
158 strcat (error_buf, "\n");
159 len = strlen (error_buf) + strlen (buf) + 5;
160 error_buf = (char *) realloc (error_buf, len);
161 strcat (error_buf, buf);
162 }
163 else
164 {
165 len = strlen (buf) + 5;
166 error_buf = (char *) malloc (len);
167 strcpy (error_buf, buf);
168 }
169 error_count++;
170 /* TODO: is return 0 correct? */
171 return 0;
172 }
173
174 extern "C" int fprintf (FILE * f, const char *s, ...);
175
176 static char stderrbuf[1000];
177
178 int
179 fprintf (FILE * f, const char *fmt, ...)
180 {
181 char buf[1000];
182 int rv;
183 va_list args;
184 va_start (args, fmt);
185 if (f == stderr)
186 {
187 rv = vsprintf (buf, fmt, args);
188 strcat (stderrbuf, buf);
189 if (char *nl = strchr (stderrbuf, '\n'))
190 {
191 *nl = 0;
192 /*OutputDebugString (stderrbuf); */
193 MessageBox (0, buf, "Cygwin Setup", 0);
194 stderrbuf[0] = 0;
195 }
196
197 }
198 else
199 {
200 rv = vfprintf (f, fmt, args);
201 }
202 return rv;
203 }
This page took 0.045567 seconds and 6 git commands to generate.