📄 cygcheck.cc
字号:
*eq = 0; if (strcasecmp (environ[i], known_env_vars[j]) == 0) found = 1; *eq = '='; } if (!found) { *eq = 0; printf ("%s = `%s'\n", environ[i], eq + 1); *eq = '='; } } printf ("\n"); } if (registry) { if (givehelp) printf ("Scanning registry for keys with `Cygnus' in them...\n");#if 0 /* big and not generally useful */ scan_registry (0, HKEY_CLASSES_ROOT, (char *) "HKEY_CLASSES_ROOT", 0);#endif scan_registry (0, HKEY_CURRENT_CONFIG, (char *) "HKEY_CURRENT_CONFIG", 0); scan_registry (0, HKEY_CURRENT_USER, (char *) "HKEY_CURRENT_USER", 0); scan_registry (0, HKEY_LOCAL_MACHINE, (char *) "HKEY_LOCAL_MACHINE", 0);#if 0 /* the parts we need are duplicated in HKEY_CURRENT_USER anyway */ scan_registry (0, HKEY_USERS, (char *) "HKEY_USERS", 0);#endif printf ("\n"); } else printf ("Use `-r' to scan registry\n\n"); if (givehelp) { printf ("Listing available drives...\n"); printf ("Drv Type Size Free Flags Name\n"); } int prev_mode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); int drivemask = GetLogicalDrives (); HINSTANCE k32 = LoadLibrary ("kernel32.dll"); BOOL (WINAPI * gdfse) (LPCSTR, long long *, long long *, long long *) = (BOOL (WINAPI *) (LPCSTR, long long *, long long *, long long *)) GetProcAddress (k32, "GetDiskFreeSpaceExA"); for (i = 0; i < 26; i++) { if (!(drivemask & (1 << i))) continue; char drive[4], name[200], fsname[200]; DWORD serno = 0, maxnamelen = 0, flags = 0; name[0] = name[0] = fsname[0] = 0; sprintf (drive, "%c:\\", i + 'a'); /* Report all errors, except if the Volume is ERROR_NOT_READY. ERROR_NOT_READY is returned when removeable media drives are empty (CD, floppy, etc.) */ if (!GetVolumeInformation (drive, name, sizeof (name), &serno, &maxnamelen, &flags, fsname, sizeof (fsname)) && GetLastError () != ERROR_NOT_READY) keyeprint ("dump_sysinfo: GetVolumeInformation()"); int dtype = GetDriveType (drive); char drive_type[4] = "unk"; switch (dtype) { case DRIVE_REMOVABLE: strcpy (drive_type, "fd "); break; case DRIVE_FIXED: strcpy (drive_type, "hd "); break; case DRIVE_REMOTE: strcpy (drive_type, "net"); break; case DRIVE_CDROM: strcpy (drive_type, "cd "); break; case DRIVE_RAMDISK: strcpy (drive_type, "ram"); break; default: strcpy (drive_type, "unk"); } long capacity_mb = -1; int percent_full = -1; long long free_me = 0ULL, free_bytes = 0ULL, total_bytes = 1ULL; if (gdfse != NULL && gdfse (drive, &free_me, &total_bytes, &free_bytes)) { capacity_mb = total_bytes / (1024L * 1024L); percent_full = 100 - (int) ((100.0 * free_me) / total_bytes); } else { DWORD spc = 0, bps = 0, fc = 0, tc = 1; if (GetDiskFreeSpace (drive, &spc, &bps, &fc, &tc)) { capacity_mb = (spc * bps * tc) / (1024 * 1024); percent_full = 100 - (int) ((100.0 * fc) / tc); } } printf ("%.2s %s %-6s ", drive, drive_type, fsname); if (capacity_mb >= 0) printf ("%5dMb %3d%% ", (int) capacity_mb, (int) percent_full); else printf (" N/A N/A "); printf ("%s %s %s %s %s %s %s\n", flags & FS_CASE_IS_PRESERVED ? "CP" : " ", flags & FS_CASE_SENSITIVE ? "CS" : " ", flags & FS_UNICODE_STORED_ON_DISK ? "UN" : " ", flags & FS_PERSISTENT_ACLS ? "PA" : " ", flags & FS_FILE_COMPRESSION ? "FC" : " ", flags & FS_VOL_IS_COMPRESSED ? "VC" : " ",#if 0 flags & FILE_SUPPORTS_ENCRYPTION ? "EN" : " ", flags & FILE_SUPPORTS_OBJECT_IDS ? "OI" : " ", flags & FILE_SUPPORTS_REPARSE_POINTS ? "RP" : " ", flags & FILE_SUPPORTS_SPARSE_FILES ? "SP" : " ", flags & FILE_VOLUME_QUOTAS ? "QU" : " ",#endif name); } if (!FreeLibrary (k32)) keyeprint ("dump_sysinfo: FreeLibrary()"); SetErrorMode (prev_mode); if (givehelp) { printf ("fd=floppy, hd=hard drive, cd=CD-ROM, net=Network Share\n"); printf ("CP=Case Preserving, CS=Case Sensitive, UN=Unicode\n"); printf ("PA=Persistent ACLS, FC=File Compression, VC=Volume Compression\n"); } printf ("\n"); unsigned ml_fsname = 4, ml_dir = 7, ml_type = 6; struct mntent *mnt; setmntent (0, 0); while ((mnt = getmntent (0))) { unsigned n = (int) strlen (mnt->mnt_fsname); if (ml_fsname < n) ml_fsname = n; n = (int) strlen (mnt->mnt_dir); if (ml_dir < n) ml_dir = n; } if (givehelp) { printf ("Mount entries: these map POSIX directories to your NT drives.\n"); printf ("%-*s %-*s %-*s %s\n", ml_fsname, "-NT-", ml_dir, "-POSIX-", ml_type, "-Type-", "-Flags-"); } setmntent (0, 0); while ((mnt = getmntent (0))) { printf ("%-*s %-*s %-*s %s\n", ml_fsname, mnt->mnt_fsname, ml_dir, mnt->mnt_dir, ml_type, mnt->mnt_type, mnt->mnt_opts); } printf ("\n"); add_path ((char *) "\\bin", 4); /* just in case */ if (givehelp) printf ("Looking to see where common programs can be found, if at all...\n"); for (i = 0; common_apps[i].name; i++) if (!find_on_path ((char *) common_apps[i].name, (char *) ".exe", 1, 0)) { if (common_apps[i].missing_is_good) printf ("Not Found: %s (good!)\n", common_apps[i].name); else printf ("Not Found: %s\n", common_apps[i].name); } printf ("\n"); if (givehelp) printf ("Looking for various Cygnus DLLs... (-v gives version info)\n"); for (i = 0; i < num_paths; i++) { WIN32_FIND_DATA ffinfo; sprintf (tmp, "%s/*.*", paths[i]); HANDLE ff = FindFirstFile (tmp, &ffinfo); int found = (ff != INVALID_HANDLE_VALUE); found_cygwin_dll = NULL; while (found) { char *f = ffinfo.cFileName; if (strcasecmp (f + strlen (f) - 4, ".dll") == 0) { if (strncasecmp (f, "cyg", 3) == 0) { sprintf (tmp, "%s\\%s", paths[i], f); if (strcasecmp (f, "cygwin1.dll") == 0) found_cygwin_dll = strdup (tmp); else ls (tmp); } } found = FindNextFile (ff, &ffinfo); } if (found_cygwin_dll) { ls (found_cygwin_dll); free (found_cygwin_dll); } FindClose (ff); }}static intcheck_keys (){ HANDLE h = CreateFileA ("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE || h == NULL) return (keyeprint ("check_key: Opening CONIN$")); DWORD mode; if (!GetConsoleMode (h, &mode)) keyeprint ("check_keys: GetConsoleMode()"); else { mode &= ~ENABLE_PROCESSED_INPUT; if (!SetConsoleMode (h, mode)) keyeprint ("check_keys: GetConsoleMode()"); } fputs ("\nThis key check works only in a console window,", stderr); fputs (" _NOT_ in a terminal session!\n", stderr); fputs ("Abort with Ctrl+C if in a terminal session.\n\n", stderr); fputs ("Press `q' to exit.\n", stderr); INPUT_RECORD in, prev_in; // Drop first <RETURN> key ReadConsoleInput (h, &in, 1, &mode); memset (&in, 0, sizeof in); do { prev_in = in; if (!ReadConsoleInput (h, &in, 1, &mode)) keyeprint ("ReadConsoleInput"); if (!memcmp (&in, &prev_in, sizeof in)) continue; switch (in.EventType) { case KEY_EVENT: printf ("%s %ux VK: 0x%02x VS: 0x%02x A: 0x%02x CTRL: ", in.Event.KeyEvent.bKeyDown ? "Pressed " : "Released", in.Event.KeyEvent.wRepeatCount, in.Event.KeyEvent.wVirtualKeyCode, in.Event.KeyEvent.wVirtualScanCode, (unsigned char) in.Event.KeyEvent.uChar.AsciiChar); fputs (in.Event.KeyEvent.dwControlKeyState & CAPSLOCK_ON ? "CL " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY ? "EK " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED ? "LA " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_CTRL_PRESSED ? "LC " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & NUMLOCK_ON ? "NL " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED ? "RA " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED ? "RC " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & SCROLLLOCK_ON ? "SL " : "-- ", stdout); fputs (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED ? "SH " : "-- ", stdout); fputc ('\n', stdout); break; default: break; } } while (in.EventType != KEY_EVENT || in.Event.KeyEvent.bKeyDown != FALSE || in.Event.KeyEvent.uChar.AsciiChar != 'q'); CloseHandle (h); return 0;}static voidusage (FILE * stream, int status){ fprintf (stream, "\Usage: cygcheck [OPTIONS] [program ...]\n\ -c, --check-setup check packages installed via setup.exe\n\ -s, --sysinfo system information (not with -k)\n\ -v, --verbose verbose output (indented) (for -s or programs)\n\ -r, --registry registry search (requires -s)\n\ -k, --keycheck perform a keyboard check session (not with -s)\n\ -h, --help give help about the info (not with -c)\n\ -V, --version output version information and exit\n\You must at least give either -s or -k or a program name\n"); exit (status);}struct option longopts[] = { {"check-setup", no_argument, NULL, 'c'}, {"sysinfo", no_argument, NULL, 's'}, {"registry", no_argument, NULL, 'r'}, {"verbose", no_argument, NULL, 'v'}, {"keycheck", no_argument, NULL, 'k'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, 0, 'V'}, {0, no_argument, NULL, 0}};static char opts[] = "chkrsvV";static voidprint_version (){ const char *v = strchr (version, ':'); int len; if (!v) { v = "?"; len = 1; } else { v += 2; len = strchr (v, ' ') - v; } printf ("\cygcheck version %.*s\n\System Checker for Cygwin\n\Copyright 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\Compiled on %s\n\", len, v, __DATE__);}intmain (int argc, char **argv){ int i; while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) switch (i) { case 's': sysinfo = 1; break; case 'c': check_setup = 1; break; case 'r': registry = 1; break; case 'v': verbose = 1; break; case 'k': keycheck = 1; break; case 'h': givehelp = 1; break; case 'V': print_version (); exit (0); default: usage (stderr, 1); /*NOTREACHED*/} argc -= optind; argv += optind; if (argc == 0 && !sysinfo && !keycheck && !check_setup) if (givehelp) usage (stdout, 0); else usage (stderr, 1); if ((check_setup || sysinfo) && keycheck) usage (stderr, 1); if (keycheck) return check_keys (); init_paths (); /* FIXME: Add help for check_setup */ if (argc >= 1 && givehelp && !check_setup) { if (argc == 1) { printf ("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) printf ("\n"); } if (check_setup) { dump_setup (verbose, argv, true); puts (""); } else for (i = 0; i < argc; i++) { cygcheck (argv[i]); puts (""); } if (sysinfo) { dump_sysinfo (); if (!check_setup) { puts (""); dump_setup (verbose, NULL, false); puts (""); } } if (!givehelp) puts ("Use -h to see help about each section"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -