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