]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
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 | ||
8507f105 DD |
21 | static char *cvsid = "\n%%% $Id$\n"; |
22 | ||
23c9e63c DD |
23 | #include "win32.h" |
24 | ||
25 | #include <stdio.h> | |
b11b49f3 | 26 | #include <stdlib.h> |
23c9e63c DD |
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" | |
89b1a15b | 37 | #include "log.h" |
23c9e63c DD |
38 | |
39 | unsigned int setup_timestamp = 0; | |
40 | ||
41 | extern "C" int yyparse (); | |
b11b49f3 DD |
42 | /*extern int yydebug;*/ |
43 | ||
44 | static char *error_buf = 0; | |
45 | static int error_count = 0; | |
23c9e63c DD |
46 | |
47 | void | |
48 | do_ini (HINSTANCE h) | |
49 | { | |
50 | char *ini_file = get_url_to_string (concat (MIRROR_SITE, "/setup.ini", 0)); | |
b11b49f3 | 51 | dismiss_url_status_dialog (); |
23c9e63c DD |
52 | |
53 | if (!ini_file) | |
b5b282c4 DD |
54 | { |
55 | note (IDS_SETUPINI_MISSING, MIRROR_SITE); | |
56 | next_dialog = IDD_SITE; | |
57 | return; | |
58 | } | |
23c9e63c DD |
59 | |
60 | ini_init (ini_file); | |
61 | ||
62 | setup_timestamp = 0; | |
b11b49f3 DD |
63 | /*yydebug = 1;*/ |
64 | ||
65 | if (yyparse () || error_count > 0) | |
66 | { | |
67 | if (error_count == 1) | |
68 | MessageBox (0, error_buf, "Parse Error", 0); | |
69 | else | |
70 | MessageBox (0, error_buf, "Parse Errors", 0); | |
71 | } | |
23c9e63c | 72 | |
04d6e06b | 73 | if (root_dir) |
23c9e63c | 74 | { |
04d6e06b DD |
75 | mkdir_p (1, concat (root_dir, "/etc/setup", 0)); |
76 | ||
77 | unsigned int old_timestamp = 0; | |
78 | FILE *ots = fopen (concat (root_dir, "/etc/setup/timestamp", 0), "rt"); | |
79 | if (ots) | |
23c9e63c | 80 | { |
04d6e06b DD |
81 | fscanf (ots, "%u", &old_timestamp); |
82 | fclose (ots); | |
83 | if (old_timestamp && setup_timestamp | |
84 | && (old_timestamp > setup_timestamp)) | |
85 | { | |
86 | int yn = yesno (IDS_OLD_SETUPINI); | |
87 | if (yn == IDNO) | |
89b1a15b | 88 | exit_setup (1); |
04d6e06b | 89 | } |
23c9e63c | 90 | } |
04d6e06b | 91 | if (setup_timestamp) |
23c9e63c | 92 | { |
04d6e06b DD |
93 | FILE *nts = fopen (concat (root_dir, "/etc/setup/timestamp", 0), "wt"); |
94 | if (nts) | |
95 | { | |
96 | fprintf (nts, "%u", setup_timestamp); | |
97 | fclose (nts); | |
98 | } | |
23c9e63c DD |
99 | } |
100 | } | |
101 | ||
713bbe5f | 102 | next_dialog = IDD_CHOOSE; |
23c9e63c DD |
103 | } |
104 | ||
b11b49f3 DD |
105 | extern int yylineno; |
106 | ||
107 | extern "C" int yyerror (char *s, ...) | |
23c9e63c | 108 | { |
b11b49f3 DD |
109 | char buf[1000]; |
110 | int len; | |
111 | sprintf (buf, "setup.ini line %d: ", yylineno); | |
112 | va_list args; | |
113 | va_start (args, s); | |
114 | vsprintf (buf + strlen (buf), s, args); | |
115 | OutputDebugString (buf); | |
116 | if (error_buf) | |
117 | { | |
118 | strcat (error_buf, "\n"); | |
119 | len = strlen (error_buf) + strlen (buf) + 5; | |
120 | error_buf = (char *) realloc (error_buf, len); | |
121 | strcat (error_buf, buf); | |
122 | } | |
123 | else | |
124 | { | |
125 | len = strlen (buf) + 5; | |
126 | error_buf = (char *) malloc (len); | |
127 | strcpy (error_buf, buf); | |
128 | } | |
129 | error_count++; | |
23c9e63c DD |
130 | } |
131 | ||
1fd6d0a2 | 132 | extern "C" int fprintf (FILE *f, const char *s, ...); |
23c9e63c | 133 | |
b11b49f3 DD |
134 | static char stderrbuf[1000]; |
135 | ||
23c9e63c | 136 | int |
1fd6d0a2 | 137 | fprintf (FILE *f, const char *fmt, ...) |
23c9e63c DD |
138 | { |
139 | char buf[1000]; | |
140 | int rv; | |
141 | va_list args; | |
142 | va_start (args, fmt); | |
143 | if (f == stderr) | |
144 | { | |
145 | rv = vsprintf (buf, fmt, args); | |
b11b49f3 DD |
146 | strcat (stderrbuf, buf); |
147 | if (char *nl = strchr (stderrbuf, '\n')) | |
148 | { | |
149 | *nl = 0; | |
150 | /*OutputDebugString (stderrbuf);*/ | |
151 | MessageBox (0, buf, "Cygwin Setup", 0); | |
152 | stderrbuf[0] = 0; | |
153 | } | |
154 | ||
23c9e63c DD |
155 | } |
156 | else | |
157 | { | |
158 | rv = vfprintf (f, fmt, args); | |
159 | } | |
160 | return rv; | |
161 | } |