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