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