* dump_setup.cc: New file.

* Makefile.in: Add info for dump_setup.o.
* cygcheck.cc (main): Recognize '-c' option for checking setup installed base.
* path.cc (cygpath): Read mount table if not loaded.
This commit is contained in:
Christopher Faylor 2001-11-11 06:07:36 +00:00
parent 2fac517df4
commit d0d517913c
5 changed files with 303 additions and 25 deletions

View File

@ -1,3 +1,11 @@
2001-11-11 Christopher Faylor <cgf@redhat.com>
* dump_setup.cc: New file.
* Makefile.in: Add info for dump_setup.o.
* cygcheck.cc (main): Recognize '-c' option for checking setup
installed base.
* path.cc (cygpath): Read mount table if not loaded.
2001-11-10 Christopher Faylor <cgf@redhat.com>
* Makefile.in (cygcheck.exe): Compile as -mno-cygwin executable.

View File

@ -94,12 +94,12 @@ else
$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,2,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
endif
cygcheck.exe: cygcheck.cc mingw_getopt.o path.o $(MINGW_DEP_LDLIBS)
cygcheck.exe: cygcheck.cc mingw_getopt.o path.o dump_setup.o $(MINGW_DEP_LDLIBS)
ifdef VERBOSE
$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,3,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,4,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
else
@echo $(CXX) -o $@ ${wordlist 1,2,$^} ${filter-out -B%, $(MINGW_CXXFLAGS) $(MINGW_LDFLAGS)};\
$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,3,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,4,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
endif
dumper.o: dumper.cc dumper.h
@ -143,6 +143,14 @@ else
${filter-out -I$(newlib_source)/%,$(COMPILE_CC)} $c -o $(@D)/$(basename $@)$o $(MINGW_CFLAGS) $<
endif
dump_setup.o: dump_setup.cc
ifdef VERBOSE
${filter-out -I$(newlib_source)/%,$(COMPILE_CC)} $c -o $(@D)/$(basename $@)$o $(MINGW_CFLAGS) $<
else
@echo $(CC) $c -o $(@D)/$(basename $@)$o $(MINGW_CFLAGS) ... $^;\
${filter-out -I$(newlib_source)/%,$(COMPILE_CC)} $c -o $(@D)/$(basename $@)$o $(MINGW_CFLAGS) $<
endif
clean:
rm -f *.o $(CLEAN_PROGS)

View File

@ -25,6 +25,7 @@ int registry = 0;
int sysinfo = 0;
int givehelp = 0;
int keycheck = 0;
int check_setup = 0;
#ifdef __GNUC__
typedef long long longlong;
@ -32,6 +33,8 @@ typedef long long longlong;
typedef __int64 longlong;
#endif
void dump_setup (int, char **);
const char *known_env_vars[] = {
"c_include_path",
"compiler_path",
@ -1191,6 +1194,7 @@ usage ()
}
struct option longopts[] = {
{"check-setup", no_argument, NULL, 'c'},
{"sysinfo", no_argument, NULL, 's'},
{"registry", no_argument, NULL, 'r'},
{"verbose", no_argument, NULL, 'v'},
@ -1199,7 +1203,7 @@ struct option longopts[] = {
{0, no_argument, NULL, 0}
};
char opts[] = "srvkh";
char opts[] = "srvkhc";
int
main (int argc, char **argv)
@ -1212,6 +1216,9 @@ main (int argc, char **argv)
case 's':
sysinfo = 1;
break;
case 'c':
check_setup = 1;
break;
case 'r':
registry = 1;
break;
@ -1230,10 +1237,10 @@ main (int argc, char **argv)
argc -= optind;
argv += optind;
if (argc == 0 && !sysinfo && !keycheck)
if (argc == 0 && !sysinfo && !keycheck && !check_setup)
usage ();
if (sysinfo && keycheck)
if ((check_setup || sysinfo) && keycheck)
usage ();
if (keycheck)
@ -1241,7 +1248,8 @@ main (int argc, char **argv)
init_paths ();
if (argc >= 1 && givehelp)
/* FIXME: Add help for check_setup */
if (argc >= 1 && givehelp && !check_setup)
{
if (argc == 1)
{
@ -1260,11 +1268,17 @@ main (int argc, char **argv)
printf ("\n");
}
for (i = 0; i < argc; i++)
if (check_setup)
{
cygcheck (argv[i]);
printf ("\n");
dump_setup (verbose, argv);
puts ("");
}
else
for (i = 0; i < argc; i++)
{
cygcheck (argv[i]);
puts ("");
}
if (sysinfo)
dump_sysinfo ();

251
winsup/utils/dump_setup.cc Normal file
View File

@ -0,0 +1,251 @@
/* path.cc
Copyright 2001 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include "path.h"
static int package_len = 20;
static int version_len = 20;
typedef struct
{
char pkgtar[MAX_PATH + 1];
char pkg[MAX_PATH + 1];
char ver[MAX_PATH + 1];
char tail[MAX_PATH + 1];
char what[16];
} fileparse;
static int
find_tar_ext (const char *path)
{
char *p = strchr (path, '\0') - 7;
if (p <= path)
return 0;
if (*p == '.')
{
if (strcmp (p, ".tar.gz") != 0)
return 0;
}
else if (--p <= path || strcmp (p, ".tar.bz2") != 0)
return 0;
return p - path;
}
static char *
base (const char *s)
{
if (!s)
return 0;
const char *rv = s;
while (*s)
{
if ((*s == '/' || *s == ':' || *s == '\\') && s[1])
rv = s + 1;
s++;
}
return (char *) rv;
}
/* Parse a filename into package, version, and extension components. */
int
parse_filename (const char *in_fn, fileparse& f)
{
char *p, *ver;
char fn[strlen (in_fn) + 1];
strcpy (fn, in_fn);
int n = find_tar_ext (fn);
if (!n)
return 0;
strcpy (f.tail, fn + n);
fn[n] = '\0';
f.pkg[0] = f.what[0] = '\0';
p = base (fn);
for (ver = p; *ver; ver++)
if (*ver == '-' || *ver == '_')
if (isdigit (ver[1]))
{
*ver++ = 0;
strcpy (f.pkg, p);
break;
}
else if (strcasecmp (ver, "-src") == 0 ||
strcasecmp (ver, "-patch") == 0)
{
*ver++ = 0;
strcpy (f.pkg, p);
strcpy (f.what, strlwr (ver));
strcpy (f.pkgtar, p);
strcat (f.pkgtar, f.tail);
ver = strchr (ver, '\0');
break;
}
if (!f.pkg[0])
strcpy (f.pkg, p);
if (!f.what[0])
{
int n;
p = strchr (ver, '\0');
strcpy (f.pkgtar, in_fn);
if ((p -= 4) >= ver && strcasecmp (p, "-src") == 0)
n = 4;
else if ((p -= 2) >= ver && strcasecmp (p, "-patch") == 0)
n = 6;
else
n = 0;
if (n)
{
strcpy (f.what, p + 1);
*p = '\0';
p = f.pkgtar + (p - fn) + n;
memmove (p - 4, p, strlen (p));
}
}
strcpy (f.ver, *ver ? ver : "0.0");
return 1;
}
static bool
dump_file (const char *msg, const char *fn)
{
char *path = cygpath ("/etc/setup/", fn, NULL);
FILE *fp = fopen (path, "rt");
bool printed;
char buf[4096];
if (!fp)
printed = false;
else if (!fgets (buf, 4096, fp))
printed = false;
{
char *p = strchr (buf, '\0');
printf ("%s%s%s", msg, buf, (p == buf) || p[-1] != '\n' ? "\n" : "");
printed = true;
}
if (fp)
fclose (fp);
return printed;
}
struct pkgver
{
char *name;
char *ver;
};
extern "C" {
int
compar (const void *a, const void *b)
{
const pkgver *pa = (const pkgver *) a;
const pkgver *pb = (const pkgver *) b;
return strcmp (pa->name, pb->name);
}
}
bool
match_argv (char **argv, const char *name)
{
if (!*argv)
return true;
for (char **a = argv; *a; a++)
if (strcasecmp (*a, name) == 0)
return true;
return false;
}
void
dump_setup (int verbose, char **argv)
{
char *setup = cygpath ("/etc/setup/installed.db", NULL);
FILE *fp = fopen (setup, "rt");
puts ("Cygwin Setup information");
if (fp == NULL)
goto err;
if (verbose)
{
bool need_nl = dump_file ("Last downloaded files to: ", "last-cache");
if (dump_file ("Last downloaded files from: ", "last-mirror") || need_nl)
puts ("");
}
if (!*argv)
if (!fp)
goto err;
int nlines;
nlines = 0;
char buf[4096];
while (fgets (buf, 4096, fp))
nlines += 2; /* potentially binary + source */
if (!nlines)
goto err;
rewind (fp);
pkgver *packages;
packages = (pkgver *) calloc (nlines, sizeof(packages[0]));
printf ("%-*s%-*s\n", package_len, "Package", version_len, "Version");
int n;
for (n = 0; fgets (buf, 4096, fp) && n < nlines;)
{
char *package = strtok (buf, " ");
if (!package || !*package || !match_argv (argv, package))
continue;
for (int i = 0; i < 2; i++)
{
fileparse f;
char *tar = strtok (NULL, " ");
if (!tar || !*tar || !parse_filename (tar, f))
break;
int len = strlen (package);
if (f.what[0])
len += strlen (f.what) + 1;
packages[n].name = (char *) malloc (len + 1);
strcpy (packages[n].name , package);
if (f.what[0])
strcat (strcat (packages[n].name, "-"), f.what);
packages[n].ver = strdup (f.ver);
n++;
if (strtok (NULL, " ") == NULL)
break;
}
}
if (!argv)
qsort (packages, n, sizeof (packages[0]), compar);
for (int i = 0; i < n; i++)
printf ("%-*s%-*s\n", package_len, packages[i].name,
version_len, packages[i].ver);
fclose (fp);
return;
err:
puts ("No setup information found");
if (fp)
fclose (fp);
return;
}

View File

@ -1,17 +1,12 @@
/*
* Copyright (c) 2000, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* A copy of the GNU General Public License can be found at
* http://www.gnu.org/
*
* Written by DJ Delorie <dj@cygnus.com>
*
*/
/* path.cc
Copyright 2001 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
/* The purpose of this file is to hide all the details about accessing
Cygwin's mount table. If the format or location of the mount table
@ -94,7 +89,7 @@ get_cygdrive (HKEY key, mnt *m, int issystem)
return m + 1;
}
void
static void
read_mounts ()
{
DWORD posix_path_size;
@ -277,6 +272,8 @@ cygpath (const char *s, ...)
int max_len = -1;
struct mnt *m, *match = NULL;
if (!mount_table[0].posix)
read_mounts ();
va_start (v, s);
char *path = vconcat (s, v);
if (strncmp (path, "./", 2) == 0)