* cygcheck.cc (main): Fix some formatting and help text printing.
* cygcheck.cc (find_package,list_package): New global variables. (usage): Add "--find-package" and "--list-package" options, reformat output. (longopts, opts): Add "--find-package" and "--list-package" options. (main): Process the "--find-package" and "--list-package" flags. Add new semantic checks. Add calls to find_package() and list_package(). * dump_setup.cc: Fix header comment. (match_argv): Change return type to int to distinguish between real matches and default ones. (open_package_list): New static function. (check_package_files): Factor out opening the package list file into open_package_list(). (get_packages): New static function. (dump_setup): Factor out getting a list of packages into get_packages(). (package_list, package_find): New global functions.
This commit is contained in:
		| @@ -1,3 +1,29 @@ | |||||||
|  | 2003-08-15  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* cygcheck.cc (main): Fix some formatting and help text printing. | ||||||
|  |  | ||||||
|  | 2003-08-15  Igor Pechtchanski  <pechtcha@cs.nyu.edu> | ||||||
|  |  | ||||||
|  | 	* cygcheck.cc (find_package,list_package): New global | ||||||
|  | 	variables. | ||||||
|  | 	(usage): Add "--find-package" and "--list-package" options, | ||||||
|  | 	reformat output. | ||||||
|  | 	(longopts, opts): Add "--find-package" and "--list-package" | ||||||
|  | 	options. | ||||||
|  | 	(main): Process the "--find-package" and "--list-package" | ||||||
|  | 	flags.  Add new semantic checks.  Add calls to find_package() | ||||||
|  | 	and list_package(). | ||||||
|  | 	* dump_setup.cc: Fix header comment. | ||||||
|  | 	(match_argv): Change return type to int to distinguish | ||||||
|  | 	between real matches and default ones. | ||||||
|  | 	(open_package_list): New static function. | ||||||
|  | 	(check_package_files): Factor out opening the package list | ||||||
|  | 	file into open_package_list(). | ||||||
|  | 	(get_packages): New static function. | ||||||
|  | 	(dump_setup): Factor out getting a list of packages into | ||||||
|  | 	get_packages(). | ||||||
|  | 	(package_list, package_find): New global functions. | ||||||
|  |  | ||||||
| 2003-08-15  Corinna Vinschen  <corinna@vinschen.de> | 2003-08-15  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* regtool.cc (usage): Add missing linefeed.  Move example to --help | 	* regtool.cc (usage): Add missing linefeed.  Move example to --help | ||||||
|   | |||||||
| @@ -26,6 +26,8 @@ int sysinfo = 0; | |||||||
| int givehelp = 0; | int givehelp = 0; | ||||||
| int keycheck = 0; | int keycheck = 0; | ||||||
| int check_setup = 0; | int check_setup = 0; | ||||||
|  | int find_package = 0; | ||||||
|  | int list_package = 0; | ||||||
|  |  | ||||||
| #ifdef __GNUC__ | #ifdef __GNUC__ | ||||||
| typedef long long longlong; | typedef long long longlong; | ||||||
| @@ -34,6 +36,8 @@ typedef __int64 longlong; | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| void dump_setup (int, char **, bool); | void dump_setup (int, char **, bool); | ||||||
|  | void package_find (int, char **); | ||||||
|  | void package_list (int, char **); | ||||||
|  |  | ||||||
| static const char version[] = "$Revision$"; | static const char version[] = "$Revision$"; | ||||||
|  |  | ||||||
| @@ -1317,13 +1321,15 @@ usage (FILE * stream, int status) | |||||||
| Usage: cygcheck [OPTIONS] [PROGRAM...]\n\ | Usage: cygcheck [OPTIONS] [PROGRAM...]\n\ | ||||||
| Check system information or PROGRAM library dependencies\n\ | Check system information or PROGRAM library dependencies\n\ | ||||||
| \n\ | \n\ | ||||||
|  -c, --check-setup  check packages installed via setup.exe\n\ |  -c, --check-setup   check packages installed via setup.exe\n\ | ||||||
|  -s, --sysinfo      system information (not with -k)\n\ |  -s, --sysinfo       system information (not with -k)\n\ | ||||||
|  -v, --verbose      verbose output (indented) (for -s or programs)\n\ |  -v, --verbose       verbose output (indented) (for -s or programs)\n\ | ||||||
|  -r, --registry     registry search (requires -s)\n\ |  -r, --registry      registry search (requires -s)\n\ | ||||||
|  -k, --keycheck     perform a keyboard check session (not with -s)\n\ |  -k, --keycheck      perform a keyboard check session (not with -[scfl])\n\ | ||||||
|  -h, --help         give help about the info (not with -c)\n\ |  -f, --find-package  find installed packages containing files (not with -[cl])\n\ | ||||||
|  -V, --version      output version information and exit\n\ |  -l, --list-package  list the contents of installed packages (not with -[cf])\n\ | ||||||
|  |  -h, --help          give help about the info (not with -[cfl])\n\ | ||||||
|  |  -V, --version       output version information and exit\n\ | ||||||
| You must at least give either -s or -k or a program name\n"); | You must at least give either -s or -k or a program name\n"); | ||||||
|   exit (status); |   exit (status); | ||||||
| } | } | ||||||
| @@ -1334,12 +1340,14 @@ struct option longopts[] = { | |||||||
|   {"registry", no_argument, NULL, 'r'}, |   {"registry", no_argument, NULL, 'r'}, | ||||||
|   {"verbose", no_argument, NULL, 'v'}, |   {"verbose", no_argument, NULL, 'v'}, | ||||||
|   {"keycheck", no_argument, NULL, 'k'}, |   {"keycheck", no_argument, NULL, 'k'}, | ||||||
|  |   {"find-package", no_argument, NULL, 'f'}, | ||||||
|  |   {"list-package", no_argument, NULL, 'l'}, | ||||||
|   {"help", no_argument, NULL, 'h'}, |   {"help", no_argument, NULL, 'h'}, | ||||||
|   {"version", no_argument, 0, 'V'}, |   {"version", no_argument, 0, 'V'}, | ||||||
|   {0, no_argument, NULL, 0} |   {0, no_argument, NULL, 0} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| static char opts[] = "chkrsvV"; | static char opts[] = "cfhklrsvV"; | ||||||
|  |  | ||||||
| static void | static void | ||||||
| print_version () | print_version () | ||||||
| @@ -1387,6 +1395,12 @@ main (int argc, char **argv) | |||||||
|       case 'k': |       case 'k': | ||||||
| 	keycheck = 1; | 	keycheck = 1; | ||||||
| 	break; | 	break; | ||||||
|  |       case 'f': | ||||||
|  | 	find_package = 1; | ||||||
|  | 	break; | ||||||
|  |       case 'l': | ||||||
|  | 	list_package = 1; | ||||||
|  | 	break; | ||||||
|       case 'h': |       case 'h': | ||||||
| 	givehelp = 1; | 	givehelp = 1; | ||||||
| 	break; | 	break; | ||||||
| @@ -1405,7 +1419,13 @@ main (int argc, char **argv) | |||||||
|     else |     else | ||||||
|       usage (stderr, 1); |       usage (stderr, 1); | ||||||
|  |  | ||||||
|   if ((check_setup || sysinfo) && keycheck) |   if ((check_setup || sysinfo || find_package || list_package) && keycheck) | ||||||
|  |     usage (stderr, 1); | ||||||
|  |  | ||||||
|  |   if ((find_package || list_package) && check_setup) | ||||||
|  |     usage (stderr, 1); | ||||||
|  |  | ||||||
|  |   if (find_package && list_package) | ||||||
|     usage (stderr, 1); |     usage (stderr, 1); | ||||||
|  |  | ||||||
|   if (keycheck) |   if (keycheck) | ||||||
| @@ -1413,21 +1433,12 @@ main (int argc, char **argv) | |||||||
|  |  | ||||||
|   init_paths (); |   init_paths (); | ||||||
|  |  | ||||||
|   /* FIXME: Add help for check_setup */ |   /* FIXME: Add help for check_setup and {list,find}_package */ | ||||||
|   if (argc >= 1 && givehelp && !check_setup) |   if (argc >= 1 && givehelp && !check_setup && !find_package && !list_package) | ||||||
|     { |     { | ||||||
|       if (argc == 1) |       printf("Here is where the OS will find your program%s, and which dlls\n", | ||||||
| 	{ | 	     argc > 1 ? "s" : ""); | ||||||
| 	  printf |       printf ("will be used for it.  Use -v to see DLL version info\n"); | ||||||
| 	    ("Here is where the OS will find your program, and which dlls\n"); |  | ||||||
| 	  printf ("will be used for it.  Use -v to see DLL version info\n"); |  | ||||||
| 	} |  | ||||||
|       else |  | ||||||
| 	{ |  | ||||||
| 	  printf |  | ||||||
| 	    ("Here is where the OS will find your programs, and which dlls\n"); |  | ||||||
| 	  printf ("will be used for them.  Use -v to see DLL version info\n"); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
|       if (!sysinfo) |       if (!sysinfo) | ||||||
| 	printf ("\n"); | 	printf ("\n"); | ||||||
| @@ -1436,13 +1447,21 @@ main (int argc, char **argv) | |||||||
|   if (check_setup) |   if (check_setup) | ||||||
|     { |     { | ||||||
|       dump_setup (verbose, argv, true); |       dump_setup (verbose, argv, true); | ||||||
|       puts (""); |     } | ||||||
|  |   else if (find_package) | ||||||
|  |     { | ||||||
|  |       package_find (verbose, argv); | ||||||
|  |     } | ||||||
|  |   else if (list_package) | ||||||
|  |     { | ||||||
|  |       package_list (verbose, argv); | ||||||
|     } |     } | ||||||
|   else |   else | ||||||
|     for (i = 0; i < argc; i++) |     for (i = 0; i < argc; i++) | ||||||
|       { |       { | ||||||
|  | 	if (i) | ||||||
|  | 	  puts (""); | ||||||
| 	cygcheck (argv[i]); | 	cygcheck (argv[i]); | ||||||
| 	puts (""); |  | ||||||
|       } |       } | ||||||
|  |  | ||||||
|   if (sysinfo) |   if (sysinfo) | ||||||
| @@ -1452,12 +1471,11 @@ main (int argc, char **argv) | |||||||
| 	{ | 	{ | ||||||
| 	  puts (""); | 	  puts (""); | ||||||
| 	  dump_setup (verbose, NULL, false); | 	  dump_setup (verbose, NULL, false); | ||||||
| 	  puts (""); |  | ||||||
| 	} | 	} | ||||||
|     } |  | ||||||
|  |  | ||||||
|   if (!givehelp) |       if (!givehelp) | ||||||
|     puts ("Use -h to see help about each section"); | 	puts ("Use -h to see help about each section"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| /* path.cc | /* dump_setup.cc | ||||||
|  |  | ||||||
|    Copyright 2001 Red Hat, Inc. |    Copyright 2001 Red Hat, Inc. | ||||||
|  |  | ||||||
| @@ -165,15 +165,15 @@ compar (const void *a, const void *b) | |||||||
| } | } | ||||||
| } | } | ||||||
|  |  | ||||||
| bool | int | ||||||
| match_argv (char **argv, const char *name) | match_argv (char **argv, const char *name) | ||||||
| { | { | ||||||
|   if (!argv || !*argv) |   if (!argv || !*argv) | ||||||
|     return true; |     return -1; | ||||||
|   for (char **a = argv; *a; a++) |   for (char **a = argv; *a; a++) | ||||||
|     if (strcasecmp (*a, name) == 0) |     if (strcasecmp (*a, name) == 0) | ||||||
|       return true; |       return a - argv + 1; | ||||||
|   return false; |   return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static bool | static bool | ||||||
| @@ -234,17 +234,13 @@ file_exists (int verbose, char *filename, const char *alt, char *package) | |||||||
|   return true; |   return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| static bool | static FILE * | ||||||
| check_package_files (int verbose, char *package) | open_package_list (char *package) | ||||||
| { | { | ||||||
|   char filelist[MAX_PATH + 1] = "etc/setup/"; |   char filelist[MAX_PATH + 1] = "etc/setup/"; | ||||||
|   strcat (strcat (filelist, package), ".lst.gz"); |   strcat (strcat (filelist, package), ".lst.gz"); | ||||||
|   if (!file_exists (false, filelist, NULL, NULL)) |   if (!file_exists (false, filelist, NULL, NULL)) | ||||||
|     { |     return NULL; | ||||||
|       if (verbose) |  | ||||||
| 	printf ("Missing file list /%s for package %s\n", filelist, package); |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|   static char *zcat; |   static char *zcat; | ||||||
|   static char *zcat_end; |   static char *zcat_end; | ||||||
| @@ -260,6 +256,21 @@ check_package_files (int verbose, char *package) | |||||||
|   strcpy (zcat_end, filelist); |   strcpy (zcat_end, filelist); | ||||||
|   FILE *fp = popen (zcat, "rt"); |   FILE *fp = popen (zcat, "rt"); | ||||||
|  |  | ||||||
|  |   return fp; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static bool | ||||||
|  | check_package_files (int verbose, char *package) | ||||||
|  | { | ||||||
|  |   FILE *fp = open_package_list (package); | ||||||
|  |   if (!fp) | ||||||
|  |     { | ||||||
|  |       if (verbose) | ||||||
|  | 	printf ("Can't open file list /etc/setup/%s.lst.gz for package %s\n", | ||||||
|  |                 package, package); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|   bool result = true; |   bool result = true; | ||||||
|   char buf[MAX_PATH + 1]; |   char buf[MAX_PATH + 1]; | ||||||
|   while (fgets (buf, MAX_PATH, fp)) |   while (fgets (buf, MAX_PATH, fp)) | ||||||
| @@ -286,25 +297,17 @@ check_package_files (int verbose, char *package) | |||||||
|   return result; |   return result; | ||||||
| } | } | ||||||
|  |  | ||||||
| void | /** | ||||||
| dump_setup (int verbose, char **argv, bool check_files) |  * Returns a calloc'd sorted list of packages or NULL if no info. | ||||||
| { |  * The last entry in the list is {NULL,NULL}. | ||||||
|  |  */ | ||||||
|  | static pkgver * | ||||||
|  | get_packages (char **argv) { | ||||||
|   char *setup = cygpath ("/etc/setup/installed.db", NULL); |   char *setup = cygpath ("/etc/setup/installed.db", NULL); | ||||||
|   FILE *fp = fopen (setup, "rt"); |   FILE *fp = fopen (setup, "rt"); | ||||||
|  |  | ||||||
|   puts ("Cygwin Package Information"); |  | ||||||
|   if (fp == NULL) |   if (fp == NULL) | ||||||
|     { |     return NULL; | ||||||
|       puts ("No package information found"); |  | ||||||
|       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 (""); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|   int nlines; |   int nlines; | ||||||
|   nlines = 0; |   nlines = 0; | ||||||
| @@ -312,12 +315,15 @@ dump_setup (int verbose, char **argv, bool check_files) | |||||||
|   while (fgets (buf, 4096, fp)) |   while (fgets (buf, 4096, fp)) | ||||||
|     nlines += 2;	/* potentially binary + source */ |     nlines += 2;	/* potentially binary + source */ | ||||||
|   if (!nlines) |   if (!nlines) | ||||||
|     goto err; |     { | ||||||
|  |       fclose (fp); | ||||||
|  |       return NULL; | ||||||
|  |     } | ||||||
|   rewind (fp); |   rewind (fp); | ||||||
|  |  | ||||||
|   pkgver *packages; |   pkgver *packages; | ||||||
|  |  | ||||||
|   packages = (pkgver *) calloc (nlines, sizeof(packages[0])); |   packages = (pkgver *) calloc (nlines + 1, sizeof(packages[0])); | ||||||
|   int n; |   int n; | ||||||
|   for (n = 0; fgets (buf, 4096, fp) && n < nlines;) |   for (n = 0; fgets (buf, 4096, fp) && n < nlines;) | ||||||
|     { |     { | ||||||
| @@ -349,23 +355,139 @@ dump_setup (int verbose, char **argv, bool check_files) | |||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |   packages[n].name = packages[n].ver = NULL; | ||||||
|  |  | ||||||
|   qsort (packages, n, sizeof (packages[0]), compar); |   qsort (packages, n, sizeof (packages[0]), compar); | ||||||
|  |  | ||||||
|  |   fclose (fp); | ||||||
|  |  | ||||||
|  |   return packages; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | dump_setup (int verbose, char **argv, bool check_files) | ||||||
|  | { | ||||||
|  |   pkgver *packages = get_packages(argv); | ||||||
|  |  | ||||||
|  |   puts ("Cygwin Package Information"); | ||||||
|  |   if (packages == NULL) | ||||||
|  |     { | ||||||
|  |       puts ("No setup information found"); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   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 (""); | ||||||
|  |     } | ||||||
|  |  | ||||||
|   printf ("%-*s %-*s     %s\n", package_len, "Package", version_len, "Version", check_files?"Status":""); |   printf ("%-*s %-*s     %s\n", package_len, "Package", version_len, "Version", check_files?"Status":""); | ||||||
|   for (int i = 0; i < n; i++) |   for (int i = 0; packages[i].name; i++) | ||||||
|     { |     { | ||||||
|       printf ("%-*s %-*s     %s\n", package_len, packages[i].name, version_len, |       printf ("%-*s %-*s     %s\n", package_len, packages[i].name, version_len, | ||||||
| 	      packages[i].ver, check_files ? | 	      packages[i].ver, check_files ? | ||||||
| 	      (check_package_files (verbose, packages[i].name) ? "OK" : "Incomplete") : ""); | 	      (check_package_files (verbose, packages[i].name) ? "OK" : "Incomplete") : ""); | ||||||
|       fflush(stdout); |       fflush(stdout); | ||||||
|     } |     } | ||||||
|   fclose (fp); |  | ||||||
|  |  | ||||||
|   return; |   free (packages); | ||||||
|  |  | ||||||
| err: |  | ||||||
|   puts ("No setup information found"); |  | ||||||
|   if (fp) |  | ||||||
|     fclose (fp); |  | ||||||
|   return; |   return; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | package_list (int verbose, char **argv) | ||||||
|  | { | ||||||
|  |   pkgver *packages = get_packages(argv); | ||||||
|  |   if (packages == NULL) | ||||||
|  |     { | ||||||
|  |       puts ("No setup information found"); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   for (int i = 0; packages[i].name; i++) | ||||||
|  |     { | ||||||
|  |       FILE *fp = open_package_list (packages[i].name); | ||||||
|  |       if (!fp) | ||||||
|  |       { | ||||||
|  | 	if (verbose) | ||||||
|  | 	  printf ("Can't open file list /etc/setup/%s.lst.gz for package %s\n", | ||||||
|  | 	      packages[i].name, packages[i].name); | ||||||
|  | 	return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       printf ("Package: %s-%s\n", packages[i].name, packages[i].ver); | ||||||
|  |  | ||||||
|  |       char buf[MAX_PATH + 1]; | ||||||
|  |       while (fgets (buf, MAX_PATH, fp)) | ||||||
|  | 	{ | ||||||
|  | 	  char *lastchar = strchr(buf, '\n'); | ||||||
|  | 	  if (lastchar[-1] != '/') | ||||||
|  | 	    printf ("    /%s", buf); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |       fclose (fp); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   free (packages); | ||||||
|  |  | ||||||
|  |   return; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | package_find (int verbose, char **argv) | ||||||
|  | { | ||||||
|  |   pkgver *packages = get_packages(NULL); | ||||||
|  |   if (packages == NULL) | ||||||
|  |     { | ||||||
|  |       puts ("No setup information found"); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   for (int i = 0; packages[i].name; i++) | ||||||
|  |     { | ||||||
|  |       FILE *fp = open_package_list (packages[i].name); | ||||||
|  |       if (!fp) | ||||||
|  |       { | ||||||
|  | 	if (verbose) | ||||||
|  | 	  printf ("Can't open file list /etc/setup/%s.lst.gz for package %s\n", | ||||||
|  | 	      packages[i].name, packages[i].name); | ||||||
|  | 	return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       char buf[MAX_PATH + 2]; | ||||||
|  |       buf[0] = '/'; | ||||||
|  |       while (fgets (buf + 1, MAX_PATH, fp)) | ||||||
|  | 	{ | ||||||
|  | 	  char *filename = strtok(buf, "\n"); | ||||||
|  | 	  int flen = strlen (filename); | ||||||
|  | 	  if (filename[flen - 1] != '/') | ||||||
|  | 	    { | ||||||
|  | 	      // FIXME: verify that /bin is mounted on /usr/bin; ditto for /lib | ||||||
|  | 	      bool is_alias = !strncmp(filename, "/usr/bin/", 9) || | ||||||
|  | 			      !strncmp(filename, "/usr/lib", 9); | ||||||
|  | 	      int a = match_argv (argv, filename); | ||||||
|  | 	      if (!a && is_alias) | ||||||
|  | 		a = match_argv (argv, filename + 4); | ||||||
|  | 	      if (!a && !strcmp(filename + flen - 4, ".exe")) | ||||||
|  | 		{ | ||||||
|  | 		  filename[flen - 4] = '\0'; | ||||||
|  | 		  a = match_argv (argv, filename); | ||||||
|  | 		} | ||||||
|  | 	      if (!a && is_alias) | ||||||
|  | 		a = match_argv (argv, filename + 4); | ||||||
|  | 	      if (a > 0) | ||||||
|  | 		printf ("%s-%s\n", packages[i].name, packages[i].ver); | ||||||
|  | 	    } | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |       fclose (fp); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   free (packages); | ||||||
|  |  | ||||||
|  |   return; | ||||||
|  | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user