]> cygwin.com Git - cygwin-apps/setup.git/blob - ini.cc
* net.cc (do_net): Default to direct download.
[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 static char *cvsid = "\n%%% $Id$\n";
22
23 #include "win32.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28
29 #include "ini.h"
30 #include "resource.h"
31 #include "concat.h"
32 #include "state.h"
33 #include "geturl.h"
34 #include "dialog.h"
35 #include "msg.h"
36 #include "mkdir.h"
37 #include "log.h"
38 #include "version.h"
39
40 unsigned int setup_timestamp = 0;
41 char *setup_version = 0;
42
43 extern "C" int yyparse ();
44 /*extern int yydebug;*/
45
46 static char *error_buf = 0;
47 static int error_count = 0;
48
49 void
50 do_ini (HINSTANCE h)
51 {
52 char *ini_file = get_url_to_string (concat (MIRROR_SITE, "/setup.ini", 0));
53 dismiss_url_status_dialog ();
54
55 if (!ini_file)
56 {
57 note (IDS_SETUPINI_MISSING, MIRROR_SITE);
58 next_dialog = IDD_SITE;
59 return;
60 }
61
62 package = 0;
63 npackages = 0;
64 setup_timestamp = 0;
65 setup_version = 0;
66
67 ini_init (ini_file);
68
69 setup_timestamp = 0;
70 /*yydebug = 1;*/
71
72 if (yyparse () || error_count > 0)
73 {
74 if (error_count == 1)
75 MessageBox (0, error_buf, "Parse Error", 0);
76 else
77 MessageBox (0, error_buf, "Parse Errors", 0);
78 }
79 else
80 {
81 /* save known-good setup.ini locally */
82 FILE *inif = fopen ("setup.ini", "wb");
83 if (inif)
84 {
85 fwrite (ini_file, 1, strlen (ini_file), inif);
86 fclose (inif);
87 }
88 }
89
90 if (root_dir)
91 {
92 mkdir_p (1, concat (root_dir, "/etc/setup", 0));
93
94 unsigned int old_timestamp = 0;
95 FILE *ots = fopen (concat (root_dir, "/etc/setup/timestamp", 0), "rt");
96 if (ots)
97 {
98 fscanf (ots, "%u", &old_timestamp);
99 fclose (ots);
100 if (old_timestamp && setup_timestamp
101 && (old_timestamp > setup_timestamp))
102 {
103 int yn = yesno (IDS_OLD_SETUPINI);
104 if (yn == IDNO)
105 exit_setup (1);
106 }
107 }
108 if (setup_timestamp)
109 {
110 FILE *nts = fopen (concat (root_dir, "/etc/setup/timestamp", 0), "wt");
111 if (nts)
112 {
113 fprintf (nts, "%u", setup_timestamp);
114 fclose (nts);
115 }
116 }
117 }
118
119 msg ("setup_version is %s, our_version is %s", setup_version?:"(null)", version);
120 if (setup_version)
121 {
122 char *ini_version = canonicalize_version (setup_version);
123 char *our_version = canonicalize_version (version);
124 if (strcmp (our_version, ini_version) < 0)
125 note (IDS_OLD_SETUP_VERSION, version, setup_version);
126 }
127
128 next_dialog = IDD_CHOOSE;
129 }
130
131 extern int yylineno;
132
133 extern "C" int yyerror (char *s, ...)
134 {
135 char buf[1000];
136 int len;
137 sprintf (buf, "setup.ini line %d: ", yylineno);
138 va_list args;
139 va_start (args, s);
140 vsprintf (buf + strlen (buf), s, args);
141 OutputDebugString (buf);
142 if (error_buf)
143 {
144 strcat (error_buf, "\n");
145 len = strlen (error_buf) + strlen (buf) + 5;
146 error_buf = (char *) realloc (error_buf, len);
147 strcat (error_buf, buf);
148 }
149 else
150 {
151 len = strlen (buf) + 5;
152 error_buf = (char *) malloc (len);
153 strcpy (error_buf, buf);
154 }
155 error_count++;
156 }
157
158 extern "C" int fprintf (FILE *f, const char *s, ...);
159
160 static char stderrbuf[1000];
161
162 int
163 fprintf (FILE *f, const char *fmt, ...)
164 {
165 char buf[1000];
166 int rv;
167 va_list args;
168 va_start (args, fmt);
169 if (f == stderr)
170 {
171 rv = vsprintf (buf, fmt, args);
172 strcat (stderrbuf, buf);
173 if (char *nl = strchr (stderrbuf, '\n'))
174 {
175 *nl = 0;
176 /*OutputDebugString (stderrbuf);*/
177 MessageBox (0, buf, "Cygwin Setup", 0);
178 stderrbuf[0] = 0;
179 }
180
181 }
182 else
183 {
184 rv = vfprintf (f, fmt, args);
185 }
186 return rv;
187 }
This page took 0.043926 seconds and 5 git commands to generate.