di-4.52/0000755000175000017500000000000014421556642010155 5ustar bllblldi-4.52/features/0000755000175000017500000000000014421556642011773 5ustar bllblldi-4.52/features/checkbuild.dat0000644000175000017500000000127114421556642014563 0ustar bllblloutput none command awk nawk mawk gawk command cat command date command egrep command grep command mkdir command rm command sed command sort command touch command tr command uname command wc setint build_commands 0 if build_cmds _command_awk -a _command_cat -a _command_date -a \ _command_egrep -a _command_grep -a _command_mkdir -a \ _command_rm -a _command_sed -a \ _command_sort -a _command_touch -a \ _command_tr -a _command_uname -a _command_wc setint build_commands 1 endif if chk_build_cmds ! _setint_build_commands echo echo ** ERROR: The build requires the following commands: echo ** awk, bc, cat, egrep, grep, mkdir, rm, sed, sort, tr and wc echo exit endif di-4.52/features/dioptions.dat0000644000175000017500000000155414421556642014502 0ustar bllbll# This is the 'di' options file. # It will not be removed when the directory # is cleaned, so your settings will be saved. # # Once you have it set up, you can reuse it # to rebuild 'di' with your preferences. # # When a new version of 'di' is released, you # can copy this file over and rebuild. # # enable NLS? NLS=T # use windows API? WINAPI=F # # The default output format # # default: # DI_DEFAULT_FORMAT=smbuvpT # alternatives: # DI_DEFAULT_FORMAT=MbuvpT # # The default display size # k - kbytes # m - mbytes # g - gbytes # h - scaled alternative 1 (human readable) # H - scaled alternative 2 (human readable) # # default: # DI_DEFAULT_DISP_SIZE=H # # The environment variables: # CC, CFLAGS, LDFLAGS, LIBS, SHCFLAGS, SHLDFLAGS, # DC and DFLAGS # may be set here. If these variables are set in # the environment, they will override any settings # here. # di-4.52/features/checkperlbuild.dat0000644000175000017500000000126714421556642015453 0ustar bllblloutput none command awk nawk mawk gawk command cat command date command egrep command grep command mkdir command perl command pwd command rm command sed command sort command tr command uname setint build_commands 0 if build_cmds _command_awk -a _command_cat -a _command_egrep -a \ _command_grep -a _command_mkdir -a _command_perl -a \ _command_pwd -a _command_rm -a _command_sed -a \ _command_sort -a _command_tr -a _command_uname setint build_commands 1 endif if chk_build_cmds ! _setint_build_commands echo echo ** ERROR: The build requires the following commands: echo ** awk, cat, date, egrep, grep, mkdir, perl, pwd, rm, echo ** sed, sort, and tr echo exit endif di-4.52/features/checkinstall.dat0000644000175000017500000000100014421556642015120 0ustar bllblloutput none command chmod command cp command grep command ln command mkdir command mv command rm command sed setint install_commands 0 if install_cmds _command_chmod -a _command_cp -a _command_grep -a \ _command_ln -a _command_mkdir -a _command_mv -a _command_rm -a \ _command_sed setint install_commands 1 endif if chk_install_cmds ! _setint_install_commands echo echo ** ERROR: The install requires the following commands: echo ** chmod, cp, grep, ln, mkdir, mv, rm and sed echo exit endif di-4.52/di.10000644000175000017500000003150414421556642010636 0ustar bllbll.\" .\" di.1 .\" .\" Copyright 1994-2018 Brad Lanam Walnut Creek CA USA .\" .\" brad.lanam.di_at_gmail.com .\" .TH di 1 "17 Jan 2013" .SH Name di \- disk information .SH Synopsis .\" di [-AacghHjklLmnPqRtZ] [-B block-size] [-d display-size] [-f format] .\" [-I include-fstyp-list] [-s sort-type] [-w block-width] .\" [-W inode-width] [-x exclude-fstyp-list] [-X debug-level] .\" [-z zone-name] [file [...]] .B di [\fB\-AacghHjklLmnPqRtZ\fP] [\fB\-B\fP \fIblock\-size\fP] [\fB\-d\fP \fIdisplay\-size\fP] [\fB\-f\fP \fIformat\fP] [\fB\-I\fP \fIinclude\-fstyp\-list\fP] [\fB\-s\fP \fIsort\-type\fP] [\fB\-w\fP \fIblock\-width\fP] [\fB\-W\fP \fIinode\-width\fP] [\fB\-x\fP \fIexclude\-fstyp\-list\fP] [\fB\-X\fP \fIdebug-level\fP] [\fB\-z\fP \fIzone\-name\fP] [\fIfile\fP [...]] .PP .B mi .SH Description \fIdi\fP Displays usage information on mounted filesystems. Block values are reported in a human readable format. If the user or group has a disk quota, the values reported are adjusted according the quotas that apply to the user. .PP If \fIfile\fP is specified, the usage information for the partition on which \fIfile\fP is located is printed. .PP Unless the \-a flag is specified, the following mounted filesystems will not normally be displayed: filesystems with total space <= 0; loopback filesystems that are duplicates of other normally mounted filesystems (filesystem type of 'lofs' , 'none', or 'nullfs'); loopback filesystems that are part of a zone (Solaris); filesystems for which the system's ignore flag is set; filesystems that have a device name of 'tmpfs', 'cgroup' or 'swap'; filesystems that have a device name starting with 'com.apple.TimeMachine.'. .PP Filesystems that the user does not have permissions to access will not be displayed at all. .PP \fImi\fP Displays the mounted filesystem information. .PP Several options may be specified to control the output of \fIdi\fP and \fImi\fP: .TP .B \-A Print all fields (used for debugging). Mount points and device names are printed at full width. .TP .B \-a (compatibility: \fB\-\-all\fP) .br Prints all mounted devices (normally, those with 0 total space are not printed \- e.g. \fB/dev/proc\fP, \fB/dev/fd\fP). .TP .B \-B .I block\-size (compatibility: \fB\-\-block\-size\fP, \fB\-b\fP) .br Change the base block size from 1024 (default) to the size specified. \fIblock\-size\fP may be one of: k\ \-\ 1024 bytes, si\ \-\ 1000 bytes, or a specific size. .TP .B \-c (alias: \fB\-\-csv\-output\fP) .br Comma separated values are output. The titles are output as the format string specifiers. Totals are turned off. See also the \-n flag. .TP .B \-C (alias: \fB\-\-csv\-tabs\fP) .br Values are output with tab separators. See also the \-c option. .TP .B \-d .I display\-size (alias: \fB\-\-display\-size\fP) .br Display the usage in units specified by \fIdisplay\-size\fP. Note that if the base block size is SI units of 1000 bytes, the display size is calculated using those units. \fIdisplay\-size\fP may be one of: 512\ \-\ POSIX, k\ \-\ kilobytes, m\ \-\ megabytes, g\ \-\ gigabytes, t\ \-\ terabytes, p\ \-\ petabytes, e\ \-\ exabytes, z\ \-\ zettabytes, y\ \-\ yottabytes, h\ \-\ Scaled alternative 1, H\ \-\ Scaled alternative 2, or a specific value to use as the block size. .IP Block display sizes greater than 1024 bytes are displayed with a precision of one decimal place after the radix. .IP The Scaled alternatives scale the sizes displayed and appends a suffix (e.g. 48.0k, 3.4M). .IP With scaled alternative 1, sizes within a line may scale to different units. .IP Scaled alternative 2 scales all the sizes in each individual line to the same unit size (the largest needed). .TP .B \-f .I format Use the specified format string \fIformat\fP. See the \fBFormat Strings\fP section. .TP .B \-g (alias for: \fB\-dg\fP) .br Display sizes in gigabytes. .TP .B \-h (alias for: \fB\-dh\fP) .br Display partition sizes in scaled alternative 1 format. .TP .B \-\-help .br Display some basic usage information. .TP .B \-H (alias for: \fB\-dH\fP; compatibility: \fB\-\-human\-readable\fP) .br Display partition sizes in scaled alternative 2 format. .TP .B \-I .I include\-fstype\-list (compatibility: \fB\-F\fP, \fB\-\-type\fP) .br Include \fIonly\fP the file system types listed in \fIinclude\-fstyp\-list\fP. The list is a comma separated list of file system types. Multiple \-I options may be specified. If the 'fuse' filesystem type is specified, all fuse* filesystems will be included. .br e.g. \-I nfs,tmpfs or \-I nfs \-I tmpfs. .TP .B \-\-inodes Ignored. Use the \-f option. .TP .B \-j (alias: \fB\-\-json\-output\fP) .br The data is output as an array of json objects. Totals are turned off. Use of format specifiers that specify the same field will result in duplicated field names. (e.g. \fBp\fP, \fB1\fP, \fB2\fP) .TP .B \-k (alias for: \fB\-dk\fP) .br Display sizes in Kbytes. .TP .B \-l (compatibility: \fB\-\-local\fP) .br Display only local file systems. .TP .B \-L Turn off check for duplicate filesystems (loopback (lofs/none) mounts). .TP .B \-m (alias for: \fB\-dm\fP) .br Display sizes in megabytes. .TP .B \-n Do not print a header line above the list of file systems. Useful when parsing the output of \fIdi\fP. .TP .B \-\-no\-sync Ignored. .TP .B \-P (compatibility: \fB\-\-portability\fP) .br Output format is POSIX standard. 512 byte block size is the default. The \-k option may be used. .TP .B \-\-print\-type Ignored. Use the \-f option. .TP .B \-q Disable quota checks. .TP .B \-R (alias: \-\-dont\-resolve\-symlinks) .br Do not resolve symlinks (for mount points that have a trailing UUID). .TP .B \-s .I sort\-type .br Use \fIsort\-type\fP to sort the output. The output of \fIdi\fP is normally sorted by mount point. The following sort flags may be used to change the sort order: \fBm\fP \- by mount point (default); \fBn\fP \- leave unsorted (as it appears in the mount table); \fBs\fP \- by device name; \fBT\fP \- by total space; \fBf\fP \- by free space; \fBa\fP \- by available space; \fBt\fP \- by filesystem type; \fBr\fP \- reverse the sort order; This will apply to all sort flags following this sort flag. .IP These sort options may be combined in any order. e.g.: .RS di \-stsrm # by type, device name, reversed mount; .br di \-strsrm # by type, reversed device-name, mount. .RE .TP .B \-\-si An alias for \fB-dH -Bsi\fP. .TP .B \-\-sync Ignored. .TP .B \-t (compatibility: \fB\-\-total\fP) .br Print a totals line below the list of file systems. Pooled filesystems (zfs, advfs) have only the main pool added to the total. Pooled filesystems that do not have pool information available (btrfs, apfs) will not total up correctly. It is up to the user to exclude (using the \-x option) read\-only filesystems (cdfs, iso9660), swap-based (memfs, mfs, tmpfs) filesystems and user (fuse*) filesystems. Excluding the 'fuse' filesystem will exclude all fuse* filesystems. .TP .B \-w .I block\-width .br Set the print width for block values. The default is eight. .TP .B \-v Ignored. .TP .B \-\-version .br Display di's version and default format string. .TP .B \-W .I inode\-width .br Set the print width for inode values. Default is seven. .TP .B \-x .I exclude\-fstype\-list (compatibility: \fB\-\-exclude\-type\fP) .br Exclude the file system types listed in \fIexclude\-fstyp\-list\fP. The list is a comma separated list of file system types. Multiple \-x options may be specified. If the 'fuse' filesystem type is excluded, all fuse* filesystems will be excluded. e.g. \-x nfs,tmpfs or \-x nfs \-x tmpfs. .TP .B \-X .I level .br Set the program's debugging level to \fIdebug-level\fP. .TP .B \-z .I zone-name .br Display the filesystems for the specified zone. The zone must be visible to the user. .TP .B \-Z (alias for: \fB\-z all\fP) .br Display the filesystems for all visible zones. .SH Format Strings The output of \fIdi\fP may be specified via a format string. This string may be given either via the \fB-f\fP command line option or as part of the \fBDI_ARGS\fP environment variable. The format string may specify the following columns: .RS .5 .TP .B m Print the name of the mount point. .TP .B M Print the name of the mount point, at full length. The mount point is formatted to the maximum width necessary for the longest mount point name. .TP .B s Print the file system name (device name or remote mount point). .TP .B S Print the file system name (device name or remote mount point), at full length. The file system name is formatted to the maximum width necessary for the longest file system name. .TP .B t Print the file system type. .TP .B T Print the file system type at full length. The file system type is formatted to the maximum width necessary for the longest file system type. .TP .B Total Available .TP .B b Print the total number of megabytes on the file system. .TP .B B Print the total number of megabytes on the file system available for use by normal users. .TP .B In Use .TP .B u Print the number of megabytes in use on the file system (actual number of megabytes used = total \- free). .TP .B c Print the number of megabytes not available for use by normal users (total \- available). Note that this calculation does work correctly the 'apfs' filesystem. .TP .B Free .TP .B f Print the number of free (unused) megabytes on the file system. .TP .B v Print the number of megabytes available for use by normal users. .TP .B Percentage Used .TP .B p Print the percentage of megabytes not available for use by normal users (number of megabytes not available for use / total disk space). .TP .B 1 Print the percentage of total megabytes in use (actual number of megabytes used / total disk space). .TP .B 2 Print the percentage of megabytes in use, BSD-style. Represents the percentage of user-available space in use. Note that values over 100% are possible (actual number of megabytes used / disk space available to non-root users). .TP .B Percentage Free .TP .B a Print the percentage of megabytes available for use by normal users (number of megabytes available for use / total disk space). .TP .B 3 Print the percentage of total megabytes free (actual number of megabytes free / total disk space). .TP .B Inodes .TP .B i Print the total number of file slots (inodes) that can be created on the file system. .TP .B U Print the number of file slots in use. .TP .B F Print the number of file slots available. .TP .B P Print the percentage of file slots in use. .TP .B Mount Information .TP .B I Print the time the filesystem was mounted. This column is not supported on all systems. .TP .B O Print the filesystem mount options. .RE .PP The default format string for \fIdi\fP is \fBsmbuvpT\fP. .PP The default format string for \fImi\fP is \fBMSTIO\fP. .PP The format string may also contain any other character not listed above. The character will be printed as is. e.g. di \-f 'mbuvp|iUFP' will print the character '|' between the disk usage and the file slot usage. The command sequence: .RS .br di \-f 'mbuvp .br miUFP' .br .RE will print two lines of data for each filesystem. .SH Examples Various \fIdf\fP equivalent format strings for System V release 4 are: .RS \fI/usr/bin/df \-v\fP di \-P \-f msbuf1 .br \fI/usr/bin/df \-k\fP di \-dk \-f sbcvpm .br \fI/usr/ucb/df\fP di \-dk \-f sbuv2m .RE GNU df: .RS \fIdf\fP di \-dk \-f SbuvpM \-w 10 .br \fIdf \-T\fP di \-dk \-f STbuvpM \-w 10 .RE AIX df: .RS \fIdf\fP di \-d 512 \-f Sbf1UPM \-w 10 .br \fIdf \-I\fP di -d 512 \-f Sbuf1M .br \fIdf \-I \-M\fP di \-d 512 \-f SMbuf1 \-w 10 .RE HP-UX bdf: .RS \fIbdf\fP di \-d k \-f Sbuv2M .br \fIbdf \-i\fP di \-d k \-f Sbuv2UFPM .RE .PP If you like your numbers to add up/calculate the percentage correctly, try one of the following format strings: .PP .RS di \-f SMbuf1T .br di \-f SMbcvpT .br di \-f SMBuv2T .RE .SH Environment Variables The DI_ARGS environment variable may be used to specify command line arguments. e.g. If you always want gigabytes displayed, set DI_ARGS equal to "\-dg". Any command line arguments specified will override the DI_ARGS environment variable. .PP The DI_LOCALE_DIR environment variable may be used to specify the location of the di program's locale message files. .PP The GNU df POSIXLY_CORRECT, and DF_BLOCK_SIZE and the BSD BLOCKSIZE environment variables are honored. .SH Note For filesystems that do not report available space (e.g. System V release 3), the number of available space is set to the free space. .SH WARNING Do not replace your system's \fIdf\fP command with this program. You will in all likelihood break your installation procedures. .SH See Also df(1), fstab(5), getmnt(2), getmntinfo(2), mnttab(4), mount(1M) statfs(2), statvfs(2) .SH Bugs Send bug reports to: brad.lanam.di @ gmail.com .PP Known Issues: .PP di will probably not process a zettabyte or yottabyte sized filesystem properly due to overflow of a long long. .SH Website https://diskinfo-di.sourceforge.io/ .SH Author This program is Copyright 1994-2021 by Brad Lanam. .PP Brad Lanam, Pleasant Hill, CA (brad.lanam.di @ gmail.com) di-4.52/ChangeLog.txt0000644000175000017500000006063114421556642012553 0ustar bllbllCHANGES 4.52 -- Makefile cleanup. Remove D Language targets. Makefile cleanup. Remove support for K&R compilers and ancient systems. Mac OS: apfs filesystems with a mount point starting with /System/ are ignored by default. Fix debug output for env vars. DI_ARGS: print error and exit when encountering unknown data. 4.51 2021-11-8 Handle permission denied errors. 4.50 2021-4-5 JSON: Exclude extraneous format characters from the json output. JSON: Fix quoting around human-readable values. Totals: Support APFS filesystem. Mac OS: Put time machine filesystems on the ignore list. Linux: Put filesytems using 'tmpfs' or 'cgroup' as the device name on the ignore list. Solaris: Put filesystems using 'swap' as the device name on the ignore list. 4.49 2021-3-16 Added the -j (--json-output) option to output json data. Internal code cleanup. 4.48.0.1 2021-1-30 Update di.spec. Update mkconfig to version 2.6.3. 4.48 2020-6-3 disable spurious compiler warnings. Various build fixes. make test no longer fails if perl is not present. Updated mkconfig to version 2.3. 4.47.3 2019-12-23 Fixed missing link flags for clang. 4.47.2 2019-10-30 Minor makefile cleanup. 4.47.1 2019-6-25 Update mkconfig to version 2.1.1 (fixes build on 32-bit). Add configs/config.ms.cl (visual studio definitions). 4.47 2018-8-12 Fixed bugs located by scan.coverity.com. This should fix a numeric sort bug. Update mkconfig to version 2.0.0 and make changes to support it. Get perl extension build working again. 4.46 2018-4-11 Tcl: Fix bad allocation. Tcl: Raise errors rather than exiting. Exit program when incorrect options are specified. Update mkconfig to version 1.31. Add missing mkconfig/runtests.sh. 4.45 2018-4-10 Update mkconfig to version 1.30 to fix modern libintl.h/printf tests. 4.44 2017-5-23 Fixed check of exabyte sized filesystems. The signed check now only checks for -1 and -2; there could still be situations where the overflow exactly matches these values. Added faster method for windows check for missing removable filesystems. 4.43 2016-8-9 Cleaned up some compiler warnings. Fixed memory allocation problem. Tcl interface fixes 4.42 2016-2-22 Fixed a parsing bug in the Tcl interface. Added a Perl interface. 4.41 2016-1-24 Fixed bug specifying more than one filesystem on the command line. Added sort by free space, total space. Updated manual page: missing, new sort options. 4.40 2016-1-22 Updated the Tcl interface to return the 'display' key as a list. 4.39 2016-1-22 Added a Tcl interface. Fixed CSV header to honor -n flag. Added -C, --csv-tabs to output CSV with tabs. Fixes for mingw (build, long double can't be printf'd). Update mkconfig to version 1.27 4.38 2016-1-6 Honor FreeBSD NO_PIE environment variable. Update mkconfig to version 1.26 4.37 2015-10-18 Fixed a problem when processing the DI_ARGS environment variable. Hardened compiler options: reference: http://wiki.debian.org/Hardening Code cleanup to fix compiler warnings. 4.36 2015-5-18 Updated test for NFS remote filesystems. 4.35 2014-2-15 Updates for Irix. Fixed a bug when -I/-x were specified in addition to a filespec. Updated build system to mkconfig-1.24 4.34 2013-1-19 When a filename is specified on the command line, attempt to choose the best filesystem to display when there are multiple choices. Error check realpath() return value. Only canonicalize device names if it has a trailing uuid. Add -R (--dont-resolve-symlink) option to turn off canonicalization. Clean up code to fix clang warnings. Minor updates to support Xenix. 4.33 2012-11-15 Recoded quota handling as information was improperly losing precision. Added support for dragonflybsd's vquotactl(). Added support for hammer-pfs (pooled filesystems). Exclude rootfs, devfs, procfs, kernfs, ptyfs and devtmpfs by default. Minor updates to main makefile. Minor directory rearrangement for os-specific config files. Fixed possible case of systems with a memcpy macro and no library function. Make sure D tests are not run. HP-UX bcc seems to support long long after all. This is on 11.11. Maybe the older versions did not? No access to 10.20. Updated build system to mkconfig-1.22. 4.32 2012-10-21 Exclude rootfs by default. Canonacalize the special device name. Updated quota code for NetBSD 6 (quota_open() et.al.). Fixed AIX group quota check. Fixed AIX 7 support. Unlike AIX 5, AIX 7 gives a permission denied error when a user tries to get their quota. Updated build system to mkconfig-1.21. 4.31 2011-11-20 Filesystems that would return a 'Permission Denied' are not displayed at all, even with -a. Fixed totals with pooled filesystems (when main pool not mounted). Fixed a very rare divide by 0 condition. Code cleanup. Updated build system to mkconfig-1.19. 4.30 2011-10-8 Added support for long options. GNU df compatible long options have been added and are processed appropriately. Removed program name settings from Makefile and di.c. Minor code cleanup. Added hp-ux bundled cc static target. Updated build system to mkconfig-1.18. 4.29 2011-9-30 Added the -c option to output in CSV format (request by H.Merijn Brand). Fixed bB format titles. Added checks to make sure required programs for build/install are present. Various fixes for HP-UX, ULTRIX, SCO OpenServer, UnixWare. Added pre-generated config.h files for ULTRIX. Updated build system to mkconfig-1.17. 4.28 2011-9-11 Fixed compiler warnings for 64-bit. Added support for DragonFlyBSD. Updated build system to mkconfig-1.15 (Solaris 2.6 fixes; pdksh allowed) 4.27 2010-12-29 Rearranged directory structure. Added support for long double to hold zettas and yottas. Added support for the windows digital mars c compiler. Added a fix for windows removable drives. Rewrote snprintf macros as they didn't work on MacOSX. Fixed quotactl argument for systems w/o QCMD macro. Check for type of structure members and call the correct xdr function. Many minor fixes for compiler warnings. Fixed Makefiles to redirect 'cd' output (CDPATH). Updated build system to mkconfig 1.11. 4.26 2010-7-25 Fix FreeBSD 5 panic when trying to get quotas on devfs. Updated build system to mkconfig-1.10. 4.25 2010-7-4 Added support for quotas. Fix for Tru64 advfs pools. Fixed loopback filesystem (lofs/none) exclusion; enabled for all systems. Added an optional DI_LOCALE_DIR environment variable to point to the locale directory where di's messages are installed. Changed the sort to use strcoll() rather than strcmp(). Updated build system to mkconfig-1.6. Removed turnoffwinapi.sh, hasnls.sh & turnoffnls.sh and updated to use new build system tools. Added dioptions.dat to control options. More fixes for totals in a pooled/non-pooled mix when pooled filesystems are not displayed. 4.24 2010-5-14 Added spanish translation (David Sastre). Update some column widths to help support spanish. Check mbrlen() return code. Fix turnoffnls.sh (broken during rewrite). Add missing defines in static configurations. Added turnoffwinapi.sh for cygwin. 4.23 2010-5-10 Fix internationalized strings to line up properly. Changed default block size output to -dH (scaled format 2). Brought up to date for AIX, Tru64. Added support for MinGW on Windows. Added support for QNX. Solaris 8 x86 w/gcc3 currently fails. 4.22 2010-5-2 Updated to use mkconfig 1.3. Fixes problem with linking in unneeded libraries. Replaced hasnls program with a shell script. 4.21 2010-4-11 Fixed features/turnoffnls.sh. Makefile cleanup (Mike Frysinger). 4.20 2010-3-7 Added VMS. Fixed totals for pooled filesystems, again (incorrect sort, skipped fs, pooled fs on command line). Remove initial build script and use new mkconfig. Rewrite makefile. Moved mkconfig to its own package. Move regression tests into tests.d directory. Minor updates to manual page. 4.19 2010-2-1 Fix totals to add up when using small block sizes. Fix totals for mixed pooled and non-pooled filesystems. Add fix for automounted directories: https://bugzilla.redhat.com/show_bug.cgi?id=497830 (df) Builds on BSD 4.3. Changed format of config.h file. Code cleanup. 4.18 2009-11-29 Code cleanup. The default configuration method has been changed to use a shell script. The perl configuration script is still available (./Build -mkpl). 4.17 2009-11-22 Totals have been changed to add up whatever filesystems are displayed. This is more intuitive for the user. It is up to the user to exclude read-only filesystems (cdfs, iso9660), memory-based filesystems (memfs, mfs, tmpfs) and user filesystems (fuse*). Excluding the 'fuse' type will exclude all fuse* filesystems. As before, only the main pool of a pooled filesystem is totaled. The build now works on unixware (getmntent is in libgen). The build now works on syllable. The default configuration method has been changed to use the perl script. Removed iffe, as it doesn't support class testing. 4.16 2009-9-20 Fixed a nested macro issue on Mac OS X 10.6. Fixed bugs with filename arguments. 4.15 2009-9-17 Fixed filename argument w/non-printing filesystem. Build now works on Haiku. 4.14 2009-9-10 Code cleanup. Change size labels to match SI standards (1024 vs 1000). Build now works on Debian GNU-kFreeBSD. 4.13 2008-5-25 Fixed totals to correctly account for pooled filesystems. 4.12 19 Jan 2008 Change of e-mail addresses. 4.11 29 May 2007 Fixed minor bug for 'di -sn -t' introduced in 4.10. Code cleanup -- move global variables into local structures. Recoded sorting, added sort by filesystem type. 4.10 24 Feb 2007 Handle pooled filesystems so that the total space doesn't get added more than once. Compaq Tru64 advfs is untested. 4.9 2 Nov 2006 Fixed an uninitialized variable used for Solaris zones. Minor fixes to mkconfig.pl. 4.8 5 Oct 2006 Linux's statvfs() is not POSIX compliant and does not use f_frsize. The correct value is returned in f_bsize. Since there's no way to tell which type of statvfs() is in use, we have to hard-code the logic for linux. This sucks. More minor improvements to mkconfig.pl. Add logic to find the correct msgfmt program to use. 4.7 23 Sep 2006 Changed the operation of the -a, -x and -I flags so that it is possible to specify -a and still exclude filesystems from the list. Added the -L flag to not check for duplicate filesystems. 4.6 [3 Sep 2006] Improve mkconfig.pl configuration to be more robust, find needed libraries. Improve mkconfig.pl portability. 4.5 [29 Mar 2006] Fix uninitialized variable. Fix manual page formatting. 4.4 [21 Nov 2005] Add zone support for Solaris (-z). Update mkconfig.pl for compatibility w/perl 5.005. 4.3 [29 Oct 2005] Change -P option and POSIXLY_CORRECT environment variable to display POSIX standard output. Add 'a' and '3' format options to display %avail and %free space (request by Bill Poser). Add check and routine to use getvfsstat() for NetBSD 3.x. Add processing of DI_ARGS environment variable. 4.2 [12 Oct 2005] Added -nonls argument to 'Build' to turn off all NLS. Add +DAportable for HP-UX 10.x. Add -qmaxmem=-1 for AIX. Fix compile warning in dilib.c for AIX. Improve tests for libintl.sl for HP-UX. Check /usr/local for libintl.sl also. Version number was inadverdently left as 4.1. 4.1 [6 Aug 2005] Created a perl script as an alternative to iffe to create the config.h file. Internationalization configuration now works for Cygwin, FreeBSD, NetBSD and HP/UX. 4.0 [26 Jul 2005] Metadist is no longer supported; Only the iffe configuration method is now available. Removed -h help flag, changed it to be scaled alternative 1 display to match other 'df' programs. Alias -x to -i to match other 'df' programs. -x will be preferred. Old -x (debug) changed to -X. POSIX -dp flag was broken. Removed. Added -P option. Alias -F to -I for compatibility. Updates to manual page. Internationalization files are now automatically installed if the NLS routines are detected. 3.11 [11 mar 2004] Fixed bug: checking mount options to see if partition was read-only (bsd style get/set/endmntent). 3.10 [26 feb 2004] Added German .po file (Many thanks to Hartmut Haase). Added -64 to Build for 64 bit binaries. Added missing internationalization calls in di.c. 3.9 [25 may 2003] Fixed bug with uninitialized 'dbsstr' variable. iffe: upgraded to 2002-03-06. Don't need to include stdio.h in most di.iffe tests. lib test fixed for cygwin. 3.8 [12 jan 2003] Rewrote block size display processing. It did not match the *BSD implementation of the BLOCKSIZE environment variable. Latest metaconfig (Configure) Add -k alias for -dk. 3.7 [4 sep 2002] Check for initial '/' character in special device name before doing stat(). Otherwise we pick up normal files. Update iffe. Add exa, zetta, yotta support (-de, -dz, -dy). Add support for 1000 byte base block size (and others) (-b option). Add alternative scaled format (-dH, -H). 3.6 [30 jul 2002] Change to use mntctl() in preference to set/get/endmntent() for AIX. AIX: fix to display hostname in special device name for remote mounts. README updated for cygwin Configure/configure problem. Workaround in di.h for cygwin/Configure getopt() problem. Converted all strcpy() to strncpy(). 3.5 [17 jul 2002] Change 'memfs' to 'mfs' for memory file system (FreeBSD). Not added to totals. Added License. Update to use snprintf if available. Update 'Configure' to match 'iffe' build as closely as possible. Fix C code to compile w/non-ansi compiler (HP-UX bundled). Many configuration fixes (hp-ux, aix, et.al.). 3.4 [20 apr 2002] Fix bugs in include/ignore list generation. Rewrite ignore/include lists to allow multiple command line specification of ignore/include lists. Change so -f overrides DIFMT environment variable. Fix bugs in -s command line option. Make more friendly. Add -H (-dh) scaled display format. nfs mounts are always remote. 3.3 [1 apr 2002] Bug fixes for AIX, HP/UX installation. 3.2 [27 feb 2002] Add internationalization code. Update windows code. cleanup. 3.1 [15 nov 2001] Bug fixes for SunOS 4. 3.0 [7 aug 2001] Added getfsstat() for Compaq Tru-64 (and FreeBSD, etc.) systems. Compaq Tru-64 code cleaned up. Thanks to Compaq for their test drive program! More cleanup. Added iffe configuration. 2.4 [12 feb 2001] Fixed so di doesn't statfs() the disks it doesn't need to. Removed fs basetype stuff. Split out disk routines into separate module. Lots of cleanup. Totals: fix to take into account block size of partition. Totals: ignore read-only, partitions not normally printed. Totals: ignore memory filesystems (tmpfs, memfs). 2.3 [24 feb 2000] Modified hints for solaris to do 64 bit compilation. Removed extra libc setting for linux. Added support for BeOS. This required ansi function headers. 2.2 [24 dec 1999] Hints for dec_osf added. Changed HAS_GETMNTINFOFSIZE to be preferred over HAS_GETMNTINFOBSIZE; modified bsdos hints appropriately. Look for include file. 2.1 [24 dec 1999] Added +DAportable for HP-UX. Hints for openbsd added. Made installperm as separate target in makefile. Modified duplicate checking slightly. Changed MNT_NOWAIT to MNT_WAIT. This will work better on FreeBSD. Hopefully will work w/nfs mounts. 2.0 [15 apr 1999] Now uses dist 3.0PL70 for configuration. Duplicate filesystems (automounted) are not displayed. This probably does not work for Digital's advfs. 1.24 [never released] Added Windows w/gcc. The Solaris 2.6 statvfs() bug has a patch out for it. Patch #105572-05 (?). 1.23 [6 jul 1998] Improved Windows. 1.22 [1 jul 1998] Added Windows. Don't know the routines to get the number of file slots or the file system type (FAT12/16/32). Changed default to display megabytes. 1.21 [8 sep 1997] Fixed AIX typo. Linux 2.x 1.20 Added Solaris large file system support. Note that ver 2.6 Beta_Update has a bug in the statvfs() routine, and the non-root available disk space is improperly reported. 1.19 [4 feb 1996] Added mount time, mount options. Link di to the mi command. 1.18 [21 aug 1995] Fixed some ignore/include list problems. Fixed local mount flag for OSF/1. 1.17 [10 aug 1995] Changed block values from unsigned long to doubles so that we can display using different block sizes (-d flag). Added -l flag for local filesystems only. 1.16 [8 aug 1995] Added A/UX [ blemoine@-NOSPAM-atheist.tamu.edu (Brett G. Lemoine) ] Added convex [ "Schilperoort J.W." ] 1.15 [1 aug 1995] Fixed bsdi 1.x and bsdi 2.x. Fragments weren't supported. Fixed FreeBSD 1.x and 2.x; same problem. Changed sco_sl makefile entry. 1.14 [22 jul 1995] Fixed problem with display widths in conjunction with ignore/include lists. 1.13 [17 mar 1995] changed default length of filesystem type field to 7. new debug 'all' format. check for 0 fragment size; replace w/block size if we have it. 1.12 [28 jan 1995] sco nfs 'nothing' fix. freebsd 2.x; better freebsd filesystem types. 1.11 [3 dec 1994] bsdi 1.10 [24 nov 1994] added freebsd. 1.9 [30 aug 1994] makefile fixes. 1.8 [28 may 1994] removed mount option junk. added AIX. 1.7 [2 may 1994] cleaned up sgi in the makefile. changed linux to be w/o need_statfs_defs. solaris cdrom returning all sorts of negative values. T format option. mount options. SunOs filesystem type info. 1.6 [never released] ultrix bug fixes. add dynix to makefile. 1.5 [26 mar 1994] sun had f_bfree instead of f_bavail! xenix, linux, sco -w, -W, -B. fixed width for -f M, -f S. usage. Allow other characters in format string. 1.51 (local, pat@rwing) SunOS *does* support filesystem type info. Its all in the mntent structure, but requires a small bit of work (see source). 1.4 [4 mar 1994] -f B bcopy. solaris cdrom reports -2 for free blocks. 1.3 [3 mar 1994] Command line specification of filenames. sort output. osf/1, ultrix. -F, -f M, -F S. 1.2 [2 mar 1994] # of inodes can be -1L return code for getDiskInfo shouldn't be checked. name of mount point must be maxpathlen. error conditions. pyramid. 1.1 [27 feb 1994] initial release di-4.52/tests.d/0000755000175000017500000000000014421556642011541 5ustar bllblldi-4.52/tests.d/diexec.sh0000755000175000017500000000162514421556642013345 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'execute di' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ unset DI_ARGS unset DIFMT for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi tdir=$_MKCONFIG_RUNTOPDIR/$d ( cd $tdir if [ $? -eq 0 ]; then instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 fi ) if [ -x ${tdir}/di ]; then putsnonl " ${d}" >&5 ${tdir}/di grc=$? if [ $grc -ne 0 ]; then putsnonl "*" >&5 else # look for invalid floating point numbers ${tdir}/di -n | egrep '(inf|nan)' rc=$? if [ $rc -eq 0 ]; then putsnonl "*" >&5 grc=1 fi fi else if [ $d = C ]; then puts "## no di executable found for dir $d" grc=1 fi fi done exit $grc di-4.52/tests.d/diinst.sh0000755000175000017500000000213514421556642013373 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 install maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi tdir=$_MKCONFIG_RUNTOPDIR/$d ( cd $tdir if [ $? -eq 0 ]; then instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 fi ) if [ -x ${tdir}/di ]; then putsnonl " ${d}" >&5 cd ${tdir} grc=0 instdir="`pwd`/test_di" unset MAKEFLAGS ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} install rc=$? # leave a copy laying around...make realclean will clean it up set +f cp mkconfig.log mkconfig.cache mkc*.vars di.env di.reqlibs \ $_MKCONFIG_TSTRUNTMPDIR set -f if [ $rc -ne 0 ]; then grc=$rc; fi ${instdir}/bin/di rc=$? if [ $rc -ne 0 ]; then grc=$rc; fi if [ $grc -ne 0 ]; then putsnonl "*" >&5 fi else if [ $d = C ]; then puts "## no di executable found for dir $d" grc=1 fi fi done exit $grc di-4.52/tests.d/ditot.sh0000755000175000017500000000245014421556642013224 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'di totals' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ . $_MKCONFIG_DIR/bin/shellfuncs.sh testshcapability unset DI_ARGS unset DIFMT FORMATS="b B u c f v i U F" grc=0 for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi tdir=$_MKCONFIG_RUNTOPDIR/$d ( cd $tdir if [ $? -eq 0 ]; then instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all \ > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 fi ) if [ -x ${tdir}/di ]; then putsnonl " ${d}" >&5 for format in $FORMATS; do puts "Checking format: $format" # have to exclude zfs, null (dragonflybsd) # otherwise this test won't work. # include the normally excluded to get some data. # ctfs,objfs,sharefs have weird used inode counts (U) didata=`${tdir}/di -n -d1 -f $format -t -a -x apfs,null,zfs,ctfs,objfs,sharefs 2>/dev/null ` summtot=`(echo "0 ";echo $didata | sed 's/ */ + /g'; echo " - p") | dc` if [ $summtot -ne 0 ]; then putsnonl "*" >&5 puts "## format: $format failed" grc=1 fi done else if [ $d = C ]; then puts "## no di executable found for dir $d" grc=1 fi fi done exit $grc di-4.52/tests.d/disort.sh0000755000175000017500000000564214421556642013413 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'di sort' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ LC_ALL="C" export LC_ALL unset DI_ARGS unset DIFMT dotest () { chkdiff s1 s2 rc=$? if [ $rc -ne 0 ]; then echo "=== s1" cat s1 echo "=== s2" cat s2 fi if [ $rc -ne 0 ]; then grc=$rc fi } for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi tdir=$_MKCONFIG_RUNTOPDIR/$d ( cd $tdir if [ $? -eq 0 ]; then instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 fi ) if [ -x $tdir/di ]; then putsnonl " ${d}" >&5 puts "## regular sort first, then di sort" puts "by special" ${tdir}/di -n -a -f S | sort > s1 ${tdir}/di -n -a -f S -ss > s2 dotest puts "by special reverse" ${tdir}/di -n -a -f S | sort -r > s1 ${tdir}/di -n -a -f S -srs > s2 dotest puts "by special w/total" ${tdir}/di -n -a -f S | sort -t'~' > s1 ${tdir}/di -n -a -f S -ss -t | sed '$d' > s2 dotest puts "by special and mount w/total" ${tdir}/di -n -a -f 'S~M' | sort -t'~' > s1 ${tdir}/di -n -a -f 'S~M' -ssm -t | sed '$d' > s2 dotest puts "by mount" ${tdir}/di -n -a -f M | sort -t'~' > s1 ${tdir}/di -n -a -f M -sm > s2 dotest puts "by mount reverse" ${tdir}/di -n -a -f M | sort -r > s1 ${tdir}/di -n -a -f M -srm > s2 dotest puts "by mount w/total" ${tdir}/di -n -a -f M | sort -t'~' > s1 ${tdir}/di -n -a -f M -sm -t | sed '$d' > s2 dotest puts "by mount and special w/total" ${tdir}/di -n -a -f 'M~S' | sort -t'~' > s1 ${tdir}/di -n -a -f 'M~S' -sms -t | sed '$d' > s2 dotest puts "by type" ${tdir}/di -n -a -f T | sort > s1 ${tdir}/di -n -a -f T -st > s2 dotest puts "by type reverse" ${tdir}/di -n -a -f T | sort -r > s1 ${tdir}/di -n -a -f T -srt > s2 dotest puts "by type w/total" ${tdir}/di -n -a -f T | sort -t'~' > s1 ${tdir}/di -n -a -f T -st -t | sed '$d' > s2 dotest puts "by type and special and mount w/total" ${tdir}/di -n -a -f 'T~S~M' | sort -t'~' > s1 ${tdir}/di -n -a -f 'T~S~M' -stsm -t | sed '$d' > s2 dotest sort -k1 > /dev/null < /dev/null if [ $? = 0 ]; then puts "by type and special and mount reversed 2 and 3" ${tdir}/di -n -a -f 'T~S~M' | sort -t'~' -k1,1 -k2,2r -k3,3r > s1 ${tdir}/di -n -a -f 'T~S~M' -strsm > s2 dotest puts "by type and special and mount reversed 2 " ${tdir}/di -n -a -f 'T~S~M' | sort -t'~' -k1,1 -k2,2r -k3,3 > s1 ${tdir}/di -n -a -f 'T~S~M' -strsrm > s2 dotest fi rm -f s1 s2 if [ $grc -ne 0 ]; then putsnonl "*" >&5 fi else if [ $d = C ]; then puts "## no di executable found for dir $d" putsnonl "*" >&5 grc=1 fi fi done exit $grc di-4.52/tests.d/diarg.sh0000755000175000017500000000750514421556642013175 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'run di w/arguments' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ . $_MKCONFIG_DIR/bin/shellfuncs.sh testshcapability testArgument () { as=$a a=`echo $a | sed 's/_/ /g'` of="out.${d}.${as}" ofc="out.C.${as}" cmd="${tdir}/di ${a} > ${of}" o=`eval $cmd 2>&1` rc=$? if [ $rc -ne 0 ]; then lrc=$rc; fi if [ "$o" != "" ]; then puts "## $cmd failed with output:" puts $o lrc=1 else puts "## $cmd ok" fi case $a in "-d"*) cmd="${tdir}/di -n $a" eval "$cmd | egrep '(inf|nan)'" rc=$? if [ $rc -eq 0 ]; then lrc=1 fi ;; esac } testargs="-A -a --all -bk -bsi -b1024 -b1000 -b512 \ -Bk -Bsi -B1024 -B1000 -B512 \ --block-size=k --block-size=si --block-size=1024 --block-size=1000 \ --block-size=512 -c --csv-output -C --csv-tabs \ -d1 -d512 -dk -dm -dg -dt -dp -de -dz -dy -dh -dH -d1024 -d1000 \ --dont-resolve-symlink \ -fmtsMTSObuf13bcvpaBuv2iUFP \ -fM -fS -fT --format-string=M --format-string=S \ --format-string=T -g -Ftmpfs -h -H --help --human-readable -itmpfs \ --inodes \ -j --json-output \ -k -l --local -m -n --no-sync -P --portability --print-type \ -q -R \ -sm -ss -st -srm -srs -srt -sa -sra -sT -srT -sf -srf \ -t --total --type=tmpfs -v --version \ -w20 -W20 -xtmpfs --exclude-type=tmpfs -X1 -zall -Z \ -b_k -b_si -b_1024 -b_1000 -b_512 -B_k -B_si -B_1024 \ -B_1000 -B_512 \ -d_1 -d_512 -d_k -d_m -d_g -d_t -d_p -d_e \ -d_z -d_y -d_h -d_H -d_1024 -d_1000 -f_M -f_S \ -f_T -F_tmpfs \ -i_tmpfs -a_-i_tmpfs \ -s_m -s_s -s_t -s_rm -s_rs -s_rt -w_20 -W_20 \ -x_tmpfs -a_-x_tmpfs -X_1 \ -z_all " unset DI_ARGS unset DIFMT for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi lrc=0 tdir=$_MKCONFIG_RUNTOPDIR/$d ( cd $tdir if [ $? -eq 0 ]; then instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 fi ) # just allocate disk space first time through if [ -x ${tdir}/di ]; then for a in $testargs; do testArgument done fi done # disk space should be allocated now; rerun for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi lrc=0 tdir=$_MKCONFIG_RUNTOPDIR/$d if [ -x ${tdir}/di ]; then putsnonl " ${d}" >&5 # most all unix ${tdir}/di -n -f M / 2>/dev/null | grep '^/[ ]*$' > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ]; then # mac os ${tdir}/di -n -f M / 2>/dev/null | grep '^/System/Volumes/Data$' > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ]; then # cygwin ${tdir}/di -n -f M / 2>/dev/null | grep '/usr/bin$' > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ]; then # cygwin ${tdir}/di -n -f M / 2>/dev/null | grep '^C:\\[ ]*$' > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ]; then # other machines w/odd setup ${tdir}/di -n -f M /boot 2>/dev/null | grep '^/boot[ ]*$' > /dev/null 2>&1 rc=$? fi fi fi fi lrc=$rc puts "## di -n -f M / : $rc" for a in $testargs; do testArgument if [ $grc -eq 0 -a $d = D ]; then case ${a} in "-d"*1|"-d"*512|"-d"*1000|"-d"*1024|"-d"*k|"-d"*m) ;; "-k"|"-m"|"-P"|"--portability"|"-X"*) ;; *) chkdiff ${ofc} ${of} if [ $grc -ne 0 ]; then lrc=1 fi grc=0 # reset this... ;; esac fi done if [ $lrc -ne 0 ]; then putsnonl "*" >&5 grc=1 fi else if [ $d = C ]; then puts "## no di executable found for dir $d" grc=1 fi fi done exit $grc di-4.52/tests.d/buildsh.sh0000755000175000017500000001133014421556642013530 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'build w/mkconfig.sh' maindoquery $1 $_MKC_SH getsname $0 dosetup $@ . $_MKCONFIG_DIR/bin/shellfuncs.sh testshcapability for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi tdir=$_MKCONFIG_RUNTOPDIR/$d if [ -d ${tdir} ]; then cd $tdir instdir="`pwd`/test_di" unset MAKEFLAGS if [ $d = D -a "$DC" != "" ]; then ${MAKE:-make} ${TMAKEFLAGS} realclean ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} di.env > env.make.log 2>&1 rc=$? if [ $rc -ne 0 -o ! -f ./di.env ]; then test -f env.make.log && rm -f env.make.log continue; fi ( . ./di.env if [ "${DVERSION}" = "" -o "${DVERSION}" = "1" ]; then exit 1 fi exit 0 ) rc=$? if [ $rc -ne 0 ]; then test -f env.make.log && rm -f env.make.log continue fi fi putsnonl " ${d}" >&5 ${MAKE:-make} ${TMAKEFLAGS} realclean ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all > make.log 2>&1 rc=$? if [ $rc != 0 ]; then grc=$rc; fi if [ $grc -eq 0 ]; then systype=`uname -s` # haiku has too many warnings to deal with if [ "$systype" != "Haiku" ]; then # C: # openbsd: malloc.h, always misused, in file included, in function # openbsd: unfortunately, some output is on separate lines. # openbsd: warning: strcat() is almost always misused, please use strlcat() # solaris: tokens ignored... (dollar sign) # solaris: Function has no return statement : main # freebsd 4.9: from xxx.c:66: (separate line) # freebsd 4.9: /usr/include....function declaration isn't a prototype # AIX: extra msg from make: Target is up to date # Tru64: complains about long long being a new feature. # Tru64: extra ----^ lines # Tru64:(null command) - not sure where that's coming from # SCO_SV: # SCO_SV: warning: `/*' within comment # clang: 'warning: unknown warning option' # clang: X warnings? generated. # many: unrecognized #pragma ignored # miros:gcc: someone does not honour COPTS correctly # gcc:fstack-protector not supported for this target # D: # FLAGS= (makefile) # -- (makefile) cat make.log | grep -v 'dioptions.dat' | grep -v '^load\-unit:' | grep -v '^output\-file:' | grep -v '^option\-file:' | grep -v ' \.\.\. ' | grep -vi mkconfig | grep -v reqlibs | grep -v 'Leaving directory' | grep -v 'Entering directory' | grep -v 'cc \-[co]' | grep -v 'cc32 \-[co]' | grep -v 'cc64 \-[co]' | grep -v 'clang \-[co]' | grep -v 'xlc \-[co]' | grep -v digetentries.o | grep -v '\*\*\* ' | grep -v 'di\.env' | grep -v '^CC=' | grep -v '#warning' | grep -v 'strcpy.*always misused' | grep -v 'strcat.*always misused' | grep -v '^In file included' | grep -v ': In function' | grep -v 'tokens ignored at end of directive line' | grep -v 'Function has no return statement : main' | grep -v '^ *from [^ ]*.[ch]:[0-9]*[:,]$' | grep -v '/usr/include.*function declaration.*a prototype' | grep -v '^Target.*is up to date' | grep -v '^------' | grep -v 'is a new feature' | grep -v '^ *typedef.* long long ' | grep -v 'warning: .... within comment' | grep -v 'Unknown option.*-Wextra.*ignored.' | grep -v 'Unknown option.*-Wno-unused-but-set-variable.*ignored' | grep -v 'warning: unknown warning option' | grep -v 'warning.*generated\.' | grep -v 'Unknown option.*-Wno-unused-parameter.*ignored' | grep -v 'unrecognized #pragma ignored' | grep -v 'someone does not honour COPTS correctly' | grep -v 'fstack-protector not supported for this target' | grep -v FLAGS= | grep -v '(null command)' | grep -v -- '--' | cat > make_extra.log extra=`cat make_extra.log | wc -l | sed -e 's/^ *//'` if [ $extra -ne 0 ]; then puts "## extra output" grc=1 fi fi # not Haiku fi # if the build worked fi mkdir -p $_MKCONFIG_TSTRUNTMPDIR/buildsh_${d}${stag} set +f for f in mkconfig.log mkconfig.cache mkc*.vars di.env di.reqlibs \ env.make.log make.log make_extra.log; do if [ -f $f ]; then mv $f $_MKCONFIG_TSTRUNTMPDIR/buildsh_${d}${stag} fi done set -f done exit $grc di-4.52/tests.d/dinls.sh0000755000175000017500000000366714421556642013225 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'di nls' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ unset DI_ARGS unset DIFMT set -x for d in C D; do if [ $d = D -a \( "$DC" = "" -o "$DC" = "skip" \) ]; then continue fi tdir=$_MKCONFIG_RUNTOPDIR/$d ( cd $tdir if [ $? -eq 0 ]; then instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} install >> ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 fi ) if [ -x ${tdir}/di ]; then putsnonl " ${d}" >&5 if [ $d = C ]; then grep '^#define _enable_nls 1' ${tdir}/config.h hasnls=$? fi if [ $d = D ]; then grep '^enum int _enable_nls = 1;' ${tdir}/config.d hasnls=$? fi if [ ${hasnls} -ne 0 ];then putsnonl " skipped" >&5 exit 0 fi testdir=${tdir}/test_di DI_LOCALE_DIR=${testdir}/share/locale export DI_LOCALE_DIR grc=1 for l in "de" "de_DE" "de_DE.utf-8" "de_DE.UTF-8" \ "de_DE.ISO8859-1" "de_DE.ISO8859-15" ; do LC_ALL="${l}" ${testdir}/bin/di -A | grep Benutzt >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then grc=0 break # only need to know that one works... fi done if [ $grc -ne 0 ]; then for l in "es" "es_ES" "es_ES.utf-8" "es_ES.UTF-8" \ "es_ES.ISO8859-1" "es_ES.ISO8859-15" ; do LC_ALL="${l}" ${testdir}/bin/di -A | grep Disponible >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then grc=0 break # only need to know that one works... fi done fi # cannot depend on german or spanish being installed... if [ $grc -ne 0 ]; then putsnonl " de/es not installed?" >&5 grc=0 fi else if [ $d = C ]; then puts "## no di executable found for dir $d" grc=1 fi fi done exit $grc di-4.52/tests.d/test_order0000644000175000017500000000007514421556642013640 0ustar bllbll1 buildsh 2 diexec 3 diarg 3 disort 3 ditot 4 diinst 5 dinls di-4.52/README.txt0000644000175000017500000002277614421556642011671 0ustar bllblldi - disk information utility (version 4.52) Website: https://diskinfo-di.sourceforge.io/ SourceForge: https://sourceforge.net/projects/diskinfo-di/ CONTENTS Description Installation Tcl Perl Bugs and Known Issues Requirements Porting Information Acknowledgements Copyright DESCRIPTION 'di' is a disk information utility, displaying everything (and more) that your 'df' command does. It features the ability to display your disk usage in whatever format you prefer. It is designed to be highly portable. Great for heterogenous networks. INSTALLATION To build: make -e dioptions.dat # Edit dioptions.dat and change it # to set your preferences. # Add your CC, CFLAGS and LDFLAGS settings. # This file will not be removed and can be reused # for the next release. make -e make -e install Example to change compiler and prefix: CC=gcc prefix=/opt/bin make -e If you don't have a bourne shell compatible shell, Try building with perl: make -e all-perl The CC, CFLAGS, CPPFLAGS, prefix, LDFLAGS, and LIBS environment variables may be set and exported prior to running make. This will override any settings in 'dioptions.dat'. The LOCALEDIR environment variable defaults to ${prefix}/share/locale. The installation uses the INSTALL_DIR (default ${prefix}), INSTALL_BIN_DIR ($INSTALL_DIR/bin), and INST_LOCALEDIR ($INSTALL_DIR/share/locale) environment variables for installation. The internationalization files are automatically built and installed if your system supports internationalization. Windows installation: Alternative 1 - uses pre-built config.win or config.mingw Cygwin gcc: make -e windows-gcc (uses cygwin API) MinGW: mingw32-make -e MAKE=mingw32-make CC=gcc windows-mingw (uses windows API) Msys2: make WINAPI=T NO_PIE=yes Alternative 2 - builds a new config.h file (Cygwin). make -e NO_PIE=yes CC=gcc make -e NO_PIE=yes CC=gcc WINAPI=T # windows API Alternative 3 - builds a new config.h file (MSys) # make sure your PATH is set properly make -e _MKCONFIG_SHELL=bash WINAPI=T NO_PIE=yes CC=gcc You may need to change _lib_GetDiskFreeSpaceEX to 0 in the config.h file for older windows systems. HP-UX: Some versions of gcc on HP-UX break the include files. If you see: header: rpc/rpc.h ... no try: env CC=gcc CFLAGS="-D_LABEL_T" make -e On some HP-UX systems, quotactl isn't declared. If you want quota support, make sure config.h has: #define _lib_quotactl 1 #define _args_quotactl 4 #define _c_arg_1__quotactl int #define _c_arg_2__quotactl char * #define _c_arg_3__quotactl int #define _c_arg_4__quotactl caddr_t #define _quotactl_pos_1 0 #define _quotactl_pos_2 1 64-bit: env CFLAGS="-z +Z +DD64" LDFLAGS="+DD64" make -e 64-bit gcc: env CC=gcc CFLAGS="-fPIC -mlp64 -D_LABEL_T" \ LDFLAGS="-mlp64 -L/usr/lib/hpux64" make -e 32-bit: env CFLAGS="-z +Z +DD32" LDFLAGS="+DD32" make -e 32-bit gcc: env CC=gcc CFLAGS="-fPIC -milp32 -D_LABEL_T" \ LDFLAGS="-milp32 -L/usr/lib/hpux32" make -e Bundled cc: cd C;make hpux-cc Tru64: export BIN_SH=svr4 beforehand. DragonFlyBSD: If quotas are not turned on in the kernel (/boot/loader.conf), the vquotactl interface will not be configured into di. The default build available from DragonFly dports does not have the vquotactl interface turned on. Installation Permissions: Some old systems (Sys V variants) only allow root to read the mount table. In SysV.4 and Solaris, the mount command would reset the permissions to be root readable only (fixed in Solaris 7). If this is needed on your system, do: make installperms TCL The Tcl extension provides access to the di utility via the [diskspace] command. To build: cd C; make -e tcl-sh Windows Cygwin: cd C; make CC=gcc NO_PIE=yes tcl-sh Windows Msys: cd C; make WINAPI=T NO_PIE=yes tcl-sh See C/di-example.tcl for a usage example. PERL The Perl extension provides access to the di utility via the [Filesys::di::diskspace] command. To build: # perl-perl can be substituted for perl-sh to use the # perl configuration script instead of the shell # configuration scripts. cd C; make -e perl-sh; cd Perl; make PREFIX=your-prefix install Windows Cygwin: # I had to install libcrypt-devel for 'crypt.h'. # No idea why perl would require that. # perl-perl is faster than perl-sh. cd C; make CC=gcc NO_PIE=yes perl-perl Windows Msys: # untested; I don't have mingw perl. cd C; make -e WINAPI=T NO_PIE=yes CC=gcc perl-sh See C/Perl/ex/perl-example.pl for a usage example. BUGS AND KNOWN ISSUES What's Not Tested: - pooled filesystems on Tru64. - I have access to a Tru64 system w/quotas, but there's only one filesystem per pool. - quotas: - MacOSX - No access to users with quotas. - MS VC++ has not been tested in a *very* long while. - A/UX, Cray, UNICOS, Next, Pyramid, SCO Unix, Sequent have not been tested in a *very* long while. Known Issues - quotas: - Solaris ufs requires the quotas file to be readable, or make the di program setuid. Neither recommended. - Linux 2.4 - not working - HP-UX - quotactl() isn't declared. See HP-UX section above. - NetBSD 6 - group quotas can't be fetched by ordinary users (EPERM). If the account is limited by a group quota, it won't be reported. - AIX 7 - Unlike AIX 5, AIX 7 gives a permission denied error when a user tries to get their quota. Could make di suid, but that's not a good idea. - pooled filesystems: - hammer: the usage reported for pseudo-filesystems is the usage for the main pool. Therefore the total used and size will be wrong. - btrfs: there's no way to identify the pools. - cygwin with clang does not work. - the pre-configured builds have not been tested in a while. Send bug reports along with the output from 'di -A -a -X 5', output from your standard df command (as verbose as possible), mkconfig.log, mkconfig_env.log, di.env, and config.h to: brad.lanam.di_at_gmail.com If the 'config.h' doesn't get set up correctly, please let me know. E-mail me the incorrect (and corrected if possible) config.h file, and any other information as appropriate. REQUIREMENTS bourne/ksh/bash shell C compiler awk (mawk/nawk/gawk) make cat chmod ln mkdir mv rm sed test mkconfig.sh: a bourne compatible shell that supports shell functions, standard output from 'set'. cat egrep expr grep rm sed sort test mkconfig.pl: cat perl rm mksetopt.sh: mv rm sed test NLS: msgfmt sed runtests.sh (not a requirement for building or installing): ar cat cp dc diff env expr egrep mv rm sed sort test tr PORTING di 4.47 has been tested on the following platforms: Linux RedHat 7.3 (gcc) CentOS 3.9 (gcc) Fedora 7 (gcc) Fedora 27 (gcc) MX Linux 17.1 (gcc, clang) BSD DragonflyBSD 4.4 (gcc) FreeBSD 7.0 (cc) FreeBSD 11.0 (clang) NetBSD 1.62 (cc) NetBSD 2.0 (cc) NetBSD 7.0.1 (gcc) OpenBSD 4.4 (gcc) Windows Msys2 (gcc) Cygwin (gcc) Other AIX 7.1 (gcc) Mac OS X 10.12.6 (clang) QNX 6.5 (cc) SCO SV 6.0.0 (cc) Solaris 11/x86 (cc12.3) Solaris 10/sparc (cc12.3) Solaris 9/x86 (gcc3) Tru64 5.1B (cc) UnixWare 7.1.4 (cc) di has been ported to the following systems in the past: A/UX, AIX, BeOS, BSD, BSDI, Convex, Cray UNICOS, Cray UNICOS/mk, DragonflyBSD, FreeBSD, Haiku, HP/UX, Linux, MacOSX, MirOS, NetBSD, Next, OpenBSD, OS/2, OSF/1, Pyramid, SCO OpenServer, SCO Unix, Sequent Dynix and PT/x, SGI Irix, Solaris, SunOS, Syllable, System V.3, System V.4, Tru64, ULTRIX, UnixWare, VMS, Windows, Xenix ACKNOWLEDGEMENTS And for their comments/source/manual pages and/or bug fixes, thanks! J.J.Bailey Karl Vogel [pyramid] Bryan Costales Mark Neale Pat Myrto [sunOS filesystem type stuff] Henri Karrenbeld [sgi] Peter Bray George M. Sipe [manual page] Jeffrey Mogul [ultrix, osf/1, manual page, new format options] Th. Bullinger [help usage] Seth Theriault [next, tru64] Stephen J. Walick [SCO] Gerald Rinske [sgi] Mike Grupenhoff [linux] R.K.Lloyd [hpux] William Gibbs [xenix] Randy Thompson [sequent] Erik O'Shaughnessy [aix] Bill Davidsen [linux, SCO, etc., new format options] Fred Smith [coherent 4.2.05] Andrey Blochintsev [bsdi] Brian Ginsbach [netbsd, irix, unicos] et. al. COPYRIGHT Copyright 1994-2023 Brad Lanam, Pleasant Hill, CA, USA brad.lanam.di_at_gmail.com https://diskinfo-di.sourceforge.io di-4.52/Makefile0000644000175000017500000001305614421556642011622 0ustar bllbll# # di makefile - top level # # Copyright 2001-2011 Brad Lanam Walnut Creek CA, USA # Copyright 2023 Brad Lanam Pleasant Hill CA, USA # SHELL = /bin/sh FROMDIR = C ### # mkconfig variables MKCONFIGPATH = mkconfig ### # common programs # CAT = cat CHGRP = chgrp CHMOD = chmod CHOWN = chown CP = cp LN = ln MKDIR = mkdir MV = mv RM = rm RPMBUILD = rpmbuild SED = sed TEST = test MKC_DIR = ./mkconfig ### # installation options # prefix = /usr/local PREFIX = $(prefix) PROG = di MPROG = mi # BINDIR = $(PREFIX)/bin DATADIR = $(PREFIX)/share MANDIR = $(DATADIR)/man LOCALEDIR = $(DATADIR)/locale INST_DIR = $(DESTDIR)$(PREFIX) INST_BINDIR = $(DESTDIR)$(BINDIR) INST_DATADIR = $(DESTDIR)$(DATADIR) INST_MANDIR = $(DESTDIR)$(MANDIR) INST_LOCALEDIR = $(DESTDIR)$(LOCALEDIR) DITARGET = $(INST_BINDIR)/$(PROG)$(EXE_EXT) MTARGET = $(INST_BINDIR)/$(MPROG)$(EXE_EXT) # if you need permissions other than the default, # edit these, and do a "make installperm". USER = root GROUP = bin INSTPERM = 4111 # install suid if your system has a mount table only root # can read. For SysV.4 and Solaris, the mount command may # reset the permissions of /etc/mnttab. # # simple man page installation # DI_MANDIR = $(INST_MANDIR)/man1 MAN_TARGET = $(PROG).1 MANPERM = 644 ### # all .PHONY: all all: $(MAKE) checkbuild cd C >/dev/null && $(MAKE) CC=$(CC) -e all .PHONY: all-c all-c: $(MAKE) checkbuild cd C >/dev/null && $(MAKE) CC=$(CC) -e all .PHONY: tcl-sh tcl-sh: $(MAKE) checkbuild cd C >/dev/null && $(MAKE) CC=$(CC) -e tcl-sh .PHONY: all-perl all-perl: $(MAKE) checkperlbuild cd C >/dev/null && $(MAKE) CC=$(CC) -e all-perl .PHONY: windows-gcc windows-gcc: cd C >/dev/null && $(MAKE) -e windows-gcc .PHONY: windows-clang windows-clang: cd C >/dev/null && $(MAKE) -e windows-clang .PHONY: windows-msys windows-msys: cd C >/dev/null && $(MAKE) -e windows-msys .PHONY: windows-mingw windows-mingw: cd C >/dev/null && $(MAKE) -e windows-mingw .PHONY: test test: $(MAKE) checkbuild $(MAKE) checkinstall cd C >/dev/null && $(MAKE) -e test $(MAKE) -e tests.done tests.done: $(MKC_DIR)/runtests.sh @echo "## running tests" CC=$(CC) DC="skip" $(_MKCONFIG_SHELL) \ $(MKC_DIR)/runtests.sh ./tests.d touch tests.done ### ### # installation .PHONY: install install: $(MAKE) all-c $(MAKE) checkinstall . ./C/di.env; $(MAKE) -e FROMDIR=$(FROMDIR) install-prog install-man .PHONY: build.po build-po: -. ./C/di.env; \ (cd po >/dev/null && for i in *.po; do \ j=`echo $$i | $(SED) 's,\\.po$$,,'`; \ $${XMSGFMT} -o $$j.mo $$i; \ done) .PHONY: install-po install-po: build-po -$(TEST) -d $(INST_LOCALEDIR) || $(MKDIR) -p $(INST_LOCALEDIR) -(cd po >/dev/null && for i in *.po; do \ j=`echo $$i | $(SED) 's,\\.po$$,,'`; \ $(TEST) -d $(INST_LOCALEDIR)/$$j || \ $(MKDIR) $(INST_LOCALEDIR)/$$j; \ $(TEST) -d $(INST_LOCALEDIR)/$$j/LC_MESSAGES || \ $(MKDIR) $(INST_LOCALEDIR)/$$j/LC_MESSAGES; \ $(CP) -f $$j.mo $(INST_LOCALEDIR)/$$j/LC_MESSAGES/di.mo; \ $(RM) -f $$j.mo; \ done) .PHONY: install-prog install-prog: $(TEST) -d $(INST_DIR) || $(MKDIR) -p $(INST_DIR) $(TEST) -d $(INST_BINDIR) || $(MKDIR) $(INST_BINDIR) $(CP) -f ./$(FROMDIR)/$(PROG)$(EXE_EXT) $(DITARGET) -$(RM) -f $(MTARGET) > /dev/null 2>&1 -$(LN) -s $(DITARGET) $(MTARGET) @-test -f $(FROMDIR)/config.h && \ grep '^#define _enable_nls 1' $(FROMDIR)/config.h >/dev/null 2>&1 && \ (. ./$(FROMDIR)/di.env; $(MAKE) -e LOCALEDIR="$(LOCALEDIR)" \ install-po) .PHONY: install-man install-man: -$(TEST) -d $(INST_MANDIR) || $(MKDIR) -p $(INST_MANDIR) -$(TEST) -d $(DI_MANDIR) || $(MKDIR) -p $(DI_MANDIR) $(CP) -f di.1 $(DI_MANDIR)/$(MAN_TARGET) $(CHMOD) $(MANPERM) $(DI_MANDIR)/$(MAN_TARGET) .PHONY: installperms installperms: $(CHOWN) $(USER) $(DITARGET) $(CHGRP) $(GROUP) $(DITARGET) $(CHMOD) $(INSTPERM) $(DITARGET) ### # packaging .PHONY: tar tar: @-rm -f di-[0-9].[0-9][0-9][a-z].tar.gz > /dev/null 2>&1 ./mktar.sh ### # cleaning # Leaves: # _tmp_mkconfig/, _mkconfig_runtests/ .PHONY: clean clean: @-rm -rf mkconfig.cache mkc*.vars mkconfig.log \ checkbuild checkperlbuild checkinstall \ tests.done \ tests.d/test_order.tmp > /dev/null 2>&1; exit 0 @-find . -name '*~' -print | xargs rm >/dev/null 2>&1; exit 0 @-(cd C >/dev/null && $(MAKE) clean > /dev/null 2>&1); exit 0 # Leaves: # _tmp_mkconfig/, _mkconfig_runtests/ .PHONY: realclean realclean: @-$(MAKE) clean > /dev/null 2>&1 @-(cd C >/dev/null && $(MAKE) realclean > /dev/null 2>&1); exit 0 # leaves: # dioptions.dat .PHONY: distclean distclean: @-$(MAKE) realclean > /dev/null 2>&1 @-rm -rf mkconfig.cache mkc*.vars mkconfig.log \ mkc_files _mkconfig_runtests \ checkbuild checkperlbuild checkinstall \ tests.done _tmp_mkconfig *~ */*~ \ */*/*~ *.orig > /dev/null 2>&1; exit 0 @-(cd C >/dev/null && $(MAKE) distclean > /dev/null 2>&1); exit 0 ### # dioptions.dat dioptions.dat: features/dioptions.dat @$(CP) features/dioptions.dat dioptions.dat @$(CHMOD) u+w dioptions.dat @touch dioptions.dat # to get mod date current ### # pre-checks checkbuild: features/checkbuild.dat $(_MKCONFIG_SHELL) \ $(MKCONFIGPATH)/mkconfig.sh features/checkbuild.dat touch checkbuild checkperlbuild: features/checkperlbuild.dat $(_MKCONFIG_SHELL) \ $(MKCONFIGPATH)/mkconfig.sh features/checkperlbuild.dat touch checkperlbuild checkinstall: features/checkinstall.dat $(_MKCONFIG_SHELL) \ $(MKCONFIGPATH)/mkconfig.sh features/checkinstall.dat touch checkinstall .PHONY: envcheck envcheck: echo "prefix $(prefix)" echo "PREFIX $(PREFIX)" echo "BINDIR $(BINDIR)" echo "DATADIR $(DATADIR)" echo "LOCALEDIR $(LOCALEDIR)" di-4.52/mkconfig/0000755000175000017500000000000014421556642011752 5ustar bllblldi-4.52/mkconfig/mkconfig.sh0000755000175000017500000005610614421556642014116 0ustar bllbll#!/bin/sh # # Copyright 2009-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - saved stdin (mkconfig.sh) # 6 - temporary (c-main.sh, mkconfig.sh) # 4 - temporary (c-main.sh) # # disable path name expansion set -f # set this globally. unset CDPATH # this is a workaround for ksh93 on solaris if [ "$1" = -d ]; then cd $2 shift shift fi mypath=`echo $0 | sed -e 's,/[^/]*$,,' -e 's,^\.,./.,'` _MKCONFIG_DIR=`(cd $mypath;pwd)` export _MKCONFIG_DIR . ${_MKCONFIG_DIR}/bin/shellfuncs.sh . ${_MKCONFIG_DIR}/bin/envfuncs.sh doshelltest $0 $@ MKC_FILES=${MKC_FILES:-mkc_files} LOG="${MKC_FILES}/mkconfig.log" _MKCONFIG_TMP="${MKC_FILES}/_tmp_mkconfig" CACHEFILE="${MKC_FILES}/mkconfig.cache" OPTIONFILE="options.dat" _MKCONFIG_PREFIX=mkc # need a default in case no units loaded optionsloaded=F allchglist="" INC="mkcinclude.txt" # temporary _chkconfigfname () { if [ "$CONFH" = "" ]; then puts "Config file name not set. Exiting." _exitmkconfig 1 fi } _exitmkconfig () { rc=$1 exit $rc } _savecache () { # And save the data for re-use. # Some shells don't quote the values in the set # command like bash does. So we do it. # Then we have to undo it for bash. # # The $'' syntax interpolates backslashes and nothing else. # For these, remove the $. # # And then there's: x='', which gets munged. # Any value that actually ends with an '=' is going to get mangled. # #savecachedebug=F #if [ $savecachedebug = T ]; then # puts "## savecache original" # set | grep "^mkc_" # puts "## savecache A" # set | grep "^mkc_" | \ # sed -e "s/=/='/" # puts "## savecache B" # set | grep "^mkc_" | \ # sed -e "s/=/='/" -e "s/$/'/" # puts "## savecache C" # set | grep "^mkc_" | \ # sed -e "s/=/='/" -e "s/$/'/" -e "s/''/'/g" # puts "## savecache D" # set | grep "^mkc_" | \ # sed -e "s/=/='/" -e "s/$/'/" -e "s/''/'/g" \ # -e "s/^\([^=]*\)='$/\1=''/" # puts "## savecache E" # set | grep "^mkc_" | \ # sed -e "s/=/='/" -e "s/$/'/" -e "s/''/'/g" \ # -e "s/^\([^=]*\)='$/\1=''/" -e "s/='\$'/='/" #fi #unset savecachedebug set | grep "^mkc_" | \ sed -e "s/=/='/" -e "s/$/'/" -e "s/''/'/g" \ -e "s/^\([^=]*\)='$/\1=''/" -e "s/='\$'/='/" \ > ${CACHEFILE} } setvariable () { prefix=$1 svname=$2 if [ $varsfileopen = F ]; then for v in `set | grep "^mkv_" | sed -e 's/=.*$//'`; do unset $v done varsfileopen=T >$VARSFILE exec 8>>$VARSFILE fi cmd="test \"X\$mkv_${prefix}_${svname}\" != X > /dev/null 2>&1" eval $cmd rc=$? # if already in the list of vars, don't add it to the file again. if [ $rc -ne 0 ]; then puts ${svname} >&8 fi cmd="mkv_${prefix}_${svname}=T" eval $cmd puts " setvariable: $cmd" >&9 } setdata () { prefix=$1 sdname=$2 sdval=$3 if [ "$_MKCONFIG_EXPORT" = T ]; then _doexport $sdname "$sdval" fi cmd="mkc_${prefix}_${sdname}=\"${sdval}\"" eval $cmd puts " setdata: $cmd" >&9 setvariable $prefix $sdname } getdata () { var=$1 prefix=$2 gdname=$3 cmd="${var}=\${mkc_${prefix}_${gdname}}" eval $cmd } _setifleveldisp () { ifleveldisp="" for il in $iflevels; do ifleveldisp="${il}${ifleveldisp}" done if [ "$ifleveldisp" != "" ]; then doappend ifleveldisp " " fi } printlabel () { tname=$1 tlabel=$2 puts " $ifleveldisp[${tname}] ${tlabel} ... " >&9 putsnonl "${ifleveldisp}${tlabel} ..." >&1 } _doexport () { var=$1 val=$2 cmd="${var}=\"${val}\"" eval $cmd cmd="export ${var}" eval $cmd } printyesno_actual () { ynname=$1 ynval=$2 yntag=${3:-} puts " [${ynname}] $ynval ${yntag}" >&9 puts " $ynval ${yntag}" >&1 } printyesno_val () { ynname=$1 ynval=$2 yntag=${3:-} if [ "$ynval" != 0 ]; then printyesno_actual "$ynname" "$ynval" "${yntag}" else printyesno_actual "$ynname" no "${yntag}" fi } printyesno () { ynname=$1 ynval=$2 yntag=${3:-} if [ "$ynval" != 0 ]; then ynval=yes fi printyesno_val "$ynname" $ynval "$yntag" } checkcache_val () { prefix=$1 tname=$2 getdata tval ${prefix} ${tname} rc=1 if [ "$tval" != "" ]; then setvariable $prefix $tname printyesno_actual $tname "$tval" " (cached)" rc=0 fi return $rc } checkcache () { prefix=$1 tname=$2 getdata tval ${prefix} ${tname} rc=1 if [ "$tval" != "" ]; then setvariable $prefix $tname printyesno $tname $tval " (cached)" rc=0 fi return $rc } _loadoptions () { if [ $optionsloaded = F -a -f "${OPTIONFILE}" ]; then exec 6<&0 < ${OPTIONFILE} while read o; do case $o in "") continue ;; \#*) continue ;; esac topt=`puts "$o" | sed 's/=.*//'` tval=`puts "$o" | sed 's/.*=//'` eval "_mkc_opt_${topt}=\"${tval}\"" done exec <&6 6<&- optionsloaded=T fi } check_command () { name=$1 shift ccmd=$1 locnm=_cmd_loc_${ccmd} printlabel $name "command: ${ccmd}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi trc=0 val="" while test $# -gt 0; do ccmd=$1 shift locatecmd tval $ccmd if [ "$tval" != "" ]; then val=$tval trc=1 fi done printyesno_val $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${trc} if [ $trc -eq 1 ]; then setdata ${_MKCONFIG_PREFIX} ${locnm} ${val} fi } check_grep () { name=$1; shift tag=$1; shift pat=$1; shift fn=$1; shift locnm=_grep_${name} printlabel $name "grep: ${tag}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi grep -l ${pat} ${fn} > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then trc=1; else trc=0; fi printyesno $name $trc setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_ifoption () { ifdispcount=$1 type=$2 name=$3 oopt=$4 printlabel $name "$type ($ifdispcount): ${oopt}" _loadoptions trc=0 # if option is not set, it's false found=F if [ $optionsloaded = T ]; then eval tval=\$_mkc_opt_${oopt} # override the option value with the environment variable eval tenvval=\$${oopt} if [ "$tenvval" != "" ]; then tval=$tenvval fi if [ "$tval" != "" ]; then found=T trc=$tval tolower trc puts " found option: $oopt $trc" >&9 if [ "$trc" = t ]; then trc=1; fi if [ "$trc" = f ]; then trc=0; fi if [ "$trc" = enable ]; then trc=1; fi if [ "$trc" = disable ]; then trc=0; fi if [ "$trc" = true ]; then trc=1; fi if [ "$trc" = false ]; then trc=0; fi if [ "$trc" = yes ]; then trc=1; fi if [ "$trc" = no ]; then trc=0; fi fi fi # these must be set before ifnotoption processing if [ $optionsloaded = F ]; then trc=0 elif [ "$found" = F ]; then trc=0 fi if [ $type = ifnotoption ]; then if [ $trc -eq 0 ]; then trc=1; else trc=0; fi fi if [ $optionsloaded = F ]; then printyesno_actual $name "no options file" elif [ "$found" = F ]; then printyesno_actual $name "option not found" else printyesno $name $trc fi return $trc } check_if () { iflabel=$1 ifdispcount=$2 ifline=$3 name=$iflabel printlabel $name, "if ($ifdispcount): $iflabel"; boolclean ifline puts "## ifline: $ifline" >&9 trc=0 # if option is not set, it's false nline="test " ineq=0 qtoken="" quoted=0 for token in $ifline; do puts "## token: $token" >&9 case $token in \'*\') token=`puts $token | sed -e s,\',,g` puts "## begin/end quoted token" >&9 ;; \'*) qtoken=$token puts "## begin qtoken: $qtoken" >&9 quoted=1 continue ;; esac if [ $quoted -eq 1 ]; then case $token in *\') token="${qtoken} $token" token=`puts $token | sed -e s,\',,g` puts "## end qtoken: $token" >&9 quoted=0 ;; *) qtoken="$qtoken $token" puts "## in qtoken: $qtoken" >&9 continue ;; esac fi if [ $ineq -eq 1 ]; then ineq=2 getdata tvar ${_MKCONFIG_PREFIX} $token elif [ $ineq -eq 2 ]; then doappend nline " ( '$tvar' = '$token' )" ineq=0 else case $token in ==) ineq=1 ;; \(|\)|-a|-o|!) doappend nline " $token" ;; *) getdata tvar ${_MKCONFIG_PREFIX} $token if [ "$tvar" != 0 -a "$tvar" != "" ]; then tvar=1; else tvar=0; fi tvar="( $tvar = 1 )" doappend nline " $tvar" ;; esac fi done if [ "$ifline" != "" ]; then dosubst nline '(' '\\\\\\(' ')' '\\\\\\)' puts "## nline: $nline" >&9 eval $nline trc=$? puts "## eval nline: $trc" >&9 # replace w/ shell return if [ $trc -eq 0 ]; then trc=1; else trc=0; fi puts "## eval nline final: $trc" >&9 fi texp=$_MKCONFIG_EXPORT _MKCONFIG_EXPORT=F printyesno "$name" $trc _MKCONFIG_EXPORT=$texp return $trc } check_set () { nm=$1 type=$2 sval=$3 name=$type tnm=$1 dosubst tnm '_setint_' '' '_setstr' '' printlabel $name "${type}: ${tnm}" if [ "$type" = set ]; then getdata tval ${prefix} ${nm} if [ "$tval" != "" ]; then printyesno $nm "${sval}" setdata ${_MKCONFIG_PREFIX} ${nm} "${sval}" else printyesno_actual $nm "no such variable" fi elif [ "$type" = setint ]; then printyesno_actual $nm "${sval}" setdata ${_MKCONFIG_PREFIX} ${nm} "${sval}" else printyesno_actual $nm "${sval}" setdata ${_MKCONFIG_PREFIX} ${nm} "${sval}" fi } _read_option () { onm=$1 def=$2 _loadoptions oval=$def if [ $optionsloaded = T ]; then eval tval=\$_mkc_opt_${onm} if [ "$tval" != "" ]; then found=T puts " found option: $onm $tval" >&9 oval="$tval" fi fi } check_option () { nm=$1 onm=$2 def=$3 name=$nm printlabel $name "option: ${onm}" _read_option $onm "$def" printyesno_actual $nm "$oval" setdata ${_MKCONFIG_PREFIX} ${nm} "${oval}" } check_echo () { val=$1 puts "## echo: $val" >&9 puts "$val" >&1 } check_exit () { puts "## exit" >&9 _exitmkconfig 5 } check_substitute () { nm=$1 sub1=$2 sub2=$3 printlabel $nm "substitute: ${sub1} ${sub2}" doappend allchglist " -e 's~${sub1}~${sub2}~g'" printyesno $nm 1 } _doloadunit () { lu=$1 dep=$2 if [ "$dep" = Y ]; then slu=${lu} tag=" (dependency)" fi if [ -f ${_MKCONFIG_DIR}/units/${lu}.sh ]; then puts "load-unit: ${lu} ${tag}" >&1 puts " found ${lu} ${tag}" >&9 . ${_MKCONFIG_DIR}/units/${lu}.sh tlu=$lu dosubst tlu '-' '_' eval "_MKCONFIG_UNIT_${tlu}=Y" fi if [ "$dep" = Y ]; then lu=$slu tag="" fi } require_unit () { units=$@ for rqu in $units; do trqu=$rqu dosubst trqu '-' '_' cmd="val=\$_MKCONFIG_UNIT_${trqu}" eval $cmd if [ "$val" = Y ]; then puts " required unit ${rqu} already loaded" >&9 continue fi puts " required unit ${rqu} needed" >&9 _doloadunit $rqu Y done } _create_output () { if [ ${CONFH} != none ]; then confdir=`puts ${CONFH} | sed -e 's,/[^/]*$,,'` test -d $confdir || mkdir -p $confdir > ${CONFH} exec 8>>${CONFH} preconfigfile ${CONFH} ${configfile} >&8 if [ -f $VARSFILE ]; then exec 6<&0 < $VARSFILE while read cfgvar; do getdata val ${_MKCONFIG_PREFIX} $cfgvar output_item ${CONFH} ${cfgvar} "${val}" >&8 done exec <&6 6<&- fi stdconfigfile ${CONFH} >&8 cat $INC >&8 postconfigfile ${CONFH} >&8 exec 8>&- if [ "$allchglist" != "" ]; then cmd="sed ${allchglist} ${CONFH} > ${CONFH}.tmp;mv ${CONFH}.tmp ${CONFH}" eval $cmd fi fi } main_process () { configfile=$1 reqlibs="" if [ -f "$CACHEFILE" ]; then . $CACHEFILE fi reqhdr="" inproc=0 ininclude=0 doproclist="" doproc=1 linenumber=0 ifstmtcount=0 ifleveldisp="" iflevels="" ifcurrlvl=0 doif=$ifcurrlvl initifs > $INC case ${configfile} in /*) ;; *) configfile="../../${configfile}" ;; esac # save stdin in fd 7. # and reset stdin to get from the configfile. # this allows us to run the while loop in the # current shell rather than a subshell. # default varsfile. # a main loadunit will override this. # but don't open it unless it is needed. varsfileopen=F if [ "$VARSFILE" = "" -a "${_MKCONFIG_PREFIX}" != "" ]; then VARSFILE="../mkc_none_${_MKCONFIG_PREFIX}.vars" fi # ksh93 93u 'read' changed. Need the raw read for 'include'. # Unfortunately, this affects other shells. # shellfuncs tests for the necessity. rawarg= # save stdin in fd 7; open stdin exec 7<&0 < ${configfile} while read ${rawarg} tdatline; do resetifs domath linenumber "$linenumber + 1" puts "#### ${linenumber}: ${tdatline}" >&9 if [ $ininclude -eq 1 ]; then if [ "${tdatline}" = endinclude ]; then ininclude=0 rawarg= resetifs else if [ $shreqreadraw -eq 1 ]; then # have to do our own backslash processing. # backquotes suck. tdatline=`puts "${tdatline}" | sed -e 's/\\\\\\([^\\\\]\\)/\\1/g' -e 's/\\\\\\\\/\\\\/g'` fi puts "${tdatline}" >> $INC fi else case ${tdatline} in "") continue ;; \#*) continue ;; *) puts "#### ${linenumber}: ${tdatline}" >&9 ;; esac fi if [ $ininclude -eq 0 ]; then case ${tdatline} in "else") if [ $ifcurrlvl -eq $doif ]; then if [ $doproc -eq 0 ]; then doproc=1; else doproc=0; fi set -- $iflevels shift iflevels=$@ iflevels="-$ifstmtcount $iflevels" _setifleveldisp puts "## else: ifcurrlvl: $ifcurrlvl doif: $doif doproc:$doproc" >&9 puts "## else: iflevels: $iflevels" >&9 else puts "## else: ifcurrlvl: $ifcurrlvl doif: $doif doproc:$doproc" >&9 fi ;; "if "*|"ifoption"*|"ifnotoption"*) if [ $doproc -eq 0 ]; then domath ifcurrlvl "$ifcurrlvl + 1" puts "## if: ifcurrlvl: $ifcurrlvl doif: $doif" >&9 fi ;; "endif") puts "## endifA: ifcurrlvl: $ifcurrlvl doif: $doif" >&9 if [ $ifcurrlvl -eq $doif ]; then set $doproclist c=$# if [ $c -gt 0 ]; then puts "## doproclist: $doproclist" >&9 doproc=$1 shift doproclist=$@ puts "## doproc: $doproc doproclist: $doproclist" >&9 set -- $iflevels shift iflevels=$@ _setifleveldisp puts "## endif iflevels: $iflevels" >&9 else doproc=1 ifleveldisp="" iflevels="" fi domath doif "$doif - 1" fi domath ifcurrlvl "$ifcurrlvl - 1" puts "## endifB: ifcurrlvl: $ifcurrlvl doif: $doif" >&9 ;; esac if [ $doproc -eq 1 ]; then case ${tdatline} in command*) _chkconfigfname set $tdatline cmd=$2 shift nm="_command_${cmd}" check_command ${nm} $@ ;; grep*) _chkconfigfname set $tdatline tag=$2 shift nm="_grep_${tag}" check_grep ${nm} $@ ;; "echo"*) _chkconfigfname set $tdatline shift val=$@ check_echo "${val}" ;; "exit") check_exit ;; substitute) check_substitute $@ ;; endinclude) ;; ifoption*|ifnotoption*) _chkconfigfname set $tdatline type=$1 opt=$2 nm="_${type}_${opt}" puts "## if: ifcurrlvl: $ifcurrlvl" >&9 domath ifstmtcount "$ifstmtcount + 1" check_ifoption $ifstmtcount $type ${nm} ${opt} rc=$? iflevels="+$ifstmtcount $iflevels" _setifleveldisp puts "## ifopt iflevels: $iflevels" >&9 doproclist="$doproc $doproclist" doproc=$rc puts "## doproc: $doproc doproclist: $doproclist" >&9 ;; "if "*) _chkconfigfname set $tdatline shift label=$1 shift ifline=$@ domath ifcurrlvl "$ifcurrlvl + 1" puts "## if: ifcurrlvl: $ifcurrlvl" >&9 domath ifstmtcount "$ifstmtcount + 1" check_if $label $ifstmtcount "$ifline" rc=$? iflevels="+$ifstmtcount $iflevels" _setifleveldisp puts "## if iflevels: $iflevels" >&9 doproclist="$doproc $doproclist" doproc=$rc doif=$ifcurrlvl puts "## doproc: $doproc doproclist: $doproclist" >&9 ;; "else") ;; "endif") ;; include) _chkconfigfname ininclude=1 if [ $shreqreadraw -eq 1 ]; then rawarg=-r fi ;; loadunit*) set $tdatline type=$1 file=$2 _doloadunit ${file} N if [ $varsfileopen = T ]; then exec 8>&- varsfileopen=F fi if [ "${_MKCONFIG_PREFIX}" != "" ]; then VARSFILE="../mkc_${CONFHTAG}_${_MKCONFIG_PREFIX}.vars" fi ;; option-file*) set $tdatline type=$1 file=$2 case ${file} in /*) OPTIONFILE=${file} ;; *) OPTIONFILE="../../${file}" ;; esac puts "option-file: ${file}" >&1 puts " option file name: ${OPTIONFILE}" >&9 ;; option*) _chkconfigfname set $tdatline optnm=$2 shift; shift tval=$@ nm="_opt_${optnm}" check_option ${nm} $optnm "${tval}" ;; output*) newout=F if [ $varsfileopen = T ]; then exec 8>&- varsfileopen=F newout=T fi if [ $inproc -eq 1 ]; then _create_output CONFH=none CONFHTAG=none CONFHTAGUC=NONE fi if [ $newout = T ]; then new_output_file > $INC # restart include fi set $tdatline type=$1 file=$2 case ${file} in none) CONFH=${file} ;; /*) CONFH=${file} ;; *) CONFH="../../${file}" ;; esac puts "output-file: ${file}" >&1 puts " config file name: ${CONFH}" >&9 file=`puts $file | sed -e 's,.*/,,'` file=`puts $file | sed -e 's/\..*//'` CONFHTAG=$file CONFHTAGUC=$file toupper CONFHTAGUC if [ "${_MKCONFIG_PREFIX}" != "" ]; then VARSFILE="../mkc_${CONFHTAG}_${_MKCONFIG_PREFIX}.vars" fi inproc=1 ;; standard) _chkconfigfname standard_checks ;; "set "*|setint*|setstr*) _chkconfigfname set $tdatline type=$1 nm=$2 if [ "$type" = setint -o "$type" = setstr ]; then nm="_${type}_$2" fi shift; shift tval=$@ check_set ${nm} $type "${tval}" ;; *) _chkconfigfname set $tdatline type=$1 chk="check_${type}" cmd="$chk $@" eval $cmd ;; esac fi # doproc fi # ininclude if [ $ininclude -eq 1 ]; then setifs fi done # reset the file descriptors back to the norm. # set stdin to saved fd 7; close fd 7 exec <&7 7<&- if [ $varsfileopen = T ]; then exec 8>&- varsfileopen=F fi _savecache # save the cache file. _create_output } usage () { puts "Usage: $0 [-C] [-c ] [-o ] [-L ] -C : clear cache-file defaults: : mkconfig.cache : mkconfig.log" } # main mkconfigversion unset GREP_OPTIONS unset ENV unalias sed > /dev/null 2>&1 unalias grep > /dev/null 2>&1 unalias ls > /dev/null 2>&1 unalias rm > /dev/null 2>&1 LC_ALL=C export LC_ALL clearcache=0 while test $# -gt 1; do case $1 in -C) shift clearcache=1 ;; -c) shift CACHEFILE=$1 shift ;; -L) shift LOG=$1 shift ;; -o) shift OPTIONFILE=$1 shift ;; esac done configfile=$1 if [ $# -ne 1 ] || [ ! -f $configfile ]; then puts "No configuration file specified or not found." usage exit 1 fi if [ -d $_MKCONFIG_TMP -a $_MKCONFIG_TMP != ${MKC_FILES}/_tmp_mkconfig ]; then puts "$_MKCONFIG_TMP must not exist." usage exit 1 fi test -d $_MKCONFIG_TMP && rm -rf $_MKCONFIG_TMP > /dev/null 2>&1 mkdir -p $_MKCONFIG_TMP cd $_MKCONFIG_TMP LOG="../../$LOG" REQLIB="../../$REQLIB" CACHEFILE="../../$CACHEFILE" VARSFILE="../../$VARSFILE" OPTIONFILE="../../$OPTIONFILE" CONFH=none CONFHTAG=none CONFHTAGUC=NONE if [ $clearcache -eq 1 ]; then rm -f $CACHEFILE > /dev/null 2>&1 rm -f ../mkconfig_*.vars > /dev/null 2>&1 fi dt=`date` exec 9>>$LOG puts "#### " >&9 puts "# Start: $dt " >&9 puts "# $0 ($shell) using $configfile " >&9 puts "#### " >&9 puts "shell: $shell" >&9 puts "has printf: ${shhasprintf}" >&9 puts "has append: ${shhasappend}" >&9 puts "has math: ${shhasmath}" >&9 puts "has upper: ${shhasupper}" >&9 puts "has lower: ${shhaslower}" >&9 puts "read raw req: ${shreqreadraw}" >&9 locateawkcmd puts "awk: $awkcmd" >&9 locatepkgconfigcmd echo "pkg-config: $pkgconfigcmd" >&9 puts "$0 ($shell) using $configfile" main_process $configfile dt=`date` puts "#### " >&9 puts "# End: $dt " >&9 puts "#### " >&9 exec 9>&- cd .. if [ "$MKC_KEEP_TMP" = "" ]; then test -d $_MKCONFIG_TMP && rm -rf $_MKCONFIG_TMP > /dev/null 2>&1 fi exit 0 di-4.52/mkconfig/mkc.sh0000755000175000017500000000323414421556642013065 0ustar bllbll#!/bin/sh # # Copyright 2009-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # this is a workaround for ksh93 on solaris unset CDPATH if [ "$1" = "-d" ]; then cd $2 shift shift fi mypath=`echo $0 | sed -e 's,/[^/]*$,,' -e 's,^\.,./.,'` _MKCONFIG_DIR=`(cd $mypath;pwd)` export _MKCONFIG_DIR . ${_MKCONFIG_DIR}/bin/shellfuncs.sh . ${_MKCONFIG_DIR}/bin/envfuncs.sh doshelltest $0 $@ if [ "$MKC_PREFIX" != "" ]; then if [ "$MKC_CONFDIR" = "" ]; then MKC_CONFDIR=. export MKC_CONFDIR else test -d "${MKC_CONFDIR}" || mkdir -p "${MKC_CONFDIR}" fi if [ "$MKC_OUTPUT" = "" ]; then MKC_OUTPUT=config.h export MKC_OUTPUT fi if [ ! -f ${MKC_CONFDIR}/${MKC_PREFIX}.env ]; then ${_MKCONFIG_SHELL} ${MKC_DIR}/mkconfig.sh ${MKC_CONFDIR}/${MKC_PREFIX}-env.mkc fi if [ -f ${MKC_PREFIX}.env ]; then . ./${MKC_PREFIX}.env if [ ! -f ${MKC_OUTPUT} ]; then ${_MKCONFIG_SHELL} ${MKC_DIR}/mkconfig.sh ${MKC_CONFDIR}/${MKC_PREFIX}.mkc fi fi fi rc=0 args=$@ found=T case $1 in -compile|-comp|-link) ${_MKCONFIG_SHELL} ${_MKCONFIG_DIR}/bin/mkcl.sh -d `pwd` "$@" rc=$? shift ;; -staticlib) shift ${_MKCONFIG_SHELL} ${_MKCONFIG_DIR}/bin/mkstaticlib.sh -d `pwd` "$@" rc=$? ;; -setopt) shift ${_MKCONFIG_SHELL} ${_MKCONFIG_DIR}/bin/mkcsetopt.sh -d `pwd` "$@" rc=$? ;; -reqlib) shift ${_MKCONFIG_SHELL} ${_MKCONFIG_DIR}/bin/mkreqlib.sh -d `pwd` "$@" rc=$? ;; -makeconfig) rc=0 ;; *) found=F ;; esac if [ $found = F ]; then echo "Usage: $0 {-compile|-link|-setopt|-reqlib|-staticlib|-sharedlib} " exit 1 fi exit $rc di-4.52/mkconfig/units/0000755000175000017500000000000014421556642013114 5ustar bllblldi-4.52/mkconfig/units/env-systype.sh0000755000175000017500000000736414421556642015773 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # require_unit env-main env_dolocuname=F _dolocuname () { if [ $env_dolocuname = "T" ]; then return fi locatecmd xuname uname puts "uname located: ${xuname}" >&9 env_dolocuname=T } check_system () { name="_MKCONFIG_SYS" arg=$2 uarg=$arg toupper uarg name="${name}${uarg}" _dolocuname if [ "$arg" = "type" ]; then printlabel $name "system: type" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi if [ "${xuname}" != "" ] then _MKCONFIG_SYSTYPE=`${xuname} -s` else puts "no uname, try some guessing" >&9 # no uname...we'll have to do some guessing. _MKCONFIG_SYSTYPE="unknown" if [ -f /vmunix ]; then # some sort of BSD variant _MKCONFIG_SYSTYPE="BSD" else _MKCONFIG_SYSTYPE="SYSV" # some SysV variant, probably. fi fi puts "type: ${_MKCONFIG_SYSTYPE}" >&9 printyesno_val _MKCONFIG_SYSTYPE "${_MKCONFIG_SYSTYPE}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_SYSTYPE "${_MKCONFIG_SYSTYPE}" fi if [ "$arg" = "rev" ]; then printlabel $name "system: rev" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi if [ "${xuname}" != "" ] then case ${_MKCONFIG_SYSTYPE} in AIX) tmp=`( (oslevel) 2>/dev/null || puts "not found") 2>&1` case "$tmp" in 'not found') _MKCONFIG_SYSREV="$4"."$3" ;; '<3240'|'<>3240') _MKCONFIG_SYSREV=3.2.0 ;; '=3240'|'>3240'|'<3250'|'<>3250') _MKCONFIG_SYSREV=3.2.4 ;; '=3250'|'>3250') _MKCONFIG_SYSREV=3.2.5 ;; *) _MKCONFIG_SYSREV=$tmp ;; esac ;; *) _MKCONFIG_SYSREV=`${xuname} -r` ;; esac else puts "no uname, try some guessing" >&9 # no uname...we'll have to do some guessing. _MKCONFIG_SYSREV="unknown" if [ -f /vmunix ]; then # sys/param.h might have: # #define BSD 43 # #define BSD4_3 1 rev=`grep '^#define.*BSD[^0-9]' /usr/include/sys/param.h | sed 's,/.*,,'` if [ "rev" != "" ]; then rev=`puts $rev | sed 's/^[^0-9]*\([0-9]\)\([0-9]\).*/\1.\2/'` _MKCONFIG_SYSREV="$rev" fi fi fi puts "rev: ${_MKCONFIG_SYSREV}" >&9 printyesno_val _MKCONFIG_SYSREV "${_MKCONFIG_SYSREV}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_SYSREV "${_MKCONFIG_SYSREV}" fi if [ "$arg" = "arch" ]; then printlabel $name "system: arch" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi if [ "${xuname}" != "" ] then _MKCONFIG_SYSARCH=`${xuname} -m` else puts "no uname, try some guessing" >&9 # no uname...we'll have to do some guessing. _MKCONFIG_SYSARCH="unknown" locatecmd xarch arch puts "arch located: ${xarch}" >&9 if [ "${xarch}" != "" ]; then _MKCONFIG_SYSARCH=`arch` fi fi puts "arch: ${_MKCONFIG_SYSARCH}" >&9 printyesno_val _MKCONFIG_SYSARCH "${_MKCONFIG_SYSARCH}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_SYSARCH "${_MKCONFIG_SYSARCH}" fi } check_standard_system () { check_system system type check_system system rev check_system system arch } di-4.52/mkconfig/units/env-main.sh0000755000175000017500000000726714421556642015201 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # _MKCONFIG_PREFIX=env _MKCONFIG_HASEMPTY=T _MKCONFIG_EXPORT=T preconfigfile () { pc_configfile=$1 configfile=$2 puts "#!/bin/sh" puts "# Created on: `date`" puts "# From: ${configfile}" puts "# Using: mkconfig-${_MKCONFIG_VERSION}" return } stdconfigfile () { pc_configfile=$1 return } postconfigfile () { pc_configfile=$1 return } standard_checks () { return } check_source () { nm=$1 fn=$2 tfn=$fn dosubst tfn '.*/' '' '\.' '' '-' '' name=_${nm}_${tfn} printlabel $nm "source: $fn" trc=0 val=0 if [ -f $fn ]; then trc=1 val=$fn fi printyesno $name $trc setdata ${_MKCONFIG_PREFIX} ${name} $val } output_item () { out=$1 name=$2 val=$3 case $name in _source_*) if [ $val != "0" ]; then puts ". ${val}" fi ;; _setint*|_setstr*|_opt_*) tname=$name dosubst tname '_setint_' '' '_setstr_' '' '_opt_' '' puts "${tname}=\"${val}\"" puts "export ${tname}" ;; *) puts "${name}=\"${val}\"" puts "export ${name}" ;; esac } check_test_multword () { name=$1 printlabel $name "test: multiword" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi val="word1 word2" printyesno_val $name "$val" setdata ${_MKCONFIG_PREFIX} $name "$val" } new_output_file () { return 0 } check_pkg () { type=$2 pkgname=$3 pkgpath=$4 name=_pkg_${type}_${pkgname} dosubst name '\.' '' '-' '' puts "pkg $type: $pkgname $pkgpath" >&9 printlabel $name "pkg ${type}: ${pkgname}" check_pkg_exists $name $pkgname $pkgpath trc=$? if [ $trc -eq 0 ]; then return $trc fi check_pkg_$type $name $pkgname $pkgpath trc=$? return $trc } check_pkg_exists () { name=$1 pkgname=$2 pkgpath=$3 trc=0 if [ "${pkgconfigcmd}" = "" ]; then printyesno $name $trc "(no pkg-config)" return $trc fi OPKG_CONFIG_PATH=$PKG_CONFIG_PATH if [ "$pkgpath" != "" ]; then if [ "$PKG_CONFIG_PATH" != "" ]; then doappend PKG_CONFIG_PATH : fi doappend PKG_CONFIG_PATH $pkgpath fi export PKG_CONFIG_PATH ${pkgconfigcmd} --exists $pkgname rc=$? if [ $rc -ne 0 ]; then printyesno $name $trc "(no such package)" else trc=1 fi unset PKG_CONFIG_PATH if [ "$OPKG_CONFIG_PATH" != "" ]; then PKG_CONFIG_PATH=$OPKG_CONFIG_PATH fi return $trc } test_cflag () { flag=$1 puts "#include int main () { return 0; }" > t.c puts "# test ${flag}" >&9 # need to set w/all cflags; gcc doesn't always error out otherwise TMPF=t$$.txt setcflags ${CC} ${CFLAGS} ${flag} t.c > $TMPF 2>&1 rc=$? if [ $rc -ne 0 ]; then flag=0 fi grep -i "warning.*${flag}" $TMPF > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then flag=0 fi cat $TMPF >&9 rm -f $TMPF > /dev/null 2>&1 } test_ldflags () { flag=$1 setcflags setldflags setlibs puts "#include int main () { return 0; }" > t.c puts "# test ${flag}" >&9 # need to set w/all cflags/ldflags; gcc doesn't always error out otherwise TMPF=t$$.txt ${CC} ${CFLAGS} ${LDFLAGS} ${flag} -o t t.c > $TMPF 2>&1 rc=$? if [ $rc -ne 0 ]; then flag=0 fi grep -i "warning.*${flag}" $TMPF > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then flag=0 fi cat $TMPF >&9 rm -f $TMPF > /dev/null 2>&1 } di-4.52/mkconfig/units/c-support.sh0000755000175000017500000001340414421556642015411 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # CPPCOUNTER=1 postcc=" /* some gcc's (cygwin) redefine __restrict again */ #if defined (__restrict) # undef __restrict #endif #define __restrict " _c_print_headers () { incheaders=$1 cppchk=$2 if [ "$incheaders" = "none" ]; then return fi out="${PH_PREFIX}${incheaders}" if [ -f $out ]; then cat $out return fi if [ "$PH_STD" = "T" -a "$incheaders" = "std" ]; then _c_print_hdrs std $cppchk > $out cat $out return fi if [ "$PH_ALL" = "T" -a "$incheaders" = "all" ]; then _c_print_hdrs all $cppchk > $out cat $out return fi # until PH_STD/PH_ALL becomes true, just do normal processing. _c_print_hdrs $incheaders $cppchk } _c_print_hdrs () { incheaders=$1 cppchk=$2 if [ "${incheaders}" = "all" -o "${incheaders}" = "std" ]; then for tnm in '_hdr_stdio' '_hdr_stdlib' '_sys_types' '_sys_param'; do getdata tval ${_MKCONFIG_PREFIX} ${tnm} if [ "${tval}" != "0" -a "${tval}" != "" ]; then puts "#include <${tval}>" # for cygwin/gcc if [ "$cppchk" = T -a $tnm = _hdr_stdio ]; then puts "${postcc}" fi fi done fi if [ "${incheaders}" = "all" -a -f "$VARSFILE" ]; then # save stdin in fd 6; open stdin exec 6<&0 < ${VARSFILE} while read cfgvar; do getdata hdval ${_MKCONFIG_PREFIX} ${cfgvar} case ${cfgvar} in _hdr_stdio|_hdr_stdlib|_sys_types|_sys_param) ;; _hdr_linux_quota) if [ "${hdval}" != "0" ]; then getdata iqval ${_MKCONFIG_PREFIX} '_inc_conflict__sys_quota__hdr_linux_quota' if [ "${iqval}" = "1" ]; then puts "#include <${hdval}>" fi fi ;; _sys_time) if [ "${hdval}" != "0" ]; then getdata itval ${_MKCONFIG_PREFIX} '_inc_conflict__hdr_time__sys_time' if [ "${itval}" = "1" ]; then puts "#include <${hdval}>" fi fi ;; _hdr_*|_sys_*) if [ "${hdval}" != "0" -a "${hdval}" != "" ]; then puts "#include <${hdval}>" fi ;; esac done # set std to saved fd 6; close 6 exec <&6 6<&- fi } _c_chk_run () { crname=$1 code=$2 inc=$3 _c_chk_link_libs ${crname} "${code}" $inc rc=$? puts "## run test: link: $rc" >&9 rval=0 if [ $rc -eq 0 ]; then rval=`./${crname}.exe` rc=$? puts "## run test: run: $rc retval:$rval" >&9 if [ $rc -lt 0 ]; then _exitmkconfig $rc fi fi _retval=$rval return $rc } _c_chk_link_libs () { cllname=$1 code=$2 inc=$3 shift;shift;shift ocounter=0 clotherlibs="'$otherlibs'" dosubst clotherlibs ',' "' '" if [ "${clotherlibs}" != "" ]; then eval "set -- $clotherlibs" ocount=$# else ocount=0 fi tcfile=${cllname}.c >${tcfile} # $cllname should be unique exec 4>>${tcfile} puts "${precc}" >&4 _c_print_headers $inc >&4 puts "${code}" | sed 's/_dollar_/$/g' >&4 exec 4>&- dlibs="" otherlibs="" _c_chk_link $cllname rc=$? puts "## link test (none): $rc" >&9 if [ $rc -ne 0 ]; then while test $ocounter -lt $ocount; do domath ocounter "$ocounter + 1" eval "set -- $clotherlibs" cmd="olibs=\$${ocounter}" eval $cmd dlibs=${olibs} otherlibs=${olibs} _c_chk_link $cllname rc=$? puts "## link test (${olibs}): $rc" >&9 if [ $rc -eq 0 ]; then break fi done fi _retdlibs=$dlibs return $rc } _c_chk_cpp () { cppname=$1 code="$2" inc=$3 tcppfile=${cppname}.c tcppout=${cppname}.out tcppreuse=F if [ "$code" = "" -a $inc = all ]; then tcppreuse=T tcppfile=chkcpp_${CPPCOUNTER}.c tcppout=chkcpp_${CPPCOUNTER}.out if [ -f $tcppfile -a -f $tcppout ]; then test -f ${cppname}.out && rm -f ${cppname}.out ln -s ${tcppout} ${cppname}.out puts "## _cpp test: reusing $tcppout" >&9 rc=0 return $rc fi fi # $cppname should be unique exec 4>>${tcppfile} puts "${precc}" >&4 _c_print_headers $inc T >&4 puts "${code}" | sed 's/_dollar_/$/g' >&4 exec 4>&- setcflags cmd="${CC} ${CFLAGS} -E ${tcppfile} > ${tcppout} " puts "## _cpp test: $cmd" >&9 cat ${tcppfile} >&9 eval $cmd >&9 2>&9 rc=$? if [ $rc -lt 0 ]; then _exitmkconfig $rc fi if [ $tcppreuse = T ]; then test -f ${cppname}.out && rm -f ${cppname}.out ln -s ${tcppout} ${cppname}.out fi puts "## _cpp test: $rc" >&9 return $rc } _c_chk_link () { clname=$1 setcflags setldflags setlibs cmd="${CC} ${CFLAGS} -o ${clname}.exe ${clname}.c " cmd="${cmd} ${LDFLAGS} ${LIBS} " _clotherlibs=$otherlibs if [ "${_clotherlibs}" != "" ]; then cmd="${cmd} ${_clotherlibs} " fi puts "## _link test: $cmd" >&9 cat ${clname}.c >&9 eval $cmd >&9 2>&9 rc=$? if [ $rc -lt 0 ]; then _exitmkconfig $rc fi puts "## _link test: $rc" >&9 if [ $rc -eq 0 ]; then if [ ! -x "${clname}.exe" ]; then # not executable rc=1 fi fi return $rc } _c_chk_compile () { ccname=$1 code=$2 inc=$3 tcfile=${ccname}.c >${tcfile} # $ccname should be unique exec 4>>${tcfile} puts "${precc}" >&4 _c_print_headers $inc >&4 puts "${code}" | sed 's/_dollar_/$/g' >&4 exec 4>&- setcflags cmd="${CC} ${CFLAGS} -c ${tcfile}" puts "## compile test: $cmd" >&9 cat ${ccname}.c >&9 eval ${cmd} >&9 2>&9 rc=$? puts "## compile test: $rc" >&9 return $rc } do_c_check_compile () { dccname=$1 code=$2 inc=$3 _c_chk_compile ${dccname} "${code}" $inc rc=$? try=0 if [ $rc -eq 0 ]; then try=1 fi printyesno $dccname $try setdata ${_MKCONFIG_PREFIX} ${dccname} ${try} } di-4.52/mkconfig/units/d-main.sh0000755000175000017500000012400014421556642014615 0ustar bllbll#!/bin/sh # # Copyright 2011-2018 Brad Lanam Walnut Creek CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for d-main.sh (d-main.sh) # 4 - temporary for d-main.sh (d-main.sh) # require_unit d-support require_unit c-support _MKCONFIG_PREFIX=d _MKCONFIG_HASEMPTY=F _MKCONFIG_EXPORT=F PH_PREFIX="mkc_ph." PH_STD=F PH_ALL=F PI_PREFIX="mkc_pi." PI_ALL=F chdr_standard_done=F ENUM1="" ENUM2="" ENUM3="" if [ "$DVERSION" = 1 ]; then ENUM1=": " ENUM2="{ " ENUM3=" }" fi _init_var_lists () { cdefs="" cdcls="" ctypes="" cstructs="" cmacros="" daliases="" dasserts="" modname="" } _create_enum () { out=F type=$1 if [ $type = "-o" ]; then out=T shift type=$1 fi var=$2 val=$3 estr="enum " e1=$ENUM1 e2=$ENUM2 e3=$ENUM3 strq="" if [ $type = string ]; then strq="\"" if [ "$DVERSION" = 1 ]; then estr="" e1="" e2="" e3="" fi fi if [ $type = double ]; then if [ "$DVERSION" = 1 ]; then estr="" e1="" e2="" e3="" fi fi tenum="${estr}${e1}${type} ${e2}${var} = ${strq}${val}${strq}${e3};" if [ $out = T ]; then puts $tenum fi } modify_ctypes () { tmcnm1=$1 tcode1=$2 # modify c types cmd=" sed -e 's/[ ]long[ ]*int[ ]/ long /g;# still C' \ -e 's/[ ]short[ ]*int\([ *]\)/ short\1/g;# still C' \ -e 's/[ ]signed[ ]*/ /g;# still C' \ -e 's/[ ]long[ ]*double\([ *]\)/ xlongdx\1/g' \ -e 's/double\([ *]\)/xdoublex\1/g' \ -e 's/float\([ *]\)/xfloatx\1/g' \ -e 's/unsigned[ ]long[ ]*long\([ *]\)/uxlonglongx\1/g' \ -e 's/long[ ]*long\([ *]\)/xlonglongx\1/g' \ -e 's/unsigned[ ]*short\([ *]\)/uxshortx\1/g' \ -e 's/unsigned[ ]*char\([ *]\)/uxbytex\1/g' \ -e 's/unsigned[ ]*int\([ *]\)/uxintx\1/g' \ -e 's/unsigned[ ]*long\([ *]\)/uxlongx\1/g' \ -e 's/[ ]unsigned\([ *]\)/ uxintx\1/g; # unsigned w/o any type' \ -e 's/[ ]char\([ *]\)/ xcharx\1/g' \ -e 's/[ ]short\([ *]\)/ xshortx\1/g' \ -e 's/[ ]int\([ *]\)/ xintx\1/g' \ -e 's/[ ]long\([ *]\)/ xlongx\1/g' \ | sed -e 's/xlongdx/${_c_long_double}/g' \ -e 's/xdoublex/${_c_double}/g' \ -e 's/xfloatx/${_c_float}/g' \ -e 's/xlonglongx/${_c_long_long}/g' \ -e 's/xlongx/${_c_long}/g' \ -e 's/xintx/${_c_int}/g' \ -e 's/xshortx/${_c_short}/g' \ -e 's/xcharx/${_c_char}/g' \ -e 's/xbytex/byte/g' " puts "##### modify_ctypes" >&9 # puts "##### modify_ctypes: before" >&9 # puts "$tcode1" >&9 # puts "##### modify_ctypes: end before" >&9 # puts "##### modify_ctypes: $cmd" >&9 eval "${tmcnm1}=\`puts \"\${tcode1}\" | ${cmd}\`" >&9 2>&9 # puts "#### modify_ctypes: after" >&9 # eval "puts \"\$${tmcnm1}\"" >&9 # puts "#### modify_ctypes: end after" >&9 } modify_cchglist () { tmcnm2=$1 tcode2=$2 puts "##### modify_cchglist" >&9 # puts "##### modify_cchglist: before" >&9 # puts "$tcode2" >&9 # puts "##### modify_cchglist: end before" >&9 cmd="sed ${cchglist2} -e 's/a/a/;# could be empty'" # puts "##### modify_cchglist: $cmd" >&9 eval "tcode2=\`puts \"\${tcode2}\" | ${cmd}\`" >&9 2>&9 cmd="sed ${cchglist1} -e 's/a/a/;# could be empty'" # puts "##### modify_cchglist: $cmd" >&9 eval "tcode2=\`puts \"\${tcode2}\" | ${cmd}\`" >&9 2>&9 # puts "#### modify_cchglist: after" >&9 # puts "${tcode2}" >&9 # puts "#### modify_cchglist: end after" >&9 eval "${tmcnm2}=\"\${tcode2}\"" } modify_ccode () { tmcnm3=$1 tcode3=$2 puts "##### modify_ccode" >&9 # puts "##### modify_ccode: before" >&9 # puts "$tcode3" >&9 # puts "##### modify_ccode: end before" >&9 cmd=" sed -e 's/[ ][ ]*/ /g;# clean up spacing' \ -e 's,/\*[^\*]*\*/,,;# remove /* comments' \ -e 's,//.*$,,;# remove // comments' \ -e '# change sizeof(v) to v.sizeof' \ -e 's/sizeof[ ]*\(([^)]*)\)/\1.sizeof/g' \ -e '# remove gcc-isms' \ -e 's/__extension__//g;# gcc-ism' \ -e 's/__const\([^a-zA-Z0-9_]\)/\1/g;# gcc-ism' \ -e 's/\*[ ]*const/*/g; # not handled: change *const to *' \ -e '# change version to version_ (reserved keyword)' \ -e 's/\([^a-zA-Z0-9_]\)version\([^a-zA-Z0-9_]\)/\1version_\2/g' \ -e '# remove spacing before braces' \ -e 's/[ ]*\([{}]\)/ \1/;' \ " # puts "##### modify_ccode: ${cmd}" >&9 eval "tcode3=\`puts \"\${tcode3}\" | ${cmd} \`" >&9 2>&9 # puts "#### modify_ccode: after A" >&9 # puts "${tcode3}" >&9 # puts "#### modify_ccode: end after A" >&9 modify_cchglist tcode3 "${tcode3}" cmd="sed -e '# handle multi-line statements' \ -e '# next lines append any line w/o semicolon or open brace' \ -e '# this is necessary for the function conversion to work.' \ -e '/^[^;{]*$/ N' \ -e '/^[^;{]*$/ N' \ -e '/^[^;{]*$/ N' \ -e '/^[^;{]*$/ N' \ -e '/^[^;{]*$/ N' \ -e '# convert functions' \ -e 's/^\(.*\)([ ]*\*[ ]*\([a-zA-Z0-9_][a-zA-Z0-9_]*\)[ ]*)[ ]*(\(.*\))[^(),a-zA-Z0-9_*]*;/\1 function(\3) \2;/' \ -e 's/^\(.*alias.*\)[ ][ *]*\([a-zA-Z0-9_][a-zA-Z0-9_]*\)[ ][ ]*(\(.*\))[^(),a-zA-Z0-9_*]*;/\1 function(\3) \2;/' \ -e '# change (void) to ()' \ -e 's/( *void *)/()/' \ -e '# no const functions' \ -e 's/^ *const\( *\)/\1/' \ | sed -e '# leading double underscores are not allowed' \ -e 's/\([ \*]\)__/\1_t_/g' \ -e 's/_t_FILE__/__FILE__/g; # revert' \ -e 's/_t_LINE__/__LINE__/g; # revert' \ -e '# change casts...these do not have the word function...' \ -e '/function/! s/\(([ ]*[a-zA-Z_][a-zA-Z0-9_]*[ *]*)[ ]*[a-zA-Z0-9_(]\)/cast\1/g' \ | sed -e '/^_END_;$/d; # workaround for sed N above' " # puts "##### modify_ccode: ${cmd}" >&9 # add _END_; as workaround for sed N above eval "tcode3=\`puts \"\${tcode3} _END_;\" | ${cmd} \`" >&9 2>&9 if [ "$DVERSION" = 1 ]; then cmd="sed -e 's/const *//g; # remove all const'" eval "tcode3=\`puts \"\${tcode3}\" | ${cmd} \`" >&9 2>&9 fi # puts "#### modify_ccode: after B" >&9 # puts "${tcode3}" >&9 # puts "#### modify_ccode: end after B" >&9 eval "${tmcnm3}=\"\${tcode3}\"" } dump_ccode () { ccode="" if [ "${cdefs}" != "" ]; then doappend ccode "${cdefs}" fi if [ "${ctypes}" != "" ]; then doappend ccode " extern (C) { ${ctypes} } // extern (C) " fi if [ "${cstructs}" != "" ]; then doappend ccode " extern (C) { ${cstructs} } // extern (C) " fi if [ "${cdcls}" != "" ]; then doappend ccode " extern (C) { ${cdcls} } // extern (C) " fi if [ "${ccode}" != "" ]; then # handle types separately; don't want to do this on converted macros modify_ctypes ccode "${ccode}" fi if [ "${cmacros}" != "" ]; then # macros don't get wrapped in extern(C). They are helper functions, # not replacements. doappend ccode " ${cmacros} " fi if [ "${ccode}" != "" ]; then puts "" modify_ccode ccode "${ccode}" puts "${ccode}" fi if [ "${daliases}" != "" ]; then puts "${daliases}" fi if [ "${dasserts}" != "" ]; then puts "${dasserts}" fi } create_chdr_nm () { chvar=$1 thdr=$2 tnm=$thdr # dots are for relative pathnames... dosubst tnm '/' '_' ':' '_' '\.h' '' '\.' '' case $tnm in sys_*) tnm="_${tnm}" ;; *) tnm="_hdr_${tnm}" ;; esac eval "$chvar=${tnm}" } preconfigfile () { pc_configfile=$1 configfile=$2 puts "DC: ${DC}" >&9 puts "DVERSION: ${DVERSION}" >&9 puts "DFLAGS: ${DFLAGS}" >&9 puts "LDFLAGS: ${LDFLAGS}" >&9 puts "LIBS: ${LIBS}" >&9 puts "DC_OF: ${DC_OF}" >&9 puts "// Created on: `date`" puts "// From: ${configfile}" puts "// Using: mkconfig-${_MKCONFIG_VERSION}" if [ "$modname" != "" ]; then puts '' puts "module $modname;" fi if [ "$DVERSION" = 2 ]; then getdata tval ${_MKCONFIG_PREFIX} '_import_std_string' if [ "$tval" != "0" -a "$tval" != "" ]; then puts '' puts "import std.string;" fi fi getdata tval ${_MKCONFIG_PREFIX} '_type_string' if [ "$tval" = "0" ]; then puts "alias char[] string;" fi if [ "${_MKCONFIG_SYSTYPE}" != "" ]; then _create_enum -o string SYSTYPE "${_MKCONFIG_SYSTYPE}" fi cmd="dump_ccode" if [ $noprefix = T ]; then cmd="$cmd | sed -e 's/C_ST_//g' -e 's/C_ENUM_//g' -e 's/C_UN_//'g \ -e 's/C_TYP_//g' -e 's/C_MACRO_//g' " fi eval $cmd if [ "${DC}" = "" ]; then puts "No compiler specified" >&2 return fi } stdconfigfile () { pc_configfile=$1 } postconfigfile () { pc_configfile=$1 } standard_checks () { if [ "${DC}" = "" ]; then puts "No compiler specified" >&2 return fi check_import import std.string check_type type string check_tangolib # this will be output as an enum also. setdata ${_MKCONFIG_PREFIX} _setint_D_VERSION ${DVERSION} } check_type () { shift type=$@ nm="_type_${type}" dosubst nm ' ' '_' name=$nm dosubst type 'star' '*' printlabel $name "type: ${type}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code=" ${type} value; struct xxx { ${type} mem; }; static xxx v; xxx* f() { return &v; }; int main () { xxx *tmp; tmp = f(); return (0); } " do_d_check_compile ${name} "${code}" all } check_tangolib () { tname=_d_tango_lib printlabel $tname "Tango lib:" checkcache ${_MKCONFIG_PREFIX} $tname if [ $rc -eq 0 ]; then return; fi code=" import tango.io.Stdout; int main () { Stdout (\"hello world\"); return (0); } " do_d_check_compile ${tname} "${code}" all } check_import () { type=$1 imp=$2 shift;shift reqimp=$* nm1=`puts ${imp} | sed -e 's,/.*,,'` nm2="_`puts $imp | sed -e \"s,^${nm1},,\" -e 's,^/*,,'`" nm="_${type}_${nm1}" if [ "$nm2" != "_" ]; then doappend nm $nm2 fi dosubst nm '/' '_' '\.' '_' name=$nm file=$imp printlabel $name "import: ${file}" # no cache check code="" if [ "${reqimp}" != "" ]; then set ${reqimp} while test $# -gt 0; do doappend code "import $1; " shift done fi doappend code "import $file; int main (char[][] args) { return 0; } " rc=1 > ${name}.d # re-init file _d_chk_compile ${name} "${code}" std rc=$? val=0 if [ $rc -eq 0 ]; then val=${file} fi printyesno $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_member () { shift struct=$1 shift member=$1 nm="_mem_${struct}_${member}" dosubst nm ' ' '_' name=$nm printlabel $name "exists: ${struct}.${member}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="void main (char[][] args) { ${struct} stmp; int i; i = stmp.${member}.sizeof; }" do_d_check_compile ${name} "${code}" all } check_size () { shift type=$* nm="_siz_${type}" dosubst nm ' ' '_' name=$nm getdata tangoval ${_MKCONFIG_PREFIX} '_d_tango_lib' printlabel $name "sizeof: ${type}" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi if [ $tangoval -eq 0 ]; then code="import std.stdio; void main (char[][] args) { writef(\"%d\", (${type}).sizeof); }" else code="import tango.io.Stdout; void main (char[][] args) { Stdout ((${type}).sizeof); }" fi _d_chk_run ${name} "${code}" all rc=$? val=$_retval if [ $rc -ne 0 ]; then val=0 fi printyesno_val $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_lib () { func=$2 shift;shift libs=$* nm="_lib_${func}" otherlibs=${libs} name=$nm rfunc=$func dosubst rfunc '_dollar_' '$' if [ "${otherlibs}" != "" ]; then printlabel $name "function: ${rfunc} [${otherlibs}]" # code to check the cache for which libraries is not written else printlabel $name "function: ${rfunc}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi fi trc=0 code="int main (char[][] args) { auto f = ${rfunc}; return (is(typeof(${rfunc}) == return)); }" _d_chk_run ${name} "${code}" all rc=$? if [ $rc -eq 1 ]; then rc=0 else rc=1 fi dlibs=$_retdlibs if [ $rc -eq 0 ]; then trc=1 fi tag="" if [ $rc -eq 0 -a "$dlibs" != "" ]; then tag=" with ${dlibs}" cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi printyesno $name $trc "$tag" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_class () { class=$2 shift;shift libs=$* nm="_class_${class}" dosubst nm '/' '_' ':' '_' otherlibs=${libs} name=$nm trc=0 if [ "$otherlibs" != "" ]; then printlabel $name "class: ${class} [${otherlibs}]" else printlabel $name "class: ${class}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi fi code="void main (char[][] args) { ${class} testclass; testclass = new ${class}; }" _d_chk_link_libs ${name} "${code}" all rc=$? if [ $rc -eq 0 ]; then trc=1 fi tag="" if [ $rc -eq 0 -a "${dlibs}" != "" ]; then tag=" with ${dlibs}" cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi printyesno $name $trc "$tag" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } _map_int_csize () { nm=$1 eval "tnm=_csiz_${nm}" getdata tval ${_MKCONFIG_PREFIX} $tnm mval="" if [ $tval -eq 1 ]; then mval=char; fi # leave char as char if [ $tval -eq 2 ]; then mval=short; fi if [ $tval -eq 4 ]; then mval=int; fi if [ $tval -eq 8 ]; then mval=long; fi if [ "$mval" = "" ]; then mval=long; fi doappend daliases "alias ${mval} C_NATIVE_${nm}; " eval "_c_${nm}=${mval}" if [ ${nm} != char ]; then doappend daliases "alias u${mval} C_NATIVE_unsigned_${nm}; " eval "_c_unsigned_${nm}=u${mval}" fi } _map_float_csize () { nm=$1 eval "tnm=_csiz_${nm}" getdata tval ${_MKCONFIG_PREFIX} $tnm mval="" if [ $tval -eq 4 ]; then mval=float; fi if [ $tval -eq 8 ]; then mval=double; fi if [ $tval -eq 12 ]; then mval=real; fi if [ "$mval" = "" ]; then mval=real; fi doappend daliases "alias ${mval} C_NATIVE_${nm}; " eval "_c_${nm}=${mval}" } # the rest of the check() routines are for the C/D language interface. check_csizes () { check_csize int char check_csize int short check_csize int int check_csize int long check_csize int "long long" check_csize float float check_csize float double check_csize float "long double" _map_int_csize char _map_int_csize short _map_int_csize int _map_int_csize long _map_int_csize long_long _map_float_csize float _map_float_csize double _map_float_csize long_double } check_csize () { basetype=$1 shift type=$* nm="_csiz_${type}" dosubst nm ' ' '_' name=$nm printlabel $name "c-sizeof: ${type}" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="main () { printf(\"%u\", sizeof(${type})); return (0); }" _c_chk_run ${name} "${code}" all rc=$? val=$_retval if [ $rc -ne 0 ]; then val=0 fi printyesno_val $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_clib () { func=$2 shift;shift libs=$* nm="_clib_${func}" otherlibs=${libs} name=$nm rfunc=$func dosubst rfunc '_dollar_' '$' if [ "${otherlibs}" != "" ]; then printlabel $name "c-function: ${rfunc} [${otherlibs}]" # code to check the cache for which libraries is not written else printlabel $name "c-function: ${rfunc}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi fi trc=0 code=" extern (C) { void ${rfunc}(); } alias int function () _TEST_fun_; _TEST_fun_ i= cast(_TEST_fun_) &${rfunc}; void main (char[][] args) { i(); } " _d_chk_link_libs ${name} "${code}" all rc=$? dlibs=$_retdlibs if [ $rc -eq 0 ]; then trc=1 fi tag="" if [ $rc -eq 0 -a "$dlibs" != "" ]; then tag=" with ${dlibs}" cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi printyesno $name $trc "$tag" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_chdr () { chdrargs=$@ if [ $chdr_standard_done = F ]; then _check_chdr chdr "stdio.h" _check_chdr chdr "stdlib.h" _check_chdr csys "types.h" _check_chdr csys "param.h" PH_STD=T PH_ALL=T chdr_standard_done=T fi _check_chdr $chdrargs } _check_chdr () { type=$1 hdr=$2 shift;shift reqhdr=$* case ${type} in csys) hdr="sys/${hdr}" ;; esac create_chdr_nm nm $hdr name=$nm printlabel $name "c-header: ${hdr}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="" if [ "${reqhdr}" != "" ]; then set ${reqhdr} while test $# -gt 0; do doappend code " #include <$1> " shift done fi doappend code "#include <${hdr}> main () { return (0); } " _c_chk_compile ${name} "${code}" std rc=$? val=0 if [ $rc -eq 0 ]; then val=${hdr} fi if [ "$CPPCOUNTER" != "" ]; then domath CPPCOUNTER "$CPPCOUNTER + 1" fi printyesno $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_csys () { check_chdr $@ } check_cdefine () { btype=$2 defname=$3 shift;shift;shift nm="_cdefine_${defname}" name=$nm printlabel $name "c-define ($btype): ${defname}" # no cache case $btype in short) o="%d" btype2=${_c_short} ;; int) o="%d" btype2=${_c_int} ;; long) o="%ld" btype2=${_c_long} ;; longlong) o="%lld" btype2=${_c_long_long} ;; hexshort) o="0x%x" btype2=${_c_short} ;; hex) o="0x%x" btype2=${_c_int} ;; hexlong) o="0x%lx" btype2=${_c_long} ;; hexlonglong) o="0x%llx" btype2=${_c_long_long} ;; float) o="%g" btype2=double ;; string) o="%s" btype2=string ;; char) o="%s" btype2=char ;; esac suffix="" if [ $btype2 = long ]; then suffix=L fi code="int main () { printf (\"${o}${suffix}\", ${defname}); return (0); }" _c_chk_run ${name} "${code}" all rc=$? if [ $rc -lt 0 ]; then _exitmkconfig $rc fi val=$_retval trc=0 if [ $rc -eq 0 -a "$val" != "" ]; then _create_enum ${btype2} ${defname} "${val}" trc=1 doappend cdefs "${tenum} " fi printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_ctype () { type=$2 typname=$3 shift;shift;shift nm="_ctype_${typname}" name=$nm printlabel $name "c-type ($type): ${typname}" # no cache val=0 u="" code="int main () { printf (\"%u\", sizeof(${typname})); return (0); }" _c_chk_cpp ${name} "${code}" all rc=$? if [ $rc -eq 0 ]; then tdata=`egrep ".*typedef.*[ \*]+${typname}[ ]*;" $name.out 2>/dev/null | sed -e 's/ *__attribute__ *(.*) *//' ` rc=$? if [ $rc -eq 0 ]; then _c_chk_run ${name} "${code}" all rc=$? val=$_retval fi fi if [ $rc -eq 0 ]; then code="int main () { int rc; ${typname} ww; ww = ~ 0; rc = ww < 0 ? 0 : 1; printf (\"%d\", rc); return (0); }" _c_chk_run ${name}_uchk "${code}" all rc=$? uval=$_retval if [ $rc -ne 0 ]; then uval=0 fi if [ $uval -eq 1 ]; then u=u fi fi if [ $type = int -a $rc -eq 0 ]; then case $val in 1) dtype=byte ;; 2) dtype=short ;; 4) dtype=int ;; *) dtype=long ;; esac fi if [ $type = float -a $rc -eq 0 ]; then case $val in 4) dtype=float ;; 8) dtype=double ;; *) dtype=real ;; esac fi if [ $rc -eq 0 ]; then ntypname=$typname ntypname=C_TYP_${ntypname} if [ $noprefix = F -o ${dtype} != ${ntypname} ]; then doappend daliases "alias ${u}${dtype} ${ntypname}; " fi doappend dasserts "static assert ((${ntypname}).sizeof == ${val}); " doappend cchglist1 "-e 's/\([^a-zA-Z0-9_]\)${typname}\([^a-zA-Z0-9_]\)/\1${ntypname}\2/g' " fi printyesno_val $name $val "" setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_ctypedef () { type=$1 typname=$2 shift;shift nm="_ctypedef_${typname}" name=$nm printlabel $name "c-typedef: ${typname}" # no cache # check and see if typedef already done by cstruct. # check and make sure cstruct was executed. getdata tval ${_MKCONFIG_PREFIX} $name puts "## chk:got:$tval: for $name" >&9 if [ "$tval" != 0 -a "$tval" != 1 -a "$tval" != "" ]; then getdata ttval ${_MKCONFIG_PREFIX} _cstruct_$tval puts "## chk:got:$ttval: for _cstruct_$tval" >&9 if [ "$ttval" = 1 ]; then puts "## already done by cstruct" >&9 # reset data to 1. setdata ${_MKCONFIG_PREFIX} ${name} 1 printyesno $name "already" return fi fi trc=0 code="" _c_chk_cpp ${name} "" all rc=$? if [ $rc -eq 0 ]; then tdata=`${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcexttypedef.awk ${name}.out ${typname}` tdata=`puts $tdata` # make single line. puts "## tdata(0): ${tdata}" >&9 if [ "$tdata" != "" ]; then trc=1 tdata=`puts $tdata | sed -e \ 's/^\(.*\)([ *]*\([a-zA-Z0-9_][a-zA-Z0-9_]*\)[ ]*)[ ]*(\(.*\))[ ]*;/\1 function(\3) \2;/' \ -e 's/[ ]*;/;/'` puts "## tdata(B): ${tdata}" >&9 dosubst tdata typedef alias puts "## tdata(c): ${tdata}" >&9 tta=a ttb=b if [ $noprefix = T ]; then ttl=`puts $tdata | sed 's/^alias *[sue][trucniom]* *\([a-zA-Z0-9_]*\) *\([a-zA-Z0-9_]*\);/\1 \2/'` set $ttl if [ $# -eq 2 ]; then tta=$1 ttb=$2 fi fi if [ $tta != $ttb ]; then doappend ctypes "$tdata " fi fi fi printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } _findheader () { fhpat=$1 shift # need path to header file if [ "$cmpaths" = "" ]; then cmpaths="/usr/include . " if [ "$CFLAGS" != "" ]; then next=F for f in $CFLAGS; do if [ $next = T ]; then doappend cmpaths ' ' doappend cmpaths $f fi next=F case $f in -I*) if [ $f = "-I" ]; then next=T else dosubst f '-I' '' doappend cmpaths ' ' doappend cmpaths $f fi ;; esac done fi fi fhrc=0 while test $# -gt 0; do thdr=$1 case $thdr in *.h) create_chdr_nm nhdr $thdr getdata vhdr ${_MKCONFIG_PREFIX} $nhdr puts " checking $thdr : $nhdr : $vhdr " >&9 if [ "${vhdr}" != "0" -a "${vhdr}" != "" ]; then for p in $cmpaths; do puts " checking $p/$thdr for $fhpat" >&9 if [ -f $p/$thdr ]; then egrep "$fhpat" $p/$thdr >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then fhrc=1 fhdr=$p/$thdr puts " found $fhdr for $mname" >&9 break fi fi done fi ;; *) break ;; esac shift done } check_cmacro () { mname=$2 shift;shift nm="_cmacro_${mname}" name=$nm printlabel $name "c-macro: ${mname}" # no cache trc=0 cmpaths="" _findheader "define[ ]*${mname}[^a-zA-Z0-9_]" $@ puts " \$@:$@" >&9 # eat the rest of the .h args while test $# -gt 0; do thdr=$1 case $thdr in *.h) ;; *) break ;; esac shift done if [ $fhrc -eq 1 ]; then macro=`${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextmacro.awk $fhdr ${mname}` puts " extracted macro: $macro" >&9 macro=`puts ${macro} | sed -e 's/ / /g;# tab to space' \ -e 's/^# *define *//' \ -e 's/\$/; }/' \ -e 's/([ *]*\(a-zA-Z0-9_]*\))->/\1./g' \ -e 's/->/./g' \ -e 's/(\([a-zA-Z0-9_]*\))\./\1./g;# (name). to name.' \ -e 's/^/auto C_MACRO_/' \ -e 's/\(C_MACRO_[a-zA-Z0-9_]*([^)]*) *\)/\1 { return /' \ -e 's/\(C_MACRO_[a-zA-Z0-9_]* *\)/\1 () { return /'` puts " initial macro: $macro" >&9 trc=1 fi # always pull the type off the list, even for D2 type=$1 shift if [ "$type" = "" ]; then type=int fi if [ "$type" = void ]; then macro=`puts ${macro} | sed -e "s/return//"` fi if [ "$DVERSION" = 1 -a $rc -eq 0 -a $trc -eq 1 ]; then macro=`puts ${macro} | sed -e "s/^auto/${type}/"` puts " macroC: $macro" >&9 fi tfirst=1 if [ $rc -eq 0 -a $trc -eq 1 -a $# -gt 0 ]; then while test $# -gt 0; do type=$1 if [ $tfirst -eq 1 ]; then macro=`puts ${macro} | sed -e "s/(/(${type} /" ` puts " macroD: $macro" >&9 tfirst=0 ttype=`puts $type | sed 's/\*/\\\\*/g'` tmp="($ttype [a-zA-Z0-9_]*" else puts " tmp: $tmp" >&9 cmd="macro=\`puts \${macro} | sed -e 's/\(${tmp}\) *, */\\\\1, ${type} /'\`" puts " cmdE: $cmd" >&9 eval $cmd puts " macroE: $macro" >&9 ttype=`puts $type | sed 's/\*/\\\\*/g'` doappend tmp ", ${ttype} [a-zA-Z0-9_]*" fi shift done fi if [ $rc -eq 0 -a $trc -eq 1 ]; then nmname=$mname nmname=C_MACRO_${nmname} doappend cmacros "${macro} " doappend cchglist1 "-e 's/\([^a-zA-Z0-9_]\)${mname}\([^a-zA-Z0-9_]\)/\1${nmname}\2/g' " fi printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_cunion () { check_cstruct $@ } check_cenum () { check_cstruct $@ } check_cstruct () { type=$1 s=$2 shift;shift nm="_${type}_${s}" ctype=$type ctype=`puts $ctype | sed -e 's/^c//'` lab=C_ST_ case $ctype in enum) lab=C_ENUM_ ;; union) lab=C_UN_ ;; esac name=$nm printlabel $name "c-${ctype}: ${s}" # no cache code="" _c_chk_cpp $name "" all rc=$? trc=0 rval=0 origstnm="" stnm="" tdnm="" havest=F if [ $rc -eq 0 ]; then st=`${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextstruct.awk -v dcode=T ${name}.out ${s} ` puts "#### initial ${ctype}" >&9 puts "${st}" >&9 puts "#### end initial ${ctype}" >&9 if [ "${st}" != "" ]; then havest=T tst=`puts ${st} | sed -e 's/{.*}/ = /' -e 's/[ ]/ /g' -e 's/ / /g' \ -e 's/^ *//' -e 's/[ ;]*\$//'` puts "### ${ctype} basics:${tst}:" >&9 # should now be: [typedef] {struct|union|enum} [name] = [name2] if [ "${tst}" != "" ]; then set ${tst} havetypedef=F if [ $1 = typedef ]; then havetypedef=T shift fi shift # the type, which we know already if [ $1 != "=" ]; then stnm=$1 shift fi shift # remove the equals sign if [ $# -gt 0 ]; then tdnm=$1 shift fi puts "#### stnm=${stnm}" >&9 otdnm=$tdnm dosubst otdnm '\*' '' ttdnm=$tdnm dosubst ttdnm '\*' '\\*' puts "#### tdnm=tdnm:${tdnm}:otdnm:${otdnm}:" >&9 if [ "$stnm" != "" -o "$otdnm" != "" ]; then trc=1 fi # remove 'typedef' keyword # remove trailing name before ; # remove "struct $stnm" # remove "struct" # remove all const # remove blank lines st=`puts "${st}" | sed -e 's/[ ]/ /g' -e 's/ / /g' \ -e 's/typedef *//' \ -e "s/${ttdnm} *;/;/; # typedef name or named struct" \ -e "s/ *${ctype} *${stnm} *{/{/" \ -e "s/^ *${ctype} *${stnm} *\$//" \ -e 's/\([^a-zA-Z0-9_]\)const\([^a-zA-Z0-9_]\)/\1 \2/g; # not supported' \ -e 's/^const\([^a-zA-Z0-9_]\)/\1/g; # not supported' \ | grep -v '^ *$' ` # change all other struct/union/enum to our tag. if [ "$stnm" != "" ]; then st=`puts "${st}" | sed -e "s/${ctype} *${stnm}\\([^a-zA-Z0-9_]\\)/${lab}${stnm}\\1/"` fi puts "#### modified ${ctype} (A)" >&9 puts ":${st}:" >&9 puts "#### end modified ${ctype} (A)" >&9 else trc=0 fi fi if [ $havest = T ]; then puts "### check for nested struct/union/enum" >&9 # look for any nested structure definitions as changed by # the awk extractor and add them to the cchglist. # remove the struct/union/enum tags from the structure now also # for those definitions that are found. tst=$st inst=0 bffound=F while read tsline; do case $tsline in *struct*{|*union*{|*enum*{) puts "### found: ${tsline}" >&9 ttype=`puts ${tsline} | sed -e 's/^[ const]*\([sue][trucniom]*\) *.*/\1/'` tl=`puts ${tsline} | sed -e "s/^.*${ttype} *\([a-zA-Z0-9_]*\) *{.*/\1/"` tlab=`puts ${tl} | sed 's/^\(C_[STUNEM]*_\).*/\1/'` tl=`puts ${tl} | sed -e "s/^${tlab}//"` puts "### ttype: ${ttype}" >&9 puts "### tlab: ${tlab}" >&9 puts "### tl: ${tl}" >&9 if [ "$tl" != "" ]; then st=`puts "${st}" | sed -e "s/${ttype} *${tl}/${tl}/g"` doappend cchglist2 "-e 's/\([^a-zA-Z0-9_]\)${tl}\([^a-zA-Z0-9_]\)/\1${tlab}${tl}\2/g' " doappend cchglist2 "-e 's/^${tl}\([^a-zA-Z0-9_]\)/${tlab}${tl}\1/g' " fi domath inst "$inst + 1" ;; *"}"*) if [ $inst -ge 1 ]; then tnname=`puts ${tsline} | sed -e 's/.*}[ *]*\([^; ]*\) *;/\1/'` # doesn't handle } w/no semi right. if [ "$tnname" != "" -a "$tnname" != "}" ]; then puts "### tnname:${tnname}:" >&9 doappend cchglist1 "-e 's/->${tnname}\././g' " doappend cchglist1 "-e 's/\.${tnname}\././g' " st=`puts "${st}" | sed -e "s/}[ *]*${tnname} *;/};/"` fi fi domath inst "$inst - 1" ;; *":"*) bffound=T ;; *) ;; esac # runs the 'while read' in the local shell, not a subshell. done << _HERE_ ${st} _HERE_ if [ $bffound = T ]; then nst="" inbf=0 bftsiz=0 bffcnt=1 while read tsline; do case $tsline in *":"*) inbf=1 tline=`puts $tsline | sed 's/.*://'` puts $tline | grep sizeof > /dev/null 2>&1 rc=$? while test $rc -eq 0; do ttval=`puts $tline | sed -e 's/.*sizeof *( *\([^)]*\) *).*/\1/'` tnm="_csiz_${ttval}" dosubst tnm ' ' '_' getdata tval ${_MKCONFIG_PREFIX} $tnm if [ "$tval" = "" ]; then tval=0 fi tline=`puts $tline | sed -e "s/\(.*\)sizeof *([^)]*)\(.*\)/\1 ${tval} \2/"` puts $tline | grep sizeof > /dev/null 2>&1 rc=$? done # remove casts tline=`puts $tline | \ sed -e 's/([a-z ]*)//g' -e 's/ *;//' -e 's// /g' -e 's/ / /g'` domath tval " $tline " domath bftsiz "$bftsiz + $tval" puts "## bf:$tline:$tval:$bftsiz" >&9 ;; *) if [ $inbf -eq 1 ]; then if [ $bftsiz -ne 0 ]; then domath tval "$bftsiz % 8" if [ $tval -eq 0 ]; then domath tval "$bftsiz / 8" puts "## bf:ubyte[$tval] bitfield_${s}${bffcnt};" >&9 doappend nst " ubyte[$tval] bitfield_${s}${bffcnt};" else doappend nst " #error: structure has bitfields that do not add to a multiple of 8. ubyte bitfield_${s}${bffcnt} : $bftsiz;" fi domath bffcnt "$bffcnt + 1" fi bftsiz=0 inbf=0 fi doappend nst " $tsline" ;; esac # runs the 'while read' in the local shell, not a subshell. done << _HERE_ ${st} _HERE_ puts "## old st:$st:" >&9 st=$nst puts "## new st:$st:" >&9 fi ts=$s if [ "$stnm" = "" -a "$tdnm" != "$otdnm" ]; then ts=${s}_ fi st=`( puts "${ctype} ${lab}${ts} "; puts "${st}" )` puts "#### modified ${ctype} (B)" >&9 puts "${st}" >&9 puts "#### end modified ${ctype} (B)" >&9 # save this for possible later use (cmembertype, cmemberxdr) cmd="CST_${s}=\${st}" eval $cmd puts " save: CST_${s}" >&9 else trc=0 fi if [ $trc -eq 1 ]; then if [ $ctype != enum ]; then # don't try to get size if there's no way to access the structure. # e.g. typedef struct { int a; } *b; if [ "$otdnm" = "" -o \ \( "$tdnm" != "" -a "$otdnm" = "$tdnm" \) ]; then tstnm=$otdnm if [ "$tstnm" = "" ]; then tstnm="${ctype} ${stnm}" # c language name fi puts "#### check size using: ${tstnm}" >&9 code="main () { printf (\"%d\", sizeof (${tstnm})); return (0); }" _c_chk_run ${name} "${code}" all rc=$? if [ $rc -lt 0 ]; then _exitmkconfig $rc fi rval=$_retval puts "#### not enum: rval=${rval}" >&9 if [ $rc -ne 0 ]; then trc=0 fi fi fi else trc=0 fi fi if [ $trc -eq 1 ]; then if [ "$stnm" != "" ]; then puts "## add to cchglist: -e 's/\([^a-zA-Z0-9_]\)${ctype} *${stnm}\([^a-zA-Z0-9_]\)/\1${lab}${s}\2/g' " >&9 doappend cchglist2 "-e 's/\([^a-zA-Z0-9_]\)${ctype} *${stnm}\([^a-zA-Z0-9_]\)/\1${lab}${s}\2/g' " puts "## add to cchglist: -e 's/^${ctype} *${stnm}\([^a-zA-Z0-9_]\)/${lab}${s}\1/g' " >&9 doappend cchglist2 "-e 's/^${ctype} *${stnm}\([^a-zA-Z0-9_]\)/${lab}${s}\1/g' " fi if [ $havetypedef = T -a "$otdnm" != "" ]; then puts "## add to cchglist: -e 's/\([^a-zA-Z0-9_]\)${otdnm}\([^a-zA-Z0-9_]\)/\1${lab}${s}\2/g' " >&9 doappend cchglist1 "-e 's/\([^a-zA-Z0-9_]\)${otdnm}\([^a-zA-Z0-9_]\)/\1${lab}${s}\2/g' " puts "## add to cchglist: -e 's/^${otdnm}\([^a-zA-Z0-9_]\)/${lab}${s}\1/g' " >&9 doappend cchglist1 "-e 's/^${otdnm}\([^a-zA-Z0-9_]\)/${lab}${s}\1/g' " fi doappend cstructs " ${st} " if [ $havetypedef = T -a "$otdnm" != "" ]; then # if noprefix is on, don't alias some name to itself. if [ $noprefix = F -o ${s} != ${tdnm} ]; then puts "## add alias: ${lab}${ts} ${tdnm}" >&9 setdata ${_MKCONFIG_PREFIX} _ctypedef_${otdnm} $s doappend daliases "alias ${lab}${ts} ${tdnm}; " fi fi if [ $havetypedef = T -a "$otdnm" != "" -a \ "$stnm" != "" -a "$stnm" != "$s" ]; then puts "## add alias: ${lab}${ts} ${lab}${stnm}" >&9 setdata ${_MKCONFIG_PREFIX} _ctypedef_${stnm} $s doappend daliases "alias ${lab}${ts} ${lab}${stnm}; " fi if [ $lab != enum -a $rval -gt 0 ]; then # save the size setdata ${_MKCONFIG_PREFIX} _csiz_${ctype}_${s} ${rval} doappend dasserts "static assert ((${lab}${s}).sizeof == ${rval}); " fi fi printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_cmember () { shift struct=$1 shift member=$1 nm="_cmem_${struct}_${member}" dosubst nm ' ' '_' name=$nm printlabel $name "exists (C): ${struct}.${member}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi trc=0 tdfile="${name}.d" > ${tdfile} exec 4>>${tdfile} dump_ccode >&4 exec 4>&- code="void main (char[][] args) { C_ST_${struct} stmp; int i; i = stmp.${member}.sizeof; }" do_d_check_compile ${name} "${code}" all } check_cmembertype () { shift struct=$1 shift member=$1 nm="_cmembertype_${struct}_${member}" dosubst nm ' ' '_' name=$nm printlabel $name "member:type (C): ${struct} ${member}" # no cache trc=0 cmd="st=\${CST_${struct}}" puts " get: ${cmd}" >&9 eval $cmd if [ "$st" != "" ]; then puts " struct ${struct}: ${st}" >&9 tmem=`puts "$st" | grep "${member} *;\$"` rc=$? puts " found: ${tmem}" >&9 if [ $rc -eq 0 ]; then mtype=`puts $tmem | sed -e "s/ *${member} *;$//" -e 's/^ *//'` puts " type:${mtype}:" >&9 puts " member:${member}:" >&9 trc=1 if [ "${mtype}" != "" -a "${member}" != "" -a \( \ $noprefix = F -o "${mtype}" != "${member}" \) ]; then doappend daliases "alias ${mtype} C_TYP_${member}; " fi fi fi printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_cmemberxdr () { shift struct=$1 shift member=$1 nm="_cmemberxdr_${struct}_${member}" dosubst nm ' ' '_' name=$nm printlabel $name "member:XDR (C): ${struct} ${member}" # no cache trc=0 cmd="st=\${CST_${struct}}" puts " get: ${cmd}" >&9 eval $cmd if [ "$st" != "" ]; then puts " struct ${struct}: ${st}" >&9 tmem=`puts "$st" | grep "${member} *;\$"` rc=$? puts " found: ${tmem}" >&9 if [ $rc -eq 0 ]; then mtype=`puts $tmem | sed -e "s/ *${member} *;$//" -e 's/^ *//'` puts " type: ${mtype}" >&9 trc=1 doappend daliases "alias xdr_${mtype} xdr_${member}; " fi fi printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_cdcl () { type=$1 dname=$2 argflag=0 ccount=0 noconst=F shift;shift if [ "$dname" = args ]; then argflag=1 dname=$1 shift if [ "$dname" = noconst ]; then noconst=T dname=$1 shift fi fi nm="_cdcl_${dname}" name=$nm printlabel $name "c-dcl: ${dname}" # no cache trc=0 oldprecc="${precc}" doappend precc "/* get rid of most gcc-isms */ /* keep __asm__ to check for function renames */ #define __attribute__(a) #define __nonnull__(a,b) #define __restrict #define __restrict__ #define __THROW #define __const const " code="" _c_chk_cpp ${name} "/**/" all # force no-reuse due to precc rc=$? if [ $rc -eq 0 ]; then egrep "[ \*]${dname}[ ]*\(" $name.out >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then trc=1 fi if [ $trc -eq 1 ]; then dcl=`${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextdcl.awk ${name}.out ${dname}` dcl=`puts $dcl` # make single line. puts "## dcl(0): ${dcl}" >&9 # extern will be replaced # ; may or may not be present, so remove it. cmd="dcl=\`puts \"\$dcl\" | sed -e 's/extern *//' -e 's/;//' \`" eval $cmd if [ "$DVERSION" = 1 ]; then dosubst dcl 'const' '' fi puts "## dcl(A): ${dcl}" >&9 puts $dcl | grep __asm__ > /dev/null 2>&1 rc=$? dclren="" if [ $rc -eq 0 ]; then dclren=`puts $dcl | sed -e 's/.*__asm__[ ]*("" "\([a-z0-9A-Z_]*\)")/\1/'` fi puts "## dclren: ${dclren}" >&9 if [ "$dclren" != "" ]; then doappend daliases "alias ${dclren} ${dname}; " cmd="dcl=\`puts \"\$dcl\" | \ sed -e 's/[ ]*__asm__[ ]*([^)]*)[ ]*//' \ -e 's/\([ \*]\)${dname}\([ (]\)/\1${dclren}\2/' \`" eval $cmd puts "## dcl(B): ${dcl}" >&9 fi cmd="dcl=\`puts \"\$dcl\" | sed -e 's/( *void *)/()/' \`" eval $cmd puts "## dcl(C): ${dcl}" >&9 tdcl=$dcl modify_ctypes tdcl "${tdcl}" modify_cchglist tdcl "${tdcl}" # need any struct renames for args puts "## tdcl(D): ${tdcl}" >&9 if [ $argflag = 1 ]; then c=`puts ${tdcl} | sed 's/[^,]*//g'` ccount=`putsnonl "$c" | wc -c` domath ccount "$ccount + 1" # 0==1 also, unfortunately c=`puts ${tdcl} | sed 's/^[^(]*(//'` c=`puts ${c} | sed 's/)[^)]*$//'` puts "## c(E): ${c}" >&9 val=1 while test "${c}" != ""; do tmp=$c tmp=`puts ${c} | sed -e 's/ *,.*$//' -e 's/[ ]/ /g'` dosubst tmp 'struct ' 'struct#' 'union ' 'union#' 'enum ' 'enum#' # only do the following if the names of the variables are declared puts ${tmp} | grep ' ' > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then tmp=`puts ${tmp} | sed -e 's/ *[A-Za-z0-9_]*$//'` fi dosubst tmp 'struct#' 'struct ' 'union#' 'union ' 'enum#' 'enum ' if [ $noconst = T ]; then tmp=`puts ${tmp} | sed -e 's/const *//'` fi puts "## tmp(F): ${tmp}" >&9 nm="_c_arg_${val}_${dname}" setdata ${_MKCONFIG_PREFIX} ${nm} "${tmp}" case ${tmp} in struct*|union*|enum*) ;; *) doappend daliases "alias ${tmp} ${nm}_alias; " ;; esac domath val "$val + 1" c=`puts ${c} | sed -e 's/^[^,]*//' -e 's/^[ ,]*//'` done tname=${dclren:-$dname} puts "## tname(G): ${tname} ($dname - $dclren)" >&9 c=`puts ${tdcl} | sed -e 's/[ ]/ /g' \ -e "s/\([ \*]\)${tname}[ (].*/\1/" \ -e 's/^ *//' \ -e 's/ *$//'` if [ $noconst = T ]; then c=`puts ${c} | sed -e 's/const *//'` fi nm="_c_type_${dname}" setdata ${_MKCONFIG_PREFIX} ${nm} "${c}" fi doappend cdcls " ${dcl}; " fi fi precc="${oldprecc}" printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} if [ $argflag = 1 ]; then nm="_c_args_${dname}" setdata ${_MKCONFIG_PREFIX} ${nm} ${ccount} fi } check_module () { type=$1 modname=$2 printlabel $name "module:" printyesno_val $name $modname } check_noprefix () { name=$1 noprefix=T printlabel $name "noprefix:" val=1 printyesno $name $val } output_item () { out=$1 name=$2 val=$3 tval=false if [ "$val" != "0" ]; then tval=true fi case ${name} in _setstr_*|_opt_*|_c_arg_*|_c_type_*) tname=$name dosubst tname '_setstr_' '' '_opt_' '' _create_enum -o string ${tname} "${val}" ;; _setint_*|_csiz_*|_siz_*|_c_args_*|_ctype_*) tname=$name dosubst tname '_setint_' '' _create_enum -o int ${tname} ${val} ;; *) _create_enum -o bool ${name} "${tval}" ;; esac } new_output_file () { _init_var_lists return } # initialization _init_var_lists cchglist1="" cchglist2="" cmpaths="" noprefix=F di-4.52/mkconfig/units/env-cc.sh0000755000175000017500000005127714421556642014642 0ustar bllbll#!/bin/sh # # Copyright 2001-2018 Brad Lanam, Walnut Creek, California USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # require_unit env-main require_unit env-systype env_dogetconf=F _MKCONFIG_32BIT_FLAGS=F # helper routine _setflags () { while test $# -gt 0; do _tvar=$1 _tenm=$2 shift;shift eval _tval=\$$_tvar dosubst _tval '^ *' '' setdata ${_MKCONFIG_PREFIX} ${_tenm} "$_tval" done } _dogetconf () { if [ "$env_dogetconf" = T ]; then return fi if [ ${_MKCONFIG_32BIT_FLAGS} = T ]; then lfccflags= lfldflags= lflibs= env_dogetconf=T return fi locatecmd xgetconf getconf if [ z${xgetconf} != z ] then puts "using flags from getconf" >&9 lfccflags="`${xgetconf} LFS_CFLAGS 2>/dev/null`" if [ "$lfccflags" = undefined ]; then lfccflags= fi lfldflags="`${xgetconf} LFS_LDFLAGS 2>/dev/null`" if [ "$lfldflags" = undefined ]; then lfldflags= fi lflibs="`${xgetconf} LFS_LIBS 2>/dev/null`" if [ "$lflibs" = undefined ]; then lflibs= fi fi env_dogetconf=T } check_32bitflags () { _MKCONFIG_32BIT_FLAGS=T printlabel _MKCONFIG_32BIT_FLAGS "32 bit flags" printyesno_val _MKCONFIG_32BIT_FLAGS "${_MKCONFIG_32BIT_FLAGS}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_32BIT_FLAGS "${_MKCONFIG_32BIT_FLAGS}" } check_cc () { _read_option CC cc CC=${CC:-${oval}} printlabel CC "C compiler" case ${_MKCONFIG_SYSTYPE} in BeOS|Haiku) case ${CC} in cc|gcc) CC=g++ ;; esac ;; syllable) case ${CC} in cc|gcc) CC=g++ ;; esac ;; esac puts "cc:${CC}" >&9 printyesno_val CC "${CC}" setdata ${_MKCONFIG_PREFIX} CC "${CC}" if [ ${_MKCONFIG_32BIT_FLAGS} = F ]; then setdata ${_MKCONFIG_PREFIX} _MKCONFIG_32BIT_FLAGS "${_MKCONFIG_32BIT_FLAGS}" fi } check_using_cplusplus () { usingcplusplus="N" printlabel _MKCONFIG_USING_CPLUSPLUS "Using c++" case ${CC} in *g++*|*clang++*|*c++*) usingcplusplus="Y" ;; esac printyesno_val _MKCONFIG_USING_CPLUSPLUS "${usingcplusplus}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_CPLUSPLUS "${usingcplusplus}" } check_using_gcc () { usinggcc="N" printlabel _MKCONFIG_USING_GCC "Using gcc/g++" # check for gcc... ${CC} -v 2>&1 | grep 'gcc version' >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then puts "found gcc" >&9 usinggcc="Y" fi case ${CC} in *gcc*|*g++*) usinggcc="Y" ;; esac printyesno_val _MKCONFIG_USING_GCC "${usinggcc}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_GCC "${usinggcc}" } check_using_clang () { usingclang="N" printlabel _MKCONFIG_USING_CLANG "Using clang" # check for clang... ${CC} -v 2>&1 | grep 'clang version' > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then puts "found clang" >&9 usingclang="Y" fi case ${CC} in *clang*) usingclang="Y" ;; esac printyesno_val _MKCONFIG_USING_CLANG "${usingclang}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_CLANG "${usingclang}" } check_using_gnu_ld () { usinggnuld="N" printlabel _MKCONFIG_USING_GNU_LD "Using gnu ld" # check for gnu ld... # dragonfly bsd 5.8.1 gcc8 reports 'GNU gold' rather than 'GNU ld'. ld -v 2>&1 | grep 'GNU' > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then puts "found gnu ld" >&9 usinggnuld="Y" fi printyesno_val _MKCONFIG_USING_GNU_LD "${usinggnuld}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_GNU_LD "${usinggnuld}" } check_cflags () { cflags_debug=${CFLAGS_DEBUG:-} cflags_optimize=${CFLAGS_OPTIMIZE:--O2} cflags_include=${CFLAGS_INCLUDE} cflags_user=${CFLAGS_USER} cflags_compiler=${CFLAGS_COMPILER} cflags_system=${CFLAGS_SYSTEM} cflags_application=${CFLAGS_APPLICATION} if [ "${_MKCONFIG_USING_GCC}" = Y ]; then puts "set gcc flags" >&9 gccflags="-Wall -Waggregate-return -Wconversion -Wformat -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes -Wunused -Wno-unknown-pragmas" # -Wextra -Wno-unused-but-set-variable -Wno-unused-parameter case ${CC} in g++|c++) if [ "${_MKCONFIG_USING_GCC}" = Y ]; then puts "set g++ flags" >&9 gccflags="-Wall -Waggregate-return -Wconversion -Wformat -Wpointer-arith -Wshadow -Wunused" fi ;; esac doappend cflags_compiler " $gccflags" fi if [ "${_MKCONFIG_USING_CLANG}" = Y ]; then puts "set clang flags" >&9 doappend cflags_compiler " -Wno-unknown-warning-option -Weverything -Wno-padded -Wno-format-nonliteral -Wno-cast-align -Wno-system-headers -Wno-disabled-macro-expansion" fi TCC=${CC} if [ "${_MKCONFIG_USING_GCC}" = Y ]; then TCC=gcc fi case ${_MKCONFIG_SYSTYPE} in AIX) if [ "${_MKCONFIG_USING_GCC}" = N ]; then doappend cflags_system " -qhalt=e -qmaxmem=-1" case ${_MKCONFIG_SYSREV} in 4.*) doappend cflags_system " -DUSE_ETC_FILESYSTEMS=1" ;; esac fi ;; DragonFly|FreeBSD|OpenBSD) # *BSD has many packages that get installed in /usr/local doappend cflags_include " -I/usr/local/include" ;; HP-UX) if [ "z${lfccflags}" = z -a "${_MKCONFIG_32BIT_FLAGS}" = F ]; then doappend cflags_system " -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" fi case ${TCC} in cc) case ${_MKCONFIG_SYSREV} in *.10.*) doappend cflags_system " +DAportable" ;; esac cc -v 2>&1 | grep -l Bundled > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ]; then doappend cflags_system " -Ae" fi _MKCONFIG_USING_GCC=N ;; esac if [ -d /usr/local/include -a \ -d /usr/local/lib ]; then doappend cflags_include " -I/usr/local/include" fi ;; SunOS) case ${_MKCONFIG_SYSREV} in 5.*) case ${TCC} in cc) # If solaris is compile w/strict ansi, we get # a work-around for the long long type with # large files. So we compile w/extensions. doappend cflags_system " -Xa -v" # optimization; -xO3 is good. -xO4 must be set by user. cflags_optimize="-xO3" ;; esac ;; esac ;; esac _dogetconf # largefile flags doappend cflags_system " $lfccflags" # plain CFLAGS will be interpreted as the user's cflags _read_option CFLAGS "" cflags_user=$CFLAGS _read_option CFLAGS_DEBUG "" if [ "z$CFLAGS_DEBUG" != z ]; then cflags_debug="$CFLAGS_DEBUG" fi _read_option CFLAGS_OPTIMIZE "" if [ "z$CFLAGS_OPTIMIZE" != z ]; then cflags_optimize="$CFLAGS_OPTIMIZE" fi _read_option CFLAGS_INCLUDE "" doappend cflags_include " $CFLAGS_INCLUDE" doappend cflags_include " $CPPFLAGS" puts "cflags_debug:${cflags_debug}" >&9 puts "cflags_optimize:${cflags_optimize}" >&9 puts "cflags_include:${cflags_include}" >&9 puts "cflags_user:${cflags_user}" >&9 puts "cflags_compiler:${cflags_compiler}" >&9 puts "cflags_system:${cflags_system}" >&9 puts "cflags_application:${cflags_application}" >&9 _setflags \ cflags_debug CFLAGS_DEBUG \ cflags_optimize CFLAGS_OPTIMIZE \ cflags_user CFLAGS_USER \ cflags_include CFLAGS_INCLUDE \ cflags_compiler CFLAGS_COMPILER \ cflags_system CFLAGS_SYSTEM \ cflags_application CFLAGS_APPLICATION } check_addcflag () { name=$1 flag=$2 printlabel CFLAGS_APPLICATION "Add C flag: ${flag}" test_cflag "$flag" printyesno $name "${flag}" if [ $flag != 0 ]; then doappend CFLAGS_APPLICATION " $flag" setdata ${_MKCONFIG_PREFIX} CFLAGS_APPLICATION "$CFLAGS_APPLICATION" fi } check_pkg_cflags () { name=$1 pkgname=$2 pkgpath=$3 OPKG_CONFIG_PATH=$PKG_CONFIG_PATH if [ "$pkgpath" != "" ]; then if [ "$PKG_CONFIG_PATH" != "" ]; then doappend PKG_CONFIG_PATH : fi doappend PKG_CONFIG_PATH $pkgpath fi export PKG_CONFIG_PATH tcflags=`${pkgconfigcmd} --cflags $pkgname` unset PKG_CONFIG_PATH if [ "$OPKG_CONFIG_PATH" != "" ]; then PKG_CONFIG_PATH=$OPKG_CONFIG_PATH fi test_cflag "$tcflags" printyesno_val $name "${flag}" if [ "$flag" != 0 ]; then doappend CFLAGS_APPLICATION " $flag" setdata ${_MKCONFIG_PREFIX} CFLAGS_APPLICATION "$CFLAGS_APPLICATION" fi } check_pkg_include () { name=$1 pkgname=$2 pkgpath=$3 OPKG_CONFIG_PATH=$PKG_CONFIG_PATH if [ "$pkgpath" != "" ]; then if [ "$PKG_CONFIG_PATH" != "" ]; then doappend PKG_CONFIG_PATH : fi doappend PKG_CONFIG_PATH $pkgpath fi export PKG_CONFIG_PATH tcflags=`${pkgconfigcmd} --cflags-only-I $pkgname` unset PKG_CONFIG_PATH if [ "$OPKG_CONFIG_PATH" != "" ]; then PKG_CONFIG_PATH=$OPKG_CONFIG_PATH fi test_cflag "$tcflags" printyesno_val $name "${flag}" if [ "$flag" != 0 ]; then doappend CFLAGS_APPLICATION " $flag" setdata ${_MKCONFIG_PREFIX} CFLAGS_APPLICATION "$CFLAGS_APPLICATION" fi } check_pkg_libs () { name=$1 pkgname=$2 pkgpath=$3 OPKG_CONFIG_PATH=$PKG_CONFIG_PATH if [ "$pkgpath" != "" ]; then if [ "$PKG_CONFIG_PATH" != "" ]; then doappend PKG_CONFIG_PATH : fi doappend PKG_CONFIG_PATH $pkgpath export PKG_CONFIG_PATH fi export PKG_CONFIG_PATH tldflags=`${pkgconfigcmd} --libs $pkgname` unset PKG_CONFIG_PATH if [ "$OPKG_CONFIG_PATH" != "" ]; then PKG_CONFIG_PATH=$OPKG_CONFIG_PATH fi test_ldflags "$tldflags" printyesno_val $name "$flag" if [ "$flag" != 0 ]; then doappend LDFLAGS_LIBS_APPLICATION " $flag" setdata ${_MKCONFIG_PREFIX} LDFLAGS_LIBS_APPLICATION "$LDFLAGS_LIBS_APPLICATION" fi } check_addldflag () { name=$1 flag=$2 printlabel LDFLAGS_APPLICATION "Add LD flag: ${flag}" test_ldflags "$flag" printyesno $name "$flag" if [ $flag != 0 ]; then doappend ldflags_application " $flag" _setflags ldflags_application LDFLAGS_APPLICATION fi } check_ldflags () { TCC=${CC} if [ "${_MKCONFIG_USING_GCC}" = Y ]; then TCC=gcc fi ldflags_debug=${LDFLAGS_DEBUG:-} ldflags_optimize=${LDFLAGS_OPTIMIZE:-} ldflags_user=${LDFLAGS_USER:-} ldflags_compiler=${LDFLAGS_COMPILER:-} ldflags_system=${LDFLAGS_SYSTEM:-} ldflags_application=${LDFLAGS_APPLICATION:-} doappend ldflags_system " $lfldflags" case ${_MKCONFIG_SYSTYPE} in FreeBSD) # FreeBSD has many packages that get installed in /usr/local doappend ldflags_system " -L/usr/local/lib" ;; HP-UX) # check for libintl in other places... if [ -d /usr/local/include -a \ -d /usr/local/lib ]; then doappend ldflags_system " -L/usr/local/lib" if [ -d /usr/local/lib/hpux32 ]; then doappend ldflags_system " -L/usr/local/lib/hpux32" fi fi case ${TCC} in cc) doappend ldflags_system " -Wl,+s" ;; esac ;; OS/2) doappend ldflags_system " -Zexe" ;; SunOS) case ${_MKCONFIG_SYSREV} in 5.*) case ${TCC} in cc) case $CFLAGS_OPTIMIZE in -xO[3456]) ldflags_optimize="-fast" ;; esac ;; esac ;; esac ;; esac _dogetconf # plain LDFLAGS will be interpreted as the user's ldflags _read_option LDFLAGS "" ldflags_user=$LDFLAGS _read_option LDFLAGS_DEBUG "" if [ "z$LDFLAGS_DEBUG" != z ]; then ldflags_debug="$LDFLAGS_DEBUG" else _read_option CFLAGS_DEBUG "" if [ "z$CFLAGS_DEBUG" != z ]; then ldflags_debug="$CFLAGS_DEBUG" fi fi _read_option LDFLAGS_OPTIMIZE "" if [ "z$LDFLAGS_OPTIMIZE" != z ]; then ldflags_optimize="$LDFLAGS_OPTIMIZE" else _read_option CFLAGS_OPTIMIZE "" if [ "z$CFLAGS_OPTIMIZE" != z ]; then ldflags_optimize="$CFLAGS_OPTIMIZE" fi fi puts "ldflags_debug:${ldflags_debug}" >&9 puts "ldflags_optimize:${ldflags_optimize}" >&9 puts "ldflags_user:${ldflags_user}" >&9 puts "ldflags_compiler:${ldflags_compiler}" >&9 puts "ldflags_system:${ldflags_system}" >&9 puts "ldflags_application:${ldflags_application}" >&9 _setflags \ ldflags_debug LDFLAGS_DEBUG \ ldflags_optimize LDFLAGS_OPTIMIZE \ ldflags_user LDFLAGS_USER \ ldflags_compiler LDFLAGS_COMPILER \ ldflags_system LDFLAGS_SYSTEM \ ldflags_application LDFLAGS_APPLICATION } check_libs () { _dogetconf ldflags_libs_user=${LDFLAGS_LIBS_USER:-} ldflags_libs_application=${LDFLAGS_LIBS_APPLICATION:-} ldflags_libs_system=${LDFLAGS_LIBS_SYSTEM:-} TCC=${CC} if [ "${_MKCONFIG_USING_GCC}" = Y ]; then TCC=gcc fi case ${_MKCONFIG_SYSTYPE} in BeOS|Haiku) # uname -m does not reflect actual architecture doappend ldflags_libs_system " -lroot -lbe" ;; esac # largefile flags doappend ldflags_libs_system " $lflibs" _read_option LIBS "" doappend ldflags_libs_user " $LIBS" puts "ldflags_libs_user:${ldflags_libs_user}" >&9 puts "ldflags_libs_application:${ldflags_libs_application}" >&9 puts "ldflags_libs_system:${ldflags_libs_system}" >&9 _setflags \ ldflags_libs_user LDFLAGS_LIBS_USER \ ldflags_libs_application LDFLAGS_LIBS_APPLICATION \ ldflags_libs_system LDFLAGS_LIBS_SYSTEM } # for backwards compatibility check_shcflags () { check_cflags_shared } check_cflags_shared () { printlabel CFLAGS_SHARED "shared library cflags" cflags_shared="" if [ "$_MKCONFIG_USING_GCC" != Y ]; then case ${_MKCONFIG_SYSTYPE} in CYGWIN*|MSYS*|MINGW*) # apparently, clang does not need this any more. doappend cflags_shared "" ;; Darwin) doappend cflags_shared " -fno-common" ;; HP-UX) doappend cflags_shared " +Z" ;; IRIX*) doappend cflags_shared " -KPIC" ;; OSF1) # none doappend cflags_shared " -fPIC" ;; SCO_SV) doappend cflags_shared " -KPIC" ;; SunOS) doappend cflags_shared " -KPIC" ;; UnixWare) doappend cflags_shared " -KPIC" ;; *) doappend cflags_shared " -fPIC" ;; esac else doappend cflags_shared " -fPIC" fi _read_option CFLAGS_SHARED "" if [ "z$CFLAGS_SHARED" != z ]; then cflags_shared_user="${CFLAGS_SHARED}" fi printyesno_val CFLAGS_SHARED "$cflags_shared $cflags_shared_user" _setflags \ cflags_shared CFLAGS_SHARED \ cflags_shared_user CFLAGS_SHARED_USER } # for backwards compatibility check_shldflags () { check_ldflags_shared } check_ldflags_shared () { printlabel LDFLAGS_SHARED_LIBLINK "shared library ldflags" if [ "$_MKCONFIG_USING_GCC" != Y ]; then case ${_MKCONFIG_SYSTYPE} in AIX) doappend ldflags_shared_liblink " -G" ;; Darwin) doappend ldflags_shared_liblink " -dynamiclib" ;; HP-UX) doappend ldflags_shared_liblink " -b" ;; IRIX*) # "-shared" doappend ldflags_shared_liblink " -shared" ;; OSF1) doappend ldflags_shared_liblink " -msym -no_archive -shared" ;; SCO_SV) doappend ldflags_shared_liblink " -G" ;; SunOS) doappend ldflags_shared_liblink " -G" ;; UnixWare) doappend ldflags_shared_liblink " -G" ;; *) doappend ldflags_shared_liblink " -shared" ;; esac else doappend ldflags_shared_liblink " -shared" fi _read_option LDFLAGS_SHARED "" if [ "z$LDFLAGS_SHARED" != z ]; then ldflags_shared_user="${LDFLAGS_SHARED}" fi printyesno_val LDFLAGS_SHARED "$ldflags_shared_liblink $ldflags_shared_user" _setflags \ ldflags_shared_liblink LDFLAGS_SHARED_LIBLINK ldflags_shared_user LDFLAGS_SHARED_USER } check_sharednameflag () { printlabel SHLDNAMEFLAG "shared lib name flag" SHLDNAMEFLAG="-Wl,-soname=" if [ "$_MKCONFIG_USING_GNU_LD" != Y ]; then case ${_MKCONFIG_SYSTYPE} in Darwin) # -compatibility_version -current_version ;; HP-UX) SHLDNAMEFLAG="-Wl,+h " ;; IRIX*) # -soname ;; OSF1) # -soname ;; SunOS) SHLDNAMEFLAG="-Wl,-h " ;; *) SHLDNAMEFLAG="" ;; esac fi printyesno_val SHLDNAMEFLAG "$SHLDNAMEFLAG" setdata ${_MKCONFIG_PREFIX} SHLDNAMEFLAG "$SHLDNAMEFLAG" } check_shareexeclinkflag () { printlabel LDFLAGS_EXEC_LINK "shared executable link flag " LDFLAGS_EXEC_LINK="-Bdynamic" if [ "$_MKCONFIG_USING_GNU_LD" != Y ]; then case ${_MKCONFIG_SYSTYPE} in AIX) LDFLAGS_EXEC_LINK="-brtl -bdynamic" ;; HP-UX) LDFLAGS_EXEC_LINK="" ;; OSF1) LDFLAGS_EXEC_LINK="" ;; SunOS) # -Bdynamic ;; *) LDFLAGS_EXEC_LINK="" ;; esac if [ "$_MKCONFIG_USING_GCC" = Y ]; then LDFLAGS_EXEC_LINK=`echo "$LDFLAGS_EXEC_LINK" | sed -e 's/^-/-Wl,-/' -e 's/^\+/-Wl,+/' -e 's/ */ -Wl,/g'` fi fi printyesno_val LDFLAGS_EXEC_LINK "$LDFLAGS_EXEC_LINK" setdata ${_MKCONFIG_PREFIX} LDFLAGS_EXEC_LINK "$LDFLAGS_EXEC_LINK" } check_sharerunpathflag () { printlabel LDFLAGS_RUNPATH "shared run path flag " LDFLAGS_RUNPATH="-Wl,-rpath=" if [ "$_MKCONFIG_USING_GNU_LD" != Y ]; then case ${_MKCONFIG_SYSTYPE} in HP-UX) LDFLAGS_RUNPATH="+b " ;; IRIX*) LDFLAGS_RUNPATH="-rpath " ;; OSF1) LDFLAGS_RUNPATH="-rpath " ;; SCO_SV) LDFLAGS_RUNPATH="-R " ;; SunOS) LDFLAGS_RUNPATH="-R" ;; UnixWare) LDFLAGS_RUNPATH="-R " ;; *) LDFLAGS_RUNPATH="" ;; esac if [ "$_MKCONFIG_USING_GCC" = Y ]; then # the trailing space will be converted to ' -Wl,' and # the library runpath will be appended by mkcl.sh LDFLAGS_RUNPATH=`echo "$LDFLAGS_RUNPATH" | sed -e 's/^-/-Wl,-/' -e 's/^\+/-Wl,+/' -e 's/ */ -Wl,/g'` fi fi printyesno_val LDFLAGS_RUNPATH "$LDFLAGS_RUNPATH" setdata ${_MKCONFIG_PREFIX} LDFLAGS_RUNPATH "$LDFLAGS_RUNPATH" } check_addconfig () { name=$1 evar=$2 addto=$3 printlabel ADDCONFIG "Add Config: ${evar} ${addto}" eval _tvar="\$$evar" if [ "z$_tvar" != z ]; then printyesno_val $name yes doappend $addto " $_tvar" puts "got: ${evar} ${_tvar}" >&9 eval puts "\"$addto: \$$addto\"" >&9 ucaddto=$addto toupper ucaddto _setflags $addto $ucaddto else printyesno_val $name no fi } check_findconfig () { name=$1 cfile=$2 printlabel FINDCONFIG "Search for: ${cfile}" sp= incchk= pp=`puts $PATH | sed 's/:/ /g'` for p in $pp $HOME/local/lib /usr/local/lib /opt/local/lib; do td=$p case $p in */bin) td=`puts $p | sed 's,/bin$,/lib,'` ;; esac if [ -d $td ]; then if [ -f "$td/$cfile.sh" ]; then puts "found: ${td}" >&9 sp=$td break fi fi done if [ z$sp != z ]; then printyesno_val $name yes setdata ${_MKCONFIG_PREFIX} config_${cfile} Y setdata ${_MKCONFIG_PREFIX} config_path_${cfile} $sp/$cfile . $sp/$cfile.sh ; # load the environment variables else printyesno_val $name no setdata ${_MKCONFIG_PREFIX} config_${cfile} N fi } check_findpc () { name=$1 cfile=$2 printlabel FINDPC "Search for: ${cfile}" sp= incchk= pp=`puts $PATH | sed 's/:/ /g'` for p in $pp $HOME/local/lib /usr/local/lib \ /opt/local/lib /usr/lib/x86_64-linux-gnu; do td=$p case $p in */bin) dosubst td '/bin$' '/lib' ;; esac doappend td /pkgconfig if [ -d $td ]; then if [ -f "$td/$cfile.sh" ]; then puts "found: ${td}" >&9 sp=$td break fi fi done if [ z$sp != z ]; then printyesno_val $name yes setdata ${_MKCONFIG_PREFIX} pc_${cfile} Y setdata ${_MKCONFIG_PREFIX} pc_path_${cfile} $sp/$cfile . $sp/$cfile.sh ; # load the environment variables else printyesno_val $name no setdata ${_MKCONFIG_PREFIX} pc_${cfile} N fi } check_standard_cc () { check_cc check_using_gcc check_using_gnu_ld check_using_clang check_using_cplusplus check_cflags check_ldflags } di-4.52/mkconfig/units/env-dc.sh0000755000175000017500000001032014421556642014623 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam, Walnut Creek, California USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # require_unit env-main require_unit env-systype check_dc () { _read_option DC gdc DC=${DC:-${oval}} printlabel DC "D compiler" puts "dc:${DC}" >&9 case ${DC} in *ldc*|*ldmd*) setdata ${_MKCONFIG_PREFIX} DC_OPT "-O3" setdata ${_MKCONFIG_PREFIX} DC_OF "-of" setdata ${_MKCONFIG_PREFIX} DC_RELEASE "-release" setdata ${_MKCONFIG_PREFIX} DC_INLINE "" setdata ${_MKCONFIG_PREFIX} DC_UNITTEST "-unittest" setdata ${_MKCONFIG_PREFIX} DC_DEBUG "-d-debug" setdata ${_MKCONFIG_PREFIX} DC_VERSION "-d-version" setdata ${_MKCONFIG_PREFIX} DC_INTFC "-d-intfc" setdata ${_MKCONFIG_PREFIX} DC_DEPRECATED "-d-deprecated" setdata ${_MKCONFIG_PREFIX} DC_COV "" setdata ${_MKCONFIG_PREFIX} DC_LINK "-L" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_GDC "N" ;; *dmd*) setdata ${_MKCONFIG_PREFIX} DC_OPT "-O" setdata ${_MKCONFIG_PREFIX} DC_OF "-of" setdata ${_MKCONFIG_PREFIX} DC_RELEASE "-release" setdata ${_MKCONFIG_PREFIX} DC_INLINE "-inline" setdata ${_MKCONFIG_PREFIX} DC_UNITTEST "-unittest" setdata ${_MKCONFIG_PREFIX} DC_DEBUG "-debug" setdata ${_MKCONFIG_PREFIX} DC_VERSION "-version" setdata ${_MKCONFIG_PREFIX} DC_INTFC "-H" setdata ${_MKCONFIG_PREFIX} DC_DEPRECATED "-d" setdata ${_MKCONFIG_PREFIX} DC_COV "-cov" setdata ${_MKCONFIG_PREFIX} DC_LINK "-L" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_GDC "N" ;; *gdc*) setdata ${_MKCONFIG_PREFIX} DC_OPT "-O2" setdata ${_MKCONFIG_PREFIX} DC_OF "-o" setdata ${_MKCONFIG_PREFIX} DC_RELEASE "-frelease" setdata ${_MKCONFIG_PREFIX} DC_INLINE "--inline" setdata ${_MKCONFIG_PREFIX} DC_UNITTEST "-funittest" setdata ${_MKCONFIG_PREFIX} DC_DEBUG "--debug" setdata ${_MKCONFIG_PREFIX} DC_VERSION "-fversion" setdata ${_MKCONFIG_PREFIX} DC_INTFC "-fintfc" setdata ${_MKCONFIG_PREFIX} DC_DEPRECATED "-fdeprecated" setdata ${_MKCONFIG_PREFIX} DC_COV "--cov" setdata ${_MKCONFIG_PREFIX} DC_LIBS "-lgcov" setdata ${_MKCONFIG_PREFIX} DC_LINK "" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_GDC "Y" ;; esac > tv.d puts ' int main (char[][] args) { version (D_Version2) { return 2; } version (D_Version3) { return 3; } version (D_Version4) { return 4; } version (D_Version5) { return 5; } version (D_Version6) { return 6; } return 1; } ' dver= grc=1 ${DC} ${DC_OF}tv.exe tv.d rc=$? if [ $rc -eq 0 ]; then if [ ! -x ./tv.exe ]; then rc=127 else ./tv.exe rc=$? fi case $rc in [1-9]) dver=$rc grc=0 ;; *) ;; esac fi if [ $grc -ne 0 ]; then puts "## Failure to determine D version" exit 1 fi setdata ${_MKCONFIG_PREFIX} DVERSION $dver printyesno_val DC "${DC}" "v${dver}" setdata ${_MKCONFIG_PREFIX} DC "${DC}" } check_using_gdc () { usinggdc="N" printlabel _MKCONFIG_USING_GDC "Using gdc" # check for gdc... ${DC} -v 2>&1 | grep 'gdc version' > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ] then puts "found gdc" >&9 usinggdc="Y" fi case ${DC} in *gdc*) usinggdc="Y" ;; esac printyesno_val _MKCONFIG_USING_GDC "${usinggdc}" setdata ${_MKCONFIG_PREFIX} _MKCONFIG_USING_GDC "${usinggdc}" } check_dflags () { _read_option DFLAGS "" dflags="${DFLAGS:-${oval}}" _read_option DINCLUDES "" dincludes="${DINCLUDES:-${oval}}" printlabel DFLAGS "D flags" gdcflags="" if [ "${_MKCONFIG_USING_GDC}" = "Y" ] then puts "set gdc flags" >&9 gdcflags="" fi TDC=${DC} if [ "${_MKCONFIG_USING_GDC}" = "Y" ] then TDC=gdc fi dflags="$gdcflags $dflags" puts "dflags:${dflags}" >&9 printyesno_val DFLAGS "$dflags" setdata ${_MKCONFIG_PREFIX} DFLAGS "$dflags" } di-4.52/mkconfig/units/env-extension.sh0000755000175000017500000000413414421556642016257 0ustar bllbll#!/bin/sh # # Copyright 2001-2018 Brad Lanam, Walnut Creek, California, USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # require_unit env-main check_extension () { type=$2 name="${type}ext" eval check_${name} } check_objext () { name=OBJ_EXT printlabel $name "extension: object" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi TMPF=objext CC=${CC:-cc} > $TMPF.c puts ' #include int main () { printf ("hello\n"); return 0; } ' ${CC} -c $TMPF.c > /dev/null 2>&1 # don't care about warnings... OBJ_EXT=".o" if [ -f "$TMPF.obj" ]; then puts "object extension is .obj" >&9 OBJ_EXT=".obj" else puts "object extension is .o" >&9 fi printyesno_val $name "${OBJ_EXT}" setdata ${_MKCONFIG_PREFIX} $name "${OBJ_EXT}" } check_exeext () { name=EXE_EXT printlabel $name "extension: executable" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi TMPF=exeext CC=${CC:-cc} > $TMPF.c puts ' #include int main () { printf ("hello\n"); return 0; } ' ${CC} -o $TMPF $TMPF.c > /dev/null 2>&1 # don't care about warnings EXE_EXT="" if [ -f "$TMPF.exe" ] then puts "executable extension is .exe" >&9 EXE_EXT=".exe" else puts "executable extension is none" >&9 fi printyesno_val $name "${EXE_EXT}" setdata ${_MKCONFIG_PREFIX} $name "${EXE_EXT}" } check_shlibext () { name=SHLIB_EXT printlabel $name "extension: shared library" SHLIB_EXT=".so" case ${_MKCONFIG_SYSTYPE} in HP-UX) SHLIB_EXT=".sl" ;; AIX) SHLIB_EXT=".a" ;; Darwin) SHLIB_EXT=".dylib" ;; CYGWIN*|MSYS*|MINGW*) SHLIB_EXT=".dll" ;; esac printyesno_val $name "$SHLIB_EXT" setdata ${_MKCONFIG_PREFIX} $name "$SHLIB_EXT" } di-4.52/mkconfig/units/c-include-conflict.sh0000755000175000017500000000320714421556642017117 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # check and see if there is a conflict between include files. # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # require_unit c-main _prefix_header () { nm=$1 val=$2 case $val in sys*) eval "$nm=_${val}" ;; *) eval "$nm=_hdr_${val}" ;; esac } check_include_conflict () { i1=$2 i2=$3 if [ "${CC}" = "" ]; then puts "No compiler specified" >&2 return fi oi1=$i1 dosubst i1 '/' '_' ':' '_' '\.h' '' _prefix_header i1 $i1 oi2=$i2 dosubst i2 '/' '_' ':' '_' '\.h' '' _prefix_header i2 $i2 name="_inc_conflict_${i1}_${i2}" # by default, ok to include both # if one or the other does not exist, the flag will be true. # if it compiles ok with both, the flag will be true. trc=1 printlabel $name "header: include both ${oi1} & ${oi2}" getdata h1 ${_MKCONFIG_PREFIX} $i1 getdata h2 ${_MKCONFIG_PREFIX} $i2 if [ "${h1}" != "0" -a "${h2}" != "0" ]; then checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="#include <${h1}> #include <${h2}> int main () { return 0; } " do_c_check_compile "${name}" "${code}" std else setdata ${_MKCONFIG_PREFIX} "${name}" "${trc}" printyesno "${name}" $trc "" fi } di-4.52/mkconfig/units/d-support.sh0000755000175000017500000001017714421556642015416 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # _d_print_imports () { imports=$1 if [ "$imports" = "none" ]; then return fi out="${PI_PREFIX}${imports}" if [ -f $out ]; then cat $out return fi if [ "$PI_ALL" = "T" -a "$imports" = "all" ]; then _d_print_imps all > $out cat $out return fi # until PI_ALL becomes true, just do normal processing. _d_print_imps $imports } _d_print_imps () { imports=$1 if [ "${imports}" = "all" -o "${imports}" = "std" ]; then for tnm in '_import_std_stdio' '_import_std_string'; do getdata tval ${_MKCONFIG_PREFIX} ${tnm} if [ "${tval}" != "0" -a "${tval}" != "" ]; then puts "import ${tval};" fi done fi if [ "${imports}" = "all" -a -f "$VARSFILE" ]; then # save stdin in fd 6; open stdin exec 6<&0 < ${VARSFILE} while read cfgvar; do getdata hdval ${_MKCONFIG_PREFIX} ${cfgvar} case ${cfgvar} in _import_std_stdio|_import_std_string) ;; _import_*) if [ "${hdval}" != "0" -a "${hdval}" != "" ]; then puts "import ${hdval};" fi ;; esac done # set std to saved fd 6; close 6 exec <&6 6<&- fi } _d_chk_run () { drname=$1 code=$2 inc=$3 _d_chk_link_libs ${drname} "${code}" $inc rc=$? puts "## run test: link: $rc" >&9 rval=0 if [ $rc -eq 0 ]; then rval=`./${drname}.exe` rc=$? puts "## run test: run: $rc retval: $rval" >&9 if [ $rc -lt 0 ]; then _exitmkconfig $rc fi fi _retval=$rval return $rc } _d_chk_link_libs () { dllname=$1 code=$2 inc=$3 shift;shift;shift ocounter=0 dlotherlibs="'$otherlibs'" dosubst dlotherlibs ',' "' '" if [ "${dlotherlibs}" != "" ]; then eval "set -- $dlotherlibs" ocount=$# else ocount=0 fi tdfile=${dllname}.d # $dllname should be unique exec 4>>${tdfile} _d_print_imports $inc >&4 puts "${code}" | sed 's/_dollar_/$/g' >&4 exec 4>&- dlibs="" otherlibs="" _d_chk_link $dllname rc=$? puts "## link test (none): $rc" >&9 if [ $rc -ne 0 ]; then while test $ocounter -lt $ocount; do domath ocounter "$ocounter + 1" eval "set -- $dlotherlibs" cmd="olibs=\$${ocounter}" eval $cmd dlibs=${olibs} otherlibs=${olibs} _d_chk_link $dllname rc=$? puts "## link test (${olibs}): $rc" >&9 if [ $rc -eq 0 ]; then break fi done fi _retdlibs=$dlibs return $rc } _d_chk_link () { dlname=$1 cmd="${_MKCONFIG_DIR}/mkc.sh -d `pwd` -complink -e -c ${DC} \ -o ${dlname}${OBJ_EXT} -- ${DFLAGS} ${dlname}.d " puts "## _link test (compile): $cmd" >&9 cat ${dlname}.d >&9 eval ${cmd} >&9 2>&9 rc=$? if [ $rc -lt 0 ]; then _exitmkconfig $rc fi puts "## _link compile: $rc" >&9 cmd="${_MKCONFIG_DIR}/mkc.sh -d `pwd` -complink -e -c ${DC} -o ${dlname}.exe \ -- ${DFLAGS} ${dlname}${OBJ_EXT} ${LDFLAGS} ${LIBS} " _dlotherlibs=$otherlibs if [ "${_dlotherlibs}" != "" ]; then cmd="${cmd} ${_dlotherlibs} " fi puts "## _link test (link): $cmd" >&9 cat ${dlname}.d >&9 eval $cmd >&9 2>&9 rc=$? if [ $rc -lt 0 ]; then _exitmkconfig $rc fi puts "## _link link: $rc" >&9 if [ $rc -eq 0 ]; then if [ ! -x "${dlname}.exe" ]; then # not executable rc=1 fi fi return $rc } _d_chk_compile () { dfname=$1 code=$2 inc=$3 tdfile=${dfname}.d # $dfname should be unique exec 4>>${tdfile} _d_print_imports $inc >&4 puts "${code}" | sed 's/_dollar_/$/g' >&4 exec 4>&- cmd="${_MKCONFIG_DIR}/mkc.sh -d `pwd` -complink -e -c ${DC} \ -o ${dfname}${OBJ_EXT} -- ${DFLAGS} ${tdfile} " puts "## compile test: $cmd" >&9 cat ${dfname}.d >&9 eval ${cmd} >&9 2>&9 rc=$? puts "## compile test: $rc" >&9 return $rc } do_d_check_compile () { ddfname=$1 code=$2 inc=$3 _d_chk_compile ${ddfname} "${code}" $inc rc=$? try=0 if [ $rc -eq 0 ]; then try=1 fi printyesno $ddfname $try setdata ${_MKCONFIG_PREFIX} ${ddfname} ${try} } di-4.52/mkconfig/units/c-main.sh0000755000175000017500000004516314421556642014630 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # The four headers: stdio.h, stdlib.h, sys/types.h, and sys/param.h # are always checked. FreeBSD has header inclusion bugs and requires # sys/param.h. # # The keywords 'void' and 'const' are always tested. # # Prototype support is always tested. # # The following code is present in the final config.h file: # # #ifndef MKC_STANDARD_DEFS # # define MKC_STANDARD_DEFS 1 # # if ! _key_void # # define void int # # endif # # if ! _key_const # # define const # # endif # # if ! _key_void || ! _param_void_star # typedef char *_pvoid; # # else # typedef void *_pvoid; # # endif # # # ifndef _ # # if _proto_stdc # # define _(args) args # # else # # define _(args) () # # endif # # endif # #endif /* MKC_STANDARD_DEFS */ # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 4 - temporary for c-main.sh (c-main.sh) # require_unit c-support _MKCONFIG_PREFIX=c _MKCONFIG_HASEMPTY=F _MKCONFIG_EXPORT=F PH_PREFIX="mkc_ph." PH_STD=F PH_ALL=F precc=' #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) # define _(x) x #else # define _(x) () # define void char #endif #if defined(__cplusplus) || defined (c_plusplus) # define CPP_EXTERNS_BEG extern "C" { # define CPP_EXTERNS_END } CPP_EXTERNS_BEG extern int printf (const char *, ...); CPP_EXTERNS_END #else # define CPP_EXTERNS_BEG # define CPP_EXTERNS_END #endif ' preconfigfile () { pc_configfile=$1 configfile=$2 # log all of the compiler and linker options for nm in CC CFLAGS_OPTIMIZE CFLAGS_DEBUG CFLAGS_INCLUDE CFLAGS_USER \ CFLAGS_APPLICATION CFLAGS_COMPILER CFLAGS_SYSTEM CFLAGS_SHARED \ CFLAGS_SHARED_USER LDFLAGS_OPTIMIZE LDFLAGS_DEBUG LDFLAGS_USER \ LDFLAGS_APPLICATION LDFLAGS_COMPILER LDFLAGS_SYSTEM \ LDFLAGS_SHARED LDFLAGS_SHARED_LIBLINK LDFLAGS_SHARED_USER \ LDFLAGS_LIBS_USER LDFLAGS_LIBS_APPLICATION LDFLAGS_LIBS_SYSTEM; do cmd="puts \"$nm: \${$nm}\"" eval $cmd >&9 done if [ "${CC}" = "" ]; then puts "No compiler specified" >&2 return fi puts "/* Created on: `date`" puts " From: ${configfile}" puts " Using: mkconfig-${_MKCONFIG_VERSION} */" puts '' puts "#ifndef MKC_INC_${CONFHTAGUC}_H #define MKC_INC_${CONFHTAGUC}_H 1 " } stdconfigfile () { pc_configfile=$1 puts ' #ifndef MKC_STANDARD_DEFS # define MKC_STANDARD_DEFS 1 # if ! _key_void # define void int # endif # if ! _key_void || ! _param_void_star typedef char *_pvoid; # else typedef void *_pvoid; # endif # if ! _key_const # define const # endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif #endif /* MKC_STANDARD_DEFS */ ' } postconfigfile () { pc_configfile=$1 puts " #endif /* MKC_INC_${CONFHTAGUC}_H */" } standard_checks () { if [ "${CC}" = "" ]; then puts "No compiler specified" >&2 return fi check_hdr hdr "stdio.h" check_hdr hdr "stdlib.h" check_hdr sys "types.h" check_hdr sys "param.h" PH_STD=T check_key key "void" check_key key "const" check_param_void_star check_proto "_proto_stdc" PH_ALL=T } check_hdr () { type=$1 hdr=$2 shift;shift reqhdr=$* # input may be: ctype.h kernel/fs_info.h # storage/Directory.h nm1=`puts ${hdr} | sed -e 's,/.*,,'` nm2="_`puts $hdr | sed -e s,\^${nm1},, -e 's,^/*,,'`" nm="_${type}_${nm1}" if [ "$nm2" != "_" ]; then doappend nm $nm2 fi dosubst nm '/' '_' ':' '_' '\.h' '' case ${type} in sys) hdr="sys/${hdr}" ;; esac name=$nm file=$hdr printlabel $name "header: ${file}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="" if [ "${reqhdr}" != "" ]; then set ${reqhdr} while test $# -gt 0; do doappend code " #include <$1> " shift done fi doappend code " #include <$file> int main () { return (0); } " rc=1 _c_chk_compile ${name} "${code}" std rc=$? val=0 if [ $rc -eq 0 ]; then val=${file} fi if [ "$CPPCOUNTER" != "" ]; then domath CPPCOUNTER "$CPPCOUNTER + 1" fi printyesno $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_sys () { check_hdr $@ } check_const () { constant=$2 shift;shift reqhdr=$* nm="_const_${constant}" name=$nm printlabel $name "constant: ${constant}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="" if [ "${reqhdr}" != "" ]; then set ${reqhdr} while test $# -gt 0; do doappend code " #include <$1> " shift done fi doappend code " int main () { if (${constant} == 0) { 1; } return (0); } " do_c_check_compile ${name} "${code}" all } check_key () { keyword=$2 name="_key_${keyword}" printlabel $name "keyword: ${keyword}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="int main () { int ${keyword}; ${keyword} = 1; return (0); }" _c_chk_compile ${name} "${code}" std rc=$? trc=0 if [ $rc -ne 0 ]; then # failure means it is reserved... trc=1 fi printyesno $name $trc setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_proto () { name=$1 printlabel $name "supported: prototypes" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code=' CPP_EXTERNS_BEG extern int foo (int, int); CPP_EXTERNS_END int bar () { int rc; rc = foo (1,1); return 0; } ' do_c_check_compile ${name} "${code}" std } check_typ () { shift type=$@ nm="_typ_${type}" dosubst nm ' ' '_' name=$nm dosubst type 'star' '*' printlabel $name "type: ${type}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code=" struct xxx { ${type} mem; }; static struct xxx v; struct xxx* f() { return &v; } int main () { struct xxx *tmp; tmp = f(); return (0); } " do_c_check_compile ${name} "${code}" all } check_define () { shift def=$1 nm="_define_${def}" name=$nm printlabel $name "defined: ${def}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="int main () { #if defined(${def}) # define MKC_DEFINED 1 #endif #ifdef MKC_DEFINED printf (\"mkc_defined ${def}\"); #endif }" trc=0 _c_chk_cpp "$name" "$code" all rc=$? if [ $rc -eq 0 ]; then egrep -l "mkc_defined" $name.out >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then trc=1 fi fi setdata ${_MKCONFIG_PREFIX} ${name} ${trc} printyesno $name $trc } check_param_void_star () { name="_param_void_star" printlabel $name "parameter: void *" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code=" char * tparamvs (ptr) void *ptr; { ptr = (void *) NULL; return (char *) ptr; } " do_c_check_compile ${name} "${code}" all } check_printf_long_double () { name="_printf_long_double" otherlibs="-lintl" printlabel $name "printf: long double printable" code="int main (int argc, char *argv[]) { long double a; long double b; char t[40]; a = 1.0; b = 2.0; a = a / b; sprintf (t, \"%.1Lf\", a); if (strcmp(t,\"0.5\") == 0) { return (0); } return (1); }" _c_chk_run "$name" "$code" all rc=$? dlibs=$_retdlibs if [ $rc -eq 0 -a "$dlibs" != "" ]; then cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi if [ $rc -eq 0 ]; then trc=1; else trc=0; fi otherlibs="" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} printyesno $name $trc } check_member () { shift struct=$1 if [ "$struct" = "struct" ]; then shift struct="struct $1" fi if [ "$struct" = "union" ]; then shift struct="union $1" fi shift member=$1 nm="_mem_${struct}_${member}" dosubst nm ' ' '_' name=$nm printlabel $name "exists: ${struct}.${member}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="int main () { ${struct} s; int i; i = sizeof (s.${member}); }" do_c_check_compile ${name} "${code}" all } check_memberxdr () { shift struct=$1 shift member=$1 nm="_memberxdr_${struct}_${member}" dosubst nm ' ' '_' name=$nm printlabel $name "member:XDR: ${struct} ${member}" # no cache _c_chk_cpp $name "" all rc=$? trc=0 if [ $rc -eq 0 ]; then st=`${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextstruct.awk ${name}.out ${struct}` if [ "$st" != "" ]; then puts " ${struct}: ${st}" >&9 tmem=`puts "$st" | grep "${member} *;\$"` rc=$? puts " found: ${tmem}" >&9 if [ $rc -eq 0 ]; then mtype=`puts $tmem | sed -e "s/ *${member} *;$//" -e 's/^ *//'` puts " type: ${mtype}" >&9 trc=1 setdata ${_MKCONFIG_PREFIX} xdr_${member} xdr_${mtype} fi fi # found the structure fi # cpp worked printyesno $name $trc "" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } check_size () { shift type=$* otherlibs="-lintl" nm="_siz_${type}" dosubst nm ' ' '_' name=$nm printlabel $name "sizeof: ${type}" if [ "$MKC_CROSS" = Y ]; then puts "## size: cross compiling is active" >&9 code="int main () { printf(\"%u\", sizeof(${type})); return (0); }" _c_chk_compile ${name} "${code}" all rc=$? if [ $rc -eq 0 ]; then sz=1 # this could be sped up by moving the common sizes to the beginning # of the list of sizes to test. while test $sz -lt 129; do code=" #include #include int main () { size_t a = sizeof(int); switch (a) { case ${sz}: case sizeof(${type}): { break; } } } " _c_chk_compile ${name} "${code}" all trc=$? if [ $trc -ne 0 ]; then _retval=$sz rc=0 break fi if [ $sz -eq 1 ]; then sz=2 else domath sz "$sz + 2" fi done else _retval=0 rc=1 fi else puts "## size: cross compiling is NOT active" >&9 code="int main () { printf(\"%u\", sizeof(${type})); return (0); }" _c_chk_run ${name} "${code}" all rc=$? fi dlibs=$_retdlibs val=$_retval if [ $rc -ne 0 ]; then val=0 fi if [ $rc -eq 0 -a "$dlibs" != "" ]; then cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi otherlibs="" printyesno_val $name $val setdata ${_MKCONFIG_PREFIX} ${name} ${val} } check_dcl () { type=$2 var=$3 nm="_dcl_${var}" if [ "$type" = "int" ]; then check_int_declare $nm $var elif [ "$type" = "ptr" ]; then check_ptr_declare $nm $var fi } check_args () { type=$1 noconst=F if [ "$2" = "noconst" ]; then noconst=T shift fi funcnm=$2 nm="_args_${funcnm}" name=$nm printlabel $name "args: ${funcnm}" # no cache trc=0 ccount=0 oldprecc="${precc}" if [ "$_have_variadic" = "" ]; then precc="" code="#define testvariadic(...)" _c_chk_cpp _args_testvariadic "$code" all rc=$? _have_variadic=F if [ $rc -eq 0 ]; then _have_variadic=T fi fi asmdef="#define __asm__(a)" if [ $_have_variadic = T ]; then asmdef="#define __asm__(...)" fi precc="$oldprecc" doappend precc "/* get rid of most gcc-isms */ #define __asm(a) $asmdef #define __attribute__(a) #define __nonnull__(a,b) #define __restrict #define __restrict__ #if defined(__THROW) # undef __THROW #endif #define __THROW #define __const const " code="" _c_chk_cpp ${name} "/**/" all # force no-reuse due to precc. rc=$? precc="${oldprecc}" if [ $rc -eq 0 ]; then egrep -l "[ *]${funcnm}[ ]*\(" $name.out >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then trc=1 fi # have a declaration if [ $trc -eq 1 ]; then dcl=`${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextdcl.awk ${name}.out ${funcnm}` # make single line, use no quotes # remove carriage returns...msys2 sometimes has them embedded. # \r is not recognized by older shells, use tr. dcl=`puts $dcl | tr '\r' ' '` # extern will be replaced # ; may or may not be present, so remove it. cmd="dcl=\`puts \"\$dcl\" | sed -e 's/extern *//' -e 's/;//' \`" eval $cmd puts "## dcl(A): ${dcl}" >&9 cmd="dcl=\`puts \"\$dcl\" | sed -e 's/( *void *)/()/' \`" eval $cmd puts "## dcl(C): ${dcl}" >&9 c=`puts "${dcl}" | sed 's/[^,]*//g'` ccount=`putsnonl "$c" | wc -c` domath ccount "$ccount + 1" # 0==1 also, unfortunately c=`puts "${dcl}" | sed 's/^[^(]*(//'` c=`puts "${c}" | sed 's/)[^)]*$//'` puts "## c(E): ${c}" >&9 val=1 while test "${c}" != ""; do tmp=$c tmp=`puts "${c}" | sed -e 's/ *,.*$//' -e 's/[ ]/ /g'` dosubst tmp 'struct ' 'struct#' 'union ' 'union#' 'enum ' 'enum#' # only do the following if the names of the variables are declared puts "${tmp}" | grep ' ' > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then tmp=`puts "${tmp}" | sed -e 's/ *[A-Za-z0-9_]*$//'` fi dosubst tmp 'struct#' 'struct ' 'union#' 'union ' 'enum#' 'enum ' if [ $noconst = T ]; then tmp=`puts "${tmp}" | sed -e 's/const *//'` fi puts "## tmp(F): ${tmp}" >&9 nm="_c_arg_${val}_${funcnm}" setdata ${_MKCONFIG_PREFIX} ${nm} "${tmp}" domath val "$val + 1" c=`puts "${c}" | sed -e 's/^[^,]*//' -e 's/^[ ,]*//'` puts "## c(G): ${c}" >&9 done c=`puts "${dcl}" | sed -e 's/[ ]/ /g' \ -e "s/\([ \*]\)${funcnm}[ (].*/\1/" \ -e 's/^ *//' \ -e 's/ *$//'` puts "## c(T0): ${c}" >&9 if [ $noconst = T ]; then c=`puts "${c}" | sed -e 's/const *//'` fi puts "## c(T1): ${c}" >&9 nm="_c_type_${funcnm}" setdata ${_MKCONFIG_PREFIX} ${nm} "${c}" fi fi printyesno_val $name $ccount "" nm="_args_${funcnm}" setdata ${_MKCONFIG_PREFIX} ${nm} ${ccount} } check_int_declare () { name=$1 function=$2 printlabel $name "declared: ${function}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="int main () { int x; x = ${function}; }" do_c_check_compile ${name} "${code}" all } check_ptr_declare () { name=$1 function=$2 printlabel $name "declared: ${function}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi code="int main () { void *x; x = ${function}; }" do_c_check_compile ${name} "${code}" all } check_npt () { func=$2 req=$3 has=1 if [ "${req}" != "" ]; then getdata has ${_MKCONFIG_PREFIX} "${req}" fi nm="_npt_${func}" name=$nm proto=$func printlabel $name "need prototype: ${proto}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi if [ ${has} -eq 0 ]; then setdata ${_MKCONFIG_PREFIX} ${name} 0 printyesno $name 0 return fi code=" CPP_EXTERNS_BEG struct _TEST_struct { int _TEST_member; }; extern struct _TEST_struct* ${proto} _((struct _TEST_struct*)); CPP_EXTERNS_END " do_c_check_compile ${name} "${code}" all } check_lib () { func=$2 shift;shift otherlibs=$* nm="_lib_${func}" name=$nm rfunc=$func dosubst rfunc '_dollar_' '$' if [ "${otherlibs}" != "" ]; then printlabel $name "function: ${rfunc} [${otherlibs}]" # code to check the cache for which libraries are specified is not written else printlabel $name "function: ${rfunc}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi fi trc=0 # unfortunately, this does not work if the function # is not declared. if [ "$_MKCONFIG_USING_CPLUSPLUS" = Y ]; then hinc=none code=" CPP_EXTERNS_BEG #undef $rfunc typedef char (*_TEST_fun_)(); char $rfunc(); _TEST_fun_ f = $rfunc; CPP_EXTERNS_END int main () { if (f == $rfunc) { return 0; } return 1; } " else hinc=all code=" CPP_EXTERNS_BEG typedef char (*_TEST_fun_)(); _TEST_fun_ f = $rfunc; CPP_EXTERNS_END int main () { f(); if (f == $rfunc) { return 0; } return 1; } " fi _c_chk_link_libs ${name} "${code}" $hinc rc=$? dlibs=$_retdlibs if [ $rc -eq 0 ]; then trc=1 fi tag="" if [ $rc -eq 0 -a "$dlibs" != "" ]; then tag=" with ${dlibs}" cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi if [ ${trc} -eq 0 -a "$_MKCONFIG_TEST_EXTERN" != "" ]; then if [ $_MKCONFIG_USING_CPLUSPLUS = Y ]; then hinc=none code=" CPP_EXTERNS_BEG #undef $rfunc typedef char (*_TEST_fun_)(); char $rfunc(); _TEST_fun_ f = $rfunc; CPP_EXTERNS_END int main () { if (f == $rfunc) { return 0; } return 1; } " else hinc=all code=" CPP_EXTERNS_BEG /* Normally, we don't want to do this, as on some systems we can get spurious errors where the lib does not exist and the link works! On modern systems, this simply isn't necessary. */ extern int ${func}(); typedef char (*_TEST_fun_)(); _TEST_fun_ f = $rfunc; CPP_EXTERNS_END int main () { f(); if (f == $rfunc) { return 0; } return 1; } " fi _c_chk_link_libs ${name} "${code}" $hinc rc=$? dlibs=$_retdlibs if [ $rc -eq 0 ]; then trc=1 fi tag="" if [ $rc -eq 0 -a "$dlibs" != "" ]; then tag=" with ${dlibs}" cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi fi otherlibs="" printyesno $name $trc "$tag" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} return $trc } check_class () { class=$2 shift;shift otherlibs=$* nm="_class_${class}" dosubst nm '/' '_' ':' '_' name=$nm trc=0 code=" int main () { ${class} testclass; } " if [ "$otherlibs" != "" ]; then printlabel $name "class: ${class} [${otherlibs}]" else printlabel $name "class: ${class}" checkcache ${_MKCONFIG_PREFIX} $name if [ $rc -eq 0 ]; then return; fi fi _c_chk_link_libs ${name} "${code}" all rc=$? if [ $rc -eq 0 ]; then trc=1 fi tag="" if [ $rc -eq 0 -a "${dlibs}" != "" ]; then tag=" with ${dlibs}" cmd="mkc_${_MKCONFIG_PREFIX}_lib_${name}=\"${dlibs}\"" eval $cmd fi otherlibs="" printyesno $name $trc "$tag" setdata ${_MKCONFIG_PREFIX} ${name} ${trc} } output_item () { out=$1 name=$2 val=$3 tval=0 if [ "$val" != "0" ]; then tval=1 fi case ${name} in _setint_*) tname=$name dosubst tname '_setint_' '' puts "#define ${tname} ${val}" ;; _setstr_*|_opt_*|_cmd_loc_*) tname=$name dosubst tname '_setstr_' '' '_opt_' '' puts "#define ${tname} \"${val}\"" ;; _hdr_*|_sys_*|_command_*) puts "#define ${name} ${tval}" ;; *) # _c_arg, _c_type go here also puts "#define ${name} ${val}" ;; esac } new_output_file () { return 0 } di-4.52/mkconfig/units/env-msgfmt.sh0000755000175000017500000000210714421556642015536 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam, Walnut Creek, California USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - >>$LOG (mkconfig.sh) # 8 - >>$VARSFILE, >>$CONFH (mkconfig.sh) # 7 - temporary for mkconfig.sh (mkconfig.sh) # 6 - temporary for c-main.sh (c-main.sh) # 5 - temporary for c-main.sh (c-main.sh) # require_unit env-main # optional unit: cflags check_cmd_msgfmt () { name="$1" name=XMSGFMT printlabel $name "command: locate msgfmt" checkcache_val ${_MKCONFIG_PREFIX} $name if [ $? -eq 0 ]; then return; fi locatecmd xmsgfmt msgfmt locatecmd xgmsgfmt gmsgfmt mfmt="${xmsgfmt}" if [ "$_MKCONFIG_USING_GCC" = "Y" ] then mfmt="${xgmsgfmt:-${xmsgfmt}}" if [ -x "${xccpath}/msgfmt" ] then mfmt="${xccpath}/msgfmt" fi if [ -x "${xccpath}/gmsgfmt" ] then mfmt="${xccpath}/gmsgfmt" fi fi printyesno_val XMSGFMT $xmsgfmt setdata ${_MKCONFIG_PREFIX} "XMSGFMT" "${xmsgfmt}" } di-4.52/mkconfig/README.txt0000644000175000017500000000520214421556642013447 0ustar bllbllmkconfig - configuration tool (version 2.6.1) Website: https://mkconfig.sourceforge.io/ SourceForge: https://sourceforge.net/projects/mkconfig/ mkconfig is a build configuration utility. It creates an output file intended to be included as a header file, run as a shell script, used as a configuration file, or any other use. mkconfig is written in portable shell script and designed to be extensible for any configuration use. It also includes tools that can be used to compile, link and build libraries and executables using the shell configuration previously built. See: examples/helloworld for a simple example. Another example of mkconfig in use can be seen in the 'di' program at https://sourceforge.net/projects/diskinfo-di/ mkconfig works with most any bourne shell compatible shell. Modern shells that are not bourne shell compatible are: posh, bosh, zsh (compatibility mode). Very old shells do not have the memory capabilities needed in order to save the large number of variables that mkconfig needs. TESTING Version 2.4 has been tested on: Linux Debian 9 (gcc6) (bash4, dash) Fedora 7 (gcc) (bash3, sh/bash3) Fedora 27 (gcc7) (bash4, sh/bash4) MX Linux 19.2 (gcc8, clang) (ksh93 osh bash5 dash mksh yash) BSD DragonflyBSD 5.8.1 (gcc) (bash5, dash, pdksh, ksh93, mksh) FreeBSD 7.0 (gcc4) (sh) FreeBSD 11.0 (clang6) (sh, bash4, dash, pdksh, ksh93, mksh) FreeBSD 12.0 (clang6) (sh, bash4) NetBSD 9.0 (gcc) (pdksh, sh) OpenBSD 6.3 (clang5) (pdksh, sh) Windows Msys2 (gcc9, clang) (ash, bash4, dash, sh/bash4) Cygwin (gcc8, clang8) (ash, bash4, dash, mksh, sh/bash4) Other AIX 7.1 (xlc, gcc4) (bash4, ksh, ksh93, sh) AIX 7.2 (xlc, gcc7) (bash4, ksh, ksh93, sh) HP-UX 11.11 (gcc4) (sh, ksh, bash4) Mac OS X 10.15.5 (clang) (bash3, dash, ksh93, sh/bash3) QNX 6.5 (cc) (pdksh, bash4, sh/pdksh) SCO SV 6.0.0 (cc, gcc2) (sh, ksh, ksh93, bash3, bash2) Solaris 11/x86 (cc 12.3, gcc5) (bash4, ksh93, sh/ksh93) Solaris 10/sparc (cc 12.3, gcc5) (bash4, sh(1), sh, bash3, ksh) Solaris 9/x86 (cc 12, gcc4) (bash4, ksh93, sh(1), bash2, sh) Tru64 5.1b (cc, gcc) (sh, ksh, bash2) UnixWare 7.1.4 (cc, gcc2) (sh, ksh93, ksh88, bash2) (1) not a standard solaris shell ISSUES - D Compiler bugs: ldc2 has structure size problems on 64bit (issue #28). gdc 4.6.3 (LinuxMint) has structure size problems on 64bit. - The D language portions have not been tested or used in a very long time. di-4.52/mkconfig/LICENSE0000644000175000017500000000166114421556642012763 0ustar bllbll Copyright 2010-2018 Brad Lanam, Walnut Creek, CA, USA Copyright 2020-2021 Brad Lanam Pleasant Hill CA, USA This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. di-4.52/mkconfig/mkconfig.pl0000755000175000017500000014217214421556642014116 0ustar bllbll#!/usr/bin/perl # # Copyright 2006-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # HP-UX doesn't have these installed. # use strict; # use Config; require 5.005; my $CONFH; my $MKC_FILES = 'mkc_files'; if ( $ENV{'MKC_FILES'} ne "" ) { $MKC_FILES = $ENV{'MKC_FILES'}; } mkdir $MKC_FILES, 0777; my $LOG = "../../${MKC_FILES}/mkconfig.log"; my $_MKCONFIG_TMP = "${MKC_FILES}/_tmp_mkconfig"; my $OPTIONFILE = "../../options.dat"; my $VARSFILE = "../../${MKC_FILES}/mkc_none_c.vars"; my $CACHEFILE = "../../${MKC_FILES}/mkconfig.cache"; my $REQLIB = "../../${MKC_FILES}/mkconfig.reqlibs"; my $_MKCONFIG_DIR = "invalid"; my $precc = <<'_HERE_'; #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) # define _(x) x #else # define _(x) () # define void char #endif #if defined(__cplusplus) || defined (c_plusplus) # define CPP_EXTERNS_BEG extern "C" { # define CPP_EXTERNS_END } CPP_EXTERNS_BEG extern int printf (const char *, ...); CPP_EXTERNS_END #else # define CPP_EXTERNS_BEG # define CPP_EXTERNS_END #endif _HERE_ my $postcc = <<'_HERE_'; /* some gcc's (cygwin) redefine __restrict again */ #if defined (__restrict) # undef __restrict #endif #define __restrict _HERE_ my $optionsloaded = 0; my %optionshash; my $iflevels = ''; my $awkcmd = 'awk'; foreach my $p (split /[;:]/o, $ENV{'PATH'}) { if (-x "$p/awk" && $awkcmd eq "") { $awkcmd = "$p/awk"; } if (-x "$p/nawk" && $awkcmd !~ /mawk$/o && $awkcmd !~ /gawk$/o) { $awkcmd = "$p/nawk"; } if (-x "$p/mawk" && $awkcmd !~ /gawk$/o) { $awkcmd = "$p/mawk"; } if (-x "$p/gawk") { $awkcmd = "$p/gawk"; } } sub exitmkconfig { my $rc = shift; exit 1; } sub printlabel { my ($name, $label) = @_; print LOGFH "## ${iflevels}[$name] $label ... \n"; print STDOUT "${iflevels}$label ... "; } sub printyesno_actual { my ($name, $val, $tag) = @_; print LOGFH "## [$name] $val $tag\n"; print STDOUT "$val $tag\n"; } sub printyesno_val { my ($name, $val, $tag) = @_; if ($val ne '0') { printyesno_actual ($name, $val, $tag); } else { printyesno_actual ($name, 'no', $tag); } } sub printyesno { my ($name, $val, $tag) = @_; if ($val ne "0") { $val = "yes"; } printyesno_val $name, $val, $tag; } sub savevars { my ($r_clist) = @_; open (MKCV, ">$VARSFILE"); foreach my $val (@{$r_clist->{'vars'}}) { print MKCV $val, "\n"; } close (MKCV); } sub savecache { my ($r_clist, $r_config) = @_; open (MKCC, ">$CACHEFILE"); foreach my $val (@{$r_clist->{'clist'}}) { if ($val =~ /^lib__lib_/o) { $tval = $val; $tval =~ s/^lib_//o; print MKCC "mkc_c_lib_${tval}='" . $r_config->{$val} . "'\n"; } else { print MKCC "mkc_c_${val}='" . $r_config->{$val} . "'\n"; } } close (MKCC); } sub checkcache_val { my ($name, $r_clist, $r_config) = @_; my $rc = 1; if (defined ($r_config->{$name}) && $r_config->{$name} ne "" ) { push @{$r_clist->{'vars'}}, $name; my $r_hash = $r_clist->{'vhash'}; $r_hash->{$name} = 1; printyesno_val $name, $r_config->{$name}, " (cached)"; $rc = 0; } return $rc; } sub checkcache { my ($name, $r_clist, $r_config) = @_; my $rc = 1; if (defined ($r_config->{$name}) && $r_config->{$name} ne "" ) { push @{$r_clist->{'vars'}}, $name; my $r_hash = $r_clist->{'vhash'}; $r_hash->{$name} = 1; printyesno $name, $r_config->{$name}, " (cached)"; $rc = 0; } return $rc; } sub loadoptions { if ($optionsloaded == 0 && open (OPTS, "<$OPTIONFILE")) { while (my $o = ) { chomp $o; if ($o =~ /^$/o || $o =~ /^#/o) { next; } my ($onm, $val) = split (/=/, $o); printf LOGFH "## load: $onm = $val\n"; $optionshash{$onm} = $val; } $optionsloaded = 1; close (OPTS); } } sub setclist { my ($r_clist, $name) = @_; $r_hash = $r_clist->{'chash'}; if (! defined ($r_hash->{$name})) { push @{$r_clist->{'clist'}}, $name; $r_hash->{$name} = 1; } } sub setlist { my ($r_clist, $name) = @_; my $r_hash = $r_clist->{'vhash'}; if (! defined ($r_hash->{$name})) { push @{$r_clist->{'vars'}}, $name; $r_hash->{$name} = 1; } setclist ($r_clist, $name); } sub setcflags { my $CFLAGS = ''; if ( $ENV{'CFLAGS_ALL'} ne "" ) { $CFLAGS= $ENV{'CFLAGS_ALL'}; } else { $CFLAGS .= ' ' . $ENV{'CFLAGS_OPTIMIZE'}; $CFLAGS .= ' ' . $ENV{'CFLAGS_DEBUG'}; $CFLAGS .= ' ' . $ENV{'CFLAGS_INCLUDE'}; $CFLAGS .= ' ' . $ENV{'CFLAGS_USER'}; $CFLAGS .= ' ' . $ENV{'CFLAGS_APPLICATION'}; $CFLAGS .= ' ' . $ENV{'CFLAGS_COMPILER'}; $CFLAGS .= ' ' . $ENV{'CFLAGS_SYSTEM'}; } $ENV{'CFLAGS'} = $CFLAGS; } sub setldflags { my $LDFLAGS = ''; if ( $ENV{'LDFLAGS_ALL'} ne "" ) { $LDFLAGS = $ENV{'LDFLAGS_ALL'} } else { $LDFLAGS .= ' ' . $ENV{'LDFLAGS_OPTIMIZE'}; $LDFLAGS .= ' ' . $ENV{'LDFLAGS_DEBUG'}; $LDFLAGS .= ' ' . $ENV{'LDFLAGS_USER'}; $LDFLAGS .= ' ' . $ENV{'LDFLAGS_APPLICATION'}; $LDFLAGS .= ' ' . $ENV{'LDFLAGS_COMPILER'}; $LDFLAGS .= ' ' . $ENV{'LDFLAGS_SYSTEM'}; } $ENV{'LDFLAGS'} = $LDFLAGS; } sub setlibs { my $LIBS = ''; if ( $ENV{'LDFLAGS_LIBS_ALL'} ne "" ) { $LIBS = $ENV{'LDFLAGS_LIBS_ALL'} } else { $LIBS .= ' ' . $ENV{'LDFLAGS_LIBS_USER'}; $LIBS .= ' ' . $ENV{'LDFLAGS_LIBS_APPLICATION'}; $LIBS .= ' ' . $ENV{'LDFLAGS_LIBS_SYSTEM'}; } $ENV{'LIBS'} = $LIBS; } sub print_headers { my ($r_a, $r_clist, $r_config, $cppchk) = @_; my $txt; $txt = ''; if ($r_a->{'incheaders'} eq 'none') { return $txt; } if ($r_a->{'incheaders'} eq 'all' || $r_a->{'incheaders'} eq 'std') { # always include these four if present ... foreach my $val ('_hdr_stdio', '_hdr_stdlib', '_sys_types', '_sys_param') { if (defined ($r_config->{$val}) && $r_config->{$val} ne '0') { $txt .= "#include <" . $r_config->{$val} . ">\n"; # for cygwin/gcc if ($cppchk && $val eq '_hdr_stdio') { $txt .= $postcc; } } } } if ($r_a->{'incheaders'} eq 'all') { foreach my $val (@{$r_clist->{'vars'}}) { if ($val !~ m#^(_hdr_|_sys_)#o) { next; } if ($val eq '_hdr_stdio' || $val eq '_hdr_stdlib' || $val eq '_sys_types' || $val eq '_sys_param') { next; } if ($val eq '_sys_time' && $r_config->{'_sys_time'} ne '0' && $r_config->{'_inc_conflict__hdr_time__sys_time'} eq '0') { next; } if ($val eq '_hdr_linux_quota' && $r_config->{'_hdr_linux_quota'} ne '0' && $r_config->{'_inc_conflict__sys_quota__hdr_linux_quota'} eq '0') { next; } if ($r_config->{$val} ne '0') { $txt .= "#include <" . $r_config->{$val} . ">\n"; } } $txt .= "\n"; } return $txt; } sub _chk_run { my ($name, $code, $r_val, $r_clist, $r_config, $r_a) = @_; my $rc = _chk_link ($name, $code, $r_clist, $r_config, { 'incheaders' => 'all', %$r_a, }); print LOGFH "## run test: link: $rc\n"; $$r_val = 0; if ($rc == 0) { $rc = system ("./$name.exe > $name.out"); if ($rc & 127) { exitmkconfig ($rc); } $rc >>= 8; print LOGFH "## run test: run: $rc\n"; if ($rc == 0) { open (CRFH, "<$name.out"); $$r_val = ; chomp $$r_val; close CRFH; } } return $rc; } sub _chk_link { my ($name, $code, $r_clist, $r_config, $r_a) = @_; my $otherlibs = ''; if (defined ($r_a->{'otherlibs'})) { $otherlibs = $r_a->{'otherlibs'}; } open (CLFH, ">$name.c"); print CLFH $precc; my $hdrs = print_headers ($r_a, $r_clist, $r_config, 0); print CLFH $hdrs; print CLFH $code; close CLFH; my $rc = system ("cat $name.c >> $LOG"); if ($rc & 127) { exitmkconfig ($rc); } my $dlibs = ''; $rc = _chk_link_libs ($name, {} ); if ($rc != 0) { if ($otherlibs ne '') { my @olibs = split (/,/, $otherlibs); my $oliblist = ''; foreach my $olib (@olibs) { $oliblist = $oliblist . ' ' . $olib; $rc = _chk_link_libs ($name, { 'otherlibs' => $oliblist, } ); if ($rc == 0) { my $r_hash = $r_config->{'reqlibs'}; my @vals = split (/\s+/, $oliblist); $dlibs = ''; foreach my $val (@vals) { if ($val eq '') { next; } if (! defined ($r_hash->{$val})) { print LOGFH " reqlib: $val: new\n"; push @{$r_config->{'reqlibs_list'}}, $val; } else { print LOGFH " reqlib: $val: already\n"; } $r_hash->{$val} = 1; $dlibs .= $val . ' '; } last; } } } } $dlibs =~ s/ *$//o; $r_a->{'dlibs'} = $dlibs; return $rc; } sub _chk_link_libs { my ($name, $r_a) = @_; setcflags setldflags setlibs my $cmd = "$ENV{'CC'} $ENV{'CFLAGS'} "; if (defined ($r_a->{'cflags'})) { $cmd .= ' ' . $r_a->{'cflags'} . ' '; } $cmd .= "-o $name.exe $name.c"; $cmd .= " $ENV{'LDFLAGS'} $ENV{'LIBS'}"; if (defined ($r_a->{'otherlibs'}) && $r_a->{'otherlibs'} ne undef) { $cmd .= ' ' . $r_a->{'otherlibs'} . ' '; } print LOGFH "## link test: $cmd\n"; my $rc = system ("$cmd >> $LOG 2>&1"); if ($rc & 127) { exitmkconfig ($rc); } print LOGFH "## link test: $rc\n"; if ($rc == 0) { if (! -x "$name.exe") # not executable. { $rc = 1; } } return $rc; } sub _chk_cpp { my ($name, $code, $r_clist, $r_config, $r_a) = @_; open (CCFH, ">$name.c"); print CCFH $precc; my $hdrs = print_headers ($r_a, $r_clist, $r_config, 1); print CCFH $hdrs; print CCFH $code; close CCFH; setcflags my $cmd = "$ENV{'CC'} $ENV{'CFLAGS'} "; if (defined ($r_a->{'cflags'})) { $cmd .= ' ' . $r_a->{'cflags'} . ' '; } $cmd .= "-E $name.c > $name.out "; my $rc = system ("cat $name.c >> $LOG"); if ($rc & 127) { exitmkconfig ($rc); } $rc = system ("$cmd 2>>$LOG"); print LOGFH "## cpp test: $cmd\n"; if ($rc & 127) { exitmkconfig ($rc); } print LOGFH "## cpp test: $rc\n"; if ($rc == 0 && ! -f "$name.out") { print LOGFH "## can't locate $name.out\n"; $rc = -2; } return $rc; } sub _chk_compile { my ($name, $code, $r_clist, $r_config, $r_a) = @_; open (CCFH, ">$name.c"); print CCFH $precc; my $hdrs = print_headers ($r_a, $r_clist, $r_config, 0); print CCFH $hdrs; print CCFH $code; close CCFH; setcflags my $cmd = "$ENV{'CC'} $ENV{'CFLAGS'} -c $name.c"; print LOGFH "## compile test: $cmd\n"; my $rc = system ("cat $name.c >> $LOG"); if ($rc & 127) { exitmkconfig ($rc); } $rc = system ("$cmd >> $LOG 2>&1"); if ($rc & 127) { exitmkconfig ($rc); } print LOGFH "## compile test: $rc\n"; return $rc; } sub do_chk_compile { my ($name, $code, $inc, $r_clist, $r_config) = @_; my $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => $inc, }); my $trc = 0; if ($rc == 0) { $trc = 1; } printyesno $name, $trc; setlist $r_clist, $name; $r_config->{$name} = $trc; } sub check_header { my ($name, $file, $r_clist, $r_config, $r_a) = @_; printlabel $name, "header: $file"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } my $r_rh = $r_a->{'reqhdr'} || []; my $code = ''; foreach my $reqhdr (@$r_rh) { $code .= <<"_HERE_"; #include <$reqhdr> _HERE_ } $code .= <<"_HERE_"; #include <${file}> int main () { return (0); } _HERE_ my $rc = 1; $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => 'std', }); my $val = 0; if ($rc == 0) { $val = $file; } printyesno $name, $val; setlist $r_clist, $name; $r_config->{$name} = $val; } sub check_constant { my ($name, $constant, $r_clist, $r_config, $r_a) = @_; printlabel $name, "constant: $constant"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } my $r_rh = $r_a->{'reqhdr'} || []; my $code = ''; foreach my $reqhdr (@$r_rh) { $code .= <<"_HERE_"; #include <$reqhdr> _HERE_ } $code .= <<"_HERE_"; int main () { if (${constant} == 0) { 1; } return (0); } _HERE_ do_chk_compile ($name, $code, 'all', $r_clist, $r_config); } # if the keyword is reserved, the compile will fail. sub check_keyword { my ($name, $keyword, $r_clist, $r_config) = @_; printlabel $name, "keyword: $keyword"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } $r_config->{$name} = 0; my $code = <<"_HERE_"; int main () { int ${keyword}; ${keyword} = 1; return (0); } _HERE_ my $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => 'std', }); setlist $r_clist, $name; if ($rc != 0) # failure means it is reserved... { $r_config->{$name} = 1; } printyesno $name, $r_config->{$name}; } sub check_proto { my ($name, $r_clist, $r_config) = @_; printlabel $name, "supported: prototypes"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } my $code = <<"_HERE_"; CPP_EXTERNS_BEG extern int foo (int, int); CPP_EXTERNS_END int bar () { int rc; rc = foo (1,1); return 0; } _HERE_ my $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => 'all', }); setlist $r_clist, $name; $r_config->{$name} = 0; if ($rc == 0) { $r_config->{$name} = 1; } printyesno $name, $r_config->{$name}; } sub check_command { my ($name, $cmds, $r_clist, $r_config) = @_; my @cmdlist = split (/ +/o, $cmds); my $cmd = $cmdlist[0]; $name = "_command_${cmd}"; my $locnm = "_cmd_loc_${cmd}"; printlabel $name, "command: $cmd"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; $r_config->{$name} = 0; foreach my $cmd (@cmdlist) { foreach my $p (split /[;:]/o, $ENV{'PATH'}) { if (-x "$p/$cmd") { setlist $r_clist, $locnm; $r_config->{$locnm} = "$p/$cmd"; $r_config->{$name} = 1; last; } } } printyesno_val $name, $r_config->{$name}; } sub check_grep { my ($name, $args, $r_clist, $r_config) = @_; my @arglist = split (/ +/o, $args); my $tag = $arglist[0]; my $pat= $arglist[1]; my $fn = $arglist[2]; $name = "_grep_${tag}"; my $locnm = "_grep_${tag}"; printlabel $name, "grep: $tag"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; $r_config->{$name} = 0; my $rc = system ("grep '${pat}' $fn > /dev/null 2>&1"); if ($rc == 0) { $r_config->{$name} = 1; } printyesno_val $name, $r_config->{$name}; } sub check_ifoption { my ($ifcount, $type, $name, $opt, $r_clist, $r_config) = @_; printlabel $name, "$type ($ifcount): $opt"; loadoptions (); my $trc = 0; my $found = 'F'; if ($optionsloaded && defined ($optionshash{$opt})) { $found = 'T'; $trc = lc $optionshash{$opt}; print LOGFH "## found: $opt => $trc\n"; if ($trc eq 't') { $trc = 1; } if ($trc eq 'enable') { $trc = 1; } if ($trc eq 'f') { $trc = 0; } if ($trc eq 'disable') { $trc = 0; } if ($trc eq 'true') { $trc = 1; } if ($trc eq 'false') { $trc = 0; } if ($trc eq 'yes') { $trc = 1; } if ($trc eq 'no') { $trc = 0; } } if (! $optionsloaded) { $trc = 0; } elsif ($found eq 'F') { $trc = 0; } if ($type eq 'ifnotoption') { $trc = $trc == 0 ? 1 : 0; } if (! $optionsloaded) { printyesno_actual $name, "no options file"; } elsif ($found eq 'F') { printyesno_actual $name, "option not found"; } else { printyesno $name, $trc; } return $trc; } sub check_if { my ($iflabel, $ifcount, $ifline, $r_clist, $r_config) = @_; my $name = "_if_$iflabel"; my $trc = 0; # make parseable $ifline =~ s/!/ ! /og; $ifline =~ s/\(/ ( /og; $ifline =~ s/\)/ ) /og; $ifline =~ s/&&/ \&\& /og; $ifline =~ s/ and / && /og; $ifline =~ s/ -a / && /og; $ifline =~ s/\|\|/ || /og; $ifline =~ s/ or / || /og; $ifline =~ s/ -o / || /og; $ifline =~ s/ not / ! /og; $ifline =~ s/ +/ /og; $ifline =~ s/^ *//og; $ifline =~ s/ *$//og; printlabel $name, "if ($ifcount): $iflabel"; my $nline = ''; print LOGFH "## ifline: $ifline\n"; my $ineq = 0; my $val; my $quoted = 0; my $qtoken; foreach my $token (split (/\s/, $ifline)) { if ($token =~ /^'.*'$/o) { print LOGFH "## start/end qtoken\n"; $token =~ s/'//go; } elsif ($token =~ /^'/o) { $qtoken = $token; $quoted = 1; print LOGFH "## start qtoken\n"; next; } if ($quoted) { if ($token =~ /'$/o) { $token = $qtoken . ' ' . $token; $token =~ s/'//go; print LOGFH "## end qtoken\n"; $quoted = 0; } else { $qtoken = $qtoken . ' ' . $token; print LOGFH "## in qtoken\n"; next; } } if ($ineq == 1) { $ineq = 2; print LOGFH "## value of $token(B): " . $r_config->{$token} . "\n"; $val = $r_config->{$token}; } elsif ($ineq == 2) { print LOGFH "## end ==\n"; $ineq = 0; $nline .= "('$val' eq '$token') ? 1 : 0"; $nline .= ' '; } elsif ($token eq '==') { print LOGFH "## begin ==\n"; $ineq = 1; } elsif ($token eq '(' || $token eq ')' || $token eq '&&' || $token eq '||' || $token eq '!') { $nline .= $token . ' '; } else { print LOGFH "## value of $token: " . $r_config->{$token} . "\n"; $nline .= $r_config->{$token} ne '0' && $r_config->{$token} ne '' ? 1 : 0; $nline .= ' '; } } print LOGFH "## nline: $nline\n"; $trc = eval $nline; printyesno $name, $trc; return $trc; } sub check_set { my ($name, $type, $val, $r_clist, $r_config) = @_; my $tnm = $name; $tnm =~ s/^_setint_//; $tnm =~ s/^_setstr_//; printlabel $name, "${type}: $tnm"; if ($type eq 'set') { if (defined ($r_config->{$name})) { setlist $r_clist, $name; $r_config->{$name} = $val; printyesno $name, $r_config->{$name}; } else { printyesno_actual $name, 'no such variable'; } } elsif ($type eq 'setint') { setlist $r_clist, $name; $r_config->{$name} = $val; printyesno_actual $name, $r_config->{$name}; } else { setlist $r_clist, $name; $r_config->{$name} = $val; printyesno_actual $name, $r_config->{$name}; } } sub check_option { my ($name, $onm, $def, $r_clist, $r_config) = @_; printlabel $name, "option: $onm"; loadoptions (); my $oval = $def; if ($optionsloaded && defined ($optionshash{$onm})) { $oval = $optionshash{$onm}; print LOGFH "## found: $onm => $oval\n"; } setlist $r_clist, $name; $r_config->{$name} = $oval; printyesno_actual $name, $r_config->{$name}; } sub check_include_conflict { my ($name, $h1, $h2, $r_clist, $r_config) = @_; my $i1 = $h1; $i1 =~ s,/,_,go; $i1 =~ s,\.h$,,o; $i1 =~ s,:,,go; if ($i1 =~ m#^sys#o) { $i1 = "_${i1}"; } else { $i1 = "_hdr_${i1}"; } my $i2 = $h2; $i2 =~ s,/,_,go; $i2 =~ s,\.h$,,o; $i2 =~ s,:,,go; if ($i2 =~ m#^sys#o) { $i2 = "_${i2}"; } else { $i2 = "_hdr_${i2}"; } $name = "${name}_${i1}_${i2}"; printlabel $name, "header: include both $h1 & $h2"; if (defined ($r_config->{${i1}}) && $r_config->{${i1}} ne '0' && defined ($r_config->{${i2}}) && $r_config->{${i2}} ne '0') { if (checkcache ($name, $r_clist, $r_config) == 0) { return; } my $code = <<"_HERE_"; #include <$h1> #include <$h2> int main () { return 0; } _HERE_ do_chk_compile ($name, $code, 'std', $r_clist, $r_config); } else { setlist $r_clist, $name; $r_config->{$name} = 1; printyesno $name, $r_config->{$name}; } } sub check_npt { my ($name, $proto, $req, $r_clist, $r_config) = @_; printlabel $name, "need prototype: $proto"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } if (defined ($r_config->{$req}) && $r_config->{$req} eq '0') { $r_config->{$name} = 0; setlist $r_clist, $name; printyesno $name, $r_config->{$name}; return; } my $code = <<"_HERE_"; CPP_EXTERNS_BEG struct _TEST_struct { int _TEST_member; }; extern struct _TEST_struct* $proto _((struct _TEST_struct*)); CPP_EXTERNS_END _HERE_ do_chk_compile ($name, $code, 'all', $r_clist, $r_config); } sub check_type { my ($name, $type, $r_clist, $r_config) = @_; $type =~ s/star/*/og; printlabel $name, "type: $type"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } my $code = <<"_HERE_"; struct xxx { $type mem; }; static struct xxx v; struct xxx* f() { return &v; } int main () { struct xxx *tmp; tmp = f(); return (0); } _HERE_ do_chk_compile ($name, $code, 'all', $r_clist, $r_config); } sub check_defined { my ($name, $def, $r_clist, $r_config) = @_; printlabel $name, "defined: $def"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; my $code = <<"_HERE_"; int main () { #ifdef ${def} return (0); #else return (1); #endif } _HERE_ my $val = 0; my $rc = _chk_run ($name, $code, \$val, $r_clist, $r_config, {}); $r_config->{$name} = $rc == 0 ? 1 : 0; printyesno $name, $r_config->{$name}; } sub check_param_void_star { my ($name, $r_clist, $r_config) = @_; printlabel $name, "parameter: void *"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } my $code = <<"_HERE_"; char * tparamvs (ptr) void *ptr; { ptr = (void *) NULL; return (char *) ptr; } _HERE_ do_chk_compile ($name, $code, 'all', $r_clist, $r_config); } sub check_printf_long_double { my ($name, $r_clist, $r_config) = @_; printlabel $name, "printf: long double printable"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; my $code = << "_HERE_"; int main (int argc, char *argv[]) { long double a; long double b; char t[40]; a = 1.0; b = 2.0; a = a / b; sprintf (t, \"%.1Lf\", a); if (strcmp(t,\"0.5\") == 0) { return (0); } return (1); } _HERE_ my $val = 0; my %a = ( 'incheaders' => 'all', ); my $rc = _chk_run ($name, $code, \$val, $r_clist, $r_config, \%a); $r_config->{$name} = $rc == 0 ? 1 : 0; printyesno $name, $r_config->{$name}; } sub check_lib { my ($name, $func, $r_clist, $r_config, $r_a) = @_; setlist $r_clist, $name; my $val = $r_a->{'otherlibs'} || ''; $rfunc = $func; $rfunc =~ s/_dollar_/\$/g; if ($val ne '') { printlabel $name, "function: $rfunc [$val]"; } else { printlabel $name, "function: $rfunc"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } } $r_config->{$name} = 0; # unfortunately, this does not work if the function # is not declared. my $hinc = 'all'; my $code = ''; if ($ENV{'_MKCONFIG_USING_CPLUSPLUS'} eq 'Y') { $hinc = 'none'; $code = <<"_HERE_"; CPP_EXTERNS_BEG #undef $rfunc typedef char (*_TEST_fun_)(); char $rfunc(); _TEST_fun_ f = $rfunc; CPP_EXTERNS_END int main () { if (f == $rfunc) { return 0; } return 1; } _HERE_ } else { $hinc = 'all'; $code = <<"_HERE_"; CPP_EXTERNS_BEG typedef char (*_TEST_fun_)(); _TEST_fun_ f = $rfunc; CPP_EXTERNS_END int main () { f(); if (f == $rfunc) { return 0; } return 1; } _HERE_ } my %a = ( 'incheaders' => $hinc, 'otherlibs' => $val, ); my $rc = _chk_link ($name, $code, $r_clist, $r_config, \%a); my $tag = ''; if ($rc == 0) { $r_config->{$name} = 1; if ($a{'dlibs'} ne '') { $tag = " with $a{'dlibs'}"; $r_config->{"lib_$name"} = $a{'dlibs'}; setclist $r_clist, "lib_$name"; } } printyesno $name, $r_config->{$name}, $tag; } sub check_class { my ($name, $class, $r_clist, $r_config, $r_a) = @_; setlist $r_clist, $name; my $val = $r_a->{'otherlibs'} || ''; if ($val ne '') { printlabel $name, "class: $class [$val]"; } else { printlabel $name, "class: $class"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } } $r_config->{$name} = 0; my $code = <<"_HERE_"; int main () { $class testclass; } _HERE_ my %a = ( 'incheaders' => 'all', 'otherlibs' => $val, ); my $rc = _chk_link ($name, $code, $r_clist, $r_config, \%a); my $tag = ''; if ($rc == 0) { $r_config->{$name} = 1; if ($a{'dlibs'} ne '') { $tag = " with $a{'dlibs'}"; $r_config->{"lib_$name"} = $a{'dlibs'}; setlist $r_clist, "lib_$name"; } } printyesno $name, $r_config->{$name}, $tag; } sub check_args { my ($name, $funcnm, $r_a, $r_clist, $r_config) = @_; printlabel $name, "args: $funcnm"; # no cache if ($ENV{'_MKCONFIG_USING_GCC'} eq 'N' && $ENV{'_MKCONFIG_SYSTYPE'} eq 'HP-UX' ) { my $tcc = `$ENV{'CC'} -v 2>&1`; if ($tcc =~ /Bundled/o) { print " bundled cc; skipped"; return; } } my $oldprecc = $precc; $precc .= "/* get rid of most gcc-isms */ #define __asm(a) #define __asm__(a) #define __attribute__(a) #define __nonnull__(a,b) #define __restrict #define __restrict__ #if defined(__THROW) # undef __THROW #endif #define __THROW #define __const const "; my $rc = _chk_cpp ($name, "", $r_clist, $r_config, { 'incheaders' => 'all', }); $precc = $oldprecc; my $ccount = 0; if ($rc == 0) { my $cmd = "egrep \"[ *]" . ${funcnm} . "[ ]*\\(\" $name.out >/dev/null 2>&1"; $rc = system ($cmd); print LOGFH "## args: $cmd $rc\n"; if ($rc == 0) { my $dcl = `${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextdcl.awk ${name}.out ${funcnm}`; # $dcl may be multi-line...fix this now. $dcl =~ s/[ \n\r]/ /gos; $dcl =~ s/extern *//o; $dcl =~ s/;//o; print LOGFH "## dcl(A): $dcl\n"; $dcl =~ s/\( *void *\)/()/o; print LOGFH "## dcl(C): $dcl\n"; my $c = $dcl; $c =~ s/[^,]*//go; $ccount = length ($c); $ccount += 1; $c = $dcl; $c =~ s/^[^\(]*\(//o; $c =~ s/\)[^\)]*$//o; print LOGFH "## c(E): ${c}\n"; my $val = 1; while (${c} ne "") { my $tc = $c; $tc =~ s/ *,.*$//o; $tc =~ s/[ ]+/ /go; if ($r_a->{'noconst'} eq 'T') { $tc =~ s/const *//o; } $tc =~ s/^ *//; $tc =~ s/ *$//; # only do the following if the names of the variables are declared $tc =~ s/(struct|union|enum) /$1#/; if ($tc =~ / /o) { $tc =~ s/ *[A-Za-z0-9_]*$//o; } $tc =~ s/(struct|union|enum)#/$1 /; print LOGFH "## tc(F): ${tc}\n"; my $nm = "_c_arg_${val}_${funcnm}"; setlist $r_clist, $nm; $r_config->{$nm} = $tc; $val += 1; $c =~ s/^[^,]*//o; $c =~ s/^[ ,]*//o; print LOGFH "## c(G): ${c}\n"; } $c = $dcl; $c =~ s/[ ]+/ /go; $c =~ s/([ \*])${funcnm}[ \(].*/$1/; $c =~ s/^ *//o; $c =~ s/ *$//o; if ($r_a->{'noconst'}) { $c =~ s/const *//; } $nm = "_c_type_${funcnm}"; setlist $r_clist, $nm; $r_config->{$nm} = $c; } } setlist $r_clist, $name; $r_config->{$name} = $ccount; printyesno_val $name, $r_config->{$name}; } sub check_size { my ($name, $type, $r_clist, $r_config) = @_; printlabel $name, "sizeof: $type"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; $r_config->{$name} = 0; my $code = <<"_HERE_"; int main () { printf("%u\\n", sizeof($type)); return (0); } _HERE_ my $val = 0; my $rc = _chk_run ($name, $code, \$val, $r_clist, $r_config, {}); if ($rc == 0) { $val =~ s/\r//gos; $r_config->{$name} = $val; } printyesno_val $name, $r_config->{$name}; } sub check_member { my ($name, $struct, $member, $r_clist, $r_config) = @_; printlabel $name, "exists: $struct.$member"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; $r_config->{$name} = 0; my $code = <<"_HERE_"; int main () { $struct s; int i; i = sizeof (s.$member); } _HERE_ my $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => 'all', }); if ($rc == 0) { $r_config->{$name} = 1; } printyesno $name, $r_config->{$name}; } sub check_memberxdr { my ($name, $struct, $member, $r_clist, $r_config) = @_; printlabel $name, "member:xdr: $struct.$member"; # no cache $r_config->{$name} = 0; my $rc = _chk_cpp ($name, "", $r_clist, $r_config, { 'incheaders' => 'all', }); if ($rc == 0) { print LOGFH `pwd` . "\n"; print LOGFH "## ${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextstruct.awk ${name}.out ${struct}\n"; my $st = `${awkcmd} -f ${_MKCONFIG_DIR}/util/mkcextstruct.awk ${name}.out ${struct}`; print LOGFH "## xdr(A): $st\n"; if ($st =~ m/${member}\s*;/s) { my $mtype = $st; $mtype =~ s/\s*${member}\s*;.*//s; $mtype =~ s/.*\s//os; print LOGFH "## xdr(B): $mtype\n"; setlist $r_clist, "xdr_${member}"; $r_config->{"xdr_${member}"} = "xdr_${mtype}"; $r_config->{$name} = 1; } } setlist $r_clist, $name; printyesno $name, $r_config->{$name}; } sub check_int_declare { my ($name, $function, $r_clist, $r_config) = @_; printlabel $name, "declared: $function"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; $r_config->{$name} = 0; my $code = <<"_HERE_"; int main () { int x; x = $function; } _HERE_ my $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => 'all', }); if ($rc == 0) { $r_config->{$name} = 1; } printyesno $name, $r_config->{$name}; } sub check_ptr_declare { my ($name, $function, $r_clist, $r_config) = @_; printlabel $name, "declared: $function"; if (checkcache ($name, $r_clist, $r_config) == 0) { return; } setlist $r_clist, $name; $r_config->{$name} = 0; my $code = <<"_HERE_"; int main () { void *x; x = $function; } _HERE_ my $rc = _chk_compile ($name, $code, $r_clist, $r_config, { 'incheaders' => 'all', }); if ($rc == 0) { $r_config->{$name} = 1; } printyesno $name, $r_config->{$name}; } sub check_standard { my ($r_clist, $r_config) = @_; # FreeBSD has buggy headers, requires sys/param.h as a required include. # always check for these headers. my @headlist1 = ( [ "_hdr_stdio", "stdio.h", ], [ "_hdr_stdlib", "stdlib.h", ], [ "_sys_types", "sys/types.h", ], [ "_sys_param", "sys/param.h", ], ); foreach my $r_arr (@headlist1) { check_header ($$r_arr[0], $$r_arr[1], $r_clist, $r_config, { 'reqhdr' => [], }); } check_keyword ('_key_void', 'void', $r_clist, $r_config); check_keyword ('_key_const', 'const', $r_clist, $r_config); check_param_void_star ('_param_void_star', $r_clist, $r_config); check_proto ('_proto_stdc', $r_clist, $r_config); } sub create_output { my ($r_clist, $r_config, $include, $configfile) = @_; if ($CONFH eq 'none') { return; } my $dt=`date`; chomp $dt; open (CCOFH, ">$CONFH"); print CCOFH <<"_HERE_"; /* Created on: ${dt} From: ${configfile} Using: mkconfig-${_MKCONFIG_VERSION} (perl) */ #ifndef MKC_INC_${CONFHTAGUC}_H #define MKC_INC_${CONFHTAGUC}_H 1 _HERE_ foreach my $val (@{$r_clist->{'vars'}}) { if ($val =~ m#^lib__lib_#o) { next; } my $tval = 0; if ($r_config->{$val} ne "0") { $tval = 1; } if ($val =~ m#^_setint_#o) { $tnm = $val; $tnm =~ s/^_setint_//; print CCOFH "#define $tnm " . $r_config->{$val} . "\n"; } elsif ($val =~ m#^(_setstr_|_opt_|_cmd_loc_)#o) { $tnm = $val; $tnm =~ s/^_setstr_//; $tnm =~ s/^_opt_//; print CCOFH "#define $tnm \"" . $r_config->{$val} . "\"\n"; } elsif ($val =~ m#^(_hdr|_sys|_command)#o) { print CCOFH "#define $val $tval\n"; } else { print CCOFH "#define $val " . $r_config->{$val} . "\n"; } } # standard tail -- always needed; non specific print CCOFH <<'_HERE_'; #ifndef MKC_STANDARD_DEFS # define MKC_STANDARD_DEFS 1 # if ! _key_void # define void int # endif # if ! _key_void || ! _param_void_star typedef char *_pvoid; # else typedef void *_pvoid; # endif # if ! _key_const # define const # endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif #endif /* MKC_STANDARD_DEFS */ _HERE_ print CCOFH $include; print CCOFH <<"_HERE_"; #endif /* MKC_INC_${CONFHTAGUC}_H */ _HERE_ close CCOFH; } sub main_process { my ($configfile) = @_; my (%clist, %config); $clist{'clist'} = (); $clist{'chash'} = {}; $clist{'vars'} = (); $clist{'vhash'} = {}; $config{'reqlibs'} = {}; $config{'reqlibs_list'} = (); if (-f $CACHEFILE) { open (MKCC, "<$CACHEFILE"); while (my $line = ) { chomp $line; if ($line =~ m/^mkc_c_(.*)=\$?'?(.*)'?/o) { my $name = $1; my $val = $2; $config{$name} = $val; push @{$clist{'clist'}}, $name; $clist{'chash'}->{$name} = 1; } } close (MKCC); } my $tconfigfile = $configfile; if ($configfile !~ m#^/#) { $tconfigfile = "../../$configfile"; } if (! open (DATAIN, "<$tconfigfile")) { print STDOUT "$configfile: $!\n"; exit 1; } my $linenumber = 0; my $inheaders = 1; my $ininclude = 0; my @doproclist; my $inproc = 0; my $doproc = 1; my $include = ''; my $tline = ''; my $ifstmtcount = 0; my $ifcurrlvl = 0; my $doif = $ifcurrlvl; while (my $line = ) { chomp $line; ++$linenumber; if ($ininclude == 0 && ($line =~ /^#/o || $line eq '')) { next; } if ($tline ne '') { $line = $tline . ' ' . $line; $tline = ''; } if ($line =~ /[^\\]\\$/o) { $tline = $line; $tline =~ s/\\$//o; next; } if ($ininclude == 1 && $line =~ m#^\s*endinclude$#o) { print LOGFH "end include\n"; $ininclude = 0; next; } elsif ($ininclude == 1) { $line =~ s,\\(.),$1,g; $include .= $line . "\n"; next; } if ($inheaders && $line !~ m#^\s*(hdr|sys)#o) { $inheaders = 0; } print LOGFH "#### ${linenumber}: ${line}\n"; if ($line =~ m#^\s*else#o) { if ($ifcurrlvl == $doif) { $doproc = $doproc == 0 ? 1 : 0; $iflevels =~ s/.\d+\s$//; $iflevels .= "-$ifstmtcount "; } } elsif ($line =~ m#^\s*if\s#o) { if ($doproc == 0) { $ifcurrlvl += 1; } } elsif ($line =~ m#^\s*endif#o) { if ($ifcurrlvl == $doif) { if ($#doproclist >= 0) { print LOGFH "## endif: doproclist: " . join (' ', @doproclist) . "\n"; $doproc = shift @doproclist; print LOGFH "## endif: doproclist now : " . join (' ', @doproclist) . "\n"; print LOGFH "## endif: doproc: $doproc\n"; $iflevels =~ s/.\d+\s$//; } else { $doproc = 1; $iflevels = ''; } $doif -= 1; } $ifcurrlvl -= 1; } if ($doproc == 1) { if ($line =~ m#^\s*output\s+([^\s]+)#o) { if ($inproc == 1) { savevars (\%clist); create_output (\%clist, \%config, $include, $configfile); $CONFH = 'none'; $CONFHTAG = 'none'; $CONFHTAGUC = 'NONE'; $include = ''; } print "output-file: $1\n"; my $tconfh = $1; if ($tconfh =~ m#^/#o) { $CONFH = $tconfh; } else { $CONFH = "../../$tconfh"; } $CONFHTAG = $tconfh; $CONFHTAG =~ s,.*/,,; $CONFHTAG =~ s,\..*$,,; $CONFHTAGUC = uc $CONFHTAG; print LOGFH "config file: $CONFH\n"; $inproc = 1; $VARSFILE = "../../${MKC_FILES}/mkc_${CONFHTAG}_c.vars"; $clist{'vars'} = (); $clist{'vhash'} = {}; } elsif ($line =~ m#^\s*option\-file\s+([^\s]+)#o) { print "option-file: $1\n"; my $tfile = $1; if ($tfile =~ m#^/#o) { $OPTIONFILE = $tfile; } else { $OPTIONFILE = "../../$tfile"; } print LOGFH "options file: $OPTIONFILE\n"; } elsif ($line =~ m#^\s*standard#o) { check_standard (\%clist, \%config); } elsif ($line =~ m#^\s*loadunit#o) { ; } elsif ($line =~ m#^\s*args\s+(.*)$#o) { my $funcnm = $1; %args = ( 'noconst' => 'F' ); if ($funcnm =~ /^noconst */o) { $funcnm =~ s/^noconst *//o; $args{'noconst'} = 'T'; } my $nm = "_args_${funcnm}"; $nm =~ s,/,_,go; $nm =~ s,:,_,go; check_args ($nm, $funcnm, \%args, \%clist, \%config); } elsif ($line =~ m#^\s*include_conflict\s+([^\s]+)\s+([^\s]+)#o) { my $i1 = $1; my $i2 = $2; check_include_conflict ('_inc_conflict', $i1, $i2, \%clist, \%config); } elsif ($line =~ m#^\s*rquota_xdr$#o) { check_rquota_xdr ('_rquota_xdr', \%clist, \%config); } elsif ($line =~ m#^\s*gqa_uid_xdr$#o) { check_gqa_uid_xdr ('_gqa_uid_xdr', \%clist, \%config); } elsif ($line =~ m#^\s*include$#o) { print LOGFH "start include\n"; $ininclude = 1; } elsif ($line =~ m#^\s*(hdr|sys)\s+([^\s]+)\s*(.*)#o) { my $typ = $1; my $hdr = $2; my $reqhdr = $3; my $nm = "_${typ}_"; # create the standard header name for config.h $nm .= $hdr; $nm =~ s,/,_,go; $nm =~ s,\.h$,,o; $nm =~ s,:,_,go; if ($typ eq 'sys') { $hdr = 'sys/' . $hdr; } $reqhdr =~ s/^\s*//o; $reqhdr =~ s/\s*$//o; my @oh = split (/\s+/, $reqhdr); check_header ($nm, $hdr, \%clist, \%config, { 'reqhdr' => \@oh, }); } elsif ($line =~ m#^\s*const\s+([^\s]+)\s*(.*)#o) { my $tnm = $1; my $reqhdr = $2; my $nm = "_const_" . $tnm; $reqhdr =~ s/^\s*//o; $reqhdr =~ s/\s*$//o; my @oh = split (/\s+/, $reqhdr); check_constant ($nm, $tnm, \%clist, \%config, { 'reqhdr' => \@oh, }); } elsif ($line =~ m#^\s*command\s+(.*)#o) { my $cmds = $1; check_command ('', $cmds, \%clist, \%config); } elsif ($line =~ m#^\s*grep\s+(.*)#o) { check_grep ('', $1, \%clist, \%config); } elsif ($line =~ m#^\s*(if(not)?option)\s+([^\s]+)#o) { my $type = $1; my $opt = $3; my $nm = "_${type}_${opt}"; ++$ifstmtcount; my $rc = check_ifoption ($ifstmtcount, $type, $nm, $opt, \%clist, \%config); $iflevels .= "+$ifstmtcount "; unshift @doproclist, $doproc; $doproc = $rc; print LOGFH "## ifoption: doproclist: " . join (' ', @doproclist) . "\n"; print LOGFH "## ifoption: doproc: $doproc\n"; } elsif ($line =~ m#^\s*if\s+([^\s]+)\s+(.*)#o) { my $iflabel = $1; my $ifline = $2; ++$ifcurrlvl; ++$ifstmtcount; print LOGFH "## if: label: $iflabel count $ifstmtcount line: $ifline\n"; my $rc = check_if ($iflabel, $ifstmtcount, $ifline, \%clist, \%config); $iflevels .= "+$ifstmtcount "; unshift @doproclist, $doproc; $doproc = $rc; $doif = $ifcurrlvl; print LOGFH "## if: doproclist: " . join (' ', @doproclist) . "\n"; print LOGFH "## if: doproc: $doproc\n"; } elsif ($line =~ m#^\s*(endif|else)#o) { ; } elsif ($line =~ m#^\s*echo\s+(.*)$#o) { print $1; } elsif ($line =~ m#^\s*exit$#o) { print $1; } elsif ($line =~ m#^\s*(set(int|str)?)\s+([^\s]+)\s*(.*)#o) { my $type = $1; my $nm = $3; if ($type eq 'setint' || $type eq 'setstr') { $nm = "_${type}_$3"; } my $val = $4; check_set ($nm, $type, $val, \%clist, \%config); } elsif ($line =~ m#^\s*option\s+([^\s]+)\s*(.*)#o) { my $nm = "_opt_$1"; my $onm = $1; my $def = $2; check_option ($nm, $onm, $def, \%clist, \%config); } elsif ($line =~ m#^\s*npt\s+([^\s]*)\s*(.*)#o) { my $func = $1; my $req = $2; my $nm = "_npt_" . $func; check_npt ($nm, $func, $req, \%clist, \%config); } elsif ($line =~ m#^\s*key\s+(.*)#o) { my $tnm = $1; my $nm = "_key_" . $tnm; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_keyword ($nm, $tnm, \%clist, \%config); } } elsif ($line =~ m#^\s*class\s+([^\s]+)\s*(.*)?#o) { my $class = $1; my $libs = $2 || ''; my $nm = "_class_" . $class; $nm =~ s,:,_,go; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_class ($nm, $class, \%clist, \%config, { 'otherlibs' => $libs, }); } } elsif ($line =~ m#^\s*typ\s+(.*)#o) { my $tnm = $1; my $nm = "_typ_" . $tnm; $nm =~ s, ,_,go; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_type ($nm, $tnm, \%clist, \%config); } } elsif ($line =~ m#^\s*define\s+(.*)#o) { my $tnm = $1; my $nm = "_define_" . $tnm; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_defined ($nm, $tnm, \%clist, \%config); } } elsif ($line =~ m#^\s*lib\s+([^\s]+)\s*(.*)?#o) { my $func = $1; my $libs = $2 || ''; my $nm = "_lib_" . $func; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_lib ($nm, $func, \%clist, \%config, { 'otherlibs' => $libs, }); } } elsif ($line =~ m#^\s*dcl\s+([^\s]*)\s+(.*)#o) { my $type = $1; my $var = $2; my $nm = "_dcl_" . $var; if (! defined ($config{$nm}) || $config{$nm} eq '0') { if ($type eq 'int') { check_int_declare ($nm, $var, \%clist, \%config); } elsif ($type eq 'ptr') { check_ptr_declare ($nm, $var, \%clist, \%config); } } } elsif ($line =~ m#^\s*printf_long_double#o) { check_printf_long_double ('_printf_long_double', \%clist, \%config); } elsif ($line =~ m#^\s*member\s+(.*)\s+([^\s]+)#o) { my $struct = $1; my $member = $2; my $nm = "_mem_" . $struct . '_' . $member; $nm =~ s/ /_/go; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_member ($nm, $struct, $member, \%clist, \%config); } } elsif ($line =~ m#^\s*memberxdr\s+(.*)\s+([^\s]+)#o) { my $struct = $1; my $member = $2; my $nm = "_memberxdr_" . $struct . '_' . $member; $nm =~ s/ /_/go; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_memberxdr ($nm, $struct, $member, \%clist, \%config); } } elsif ($line =~ m#^\s*size\s+(.*)#o) { my $typ = $1; $typ =~ s/\s*$//o; my $nm = "_siz_" . $typ; $nm =~ s, ,_,go; if (! defined ($config{$nm}) || $config{$nm} eq '0') { check_size ($nm, $typ, \%clist, \%config); } } else { print LOGFH "unknown command: $line\n"; print STDOUT "unknown command: $line\n"; } } } savevars (\%clist); savecache (\%clist, \%config); create_output (\%clist, \%config, $include, $configfile); # This is here for os/2 and other systems w/no usable bourne shell. # it is not up to date, as it will output libraries that are not # needed by the final configuration. open (RLIBFH, ">$REQLIB"); my $r_list = $config{'reqlibs_list'}; print RLIBFH join (' ', @{$r_list}) . "\n"; close RLIBFH; } sub usage { print STDOUT "Usage: $0 [-c ] [-L ]\n"; print STDOUT " [-o ] [-C] \n"; print STDOUT " -C : clear cache-file\n"; print STDOUT "defaults:\n"; print STDOUT " : mkconfig.cache\n"; print STDOUT " : mkconfig.log\n"; print STDOUT " : options.dat\n"; } # main my $clearcache = 0; while ($#ARGV > 0) { if ($ARGV[0] eq "-C") { shift @ARGV; $clearcache = 1; } if ($ARGV[0] eq "-c") { shift @ARGV; $CACHEFILE = $ARGV[0]; shift @ARGV; } if ($ARGV[0] eq "-L") { shift @ARGV; $LOG = $ARGV[0]; shift @ARGV; } if ($ARGV[0] eq "-o") { shift @ARGV; $OPTIONFILE = $ARGV[0]; shift @ARGV; } } my $configfile = $ARGV[0]; if (! defined ($configfile) || ! -f $configfile) { usage; exit 1; } if (-d $_MKCONFIG_TMP && $_MKCONFIG_TMP ne "mkc_files/_tmp_mkconfig") { usage; exit 1; } delete $ENV{'CDPATH'}; delete $ENV{'GREP_OPTIONS'}; delete $ENV{'ENV'}; $ENV{'LC_ALL'} = "C"; my $tpath = $0; $tpath =~ s,/[^/]*$,,; my $currdir =`pwd`; chomp $currdir; if (! chdir $tpath) { die ("Unable to cd to $tpath. $!\n"); } $_MKCONFIG_VERSION=`cat $tpath/VERSION`; chomp $_MKCONFIG_VERSION; $_MKCONFIG_DIR = `pwd`; chomp $_MKCONFIG_DIR; if (! chdir $currdir) { die ("Unable to cd to $currdir. $!\n"); } if (-d $_MKCONFIG_TMP) { system ("rm -rf $_MKCONFIG_TMP"); } mkdir $_MKCONFIG_TMP, 0777; if (! chdir $_MKCONFIG_TMP) { die ("Unable to cd to $_MKCONFIG_TMP. $!\n"); } if ($clearcache) { unlink $CACHEFILE; unlink $VARSFILE; } print STDOUT "$0 using $configfile\n"; unlink $LOG; open (LOGFH, ">>$LOG"); $ENV{'CFLAGS'} = $ENV{'CFLAGS'}; foreach my $nm ('CC', 'CFLAGS_OPTIMIZE', 'CFLAGS_DEBUG', 'CFLAGS_INCLUDE', 'CFLAGS_USER', 'CFLAGS_APPLICATION', 'CFLAGS_COMPILER', 'CFLAGS_SYSTEM', 'CFLAGS_SHARED', 'CFLAGS_SHARED_USER', 'LDFLAGS_OPTIMIZE', 'LDFLAGS_DEBUG', 'LDFLAGS_USER', 'LDFLAGS_APPLICATION', 'LDFLAGS_COMPILER', 'LDFLAGS_SYSTEM', 'LDFLAGS_SHARED', 'LDFLAGS_SHARED_LIBLINK', 'LDFLAGS_LIBS_USER', 'LDFLAGS_LIBS_APPLICATION', 'LDFLAGS_LIBS_SYSTEM') { print LOGFH "$nm: $ENV{$nm}\n"; } print LOGFH "awk: $awkcmd\n"; main_process $configfile; close LOGFH; if ($ENV{'MKC_KEEP_TMP'} eq "") { if (-d $_MKCONFIG_TMP) { system ("rm -rf $_MKCONFIG_TMP"); } } exit 0; di-4.52/mkconfig/VERSION0000644000175000017500000000000614421556642013016 0ustar bllbll2.6.3 di-4.52/mkconfig/util/0000755000175000017500000000000014421556642012727 5ustar bllblldi-4.52/mkconfig/util/mkcextmacro.awk0000755000175000017500000000710014421556642015751 0ustar bllbll#!/usr/bin/awk # # Copyright 2010-2018 Brad Lanam Walnut Creek CA # Copyright 2020 Brad Lanam Pleasant Hill CA BEGIN { macrostart = "^#[ ]*define[ ]*" ARGV[2] "[ (]" delete ARGV[2]; ins = 0; doend = 0; #print "macrostart:" macrostart; cf = ENVIRON["CFLAGS"]; #print "cf:" cf ":"; split (cf,cfa); for (cfi in cfa) { #print "cfi:" cfi ":cfa[cfi]:" cfa[cfi]; if (cfa[cfi] ~ /^-D/) { gsub (/-D/,"",cfa[cfi]); if (match (cfa[cfi], "=")) { split (cfa[cfi], cfaa, /=/); tcfv = cfaa[1]; if (cfaa[2] > 0) { #print "cflags:" tcfv ":"; cflags[tcfv] = 1; } } else { #print "cflags:" cfa[cfi] ":"; cflags[cfa[cfi]] = 1; } } } exclude = 0; } { #print NR ": " $0; # remove comments gsub (/\/\/.*$/, ""); gsub (/\/\*.*\*\//, ""); gsub (/[ ]*$/, ""); if ($0 ~ /^# *ifndef/) { gsub (/^# *ifndef/, "#if !"); } if ($0 ~ /^# *ifdef/) { gsub (/^# *ifdef/, "#if "); } # this is very simplistic. # there is no precedence and no handling of parentheses if ($0 ~ /^# *if/) { #print "if:"; l = $0; gsub (/^# *if[a-z]*/, "", l); gsub (/defined *\(/, "", l); gsub (/\)/, "", l); gsub (/!/, " NOT ", l); gsub (/\&\&/, " AND ", l); gsub (/\|\|/, " OR ", l); gsub (/^ */, "", l); #print "if:l:" l; l = l " END"; split (l, la); ecount = 0; for (val in ea) { delete ea[val]; } rval = 0; dopop = 0; for (li = 1; la[li] != "END"; ++li) { #print "if:token:" li ":" la[li]; if (la[li] == "END") { continue; } else if (la[li] == "AND" || la[li] == "OR") { ea[ecount++] = rval; ea[ecount++] = la[li]; continue; } else if (la[li] == "NOT") { ea[ecount++] = la[li]; continue; } else { val = 0; if (la[li] ~ /^[0-9]+$/) { val = la[li]; } else if (la[li] in cflags) { #print "ifB':la[li]:" la[li] ":cflags[la[li]]:" cflags[la[li]] ":"; val = 1; } #print "ifB:val:" val; if (ecount > 0) { --ecount; if (ea[ecount] == "AND") { rval = ea[ecount - 1] && val; --ecount; } if (ea[ecount] == "OR") { rval = ea[ecount - 1] || val; --ecount; } if (ea[ecount] == "NOT") { rval = 1 - val; } } else { rval = val; } #print "ifA:rval:" rval; } dopop = 0; } #print "ifEND:rval:" rval; if (rval == 0) { exclude = 1; } } if ($0 ~ /^# *else/) { #print "else:"; exclude = 1 - exclude; } if ($0 ~ /^# *endif/) { #print "endif:"; exclude = 0; } if (exclude == 1) { #print "excluding"; next; } if ($0 ~ /^# *define/ && (NF == 3 || NF == 4)) { l = $0; gsub (/^# *define */, "", l); #print "check define:" l ":"; split (l, la); if (la[2] ~ /^[0-9]+$/) { #print "define:" la[1] ":" la[2]; if (la[2] > 0) { cflags[la[1]] = 1; } if (la[1] in cflags) { cflags[la[1]] = 1; } } } #print "main:" $0; if (ins == 0 && $0 ~ macrostart) { #print "start: " $0; ins = 1; macro = $0; #print "macroA:" macro; doend = 1; if ($0 ~ /\\$/) { doend = 0; gsub (/[ ]*\\$/, " ", macro); #print "macroB:" macro; #print "not end: "; } } else if (ins == 1) { #print "cont: " $0; macro = macro $0; #print "macroC:" macro; doend = 1; if ($0 ~ /\\$/) { doend = 0; gsub (/[ ]*\\$/, " ", macro); #print "macroD:" macro; #print "not end: "; } } else if (ins == 1) { #print "ins = 1; end "; doend = 1; } if (doend == 1) { print macro; exit; } } di-4.52/mkconfig/util/mkcextdcl.awk0000755000175000017500000000333014421556642015413 0ustar bllbll#!/usr/bin/awk # # Copyright 2010-2018 Brad Lanam Walnut Creek CA # Copyright 2020 Brad Lanam Pleasant Hill CA BEGIN { dclstart = "[ *]" ARGV[2] "[ ]*\\("; delete ARGV[2]; bcount = 0; acount = 0; ins = 0; havestart = 0; doend = 0; sarr[0] = ""; #print "dclstart:" dclstart; } { #print "havestart:" havestart " ins:" ins " bcount:" bcount " acount:" acount; if ($0 ~ /^#/) { next; } else if (ins == 0 && $0 ~ dclstart) { #print "start: " $0; ins = 1; acount = 0; sarr[acount] = $0; acount = acount + 1; havestart = 1; tstr = $0; gsub (/[^\(]/, "", tstr); bcount = bcount + length (tstr); #print "start: " length(tstr) " ("; tstr = $0; gsub (/[^\)]/, "", tstr); bcount = bcount - length (tstr); #print "start: " length(tstr) " )"; if (bcount <= 0 && length (tstr) > 0) { doend = 1; } } else if (ins == 1 && $0 ~ /\(/) { #print "(: " $0; sarr[acount] = $0; acount = acount + 1; tstr = $0; gsub (/[^\(]/, "", tstr); bcount = bcount + length (tstr); #print "(: " length(tstr) " ("; tstr = $0; gsub (/[^\(]/, "", tstr); bcount = bcount - length (tstr); #print "(: " length(tstr) " )"; if (bcount <= 0) { ins = 0; } } else if (ins == 1 && $0 ~ /\)/) { #print "): " $0; sarr[acount] = $0; acount = acount + 1; tstr = $0; gsub (/[^\)]/, "", tstr); bcount = bcount - length (tstr); #print "): " length(tstr) " )"; if (bcount <= 0) { if (havestart == 1) { doend = 1; } ins = 0; } } else if (ins == 1) { #print "1: " $0; sarr[acount] = $0; acount = acount + 1; } if (doend == 1) { for (i = 0; i < acount; ++i) { print sarr[i]; } exit; } } di-4.52/mkconfig/util/mkcextstruct.awk0000755000175000017500000001740114421556642016201 0ustar bllbll#!/usr/bin/awk # # Copyright 2010-2018 Brad Lanam Walnut Creek CA # Copyright 2020 Brad Lanam Pleasant Hill CA BEGIN { if (dcode != "T") { dcode = "F"; } ststructA = "(struct|class|union|enum)[ ]*"; ststruct1 = "(struct|class|union|enum)[ ]*\\{"; ststruct2 = "typedef[ ][ ]*(struct|class|union|enum)[ ]*[a-zA-Z0-9_]*[ ]*{?[ ]*$"; ststart1 = "(struct|class|union|enum)[ ]*" ARGV[2] "$"; ststart2 = "(struct|class|union|enum)[ ]*" ARGV[2] "[^a-zA-Z0-9_]"; stforward = "(struct|class|union|enum)[ ]*" ARGV[2] "[ ]*;"; stother = "(struct|class|union|enum)[ ]*" ARGV[2] "[ ][ ]*[*a-zA-Z0-9_]"; stend = "[ *]" ARGV[2] "_t[ ]*;"; stendb = "[ *]" ARGV[2] "[ ]*;"; delete ARGV[2]; bcount = 0; acount = 0; ins = 0; inend = 0; havestart = 0; doend = 0; hadend = 0; sarr[0] = ""; nsarr[0] = ""; savens = ""; lineno = 0; #print "dcode:" dcode; #print "ststruct1:" ststruct1; #print "ststruct2:" ststruct2; #print "ststart1:" ststart1; #print "ststart2:" ststart2; #print "stforward:" stforward; #print "stother:" stother; #print "stend:" stend; #print "stendb:" stendb; } { lineno = lineno + 1; #print lineno ": " $0; #if ($0 ~ ststruct1) { print " " lineno ": matches ststruct1"; } #if ($0 ~ ststruct2) { print " " lineno ": matches ststruct2"; } #if ($0 ~ ststart1) { print " " lineno ": matches ststart"; } #if ($0 ~ ststart2) { print " " lineno ": matches ststart"; } #if ($0 ~ stforward) { print " " lineno ": matches stforward"; } #if ($0 ~ stother) { print " " lineno ": matches stother: " $0; } #if ($0 ~ stend) { print " " lineno ": matches stend: " $0; } #if ($0 ~ stendb) { print " " lineno ": matches stendb: " $0; } #print "havestart:" havestart ":ins:" ins ":bcount:" bcount ":hadend:" hadend ":"; if ($0 ~ /^#/) { next; } else if (ins == 0 && ($0 ~ ststart1 || $0 ~ ststart2) && $0 !~ stforward && $0 !~ stother) { #print lineno ": start: "; hadend = 0; savens = ""; for (val in nsarr) { delete nsarr[val]; } nsarr[0] = ""; acount = 0; ins = 1; gsub (/[ ]*$/, "", $0); sarr[acount] = $0; acount = acount + 1; havestart = 1; tstr = $0; gsub (/[^\{]/, "", tstr); bcount = bcount + length (tstr); tstr = $0; gsub (/[^}]/, "", tstr); bcount = bcount - length (tstr); if (bcount <= 0 && length (tstr) > 0) { doend = 1; } } else if (havestart == 0 && bcount == 0 && ($0 ~ ststruct1 || $0 ~ ststruct2) && $0 !~ stforward && $0 !~ stother) { #print lineno ": struct: "; hadend = 0; savens = ""; for (val in nsarr) { delete nsarr[val]; } nsarr[0] = ""; acount = 0; ins = 1; tstr = $0; gsub (/[^\{]/, "", tstr); bcount = bcount + length (tstr); tstr = $0; gsub (/[^}]/, "", tstr); bcount = bcount - length (tstr); if (bcount <= 0 && length(tstr) > 0) { ins = 0; bcount = 0; savens = ""; for (val in nsarr) { delete nsarr[val]; } nsarr[0] = ""; } if ($0 ~ stend || $0 ~ stendb) { #print lineno ": matches endA: doend"; doend = 1; } acount = 0; gsub (/[ ]*$/, "", $0); sarr[acount] = $0; acount = acount + 1; } else if (hadend == 1 && acount > 0 && bcount == 0 && havestart == 0 && ($0 ~ stend || $0 ~ stendb)) { #print lineno ": endB: "; hadend = 0; gsub (/[ ]*$/, "", $0); sarr[acount] = $0; acount = acount + 1; doend = 1; } else if (ins == 1 && $0 !~ /(struct|class|union|enum)[ ]*\{/ && $0 ~ /(const *)?(struct|class|union|enum)[ ]*[a-zA-Z_][a-zA-Z0-9_]*[ \{]*$/ && $0 !~ /(const *)?(struct|class|union|enum)[ ].*;/) { # nested structure, not an unnamed structure # is named, but not followed by anything else #print lineno ": nested struct: "; hadend = 0; savens = ""; gsub (/[ ]*$/, "", $0); tstr = $0; if (dcode) { if ($0 ~ /struct/) { ttype = "struct"; tlab = "C_ST_"; #print lineno ": found struct" } if ($0 ~ /class/) { ttype = "class"; tlab = "C_CLASS_"; #print lineno ": found class" } if ($0 ~ /union/) { ttype = "union"; tlab = "C_UN_"; #print lineno ": found union" } if ($0 ~ /enum/) { ttype = "enum"; tlab = "C_ENUM_"; #print lineno ": found enum" } sub (/(struct|class|union|enum)[ ]*/, "&" tlab, tstr); #print lineno ": nested(A): " tstr } sarr [acount] = tstr; acount = acount + 1; tstr = $0; gsub (/[^\{]/, "", tstr); bcount = bcount + length (tstr); tstr = $0; gsub (/[^}]/, "", tstr); bcount = bcount - length (tstr); if (bcount <= 0 && length(tstr) > 0) { ins = 0; } if (ins == 1) { tstr = $0; #print lineno ": nested(B): ", $0 if (dcode) { sub (/[ const]*(struct|class|union|enum)[ ]*/, "", tstr); sub (/[ ].*/, "", tstr); } #print lineno ": nested(C): ", tstr; savens = tstr; if (bcount > 1) { nsarr[bcount] = tstr; savens = ""; #print lineno ": nested save: " tstr; } } } else if (ins == 1 && $0 ~ /\{/) { #print lineno ": {: "; hadend = 0; sarr[acount] = $0; acount = acount + 1; tstr = $0; gsub (/[^\{]/, "", tstr); bcount = bcount + length (tstr); tstr = $0; gsub (/[^}]/, "", tstr); bcount = bcount - length (tstr); if (bcount <= 0 && length(tstr) > 0) { ins = 0; } if (ins == 1 && bcount > 1 && savens != "") { #print lineno ": nested last: ", savens; if (bcount > 1) { nsarr[bcount] = savens; #print lineno ": nested save: " savens; } savens = ""; } } else if (ins == 1 && $0 ~ /}/) { #print lineno ": }: "; gsub (/[ ]*$/, "", $0); sarr[acount] = $0; acount = acount + 1; tstr = $0; gsub (/[^}]/, "", tstr); l = length(tstr); bcount = bcount - l; stendtestb = "}[ *][a-zA-Z0-9_]*[ ]*;"; if (l > 0 && $0 !~ stendtestb) { #print lineno ": }: hadend: =1: "; hadend = 1; } else { #print lineno ": }: hadend: =0: "; hadend = 0; } if (bcount <= 0) { #print lineno ": }: bcount: 0"; bcount = 0; if (havestart == 1) { #print lineno ": }: havestart: doend"; doend = 1; } if ($0 ~ stend || $0 ~ stendb) { #print lineno ": matches endC: doend"; doend = 1; } ins = 0; } else if (l > 0 && $0 !~ /}[ ;]*$/) { #print lineno ": end struct dcl: " $0; if (dcode) { tstr = $0; # if there's a declaration of a pointer to the nested structure # we'll be adding the declaration. # if so, remove the name now. # otherwise, keep the name for processing by d-main.sh if (nsarr[bcount + 1] != "") { sub (/}.*/, "};", tstr); sarr [acount - 1] = tstr; } #print lineno ": nsarr1: " nsarr[bcount + 1]; if (nsarr[bcount + 1] != "") { tstr = $0; sub (/}[ ]*/, tlab nsarr[bcount + 1] " ", tstr); sarr [acount] = tstr; acount = acount + 1; } } hadend = 0; } } else if (ins == 1) { #print lineno ": 1: " $0; #print lineno ": 1: hadend:" hadend; if (hadend == 1 && nsarr[bcount + 1] != "") { if ($0 ~ /[ *]*[_A-Za-z]/) { #print lineno ": 1: hadend: match" tstr = $0; if (dcode) { tstr = " " tlab nsarr[bcount + 1] " " $0; } sarr[acount] = tstr; acount = acount + 1; } else { gsub (/[ ]*$/, "", $0); sarr[acount] = $0; acount = acount + 1; } } else { gsub (/[ ]*$/, "", $0); sarr[acount] = $0; acount = acount + 1; } hadend = 0; } else if (ins == 0) { if ($0 ~ ststructA) { hadend = 0; } } if (doend == 1) { for (i = 0; i < acount; ++i) { print sarr[i]; } exit; } } di-4.52/mkconfig/util/mkcexttypedef.awk0000755000175000017500000000240014421556642016306 0ustar bllbll#!/usr/bin/awk # # Copyright 2010-2018 Brad Lanam Walnut Creek CA # Copyright 2020 Brad Lanam Pleasant Hill CA BEGIN { tdstart = "[ ]*typedef"; funcpat = "[ (*]" ARGV[2] "[ )]"; semipat = "[ *]" ARGV[2] "[ ]*;$"; delete ARGV[2]; intypedef = 0; acount = 0; docheck = 0; tarr = ""; lineno = 0; #print "tdstart:" tdstart ":"; #print "funcpat:" funcpat ":"; #print "semipat:" semipat ":"; } { lineno = lineno + 1; #print lineno ": " $0; if ($0 ~ /^#/) { next; } else if (intypedef == 0 && $0 ~ tdstart) { #print "start:"; intypedef = 1; acount = 0; sarr[acount] = $0; acount = acount + 1; tarr = tarr $0; if ($0 ~ /;$/) { #print "have semi"; docheck = 1; } } else if (intypedef == 1) { #print "in:"; sarr[acount] = $0; acount = acount + 1; tarr = tarr $0; if ($0 ~ /;$/) { #print "have semi"; docheck = 1; } } if (docheck == 1) { #print "docheck: tarr:" tarr ":"; if (tarr ~ funcpat || tarr ~ semipat) { #print "docheck: match"; doend = 1; } } if (doend == 1) { for (i = 0; i < acount; ++i) { print sarr[i]; } exit; } if (docheck == 1) { #print "docheck: no match"; acount = 0; tarr = ""; docheck = 0; intypedef = 0; } } di-4.52/mkconfig/bin/0000755000175000017500000000000014421556642012522 5ustar bllblldi-4.52/mkconfig/bin/mkcl.sh0000755000175000017500000001671114421556642014015 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # unset CDPATH # this is a workaround for ksh93 on solaris if [ "$1" = "-d" ]; then cd $2 shift shift fi . ${_MKCONFIG_DIR}/bin/shellfuncs.sh doshelltest $0 $@ addlib () { lfn=$1 found=F nlibnames= for tf in $libnames; do if [ $lfn = $tf ]; then found=T # a match will be moved to the end of the list else doappend nlibnames " $tf" fi done doappend nlibnames " ${lfn}" libnames=${nlibnames} } addlibpath () { lp=$1 found=F for tp in $libpathnames; do if [ $lp = $tp ]; then found=T # a match will be kept. break fi done if [ $found = F ]; then doappend libpathnames " ${lp}" fi } compile=F link=F shared=F mkexec=F mklib=F doecho=F comp=${CC} reqlibfiles= MKC_FILES=${MKC_FILES:-mkc_files} logfile=${MKC_FILES}/mkc_compile.log c=T d=F while test $# -gt 0; do case $1 in -compile|-comp) shift compile=T shared=F ;; -link) shift link=T ;; -log) shift logfile=$1 shift ;; -shared) shift shared=T ;; -exec) shift mkexec=T ;; -lib) shift mkexec=F mklib=T ;; -c) shift comp=$1 shift case ${comp} in *gdc*|*ldc*|*dmd*) d=T c=F ;; esac ;; -d) shift ndir=$1 cd $ndir rc=$? if [ $rc -ne 0 ]; then puts "## Unable to cd to $ndir" grc=$rc exit $grc fi shift ;; -e) doecho=T shift ;; -o) shift outfile=$1 shift ;; -r) shift doappend reqlibfiles " $1" shift ;; [A-Za-z0-9_][A-Za-z0-9_]*=[\'\"]*[\'\"]) eval $1 shift ;; -D*|-U*) doappend CFLAGS_USER " $1" shift ;; --) shift break ;; *) break ;; esac done if [ "$logfile" != "" ]; then exec 9>>$logfile puts "# `date`" >&9 fi # DC_LINK should be in environment already. OUTFLAG="-o " DC_LINK= case ${comp} in *dmd*|*ldc*) # catches ldmd, ldmd2 also OUTFLAG=${DC_OF:-"-of"} DC_LINK=-L ;; *gdc*) OUTFLAG=${DC_OF:-"-o "} ;; *gcc*|*cc*) DC_LINK= ;; esac flags= files= objects= libnames= libpathnames= islib=0 ispath=0 olibs= havesource=F if [ "$reqlibfiles" != "" ]; then for rf in $reqlibfiles; do doappend olibs "`cat $rf`" done fi grc=0 for f in $@ $olibs; do case $f in -D*) doappend CFLAGS_USER $1 shift ;; -L) ispath=1 ;; -L*) tf=$f dosubst tf '-L' '' if [ ! -d "$tf" ]; then puts "## unable to locate dir $tf" grc=1 else addlibpath $tf fi ;; -l) islib=1 ;; -l*) addlib $f ;; lib*) addlib $f ;; *${OBJ_EXT}) if [ ! -f "$f" ]; then puts "## unable to locate $f" grc=1 else doappend objects " $f" fi ;; *.c|*.d|*.m) if [ ! -f "$f" ]; then puts "## unable to locate $f" grc=1 else doappend files " $f" havesource=T fi ;; "-"*) doappend flags " $f" if [ $f = "-c" ]; then compile=T fi ;; *) if [ $islib -eq 1 ]; then addlib "-l$f" elif [ $ispath -eq 1 ]; then if [ ! -d "$f" ]; then puts "## unable to locate dir $f" grc=1 else addlibpath $f fi fi islib=0 ispath=0 ;; esac done libs= for lfn in $libnames; do doappend libs " ${DC_LINK}${lfn}" done libpath= for lp in $libpathnames; do doappend libpath ":${lp}" done dosubst libpath '^:' '' outflags="" if [ "$outfile" = "" ]; then flags="${flags} -c" else outflags="${OUTFLAG}$outfile" case ${outfile} in *.o|*.obj) flags="${flags} -c" ;; esac fi allcflags= if [ $havesource = T ]; then if [ $c = T ];then if [ "$CFLAGS_ALL" != "" ]; then doappend allcflags " ${CFLAGS_ALL}" else doappend allcflags " ${CFLAGS_OPTIMIZE}" # optimization flags doappend allcflags " ${CFLAGS_DEBUG}" # debug flags doappend allcflags " ${CFLAGS_INCLUDE}" # any include files doappend allcflags " ${CFLAGS_USER}" # specified by the user if [ $shared = T ];then doappend allcflags " ${CFLAGS_SHARED}" doappend allcflags " ${CFLAGS_SHARED_USER}" fi doappend allcflags " ${CFLAGS_APPLICATION}" # added by the config process doappend allcflags " ${CFLAGS_COMPILER}" # compiler flags doappend allcflags " ${CFLAGS_SYSTEM}" # needed for this system fi fi if [ $d = T ];then doappend allcflags " ${DFLAGS}" fi fi allldflags= ldflags_runpath= ldflags_shared_libs= ldflags_exec_link= if [ $link = T ]; then if [ "$LDFLAGS_ALL" != "" ]; then doappend allldflags " ${LDFLAGS_ALL}" else doappend allldflags " ${LDFLAGS_OPTIMIZE}" # optimization flags doappend allldflags " ${LDFLAGS_DEBUG}" # debug flags doappend allldflags " ${LDFLAGS_USER}" # specified by the user doappend allldflags " ${LDFLAGS_APPLICATION}" # added by the config process doappend allldflags " ${LDFLAGS_COMPILER}" # link flags doappend allldflags " ${LDFLAGS_SYSTEM}" # needed for this system fi fi if [ $link = T -a $shared = T ]; then doappend allldflags " ${LDFLAGS_SHARED_LIBLINK}" doappend allldflags " ${LDFLAGS_SHARED_USER}" fi if [ \( $shared = T \) -o \( $mkexec = T \) ]; then ldflags_runpath="" if [ "${libpath}" != "" -a "${LDFLAGS_RUNPATH}" != "" ]; then dosubst libpath '^:' '' ldflags_runpath="${LDFLAGS_RUNPATH}${libpath}" fi ldflags_shared_libs="" if [ "${libs}" != "" -a "${libpath}" != "" ]; then ### is this right??? ldflags_shared_libs="${DC_LINK}-L${libpath}" fi ldflags_exec_link="" if [ $mklib = F -a $mkexec = T ]; then if [ "${LDFLAGS_EXEC_LINK}" != "" ]; then ldflags_exec_link="${LDFLAGS_EXEC_LINK}" fi fi fi if [ $link = T ]; then if [ "$LDFLAGS_LIBS_ALL" != "" ]; then doappend alllibs " ${LDFLAGS_LIBS_ALL}" else doappend alllibs " ${LDFLAGS_LIBS_USER}" doappend alllibs " ${LDFLAGS_LIBS_APPLICATION}" doappend alllibs " ${LDFLAGS_LIBS_SYSTEM}" fi fi # clear the standard env vars so they don't get picked up. CFLAGS= CPPFLAGS= LDFLAGS= LIBS= cmd="${comp} ${allcflags} ${flags} ${allldflags} ${ldflags_exec_link} \ $outflags $objects \ ${files} ${ldflags_runpath} ${ldflags_shared_libs} ${alllibs} ${libs}" disp="" if [ $compile = T ]; then disp="${disp}COMPILE ${files} ... " if [ "$logfile" != "" ]; then puts "COMPILE ${files}" >&9 fi fi if [ $link = T ]; then disp="${disp}LINK ${outfile} ... " if [ "$logfile" != "" ]; then puts "LINK ${outfile}" >&9 fi fi if [ $doecho = T ]; then puts "" puts " $cmd" fi if [ "$logfile" != "" ]; then puts " $cmd" >&9 fi out="" if [ "$logfile" != "" ]; then out=`eval $cmd 2>&1` rc=$? puts "$out" >&9 if [ $doecho = T ]; then puts "$out" fi else eval $cmd rc=$? fi if [ $rc -eq 0 ]; then puts "$out" | grep -i warning: >/dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then disp="${disp} warnings" else disp="${disp} ok" fi else disp="${disp} fail" grc=$rc fi puts $disp if [ "$logfile" != "" ]; then exec 9>&- fi exit $grc di-4.52/mkconfig/bin/mkcsetopt.sh0000755000175000017500000000154614421556642015100 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # # This script is used to change an option in an options file. # Usage: # mkcsetopt.sh [-o options-file] option-name value # set -f unset CDPATH # this is a workaround for ksh93 on solaris if [ "$1" = "-d" ]; then cd $2 shift shift fi . ${_MKCONFIG_DIR}/bin/shellfuncs.sh doshelltest $0 $@ OPTFILE=options.dat while test $# -gt 1; do case $1 in -o) shift OPTFILE=$1 shift ;; *) break ;; esac done opt=$1 val=$2 OPTNEW=options.new exec 8>>${OPTNEW} exec 7<&0 < ${OPTFILE} while read oline; do case $oline in ${opt}=*) oline=`echo $oline | sed "s/=.*/=${val}/"` ;; esac echo $oline >&8 done exec <&7 7<&- mv ${OPTNEW} ${OPTFILE} test -f ${OPTNEW} && rm -f ${OPTNEW} exit $rc di-4.52/mkconfig/bin/capabilities.sh0000755000175000017500000000116314421556642015513 0ustar bllbll#!/bin/sh # # Copyright 2020 Brad Lanam Pleasant Hill CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # if [ "${_MKCONFIG_DIR}" = "" ]; then echo "Usage: _MKCONFIG_DIR= bin/capabilities.sh" exit 1 fi unset CDPATH # this is a workaround for ksh93 on solaris if [ "$1" = "-d" ]; then cd $2 shift shift fi . ${_MKCONFIG_DIR}/bin/shellfuncs.sh doshelltest $0 $@ puts "$shell $shvers" puts "printf: $shhasprintf ($shhasprintferr)" puts "append: $shhasappend" puts "math: $shhasmath ($shhasmatherr)" puts "typeset -u: $shhasupper" puts "typeset -l: $shhaslower" puts "readraw required: $shreqreadraw" di-4.52/mkconfig/bin/envfuncs.sh0000755000175000017500000000220714421556642014711 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek, CA, USA # Copyright 2020 Brad Lanam Pleasant Hill CA # setcflags () { CFLAGS="" if [ "$CFLAGS_ALL" != "" ]; then CFLAGS="$CFLAGS_ALL" else doappend CFLAGS " ${CFLAGS_OPTIMIZE}" doappend CFLAGS " ${CFLAGS_DEBUG}" doappend CFLAGS " ${CFLAGS_INCLUDE}" doappend CFLAGS " ${CFLAGS_USER}" doappend CFLAGS " ${CFLAGS_APPLICATION}" doappend CFLAGS " ${CFLAGS_COMPILER}" doappend CFLAGS " ${CFLAGS_SYSTEM}" fi export CFLAGS } setldflags () { LDFLAGS="" if [ "$LDFLAGS_ALL" != "" ]; then LDFLAGS="$LDFLAGS_ALL" else doappend LDFLAGS " ${LDFLAGS_OPTIMIZE}" doappend LDFLAGS " ${LDFLAGS_DEBUG}" doappend LDFLAGS " ${LDFLAGS_USER}" doappend LDFLAGS " ${LDFLAGS_APPLICATION}" doappend LDFLAGS " ${LDFLAGS_COMPILER}" doappend LDFLAGS " ${LDFLAGS_SYSTEM}" fi export LDFLAGS } setlibs () { LIBS="" if [ "$LDFLAGS_LIBS_ALL" != "" ]; then LIBS="$LDFLAGS_LIBS_ALL" else doappend LIBS " ${LDFLAGS_LIBS_USER}" doappend LIBS " ${LDFLAGS_LIBS_APPLICATION}" doappend LIBS " ${LDFLAGS_LIBS_SYSTEM}" fi export LIBS } di-4.52/mkconfig/bin/shellfuncs.sh0000755000175000017500000003001514421556642015226 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek, CA, USA # Copyright 2020 Brad Lanam Pleasant Hill CA # if [ ! -f "${_MKCONFIG_DIR}/VERSION" ]; then echo "Unable to locate ${_MKCONFIG_DIR}/VERSION." echo "Not a valid mkconfig installation." exit 1 fi # dash on Mandriva 2011 segfaults intermittently when: # read _MKCONFIG_VERSION < ${_MKCONFIG_DIR}/VERSION # export _MKCONFIG_VERSION # was used. _MKCONFIG_VERSION=`cat ${_MKCONFIG_DIR}/VERSION` export _MKCONFIG_VERSION # posh set command doesn't output correct data; don't bother with it. # older yash has quoting/backquote issues (what version did this get fixed?) # bosh is a disaster. # zsh is not bourne shell compatible # set | grep can be fixed (nulls are output) with: set | strings | grep # and 'emulate ksh' can be set in mkconfig.sh, but there # are more issues, and I'm not interested in tracking them down. tryshell="bash bash5 bash4 bash3 ksh ksh88 ksh93 mksh pdksh yash ash dash bash2 sh sh5 osh" mkconfigversion () { echo "mkconfig version ${_MKCONFIG_VERSION}" } dosubst () { subvar=$1 shift sa="" while test $# -gt 0; do pattern=$1 sub=$2 shift shift sa="${sa} -e \"s~${pattern}~${sub}~g\"" done cmd="${subvar}=\`echo \${${subvar}} | sed ${sa}\`" eval $cmd; } test_echo () { shhasprintf=0 shhasprintferr="" (eval 'printf %s hello >/dev/null') 2>/dev/null rc=$? # Virtually all shells have printf. # I had not known it was supported so far back -- most # everything used echo, and printf was not mentioned much. # 'printf' is POSIX compliant. if [ $rc -eq 0 ]; then shhasprintf=1 eval 'putsnonl () { printf '%s' "$*"; }' eval 'puts () { printf "%s\n" "$*"; }' else shhasprintferr=none fi # # Backslash interpolation with echo and single quotes has issues. # Apparently I didn't code anything that ran into that problem. # # echo with single quotes should be avoided as too many shells # interpolate backslashes when they should not. # # The read/printf combo fails due to differences from read/echo. # # 2019-6-26: Apparently some older ksh93 also have this issue. # 2020-6-10: Apparently there are differences in quite a few shells here. # I am surprised I did not run into portability issues with this. # # $ echo "a \\ b" # a \ b # $ printf "%s\n" "a \\ b" # a \ b # $ cat tt # a \\ b # $ read tdat < tt # $ echo "$tdat" # a \ b # should be: a \ b # $ printf "%s\n" "$tdat" # a \\ b # should be: a \ b # $ echo 'a \\ b' # a \ b # should be: a \\ b # $ printf "%s\n" 'a \\ b' # a \\ b # should be: a \\ b # $ # # Test for interpolation bugs. # If bugs are present, use 'echo'. tz="a \\\\ b" # should always interpolate as: a \\ b t1=`echo "$tz"` # and both of these should return: a \\ b t2=`printf '%s\n' "$tz"` # have to test against the original in order to catch the change # if echo and printf do not match each other, it is very likely # that the read/echo/printf mismatches also occur. # osh does some odd stuff internally according to the output here, # but echo and printf still seem to work. if [ \( "$tz" != "$t1" \) -o \( "$tz" != "$t2" \) ]; then shhasprintf=0 shhasprintferr=mismatch fi # 'echo' works everywhere, but is not a POSIX compliant command. # Have not found any bourne compatible shell that does not support # either -n or \c. if [ $shhasprintf -eq 0 ]; then _tEN='-n' _tEC='' if [ "`echo -n test`" = "-n test" ]; then _tEN='' _tEC='\c' fi eval 'putsnonl () { echo ${_tEN} "$*${_tEC}"; }' eval 'puts () { echo "$*"; }' fi } # The += form is much, much faster and less prone to errors. test_append () { shhasappend=0 (eval 'x=a;x+=b; test z$x = zab') 2>/dev/null if [ $? -eq 0 ]; then shhasappend=1 eval 'doappend () { eval $1+=\$2; }' else eval 'doappend () { eval $1=\$${1}\$2; }' fi } test_readraw () { # $ cat tt # a \\ b # $ read tdat < tt # $ echo "$tdat" # a \ b # should be: a \ b # $ printf "%s\n" "$tdat" # a \\ b # should be: a \ b shreqreadraw=0 # unixware 7.14 compiles and runs this code ok, but it's shell gets # completely wacked out later. So run it in a subshell. # (similar to mandriva 2011 problem with read < file) ( rrv='aa\\\\bb' read rrx << _HERE_ $rrv _HERE_ ( eval "read -r rry <<_HERE_ $rrv _HERE_" ) 2>/dev/null yrc=$? if [ $yrc -eq 0 ]; then read -r rry << _HERE_ $rrv _HERE_ if [ "${rrx}" != 'aa\\bb' -a "${rry}" = 'aa\\\\bb' ]; then shreqreadraw=1 fi fi exit $shreqreadraw ) shreqreadraw=$? } # use the faster method $((expr)) if possible. test_math () { shhasmath=0 shhasmatherr=none (eval 'x=1;y=$(($x+1)); test z$y = z2') 2>/dev/null rc=$? if [ $rc -eq 0 ]; then shhasmath=1 shhasmatherr="" eval 'domath () { mthvar=$1; mthval=\$\(\($2\)\); eval $mthvar=$mthval; }' fi if [ $shhasmath -eq 0 ]; then eval 'domath () { mthvar=$1; mthval=`expr $2`; eval $mthvar=$mthval; }' fi } # use the faster shell built-in if possible. test_upper () { shhasupper=0 (eval 'typeset -u xuvar;xuvar=x;test z$xuvar = zX') 2>/dev/null if [ $? -eq 0 ]; then shhasupper=1 eval 'toupper () { ucvar=$1; typeset -u ucval; eval "ucval=\${$ucvar};$ucvar=\$ucval"; }' else eval 'toupper () { ucvar=$1; cmd="$ucvar=\`echo \${$ucvar} | tr \"[a-z]\" \"[A-Z]\"\`"; eval "$cmd"; }' fi } # use the faster shell built-in if possible. test_lower () { shhaslower=0 (eval 'typeset -l xuvar;xuvar=X;test z$xuvar = zx') 2>/dev/null if [ $? -eq 0 ]; then shhaslower=1 eval 'tolower () { lcvar=$1; typeset -l lcval; eval "lcval=\${$lcvar};$lcvar=\$lcval"; }' else eval 'tolower () { lcvar=$1; cmd="$lcvar=\`echo \${$lcvar} | tr \"[A-Z]\" \"[a-z]\"\`"; eval "$cmd"; }' fi } testshcapability () { test_echo test_append test_readraw test_math test_upper test_lower } getshelltype () { if [ "$1" != "" ]; then trs=$1 shift fi gstecho=F if [ "$1" = echo ]; then gstecho=T fi baseshell=${_shell:-sh} # unknown or old shell=${_shell:-sh} # unknown or old if [ "$trs" != "" ]; then dispshell=`echo $trs | sed -e 's,.*/,,'` else dispshell=$shell fi ( eval 'echo ${.sh.version}' ) >/dev/null 2>&1 if [ $? -eq 0 ]; then eval 'KSH_VERSION=${.sh.version}' fi if [ "$KSH_VERSION" != "" ]; then shell=ksh baseshell=ksh shvers=$KSH_VERSION case $KSH_VERSION in *PD*) shell=pdksh ;; *93*) shell=ksh93 ;; *88*) shell=ksh88 ;; *MIRBSD*) shell=mksh ;; esac elif [ "$BASH_VERSION" != "" ]; then shvers=$BASH_VERSION ver=`echo $BASH_VERSION | sed 's/\..*//'` shell=bash${ver} baseshell=bash elif [ "$ZSH_VERSION" != "" ]; then shvers=$ZSH_VERSION shell=zsh baseshell=zsh elif [ "$POSH_VERSION" != "" ]; then shvers=$POSH_VERSION shell=posh baseshell=posh elif [ "$YASH_VERSION" != "" ]; then shvers=$YASH_VERSION shell=yash baseshell=yash elif [ "$OIL_VERSION" != "" ]; then shvers=$OIL_VERSION shell=osh baseshell=osh fi if [ $dispshell = sh -a $dispshell != $shell ]; then dispshell="$dispshell-$shell" elif [ $dispshell = $baseshell ]; then dispshell=$shell fi # can try --version, but don't really know the path # of the shell running us; can't depend on $SHELL. # and it only works for bash and some versions of ksh. if [ $gstecho = T ]; then echo $dispshell $shvers fi } doshelltest () { # force shell type. if [ "$_MKCONFIG_SHELL" != "" ]; then if [ "$SHELL" != "$_MKCONFIG_SHELL" ]; then SHELL="$_MKCONFIG_SHELL" export SHELL loc=`pwd` s=$1 shift exec $SHELL $dstscript $s -d $loc $@ fi fi getshelltype # for display of error below chkshell "" $shell if [ $? -ne 0 ]; then echo "The shell in use ($dispshell) does not have the correct functionality:" >&2 echo $chkmsg >&2 echo "Please try another shell. _MKCONFIG_SHELL can be set to the path of another shell to override /bin/sh." >&2 exit 1 fi testshcapability } locatecmd () { lvar=$1 ltcmd=$2 getpaths lcmd="" for p in $_pthlist; do if [ -x "$p/$ltcmd" ]; then lcmd="$p/$ltcmd" break fi done eval $lvar=$lcmd } mkverscomp () { v=$1 # put a 1 in front to avoid any octal constant issue. echo $v | $awkcmd -F. '{ printf("1%03d%03d%03d\n", $1,$2,$3); }' } # rc = 0 : same version # rc = 1 : smaller version # rc = 2 : greater version versioncompare () { v1=`mkverscomp $1` v2=`mkverscomp $2` rc=0 if [ $v1 -lt $v2 ]; then rc=1 fi if [ $v1 -gt $v2 ]; then rc=2 fi return $rc } # function to make sure the shell has # some basic capabilities w/o weirdness. chkshell () { doecho=F if [ "$1" = "echo" ]; then doecho=T fi shellpath=$2 grc=0 case $shellpath in *yash) # reject older versions of yash # I do not know in what version the quoting/backquoting issues # got fixed. locateawkcmd versioncompare $YASH_VERSION 2.48 rc=$? if [ $rc -eq 1 ]; then chkmsg="${chkmsg} older versions of yash are not supported" grc=1 fi ;; esac chkmsg="" # test to make sure the set command works properly # some shells output xyzzy=abc def # some shells output xyzzy='abc def' # some shells output xyzzy=$'abc def' (ok; handled in mkconfig.sh) # yash does this correctly, but had quoting/backquote issues in older versions. ( cmd='xyzzy="abc def"; val=`set | grep "^xyzzy"`; test "$val" = "xyzzy=abc def"' eval $cmd 2>/dev/null if [ $? -eq 0 ]; then exit 0 fi cmd="xyzzy=\"abc def\"; val=\`set | grep \"^xyzzy\"\`; test \"\$val\" = \"xyzzy='abc def'\" -o \"\$val\" = \"xyzzy=\\$'abc def'\"" eval $cmd 2>/dev/null rc=$? exit $rc ) rc=$? if [ $rc -ne 0 ]; then grc=$rc chkmsg="${chkmsg} 'set' output not x=a b or x='a b' or x=\$'a b'." fi # test to make sure the 'set -f' command is supported. ( cmd='set -f' eval $cmd 2>/dev/null rc=$? if [ $rc -eq 0 ]; then exit 0 fi exit $rc ) rc=$? if [ $rc -ne 0 ]; then grc=$rc chkmsg="${chkmsg} 'set -f' not supported" fi if [ $doecho = "T" ]; then echo $chkmsg fi return $grc } getpaths () { if [ "$_pthlist" != "" ]; then return fi systype=`uname -s` tpthlist=`echo $PATH | sed 's/:/ /g'` # cygwin's /bin and /usr/bin are both mounted on same spot case ${systype} in CYGWIN*) d=/bin tpthlist=`echo $tpthlist | sed -e "s,^$d ,," -e "s, $d,,"` ;; esac # remove symlinks for d in $tpthlist; do if [ ! -d $d ]; then tpthlist=`echo $tpthlist | sed -e "s,^$d ,," -e "s, $d,,"` else if [ -h $d ]; then tpthlist=`echo $tpthlist | sed -e "s,^$d ,," -e "s, $d,,"` # make sure path symlink is pointing to is in the list npath=`ls -ld $d | sed 's/.*-> //'` tpthlist="$tpthlist $npath" fi fi done # remove dups _pthlist="" for d in $tpthlist; do _pthlist="$_pthlist $d" done _pthlist=`echo $_pthlist | sort -u` } initifs () { hasifs=0 if [ "$IFS" != "" ]; then OIFS="$IFS" hasifs=1 fi } setifs () { # just newline for parsing include section IFS=" " } resetifs () { if [ $hasifs -eq 1 ]; then IFS="$OIFS" else unset IFS fi } boolclean () { nm=$1 dosubst $nm '(' ' ( ' ')' ' ) ' dosubst $nm ' not ' ' ! ' ' and ' ' -a ' ' or ' ' -o ' dosubst $nm '!' ' ! ' '&&' ' -a ' '||' ' -o ' dosubst $nm ' \+' ' ' '^ *' '' ' *$' '' } locateawkcmd () { locatecmd awkcmd awk locatecmd nawkcmd nawk locatecmd gawkcmd gawk locatecmd mawkcmd mawk if [ "$nawkcmd" != "" ]; then awkcmd=$nawkcmd fi if [ "$mawkcmd" != "" ]; then awkcmd=$mawkcmd fi if [ "$gawkcmd" != "" ]; then awkcmd=$gawkcmd fi } locatepkgconfigcmd () { locatecmd pkgconfigcmd pkg-config } di-4.52/mkconfig/bin/mkstaticlib.sh0000755000175000017500000000441514421556642015373 0ustar bllbll#!/bin/sh # # Copyright 2010-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # unset CDPATH # this is a workaround for ksh93 on solaris if [ "$1" = "-d" ]; then cd $2 shift shift fi . ${_MKCONFIG_DIR}/bin/shellfuncs.sh doshelltest $0 $@ libnm="" objects="" grc=0 doecho=F MKC_FILES=${MKC_FILES:-mkc_files} logfile=${MKC_FILES}/mkc_compile.log while test $# -gt 0; do case $1 in -e) shift doecho=T ;; --) shift ;; -log) shift logfile=$1 shift ;; -o) shift tf=$1 shift if [ "$libnm" = "" ]; then libnm=$tf continue fi ;; *${OBJ_EXT}) tf=$1 shift if [ ! -f "$tf" ]; then puts "## unable to locate $tf" grc=1 else doappend objects " $tf" fi ;; *) tf=$1 shift if [ "$libnm" = "" ]; then libnm=$tf continue fi ;; esac done if [ "$logfile" != "" ]; then exec 9>>$logfile puts "# `date`" >&9 fi locatecmd ranlibcmd ranlib locatecmd arcmd ar locatecmd lordercmd lorder locatecmd tsortcmd tsort if [ "$arcmd" = "" ]; then puts "## Unable to locate 'ar' command" grc=1 fi if [ $grc -eq 0 ]; then dosubst libnm '${SHLIB_EXT}$' '' libfnm=${libnm} # for really old systems... if [ "$ranlibcmd" = "" -a "$lordercmd" != "" -a "$tsortcmd" != "" ]; then objects=`$lordercmd ${objects} | $tsortcmd` fi test -f $libfnm && rm -f $libfnm cmd="$arcmd cq $libfnm ${objects}" putsnonl "CREATE ${libfnm} ..." if [ "$logfile" != "" ]; then puts "CREATE ${libfnm}" >&9 fi if [ $doecho = "T" ]; then puts "" puts $cmd fi if [ "$logfile" != "" ]; then out=`eval $cmd 2>&1` rc=$? puts "$out" >&9 if [ $doecho = T ]; then puts "$out" fi else eval $cmd rc=$? fi if [ $rc -ne 0 ]; then grc=$rc fi if [ "$ranlibcmd" != "" ]; then cmd="$ranlibcmd $libfnm" if [ $doecho = "T" ]; then puts $cmd fi if [ "$logfile" != "" ]; then eval $cmd >&9 rc=$? else eval $cmd rc=$? fi fi if [ $rc -ne 0 ]; then puts " fail" grc=$rc else puts " ok" fi fi if [ "$logfile" != "" ]; then exec 9>&- fi exit $grc di-4.52/mkconfig/bin/testfuncs.sh0000755000175000017500000000570214421556642015103 0ustar bllbll#!/bin/sh # # Copyright 2011-2018 Brad Lanam Walnut Creek, CA, USA # Copyright 2020 Brad Lanam Pleasant Hill CA # maindodisplay () { snm=$2 if [ "$1" = "-d" ]; then echo $snm exit 0 fi } maindoquery () { if [ "$1" = "-q" ]; then exit $2 fi } chkccompiler () { if [ "${CC}" = "" ]; then echo " no C compiler; skipped" >&5 exit 0 fi } chkdcompiler () { if [ "${DC}" = "" ]; then echo " no D compiler; skipped" >&5 exit 0 fi } getsname () { tsnm=$1 tsnm=`echo $tsnm | sed -e 's,.*/,,' -e 's,\.sh$,,'` scriptnm=${tsnm} } dosetup () { grc=0 stag="" if [ $# -eq 2 ];then stag=$1 shift fi script=$@ set -f } dorunmkc () { drmclear="-C" if [ "$1" = "-nc" ];then drmclear="" shift fi case ${script} in *mkconfig.sh) ${_MKCONFIG_SHELL} ${script} -d `pwd` \ ${drmclear} ${_MKCONFIG_RUNTESTDIR}/${scriptnm}.dat ;; *) perl ${script} ${drmclear} ${_MKCONFIG_RUNTESTDIR}/${scriptnm}.dat ;; esac if [ "$1" = "reqlibs" ]; then case $script in *mkconfig.sh) ${_MKCONFIG_SHELL} ${_MKCONFIG_RUNTOPDIR}/mkc.sh -d `pwd` -reqlib $2 ;; esac fi } chkccompile () { fn=$1 ${CC} -c ${CFLAGS} ${fn} if [ $? -ne 0 ]; then echo "## compile of ${fn} failed" grc=1 fi } chkouthcompile () { if [ $grc -eq 0 ]; then > testouth.c echo ' #include #include int main () { return 0; } ' chkccompile testouth.c fi } chkdcompile () { fn=$1 bfn=$fn bfn=`echo $fn | sed 's/\.d$//'` cmd="${_MKCONFIG_DIR}/mkc.sh -d `pwd` -complink -e -c ${DC} \ -o ${bfn}${OBJ_EXT} -- ${DFLAGS} ${fn} " eval ${cmd} if [ $? -ne 0 ]; then echo "## compile of ${fn} failed" grc=1 fi } chkdiff () { f1=$1 f2=$2 echo "## diff of $f1 $f2" diff -b $f1 $f2 rc=$? if [ $rc -ne 0 ]; then echo "## diff of $f1 $f2 failed" grc=$rc; fi } chkgrep () { pat=$1 fn=$2 arg=$3 arg2=$4 echo "chkgrep: pwd: `pwd`" echo "chkgrep: fn: $fn" if [ "$arg" = "wc" ]; then tl=`egrep -l "$pat" ${fn} 2>/dev/null | wc -l` rc=$? if [ ${tl} -ne ${arg2} ]; then grc=1 fi else egrep -l "$pat" ${fn} >/dev/null 2>&1 rc=$? fi if [ "$arg" = "" -a $rc -ne 0 ]; then grc=$rc echo "## ${fn}: grep for '$pat' failed" fi if [ "$arg" = "neg" -a $rc -eq 0 ]; then grc=$rc echo "## ${fn}: grep for '$pat' succeeded when it should not" fi } chkouth () { xp=$1 shift chkgrep "$xp" out.h $@ } chkoutd () { xp=$1 shift chkgrep "$xp" out.d $@ } chkcache () { xp=$1 shift chkgrep "$xp" ${MKC_FILES}/mkconfig.cache $@ } chkenv () { xp=$1 shift chkgrep "$xp" test.env $@ } testcleanup () { if [ "$stag" != "none" ]; then for x in out.h out.d testouth.c opts test.env c.env \ mkc_files \ $@; do # test -e is not supported by older shells. test -f ${x} && mv ${x} ${x}${stag} test -d ${x} && mv ${x} ${x}${stag} done fi } di-4.52/mkconfig/bin/mkreqlib.sh0000755000175000017500000000416714421556642014677 0ustar bllbll#!/bin/sh # # Copyright 2009-2018 Brad Lanam Walnut Creek, CA USA # Copyright 2020 Brad Lanam Pleasant Hill CA # set -f unset CDPATH # this is a workaround for ksh93 on solaris if [ "$1" = "-d" ]; then cd $2 shift shift fi . ${_MKCONFIG_DIR}/bin/shellfuncs.sh doshelltest $0 $@ RUNTOPDIR=`pwd` MKC_FILES=${MKC_FILES:-mkc_files} CACHEFILE="${MKC_FILES}/mkconfig.cache" unset GREP_OPTIONS unset ENV getlibdata () { var=$1 gdname=$2 lang=$3 cmd="${var}=\${mkc_${lang}_lib_${gdname}}" eval $cmd } mkconfigversion debug=F OUTLIBFILE="${MKC_FILES}/mkconfig.reqlibs" while test $# -gt 1; do case $1 in -X) shift debug=T ;; -c) shift CACHEFILE=$1 shift ;; -o|-l) # -l backwards compatibility shift OUTLIBFILE=$1 shift ;; esac done CONFH=$1 ok=1 if [ ! -f "${CONFH}" ]; then echo "Unable to locate ${CONFH}" ok=0 fi if [ ! -f "$RUNTOPDIR/$CACHEFILE" ]; then echo "Unable to locate $RUNTOPDIR/$CACHEFILE" ok=0 fi if [ $ok -eq 0 ]; then exit 1 fi reqlibs="" . $RUNTOPDIR/$CACHEFILE exec 7<&0 < ${CONFH} dver=0 while read cline; do if [ $debug = T ]; then echo "cline:$cline:" fi case $cline in "#define _lib_"*1) lang=c ;; "enum bool _clib_"*" = true;") lang=d dver=2 ;; "enum bool _lib_"*" = true;") lang=d dver=2 ;; "enum : bool { _clib_"*" = true };") lang=d dver=1 ;; "enum : bool { _lib_"*" = true };") lang=d dver=1 ;; *) continue ;; esac # bash2 can't handle # in subst if [ $lang = "d" -a $dver -eq 1 ]; then dosubst cline ': ' '' '{ ' '' ' }' '' fi dosubst cline '#define ' '' ' 1' '' ' = true;' '' 'enum bool ' '' getlibdata var $cline $lang if [ $debug = T ]; then echo "cline:$cline:lang:$lang:var:$var:" fi if [ "$var" != "" ]; then echo $reqlibs | grep -- $var > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ]; then doappend reqlibs " $var" if [ $debug = T ]; then echo "append:$var" fi fi fi done exec <&7 7<&- echo $reqlibs > $OUTLIBFILE di-4.52/mkconfig/Makefile.inc0000644000175000017500000000340014421556642014157 0ustar bllbll# included by MKC_FILES = mkc_files MKC_FILET = $(MKC_FILES)/$(MKC_PREFIX).t MKC_REQLIB = $(MKC_FILES)/$(MKC_PREFIX).reqlibs MKC_DEPFILE = $(MKC_FILES)/$(MKC_PREFIX).depends MKC_ENVFILE = $(MKC_PREFIX).env MKC_CONFDIR = . MKC_CONF = $(MKC_CONFDIR)/$(MKC_PREFIX).mkc MKC_ENV_CONF = $(MKC_CONFDIR)/$(MKC_PREFIX)-env.mkc # executable $(MKC_PREFIX)$(EXE_EXT): $(MKC_DEPFILE) $(MKC_REQLIB) $(objects) @CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh \ -link -exec -r $(MKC_REQLIB) \ -o $(MKC_PREFIX)$(EXE_EXT) $(objects) # required libraries $(MKC_REQLIB): $(MKC_FILET) $(MKC_OUTPUT) @CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh \ -reqlib -o $(MKC_REQLIB) $(MKC_OUTPUT) # dependencies $(MKC_DEPFILE): $(MKC_FILET) $(MKC_OUTPUT) $(sources) $(CC) -E -MM $(sources) > $(MKC_DEPFILE) sed -e '/# DO NOT DELETE/,$$ d' Makefile > Makefile.bak (cat Makefile.bak;echo "# DO NOT DELETE";cat $(MKC_DEPFILE)) > Makefile @rm -f Makefile.bak # output configuration file $(MKC_OUTPUT): $(MKC_FILET) $(MKC_ENVFILE) $(MKC_CONF) @CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh $(MKC_CONF) # object files .c$(OBJ_EXT): @CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -compile $< # environment variables $(MKC_ENVFILE): $(MKC_FILET) $(MKC_ENV_CONF) @CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh $(MKC_ENV_CONF) $(MKC_FILET): @test -d $(MKC_FILES) || mkdir $(MKC_FILES) @touch $(MKC_FILET) .PHONY: mkc-clean mkc-clean: -rm -f $(objects) \ $(MKC_PREFIX)$(EXE_EXT) \ > /dev/null 2>&1; exit 0 .PHONY: mkc-distclean mkc-distclean: $(MKC_FILET) -$(MAKE) mkc-clean > /dev/null 2>&1 -rm -rf mkc_* mkconfig.cache mkconfig.log \ $(MKC_FILES) $(MKC_OUTPUT) $(MKC_ENVFILE) \ _tmp_mkconfig _mkconfig_runtests \ > /dev/null 2>&1; exit 0 di-4.52/mkconfig/runtests.sh0000755000175000017500000002772214421556642014212 0ustar bllbll#!/bin/sh # # Copyright 1994-2018 Brad Lanam, Walnut Creek, CA # Copyright 2020 Brad Lanam Pleasant Hill CA # # # speed at the cost of maintainability... # File Descriptors: # 9 - $TSTRUNLOG # 8 - $MAINLOG # 7 - $TMPORDER # 5 - stdout (as 1 is directed to the log) # set -f # global DOPERL=T TESTORDER=test_order SUBDIR=F # this is a workaround for ksh93 on solaris if [ "$1" = -d ]; then cd $2 shift shift fi unset CDPATH if [ "$1" = -s ]; then SUBDIR=T shift CC="$1" DC="$2" shelllist="$3" _pthlist="$4" TMPOUT="$5" shift; shift; shift; shift; shift fi if [ $# -lt 1 ]; then echo "Usage: $0 [ ...]" exit 1 fi unset GREP_OPTIONS unset ENV unalias sed > /dev/null 2>&1 unalias grep > /dev/null 2>&1 unalias ls > /dev/null 2>&1 unalias rm > /dev/null 2>&1 LC_ALL=C export LC_ALL # this is used for regression testing. getlistofshells () { getpaths echo "## PATH: $PATH" >&8 echo "## paths: $_pthlist" >&8 tshelllist="" inodelist="" for d in $_pthlist; do for s in $tryshell ; do rs=$d/$s if [ -x $rs ]; then while [ -h $rs -a $s != osh ]; do ors=$rs rs="`ls -l $rs | sed 's/.* //'`" case $rs in /*) ;; *) rs="$d/$rs" ;; esac # /etc/alternatives/xxx has some weird names w/dots. # all ksh* are ksh # anything not ksh/bash/zsh/osh is sh # if the name is sh->bash or sh->ksh; don't follow symlink. ts=`echo $rs | sed -e 's,.*[/\.],,' \ -e 's/ksh88/ksh/' -e 's/ksh93/ksh/' ` tts=`echo $s | sed -e 's/ksh88/ksh/' -e 's/ksh93/ksh/' ` if [ $ts != ksh -a $ts != bash -a $ts != zsh ]; then ts=sh fi if [ $ts != ksh -a $tts != bash -a $tts != zsh ]; then tts=sh fi if [ $ts != $tts ]; then rs=$ors break fi rs=`echo $rs | sed 's,/[^/]*/\.\./,/,'` rs=`echo $rs | sed 's,/[^/]*/\.\./,/,'` rs=`echo $rs | sed 's,/[^/]*/\.\./,/,'` rs=`echo $rs | sed 's,/[^/]*/\.\./,/,'` done inode=`ls -i ${rs} | sed -e 's/^ *//' -e 's/ .*//'` inode=${inode}${s} # append shell type also found=F for i in $inodelist; do if [ "$inode" = "${i}" ]; then found=T break fi done if [ $found = T ]; then continue fi if [ -x $rs ]; then cmd="$rs -c \". $_MKCONFIG_DIR/bin/shellfuncs.sh;getshelltype $rs echo\"" set `eval $cmd` dispshell=$1 echo " found: $rs ($dispshell)" >&8 case $dispshell in *) tshelllist="${tshelllist} $rs" if [ "${inode}" != ${s} ]; then inodelist="${inodelist} ${inode}" fi ;; esac fi # if executable fi # if there is a file done done tshelllist=`echo "$tshelllist" | sort -u` systype=`uname -s` shelllist="" for s in $tshelllist; do putsnonl " check $s" >&8 putsnonl " $s" cmd="$s -c \". $_MKCONFIG_DIR/bin/shellfuncs.sh;chkshell echo $s\"" eval $cmd >&8 2>&1 rc=$? cmd="$s -c \". $_MKCONFIG_DIR/bin/shellfuncs.sh;getshelltype $s echo\"" set `eval $cmd` dispshell=$1 shift shvers=$@ if [ $rc -eq 0 ]; then echo " ok" >&8 shelllist="${shelllist} $s" echo " [$dispshell $shvers] (ok)" else echo " ng" >&8 echo " : $chkmsg" >&8 echo " [$dispshell $shvers] (ng)" fi done } runshelltest () { stag="" if [ "$_MKCONFIG_SHELL" != "" ]; then stag=".${scount}_${dispshell}" fi TSTRUNLOG=${_MKCONFIG_TSTRUNTMPDIR}/${tbase}.log${stag} > $TSTRUNLOG exec 9>>$TSTRUNLOG echo "####" >&9 echo "# Test: $tbase $arg" >&9 if [ "$_MKCONFIG_SHELL" != "" ]; then echo "## testing with ${_MKCONFIG_SHELL} " >&9 fi echo "# $dt" >&9 echo "####" >&9 cd $_MKCONFIG_TSTRUNTMPDIR if [ "$_MKCONFIG_SHELL" != "" ]; then putsnonl " ${dispshell}" fi targ=$arg if [ "$arg" != "" ]; then targ="$_MKCONFIG_DIR/$arg" fi # dup stdout to 5; redirect stdout to 9; redirect stderr to new 1. ${_MKCONFIG_SHELL} $_MKCONFIG_RUNTESTDIR/$tf "$stag" $targ 5>&1 >&9 2>&1 rc=$? cd $_MKCONFIG_RUNTESTDIR dt=`date` echo "####" >&9 echo "# $dt" >&9 echo "# exit $rc" >&9 echo "####" >&9 exec 9>&- if [ $rc -ne 0 -a "$_MKCONFIG_SHELL" != "" ]; then putsnonl "*" fi return $rc } # # main # _MKCONFIG_RUNTOPDIR=`pwd` export _MKCONFIG_RUNTOPDIR mypath=`echo $0 | sed -e 's,/[^/]*$,,' -e 's,^\.,./.,'` if [ "$mypath" = runtests.sh ]; then mypath=. fi _MKCONFIG_DIR=`(cd $mypath;pwd)` export _MKCONFIG_DIR . ${_MKCONFIG_DIR}/bin/shellfuncs.sh _MKC_ONCE=0 export _MKC_ONCE _MKC_SH=1 export _MKC_SH _MKC_PL=2 export _MKC_PL _MKC_SH_PL=3 export _MKC_SH_PL doshelltest $0 $@ if [ $SUBDIR = F ]; then mkconfigversion fi testdir=$1 if [ ! -d $testdir ]; then echo "## Unable to locate $testdir" exit 1 fi shift teststorun=$* cd $testdir if [ $? != 0 ]; then echo "## Unable to cd to $testdir" exit 1 fi _MKCONFIG_RUNTESTDIR=`pwd` export _MKCONFIG_RUNTESTDIR MKC_FILES=${MKC_FILES:-mkc_files} export MKC_FILES if [ $SUBDIR = F ]; then _MKCONFIG_RUNTMPDIR=$_MKCONFIG_RUNTOPDIR/${MKC_FILES}/_mkconfig_runtests export _MKCONFIG_RUNTMPDIR CC=${CC:-cc} export CC DC=${DC:-gdc} export DC else btestdir=`echo $testdir | sed 's,.*/,,'` _MKCONFIG_RUNTMPDIR=$_MKCONFIG_RUNTOPDIR/${MKC_FILES}/_mkconfig_runtests/$btestdir export _MKCONFIG_RUNTMPDIR fi d=`dirname $_MKCONFIG_RUNTMPDIR` test -d $d || mkdir -p $d TMPORDER=test_order.tmp > $TMPORDER if [ "$teststorun" = "" ]; then if [ ! -f "$TESTORDER" ]; then ls -1d *.d *.sh 2>/dev/null | sed -e 's/\.sh$//' -e 's/^/1/' >> $TMPORDER else sort -n $TESTORDER >> $TMPORDER fi else for t in $teststorun; do echo "1 $t" done >> $TMPORDER fi if [ $SUBDIR = F ]; then test -d $_MKCONFIG_RUNTMPDIR && rm -rf "$_MKCONFIG_RUNTMPDIR" fi test -d $_MKCONFIG_RUNTMPDIR || mkdir $_MKCONFIG_RUNTMPDIR MAINLOG=${_MKCONFIG_RUNTMPDIR}/main.log if [ $SUBDIR = F ]; then > $MAINLOG fi exec 8>>$MAINLOG if [ $SUBDIR = F ]; then echo "## locating valid shells" getlistofshells fi locateawkcmd echo "awk: $awkcmd" >&8 locatepkgconfigcmd echo "pkg-config: $pkgconfigcmd" >&8 export shelllist grc=0 count=0 fcount=0 fpass=0 lastpass="" # save stdin in fd 7 exec 7<&0 < ${TMPORDER} while read tline; do set $tline pass=$1 tbase=$2 if [ "$lastpass" = "" ]; then lastpass=$pass fi if [ $grc -ne 0 -a "$lastpass" != "$pass" ]; then if [ $SUBDIR = F ]; then echo "## stopping tests due to failures in $testdir/ pass $lastpass" else fpass=$lastpass fi echo "## stopping tests due to failures in $testdir/ pass $lastpass" >&8 break fi if [ -d "$tbase" ]; then ocwd=`pwd` cd $_MKCONFIG_DIR TMPOUT=${_MKCONFIG_RUNTMPDIR}/${tbase}.out ${_MKCONFIG_SHELL} ./runtests.sh -s "$CC" "$DC" "$shelllist" "$_pthlist" $TMPOUT $testdir/$tbase retvals=`tail -1 $TMPOUT` rm -f $TMPOUT > /dev/null 2>&1 set $retvals retcount=$1 retfcount=$2 retfpass=$3 domath count "$count + $retcount" domath fcount "$fcount + $retfcount" rc=$retfcount if [ $rc -ne 0 ]; then grc=$rc echo "## stopping tests due to failures in $testdir/$tbase/ pass $retfpass (pass $lastpass) " echo "## stopping tests due to failures in $testdir/$tbase/ pass $retfpass (pass $lastpass)" >&8 break fi cd $ocwd continue fi tprefix=`echo $tbase | sed 's/-.*//'` if [ "${CC}" = "" -a "$tprefix" = c ]; then continue fi if [ "${DC}" = "" -a "$tprefix" = d ]; then continue fi tf="${tbase}.sh" tconfig="${tbase}.config" tconfh="${tbase}.ctmp" ok=T if [ ! -f ./$tf ]; then echo "$tbase ... missing ... failed" echo "$tbase ... missing ... failed" >&8 ok=F elif [ ! -x ./$tf ]; then echo "$tbase ... permission denied ... failed" echo "$tbase ... permission denied ... failed" >&8 ok=F fi if [ $ok = F ]; then domath fcount "$fcount + 1" domath count "$count + 1" continue fi dt=`date` arg="mkconfig.sh" scount="" putsnonl "$tbase ..." putsnonl "$tbase ..." >&8 _MKCONFIG_TSTRUNTMPDIR=$_MKCONFIG_RUNTMPDIR/${tbase} export _MKCONFIG_TSTRUNTMPDIR mkdir ${_MKCONFIG_TSTRUNTMPDIR} if [ -f $tconfig ]; then cp $tconfig $_MKCONFIG_TSTRUNTMPDIR/$tconfh fi tfdisp=`$_MKCONFIG_RUNTESTDIR/$tf -d` putsnonl " ${tfdisp}" putsnonl " ${tfdisp}" >&8 $_MKCONFIG_RUNTESTDIR/$tf -q runshpl=$? if [ $runshpl -eq $_MKC_SH -o $runshpl -eq $_MKC_SH_PL ]; then putsnonl " ..." putsnonl " ..." >&8 src=0 scount=1 for s in $shelllist; do unset _shell unset dispshell cmd="$s -c \". $_MKCONFIG_DIR/bin/shellfuncs.sh;getshelltype $s echo\"" set `eval $cmd` dispshell=$1 _MKCONFIG_SHELL=$s export _MKCONFIG_SHELL runshelltest rc=$? if [ $rc -ne 0 ]; then src=$rc; fi domath scount "$scount + 1" unset _shell unset dispshell unset _MKCONFIG_SHELL done else runshelltest src=$? fi if [ $src -eq 166 ]; then echo " ... skipped" echo " skipped" >&8 elif [ $src -ne 0 ]; then src=1 grc=1 if [ $tbase = c-compiler -a $grc -ne 0 ]; then CC="" grc=0 fi if [ $tbase = d-compiler -a $grc -ne 0 ]; then DC="" grc=0 fi if [ $grc -eq 0 ]; then echo " ... skipping $tprefix compiler tests" echo " skipping $tprefix compiler tests" >&8 else echo " ... failed" echo " failed" >&8 domath fcount "$fcount + 1" fi else echo " ... success" echo " success" >&8 fi domath count "$count + 1" if [ $src -eq 0 -a "$MKC_CLEAN_RUN_TMP" = Y ]; then test -d "$_MKCONFIG_TSTRUNTMPDIR" && rm -rf "$_MKCONFIG_TSTRUNTMPDIR" fi # for some reason, unixware can't handle this if it is split into # multiple lines. if [ "$DOPERL" = T -a \( $runshpl -eq $_MKC_PL -o $runshpl -eq $_MKC_SH_PL \) ]; then _MKCONFIG_TSTRUNTMPDIR=$_MKCONFIG_RUNTMPDIR/${tbase}_pl export _MKCONFIG_TSTRUNTMPDIR mkdir ${_MKCONFIG_TSTRUNTMPDIR} TSTRUNLOG=$_MKCONFIG_TSTRUNTMPDIR/${tbase}.log > $TSTRUNLOG exec 9>>$TSTRUNLOG dt=`date` echo "####" >&9 echo "# Test: $tf mkconfig.pl" >&9 echo "# $dt" >&9 echo "####" >&9 putsnonl "$tbase ..." putsnonl "$tbase ..." >&8 putsnonl " ${tfdisp}" putsnonl " ${tfdisp}" >&8 putsnonl " ... perl" putsnonl " ... perl" >&8 echo "## Using mkconfig.pl " >&9 if [ -f $tconfig ]; then cp $tconfig $_MKCONFIG_TSTRUNTMPDIR/$tconfh fi cd $_MKCONFIG_TSTRUNTMPDIR # dup stdout to 5; redirect stdout to 9; redirect stderr to new 1. $_MKCONFIG_RUNTESTDIR/$tf none $_MKCONFIG_DIR/mkconfig.pl 5>&1 >&9 2>&1 rc=$? cd $_MKCONFIG_RUNTESTDIR dt=`date` echo "####" >&9 echo "# $dt" >&9 echo "# exit $rc" >&9 echo "####" >&9 exec 9>&- if [ $rc -ne 0 ]; then echo " ... failed" echo " failed" >&8 domath fcount "$fcount + 1" grc=1 else echo " ... success" echo " success" >&8 fi domath count "$count + 1" if [ $rc -eq 0 -a "$MKC_CLEAN_RUN_TMP" = Y ]; then test -d "$_MKCONFIG_TSTRUNTMPDIR" && rm -rf "$_MKCONFIG_TSTRUNTMPDIR" fi fi lastpass=$pass done # set std to saved fd 7; close 7 exec <&7 7<&- test -f $TMPORDER && rm -f $TMPORDER if [ $count -eq 0 ]; then # this can't be right... $fcount = -1 fi exec 8>&- if [ $SUBDIR = F ]; then echo "$count tests $fcount failures" if [ $fcount -eq 0 ]; then if [ "$MKC_KEEP_RUN_TMP" = "" ]; then ( cd $_MKCONFIG_RUNTMPDIR/../.. test -d "$_MKCONFIG_RUNTMPDIR" && rm -rf "$_MKCONFIG_RUNTMPDIR" test -d "${MKC_FILES}" && rmdir "${MKC_FILES}" > /dev/null 2>&1 ) fi fi else echo "$count $fcount $fpass" > $TMPOUT fi exit $fcount di-4.52/mkconfig/ChangeLog0000644000175000017500000003505114421556642013530 0ustar bllbllCHANGES 2.6.3 2021-1-30 Fix 'pkg libs' directive. 2.6.2 2021-1-30 Add 'pkg include' directive. Update documentation. 2.6.1 2020-9-25 Fix PKG_CONFIG_PATH handling. 2.6 2020-9-25 Add support for pkg-config --cflags and pkg-config --libs 2.5 2020-7 Rework domath function so that it can be used with osh. 2.4 2020-6-13 Added 'standard_cc' (env-cc), 'standard_system' (env-system) commands. Fixed 'defined', 'size' directives so that they will work with a cross-compile (MKC_CROSS=Y must be defined). Added examples/helloworld. Added Makefile.inc for simple builds. Made easier to use. Move most work files to a sub-directory. Fixed AIX shared library linking (xlc and gcc). Fixed HP-UX shared library linking. Fixed OSF1 (Tru64) shared library linking (cc and gcc). Fixed Msys2 and Cygwin shared library linking (clang). Tested on 23 platforms. 2.3 [2020-6-3] Fixed an issue propogating LDFLAGS_SHARED. Fix library check when using g++. Propogate CFLAGS_OPTIMIZE and CFLAGS_DEBUG properly to linker. Added bin/capabilities.sh script. Added yash to the supported scripts list (version 2.48 or later; I don't know when its issues were fixed). 2.2 [2020-5-22] Added support for oilshell (osh; oilshell.org). mkcl.sh will display its messages as a single printf so that make -j does not look really weird. 2.1.1 [2019-6-25] env-cc: Fix getconf/cflags_system. Fix putsnonl function when 'echo' is in use. 2.1.0 [2018-12-27] Add test for shell interpolation bug. Use printf if possible for POSIX compliance. env-cc: Fix cflags_shared. env-cc: Pick up all cflags* and ldflags* defaults from the environment. mkcl.sh: Fix processing of LDFLAGS. mkcl.sh: Support .m extension. mkcl.sh: Support command line set of env vars (must be quoted). env-cc: Add support for DragonFlyBSD. env-cc: Add support for pkgconfig files (findpc). 2.0.0 [2018-8-12] C: split CFLAGS, LDFLAGS, LIBS into multiple environment variables for easier processing. D language is probably broken. C: fix shared flags C: Various bug fixes for msys2, tru64, etc. Clean up interfaces to mkcl.sh, mkstaticlib.sh Clean output style for mkc.sh. Added compilation log file. Added 'findconfig' and 'addconfig' commands for *Config.sh files. Removed 'findincludefile' command. Remove mksharedlib.sh (now part of mkcl.sh). 1.31 [2018-4-11] env-cc: update findincludepath to search more common paths. Remove Makefile and MANIFEST from standard distribution. 1.30 [2018-4-10] Repo got completely mucked up. Restore lost code. C: size: -lintl option for modern libintl.h C: printf_long_double : -lintl option for modern libintl.h Minor code cleanup. Update copyrights. 1.29 [2018-4-6] Changed .tar.gz creation to not include tests. 1.28 [2016-8-9] Cleaned up some compiler warnings. More fixes for msys/mingw. 1.27 [2016-2-22] Protected standard definitions from multiple inclusion. Fixed ifoption/ifnotoption. Removed 'lib' prefix when creating libraries. Removed LDFLAGS when creating shared libraries. Fixes to run under msys. Added printf_long_double test (for mingw). Fix cache bug with values ending in '='. Fixed args test on mac os x. Fixed args test for cygwin. 1.26 [2016-1-6] Added yes/no as possible option values. Options can be overridden by environment variables. 1.25 [2015-10-18] Fix 'using_gnu_ld' environment test. Add 'addldflag' to env-cc. 1.24 [2014-2-15] Updates for MirOS and Irix. Added -Wno-disabled-macro-expansion for clang. 1.23 [19 Jan 2013] Added the 'using_clang' environment directive. Added default flags for the clang compiler. 1.22 [15 Nov 2012] Fixed the display of the define directive. Fixed issues where the cache should not be used for XDR types and library function arguments. Fixed processing of nested if statements. 1.21 [18 Oct 2012] Added examples directory. clang: add -Wno-unknown-warning-option addcflag directive updated to not add the flag if the compiler has a warning. Fixed read problems with ksh93 93u+. Added a work-around for cd problem w/debian ksh93 93u+ (bug #679966). Handle __restrict__ on NetBSD 6. Remove improper link flags for AIX. Not tested. 1.20 [25 Jan 2012] D: rewrite c-typedef extraction. D: handle situations where structure is typedef'd and a ctypedef directive is issued. D: several fixes for C structure extraction. D: improved nested structure handling. D: basic handling for bitfields in structures. D: changed prefix from C_TYP_ to C_NATIVE_ for native c types. D: Added the noprefix directive to not add C_ST_, C_TYP_, etc. prefixes to the original C language types (but not C_NATIVE_). D: Casts are converted. May still be some issues. env: Added the source directive. D: fixed macro extraction with partial name. D: convert the version keyword to version_ D: handle multi-line statements better. D: added the module directive. D: added the substitute directive. Minor speed improvements for header extraction. D: fixed multiple output files. mkc.sh: -comp: fixed to add -c flag when compiling to object w/-o flag. mkc.sh: merge -link and -comp. D: fixed some D1 conversion issues. Fixed if statements with unknown variables. D: wrap ctypes in extern D: fixed type conversions (followed by asterisk, lone unsigned) 1.19 [20 Nov 2011] Created mkc.sh as a single entry point for compiling, linking, creating libraries, setting options and finding required libraries. Solaris 2.6 /bin/sh is no longer excluded. Fixed problem with .vars file not being cleaned on remake. D: Rework c-structure extraction. D: Better handling of nested structures and typedef'd structures. D: Add aliases for c argument types. D: revert cache check where it shouldn't be cached. D: Add aliases for c basic types (csizes directive). Fixed mkreqlib.sh to handle clibs for D. Fixed c-declaration test for freebsd. Change support for tango library and Dv1. Changed env-dc to compile to get D version. Changed env-cc and env-dc to pick up standard env variables from the options file. This allows the options file to keep all configuration data. Rearranged directory structure. 1.18 [8 Oct 2011] D: C structures are wrapped in extern (C) {} (to properly declare functions). Fixed multiple output files in the same directory. Fixed multiple inclusion tag for C output file. Fixed and updated shell locater for runtests.sh. Removed -std1 for OSF1 (Tru64). Added 'ksh88', 'ksh93' as valid shell names. 1.17 [30 Sep 2011] Fixed cmacro directive for D. Added cmembertype, cmemberxdr for D. Added memberxdr for C. Removed rquota_xdr, gqa_uid_xdr. Improved documentation. Rewrote test suite. Fixed 'lib' for D. Updated env-cc.sh for SCO OpenServer and UnixWare. Fixed structure extraction for HP-UX. Various fixes for HP-UX, SCO OpenServer, UnixWare. * Shared lib tests fail for HP-UX ansi cc. 1.16 [16 Sep 2011] Removed 'di' leftovers. Changed internal prefix to 'mkc'. Added 'echo' and 'exit' directives. Fixed d language tests to be 32/64 bit safe. Fixed d language tests for d version 1. Fixed d language tests for tango library. Added initial support for ldc and tango libraries. * On 64-bit, ldc's unions don't match C language sizes. * ldc1 doesn't have alias for 'string'. * ldc2 tested w/-d flag. Tested with dmd1, dmd2, ldc1, ldc2 on 64-bit. Tested with dmd1, dmd2, ldc1, ldc2, gdc1, gdc2 on 32-bit. 1.15 [11 Sep 2011] Added pdksh in as a valid shell Added 'args' directive (C) Removed statfs, setmntent, quotactl, getfsstat_type (breaks backwards compatibility) Added 'addcflags' directive (env) Fixed args directive to return valid types (C) Fixed cdcl directive to return valid types (D) Updated args directive to save return type (C) Updated cdcl directive to save return type (D) Fixed shell validity tests. 1.14 [22 May 2011] Renamed ctypeconv to ctype (breaks backwards compatibility). Rewrite ctype check command to use the C typedef name, and add an alias. Fixed ctype to handle unsigned typedefs correctly. Fixed nested structure handling. ctypedef will now find function pointer typedefs. Made D-C prefixes more consistent (breaks backwards compatibility). Added cmacro to convert C macros to functions. Merged cdefint and cdefstr to cdefine; made more generic (breaks backwards compatibility). Added breakdown of arg types for "cdcl args ...". 1.13 [27 Feb 2011] Handle gcc __asm__ function renames. Update doc for cdcl. 1.12 [16 Feb 2011] Added d-ctypeconv check command. Renamed d-ctype to d-ctypedef. Updated to work with D1. More fixes for D, D-C checks. 1.11 [29 Dec 2010] Fixed output of "yes with" libraries. Rearranged tests and test directories. Fixed test subdirectory handling. Added c-rquota, c-getfsstat. Added unset CDPATH. The output from the cd command broke the scripts. Added D language (not yet complete). Backwards compatibility broken for mklink.sh. 1.10 [22 Jul 2010] Renamed reqlibs.txt to mkconfig.reqlibs. Breaks backwards compatibility. Added support for multiple output files. Fixed naming of runtest log files. Added mkstaticlib.sh. Added mksharedlib.sh: preliminary support for shared libs. Added mklink.sh: preliminary Added new env-cc vars to support shared libs. Added new env-extension vars to support shared libs. Bug fix: workaround for ksh93 unable to getcwd() on Solaris. Fixed env-extension to match manual page. 1.9 [12 Jul 2010] Fixed regression tests to work w/c++. Code cleanup. 1.8 [10 Jul 2010] Internal code cleanup. Modify tests to take -d parameter for description output. Stop tests on change of pass number on failure. Add check_option. Fixed member test so either structs or typedefs can be used. Changed member test names to be _mem_struct_s_member or _mem_sometype_member. Breaks backwards compatibility. 1.7 [5 Jul 2010] Add labels to if statement. if statement counter and display. 1.6 [4 Jul 2010] Fix getlistofshells() when absolute path. Added c-quotactl unit. Renamed c-include-time to c-include-conflict, and changed how c-include-conflict works. Added define, set, setint, setstr, ifoption, ifnotoption, if. Added option-file. Added mkcsetopt.sh 1.5 [13 May 2010 - separate release] Change tmp directory structure and where logs go. Fixes for mkconfig.pl to handle absolute paths. Remove /bin from path for cygwin (duplicate of /usr/bin). Code cleanup. 1.4 (di ver 4.23) [10 May 2010] Move -lsun, -lseq out of env-cc.sh Update env-cc.sh to handle QNX getconf 'undefined' output. Fix cache test (tests.d/cache.sh). Fix edit when /bin is symlink (shellfuncs.sh). Added test for -n support for shells. Added support to mkconfig.sh to munge set output that has $s in it. Export shelllist in runtests.sh; more efficient. Redo paths in shellfuncs; make sure symlinked paths are present. Needed for Tru64, do: export BIN_SH=svr4 beforehand. 1.3 (di ver 4.22) [1 may 2010] Use the configuration file and cache to determine the necessary libraries to link in rather than linking in all found. Change library format to allow better control of link tests. Change dosubst() to always use sed. It's more reliable. 1.2 (di ver 4.20, 4.21) [12 mar 2010] Rewrite mkconfig.sh to use unit scripts and increase performance. Add environment units. Allow _MKCONFIG_SHELL to override shell. 1.1 (di ver 4.19) [1 Feb 2010] Changed format of config.h file. Fixed a quoting bug in mkconfig.sh. mkconfig enhancements and cleanup. 1.0 (di ver 4.18) [29 Nov 2009] Initial coding di-4.52/di.spec0000755000175000017500000000311514421556642011430 0ustar bllbllName: di Version: 4.51.1 Release: 1%{?dist} Summary: 'di' is a disk information utility, displaying everything (and more) that your 'df' command does. Group: System Environment/Base License: zlib/libpng URL: https://diskinfo-di.sourceforge.io/ Source0: https://sourceforge.net/projects/diskinfo-di/files/di-%{version}.tar.gz/download Source1: http://www.fossies.org/unix/misc/di-%{version}.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) # Build requires: cat cp grep ln msgfmt mv rm sed sort test uname tr wc #BuildRequires: #Requires: %description 'di' is a disk information utility, displaying everything (and more) that your 'df' command does. It features the ability to display your disk usage in whatever format you prefer. It also checks the user and group quotas, so that the user sees the space available for their use, not the system wide disk space. It is designed to be portable across many platforms and is great for heterogenous networks. %prep %setup -q %build make PREFIX=/usr LOCALEDIR=/usr/share/locale %install test -d $RPM_BUILD_ROOT || mkdir $RPM_BUILD_ROOT test -d $RPM_BUILD_ROOT/usr || mkdir $RPM_BUILD_ROOT/usr make DESTDIR=$RPM_BUILD_ROOT install %clean rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root,-) %doc README.txt LICENSE MANIFEST /usr/bin/di /usr/bin/mi /usr/share/locale/de/LC_MESSAGES/di.mo /usr/share/locale/en/LC_MESSAGES/di.mo /usr/share/locale/es/LC_MESSAGES/di.mo /usr/share/man/man1/di.1.gz # For Mandriva 2011, change di.1.gz to di.1.xv %changelog di-4.52/LICENSE0000644000175000017500000000165414421556642011170 0ustar bllbll Copyright 1994-2021 Brad Lanam, Walnut Creek, CA, USA Copyright 2023 Brad Lanam Pleasant Hill CA, USA This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. di-4.52/D/0000755000175000017500000000000014421556642010340 5ustar bllblldi-4.52/D/features/0000755000175000017500000000000014421556642012156 5ustar bllblldi-4.52/D/features/env.dat0000644000175000017500000000042614421556642013442 0ustar bllblloption-file ../dioptions.dat loadunit env-main loadunit env-systype loadunit env-dc loadunit env-cc loadunit env-msgfmt loadunit env-extension output di.env system type system rev system arch dc using_gdc dflags cc cflags ldflags libs extension obj extension exe cmd_msgfmt di-4.52/D/features/mkconfig.dat0000644000175000017500000001745014421556642014454 0ustar bllbll# # Copyright 2011 Brad Lanam, Walnut Creek, California USA # # option-file ../dioptions.dat loadunit d-main output config.d standard csizes # di.d: for version chdr version.h # stat() csys stat.h # O_RDONLY chdr fcntl.h # NLS support: # libintl.h has dcls for gettext(), et. al. chdr libintl.h # locale.h has LC_ALL chdr locale.h # unistd.h has geteuid, et. al. chdr unistd.h # diskpart.d: # All: chdr string.h # Linux: # _PATH_MOUNTED MNTTYPE_IGNORE chdr mntent.h # Linux: # for struct statvfs, statvfs() csys statvfs.h # FreeBSD: # for getfsstat(); MNT_NOWAIT; struct statfs csys mount.h # diquota.d: # Linux: # XGETQUOTA chdr linux/dqblk_xfs.h # Solaris: csys fs/ufs_quota.h # Linux: # quotas: QCMD, SUBCMD*, struct dqblk, USRQUOTA, GRPQUOTA csys quota.h # quotas: uid_t, gid_t csys types.h # FreeBSD: # quotas: QCMD, SUBCMD*, struct dqblk, USRQUOTA, GRPQUOTA chdr ufs/ufs/quota.h # NFS quotas chdr rpc/types.h # FreeBSD has broken rpc headers chdr rpc/auth.h rpc/types.h chdr rpc/clnt.h rpc/types.h rpc/auth.h chdr rpc/rpc.h chdr rpcsvc/rquota.h ### Other C library routines clib exit cdcl exit ### For NLS support clib bindtextdomain -lintl, -lintl -liconv clib gettext -lintl, -lintl -liconv clib setlocale clib textdomain -lintl, -lintl -liconv cdefine hex LC_ALL cdcl bindtextdomain cdcl gettext cdcl setlocale cdcl textdomain command msgfmt gmsgfmt ### diskpart.d: # All: clib strlen cdcl strlen clib strcoll cdcl strcoll clib strcmp cdcl strcmp # FreeBSD: for struct statfs from mount.h ctype int uid_t ctype int int32_t ctype int int64_t ctype int uint32_t ctype int uint64_t cstruct fsid # FreeBSD: for struct statvfs from statvfs.h ctype int fsblkcnt_t ctype int fsfilcnt_t # FreeBSD: # getfsstat clib getfsstat cdcl args noconst getfsstat # Linux: # get/set/endmntent clib endmntent cdcl endmntent # some unixware needs -lgen clib getmntent -lgen cdcl getmntent clib setmntent cdcl args noconst setmntent # Linux: from mntent.h cdefine string _PATH_MOUNTED cdefine string _PATH_MNTTAB cdefine string MOUNTED cdefine string MNTTAB # Linux: from mntent.h cdefine string MNTTYPE_IGNORE # Linux: from mntent.h cstruct mntent # Linux: for struct statvfs from statvfs.h ctype int __fsblkcnt_t ctype int __fsfilcnt_t # Linux: 64-bit: for struct statvfs from statvfs.h ctype int __fsblkcnt64_t ctype int __fsfilcnt64_t # Linux: statvfs clib statvfs cdcl statvfs # Linux: from statvfs.h cstruct statvfs # FreeBSD: from mount.h cstruct statfs # FreeBSD: from mount.h cdefine int MNT_NOWAIT cdefine hex MNT_RDONLY cdefine hex MNT_LOCAL # Linux: from statvfs.h cmember statvfs f_basetype # FreeBSD: struct statfs from mount.h cmember statfs f_fstypename cmember statfs f_ftype cmember statfs f_fsize cmember statfs f_bsize ### diquota.d # uid/gid; geteuid, getegid ctype int gid_t ctype int __gid_t # done above #ctype int uid_t ctype int __uid_t clib getegid clib geteuid cdcl getegid cdcl geteuid # from sys/quota.h cdefine hex SUBCMDSHIFT cdefine hex SUBCMDMASK if sysquota _sys_quota cmacro QCMD sys/quota.h int int int endif if ufsufsquota _hdr_ufs_ufs_quota cmacro QCMD ufs/ufs/quota.h int int int endif cdefine hex Q_GETQUOTA cdefine hex Q_XGETQUOTA cdefine hex USRQUOTA cdefine hex GRPQUOTA # from rpcsvc/rquota.h cdefine int RQUOTAPROG cdefine int RQUOTAVERS cdefine int RQUOTAPROC_GETQUOTA # from sys/quota.h # linux clib quotactl cdcl args noconst quotactl cstruct dqblk cmember dqblk dqb_curspace cmember dqblk dqb_curblocks cmember dqblk dqb_fhardlimit cmember dqblk dqb_fsoftlimit cmember dqblk dqb_curfiles # from linux/dqblk_xfs.h # linux ctype int __s8 ctype int __s16 ctype int __s32 ctype int __u16 ctype int __u32 ctype int __u64 # Linux: cdefine hex BLOCK_SIZE # Linux: xfs quotas cstruct fs_disk_quota # Tru64, et. al. cdefine hex DEV_BSIZE # FreeBSD: cdefine int __FreeBSD__ # AIX: cdefine hex DQBSIZE cdefine int _AIX # from rpcsvc/rquota.h # linux cdefine int TRUE cdefine int FALSE ctype int u_int64_t ctype int u_int32_t ctypedef __caddr_t ctypedef caddr_t # from rpc/auth.h clib authunix_create_default cdcl authunix_create_default cmacro auth_destroy rpc/auth.h void 'AUTH *' # from rpc/clnt.h cmacro clnt_call rpc/clnt.h clnt_stat 'CLIENT *' u_long xdrproc_t caddr_t xdrproc_t caddr_t 'struct timeval' cmacro clnt_destroy rpc/clnt.h void 'CLIENT *' clib clnt_create cdcl clnt_create # NFS quotas clib xdr_quota_get cdcl xdr_quota_get clib xdr_quota_rslt cdcl xdr_quota_rslt clib xdr_string cdcl xdr_string clib xdr_int cdcl xdr_int clib xdr_u_int cdcl xdr_u_int clib xdr_bool cdcl xdr_bool cdefine int RQ_PATHLEN # from rpcsvc/rquota.h ctype int bool_t ctype int enum_t ctype int u_int ctype int u_long # done above #ctype int int32_t cstruct rquota ctypedef rquota cmemberxdr rquota rq_bhardlimit cmemberxdr rquota rq_bsoftlimit cmemberxdr rquota rq_curblocks cmemberxdr rquota rq_fhardlimit cmemberxdr rquota rq_fsoftlimit cmemberxdr rquota rq_curfiles cenum gqr_status ctypedef gqr_status cstruct getquota_rslt cmember getquota_rslt gqr_status cmember getquota_rslt gqr_rquota cenum xdr_op cenum clnt_stat cenum auth_stat ctypedef xdrproc_t # Linux: ctype int __time_t ctype int __suseconds_t # FreeBSD: ctype int time_t ctype int suseconds_t ctype int rpcproc_t ctype int rpcprog_t ctype int rpcvers_t # cstruct timeval cstruct rpc_err cstruct getquota_args cmembertype getquota_args gqa_uid cmemberxdr getquota_args gqa_uid cstruct opaque_auth cunion des_block cstruct AUTH ctypedef AUTH cstruct CLIENT ctypedef CLIENT cstruct XDR ctypedef XDR ### di.d cdefine string DI_VERSION # for struct stat cstruct timespec ctype int __dev_t ctype int fflags_t ctype int ino_t ctype int __ino_t ctype int __ino64_t ctype int mode_t ctype int __mode_t ctype int nlink_t ctype int __nlink_t ctype int off_t ctype int __off_t ctype int __off64_t ctype int blksize_t ctype int __blksize_t ctype int blkcnt_t ctype int __blkcnt_t ctype int __blkcnt64_t #ctype int __uid_t #ctype int __gid_t #ctype int __time_t ctype int __int32_t #ctype int int32_t ctype int __uint32_t #ctype int uint32_t cstruct stat clib stat cdcl stat clib fstat cdcl fstat cdefine int O_RDONLY cdefine int O_NOCTTY clib open cdcl open clib close cdcl close ### options # see dioptions.dat to change these option DI_DEFAULT_FORMAT smbuvpT option DI_DEFAULT_DISP_SIZE H ifnotoption NLS set _lib_bindtextdomain 0 set _lib_gettext 0 set _lib_setlocale 0 set _lib_textdomain 0 set _hdr_libintl 0 set _hdr_locale 0 set _command_msgfmt 0 endif if hasnls _clib_bindtextdomain && _clib_gettext && _clib_setlocale && \ _clib_textdomain && _hdr_libintl && _hdr_locale && \ _command_msgfmt setint _enable_nls 1 else set _clib_bindtextdomain 0 set _clib_gettext 0 set _clib_setlocale 0 set _clib_textdomain 0 set _hdr_libintl 0 set _hdr_locale 0 set _command_msgfmt 0 setint _enable_nls 0 endif if stdquotas _hdr_linux_quota || _hdr_ufs_quota || _hdr_ufs_ufs_quota || \ _sys_fs_ufs_quota || _sys_quota || _clib_quotactl setint _has_std_quotas 1 else setint _has_std_quotas 0 endif if stdnfsquotas _hdr_rpc_rpc && _hdr_rpcsvc_rquota && _clib_xdr_int && \ _cmemberxdr_rquota_rq_bhardlimit && _cmemberxdr_getquota_args_gqa_uid setint _has_std_nfs_quotas 1 else setint _has_std_nfs_quotas 0 endif include static if (_ctype_uid_t > 0) { alias C_TYP_uid_t Uid_t; } else { alias int Uid_t; } static if (_ctype_gid_t > 0) { alias C_TYP_gid_t Gid_t; } else { alias int Gid_t; } static if (! _clib_strcoll) { alias strcoll strcmp; } enum string DI_PROG = "di"; enum string DI_PREFIX = "/home/bll/DI/di/C/test_di"; // needed for getmntent() import core.stdc.stdio; // for FILE endinclude di-4.52/D/options.d0000644000175000017500000003554714421556642012216 0ustar bllbll// written in the D programming language module options; import std.string; import std.ascii : isDigit; import std.utf; import std.conv : to; private import std.process : getenv; debug (1) { import std.stdio; } version (unittest) { import std.stdio; private import std.process : setenv, unsetenv; } import config; import dihelp; import digetoptn; import dispopts; private immutable string DI_ALL_FORMAT = "MTS\n\tO\n\tbuf13\n\tbcvpa\n\tBuv2\n\tiUFP"; private immutable string DI_POSIX_FORMAT = "SbuvpM"; private immutable string DI_DEFAULT_SORT = "m"; struct Options { bool csvOutput = false; bool displayAll = false; bool localOnly = false; bool includeLoopback = false; bool printHeader = true; bool quotaCheck = true; bool displayTotal = false; bool debugHeader = false; bool unknown = false; short debugLevel = 0; string formatString = DI_DEFAULT_FORMAT; string sortType = DI_DEFAULT_SORT; string zoneDisplay; bool[string] includeList; bool[string] excludeList; } int getDIOptions (string[] args, ref Options opts, ref DisplayOpts dispOpts) { int idx; string s; if ((s = getenv ("DIFMT")) != null) { opts.formatString = s; } // gnu df if ((s = getenv ("POSIXLY_CORRECT")) != null) { dispOpts.dbsstr = "512"; opts.formatString = DI_POSIX_FORMAT; dispOpts.posixCompat = true; } // bsd df if ((s = getenv ("BLOCKSIZE")) != null) { dispOpts.dbsstr = s; } // gnu df if ((s = getenv ("DF_BLOCK_SIZE")) != null) { dispOpts.dbsstr = s; } if ((s = getenv ("DI_ARGS")) != null) { processOpts (s, opts, dispOpts); } idx = processOpts (args, opts, dispOpts); return idx; } unittest { bool fail; int failures; int tcount; Options opts; DisplayOpts dispOpts; unsetenv ("DI_ARGS"); unsetenv ("BLOCKSIZE"); unsetenv ("DF_BLOCK_SIZE"); unsetenv ("POSIXLY_CORRECT"); ++tcount; fail = false; opts = opts.init; setenv ("DIFMT", "SMT", true); getDIOptions ([""], opts, dispOpts); if (opts.formatString != "SMT") { fail = true; } if (fail) { ++failures; writefln ("# %s: fail: %s", "getDIOptions:", "Env: DIFMT"); writefln (" expected: %s got %s", "SMT", opts.formatString); } unsetenv ("DIFMT"); ++tcount; fail = false; opts = opts.init; setenv ("POSIXLY_CORRECT", " ", true); getDIOptions ([""], opts, dispOpts); if (dispOpts.dbsstr != "512") { fail = true; } if (opts.formatString != DI_POSIX_FORMAT) { fail = true; } if (dispOpts.posixCompat != true) { fail = true; } if (fail) { ++failures; writefln ("# %s: fail: %s", "getDIOptions:", "Env: POSIXLY_CORRECT"); writefln (" expected: %s got %s", "512", dispOpts.dbsstr); writefln (" expected: %s got %s", DI_POSIX_FORMAT, opts.formatString); writefln (" expected: %s got %s", true, dispOpts.posixCompat); } unsetenv ("POSIXLY_CORRECT"); ++tcount; fail = false; opts = opts.init; setenv ("DF_BLOCK_SIZE", "kB", true); getDIOptions ([""], opts, dispOpts); if (dispOpts.dbsstr != "kB") { fail = true; } if (fail) { ++failures; writefln ("# %s: fail: %s", "getDIOptions:", "Env: DF_BLOCK_SIZE"); writefln (" expected: %s got %s", "kB", dispOpts.dbsstr); } unsetenv ("DF_BLOCK_SIZE"); ++tcount; fail = false; opts = opts.init; setenv ("BLOCKSIZE", "kB", true); getDIOptions ([""], opts, dispOpts); if (dispOpts.dbsstr != "kB") { fail = true; } if (fail) { ++failures; writefln ("# %s: fail: %s", "getDIOptions:", "Env: BLOCKSIZE"); writefln (" expected: %s got %s", "kB", dispOpts.dbsstr); } unsetenv ("BLOCKSIZE"); if (failures > 0) { write ("unittest: options: getDIOptions: "); writefln ("failed: %d of %d", failures, tcount); } } private: int processOpts (string str, ref Options opts, ref DisplayOpts dispOpts) { return processOpts (["dummy"] ~ split(strip(str)), opts, dispOpts); } int processOpts (string[] args, ref Options opts, ref DisplayOpts dispOpts) { int idx; OptInfo[string] options; with (opts) { auto delA = delegate (string arg, string val) { formatString = DI_ALL_FORMAT; }; auto delB = delegate (string arg, string val) { processBaseSize (val, dispOpts); }; auto delg = delegate (string arg, string val) { dispOpts.dbsstr = "g"; }; auto delh = delegate (string arg, string val) { dispOpts.dbsstr = "h"; }; auto delH = delegate (string arg, string val) { dispOpts.dbsstr = "H"; }; auto delhelp = delegate (string arg, string val) { usage(); exit (0); }; auto delI = delegate (string arg, string val) { processIncludeList (val, opts); }; auto delk = delegate (string arg, string val) { dispOpts.dbsstr = "k"; }; auto delm = delegate (string arg, string val) { dispOpts.dbsstr = "m"; }; auto delP = delegate (string arg, string val) { if (dispOpts.dbsstr != "k") { dispOpts.dbsstr = "512"; } formatString = DI_POSIX_FORMAT; dispOpts.posixCompat = true; }; auto dels = delegate (string arg, string val) { sortType = processSort (val); }; auto delsi = delegate (string arg, string val) { dispOpts.baseDispSize = size1000; dispOpts.baseDispIdx = idx1000; dispOpts.dbsstr = "H"; }; auto delversion = delegate (string arg, string val) { dispVersion(); exit (0); }; auto delx = delegate (string arg, string val) { processExcludeList (val, opts); }; auto delZ = delegate (string arg, string val) { zoneDisplay = "all"; }; goinit (options, "-A", GETOPTN_FUNC_NOARG, cast(void *) null, delA); goinit (options, "-a", GETOPTN_BOOL, cast(void *) &displayAll, null); goinit (options, "--all", GETOPTN_ALIAS, cast(void *) &"-a", null); goinit (options, "-b", GETOPTN_ALIAS, cast(void *) &"-B", null ); goinit (options, "--block-size", GETOPTN_ALIAS, cast(void *) &"-B", null ); goinit (options, "-B", GETOPTN_FUNC_ARG, cast(void *) null, delB ); goinit (options, "-c", GETOPTN_BOOL, cast(void *) &csvOutput, null ); goinit (options, "--csv-output", GETOPTN_ALIAS, cast(void *) &"-c", null ); goinit (options, "-d", GETOPTN_STRING, cast(void *) &dispOpts.dbsstr, null ); goinit (options, "-f", GETOPTN_STRING, cast(void *) &formatString, null ); goinit (options, "--format-string", GETOPTN_ALIAS, cast(void *) &"-f", null ); goinit (options, "-F", GETOPTN_ALIAS, cast(void *) &"-I", null ); goinit (options, "-g", GETOPTN_FUNC_NOARG, cast(void *) null, delg ); goinit (options, "-h", GETOPTN_FUNC_NOARG, cast(void *) null, delh ); goinit (options, "-H", GETOPTN_FUNC_NOARG, cast(void *) null, delH ); goinit (options, "--help", GETOPTN_FUNC_NOARG, cast(void *) null, delhelp ); goinit (options, "--human-readable", GETOPTN_ALIAS, cast(void *) &"-H", null ); goinit (options, "-?", GETOPTN_ALIAS, cast(void *) &"--help", null ); goinit (options, "-i", GETOPTN_ALIAS, cast(void *) &"-x", null ); goinit (options, "-I", GETOPTN_FUNC_ARG, cast(void *) null, delI ); goinit (options, "--inodes", GETOPTN_IGNORE, cast(void *) null, null ); goinit (options, "-k", GETOPTN_FUNC_NOARG, cast(void *) null, delk ); goinit (options, "-l", GETOPTN_BOOL, cast(void *) &localOnly, null ); goinit (options, "--local", GETOPTN_ALIAS, cast(void *) &"-l", null ); goinit (options, "-L", GETOPTN_BOOL, cast(void *) &includeLoopback, null ); goinit (options, "-m", GETOPTN_FUNC_NOARG, cast(void *) null, delm ); goinit (options, "-n", GETOPTN_BOOL, cast(void *) &printHeader, null ); goinit (options, "--no-sync", GETOPTN_IGNORE, cast(void *) null, null ); goinit (options, "-P", GETOPTN_FUNC_NOARG, cast(void *) null, delP ); goinit (options, "--portability", GETOPTN_ALIAS, cast(void *) &"-P", null ); goinit (options, "--print-type", GETOPTN_IGNORE, cast(void *) null, null ); goinit (options, "-q", GETOPTN_BOOL, cast(void *) "aCheck, null ); goinit (options, "-s", GETOPTN_FUNC_ARG, cast(void *) null, dels ); goinit (options, "--si", GETOPTN_FUNC_NOARG, cast(void *) null, delsi ); goinit (options, "--sync", GETOPTN_IGNORE, cast(void *) null, null ); goinit (options, "-t", GETOPTN_BOOL, cast(void *) &displayTotal, null ); goinit (options, "--total", GETOPTN_ALIAS, cast(void *) &"-t", null ); goinit (options, "--type", GETOPTN_ALIAS, cast(void *) &"-I", null ); goinit (options, "-v", GETOPTN_IGNORE, cast(void *) null, null ); goinit (options, "--version", GETOPTN_FUNC_NOARG, cast(void *) null, delversion ); goinit (options, "-w", GETOPTN_SHORT, cast(void *) &dispOpts.width, null ); goinit (options, "-W", GETOPTN_SHORT, cast(void *) &dispOpts.inodeWidth, null ); goinit (options, "-x", GETOPTN_FUNC_ARG, cast(void *) null, delx ); goinit (options, "--exclude-type", GETOPTN_ALIAS, cast(void *) &"-x", null ); goinit (options, "-X", GETOPTN_SHORT, cast(void *) &debugLevel, null ); goinit (options, "-z", GETOPTN_STRING, cast(void *) &zoneDisplay, null ); goinit (options, "-Z", GETOPTN_FUNC_NOARG, cast(void *) null, delZ ); idx = getoptn (GETOPTN_LEGACY, args, options); } return idx; } version (unittest) { mixin template MoptionsTest(T) { void test (string l, bool expected, string o, ref T var, T rv, int ri) { int i; bool fail; ++tcount; opts = opts.init; i = processOpts (o, opts, dispOpts); //writeln ("### OA:i:", i, ":ri:", ri); //writeln ("### OA:var:", var, ":rv:", rv); if (var != rv) { fail = true; } if (i != ri) { fail = true; } if (fail) { ++failures; writefln ("# %s: fail: %s", "processOpts:", l); writefln (" expected: %s got %s", rv, var); writefln (" expected: %s got %s", ri, i); } } } } unittest { int failures; int tcount; Options opts; DisplayOpts dispOpts; string s; mixin MoptionsTest!bool tbool; mixin MoptionsTest!string tstr; mixin MoptionsTest!real treal; mixin MoptionsTest!short tshort; mixin MoptionsTest!(bool[string]) tbaa; with (opts) { tbool.test ("-a: displayAll", true, "-a", displayAll, true, 2); tstr.test ("-d k: dispOpts.dbsstr", true, "-d k", dispOpts.dbsstr, "k", 3); tstr.test ("-k: dispOpts.dbsstr", true, "-k", dispOpts.dbsstr, "k", 2); tstr.test ("-d g: dispOpts.dbsstr", true, "-d g", dispOpts.dbsstr, "g", 3); tstr.test ("-g: dispOpts.dbsstr", true, "-g", dispOpts.dbsstr, "g", 2); tstr.test ("-d m: dispOpts.dbsstr", true, "-d m", dispOpts.dbsstr, "m", 3); tstr.test ("-m: dispOpts.dbsstr", true, "-m", dispOpts.dbsstr, "m", 2); tstr.test ("-d h: dispOpts.dbsstr", true, "-d h", dispOpts.dbsstr, "h", 3); tstr.test ("-h: dispOpts.dbsstr", true, "-h", dispOpts.dbsstr, "h", 2); tstr.test ("-d H: dispOpts.dbsstr", true, "-d H", dispOpts.dbsstr, "H", 3); tstr.test ("-H: dispOpts.dbsstr", true, "-H", dispOpts.dbsstr, "H", 2); tstr.test ("-A: formatString", true, "-A", formatString, DI_ALL_FORMAT, 2); treal.test ("-b 1000: dispOpts.baseDispSize", true, "-b 1000", dispOpts.baseDispSize, 1000.0, 3); treal.test ("-b 1024: dispOpts.baseDispSize", true, "-b 1024", dispOpts.baseDispSize, 1024.0, 3); treal.test ("-b d: dispOpts.baseDispSize", true, "-b d", dispOpts.baseDispSize, 1000.0, 3); treal.test ("-b k: dispOpts.baseDispSize", true, "-b k", dispOpts.baseDispSize, 1024.0, 3); tstr.test ("-f: formatString", true, "-f SMbuvpT", formatString, "SMbuvpT", 3); tbaa.test ("-I nfs: includeList", true, "-I nfs", includeList, ["nfs":true], 3); tbaa.test ("-I nfs,jfs: includeList", true, "-I nfs,jfs", includeList, ["nfs":true,"jfs":true], 3); tbaa.test ("-I nfs -I jfs: includeList", true, "-I nfs -I jfs", includeList, ["nfs":true,"jfs":true], 5); tbool.test ("-l: localOnly", true, "-l", localOnly, true, 2); tbool.test ("-L: includeLoopback", true, "-L", includeLoopback, true, 2); tbool.test ("-n: printHeader", true, "-n", printHeader, false, 2); tstr.test ("-P: dispOpts.dbsstr", true, "-P", dispOpts.dbsstr, "512", 2); tbool.test ("-P: dispOpts.posixCompat", true, "-P", dispOpts.posixCompat, true, 2); tstr.test ("-P: formatString", true, "-P", formatString, DI_POSIX_FORMAT, 2); tstr.test ("-P -k: dispOpts.dbsstr", true, "-P -k", dispOpts.dbsstr, "k", 3); tstr.test ("-k -P: dispOpts.dbsstr", true, "-k -P", dispOpts.dbsstr, "k", 3); tbool.test ("-q: quotaCheck", true, "-q", quotaCheck, false, 2); tstr.test ("-s r: sortType", true, "-s r", sortType, "rm", 3); tstr.test ("-s t: sortType", true, "-s t", sortType, "tm", 3); tstr.test ("-s trsrm: sortType", true, "-s trsrm", sortType, "trsrm", 3); tbool.test ("-t: displayTotal", true, "-t", displayTotal, true, 2); tshort.test ("-w 12: dispOpts.width", true, "-w 12", dispOpts.width, 12, 3); tshort.test ("-W 12: dispOpts.inodeWidth", true, "-W 12", dispOpts.width, 12, 3); tbaa.test ("-x nfs: excludeList", true, "-x nfs", excludeList, ["nfs":true], 3); tbaa.test ("-x nfs,jfs: excludeList", true, "-x nfs,jfs", excludeList, ["nfs":true,"jfs":true], 3); tbaa.test ("-x nfs -x jfs: excludeList", true, "-x nfs -x jfs", excludeList, ["nfs":true,"jfs":true], 5); tstr.test ("-z some: zoneDisplay", true, "-z some", zoneDisplay, "some", 3); tstr.test ("-Z: zoneDisplay", true, "-Z", zoneDisplay, "all", 2); tshort.test ("-X 4: debugLevel", true, "-X 4", debugLevel, 4, 3); } if (failures > 0) { write ("unittest: options: processOpts: "); writefln ("failed: %d of %d", failures, tcount); } } void processBaseSize (string arg, ref DisplayOpts dispOpts) { size_t i = 0; dchar c; with (dispOpts) { c = decode (arg, i); if (isDigit (c)) { baseDispSize = to!(typeof(baseDispSize))(arg); baseDispIdx = idx1000; // unknown, really if (baseDispSize == 1024.0) { baseDispIdx = idx1024; } } else if (arg == "k") { baseDispSize = size1024; baseDispIdx = idx1024; } else if (arg == "d" || arg == "si") { baseDispSize = size1000; baseDispIdx = idx1000; } } } string processSort (string arg) { string sortType; sortType = arg; if (arg == "r") { // backwards compatibility sortType = "rm"; } if (arg == "t") { // add some additional sorting... sortType = "tm"; } return sortType; } void processIncludeList (string arg, ref Options opts) { foreach (str; split (arg, ",")) { opts.includeList[str] = true; } } void processExcludeList (string arg, ref Options opts) { foreach (str; split (arg, ",")) { opts.excludeList[str] = true; } } di-4.52/D/di.d0000644000175000017500000001332414421556642011104 0ustar bllbll// written in the D programming language import std.stdio; import std.string; import config; import options; import dispopts; import diskpart; import display; import dilocale; import diquota; enum string FUSE_FS = "fuse"; void main (string[] args) { Options opts; DisplayOpts dispOpts; bool hasLoopback; initLocale (); auto optidx = getDIOptions (args, opts, dispOpts); auto dps = new DiskPartitions (opts.debugLevel); dps.getEntries (); auto hasPooled = preCheckDiskPartitions (dps, opts); if (optidx < args.length || opts.includeLoopback == false) { getDiskStatInfo (dps); hasLoopback = getDiskSpecialInfo (dps); } if (optidx < args.length) { auto rc = checkFileInfo (dps, opts, hasPooled, args, optidx); } dps.getPartitionInfo (); checkDiskPartitions (dps, opts, hasLoopback); if (opts.quotaCheck) { checkDiskQuotas (dps, opts); } doDisplay (opts, dispOpts, dps, hasPooled); } bool preCheckDiskPartitions (ref DiskPartitions dps, Options opts) { bool hasPooled; foreach (ref dp; dps.diskPartitions) { if (dp.fsType == "zfs" || dp.fsType == "advfs") { dp.isPooledFS = true; hasPooled = true; } if (! dp.isRemote && dp.fsType[0..2] == "nfs") { dp.isRemote = true; } if (opts.localOnly && dp.isRemote) { dp.printFlag = dp.DI_PRINT_IGNORE; } checkIncludeList (dp, opts); if (opts.excludeList.length > 0) { if (opts.excludeList.get (dp.fsType, false) || (dp.fsType[0..3] == FUSE_FS && opts.excludeList.get (FUSE_FS, false))) { dp.printFlag = dp.DI_PRINT_EXCLUDE; } } } return hasPooled; } void checkIncludeList (ref DiskPartitions.DiskPartition dp, Options opts) { if (opts.includeList.length > 0) { if (dp.printFlag != dp.DI_PRINT_BAD && dp.printFlag != dp.DI_PRINT_OUTOFZONE && opts.includeList.get (dp.fsType, false) || (dp.fsType[0..3] == FUSE_FS && opts.includeList.get (FUSE_FS, false))) { dp.doPrint = true; } else { dp.doPrint = false; } } } void checkDiskPartitions (ref DiskPartitions dps, Options opts, bool hasLoopback) { foreach (ref dp; dps.diskPartitions) { dp.doPrint = true; if (dp.printFlag == dp.DI_PRINT_EXCLUDE || dp.printFlag == dp.DI_PRINT_BAD || dp.printFlag == dp.DI_PRINT_OUTOFZONE) { dp.doPrint = false; /* -a flag does not affect these */ continue; } if (dp.printFlag == dp.DI_PRINT_IGNORE || dp.printFlag == dp.DI_PRINT_SKIP) { dp.doPrint = opts.displayAll; continue; } dp.checkPartSizes; if (dp.printFlag == dp.DI_PRINT_OK) { if (dp.totalBlocks <= 0.0) { dp.printFlag = dp.DI_PRINT_IGNORE; dp.doPrint = opts.displayAll; } } if (hasLoopback && opts.includeLoopback == false) { if (dp.isLoopback) { dp.printFlag = dp.DI_PRINT_IGNORE; dp.doPrint = opts.displayAll; } } checkIncludeList (dp, opts); } } void getDiskStatInfo (ref DiskPartitions dps) { C_ST_stat statBuf; foreach (ref dp; dps.diskPartitions) { if (dp.printFlag == dp.DI_PRINT_EXCLUDE || dp.printFlag == dp.DI_PRINT_BAD || dp.printFlag == dp.DI_PRINT_OUTOFZONE) { continue; } dp.st_dev = dp.DI_UNKNOWN_DEV; if (stat (toStringz (dp.name), &statBuf) == 0) { dp.st_dev = cast(uint) statBuf.st_dev; } } } bool getDiskSpecialInfo (ref DiskPartitions dps) { C_ST_stat statBuf; bool hasLoopback; foreach (ref dp; dps.diskPartitions) { if (dp.name[0] == '/' && stat (toStringz(dp.special), &statBuf) == 0) { dp.sp_dev = cast(uint) statBuf.st_dev; dp.sp_rdev = cast(uint) statBuf.st_rdev; /* Solaris's loopback device is "lofs" */ /* linux loopback device is "none" */ /* linux has rdev = 0 */ /* DragonFlyBSD's loopback device is "null" */ /* DragonFlyBSD has rdev = -1 */ /* solaris is more consistent; rdev != 0 for lofs */ /* solaris makes sense. */ if ((dp.fsType == "lofs" && dp.sp_rdev != 0) || dp.fsType == "null" || dp.fsType == "none") { dp.isLoopback = true; hasLoopback = true; } else { dp.sp_dev = 0; dp.sp_rdev = 0; } } } return hasLoopback; } bool checkFileInfo (ref DiskPartitions dps, Options opts, bool hasPooled, string[] args, int optidx) { C_ST_stat statBuf; foreach (ref dp; dps.diskPartitions) { if (dp.printFlag == dp.DI_PRINT_OK) { dp.printFlag = dp.DI_PRINT_IGNORE; } } if (hasPooled) { size_t[] sortIndex; sortIndex.length = dps.diskPartitions.length; for (int i = 0; i < sortIndex.length; ++i) { sortIndex[i] = i; } dps.sortPartitions (sortIndex, "s"); } for (auto i = optidx; i < args.length; ++i) { auto fd = open (toStringz(args[i]), O_RDONLY | O_NOCTTY); C_NATIVE_int rc; if (fd < 0) { rc = stat (toStringz(args[i]), &statBuf); } else { rc = fstat (fd, &statBuf); close (fd); } if (rc == 0) { foreach (ref dp; dps.diskPartitions) { if (opts.debugLevel > 5) { writefln ("check %s against %s: %d %d", args[i], dp.name, cast(uint) statBuf.st_dev, dp.st_dev); } if (dp.st_dev != dp.DI_UNKNOWN_DEV && cast(uint) statBuf.st_dev == dp.st_dev && ! dp.isLoopback) { dp.printFlag = dp.DI_PRINT_FORCE; break; } } // for each partition } // if stat of file worked } // for each command line argument return true; } di-4.52/D/Makefile0000644000175000017500000001116514421556642012004 0ustar bllbll# # di makefile - D # # Copyright 2011 Brad Lanam Walnut Creek CA, USA # OBJ_EXT = .o EXE_EXT = CC = cc DC = gdc # # common programs # CAT = cat CHGRP = chgrp CHMOD = chmod CHOWN = chown CP = cp LN = ln MKDIR = mkdir MV = mv RM = rm ### # mkconfig variables MKC_DIR = ../mkconfig MKCONFIG_TYPE = sh MKC_REQLIB = di.reqlibs # set to -e to echo command lines. MKCECHO = ### # main # have to get various environment variables set up. # DTESTFLAGS="$$DC_OPT $$DC_RELEASE $$DC_INLINE" di-programs # compiling w/o the unittest flag doesn't work w/incremental linking .PHONY: all all: di.env . ./di.env; \ $(MAKE) -e MKCONFIG_TYPE=sh \ DTESTFLAGS="$$DC_UNITTEST" di-programs # DTESTFLAGS="$$DC_UNITTEST $$DC_COV $$DC_DEBUG" \ .PHONY: all-test all-test: di.env . ./di.env; \ $(MAKE) -e MKCONFIG_TYPE=sh \ DTESTFLAGS="$$DC_UNITTEST $$DC_COV " \ LIBS="$(LIBS) $$DC_LIBS" di-programs ### # environment #### possibly merge features/env.dat w/C version??? di.env: features/env.dat ../dioptions.dat @-$(RM) -f di.env tests.done CFLAGS="-I`pwd`/../C" $(_MKCONFIG_SHELL) \ $(MKC_DIR)/mkconfig.sh features/env.dat ### # cleaning # leaves: # config.d, di.env, di.reqlibs .PHONY: clean clean: @-rm -f di di.exe mi mi.exe \ *.o *.obj *.lst *.gcno *.gcda *.gcov \ mkconfig.log mkconfig.cache mkc*.vars *~ \ > /dev/null 2>&1 # leaves: # _mkconfig_runtests, _tmp_mkconfig .PHONY: realclean realclean: @$(MAKE) clean > /dev/null 2>&1 @-$(RM) -rf config.d di.env $(MKC_REQLIB) \ >/dev/null 2>&1 # leaves: .PHONY: distclean distclean: @$(MAKE) realclean > /dev/null 2>&1 @-$(RM) -rf _mkconfig_runtests _tmp_mkconfig test_di \ >/dev/null 2>&1 ### # installation .PHONY: install install: di-programs di.env . ./di.env;cd ..;$(MAKE) -e prefix=$(prefix) LOCALEDIR=$(LOCALEDIR) FROMDIR=D install ### # programs .PHONY: di-programs di-programs: di$(EXE_EXT) ### # configuration file ../dioptions.dat: ../features/dioptions.dat cd ../;$(MAKE) dioptions.dat config.d: di.env ../dioptions.dat features/mkconfig.dat @-$(RM) -f config.d tests.done @if [ "$(DI_NO_NLS)" != "" ]; then \ echo "*** User requested no NLS"; \ $(MKC_DIR)/mkcsetopt.sh -o ../dioptions.dat NLS F; fi @. ./di.env;$(_MKCONFIG_SHELL) \ $(MKC_DIR)/mkconfig.sh \ features/mkconfig.dat; fi $(MKC_REQLIB): di.env config.d $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -reqlib -o \ $(MKC_REQLIB) config.d ### # executables OBJECTS = config$(OBJ_EXT) di$(OBJ_EXT) \ dihelp$(OBJ_EXT) dilocale$(OBJ_EXT) \ diquota$(OBJ_EXT) diskpart$(OBJ_EXT) display$(OBJ_EXT) \ dispopts$(OBJ_EXT) digetoptn$(OBJ_EXT) options$(OBJ_EXT) di$(EXE_EXT): $(OBJECTS) $(MKC_REQLIB) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -link $(MKCECHO) -c $(DC) \ -o di$(EXE_EXT) -r $(MKC_REQLIB) -- $(LDFLAGS) $(OBJECTS) $(LIBS) ### # objects config$(OBJ_EXT): config.d $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) config.d di$(OBJ_EXT): di.d config$(OBJ_EXT) \ diskpart$(OBJ_EXT) dihelp$(OBJ_EXT) \ dilocale$(OBJ_EXT) diquota$(OBJ_EXT) \ display$(OBJ_EXT) dispopts$(OBJ_EXT) \ digetoptn$(OBJ_EXT) options$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) di.d digetoptn$(OBJ_EXT): digetoptn.d config$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) digetoptn.d dihelp$(OBJ_EXT): dihelp.d config$(OBJ_EXT) dilocale$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) dihelp.d dilocale$(OBJ_EXT): dilocale.d config$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) dilocale.d diquota$(OBJ_EXT): diquota.d config$(OBJ_EXT) diskpart$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) diquota.d diskpart$(OBJ_EXT): diskpart.d config$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) diskpart.d display$(OBJ_EXT): display.d config$(OBJ_EXT) dilocale$(OBJ_EXT) \ diskpart$(OBJ_EXT) dispopts$(OBJ_EXT) \ options$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) display.d dispopts$(OBJ_EXT): dispopts.d config$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) dispopts.d options$(OBJ_EXT): options.d config$(OBJ_EXT) \ dispopts$(OBJ_EXT) dihelp$(OBJ_EXT) digetoptn$(OBJ_EXT) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -comp $(MKCECHO) -c $(DC) -o $@ \ -- $(DFLAGS) $(DTESTFLAGS) options.d di-4.52/D/dilocale.d0000644000175000017500000000131414421556642012260 0ustar bllbll// written in the D programming language import std.string; import std.conv : to; private import std.process : getenv; import config; enum string DI_LOCALE_DIR = DI_PREFIX ~ "/share/locale"; static if (_enable_nls) { auto DI_GT (string txt) { return (to!string(gettext(toStringz(txt)))); } } else { auto DI_GT (string txt) { return (txt); } } void initLocale () { string localeptr = null; static if (_clib_setlocale) { setlocale (LC_ALL, ""); } static if (_enable_nls) { if ((localeptr = getenv ("DI_LOCALE_DIR")) == cast(string) null) { localeptr = DI_LOCALE_DIR; } bindtextdomain (toStringz(DI_PROG), toStringz(localeptr)); textdomain (toStringz(DI_PROG)); } } di-4.52/D/display.d0000644000175000017500000006360714421556642012166 0ustar bllbll// written in the D programming language module display; import std.stdio; import std.string; import std.ascii : isDigit; import std.uni : toLower; import std.conv : to; private import std.utf : count; private import std.math : floor; import config; import options; import dispopts; import diskpart; import dilocale; private: enum dchar FMT_MOUNT = 'm', FMT_MOUNT_FULL = 'M', FMT_SPECIAL = 's', FMT_SPECIAL_FULL = 'S', FMT_TYPE = 't', FMT_TYPE_FULL = 'T', FMT_BLOCKS_TOT = 'b', FMT_BLOCKS_TOT_AVAIL = 'B', FMT_BLOCKS_USED = 'u', FMT_BLOCKS_CALC_USED = 'c', FMT_BLOCKS_FREE = 'f', FMT_BLOCKS_AVAIL = 'v', FMT_BLOCKS_PERC_NOT_AVAIL = 'p', FMT_BLOCKS_PERC_USED = '1', FMT_BLOCKS_PERC_USED_AVAIL = '2', FMT_BLOCKS_PERC_AVAIL = 'a', FMT_BLOCKS_PERC_FREE = '3', FMT_INODES_TOT = 'i', FMT_INODES_USED = 'U', FMT_INODES_FREE = 'F', FMT_INODES_PERC = 'P', FMT_MOUNT_TIME = 'I', FMT_MOUNT_OPTIONS = 'O'; enum int FTYPE_STRING = 1, FTYPE_SPACE = 2, FTYPE_PERC_SPACE = 3, FTYPE_INODE = 4, FTYPE_PERC_INODE = 5; struct FormatInfo { dchar key; int ftype; long width; string title; }; FormatInfo[] formatTypes = [ { key: FMT_MOUNT, ftype: FTYPE_STRING, width: 15, title: "Mount" }, { key: FMT_MOUNT_FULL, ftype: FTYPE_STRING, width: 15, title: "Mount" }, { key: FMT_SPECIAL, ftype: FTYPE_STRING, width: 18, title: "Filesystem" }, { key: FMT_SPECIAL_FULL, ftype: FTYPE_STRING, width: 18, title: "Filesystem" }, { key: FMT_TYPE, ftype: FTYPE_STRING, width: 7, title: "fsType" }, { key: FMT_TYPE_FULL, ftype: FTYPE_STRING, width: 7, title: "fs Type" }, { key: FMT_BLOCKS_TOT, ftype: FTYPE_SPACE, width: 8, title: "" }, { key: FMT_BLOCKS_TOT_AVAIL, ftype: FTYPE_SPACE, width: 8, title: "" }, { key: FMT_BLOCKS_USED, ftype: FTYPE_SPACE, width: 8, title: "Used" }, { key: FMT_BLOCKS_CALC_USED, ftype: FTYPE_SPACE, width: 8, title: "Used" }, { key: FMT_BLOCKS_FREE, ftype: FTYPE_SPACE, width: 8, title: "Free" }, { key: FMT_BLOCKS_AVAIL, ftype: FTYPE_SPACE, width: 8, title: "Avail" }, { key: FMT_BLOCKS_PERC_NOT_AVAIL, ftype: FTYPE_PERC_SPACE, width: 6, title: "%Used" }, { key: FMT_BLOCKS_PERC_USED, ftype: FTYPE_PERC_SPACE, width: 6, title: "%Used" }, { key: FMT_BLOCKS_PERC_USED_AVAIL, ftype: FTYPE_PERC_SPACE, width: 6, title: "%Used" }, { key: FMT_BLOCKS_PERC_AVAIL, ftype: FTYPE_PERC_SPACE, width: 5, title: "%Free" }, { key: FMT_BLOCKS_PERC_FREE, ftype: FTYPE_PERC_SPACE, width: 5, title: "%Free" }, { key: FMT_INODES_TOT, ftype: FTYPE_INODE, width: 9, title: "Inodes" }, { key: FMT_INODES_USED, ftype: FTYPE_INODE, width: 9, title: "IUsed" }, { key: FMT_INODES_FREE, ftype: FTYPE_INODE, width: 9, title: "IFree" }, { key: FMT_INODES_PERC, ftype: FTYPE_PERC_INODE, width: 6, title: "%IUsed" }, { key: FMT_MOUNT_TIME, ftype: FTYPE_STRING, width: 0, title: "" }, { key: FMT_MOUNT_OPTIONS, ftype: FTYPE_STRING, width: 15, title: "Options" } ]; size_t[dchar] formatTypesIdxs; bool fmtInfoIdxsInitialized; struct DisplayData { Options opts; DisplayOpts dispOpts; DiskPartitions dps; string titleString; string[dchar] dispFmtString; }; struct DisplayTable { real size; real low; real high; short precision; char key; string suffix; string disp[2]; }; DisplayTable[] displayTable = [ // size == low except for bytes { size: 0, low: 0, high: 0, precision: 0, key: 'b', suffix: " ", disp: [ "Bytes", "Bytes" ] }, { size: 0, low: 0, high: 0, precision: 0, key: 'k', suffix: "K", disp: [ "KBytes", "KBytes" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'm', suffix: "M", disp: [ "Megs", "Mebis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'g', suffix: "G", disp: [ "Gigs", "Gibis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 't', suffix: "T", disp: [ "Teras", "Tebis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'p', suffix: "P", disp: [ "Petas", "Pebis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'e', suffix: "E", disp: [ "Exas", "Exbis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'z', suffix: "Z", disp: [ "Zettas", "Zebis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'y', suffix: "Y", disp: [ "Yottas", "Yobis" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'h', suffix: "h", disp: [ "Size", "Size" ] }, { size: 0, low: 0, high: 0, precision: 1, key: 'H', suffix: "H", disp: [ "Size", "Size" ] } ]; size_t[char] displayIdxs; bool dispIdxsInitialized; public: void doDisplay (Options opts, ref DisplayOpts dispOpts, DiskPartitions dps, bool hasPooled) { DisplayData dispData; initializeIdxs (); initializeTitles (dispOpts); initializeDisplayTable (dispOpts); setDispBlockSize (dispOpts); if (opts.debugLevel > 30) { dumpDispTable (); } dispData.opts = opts; dispData.dispOpts = dispOpts; dispData.dps = dps; buildDisplayList (dispData); displayTitle (dispData); displayPartitions (dispData, hasPooled); } private: void dumpDispTable () { foreach (disp; displayTable) { writefln ("%s %s %-6s sz:%25.0f\n low:%25.0f high:%25.0f", disp.key, disp.suffix, disp.disp[0], disp.size, disp.low, disp.high); } } void buildDisplayList (ref DisplayData dispData) { int[dchar] dpMax; bool first = true; foreach (dchar c; dispData.opts.formatString) { if (c in formatTypesIdxs && formatTypes[formatTypesIdxs[c]].ftype == FTYPE_STRING) { dpMax[c] = 0; } } foreach (dp; dispData.dps.diskPartitions) { if (! dp.doPrint) { continue; } if (FMT_SPECIAL_FULL in dpMax) { setMaxLen (dp.special, dpMax[FMT_SPECIAL_FULL]); } if (FMT_MOUNT_FULL in dpMax) { setMaxLen (dp.name, dpMax[FMT_MOUNT_FULL]); } if (FMT_TYPE_FULL in dpMax) { setMaxLen (dp.fsType, dpMax[FMT_TYPE_FULL]); } if (FMT_MOUNT_OPTIONS in dpMax) { setMaxLen (dp.mountOptions, dpMax[FMT_MOUNT_OPTIONS]); } } foreach (dchar c; dispData.opts.formatString) { if (c in formatTypesIdxs) { string fmt; auto title = DI_GT (formatTypes[formatTypesIdxs[c]].title); auto ftype = formatTypes[formatTypesIdxs[c]].ftype; auto width = formatTypes[formatTypesIdxs[c]].width; switch (c) { case FMT_MOUNT_FULL: case FMT_SPECIAL_FULL: case FMT_TYPE_FULL: case FMT_MOUNT_TIME: case FMT_MOUNT_OPTIONS: { width = dpMax[c]; break; } case FMT_BLOCKS_TOT: case FMT_BLOCKS_TOT_AVAIL: { title = DI_GT (dispData.dispOpts.dispBlockLabel); break; } default: { break; } } if (dispData.opts.csvOutput) { title = to!string(c); } auto utflen = std.utf.count (title); if (utflen > width) { width = utflen; } switch (ftype) { case FTYPE_STRING: { fmt = format ("%%-%d.%ds ", width, width); if (dispData.opts.csvOutput) { fmt = "\"%s\""; } dispData.dispFmtString[c] = fmt; break; } case FTYPE_SPACE: { if (dispData.dispOpts.width != 0) { width = dispData.dispOpts.width; } auto twidth = width; if (dispData.dispOpts.dbsstr == "h" || dispData.dispOpts.dbsstr == "H") { --twidth; } fmt = format ("%%%d.%df", twidth, dispData.dispOpts.precision); if (dispData.opts.csvOutput) { fmt = format ("%%.%df", dispData.dispOpts.precision); } dispData.dispFmtString[c] = fmt; break; } case FTYPE_PERC_SPACE: { auto twidth = width - 2; if (twidth < 1) { twidth = 1; } fmt = format ("%%%d.0f%%%% ", twidth); if (dispData.opts.csvOutput) { fmt = "%.0f%%"; } dispData.dispFmtString[c] = fmt; break; } case FTYPE_INODE: { if (dispData.dispOpts.inodeWidth != 0) { width = dispData.dispOpts.inodeWidth; } fmt = format ("%%%d.0f ", width); if (dispData.opts.csvOutput) { fmt = "%.0f"; } dispData.dispFmtString[c] = fmt; break; } case FTYPE_PERC_INODE: { fmt = format ("%%%d.0f%%%% ", width); if (dispData.opts.csvOutput) { fmt = "%.0f%%"; } dispData.dispFmtString[c] = fmt; break; } default: { break; } } // switch on format type auto twid = width + title.length - utflen; if (dispData.opts.csvOutput) { fmt = "%s"; } else { if (ftype == FTYPE_STRING) { fmt = format ("%%-%d.%ds ", twid, twid); } else { fmt = format ("%%%d.%ds ", twid, twid); } } if (dispData.opts.csvOutput && ! first) { dispData.titleString ~= ","; } dispData.titleString ~= format (fmt, title); } else { dispData.titleString ~= format ("%s", c); } first = false; } // for each format string char } void displayTitle (ref DisplayData dispData) { if (! dispData.opts.printHeader) { return; } writeln (dispData.titleString); } void displayPartitions (ref DisplayData dispData, bool hasPooled) { size_t[] sortIndex; sortIndex.length = dispData.dps.diskPartitions.length; for (int i = 0; i < sortIndex.length; ++i) { sortIndex[i] = i; } if (dispData.opts.displayTotal) { bool inpool; string lastpool; dispData.dps.tot.initDiskPartition; dispData.dps.tot.name = DI_GT("Total"); if (hasPooled) { dispData.dps.sortPartitions (sortIndex, "s"); } foreach (size_t i, size_t v; sortIndex) { bool startpool; auto dp = dispData.dps.diskPartitions[v]; startpool = false; if (hasPooled && dp.isPooledFS) { if (lastpool.length == 0 || (dp.special.length >= lastpool.length && lastpool != dp.special[0..lastpool.length])) { lastpool = dp.special; auto si = indexOf (lastpool, "#"); /* for advfs */ if (si >= 0) { lastpool.length = si; } si = indexOf (lastpool, "/"); /* for zfs */ if (si >= 0) { lastpool.length = si; } inpool = false; startpool = true; } } else { inpool = false; } if (dp.doPrint) { /* only add in a pooled filesystem if it's the first in the list */ /* belonging to that pool */ if (! inpool) { dispData.dps.tot.totalBlocks += dp.totalBlocks; dispData.dps.tot.freeBlocks += dp.freeBlocks; dispData.dps.tot.availBlocks += dp.availBlocks; dispData.dps.tot.totalInodes += dp.totalInodes; dispData.dps.tot.freeInodes += dp.freeInodes; dispData.dps.tot.availInodes += dp.availInodes; } else { /* if in a pool of disks, add the total used to the totals */ dispData.dps.tot.totalBlocks += dp.totalBlocks - dp.freeBlocks; dispData.dps.tot.totalInodes += dp.totalInodes - dp.freeInodes; } } if (startpool) { inpool = true; } } } dispData.dps.sortPartitions (sortIndex, dispData.opts.sortType); foreach (size_t i, size_t v; sortIndex) { auto dp = dispData.dps.diskPartitions[v]; if (! dp.doPrint) { continue; } printPartition (dispData, dp); } // for each disk partition if (dispData.opts.displayTotal) { printPartition (dispData, dispData.dps.tot); } } void printPartition (ref DisplayData dispData, DiskPartitions.DiskPartition dp) { string outString; string sval; real rval; real uval; size_t dHidx; bool first = true; if (dispData.dispOpts.dbsstr == "H") { real mval = 0.0; foreach (dchar c; dispData.opts.formatString) { if (c in formatTypesIdxs) { auto ftype = formatTypes[formatTypesIdxs[c]].ftype; if (ftype == FTYPE_SPACE) { switch (c) { case FMT_BLOCKS_TOT: { rval = dp.totalBlocks; break; } case FMT_BLOCKS_TOT_AVAIL: { rval = dp.totalBlocks - (dp.freeBlocks - dp.availBlocks); break; } case FMT_BLOCKS_USED: { rval = dp.totalBlocks - dp.freeBlocks; break; } case FMT_BLOCKS_CALC_USED: { rval = dp.totalBlocks - dp.availBlocks; break; } case FMT_BLOCKS_FREE: { rval = dp.freeBlocks; break; } case FMT_BLOCKS_AVAIL: { rval = dp.availBlocks; break; } default: { break; } } // switch on format character if (rval > mval) { mval = rval; } } // is FTYPE_SPACE } // valid format character } // for each character in format string dHidx = findDispSize (mval); } // if -d H foreach (dchar c; dispData.opts.formatString) { if (c in formatTypesIdxs) { auto ftype = formatTypes[formatTypesIdxs[c]].ftype; switch (c) { case FMT_MOUNT: case FMT_MOUNT_FULL: { sval = dp.name; break; } case FMT_SPECIAL: case FMT_SPECIAL_FULL: { sval = dp.special; break; } case FMT_TYPE: case FMT_TYPE_FULL: { sval = dp.fsType; break; } case FMT_BLOCKS_TOT: { rval = dp.totalBlocks; break; } case FMT_BLOCKS_TOT_AVAIL: { rval = dp.totalBlocks - (dp.freeBlocks - dp.availBlocks); break; } case FMT_BLOCKS_USED: { rval = dp.totalBlocks - dp.freeBlocks; break; } case FMT_BLOCKS_CALC_USED: { rval = dp.totalBlocks - dp.availBlocks; break; } case FMT_BLOCKS_FREE: { rval = dp.freeBlocks; break; } case FMT_BLOCKS_AVAIL: { rval = dp.availBlocks; break; } case FMT_BLOCKS_PERC_NOT_AVAIL: { rval = dp.totalBlocks; uval = dp.totalBlocks - dp.availBlocks; break; } case FMT_BLOCKS_PERC_USED: { rval = dp.totalBlocks; uval = dp.totalBlocks - dp.freeBlocks; break; } case FMT_BLOCKS_PERC_USED_AVAIL: { rval = dp.totalBlocks - (dp.freeBlocks - dp.availBlocks); uval = dp.totalBlocks - dp.freeBlocks; break; } case FMT_BLOCKS_PERC_AVAIL: { rval = dp.totalBlocks; uval = dp.availBlocks; break; } case FMT_BLOCKS_PERC_FREE: { rval = dp.totalBlocks; uval = dp.freeBlocks; break; } case FMT_INODES_TOT: { rval = dp.totalInodes; break; } case FMT_INODES_USED: { rval = dp.totalInodes - dp.freeInodes; break; } case FMT_INODES_FREE: { rval = dp.freeInodes; break; } case FMT_INODES_PERC: { rval = dp.totalInodes; uval = dp.totalInodes - dp.availInodes; break; } case FMT_MOUNT_TIME: { break; } case FMT_MOUNT_OPTIONS: { sval = dp.mountOptions; break; } default: { break; } } // switch on format character switch (ftype) { case FTYPE_STRING: { if (dispData.opts.csvOutput && ! first) { outString ~= ","; } outString ~= format (dispData.dispFmtString[c], sval); break; } case FTYPE_SPACE: { if (dispData.opts.csvOutput && ! first) { outString ~= ","; } outString ~= blockDisplay (dispData, c, rval, dHidx, dispData.opts.csvOutput); break; } case FTYPE_PERC_SPACE: case FTYPE_PERC_INODE: { if (dispData.opts.csvOutput && ! first) { outString ~= ","; } outString ~= percDisplay (dispData, c, rval, uval); break; } case FTYPE_INODE: { if (dispData.opts.csvOutput && ! first) { outString ~= ","; } outString ~= inodeDisplay (dispData, c, rval); break; } default: { break; } } } else { outString ~= c; } first = false; } // for each format character writeln (outString); } auto findDispSize (real val) { foreach (i, dt; displayTable) { if (val >= dt.low && val < dt.high) { return i; } } return displayIdxs['m']; } string blockDisplay (const DisplayData dispData, const dchar c, const real val, const size_t dHidx, bool csvOutput) { size_t idx; real dbs = dispData.dispOpts.dispBlockSize; string suffix = ""; if (dispData.dispOpts.dbsstr == "h") { idx = findDispSize (val); } if (dispData.dispOpts.dbsstr == "H") { idx = dHidx; } if (dispData.dispOpts.dbsstr == "h" || dispData.dispOpts.dbsstr == "H") { dbs = displayTable[idx].size; suffix = displayTable[idx].suffix; } auto nval = val / dbs; auto fmt = dispData.dispFmtString[c] ~ suffix; if (! csvOutput) { fmt ~= " "; } else { fmt = "\"" ~ fmt ~ "\""; } return format (fmt, nval); } string inodeDisplay (const DisplayData dispData, const dchar c, const real val) { size_t idx; string suffix = ""; auto fmt = dispData.dispFmtString[c]; return format (fmt, val); } string percDisplay (const DisplayData dispData, const dchar c, const real tval, const real uval) { real perc; if (tval > 0.0) { perc = uval / tval; perc *= 100; } else { perc = 0.0; } auto fmt = dispData.dispFmtString[c]; return format (fmt, perc); } void setDispBlockSize (ref DisplayOpts dispOpts) { real val; char c; val = 1024.0 * 1024.0; c = dispOpts.dbsstr[0]; if (isDigit (c)) { val = to!(typeof(val))(dispOpts.dbsstr); val = floor (val); // make sure it's an integer value //writefln ("digit:%s:val=%25.0f", dispOpts.dbsstr, val); foreach (disp; displayTable) { if (val == disp.size) { c = disp.key; //writefln ("digit:%s", c); break; } } } else { if (c != 'H') { c = cast(char) toLower (c); } if (dispOpts.dbsstr == "HUMAN") { c = 'h'; } //writefln ("non-digit:%s:%s", dispOpts.dbsstr, c); if (dispOpts.dbsstr.length > 1 && dispOpts.dbsstr[1] == 'B' && dispOpts.baseDispSize != size1000) { //writefln ("non-digit:1000:%s", c); dispOpts.baseDispSize = size1000; dispOpts.baseDispIdx = idx1000; initializeDisplayTable (dispOpts); } if (dispOpts.dbsstr.length > 1 && dispOpts.dbsstr[1] == 'b' && dispOpts.baseDispSize != size1024) { //writefln ("non-digit:1024:%s", c); dispOpts.baseDispSize = size1024; dispOpts.baseDispIdx = idx1024; initializeDisplayTable (dispOpts); } } if (c in displayIdxs) { auto idx = displayIdxs [c]; dispOpts.dispBlockLabel = displayTable [idx].disp [dispOpts.baseDispIdx]; val = displayTable [idx].size; dispOpts.precision = displayTable [idx].precision; } else { foreach (idx, disp; displayTable) { if (disp.key == 'h') { break; } auto tval = val / disp.size; if (floor (tval) == tval) { auto s = disp.suffix; if (idx == 0) { s = "b"; } dispOpts.dispBlockLabel = format ("%.0f%s", tval, s); } } } if (dispOpts.posixCompat && val == 512.0) { dispOpts.dispBlockLabel = "512-blocks"; } if (dispOpts.posixCompat && val == 1024.0) { dispOpts.dispBlockLabel = "1024-blocks"; } //writefln ("block label:%s", dispOpts.dispBlockLabel); dispOpts.dispBlockSize = val; //writefln ("block size:%.0f", val); } unittest { DisplayOpts dispOpts; int tcount; int failures; void test (string l, bool posix, string dbsstr, real bds, int bdi, string rdbl, real rdbs) { bool fail; ++tcount; dispOpts = dispOpts.init; dispOpts.dbsstr = dbsstr; dispOpts.baseDispSize = bds; dispOpts.baseDispIdx = bdi; dispOpts.posixCompat = posix; setDispBlockSize (dispOpts); if (dispOpts.dispBlockLabel != rdbl) { fail = true; } if (dispOpts.dispBlockSize != rdbs) { fail = true; } if (fail) { ++failures; writefln ("# setDispBlockSize-fail: %s", l); writefln (" using:dbsstr:%s: bds:%.0f: bdi:%d: rdbl:%s: rdbs:%.0f:", dbsstr, bds, bdi, rdbl, rdbs); writefln (" expected: %s got %s", rdbl, dispOpts.dispBlockLabel); writefln (" expected: %.0f got %.0f", rdbs, dispOpts.dispBlockSize); } } initializeIdxs (); dispOpts.baseDispSize = size1024; dispOpts.baseDispIdx = idx1024; initializeDisplayTable (dispOpts); for (auto i = 0; i < displayTable.length; ++i) { test (format("%.0f", displayTable[i].size), false, format ("%.0f", displayTable[i].size), size1024, idx1024, displayTable[i].disp[1], displayTable[i].size); test (to!string(displayTable[i].key), false, to!string(displayTable[i].key), size1024, idx1024, displayTable[i].disp[1], displayTable[i].size); } test ("HUMAN", false, "HUMAN", size1024, idx1024, "Size", 0); dispOpts.baseDispSize = size1000; dispOpts.baseDispIdx = idx1000; initializeDisplayTable (dispOpts); for (auto i = 0; i < displayTable.length; ++i) { test (format("%.0f", displayTable[i].size), false, format ("%.0f", displayTable[i].size), size1000, idx1000, displayTable[i].disp[0], displayTable[i].size); test (to!string(displayTable[i].key), false, to!string(displayTable[i].key), size1000, idx1000, displayTable[i].disp[0], displayTable[i].size); } test ("HUMAN", false, "HUMAN", size1000, idx1000, "Size", 0); dispOpts.baseDispSize = size1000; dispOpts.baseDispIdx = idx1000; initializeDisplayTable (dispOpts); for (auto i = 0; i < displayTable.length; ++i) { test (format ("%sB", displayTable[i].key), false, format ("%sB", displayTable[i].key), size1024, idx1024, displayTable[i].disp[0], displayTable[i].size); } test ("2.5", false, "2.5", size1000, idx1000, "2b", 2); test ("2", false, "2", size1000, idx1000, "2b", 2); test ("2048", false, "2048", size1000, idx1000, "2048b", 2048); test ("2000", false, "2000", size1000, idx1000, "2K", 2000); dispOpts.baseDispSize = size1024; dispOpts.baseDispIdx = idx1024; initializeDisplayTable (dispOpts); for (auto i = 0; i < displayTable.length; ++i) { test (format ("%sb", displayTable[i].key), false, format ("%sb", displayTable[i].key), size1000, idx1000, displayTable[i].disp[1], displayTable[i].size); } test ("2.5", false, "2.5", size1024, idx1024, "2b", 2.0); test ("2", false, "2", size1024, idx1024, "2b", 2.0); test ("2048", false, "2048", size1024, idx1024, "2K", 2048.0); test ("2000", false, "2000", size1024, idx1024, "2000b", 2000.0); test ("Posix-1024", true, "k", size1024, idx1024, "1024-blocks", 1024.0); test ("Posix-512", true, "512", size1024, idx1024, "512-blocks", 512.0); if (failures > 0) { write ("unittest: display: setDispBlockSize: "); writefln ("failed: %d of %d", failures, tcount); } } void initializeDisplayTable (ref DisplayOpts dispOpts) { displayTable [0].size = 1; displayTable [0].low = 1; // temporary, reset below displayTable [0].high = dispOpts.baseDispSize; for (auto i = 1; i < displayTable.length; ++i) { if (displayTable [i].key == 'h') { break; } if (displayTable [i].key == 'H') { break; } displayTable [i].size = displayTable [i - 1].size * dispOpts.baseDispSize; displayTable [i].low = displayTable [i - 1].low * dispOpts.baseDispSize; displayTable [i].high = displayTable [i - 1].high * dispOpts.baseDispSize; } displayTable [0].low = 0; } void initializeIdxs () { if (! dispIdxsInitialized) { foreach (idx, dt; displayTable) { displayIdxs[dt.key] = idx; } dispIdxsInitialized = true; } if (! fmtInfoIdxsInitialized) { foreach (idx, fi; formatTypes) { formatTypesIdxs[fi.key] = idx; } fmtInfoIdxsInitialized = true; } } void setMaxLen (string val, ref int max) { int len = cast(int) val.length; if (len > max) { max = len; } } void initializeTitles (DisplayOpts dispOpts) { if (dispOpts.posixCompat) { formatTypes[formatTypesIdxs[FMT_MOUNT_FULL]].title = "Mounted On"; formatTypes[formatTypesIdxs[FMT_BLOCKS_AVAIL]].title = "Available"; formatTypes[formatTypesIdxs[FMT_BLOCKS_PERC_NOT_AVAIL]].title = "Capacity"; formatTypes[formatTypesIdxs[FMT_BLOCKS_PERC_USED]].title = "Capacity"; formatTypes[formatTypesIdxs[FMT_BLOCKS_PERC_USED_AVAIL]].title = "Capacity"; } } di-4.52/D/digetoptn.d0000644000175000017500000007045014421556642012510 0ustar bllbll// written in the D programming language module digetoptn; import std.variant; import std.string; import std.conv : to; debug (1) { import std.stdio; } version (unittest) { import std.stdio; import std.math; } import config; enum string endArgs = "--", longOptStart = "--"; enum char shortOptStart = '-', argAssign = '='; // enum getoptType {} doesn't seem to work. enum ubyte GETOPTN_LEGACY = 0, GETOPTN_MODERN = 1; alias ubyte getoptType; enum ubyte GETOPTN_BOOL = 1, GETOPTN_STRING = 2, GETOPTN_BYTE = 3, GETOPTN_SHORT = 4, GETOPTN_INT = 5, GETOPTN_LONG = 6, GETOPTN_DOUBLE = 7, GETOPTN_REAL = 8, GETOPTN_ALIAS = 9, GETOPTN_FUNC_NOARG = 10, GETOPTN_FUNC_ARG = 11, GETOPTN_IGNORE = 12; private struct ArgInfo { string arg; string argval; int asidx; // for short options; current position in arg str int avidx; // for short options; start of arg val size_t alen; bool longOptFlag; bool attachedArg; bool haveArg; }; struct OptInfo { getoptType otype; void * optval; void delegate (string option, string argval) odg; }; void goinit (ref OptInfo[string] oiaa, string option, getoptType otype, void *optval, void delegate (string option, string argval) odg) { OptInfo oi = { otype: otype, optval: optval, odg: odg }; oiaa[option] = oi; } int getoptn (getoptType gtype, string[] allargs, OptInfo[string] opts) { ArgInfo ainfo; int rv; debug (1) { foreach (k, arg; allargs) { writefln ("getoptn:args:%d:%s:", k, arg); } } with (ainfo) { outerfor: for (auto aidx = 1; aidx < allargs.length; ++aidx) { arg = allargs[aidx]; argval = null; attachedArg = false; haveArg = false; if (allargs.length > aidx + 1) { argval = allargs[aidx + 1]; } asidx = 1; avidx = 2; if (arg[0] != shortOptStart || arg == endArgs) { if (arg == endArgs) { ++aidx; } debug (1) { writefln ("getoptn:nomore:aidx:%d:", aidx); } rv = aidx - 1; // end of loop adds one break outerfor; } int rc = 0; longOptFlag = false; if (arg[0..2] == longOptStart) { longOptFlag = true; } alen = arg.length; // check if there's an = assignment... auto ival = indexOf (arg, argAssign); if (ival >= 0) { alen = ival; } debug (1) { writefln ("getoptn:%d:%s:%s:", aidx, arg, arg[0..alen]); } innerwhile: while (asidx < arg.length && arg[asidx] != '\0') { debug (1) { writefln ("getoptn:aidx:%d:asidx:%d:alen:%d:avidx:%d:arg:%s:", aidx, asidx, arg.length, avidx, arg); } rc = checkOption (gtype, ainfo, arg[0..alen], opts); debug (1) { writefln ("getoptn:co:rc:%d", rc); } rv = aidx; // end of loop adds one // if the option had an argument, process the next arg // otherwise, it was a boolean, and asidx is used. if (rc != 0) { aidx += rc - 1; // increment by rc less one, for loop will inc again rv = aidx; // end of loop adds one if (haveArg) { break innerwhile; } } // handles boolean --arg if (longOptFlag || gtype == GETOPTN_MODERN) { debug (1) { writefln ("getoptn:break inner:"); } break innerwhile; } ++asidx; ++avidx; } // while } // for } // with debug (1) { writefln ("getoptn:exit:%d:rv:%d", allargs.length, rv + 1); } return rv + 1; } private: version (unittest) { mixin template MgetoptTest(T) { void test (getoptType gtype, string l, bool expok, T[] res, T init, T[] expected, OptInfo[string] opts, string[] a, int wantrc) { for (auto i = 0; i < 4; ++i) { res[i] = init; } int idx; int fail = 0; ++tcount; a = ["dummy"] ~ a; try { idx = getoptn (gtype, a, opts); for (auto i = 0; i < 4; ++i) { if (expected[i] != res[i]) { fail = 1; debug (1) { writefln (" getoptn: %d: exp:%s:res:%s:", i, expected[i], res[i]); } } } if (idx != wantrc) { fail = 2; debug (1) { writefln (" getoptn:idx:%d:want:%d:", idx, wantrc); } } if (! expok) { fail = 3; debug (1) { writefln (" getoptn: expected failure"); } } } catch (Exception e) { if (expok) { writefln (" getoptn: expected success; got: %s", e.msg); fail = 4; } } if (fail) { ++failures; writefln ("# %s: fail: %s", testname, l); } } } } // for getopt(); unittest { int failures; int tcount; bool[4] rb; int[4] ri; long[4] rl; double[4] rd; real[4] rr; string testname = "getopt"; mixin MgetoptTest!bool tbool; mixin MgetoptTest!int tint; mixin MgetoptTest!double tdouble; OptInfo[string] opta; goinit (opta, "-a", GETOPTN_BOOL, cast(void *) &rb[0], null); goinit (opta, "-b", GETOPTN_BOOL, cast(void *) &rb[1], null); goinit (opta, "-c", GETOPTN_BOOL, cast(void *) &rb[2], null); goinit (opta, "-d", GETOPTN_BOOL, cast(void *) &rb[3], null); tbool.test (GETOPTN_LEGACY, "boolean bundled, no args", true, rb, false, [false,false,false,false], opta, [], 1); tbool.test (GETOPTN_LEGACY, "boolean bundled, all", true, rb, false, [true,true,true,true], opta, ["-abcd"], 2); tbool.test (GETOPTN_LEGACY, "boolean separate, all", true, rb, false, [true,true,true,true], opta, ["-a", "-b", "-c", "-d"], 5); tbool.test (GETOPTN_LEGACY, "boolean separate, bc", true, rb, false, [false,true,true,false], opta, ["-b", "-c"], 3); tbool.test (GETOPTN_LEGACY, "boolean separate, ad", true, rb, false, [true,false,false,true], opta, ["-a", "-d"], 3); tbool.test (GETOPTN_LEGACY, "boolean unrecognized option: bundled", false, rb, false, [true,true,true,true], opta, ["-abxd"], 0); OptInfo[string] optb; goinit (optb, "--testa", GETOPTN_BOOL, cast(void *) &rb[0], null); goinit (optb, "--testb", GETOPTN_BOOL, cast(void *) &rb[1], null); goinit (optb, "--testc", GETOPTN_BOOL, cast(void *) &rb[2], null); goinit (optb, "--testd", GETOPTN_BOOL, cast(void *) &rb[3], null); tbool.test (GETOPTN_LEGACY, "boolean long option", true, rb, false, [true,false,false,true], optb, ["--testa", "--testd"], 3); tbool.test (GETOPTN_LEGACY, "boolean check return idx", true, rb, false, [true,true,true,true], opta, ["-abcd"], 2); OptInfo[string] opte; goinit (opte, "-a", GETOPTN_INT, cast(void *) &ri[0], null); goinit (opte, "-b", GETOPTN_INT, cast(void *) &ri[1], null); goinit (opte, "-c", GETOPTN_INT, cast(void *) &ri[2], null); goinit (opte, "-d", GETOPTN_INT, cast(void *) &ri[3], null); tint.test (GETOPTN_LEGACY, "int separate, ad", true, ri, 0, [1,0,0,2], opte, ["-a", "1", "-d", "2"], 5); tint.test (GETOPTN_LEGACY, "int attached, ad", true, ri, 0, [1,0,0,2], opte, ["-a1", "-d2"], 3); tint.test (GETOPTN_LEGACY, "int non option stop arg", true, ri, 0, [1,0,0,0], opte, ["-a", "1", "3", "-d", "2"], 3); tint.test (GETOPTN_LEGACY, "int -- stop arg", true, ri, 0, [1,0,0,0], opte, ["-a", "1", "--", "-d", "2"], 4); tint.test (GETOPTN_LEGACY, "int attached non option stop arg", true, ri, 0, [1,0,0,0], opte, ["-a1", "3", "-d", "2"], 2); tint.test (GETOPTN_LEGACY, "int attached separate", true, ri, 0, [1,0,0,2], opte, ["-a1", "-d", "2"], 4); tint.test (GETOPTN_LEGACY, "int missing", false, ri, 0, [1,0,0,9], opte, ["-a1", "-d"], 0); OptInfo[string] optf; goinit (optf, "--testa", GETOPTN_INT, cast(void *) &ri[0], null); goinit (optf, "--testb", GETOPTN_INT, cast(void *) &ri[1], null); goinit (optf, "--testc", GETOPTN_INT, cast(void *) &ri[2], null); goinit (optf, "--testd", GETOPTN_INT, cast(void *) &ri[3], null); tint.test (GETOPTN_LEGACY, "int long options", true, ri, 0, [1,0,0,2], optf, ["--testa", "1", "--testd", "2"], 5); tint.test (GETOPTN_LEGACY, "int unrecognized long option", false, ri, 0, [999,0,0,999], optf, ["--testz", "1", "--testd", "2"], 0); tint.test (GETOPTN_LEGACY, "int unrecognized short option", false, ri, 0, [998,0,0,998], optf, ["-x", "1", "--testd", "2"], 0); if (failures > 0) { write ("unittest: digetopt: getoptn: "); writefln ("failed: %d of %d", failures, tcount); } } int checkOption (getoptType gtype, ref ArgInfo ainfo, string chkarg, OptInfo[string] opts) { string tchk = to!string(shortOptStart) ~ to!string(chkarg[ainfo.asidx]); debug (1) { writefln ("chk:%s:%s:%d", chkarg, tchk, opts.length); foreach (k, v; opts) { writefln (" chk:%s:", k); } } if (chkarg in opts || tchk in opts) { OptInfo opt; if (chkarg in opts) { opt = opts[chkarg]; debug (1) { writefln ("chk:found:%s:", chkarg); } } if (tchk in opts) { debug (1) { writefln ("chk:found:%s:", tchk); } opt = opts[tchk]; } if (opt.otype == GETOPTN_IGNORE) { debug (1) { writefln ("chk:ignore"); } return 1; } else if (opt.otype == GETOPTN_ALIAS) { debug (1) { writefln ("chk:alias:%s:", *(cast(string*)opt.optval)); } ainfo.asidx = 1; return checkOption (gtype, ainfo, *(cast(string*)opt.optval), opts); } else { debug (1) { writefln ("chk:do process"); writefln ("chk:proc:%s:%s:%d", ainfo.arg, chkarg, ainfo.asidx); } return processOption (gtype, ainfo, opt); } } string s = "Unrecognized option: " ~ ainfo.arg; throw new Exception(s); return 0; } version (unittest) { int docoTest (T) (getoptType gtype, string[] a, OptInfo[string] opts, bool expok, T init, ref T res, T expres, int expret, ref int rv) { int rc; int fail; ArgInfo ainfo; res = init; with (ainfo) { arg = a[0]; argval = null; attachedArg = false; haveArg = false; if (a.length > 1) { argval = a[1]; } asidx = 1; avidx = 2; alen = arg.length; auto ival = indexOf (arg, argAssign); if (ival >= 0) { alen = ival; } longOptFlag = false; if (arg[0..2] == longOptStart) { longOptFlag = true; } } try { rc = checkOption (gtype, ainfo, ainfo.arg[0..ainfo.alen], opts); rv = rc; if (rc != expret) { fail = 2; } if (expres != res) { fail = 1; } if (! expok) { fail = 3; } } catch (Exception e) { if (expok) { writefln (" getoptn: expected success; got: %s", e.msg); fail = 4; } } return fail; } mixin template MCOTest (T) { void test (T) (getoptType gtype, string label, string[] a, OptInfo[string] opts, bool expok, T init, ref T res, T expres, int expret) { int rv; ++tcount; auto fail = docoTest!(T) (gtype, a, opts, expok, init, res, expres, expret, rv); if (fail > 0) { ++failures; writefln ("# %s: fail: %s", testname, label); writefln (" expected ok : %d", expok); writefln (" fail return : %d", fail); writefln (" expected return: %s got %s", expret, rv); writefln (" expected value : %s got %s", expres, res); } } } } unittest { string testname = "chk"; int failures; int tcount; bool rb; mixin MCOTest!bool tbool; string rs; mixin MCOTest!string tstr; OptInfo[string] opta; goinit (opta, "-a", GETOPTN_BOOL, cast(void *) &rb, null); goinit (opta, "-b", GETOPTN_ALIAS, cast(void *) &"-a", null); tbool.test (GETOPTN_LEGACY, "co: alias: single", ["-b"], opta, true, false, rb, true, 1); OptInfo[string] optb; goinit (optb, "-a", GETOPTN_BOOL, cast(void *) &rb, null); goinit (optb, "-b", GETOPTN_ALIAS, cast(void *) &"-a", null); goinit (optb, "-c", GETOPTN_ALIAS, cast(void *) &"-b", null); tbool.test (GETOPTN_LEGACY, "co: alias: double", ["-c"], optb, true, false, rb, true, 1); OptInfo[string] optc; goinit (optc, "-a", GETOPTN_BOOL, cast(void *) &rb, null); goinit (optc, "-b", GETOPTN_ALIAS, cast(void *) &"-a", null); goinit (optc, "--clong", GETOPTN_ALIAS, cast(void *) &"-b", null); tbool.test (GETOPTN_LEGACY, "co: alias: long", ["--clong"], optc, true, false, rb, true, 1); OptInfo[string] optd; goinit (optd, "-a", GETOPTN_STRING, cast(void *) &rs, null); goinit (optd, "-b", GETOPTN_ALIAS, cast(void *) &"-a", null); tstr.test (GETOPTN_LEGACY, "co: alias: arg,=", ["-b=def"], optd, true, "abc", rs, "def", 1); OptInfo[string] opte; goinit (opte, "-a", GETOPTN_STRING, cast(void *) &rs, null); goinit (opte, "--blong", GETOPTN_ALIAS, cast(void *) &"-a", null); tstr.test (GETOPTN_LEGACY, "co: alias: long,arg,=", ["--blong=def"], opte, true, "abc", rs, "def", 1); OptInfo[string] optf; goinit (optf, "--along", GETOPTN_STRING, cast(void *) &rs, null); goinit (optf, "-b", GETOPTN_ALIAS, cast(void *) &"--along", null); tstr.test (GETOPTN_LEGACY, "co: alias: short,arg,=", ["-b=def"], optf, true, "abc", rs, "def", 1); OptInfo[string] optg; goinit (optg, "-a", GETOPTN_STRING, cast(void *) &rs, null); goinit (optg, "-b", GETOPTN_ALIAS, cast(void *) &"-a", null); tstr.test (GETOPTN_LEGACY, "co: alias: arg,sep", ["-b", "def"], optg, true, "abc", rs, "def", 2); OptInfo[string] opth; goinit (opth, "-a", GETOPTN_STRING, cast(void *) &rs, null); goinit (opth, "--blong", GETOPTN_ALIAS, cast(void *) &"-a", null); tstr.test (GETOPTN_LEGACY, "co: alias: long,arg,sep", ["--blong", "def"], opth, true, "abc", rs, "def", 2); OptInfo[string] opti; goinit (opti, "--along", GETOPTN_STRING, cast(void *) &rs, null); goinit (opti, "-b", GETOPTN_ALIAS, cast(void *) &"--along", null); tstr.test (GETOPTN_LEGACY, "co: alias: short,arg,sep", ["-b", "def"], opti, true, "abc", rs, "def", 2); if (failures > 0) { write ("unittest: digetopt: checkOption: "); writefln ("failed: %d of %d", failures, tcount); } } void checkHaveArg (in bool haveArg, in string oa) { if (! haveArg) { string s = "Missing argument for -" ~ oa; debug (1) { writefln ("** throwing %s", s); } throw new Exception(s); } } int processOption (getoptType gtype, ref ArgInfo ainfo, OptInfo opt) { int rc = 0; with (ainfo) { debug (1) { writefln ("## proc:arg:%s:", arg); } // if length != alen there is a =argval // if LEGACY && there's more string and not a boolean, then is argval debug (1) { writefln (" :otype:%d:alen:%d:len:%d:asidx:%d:avidx:%d:arg:%s:", opt.otype, alen, arg.length, asidx, avidx, arg); } if (opt.otype != GETOPTN_BOOL && arg.length != alen) { argval = arg[alen + 1..$]; // -...=val attachedArg = true; haveArg = true; debug (1) { writefln (" :att:=:%s:", argval); } } else if (gtype == GETOPTN_LEGACY && opt.otype != GETOPTN_BOOL && ! longOptFlag && arg.length > avidx) { argval = arg[avidx..$]; // short option -fval attachedArg = true; haveArg = true; debug (1) { writefln (" :att:legacy:%s:", argval); } } else if (opt.otype != GETOPTN_BOOL && argval != null) { haveArg = true; debug (1) { writefln (" :sep:%s:", argval); } } debug (1) { writefln (" :arg:%s:asidx:%d:avidx:%d:att:%d:have:%d:argval:%s:", arg, asidx, avidx, attachedArg, haveArg, argval); } if (opt.otype == GETOPTN_IGNORE) { ++rc; } else if (opt.otype == GETOPTN_BOOL) { *(cast(bool*)opt.optval) = 1 - *(cast(bool*)opt.optval); ++rc; } else if (opt.otype == GETOPTN_ALIAS) { return 1; } else if (opt.otype == GETOPTN_BYTE) { checkHaveArg (haveArg, arg); *(cast(byte*)opt.optval) = to!(byte)(argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_SHORT) { checkHaveArg (haveArg, arg); *(cast(short*)opt.optval) = to!(short)(argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_INT) { checkHaveArg (haveArg, arg); *(cast(int*)opt.optval) = to!(int)(argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_LONG) { checkHaveArg (haveArg, arg); *(cast(long*)opt.optval) = to!(long)(argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_DOUBLE) { checkHaveArg (haveArg, arg); *(cast(double*)opt.optval) = to!(double)(argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_REAL) { checkHaveArg (haveArg, arg); *(cast(real*)opt.optval) = to!(real)(argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_STRING) { checkHaveArg (haveArg, arg); *(cast(string*)opt.optval) = cast(string) argval; if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_FUNC_ARG) { opt.odg (arg, argval); if (! attachedArg) { ++rc; } ++rc; } else if (opt.otype == GETOPTN_FUNC_NOARG) { opt.odg (arg, argval); ++rc; } else { throw new Exception("Unhandled type passed to getopt()"); } } debug (1) { writefln (" :rc:%d:", rc); } return rc; } version (unittest) { int dopoTest (T) (getoptType gtype, string[] a, OptInfo opt, bool expok, T init, ref T res, T expres, int expret, ref int rv) { int rc; int fail; ArgInfo ainfo; res = init; with (ainfo) { arg = a[0]; argval = null; attachedArg = false; haveArg = false; if (a.length > 1) { argval = a[1]; } asidx = 1; avidx = 2; alen = arg.length; auto ival = indexOf (arg, argAssign); if (ival >= 0) { alen = ival; } longOptFlag = false; if (arg[0..2] == longOptStart) { longOptFlag = true; } } try { rc = processOption (gtype, ainfo, opt); rv = rc; if (rc != expret) { fail = 2; } if (expres != res) { fail = 1; } if (! expok) { fail = 3; } } catch (Exception e) { if (expok) { writefln (" getoptn: expected success; got: %s", e.msg); fail = 4; } } return fail; } mixin template MPOTest (T) { void test (T) (getoptType gtype, string label, string[] a, OptInfo opt, bool expok, T init, ref T res, T expres, int expret) { int rv; ++tcount; auto fail = dopoTest!(T) (gtype, a, opt, expok, init, res, expres, expret, rv); if (fail > 0) { ++failures; writefln ("# %s: fail: %s", testname, label); writefln (" expected ok : %d", expok); writefln (" fail return : %d", fail); writefln (" expected return: %s got %s", expret, rv); writefln (" expected value : %s got %s", expres, res); } } } mixin template MPOIntegerTest (T) { void test (string lab, getoptType otype) { T v; void tester (T) (getoptType gtype, string label, string[] a, OptInfo opt, bool expok, T init, ref T res, T expres, int expret) { int rv; ++tcount; auto fail = dopoTest!(T) (gtype, a, opt, expok, init, res, expres, expret, rv); if (fail > 0) { ++failures; writefln ("# %s: fail: %s", testname, label); writefln (" expected ok : %d", expok); writefln (" fail return : %d", fail); writefln (" expected return: %s got %s", expret, rv); writefln (" expected value : %s got %s", expres, res); } } OptInfo opt1 = { otype, cast(void *) &v, null }; tester (GETOPTN_LEGACY, lab ~ " leg,sopt,sep", ["-a", "1"], opt1, true, cast(T) 0, v, cast(T) 1, 2); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,att", ["-a1"], opt1, true, cast(T) 0, v, cast(T) 1, 1); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,=", ["-a=1"], opt1, true, cast(T) 0, v, cast(T) 1, 1); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,miss", ["-a"], opt1, false, cast(T) 0, v, cast(T) 0, 0); tester (GETOPTN_MODERN, lab ~ " mod,sopt,att", ["-a1"], opt1, false, cast(T) 0, v, cast(T) 0, 1); tester (GETOPTN_MODERN, lab ~ " mod,sopt,=", ["-a=1"], opt1, true, cast(T) 0, v, cast(T) 1, 1); OptInfo opt2 = { otype, cast(void *) &v, null }; tester (GETOPTN_MODERN, lab ~ " mod,lopt,=", ["--a=1"], opt2, true, cast(T) 0, v, cast(T) 1, 1); tester (GETOPTN_MODERN, lab ~ " mod,lopt,sep", ["--a", "1"], opt2, true, cast(T) 0, v, cast(T) 1, 2); tester (GETOPTN_MODERN, lab ~ " mod,lopt,miss", ["--a"], opt2, false, cast(T) 0, v, cast(T) 0, 1); tester (GETOPTN_MODERN, lab ~ " mod,lopt,att", ["--a1"], opt2, false, cast(T) 0, v, cast(T) 0, 1); tester (GETOPTN_LEGACY, lab ~ " mod,lopt,att", ["--a1"], opt2, false, cast(T) 0, v, cast(T) 0, 1); } } mixin template MPORealTest (T) { void test (string lab, getoptType otype) { T v; void tester (T) (getoptType gtype, string label, string[] a, OptInfo opt, bool expok, T init, ref T res, T expres, int expret) { int rv; ++tcount; auto fail = dopoTest!(T) (gtype, a, opt, expok, init, res, expres, expret, rv); if (fail > 0) { if (fail == 1 && fabs(expres - res) > 0.000001) { ++failures; writefln ("# %s: fail: %s", testname, label); writefln (" expected ok : %d", expok); writefln (" fail return : %d", fail); writefln (" expected return: %s got %s", expret, rv); } } } OptInfo opt1 = { otype, cast(void *) &v, null }; tester (GETOPTN_LEGACY, lab ~ " leg,sopt,sep", ["-a", "1.25"], opt1, true, cast(T) 0, v, cast(T) 1.25, 2); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,att", ["-a1.25"], opt1, true, cast(T) 0, v, cast(T) 1.25, 1); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,=", ["-a=1.25"], opt1, true, cast(T) 0, v, cast(T) 1.25, 1); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,miss", ["-a"], opt1, false, cast(T) 0, v, cast(T) 0, 0); tester (GETOPTN_MODERN, lab ~ " mod,sopt,att", ["-a1.25"], opt1, false, cast(T) 0, v, cast(T) 0, 1); tester (GETOPTN_MODERN, lab ~ " mod,sopt,=", ["-a=1.25"], opt1, true, cast(T) 0, v, cast(T) 1.25, 1); OptInfo opt2 = { otype, cast(void *) &v, null }; tester (GETOPTN_MODERN, lab ~ " mod,lopt,=", ["--a=1.25"], opt2, true, cast(T) 0, v, cast(T) 1.25, 1); tester (GETOPTN_MODERN, lab ~ " mod,lopt,sep", ["--a", "1.25"], opt2, true, cast(T) 0, v, cast(T) 1.25, 2); tester (GETOPTN_MODERN, lab ~ " mod,lopt,miss", ["--a"], opt2, false, cast(T) 0, v, cast(T) 0, 1); tester (GETOPTN_MODERN, lab ~ " mod,lopt,att", ["--a1.25"], opt2, false, cast(T) 0, v, cast(T) 0, 1); tester (GETOPTN_LEGACY, lab ~ " mod,lopt,att", ["--a1.25"], opt2, false, cast(T) 0, v, cast(T) 0, 1); } } mixin template MPOStringTest (T) { void test (string lab, getoptType otype) { T v; void tester (T) (getoptType gtype, string label, string[] a, OptInfo opt, bool expok, T init, ref T res, T expres, int expret) { int rv; ++tcount; auto fail = dopoTest!(T) (gtype, a, opt, expok, init, res, expres, expret, rv); if (fail > 0) { ++failures; writefln ("# %s: fail: %s", testname, label); writefln (" expected ok : %d", expok); writefln (" fail return : %d", fail); writefln (" expected return: %s got %s", expret, rv); writefln (" expected value : %s got %s", expres, res); } } OptInfo opt1 = { otype, cast(void *) &v, null }; tester (GETOPTN_LEGACY, lab ~ " leg,sopt,sep", ["-a", "abc"], opt1, true, cast(T) "def", v, cast(T) "abc", 2); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,att", ["-aabc"], opt1, true, cast(T) "def", v, cast(T) "abc", 1); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,=", ["-a=abc"], opt1, true, cast(T) "def", v, cast(T) "abc", 1); tester (GETOPTN_LEGACY, lab ~ " leg,sopt,miss", ["-a"], opt1, false, cast(T) "def", v, cast(T) "def", 0); tester (GETOPTN_MODERN, lab ~ " mod,sopt,att", ["-aabc"], opt1, false, cast(T) "def", v, cast(T) "def", 1); tester (GETOPTN_MODERN, lab ~ " mod,sopt,=", ["-a=abc"], opt1, true, cast(T) "def", v, cast(T) "abc", 1); OptInfo opt2 = { otype, cast(void *) &v, null }; tester (GETOPTN_MODERN, lab ~ " mod,lopt,=", ["--a=abc"], opt2, true, cast(T) "def", v, cast(T) "abc", 1); tester (GETOPTN_MODERN, lab ~ " mod,lopt,sep", ["--a", "abc"], opt2, true, cast(T) "def", v, cast(T) "abc", 2); tester (GETOPTN_MODERN, lab ~ " mod,lopt,miss", ["--a"], opt2, false, cast(T) "def", v, cast(T) "def", 1); tester (GETOPTN_MODERN, lab ~ " mod,lopt,att", ["--aabc"], opt2, false, cast(T) "def", v, cast(T) "def", 1); tester (GETOPTN_LEGACY, lab ~ " mod,lopt,att", ["--aabc"], opt2, false, cast(T) "def", v, cast(T) "def", 1); } } mixin template MPOFuncTest (T) { void test (getoptType gtype, string label, string[] a, OptInfo opt, bool expok, ref string res, string expres, int expret) { int rv; ++tcount; auto fail = dopoTest!string (gtype, a, opt, expok, null, res, expres, expret, rv); if (fail > 0) { ++failures; writefln ("# %s: fail: %s", testname, label); writefln (" expected ok : %d", expok); writefln (" fail return : %d", fail); writefln (" expected return: %s got %s", expret, rv); writefln (" expected value : %s got %s", expres, res); } } } } // for processOption() unittest { string testname = "proc"; int failures; int tcount; bool rb; mixin MPOTest!bool tbool; string rs; mixin MPOFuncTest!string tfunc; mixin MPOIntegerTest!byte tibyte; mixin MPOIntegerTest!short tishort; mixin MPOIntegerTest!int tiint; mixin MPOIntegerTest!long tilong; mixin MPORealTest!double trdouble; mixin MPORealTest!real trreal; mixin MPOStringTest!string tsstring; mixin MPOStringTest!(char[]) tschar; OptInfo opta = { GETOPTN_BOOL, cast(void *) &rb, null }; tbool.test (GETOPTN_LEGACY, "bool: leg,sopt,f->t", ["-a"], opta, true, false, rb, true, 1); tbool.test (GETOPTN_LEGACY, "bool: leg,sopt,t->f", ["-a"], opta, true, true, rb, false, 1); OptInfo optb = { GETOPTN_BOOL, cast(void *) &rb, null }; tbool.test (GETOPTN_MODERN, "bool: mod,lopt,t->f", ["--a"], optb, true, false, rb, true, 1); tbool.test (GETOPTN_MODERN, "bool: mod,lopt,f->t", ["--a"], optb, true, true, rb, false, 1); OptInfo optc = { GETOPTN_IGNORE, cast(void *) null, null }; tbool.test (GETOPTN_MODERN, "ingore: mod,lopt,f->t", ["--a"], optc, true, true, rb, true, 1); tibyte.test ("byte", GETOPTN_BYTE); tishort.test ("short", GETOPTN_SHORT); tiint.test ("int", GETOPTN_INT); tilong.test ("long", GETOPTN_LONG); trdouble.test ("double", GETOPTN_DOUBLE); trreal.test ("real", GETOPTN_REAL); tsstring.test ("string", GETOPTN_STRING); tschar.test ("char", GETOPTN_STRING); auto d1 = delegate (string arg, string val) { rs = arg; }; OptInfo optd = { GETOPTN_FUNC_NOARG, cast(void *) rs, d1 }; tfunc.test (GETOPTN_MODERN, "func: mod,noarg", ["-a", "def"], optd, true, rs, "-a", 1); auto d2 = delegate (string arg, string val) { rs = val; }; OptInfo opte = { GETOPTN_FUNC_ARG, cast(void *) rs, d2 }; tfunc.test (GETOPTN_MODERN, "func: mod,arg", ["-a", "def"] , opte, true, rs, "def", 2); if (failures > 0) { write ("unittest: digetopt: processOption: "); writefln ("failed: %d of %d", failures, tcount); } } di-4.52/D/dihelp.d0000644000175000017500000000412514421556642011754 0ustar bllbll// written in the D programming language module dihelp; import std.stdio; import config; import dilocale; void dispVersion () { writefln (DI_GT("di version %s Default Format: %s"), DI_VERSION, DI_DEFAULT_FORMAT); } void usage () { dispVersion (); /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ writeln (DI_GT("Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]")); writeln (DI_GT(" [-I include-fstyp-list] [file [...]]")); writeln (DI_GT(" -a : print all mounted devices")); writeln (DI_GT(" -d x : size to print blocks in (512 - POSIX, k - kbytes,")); writeln (DI_GT(" m - megabytes, g - gigabytes, t - terabytes, h - human readable).")); writeln (DI_GT(" -f x : use format string ")); writeln (DI_GT(" -I x : include only file system types in ")); writeln (DI_GT(" -x x : exclude file system types in ")); writeln (DI_GT(" -l : display local filesystems only")); writeln (DI_GT(" -n : don't print header")); writeln (DI_GT(" -t : print totals")); writeln (DI_GT(" Format string values:")); writeln (DI_GT(" m - mount point M - mount point, full length")); writeln (DI_GT(" b - total kbytes B - kbytes available for use")); writeln (DI_GT(" u - used kbytes c - calculated kbytes in use")); writeln (DI_GT(" f - kbytes free v - kbytes available")); writeln (DI_GT(" p - percentage not avail. for use 1 - percentage used")); writeln (DI_GT(" 2 - percentage of user-available space in use.")); writeln (DI_GT(" i - total file slots (i-nodes) U - used file slots")); writeln (DI_GT(" F - free file slots P - percentage file slots used")); writeln (DI_GT(" s - filesystem name S - filesystem name, full length")); writeln (DI_GT(" t - disk partition type T - partition type, full length")); writeln (DI_GT("See manual page for more options.")); } di-4.52/D/dispopts.d0000644000175000017500000000107314421556642012353 0ustar bllbll// written in the D programming language module dispopts; import std.stdio; import std.string; import config; enum real size1000 = 1000.0, size1024 = 1024.0; enum int idx1000 = 0, idx1024 = 1; struct DisplayOpts { bool posixCompat = false; real dispBlockSize = 0; real baseDispSize = size1024; int baseDispIdx = idx1024; short precision = 0; short width = 0; short inodeWidth = 0; string dbsstr = "H"; string dispBlockLabel; }; di-4.52/D/d.README0000644000175000017500000000251414421556642011444 0ustar bllblldi - disk information utility (version 4.32) This code is out of date and has not been updated to work with the latest D compiler. This code is out of date and has not been updated to match the current version of the C code. This code is in development. It is only included here as an example on how to use 'mkconfig' with the D language. 2012-10-19: gdc not tested. paths are not canonacalized. 2011-11-18: the code will not link without the second set of unittest blocks in options.d. No idea why. Apparently some sort of bug due to ???. 2012-1-17: Debian gdc-4.6.2-4 : same issue. 2012-1-26: FreeBSD : loss of precision somewhere and the values for zottas (and hence yobis) gets messed up. Got: 999999999999999983222784 Instead of: 1000000000000000000000000 This occurs with gcc-4.2.1 also, so it is a gcc bug on FreeBSD. Zones are not working; don't have a D compiler on Solaris. CHANGES 4.32 [18 Oct 2012] Change getErrno to errno. Rearranged diskpart.d class def. Cleanup. 4.31 [20 Nov 2011] Most command line arguments are working. Updated build system to mkconfig-1.19 COPYRIGHT Copyright 2011 Brad Lanam, Walnut Creek, CA, USA di-4.52/D/diskpart.d0000644000175000017500000003141214421556642012327 0ustar bllbll// written in the D programming language module diskpart; import std.stdio; import std.string; import std.conv : to; private import core.memory : GC; private import core.stdc.stdio; private import core.stdc.errno; import config; class DiskPartitions { public: struct DiskPartition { bool isRemote; bool isReadOnly; bool doPrint; bool isPooledFS; bool isLoopback; byte printFlag; ushort index; uint st_dev; // disk device number uint sp_dev; // special device number uint sp_rdev; // special rdev # real totalBlocks; real freeBlocks; real availBlocks; real blockSize; real totalInodes; real freeInodes; real availInodes; string name; // mount point string special; // special device name string fsType; // type of file system string mountOptions; string mountTime; void checkPartSizes () { if (this.freeBlocks < 0.0) { this.freeBlocks = 0.0; } if (this.availBlocks < 0.0) { this.availBlocks = 0.0; } if (this.totalInodes < 0.0) { this.freeInodes = 0.0; this.availInodes = 0.0; } } void initDiskPartition () { this.totalBlocks = 0.0; this.freeBlocks = 0.0; this.availBlocks = 0.0; this.totalInodes = 0.0; this.freeInodes = 0.0; this.availInodes = 0.0; } // for .st_dev enum DI_UNKNOWN_DEV = 0xFFFFFFFF; // for .printFlag enum byte DI_PRINT_OK = 0, DI_PRINT_IGNORE = 1, DI_PRINT_BAD = 2, DI_PRINT_OUTOFZONE = 3, DI_PRINT_EXCLUDE = 4, DI_PRINT_FORCE = 5, DI_PRINT_SKIP = 6; }; // struct DiskPartition public: DiskPartition[] diskPartitions; DiskPartition tot; this () {} this (int dbg) { this.debugLevel = dbg; } void setDebugLevel (int dbg) { debugLevel = dbg; } void getEntries () { static if (_clib_getmntent && _clib_setmntent && _clib_endmntent && ! _clib_getfsstat) { FILE * f; C_ST_mntent * mntEntry; static if (_c_args_setmntent == 1) { f = setmntent (toStringz(DI_MOUNT_FILE)); } else static if (_c_args_setmntent == 2) { f = setmntent (toStringz(DI_MOUNT_FILE), toStringz("r")); } if (f == cast(FILE *) null) { string s = format ("Unable to open %s errno %d", DI_MOUNT_FILE, errno()); throw new Exception (s); } scope (exit) { endmntent (f); } while ((mntEntry = getmntent (f)) != cast (C_ST_mntent *) null) { DiskPartition dp; dp.initDiskPartition; dp.special = to!(typeof(dp.special))(mntEntry.mnt_fsname); dp.name = to!(typeof(dp.special))(mntEntry.mnt_dir); dp.fsType = to!(typeof(dp.special))(mntEntry.mnt_type); if (dp.special == "none") { dp.printFlag = dp.DI_PRINT_IGNORE; } if (dp.fsType == "rootfs") { dp.printFlag = dp.DI_PRINT_IGNORE; } if (dp.fsType == MNTTYPE_IGNORE) { dp.printFlag = dp.DI_PRINT_IGNORE; } if (dp.fsType[0..2] == "nfs") { dp.isRemote = true; } /+ if ((devp = strstr (mntEntry->mnt_opts, "dev=")) != (char *) NULL) { if (devp != mntEntry->mnt_opts) { --devp; } *devp = 0; /* point to preceeding comma and cut off */ } if (chkMountOptions (mntEntry->mnt_opts, DI_MNTOPT_RO) != (char *) NULL) { diptr->isReadOnly = TRUE; } +/ dp.mountOptions = to!(typeof(dp.mountOptions))(mntEntry.mnt_opts); if (debugLevel > 5) { writefln ("mnt:%s - %s:%s: %d %d", dp.name, dp.special, dp.fsType, dp.printFlag, dp.isReadOnly); writefln (" %s", dp.mountOptions); } dp.index = indexCount++; diskPartitions ~= dp; } // while there are mount entries } // _clib_get/set/endmntent static if (_clib_getfsstat) { C_ST_statfs *mntbufp; // if (debug > 0) { printf ("# getDiskEntries: getfsstat\n"); } auto count = getfsstat (cast(C_ST_statfs *) null, cast(_c_arg_2_getfsstat_alias) 0, MNT_NOWAIT); if (count < 1) { // fprintf (stderr, "Unable to do getfsstat () errno %d\n", errno); return; } auto bufsize = C_ST_statfs.sizeof * cast(size_t)count; mntbufp = cast(C_ST_statfs*) GC.calloc (bufsize); count = getfsstat (mntbufp, cast(_c_arg_2_getfsstat_alias)bufsize, MNT_NOWAIT); for (auto idx = 0; idx < count; idx++) { DiskPartition dp; dp.initDiskPartition; auto sp = mntbufp + idx; copyCstring (dp.special, sp.f_mntfromname); copyCstring (dp.name, sp.f_mntonname); static if (_cmem_statfs_f_fstypename) { copyCstring (dp.fsType, sp.f_fstypename); // } else static if (_lib_sysfs && _cmem_statfs_f_type) { // char fbuff [DI_TYPE_LEN]; // sysfs (GETFSTYP, sp.f_type, fbuff); // copyCstring (dp.fsType, fbuff); // } else static if (_dcl_mnt_names && _cmem_statfs_f_type) { // ; } if (dp.fsType.length > 2 && dp.fsType[0..2] == "nfs") { dp.isRemote = true; } static if (_cdefine_MNT_RDONLY) { if ((sp.f_flags & MNT_RDONLY) == MNT_RDONLY) { dp.isReadOnly = TRUE; } } static if (_cdefine_MNT_LOCAL) { if ((sp.f_flags & MNT_LOCAL) != MNT_LOCAL) { dp.isRemote = TRUE; } } static if (_cmem_statfs_f_fsize) { dp.blockSize = sp.f_fsize; } else static if (_cmem_statfs_f_bsize) { dp.blockSize = sp.f_bsize; } dp.totalBlocks = cast(typeof(dp.totalBlocks)) sp.f_blocks * dp.blockSize; dp.freeBlocks = cast(typeof(dp.freeBlocks)) sp.f_bfree * dp.blockSize; dp.availBlocks = cast(typeof(dp.availBlocks)) sp.f_bavail * dp.blockSize; dp.totalInodes = sp.f_files; dp.freeInodes = sp.f_ffree; dp.availInodes = sp.f_ffree; dp.index = indexCount++; diskPartitions ~= dp; } GC.free (mntbufp); return; } /+ # if _dcl_mnt_names # if ! defined (MNT_NUMTYPES) # define MNT_NUMTYPES (sizeof(mnt_names)/sizeof(char *)) # endif # endif # define DI_UNKNOWN_FSTYPE "(%.2d)?" convertMountOptions ((long) sp->f_flags, diptr); # if _mem_struct_statfs_f_type # if defined (MOUNT_NFS3) if (sp->f_type == MOUNT_NFS3) { strncat (diptr->options, "v3,", DI_OPT_LEN - strlen (diptr->options) - 1); } # endif # endif # if _mem_struct_statfs_mount_info && \ defined (MOUNT_NFS) && \ (_mem_struct_statfs_f_type || _mem_struct_statfs_f_fstypename) # if _mem_struct_statfs_f_type if (sp->f_type == MOUNT_NFS # endif # if _mem_struct_statfs_f_fstypename if (strcmp (sp->f_fstypename, MOUNT_NFS) == 0 # endif # if _mem_struct_statfs_f_fstypename && defined (MOUNT_NFS3) || strcmp (sp->f_fstypename, MOUNT_NFS3) == 0 # endif # if _mem_struct_statfs_f_type && defined (MOUNT_NFS3) || sp->f_type == MOUNT_NFS3 # endif ) { struct nfs_args *na; na = &sp->mount_info.nfs_args; convertNFSMountOptions (na->flags, na->wsize, na->rsize, diptr); } # endif trimChar (diptr->options, ','); # if _dcl_mnt_names && _mem_struct_statfs_f_type fstype = sp->f_type; if ((fstype >= 0) && (fstype < MNT_NUMTYPES)) { strncpy (diptr->fsType, mnt_names [fstype], DI_TYPE_LEN); } else { Snprintf1 (diptr->fsType, sizeof (diptr->fsType), DI_UNKNOWN_FSTYPE, fstype); } # endif } +/ } void getPartitionInfo () { static if (_clib_statvfs && ! _clib_getfsstat) { C_ST_statvfs statBuf; foreach (ref dp; diskPartitions) { if (dp.printFlag == dp.DI_PRINT_OK || dp.printFlag == dp.DI_PRINT_SKIP || dp.printFlag == dp.DI_PRINT_FORCE) { if (statvfs (toStringz(dp.name), &statBuf) != 0) { string s = format ("statvfs: %s errno %d", dp.name, errno()); throw new Exception (s); } if (statBuf.f_frsize == 0 && statBuf.f_bsize != 0) { dp.blockSize = statBuf.f_bsize; } else { dp.blockSize = statBuf.f_frsize; } /* Linux! statvfs() returns values in f_bsize rather f_frsize. Bleah.*/ /* Non-POSIX! Linux manual pages are incorrect. */ static if (SYSTYPE == "Linux") { dp.blockSize = statBuf.f_bsize; } dp.totalBlocks = cast(typeof(dp.totalBlocks)) statBuf.f_blocks * dp.blockSize; dp.freeBlocks = cast(typeof(dp.freeBlocks)) statBuf.f_bfree * dp.blockSize; dp.availBlocks = cast(typeof(dp.availBlocks)) statBuf.f_bavail * dp.blockSize; dp.totalInodes = statBuf.f_files; dp.freeInodes = statBuf.f_ffree; dp.availInodes = statBuf.f_favail; static if (_cmem_statvfs_f_basetype) { if (dp.fsType.length == 0) { copyCstring (dp.fsType, statBuf.f_basetype); } } if (debugLevel > 5) { writefln ("part:%s: %.0f : %.0f %.0f %.0f", dp.name, dp.blockSize, dp.totalBlocks, dp.freeBlocks, dp.availBlocks); } } } } return; } void sortPartitions (ref size_t[] sortIndex, string sortType) { int gap; auto count = this.diskPartitions.length; if (count <= 1) { return; } gap = 1; while (gap < count) { gap = 3 * gap + 1; } for (gap /= 3; gap > 0; gap /= 3) { for (int i = gap; i < count; ++i) { auto tempIndex = sortIndex[i]; auto j = i - gap; while (j >= 0 && dpCompare (this.diskPartitions, sortType, sortIndex[j], tempIndex) > 0) { sortIndex[j+gap] = sortIndex[j]; j = j - gap; } j += gap; if (j != i) { sortIndex[j] = tempIndex; } } // insertion sort by gap size } // for gap size } // sortPartitions private: int dpCompare (ref DiskPartitions.DiskPartition[] dps, string sortType, size_t i, size_t j) { int rc; int sortOrder; /* reset sort order to the default start value */ sortOrder = DI_SORT_ASCENDING; rc = 0; foreach (char st; sortType) { switch (st) { case DI_SORT_NONE: { break; } case DI_SORT_MOUNT: { rc = strcoll (toStringz(dps[i].name), toStringz(dps[j].name)); rc *= sortOrder; break; } case DI_SORT_REVERSE: { sortOrder *= -1; break; } case DI_SORT_SPECIAL: { rc = strcoll (toStringz(dps[i].special), toStringz(dps[j].special)); rc *= sortOrder; break; } case DI_SORT_TYPE: { rc = strcoll (toStringz(dps[i].fsType), toStringz(dps[j].fsType)); rc *= sortOrder; break; } case DI_SORT_AVAIL: { auto v = dps[i].availBlocks - dps[j].availBlocks; rc = v < 0.00001 ? 0 : v > 0.0 ? 1 : -1; rc *= sortOrder; break; } default: { break; } } /* switch on sort type */ if (rc != 0) { return rc; } } return rc; } private: int debugLevel; short indexCount; static if (_cdefine__PATH_MOUNTED) { alias _PATH_MOUNTED DI_MOUNT_FILE; } else static if (_cdefine__PATH_MNTTAB) { alias _PATH_MNTTAB DI_MOUNT_FILE; } else static if (_cdefine_MOUNTED) { alias MOUNTED DI_MOUNT_FILE; } else static if (_cdefine_MNTTAB) { alias MNTTAB DI_MOUNT_FILE; } else { enum string DI_MOUNT_FILE = "/etc/mnttab"; } static if (! _cdefine_MNTTYPE_IGNORE) { enum string MNTTYPE_IGNORE = "ignore"; } void copyCstring (ref string a, char[] b) { auto l = strlen (b.ptr); a = to!(string)(b[0..l]); } enum char DI_SORT_NONE = 'n', DI_SORT_MOUNT = 'm', DI_SORT_SPECIAL = 's', DI_SORT_AVAIL = 'a', DI_SORT_REVERSE = 'r', DI_SORT_TYPE = 't', DI_SORT_ASCENDING = 1; }; // class DiskPartitions di-4.52/D/diquota.d0000644000175000017500000003702614421556642012163 0ustar bllbll// written in the D programming language module diquota; import std.stdio; import std.string; private import std.process : geteuid, getegid; private import core.stdc.errno; import config; import options; import diskpart; struct diQuota_t { string special; string name; string fsType; Uid_t uid; Gid_t gid; real limit; real used; real ilimit; real iused; } static if (_cdefine_BLOCK_SIZE) { alias BLOCK_SIZE DI_QUOT_BLOCK_SIZE; /* linux */ } else static if (_cdefine_DQBSIZE) { alias DQBSIZE DI_QUOT_BLOCK_SIZE; /* aix */ } else static if (_cdefine_DEV_BSIZE) { alias DEV_BSIZE DI_QUOT_BLOCK_SIZE; /* tru64, et. al. */ } else { enum size_t DI_QUOT_BLOCK_SIZE = 512; } /* rename certain structure members for portability */ static if (_cmem_dqblk_dqb_fsoftlimit) { alias dqb_fsoftlimit dqb_isoftlimit; } static if (_cmem_dqblk_dqb_fhardlimit) { alias dqb_fhardlimit dqb_ihardlimit; } static if (_cmem_dqblk_dqb_curfiles) { alias dqb_curfiles dqb_curinodes; } void checkDiskQuotas (ref DiskPartitions dps, Options opts) { int i; Uid_t uid; Gid_t gid; diQuota_t diqinfo; real tsize; uid = 0; gid = 0; static if (_has_std_quotas) { uid = geteuid (); gid = getegid (); } foreach (ref dp; dps.diskPartitions) { // if (! dp.doPrint) { // continue; // } diqinfo.uid = uid; diqinfo.gid = gid; diqinfo.name = dp.name; diqinfo.special = dp.special; diqinfo.fsType = dp.fsType; diquota (&diqinfo, opts); if (opts.debugLevel > 2) { writefln ("quota: %s limit: %f", dp.name, diqinfo.limit); writefln ("quota: tot: %f", dp.totalBlocks); writefln ("quota: %s used: %f", dp.name, diqinfo.used); writefln ("quota: avail: %f", dp.availBlocks); } if (diqinfo.limit != 0 && diqinfo.limit < dp.totalBlocks) { dp.totalBlocks = diqinfo.limit; tsize = diqinfo.limit - diqinfo.used; if (tsize < 0) { tsize = 0; } if (tsize < dp.availBlocks) { dp.availBlocks = tsize; dp.freeBlocks = tsize; if (opts.debugLevel > 2) { writefln ("quota: using quota for: total free avail"); } } else if (tsize > dp.availBlocks && tsize < dp.freeBlocks) { dp.freeBlocks = tsize; if (opts.debugLevel > 2) { writefln ("quota: using quota for: total free"); } } else { if (opts.debugLevel > 2) { writefln ("quota: using quota for: total"); } } } if (diqinfo.ilimit != 0 && diqinfo.ilimit < dp.totalInodes) { dp.totalInodes = diqinfo.ilimit; tsize = diqinfo.ilimit - diqinfo.iused; if (tsize < 0) { tsize = 0; } if (tsize < dp.availInodes) { dp.availInodes = tsize; dp.freeInodes = tsize; if (opts.debugLevel > 2) { writefln ("quota: using quota for inodes: total free avail"); } } else if (tsize > dp.availInodes && tsize < dp.freeInodes) { dp.freeInodes = tsize; if (opts.debugLevel > 2) { writefln ("quota: using quota for inodes: total free"); } } else { if (opts.debugLevel > 2) { writefln ("quota: using quota for inodes: total"); } } } } return; } void diquota (diQuota_t *diqinfo, Options opts) { int rc; int xfsflag; static if (_cstruct_dqblk) { C_ST_dqblk qinfo; char *qiptr; } static if (_cstruct_fs_disk_quota) { C_ST_fs_disk_quota xfsqinfo; } static if (_has_std_quotas) { int ucmd; int gcmd; } if (opts.debugLevel > 5) { writefln ("quota: diquota %s %s ", diqinfo.name, diqinfo.fsType); } rc = -1; xfsflag = FALSE; diqinfo.limit = 0; diqinfo.used = 0; diqinfo.ilimit = 0; diqinfo.iused = 0; if (diqinfo.fsType.length >= 3 && diqinfo.fsType[0..3] == "nfs" && diqinfo.fsType != "nfsd") { if (opts.debugLevel > 5) { writefln ("quota: diquota: nfs"); } static if (_has_std_nfs_quotas) { diquota_nfs (diqinfo, opts); } return; } if (diqinfo.fsType == "xfs") { if (opts.debugLevel > 5) { writefln ("quota: diquota: xfs"); } static if (_hdr_linux_dqblk_xfs) { ucmd = C_MACRO_QCMD (Q_XGETQUOTA, USRQUOTA); gcmd = C_MACRO_QCMD (Q_XGETQUOTA, GRPQUOTA); qiptr = cast(char *) &xfsqinfo; xfsflag = TRUE; } ; } else { static if (_has_std_quotas) { /* hp-ux doesn't have QCMD */ ucmd = Q_GETQUOTA; gcmd = Q_GETQUOTA; } static if (_cmacro_QCMD) { ucmd = C_MACRO_QCMD (Q_GETQUOTA, USRQUOTA); gcmd = C_MACRO_QCMD (Q_GETQUOTA, GRPQUOTA); } static if (_cstruct_dqblk) { qiptr = cast(char *) &qinfo; } } static if (_cdefine___FreeBSD__ && _t_FreeBSD__ == 5) { /* quotactl on devfs fs panics the system (FreeBSD 5.1) */ if (strcmp (diqinfo.fsType, "ufs") != 0) { return; } } if (opts.debugLevel > 5) { writefln ("quota: quotactl on %s (%s)", diqinfo.name, _c_arg_1_quotactl); } static if (_clib_quotactl && _c_arg_1_quotactl == "char *") { rc = quotactl (toStringz(diqinfo.name), ucmd, cast(int) diqinfo.uid, cast(caddr_t) qiptr); } static if (_clib_quotactl && _c_arg_2_quotactl == "char *") { /* AIX has linux compatibility routine, but still need name */ static if (_cdefine__AIX) { rc = quotactl (ucmd, toStringz(diqinfo.name), cast(int) diqinfo.uid, cast(caddr_t) qiptr); } else { rc = quotactl (ucmd, toStringz(diqinfo.special), cast(int) diqinfo.uid, cast(caddr_t) qiptr); } } static if (_sys_fs_ufs_quota) { /* Solaris */ { int fd; C_ST_quotctl qop; char tname [DI_NAME_LEN]; qop.op = Q_GETQUOTA; qop.uid = diqinfo.uid; qop.addr = cast(caddr_t) qiptr; strcpy (tname, diqinfo.name); strcat (tname, "/quotas"); fd = open (tname, O_RDONLY | O_NOCTTY); if (fd >= 0) { rc = ioctl (fd, Q_QUOTACTL, &qop); close (fd); } else { rc = fd; } } } /* _sys_fs_ufs_quota */ if (opts.debugLevel > 5) { writefln ("quota: quotactl on %s : rc %d : errno %d", diqinfo.name, rc, errno); } static if (_has_std_quotas) { di_process_quotas ("usr", diqinfo, rc, xfsflag, qiptr, opts); static if (_cdefine_GRPQUOTA) { if (rc == 0 || errno != ESRCH) { static if (_clib_quotactl && _c_arg_1_quotactl == "char *") { rc = quotactl (toStringz(diqinfo.name), gcmd, cast(int) diqinfo.gid, cast(caddr_t) qiptr); } static if (_clib_quotactl && _c_arg_1_quotactl != "char *") { rc = quotactl (gcmd, toStringz(diqinfo.special), cast(int) diqinfo.gid, cast(caddr_t) qiptr); } di_process_quotas ("grp", diqinfo, rc, xfsflag, qiptr, opts); } } /* _cdefine_GRPQUOTA */ } /* _has_std_quotas */ } static if (_has_std_nfs_quotas) { static if (_cdefine_RQ_PATHLEN) { alias RQ_PATHLEN DI_RQ_PATHLEN; } else { enum int DI_RQ_PATHLEN = 1024; } extern (C) { static C_TYP_bool_t xdr_quota_get (XDR *xp, C_ST_getquota_args *args) { if (! xdr_string (xp, &args.gqa_pathp, DI_RQ_PATHLEN)) { return 0; } if (! xdr_gqa_uid (xp, &args.gqa_uid)) { return 0; } return 1; } static C_TYP_bool_t xdr_quota_rslt (XDR *xp, C_ST_getquota_rslt *rslt) { C_ENUM_gqr_status quotastat; int intquotastat; C_ST_rquota *rptr; if (! xdr_int (xp, &intquotastat)) { return 0; } quotastat = cast(C_ENUM_gqr_status) intquotastat; static if (_cmem_getquota_rslt_gqr_status) { rslt.gqr_status = quotastat; } else { rslt.status = quotastat; } rptr = &rslt.gqr_rquota; if (! xdr_int (xp, &rptr.rq_bsize)) { return 0; } if (! xdr_bool (xp, &rptr.rq_active)) { return 0; } if (! xdr_rq_bhardlimit (xp, &rptr.rq_bhardlimit)) { return 0; } if (! xdr_rq_bsoftlimit (xp, &rptr.rq_bsoftlimit)) { return 0; } if (! xdr_rq_curblocks (xp, &rptr.rq_curblocks)) { return 0; } if (! xdr_rq_fhardlimit (xp, &rptr.rq_fhardlimit)) { return 0; } if (! xdr_rq_fsoftlimit (xp, &rptr.rq_fsoftlimit)) { return 0; } if (! xdr_rq_curfiles (xp, &rptr.rq_curfiles)) { return 0; } return (1); } } /* extern (C) */ static void diquota_nfs (diQuota_t *diqinfo, Options opts) { C_ST_CLIENT *rqclnt; C_ENUM_clnt_stat clnt_stat; C_ST_timeval timeout; string host; string path; char[] hostz; char[] pathz; C_ST_getquota_args args; C_ST_getquota_rslt result; C_ST_rquota *rptr; int quotastat; real tsize; if (opts.debugLevel > 5) { writefln ("quota: diquota_nfs"); } timeout.tv_sec = 2; timeout.tv_usec = 0; host = diqinfo.special; path = host; hostz = host.dup; auto idx = indexOf (host, ':'); if (idx != -1) { hostz[idx] = '\0'; ++idx; path = host[idx..$]; } pathz = path.dup; pathz ~= '\0'; if (opts.debugLevel > 5) { writefln ("quota: nfs: host: %s path: %s", host, path); writefln ("quota: nfs: hostz: %s pathz: %s", hostz, pathz); } args.gqa_pathp = pathz.ptr; args.gqa_uid = cast(C_TYP_gqa_uid) diqinfo.uid; rqclnt = clnt_create (hostz.ptr, cast(C_TYP_u_long) RQUOTAPROG, cast(C_TYP_u_long) RQUOTAVERS, toStringz("udp")); if (rqclnt == cast(CLIENT *) null) { if (opts.debugLevel > 2) { writefln ("quota: nfs: create failed %d", errno); } return; } rqclnt.cl_auth = authunix_create_default(); clnt_stat = C_MACRO_clnt_call (rqclnt, cast(C_TYP_u_long) RQUOTAPROC_GETQUOTA, cast(xdrproc_t) &xdr_quota_get, cast(caddr_t) &args, cast(xdrproc_t) &xdr_quota_rslt, cast(caddr_t) &result, timeout); if (clnt_stat != C_ENUM_clnt_stat.RPC_SUCCESS) { if (opts.debugLevel > 2) { writefln ("quota: nfs: not success: %d", cast(int) clnt_stat); } if (rqclnt.cl_auth) { C_MACRO_auth_destroy (rqclnt.cl_auth); } C_MACRO_clnt_destroy (rqclnt); return; } static if (_cmem_getquota_rslt_gqr_status) { quotastat = result.gqr_status; } else { quotastat = result.status; } if (quotastat == 1) { rptr = &result.gqr_rquota; if (opts.debugLevel > 2) { writefln ("quota: nfs: status 1"); writefln ("quota: nfs: rq_bsize: %d", rptr.rq_bsize); writefln ("quota: nfs: rq_active: %d", rptr.rq_active); } diqinfo.limit = rptr.rq_bhardlimit * rptr.rq_bsize; tsize = rptr.rq_bsoftlimit * rptr.rq_bsize; if (tsize != 0 && tsize < diqinfo.limit) { diqinfo.limit = tsize; } if (diqinfo.limit != 0) { diqinfo.used = rptr.rq_curblocks * rptr.rq_bsize; } diqinfo.ilimit = rptr.rq_fhardlimit; tsize = rptr.rq_fsoftlimit; if (tsize != 0 && tsize < diqinfo.ilimit) { diqinfo.ilimit = tsize; } if (diqinfo.ilimit != 0) { diqinfo.iused = rptr.rq_curfiles; } } if (rqclnt.cl_auth) { C_MACRO_auth_destroy (rqclnt.cl_auth); } C_MACRO_clnt_destroy (rqclnt); } } /* have rpc headers */ static if (_has_std_quotas) { static void di_process_quotas (string tag, diQuota_t *diqinfo, int rc, int xfsflag, char *cqinfo, Options opts) { real quotBlockSize = DI_QUOT_BLOCK_SIZE; real tsize; real tlimit; C_ST_dqblk *qinfo; static if (_cstruct_fs_disk_quota) { C_ST_fs_disk_quota *xfsqinfo; } if (opts.debugLevel > 5) { writefln ("quota: di_process_quotas"); } qinfo = cast(C_ST_dqblk *) cqinfo; if (xfsflag) { static if (_cstruct_fs_disk_quota) { xfsqinfo = cast(C_ST_fs_disk_quota *) cqinfo; } quotBlockSize = 512; } if (rc == 0) { tlimit = 0; if (xfsflag) { static if (_cstruct_fs_disk_quota) { tsize = xfsqinfo.d_blk_hardlimit; } ; } else { tsize = qinfo.dqb_bhardlimit; } if (opts.debugLevel > 2) { writefln ("quota: %s %s orig hard: %f", tag, diqinfo.name, tsize); } // OLD: tsize = tsize * quotBlockSize / diqinfo.blockSize; if (tsize != 0 && (tsize < diqinfo.limit || diqinfo.limit == 0)) { diqinfo.limit = tsize; tlimit = tsize; } if (xfsflag) { static if (_cstruct_fs_disk_quota) { tsize = xfsqinfo.d_blk_softlimit; } ; } else { tsize = qinfo.dqb_bsoftlimit; } if (opts.debugLevel > 2) { writefln ("quota: %s %s orig soft: %f", tag, diqinfo.name, tsize); } // OLD: tsize = tsize * quotBlockSize / diqinfo.blockSize; if (tsize != 0 && (tsize < diqinfo.limit || diqinfo.limit == 0)) { if (opts.debugLevel > 2) { writefln ("quota: using soft: %f", tsize); } diqinfo.limit = tsize; tlimit = tsize; } /* any quota set? */ if (tlimit == 0) { if (opts.debugLevel > 2) { writefln ("quota: %s %s no quota", tag, diqinfo.name); } return; } static if (_cmem_dqblk_dqb_curspace) { // OLD: tsize = qinfo.dqb_curspace / diqinfo.blockSize; if (tsize > diqinfo.used || diqinfo.used == 0) { diqinfo.used = tsize; } } static if (_cmem_dqblk_dqb_curblocks) { if (xfsflag) { static if (_cstruct_fs_disk_quota) { tsize = xfsqinfo.d_bcount; } ; } else { tsize = qinfo.dqb_curblocks; } // OLD: tsize = tsize * quotBlockSize / diqinfo.blockSize; if (tsize > diqinfo.used || diqinfo.used == 0) { diqinfo.used = tsize; } } if (opts.debugLevel > 2) { writefln ("quota: %s %s used: %f limit: %f", tag, diqinfo.name, diqinfo.used, diqinfo.limit); } if (xfsflag) { static if (_cstruct_fs_disk_quota) { tsize = xfsqinfo.d_ino_hardlimit; } ; } else { tsize = qinfo.dqb_ihardlimit; } if (tsize != 0 && (tsize < diqinfo.ilimit || diqinfo.ilimit == 0)) { diqinfo.ilimit = tsize; tlimit = tsize; } if (opts.debugLevel > 2) { writefln ("quota: %s %s i hard: %f", tag, diqinfo.name, tsize); } if (xfsflag) { static if (_cstruct_fs_disk_quota) { tsize = xfsqinfo.d_ino_softlimit; } ; } else { tsize = qinfo.dqb_isoftlimit; } if (tsize != 0 && (tsize < diqinfo.ilimit || diqinfo.ilimit == 0)) { diqinfo.ilimit = tsize; tlimit = tsize; } if (opts.debugLevel > 2) { writefln ("quota: %s %s i soft: %f", tag, diqinfo.name, tsize); } /* any quota set? */ if (tlimit == 0) { if (opts.debugLevel > 2) { writefln ("quota: %s %s no inode quota", tag, diqinfo.name); } return; } if (xfsflag) { static if (_cstruct_fs_disk_quota) { tsize = xfsqinfo.d_icount; } ; } else { tsize = qinfo.dqb_curinodes; } if (tsize > diqinfo.iused || diqinfo.iused == 0) { diqinfo.iused = tsize; } if (opts.debugLevel > 2) { writefln ("quota: %s %s i used: %f", tag, diqinfo.name, tsize); } } else { if (opts.debugLevel > 2) { writefln ("quota: %s %s errno %d", tag, diqinfo.name, errno); } } } } /* _has_std_quotas */ di-4.52/MANIFEST0000644000175000017500000000620314421556642011307 0ustar bllbllC/ C di source C/Makefile C Makefile C/configs/ stand-alone configuration files. C/configs/config.mingw config.h for Windows (MinGW) C/configs/config.vms config.h for VMS C/configs/config.vms.b alternate config.h for VMS C/configs/config.cygwin.gcc config.h for Windows cygwin-gcc C/di-example.tcl example tcl script C/di.c di source C/di.h di source C/dimain.c di source C/dimain.h di source C/didiskutil.c di source C/digetentries.c di source C/digetinfo.c di source C/dimntopt.h di source C/diquota.c di source C/display.c di source C/display.h di source C/mkc_config/ di configuration C/mkc_config/di-env.mkc environment configuration C/mkc_config/di-env-shared.mkc tcl environment configuration C/mkc_config/di-getoptn.mkc getoptn test configuration C/mkc_config/di.mkc mkconfig configuration C/mkc_config/di-tcl.mkc additional tcl configuration C/getoptn.c di source C/getoptn.h di source C/options.c di source C/options.h di source C/realloc.c di source C/strdup.c di source C/strstr.c di source C/tcldiskspace.c tcl interface script C/Perl/ perl interface C/Perl/Changes C/Perl/README C/Perl/ex/ C/Perl/ex/perl-example.pl C/Perl/t/ C/Perl/t/diskspace.t C/Perl/MANIFEST C/Perl/di.xs C/Perl/Makefile.PL C/Perl/lib/ C/Perl/lib/Filesys/ C/Perl/lib/Filesys/di.pm C/Perl/ppport.h C/tests.d/ regression tests for di C/tests.d/buildpl.sh C/tests.d/compshpl.sh C/tests.d/env.sh C/tests.d/getoptn.sh C/tests.d/getoptn.txt C/tests.d/rpmbuild.sh C/tests.d/test_order C/trimchar.c di source C/version.h di source D/ D di source D/Makefile D Makefile D/d.README D source README D/di.d di source D/digetoptn.d di source D/dihelp.d di source D/dilocale.d di source D/diquota.d di source D/diskpart.d di source D/display.d di source D/dispopts.d di source D/features/ di configuration D/features/env.dat environment configuration D/features/mkconfig.dat mkconfig configuration D/options.d di source ChangeLog.txt Change Log LICENSE License MANIFEST This file Makefile Top Level Makefile README.txt Read This di.1 di Manual Page di.spec rpmspec file features/ features/checkbuild.dat features/checkinstall.dat features/checkperlbuild.dat features/dioptions.dat di options mktar.sh Creates the tar file po/ internationalization po/de.po po/en.po po/es.po tests.d/ regression tests for di tests.d/buildsh.sh tests.d/diarg.sh tests.d/diexec.sh tests.d/diinst.sh tests.d/dinls.sh tests.d/disort.sh tests.d/ditot.sh tests.d/test_order di-4.52/C/0000755000175000017500000000000014421556642010337 5ustar bllblldi-4.52/C/mkc_config/0000755000175000017500000000000014421556642012436 5ustar bllblldi-4.52/C/mkc_config/di.mkc0000644000175000017500000002000714421556642013525 0ustar bllbll# # Copyright 2006-2018 Brad Lanam, Walnut Creek, California USA # # option-file ../dioptions.dat loadunit c-main loadunit c-include-conflict output config.h standard hdr ctype.h hdr dcdef.h hdr descrip.h hdr dirent.h hdr dvidef.h hdr dvsdef.h hdr errno.h hdr fcntl.h hdr fshelp.h hdr gui/window.h hdr jfs/quota.h hdr kernel/fs_info.h hdr limits.h hdr linux/dqblk_xfs.h # aix 5 doesn't declare their own, use the compatibility version hdr linux/quota.h hdr libintl.h hdr libprop/proplib.h hdr locale.h hdr malloc.h hdr mcheck.h hdr memory.h hdr mntent.h hdr mnttab.h # NetBSD hdr quota.h hdr rpc/rpc.h hdr rpcsvc/rquota.h hdr ssdef.h hdr starlet.h hdr storage/Directory.h hdr storage/Entry.h hdr storage/Path.h # syllable: broken design, broken header hdr storage/volumes.h gui/window.h hdr string.h hdr strings.h hdr time.h hdr ufs/quota.h hdr ufs/ufs/quota.h hdr unistd.h hdr util/string.h hdr wchar.h hdr windows.h hdr winioctl.h windows.h hdr zone.h sys dcmd_blk.h sys file.h sys fs_types.h sys fs/ufs_quota.h sys fstyp.h sys fstypes.h sys ftype.h sys io.h sys mntctl.h # SCO OpenServer/UnixWare require sys/mnttab.h for struct mnttab declaration. sys mntent.h sys/mnttab.h sys mnttab.h sys mount.h sys quota.h sys stat.h sys statfs.h sys statvfs.h sys time.h sys vfs.h sys vfs_quota.h sys vfstab.h sys vmount.h include_conflict time.h sys/time.h include_conflict sys/quota.h linux/quota.h command msgfmt gmsgfmt # rpmbuild used for regression tests command rpmbuild const O_NOCTTY define bcopy define bzero define IOCTL_STORAGE_CHECK_VERIFY2 define MCTL_QUERY define memcpy define memset define QCMD define S_ISLNK typ struct dqblk typ struct quotaval typ struct ufs_dqblk typ fs_disk_quota_t typ gid_t typ statvfs_t typ size_t typ uint_t typ uid_t lib bcopy lib bindtextdomain -lintl, -lintl -liconv lib bzero lib CreateFile lib DeviceIoControl # unknown if -lsun, -lseq are needed (old irix, sequent) lib endmntent -lsun, -lseq lib fs_stat_dev lib fshelp lib GetDiskFreeSpace lib GetDiskFreeSpaceEx lib GetDriveType lib getfsstat lib GetLogicalDriveStrings lib GetVolumeInformation lib getmnt # unixware put getmntent into libgen for some reason # -lsun, -lseq are untested (old irix, sequent) lib getmntent -lgen, -lsun, -lseq lib getmntinfo lib gettext -lintl, -lintl -liconv lib getvfsstat lib getzoneid lib hasmntopt lib lstat lib mbrlen lib mcheck_pedantic -lmcheck lib memcpy lib memset # AIX doesn't declare this :( # Look for MCTL_QUERY (see below) lib mntctl lib next_dev # dragonflybsd; need this to get the library lib prop_dictionary_create -lprop # quota_open is a new interface from NetBSD lib quota_open -lquota -lrpcsvc lib quotactl lib realpath lib setlocale -lintl, -lintl -liconv # unknown if -lsun, -lseq are needed (old irix, sequent) lib setmntent -lsun, -lseq lib snprintf -lsnprintf lib statfs lib statvfs lib strcoll lib strdup lib strstr # VMS lib sys_dollar_device_scan # VMS lib sys_dollar_getdviw lib sysfs lib textdomain -lintl, -lintl -liconv # dragonflybsd lib vquotactl # need this to get the optional library lib xdr_int -lnsl lib zone_getattr lib zone_list # get the correct xdr types... memberxdr rquota rq_bhardlimit memberxdr rquota rq_bsoftlimit memberxdr rquota rq_curblocks memberxdr rquota rq_fhardlimit memberxdr rquota rq_fsoftlimit memberxdr rquota rq_curfiles memberxdr getquota_args gqa_uid # to prevent warnings # some systems are u_int, size_t, u_long args noconst getfsstat args noconst getvfsstat args noconst quotactl setint _quotactl_pos_1 0 setint _quotactl_pos_2 0 if quotactl_pos_1 == _c_arg_1_quotactl 'char *' setint _quotactl_pos_1 1 endif if quotactl_pos_2 == _c_arg_2_quotactl 'char *' setint _quotactl_pos_2 1 endif if quotactl_pos_2 == _c_arg_2_quotactl 'caddr_t' setint _quotactl_pos_2 1 endif args noconst setmntent args noconst statfs class os::Volumes -lsyllable npt getenv npt getmnt npt mntctl npt quotactl npt statfs _lib_statfs dcl int errno dcl ptr mnt_names member struct dqblk dqb_curspace member struct dqblk dqb_curblocks member struct dqblk dqb_fhardlimit member struct dqblk dqb_fsoftlimit member struct dqblk dqb_curfiles member struct getquota_rslt gqr_status member struct getquota_rslt gqr_rquota member struct mnttab mt_mntopts member struct statfs f_bsize member struct statfs f_fsize member struct statfs f_fstyp member struct statfs f_iosize member struct statfs f_frsize member struct statfs f_fstypename member struct statfs mount_info member struct statfs f_type member struct statvfs f_basetype size long long size long double if have_long_double ( ( == _siz_long_double 8 ) || ( == _siz_long_double 16 ) ) printf_long_double else setint _printf_long_double 0 endif # workaround for AIX # mntctl() is not declared if AIX_mntctl _sys_vmount && _define_MCTL_QUERY set _lib_mntctl 1 endif # dragonflybsd may have vquotactl, but it may not be turned on. if DFLYBSD_vquotactl _lib_vquotactl grep DFLYBSD_vquota vfs.quota_enabled=.*1 /boot/loader.conf if DFLYBSD_vquota_chk ! _grep_DFLYBSD_vquota set _lib_vquotactl 0 set _lib_prop_dictionary_create 0 endif endif if stdquotas ( _lib_quotactl || _lib_quota_open || _lib_vquotactl || \ _typ_struct_dqblk || _typ_struct_ufs_dqblk ) setint _has_std_quotas 1 else setint _has_std_quotas 0 endif if stdnfsquotas _hdr_rpc_rpc && _hdr_rpcsvc_rquota && _lib_xdr_int && \ _memberxdr_rquota_rq_bhardlimit && _memberxdr_getquota_args_gqa_uid setint _has_std_nfs_quotas 1 else setint _has_std_nfs_quotas 0 endif ifoption MCHECK if mcheckexists _hdr_mcheck && _lib_mcheck_pedantic setint _use_mcheck 1 else setint _use_mcheck 0 endif else setint _use_mcheck 0 endif ifnotoption NLS set _lib_bindtextdomain 0 set _lib_gettext 0 set _lib_setlocale 0 set _lib_textdomain 0 set _hdr_libintl 0 set _hdr_locale 0 set _command_msgfmt 0 endif if hasnls _lib_bindtextdomain && _lib_gettext && _lib_setlocale && \ _lib_textdomain && _hdr_libintl && _hdr_locale && \ _command_msgfmt setint _enable_nls 1 else set _lib_bindtextdomain 0 set _lib_gettext 0 set _lib_setlocale 0 set _lib_textdomain 0 set _hdr_libintl 0 set _hdr_locale 0 set _command_msgfmt 0 setint _enable_nls 0 endif ifnotoption WINAPI set _hdr_windows 0 set _hdr_winioctl 0 set _lib_CreateFile 0 set _lib_DeviceIoControl 0 set _lib_GetDiskFreeSpace 0 set _lib_GetDiskFreeSpaceEx 0 set _lib_GetDriveType 0 set _lib_GetLogicalDriveStrings 0 set _lib_GetVolumeInformation 0 endif # see dioptions.dat to change these option DI_DEFAULT_FORMAT smbuvpT option DI_DEFAULT_DISP_SIZE H include #if _typ_statvfs_t # define Statvfs_t statvfs_t #else # define Statvfs_t struct statvfs #endif #if _typ_size_t # define Size_t size_t #else # define Size_t unsigned int #endif #if _typ_uint_t # define Uint_t uint_t #else # define Uint_t unsigned int #endif #if _typ_uid_t # define Uid_t uid_t #else # define Uid_t int #endif #if _typ_gid_t # define Gid_t gid_t #else # define Gid_t int #endif /* Do this the old-fashioned way for old compilers */ /* Have to work around MacOSX's snprintf macro. */ #if _lib_snprintf # define Snprintf1 snprintf # define Snprintf2 snprintf # define Snprintf3 snprintf # define Snprintf4 snprintf #else # define Snprintf1(a1,a2,a3,a4) sprintf(a1,a3,a4) # define Snprintf2(a1,a2,a3,a4,a5) sprintf(a1,a3,a4,a5) # define Snprintf3(a1,a2,a3,a4,a5,a6) sprintf(a1,a3,a4,a5,a6) # define Snprintf4(a1,a2,a3,a4,a5,a6,a7) sprintf(a1,a3,a4,a5,a6,a7) #endif #if ! _lib_strcoll # define strcoll strcmp #endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif endinclude di-4.52/C/mkc_config/di-env.mkc0000644000175000017500000000344214421556642014317 0ustar bllblloption-file ../dioptions.dat loadunit env-main loadunit env-systype loadunit env-cc loadunit env-msgfmt loadunit env-extension output di.env standard_system standard_cc addcflag -fno-common addcflag -Wextra addcflag -Wno-unused-but-set-variable addcflag -Wno-unused-parameter addcflag -Wno-unknown-pragmas addcflag -Wno-float-equal addcflag -Wno-shift-sign-overflow addcflag -Wno-stringop-overflow addcflag -Wno-stringop-truncation # turn off mac os warning addcflag -Wno-poison-system-directories # gcc hardening # reference: wiki.debian.org/Hardening addcflag -Wformat addcflag -Wformat-security addcflag -Werror=format-security # these confuse other compilers...make them GCC only # solaris will not link w/-fstack-protector, so it # can only be set when the gnu linker is in use. if UsingGNU_LD == _MKCONFIG_USING_GNU_LD Y && == _MKCONFIG_USING_GCC Y ifnotoption NO_PIE # gcc hardening # reference: wiki.debian.org/Hardening addcflag -D_FORTIFY_SOURCE=2 addcflag -fstack-protector-strong addcflag -fstack-protector-all addcflag -fPIE addldflag -fstack-protector-strong addldflag -fstack-protector-all addldflag -pie addldflag -Wl,-pie addldflag -Wl,-z,relro addldflag -Wl,-z,now else addcflag -D_FORTIFY_SOURCE=0 endif endif # these confuse other compilers...make them CLANG only if UsingCLANG == _MKCONFIG_USING_CLANG Y addcflag -Werror,-Wunused-command-line-argument ifnotoption NO_PIE # gcc hardening # reference: wiki.debian.org/Hardening addcflag -D_FORTIFY_SOURCE=2 addcflag -fstack-protector-strong addcflag -fstack-protector-all addldflag -fstack-protector-strong addldflag -fstack-protector-all addcflag -DPIE addcflag -fPIE addldflag -pie addldflag -Wl,-pie else addcflag -D_FORTIFY_SOURCE=0 endif endif libs extension obj extension exe cmd_msgfmt di-4.52/C/mkc_config/di-getoptn.mkc0000644000175000017500000000045514421556642015210 0ustar bllbll# # Copyright 2006-2018 Brad Lanam, Walnut Creek, California USA # # loadunit c-main output gconfig.h standard hdr string.h hdr strings.h hdr math.h lib fabs -lm typ size_t include #if _typ_size_t # define Size_t size_t #else # define Size_t unsigned int #endif endinclude di-4.52/C/mkc_config/di-env-shared.mkc0000644000175000017500000000365014421556642015564 0ustar bllblloption-file ../dioptions.dat loadunit env-main loadunit env-systype loadunit env-cc loadunit env-msgfmt loadunit env-extension output di-shared.env standard_system standard_cc # needed for tcl build addcflag -fPIC # standard flags addcflag -Wextra addcflag -Wno-unused-but-set-variable addcflag -Wno-unused-parameter addcflag -Wno-unknown-pragmas addcflag -Wno-float-equal addcflag -Wno-shift-sign-overflow addcflag -Wno-stringop-overflow addcflag -Wno-stringop-truncation # turn off mac os warning addcflag -Wno-poison-system-directories # gcc hardening # reference: wiki.debian.org/Hardening addcflag -Wformat addcflag -Wformat-security addcflag -Werror=format-security # these confuse other compilers...make them GCC only # solaris will not link w/-fstack-protector, so it # can only be set when the gnu linker is in use. if UsingGNU_LD ( == _MKCONFIG_USING_GNU_LD Y ) && ( == _MKCONFIG_USING_GCC Y ) ifnotoption NO_PIE addcflag -fstack-protector-strong addcflag -fstack-protector-all addldflag -fstack-protector-strong addldflag -fstack-protector-all addcflag -D_FORTIFY_SOURCE=2 else addcflag -D_FORTIFY_SOURCE=0 endif endif # these confuse other compilers...make them CLANG only if UsingCLANG == _MKCONFIG_USING_CLANG Y addcflag -Werror,-Wunused-command-line-argument ifnotoption NO_PIE addcflag -fstack-protector-strong addcflag -fstack-protector-all addldflag -fstack-protector-strong addldflag -fstack-protector-all addcflag -D_FORTIFY_SOURCE=2 else addcflag -D_FORTIFY_SOURCE=0 endif endif libs cflags_shared ldflags_shared sharednameflag shareexeclinkflag sharerunpathflag addldflag -Wl,--as-needed pkg include tcl pkg libs tcl # windows does not include the pkg-config files. if not_have_pkg_libs_tcl ! _pkg_libs_tcl findconfig tclConfig addconfig TCL_STUB_LIB_SPEC ldflags_libs_application addconfig TCL_INCLUDE_SPEC cflags_application endif extension obj extension exe cmd_msgfmt extension shlib di-4.52/C/mkc_config/di-tcl.mkc0000644000175000017500000000017014421556642014304 0ustar bllblloption-file ../dioptions.dat loadunit c-main output configtcl.h hdr tcl.h lib Tcl_InitStubs -DUSE_TCL_STUBS di-4.52/C/display.h0000644000175000017500000000076414421556642012164 0ustar bllbll#ifndef DI_INC_DISPLAY_H #define DI_INC_DISPLAY_H /* * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" # if defined (__cplusplus) || defined (c_plusplus) extern "C" { # endif /* display.c */ extern char *printDiskInfo (diData_t *); extern void sortArray (diOptions_t *, diDiskInfo_t *, int, int); extern const char *getPrintFlagText (int); # if defined (__cplusplus) || defined (c_plusplus) } # endif #endif /* DI_INC_DISPLAY_H */ di-4.52/C/options.c0000644000175000017500000006445414421556642012213 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #include "getoptn.h" #include "options.h" #include "version.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _hdr_ctype # include #endif #if _hdr_errno # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _hdr_libintl # include #endif #if _use_mcheck # include #endif struct pa_tmp { diData_t *diData; diOptions_t *diopts; diOutput_t *diout; char *dbsstr; Size_t dbsstr_sz; }; typedef struct { _print_size_t size; const char *disp[2]; } dispTable_t; static dispTable_t dispTable [] = { { (_print_size_t) 0.0, { "KBytes", "KBytes" } }, { (_print_size_t) 0.0, { "Megs", "Mebis" } }, { (_print_size_t) 0.0, { "Gigs", "Gibis" } }, { (_print_size_t) 0.0, { "Teras", "Tebis" } }, { (_print_size_t) 0.0, { "Petas", "Pebis" } }, { (_print_size_t) 0.0, { "Exas", "Exbis" } }, { (_print_size_t) 0.0, { "Zettas", "Zebis" } }, { (_print_size_t) 0.0, { "Yottas", "Yobis" } } }; #define DI_DISPTAB_SIZE (sizeof (dispTable) / sizeof (dispTable_t)) #define DI_ARGV_SEP " " /* space, tab */ #define DI_MAX_ARGV 50 #define DI_LIST_SEP "," #define DI_POSIX_FORMAT "SbuvpM" #define DI_DEF_MOUNT_FORMAT "MST\n\tO" #define DI_ALL_FORMAT "MTS\n\tO\n\tbuf13\n\tbcvpa\n\tBuv2\n\tiUFP" # if defined (__cplusplus) || defined (c_plusplus) extern "C" { # endif extern int debug; static void processStringArgs _((const char *, char *, diData_t *, char *)); static int processArgs _((int, const char * const [], diData_t *, char *, Size_t)); static int parseList _((iList_t *, char *)); static void processOptions _((const char *, char *)); static void processOptionsVal _((const char *, char *, char *)); static void usage _((void)); static void setDispBlockSize _((char *, diOptions_t *, diOutput_t *)); static void initDisplayTable _((diOptions_t *)); static void setExitFlag _((diOptions_t *, unsigned int)); # if defined (__cplusplus) || defined (c_plusplus) } # endif static void processStringArgs (const char *progname, char *ptr, diData_t *diData, char *dbsstr) { char *dptr; char *tptr; int nargc; const char *nargv [DI_MAX_ARGV]; diOptions_t *diopts; if (ptr == (char *) NULL || strcmp (ptr, "") == 0) { return; } diopts = &diData->options; dptr = (char *) NULL; dptr = strdup (ptr); if (dptr == (char *) NULL) { fprintf (stderr, "strdup failed in main() (1). errno %d\n", errno); setExitFlag (diopts, DI_EXIT_FAIL); return; } if (dptr != (char *) NULL) { int optidx; tptr = strtok (dptr, DI_ARGV_SEP); nargc = 1; nargv[0] = progname; while (tptr != (char *) NULL) { if (nargc >= DI_MAX_ARGV) { break; } nargv[nargc++] = tptr; tptr = strtok ((char *) NULL, DI_ARGV_SEP); } optidx = processArgs (nargc, nargv, diData, dbsstr, sizeof (dbsstr) - 1); if (optidx < nargc) { fprintf (stderr, "%s: unknown data found in DI_ARGS: %s\n", progname, nargv [optidx]); diopts->errorCount += 1; if (diopts->errorCount > 0) { setExitFlag (diopts, DI_EXIT_WARN); } } free ((char *) dptr); } } int getDIOptions (int argc, const char * const argv[], diData_t *diData) { const char * argvptr; char * ptr; char dbsstr [30]; int optidx; int ec; diOptions_t *diopts; diOutput_t *diout; diopts = &diData->options; diout = &diData->output; strncpy (dbsstr, DI_DEFAULT_DISP_SIZE, sizeof (dbsstr)); /* default */ ec = 0; argvptr = argv [0] + strlen (argv [0]) - 2; if (memcmp (argvptr, "mi", (Size_t) 2) == 0) { diopts->formatString = DI_DEF_MOUNT_FORMAT; } else /* don't use DIFMT env var if running mi. */ { if ((ptr = getenv ("DIFMT")) != (char *) NULL) { diopts->formatString = ptr; } } /* gnu df */ if ((ptr = getenv ("POSIXLY_CORRECT")) != (char *) NULL) { strncpy (dbsstr, "512", sizeof (dbsstr)); diopts->formatString = DI_POSIX_FORMAT; diopts->posix_compat = TRUE; diopts->csv_output = FALSE; diopts->json_output = FALSE; } /* bsd df */ if ((ptr = getenv ("BLOCKSIZE")) != (char *) NULL) { strncpy (dbsstr, ptr, sizeof (dbsstr)-1); } /* gnu df */ if ((ptr = getenv ("DF_BLOCK_SIZE")) != (char *) NULL) { strncpy (dbsstr, ptr, sizeof (dbsstr)-1); } if ((ptr = getenv ("DI_ARGS")) != (char *) NULL) { processStringArgs (argv [0], ptr, diData, dbsstr); } optidx = processArgs (argc, argv, diData, dbsstr, sizeof (dbsstr) - 1); if (debug > 0) { int j; printf ("# ARGS:"); for (j = 0; j < argc; ++j) { printf (" %s", argv[j]); } printf ("\n"); printf ("# blocksize: %s\n", dbsstr); if (memcmp (argvptr, "mi", (Size_t) 2) != 0) { if ((ptr = getenv ("DIFMT")) != (char *) NULL) { printf ("# DIFMT:%s\n", ptr); } } if ((ptr = getenv ("POSIXLY_CORRECT")) != (char *) NULL) { printf ("# POSIXLY_CORRECT:%s\n", ptr); } if ((ptr = getenv ("BLOCKSIZE")) != (char *) NULL) { printf ("# BLOCKSIZE:%s\n", ptr); } if ((ptr = getenv ("DF_BLOCK_SIZE")) != (char *) NULL) { printf ("# DF_BLOCK_SIZE:%s\n", ptr); } if ((ptr = getenv ("DI_ARGS")) != (char *) NULL) { printf ("# DI_ARGS:%s\n", ptr); } } initDisplayTable (diopts); setDispBlockSize (dbsstr, diopts, diout); return optidx; } static int processArgs (int argc, const char * const argv [], diData_t *diData, char *dbsstr, Size_t dbsstr_sz) { int i; int optidx; int errorCount; diOptions_t *diopts; diOutput_t *diout; struct pa_tmp padata; /* the really old compilers don't have automatic initialization */ static getoptn_opt_t opts[] = { /* 0 */ #define OPT_INT_A 0 { "-A", GETOPTN_STRPTR, NULL /*&diopts->formatString*/, 0, (void *) DI_ALL_FORMAT }, /* 1 */ #define OPT_INT_a 1 { "-a", GETOPTN_FUNC_BOOL, NULL /*&padata*/, 0, NULL /*processOptions*/ }, /* 2 */ { "--all", GETOPTN_ALIAS, (void *) "-a", 0, NULL }, /* 3 */ #define OPT_INT_B 3 { "-B", GETOPTN_FUNC_VALUE, NULL /*&padata*/, 0, NULL /*processOptionsVal*/ }, /* 4 */ { "-b", GETOPTN_ALIAS, (void *) "-B", 0, NULL }, /* 5 */ { "--block-size", GETOPTN_ALIAS, (void *) "-B", 0, NULL }, /* 6 */ #define OPT_INT_c 6 { "-c", GETOPTN_BOOL, NULL /*&diopts->csv_output*/, 0 /*sizeof(diopts->csv_output)*/, NULL }, /* 7 */ #define OPT_INT_C 7 { "-C", GETOPTN_BOOL, NULL /*&diopts->csv_tabs*/, 0 /*sizeof(diopts->csv_tabs)*/, NULL }, /* 8 */ { "--csv-output", GETOPTN_ALIAS, (void *) "-c", 0, NULL }, /* 9 */ { "--csv-tabs", GETOPTN_ALIAS, (void *) "-C", 0, NULL }, /* 10 */ #define OPT_INT_d 10 { "-d", GETOPTN_STRING, NULL /*dbsstr*/, 0 /*dbsstr_sz*/, NULL }, /* 11 */ { "--display-size", GETOPTN_ALIAS, (void *) "-d", 0, NULL }, /* 12 */ { "--dont-resolve-symlink", GETOPTN_ALIAS, (void *) "-R", 0, NULL }, /* 13 */ #define OPT_INT_f 13 { "-f", GETOPTN_STRPTR, NULL /*&diopts->formatString*/, 0, NULL }, /* 14 */ { "--format-string", GETOPTN_ALIAS, (void *) "-f", 0, NULL }, /* 15 */ { "-F", GETOPTN_ALIAS, (void *) "-I", 0, NULL }, /* 16 */ #define OPT_INT_g 16 { "-g", GETOPTN_STRING, NULL /*dbsstr*/, 0 /*dbsstr_sz*/, (void *) "g" }, /* 17 */ #define OPT_INT_h 17 { "-h", GETOPTN_STRING, NULL /*dbsstr*/, 0 /*dbsstr_sz*/, (void *) "h" }, /* 18 */ #define OPT_INT_H 18 { "-H", GETOPTN_STRING, NULL /*dbsstr*/, 0 /*dbsstr_sz*/, (void *) "H" }, /* 19 */ #define OPT_INT_help 19 { "--help", GETOPTN_FUNC_BOOL, NULL, 0, NULL /*processOptions*/ }, /* 20 */ { "--human-readable", GETOPTN_ALIAS, (void *) "-H", 0, NULL }, /* 21 */ #define OPT_INT_qmark 21 { "-?", GETOPTN_FUNC_BOOL, NULL, 0, NULL /*processOptions*/ }, /* 22 */ { "-i", GETOPTN_ALIAS, (void *) "-x", 0, NULL }, /* 23 */ #define OPT_INT_I 23 { "-I", GETOPTN_FUNC_VALUE, NULL /*&padata*/, 0, NULL /*processOptionsVal*/ }, /* 24 */ { "--inodes",GETOPTN_IGNORE, NULL, 0, NULL }, /* 25 */ #define OPT_INT_j 25 { "-j", GETOPTN_BOOL, NULL /*&diopts->json_output*/, 0 /*sizeof(diopts->json_output)*/, NULL }, /* 26 */ { "--json-output", GETOPTN_ALIAS, (void *) "-j", 0, NULL }, /* 27 */ #define OPT_INT_k 27 { "-k", GETOPTN_STRING, NULL /*dbsstr*/, 0 /*dbsstr_sz*/, (void *) "k" }, /* 28 */ #define OPT_INT_l 28 { "-l", GETOPTN_BOOL, NULL /*&diopts->localOnly*/, 0 /*sizeof (diopts->localOnly)*/, NULL }, /* 29 */ { "--local",GETOPTN_ALIAS, (void *) "-l", 0, NULL }, /* 30 */ #define OPT_INT_L 30 { "-L", GETOPTN_BOOL, NULL /*&diopts->excludeLoopback*/, 0 /*sizeof (diopts->excludeLoopback)*/, NULL }, /* 31 */ #define OPT_INT_m 31 { "-m", GETOPTN_STRING, NULL /*dbsstr*/, 0 /*dbsstr_sz*/, (void *) "m" }, /* 32 */ #define OPT_INT_n 32 { "-n", GETOPTN_BOOL, NULL /*&diopts->printHeader*/, 0 /*sizeof (diopts->printHeader)*/, NULL }, /* 33 */ { "--no-sync", GETOPTN_IGNORE, NULL, 0, NULL }, /* 34 */ #define OPT_INT_P 34 { "-P", GETOPTN_FUNC_BOOL, NULL /*&padata*/, 0, NULL /*processOptions*/ }, /* 35 */ { "--portability", GETOPTN_ALIAS, (void *) "-P", 0, NULL }, /* 36 */ { "--print-type", GETOPTN_IGNORE, NULL, 0, NULL }, /* 37 */ #define OPT_INT_q 37 { "-q", GETOPTN_BOOL, NULL /*&diopts->quota_check*/, 0 /*sizeof (diopts->quota_check)*/, NULL }, /* 38 */ #define OPT_INT_R 38 { "-R", GETOPTN_BOOL, NULL /*&diopts->dontResolveSymlink*/, 0 /*sizeof (diopts->dontResolveSymlink)*/, NULL }, /* 39 */ #define OPT_INT_s 39 { "-s", GETOPTN_FUNC_VALUE, NULL /*&padata*/, 0, NULL /*processOptionsVal*/ }, /* 40 */ #define OPT_INT_si 40 { "--si", GETOPTN_FUNC_BOOL, NULL /*&padata*/, 0, NULL /*processOptions*/ }, /* 41 */ { "--sync", GETOPTN_IGNORE, NULL, 0, NULL }, /* 42 */ #define OPT_INT_t 42 { "-t", GETOPTN_BOOL, NULL /*&diopts->printTotals*/, 0 /*sizeof (diopts->printTotals)*/, NULL }, /* 43 */ { "--total",GETOPTN_ALIAS, (void *) "-t", 0, NULL }, /* 44 */ { "--type", GETOPTN_ALIAS, (void *) "-I", 0, NULL }, /* 45 */ { "-v", GETOPTN_IGNORE, NULL, 0, NULL }, /* 46 */ #define OPT_INT_version 46 { "--version", GETOPTN_FUNC_BOOL, NULL, 0, NULL /*processOptions*/ }, /* 47 */ #define OPT_INT_w 47 { "-w", GETOPTN_SIZET, NULL /*&diout->width*/, 0 /*sizeof (diout->width)*/, NULL }, /* 48 */ #define OPT_INT_W 48 { "-W", GETOPTN_SIZET, NULL /*&diout->inodeWidth*/, 0 /*sizeof (diout->inodeWidth)*/, NULL }, /* 49 */ #define OPT_INT_x 49 { "-x", GETOPTN_FUNC_VALUE, NULL /*&padata*/, 0, NULL /*processOptionsVal*/ }, /* 50 */ { "--exclude-type", GETOPTN_ALIAS, (void *) "-x", 0, NULL }, /* 51 */ #define OPT_INT_X 51 { "-X", GETOPTN_FUNC_VALUE, NULL /*&padata*/, 0, NULL /*processOptionsVal*/ }, /* 52 */ #define OPT_INT_z 52 { "-z", GETOPTN_STRING, NULL /*&diData->zoneInfo.zoneDisplay*/, 0 /*sizeof (diData->zoneInfo.zoneDisplay)*/, NULL }, /* 53 */ #define OPT_INT_Z 53 { "-Z", GETOPTN_STRING, NULL /*&diData->zoneInfo.zoneDisplay*/, 0 /*sizeof (diData->zoneInfo.zoneDisplay)*/, (void *) "all" } }; static int dbsids[] = { OPT_INT_d, OPT_INT_g, OPT_INT_h, OPT_INT_H, OPT_INT_k, OPT_INT_m }; static int paidb[] = { OPT_INT_a, OPT_INT_help, OPT_INT_qmark, OPT_INT_P, OPT_INT_si, OPT_INT_version }; static int paidv[] = { OPT_INT_B, OPT_INT_I, OPT_INT_s, OPT_INT_x, OPT_INT_X }; diopts = &diData->options; diout = &diData->output; /* this is seriously gross, but the old compilers don't have */ /* automatic aggregate initialization */ /* don't forget to change dbsids, paidb and paidv above also */ opts[OPT_INT_A].valptr = (void *) &diopts->formatString; /* -A */ opts[OPT_INT_c].valptr = (void *) &diopts->csv_output; /* -c */ opts[OPT_INT_c].valsiz = sizeof (diopts->csv_output); opts[OPT_INT_C].valptr = (void *) &diopts->csv_tabs; /* -C */ opts[OPT_INT_C].valsiz = sizeof (diopts->csv_tabs); opts[OPT_INT_f].valptr = (void *) &diopts->formatString; /* -f */ opts[OPT_INT_j].valptr = (void *) &diopts->json_output; /* -j */ opts[OPT_INT_j].valsiz = sizeof (diopts->json_output); opts[OPT_INT_l].valptr = (void *) &diopts->localOnly; /* -l */ opts[OPT_INT_l].valsiz = sizeof (diopts->localOnly); opts[OPT_INT_L].valptr = (void *) &diopts->excludeLoopback; /* -L */ opts[OPT_INT_L].valsiz = sizeof (diopts->excludeLoopback); opts[OPT_INT_n].valptr = (void *) &diopts->printHeader; /* -n */ opts[OPT_INT_n].valsiz = sizeof (diopts->printHeader); opts[OPT_INT_q].valptr = (void *) &diopts->quota_check; /* -q */ opts[OPT_INT_q].valsiz = sizeof (diopts->quota_check); opts[OPT_INT_R].valptr = (void *) &diopts->dontResolveSymlink; /* -R */ opts[OPT_INT_R].valsiz = sizeof (diopts->dontResolveSymlink); opts[OPT_INT_t].valptr = (void *) &diopts->printTotals; /* -t */ opts[OPT_INT_t].valsiz = sizeof (diopts->printTotals); opts[OPT_INT_w].valptr = (void *) &diout->width; /* -w */ opts[OPT_INT_w].valsiz = sizeof (diout->width); opts[OPT_INT_W].valptr = (void *) &diout->inodeWidth; /* -W */ opts[OPT_INT_W].valsiz = sizeof (diout->inodeWidth); opts[OPT_INT_z].valptr = (void *) diData->zoneInfo.zoneDisplay; /* -z */ opts[OPT_INT_z].valsiz = sizeof (diData->zoneInfo.zoneDisplay); opts[OPT_INT_Z].valptr = (void *) diData->zoneInfo.zoneDisplay; /* -Z */ opts[OPT_INT_Z].valsiz = sizeof (diData->zoneInfo.zoneDisplay); for (i = 0; i < (int) (sizeof (dbsids) / sizeof (int)); ++i) { opts[dbsids[i]].valptr = (void *) dbsstr; opts[dbsids[i]].valsiz = dbsstr_sz; } for (i = 0; i < (int) (sizeof (paidb) / sizeof (int)); ++i) { opts[paidb[i]].valptr = (void *) &padata; opts[paidb[i]].value2 = (void *) processOptions; if (diopts->exitFlag != DI_EXIT_NORM) { break; } } for (i = 0; i < (int) (sizeof (paidv) / sizeof (int)); ++i) { opts[paidv[i]].valptr = (void *) &padata; opts[paidv[i]].value2 = (void *) processOptionsVal; if (diopts->exitFlag != DI_EXIT_NORM) { break; } } optidx = -1; if (diopts->exitFlag != DI_EXIT_NORM) { return optidx; } padata.diData = diData; padata.diopts = diopts; padata.diout = diout; padata.dbsstr = dbsstr; padata.dbsstr_sz = dbsstr_sz; optidx = getoptn (GETOPTN_LEGACY, argc, argv, sizeof (opts) / sizeof (getoptn_opt_t), opts, &errorCount); diopts->errorCount += errorCount; if (diopts->errorCount > 0) { setExitFlag (diopts, DI_EXIT_WARN); } if (diopts->csv_tabs) { diopts->csv_output = TRUE; } if (diopts->csv_output || diopts->json_output) { diopts->printTotals = FALSE; } if (diopts->json_output) { diopts->printHeader = FALSE; } return optidx; } static void processOptions (const char *arg, char *valptr) { struct pa_tmp *padata; padata = (struct pa_tmp *) valptr; if (strcmp (arg, "-a") == 0) { padata->diopts->displayAll = TRUE; strncpy (padata->diData->zoneInfo.zoneDisplay, "all", MAXPATHLEN); } else if (strcmp (arg, "--help") == 0 || strcmp (arg, "-?") == 0) { usage(); setExitFlag (padata->diopts, DI_EXIT_OK); } else if (strcmp (arg, "-P") == 0) { /* don't override -k option */ if (strcmp (padata->dbsstr, "k") != 0) { strncpy (padata->dbsstr, "512", padata->dbsstr_sz); } padata->diopts->formatString = DI_POSIX_FORMAT; padata->diopts->posix_compat = TRUE; padata->diopts->csv_output = FALSE; } else if (strcmp (arg, "--si") == 0) { padata->diopts->baseDispSize = (_print_size_t) DI_VAL_1000; padata->diopts->baseDispIdx = DI_DISP_1000_IDX; strncpy (padata->dbsstr, "H", padata->dbsstr_sz); } else if (strcmp (arg, "--version") == 0) { printf (DI_GT("di version %s Default Format: %s\n"), DI_VERSION, DI_DEFAULT_FORMAT); setExitFlag (padata->diopts, DI_EXIT_OK); } else { fprintf (stderr, "di_panic: bad option setup\n"); } return; } static void processOptionsVal (const char *arg, char *valptr, char *value) { struct pa_tmp *padata; int rc; padata = (struct pa_tmp *) valptr; if (strcmp (arg, "-B") == 0) { if (isdigit ((int) (*value))) { padata->diopts->baseDispSize = (_print_size_t) atof (value); padata->diopts->baseDispIdx = DI_DISP_1000_IDX; /* unknown, really */ if (padata->diopts->baseDispSize == (_print_size_t) DI_VAL_1024) { padata->diopts->baseDispIdx = DI_DISP_1024_IDX; } } else if (strcmp (value, "k") == 0) { padata->diopts->baseDispSize = (_print_size_t) DI_VAL_1024; padata->diopts->baseDispIdx = DI_DISP_1024_IDX; } else if (strcmp (value, "d") == 0 || strcmp (value, "si") == 0) { padata->diopts->baseDispSize = (_print_size_t) DI_VAL_1000; padata->diopts->baseDispIdx = DI_DISP_1000_IDX; } } else if (strcmp (arg, "-I") == 0) { rc = parseList (&padata->diData->includeList, value); if (rc != 0) { setExitFlag (padata->diopts, DI_EXIT_FAIL); return; } } else if (strcmp (arg, "-s") == 0) { strncpy (padata->diopts->sortType, value, DI_SORT_MAX); /* for backwards compatibility */ /* reverse by itself - change to reverse mount point */ if (strcmp (padata->diopts->sortType, "r") == 0) { strncpy (padata->diopts->sortType, "rm", DI_SORT_MAX); } /* add some sense to the sort order */ if (strcmp (padata->diopts->sortType, "t") == 0) { strncpy (padata->diopts->sortType, "tm", DI_SORT_MAX); } } else if (strcmp (arg, "-x") == 0) { parseList (&padata->diData->ignoreList, value); } else if (strcmp (arg, "-X") == 0) { debug = atoi (value); padata->diopts->printDebugHeader = TRUE; padata->diopts->printTotals = TRUE; padata->diopts->printHeader = TRUE; padata->diout->width = 10; padata->diout->inodeWidth = 10; } else { fprintf (stderr, "di_panic: bad option setup\n"); } return; } static int parseList (iList_t *list, char *str) { char *dstr; char *ptr; char *lptr; int count; int ocount; int ncount; int i; unsigned int len; dstr = strdup (str); if (dstr == (char *) NULL) { fprintf (stderr, "strdup failed in parseList() (1). errno %d\n", errno); return 1; } ptr = strtok (dstr, DI_LIST_SEP); count = 0; while (ptr != (char *) NULL) { ++count; ptr = strtok ((char *) NULL, DI_LIST_SEP); } ocount = list->count; list->count += count; ncount = list->count; list->list = (char **) di_realloc ((char *) list->list, (Size_t) list->count * sizeof (char *)); if (list->list == (char **) NULL) { fprintf (stderr, "malloc failed in parseList() (2). errno %d\n", errno); free ((char *) dstr); return 1; } ptr = dstr; for (i = ocount; i < ncount; ++i) { len = (unsigned int) strlen (ptr); lptr = (char *) malloc ((Size_t) len + 1); if (lptr == (char *) NULL) { fprintf (stderr, "malloc failed in parseList() (3). errno %d\n", errno); free ((char *) dstr); return 1; } strncpy (lptr, ptr, (Size_t) len); lptr[len] = '\0'; list->list [i] = lptr; ptr += len + 1; } free ((char *) dstr); return 0; } /* * usage */ static void usage (void) { printf (DI_GT("di version %s Default Format: %s\n"), DI_VERSION, DI_DEFAULT_FORMAT); /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ printf (DI_GT("Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n")); printf (DI_GT(" [-I include-fstyp-list] [file [...]]\n")); printf (DI_GT(" -a : print all mounted devices\n")); printf (DI_GT(" -d x : size to print blocks in (512 - POSIX, k - kbytes,\n")); printf (DI_GT(" m - megabytes, g - gigabytes, t - terabytes, h - human readable).\n")); printf (DI_GT(" -f x : use format string \n")); printf (DI_GT(" -I x : include only file system types in \n")); printf (DI_GT(" -x x : exclude file system types in \n")); printf (DI_GT(" -l : display local filesystems only\n")); printf (DI_GT(" -n : don't print header\n")); printf (DI_GT(" -t : print totals\n")); printf (DI_GT(" Format string values:\n")); printf (DI_GT(" m - mount point M - mount point, full length\n")); printf (DI_GT(" b - total kbytes B - kbytes available for use\n")); printf (DI_GT(" u - used kbytes c - calculated kbytes in use\n")); printf (DI_GT(" f - kbytes free v - kbytes available\n")); printf (DI_GT(" p - percentage not avail. for use 1 - percentage used\n")); printf (DI_GT(" 2 - percentage of user-available space in use.\n")); printf (DI_GT(" i - total file slots (i-nodes) U - used file slots\n")); printf (DI_GT(" F - free file slots P - percentage file slots used\n")); printf (DI_GT(" s - filesystem name S - filesystem name, full length\n")); printf (DI_GT(" t - disk partition type T - partition type, full length\n")); printf (DI_GT("See manual page for more options.\n")); } static void setDispBlockSize (char *ptr, diOptions_t *diopts, diOutput_t *diout) { unsigned int len; _print_size_t val; char *tptr; static char tempbl [15]; char ttempbl [15]; if (isdigit ((int) (*ptr))) { val = (_print_size_t) atof (ptr); } else { val = (_print_size_t) 1.0; } tptr = ptr; len = (unsigned int) strlen (ptr); if (! isdigit ((int) *tptr)) { int idx; idx = -1; switch (*tptr) { case 'k': case 'K': { idx = DI_ONE_K; break; } case 'm': case 'M': { idx = DI_ONE_MEG; break; } case 'g': case 'G': { idx = DI_ONE_GIG; break; } case 't': case 'T': { idx = DI_ONE_TERA; break; } case 'p': case 'P': { idx = DI_ONE_PETA; break; } case 'e': case 'E': { idx = DI_ONE_EXA; break; } case 'z': case 'Z': { idx = DI_ONE_ZETTA; break; } case 'y': case 'Y': { idx = DI_ONE_YOTTA; break; } case 'h': { val = (_print_size_t) DI_DISP_HR; diout->dispBlockLabel = "Size"; break; } case 'H': { val = (_print_size_t) DI_DISP_HR_2; diout->dispBlockLabel = "Size"; break; } default: { if (strncmp (ptr, "HUMAN", (Size_t) 5) == 0) { val = (_print_size_t) DI_DISP_HR; } else { /* some unknown string value */ idx = DI_ONE_MEG; } break; } } if (idx >= 0) { if (len > 1) { ++tptr; if (*tptr == 'B') { diopts->baseDispSize = (_print_size_t) DI_VAL_1000; diopts->baseDispIdx = DI_DISP_1000_IDX; } } if (val == (_print_size_t) 1.0) { diout->dispBlockLabel = dispTable [idx].disp [diopts->baseDispIdx]; } else { Snprintf1 (ttempbl, sizeof (tempbl), "%%.0%s %%s", DI_Lf); Snprintf2 (tempbl, sizeof (tempbl), ttempbl, val, DI_GT (dispTable [idx].disp [diopts->baseDispIdx])); diout->dispBlockLabel = tempbl; } val *= dispTable [idx].size; } /* known size multiplier */ } else { int i; int ok; ok = 0; for (i = 0; i < (int) DI_DISPTAB_SIZE; ++i) { if (val == dispTable [i].size) { diout->dispBlockLabel = dispTable [i].disp [diopts->baseDispIdx]; ok = 1; break; } } if (ok == 0) { Snprintf1 (ttempbl, sizeof (ttempbl), "%%.0%sb", DI_Lf); Snprintf1 (tempbl, sizeof (tempbl), ttempbl, val); diout->dispBlockLabel = tempbl; } } /* some oddball block size */ if (diopts->posix_compat && val == (_print_size_t) DI_VAL_512) { diout->dispBlockLabel = "512-blocks"; } if (diopts->posix_compat && val == (_print_size_t) DI_VAL_1024) { diout->dispBlockLabel = "1024-blocks"; } diopts->dispBlockSize = val; } static void initDisplayTable (diOptions_t *diopts) { int i; /* initialize dispTable array */ dispTable [0].size = diopts->baseDispSize; for (i = 1; i < (int) DI_DISPTAB_SIZE; ++i) { dispTable [i].size = dispTable [i - 1].size * diopts->baseDispSize; } } static void setExitFlag (diOptions_t *diopts, unsigned int exitFlag) { if (exitFlag > diopts->exitFlag) { diopts->exitFlag = exitFlag; } } di-4.52/C/tests.d/0000755000175000017500000000000014421556642011723 5ustar bllblldi-4.52/C/tests.d/compshpl.sh0000755000175000017500000000321214421556642014105 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'compare mkconfig.sh mkconfig.pl' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ perl -v > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ] ; then exit 166 fi cd $_MKCONFIG_RUNTOPDIR grc=0 unset MAKEFLAGS ${MAKE:-make} ${TMAKEFLAGS} realclean rm -f config.h.sh config.h.pl cache.pl cache.sh \ vars.pl vars.sh ${MAKE:-make} ${TMAKEFLAGS} -e config.h sed -e '/Created on: /,/Using: mkc/d' config.h > config.h.sh rm -f config.h grep -v '^mkc_env' ${MKC_FILES}/mkconfig.cache | sort > cache.sh sort ${MKC_FILES}/mkc_config_c.vars > vars.sh mv ${MKC_FILES}/mkconfig.cache ${_MKCONFIG_TSTRUNTMPDIR}/mkconfig_sh.cache mv ${MKC_FILES}/mkc_config_c.vars ${_MKCONFIG_TSTRUNTMPDIR}/mkc_config_c_sh.vars mv ${MKC_FILES}/mkc_di_env.vars ${_MKCONFIG_TSTRUNTMPDIR}/mkc_di_env.vars mv ${MKC_FILES}/mkconfig.log ${_MKCONFIG_TSTRUNTMPDIR}/mkconfig_sh.log mv di.env ${_MKCONFIG_TSTRUNTMPDIR}/di_sh.env ${MAKE:-make} ${TMAKEFLAGS} -e MKCONFIG_TYPE=perl config.h sed -e '/Created on: /,/Using: mkc/d' config.h > config.h.pl rm -f config.h sort ${MKC_FILES}/mkconfig.cache > cache.pl sort ${MKC_FILES}/mkc_config_c.vars > vars.pl mv ${MKC_FILES}/mkconfig.cache $_MKCONFIG_TSTRUNTMPDIR/mkconfig_pl.cache mv ${MKC_FILES}/mkc_config_c.vars $_MKCONFIG_TSTRUNTMPDIR/mkc_config_c_pl.vars mv ${MKC_FILES}/mkconfig.log $_MKCONFIG_TSTRUNTMPDIR/mkconfig_pl.log mv di.env $_MKCONFIG_TSTRUNTMPDIR/di_pl.env chkdiff config.h.sh config.h.pl mv config.h.sh config.h.pl $_MKCONFIG_TSTRUNTMPDIR chkdiff cache.sh cache.pl mv cache.sh cache.pl $_MKCONFIG_TSTRUNTMPDIR chkdiff vars.sh vars.pl mv vars.sh vars.pl $_MKCONFIG_TSTRUNTMPDIR exit $grc di-4.52/C/tests.d/getoptn.sh0000755000175000017500000000122314421556642013740 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'getoptn' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ cd $_MKCONFIG_RUNTOPDIR unset MAKEFLAGS ${MAKE:-make} ${TMAKEFLAGS} realclean ${MAKE:-make} ${TMAKEFLAGS} -e di.env . ./di.env ${MAKE:-make} ${TMAKEFLAGS} -e getoptn_test.exe > ${_MKCONFIG_TSTRUNTMPDIR}/make.log 2>&1 rc=$? if [ $rc != 0 ]; then grc=$rc; fi if [ $grc -eq 0 ]; then ./getoptn_test.exe > ${_MKCONFIG_TSTRUNTMPDIR}/getoptn_test.out 2>&1 if [ -s ${_MKCONFIG_TSTRUNTMPDIR}/getoptn_test.out ]; then chkdiff ${_MKCONFIG_RUNTESTDIR}/getoptn.txt \ ${_MKCONFIG_TSTRUNTMPDIR}/getoptn_test.out fi fi exit $grc di-4.52/C/tests.d/getoptn.txt0000644000175000017500000000071114421556642014143 0ustar bllbll** expect argument missing test 32: -i argument missing ** expect invalid size test 33: int: invalid size (line 7) ** expect invalid size test 34: long: invalid size (line 8) ** expect invalid size test 35: long: invalid size (line 9) ** expect invalid pointer test 45: string: invalid pointer (line 21) ** expect invalid pointer test 46: func_bool: invalid function ptr (line 22) ** expect invalid pointer test 47: func_val: invalid function ptr (line 23) di-4.52/C/tests.d/env.sh0000755000175000017500000000225114421556642013052 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh . $_MKCONFIG_DIR/bin/shellfuncs.sh maindodisplay $1 'check environment in make' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ cd ${_MKCONFIG_RUNTOPDIR} rc=$? if [ $rc -ne 0 ]; then puts "ERROR: Unable to cd to ${_MKCONFIG_RUNTOPDIR}" exit $rc fi ${MAKE:-make} di.env . ./di.env unset MAKEFLAGS ${MAKE:-make} ${TMAKEFLAGS} --version 2>&1 | egrep "GNU Make" > /dev/null 2>&1 rc=$? if [ $rc -eq 0 ]; then ${MAKE:-make} ${TMAKEFLAGS} -e --no-print-directory rtest-env | sed -e 's/^ *//' -e 's/ *$//' > ${_MKCONFIG_TSTRUNTMPDIR}/e2 2>/dev/null ${_MKCONFIG_TSTRUNTMPDIR}/e2 2>/dev/null else ${MAKE:-make} ${TMAKEFLAGS} -e rtest-env | sed -e 's/^ *//' -e 's/ *$//' > ${_MKCONFIG_TSTRUNTMPDIR}/e2 2>/dev/null fi cd ${_MKCONFIG_TSTRUNTMPDIR} rc=$? if [ $rc -ne 0 ]; then puts "ERROR: Unable to cd to ${_MKCONFIG_TSTRUNTMPDIR}" exit $rc fi echo "${_MKCONFIG_SYSTYPE} ${_MKCONFIG_SYSREV} ${_MKCONFIG_SYSARCH} ${CC} ${_MKCONFIG_USING_GCC} ${CFLAGS_OPTIMIZE} ${CFLAGS_COMPILER} ${LDFLAGS_COMPILER} ${OBJ_EXT} ${EXE_EXT} ${XMSGFMT}" | sed -e 's/^ *//' -e 's/ *$//' > e1 chkdiff e1 e2 testcleanup e1 e2 env.log exit $grc di-4.52/C/tests.d/buildpl.sh0000755000175000017500000000103114421556642013710 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh maindodisplay $1 'build w/mkconfig.pl' maindoquery $1 $_MKC_ONCE getsname $0 dosetup $@ perl -v > /dev/null 2>&1 rc=$? if [ $rc -ne 0 ] ; then exit 166 fi cd $_MKCONFIG_RUNTOPDIR unset MAKEFLAGS ${MAKE:-make} ${TMAKEFLAGS} realclean instdir="`pwd`/test_di" ${MAKE:-make} ${TMAKEFLAGS} -e prefix=${instdir} all-perl grc=$? # leave a copy there...realclean will get them... set +f cp mkconfig.log mkconfig.cache mkc*.vars di.env di.reqlibs \ $_MKCONFIG_TSTRUNTMPDIR set -f exit $grc di-4.52/C/tests.d/rpmbuild.sh0000755000175000017500000000173414421556642014105 0ustar bllbll#!/bin/sh . $_MKCONFIG_DIR/bin/testfuncs.sh getsname $0 dosetup $@ maindodisplay $1 rpmbuild maindoquery $1 $_MKC_ONCE . $_MKCONFIG_DIR/bin/shellfuncs.sh locatecmd locrpmbuild rpmbuild if [ "${locrpmbuild}" = "" ];then putsnonl " skipped" >&5 exit 0 fi rvers=`rpmbuild --version | tr -cd '0-9' | sed 's/^\(...\).*/\1/'` if [ $rvers -lt 470 ]; then putsnonl " old version skipped" >&5 exit 0 fi march=`rpmbuild --showrc | grep '^build arch' | sed 's/.*: *//'` puts "## Machine Architecture: ${march}" cd ${_MKCONFIG_RUNTOPDIR} DI_VERSION=`grep DI_VERSION version.h | sed -e 's/"$//' -e 's/.*"//'` unset MAKEFLAGS ${MAKE:-make} ${TMAKEFLAGS} -e di.env . ./di.env grc=0 ${MAKE:-make} ${TMAKEFLAGS} -e DI_DIR=".." DI_VERSION=${DI_VERSION} MARCH=${march} testrpmbuild rc=$? if [ $rc -ne 0 ]; then grc=$rc; fi # leave a copy there...realclean will get them... set +f cp mkconfig.log mkconfig.cache mkc*.vars di.env di.reqlibs \ $_MKCONFIG_TSTRUNTMPDIR set -f exit $grc di-4.52/C/tests.d/test_order0000644000175000017500000000006014421556642014014 0ustar bllbll1 env 2 getoptn 3 buildpl 4 compshpl 5 rpmbuild di-4.52/C/version.h0000644000175000017500000000021614421556642012174 0ustar bllbll#ifndef DI_INC_VERSION_H #define DI_INC_VERSION_H /* * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ # define DI_VERSION "4.52" #endif di-4.52/C/Makefile0000644000175000017500000002631314421556642012004 0ustar bllbll# # di makefile - C # # Copyright 2001-2018 Brad Lanam Walnut Creek CA, USA # Copyright 2023 Brad Lanam, Pleasant Hill, CA # MKC_PREFIX = di MKC_CONFDIR = mkc_config MKC_FILES = mkc_files MKC_OUTPUT = config.h MKC_ENV = $(MKC_PREFIX).env MKC_ENV_SHR = $(MKC_PREFIX)-shared.env MKC_CONF = $(MKC_CONFDIR)/$(MKC_PREFIX).mkc MKC_ENV_CONF = $(MKC_CONFDIR)/$(MKC_PREFIX)-env.mkc MKC_ENV_SHR_CONF = $(MKC_CONFDIR)/$(MKC_PREFIX)-env-shared.mkc MKC_CONF_TCL = $(MKC_CONFDIR)/$(MKC_PREFIX)-tcl.mkc MKC_CONF_GETOPTN = $(MKC_CONFDIR)/$(MKC_PREFIX)-getoptn.mkc # for tests.done DC = gdc OBJ_EXT = .o EXE_EXT = ### # common programs # CAT = cat CHGRP = chgrp CHMOD = chmod CHOWN = chown CP = cp LN = ln MKDIR = mkdir MV = mv RM = rm RPMBUILD = rpmbuild SED = sed TEST = test ### # installation options # prefix = /usr/local PREFIX = $(prefix) BINDIR = $(PREFIX)/bin DATADIR = $(PREFIX)/share MANDIR = $(DATADIR)/man LOCALEDIR = $(DATADIR)/locale ### # additional flags/libraries # DI_SHARED = DI_CFLAGS = -DDI_LOCALE_DIR=\\\"$(LOCALEDIR)\\\" ### # mkconfig variables MKC_DIR = ../mkconfig MKCONFIG_TYPE = sh MKC_REQLIB = di.reqlibs MKC_TCLREQLIB = di-tcl.reqlibs MKC_ECHO = #MKC_ECHO = -e ### # main # have to get various environment variables set up. .PHONY: all all: all-sh .PHONY: all-sh all-sh: $(MKC_ENV) . ./$(MKC_ENV);$(MAKE) -e MKCONFIG_TYPE=sh di-programs .PHONY: all-perl all-perl: $(MKC_ENV) . ./$(MKC_ENV);$(MAKE) -e MKCONFIG_TYPE=perl di-programs # tcl interface .PHONY: tcl-sh tcl-sh: $(MKC_ENV_SHR) . ./$(MKC_ENV_SHR);$(MAKE) -e MKCONFIG_TYPE=sh tcl-programs # this is not working...need to research #tcl-perl: $(MKC_ENV_SHR) # . ./$(MKC_ENV_SHR);$(MAKE) -e MKCONFIG_TYPE=perl tcl-programs # perl interface .PHONY: perl-sh perl-sh: $(MKC_ENV_SHR) . ./$(MKC_ENV_SHR);$(MAKE) -e MKCONFIG_TYPE=sh perl-programs .PHONY: perl-perl perl-perl: $(MKC_ENV_SHR) . ./$(MKC_ENV_SHR);$(MAKE) -e MKCONFIG_TYPE=perl perl-programs .PHONY: test test: tests.done ### # environment $(MKC_ENV): $(MKC_ENV_CONF) ../dioptions.dat @-$(RM) -f $(MKC_ENV) tests.done CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh $(MKC_ENV_CONF) $(MKC_ENV_SHR): $(MKC_ENV_SHR_CONF) @-$(RM) -f $(MKC_ENV_SHR) tests.done CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh \ $(MKC_ENV_SHR_CONF) ### # specific builds # This was tested using vc # Use: # nmake MAKE=nmake windows # .PHONY: windows windows: @$(MAKE) ../dioptions.dat copy /y NUL: $(MKC_ENV) -del config.h copy /y /b NUL:+configs\config.ms.cl config.h copy /y NUL: $(MKC_REQLIB) $(MAKE) \ MAKE=nmake CC=cl LD=cl EXE_EXT=".exe" OBJ_EXT=".obj" \ DI_CFLAGS="$(DI_CFLAGS) -nologo -O2" \ LDFLAGS="-nologo -O2" di-programs # This was tested using cygwin .PHONY: windows-gcc windows-gcc: @$(MAKE) ../dioptions.dat @echo ':' > $(MKC_ENV);chmod a+rx $(MKC_ENV) @-$(RM) -f config.h mkconfig.cache mkc*.vars tests.done $(CP) -f configs/config.cygwin.gcc config.h @echo '-lintl' > $(MKC_REQLIB) $(MAKE) \ CC=gcc LD=gcc EXE_EXT=".exe" OBJ_EXT=".o" \ DI_CFLAGS="$(DI_CFLAGS) -g -O2" \ LDFLAGS="-g -O2" di-programs .PHONY: windows-msys windows-msys: MAKE=mingw32-make cp ../features/dioptions.dat ../dioptions.dat > $(MKC_ENV) -rm config.h cp configs/config.mingw config.h > $(MKC_REQLIB) $(MAKE) \ MAKE=$(MAKE) \ CC=gcc \ EXE_EXT=".exe" OBJ_EXT=".o" \ DI_CFLAGS="$(DI_CFLAGS) -g -O2" \ LDFLAGS="-g -O2" di-programs .PHONY: windows-mingw windows-mingw: MAKE=mingw32-make copy /y /b NUL:+..\features\dioptions.dat ..\dioptions.dat copy /y NUL: $(MKC_ENV) -del config.h copy /y /b NUL:+configs\config.mingw config.h copy /y NUL: $(MKC_REQLIB) $(MAKE) \ MAKE=$(MAKE) \ CC=gcc LD=gcc \ EXE_EXT=".exe" OBJ_EXT=".o" \ DI_CFLAGS="$(DI_CFLAGS) -g -O2" \ LDFLAGS="-g -O2" mingw-di.exe .PHONY: os2-gcc os2-gcc: @echo ':' > $(MKC_ENV);chmod a+rx $(MKC_ENV) $(MAKE) MKCONFIG_TYPE=perl \ CC=gcc LD=gcc EXE_EXT=".exe" OBJ_EXT=".o" \ DI_CFLAGS="$(DI_CFLAGS) -g -O2" \ LDFLAGS="-g -O2 -Zexe" di.exe ### # cleaning # leaves: # config.h configtcl.h di.reqlibs # ../dioptions.dat, tests.done, test_di, $(MKC_ENV), $(MKC_ENV_SHR) .PHONY: clean clean: @-cd Perl; \ if [ -f Makefile ]; then \ $(MAKE) clean; \ fi @-$(RM) -rf di mi \ di.exe mingw-di.exe mi.exe \ tcldiskspace.bld diskspace.so diskspace.dylib diskspace.dll \ perlfilesysdi.bld libdiperl.a \ *.o *.obj $(MKC_FILES)/mkconfig.log \ tests.done $(MKC_FILES)/_tmp_mkconfig tests.d/chksh* \ $(MKC_FILES)/mkconfig.cache mkc*.vars \ getoptn_test* gconfig.h getoptn.reqlibs \ $(MKC_FILES)/mkconfig.reqlibs $(MKC_FILES)/mkc_compile.log \ Perl/Filesys-di-*.tar.gz \ Perl/Makefile.old \ tests.d/test_order.tmp >/dev/null 2>&1; exit 0 @-find . -name '*~' -print | xargs rm > /dev/null 2>&1; exit 0 # leaves: # _mkconfig_runtests, mkc_files, ../dioptions.dat # tests.done, test_di .PHONY: realclean realclean: @$(MAKE) clean >/dev/null 2>&1 @-$(RM) -rf config.h configtcl.h gconfig.h \ $(MKC_ENV) $(MKC_ENV_SHR) $(MKC_REQLIB) $(MKC_TCLREQLIB) \ >/dev/null 2>&1; exit 0 # leaves: # ../dioptions.dat .PHONY: distclean distclean: @-cd Perl; \ if [ -f Makefile ]; then \ $(MAKE) distclean; \ fi @$(MAKE) realclean >/dev/null 2>&1 @-$(RM) -rf tests.done test_di \ _mkconfig_runtests \ $(MKC_FILES) \ *~ *.orig */*.orig \ >/dev/null 2>&1; exit 0 ### # installation .PHONY: install install: $(MAKE) all . ./$(MKC_ENV);cd ..;$(MAKE) -e PREFIX=$(PREFIX) \ LOCALEDIR=$(LOCALEDIR) FROMDIR=C install ### # programs .PHONY: di-programs di-programs: di$(EXE_EXT) .PHONY: tcl-programs tcl-programs: tcldiskspace.bld .PHONY: perl-programs perl-programs: perlfilesysdi.bld ### # configuration file ../dioptions.dat: ../features/dioptions.dat cd ../;$(MAKE) dioptions.dat config.h: $(MKC_ENV) ../dioptions.dat $(MKC_CONF) @-$(RM) -f config.h tests.done @if [ "$(DI_NO_NLS)" != "" ]; then \ echo "*** User requested no NLS"; \ $(MKC_DIR)/mkc.sh -setopt -o ../dioptions.dat NLS F; fi @if [ "$(MKCONFIG_TYPE)" = "sh" -o "$(MKCONFIG_TYPE)" = "" ]; then \ . ./$(MKC_ENV);$(_MKCONFIG_SHELL) \ $(MKC_DIR)/mkconfig.sh \ $(MKC_CONF); fi @if [ "$(MKCONFIG_TYPE)" = "perl" ]; then \ . ./$(MKC_ENV);perl \ $(MKC_DIR)/mkconfig.pl \ $(MKC_CONF); fi configtcl.h: $(MKC_ENV_SHR) ../dioptions.dat $(MKC_CONF_TCL) @-$(RM) -f configtcl.h @if [ "$(MKCONFIG_TYPE)" = "sh" -o "$(MKCONFIG_TYPE)" = "" ]; then \ . ./$(MKC_ENV_SHR);$(_MKCONFIG_SHELL) \ $(MKC_DIR)/mkconfig.sh \ $(MKC_CONF_TCL); fi @if [ "$(MKCONFIG_TYPE)" = "perl" ]; then \ . ./$(MKC_ENV_SHR);perl \ $(MKC_DIR)/mkconfig.pl \ $(MKC_CONF_TCL); fi $(MKC_REQLIB): config.h @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -reqlib \ -o $(MKC_REQLIB) config.h $(MKC_TCLREQLIB): configtcl.h @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -reqlib \ -o $(MKC_TCLREQLIB) configtcl.h ### # executables LIBOBJECTS = dimain$(OBJ_EXT) didiskutil$(OBJ_EXT) \ digetentries$(OBJ_EXT) digetinfo$(OBJ_EXT) \ diquota$(OBJ_EXT) display$(OBJ_EXT) getoptn$(OBJ_EXT) \ options$(OBJ_EXT) realloc$(OBJ_EXT) strdup$(OBJ_EXT) \ strstr$(OBJ_EXT) trimchar$(OBJ_EXT) MAINOBJECTS = di$(OBJ_EXT) TCLOBJECTS = tcldiskspace$(OBJ_EXT) di$(EXE_EXT): $(MKC_REQLIB) $(MAINOBJECTS) $(LIBOBJECTS) @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh \ -link -exec $(MKC_ECHO) \ -r $(MKC_REQLIB) -o di$(EXE_EXT) \ $(MAINOBJECTS) $(LIBOBJECTS) # for ms cl #di$(EXE_EXT): $(MAINOBJECTS) $(LIBOBJECTS) # $(LD) -Fedi$(EXE_EXT) $(MAINOBJECTS) $(LIBOBJECTS) tcldiskspace.bld: $(MKC_REQLIB) $(MKC_TCLREQLIB) \ $(TCLOBJECTS) $(LIBOBJECTS) @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -link -shared $(MKC_ECHO) \ -lib -o diskspace$(SHLIB_EXT) \ -r $(MKC_REQLIB) -r $(MKC_TCLREQLIB) \ $(TCLOBJECTS) $(LIBOBJECTS) $(LIBS) @touch tcldiskspace.bld perlfilesysdi.bld: $(MKC_REQLIB) $(LIBOBJECTS) @echo "*** Using libs: `$(CAT) $(MKC_REQLIB)`" @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -staticlib $(MKC_ECHO) \ -o libdiperl.a $(LIBOBJECTS) $(LIBS) \ `$(CAT) $(MKC_REQLIB)` # Don't know how to pass additional libs to Makefile.PL # so pass all the information. ( \ cd Perl ; \ perl Makefile.PL LIBS="-L.. -ldiperl `$(CAT) ../$(MKC_REQLIB)`" ; \ $(MAKE) ; \ $(MAKE) test ; \ ) @touch perlfilesysdi.bld mingw-di$(EXE_EXT): $(MAINOBJECTS) $(LIBOBJECTS) $(CC) -o mingw-di$(EXE_EXT) \ $(DI_CFLAGS) $(LDFLAGS) $(LIBOBJECTS) $(LIBS) ### # objects .c$(OBJ_EXT): @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -compile $(MKC_ECHO) \ $(DI_SHARED) $(DI_CFLAGS) $< # for ms cl #.c$(OBJ_EXT): # $(CC) -c $(DI_SHARED) $(DI_CFLAGS) $< di$(OBJ_EXT): di.c config.h di.h dimain.h getoptn.h \ options.h version.h tcldiskspace$(OBJ_EXT): tcldiskspace.c config.h di.h \ dimain.h getoptn.h \ options.h dimain$(OBJ_EXT): dimain.c config.h di.h dimain.h getoptn.h \ options.h digetinfo$(OBJ_EXT): digetinfo.c config.h di.h dimntopt.h didiskutil$(OBJ_EXT): didiskutil.c config.h di.h dimntopt.h digetentries$(OBJ_EXT): digetentries.c config.h di.h dimntopt.h diquota$(OBJ_EXT): diquota.c config.h di.h display$(OBJ_EXT): display.c config.h di.h display.h options.h version.h getoptn$(OBJ_EXT): getoptn.c config.h getoptn.h options$(OBJ_EXT): options.c config.h di.h options.h realloc$(OBJ_EXT): realloc.c config.h di.h strdup$(OBJ_EXT): strdup.c config.h di.h strstr$(OBJ_EXT): strstr.c config.h di.h trimchar$(OBJ_EXT): trimchar.c config.h di.h ### # regression testing .PHONY: all-test all-test: tests.done tests.done: $(MKC_DIR)/runtests.sh @echo "## running tests" CC=$(CC) DC=$(DC) $(_MKCONFIG_SHELL) \ $(MKC_DIR)/runtests.sh ./tests.d touch tests.done # needs environment .PHONY: testrpmbuild testrpmbuild: -$(TEST) -d ./rpmbuild && rm -rf ./rpmbuild $(MKDIR) -p ./rpmbuild/SOURCES $(MKDIR) -p ./rpmbuild/BUILD $(CP) -f $(DI_DIR)/di-$(DI_VERSION).tar.gz ./rpmbuild/SOURCES $(LN) -f ./rpmbuild/SOURCES/di-$(DI_VERSION).tar.gz ./rpmbuild/SOURCES/download $(RPMBUILD) --define="_topdir `pwd`/rpmbuild" -ba ../di.spec $(TEST) -f ./rpmbuild/RPMS/$(MARCH)/di-$(DI_VERSION)-1.$(MARCH).rpm || exit 1 $(TEST) -f ./rpmbuild/SRPMS/di-$(DI_VERSION)-1.src.rpm || exit 1 $(TEST) -d ./rpmbuild && rm -rf ./rpmbuild # needs environment .PHONY: rtest-env rtest-env: @echo "$(_MKCONFIG_SYSTYPE)" @echo "$(_MKCONFIG_SYSREV)" @echo "$(_MKCONFIG_SYSARCH)" @echo "$(CC)" @echo "$(_MKCONFIG_USING_GCC)" @echo "$(CFLAGS_OPTIMIZE)" @echo "$(CFLAGS_COMPILER)" @echo "$(LDFLAGS_COMPILER)" @echo "$(OBJ_EXT)" @echo "$(EXE_EXT)" @echo "$(XMSGFMT)" .PHONY: test-env test-env: @echo "cc: $(CC)" @echo "make: $(MAKE)" gconfig.h: $(MKC_ENV) mkc_config/di-getoptn.mkc @-$(RM) -f gconfig.h @if [ "$(MKCONFIG_TYPE)" = "sh" -o "$(MKCONFIG_TYPE)" = "" ]; then \ . ./$(MKC_ENV); \ $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh \ $(MKC_CONF_GETOPTN); fi @if [ "$(MKCONFIG_TYPE)" = "perl" ]; then \ . ./$(MKC_ENV); \ perl $(MKC_DIR)/mkconfig.pl \ $(MKC_CONF_GETOPTN); fi getoptn_test$(OBJ_EXT): getoptn.c gconfig.h getoptn.h @. ./$(MKC_ENV);$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -compile \ -DTEST_GETOPTN=1 \ -o getoptn_test$(OBJ_EXT) getoptn.c getoptn.reqlibs: $(MKC_ENV) gconfig.h @. ./$(MKC_ENV);$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -reqlib \ -o getoptn.reqlibs gconfig.h getoptn_test.exe: getoptn_test$(OBJ_EXT) getoptn.reqlibs @. ./$(MKC_ENV);$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -link -exec \ $(MKC_ECHO) -r getoptn.reqlibs \ -o getoptn_test.exe $(LDFLAGS) \ getoptn_test$(OBJ_EXT) di-4.52/C/dimain.h0000644000175000017500000000170514421556642011754 0ustar bllbll#ifndef DI_INC_DIMAIN_H #define DI_INC_DIMAIN_H /* * Copyright 2016-2018 Brad Lanam Walnut Creek CA USA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" # if defined (__cplusplus) || defined (c_plusplus) extern "C" { # endif #if ! _dcl_errno extern int errno; #endif /* dimain.c */ extern char *dimainproc (int, const char * const [], int, diData_t *); extern void checkDiskInfo (diData_t *, int); extern void checkDiskQuotas (diData_t *); extern int checkFileInfo (diData_t *, int, int, const char *const[]); extern void cleanup (diData_t *); extern int getDiskSpecialInfo (diData_t *, unsigned int); extern void getDiskStatInfo (diData_t *); extern void preCheckDiskInfo (diData_t *); extern void initLocale (void); extern void initZones (diData_t *); # if defined (__cplusplus) || defined (c_plusplus) } # endif #endif /* DI_INC_DIMAIN_H */ di-4.52/C/display.c0000644000175000017500000012050314421556642012151 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #include "display.h" #include "options.h" #include "version.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_ctype # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _hdr_libintl # include #endif #if _hdr_wchar # include #endif #if _use_mcheck # include #endif extern int debug; #define DI_FMT_VALID_CHARS "mMsStTbBucfvp12a3iUFPIO" /* mount information */ #define DI_FMT_MOUNT 'm' #define DI_FMT_MOUNT_FULL 'M' #define DI_FMT_SPECIAL 's' #define DI_FMT_SPECIAL_FULL 'S' #define DI_FMT_TYPE 't' #define DI_FMT_TYPE_FULL 'T' /* disk information */ #define DI_FMT_BTOT 'b' #define DI_FMT_BTOT_AVAIL 'B' #define DI_FMT_BUSED 'u' #define DI_FMT_BCUSED 'c' #define DI_FMT_BFREE 'f' #define DI_FMT_BAVAIL 'v' #define DI_FMT_BPERC_NAVAIL 'p' #define DI_FMT_BPERC_USED '1' #define DI_FMT_BPERC_BSD '2' #define DI_FMT_BPERC_AVAIL 'a' #define DI_FMT_BPERC_FREE '3' #define DI_FMT_ITOT 'i' #define DI_FMT_IUSED 'U' #define DI_FMT_IFREE 'F' #define DI_FMT_IPERC 'P' #define DI_FMT_MOUNT_TIME 'I' #define DI_FMT_MOUNT_OPTIONS 'O' typedef struct { const char fmtChar; const char *displayName; const char *posixName; const char *jsonName; } formatNames_t; static formatNames_t formatNames [] = { { DI_FMT_MOUNT, "Mount", NULL, "mount" }, { DI_FMT_MOUNT_FULL, "Mount", "Mounted On", "mount" }, { DI_FMT_SPECIAL, "Filesystem", NULL, "filesystem" }, { DI_FMT_SPECIAL_FULL, "Filesystem", NULL, "filesystem" }, { DI_FMT_TYPE, "fsType", NULL, "fstype" }, { DI_FMT_TYPE_FULL, "fs Type", NULL, "fstype" }, { DI_FMT_BTOT, NULL, NULL, "size" }, { DI_FMT_BTOT_AVAIL, NULL, NULL, "size" }, { DI_FMT_BUSED, "Used", NULL, "used" }, { DI_FMT_BCUSED, "Used", NULL, "used" }, { DI_FMT_BFREE, "Free", NULL, "free" }, { DI_FMT_BAVAIL, "Avail", "Available", "available" }, { DI_FMT_BPERC_NAVAIL, "%Used", "Capacity", "percused" }, { DI_FMT_BPERC_USED, "%Used", "Capacity", "percused" }, { DI_FMT_BPERC_BSD, "%Used", "Capacity", "percused" }, { DI_FMT_BPERC_AVAIL, "%Free", NULL, "percfree" }, { DI_FMT_BPERC_FREE, "%Free", NULL, "percfree" }, { DI_FMT_ITOT, "Inodes", NULL, "inodes" }, { DI_FMT_IUSED, "IUsed", NULL, "inodesused" }, { DI_FMT_IFREE, "IFree", NULL, "inodesfree" }, { DI_FMT_IPERC, "%IUsed", NULL, "percinodesused" }, { DI_FMT_MOUNT_TIME, "Mount Time", NULL, "mounttime" }, { DI_FMT_MOUNT_OPTIONS, "Options", NULL, "options" } }; #define DI_FORMATNAMES_SIZE (sizeof (formatNames) / sizeof (formatNames_t)) #define DI_SORT_NONE 'n' #define DI_SORT_MOUNT 'm' #define DI_SORT_SPECIAL 's' #define DI_SORT_TOTAL 'T' #define DI_SORT_FREE 'f' #define DI_SORT_AVAIL 'a' #define DI_SORT_REVERSE 'r' #define DI_SORT_TYPE 't' #define DI_SORT_ASCENDING 1 #define DI_PERC_FMT " %%3.0%s%%%% " #define DI_POSIX_PERC_FMT " %%3.0%s%%%% " #define DI_JUST_LEFT 0 #define DI_JUST_RIGHT 1 typedef struct { _print_size_t low; _print_size_t high; _print_size_t dbs; /* display block size */ const char *format; const char *suffix; } sizeTable_t; static sizeTable_t sizeTable [] = { { 0, 0, 1, (char *) NULL, " " }, { 0, 0, 0, (char *) NULL, "K" }, #define DI_ONE_MEG_SZTAB 2 { 0, 0, 0, (char *) NULL, "M" }, { 0, 0, 0, (char *) NULL, "G" }, { 0, 0, 0, (char *) NULL, "T" }, { 0, 0, 0, (char *) NULL, "P" }, { 0, 0, 0, (char *) NULL, "E" }, { 0, 0, 0, (char *) NULL, "Z" }, { 0, 0, 0, (char *) NULL, "Y" } }; #define DI_SIZETAB_SIZE (sizeof (sizeTable) / sizeof (sizeTable_t)) #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif static void addTotals _((const diDiskInfo_t *, diDiskInfo_t *, int)); static void getMaxFormatLengths _((diData_t *)); static int diCompare _((const diOptions_t *, const diDiskInfo_t *, unsigned int, unsigned int)); static int findDispSize _((_print_size_t)); static Size_t istrlen _((const char *)); static char *printInfo _((diDiskInfo_t *, diOptions_t *, diOutput_t *)); static char *printSpace _((const diOptions_t *, const diOutput_t *, _fs_size_t, int)); static char *processTitles _((diOptions_t *, diOutput_t *)); static char *printPerc _((_fs_size_t, _fs_size_t, const char *)); static void initSizeTable _((diOptions_t *, diOutput_t *)); static void appendFormatStr _((char *, const char *, char **, Size_t *, Size_t *)); static void appendFormatVal _((char *, _fs_size_t, char **, Size_t *, Size_t *)); static void append _((const char *, char **, Size_t *, Size_t *)); #if defined (__cplusplus) || defined (c_plusplus) } #endif /* * printDiskInfo * * Print out the disk information table. * Loops through all mounted disks, prints and calculates totals. * * The method to get widths and handle titles and etc. is rather a * mess. There may be a better way to handle it. * */ char * printDiskInfo (diData_t *diData) { int i; diOptions_t *diopts; diDiskInfo_t *diskInfo; diDiskInfo_t totals; char lastpool [DI_SPEC_NAME_LEN + 1]; Size_t lastpoollen = { 0 }; int inpool = { FALSE }; diOutput_t *diout; char *out; Size_t outlen; Size_t outcurrlen; char *tout; int first; int ishr; first = TRUE; out = (char *) NULL; outlen = 0; outcurrlen = 0; lastpool[0] = '\0'; diopts = &diData->options; diout = &diData->output; initSizeTable (diopts, diout); if (diopts->printTotals) { di_initDiskInfo (&totals); strncpy (totals.name, DI_GT("Total"), (Size_t) DI_NAME_LEN); totals.printFlag = DI_PRNT_OK; } getMaxFormatLengths (diData); tout = processTitles (diopts, diout); if (diopts->printHeader) { append (tout, &out, &outcurrlen, &outlen); } free (tout); if (diopts->json_output) { tout = "{\n \"partitions\" : [\n"; append (tout, &out, &outcurrlen, &outlen); } if (diopts->dispBlockSize == (_print_size_t) DI_DISP_HR || diopts->dispBlockSize == (_print_size_t) DI_DISP_HR_2) { --diout->width; } ishr = diopts->dispBlockSize == (_print_size_t) DI_DISP_HR || diopts->dispBlockSize == (_print_size_t) DI_DISP_HR_2; if (! ishr && (diopts->dispBlockSize > 0 && diopts->dispBlockSize <= (_print_size_t) DI_VAL_1024)) { if (diopts->csv_output || diopts->json_output) { Snprintf1 (diout->blockFormat, sizeof (diout->blockFormat), "%%.0%s%%s", DI_Lf); } else { Snprintf2 (diout->blockFormat, sizeof (diout->blockFormat), "%%%d.0%s%%s", (int) diout->width, DI_Lf); } } else { if (diopts->csv_output || diopts->json_output) { Snprintf1 (diout->blockFormatNR, sizeof (diout->blockFormatNR), "%%.0%s%%s", DI_Lf); if (! ishr) { Snprintf1 (diout->blockFormat, sizeof (diout->blockFormat), "%%.1%s%%s", DI_Lf); } else { Snprintf1 (diout->blockFormat, sizeof (diout->blockFormat), "\"%%.1%s%%s\"", DI_Lf); } } else { Snprintf2 (diout->blockFormatNR, sizeof (diout->blockFormatNR), "%%%d.0%s%%s", (int) diout->width, DI_Lf); Snprintf2 (diout->blockFormat, sizeof (diout->blockFormat), "%%%d.1%s%%s", (int) diout->width, DI_Lf); } } if (diopts->dispBlockSize == (_print_size_t) DI_DISP_HR || diopts->dispBlockSize == (_print_size_t) DI_DISP_HR_2) { ++diout->width; } if (diopts->csv_output || diopts->json_output) { Snprintf1 (diout->inodeFormat, sizeof (diout->inodeFormat), "%%%s", DI_LLu); } else { Snprintf2 (diout->inodeFormat, sizeof (diout->inodeFormat), "%%%d%s", (int) diout->inodeWidth, DI_LLu); } diskInfo = diData->diskInfo; if (diopts->printTotals) { if (diData->haspooledfs && ! diData->totsorted) { char tempSortType [DI_SORT_MAX + 1]; /* in order to find the main pool entries, */ /* we must have the array sorted by special device name */ strncpy (tempSortType, diopts->sortType, DI_SORT_MAX); strncpy (diopts->sortType, "s", DI_SORT_MAX); sortArray (diopts, diskInfo, diData->count, DI_TOT_SORT_IDX); strncpy (diopts->sortType, tempSortType, DI_SORT_MAX); diData->totsorted = TRUE; } for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; int ispooled; int startpool; ispooled = FALSE; startpool = FALSE; dinfo = &(diskInfo [diskInfo [i].sortIndex[DI_TOT_SORT_IDX]]); /* is it a pooled filesystem type? */ if (diData->haspooledfs && di_isPooledFs (dinfo)) { ispooled = TRUE; if (lastpoollen == 0 || strncmp (lastpool, dinfo->special, lastpoollen) != 0) { strncpy (lastpool, dinfo->special, DI_SPEC_NAME_LEN); lastpoollen = di_mungePoolName (lastpool); inpool = FALSE; startpool = TRUE; if (strcmp (dinfo->fsType, "null") == 0 && strcmp (dinfo->special + strlen (dinfo->special) - 5, "00000") != 0) { /* dragonflybsd doesn't have the main pool mounted */ inpool = TRUE; } } } else { inpool = FALSE; } if (dinfo->doPrint) { addTotals (dinfo, &totals, inpool); } else { if (debug > 2) { printf ("tot:%s:%s:skip\n", dinfo->special, dinfo->name); } } if (startpool) { inpool = TRUE; } } /* for each entry */ } /* if the totals are to be printed */ diskInfo = diData->diskInfo; if (strcmp (diopts->sortType, "n") != 0) { sortArray (diopts, diskInfo, diData->count, DI_MAIN_SORT_IDX); } for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &(diskInfo [diskInfo [i].sortIndex[DI_MAIN_SORT_IDX]]); if (debug > 5) { printf ("pdi:%s:%s:%d:\n", dinfo->name, getPrintFlagText ((int) dinfo->printFlag), dinfo->doPrint); } if (! dinfo->doPrint) { continue; } if (! first && diopts->json_output) { append (",\n", &out, &outcurrlen, &outlen); } first = FALSE; tout = printInfo (dinfo, diopts, diout); append (tout, &out, &outcurrlen, &outlen); free (tout); } if (diopts->json_output) { append ("\n", &out, &outcurrlen, &outlen); } if (diopts->printTotals) { tout = printInfo (&totals, diopts, diout); append (tout, &out, &outcurrlen, &outlen); free (tout); } if (diopts->json_output) { tout = " ]\n}\n"; append (tout, &out, &outcurrlen, &outlen); } return out; } /* * sortArray * */ void sortArray (diOptions_t *diopts, diDiskInfo_t *data, int count, int sidx) { unsigned int tempIndex; int gap; register int j; register int i; if (count <= 1) { return; } gap = 1; while (gap < count) { gap = 3 * gap + 1; } for (gap /= 3; gap > 0; gap /= 3) { for (i = gap; i < count; ++i) { tempIndex = data[i].sortIndex[sidx]; j = i - gap; while (j >= 0 && diCompare (diopts, data, data[j].sortIndex[sidx], tempIndex) > 0) { data[j + gap].sortIndex[sidx] = data[j].sortIndex[sidx]; j -= gap; } j += gap; if (j != i) { data[j].sortIndex[sidx] = tempIndex; } } } } /* for debugging */ const char * getPrintFlagText (int pf) { return pf == DI_PRNT_OK ? "ok" : pf == DI_PRNT_BAD ? "bad" : pf == DI_PRNT_IGNORE ? "ignore" : pf == DI_PRNT_EXCLUDE ? "exclude" : pf == DI_PRNT_OUTOFZONE ? "outofzone" : pf == DI_PRNT_FORCE ? "force" : pf == DI_PRNT_SKIP ? "skip" : "unknown"; } static void appendFormatStr (char *fmt, const char *val, char **ptr, Size_t *clen, Size_t *len) { char tdata [1024]; Snprintf1 (tdata, sizeof(tdata), fmt, val); append (tdata, ptr, clen, len); } static void appendFormatVal (char *fmt, _fs_size_t val, char **ptr, Size_t *clen, Size_t *len) { char tdata [1024]; Snprintf1 (tdata, sizeof(tdata), fmt, val); append (tdata, ptr, clen, len); } static void append (const char *val, char **ptr, Size_t *clen, Size_t *len) { Size_t vlen; Size_t bumplen; Size_t nlen; if (val == (char *) NULL) { return; } bumplen = 100; vlen = strlen (val); if (*clen + vlen >= *len) { nlen = vlen + *clen + 1; *ptr = (char *) realloc (*ptr, nlen); memset (*ptr+*clen, 0, nlen-*clen); *len = nlen; } strcat (*ptr, val); *clen += vlen; } /* * printInfo * * Print the information for a single partition. Loop through the * format string and print the particular items wanted. * */ static char * printInfo (diDiskInfo_t *diskInfo, diOptions_t *diopts, diOutput_t *diout) { _fs_size_t used; _fs_size_t totAvail; const char *ptr; char tfmt[2]; int valid; _print_size_t temp; int idx; int tidx; static char percFormat [15]; static int percInit = FALSE; int first; char ttext[2]; char *out; char *tout; const char *t; Size_t outlen; Size_t outcurrlen; int i; out = (char *) NULL; outlen = 0; outcurrlen = 0; if (diopts->json_output) { t = " {\n"; append (t, &out, &outcurrlen, &outlen); } first = TRUE; if (! percInit) { if (diopts->json_output) { Snprintf1 (percFormat, sizeof(percFormat), "%%.0%s", DI_Lf); } else if (diopts->csv_output) { Snprintf1 (percFormat, sizeof(percFormat), "%%.0%s%%%%", DI_Lf); } else { if (diopts->posix_compat) { Snprintf1 (percFormat, sizeof(percFormat), DI_POSIX_PERC_FMT, DI_Lf); } else { Snprintf1 (percFormat, sizeof(percFormat), DI_PERC_FMT, DI_Lf); } } percInit = TRUE; } idx = 0; temp = (_print_size_t) 0.0; /* gcc compile warning */ if (diopts->dispBlockSize == (_print_size_t) DI_DISP_HR_2) { idx = DI_ONE_MEG_SZTAB; /* default */ ptr = diopts->formatString; while (*ptr) { valid = FALSE; switch (*ptr) { case DI_FMT_BTOT: { temp = (_print_size_t) diskInfo->totalSpace; valid = TRUE; break; } case DI_FMT_BTOT_AVAIL: { temp = (_print_size_t) (diskInfo->totalSpace - (diskInfo->freeSpace - diskInfo->availSpace)); valid = TRUE; break; } case DI_FMT_BUSED: { temp = (_print_size_t) (diskInfo->totalSpace - diskInfo->freeSpace); valid = TRUE; break; } case DI_FMT_BCUSED: { temp = (_print_size_t) (diskInfo->totalSpace - diskInfo->availSpace); valid = TRUE; break; } case DI_FMT_BFREE: { temp = (_print_size_t) diskInfo->freeSpace; valid = TRUE; break; } case DI_FMT_BAVAIL: { temp = (_print_size_t) diskInfo->availSpace; valid = TRUE; break; } } if (valid) { tidx = findDispSize (temp); /* want largest index */ if (tidx > idx) { idx = tidx; } } ++ptr; } } ptr = diopts->formatString; while (*ptr) { tfmt[0] = *ptr; tfmt[1] = '\0'; valid = strstr (DI_FMT_VALID_CHARS, tfmt) == NULL ? FALSE : TRUE; if (*ptr == DI_FMT_MOUNT_TIME && diout->maxMntTimeString == 0) { valid = FALSE; } if (valid && (diopts->csv_output || diopts->json_output)) { if (! first) { t = ","; if (diopts->csv_tabs) { t = " "; /* tab here */ } if (diopts->json_output) { t = ",\n"; } append (t, &out, &outcurrlen, &outlen); } first = FALSE; } if (valid && diopts->json_output) { for (i = 0; i < (int) DI_FORMATNAMES_SIZE; ++i) { if (*ptr == formatNames[i].fmtChar) { t = " \""; append (t, &out, &outcurrlen, &outlen); t = formatNames[i].jsonName; append (t, &out, &outcurrlen, &outlen); t = "\" : "; append (t, &out, &outcurrlen, &outlen); break; } } } switch (*ptr) { case DI_FMT_MOUNT: case DI_FMT_MOUNT_FULL: { appendFormatStr (diout->mountFormat, diskInfo->name, &out, &outcurrlen, &outlen); break; } case DI_FMT_BTOT: { tout = printSpace (diopts, diout, diskInfo->totalSpace, idx); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BTOT_AVAIL: { tout = printSpace (diopts, diout, diskInfo->totalSpace - (diskInfo->freeSpace - diskInfo->availSpace), idx); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BUSED: { tout = printSpace (diopts, diout, diskInfo->totalSpace - diskInfo->freeSpace, idx); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BCUSED: { tout = printSpace (diopts, diout, diskInfo->totalSpace - diskInfo->availSpace, idx); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BFREE: { tout = printSpace (diopts, diout, diskInfo->freeSpace, idx); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BAVAIL: { tout = printSpace (diopts, diout, diskInfo->availSpace, idx); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BPERC_NAVAIL: { used = diskInfo->totalSpace - diskInfo->availSpace; totAvail = diskInfo->totalSpace; tout = printPerc (used, totAvail, percFormat); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BPERC_USED: { used = diskInfo->totalSpace - diskInfo->freeSpace; totAvail = diskInfo->totalSpace; tout = printPerc (used, totAvail, percFormat); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BPERC_BSD: { used = diskInfo->totalSpace - diskInfo->freeSpace; totAvail = diskInfo->totalSpace - (diskInfo->freeSpace - diskInfo->availSpace); tout = printPerc (used, totAvail, percFormat); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BPERC_AVAIL: { _fs_size_t bfree; bfree = diskInfo->availSpace; totAvail = diskInfo->totalSpace; tout = printPerc (bfree, totAvail, percFormat); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_BPERC_FREE: { _fs_size_t bfree; bfree = diskInfo->freeSpace; totAvail = diskInfo->totalSpace; tout = printPerc (bfree, totAvail, percFormat); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_ITOT: { appendFormatVal (diout->inodeFormat, diskInfo->totalInodes, &out, &outcurrlen, &outlen); break; } case DI_FMT_IUSED: { appendFormatVal (diout->inodeFormat, diskInfo->totalInodes - diskInfo->freeInodes, &out, &outcurrlen, &outlen); break; } case DI_FMT_IFREE: { appendFormatVal (diout->inodeFormat, diskInfo->freeInodes, &out, &outcurrlen, &outlen); break; } case DI_FMT_IPERC: { used = diskInfo->totalInodes - diskInfo->availInodes; totAvail = diskInfo->totalInodes; tout = printPerc (used, totAvail, percFormat); append (tout, &out, &outcurrlen, &outlen); break; } case DI_FMT_SPECIAL: case DI_FMT_SPECIAL_FULL: { appendFormatStr (diout->specialFormat, diskInfo->special, &out, &outcurrlen, &outlen); break; } case DI_FMT_TYPE: case DI_FMT_TYPE_FULL: { appendFormatStr (diout->typeFormat, diskInfo->fsType, &out, &outcurrlen, &outlen); break; } case DI_FMT_MOUNT_OPTIONS: { appendFormatStr (diout->optFormat, diskInfo->options, &out, &outcurrlen, &outlen); break; } case DI_FMT_MOUNT_TIME: { break; } default: { if (! diopts->json_output) { ttext[0] = *ptr; ttext[1] = '\0'; append (ttext, &out, &outcurrlen, &outlen); } break; } } ++ptr; if (! diopts->csv_output && ! diopts->json_output && *ptr && valid) { append (" ", &out, &outcurrlen, &outlen); } } if (diopts->json_output) { append ("\n }", &out, &outcurrlen, &outlen); } if (! diopts->json_output && outcurrlen > 0) { append ("\n", &out, &outcurrlen, &outlen); } return out; } static char * printSpace (const diOptions_t *diopts, const diOutput_t *diout, _fs_size_t usage, int idx) { _print_size_t tdbs; _print_size_t mult; _print_size_t temp; const char *suffix; const char *format; static char tdata [1024]; suffix = ""; format = diout->blockFormat; tdbs = diopts->dispBlockSize; if (diopts->dispBlockSize == (_print_size_t) DI_DISP_HR) { temp = (_print_size_t) usage; idx = findDispSize (temp); } if (diopts->dispBlockSize == (_print_size_t) DI_DISP_HR || diopts->dispBlockSize == (_print_size_t) DI_DISP_HR_2) { if (idx == -1) { tdbs = sizeTable [DI_ONE_MEG].dbs; } else { tdbs = sizeTable [idx].dbs; format = sizeTable [idx].format; suffix = sizeTable [idx].suffix; } } mult = (_print_size_t) 1.0 / tdbs; Snprintf2 (tdata, sizeof(tdata), format, (_print_size_t) usage * mult, suffix); return tdata; } static int findDispSize (_print_size_t siz) { int i; for (i = 0; i < (int) DI_SIZETAB_SIZE; ++i) { if (siz >= sizeTable [i].low && siz < sizeTable [i].high) { return i; } } return -1; } /* * addTotals * * Add up the totals for the blocks/inodes * */ static void addTotals (const diDiskInfo_t *diskInfo, diDiskInfo_t *totals, int inpool) { if (debug > 2) { printf ("tot:%s:%s:inp:%d\n", diskInfo->special, diskInfo->name, inpool); } /* * zfs: * The total is the space used + the space free. * Free space is the space available in the pool. * Available space is the space available in the pool. * Thus: total - free = used. * -- To get the real total, add the total for the pool * and all used space for all inpool filesystems. * * apfs: * An easy hierarchy: * /dev/disk1 the container, is not mounted. * /dev/disk1s1 partition 1 * /dev/disk1s2 partition 2 * /dev/disk1s3 partition 3 * The first disk is used as the root of the pool, even though it * is not the container. * The total is the total space. * Free space is the space available + space used. * (or total space - space used). * Available space is the space available in the pool. * Thus: total - free = used. * -- To get (totals - free) to work for the totals, subtract * all free space returned by in-pool filesystems. * * hammer, hammer2: * Typically, a null mount is used such as: * /dev/serno/SERIAL.s1a /build hammer * /build/usr /usr null * /build/usr.local /usr/local null * There are also pfs mounts: * /dev/ad1s1a@LOCAL /d1 hammer2 * /dev/ad1s1a@d1.a /d1/a hammer2 * Or * /dev/serno/SERIAL.s1a /mnt hammer2 * /dev/serno/SERIAL.s1a@mnt.usr /mnt/usr hammer2 * Or * @build /build hammer2 * @build.var /build/var null * Difficult to process, as the naming is not consistent. * Not implemented. * * advfs: * Unknown. Assume the same as zfs. */ if (inpool) { if (debug > 2) {printf (" tot:inpool:\n"); } if (strcmp (diskInfo->fsType, "apfs") == 0) { totals->freeSpace -= diskInfo->totalSpace - diskInfo->freeSpace; } else { /* zfs, old hammer, advfs */ totals->totalSpace += diskInfo->totalSpace - diskInfo->freeSpace; totals->totalInodes += diskInfo->totalInodes - diskInfo->freeInodes; } } else { if (debug > 2) {printf (" tot:not inpool:add all totals\n"); } totals->totalSpace += diskInfo->totalSpace; totals->freeSpace += diskInfo->freeSpace; totals->availSpace += diskInfo->availSpace; totals->totalInodes += diskInfo->totalInodes; totals->freeInodes += diskInfo->freeInodes; totals->availInodes += diskInfo->availInodes; } } /* * processTitles * * Sets up the column format strings w/the appropriate defaults. * Loop through the format string and adjust the various column sizes. * * At the same time print the titles. * */ static char * processTitles (diOptions_t *diopts, diOutput_t *diout) { const char *ptr; int valid; Size_t wlen; Size_t *wlenptr; int justification; const char *pstr = { "" }; char *fstr; Size_t maxsize; char tformat [30]; char ttext [2]; int first; char *out; Size_t outcurrlen; Size_t outlen; int i; out = (char *) NULL; outlen = 0; outcurrlen = 0; first = TRUE; if (diopts->printDebugHeader) { printf (DI_GT("di version %s Default Format: %s\n"), DI_VERSION, DI_DEFAULT_FORMAT); } ptr = diopts->formatString; while (*ptr) { valid = TRUE; wlen = 0; wlenptr = (Size_t *) NULL; fstr = (char *) NULL; maxsize = 0; justification = DI_JUST_LEFT; for (i = 0; i < (int) DI_FORMATNAMES_SIZE; ++i) { if (*ptr == formatNames[i].fmtChar) { pstr = formatNames[i].displayName; if (diopts->posix_compat && formatNames[i].posixName != NULL) { pstr = formatNames[i].posixName; } if (pstr == NULL) { pstr = diout->dispBlockLabel; } break; } } switch (*ptr) { case DI_FMT_MOUNT: { wlen = 15; wlenptr = &diout->maxMountString; fstr = diout->mountFormat; maxsize = sizeof (diout->mountFormat) - 1; break; } case DI_FMT_MOUNT_FULL: { wlen = diout->maxMountString; if (wlen <= 0) { wlen = 7; } wlenptr = &diout->maxMountString; fstr = diout->mountFormat; maxsize = sizeof (diout->mountFormat) - 1; break; } case DI_FMT_BTOT: case DI_FMT_BTOT_AVAIL: { wlen = diout->width; wlenptr = &diout->width; justification = DI_JUST_RIGHT; break; } case DI_FMT_BUSED: case DI_FMT_BCUSED: { wlen = diout->width; wlenptr = &diout->width; justification = DI_JUST_RIGHT; break; } case DI_FMT_BFREE: { wlen = diout->width; wlenptr = &diout->width; justification = DI_JUST_RIGHT; break; } case DI_FMT_BAVAIL: { wlen = diout->width; wlenptr = &diout->width; justification = DI_JUST_RIGHT; break; } case DI_FMT_BPERC_NAVAIL: case DI_FMT_BPERC_USED: case DI_FMT_BPERC_BSD: { if (diopts->posix_compat) { wlen = 9; } else { wlen = 6; } break; } case DI_FMT_BPERC_AVAIL: case DI_FMT_BPERC_FREE: { wlen = 5; break; } case DI_FMT_ITOT: { justification = DI_JUST_RIGHT; wlen = diout->inodeWidth; wlenptr = &diout->inodeWidth; fstr = diout->inodeLabelFormat; maxsize = sizeof (diout->inodeLabelFormat) - 1; break; } case DI_FMT_IUSED: { justification = DI_JUST_RIGHT; wlen = diout->inodeWidth; wlenptr = &diout->inodeWidth; fstr = diout->inodeLabelFormat; maxsize = sizeof (diout->inodeLabelFormat) - 1; break; } case DI_FMT_IFREE: { justification = DI_JUST_RIGHT; wlen = diout->inodeWidth; wlenptr = &diout->inodeWidth; fstr = diout->inodeLabelFormat; maxsize = sizeof (diout->inodeLabelFormat) - 1; break; } case DI_FMT_IPERC: { wlen = 6; break; } case DI_FMT_SPECIAL: { wlen = 18; wlenptr = &diout->maxSpecialString; fstr = diout->specialFormat; maxsize = sizeof (diout->specialFormat) - 1; break; } case DI_FMT_SPECIAL_FULL: { wlen = diout->maxSpecialString; wlenptr = &diout->maxSpecialString; fstr = diout->specialFormat; maxsize = sizeof (diout->specialFormat) - 1; break; } case DI_FMT_TYPE: { wlen = 7; wlenptr = &diout->maxTypeString; fstr = diout->typeFormat; maxsize = sizeof (diout->typeFormat) - 1; break; } case DI_FMT_TYPE_FULL: { wlen = diout->maxTypeString; wlenptr = &diout->maxTypeString; fstr = diout->typeFormat; maxsize = sizeof (diout->typeFormat) - 1; break; } case DI_FMT_MOUNT_OPTIONS: { wlen = diout->maxOptString; wlenptr = &diout->maxOptString; fstr = diout->optFormat; maxsize = sizeof (diout->optFormat) - 1; break; } case DI_FMT_MOUNT_TIME: { break; } default: { if (! diopts->json_output) { ttext[0] = *ptr; ttext[1] = '\0'; append (ttext, &out, &outcurrlen, &outlen); } valid = FALSE; break; } } if (wlen > 0) { Size_t ilen; Size_t olen; Size_t len; Size_t tlen; const char *jstr; pstr = DI_GT (pstr); olen = (Size_t) strlen (pstr); ilen = (Size_t) istrlen (pstr); wlen = ilen > wlen ? ilen : wlen; len = wlen; tlen = len + olen - ilen; /* for the title only */ jstr = justification == DI_JUST_LEFT ? "-" : ""; Snprintf3 (tformat, sizeof (tformat), "%%%s%d.%ds", jstr, (int) tlen, (int) tlen); if (diopts->csv_output) { if (! first) { if (diopts->csv_tabs) { append (" ", &out, &outcurrlen, &outlen); /* tab here */ } else { append (",", &out, &outcurrlen, &outlen); } } first = FALSE; } /* title handling */ if (diopts->csv_output) { ttext[0] = *ptr; ttext[1] = '\0'; append (ttext, &out, &outcurrlen, &outlen); } else { appendFormatStr (tformat, pstr, &out, &outcurrlen, &outlen); } if (fstr != (char *) NULL) { if (diopts->csv_output || diopts->json_output) { if (diopts->csv_tabs) { strncpy (tformat, "%s", sizeof (tformat)); } else { strncpy (tformat, "\"%s\"", sizeof (tformat)); } } if (tlen != len) { if (! diopts->csv_output) { Snprintf3 (tformat, sizeof (tformat), "%%%s%d.%ds", jstr, (int) len, (int) len); } } /* copy the format string to whereever fstr is pointing */ strncpy (fstr, tformat, maxsize); } if (wlenptr != (Size_t *) NULL) { *wlenptr = wlen; } } ++ptr; if (! diopts->csv_output && *ptr && valid) { append (" ", &out, &outcurrlen, &outlen); } } if (outcurrlen > 0) { append ("\n", &out, &outcurrlen, &outlen); } return out; } /* * printPerc * * Calculate and print a percentage using the values and format passed. * */ static char * printPerc (_fs_size_t used, _fs_size_t totAvail, const char *format) { _print_size_t perc; static char tdata [1024]; if (totAvail > 0L) { perc = (_print_size_t) used / (_print_size_t) totAvail; perc *= (_print_size_t) 100.0; } else { perc = (_print_size_t) 0.0; } Snprintf1 (tdata, sizeof(tdata), format, perc); return tdata; } static int diCompare (const diOptions_t *diopts, const diDiskInfo_t *data, unsigned int idx1, unsigned int idx2) { int rc; int sortOrder; const char *ptr; const diDiskInfo_t *d1; const diDiskInfo_t *d2; /* reset sort order to the default start value */ sortOrder = DI_SORT_ASCENDING; rc = 0; d1 = &(data[idx1]); d2 = &(data[idx2]); ptr = diopts->sortType; while (*ptr) { switch (*ptr) { case DI_SORT_NONE: { break; } case DI_SORT_MOUNT: { rc = strcoll (d1->name, d2->name); rc *= sortOrder; break; } case DI_SORT_REVERSE: { sortOrder *= -1; break; } case DI_SORT_SPECIAL: { rc = strcoll (d1->special, d2->special); rc *= sortOrder; break; } case DI_SORT_TYPE: { rc = strcoll (d1->fsType, d2->fsType); rc *= sortOrder; break; } case DI_SORT_AVAIL: case DI_SORT_FREE: case DI_SORT_TOTAL: { int temp; temp = 0; switch (*ptr) { case DI_SORT_AVAIL: { temp = d1->availSpace == d2->availSpace ? 0 : d1->availSpace < d2->availSpace ? -1 : 1; break; } case DI_SORT_FREE: { temp = d1->freeSpace == d2->freeSpace ? 0 : d1->freeSpace < d2->freeSpace ? -1 : 1; break; } case DI_SORT_TOTAL: { temp = d1->totalSpace == d2->totalSpace ? 0 : d1->totalSpace < d2->totalSpace ? -1 : 1; break; } } rc *= sortOrder; break; } } /* switch on sort type */ if (rc != 0) { return rc; } ++ptr; } return rc; } static void getMaxFormatLengths (diData_t *diData) { int i; unsigned int len; diOutput_t *diout; diout = &diData->output; /* this loop gets the max string lengths */ for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo[i]; if (dinfo->doPrint) { if (diData->haspooledfs && (strcmp (dinfo->fsType, "zfs") == 0 || strcmp (dinfo->fsType, "advfs") == 0)) { diData->disppooledfs = TRUE; } len = (unsigned int) strlen (dinfo->name); if (len > diout->maxMountString) { diout->maxMountString = len; } len = (unsigned int) strlen (dinfo->special); if (len > diout->maxSpecialString) { diout->maxSpecialString = len; } len = (unsigned int) strlen (dinfo->fsType); if (len > diout->maxTypeString) { diout->maxTypeString = len; } len = (unsigned int) strlen (dinfo->options); if (len > diout->maxOptString) { diout->maxOptString = len; } len = (unsigned int) strlen (dinfo->mountTime); if (len > diout->maxMntTimeString) { diout->maxMntTimeString = len; } } /* if we are printing this item */ } /* for all disks */ } static Size_t istrlen (const char *str) { Size_t len; #if _lib_mbrlen && _enable_nls Size_t mlen; Size_t slen; mbstate_t ps; const char *tstr; len = 0; memset (&ps, 0, sizeof (mbstate_t)); slen = strlen (str); tstr = str; while (slen > 0) { mlen = mbrlen (tstr, slen, &ps); if ((int) mlen <= 0) { return strlen (str); } ++len; tstr += mlen; slen -= mlen; } #else len = strlen (str); #endif return len; } static void initSizeTable (diOptions_t *diopts, diOutput_t *diout) { int i; /* initialize display size tables */ sizeTable [0].format = diout->blockFormatNR; sizeTable [1].format = diout->blockFormat; sizeTable [0].high = diopts->baseDispSize; sizeTable [1].low = diopts->baseDispSize; sizeTable [1].high = diopts->baseDispSize * diopts->baseDispSize; sizeTable [1].dbs = diopts->baseDispSize; for (i = 2; i < (int) DI_SIZETAB_SIZE; ++i) { sizeTable [i].format = diout->blockFormat; sizeTable [i].low = sizeTable [i - 1].low * diopts->baseDispSize; sizeTable [i].high = sizeTable [i - 1].high * diopts->baseDispSize; sizeTable [i].dbs = sizeTable [i - 1].dbs * diopts->baseDispSize; } } di-4.52/C/configs/0000755000175000017500000000000014421556642011767 5ustar bllblldi-4.52/C/configs/config.mingw0000644000175000017500000001500014421556642014273 0ustar bllbll/* Created on: Fri Jan 22 10:38:48 PST 2016 From: ../features/mkconfig.dat Using: mkconfig-1.27 */ #ifndef __INC_CONFIG_H #define __INC_CONFIG_H 1 #define _hdr_stdio 1 #define _hdr_stdlib 1 #define _sys_types 1 #define _sys_param 1 #define _key_void 1 #define _key_const 1 #define _param_void_star 1 #define _proto_stdc 1 #define _hdr_ctype 1 #define _hdr_dcdef 0 #define _hdr_descrip 0 #define _hdr_dirent 1 #define _hdr_dvidef 0 #define _hdr_dvsdef 0 #define _hdr_errno 1 #define _hdr_fcntl 1 #define _hdr_fshelp 0 #define _hdr_gui_window 0 #define _hdr_jfs_quota 0 #define _hdr_kernel_fs_info 0 #define _hdr_limits 1 #define _hdr_linux_dqblk_xfs 0 #define _hdr_linux_quota 0 #define _hdr_libintl 0 #define _hdr_libprop_proplib 0 #define _hdr_locale 0 #define _hdr_malloc 1 #define _hdr_mcheck 0 #define _hdr_memory 1 #define _hdr_mntent 0 #define _hdr_mnttab 0 #define _hdr_quota 0 #define _hdr_rpc_rpc 0 #define _hdr_rpcsvc_rquota 0 #define _hdr_ssdef 0 #define _hdr_starlet 0 #define _hdr_storage_Directory 0 #define _hdr_storage_Entry 0 #define _hdr_storage_Path 0 #define _hdr_storage_volumes 0 #define _hdr_string 1 #define _hdr_strings 1 #define _hdr_time 1 #define _hdr_ufs_quota 0 #define _hdr_ufs_ufs_quota 0 #define _hdr_unistd 1 #define _hdr_util_string 0 #define _hdr_wchar 1 #define _hdr_windows 1 #define _hdr_winioctl 1 #define _hdr_zone 0 #define _sys_dcmd_blk 0 #define _sys_file 1 #define _sys_fs_types 0 #define _sys_fs_ufs_quota 0 #define _sys_fstyp 0 #define _sys_fstypes 0 #define _sys_ftype 0 #define _sys_io 0 #define _sys_mntctl 0 #define _sys_mntent 0 #define _sys_mnttab 0 #define _sys_mount 0 #define _sys_quota 0 #define _sys_stat 1 #define _sys_statfs 0 #define _sys_statvfs 0 #define _sys_time 1 #define _sys_vfs 0 #define _sys_vfs_quota 0 #define _sys_vfstab 0 #define _sys_vmount 0 #define _inc_conflict__hdr_time__sys_time 1 #define _inc_conflict__sys_quota__hdr_linux_quota 1 #define _command_msgfmt 0 #define _cmd_loc_msgfmt "/usr/bin/msgfmt" #define _command_rpmbuild 0 #define _const_O_NOCTTY 0 #define _define_bcopy 0 #define _define_bzero 0 #define _define_MCTL_QUERY 0 #define _define_memcpy 0 #define _define_memset 0 #define _define_QCMD 0 #define _define_S_ISLNK 0 #define _typ_struct_dqblk 0 #define _typ_struct_quotaval 0 #define _typ_struct_ufs_dqblk 0 #define _typ_fs_disk_quota_t 0 #define _typ_gid_t 0 #define _typ_statvfs_t 0 #define _typ_size_t 1 #define _typ_uint_t 0 #define _typ_uid_t 0 #define _lib_bcopy 0 #define _lib_bindtextdomain 0 #define _lib_bzero 0 #define _lib_CreateFile 1 #define _lib_DeviceIoControl 1 #define _lib_endmntent 0 #define _lib_fs_stat_dev 0 #define _lib_fshelp 0 #define _lib_GetDiskFreeSpace 1 #define _lib_GetDiskFreeSpaceEx 1 #define _lib_GetDriveType 1 #define _lib_getfsstat 0 #define _lib_GetLogicalDriveStrings 1 #define _lib_GetVolumeInformation 1 #define _lib_getmnt 0 #define _lib_getmntent 0 #define _lib_getmntinfo 0 #define _lib_gettext 0 #define _lib_getvfsstat 0 #define _lib_getzoneid 0 #define _lib_hasmntopt 0 #define _lib_lstat 0 #define _lib_mbrlen 1 #define _lib_mcheck_pedantic 0 #define _lib_memcpy 1 #define _lib_memset 1 #define _lib_mntctl 0 #define _lib_next_dev 0 #define _lib_prop_dictionary_create 0 #define _lib_quota_open 0 #define _lib_quotactl 0 #define _lib_realpath 0 #define _lib_setlocale 0 #define _lib_setmntent 0 #define _lib_snprintf 1 #define _lib_statfs 0 #define _lib_statvfs 0 #define _lib_strcoll 1 #define _lib_strdup 1 #define _lib_strstr 1 #define _lib_sys_dollar_device_scan 0 #define _lib_sys_dollar_getdviw 0 #define _lib_sysfs 0 #define _lib_textdomain 0 #define _lib_vquotactl 0 #define _lib_xdr_int 0 #define _lib_zone_getattr 0 #define _lib_zone_list 0 #define _memberxdr_rquota_rq_bhardlimit 0 #define _memberxdr_rquota_rq_bsoftlimit 0 #define _memberxdr_rquota_rq_curblocks 0 #define _memberxdr_rquota_rq_fhardlimit 0 #define _memberxdr_rquota_rq_fsoftlimit 0 #define _memberxdr_rquota_rq_curfiles 0 #define _memberxdr_getquota_args_gqa_uid 0 #define _args_getfsstat 0 #define _args_getvfsstat 0 #define _args_quotactl 0 #define _quotactl_pos_1 0 #define _quotactl_pos_2 0 #define _args_setmntent 0 #define _args_statfs 0 #define _class_os__Volumes 0 #define _npt_getenv 0 #define _npt_getmnt 1 #define _npt_mntctl 1 #define _npt_quotactl 1 #define _npt_statfs 0 #define _dcl_errno 1 #define _dcl_mnt_names 0 #define _mem_struct_dqblk_dqb_curspace 0 #define _mem_struct_dqblk_dqb_curblocks 0 #define _mem_struct_dqblk_dqb_fhardlimit 0 #define _mem_struct_dqblk_dqb_fsoftlimit 0 #define _mem_struct_dqblk_dqb_curfiles 0 #define _mem_struct_getquota_rslt_gqr_status 0 #define _mem_struct_getquota_rslt_gqr_rquota 0 #define _mem_struct_mnttab_mt_mntopts 0 #define _mem_struct_statfs_f_bsize 0 #define _mem_struct_statfs_f_fsize 0 #define _mem_struct_statfs_f_fstyp 0 #define _mem_struct_statfs_f_iosize 0 #define _mem_struct_statfs_f_frsize 0 #define _mem_struct_statfs_f_fstypename 0 #define _mem_struct_statfs_mount_info 0 #define _mem_struct_statfs_f_type 0 #define _mem_struct_statvfs_f_basetype 0 #define _siz_long_long 8 #define _siz_long_double 16 #define _printf_long_double 0 #define _has_std_quotas 0 #define _has_std_nfs_quotas 0 #define _use_mcheck 0 #define _enable_nls 0 #define DI_DEFAULT_FORMAT "MbuvpT" #define DI_DEFAULT_DISP_SIZE "H" #ifndef __MKC_STANDARD_DEFS # define __MKC_STANDARD_DEFS 1 # if ! _key_void # define void int # endif # if ! _key_void || ! _param_void_star typedef char *_pvoid; # else typedef void *_pvoid; # endif # if ! _key_const # define const # endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif #endif /* __MKC_STANDARD_DEFS */ #if _typ_statvfs_t # define Statvfs_t statvfs_t #else # define Statvfs_t struct statvfs #endif #if _typ_size_t # define Size_t size_t #else # define Size_t unsigned int #endif #if _typ_uint_t # define Uint_t uint_t #else # define Uint_t unsigned int #endif #if _typ_uid_t # define Uid_t uid_t #else # define Uid_t int #endif #if _typ_gid_t # define Gid_t gid_t #else # define Gid_t int #endif /* Do this the old-fashioned way for old compilers */ /* Have to work around MacOSX's snprintf macro. */ #if _lib_snprintf # define Snprintf1 snprintf # define Snprintf2 snprintf # define Snprintf3 snprintf # define Snprintf4 snprintf #else # define Snprintf1(a1,a2,a3,a4) sprintf(a1,a3,a4) # define Snprintf2(a1,a2,a3,a4,a5) sprintf(a1,a3,a4,a5) # define Snprintf3(a1,a2,a3,a4,a5,a6) sprintf(a1,a3,a4,a5,a6) # define Snprintf4(a1,a2,a3,a4,a5,a6,a7) sprintf(a1,a3,a4,a5,a6,a7) #endif #if ! _lib_strcoll # define strcoll strcmp #endif #endif /* __INC_CONFIG_H */ di-4.52/C/configs/config.cygwin.gcc0000644000175000017500000001554314421556642015221 0ustar bllbll/* Created on: Fri Jan 22 10:41:21 PST 2016 From: ../features/mkconfig.dat Using: mkconfig-1.27 */ #ifndef __INC_CONFIG_H #define __INC_CONFIG_H 1 #define _hdr_stdio 1 #define _hdr_stdlib 1 #define _sys_types 1 #define _sys_param 1 #define _key_void 1 #define _key_const 1 #define _param_void_star 1 #define _proto_stdc 1 #define _hdr_ctype 1 #define _hdr_dcdef 0 #define _hdr_descrip 0 #define _hdr_dirent 1 #define _hdr_dvidef 0 #define _hdr_dvsdef 0 #define _hdr_errno 1 #define _hdr_fcntl 1 #define _hdr_fshelp 0 #define _hdr_gui_window 0 #define _hdr_jfs_quota 0 #define _hdr_kernel_fs_info 0 #define _hdr_limits 1 #define _hdr_linux_dqblk_xfs 0 #define _hdr_linux_quota 0 #define _hdr_libintl 1 #define _hdr_libprop_proplib 0 #define _hdr_locale 1 #define _hdr_malloc 1 #define _hdr_mcheck 0 #define _hdr_memory 1 #define _hdr_mntent 1 #define _hdr_mnttab 0 #define _hdr_quota 0 #define _hdr_rpc_rpc 0 #define _hdr_rpcsvc_rquota 0 #define _hdr_ssdef 0 #define _hdr_starlet 0 #define _hdr_storage_Directory 0 #define _hdr_storage_Entry 0 #define _hdr_storage_Path 0 #define _hdr_storage_volumes 0 #define _hdr_string 1 #define _hdr_strings 1 #define _hdr_time 1 #define _hdr_ufs_quota 0 #define _hdr_ufs_ufs_quota 0 #define _hdr_unistd 1 #define _hdr_util_string 0 #define _hdr_wchar 1 #define _hdr_windows 0 #define _hdr_winioctl 0 #define _hdr_zone 0 #define _sys_dcmd_blk 0 #define _sys_file 1 #define _sys_fs_types 0 #define _sys_fs_ufs_quota 0 #define _sys_fstyp 0 #define _sys_fstypes 0 #define _sys_ftype 0 #define _sys_io 0 #define _sys_mntctl 0 #define _sys_mntent 0 #define _sys_mnttab 0 #define _sys_mount 1 #define _sys_quota 1 #define _sys_stat 1 #define _sys_statfs 1 #define _sys_statvfs 1 #define _sys_time 1 #define _sys_vfs 1 #define _sys_vfs_quota 0 #define _sys_vfstab 0 #define _sys_vmount 0 #define _inc_conflict__hdr_time__sys_time 1 #define _inc_conflict__sys_quota__hdr_linux_quota 1 #define _command_msgfmt 1 #define _cmd_loc_msgfmt "/usr/bin/msgfmt" #define _command_rpmbuild 0 #define _const_O_NOCTTY 1 #define _define_bcopy 0 #define _define_bzero 0 #define _define_MCTL_QUERY 0 #define _define_memcpy 0 #define _define_memset 0 #define _define_QCMD 1 #define _define_S_ISLNK 1 #define _typ_struct_dqblk 1 #define _typ_struct_quotaval 0 #define _typ_struct_ufs_dqblk 0 #define _typ_fs_disk_quota_t 0 #define _typ_gid_t 1 #define _typ_statvfs_t 0 #define _typ_size_t 1 #define _typ_uint_t 0 #define _typ_uid_t 1 #define _lib_bcopy 1 #define _lib_bindtextdomain 1 #define _lib_bzero 1 #define _lib_CreateFile 0 #define _lib_DeviceIoControl 0 #define _lib_endmntent 1 #define _lib_fs_stat_dev 0 #define _lib_fshelp 0 #define _lib_GetDiskFreeSpace 0 #define _lib_GetDiskFreeSpaceEx 0 #define _lib_GetDriveType 0 #define _lib_getfsstat 0 #define _lib_GetLogicalDriveStrings 0 #define _lib_GetVolumeInformation 0 #define _lib_getmnt 0 #define _lib_getmntent 1 #define _lib_getmntinfo 0 #define _lib_gettext 1 #define _lib_getvfsstat 0 #define _lib_getzoneid 0 #define _lib_hasmntopt 0 #define _lib_lstat 1 #define _lib_mbrlen 1 #define _lib_mcheck_pedantic 0 #define _lib_memcpy 1 #define _lib_memset 1 #define _lib_mntctl 0 #define _lib_next_dev 0 #define _lib_prop_dictionary_create 0 #define _lib_quota_open 0 #define _lib_quotactl 1 #define _lib_realpath 1 #define _lib_setlocale 1 #define _lib_setmntent 1 #define _lib_snprintf 1 #define _lib_statfs 1 #define _lib_statvfs 1 #define _lib_strcoll 1 #define _lib_strdup 1 #define _lib_strstr 1 #define _lib_sys_dollar_device_scan 0 #define _lib_sys_dollar_getdviw 0 #define _lib_sysfs 0 #define _lib_textdomain 1 #define _lib_vquotactl 0 #define _lib_xdr_int 0 #define _lib_zone_getattr 0 #define _lib_zone_list 0 #define _memberxdr_rquota_rq_bhardlimit 0 #define _memberxdr_rquota_rq_bsoftlimit 0 #define _memberxdr_rquota_rq_curblocks 0 #define _memberxdr_rquota_rq_fhardlimit 0 #define _memberxdr_rquota_rq_fsoftlimit 0 #define _memberxdr_rquota_rq_curfiles 0 #define _memberxdr_getquota_args_gqa_uid 0 #define _args_getfsstat 0 #define _args_getvfsstat 0 #define _c_arg_1_quotactl int #define _c_arg_2_quotactl char * #define _c_arg_3_quotactl int #define _c_arg_4_quotactl caddr_t #define _c_type_quotactl int #define _args_quotactl 4 #define _quotactl_pos_1 0 #define _quotactl_pos_2 1 #define _c_arg_1_setmntent char * #define _c_arg_2_setmntent char * #define _c_type_setmntent FILE * #define _args_setmntent 2 #define _c_arg_1_statfs char * #define _c_arg_2_statfs struct statfs * #define _c_type_statfs int #define _args_statfs 2 #define _class_os__Volumes 0 #define _npt_getenv 0 #define _npt_getmnt 1 #define _npt_mntctl 1 #define _npt_quotactl 0 #define _npt_statfs 0 #define _dcl_errno 1 #define _dcl_mnt_names 0 #define _mem_struct_dqblk_dqb_curspace 1 #define _mem_struct_dqblk_dqb_curblocks 0 #define _mem_struct_dqblk_dqb_fhardlimit 0 #define _mem_struct_dqblk_dqb_fsoftlimit 0 #define _mem_struct_dqblk_dqb_curfiles 0 #define _mem_struct_getquota_rslt_gqr_status 0 #define _mem_struct_getquota_rslt_gqr_rquota 0 #define _mem_struct_mnttab_mt_mntopts 0 #define _mem_struct_statfs_f_bsize 1 #define _mem_struct_statfs_f_fsize 0 #define _mem_struct_statfs_f_fstyp 0 #define _mem_struct_statfs_f_iosize 0 #define _mem_struct_statfs_f_frsize 0 #define _mem_struct_statfs_f_fstypename 0 #define _mem_struct_statfs_mount_info 0 #define _mem_struct_statfs_f_type 1 #define _mem_struct_statvfs_f_basetype 0 #define _siz_long_long 8 #define _siz_long_double 16 #define _printf_long_double 1 #define _has_std_quotas 1 #define _has_std_nfs_quotas 0 #define _use_mcheck 0 #define _enable_nls 1 #define DI_DEFAULT_FORMAT "MbuvpT" #define DI_DEFAULT_DISP_SIZE "H" #ifndef __MKC_STANDARD_DEFS # define __MKC_STANDARD_DEFS 1 # if ! _key_void # define void int # endif # if ! _key_void || ! _param_void_star typedef char *_pvoid; # else typedef void *_pvoid; # endif # if ! _key_const # define const # endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif #endif /* __MKC_STANDARD_DEFS */ #if _typ_statvfs_t # define Statvfs_t statvfs_t #else # define Statvfs_t struct statvfs #endif #if _typ_size_t # define Size_t size_t #else # define Size_t unsigned int #endif #if _typ_uint_t # define Uint_t uint_t #else # define Uint_t unsigned int #endif #if _typ_uid_t # define Uid_t uid_t #else # define Uid_t int #endif #if _typ_gid_t # define Gid_t gid_t #else # define Gid_t int #endif /* Do this the old-fashioned way for old compilers */ /* Have to work around MacOSX's snprintf macro. */ #if _lib_snprintf # define Snprintf1 snprintf # define Snprintf2 snprintf # define Snprintf3 snprintf # define Snprintf4 snprintf #else # define Snprintf1(a1,a2,a3,a4) sprintf(a1,a3,a4) # define Snprintf2(a1,a2,a3,a4,a5) sprintf(a1,a3,a4,a5) # define Snprintf3(a1,a2,a3,a4,a5,a6) sprintf(a1,a3,a4,a5,a6) # define Snprintf4(a1,a2,a3,a4,a5,a6,a7) sprintf(a1,a3,a4,a5,a6,a7) #endif #if ! _lib_strcoll # define strcoll strcmp #endif #endif /* __INC_CONFIG_H */ di-4.52/C/configs/config.vms.b0000644000175000017500000001441114421556642014204 0ustar bllbll#ifndef __INC_CONFIG_H #define __INC_CONFIG_H 1 #define _hdr_stdio 1 #define _hdr_stdlib 1 #define _sys_types 1 #define _sys_param 0 #define _key_void 1 #define _key_const 1 #define _param_void_star 1 #define _proto_stdc 1 #define _hdr_ctype 1 #define _hdr_dcdef 1 #define _hdr_descrip 1 #define _hdr_dirent 1 #define _hdr_dvidef 1 #define _hdr_dvsdef 1 #define _hdr_errno 1 #define _hdr_fcntl 1 #define _hdr_fshelp 0 #define _hdr_gui_window 0 #define _hdr_jfs_quota 0 #define _hdr_kernel_fs_info 0 #define _hdr_limits 1 #define _hdr_libintl 0 #define _hdr_libprop_proplib 0 #define _hdr_linux_dqblk_xfs 0 #define _hdr_linux_quota 0 #define _hdr_locale 1 #define _hdr_malloc 0 #define _hdr_mcheck 0 #define _hdr_memory 1 #define _hdr_mntent 0 #define _hdr_mnttab 0 #define _hdr_quota 0 #define _hdr_rpc_rpc 0 #define _hdr_rpcsvc_rquota 0 #define _hdr_storage_Directory 0 #define _hdr_storage_Entry 0 #define _hdr_storage_Path 0 #define _hdr_ssdef 1 #define _hdr_starlet 1 #define _hdr_storage_volumes 0 #define _hdr_string 1 #define _hdr_strings 1 #define _hdr_time 1 #define _hdr_ufs_quota 0 #define _hdr_ufs_ufs_quota 0 #define _hdr_unistd 1 #define _hdr_util_string 0 #define _hdr_wchar 1 #define _hdr_windows 0 #define _hdr_winioctl 0 #define _hdr_zone 0 #define _sys_dcmd_blk 0 #define _sys_file 1 #define _sys_fs_types 0 #define _sys_fs_ufs_quota 0 #define _sys_fstyp 0 #define _sys_fstypes 0 #define _sys_ftype 0 #define _sys_io 0 #define _sys_mntctl 0 #define _sys_mntent 0 #define _sys_mnttab 0 #define _sys_mount 0 #define _sys_quota 0 #define _sys_stat 1 #define _sys_statfs 0 #define _sys_statvfs 0 #define _sys_time 1 #define _sys_vfs 0 #define _sys_vfs_quota 0 #define _sys_vfstab 0 #define _sys_vmount 0 #define _inc_conflict__hdr_time__sys_time 1 #define _inc_conflict__sys_quota__hdr_linux_quota 1 #define _command_msgfmt 0 #define _command_rpmbuild 0 #define _const_O_NOCTTY 1 #define _define_bcopy 0 #define _define_bzero 0 #define _define_MCTL_QUERY 0 #define _define_memcpy 0 #define _define_memset 0 #define _define_QCMD 0 #define _define_S_ISLNK 0 #define _typ_struct_dqblk 0 #define _typ_struct_quotaval 0 #define _typ_struct_ufs_dqblk 0 #define _typ_fs_disk_quota_t 0 #define _typ_gid_t 1 #define _typ_statvfs_t 0 #define _typ_size_t 1 #define _typ_uint_t 0 #define _typ_uid_t 1 #define _lib_bcopy 1 #define _lib_bindtextdomain 1 #define _lib_bzero 1 #define _lib_CreateFile 0 #define _lib_DeviceIoControl 0 #define _lib_endmntent 0 #define _lib_fs_stat_dev 0 #define _lib_fshelp 0 #define _lib_GetDiskFreeSpace 0 #define _lib_GetDiskFreeSpaceEx 0 #define _lib_GetDriveType 0 #define _lib_getfsstat 0 #define _lib_GetLogicalDriveStrings 0 #define _lib_GetVolumeInformation 0 #define _lib_getmnt 0 #define _lib_getmntent 0 #define _lib_getmntinfo 0 #define _lib_gettext 1 #define _lib_getvfsstat 0 #define _lib_getzoneid 0 #define _lib_hasmntopt 1 #define _lib_lstat 0 #define _lib_mbrlen 1 #define _lib_mcheck_pedantic 0 #define _lib_memcpy 1 #define _lib_memset 1 #define _lib_mntctl 0 #define _lib_next_dev 0 #define _lib_prop_dictionary_create 0 #define _lib_quota_open 0 #define _lib_quotactl 0 #define _lib_realpath 0 #define _lib_setlocale 1 #define _lib_setmntent 0 #define _lib_snprintf 0 #define _lib_statfs 0 #define _lib_statvfs 0 #define _lib_strcoll 1 #define _lib_strdup 1 #define _lib_strstr 1 #define _lib_sys_dollar_device_scan 1 #define _lib_sys_dollar_getdviw 1 #define _lib_sysfs 0 #define _lib_textdomain 1 #define _lib_vquotactl 0 #define _lib_xdr_int 0 #define _lib_zone_getattr 0 #define _lib_zone_list 0 #define _memberxdr_rquota_rq_bhardlimit 0 #define _memberxdr_rquota_rq_bsoftlimit 0 #define _memberxdr_rquota_rq_curblocks 0 #define _memberxdr_rquota_rq_fhardlimit 0 #define _memberxdr_rquota_rq_fsoftlimit 0 #define _memberxdr_rquota_rq_curfiles 0 #define _mem_struct_mnttab_mt_mntopts 0 #define _memberxdr_getquota_args_gqa_uid 0 #define _args_getfsstat 0 #define _args_getvfsstat 0 #define _args_quotactl 0 #define _quotactl_pos_1 0 #define _quotactl_pos_2 0 #define _args_setmntent 0 #define _args_statfs 0 #define _class_os__Volumes 0 #define _npt_getenv 0 #define _npt_getmnt 1 #define _npt_libquota 0 #define _npt_mntctl 1 #define _npt_statfs 0 #define _dcl_errno 1 #define _dcl_mnt_names 0 #define _mem_struct_dqblk_dqb_curspace 0 #define _mem_struct_dqblk_dqb_curblocks 0 #define _mem_struct_dqblk_dqb_fhardlimit 0 #define _mem_struct_dqblk_dqb_fsoftlimit 0 #define _mem_struct_dqblk_dqb_curfiles 0 #define _mem_struct_getquota_rslt_gqr_status 0 #define _mem_struct_getquota_rslt_gqr_rquota 0 #define _mem_struct_statfs_f_bsize 0 #define _mem_struct_statfs_f_fsize 0 #define _mem_struct_statfs_f_fstyp 0 #define _mem_struct_statfs_f_iosize 0 #define _mem_struct_statfs_f_frsize 0 #define _mem_struct_statfs_f_fstypename 0 #define _mem_struct_statfs_mount_info 0 #define _mem_struct_statfs_f_type 0 #define _mem_struct_statvfs_f_basetype 0 #define _siz_long_long 0 #define _siz_long_double 0 #define _printf_long_double 0 #define _has_std_quotas 0 #define _has_std_nfs_quotas 0 #define _use_mcheck 0 #define _enable_nls 0 #define DI_DEFAULT_FORMAT "smbuvpT" #define DI_DEFAULT_DISP_SIZE "H" #ifndef __MKC_STANDARD_DEFS # define __MKC_STANDARD_DEFS 1 # if ! _key_void # define void int # endif # if ! _key_void || ! _param_void_star typedef char *_pvoid; # else typedef void *_pvoid; # endif # if ! _key_const # define const # endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif #endif /* __MKC_STANDARD_DEFS */ #if _typ_size_t # define Size_t size_t #else # define Size_t unsigned int #endif #if _typ_uint_t # define Uint_t uint_t #else # define Uint_t unsigned int #endif #if _typ_uid_t # define Uid_t uid_t #else # define Uid_t int #endif #if _typ_gid_t # define Gid_t gid_t #else # define Gid_t int #endif /* Do this the old-fashioned way for old compilers */ /* Have to work around MacOSX's snprintf macro. */ #if _lib_snprintf # define Snprintf1 snprintf # define Snprintf2 snprintf # define Snprintf3 snprintf # define Snprintf4 snprintf #else # define Snprintf1(a1,a2,a3,a4) sprintf(a1,a3,a4) # define Snprintf2(a1,a2,a3,a4,a5) sprintf(a1,a3,a4,a5) # define Snprintf3(a1,a2,a3,a4,a5,a6) sprintf(a1,a3,a4,a5,a6) # define Snprintf4(a1,a2,a3,a4,a5,a6,a7) sprintf(a1,a3,a4,a5,a6,a7) #endif #if ! _lib_strcoll # define strcoll strcmp #endif #endif /* __INC_CONFIG_H */ di-4.52/C/configs/config.vms0000644000175000017500000001441214421556642013765 0ustar bllbll#ifndef __INC_CONFIG_H #define __INC_CONFIG_H 1 #define _hdr_stdio 1 #define _hdr_stdlib 1 #define _sys_types 1 #define _sys_param 0 #define _key_void 1 #define _key_const 1 #define _param_void_star 1 #define _proto_stdc 1 #define _hdr_ctype 1 #define _hdr_dcdef 1 #define _hdr_descrip 1 #define _hdr_dirent 1 #define _hdr_dvidef 1 #define _hdr_dvsdef 1 #define _hdr_errno 1 #define _hdr_fcntl 1 #define _hdr_fshelp 0 #define _hdr_gui_window 0 #define _hdr_jfs_quota 0 #define _hdr_kernel_fs_info 0 #define _hdr_limits 1 #define _hdr_linux_dqblk_xfs 0 #define _hdr_linux_quota 0 #define _hdr_libintl 0 #define _hdr_libprop_proplib 0 #define _hdr_locale 1 #define _hdr_malloc 0 #define _hdr_mcheck 0 #define _hdr_memory 1 #define _hdr_mntent 0 #define _hdr_mnttab 0 #define _hdr_quota 0 #define _hdr_rpc_rpc 0 #define _hdr_rpcsvc_rquota 0 #define _hdr_ssdef 1 #define _hdr_starlet 1 #define _hdr_storage_Directory 0 #define _hdr_storage_Entry 0 #define _hdr_storage_Path 0 #define _hdr_storage_volumes 0 #define _hdr_string 1 #define _hdr_strings 1 #define _hdr_time 1 #define _hdr_ufs_quota 0 #define _hdr_ufs_ufs_quota 0 #define _hdr_unistd 1 #define _hdr_util_string 0 #define _hdr_wchar 1 #define _hdr_windows 0 #define _hdr_winioctl 0 #define _hdr_zone 0 #define _sys_dcmd_blk 0 #define _sys_file 1 #define _sys_fs_types 0 #define _sys_fs_ufs_quota 0 #define _sys_fstyp 0 #define _sys_fstypes 0 #define _sys_ftype 0 #define _sys_io 0 #define _sys_mntctl 0 #define _sys_mntent 0 #define _sys_mnttab 0 #define _sys_mount 0 #define _sys_quota 0 #define _sys_stat 1 #define _sys_statfs 1 #define _sys_statvfs 1 #define _sys_time 1 #define _sys_vfs 0 #define _sys_vfs_quota 0 #define _sys_vfstab 0 #define _sys_vmount 0 #define _inc_conflict__hdr_time__sys_time 1 #define _inc_conflict__sys_quota__hdr_linux_quota 1 #define _command_msgfmt 0 #define _command_rpmbuild 0 #define _const_O_NOCTTY 1 #define _define_bcopy 0 #define _define_bzero 0 #define _define_MCTL_QUERY 0 #define _define_memcpy 0 #define _define_memset 0 #define _define_QCMD 0 #define _define_S_ISLNK 0 #define _typ_struct_dqblk 0 #define _typ_struct_quotaval 0 #define _typ_struct_ufs_dqblk 0 #define _typ_fs_disk_quota_t 0 #define _typ_gid_t 1 #define _typ_statvfs_t 0 #define _typ_size_t 1 #define _typ_uint_t 0 #define _typ_uid_t 1 #define _lib_bcopy 1 #define _lib_bindtextdomain 1 #define _lib_bzero 1 #define _lib_CreateFile 0 #define _lib_DeviceIoControl 0 #define _lib_endmntent 0 #define _lib_fs_stat_dev 0 #define _lib_fshelp 0 #define _lib_GetDiskFreeSpace 0 #define _lib_GetDiskFreeSpaceEx 0 #define _lib_GetDriveType 0 #define _lib_getfsstat 0 #define _lib_GetLogicalDriveStrings 0 #define _lib_GetVolumeInformation 0 #define _lib_getmnt 0 #define _lib_getmntent 0 #define _lib_getmntinfo 0 #define _lib_gettext 1 #define _lib_getvfsstat 0 #define _lib_getzoneid 0 #define _lib_hasmntopt 1 #define _lib_lstat 0 #define _lib_mbrlen 1 #define _lib_mcheck_pedantic 0 #define _lib_memcpy 1 #define _lib_memset 1 #define _lib_mntctl 0 #define _lib_next_dev 0 #define _lib_prop_dictionary_create 0 #define _lib_quota_open 0 #define _lib_quotactl 0 #define _lib_realpath 0 #define _lib_setlocale 1 #define _lib_setmntent 0 #define _lib_snprintf 1 #define _lib_statfs 0 #define _lib_statvfs 0 #define _lib_strcoll 1 #define _lib_strdup 1 #define _lib_strstr 1 #define _lib_sys_dollar_device_scan 1 #define _lib_sys_dollar_getdviw 1 #define _lib_sysfs 0 #define _lib_textdomain 1 #define _lib_vquotactl 0 #define _lib_xdr_int 0 #define _lib_zone_getattr 0 #define _lib_zone_list 0 #define _memberxdr_rquota_rq_bhardlimit 0 #define _memberxdr_rquota_rq_bsoftlimit 0 #define _memberxdr_rquota_rq_curblocks 0 #define _memberxdr_rquota_rq_fhardlimit 0 #define _memberxdr_rquota_rq_fsoftlimit 0 #define _memberxdr_rquota_rq_curfiles 0 #define _mem_struct_mnttab_mt_mntopts 0 #define _memberxdr_getquota_args_gqa_uid 0 #define _args_getfsstat 0 #define _args_getvfsstat 0 #define _args_quotactl 0 #define _quotactl_pos_1 0 #define _quotactl_pos_2 0 #define _args_setmntent 0 #define _args_statfs 0 #define _class_os__Volumes 0 #define _npt_getenv 0 #define _npt_getmnt 1 #define _npt_libquota 0 #define _npt_mntctl 1 #define _npt_statfs 0 #define _dcl_errno 1 #define _dcl_mnt_names 0 #define _mem_struct_dqblk_dqb_curspace 0 #define _mem_struct_dqblk_dqb_curblocks 0 #define _mem_struct_dqblk_dqb_fhardlimit 0 #define _mem_struct_dqblk_dqb_fsoftlimit 0 #define _mem_struct_dqblk_dqb_curfiles 0 #define _mem_struct_getquota_rslt_gqr_status 0 #define _mem_struct_getquota_rslt_gqr_rquota 0 #define _mem_struct_statfs_f_bsize 0 #define _mem_struct_statfs_f_fsize 0 #define _mem_struct_statfs_f_fstyp 0 #define _mem_struct_statfs_f_iosize 0 #define _mem_struct_statfs_f_frsize 0 #define _mem_struct_statfs_f_fstypename 0 #define _mem_struct_statfs_mount_info 0 #define _mem_struct_statfs_f_type 0 #define _mem_struct_statvfs_f_basetype 0 #define _siz_long_long 8 #define _siz_long_double 12 #define _printf_long_double 1 #define _has_std_quotas 0 #define _has_std_nfs_quotas 0 #define _use_mcheck 0 #define _enable_nls 0 #define DI_DEFAULT_FORMAT "smbuvpT" #define DI_DEFAULT_DISP_SIZE "H" #ifndef __MKC_STANDARD_DEFS # define __MKC_STANDARD_DEFS 1 # if ! _key_void # define void int # endif # if ! _key_void || ! _param_void_star typedef char *_pvoid; # else typedef void *_pvoid; # endif # if ! _key_const # define const # endif # ifndef _ # if _proto_stdc # define _(args) args # else # define _(args) () # endif # endif #endif /* __MKC_STANDARD_DEFS */ #if _typ_size_t # define Size_t size_t #else # define Size_t unsigned int #endif #if _typ_uint_t # define Uint_t uint_t #else # define Uint_t unsigned int #endif #if _typ_uid_t # define Uid_t uid_t #else # define Uid_t int #endif #if _typ_gid_t # define Gid_t gid_t #else # define Gid_t int #endif /* Do this the old-fashioned way for old compilers */ /* Have to work around MacOSX's snprintf macro. */ #if _lib_snprintf # define Snprintf1 snprintf # define Snprintf2 snprintf # define Snprintf3 snprintf # define Snprintf4 snprintf #else # define Snprintf1(a1,a2,a3,a4) sprintf(a1,a3,a4) # define Snprintf2(a1,a2,a3,a4,a5) sprintf(a1,a3,a4,a5) # define Snprintf3(a1,a2,a3,a4,a5,a6) sprintf(a1,a3,a4,a5,a6) # define Snprintf4(a1,a2,a3,a4,a5,a6,a7) sprintf(a1,a3,a4,a5,a6,a7) #endif #if ! _lib_strcoll # define strcoll strcmp #endif #endif /* __INC_CONFIG_H */ di-4.52/C/strdup.c0000644000175000017500000000140214421556642012021 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #if ! _lib_strdup # include "di.h" #if _hdr_stdio # include #endif # if _hdr_stdlib # include # endif # if _hdr_memory # include # endif # if _hdr_malloc # include # endif # if _hdr_string # include # endif # if _hdr_strings # include # endif #if _use_mcheck # include #endif char * strdup (const char *ptr) { Size_t len; char *nptr; if (ptr == (char *) NULL) { return (char *) NULL; } len = strlen (ptr); nptr = (char *) malloc (len + 1); strncpy (nptr, ptr, len); return nptr; } #else extern int debug; #endif di-4.52/C/digetentries.c0000644000175000017500000017331014421556642013176 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ /********************************************************/ /* di_getDiskEntries () Get a list of mounted filesystems. In many cases, this also does the work of di_getDiskInfo (). */ /********************************************************/ #include "config.h" #include "di.h" #include "dimntopt.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_dirent # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _sys_param # include #endif #if _sys_ftype /* QNX */ # include #endif #if _sys_dcmd_blk /* QNX */ # include #endif #if _sys_io /* QNX */ # include #endif #if _hdr_errno # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _hdr_memory # include #endif #if _hdr_malloc # include #endif #if _hdr_mntent \ && ! defined (DI_INC_MNTENT) /* Linux, kFreeBSD, HP-UX */ # define DI_INC_MNTENT 1 # include /* hasmntopt(); _PATH_MNTTAB */ #endif /* HP-UX: set/get/endmntent(); hasmntopt() */ #if _sys_mount \ && ! defined (DI_INC_SYS_MOUNT) /* FreeBSD, OpenBSD, NetBSD, HP-UX */ # define DI_INC_SYS_MOUNT 1 # include /* getmntinfo(); struct statfs */ #endif #if _sys_fstypes /* NetBSD */ # include #endif #if _sys_fs_types /* OSF/1, AROS */ # include #endif #if _sys_mnttab /* Solaris, SCO_SV, UnixWare */ # include /* getmntent(); MNTTAB */ #endif #if _sys_statfs && ! _sys_statvfs /* Linux, FreeBSD, SysV.3 */ # include /* struct statfs; statfs() */ #endif #if _sys_statvfs /* NetBSD, Solaris */ # include /* struct statvfs; statvfs() */ #endif #if _sys_vfs /* BSD 4.3 */ # include /* struct statfs */ #endif #if _sys_mntctl /* AIX */ # include #endif #if _sys_vmount /* AIX */ # include #endif #if _hdr_fshelp /* AIX */ # include #endif #if _hdr_windows /* windows */ # include #endif #if _hdr_winioctl /* windows */ # include #endif #if _hdr_kernel_fs_info /* BeOS */ # include #endif #if _hdr_storage_Directory /* BeOS */ # include #endif #if _hdr_storage_Entry /* BeOS */ # include #endif #if _hdr_storage_Path /* BeOS */ # include #endif /* bozo syllable volumes header requires gui/window */ #if _hdr_gui_window /* Syllable */ # include /* gack! */ #endif #if _hdr_storage_volumes /* Syllable */ # include /* class os::Volumes */ #endif #if _hdr_util_string /* Syllable */ # include /* os::String - to get mount name */ #endif #if _hdr_starlet /* VMS */ # include #endif #if _hdr_descrip /* VMS */ # include #endif #if _hdr_dcdef /* VMS */ # include #endif #if _hdr_dvsdef /* VMS */ # include #endif #if _hdr_ssdef /* VMS */ # include #endif #if _hdr_dvidef /* VMS */ # include #endif /********************************************************/ #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif /* workaround for AIX - mntctl not declared */ # if _lib_mntctl && _npt_mntctl extern int mntctl _((int, Size_t, char *)); # endif #if (_lib_getmntent \ || _args_statfs > 0) \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_mntctl \ && ! _lib_getmnt \ && ! _class_os__Volumes # if defined (_PATH_MOUNTED) # define DI_MOUNT_FILE _PATH_MOUNTED # else # if defined (_PATH_MNTTAB) # define DI_MOUNT_FILE _PATH_MNTTAB # else # if defined (MOUNTED) # define DI_MOUNT_FILE MOUNTED # else # if defined (MNTTAB) # define DI_MOUNT_FILE MNTTAB # else # if (USE_ETC_FILESYSTEMS) # define DI_MOUNT_FILE "/etc/filesystems" /* AIX 4.x or /etc/mntent? */ # else # define DI_MOUNT_FILE "/etc/mnttab" /* SysV.3 default */ # endif # endif # endif # endif # endif #endif #if defined (__QNX__) static int di_getQNXDiskEntries _((char *ipath, diDiskInfo_t **diskInfo, int *diCount)); #endif extern int debug; #if defined (__cplusplus) || defined (c_plusplus) } #endif /********************************************************/ #if _lib_getmntent \ && ! _lib_setmntent \ && ! _lib_mntctl \ && ! _class_os__Volumes #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif static char *checkMountOptions _((struct mnttab *, char *)); #if defined (__cplusplus) || defined (c_plusplus) } #endif /* * di_getDiskEntries * * For SysV.4, we open the file and call getmntent () repeatedly. * */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; FILE *f; int idx; struct mnttab mntEntry; char *devp; /* local ptr to dev entry */ if (debug > 0) { printf ("# di_getDiskEntries: getmntent\n"); } if ((f = fopen (DI_MOUNT_FILE, "r")) == (FILE *) NULL) { fprintf (stderr, "Unable to open: %s errno %d\n", DI_MOUNT_FILE, errno); return -1; } while (getmntent (f, &mntEntry) == 0) { idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * (Size_t) *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); strncpy (diptr->special, mntEntry.mnt_special, DI_SPEC_NAME_LEN); strncpy (diptr->name, mntEntry.mnt_mountp, DI_NAME_LEN); if (checkMountOptions (&mntEntry, DI_MNTOPT_IGNORE) != (char *) NULL) { diptr->printFlag = DI_PRNT_IGNORE; if (debug > 2) { printf ("mnt: ignore: mntopt 'ignore': %s\n", diptr->name); } } if ((devp = checkMountOptions (&mntEntry, DI_MNTOPT_DEV)) != (char *) NULL) { if (devp != mntEntry.mnt_mntopts) { --devp; } *devp = 0; /* point to preceeding comma and cut off */ } if (checkMountOptions (&mntEntry, DI_MNTOPT_RO) != (char *) NULL) { diptr->isReadOnly = TRUE; } strncpy (diptr->options, mntEntry.mnt_mntopts, DI_OPT_LEN); /* get the file system type now... */ strncpy (diptr->fsType, mntEntry.mnt_fstype, DI_TYPE_LEN); if (debug > 2) { printf ("mnt:%s - %s\n", diptr->name, diptr->fsType); } if (debug > 1) { printf ("mnt:%s - %s\n", diptr->name, diptr->special); } } fclose (f); return 0; } static char * checkMountOptions (struct mnttab *mntEntry, char *str) { # if _lib_hasmntopt return hasmntopt (mntEntry, str); # else return chkMountOptions (mntEntry->mnt_mntopts, str); # endif } #endif #if _lib_getmntent \ && _lib_setmntent \ && _lib_endmntent \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_mntctl \ && ! _lib_GetDriveType \ && ! _lib_GetLogicalDriveStrings \ && ! _class_os__Volumes /* * di_getDiskEntries * * SunOS supplies an open and close routine for the mount table. * */ #if ! defined (MNTTYPE_IGNORE) # define MNTTYPE_IGNORE "ignore" #endif int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; FILE *f; int idx; struct mntent *mntEntry; char *devp; /* local ptr to dev entry */ if (debug > 0) { printf ("# getDiskEntries: set/get/endmntent\n"); } /* if both are set not an ansi compiler... */ #if _args_setmntent == 1 if ((f = setmntent (DI_MOUNT_FILE)) == (FILE *) NULL) #else if ((f = setmntent (DI_MOUNT_FILE, "r")) == (FILE *) NULL) #endif { fprintf (stderr, "Unable to open: %s errno %d\n", DI_MOUNT_FILE, errno); return -1; } while ((mntEntry = getmntent (f)) != (struct mntent *) NULL) { idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * (Size_t) *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); strncpy (diptr->special, mntEntry->mnt_fsname, (Size_t) DI_SPEC_NAME_LEN); strncpy (diptr->name, mntEntry->mnt_dir, (Size_t) DI_NAME_LEN); strncpy (diptr->fsType, mntEntry->mnt_type, (Size_t) DI_TYPE_LEN); if (strcmp (mntEntry->mnt_fsname, "none") == 0) { diptr->printFlag = DI_PRNT_IGNORE; if (debug > 2) { printf ("mnt: ignore: special 'none': %s\n", diptr->name); } } if (strcmp (mntEntry->mnt_type, MNTTYPE_IGNORE) == 0) { diptr->printFlag = DI_PRNT_IGNORE; if (debug > 2) { printf ("mnt: ignore: mntopt 'ignore': %s\n", diptr->name); } } if ((devp = strstr (mntEntry->mnt_opts, "dev=")) != (char *) NULL) { if (devp != mntEntry->mnt_opts) { --devp; } *devp = 0; /* point to preceeding comma and cut off */ } if (chkMountOptions (mntEntry->mnt_opts, DI_MNTOPT_RO) != (char *) NULL) { diptr->isReadOnly = TRUE; } strncpy (diptr->options, mntEntry->mnt_opts, (Size_t) DI_OPT_LEN); if (debug > 1) { printf ("mnt:%s - %s : %s\n", diptr->name, diptr->special, diptr->fsType); } } endmntent (f); return 0; } #endif /* _lib_getmntent && _lib_setmntent && _lib_endmntent */ /* QNX */ #if ! _lib_getmntent \ && ! _lib_mntctl \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_getmnt \ && ! _lib_GetDriveType \ && ! _lib_GetLogicalDriveStrings \ && ! _lib_fs_stat_dev \ && ! _class_os__Volumes \ && ! _lib_sys_dollar_device_scan \ && defined (__QNX__) /* * di_getDiskEntries * * QNX * * This is bloody slow. * It would be nice to have a way to short-circuit some of * the directory subtrees. * /proc/mount/dev is not processed...hopefully that won't affect much. * */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { if (debug > 0) { printf ("# getDiskEntries: QNX\n"); } return di_getQNXDiskEntries ("/proc/mount", diskInfo, diCount); } static int di_getQNXDiskEntries (char *ipath, diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int idx; char path [MAXPATHLEN + 1]; int len; /* current length of path */ DIR *dirp; struct dirent *dent; int ret; int nodeid; int pid; int chid; int handle; int ftype; struct stat statinfo; int fd; char tspecial [DI_SPEC_NAME_LEN]; if (strcmp (ipath, "/proc/mount/dev") == 0) { return 0; } strncpy (path, ipath, MAXPATHLEN); len = strlen (path); if (!(dirp = opendir(path))) { return 0; } while ((dent = readdir(dirp))) { if (strcmp (dent->d_name, ".") == 0 || strcmp (dent->d_name, "..") == 0) { continue; } path[len] = '\0'; ret = sscanf(dent->d_name, "%d,%d,%d,%d,%d", &nodeid, &pid, &chid, &handle, &ftype); if (len + strlen(dent->d_name) + 1 > MAXPATHLEN) { continue; } path[len] = '/'; strncpy (&path[len+1], dent->d_name, MAXPATHLEN - len - 1); if (debug > 4) { printf ("check: %s\n", path); } memset(&statinfo, 0, sizeof(statinfo)); if (stat(path, &statinfo) == -1) { continue; } if (ret != 5) { if (S_ISDIR (statinfo.st_mode)) { if (debug > 4) { printf ("into: %s\n", path); } di_getQNXDiskEntries (path, diskInfo, diCount); } continue; } if (ftype != _FTYPE_ANY) { continue; } *tspecial = '\0'; if (S_ISDIR(statinfo.st_mode) && ftype == _FTYPE_ANY) { if ((fd = open (path, /* O_ACCMODE */ O_RDONLY | O_NOCTTY)) != -1) { devctl (fd, DCMD_FSYS_MOUNTED_ON, tspecial, DI_SPEC_NAME_LEN, 0); close (fd); if (*tspecial == '\0') { /* unfortunately, this cuts out /proc, /dev/sem, etc. */ /* but it also removes strange duplicate stuff */ continue; } } else { continue; } } else { continue; } idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * (Size_t) *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); path[len] = '\0'; strncpy (diptr->special, tspecial, DI_SPEC_NAME_LEN); strncpy (diptr->name, path + 11, DI_NAME_LEN); if (*diptr->name == '\0') { strncpy (diptr->name, "/", DI_NAME_LEN); } if (debug > 4) { printf ("found: %s %s\n", diptr->special, diptr->name); } } closedir (dirp); return 0; } #endif /* QNX */ /* if nothing matches, assume a SysV.3 /etc/mnttab or similar */ #if ! _lib_getmntent \ && ! _lib_mntctl \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_getmnt \ && ! _lib_GetDriveType \ && ! _lib_GetLogicalDriveStrings \ && ! _lib_fs_stat_dev \ && ! _class_os__Volumes \ && ! _lib_sys_dollar_device_scan \ && ! defined (__QNX__) /* * di_getDiskEntries * * For SysV.3 we open the file and read it ourselves. * */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; FILE *f; int idx; struct mnttab mntEntry; if (debug > 0) { printf ("# getDiskEntries: not anything; sys v.3\n"); } if ((f = fopen (DI_MOUNT_FILE, "r")) == (FILE *) NULL) { fprintf (stderr, "Unable to open: %s errno %d\n", DI_MOUNT_FILE, errno); return -1; } while (fread ((char *) &mntEntry, sizeof (struct mnttab), 1, f) == 1) { /* xenix allows null mount table entries */ /* sco nfs background mounts are marked as "nothing" */ if (mntEntry.mt_filsys [0] && strcmp (mntEntry.mt_filsys, "nothing") != 0) { idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); # if defined (COHERENT) /* Coherent seems to have these fields reversed. oh well. */ strncpy (diptr->name, mntEntry.mt_dev, DI_NAME_LEN); strncpy (diptr->special, mntEntry.mt_filsys, DI_SPEC_NAME_LEN); # else strncpy (diptr->special, mntEntry.mt_dev, DI_SPEC_NAME_LEN); strncpy (diptr->name, mntEntry.mt_filsys, DI_NAME_LEN); # endif # if _mem_struct_mnttab_mntopts strncpy (diptr->options, mntEntry.mt_mntopts, DI_OPT_LEN); # endif } if (debug > 1) { printf ("mnt:%s - %s\n", diptr->name, diptr->special); } } fclose (f); return 0; } #endif /* Sys V.3 */ /* * All of the following routines also replace di_getDiskInfo() */ #if _lib_getfsstat \ && ! (_lib_getvfsstat && _args_getvfsstat == 3) /* * di_getDiskEntries * * OSF/1 / Digital Unix / Compaq Tru64 / FreeBSD / NetBSD 2.x / OpenBSD * */ # if _dcl_mnt_names # if ! defined (MNT_NUMTYPES) # define MNT_NUMTYPES (sizeof(mnt_names)/sizeof(char *)) # endif # endif int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int count; int idx; # if _dcl_mnt_names && _mem_struct_statfs_f_type short fstype; # endif _c_arg_2_getfsstat bufsize; struct statfs *mntbufp; struct statfs *sp; if (debug > 0) { printf ("# getDiskEntries: getfsstat\n"); } count = getfsstat ((struct statfs *) NULL, (_c_arg_2_getfsstat) 0, MNT_NOWAIT); if (count < 1) { fprintf (stderr, "Unable to do getfsstat () errno %d\n", errno); return -1; } bufsize = (_c_arg_2_getfsstat) (sizeof (struct statfs) * (Size_t) count); mntbufp = malloc ((Size_t) bufsize); if (mntbufp == (struct statfs *) NULL) { fprintf (stderr, "malloc failed for mntbufp. errno %d\n", errno); return -1; } memset ((char *) mntbufp, '\0', sizeof (struct statfs) * (Size_t) count); count = getfsstat (mntbufp, bufsize, MNT_NOWAIT); *diCount = count; *diskInfo = (diDiskInfo_t *) malloc (sizeof (diDiskInfo_t) * (Size_t) count); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } memset ((char *) *diskInfo, '\0', sizeof (diDiskInfo_t) * (Size_t) count); for (idx = 0; idx < count; idx++) { _fs_size_t tblocksz; diptr = *diskInfo + idx; di_initDiskInfo (diptr); sp = mntbufp + idx; # if defined (MNT_RDONLY) if ((sp->f_flags & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } # endif # if defined (MNT_LOCAL) if ((sp->f_flags & MNT_LOCAL) != MNT_LOCAL) { diptr->isLocal = FALSE; } # endif convertMountOptions ((unsigned long) sp->f_flags, diptr); # if _mem_struct_statfs_f_type # if defined (MOUNT_NFS3) if (sp->f_type == MOUNT_NFS3) { strncat (diptr->options, "v3,", DI_OPT_LEN - strlen (diptr->options) - 1); } # endif # endif # if _mem_struct_statfs_mount_info \ && defined (MOUNT_NFS) \ && (_mem_struct_statfs_f_type || _mem_struct_statfs_f_fstypename) # if _mem_struct_statfs_f_type if (sp->f_type == MOUNT_NFS # endif # if _mem_struct_statfs_f_fstypename if (strcmp (sp->f_fstypename, MOUNT_NFS) == 0 # endif # if _mem_struct_statfs_f_fstypename && defined (MOUNT_NFS3) || strcmp (sp->f_fstypename, MOUNT_NFS3) == 0 # endif # if _mem_struct_statfs_f_type && defined (MOUNT_NFS3) || sp->f_type == MOUNT_NFS3 # endif ) { struct nfs_args *na; na = &sp->mount_info.nfs_args; convertNFSMountOptions (na->flags, na->wsize, na->rsize, diptr); } # endif trimChar (diptr->options, ','); strncpy (diptr->special, sp->f_mntfromname, (Size_t) DI_SPEC_NAME_LEN); strncpy (diptr->name, sp->f_mntonname, (Size_t) DI_NAME_LEN); # if _mem_struct_statfs_f_fsize tblocksz = (_fs_size_t) sp->f_fsize; # endif # if _mem_struct_statfs_f_bsize && ! _mem_struct_statfs_f_fsize tblocksz = (_fs_size_t) sp->f_bsize; # endif di_saveBlockSizes (diptr, tblocksz, (_fs_size_t) sp->f_blocks, (_fs_size_t) sp->f_bfree, (_fs_size_t) sp->f_bavail); di_saveInodeSizes (diptr, (_fs_size_t) sp->f_files, (_fs_size_t) sp->f_ffree, (_fs_size_t) sp->f_ffree); # if _mem_struct_statfs_f_fstypename strncpy (diptr->fsType, sp->f_fstypename, (Size_t) DI_TYPE_LEN); # else # if _lib_sysfs && _mem_struct_statfs_f_type sysfs (GETFSTYP, sp->f_type, diptr->fsType); # else # if _dcl_mnt_names && _mem_struct_statfs_f_type # define DI_UNKNOWN_FSTYPE "(%.2d)?" fstype = sp->f_type; if ((fstype >= 0) && (fstype < MNT_NUMTYPES)) { strncpy (diptr->fsType, mnt_names [fstype], DI_TYPE_LEN); } else { Snprintf1 (diptr->fsType, sizeof (diptr->fsType), DI_UNKNOWN_FSTYPE, fstype); } # endif # endif # endif } free ((char *) mntbufp); return 0; } #endif /* _lib_getfsstat */ #if _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat /* * di_getDiskEntries * * Old OSF/1 system call. * OSF/1 does this with a system call and library routine. * [mogul@wrl.dec.com (Jeffrey Mogul)] * */ # if defined (INITMOUNTNAMES) && ! _dcl_mnt_names static char *mnt_names [] = INITMOUNTNAMES; # if ! defined (MNT_NUMTYPES) # define MNT_NUMTYPES (MOUNT_MAXTYPE + 1) # endif # endif int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int count; int idx; short fstype; struct statfs *mntbufp; if (debug > 0) { printf ("# getDiskEntries: getmntinfo\n"); } count = getmntinfo (&mntbufp, MNT_WAIT); if (count < 1) { fprintf (stderr, "Unable to do getmntinfo() errno %d\n", errno); return -1; } *diCount = count; *diskInfo = (diDiskInfo_t *) malloc (sizeof (diDiskInfo_t) * (Size_t) count); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } memset ((char *) *diskInfo, '\0', sizeof (diDiskInfo_t) * (Size_t) count); if (debug > 1) { printf ("type_len %d name_len %d spec_name_len %d\n", DI_TYPE_LEN, DI_NAME_LEN, DI_SPEC_NAME_LEN); } for (idx = 0; idx < count; idx++) { _fs_size_t tblocksz; diptr = *diskInfo + idx; di_initDiskInfo (diptr); # if defined (MNT_LOCAL) if ((mntbufp [idx].f_flags & MNT_LOCAL) != MNT_LOCAL) { diptr->isLocal = FALSE; } # endif strncpy (diptr->special, mntbufp [idx].f_mntfromname, DI_SPEC_NAME_LEN); strncpy (diptr->name, mntbufp [idx].f_mntonname, DI_NAME_LEN); tblocksz = (_fs_size_t) 1024; # if _mem_struct_statfs_f_fsize /* OSF 1.x */ tblocksz = (_fs_size_t) mntbufp [idx].f_fsize; # endif # if _mem_struct_statfs_f_bsize /* OSF 2.x */ tblocksz = (_fs_size_t) mntbufp [idx].f_bsize; # endif di_saveBlockSizes (diptr, tblocksz, (_fs_size_t) mntbufp [idx].f_blocks, (_fs_size_t) mntbufp [idx].f_bfree, (_fs_size_t) mntbufp [idx].f_bavail); di_saveInodeSizes (diptr, (_fs_size_t) mntbufp [idx].f_files, (_fs_size_t) mntbufp [idx].f_ffree, (_fs_size_t) mntbufp [idx].f_ffree); fstype = mntbufp [idx].f_type; # if ! _sys_fs_types && ! defined (INITMOUNTNAMES) \ && ! _mem_struct_statfs_f_fstypename if ((fstype >= 0) && (fstype <= MOUNT_MAXTYPE)) { switch (fstype) { # if defined (MOUNT_NONE) case MOUNT_NONE: /* No Filesystem */ { strncpy (diptr->fsType, "none", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_UFS) case MOUNT_UFS: /* UNIX "Fast" Filesystem */ { strncpy (diptr->fsType, "ufs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_NFS) case MOUNT_NFS: /* Network Filesystem */ { strncpy (diptr->fsType, "nfs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_MFS) case MOUNT_MFS: /* Memory Filesystem */ { strncpy (diptr->fsType, "mfs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_MSDOS) case MOUNT_MSDOS: /* MSDOS Filesystem */ { strncpy (diptr->fsType, "msdos", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_LFS) case MOUNT_LFS: { strncpy (diptr->fsType, "lfs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_LOFS) case MOUNT_LOFS: { strncpy (diptr->fsType, "lofs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_FDESC) case MOUNT_FDESC: { strncpy (diptr->fsType, "fdesc", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_PORTAL) case MOUNT_PORTAL: { strncpy (diptr->fsType, "portal", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_NULL) case MOUNT_NULL: { strncpy (diptr->fsType, "null", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_UMAP) case MOUNT_UMAP: { strncpy (diptr->fsType, "umap", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_KERNFS) case MOUNT_KERNFS: { strncpy (diptr->fsType, "kernfs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_PROCFS) case MOUNT_PROCFS: /* proc filesystem */ { strncpy (diptr->fsType, "pfs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_AFS) case MOUNT_AFS: { strncpy (diptr->fsType, "afs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_ISOFS) case MOUNT_ISOFS: /* iso9660 cdrom */ { strncpy (diptr->fsType, "iso9660fs", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_ISO9660) && ! defined (MOUNT_CD9660) case MOUNT_ISO9660: /* iso9660 cdrom */ { strncpy (diptr->fsType, "iso9660", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_CD9660) case MOUNT_CD9660: /* iso9660 cdrom */ { strncpy (diptr->fsType, "cd9660", DI_TYPE_LEN); break; } # endif # if defined (MOUNT_UNION) case MOUNT_UNION: { strncpy (diptr->fsType, "union", DI_TYPE_LEN); break; } # endif } /* switch on mount type */ } # else # if _mem_struct_statfs_f_fstypename strncpy (diptr->fsType, mntbufp [idx].f_fstypename, DI_TYPE_LEN); # else # define DI_UNKNOWN_FSTYPE "(%.2d)?" /* could use getvfsbytype here... */ if ((fstype >= 0) && (fstype < MNT_NUMTYPES)) { strncpy (diptr->fsType, mnt_names [fstype], DI_TYPE_LEN); } else { Snprintf1 (diptr->fsType, sizeof (diptr->fsType), DI_UNKNOWN_FSTYPE, fstype); } # endif # endif /* else has sys/fs_types.h */ diptr->isReadOnly = FALSE; # if defined (MNT_RDONLY) if ((mntbufp [idx].f_flags & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } # endif convertMountOptions ((unsigned long) mntbufp [idx].f_flags, diptr); trimChar (diptr->options, ','); if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tblocks: tot:%ld free:%ld avail:%ld\n", (long) mntbufp [idx].f_blocks, (long) mntbufp [idx].f_bfree, (long) mntbufp [idx].f_bavail); # if _mem_struct_statfs_f_fsize printf ("\tfsize:%ld \n", (long) mntbufp [idx].f_fsize); # endif # if _mem_struct_statfs_f_bsize printf ("\tbsize:%ld \n", (long) mntbufp [idx].f_bsize); # endif # if _mem_struct_statfs_f_iosize printf ("\tiosize:%ld \n", (long) mntbufp [idx].f_iosize); # endif printf ("\tinodes: tot:%ld free:%ld\n", (long) mntbufp [idx].f_files, (long) mntbufp [idx].f_ffree); } } free ((char *) mntbufp); /* man page says this can't be freed. */ /* is it ok to try? */ return 0; } #endif /* _lib_getmntinfo */ #if _lib_getvfsstat && _args_getvfsstat == 3 /* * di_getDiskEntries * * NetBSD * */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int count; int idx; Size_t bufsize; struct statvfs *mntbufp; struct statvfs *sp; if (debug > 0) { printf ("# getDiskEntries: getvfsstat\n"); } count = getvfsstat ((struct statvfs *) NULL, 0, ST_NOWAIT); if (count < 1) { fprintf (stderr, "Unable to do getvfsstat () errno %d\n", errno); return -1; } bufsize = sizeof (struct statvfs) * (Size_t) count; mntbufp = malloc ((Size_t) bufsize); if (mntbufp == (struct statvfs *) NULL) { fprintf (stderr, "malloc failed for mntbufp. errno %d\n", errno); return -1; } memset ((char *) mntbufp, '\0', sizeof (struct statvfs) * (Size_t) count); count = getvfsstat (mntbufp, (Size_t) bufsize, ST_NOWAIT); *diCount = count; *diskInfo = (diDiskInfo_t *) malloc (sizeof (diDiskInfo_t) * (Size_t) count); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } memset ((char *) *diskInfo, '\0', sizeof (diDiskInfo_t) * (Size_t) count); for (idx = 0; idx < count; idx++) { _fs_size_t tblocksz; diptr = *diskInfo + idx; di_initDiskInfo (diptr); sp = mntbufp + idx; # if defined (MNT_RDONLY) if ((sp->f_flag & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } # endif # if defined (MNT_LOCAL) if ((sp->f_flag & MNT_LOCAL) != MNT_LOCAL) { diptr->isLocal = FALSE; } # endif convertMountOptions ((unsigned long) sp->f_flag, diptr); trimChar (diptr->options, ','); if (sp->f_frsize == 0 && sp->f_bsize != 0) { tblocksz = (_fs_size_t) sp->f_bsize; } else { tblocksz = (_fs_size_t) sp->f_frsize; } di_saveBlockSizes (diptr, tblocksz, (_fs_size_t) sp->f_blocks, (_fs_size_t) sp->f_bfree, (_fs_size_t) sp->f_bavail); di_saveInodeSizes (diptr, (_fs_size_t) sp->f_files, (_fs_size_t) sp->f_ffree, (_fs_size_t) sp->f_ffree); strncpy (diptr->special, sp->f_mntfromname, DI_SPEC_NAME_LEN); strncpy (diptr->name, sp->f_mntonname, DI_NAME_LEN); strncpy (diptr->fsType, sp->f_fstypename, DI_TYPE_LEN); if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tbsize:%ld frsize:%ld\n", (long) sp->f_bsize, (long) sp->f_frsize); #if _siz_long_long >= 8 printf ("\tblocks: tot:%llu free:%lld avail:%llu\n", sp->f_blocks, sp->f_bfree, sp->f_bavail); printf ("\tinodes: tot:%llu free:%llu avail:%llu\n", sp->f_files, sp->f_ffree, sp->f_favail); #else printf ("\tblocks: tot:%lu free:%lu avail:%lu\n", sp->f_blocks, sp->f_bfree, sp->f_bavail); printf ("\tinodes: tot:%lu free:%lu avail:%lu\n", sp->f_files, sp->f_ffree, sp->f_favail); #endif } } free ((char *) mntbufp); return 0; } #endif /* _lib_getvfsstat */ #if _lib_getmnt # if _npt_getmnt int getmnt _((int *, struct fs_data *, int, int, char *)); # endif /* * di_getDiskEntries * * ULTRIX does this with a system call. The system call allows one * to retrieve the information in a series of calls, but coding that * looks a little tricky; I just allocate a huge buffer and do it in * one shot. * * [mogul@wrl.dec.com (Jeffrey Mogul)] */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int count; int bufsize; int idx; short fstype; struct fs_data *fsdbuf; int start; int len; if (debug > 0) { printf ("# getDiskEntries: getmnt\n"); } bufsize = NMOUNT * sizeof (struct fs_data); /* enough for max # mounts */ fsdbuf = (struct fs_data *) malloc ((Size_t) bufsize); if (fsdbuf == (struct fs_data *) NULL) { fprintf (stderr, "malloc (%d) for getmnt () failed errno %d\n", bufsize, errno); return -1; } start = 0; count = getmnt (&start, fsdbuf, bufsize, STAT_MANY, 0); if (count < 1) { fprintf (stderr, "Unable to do getmnt () [= %d] errno %d\n", count, errno); free ((char *) fsdbuf); return -1; } *diCount = count; *diskInfo = (diDiskInfo_t *) malloc (sizeof (diDiskInfo_t) * (Size_t) count); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); free ((char *) fsdbuf); return -1; } memset ((char *) *diskInfo, '\0', sizeof (diDiskInfo_t) * count); for (idx = 0; idx < count; idx++) { diptr = *diskInfo + idx; di_initDiskInfo (diptr); if ((fsdbuf [idx].fd_req.flags & MNT_LOCAL) != MNT_LOCAL) { diptr->isLocal = FALSE; } strncpy (diptr->special, fsdbuf [idx].fd_devname, DI_SPEC_NAME_LEN); strncpy (diptr->name, fsdbuf [idx].fd_path, DI_NAME_LEN); /* ULTRIX keeps these fields in units of 1K byte */ di_saveBlockSizes (diptr, (_fs_size_t) 1024, (_fs_size_t) fsdbuf [idx].fd_btot, (_fs_size_t) fsdbuf [idx].fd_bfree, (_fs_size_t) fsdbuf [idx].fd_bfreen); di_saveInodeSizes (diptr, (_fs_size_t) fsdbuf [idx].fd_gtot, (_fs_size_t) fsdbuf [idx].fd_gfree, (_fs_size_t) fsdbuf [idx].fd_gfree); fstype = fsdbuf [idx].fd_fstype; if (fstype == GT_UNKWN) { diptr->printFlag = DI_PRNT_IGNORE; if (debug > 2) { printf ("mnt: ignore: disk type unknown: %s\n", diptr->name); } } else if ((fstype > 0) && (fstype < GT_NUMTYPES)) { strncpy (diptr->fsType, gt_names [fstype], DI_TYPE_LEN); } else { Snprintf1 (diptr->fsType, sizeof (diptr->fsType), "Unknown fstyp %.2d", fstype); } if ((fsdbuf [idx].fd_req.flags & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } else { diptr->isReadOnly = FALSE; } convertMountOptions ((unsigned long) fsdbuf [idx].fd_req.flags, diptr); trimChar (diptr->options, ','); if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tblocks: tot:%ld free:%ld avail:%ld\n", fsdbuf [idx].fd_btot, fsdbuf [idx].fd_bfree, (int) fsdbuf [idx].fd_bfreen); printf ("\tinodes: tot:%ld free:%ld\n", fsdbuf [idx].fd_gtot, fsdbuf [idx].fd_gfree); } } free ((char *) fsdbuf); return 0; } #endif /* _lib_getmnt */ #if _lib_mntctl /* * di_getDiskEntries * * AIX uses mntctl to find out about mounted file systems * This seems to be better than set/get/end, as we get the * remote filesystem flag. * */ # define DI_FSMAGIC 10 /* base AIX configuration has 5 file systems */ # define NUM_AIX_FSTYPES 6 static char *AIX_fsType [NUM_AIX_FSTYPES] = { "oaix", "", "nfs", "jfs", "", "cdrom" }; /* * from xfsm-1.80: * * MNT_AIX - "aix" * MNT_NFS - "nfs" * MNT_JFS - "jfs" * MNT_CDROM - "cdrom" * other - "user defined" * */ #define DI_RETRY_COUNT 5 int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int num; /* number of vmount structs returned */ char *vmbuf; /* buffer for vmount structs returned */ Size_t vmbufsz; /* size in bytes of vmbuf */ int i; /* index for looping and stuff */ char *bufp; /* pointer into vmbuf */ struct vmount *vmtp; /* pointer into vmbuf */ struct vfs_ent *ve; /* pointer for file system type entry */ if (debug > 0) { printf ("# getDiskEntries: mntctl\n"); } i = 0; vmbufsz = sizeof (struct vmount) * DI_FSMAGIC; /* initial vmount buffer */ do { if ((vmbuf = (char *) malloc (vmbufsz)) == (char *) NULL) { fprintf (stderr, "malloc (%d) for mntctl() failed errno %d\n", (int) vmbufsz, errno); return -1; } num = mntctl (MCTL_QUERY, vmbufsz, vmbuf); /* * vmbuf is too small, could happen for * following reasons: * - inital buffer is too small * - newly mounted file system */ if (num == 0) { memcpy (&vmbufsz, vmbuf, sizeof (vmbufsz)); /* see mntctl(2) */ if (debug > 0) { printf ("vmbufsz too small, new size: %d\n", (int) vmbufsz); } free ((char *) vmbuf); /* free this last, it's still being used! */ ++i; } } while (num == 0 && i < DI_RETRY_COUNT); if (i >= DI_RETRY_COUNT) { free ((char *) vmbuf); fprintf (stderr, "unable to allocate adequate buffer for mntctl\n"); return -1; } if (num == -1) { free ((char *) vmbuf); fprintf (stderr, "%s errno %d\n", strerror (errno), errno); return -1; } /* vmount structs returned in vmbuf */ *diCount = num; *diskInfo = (diDiskInfo_t *) malloc (sizeof (diDiskInfo_t) * (Size_t) *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. %s errno %d\n", strerror (errno), errno); return -1; } bufp = vmbuf; for (i = 0; i < num; i++) { diptr = *diskInfo + i; di_initDiskInfo (diptr); vmtp = (struct vmount *) bufp; if ((vmtp->vmt_flags & MNT_REMOTE) == MNT_REMOTE) { diptr->isLocal = FALSE; } if ((vmtp->vmt_flags & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } *diptr->special = '\0'; if (diptr->isLocal == FALSE) { strncpy (diptr->special, (char *) vmt2dataptr (vmtp, VMT_HOSTNAME), DI_SPEC_NAME_LEN); strncat (diptr->special, ":", DI_SPEC_NAME_LEN - strlen (diptr->special) - 1); } strncat (diptr->special, (char *) vmt2dataptr (vmtp, VMT_OBJECT), DI_SPEC_NAME_LEN - strlen (diptr->special) - 1); strncpy (diptr->name, (char *) vmt2dataptr (vmtp, VMT_STUB), DI_NAME_LEN); ve = getvfsbytype (vmtp->vmt_gfstype); if (ve == (struct vfs_ent *) NULL || *ve->vfsent_name == '\0') { if (vmtp->vmt_gfstype >= 0 && (vmtp->vmt_gfstype < NUM_AIX_FSTYPES)) { strncpy (diptr->fsType, AIX_fsType [vmtp->vmt_gfstype], DI_TYPE_LEN); } } else { strncpy (diptr->fsType, ve->vfsent_name, DI_TYPE_LEN); } strncpy (diptr->options, (char *) vmt2dataptr (vmtp, VMT_ARGS), DI_OPT_LEN); trimChar (diptr->options, ','); bufp += vmtp->vmt_length; if (debug > 1) { printf ("mnt:%s - %s : %s\n", diptr->name, diptr->special, diptr->fsType); printf ("\t%s\n", (char *) vmt2dataptr (vmtp, VMT_ARGS)); } } return 0; } #endif /* _lib_mntctl */ #if _lib_GetDriveType \ && _lib_GetLogicalDriveStrings /* * di_getDiskInfo * * Windows * */ # define MSDOS_BUFFER_SIZE 256 # define BYTES_PER_LOGICAL_DRIVE 4 int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int i; char diskflag; int rc; char *p; char buff [MSDOS_BUFFER_SIZE]; if (debug > 0) { printf ("# getDiskInfo: GetLogicalDriveStrings GetDriveType\n"); } diskflag = DI_PRNT_SKIP; rc = (int) GetLogicalDriveStrings (MSDOS_BUFFER_SIZE, buff); *diCount = rc / BYTES_PER_LOGICAL_DRIVE; *diskInfo = (diDiskInfo_t *) malloc (sizeof (diDiskInfo_t) * (Size_t) *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } for (i = 0; i < *diCount; ++i) { diptr = *diskInfo + i; p = buff + (BYTES_PER_LOGICAL_DRIVE * i); strncpy (diptr->name, p, DI_NAME_LEN); rc = (int) GetDriveType (p); diptr->printFlag = DI_PRNT_OK; if (rc == DRIVE_NO_ROOT_DIR) { diptr->printFlag = DI_PRNT_BAD; } /* assume that any removable drives before the */ /* first non-removable disk are floppies... */ else if (rc == DRIVE_REMOVABLE) { DWORD br; BOOL bSuccess; char handleName [MSDOS_BUFFER_SIZE + 1]; diptr->printFlag = diskflag; bSuccess = 1; strncpy (handleName, "\\\\.\\", MSDOS_BUFFER_SIZE); strncat (handleName, p, MSDOS_BUFFER_SIZE); handleName[strlen(handleName)-1] = '\0'; # if _define_IOCTL_STORAGE_CHECK_VERIFY2 HANDLE hDevice = CreateFile (handleName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); bSuccess = DeviceIoControl (hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0, NULL, 0, &br, (LPOVERLAPPED) NULL); # else HANDLE hDevice = CreateFile (handleName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); bSuccess = DeviceIoControl (hDevice, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &br, (LPOVERLAPPED) NULL); # endif CloseHandle (hDevice); if (! bSuccess) { diptr->printFlag = DI_PRNT_BAD; } } else { diskflag = DI_PRNT_OK; } if (rc != DRIVE_REMOTE) { diptr->isLocal = TRUE; } } /* for each mounted drive */ return *diCount; } #endif /* _lib_GetDiskFreeSpace || _lib_GetDiskFreeSpaceEx */ #if _lib_fs_stat_dev \ && _lib_next_dev /* * di_getDiskEntries * * For BeOS. * */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; status_t stat; int idx; int32 count; dev_t dev; char buff [B_FILE_NAME_LENGTH]; fs_info fsinfo; node_ref nref; BDirectory *dir; BEntry entry; BPath path; if (debug > 0) { printf ("# getDiskEntries: fs_stat_dev\n"); } count = 0; while ((dev = next_dev (&count)) != B_BAD_VALUE) { if ((stat = fs_stat_dev (dev, &fsinfo)) == B_BAD_VALUE) { break; } idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); *buff = '\0'; nref.device = dev; nref.node = fsinfo.root; dir = new BDirectory (&nref); stat = dir->GetEntry (&entry); stat = entry.GetPath (&path); strncpy (diptr->name, path.Path(), DI_NAME_LEN); strncpy (diptr->special, fsinfo.device_name, DI_SPEC_NAME_LEN); strncpy (diptr->fsType, fsinfo.fsh_name, DI_TYPE_LEN); di_saveBlockSizes (diptr, (_fs_size_t) fsinfo.block_size, (_fs_size_t) fsinfo.total_blocks, (_fs_size_t) fsinfo.free_blocks, (_fs_size_t) fsinfo.free_blocks); di_saveInodeSizes (diptr, (_fs_size_t) fsinfo.total_nodes, (_fs_size_t) fsinfo.free_nodes, (_fs_size_t) fsinfo.free_nodes); # if defined (MNT_RDONLY) if ((fsinfo.flags & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } # endif # if defined (MNT_PERSISTENT) if ((fsinfo.flags & MNT_PERSISTENT) != MNT_PERSISTENT) { diptr->printFlag = DI_PRNT_IGNORE; } # endif convertMountOptions ((unsigned long) fsinfo.flags, diptr); trimChar (diptr->options, ','); if (debug > 1) { printf ("mnt:%s - %s\n", diptr->name, diptr->special); printf ("dev:%d fs:%s\n", dev, diptr->fsType); printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tblocks: tot:%ld free:%ld\n", fsinfo.total_blocks, fsinfo.free_blocks); printf ("\tinodes: tot:%ld free:%ld\n", fsinfo.total_nodes, fsinfo.free_nodes); } } return 0; } #endif #if _class_os__Volumes /* * di_getDiskEntries * * For Syllable. * */ int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int idx; Uint_t i; status_t stat; uint32 count; fs_info fsinfo; os::Volumes *vols; os::String mpString; if (debug > 0) { printf ("# getDiskEntries: os::Volumes\n"); } vols = new os::Volumes; count = vols->GetMountPointCount (); for (i = 0; i < count; ++i) { if ((stat = vols->GetFSInfo (i, &fsinfo)) != 0) { break; } idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * *diCount); if (*diskInfo == (diDiskInfo_t *) NULL) { fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); stat = vols->GetMountPoint (i, &mpString); strncpy (diptr->name, mpString.c_str(), DI_NAME_LEN); strncpy (diptr->special, fsinfo.fi_device_path, DI_SPEC_NAME_LEN); strncpy (diptr->fsType, fsinfo.fi_driver_name, DI_TYPE_LEN); di_saveBlockSizes (diptr, (_fs_size_t) fsinfo.fi_block_size, (_fs_size_t) fsinfo.fi_total_blocks, (_fs_size_t) fsinfo.fi_free_blocks, (_fs_size_t) fsinfo.fi_free_user_blocks); di_saveInodeSizes (diptr, (_fs_size_t) fsinfo.fi_total_inodes, (_fs_size_t) fsinfo.fi_free_inodes, (_fs_size_t) fsinfo.fi_free_inodes); # if defined (MNT_RDONLY) if ((fsinfo.fi_flags & MNT_RDONLY) == MNT_RDONLY) { diptr->isReadOnly = TRUE; } # endif # if defined (MNT_PERSISTENT) if ((fsinfo.fi_flags & MNT_PERSISTENT) != MNT_PERSISTENT) { diptr->printFlag = DI_PRNT_IGNORE; } # endif convertMountOptions ((unsigned long) fsinfo.fi_flags, diptr); trimChar (diptr->options, ','); if (debug > 1) { printf ("mnt:%s - %s\n", diptr->name, diptr->special); printf ("dev:%d fs:%s\n", fsinfo.fi_dev, diptr->fsType); printf ("mount_args: %s\n", fsinfo.fi_mount_args); printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tblocks: tot:%ld free:%ld avail:%ld\n", (long int) fsinfo.fi_total_blocks, (long int) fsinfo.fi_free_blocks, (long int) fsinfo.fi_free_user_blocks); printf ("\tinodes: tot:%ld free:%ld\n", (long int) fsinfo.fi_total_inodes, (long int) fsinfo.fi_free_inodes); } } return 0; } #endif /* * VMS */ #if _lib_sys_dollar_device_scan && _lib_sys_dollar_getdviw /* Thanks to Craig Berry's VMS::Device for the VMS code. */ char *monthNames[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; genericID_t devInfoList[] = { #ifdef DVI$_DISPLAY_DEVNAM DVI_ENT(DISPLAY_DEVNAM, 256, DVI_IS_STRING), #endif #ifdef DVI$_DEVBUFSIZ DVI_ENT(DEVBUFSIZ, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_MAXBLOCK DVI_ENT(MAXBLOCK, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_FREEBLOCKS DVI_ENT(FREEBLOCKS, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_MAXFILES DVI_ENT(MAXFILES, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_REMOTE_DEVICE DVI_ENT(REMOTE_DEVICE, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_VOLNAM DVI_ENT(VOLNAM, 12, DVI_IS_STRING), #endif #ifdef DVI$_AVL DVI_ENT(AVL, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_MNT DVI_ENT(MNT, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_SHR DVI_ENT(SHR, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_ODS2_SUBSET0 DVI_ENT(ODS2_SUBSET0, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_ODS5 DVI_ENT(ODS5, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_NET DVI_ENT(NET, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_DEVICE_TYPE_NAME DVI_ENT(DEVICE_TYPE_NAME, 64, DVI_IS_STRING), #endif #ifdef DVI$_SHDW_MASTER DVI_ENT(SHDW_MASTER, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_SHDW_MEMBER DVI_ENT(SHDW_MEMBER, 4, DVI_IS_LONGWORD), #endif #ifdef DVI$_SHDW_MASTER_NAME DVI_ENT(SHDW_MASTER_NAME, 64, DVI_IS_STRING), #endif {NULL, 0, 0, 0} }; #define devInfoListCount ((sizeof(devInfoList)/sizeof (genericID_t)) - 1) int di_getDiskEntries (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int idx; unsigned short devNameLen; unsigned short devReturnLen; unsigned int deviceClass; char context[8] = {0,0,0,0,0,0,0,0}; struct dsc$descriptor_s devNameDesc; struct dsc$descriptor_s devSearchNameDesc; VMS_ITMLST scanItemList; VMS_ITMLST *itemList; unsigned short *returnLengths; char **returnBuffers; long *tempLong; char returnedDevName [65]; unsigned short returnedTime[7]; char displayTime[100]; int i; int status; # ifdef __ALPHA __int64 *tempLongLong; # endif _fs_size_t freeBlocks; _fs_size_t totBlocks; _fs_size_t maxFiles; _fs_size_t tblocksz; if (debug > 0) { printf ("# getDiskEntries: sys$device_scan/sys$getdviw\n"); } devNameDesc.dsc$a_pointer = returnedDevName; devNameDesc.dsc$w_length = 64; devNameDesc.dsc$b_dtype = DSC$K_DTYPE_T; devNameDesc.dsc$b_class = DSC$K_CLASS_S; devSearchNameDesc.dsc$a_pointer = "*"; devSearchNameDesc.dsc$w_length = 1; devSearchNameDesc.dsc$b_dtype = DSC$K_DTYPE_T; devSearchNameDesc.dsc$b_class = DSC$K_CLASS_S; memset (&scanItemList, 0, sizeof(VMS_ITMLST)); itemList = malloc (sizeof(VMS_ITMLST) * (devInfoListCount)); if (itemList == (VMS_ITMLST *) NULL) { fprintf (stderr, "malloc failed for itemList. errno %d\n", errno); return -1; } memset (itemList, 0, sizeof(VMS_ITMLST) * (devInfoListCount)); returnBuffers = (char **) malloc (sizeof (char *) * devInfoListCount); if (returnBuffers == (char **) NULL) { fprintf (stderr, "malloc failed for returnBuffers. errno %d\n", errno); free ((char *) itemList); return -1; } returnLengths = malloc (sizeof(short) * devInfoListCount); if (returnLengths == (short *) NULL) { fprintf (stderr, "malloc failed for returnLengths. errno %d\n", errno); free ((char *) itemList); free ((char *) returnBuffers); return -1; } for (i = 0; i < devInfoListCount; i++) { returnBuffers[i] = malloc (devInfoList[i].bufferLen + 1); if (returnBuffers[i] == (char *) NULL) { fprintf (stderr, "malloc failed for returnBuffers[i]. errno %d\n", errno); free ((char *) itemList); free ((char *) returnBuffers); free ((char *) returnLengths); return -1; } memset (returnBuffers[i], 0, devInfoList[i].bufferLen + 1); init_itemlist (&itemList[i], devInfoList[i].bufferLen, devInfoList[i].syscallValue, returnBuffers[i], &returnLengths[i]); } deviceClass = DC$_DISK; init_itemlist (&scanItemList, sizeof(deviceClass), DVS$_DEVCLASS, &deviceClass, NULL); while (sys$device_scan (&devNameDesc, &devReturnLen, &devSearchNameDesc, &scanItemList, context) == SS$_NORMAL) { idx = *diCount; ++*diCount; *diskInfo = (diDiskInfo_t *) di_realloc ((char *) *diskInfo, sizeof (diDiskInfo_t) * (Size_t) *diCount); if (*diskInfo == (di_DiskInfo_t *) NULL) fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno); return -1; } diptr = *diskInfo + idx; di_initDiskInfo (diptr); returnedDevName [devReturnLen] = '\0'; if (debug > 4) { printf ("%s\n", returnedDevName); } devNameDesc.dsc$a_pointer = returnedDevName; devNameDesc.dsc$w_length = devReturnLen; devNameDesc.dsc$b_dtype = DSC$K_DTYPE_T; devNameDesc.dsc$b_class = DSC$K_CLASS_S; strncpy (diptr->fsType, "ODS-2", DI_TYPE_LEN); /* _$9$LDA2: */ if (strlen (returnedDevName) > 4 && returnedDevName[4] == 'L') { strncpy (diptr->fsType, "LD", DI_TYPE_LEN); } status = sys$getdviw(0, 0, &devNameDesc, itemList, NULL, NULL, NULL, NULL); if (status == SS$_NORMAL) { for (i = 0; i < devInfoListCount; i++) { switch (devInfoList[i].returnType) { case DVI_IS_STRING: if (debug > 4) { printf (" string:"); printf ("%s:", devInfoList[i].name); printf ("%*s:\n", (int) returnLengths[i], (char *) returnBuffers[i]); } if (strcmp (devInfoList[i].name, "DISPLAY_DEVNAM") == 0) { strncpy (diptr->special, returnBuffers[i], returnLengths[i]); diptr->special[returnLengths[i]] = '\0'; } if (strcmp (devInfoList[i].name, "VOLNAM") == 0) { strncpy (diptr->name, returnBuffers[i], returnLengths[i]); diptr->name[returnLengths[i]] = '\0'; } if (strcmp (devInfoList[i].name, "DEVICE_TYPE_NAME") == 0) { returnBuffers[i][returnLengths[i]] = '\0'; strncat (diptr->options, "dev=", DI_OPT_LEN - strlen (diptr->options) - 1); strncat (diptr->options, returnBuffers[i], DI_OPT_LEN - strlen (diptr->options) - 1); strncat (diptr->options, ",", DI_OPT_LEN - strlen (diptr->options) - 1); } if (strcmp (devInfoList[i].name, "SHDW_MASTER_NAME") == 0) { if (returnLengths[i] > 0) { returnBuffers[i][returnLengths[i]] = '\0'; strncat (diptr->options, returnBuffers[i], DI_OPT_LEN - strlen (diptr->options) - 1); strncat (diptr->options, "),", DI_OPT_LEN - strlen (diptr->options) - 1); } } break; case DVI_IS_VMSDATE: sys$numtim (returnedTime, returnBuffers[i]); sprintf (displayTime, "%02hi-%s-%hi %02hi:%02hi:%02hi.%02hi", returnedTime[2], monthNames[returnedTime[1] - 1], returnedTime[0], returnedTime[3], returnedTime[4], returnedTime[5], returnedTime[6]); if (debug > 4) { printf (" date:"); printf ("%s:", devInfoList[i].name); printf ("%s:\n", displayTime); } break; case DVI_IS_ENUM: tempLong = (long *) returnBuffers[i]; if (debug > 4) { printf (" enum:"); printf ("%s:", devInfoList[i].name); printf ("%ld:\n", *tempLong); } break; case DVI_IS_BITMAP: case DVI_IS_LONGWORD: tempLong = (long *) returnBuffers[i]; if (debug > 4) { printf (" long:"); printf ("%s:", devInfoList[i].name); printf ("%ld:\n", *tempLong); } if (strcmp (devInfoList[i].name, "MAXBLOCK") == 0) { totBlocks = *tempLong; } if (strcmp (devInfoList[i].name, "FREEBLOCKS") == 0) { freeBlocks = *tempLong; } if (strcmp (devInfoList[i].name, "MAXFILES") == 0) { maxFiles = *tempLong; } if (strcmp (devInfoList[i].name, "REMOTE_DEVICE") == 0) { if (*tempLong == 1L) { diptr->isLocal = FALSE; } } if (strcmp (devInfoList[i].name, "NET") == 0) { if (*tempLong == 1L) { diptr->isLocal = FALSE; } } if (strcmp (devInfoList[i].name, "DEVBUFSIZ") == 0) { tblocksz = *tempLong; } if (strcmp (devInfoList[i].name, "AVL") == 0) { if (*tempLong == 0L) { diptr->printFlag = DI_PRNT_IGNORE; strncat (diptr->options, "Offline,", DI_OPT_LEN - strlen (diptr->options) - 1); } if (*tempLong == 1L) { strncat (diptr->options, "Online,", DI_OPT_LEN - strlen (diptr->options) - 1); } } if (strcmp (devInfoList[i].name, "MNT") == 0) { if (*tempLong == 1L) { strncat (diptr->options, "Mounted,", DI_OPT_LEN - strlen (diptr->options) - 1); } else { diptr->printFlag = DI_PRNT_IGNORE; } } if (strcmp (devInfoList[i].name, "SHR") == 0) { if (*tempLong == 1L) { strncat (diptr->options, "Shareable,", DI_OPT_LEN - strlen (diptr->options) - 1); } } if (strcmp (devInfoList[i].name, "SHDW_MASTER") == 0) { if (*tempLong == 1L) { strncat (diptr->options, "Shadow Master,", DI_OPT_LEN - strlen (diptr->options) - 1); } } if (strcmp (devInfoList[i].name, "SHDW_MEMBER") == 0) { if (*tempLong == 1L) { strncat (diptr->options, "Shadow Member(", DI_OPT_LEN - strlen (diptr->options) - 1); } } if (strcmp (devInfoList[i].name, "ODS2_SUBSET0") == 0) { if (*tempLong == 1L) { strncpy (diptr->fsType, "ODS-2/0", DI_TYPE_LEN); } } if (strcmp (devInfoList[i].name, "ODS5") == 0) { if (*tempLong == 1L) { strncpy (diptr->fsType, "ODS-5", DI_TYPE_LEN); } } break; # ifdef __ALPHA case DVI_IS_QUADWORD: tempLongLong = (__int64 *) returnBuffers[i]; if (debug > 4) { printf (" quad:"); printf ("%s:", devInfoList[i].name); printf ("%llu:\n", (long long) *tempLongLong); } break; # endif } } } else { /* fail */ ; } di_saveBlockSizes (diptr, tblocksz, totBlocks, freeBlocks, freeBlocks); di_saveInodeSizes (diptr, maxFiles, 0, 0); /* reset this so there's room during the next syscall */ devNameDesc.dsc$w_length = 64; trimChar (diptr->options, ','); } /* while there are entries */ for (i = 0; i < devInfoListCount; i++) { free (returnBuffers[i]); } free (returnBuffers); free (returnLengths); free (itemList); return 0; } #endif di-4.52/C/dimain.c0000644000175000017500000010323114421556642011744 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #include "dimain.h" #include "display.h" #include "version.h" #include "options.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _hdr_ctype # include #endif #if _hdr_errno # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _hdr_libintl # include #endif #if _hdr_locale # include #endif #if _sys_stat # include #endif #if _hdr_unistd # include #endif #if _hdr_memory # include #endif #if _hdr_malloc # include #endif #if _hdr_zone # include #endif #if _sys_file # include #endif #if _hdr_fcntl \ && ! defined (DI_INC_FCNTL_H) /* xenix */ # define DI_INC_FCNTL_H # include /* O_RDONLY, O_NOCTTY */ #endif #if _use_mcheck # include #endif #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif #if _npt_getenv extern char *getenv _((const char *)); #endif #if defined (__cplusplus) || defined (c_plusplus) } #endif /* end of system specific includes/configurations */ #define DI_UNKNOWN_DEV -1L extern int debug; int debug = { 0 }; #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif #if _lib_zone_list && _lib_getzoneid && _lib_zone_getattr static void checkZone _((diDiskInfo_t *, zoneInfo_t *, unsigned int)); #endif static void checkIgnoreList _((diDiskInfo_t *, iList_t *)); static void checkIncludeList _((diDiskInfo_t *, iList_t *)); static int isIgnoreFSType _((const char *)); static int isIgnoreSpecial _((const char *)); static int isIgnoreFS _((const char *, const char *)); #if _lib_realpath && _define_S_ISLNK && _lib_lstat static int checkForUUID _((const char *)); #endif #if defined (__cplusplus) || defined (c_plusplus) } #endif char * dimainproc (int argc, const char * const argv [], int intfcflag, diData_t *diData) { diOptions_t *diopts; diOutput_t *diout; int hasLoop; int optidx; char *disp; /* initialization */ disp = (char *) NULL; diData->count = 0; diData->haspooledfs = FALSE; diData->disppooledfs = FALSE; diData->totsorted = FALSE; diData->diskInfo = (diDiskInfo_t *) NULL; diData->ignoreList.count = 0; diData->ignoreList.list = (char **) NULL; diData->includeList.count = 0; diData->includeList.list = (char **) NULL; /* options defaults */ diopts = &diData->options; diopts->formatString = DI_DEFAULT_FORMAT; /* change default display format here */ diopts->dispBlockSize = (_print_size_t) (DI_VAL_1024 * DI_VAL_1024); diopts->printTotals = FALSE; diopts->printDebugHeader = FALSE; diopts->printHeader = TRUE; diopts->localOnly = FALSE; diopts->displayAll = FALSE; diopts->dontResolveSymlink = FALSE; /* loopback devices (lofs) should be excluded by default */ diopts->excludeLoopback = FALSE; #if ! _lib_sys_dollar_device_scan /* not VMS */ diopts->excludeLoopback = TRUE; #endif strncpy (diopts->sortType, "m", DI_SORT_MAX); /* default - by mount point*/ diopts->posix_compat = FALSE; diopts->baseDispSize = (_print_size_t) DI_VAL_1024; diopts->baseDispIdx = DI_DISP_1024_IDX; diopts->quota_check = TRUE; diopts->csv_output = FALSE; diopts->csv_tabs = FALSE; diopts->exitFlag = DI_EXIT_NORM; diopts->errorCount = 0; diopts->json_output = FALSE; diout = &diData->output; diout->width = 8; diout->inodeWidth = 9; diout->maxMountString = 0; /* 15 */ diout->maxSpecialString = 0; /* 18 */ diout->maxTypeString = 0; /* 7 */ diout->maxOptString = 0; diout->maxMntTimeString = 0; if (intfcflag) { diopts->csv_output = TRUE; diopts->csv_tabs = TRUE; diopts->printHeader = FALSE; } initLocale (); /* first argument is defaults */ optidx = getDIOptions (argc, argv, diData); if (diData->options.exitFlag != DI_EXIT_NORM) { return disp; } initZones (diData); if (diData->options.exitFlag != DI_EXIT_NORM) { return disp; } if (debug > 0) { printf ("di version %s\n", DI_VERSION); } /* main processing */ if (di_getDiskEntries (&diData->diskInfo, &diData->count) < 0) { cleanup (diData); return disp; } hasLoop = FALSE; preCheckDiskInfo (diData); if (optidx < argc || diopts->excludeLoopback) { getDiskStatInfo (diData); hasLoop = getDiskSpecialInfo (diData, diopts->dontResolveSymlink); } if (optidx < argc) { int rc; rc = checkFileInfo (diData, optidx, argc, argv); if (rc < 0) { cleanup (diData); diData->options.exitFlag = DI_EXIT_WARN; return disp; } } di_getDiskInfo (&diData->diskInfo, &diData->count); checkDiskInfo (diData, hasLoop); if (diopts->quota_check == TRUE) { checkDiskQuotas (diData); } disp = printDiskInfo (diData); return disp; } /* * cleanup * * free up allocated memory * */ extern void cleanup (diData_t *diData) { if (diData->diskInfo != (diDiskInfo_t *) NULL) { free ((char *) diData->diskInfo); } if (diData->ignoreList.count > 0 && diData->ignoreList.list != (char **) NULL) { free ((char *) diData->ignoreList.list); } if (diData->includeList.count > 0 && diData->includeList.list != (char **) NULL) { free ((char *) diData->includeList.list); } if (diData->zoneInfo.zones != (zoneSummary_t *) NULL) { free ((void *) diData->zoneInfo.zones); } } extern int checkFileInfo ( diData_t *diData, int optidx, int argc, const char * const argv []) { int rc; int i; int j; struct stat statBuf; diOptions_t *diopts; diDiskInfo_t *diskInfo; rc = 0; diopts = &diData->options; diskInfo = diData->diskInfo; if (diData->haspooledfs && ! diData->totsorted) { char tempSortType [DI_SORT_MAX + 2]; strncpy (tempSortType, diopts->sortType, DI_SORT_MAX); strncpy (diopts->sortType, "s", DI_SORT_MAX); sortArray (diopts, diskInfo, diData->count, DI_TOT_SORT_IDX); strncpy (diopts->sortType, tempSortType, DI_SORT_MAX); diData->totsorted = TRUE; } for (i = optidx; i < argc; ++i) { int fd; int src; /* do this to automount devices. */ /* stat() will not necessarily cause an automount. */ fd = open (argv[i], O_RDONLY | O_NOCTTY); if (fd < 0) { src = stat (argv [i], &statBuf); } else { src = fstat (fd, &statBuf); } if (src == 0) { int saveIdx; int found = { FALSE }; int inpool = { FALSE }; Size_t lastpoollen = { 0 }; char lastpool [DI_SPEC_NAME_LEN + 1]; saveIdx = 0; /* should get overridden below */ for (j = 0; j < diData->count; ++j) { diDiskInfo_t *dinfo; int startpool; int poolmain; startpool = FALSE; poolmain = FALSE; dinfo = &(diskInfo [diskInfo [j].sortIndex[DI_TOT_SORT_IDX]]); /* is it a pooled filesystem type? */ if (diData->haspooledfs && di_isPooledFs (dinfo)) { if (lastpoollen == 0 || strncmp (lastpool, dinfo->special, lastpoollen) != 0) { strncpy (lastpool, dinfo->special, DI_SPEC_NAME_LEN); lastpoollen = di_mungePoolName (lastpool); inpool = FALSE; } if (strncmp (lastpool, dinfo->special, lastpoollen) == 0) { startpool = TRUE; if (inpool == FALSE) { poolmain = TRUE; } } } else { inpool = FALSE; } if (poolmain) { saveIdx = j; } if (found && inpool) { dinfo = &(diskInfo [diskInfo [j].sortIndex[DI_TOT_SORT_IDX]]); dinfo->printFlag = DI_PRNT_SKIP; if (debug > 2) { printf (" inpool B: also process %s %s\n", dinfo->special, dinfo->name); } } if (dinfo->st_dev != (__ulong) DI_UNKNOWN_DEV && (__ulong) statBuf.st_dev == dinfo->st_dev && ! dinfo->isLoopback) { int foundnew = 0; ++foundnew; if (dinfo->printFlag == DI_PRNT_OK) { ++foundnew; } if (! isIgnoreFSType (dinfo->fsType)) { ++foundnew; } if (foundnew == 3) { dinfo->printFlag = DI_PRNT_FORCE; found = TRUE; } if (debug > 2) { printf ("file %s specified: found device %ld : %d (%s %s)\n", argv[i], dinfo->st_dev, foundnew, dinfo->special, dinfo->name); } if (inpool) { int k; for (k = saveIdx; k < j; ++k) { dinfo = &(diskInfo [diskInfo [k].sortIndex[DI_TOT_SORT_IDX]]); if (dinfo->printFlag != DI_PRNT_FORCE) { dinfo->printFlag = DI_PRNT_SKIP; } if (debug > 2) { printf (" inpool A: also process %s %s\n", dinfo->special, dinfo->name); } } } } if (startpool) { inpool = TRUE; } } } /* if stat ok */ else { if (errno != EACCES && errno != EPERM) { fprintf (stderr, "stat: %s ", argv[i]); perror (""); } rc = -1; } if (fd >= 0) { close (fd); } } /* for each file specified on command line */ /* turn everything off */ for (j = 0; j < diData->count; ++j) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo[j]; if (dinfo->printFlag == DI_PRNT_OK) { dinfo->printFlag = DI_PRNT_IGNORE; } } /* also turn off the -I and -x lists */ diData->includeList.count = 0; diData->ignoreList.count = 0; return rc; } /* * getDiskStatInfo * * gets the disk device number for each entry. * */ extern void getDiskStatInfo (diData_t *diData) { int i; struct stat statBuf; for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo [i]; /* don't try to stat devices that are not accessible */ if (dinfo->printFlag == DI_PRNT_EXCLUDE || dinfo->printFlag == DI_PRNT_BAD || dinfo->printFlag == DI_PRNT_OUTOFZONE) { continue; } dinfo->st_dev = (__ulong) DI_UNKNOWN_DEV; if (stat (dinfo->name, &statBuf) == 0) { dinfo->st_dev = (__ulong) statBuf.st_dev; if (debug > 2) { printf ("dev: %s: %ld\n", dinfo->name, dinfo->st_dev); } } else { if (errno != EACCES && errno != EPERM) { fprintf (stderr, "stat: %s ", dinfo->name); perror (""); } } } } /* * getDiskSpecialInfo * * gets the disk device number for each entry. * */ extern int getDiskSpecialInfo (diData_t *diData, unsigned int dontResolveSymlink) { int i; struct stat statBuf; int hasLoop; hasLoop = FALSE; for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo [i]; /* check for initial slash; otherwise we can pick up normal files */ if (*(dinfo->special) == '/' && stat (dinfo->special, &statBuf) == 0) { #if _lib_realpath && _define_S_ISLNK && _lib_lstat int rc; if (! dontResolveSymlink && checkForUUID (dinfo->special)) { struct stat tstatBuf; rc = lstat (dinfo->special, &tstatBuf); if (rc == 0 && S_ISLNK(tstatBuf.st_mode)) { char tspecial [DI_SPEC_NAME_LEN + 1]; if (realpath (dinfo->special, tspecial) != (char *) NULL) { strncpy (dinfo->special, tspecial, DI_SPEC_NAME_LEN); } } } #endif dinfo->sp_dev = (__ulong) statBuf.st_dev; dinfo->sp_rdev = (__ulong) statBuf.st_rdev; /* Solaris's loopback device is "lofs" */ /* linux loopback device is "none" */ /* linux has rdev = 0 */ /* DragonFlyBSD's loopback device is "null" */ /* but not with special = /.../@@- */ /* DragonFlyBSD has rdev = -1 */ /* solaris is more consistent; rdev != 0 for lofs */ /* solaris makes sense. */ if (di_isLoopbackFs (dinfo)) { dinfo->isLoopback = TRUE; hasLoop = TRUE; } if (debug > 2) { printf ("special dev: %s %s: %ld rdev: %ld loopback: %d\n", dinfo->special, dinfo->name, dinfo->sp_dev, dinfo->sp_rdev, dinfo->isLoopback); } } else { dinfo->sp_dev = 0; dinfo->sp_rdev = 0; } } return hasLoop; } /* * checkDiskInfo * * checks the disk information returned for various return values. * */ extern void checkDiskInfo (diData_t *diData, int hasLoop) { int i; int j; _fs_size_t temp; diOptions_t *diopts; diopts = &diData->options; for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo[i]; dinfo->doPrint = TRUE; /* these are never printed... */ if (dinfo->printFlag == DI_PRNT_EXCLUDE || dinfo->printFlag == DI_PRNT_BAD || dinfo->printFlag == DI_PRNT_OUTOFZONE) { if (debug > 2) { printf ("chk: skipping(%s):%s\n", getPrintFlagText ((int) dinfo->printFlag), dinfo->name); } dinfo->doPrint = FALSE; continue; } /* need to check against include list */ if (dinfo->printFlag == DI_PRNT_IGNORE || dinfo->printFlag == DI_PRNT_SKIP) { if (debug > 2) { printf ("chk: skipping(%s):%s\n", getPrintFlagText ((int) dinfo->printFlag), dinfo->name); } dinfo->doPrint = (char) diopts->displayAll; } /* Solaris reports a cdrom as having no free blocks, */ /* no available. Their df doesn't always work right! */ /* -1 is returned. */ if (debug > 5) { #if _siz_long_long >= 8 printf ("chk: %s free: %llu\n", dinfo->name, dinfo->freeSpace); #else printf ("chk: %s free: %lu\n", dinfo->name, dinfo->freeSpace); #endif } if ((_s_fs_size_t) dinfo->freeSpace == -1L || (_s_fs_size_t) dinfo->freeSpace == -2L) { dinfo->freeSpace = 0L; } if ((_s_fs_size_t) dinfo->availSpace == -1L || (_s_fs_size_t) dinfo->availSpace == -2L) { dinfo->availSpace = 0L; } temp = (_fs_size_t) ~ 0; if (dinfo->totalInodes == temp) { dinfo->totalInodes = 0; dinfo->freeInodes = 0; dinfo->availInodes = 0; } if (dinfo->printFlag == DI_PRNT_OK) { if (debug > 5) { #if _siz_long_long >= 8 printf ("chk: %s total: %lld\n", dinfo->name, dinfo->totalSpace); #else printf ("chk: %s total: %ld\n", dinfo->name, dinfo->totalSpace); #endif } if (isIgnoreFSType (dinfo->fsType)) { dinfo->printFlag = DI_PRNT_IGNORE; dinfo->doPrint = (char) diopts->displayAll; if (debug > 2) { printf ("chk: ignore-fstype: %s\n", dinfo->fsType); } } if (isIgnoreSpecial (dinfo->special)) { dinfo->printFlag = DI_PRNT_IGNORE; dinfo->doPrint = (char) diopts->displayAll; if (debug > 2) { printf ("chk: ignore-special: %s\n", dinfo->special); } } if (isIgnoreFS (dinfo->fsType, dinfo->name)) { dinfo->printFlag = DI_PRNT_IGNORE; dinfo->doPrint = (char) diopts->displayAll; if (debug > 2) { printf ("chk: ignore-fs: %s\n", dinfo->name); } } /* Some systems return a -1 or -2 as an indicator. */ if (dinfo->totalSpace == 0L || (_s_fs_size_t) dinfo->totalSpace == -1L || (_s_fs_size_t) dinfo->totalSpace == -2L) { dinfo->printFlag = DI_PRNT_IGNORE; dinfo->doPrint = (char) diopts->displayAll; if (debug > 2) { printf ("chk: ignore: totalSpace <= 0: %s\n", dinfo->name); } } } /* make sure anything in the include list didn't get turned off */ checkIncludeList (dinfo, &diData->includeList); } /* for all disks */ if (hasLoop && diopts->excludeLoopback) { /* this loop sets duplicate entries to be ignored. */ for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo[i]; if (dinfo->printFlag != DI_PRNT_OK) { if (debug > 2) { printf ("dup: chk: skipping(%s):%s\n", getPrintFlagText ((int) dinfo->printFlag), dinfo->name); } continue; } /* don't need to bother checking real partitions */ if (dinfo->sp_dev != 0 && dinfo->isLoopback) { __ulong sp_dev; __ulong sp_rdev; sp_dev = dinfo->sp_dev; sp_rdev = dinfo->sp_rdev; if (debug > 2) { printf ("dup: chk: i: %s dev: %ld rdev: %ld\n", dinfo->name, sp_dev, sp_rdev); } for (j = 0; j < diData->count; ++j) { diDiskInfo_t *dinfob; if (i == j) { continue; } dinfob = &diData->diskInfo [j]; if (dinfob->sp_dev != 0 && dinfob->st_dev == sp_dev) { if (debug > 2) { printf ("dup: for %s %ld: found: %s %ld\n", dinfo->name, sp_dev, dinfob->name, dinfob->st_dev); } dinfo->printFlag = DI_PRNT_IGNORE; dinfo->doPrint = (char) diopts->displayAll; if (debug > 2) { printf ("dup: chk: ignore: %s duplicate of %s\n", dinfo->name, dinfob->name); printf ("dup: j: dev: %ld rdev: %ld \n", dinfob->sp_dev, dinfob->sp_rdev); } } /* if dup */ } } /* if this is a loopback, non-real */ else { if (debug > 2) { printf ("chk: dup: not checked: %s prnt: %d dev: %ld rdev: %ld %s\n", dinfo->name, dinfo->printFlag, dinfo->sp_dev, dinfo->sp_rdev, dinfo->fsType); } } } /* for each disk */ } /* if the duplicate loopback mounts are to be excluded */ } extern void checkDiskQuotas (diData_t *diData) { int i; Uid_t uid; Gid_t gid; diQuota_t diqinfo; _fs_size_t tsize; uid = 0; gid = 0; #if _has_std_quotas uid = geteuid (); gid = getegid (); #endif for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo[i]; if (! dinfo->doPrint) { continue; } diqinfo.special = dinfo->special; diqinfo.name = dinfo->name; diqinfo.type = dinfo->fsType; diqinfo.uid = uid; diqinfo.gid = gid; diquota (&diqinfo); if (debug > 2) { printf ("quota: %s limit: %lld\n", dinfo->name, diqinfo.limit); printf ("quota: tot: %lld\n", dinfo->totalSpace); printf ("quota: %s used: %lld\n", dinfo->name, diqinfo.used); printf ("quota: avail: %lld\n", dinfo->availSpace); } if (diqinfo.limit != 0 && diqinfo.limit < dinfo->totalSpace) { dinfo->totalSpace = diqinfo.limit; tsize = diqinfo.limit - diqinfo.used; if ((_s_fs_size_t) tsize < 0) { tsize = 0; } if (tsize < dinfo->availSpace) { dinfo->availSpace = tsize; dinfo->freeSpace = tsize; if (debug > 2) { printf ("quota: using quota for: total free avail\n"); } } else if (tsize > dinfo->availSpace && tsize < dinfo->freeSpace) { dinfo->freeSpace = tsize; if (debug > 2) { printf ("quota: using quota for: total free\n"); } } else { if (debug > 2) { printf ("quota: using quota for: total\n"); } } } if (diqinfo.ilimit != 0 && diqinfo.ilimit < dinfo->totalInodes) { dinfo->totalInodes = diqinfo.ilimit; tsize = diqinfo.ilimit - diqinfo.iused; if ((_s_fs_size_t) tsize < 0) { tsize = 0; } if (tsize < dinfo->availInodes) { dinfo->availInodes = tsize; dinfo->freeInodes = tsize; if (debug > 2) { printf ("quota: using quota for inodes: total free avail\n"); } } else if (tsize > dinfo->availInodes && tsize < dinfo->freeInodes) { dinfo->freeInodes = tsize; if (debug > 2) { printf ("quota: using quota for inodes: total free\n"); } } else { if (debug > 2) { printf ("quota: using quota for inodes: total\n"); } } } } return; } /* * preCheckDiskInfo * * checks for ignore/include list; check for remote filesystems * and local only flag set. * checks for zones (Solaris) * */ extern void preCheckDiskInfo (diData_t *diData) { int i; diOptions_t *diopts; int hasLoop; hasLoop = FALSE; diopts = &diData->options; for (i = 0; i < diData->count; ++i) { diDiskInfo_t *dinfo; dinfo = &diData->diskInfo[i]; dinfo->sortIndex[0] = (unsigned int) i; dinfo->sortIndex[1] = (unsigned int) i; if (debug > 4) { printf ("## prechk:%s:\n", dinfo->name); } #if _lib_zone_list && _lib_getzoneid && _lib_zone_getattr checkZone (dinfo, &diData->zoneInfo, diopts->displayAll); #endif if (di_isPooledFs (dinfo)) { diData->haspooledfs = TRUE; } if (dinfo->printFlag == DI_PRNT_OK) { /* don't bother w/this check is all flag is set. */ if (! diopts->displayAll) { di_testRemoteDisk (dinfo); if (dinfo->isLocal == FALSE && diopts->localOnly) { dinfo->printFlag = DI_PRNT_IGNORE; if (debug > 2) { printf ("prechk: ignore: remote disk; local flag set: %s\n", dinfo->name); } } } } if (dinfo->printFlag == DI_PRNT_OK || dinfo->printFlag == DI_PRNT_IGNORE) { /* do these checks to override the all flag */ checkIgnoreList (dinfo, &diData->ignoreList); checkIncludeList (dinfo, &diData->includeList); } } /* for all disks */ } static void checkIgnoreList (diDiskInfo_t *diskInfo, iList_t *ignoreList) { char *ptr; int i; /* if the file system type is in the ignore list, skip it */ if (ignoreList->count > 0) { for (i = 0; i < ignoreList->count; ++i) { ptr = ignoreList->list [i]; if (debug > 2) { printf ("chkign: test: fstype %s/%s : %s\n", ptr, diskInfo->fsType, diskInfo->name); } if (strcmp (ptr, diskInfo->fsType) == 0 || (strcmp (ptr, "fuse") == 0 && strncmp ("fuse", diskInfo->fsType, (Size_t) 4) == 0)) { diskInfo->printFlag = DI_PRNT_EXCLUDE; diskInfo->doPrint = FALSE; if (debug > 2) { printf ("chkign: ignore: fstype %s match: %s\n", ptr, diskInfo->name); } break; } } } /* if an ignore list was specified */ } static void checkIncludeList (diDiskInfo_t *diskInfo, iList_t *includeList) { char *ptr; int i; /* if the file system type is not in the include list, skip it */ if (includeList->count > 0) { for (i = 0; i < includeList->count; ++i) { ptr = includeList->list [i]; if (debug > 2) { printf ("chkinc: test: fstype %s/%s : %s\n", ptr, diskInfo->fsType, diskInfo->name); } if (strcmp (ptr, diskInfo->fsType) == 0 || (strcmp (ptr, "fuse") == 0 && strncmp ("fuse", diskInfo->fsType, (Size_t) 4) == 0)) { diskInfo->printFlag = DI_PRNT_OK; diskInfo->doPrint = TRUE; if (debug > 2) { printf ("chkinc:include:fstype %s match: %s\n", ptr, diskInfo->name); } break; } else { diskInfo->printFlag = DI_PRNT_EXCLUDE; diskInfo->doPrint = FALSE; if (debug > 2) { printf ("chkinc:!include:fstype %s no match: %s\n", ptr, diskInfo->name); } } } } /* if an include list was specified */ } #if _lib_zone_list && _lib_getzoneid && _lib_zone_getattr static void checkZone (diDiskInfo_t *diskInfo, zoneInfo_t *zoneInfo, unsigned int allFlag) { int i; int idx = { -1 }; if (strcmp (zoneInfo->zoneDisplay, "all") == 0 && zoneInfo->uid == 0) { return; } for (i = 0; i < (int) zoneInfo->zoneCount; ++i) { /* find the zone the filesystem is in, if non-global */ if (debug > 5) { printf (" checkZone:%s:compare:%d:%s:\n", diskInfo->name, zoneInfo->zones[i].rootpathlen, zoneInfo->zones[i].rootpath); } if (strncmp (zoneInfo->zones[i].rootpath, diskInfo->name, zoneInfo->zones[i].rootpathlen) == 0) { if (debug > 4) { printf (" checkZone:%s:found zone:%s:\n", diskInfo->name, zoneInfo->zones[i].name); } idx = i; break; } if (idx == -1) { idx = zoneInfo->globalIdx; } } /* no root access, ignore any zones */ /* that don't match our zone id */ /* this will override any ignore flags */ /* already set */ if (zoneInfo->uid != 0) { if (debug > 5) { printf (" checkZone:uid non-zero:chk zone:%d:%d:\n", (int) zoneInfo->myzoneid, (int) zoneInfo->zones[idx].zoneid); } if (zoneInfo->myzoneid != zoneInfo->zones[idx].zoneid) { if (debug > 4) { printf (" checkZone:not root, not zone:%d:%d:outofzone:\n", (int) zoneInfo->myzoneid, (int) zoneInfo->zones[idx].zoneid); } diskInfo->printFlag = DI_PRNT_OUTOFZONE; } } if (debug > 5) { printf (" checkZone:chk name:%s:%s:\n", zoneInfo->zoneDisplay, zoneInfo->zones[idx].name); } /* not the zone we want. ignore */ if (! allFlag && diskInfo->printFlag == DI_PRNT_OK && strcmp (zoneInfo->zoneDisplay, "all") != 0 && strcmp (zoneInfo->zoneDisplay, zoneInfo->zones[idx].name) != 0) { if (debug > 4) { printf (" checkZone:wrong zone:ignore:\n"); } diskInfo->printFlag = DI_PRNT_IGNORE; } /* if displaying a non-global zone, */ /* don't display loopback filesystems */ if (! allFlag && diskInfo->printFlag == DI_PRNT_OK && strcmp (zoneInfo->zoneDisplay, "global") != 0 && diskInfo->isLoopback) { if (debug > 4) { printf (" checkZone:non-global/lofs:ignore:\n"); } diskInfo->printFlag = DI_PRNT_IGNORE; } return; } #endif extern void initLocale (void) { #if _enable_nls const char *localeptr; #endif #if _lib_setlocale && defined (LC_ALL) setlocale (LC_ALL, ""); #endif #if _enable_nls if ((localeptr = getenv ("DI_LOCALE_DIR")) == (char *) NULL) { localeptr = DI_LOCALE_DIR; } bindtextdomain ("di", localeptr); textdomain ("di"); #endif } extern void initZones (diData_t *diData) { #if _lib_zone_list && _lib_getzoneid && _lib_zone_getattr diData->zoneInfo.uid = geteuid (); #endif diData->zoneInfo.zoneDisplay [0] = '\0'; diData->zoneInfo.zoneCount = 0; diData->zoneInfo.zones = (zoneSummary_t *) NULL; #if _lib_zone_list && _lib_getzoneid && _lib_zone_getattr { int i; zoneid_t *zids = (zoneid_t *) NULL; zoneInfo_t *zi; zi = &diData->zoneInfo; zi->myzoneid = getzoneid (); if (zone_list (zids, &zi->zoneCount) == 0) { if (zi->zoneCount > 0) { zids = malloc (sizeof (zoneid_t) * zi->zoneCount); if (zids == (zoneid_t *) NULL) { fprintf (stderr, "malloc failed in main() (1). errno %d\n", errno); diData->options.exitFlag = DI_EXIT_FAIL; return; } zone_list (zids, &zi->zoneCount); zi->zones = malloc (sizeof (zoneSummary_t) * zi->zoneCount); if (zi->zones == (zoneSummary_t *) NULL) { fprintf (stderr, "malloc failed in main() (2). errno %d\n", errno); diData->options.exitFlag = DI_EXIT_FAIL; return; } } } zi->globalIdx = 0; for (i = 0; i < (int) zi->zoneCount; ++i) { int len; zi->zones[i].zoneid = zids[i]; len = zone_getattr (zids[i], ZONE_ATTR_ROOT, zi->zones[i].rootpath, MAXPATHLEN); if (len >= 0) { zi->zones[i].rootpathlen = (Size_t) len; strncat (zi->zones[i].rootpath, "/", MAXPATHLEN); if (zi->zones[i].zoneid == 0) { zi->globalIdx = i; } len = zone_getattr (zids[i], ZONE_ATTR_NAME, zi->zones[i].name, ZONENAME_MAX); if (*zi->zoneDisplay == '\0' && zi->myzoneid == zi->zones[i].zoneid) { strncpy (zi->zoneDisplay, zi->zones[i].name, MAXPATHLEN); } if (debug > 4) { printf ("zone:%d:%s:%s:\n", (int) zi->zones[i].zoneid, zi->zones[i].name, zi->zones[i].rootpath); } } } free ((void *) zids); } if (debug > 4) { printf ("zone:my:%d:%s:glob:%d:\n", (int) diData->zoneInfo.myzoneid, diData->zoneInfo.zoneDisplay, diData->zoneInfo.globalIdx); } #endif } static int isIgnoreSpecial (const char *special) { static char *appletimemachine = "com.apple.TimeMachine."; /* solaris: swap */ /* linux: cgroup, tmpfs */ if (strncmp (special, appletimemachine, strlen(appletimemachine)) == 0 || strcmp (special, "tmpfs") == 0 || strcmp (special, "cgroup") == 0 || strcmp (special, "swap") == 0) { return TRUE; } return FALSE; } static int isIgnoreFS (const char *fstype, const char *name) { static char *applesystem = "/System/"; if (strcmp (fstype, "apfs") == 0 && strncmp (name, applesystem, strlen(applesystem)) == 0) { return TRUE; } return FALSE; } static int isIgnoreFSType (const char *fstype) { if (strcmp (fstype, "rootfs") == 0 || strcmp (fstype, "procfs") == 0 || strcmp (fstype, "ptyfs") == 0 || strcmp (fstype, "kernfs") == 0 || strcmp (fstype, "devfs") == 0 || strcmp (fstype, "devtmpfs") == 0) { return TRUE; } return FALSE; } #if _lib_realpath && _define_S_ISLNK && _lib_lstat static int checkForUUID (const char *spec) { /* * /dev/mapper/luks-828fc648-9f30-43d8-a0b1-f7196a2edb66 * /dev/disk/by-uuid/cfbbd7b3-b37a-4587-a711-58fd36b2cac6 * 1 2 3 4 * 01234567890123456789012345678901234567890 * cfbbd7b3-b37a-4587-a711-58fd36b2cac6 */ Size_t len; len = strlen (spec); if (len > 36) { Size_t offset; offset = len - 36; if (*(spec + offset + 8) == '-' && *(spec + offset + 13) == '-' && *(spec + offset + 18) == '-' && *(spec + offset + 23) == '-' && strspn (spec + offset, "-1234567890abcdef") == 36) { return TRUE; } } return FALSE; } #endif /* have _lib_realpath, etc. */ di-4.52/C/di.h0000644000175000017500000002475214421556642011116 0ustar bllbll#ifndef DI_INC_DI_H #define DI_INC_DI_H /* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" /*****************************************************/ #include #if _hdr_fcntl \ && ! defined (DI_INC_FCNTL_H) /* xenix */ # define DI_INC_FCNTL_H # include #endif #if _sys_file # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _hdr_limits # include /* PATH_MAX */ #endif #if _sys_param # include /* MAXPATHLEN */ #endif #if _hdr_zone # include #endif #if ! defined (O_NOCTTY) # define O_NOCTTY 0 #endif #if ! defined (MAXPATHLEN) # if defined (_POSIX_PATH_MAX) # define MAXPATHLEN _POSIX_PATH_MAX # else # if defined (PATH_MAX) # define MAXPATHLEN PATH_MAX # endif # if defined (LPNMAX) # define MAXPATHLEN LPNMAX # endif # endif #endif #if ! defined (MAXPATHLEN) # define MAXPATHLEN 255 #endif #if _sys_fstyp /* HP-UX, Solaris */ # include /* FSTYPSZ */ # if defined (FSTYPSZ) # define DI_TYPE_LEN FSTYPSZ # endif #endif #if _sys_mount \ && ! defined (DI_INC_SYS_MOUNT) /* NetBSD */ # define DI_INC_SYS_MOUNT 1 # include /* MFSNAMELEN */ # if ! defined (DI_TYPE_LEN) && defined (MFSNAMELEN) # define DI_TYPE_LEN MFSNAMELEN # endif #endif #if _sys_vfstab /* ??? */ # include # if ! defined (DI_TYPE_LEN) && defined (FSTYPSZ) # define DI_TYPE_LEN FSTYPSZ # endif #endif #if ! defined (DI_TYPE_LEN) # define DI_TYPE_LEN 65 #endif #if ! _lib_memcpy && ! _define_memcpy # if ! _lib_bcopy && ! _define_bcopy #error No_memcpy/bcopy_available. # else # define memcpy(dst, src, cnt) (bcopy((src), (dst), (cnt)), dst) # endif #endif #if ! _lib_memset && ! _define_memset # if ! _lib_bzero && ! _define_bzero #error No_memset/bzero_available. # else # define memset(s,c,n) (bzero ((s), (n)), s) # endif #endif #define DI_NAME_LEN MAXPATHLEN #define DI_SPEC_NAME_LEN MAXPATHLEN #define DI_OPT_LEN MAXPATHLEN #define DI_MNT_TIME_LEN 24 #if _siz_long_long >= 4 typedef unsigned long long _fs_size_t; typedef long long _s_fs_size_t; # define DI_LL "ll" # define DI_LLu "llu" #else typedef unsigned long _fs_size_t; typedef long _s_fs_size_t; # define DI_LL "l" # define DI_LLu "lu" #endif #if _siz_long_double >= 8 && _printf_long_double typedef long double _print_size_t; # define DI_Lf "Lf" #else typedef double _print_size_t; # define DI_Lf "f" #endif typedef unsigned long __ulong; #if ! defined (TRUE) # define TRUE 1 #endif #if ! defined (FALSE) # define FALSE 0 #endif #define DI_PRNT_IGNORE 0 #define DI_PRNT_OK 1 #define DI_PRNT_BAD 2 #define DI_PRNT_OUTOFZONE 3 #define DI_PRNT_EXCLUDE 4 #define DI_PRNT_FORCE 5 #define DI_PRNT_SKIP 6 #define DI_MAIN_SORT_IDX 0 #define DI_TOT_SORT_IDX 1 typedef struct { unsigned int sortIndex [2]; _fs_size_t totalSpace; _fs_size_t freeSpace; _fs_size_t availSpace; _fs_size_t totalInodes; _fs_size_t freeInodes; _fs_size_t availInodes; __ulong st_dev; /* disk device number */ __ulong sp_dev; /* special device number */ __ulong sp_rdev; /* special rdev # */ char doPrint; /* do we want to print */ /* this entry? */ char printFlag; /* print flags */ char isLocal; /* is this mount point */ /* local? */ char isReadOnly; /* is this mount point */ /* read-only? */ char isLoopback; /* lofs or none fs type? */ char name [DI_NAME_LEN + 1]; /* mount point */ char special [DI_SPEC_NAME_LEN + 1]; /* special device name */ char fsType [DI_TYPE_LEN + 1]; /* type of file system */ char options [DI_OPT_LEN + 1]; char mountTime [DI_MNT_TIME_LEN + 1]; } diDiskInfo_t; typedef struct { char *special; char *name; char *type; Uid_t uid; Gid_t gid; _fs_size_t blockSize; _fs_size_t limit; _fs_size_t used; _fs_size_t ilimit; _fs_size_t iused; } diQuota_t; typedef struct { int count; char **list; } iList_t; #if ! _lib_zone_list # define zoneid_t int # define ZONENAME_MAX 65 #endif typedef struct { zoneid_t zoneid; char name [ZONENAME_MAX + 1]; char rootpath [MAXPATHLEN + 1]; Size_t rootpathlen; } zoneSummary_t; typedef struct { Uid_t uid; zoneid_t myzoneid; zoneSummary_t *zones; Uint_t zoneCount; char zoneDisplay [MAXPATHLEN + 1]; int globalIdx; } zoneInfo_t; #define DI_SORT_MAX 10 /* order from best to worst */ #define DI_EXIT_NORM 0 #define DI_EXIT_OK 1 #define DI_EXIT_WARN 2 #define DI_EXIT_FAIL 3 typedef struct { const char *formatString; _print_size_t dispBlockSize; _print_size_t baseDispSize; unsigned int baseDispIdx; char sortType [DI_SORT_MAX + 1]; unsigned int posix_compat; unsigned int quota_check; unsigned int csv_output; unsigned int csv_tabs; unsigned int excludeLoopback; unsigned int json_output; unsigned int printTotals; unsigned int printDebugHeader; unsigned int printHeader; unsigned int displayAll; unsigned int localOnly; unsigned int dontResolveSymlink; unsigned int exitFlag; int errorCount; } diOptions_t; typedef struct { Size_t inodeWidth; Size_t maxMntTimeString; Size_t maxMountString; Size_t maxOptString; Size_t maxSpecialString; Size_t maxTypeString; Size_t width; const char *dispBlockLabel; char blockFormat [25]; char blockFormatNR [25]; /* no radix */ char inodeFormat [25]; char inodeLabelFormat [25]; char mountFormat [25]; char mTimeFormat [25]; char optFormat [25]; char specialFormat [25]; char typeFormat [25]; } diOutput_t; typedef struct { int count; int haspooledfs; int disppooledfs; int totsorted; diOptions_t options; diOutput_t output; diDiskInfo_t *diskInfo; iList_t ignoreList; iList_t includeList; zoneInfo_t zoneInfo; } diData_t; # if defined (__cplusplus) || defined (c_plusplus) extern "C" { # endif #if ! _dcl_errno extern int errno; #endif /* digetentries.c */ extern int di_getDiskEntries (diDiskInfo_t **, int *); /* digetinfo.c */ extern void di_getDiskInfo (diDiskInfo_t **, int *); /* diquota.c */ extern void diquota (diQuota_t *); /* strdup.c */ # if ! _lib_strdup extern char *strdup (const char *); # endif /* strstr.c */ # if ! _lib_strstr extern char *strstr (const char *, const char *); # endif /* trimchar.c */ extern void trimChar (char *, int); /* realloc.c */ extern _pvoid di_realloc (_pvoid, Size_t); /* didiskutil.c */ extern void di_initDiskInfo (diDiskInfo_t *); extern void di_saveBlockSizes (diDiskInfo_t *, _fs_size_t, _fs_size_t, _fs_size_t, _fs_size_t); extern void di_saveInodeSizes (diDiskInfo_t *, _fs_size_t, _fs_size_t, _fs_size_t); #if _lib_getmntent \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_mntctl \ && ! _class_os__Volumes extern char *chkMountOptions (const char *, const char *); #endif extern void convertMountOptions (unsigned long, diDiskInfo_t *); extern void convertNFSMountOptions (long, long, long, diDiskInfo_t *); extern void di_testRemoteDisk (diDiskInfo_t *); extern int di_isPooledFs (diDiskInfo_t *); extern int di_isLoopbackFs (diDiskInfo_t *); extern Size_t di_mungePoolName (char *); # if defined (__cplusplus) || defined (c_plusplus) } # endif /* macro for gettext() */ #ifndef DI_GT # if _enable_nls # define DI_GT(args) gettext(args) # else # define DI_GT(args) (args) # endif #endif # if _lib_sys_dollar_device_scan && _lib_sys_dollar_getdviw /* Thanks to Craig Berry's VMS::Device for the VMS code. */ typedef struct { short buflen; /* Length of output buffer */ short itmcode; /* Item code */ void *buffer; /* Buffer address */ void *retlen; /* Return length address */ } VMS_ITMLST; # define DVI_IS_STRING 1 # define DVI_IS_LONGWORD 2 # define DVI_IS_QUADWORD 3 # define DVI_IS_WORD 4 # define DVI_IS_BYTE 5 # define DVI_IS_VMSDATE 6 # define DVI_IS_BITMAP 7 /* Each bit in the return value indicates something */ # define DVI_IS_ENUM 8 /* Each returned value has a name, and we ought to */ /* return the name instead of the value */ # define DVI_IS_ODD 9 /* A catchall */ # define DVI_IS_INPUT (1<<0) # define DVI_IS_OUTPUT (1<<1) # define DVI_ENT(a, b, c) {#a, DVI$_##a, b, c, DVI_IS_OUTPUT} typedef struct { char *name; /* Pointer to the item name */ int syscallValue; /* Value to use in the getDVI item list */ int bufferLen; /* Length the return va buf needs to be. (no nul */ /* terminators, so must be careful with the return */ /* values. */ int returnType; /* Type of data the item returns */ int inOut; /* Is this an input or an output item? */ } genericID_t ; /* Macro to fill in a 'traditional' item-list entry */ # define init_itemlist(ile, length, code, bufaddr, retlen_addr) \ { \ (ile)->buflen = (length); \ (ile)->itmcode = (code); \ (ile)->buffer = (bufaddr); \ (ile)->retlen = (retlen_addr) ;} # endif #endif /* DI_INC_DI_H */ di-4.52/C/tcldiskspace.c0000644000175000017500000001440614421556642013161 0ustar bllbll/* * Copyright 2016-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "configtcl.h" #include "di.h" #include "dimain.h" #include "version.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _hdr_unistd # include #endif #if _hdr_memory # include #endif #if _hdr_malloc # include #endif #if _hdr_tcl # define USE_TCL_STUBS # include #endif #if _use_mcheck # include #endif #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif #if _npt_getenv extern char *getenv _((const char *)); #endif #if defined (__cplusplus) || defined (c_plusplus) } #endif /* end of system specific includes/configurations */ #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif int Diskspace_Init _((Tcl_Interp *)); int diskspaceObjCmd _((ClientData, Tcl_Interp *, int, Tcl_Obj * const [])); static void addListToDict _((Tcl_Interp *, Tcl_Obj *, const char *, char *)); static void addStringToDict _((Tcl_Interp *, Tcl_Obj *, const char *, const char *)); static void addWideToDict _((Tcl_Interp *, Tcl_Obj *, const char *, _fs_size_t)); static char *diproc _((int, const char **, diData_t *)); #if defined (__cplusplus) || defined (c_plusplus) } #endif int Diskspace_Init (Tcl_Interp *interp) { #if _use_mcheck mcheck_pedantic (NULL); mtrace (); #endif if (! Tcl_InitStubs (interp, "8.5", 0)) { return TCL_ERROR; } Tcl_CreateObjCommand (interp, "diskspace", diskspaceObjCmd, (ClientData) NULL, NULL); Tcl_PkgProvide (interp, "diskspace", DI_VERSION); return TCL_OK; } int diskspaceObjCmd ( ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] ) { const char **argv; char *rv; const char *tptr; char *ttptr; char **dispargs; int i; diData_t diData; Tcl_Obj *dictObj; Tcl_Obj *tempDictObj; Tcl_Obj *mountKey; diDiskInfo_t *diskInfo; diDiskInfo_t *dinfo; /* using malloc here causes tcl to crash */ /* rather weird, as this is my value, not Tcl's */ argv = (const char **) ckalloc (sizeof(const char *) * (Size_t) (objc + 1)); for (i = 0; i < objc; ++i) { tptr = Tcl_GetString (objv[i]); argv[i] = tptr; } argv[objc] = NULL; rv = diproc (objc, argv, &diData); if (diData.options.exitFlag == DI_EXIT_FAIL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("malloc failure", -1)); Tcl_SetErrorCode(interp, "diskspace", NULL); ckfree (argv); return TCL_ERROR; } if (diData.options.exitFlag == DI_EXIT_WARN) { Tcl_SetObjResult(interp, Tcl_NewStringObj("invalid arguments", -1)); Tcl_SetErrorCode(interp, "diskspace", NULL); ckfree (argv); return TCL_ERROR; } if (diData.options.exitFlag == DI_EXIT_OK) { ckfree (argv); return TCL_OK; } diskInfo = diData.diskInfo; dictObj = Tcl_NewDictObj (); dispargs = (char **) malloc (sizeof(char *) * (Size_t) diData.count); if (rv != (char *) NULL) { ttptr = strtok (rv, "\n"); } else { ttptr = (char *) NULL; } for (i = 0; i < diData.count; ++i) { dinfo = &(diskInfo [diskInfo [i].sortIndex[DI_TOT_SORT_IDX]]); dispargs[i] = (char *) NULL; if (! dinfo->doPrint) { continue; } dispargs[i] = ttptr; if (rv != (char *) NULL) { ttptr = strtok (NULL, "\n"); } } for (i = 0; i < diData.count; ++i) { dinfo = &(diskInfo [diskInfo [i].sortIndex[DI_TOT_SORT_IDX]]); if (! dinfo->doPrint) { continue; } tempDictObj = Tcl_NewDictObj (); addStringToDict (interp, tempDictObj, "device", dinfo->special); addStringToDict (interp, tempDictObj, "fstype", dinfo->fsType); addWideToDict (interp, tempDictObj, "total", dinfo->totalSpace); addWideToDict (interp, tempDictObj, "free", dinfo->freeSpace); addWideToDict (interp, tempDictObj, "available", dinfo->availSpace); addWideToDict (interp, tempDictObj, "totalinodes", dinfo->totalInodes); addWideToDict (interp, tempDictObj, "freeinodes", dinfo->freeInodes); addWideToDict (interp, tempDictObj, "availableinodes", dinfo->availInodes); addStringToDict (interp, tempDictObj, "mountoptions", dinfo->options); if (dispargs[i] != (char *) NULL) { addListToDict (interp, tempDictObj, "display", dispargs[i]); } mountKey = Tcl_NewStringObj (dinfo->name, -1); Tcl_DictObjPut (interp, dictObj, mountKey, tempDictObj); } Tcl_SetObjResult(interp, dictObj); if (rv != (char *) NULL) { free (rv); } free (dispargs); cleanup (&diData); ckfree (argv); return TCL_OK; } static void addListToDict (Tcl_Interp *interp, Tcl_Obj *dict, const char *nm, char *val) { Tcl_Obj *tempObj; Tcl_Obj *tempObj1; Tcl_Obj *tempObj2; char *dptr; tempObj2 = Tcl_NewListObj (0, NULL); dptr = strtok (val, " "); /* tab character */ while (dptr != (char *) NULL) { tempObj = Tcl_NewStringObj (dptr, -1); Tcl_ListObjAppendElement (interp, tempObj2, tempObj); dptr = strtok (NULL, " "); /* tab character */ } tempObj1 = Tcl_NewStringObj (nm, -1); Tcl_DictObjPut (interp, dict, tempObj1, tempObj2); } static void addStringToDict (Tcl_Interp *interp, Tcl_Obj *dict, const char *nm, const char *val) { Tcl_Obj *tempObj1; Tcl_Obj *tempObj2; tempObj1 = Tcl_NewStringObj (nm, -1); tempObj2 = Tcl_NewStringObj (val, -1); Tcl_DictObjPut (interp, dict, tempObj1, tempObj2); } static void addWideToDict (Tcl_Interp *interp, Tcl_Obj *dict, const char *nm, _fs_size_t val) { Tcl_Obj *tempObj1; Tcl_Obj *tempObj2; Tcl_WideInt wideVal; wideVal = (Tcl_WideInt) val; tempObj1 = Tcl_NewStringObj (nm, -1); tempObj2 = Tcl_NewWideIntObj (wideVal); Tcl_DictObjPut (interp, dict, tempObj1, tempObj2); } static char * diproc (int argc, const char **argv, diData_t *diData) { char *disp; disp = dimainproc (argc, (const char * const *) argv, 1, diData); return disp; } di-4.52/C/diquota.c0000644000175000017500000005456414421556642012167 0ustar bllbll/* * Copyright 2011-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_unistd # include #endif #if _sys_param # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _hdr_errno # include #endif #if _hdr_time # include #endif #if _sys_time && _inc_conflict__hdr_time__sys_time # include #endif #if _hdr_libprop_proplib /* dragonflybsd */ # include #endif #if _hdr_quota # include #endif #if _sys_quota /* netbsd */ # include #endif #if _sys_fs_ufs_quota # include #endif #if _sys_vfs_quota /* dragonflybsd */ # include #endif #if _hdr_ufs_quota # include #endif #if _hdr_ufs_ufs_quota # include #endif #if _hdr_linux_dqblk_xfs # include #endif #if _hdr_jfs_quota # include #endif /* AIX 5.1 doesn't seem to have quotactl declared.... */ /* use their compatibility routine. */ #if ! _args_quotactl && _hdr_linux_quota \ && _inc_conflict__sys_quota__hdr_linux_quota # include #endif #if _hdr_rpc_rpc # include #endif #if _hdr_rpcsvc_rquota # include #endif #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif #if _has_std_quotas /* workaround for HPUX - quotactl not declared */ # if _lib_quotactl && _npt_quotactl extern int quotactl _((int, const char *, uid_t, void *)); # endif typedef union { int val; # if _typ_struct_dqblk struct dqblk qinfo; # endif # if _typ_struct_ufs_dqblk struct ufs_dqblk qinfo; # endif # if _typ_fs_disk_quota_t fs_disk_quota_t xfsqinfo; # endif # if _typ_struct_quotaval struct qval { struct quotaval qbval; struct quotaval qival; } qval; # endif # if _lib_vquotactl struct vqval { struct vqvalentry { _fs_size_t usage; _fs_size_t limit; } uvqval; struct vqvalentry gvqval; struct vqvalentry *vqvalptr; } vqval; # endif } qdata_t; static void di_process_quotas _((const char *, diQuota_t *, int, int, qdata_t *)); #endif #if _has_std_quotas && _lib_vquotactl static void vq_updUsage _((struct vqvalentry *, _fs_size_t)); static void vq_updLimit _((struct vqvalentry *, _fs_size_t)); static int vquotactl_send _((char *, char *, prop_dictionary_t, prop_dictionary_t *)); static int vquotactl_get _((diQuota_t *, struct vqval *)); #endif #if _has_std_quotas && _lib_quota_open static int quota_open_get _((struct quotahandle *, int, Uid_t, struct qval *)); #endif #if _has_std_quotas && ! _lib_quota_open && ! _lib_vquotactl static int quotactl_get _((diQuota_t *, int, Uid_t, qdata_t *)); #endif #if _has_std_nfs_quotas && ! _lib_quota_open static bool_t xdr_quota_get _((XDR *, struct getquota_args *)); static bool_t xdr_quota_rslt _((XDR *, struct getquota_rslt *)); static void diquota_nfs _((diQuota_t *)); #endif extern int debug; #if defined (__cplusplus) || defined (c_plusplus) } #endif #ifdef BLOCK_SIZE /* linux */ # define DI_QUOT_BLOCK_SIZE BLOCK_SIZE #else # ifdef DQBSIZE /* AIX */ # define DI_QUOT_BLOCK_SIZE DQBSIZE # else # ifdef DEV_BSIZE /* tru64, et. al. */ # define DI_QUOT_BLOCK_SIZE DEV_BSIZE # else # define DI_QUOT_BLOCK_SIZE 512 # endif # endif #endif /* rename certain structure members for portability */ /* it make the code below cleaner, but it's a bit more */ /* difficult to read it */ #if _mem_struct_dqblk_dqb_fsoftlimit # define dqb_isoftlimit dqb_fsoftlimit #endif #if _mem_struct_dqblk_dqb_fhardlimit # define dqb_ihardlimit dqb_fhardlimit #endif #if _mem_struct_dqblk_dqb_curfiles # define dqb_curinodes dqb_curfiles #endif /* dragonflybsd has a rather complicated method of getting */ /* the quota data. */ /* Since all results are returned, make sure to only iterate */ /* once. Much of this code is straight from vquota.c. */ #if _lib_vquotactl static void vq_updUsage (struct vqvalentry *entry, _fs_size_t usage) { if (usage > entry->usage) { entry->usage = usage; } } static void vq_updLimit (struct vqvalentry *entry, _fs_size_t limit) { if (entry->limit == 0 || limit < entry->limit) { entry->limit = limit; } } static int vquotactl_send (char *spec, char *cmd, prop_dictionary_t args, prop_dictionary_t *res) { prop_dictionary_t dict; struct plistref pref; int rv; int error; dict = prop_dictionary_create(); if (dict == NULL) { return FALSE; } rv = prop_dictionary_set_cstring (dict, "command", cmd); if (! rv) { prop_object_release (dict); return FALSE; } rv = prop_dictionary_set (dict, "arguments", args); if (! rv) { prop_object_release (dict); return FALSE; } error = prop_dictionary_send_syscall (dict, &pref); if (error != 0) { prop_object_release (dict); return FALSE; } error = vquotactl (spec, &pref); if (error != 0) { prop_object_release (dict); return FALSE; } error = prop_dictionary_recv_syscall(&pref, res); if (error != 0) { prop_object_release (dict); return FALSE; } prop_object_release (dict); return TRUE; } static int vquotactl_get (diQuota_t *diqinfo, struct vqval *vqval) { prop_dictionary_t args; prop_dictionary_t res; prop_array_t reslist; prop_object_iterator_t iter; prop_dictionary_t item; int rv; int urv; int grv; Uid_t tuid; Uid_t tgid; _fs_size_t space; _fs_size_t limit; args = prop_dictionary_create(); if (args == NULL) { return errno; } res = prop_dictionary_create(); if (res == NULL) { return errno; } rv = vquotactl_send (diqinfo->name, "get usage all", args, &res); if (! rv) { prop_object_release (args); prop_object_release (res); return -4; } reslist = prop_dictionary_get (res, "returned data"); if (reslist == NULL) { prop_object_release (args); prop_object_release (res); return errno; } iter = prop_array_iterator (reslist); if (iter == NULL) { prop_object_release (args); prop_object_release (res); return errno; } vqval->uvqval.usage = 0; vqval->uvqval.limit = 0; vqval->gvqval.usage = 0; vqval->gvqval.limit = 0; while ((item = prop_object_iterator_next(iter)) != NULL) { rv = prop_dictionary_get_uint64 (item, "limit", &limit); if (rv && limit != 0) { rv = prop_dictionary_get_uint64 (item, "space used", &space); urv = prop_dictionary_get_uint32 (item, "uid", &tuid); grv = prop_dictionary_get_uint32 (item, "gid", &tgid); if (urv && tuid == diqinfo->uid) { vq_updUsage (&(vqval->uvqval), space); vq_updLimit (&(vqval->uvqval), limit); } else if (grv && tgid == diqinfo->gid) { vq_updUsage (&(vqval->gvqval), space); vq_updLimit (&(vqval->gvqval), limit); } else if (! urv && ! grv) { vq_updUsage (&(vqval->uvqval), space); vq_updLimit (&(vqval->uvqval), limit); vq_updUsage (&(vqval->gvqval), space); vq_updLimit (&(vqval->gvqval), limit); } } } prop_object_iterator_release (iter); prop_object_release (args); prop_object_release (res); return 0; } #endif /* _lib_vquotactl */ #if _lib_quota_open static int quota_open_get (struct quotahandle *qh, int idtype, Uid_t id, struct qval *qval) { struct quotakey qkey; int rc; rc = -3; if (qh != (struct quotahandle *) NULL) { memset (&qkey, 0, sizeof (struct quotakey)); qkey.qk_idtype = idtype; qkey.qk_id = (id_t) id; qkey.qk_objtype = QUOTA_OBJTYPE_BLOCKS; rc = quota_get (qh, &qkey, &(qval->qbval)); if (rc == 0) { qkey.qk_objtype = QUOTA_OBJTYPE_FILES; rc = quota_get (qh, &qkey, &(qval->qival)); } } return rc; } #endif #if _has_std_quotas && ! _lib_quota_open && ! _lib_vquotactl static int quotactl_get (diQuota_t *diqinfo, int cmd, Uid_t id, qdata_t *qdata) { int rc; rc = -4; # if defined (__FreeBSD__) && __FreeBSD__ == 5 /* quotactl on devfs fs panics the system (FreeBSD 5.1) */ if (strcmp (diqinfo->type, "ufs") != 0) { return -4; } # endif if (debug > 5) { printf ("quota: quotactl on %s (%d %d)\n", diqinfo->name, _quotactl_pos_1, _quotactl_pos_2); } /* AIX 7 has quotactl position 1 */ # if _lib_quotactl && _quotactl_pos_1 rc = quotactl (diqinfo->name, cmd, (int) id, (caddr_t) &(qdata->qinfo)); # endif # if _lib_quotactl && ! _quotactl_pos_1 && (_quotactl_pos_2 || defined(_AIX)) # if defined(_AIX) /* AIX has linux compatibility routine, but needs name rather than special */ rc = quotactl (cmd, diqinfo->name, (int) id, (caddr_t) &(qdata->qinfo)); # else rc = quotactl (cmd, (_c_arg_2_quotactl) diqinfo->special, (int) id, (caddr_t) &(qdata->qinfo)); # endif # endif # if _has_std_quotas && _sys_fs_ufs_quota && ! _lib_vquotactl /* Solaris */ { int fd; struct quotctl qop; char tname [DI_NAME_LEN + 1]; qop.op = Q_GETQUOTA; qop.uid = id; qop.addr = (caddr_t) &(qdata->qinfo); strncpy (tname, diqinfo->name, DI_NAME_LEN); strncat (tname, "/quotas", DI_NAME_LEN); fd = open (tname, O_RDONLY | O_NOCTTY); if (fd >= 0) { rc = ioctl (fd, Q_QUOTACTL, &qop); close (fd); } else { rc = fd; } } # endif /* _sys_fs_ufs_quota */ return rc; } #endif /* ! _lib_quota_open */ void diquota (diQuota_t *diqinfo) { int rc; int xfsflag; #if _has_std_quotas qdata_t qdata; #endif #if _lib_quota_open struct quotahandle *qh; #endif #if _has_std_quotas && ! _lib_quota_open && ! _lib_vquotactl int ucmd = 0; int gcmd = 0; #endif if (debug > 5) { printf ("quota: diquota\n"); } rc = -1; xfsflag = FALSE; diqinfo->limit = 0; diqinfo->used = 0; diqinfo->ilimit = 0; diqinfo->iused = 0; #if _lib_vquotactl rc = vquotactl_get (diqinfo, &qdata.vqval); qdata.vqval.vqvalptr = &qdata.vqval.uvqval; #endif #if _lib_quota_open qh = quota_open (diqinfo->name); rc = quota_open_get (qh, QUOTA_IDTYPE_USER, diqinfo->uid, &qdata.qval); #endif #if ! _lib_quota_open if (strncmp (diqinfo->type, "nfs", (Size_t) 3) == 0 && strcmp (diqinfo->type, "nfsd") != 0) { # if _has_std_nfs_quotas diquota_nfs (diqinfo); # endif return; } #endif #if _has_std_quotas && ! _lib_quota_open && ! _lib_vquotactl if (strcmp (diqinfo->type, "xfs") == 0) { # if _hdr_linux_dqblk_xfs ucmd = QCMD (Q_XGETQUOTA, USRQUOTA); gcmd = QCMD (Q_XGETQUOTA, GRPQUOTA); xfsflag = TRUE; # endif ; } else { # if _define_QCMD ucmd = QCMD (Q_GETQUOTA, USRQUOTA); gcmd = QCMD (Q_GETQUOTA, GRPQUOTA); # else /* hp-ux doesn't have QCMD */ ucmd = Q_GETQUOTA; gcmd = Q_GETQUOTA; # endif } rc = quotactl_get (diqinfo, ucmd, diqinfo->uid, &qdata); #endif /* _has_std_quotas && ! _lib_quota_open && ! _lib_vquotactl */ #if _has_std_quotas di_process_quotas ("usr", diqinfo, rc, xfsflag, &qdata); #if _lib_vquotactl qdata.vqval.vqvalptr = &qdata.vqval.gvqval; #endif # if _lib_quota_open rc = quota_open_get (qh, QUOTA_IDTYPE_GROUP, diqinfo->uid, &qdata.qval); # endif # if ! _lib_quota_open && ! _lib_vquotactl # ifdef GRPQUOTA if (rc == 0 || errno != ESRCH) { rc = quotactl_get (diqinfo, gcmd, diqinfo->gid, &qdata); } # endif /* ifdef GRPQUOTA */ # endif /* ! _lib_quota_open && ! _lib_vquotactl */ # if _lib_quota_open if (qh != (struct quotahandle *) NULL) { quota_close (qh); } # endif # if defined(GRPQUOTA) || _lib_quota_open || _lib_vquotactl di_process_quotas ("grp", diqinfo, rc, xfsflag, &qdata); # endif #endif /* _has_std_quotas */ } #if _has_std_nfs_quotas && ! _lib_quota_open #ifdef RQ_PATHLEN # define DI_RQ_PATHLEN RQ_PATHLEN #else # define DI_RQ_PATHLEN 1024 #endif static bool_t xdr_quota_get (XDR *xp, struct getquota_args *args) { if (debug > 5) { printf ("quota: xdr_quota_get\n"); } if (! xdr_string (xp, &args->gqa_pathp, DI_RQ_PATHLEN)) { return 0; } if (! xdr_gqa_uid (xp, &args->gqa_uid)) { return 0; } return 1; } static bool_t xdr_quota_rslt (XDR *xp, struct getquota_rslt *rslt) { int quotastat; struct rquota *rptr; if (debug > 5) { printf ("quota: xdr_quota_rslt\n"); } if (! xdr_int (xp, "astat)) { return 0; } # if _mem_struct_getquota_rslt_gqr_status rslt->gqr_status = quotastat; # else # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wsign-conversion" rslt->status = (gqr_status) quotastat; # pragma clang diagnostic pop # endif # if _mem_struct_getquota_rslt_gqr_rquota rptr = &rslt->gqr_rquota; # else rptr = &rslt->getquota_rslt_u.gqr_rquota; # endif if (! xdr_int (xp, &rptr->rq_bsize)) { return 0; } if (! xdr_bool (xp, &rptr->rq_active)) { return 0; } if (! xdr_rq_bhardlimit (xp, &rptr->rq_bhardlimit)) { return 0; } if (! xdr_rq_bsoftlimit (xp, &rptr->rq_bsoftlimit)) { return 0; } if (! xdr_rq_curblocks (xp, &rptr->rq_curblocks)) { return 0; } if (! xdr_rq_fhardlimit (xp, &rptr->rq_fhardlimit)) { return 0; } if (! xdr_rq_fsoftlimit (xp, &rptr->rq_fsoftlimit)) { return 0; } if (! xdr_rq_curfiles (xp, &rptr->rq_curfiles)) { return 0; } return (1); } static void diquota_nfs (diQuota_t *diqinfo) { CLIENT *rqclnt; enum clnt_stat clnt_stat; struct timeval timeout; char host [DI_SPEC_NAME_LEN + 1]; char *ptr; char *path; struct getquota_args args; struct getquota_rslt result; struct rquota *rptr; int quotastat; _fs_size_t tsize; if (debug > 5) { printf ("quota: diquota_nfs\n"); } timeout.tv_sec = 2; timeout.tv_usec = 0; strncpy (host, diqinfo->special, DI_SPEC_NAME_LEN); path = host; ptr = strchr (host, ':'); if (ptr != (char *) NULL) { *ptr = '\0'; path = ptr + 1; } if (debug > 2) { printf ("quota: nfs: host: %s path: %s\n", host, path); } args.gqa_pathp = path; args.gqa_uid = (int) diqinfo->uid; rqclnt = clnt_create (host, (unsigned long) RQUOTAPROG, (unsigned long) RQUOTAVERS, "udp"); if (rqclnt == (CLIENT *) NULL) { if (debug > 2) { printf ("quota: nfs: create failed %d\n", errno); } return; } rqclnt->cl_auth = authunix_create_default(); clnt_stat = clnt_call (rqclnt, (unsigned long) RQUOTAPROC_GETQUOTA, (xdrproc_t) xdr_quota_get, (caddr_t) &args, (xdrproc_t) xdr_quota_rslt, (caddr_t) &result, timeout); if (clnt_stat != RPC_SUCCESS) { if (debug > 2) { printf ("quota: nfs: not success\n"); } if (rqclnt->cl_auth) { auth_destroy (rqclnt->cl_auth); } clnt_destroy (rqclnt); return; } # if _mem_struct_getquota_rslt_gqr_status quotastat = (int) result.gqr_status; # else quotastat = (int) result.status; # endif if (quotastat == 1) { # if _mem_struct_getquota_rslt_gqr_rquota rptr = &result.gqr_rquota; # else rptr = &result.getquota_rslt_u.gqr_rquota; # endif if (debug > 2) { printf ("quota: nfs: status 1\n"); printf ("quota: nfs: rq_bsize: %d\n", rptr->rq_bsize); printf ("quota: nfs: rq_active: %d\n", rptr->rq_active); } diqinfo->limit = (_fs_size_t) rptr->rq_bhardlimit * (_fs_size_t) rptr->rq_bsize; tsize = (_fs_size_t) rptr->rq_bsoftlimit * (_fs_size_t) rptr->rq_bsize; if (tsize != 0 && tsize < diqinfo->limit) { diqinfo->limit = tsize; } if (diqinfo->limit != 0) { diqinfo->used = (_fs_size_t) rptr->rq_curblocks * (_fs_size_t) rptr->rq_bsize; } diqinfo->ilimit = rptr->rq_fhardlimit; tsize = rptr->rq_fsoftlimit; if (tsize != 0 && tsize < diqinfo->ilimit) { diqinfo->ilimit = tsize; } if (diqinfo->ilimit != 0) { diqinfo->iused = rptr->rq_curfiles; } } if (rqclnt->cl_auth) { auth_destroy (rqclnt->cl_auth); } clnt_destroy (rqclnt); } #endif /* have std nfs quotas */ #if _has_std_quotas static void di_process_quotas (const char *tag, diQuota_t *diqinfo, int rc, int xfsflag, qdata_t *qdata) { _fs_size_t quotBlockSize = { DI_QUOT_BLOCK_SIZE }; _fs_size_t spaceBlockSize = { DI_QUOT_BLOCK_SIZE }; _fs_size_t tsize; _fs_size_t tlimit; if (debug > 5) { printf ("quota: di_process_quotas\n"); } # if _lib_vquotactl quotBlockSize = 1; spaceBlockSize = 1; # endif # if _mem_struct_dqblk_dqb_curspace spaceBlockSize = 1; # endif if (xfsflag) { quotBlockSize = 512; spaceBlockSize = 512; } if (rc == 0) { tsize = 0; tlimit = 0; if (debug > 1) { printf ("# diquota: blocksize: %lld\n", quotBlockSize); } if (xfsflag) { # if _typ_fs_disk_quota_t if (debug > 1) { printf ("# diquota: fs_disk_quota_t\n"); } tsize = qdata->xfsqinfo.d_blk_hardlimit; # endif ; } else { # if _lib_vquotactl if (debug > 1) { printf ("# diquota: vquotactl\n"); } tsize = qdata->vqval.vqvalptr->limit; # endif # if _typ_struct_quotaval if (debug > 1) { printf ("# diquota: struct quotaval\n"); } tsize = qdata->qval.qbval.qv_hardlimit; # endif # if _typ_struct_dqblk && ! _lib_vquotactl if (debug > 1) { printf ("# diquota: struct dqblk\n"); } tsize = qdata->qinfo.dqb_bhardlimit; # endif } if (debug > 2) { printf ("quota: %s %s b hard: %lld\n", tag, diqinfo->name, tsize); } if ((_s_fs_size_t) tsize > 0) { tsize *= quotBlockSize; if (tsize > 0 && (tsize < diqinfo->limit || diqinfo->limit == 0)) { if (debug > 2) { printf ("quota: using b hard: %lld (%lld)\n", tsize, quotBlockSize); } diqinfo->limit = tsize; tlimit = tsize; } } if (xfsflag) { # if _typ_fs_disk_quota_t tsize = qdata->xfsqinfo.d_blk_softlimit; # endif ; } else { # if _lib_vquotactl /* no soft limit, use hard */ tsize = qdata->vqval.vqvalptr->limit; # endif # if _typ_struct_quotaval tsize = qdata->qval.qbval.qv_softlimit; # endif # if _typ_struct_dqblk && ! _lib_vquotactl tsize = qdata->qinfo.dqb_bsoftlimit; # endif } if (debug > 2) { printf ("quota: %s %s b soft: %lld\n", tag, diqinfo->name, tsize); } if ((_s_fs_size_t) tsize > 0) { tsize *= quotBlockSize; if (tsize > 0 && (tsize < diqinfo->limit || diqinfo->limit == 0)) { if (debug > 2) { printf ("quota: using b soft: %lld (%lld)\n", tsize, quotBlockSize); } diqinfo->limit = tsize; tlimit = tsize; } } /* any quota set? */ if (tlimit == 0) { if (debug > 2) { printf ("quota: %s %s no quota\n", tag, diqinfo->name); } return; } if (debug > 1) { printf ("# diquota: space block size: %lld\n", spaceBlockSize); } tlimit = 0; if (xfsflag) { # if _typ_fs_disk_quota_t if (debug > 1) { printf ("# diquota: fs_disk_quota_t\n"); } tsize = qdata->xfsqinfo.d_bcount; # endif ; } else { # if _lib_vquotactl if (debug > 1) { printf ("# diquota: vquotactl\n"); } tsize = qdata->vqval.vqvalptr->usage; # endif # if _typ_struct_quotaval if (debug > 1) { printf ("# diquota: struct quotaval\n"); } tsize = qdata->qval.qbval.qv_usage; # endif # if _mem_struct_dqblk_dqb_curspace if (debug > 1) { printf ("# diquota: dqb_curspace\n"); } tsize = qdata->qinfo.dqb_curspace; # endif # if _mem_struct_dqblk_dqb_curblocks && ! _lib_vquotactl if (debug > 1) { printf ("# diquota: dqb_curblocks\n"); } tsize = qdata->qinfo.dqb_curblocks; # endif } tsize *= spaceBlockSize; if (tsize > diqinfo->used || diqinfo->used == 0) { diqinfo->used = tsize; } if (debug > 2) { printf ("quota: %s %s used: %lld limit: %lld\n", tag, diqinfo->name, diqinfo->used, diqinfo->limit); } # if ! _lib_vquotactl /* no inode limits */ if (xfsflag) { # if _typ_fs_disk_quota_t tsize = qdata->xfsqinfo.d_ino_hardlimit; # endif ; } else { # if _typ_struct_quotaval tsize = qdata->qval.qival.qv_hardlimit; # endif # if _typ_struct_dqblk && ! _lib_vquotactl tsize = qdata->qinfo.dqb_ihardlimit; # endif } if (tsize > 0 && (tsize < diqinfo->ilimit || diqinfo->ilimit == 0)) { diqinfo->ilimit = tsize; tlimit = tsize; } if (debug > 2) { printf ("quota: %s %s i hard: %lld\n", tag, diqinfo->name, tsize); } if (xfsflag) { # if _typ_fs_disk_quota_t tsize = qdata->xfsqinfo.d_ino_softlimit; # endif ; } else { # if _typ_struct_quotaval tsize = qdata->qval.qival.qv_softlimit; # endif # if _typ_struct_dqblk && ! _lib_vquotactl tsize = qdata->qinfo.dqb_isoftlimit; # endif } if (tsize > 0 && (tsize < diqinfo->ilimit || diqinfo->ilimit == 0)) { diqinfo->ilimit = tsize; tlimit = tsize; } if (debug > 2) { printf ("quota: %s %s i soft: %lld\n", tag, diqinfo->name, tsize); } /* any quota set? */ if (tlimit == 0) { if (debug > 2) { printf ("quota: %s %s no inode quota\n", tag, diqinfo->name); } return; } if (xfsflag) { # if _typ_fs_disk_quota_t tsize = qdata->xfsqinfo.d_icount; # endif ; } else { # if _typ_struct_quotaval tsize = qdata->qval.qival.qv_usage; # endif # if ! _lib_quota_open && ! _lib_vquotactl tsize = qdata->qinfo.dqb_curinodes; # endif } if (tsize > diqinfo->iused || diqinfo->iused == 0) { diqinfo->iused = tsize; } if (debug > 2) { printf ("quota: %s %s i used: %lld\n", tag, diqinfo->name, tsize); } # endif /* ! _lib_vquotactl */ } else { if (debug > 2) { printf ("quota: %s %s errno %d\n", tag, diqinfo->name, errno); } } } #endif /* _has_std_quotas */ di-4.52/C/strstr.c0000644000175000017500000000131714421556642012046 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #if ! _lib_strstr # include "di.h" #if _hdr_stdio # include #endif # if _hdr_stdlib # include # endif # if _hdr_string # include # endif # if _hdr_strings # include # endif char * strstr (const char *buff, const char *srch) { Size_t len; char * p; p = (char *) buff; if (srch == (char *) NULL) { return p; } len = strlen (srch); for (; (p = strchr (p, *srch)) != (char *) NULL; p++) { if (strncmp (p, srch, len) == 0) { return (p); } } return (char *) NULL; } #else extern int debug; #endif di-4.52/C/di-example.tcl0000755000175000017500000000140714421556642013075 0ustar bllbll#!/usr/bin/tclsh # # example tcl script # # To build the sharedlibrary: # make -e tcl-sh # On windows: # make -e WINAPI=T NO_PIE=yes tcl-sh # package require platform # the load wants the full path, not relative... set ext [info sharedlibextension] set lfn [file normalize [file join [file dirname [info script]] diskspace$ext]] load $lfn puts "== Basic information only" set d [diskspace -f {}] dict for {mount dline} $d { puts "$mount: $dline" } puts "== Basic information and some display data" set d [diskspace -f buvp] dict for {mount dline} $d { puts "$mount: $dline" } # dictionary is nested with the mount point as the key. set dir / if { [regexp -nocase {^win} [platform::generic]] } { set dir "C:\\" } puts "$dir total space: [dict get $d $dir total]" di-4.52/C/realloc.c0000644000175000017500000000124614421556642012127 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_memory # include #endif #if _hdr_malloc # include #endif #if _use_mcheck # include #endif /* * * portable realloc * some variants don't accept a null pointer for initial allocation. * */ _pvoid di_realloc (_pvoid ptr, Size_t size) { if (ptr == (_pvoid) NULL) { ptr = (_pvoid) malloc (size); } else { ptr = (_pvoid) realloc (ptr, size); } return ptr; } di-4.52/C/getoptn.c0000644000175000017500000007701414421556642012174 0ustar bllbll/* * Copyright 2011-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ /* * A new version of getopt() * Boolean short flags: -a -b (a, b) * With values: -c 123 -d=abcdef -ef * (-c = 123, -d = abcdef, -e = f) * Long options: --a --b --c 123 --d=abcdef * LEGACY: * Boolean short flags: -ab (a, b) * short flags: -version (-v = ersion) * MODERN: * Boolean long name: -ab (ab) * long flags: -version (-version) * */ #if defined(TEST_GETOPTN) # include "gconfig.h" #else # include "config.h" #endif #include "getoptn.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _use_mcheck # include #endif typedef struct { Size_t optionlen; int idx; } getoptn_optinfo_t; typedef struct { int style; int optidx; Size_t optcount; getoptn_opt_t *opts; getoptn_optinfo_t *optinfo; int argc; const char * const *argv; const char *arg; /* current arg we're processing */ Size_t arglen; /* and the length of it */ int hasvalue; /* does this arg have a value attached? */ Size_t argidx; /* index to the value */ Size_t optionlen; /* length of the option for this arg */ Size_t reprocess; /* -ab legacy form? must be 0 or 1 */ Size_t offset; /* reprocessing offset */ } getoptn_info_t; typedef void (*getoptn_func_bool_t) _((const char *option, void *valptr)); typedef void (*getoptn_func_value_t) _((const char *option, void *valptr, const char *value)); static int find_option (getoptn_info_t *info, const char *arg, const char *oarg, Size_t *argidx) { int i; Size_t junk; for (i = 0; i < (int) info->optcount; ++i) { if (info->optinfo[i].optionlen == 0) { info->optinfo[i].optionlen = strlen (info->opts[i].option); info->optinfo[i].idx = i; } if (strncmp (arg + info->offset, info->opts[i].option + info->reprocess, info->optinfo[i].optionlen - info->reprocess) == 0) { info->hasvalue = FALSE; /* info->argidx == 0 indicates top level of recursion */ if (info->argidx == 0) { info->optionlen = info->optinfo[i].optionlen; } if (info->style == GETOPTN_LEGACY) { if (info->arglen - info->offset > info->optionlen - info->reprocess) { if (info->opts[i].option_type == GETOPTN_BOOL) { info->reprocess = TRUE; if (info->offset == 0) { ++info->offset; } ++info->offset; if (info->offset >= info->arglen) { info->offset = 0; info->reprocess = FALSE; } } else { info->hasvalue = TRUE; } } else { info->offset = 0; info->reprocess = FALSE; } } if (info->style == GETOPTN_MODERN) { if (info->arglen > info->optionlen) { if (info->arg[info->optionlen] == '=') { info->hasvalue = TRUE; } else { continue; /* partial match */ } } } *argidx = info->optinfo[i].optionlen; if (info->opts[i].option_type == GETOPTN_ALIAS) { return find_option (info, (const char *) info->opts[i].valptr, oarg, &junk); } return i; } } info->reprocess = FALSE; info->offset = 0; return GETOPTN_NOTFOUND; } static const char * getoption_value (getoptn_info_t *info, getoptn_opt_t *opt) { const char *ptr; ptr = (char *) NULL; if (opt->option_type != GETOPTN_FUNC_VALUE && opt->value2 != (void *) NULL) { ptr = (const char *) opt->value2; return ptr; } if (info->hasvalue && info->arg[info->argidx] == '=') { ptr = &info->arg[info->argidx + 1]; } else if (info->hasvalue) { ptr = &info->arg[info->argidx]; } else if (info->optidx + 1 < info->argc) { ++info->optidx; ptr = info->argv[info->optidx]; } return ptr; } static int dooptchecks (getoptn_info_t *info, getoptn_opt_t *opt, getoptn_optinfo_t *optinfo, const char *tag, Size_t sz) { if (sz != 0 && opt->valsiz != sz) { fprintf (stderr, "%s: %s: invalid size (line %d)\n", info->argv[0], tag, optinfo->idx); return 1; } if (opt->valptr == NULL) { fprintf (stderr, "%s: %s: invalid pointer (line %d)\n", info->argv[0], tag, optinfo->idx); return 1; } return 0; } static int process_opt (getoptn_info_t *info, getoptn_opt_t *opt, getoptn_optinfo_t *optinfo) { const char *ptr; ptr = (char *) NULL; if (opt->option_type == GETOPTN_INT || opt->option_type == GETOPTN_LONG || opt->option_type == GETOPTN_SIZET || opt->option_type == GETOPTN_DOUBLE || opt->option_type == GETOPTN_STRING || opt->option_type == GETOPTN_STRPTR || opt->option_type == GETOPTN_FUNC_VALUE) { ptr = getoption_value (info, opt); if (ptr == (char *) NULL) { fprintf (stderr, "%s: %s argument missing\n", info->argv[0], info->arg); return 1; } } if (opt->option_type == GETOPTN_BOOL) { int *v; if (dooptchecks (info, opt, optinfo, "bool", sizeof(int)) != 0) { return 1; } v = (int *) opt->valptr; *v = 1 - *v; /* flip it */ } else if (opt->option_type == GETOPTN_INT) { int *v; if (dooptchecks (info, opt, optinfo, "int", sizeof(int)) != 0) { return 1; } v = (int *) opt->valptr; *v = atoi (ptr); } else if (opt->option_type == GETOPTN_LONG) { long *v; if (dooptchecks (info, opt, optinfo, "long", sizeof(long)) != 0) { return 1; } v = (long *) opt->valptr; *v = atol (ptr); } else if (opt->option_type == GETOPTN_SIZET) { Size_t *v; if (dooptchecks (info, opt, optinfo, "Size_t", sizeof(Size_t)) != 0) { return 1; } v = (Size_t *) opt->valptr; *v = (Size_t) atol (ptr); } else if (opt->option_type == GETOPTN_DOUBLE) { double *v; if (dooptchecks (info, opt, optinfo, "double", sizeof(double)) != 0) { return 1; } v = (double *) opt->valptr; *v = atof (ptr); } else if (opt->option_type == GETOPTN_STRING) { char *v; if (dooptchecks (info, opt, optinfo, "string", 0) != 0) { return 1; } v = (char *) opt->valptr; strncpy (v, ptr, opt->valsiz - 1); } else if (opt->option_type == GETOPTN_STRPTR) { const char **v; if (dooptchecks (info, opt, optinfo, "strptr", 0) != 0) { return 1; } v = (const char **) opt->valptr; *v = strdup (ptr); /* memory leak (one time) */ } else if (opt->option_type == GETOPTN_FUNC_BOOL) { getoptn_func_bool_t f; if (opt->value2 == (void *) NULL) { fprintf (stderr, "%s: %s: invalid function ptr (line %d)\n", info->argv[0], "func_bool", optinfo->idx); return 1; } f = (getoptn_func_bool_t) opt->value2; (f)(opt->option, opt->valptr); } else if (opt->option_type == GETOPTN_FUNC_VALUE) { getoptn_func_value_t f; if (opt->value2 == (void *) NULL) { fprintf (stderr, "%s: %s: invalid function ptr (line %d)\n", info->argv[0], "func_val", optinfo->idx); return 1; } f = (getoptn_func_value_t) opt->value2; (f)(opt->option, opt->valptr, ptr); } else { info->reprocess = FALSE; info->offset = 0; fprintf (stderr, "%s: unknown option type %d\n", info->argv[0], opt->option_type); return 1; } return 0; } int getoptn (int style, int argc, const char * const argv [], Size_t optcount, getoptn_opt_t opts [], int *errorCount) { int i; int rc; const char *arg; getoptn_opt_t *opt; getoptn_info_t info; info.style = style; info.argc = argc; info.argv = argv; info.optcount = optcount; info.opts = opts; info.optinfo = (getoptn_optinfo_t *) NULL; *errorCount = 0; if (optcount > 0) { info.optinfo = (getoptn_optinfo_t *) malloc (sizeof (getoptn_optinfo_t) * optcount); for (i = 0; i < (int) info.optcount; ++i) { info.optinfo[i].optionlen = 0; } } else { return 1 < argc ? 1 : -1; } for (info.optidx = 1; info.optidx < argc; info.optidx++) { arg = argv[info.optidx]; if (*arg != '-') { if (info.optinfo != (getoptn_optinfo_t *) NULL) { free (info.optinfo); } return info.optidx; } if (strcmp (arg, "--") == 0) { info.optidx++; if (info.optinfo != (getoptn_optinfo_t *) NULL) { free (info.optinfo); } return info.optidx; } info.argidx = 0; info.arg = arg; info.arglen = strlen (arg); info.reprocess = FALSE; info.offset = 0; do { i = find_option (&info, arg, arg, &info.argidx); if (opts[i].option_type == GETOPTN_IGNORE) { continue; } if (i == GETOPTN_NOTFOUND) { if (info.reprocess == FALSE) { fprintf (stderr, "%s: unknown option %s\n", argv[0], arg); ++*errorCount; } continue; } opt = &opts[i]; rc = process_opt (&info, opt, &info.optinfo[i]); if (rc) { ++*errorCount; } } while (info.reprocess); } if (info.optinfo != (getoptn_optinfo_t *) NULL) { free (info.optinfo); } return argc; } #if defined(TEST_GETOPTN) #if _hdr_math # include #endif static void process_opts (const char *arg, char *valptr) { if (strcmp (arg, "-h") == 0) { double *v; v = (double *) valptr; *v = 9.9; } return; } static void process_opts_val (const char *arg, char *valptr, char *value) { if (strcmp (arg, "-g") == 0) { double *v; v = (double *) valptr; *v = atof (value); } return; } int main (int argc, const char * const argv[]) { char tmp[40]; char s[40]; char s2[5]; char *sp; long l; double d; int i; int j; int k; int ec; int optidx; int ac; const char *av[10]; int grc = 0; int testno = 0; getoptn_opt_t opts[] = { { "-D", GETOPTN_STRING, &s, sizeof(s), (void *) "abc123" }, { "-b", GETOPTN_BOOL, &i, sizeof(i), NULL }, { "--b", GETOPTN_BOOL, &i, sizeof(i), NULL }, { "-c", GETOPTN_BOOL, &j, sizeof(j), NULL }, { "--c", GETOPTN_ALIAS, (void *) "-c", 0, NULL }, { "-bc", GETOPTN_BOOL, &k, sizeof(k), NULL }, { "-d", GETOPTN_DOUBLE, &d, sizeof(d), NULL }, { "-f1", GETOPTN_INT, &i, 8, NULL }, { "-f2", GETOPTN_LONG, &i, 2, NULL }, { "-f3", GETOPTN_LONG, &l, 12, NULL }, { "--i", GETOPTN_INT, &i, sizeof(i), NULL }, { "-i", GETOPTN_INT, &i, sizeof(i), NULL }, { "-i15",GETOPTN_INT, &j, sizeof(j), NULL }, { "-i17",GETOPTN_INT, &j, sizeof(j), NULL }, { "-l", GETOPTN_LONG, &l, sizeof(l), NULL }, { "-s", GETOPTN_STRING, &s, sizeof(s), NULL }, { "-sabcd", GETOPTN_BOOL, &i, sizeof(i), NULL }, { "-sp", GETOPTN_STRPTR, &sp, 0, NULL }, { "-p", GETOPTN_STRPTR, &sp, 0, NULL }, { "-S", GETOPTN_STRPTR, &sp, 0, (void *) "abc1234" }, { "-s2", GETOPTN_STRING, &s2, sizeof(s2), NULL }, { "-np1", GETOPTN_STRING, NULL, sizeof(s2), NULL }, { "-np2", GETOPTN_FUNC_BOOL, NULL, sizeof(s2), NULL }, { "-np3", GETOPTN_FUNC_VALUE, NULL, sizeof(s2), NULL }, { "-z1", GETOPTN_ALIAS, (void *) "--c", 0, NULL }, { "-z2", GETOPTN_ALIAS, (void *) "-z1", 0, NULL }, { "-z3", GETOPTN_ALIAS, (void *) "-z2", 0, NULL } }; /* test 1 */ ++testno; memset (s, '\0', sizeof (s)); ac = 2; sprintf (tmp, "test: %d", testno); av[0] = tmp; av[1] = "-D"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abc123") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 2 */ ++testno; i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-b"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 1 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 3 */ ++testno; i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "--b"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 1 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 4 */ ++testno; i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "--i=13"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 13 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 5 */ ++testno; i = 0; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "--i"; av[2] = "14"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 14 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 6 */ ++testno; i = 0; j = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i15"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 15 || j != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 7 */ ++testno; i = 0; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i"; av[2] = "16"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 16 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 8 */ ++testno; i = 0; j = 0; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i17"; av[2] = "5"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || j != 5 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 9 */ ++testno; i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i=17"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 17 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 10 */ ++testno; i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i7"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 7 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 11 */ ++testno; l = 0L; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-l"; av[2] = "19"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (l != 19 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 12 */ ++testno; i = 0; j = 0; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-b"; av[2] = "-c"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 1 || j != 1 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 13 */ ++testno; i = 0; j = 0; k = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-bc"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 1 || j != 1 || k != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 14 */ ++testno; i = 0; j = 0; k = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-bc"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || j != 0 || k != 1 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 15 */ ++testno; memset (s, '\0', sizeof (s)); ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s=abc"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abc") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 16 */ ++testno; d = 0.0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-d=1.2"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (fabs(d - 1.2) > 0.00001 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d: %.2g %d\n", testno, d, optidx); grc = 1; } /* test 17 */ ++testno; memset (s, '\0', sizeof (s)); i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-sabcd"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abcd") != 0 || i != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 18 */ ++testno; memset (s, '\0', sizeof (s)); ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s=abcde"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abcde") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 19 */ ++testno; memset (s, '\0', sizeof (s)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s"; av[2] = "abcdef"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abcdef") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 20 */ ++testno; sp = ""; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-sp"; av[2] = "0123"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (sp, "0123") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 21 */ ++testno; sp = ""; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-sp=01234"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (sp, "01234") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 22 */ ++testno; sp = ""; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-p012345"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (sp, "012345") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 23 */ ++testno; sp = ""; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-S"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (sp, "abc1234") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 24 */ ++testno; sp = ""; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-p=0123456"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (sp, "0123456") != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 25 */ ++testno; memset (s, '\0', sizeof (s)); i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-sabcd"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "") != 0 || i != 1 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 26 */ ++testno; i = 1; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-b"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 27 */ ++testno; i = 1; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "--b"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 28 */ ++testno; i = 1; j = 1; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-b"; av[2] = "-c"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || j != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 29 */ ++testno; i = 1; j = 1; k = 1; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-bc"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || j != 0 || k != 1 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d / i:%d j:%d k:%d optidx:%d ec:%d\n", testno, i, j, k, optidx, ec); grc = 1; } /* test 30 */ ++testno; i = 1; j = 1; k = 1; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-bc"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 1 || j != 1 || k != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d / i:%d j:%d k:%d optidx:%d ec:%d\n", testno, i, j, k, optidx, ec); grc = 1; } /* test 31 - empty value */ ++testno; i = 0; j = 0; k = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i="; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d / i:%d optidx:%d ec:%d\n", testno, i, optidx, ec); grc = 1; } /* test 32 - no value; should print error */ ++testno; i = 0; j = 0; k = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i"; av[2] = NULL; ec = 0; fprintf (stderr, "** expect argument missing\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || optidx != 2 || ec != 1) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 33 - wrong size; should print error */ ++testno; i = 0; j = 0; k = 0; l = 0L; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-f1=7"; av[2] = NULL; ec = 0; fprintf (stderr, "** expect invalid size\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || l != 0 || optidx != 2 || ec != 1) { fprintf (stderr, "fail test %d; %d %ld %d\n", testno, i, l, optidx); grc = 1; } /* test 34 - wrong size; should print error */ ++testno; i = 0; j = 0; k = 0; l = 0L; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-f2=7"; av[2] = NULL; ec = 0; fprintf (stderr, "** expect invalid size\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || l != 0 || optidx != 2 || ec != 1) { fprintf (stderr, "fail test %d; %d %ld %d\n", testno, i, l, optidx); grc = 1; } /* test 35 - wrong size; should print error */ ++testno; i = 0; j = 0; k = 0; l = 0L; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-f3=7"; av[2] = NULL; ec = 0; fprintf (stderr, "** expect invalid size\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || l != 0 || optidx != 2 || ec != 1) { fprintf (stderr, "fail test %d; %d %ld %d\n", testno, i, l, optidx); grc = 1; } /* test 36 - end of options */ ++testno; i = 0; j = 0; k = 0; l = 0L; ac = 4; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i=7"; av[2] = "--"; av[3] = "abc"; av[4] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 7 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 37 - no more options */ ++testno; i = 0; j = 0; k = 0; l = 0L; ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-i=7"; av[2] = "abc"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 7 || optidx != 2 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 38 - empty value followed by another option; returns the option */ ++testno; i = 0; j = 0; k = 0; memset (s, '\0', sizeof (s)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s"; av[2] = "-s"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "-s") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 39 - unknown options */ ++testno; i = 0; j = 0; k = 0; memset (s, '\0', sizeof (s)); ac = 5; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-b"; av[2] = "-c"; av[3] = "-s"; av[4] = "abc"; av[5] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abc") != 0 || i != 1 || j != 1 || optidx != 5 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 40 - legacy: mixed boolean + arg */ ++testno; i = 0; j = 0; k = 0; memset (s, '\0', sizeof (s)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-bcs"; av[2] = "abc"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s, "abc") != 0 || i != 1 || j != 1 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 41 */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s2"; av[2] = "abc"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "abc") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 42 - short string */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s2"; av[2] = "abcd"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "abcd") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 43 - short string */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s2"; av[2] = "abcde"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "abcd") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d: %s\n", testno, s2); grc = 1; } /* test 44 - short string */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-s2"; av[2] = "abcdef"; av[3] = NULL; ec = 0; optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "abcd") != 0 || optidx != 3 || ec != 0) { fprintf (stderr, "fail test %d: %s\n", testno, s2); grc = 1; } /* test 45 - null ptr */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-np1"; av[2] = "abcdef"; av[3] = NULL; ec = 0; fprintf (stderr, "** expect invalid pointer\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "") != 0 || ec != 1) { fprintf (stderr, "fail test %d: %s %d\n", testno, s2, optidx); grc = 1; } /* test 46 - null ptr */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-np2"; av[2] = "abcdef"; av[3] = NULL; ec = 0; fprintf (stderr, "** expect invalid pointer\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "") != 0 || ec != 1) { fprintf (stderr, "fail test %d: %s %d\n", testno, s2, optidx); grc = 1; } /* test 47 - null ptr */ ++testno; memset (s2, '\0', sizeof (s2)); ac = 3; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-np3"; av[2] = "abcdef"; av[3] = NULL; ec = 0; fprintf (stderr, "** expect invalid pointer\n"); optidx = getoptn (GETOPTN_MODERN, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (strcmp (s2, "") != 0 || ec != 1) { fprintf (stderr, "fail test %d: %s %d\n", testno, s2, optidx); grc = 1; } /* test 48 - alias chain */ ++testno; i = 0; j = 0; k = 0; memset (s2, '\0', sizeof (s2)); ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-z3"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || j != 1 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } /* test 49 - test boolean initial value */ ++testno; i = 0; ac = 2; sprintf (tmp, "test %d", testno); av[0] = tmp; av[1] = "-c"; av[2] = NULL; ec = 0; optidx = getoptn (GETOPTN_LEGACY, ac, av, sizeof (opts) / sizeof (getoptn_opt_t), opts, &ec); if (i != 0 || ec != 0) { fprintf (stderr, "fail test %d\n", testno); grc = 1; } return grc; } #endif /* TEST_GETOPTN */ di-4.52/C/digetinfo.c0000644000175000017500000003751014421556642012461 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ /********************************************************/ /* In the cases where di_getDiskEntries() does not get the volume information, di_getDiskInfo() is used to fetch the info. di_getDiskInfo () Gets the disk space used/available on the partitions we want displayed. */ /********************************************************/ #include "config.h" #include "di.h" #include "dimntopt.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _sys_param # include #endif #if _hdr_errno # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _sys_mount \ && ! defined (DI_INC_SYS_MOUNT) /* FreeBSD, OpenBSD, NetBSD, HP-UX */ # define DI_INC_SYS_MOUNT 1 # include /* statfs(); struct statfs; getfsstat() */ #endif #if _sys_statvfs /* Linux, Solaris, FreeBSD, NetBSD, HP-UX */ # include /* statvfs(); struct statvfs */ #endif #if _sys_vfs /* Linux, HP-UX, BSD 4.3 */ # include /* struct statfs */ #endif #if _sys_statfs && ! _sys_statvfs /* Linux, SysV.3 */ # include /* statfs(); struct statfs */ #endif #if _sys_fstyp /* SysV.3 */ # include /* sysfs() */ #endif #if _hdr_windows /* windows */ # include /* GetDiskFreeSpace(); GetVolumeInformation() */ #endif /********************************************************/ #if defined (__cplusplus) || defined (c_plusplus) extern "C" { #endif #if ! _lib_statvfs \ && _lib_statfs \ && _npt_statfs # if _lib_statfs && _args_statfs == 2 extern int statfs _((char *, struct statfs *)); # endif # if _lib_statfs && _args_statfs == 3 extern int statfs _((char *, struct statfs *, int)); # endif # if _lib_statfs && _args_statfs == 4 extern int statfs _((char *, struct statfs *, int, int)); # endif #endif extern int debug; #if defined (__cplusplus) || defined (c_plusplus) } #endif /********************************************************/ #if _lib_statvfs \ && ! _lib_fs_stat_dev \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_GetVolumeInformation \ && ! _class_os__Volumes /* * di_getDiskInfo * * SysV.4. statvfs () returns both the free and available blocks. * */ # define DI_GETDISKINFO_DEF 1 void di_getDiskInfo (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int i; Statvfs_t statBuf; if (debug > 0) { printf ("# getDiskInfo: statvfs\n"); } for (i = 0; i < *diCount; ++i) { diptr = *diskInfo + i; if (diptr->printFlag == DI_PRNT_OK || diptr->printFlag == DI_PRNT_SKIP || diptr->printFlag == DI_PRNT_FORCE) { _fs_size_t tblocksz; if (statvfs (diptr->name, &statBuf) == 0) { /* data general DG/UX 5.4R3.00 sometime returns 0 */ /* in the fragment size field. */ if (statBuf.f_frsize == 0 && statBuf.f_bsize != 0) { tblocksz = statBuf.f_bsize; } else { tblocksz = statBuf.f_frsize; } /* Linux! statvfs() returns values in f_bsize rather f_frsize. Bleah. */ /* Non-POSIX! Linux manual pages are incorrect. */ # if linux tblocksz = statBuf.f_bsize; # endif /* linux */ di_saveBlockSizes (diptr, tblocksz, (_fs_size_t) statBuf.f_blocks, (_fs_size_t) statBuf.f_bfree, (_fs_size_t) statBuf.f_bavail); di_saveInodeSizes (diptr, (_fs_size_t) statBuf.f_files, (_fs_size_t) statBuf.f_ffree, (_fs_size_t) statBuf.f_favail); # if _mem_struct_statvfs_f_basetype if (! *diptr->fsType) { strncpy (diptr->fsType, statBuf.f_basetype, DI_TYPE_LEN); } # endif if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tbsize:%ld frsize:%ld\n", (long) statBuf.f_bsize, (long) statBuf.f_frsize); # if _siz_long_long >= 8 printf ("\tblocks: tot:%llu free:%lld avail:%llu\n", (long long) statBuf.f_blocks, (long long) statBuf.f_bfree, (long long) statBuf.f_bavail); printf ("\tinodes: tot:%llu free:%llu avail:%llu\n", (long long) statBuf.f_files, (long long) statBuf.f_ffree, (long long) statBuf.f_favail); # else printf ("\tblocks: tot:%lu free:%lu avail:%lu\n", (long) statBuf.f_blocks, (long) statBuf.f_bfree, (long) statBuf.f_bavail); printf ("\tinodes: tot:%lu free:%lu avail:%lu\n", (long) statBuf.f_files, (long) statBuf.f_ffree, (long) statBuf.f_favail); # endif } } else { diptr->printFlag = DI_PRNT_BAD; if (errno != EACCES && errno != EPERM) { fprintf (stderr, "statvfs: %s ", diptr->name); perror (""); } } } } /* for each entry */ } #endif /* _lib_statvfs */ #if _lib_statfs && _args_statfs == 4 \ && ! _lib_statvfs \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_getmnt /* xenix reports a block size of 1024 bytes, but the blocks reported */ /* are based on a 512 byte block size. */ # if defined (M_XENIX) # define UBSIZE 512 # else # if ! defined (UBSIZE) # if defined (BSIZE) # define UBSIZE BSIZE # else # define UBSIZE 512 # endif # endif # endif /* * di_getDiskInfo * * SysV.3. We don't have available blocks; just set it to free blocks. * The sysfs () call is used to get the disk type name. * */ # define DI_GETDISKINFO_DEF 1 void di_getDiskInfo (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int i; struct statfs statBuf; if (debug > 0) { printf ("# getDiskInfo: sysv-statfs 4arg\n"); } for (i = 0; i < *diCount; ++i) { diptr = *diskInfo + i; if (diptr->printFlag == DI_PRNT_OK || diptr->printFlag == DI_PRNT_SKIP || diptr->printFlag == DI_PRNT_FORCE) { _fs_size_t tblocksz; if (statfs (diptr->name, &statBuf, sizeof (statBuf), 0) == 0) { # if _mem_struct_statfs_f_frsize if (statBuf.f_frsize == 0 && statBuf.f_bsize != 0) { tblocksz = (_fs_size_t) statBuf.f_bsize; } else { tblocksz = (_fs_size_t) statBuf.f_frsize; } # else tblocksz = UBSIZE; # endif di_saveBlockSizes (diptr, tblocksz, (_fs_size_t) statBuf.f_blocks, (_fs_size_t) statBuf.f_bfree, (_fs_size_t) statBuf.f_bfree); di_saveInodeSizes (diptr, (_fs_size_t) statBuf.f_files, (_fs_size_t) statBuf.f_ffree, (_fs_size_t) statBuf.f_ffree); # if _lib_sysfs && _mem_struct_statfs_f_fstyp sysfs (GETFSTYP, statBuf.f_fstyp, diptr->fsType); # endif if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); # if _mem_struct_statfs_f_frsize printf ("\tbsize:%ld\n", statBuf.f_bsize); printf ("\tfrsize:%ld\n", statBuf.f_frsize); # else printf ("\tUBSIZE:%ld\n", UBSIZE); # endif printf ("\tblocks: tot:%ld free:%ld\n", statBuf.f_blocks, statBuf.f_bfree); printf ("\tinodes: tot:%ld free:%ld\n", statBuf.f_files, statBuf.f_ffree); } } /* if we got the info */ else { diptr->printFlag = DI_PRNT_BAD; if (errno != EACCES && errno != EPERM) { fprintf (stderr, "statfs: %s ", diptr->name); perror (""); } } } } /* for each entry */ } #endif /* _args_statfs == 4 */ #if _lib_statfs && (_args_statfs == 2 || _args_statfs == 3) \ && ! _lib_statvfs \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getmnt \ && ! _lib_GetDiskFreeSpace \ && ! _lib_GetDiskFreeSpaceEx /* * di_getDiskInfo * * SunOS/BSD/Pyramid/Some Linux * */ # define DI_GETDISKINFO_DEF 1 void di_getDiskInfo (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int i; struct statfs statBuf; if (debug > 0) { printf ("# getDiskInfo: bsd-statfs 2/3arg\n"); } for (i = 0; i < *diCount; ++i) { diptr = *diskInfo + i; if (diptr->printFlag == DI_PRNT_OK || diptr->printFlag == DI_PRNT_SKIP || diptr->printFlag == DI_PRNT_FORCE) { if (statfs (diptr->name, &statBuf) == 0) { di_saveBlockSizes (diptr, (_fs_size_t) statBuf.f_bsize, (_fs_size_t) statBuf.f_blocks, (_fs_size_t) statBuf.f_bfree, (_fs_size_t) statBuf.f_bavail); di_saveInodeSizes (diptr, (_fs_size_t) statBuf.f_files, (_fs_size_t) statBuf.f_ffree, (_fs_size_t) statBuf.f_ffree); # if _lib_sysfs && _mem_struct_statfs_f_fstyp sysfs (GETFSTYP, statBuf.f_fstyp, diptr->fsType); # endif if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\tbsize:%ld\n", (long) statBuf.f_bsize); printf ("\tblocks: tot:%ld free:%ld avail:%ld\n", (long) statBuf.f_blocks, (long) statBuf.f_bfree, (long) statBuf.f_bavail); printf ("\tinodes: tot:%ld free:%ld\n", (long) statBuf.f_files, (long) statBuf.f_ffree); } } /* if we got the info */ else { diptr->printFlag = DI_PRNT_BAD; if (errno != EACCES && errno != EPERM) { fprintf (stderr, "statfs: %s ", diptr->name); perror (""); } } } } /* for each entry */ } #endif /* _args_statfs == 2 or 3 */ #if _lib_GetVolumeInformation /* * di_getDiskInfo * * Windows * */ # define DI_GETDISKINFO_DEF 1 # define MSDOS_BUFFER_SIZE 256 void di_getDiskInfo (diDiskInfo_t **diskInfo, int *diCount) { diDiskInfo_t *diptr; int i; int rc; char volName [MSDOS_BUFFER_SIZE]; char fsName [MSDOS_BUFFER_SIZE]; DWORD serialNo; DWORD maxCompLen; DWORD fsFlags; # if _lib_GetDiskFreeSpaceEx if (debug > 0) { printf ("# getDiskInfo: GetDiskFreeSpaceEx\n"); } # endif # if _lib_GetDiskFreeSpace if (debug > 0) { printf ("# getDiskInfo: GetDiskFreeSpace\n"); } # endif if (debug > 0) { printf ("# getDiskInfo: GetVolumeInformation\n"); } for (i = 0; i < *diCount; ++i) { diptr = *diskInfo + i; if (diptr->printFlag == DI_PRNT_OK || diptr->printFlag == DI_PRNT_SKIP || diptr->printFlag == DI_PRNT_FORCE) { rc = GetVolumeInformation (diptr->name, volName, MSDOS_BUFFER_SIZE, &serialNo, &maxCompLen, &fsFlags, fsName, MSDOS_BUFFER_SIZE); strncpy (diptr->fsType, fsName, DI_TYPE_LEN); strncpy (diptr->special, volName, DI_SPEC_NAME_LEN); # if _lib_GetDiskFreeSpaceEx { ULONGLONG bytesAvail; ULONGLONG bytesTotal; ULONGLONG bytesFree; rc = GetDiskFreeSpaceEx (diptr->name, (PULARGE_INTEGER) &bytesAvail, (PULARGE_INTEGER) &bytesTotal, (PULARGE_INTEGER) &bytesFree); if (rc > 0) { di_saveBlockSizes (diptr, (_fs_size_t) 1, (_fs_size_t) bytesTotal, (_fs_size_t) bytesFree, (_fs_size_t) bytesAvail); di_saveInodeSizes (diptr, (_fs_size_t) 0, (_fs_size_t) 0, (_fs_size_t) 0); } else { diptr->printFlag = DI_PRNT_BAD; if (debug) { printf ("disk %s; could not get disk space\n", diptr->name); } } if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\ttot:%llu free:%llu\n", bytesTotal, bytesFree); printf ("\tavail:%llu\n", bytesAvail); } } # else # if _lib_GetDiskFreeSpace { unsigned long sectorspercluster; unsigned long bytespersector; unsigned long totalclusters; unsigned long freeclusters; rc = GetDiskFreeSpace (diptr->name, (LPDWORD) §orspercluster, (LPDWORD) &bytespersector, (LPDWORD) &freeclusters, (LPDWORD) &totalclusters); if (rc > 0) { di_saveBlockSizes (diptr, (_fs_size_t) (sectorspercluster * bytespersector), (_fs_size_t) totalclusters, (_fs_size_t) freeclusters, (_fs_size_t) freeclusters); di_saveInodeSizes (diptr, (_fs_size_t) 0, (_fs_size_t) 0, (_fs_size_t) 0); } else { diptr->printFlag = DI_PRNT_BAD; if (debug) { printf ("disk %s; could not get disk space\n", diptr->name); } } if (debug > 1) { printf ("%s: %s\n", diptr->name, diptr->fsType); printf ("\ts/c:%ld b/s:%ld\n", sectorspercluster, bytespersector); printf ("\tclusters: tot:%ld free:%ld\n", totalclusters, freeclusters); } } # endif # endif } /* if printable drive */ } /* for each mounted drive */ } #endif /* _lib_GetVolumeInformation */ #if ! defined (DI_GETDISKINFO_DEF) void di_getDiskInfo (diDiskInfo_t **diskInfo, int *diCount) { if (debug > 0) { printf ("# getDiskInfo: empty\n"); } return; } #endif di-4.52/C/didiskutil.c0000644000175000017500000003025414421556642012654 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #include "dimntopt.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #if _hdr_memory # include #endif #if _hdr_malloc # include #endif #if _hdr_errno # include #endif #if _use_mcheck # include #endif /********************************************************/ /* This module contains utility routines for conversion and checking the data. di_initDiskInfo () initialize disk info structure di_saveBlockSizes () save the block sizes in the diskinfo structure. di_saveInodeSizes () save the inode sizes in the diskinfo structure. convertMountOptions () converts mount options to text format. convertNFSMountOptions () converts NFS mount options to text format. chkMountOptions () Checks to see if the mount option is set. Used if hasmntopt() is not present. di_testRemoteDisk () test a disk to see if it is remote (nfs, nfs3). */ void di_initDiskInfo (diDiskInfo_t *diptr) { memset ((char *) diptr, '\0', sizeof (diDiskInfo_t)); diptr->printFlag = DI_PRNT_OK; diptr->isLocal = TRUE; diptr->isReadOnly = FALSE; diptr->isLoopback = FALSE; } void di_saveBlockSizes (diDiskInfo_t *diptr, _fs_size_t block_size, _fs_size_t total_blocks, _fs_size_t free_blocks, _fs_size_t avail_blocks) { diptr->totalSpace = (_fs_size_t) total_blocks * (_fs_size_t) block_size; diptr->freeSpace = (_fs_size_t) free_blocks * (_fs_size_t) block_size; diptr->availSpace = (_fs_size_t) avail_blocks * (_fs_size_t) block_size; } void di_saveInodeSizes (diDiskInfo_t *diptr, _fs_size_t total_nodes, _fs_size_t free_nodes, _fs_size_t avail_nodes) { diptr->totalInodes = total_nodes; diptr->freeInodes = free_nodes; diptr->availInodes = avail_nodes; } void convertMountOptions (unsigned long flags, diDiskInfo_t *diptr) { #if defined (MNT_RDONLY) if ((flags & MNT_RDONLY) == MNT_RDONLY) { strncat (diptr->options, "ro,", DI_OPT_LEN - strlen (diptr->options) - 1); } else { strncat (diptr->options, "rw,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_EXRDONLY) if ((flags & MNT_EXRDONLY) == MNT_EXRDONLY) { strncat (diptr->options, "expro,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_DEFEXPORTED) if ((flags & MNT_DEFEXPORTED) == MNT_DEFEXPORTED) { strncat (diptr->options, "exprwany,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_EXPORTANON) if ((flags & MNT_EXPORTANON) == MNT_EXPORTANON) { strncat (diptr->options, "expanon,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_EXKERB) if ((flags & MNT_EXKERB) == MNT_EXKERB) { strncat (diptr->options, "expkerb,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_FORCE) if ((flags & MNT_FORCE) == MNT_FORCE) { strncat (diptr->options, "force,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_GRPID) if ((flags & MNT_GRPID) == MNT_GRPID) { strncat (diptr->options, "grpid,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_MAGICLINKS) if ((flags & MNT_MAGICLINKS) == MNT_MAGICLINKS) { strncat (diptr->options, "magiclinks,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_MLSD) if ((flags & MNT_MLSD) == MNT_MLSD) { strncat (diptr->options, "mlsd,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NOATIMES) if ((flags & MNT_NOATIMES) == MNT_NOATIMES) { strncat (diptr->options, "noatime,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NOCACHE) if ((flags & MNT_NOCACHE) == MNT_NOCACHE) { strncat (diptr->options, "nocache,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NOCOREDUMP) if ((flags & MNT_NOCOREDUMP) == MNT_NOCOREDUMP) { strncat (diptr->options, "nocoredump,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NODEV) if ((flags & MNT_NODEV) == MNT_NODEV) { strncat (diptr->options, "nodev,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NODEVMTIME) if ((flags & MNT_NODEVMTIME) == MNT_NODEVMTIME) { strncat (diptr->options, "nodevmtime,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NOEXEC) if ((flags & MNT_NOEXEC) == MNT_NOEXEC) { strncat (diptr->options, "noexec,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_NOSUID) if ((flags & MNT_NOSUID) == MNT_NOSUID) { strncat (diptr->options, "nosuid,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_QUOTA) if ((flags & MNT_QUOTA) == MNT_QUOTA) { strncat (diptr->options, "quota,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SECURE) if ((flags & MNT_SECURE) == MNT_SECURE) { strncat (diptr->options, "secure,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SMSYNC2) if ((flags & MNT_SMSYNC2) == MNT_SMSYNC2) { strncat (diptr->options, "smsync2,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SOFTDEP) if ((flags & MNT_SOFTDEP) == MNT_SOFTDEP) { strncat (diptr->options, "softdep,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SYMPERM) if ((flags & MNT_SYMPERM) == MNT_SYMPERM) { strncat (diptr->options, "symperm,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SYNC) if ((flags & MNT_SYNC) == MNT_SYNC) { strncat (diptr->options, "sync,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SYNCHRONOUS) if ((flags & MNT_SYNCHRONOUS) == MNT_SYNCHRONOUS) { strncat (diptr->options, "sync,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_THROTTLE) if ((flags & MNT_THROTTLE) == MNT_THROTTLE) { strncat (diptr->options, "throttle,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_UNION) if ((flags & MNT_UNION) == MNT_UNION) { strncat (diptr->options, "union,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_UNION) if ((flags & MNT_UNION) == MNT_UNION) { strncat (diptr->options, "union,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_REMOVABLE) if ((flags & MNT_REMOVABLE) == MNT_REMOVABLE) { strncat (diptr->options, "removable,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_PERSISTENT) if ((flags & MNT_PERSISTENT) == MNT_PERSISTENT) { strncat (diptr->options, "persistent,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_SHARED) if ((flags & MNT_SHARED) == MNT_SHARED) { strncat (diptr->options, "shared,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_BLOCKBASED) if ((flags & MNT_BLOCKBASED) == MNT_BLOCKBASED) { strncat (diptr->options, "blockbased,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_HAS_MIME) if ((flags & MNT_HAS_MIME) == MNT_HAS_MIME) { strncat (diptr->options, "mime,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_HAS_QUERY) if ((flags & MNT_HAS_QUERY) == MNT_HAS_QUERY) { strncat (diptr->options, "query,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (MNT_HAS_ATTR) if ((flags & MNT_HAS_ATTR) == MNT_HAS_ATTR) { strncat (diptr->options, "attr,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif return; } void convertNFSMountOptions (long flags, long wsize, long rsize, diDiskInfo_t *diptr) { #if defined (NFSMNT_SOFT) if ((flags & NFSMNT_SOFT) != NFSMNT_SOFT) { strncat (diptr->options, "hard,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (NFSMNT_WSIZE) if ((flags & NFSMNT_WSIZE) == NFSMNT_WSIZE) { char tmp [64]; Snprintf1 (tmp, sizeof (tmp), "wsize=%ld,", wsize); strncat (diptr->options, tmp, DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (NFSMNT_RSIZE) if ((flags & NFSMNT_RSIZE) == NFSMNT_RSIZE) { char tmp [64]; Snprintf1 (tmp, sizeof (tmp), "rsize=%ld,", rsize); strncat (diptr->options, tmp, DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (NFSMNT_INT) && defined (NFSMNT_SOFT) if ((flags & NFSMNT_SOFT) != NFSMNT_SOFT && (flags & NFSMNT_INT) == NFSMNT_INT) { strncat (diptr->options, "intr,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif #if defined (NFSMNT_TCP) if ((flags & NFSMNT_TCP) != NFSMNT_TCP) { strncat (diptr->options, "udp,", DI_OPT_LEN - strlen (diptr->options) - 1); } #endif return; } #if _lib_getmntent \ && ! _lib_getmntinfo \ && ! _lib_getfsstat \ && ! _lib_getvfsstat \ && ! _lib_mntctl \ && ! _class_os__Volumes char * chkMountOptions (const char *mntopts, const char *str) { char *ptr; char *tstr; tstr = strdup (mntopts); if (tstr == (char *) NULL) { fprintf (stderr, "strdup failed in chkMountOptions (1). errno %d\n", errno); exit (1); } ptr = strtok (tstr, ","); while (ptr != (char *) NULL) { if (strcmp (ptr, str) == 0) { free (tstr); return ptr; } ptr = strtok ((char *) NULL, ","); } free (tstr); return (char *) NULL; } #endif /* _lib_getmntent */ void di_testRemoteDisk (diDiskInfo_t *diskInfo) { if (strncmp (diskInfo->fsType, "nfs", 3) == 0) { diskInfo->isLocal = FALSE; } } int di_isPooledFs (diDiskInfo_t *diskInfo) { if (strcmp (diskInfo->fsType, "zfs") == 0 || strcmp (diskInfo->fsType, "advfs") == 0 || strcmp (diskInfo->fsType, "apfs") == 0 || (strcmp (diskInfo->fsType, "null") == 0 && strstr (diskInfo->special, "/@@-") != (char *) NULL)) { return TRUE; } return FALSE; } int di_isLoopbackFs (diDiskInfo_t *diskInfo) { if ((strcmp (diskInfo->fsType, "lofs") == 0 && diskInfo->sp_rdev != 0) || (strcmp (diskInfo->fsType, "nullfs") == 0 && strstr (diskInfo->special, "/@@-") == (char *) NULL) || strcmp (diskInfo->fsType, "none") == 0) { return TRUE; } return FALSE; } Size_t di_mungePoolName (char *poolname) { char *ptr; ptr = strchr (poolname, '#'); /* advfs */ if (ptr != (char *) NULL) { *ptr = '\0'; } else { ptr = strchr (poolname, ':'); /* dragonflybsd */ if (ptr != (char *) NULL) { *ptr = '\0'; } else { if (strncmp (poolname, "/dev/disk", 9) == 0) { /* apfs uses a standard /dev/diskNsN format */ ptr = strchr (poolname, 's'); if (ptr != (char *) NULL) { ++ptr; if (ptr != (char *) NULL) { ptr = strchr (ptr, 's'); if (ptr != (char *) NULL) { *ptr = '\0'; } } } } else { ptr = strchr (poolname, '/'); /* zfs */ if (ptr != (char *) NULL) { *ptr = '\0'; } } } } return strlen (poolname); } di-4.52/C/di.c0000644000175000017500000000663214421556642011106 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ /* * di.c * * Warning: Do not replace your system's 'df' command with this program. * You will in all likelihood break your installation procedures. * * Display sizes: * 512 - posix (512 bytes) * k - kilobytes * m - megabytes * g - gigabytes * t - terabytes * P - petabytes * E - exabytes * h - "human readable" scaled alternative 1 * H - "human readable" scaled alternative 2 * * Sort types: * N - name (default) * n - none (mount order) * s - special * a - avail * t - type * r - reverse sort * * Format string values: * m - mount point * M - mount point, full length * b - total kbytes * B - total kbytes available for use by the user. * [ (tot - (free - avail)) ] * u - kbytes used (actual number of kbytes used) [ (tot - free) ] * c - calculated number of kbytes used [ (tot - avail) ] * f - kbytes free * v - kbytes available * p - percentage not available for use. * (space not available for use / total disk space) * [ (tot - avail) / tot ] * 1 - percentage used. * (actual space used / total disk space) * [ (tot - free) / tot ] * 2 - percentage of user-available space in use (bsd style). * Note that values over 100% are possible. * (actual space used / disk space available to user) * [ (tot - free) / (tot - (free - avail)) ] * i - total i-nodes (files) * U - used i-nodes * F - free i-nodes * P - percent i-nodes used [ (tot - avail) / tot ] * s - filesystem name (special) * S - filesystem name (special), full length * t - disk partition type * T - disk partition type (full length) * I - mount time * O - mount options. * * System V.4 `/usr/bin/df -v` Has format: msbuf1 * System V.4 `/usr/bin/df -k` Has format: sbcvpm * System V.4 `/usr/ucb/df` Has format: sbuv2m * * The default format string for this program is: smbuvpT * * Environment variables: * DI_ARGS: specifies any arguments to di. * POSIXLY_CORRECT: forces posix mode. * BLOCKSIZE: BSD df block size. * DF_BLOCK_SIZE: GNU df block size. * * Note that for filesystems that do not have, or systems (SysV.3) * that do not report, available space, the amount of available space is * set to the free space. * */ #include "config.h" #include "dimain.h" #include "di.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if _use_mcheck # include #endif /* end of system specific includes/configurations */ int main (int argc, const char * argv []) { char *disp; diData_t diData; #if _use_mcheck mcheck_pedantic (NULL); mtrace (); #endif disp = dimainproc (argc, argv, 0, &diData); if (diData.options.exitFlag == DI_EXIT_FAIL) { exit (2); } if (diData.options.exitFlag == DI_EXIT_WARN) { exit (1); } if (diData.options.exitFlag == DI_EXIT_OK) { exit (0); } if (disp != (char *) NULL) { fputs (disp, stdout); free (disp); } cleanup (&diData); return 0; } di-4.52/C/getoptn.h0000644000175000017500000000262614421556642012176 0ustar bllbll#ifndef DI_INC_GETOPTN_H_ #define DI_INC_GETOPTN_H_ /* * Copyright 2011-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #if defined(TEST_GETOPTN) # include "gconfig.h" #else # include "config.h" #endif #if _sys_types \ && ! defined (DI_INC_SYS_TYPES_H) /* xenix */ # define DI_INC_SYS_TYPES_H # include #endif #if ! defined (TRUE) # define TRUE 1 #endif #if ! defined (FALSE) # define FALSE 0 #endif #define GETOPTN_NOTFOUND -1 /* option style */ /* GETOPTN_LEGACY: * -ab processes both -a and -b flags. * GETOPTN_MODERN: * -ab processes -ab flag. */ #define GETOPTN_LEGACY 'l' #define GETOPTN_MODERN 'm' /* option types */ #define GETOPTN_BOOL 0 /* flips the value */ #define GETOPTN_INT 1 #define GETOPTN_LONG 2 #define GETOPTN_DOUBLE 3 #define GETOPTN_STRING 4 #define GETOPTN_STRPTR 5 #define GETOPTN_FUNC_BOOL 6 #define GETOPTN_FUNC_VALUE 7 #define GETOPTN_ALIAS 8 #define GETOPTN_IGNORE 9 #define GETOPTN_SIZET 10 typedef struct { const char *option; int option_type; void *valptr; Size_t valsiz; void *value2; } getoptn_opt_t; extern int getoptn (int style, int argc, const char * const argv [], Size_t optcount, getoptn_opt_t opts [], int *errorCount); #endif /*DI_INC_GETOPTN_H_ */ di-4.52/C/Perl/0000755000175000017500000000000014421556642011241 5ustar bllblldi-4.52/C/Perl/ex/0000755000175000017500000000000014421556642011655 5ustar bllblldi-4.52/C/Perl/ex/perl-example.pl0000644000175000017500000000051114421556642014602 0ustar bllblluse lib './blib/lib'; use lib './blib/arch/auto/Filesys/di'; use Filesys::di; use Data::Dumper; my $r_h = diskspace (''); print Dumper ($r_h); $r_h = Filesys::di::diskspace ('-f buvp'); if ( exists($r_h->{'/'}) ) { # unix my $r_a = $r_h->{'/'}->{'display'}; my @b = @{$r_a}; my $count = $#{$r_a}; } print Dumper ($r_h); di-4.52/C/Perl/Makefile.PL0000644000175000017500000000156214421556642013217 0ustar bllblluse 5.00503; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Filesys::di', VERSION_FROM => 'lib/Filesys/di.pm', # finds $VERSION PREREQ_PM => {'Test' => 0, }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/Filesys/di.pm', # retrieve abstract from module AUTHOR => 'Brad Lanam ') : ()), LIBS => ['-L.. -ldiperl'], # e.g., '-lm' DEFINE => '', # e.g., '-DHAVE_SOMETHING' INC => '-I.. -I.', # e.g., '-I. -I/usr/include/other' # Un-comment this if you add C files to link with later: # OBJECT => '$(O_FILES)', # link all the C files too ); di-4.52/C/Perl/ppport.h0000644000175000017500000054004414421556642012745 0ustar bllbll#if 0 <<'SKIP'; #endif /* ---------------------------------------------------------------------- ppport.h -- Perl/Pollution/Portability Version 3.20 Automatically created by Devel::PPPort running under perl 5.018002. Do NOT edit this file directly! -- Edit PPPort_pm.PL and the includes in parts/inc/ instead. Use 'perldoc ppport.h' to view the documentation below. ---------------------------------------------------------------------- SKIP =pod =head1 NAME ppport.h - Perl/Pollution/Portability version 3.20 =head1 SYNOPSIS perl ppport.h [options] [source files] Searches current directory for files if no [source files] are given --help show short help --version show version --patch=file write one patch file with changes --copy=suffix write changed copies with suffix --diff=program use diff program and options --compat-version=version provide compatibility with Perl version --cplusplus accept C++ comments --quiet don't output anything except fatal errors --nodiag don't show diagnostics --nohints don't show hints --nochanges don't suggest changes --nofilter don't filter input files --strip strip all script and doc functionality from ppport.h --list-provided list provided API --list-unsupported list unsupported API --api-info=name show Perl API portability information =head1 COMPATIBILITY This version of F is designed to support operation with Perl installations back to 5.003, and has been tested up to 5.11.5. =head1 OPTIONS =head2 --help Display a brief usage summary. =head2 --version Display the version of F. =head2 --patch=I If this option is given, a single patch file will be created if any changes are suggested. This requires a working diff program to be installed on your system. =head2 --copy=I If this option is given, a copy of each file will be saved with the given suffix that contains the suggested changes. This does not require any external programs. Note that this does not automagially add a dot between the original filename and the suffix. If you want the dot, you have to include it in the option argument. If neither C<--patch> or C<--copy> are given, the default is to simply print the diffs for each file. This requires either C or a C program to be installed. =head2 --diff=I Manually set the diff program and options to use. The default is to use C, when installed, and output unified context diffs. =head2 --compat-version=I Tell F to check for compatibility with the given Perl version. The default is to check for compatibility with Perl version 5.003. You can use this option to reduce the output of F if you intend to be backward compatible only down to a certain Perl version. =head2 --cplusplus Usually, F will detect C++ style comments and replace them with C style comments for portability reasons. Using this option instructs F to leave C++ comments untouched. =head2 --quiet Be quiet. Don't print anything except fatal errors. =head2 --nodiag Don't output any diagnostic messages. Only portability alerts will be printed. =head2 --nohints Don't output any hints. Hints often contain useful portability notes. Warnings will still be displayed. =head2 --nochanges Don't suggest any changes. Only give diagnostic output and hints unless these are also deactivated. =head2 --nofilter Don't filter the list of input files. By default, files not looking like source code (i.e. not *.xs, *.c, *.cc, *.cpp or *.h) are skipped. =head2 --strip Strip all script and documentation functionality from F. This reduces the size of F dramatically and may be useful if you want to include F in smaller modules without increasing their distribution size too much. The stripped F will have a C<--unstrip> option that allows you to undo the stripping, but only if an appropriate C module is installed. =head2 --list-provided Lists the API elements for which compatibility is provided by F. Also lists if it must be explicitly requested, if it has dependencies, and if there are hints or warnings for it. =head2 --list-unsupported Lists the API elements that are known not to be supported by F and below which version of Perl they probably won't be available or work. =head2 --api-info=I Show portability information for API elements matching I. If I is surrounded by slashes, it is interpreted as a regular expression. =head1 DESCRIPTION In order for a Perl extension (XS) module to be as portable as possible across differing versions of Perl itself, certain steps need to be taken. =over 4 =item * Including this header is the first major one. This alone will give you access to a large part of the Perl API that hasn't been available in earlier Perl releases. Use perl ppport.h --list-provided to see which API elements are provided by ppport.h. =item * You should avoid using deprecated parts of the API. For example, using global Perl variables without the C prefix is deprecated. Also, some API functions used to have a C prefix. Using this form is also deprecated. You can safely use the supported API, as F will provide wrappers for older Perl versions. =item * If you use one of a few functions or variables that were not present in earlier versions of Perl, and that can't be provided using a macro, you have to explicitly request support for these functions by adding one or more C<#define>s in your source code before the inclusion of F. These functions or variables will be marked C in the list shown by C<--list-provided>. Depending on whether you module has a single or multiple files that use such functions or variables, you want either C or global variants. For a C function or variable (used only in a single source file), use: #define NEED_function #define NEED_variable For a global function or variable (used in multiple source files), use: #define NEED_function_GLOBAL #define NEED_variable_GLOBAL Note that you mustn't have more than one global request for the same function or variable in your project. Function / Variable Static Request Global Request ----------------------------------------------------------------------------------------- PL_parser NEED_PL_parser NEED_PL_parser_GLOBAL PL_signals NEED_PL_signals NEED_PL_signals_GLOBAL eval_pv() NEED_eval_pv NEED_eval_pv_GLOBAL grok_bin() NEED_grok_bin NEED_grok_bin_GLOBAL grok_hex() NEED_grok_hex NEED_grok_hex_GLOBAL grok_number() NEED_grok_number NEED_grok_number_GLOBAL grok_numeric_radix() NEED_grok_numeric_radix NEED_grok_numeric_radix_GLOBAL grok_oct() NEED_grok_oct NEED_grok_oct_GLOBAL load_module() NEED_load_module NEED_load_module_GLOBAL my_snprintf() NEED_my_snprintf NEED_my_snprintf_GLOBAL my_sprintf() NEED_my_sprintf NEED_my_sprintf_GLOBAL my_strlcat() NEED_my_strlcat NEED_my_strlcat_GLOBAL my_strlcpy() NEED_my_strlcpy NEED_my_strlcpy_GLOBAL newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL newRV_noinc() NEED_newRV_noinc NEED_newRV_noinc_GLOBAL newSV_type() NEED_newSV_type NEED_newSV_type_GLOBAL newSVpvn_flags() NEED_newSVpvn_flags NEED_newSVpvn_flags_GLOBAL newSVpvn_share() NEED_newSVpvn_share NEED_newSVpvn_share_GLOBAL pv_display() NEED_pv_display NEED_pv_display_GLOBAL pv_escape() NEED_pv_escape NEED_pv_escape_GLOBAL pv_pretty() NEED_pv_pretty NEED_pv_pretty_GLOBAL sv_2pv_flags() NEED_sv_2pv_flags NEED_sv_2pv_flags_GLOBAL sv_2pvbyte() NEED_sv_2pvbyte NEED_sv_2pvbyte_GLOBAL sv_catpvf_mg() NEED_sv_catpvf_mg NEED_sv_catpvf_mg_GLOBAL sv_catpvf_mg_nocontext() NEED_sv_catpvf_mg_nocontext NEED_sv_catpvf_mg_nocontext_GLOBAL sv_pvn_force_flags() NEED_sv_pvn_force_flags NEED_sv_pvn_force_flags_GLOBAL sv_setpvf_mg() NEED_sv_setpvf_mg NEED_sv_setpvf_mg_GLOBAL sv_setpvf_mg_nocontext() NEED_sv_setpvf_mg_nocontext NEED_sv_setpvf_mg_nocontext_GLOBAL vload_module() NEED_vload_module NEED_vload_module_GLOBAL vnewSVpvf() NEED_vnewSVpvf NEED_vnewSVpvf_GLOBAL warner() NEED_warner NEED_warner_GLOBAL To avoid namespace conflicts, you can change the namespace of the explicitly exported functions / variables using the C macro. Just C<#define> the macro before including C: #define DPPP_NAMESPACE MyOwnNamespace_ #include "ppport.h" The default namespace is C. =back The good thing is that most of the above can be checked by running F on your source code. See the next section for details. =head1 EXAMPLES To verify whether F is needed for your module, whether you should make any changes to your code, and whether any special defines should be used, F can be run as a Perl script to check your source code. Simply say: perl ppport.h The result will usually be a list of patches suggesting changes that should at least be acceptable, if not necessarily the most efficient solution, or a fix for all possible problems. If you know that your XS module uses features only available in newer Perl releases, if you're aware that it uses C++ comments, and if you want all suggestions as a single patch file, you could use something like this: perl ppport.h --compat-version=5.6.0 --cplusplus --patch=test.diff If you only want your code to be scanned without any suggestions for changes, use: perl ppport.h --nochanges You can specify a different C program or options, using the C<--diff> option: perl ppport.h --diff='diff -C 10' This would output context diffs with 10 lines of context. If you want to create patched copies of your files instead, use: perl ppport.h --copy=.new To display portability information for the C function, use: perl ppport.h --api-info=newSVpvn Since the argument to C<--api-info> can be a regular expression, you can use perl ppport.h --api-info=/_nomg$/ to display portability information for all C<_nomg> functions or perl ppport.h --api-info=/./ to display information for all known API elements. =head1 BUGS If this version of F is causing failure during the compilation of this module, please check if newer versions of either this module or C are available on CPAN before sending a bug report. If F was generated using the latest version of C and is causing failure of this module, please file a bug report using the CPAN Request Tracker at L. Please include the following information: =over 4 =item 1. The complete output from running "perl -V" =item 2. This file. =item 3. The name and version of the module you were trying to build. =item 4. A full log of the build that failed. =item 5. Any other information that you think could be relevant. =back For the latest version of this code, please get the C module from CPAN. =head1 COPYRIGHT Version 3.x, Copyright (c) 2004-2010, Marcus Holland-Moritz. Version 2.x, Copyright (C) 2001, Paul Marquess. Version 1.x, Copyright (C) 1999, Kenneth Albanowski. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO See L. =cut use strict; # Disable broken TRIE-optimization BEGIN { eval '${^RE_TRIE_MAXBUF} = -1' if $] >= 5.009004 && $] <= 5.009005 } my $VERSION = 3.20; my %opt = ( quiet => 0, diag => 1, hints => 1, changes => 1, cplusplus => 0, filter => 1, strip => 0, version => 0, ); my($ppport) = $0 =~ /([\w.]+)$/; my $LF = '(?:\r\n|[\r\n])'; # line feed my $HS = "[ \t]"; # horizontal whitespace # Never use C comments in this file! my $ccs = '/'.'*'; my $cce = '*'.'/'; my $rccs = quotemeta $ccs; my $rcce = quotemeta $cce; eval { require Getopt::Long; Getopt::Long::GetOptions(\%opt, qw( help quiet diag! filter! hints! changes! cplusplus strip version patch=s copy=s diff=s compat-version=s list-provided list-unsupported api-info=s )) or usage(); }; if ($@ and grep /^-/, @ARGV) { usage() if "@ARGV" =~ /^--?h(?:elp)?$/; die "Getopt::Long not found. Please don't use any options.\n"; } if ($opt{version}) { print "This is $0 $VERSION.\n"; exit 0; } usage() if $opt{help}; strip() if $opt{strip}; if (exists $opt{'compat-version'}) { my($r,$v,$s) = eval { parse_version($opt{'compat-version'}) }; if ($@) { die "Invalid version number format: '$opt{'compat-version'}'\n"; } die "Only Perl 5 is supported\n" if $r != 5; die "Invalid version number: $opt{'compat-version'}\n" if $v >= 1000 || $s >= 1000; $opt{'compat-version'} = sprintf "%d.%03d%03d", $r, $v, $s; } else { $opt{'compat-version'} = 5; } my %API = map { /^(\w+)\|([^|]*)\|([^|]*)\|(\w*)$/ ? ( $1 => { ($2 ? ( base => $2 ) : ()), ($3 ? ( todo => $3 ) : ()), (index($4, 'v') >= 0 ? ( varargs => 1 ) : ()), (index($4, 'p') >= 0 ? ( provided => 1 ) : ()), (index($4, 'n') >= 0 ? ( nothxarg => 1 ) : ()), } ) : die "invalid spec: $_" } qw( AvFILLp|5.004050||p AvFILL||| BhkDISABLE||5.014000| BhkENABLE||5.014000| BhkENTRY_set||5.014000| BhkENTRY||| BhkFLAGS||| CALL_BLOCK_HOOKS||| CLASS|||n CPERLscope|5.005000||p CX_CURPAD_SAVE||| CX_CURPAD_SV||| CopFILEAV|5.006000||p CopFILEGV_set|5.006000||p CopFILEGV|5.006000||p CopFILESV|5.006000||p CopFILE_set|5.006000||p CopFILE|5.006000||p CopSTASHPV_set|5.006000||p CopSTASHPV|5.006000||p CopSTASH_eq|5.006000||p CopSTASH_set|5.006000||p CopSTASH|5.006000||p CopyD|5.009002||p Copy||| CvPADLIST||| CvSTASH||| CvWEAKOUTSIDE||| DEFSV_set|5.010001||p DEFSV|5.004050||p END_EXTERN_C|5.005000||p ENTER||| ERRSV|5.004050||p EXTEND||| EXTERN_C|5.005000||p F0convert|||n FREETMPS||| GIMME_V||5.004000|n GIMME|||n GROK_NUMERIC_RADIX|5.007002||p G_ARRAY||| G_DISCARD||| G_EVAL||| G_METHOD|5.006001||p G_NOARGS||| G_SCALAR||| G_VOID||5.004000| GetVars||| GvSVn|5.009003||p GvSV||| Gv_AMupdate||5.011000| HEf_SVKEY||5.004000| HeHASH||5.004000| HeKEY||5.004000| HeKLEN||5.004000| HePV||5.004000| HeSVKEY_force||5.004000| HeSVKEY_set||5.004000| HeSVKEY||5.004000| HeUTF8||5.010001| HeVAL||5.004000| HvENAME||5.013007| HvNAMELEN_get|5.009003||p HvNAME_get|5.009003||p HvNAME||| INT2PTR|5.006000||p IN_LOCALE_COMPILETIME|5.007002||p IN_LOCALE_RUNTIME|5.007002||p IN_LOCALE|5.007002||p IN_PERL_COMPILETIME|5.008001||p IS_NUMBER_GREATER_THAN_UV_MAX|5.007002||p IS_NUMBER_INFINITY|5.007002||p IS_NUMBER_IN_UV|5.007002||p IS_NUMBER_NAN|5.007003||p IS_NUMBER_NEG|5.007002||p IS_NUMBER_NOT_INT|5.007002||p IVSIZE|5.006000||p IVTYPE|5.006000||p IVdf|5.006000||p LEAVE||| LINKLIST||5.013006| LVRET||| MARK||| MULTICALL||5.014000| MY_CXT_CLONE|5.009002||p MY_CXT_INIT|5.007003||p MY_CXT|5.007003||p MoveD|5.009002||p Move||| NOOP|5.005000||p NUM2PTR|5.006000||p NVTYPE|5.006000||p NVef|5.006001||p NVff|5.006001||p NVgf|5.006001||p Newxc|5.009003||p Newxz|5.009003||p Newx|5.009003||p Nullav||| Nullch||| Nullcv||| Nullhv||| Nullsv||| OP_CLASS||5.013007| OP_DESC||5.007003| OP_NAME||5.007003| ORIGMARK||| PAD_BASE_SV||| PAD_CLONE_VARS||| PAD_COMPNAME_FLAGS||| PAD_COMPNAME_GEN_set||| PAD_COMPNAME_GEN||| PAD_COMPNAME_OURSTASH||| PAD_COMPNAME_PV||| PAD_COMPNAME_TYPE||| PAD_DUP||| PAD_RESTORE_LOCAL||| PAD_SAVE_LOCAL||| PAD_SAVE_SETNULLPAD||| PAD_SETSV||| PAD_SET_CUR_NOSAVE||| PAD_SET_CUR||| PAD_SVl||| PAD_SV||| PERLIO_FUNCS_CAST|5.009003||p PERLIO_FUNCS_DECL|5.009003||p PERL_ABS|5.008001||p PERL_BCDVERSION|5.014000||p PERL_GCC_BRACE_GROUPS_FORBIDDEN|5.008001||p PERL_HASH|5.004000||p PERL_INT_MAX|5.004000||p PERL_INT_MIN|5.004000||p PERL_LONG_MAX|5.004000||p PERL_LONG_MIN|5.004000||p PERL_MAGIC_arylen|5.007002||p PERL_MAGIC_backref|5.007002||p PERL_MAGIC_bm|5.007002||p PERL_MAGIC_collxfrm|5.007002||p PERL_MAGIC_dbfile|5.007002||p PERL_MAGIC_dbline|5.007002||p PERL_MAGIC_defelem|5.007002||p PERL_MAGIC_envelem|5.007002||p PERL_MAGIC_env|5.007002||p PERL_MAGIC_ext|5.007002||p PERL_MAGIC_fm|5.007002||p PERL_MAGIC_glob|5.014000||p PERL_MAGIC_isaelem|5.007002||p PERL_MAGIC_isa|5.007002||p PERL_MAGIC_mutex|5.014000||p PERL_MAGIC_nkeys|5.007002||p PERL_MAGIC_overload_elem|5.007002||p PERL_MAGIC_overload_table|5.007002||p PERL_MAGIC_overload|5.007002||p PERL_MAGIC_pos|5.007002||p PERL_MAGIC_qr|5.007002||p PERL_MAGIC_regdata|5.007002||p PERL_MAGIC_regdatum|5.007002||p PERL_MAGIC_regex_global|5.007002||p PERL_MAGIC_shared_scalar|5.007003||p PERL_MAGIC_shared|5.007003||p PERL_MAGIC_sigelem|5.007002||p PERL_MAGIC_sig|5.007002||p PERL_MAGIC_substr|5.007002||p PERL_MAGIC_sv|5.007002||p PERL_MAGIC_taint|5.007002||p PERL_MAGIC_tiedelem|5.007002||p PERL_MAGIC_tiedscalar|5.007002||p PERL_MAGIC_tied|5.007002||p PERL_MAGIC_utf8|5.008001||p PERL_MAGIC_uvar_elem|5.007003||p PERL_MAGIC_uvar|5.007002||p PERL_MAGIC_vec|5.007002||p PERL_MAGIC_vstring|5.008001||p PERL_PV_ESCAPE_ALL|5.009004||p PERL_PV_ESCAPE_FIRSTCHAR|5.009004||p PERL_PV_ESCAPE_NOBACKSLASH|5.009004||p PERL_PV_ESCAPE_NOCLEAR|5.009004||p PERL_PV_ESCAPE_QUOTE|5.009004||p PERL_PV_ESCAPE_RE|5.009005||p PERL_PV_ESCAPE_UNI_DETECT|5.009004||p PERL_PV_ESCAPE_UNI|5.009004||p PERL_PV_PRETTY_DUMP|5.009004||p PERL_PV_PRETTY_ELLIPSES|5.010000||p PERL_PV_PRETTY_LTGT|5.009004||p PERL_PV_PRETTY_NOCLEAR|5.010000||p PERL_PV_PRETTY_QUOTE|5.009004||p PERL_PV_PRETTY_REGPROP|5.009004||p PERL_QUAD_MAX|5.004000||p PERL_QUAD_MIN|5.004000||p PERL_REVISION|5.006000||p PERL_SCAN_ALLOW_UNDERSCORES|5.007003||p PERL_SCAN_DISALLOW_PREFIX|5.007003||p PERL_SCAN_GREATER_THAN_UV_MAX|5.007003||p PERL_SCAN_SILENT_ILLDIGIT|5.008001||p PERL_SHORT_MAX|5.004000||p PERL_SHORT_MIN|5.004000||p PERL_SIGNALS_UNSAFE_FLAG|5.008001||p PERL_SUBVERSION|5.006000||p PERL_SYS_INIT3||5.006000| PERL_SYS_INIT||| PERL_SYS_TERM||5.014000| PERL_UCHAR_MAX|5.004000||p PERL_UCHAR_MIN|5.004000||p PERL_UINT_MAX|5.004000||p PERL_UINT_MIN|5.004000||p PERL_ULONG_MAX|5.004000||p PERL_ULONG_MIN|5.004000||p PERL_UNUSED_ARG|5.009003||p PERL_UNUSED_CONTEXT|5.009004||p PERL_UNUSED_DECL|5.007002||p PERL_UNUSED_VAR|5.007002||p PERL_UQUAD_MAX|5.004000||p PERL_UQUAD_MIN|5.004000||p PERL_USE_GCC_BRACE_GROUPS|5.009004||p PERL_USHORT_MAX|5.004000||p PERL_USHORT_MIN|5.004000||p PERL_VERSION|5.006000||p PL_DBsignal|5.005000||p PL_DBsingle|||pn PL_DBsub|||pn PL_DBtrace|||pn PL_Sv|5.005000||p PL_bufend|5.014000||p PL_bufptr|5.014000||p PL_compiling|5.004050||p PL_copline|5.014000||p PL_curcop|5.004050||p PL_curstash|5.004050||p PL_debstash|5.004050||p PL_defgv|5.004050||p PL_diehook|5.004050||p PL_dirty|5.004050||p PL_dowarn|||pn PL_errgv|5.004050||p PL_error_count|5.014000||p PL_expect|5.014000||p PL_hexdigit|5.005000||p PL_hints|5.005000||p PL_in_my_stash|5.014000||p PL_in_my|5.014000||p PL_keyword_plugin||5.011002| PL_last_in_gv|||n PL_laststatval|5.005000||p PL_lex_state|5.014000||p PL_lex_stuff|5.014000||p PL_linestr|5.014000||p PL_modglobal||5.005000|n PL_na|5.004050||pn PL_no_modify|5.006000||p PL_ofsgv|||n PL_opfreehook||5.011000|n PL_parser|5.009005|5.009005|p PL_peepp||5.007003|n PL_perl_destruct_level|5.004050||p PL_perldb|5.004050||p PL_ppaddr|5.006000||p PL_rpeepp||5.013005|n PL_rsfp_filters|5.014000||p PL_rsfp|5.014000||p PL_rs|||n PL_signals|5.008001||p PL_stack_base|5.004050||p PL_stack_sp|5.004050||p PL_statcache|5.005000||p PL_stdingv|5.004050||p PL_sv_arenaroot|5.004050||p PL_sv_no|5.004050||pn PL_sv_undef|5.004050||pn PL_sv_yes|5.004050||pn PL_tainted|5.004050||p PL_tainting|5.004050||p PL_tokenbuf|5.014000||p POP_MULTICALL||5.014000| POPi|||n POPl|||n POPn|||n POPpbytex||5.007001|n POPpx||5.005030|n POPp|||n POPs|||n PTR2IV|5.006000||p PTR2NV|5.006000||p PTR2UV|5.006000||p PTR2nat|5.009003||p PTR2ul|5.007001||p PTRV|5.006000||p PUSHMARK||| PUSH_MULTICALL||5.014000| PUSHi||| PUSHmortal|5.009002||p PUSHn||| PUSHp||| PUSHs||| PUSHu|5.004000||p PUTBACK||| PerlIO_clearerr||5.007003| PerlIO_close||5.007003| PerlIO_context_layers||5.009004| PerlIO_eof||5.007003| PerlIO_error||5.007003| PerlIO_fileno||5.007003| PerlIO_fill||5.007003| PerlIO_flush||5.007003| PerlIO_get_base||5.007003| PerlIO_get_bufsiz||5.007003| PerlIO_get_cnt||5.007003| PerlIO_get_ptr||5.007003| PerlIO_read||5.007003| PerlIO_seek||5.007003| PerlIO_set_cnt||5.007003| PerlIO_set_ptrcnt||5.007003| PerlIO_setlinebuf||5.007003| PerlIO_stderr||5.007003| PerlIO_stdin||5.007003| PerlIO_stdout||5.007003| PerlIO_tell||5.007003| PerlIO_unread||5.007003| PerlIO_write||5.007003| Perl_signbit||5.009005|n PoisonFree|5.009004||p PoisonNew|5.009004||p PoisonWith|5.009004||p Poison|5.008000||p RETVAL|||n Renewc||| Renew||| SAVECLEARSV||| SAVECOMPPAD||| SAVEPADSV||| SAVETMPS||| SAVE_DEFSV|5.004050||p SPAGAIN||| SP||| START_EXTERN_C|5.005000||p START_MY_CXT|5.007003||p STMT_END|||p STMT_START|||p STR_WITH_LEN|5.009003||p ST||| SV_CONST_RETURN|5.009003||p SV_COW_DROP_PV|5.008001||p SV_COW_SHARED_HASH_KEYS|5.009005||p SV_GMAGIC|5.007002||p SV_HAS_TRAILING_NUL|5.009004||p SV_IMMEDIATE_UNREF|5.007001||p SV_MUTABLE_RETURN|5.009003||p SV_NOSTEAL|5.009002||p SV_SMAGIC|5.009003||p SV_UTF8_NO_ENCODING|5.008001||p SVfARG|5.009005||p SVf_UTF8|5.006000||p SVf|5.006000||p SVt_IV||| SVt_NV||| SVt_PVAV||| SVt_PVCV||| SVt_PVHV||| SVt_PVMG||| SVt_PV||| Safefree||| Slab_Alloc||| Slab_Free||| Slab_to_rw||| StructCopy||| SvCUR_set||| SvCUR||| SvEND||| SvGAMAGIC||5.006001| SvGETMAGIC|5.004050||p SvGROW||| SvIOK_UV||5.006000| SvIOK_notUV||5.006000| SvIOK_off||| SvIOK_only_UV||5.006000| SvIOK_only||| SvIOK_on||| SvIOKp||| SvIOK||| SvIVX||| SvIV_nomg|5.009001||p SvIV_set||| SvIVx||| SvIV||| SvIsCOW_shared_hash||5.008003| SvIsCOW||5.008003| SvLEN_set||| SvLEN||| SvLOCK||5.007003| SvMAGIC_set|5.009003||p SvNIOK_off||| SvNIOKp||| SvNIOK||| SvNOK_off||| SvNOK_only||| SvNOK_on||| SvNOKp||| SvNOK||| SvNVX||| SvNV_nomg||5.013002| SvNV_set||| SvNVx||| SvNV||| SvOK||| SvOOK_offset||5.011000| SvOOK||| SvPOK_off||| SvPOK_only_UTF8||5.006000| SvPOK_only||| SvPOK_on||| SvPOKp||| SvPOK||| SvPVX_const|5.009003||p SvPVX_mutable|5.009003||p SvPVX||| SvPV_const|5.009003||p SvPV_flags_const_nolen|5.009003||p SvPV_flags_const|5.009003||p SvPV_flags_mutable|5.009003||p SvPV_flags|5.007002||p SvPV_force_flags_mutable|5.009003||p SvPV_force_flags_nolen|5.009003||p SvPV_force_flags|5.007002||p SvPV_force_mutable|5.009003||p SvPV_force_nolen|5.009003||p SvPV_force_nomg_nolen|5.009003||p SvPV_force_nomg|5.007002||p SvPV_force|||p SvPV_mutable|5.009003||p SvPV_nolen_const|5.009003||p SvPV_nolen|5.006000||p SvPV_nomg_const_nolen|5.009003||p SvPV_nomg_const|5.009003||p SvPV_nomg_nolen||5.013007| SvPV_nomg|5.007002||p SvPV_renew|5.009003||p SvPV_set||| SvPVbyte_force||5.009002| SvPVbyte_nolen||5.006000| SvPVbytex_force||5.006000| SvPVbytex||5.006000| SvPVbyte|5.006000||p SvPVutf8_force||5.006000| SvPVutf8_nolen||5.006000| SvPVutf8x_force||5.006000| SvPVutf8x||5.006000| SvPVutf8||5.006000| SvPVx||| SvPV||| SvREFCNT_dec||| SvREFCNT_inc_NN|5.009004||p SvREFCNT_inc_simple_NN|5.009004||p SvREFCNT_inc_simple_void_NN|5.009004||p SvREFCNT_inc_simple_void|5.009004||p SvREFCNT_inc_simple|5.009004||p SvREFCNT_inc_void_NN|5.009004||p SvREFCNT_inc_void|5.009004||p SvREFCNT_inc|||p SvREFCNT||| SvROK_off||| SvROK_on||| SvROK||| SvRV_set|5.009003||p SvRV||| SvRXOK||5.009005| SvRX||5.009005| SvSETMAGIC||| SvSHARED_HASH|5.009003||p SvSHARE||5.007003| SvSTASH_set|5.009003||p SvSTASH||| SvSetMagicSV_nosteal||5.004000| SvSetMagicSV||5.004000| SvSetSV_nosteal||5.004000| SvSetSV||| SvTAINTED_off||5.004000| SvTAINTED_on||5.004000| SvTAINTED||5.004000| SvTAINT||| SvTRUE_nomg||5.013006| SvTRUE||| SvTYPE||| SvUNLOCK||5.007003| SvUOK|5.007001|5.006000|p SvUPGRADE||| SvUTF8_off||5.006000| SvUTF8_on||5.006000| SvUTF8||5.006000| SvUVXx|5.004000||p SvUVX|5.004000||p SvUV_nomg|5.009001||p SvUV_set|5.009003||p SvUVx|5.004000||p SvUV|5.004000||p SvVOK||5.008001| SvVSTRING_mg|5.009004||p THIS|||n UNDERBAR|5.009002||p UTF8_MAXBYTES|5.009002||p UVSIZE|5.006000||p UVTYPE|5.006000||p UVXf|5.007001||p UVof|5.006000||p UVuf|5.006000||p UVxf|5.006000||p WARN_ALL|5.006000||p WARN_AMBIGUOUS|5.006000||p WARN_ASSERTIONS|5.014000||p WARN_BAREWORD|5.006000||p WARN_CLOSED|5.006000||p WARN_CLOSURE|5.006000||p WARN_DEBUGGING|5.006000||p WARN_DEPRECATED|5.006000||p WARN_DIGIT|5.006000||p WARN_EXEC|5.006000||p WARN_EXITING|5.006000||p WARN_GLOB|5.006000||p WARN_INPLACE|5.006000||p WARN_INTERNAL|5.006000||p WARN_IO|5.006000||p WARN_LAYER|5.008000||p WARN_MALLOC|5.006000||p WARN_MISC|5.006000||p WARN_NEWLINE|5.006000||p WARN_NUMERIC|5.006000||p WARN_ONCE|5.006000||p WARN_OVERFLOW|5.006000||p WARN_PACK|5.006000||p WARN_PARENTHESIS|5.006000||p WARN_PIPE|5.006000||p WARN_PORTABLE|5.006000||p WARN_PRECEDENCE|5.006000||p WARN_PRINTF|5.006000||p WARN_PROTOTYPE|5.006000||p WARN_QW|5.006000||p WARN_RECURSION|5.006000||p WARN_REDEFINE|5.006000||p WARN_REGEXP|5.006000||p WARN_RESERVED|5.006000||p WARN_SEMICOLON|5.006000||p WARN_SEVERE|5.006000||p WARN_SIGNAL|5.006000||p WARN_SUBSTR|5.006000||p WARN_SYNTAX|5.006000||p WARN_TAINT|5.006000||p WARN_THREADS|5.008000||p WARN_UNINITIALIZED|5.006000||p WARN_UNOPENED|5.006000||p WARN_UNPACK|5.006000||p WARN_UNTIE|5.006000||p WARN_UTF8|5.006000||p WARN_VOID|5.006000||p XCPT_CATCH|5.009002||p XCPT_RETHROW|5.009002||p XCPT_TRY_END|5.009002||p XCPT_TRY_START|5.009002||p XPUSHi||| XPUSHmortal|5.009002||p XPUSHn||| XPUSHp||| XPUSHs||| XPUSHu|5.004000||p XSPROTO|5.010000||p XSRETURN_EMPTY||| XSRETURN_IV||| XSRETURN_NO||| XSRETURN_NV||| XSRETURN_PV||| XSRETURN_UNDEF||| XSRETURN_UV|5.008001||p XSRETURN_YES||| XSRETURN|||p XST_mIV||| XST_mNO||| XST_mNV||| XST_mPV||| XST_mUNDEF||| XST_mUV|5.008001||p XST_mYES||| XS_APIVERSION_BOOTCHECK||5.013004| XS_VERSION_BOOTCHECK||| XS_VERSION||| XSprePUSH|5.006000||p XS||| XopDISABLE||5.014000| XopENABLE||5.014000| XopENTRY_set||5.014000| XopENTRY||5.014000| XopFLAGS||5.013007| ZeroD|5.009002||p Zero||| _aMY_CXT|5.007003||p _append_range_to_invlist||| _new_invlist||| _pMY_CXT|5.007003||p _swash_inversion_hash||| _swash_to_invlist||| aMY_CXT_|5.007003||p aMY_CXT|5.007003||p aTHXR_|5.014000||p aTHXR|5.014000||p aTHX_|5.006000||p aTHX|5.006000||p add_alternate||| add_cp_to_invlist||| add_data|||n add_range_to_invlist||| add_utf16_textfilter||| addmad||| allocmy||| amagic_call||| amagic_cmp_locale||| amagic_cmp||| amagic_deref_call||5.013007| amagic_i_ncmp||| amagic_ncmp||| anonymise_cv_maybe||| any_dup||| ao||| append_madprops||| apply_attrs_my||| apply_attrs_string||5.006001| apply_attrs||| apply||| assert_uft8_cache_coherent||| atfork_lock||5.007003|n atfork_unlock||5.007003|n av_arylen_p||5.009003| av_clear||| av_create_and_push||5.009005| av_create_and_unshift_one||5.009005| av_delete||5.006000| av_exists||5.006000| av_extend||| av_fetch||| av_fill||| av_iter_p||5.011000| av_len||| av_make||| av_pop||| av_push||| av_reify||| av_shift||| av_store||| av_undef||| av_unshift||| ax|||n bad_type||| bind_match||| block_end||| block_gimme||5.004000| block_start||| blockhook_register||5.013003| boolSV|5.004000||p boot_core_PerlIO||| boot_core_UNIVERSAL||| boot_core_mro||| bytes_cmp_utf8||5.013007| bytes_from_utf8||5.007001| bytes_to_uni|||n bytes_to_utf8||5.006001| call_argv|5.006000||p call_atexit||5.006000| call_list||5.004000| call_method|5.006000||p call_pv|5.006000||p call_sv|5.006000||p caller_cx||5.013005| calloc||5.007002|n cando||| cast_i32||5.006000| cast_iv||5.006000| cast_ulong||5.006000| cast_uv||5.006000| check_type_and_open||| check_uni||| check_utf8_print||| checkcomma||| checkposixcc||| ckWARN|5.006000||p ck_entersub_args_list||5.013006| ck_entersub_args_proto_or_list||5.013006| ck_entersub_args_proto||5.013006| ck_warner_d||5.011001|v ck_warner||5.011001|v ckwarn_common||| ckwarn_d||5.009003| ckwarn||5.009003| cl_and|||n cl_anything|||n cl_init|||n cl_is_anything|||n cl_or|||n clear_placeholders||| clone_params_del|||n clone_params_new|||n closest_cop||| convert||| cop_free||| cop_hints_2hv||5.013007| cop_hints_fetch_pvn||5.013007| cop_hints_fetch_pvs||5.013007| cop_hints_fetch_pv||5.013007| cop_hints_fetch_sv||5.013007| cophh_2hv||5.013007| cophh_copy||5.013007| cophh_delete_pvn||5.013007| cophh_delete_pvs||5.013007| cophh_delete_pv||5.013007| cophh_delete_sv||5.013007| cophh_fetch_pvn||5.013007| cophh_fetch_pvs||5.013007| cophh_fetch_pv||5.013007| cophh_fetch_sv||5.013007| cophh_free||5.013007| cophh_new_empty||5.014000| cophh_store_pvn||5.013007| cophh_store_pvs||5.013007| cophh_store_pv||5.013007| cophh_store_sv||5.013007| cr_textfilter||| create_eval_scope||| croak_no_modify||5.013003| croak_nocontext|||vn croak_sv||5.013001| croak_xs_usage||5.010001| croak|||v csighandler||5.009003|n curmad||| curse||| custom_op_desc||5.007003| custom_op_name||5.007003| custom_op_register||5.013007| custom_op_xop||5.013007| cv_ckproto_len||| cv_clone||| cv_const_sv||5.004000| cv_dump||| cv_get_call_checker||5.013006| cv_set_call_checker||5.013006| cv_undef||| cvgv_set||| cvstash_set||| cx_dump||5.005000| cx_dup||| cxinc||| dAXMARK|5.009003||p dAX|5.007002||p dITEMS|5.007002||p dMARK||| dMULTICALL||5.009003| dMY_CXT_SV|5.007003||p dMY_CXT|5.007003||p dNOOP|5.006000||p dORIGMARK||| dSP||| dTHR|5.004050||p dTHXR|5.014000||p dTHXa|5.006000||p dTHXoa|5.006000||p dTHX|5.006000||p dUNDERBAR|5.009002||p dVAR|5.009003||p dXCPT|5.009002||p dXSARGS||| dXSI32||| dXSTARG|5.006000||p deb_curcv||| deb_nocontext|||vn deb_stack_all||| deb_stack_n||| debop||5.005000| debprofdump||5.005000| debprof||| debstackptrs||5.007003| debstack||5.007003| debug_start_match||| deb||5.007003|v del_sv||| delete_eval_scope||| delimcpy||5.004000|n deprecate_commaless_var_list||| despatch_signals||5.007001| destroy_matcher||| die_nocontext|||vn die_sv||5.013001| die_unwind||| die|||v dirp_dup||| div128||| djSP||| do_aexec5||| do_aexec||| do_aspawn||| do_binmode||5.004050| do_chomp||| do_close||| do_delete_local||| do_dump_pad||| do_eof||| do_exec3||| do_execfree||| do_exec||| do_gv_dump||5.006000| do_gvgv_dump||5.006000| do_hv_dump||5.006000| do_ipcctl||| do_ipcget||| do_join||| do_magic_dump||5.006000| do_msgrcv||| do_msgsnd||| do_oddball||| do_op_dump||5.006000| do_op_xmldump||| do_open9||5.006000| do_openn||5.007001| do_open||5.004000| do_pmop_dump||5.006000| do_pmop_xmldump||| do_print||| do_readline||| do_seek||| do_semop||| do_shmio||| do_smartmatch||| do_spawn_nowait||| do_spawn||| do_sprintf||| do_sv_dump||5.006000| do_sysseek||| do_tell||| do_trans_complex_utf8||| do_trans_complex||| do_trans_count_utf8||| do_trans_count||| do_trans_simple_utf8||| do_trans_simple||| do_trans||| do_vecget||| do_vecset||| do_vop||| docatch||| doeval||| dofile||| dofindlabel||| doform||| doing_taint||5.008001|n dooneliner||| doopen_pm||| doparseform||| dopoptoeval||| dopoptogiven||| dopoptolabel||| dopoptoloop||| dopoptosub_at||| dopoptowhen||| doref||5.009003| dounwind||| dowantarray||| dump_all_perl||| dump_all||5.006000| dump_eval||5.006000| dump_exec_pos||| dump_fds||| dump_form||5.006000| dump_indent||5.006000|v dump_mstats||| dump_packsubs_perl||| dump_packsubs||5.006000| dump_sub_perl||| dump_sub||5.006000| dump_sv_child||| dump_trie_interim_list||| dump_trie_interim_table||| dump_trie||| dump_vindent||5.006000| dumpuntil||| dup_attrlist||| emulate_cop_io||| eval_pv|5.006000||p eval_sv|5.006000||p exec_failed||| expect_number||| fbm_compile||5.005000| fbm_instr||5.005000| feature_is_enabled||| fetch_cop_label||5.011000| filter_add||| filter_del||| filter_gets||| filter_read||| find_and_forget_pmops||| find_array_subscript||| find_beginning||| find_byclass||| find_hash_subscript||| find_in_my_stash||| find_runcv||5.008001| find_rundefsvoffset||5.009002| find_rundefsv||5.013002| find_script||| find_uninit_var||| first_symbol|||n foldEQ_latin1||5.013008|n foldEQ_locale||5.013002|n foldEQ_utf8_flags||5.013010| foldEQ_utf8||5.013002| foldEQ||5.013002|n fold_constants||| forbid_setid||| force_ident||| force_list||| force_next||| force_strict_version||| force_version||| force_word||| forget_pmop||| form_nocontext|||vn form||5.004000|v fp_dup||| fprintf_nocontext|||vn free_global_struct||| free_tied_hv_pool||| free_tmps||| gen_constant_list||| get_aux_mg||| get_av|5.006000||p get_context||5.006000|n get_cvn_flags|5.009005||p get_cvs|5.011000||p get_cv|5.006000||p get_db_sub||| get_debug_opts||| get_hash_seed||| get_hv|5.006000||p get_mstats||| get_no_modify||| get_num||| get_op_descs||5.005000| get_op_names||5.005000| get_opargs||| get_ppaddr||5.006000| get_re_arg||| get_sv|5.006000||p get_vtbl||5.005030| getcwd_sv||5.007002| getenv_len||| glob_2number||| glob_assign_glob||| glob_assign_ref||| gp_dup||| gp_free||| gp_ref||| grok_bin|5.007003||p grok_bslash_c||| grok_bslash_o||| grok_hex|5.007003||p grok_number|5.007002||p grok_numeric_radix|5.007002||p grok_oct|5.007003||p group_end||| gv_AVadd||| gv_HVadd||| gv_IOadd||| gv_SVadd||| gv_add_by_type||5.011000| gv_autoload4||5.004000| gv_check||| gv_const_sv||5.009003| gv_dump||5.006000| gv_efullname3||5.004000| gv_efullname4||5.006001| gv_efullname||| gv_ename||| gv_fetchfile_flags||5.009005| gv_fetchfile||| gv_fetchmeth_autoload||5.007003| gv_fetchmethod_autoload||5.004000| gv_fetchmethod_flags||5.011000| gv_fetchmethod||| gv_fetchmeth||| gv_fetchpvn_flags|5.009002||p gv_fetchpvs|5.009004||p gv_fetchpv||| gv_fetchsv|5.009002||p gv_fullname3||5.004000| gv_fullname4||5.006001| gv_fullname||| gv_get_super_pkg||| gv_handler||5.007001| gv_init_sv||| gv_init||| gv_magicalize_isa||| gv_magicalize_overload||| gv_name_set||5.009004| gv_stashpvn|5.004000||p gv_stashpvs|5.009003||p gv_stashpv||| gv_stashsv||| gv_try_downgrade||| he_dup||| hek_dup||| hfreeentries||| hsplit||| hv_assert||| hv_auxinit|||n hv_backreferences_p||| hv_clear_placeholders||5.009001| hv_clear||| hv_common_key_len||5.010000| hv_common||5.010000| hv_copy_hints_hv||5.009004| hv_delayfree_ent||5.004000| hv_delete_common||| hv_delete_ent||5.004000| hv_delete||| hv_eiter_p||5.009003| hv_eiter_set||5.009003| hv_ename_add||| hv_ename_delete||| hv_exists_ent||5.004000| hv_exists||| hv_fetch_ent||5.004000| hv_fetchs|5.009003||p hv_fetch||| hv_fill||5.013002| hv_free_ent||5.004000| hv_iterinit||| hv_iterkeysv||5.004000| hv_iterkey||| hv_iternext_flags||5.008000| hv_iternextsv||| hv_iternext||| hv_iterval||| hv_kill_backrefs||| hv_ksplit||5.004000| hv_magic_check|||n hv_magic||| hv_name_set||5.009003| hv_notallowed||| hv_placeholders_get||5.009003| hv_placeholders_p||5.009003| hv_placeholders_set||5.009003| hv_riter_p||5.009003| hv_riter_set||5.009003| hv_scalar||5.009001| hv_store_ent||5.004000| hv_store_flags||5.008000| hv_stores|5.009004||p hv_store||| hv_undef_flags||| hv_undef||| ibcmp_locale||5.004000| ibcmp_utf8||5.007003| ibcmp||| incline||| incpush_if_exists||| incpush_use_sep||| incpush||| ingroup||| init_argv_symbols||| init_dbargs||| init_debugger||| init_global_struct||| init_i18nl10n||5.006000| init_i18nl14n||5.006000| init_ids||| init_interp||| init_main_stash||| init_perllib||| init_postdump_symbols||| init_predump_symbols||| init_stacks||5.005000| init_tm||5.007002| instr|||n intro_my||| intuit_method||| intuit_more||| invert||| invlist_array||| invlist_destroy||| invlist_extend||| invlist_intersection||| invlist_len||| invlist_max||| invlist_set_array||| invlist_set_len||| invlist_set_max||| invlist_trim||| invlist_union||| invoke_exception_hook||| io_close||| isALNUMC|5.006000||p isALPHA||| isASCII|5.006000||p isBLANK|5.006001||p isCNTRL|5.006000||p isDIGIT||| isGRAPH|5.006000||p isGV_with_GP|5.009004||p isLOWER||| isOCTAL||5.013005| isPRINT|5.004000||p isPSXSPC|5.006001||p isPUNCT|5.006000||p isSPACE||| isUPPER||| isWORDCHAR||5.013006| isXDIGIT|5.006000||p is_an_int||| is_ascii_string||5.011000|n is_gv_magical_sv||| is_handle_constructor|||n is_inplace_av||| is_list_assignment||| is_lvalue_sub||5.007001| is_uni_alnum_lc||5.006000| is_uni_alnum||5.006000| is_uni_alpha_lc||5.006000| is_uni_alpha||5.006000| is_uni_ascii_lc||5.006000| is_uni_ascii||5.006000| is_uni_cntrl_lc||5.006000| is_uni_cntrl||5.006000| is_uni_digit_lc||5.006000| is_uni_digit||5.006000| is_uni_graph_lc||5.006000| is_uni_graph||5.006000| is_uni_idfirst_lc||5.006000| is_uni_idfirst||5.006000| is_uni_lower_lc||5.006000| is_uni_lower||5.006000| is_uni_print_lc||5.006000| is_uni_print||5.006000| is_uni_punct_lc||5.006000| is_uni_punct||5.006000| is_uni_space_lc||5.006000| is_uni_space||5.006000| is_uni_upper_lc||5.006000| is_uni_upper||5.006000| is_uni_xdigit_lc||5.006000| is_uni_xdigit||5.006000| is_utf8_X_LVT||| is_utf8_X_LV_LVT_V||| is_utf8_X_LV||| is_utf8_X_L||| is_utf8_X_T||| is_utf8_X_V||| is_utf8_X_begin||| is_utf8_X_extend||| is_utf8_X_non_hangul||| is_utf8_X_prepend||| is_utf8_alnum||5.006000| is_utf8_alpha||5.006000| is_utf8_ascii||5.006000| is_utf8_char_slow|||n is_utf8_char||5.006000|n is_utf8_cntrl||5.006000| is_utf8_common||| is_utf8_digit||5.006000| is_utf8_graph||5.006000| is_utf8_idcont||5.008000| is_utf8_idfirst||5.006000| is_utf8_lower||5.006000| is_utf8_mark||5.006000| is_utf8_perl_space||5.011001| is_utf8_perl_word||5.011001| is_utf8_posix_digit||5.011001| is_utf8_print||5.006000| is_utf8_punct||5.006000| is_utf8_space||5.006000| is_utf8_string_loclen||5.009003|n is_utf8_string_loc||5.008001|n is_utf8_string||5.006001|n is_utf8_upper||5.006000| is_utf8_xdigit||5.006000| is_utf8_xidcont||5.013010| is_utf8_xidfirst||5.013010| isa_lookup||| items|||n ix|||n jmaybe||| join_exact||| keyword_plugin_standard||| keyword||| leave_scope||| lex_bufutf8||5.011002| lex_discard_to||5.011002| lex_grow_linestr||5.011002| lex_next_chunk||5.011002| lex_peek_unichar||5.011002| lex_read_space||5.011002| lex_read_to||5.011002| lex_read_unichar||5.011002| lex_start||5.009005| lex_stuff_pvn||5.011002| lex_stuff_pvs||5.013005| lex_stuff_pv||5.013006| lex_stuff_sv||5.011002| lex_unstuff||5.011002| listkids||| list||| load_module_nocontext|||vn load_module|5.006000||pv localize||| looks_like_bool||| looks_like_number||| lop||| mPUSHi|5.009002||p mPUSHn|5.009002||p mPUSHp|5.009002||p mPUSHs|5.010001||p mPUSHu|5.009002||p mXPUSHi|5.009002||p mXPUSHn|5.009002||p mXPUSHp|5.009002||p mXPUSHs|5.010001||p mXPUSHu|5.009002||p mad_free||| madlex||| madparse||| magic_clear_all_env||| magic_clearenv||| magic_clearhints||| magic_clearhint||| magic_clearisa||| magic_clearpack||| magic_clearsig||| magic_dump||5.006000| magic_existspack||| magic_freearylen_p||| magic_freeovrld||| magic_getarylen||| magic_getdefelem||| magic_getnkeys||| magic_getpack||| magic_getpos||| magic_getsig||| magic_getsubstr||| magic_gettaint||| magic_getuvar||| magic_getvec||| magic_get||| magic_killbackrefs||| magic_len||| magic_methcall1||| magic_methcall|||v magic_methpack||| magic_nextpack||| magic_regdata_cnt||| magic_regdatum_get||| magic_regdatum_set||| magic_scalarpack||| magic_set_all_env||| magic_setamagic||| magic_setarylen||| magic_setcollxfrm||| magic_setdbline||| magic_setdefelem||| magic_setenv||| magic_sethint||| magic_setisa||| magic_setmglob||| magic_setnkeys||| magic_setpack||| magic_setpos||| magic_setregexp||| magic_setsig||| magic_setsubstr||| magic_settaint||| magic_setutf8||| magic_setuvar||| magic_setvec||| magic_set||| magic_sizepack||| magic_wipepack||| make_matcher||| make_trie_failtable||| make_trie||| malloc_good_size|||n malloced_size|||n malloc||5.007002|n markstack_grow||| matcher_matches_sv||| measure_struct||| memEQs|5.009005||p memEQ|5.004000||p memNEs|5.009005||p memNE|5.004000||p mem_collxfrm||| mem_log_common|||n mess_alloc||| mess_nocontext|||vn mess_sv||5.013001| mess||5.006000|v method_common||| mfree||5.007002|n mg_clear||| mg_copy||| mg_dup||| mg_findext||5.013008| mg_find||| mg_free_type||5.013006| mg_free||| mg_get||| mg_length||5.005000| mg_localize||| mg_magical||| mg_set||| mg_size||5.005000| mini_mktime||5.007002| missingterm||| mode_from_discipline||| modkids||| mod||| more_bodies||| more_sv||| moreswitches||| mro_clean_isarev||| mro_gather_and_rename||| mro_get_from_name||5.010001| mro_get_linear_isa_dfs||| mro_get_linear_isa||5.009005| mro_get_private_data||5.010001| mro_isa_changed_in||| mro_meta_dup||| mro_meta_init||| mro_method_changed_in||5.009005| mro_package_moved||| mro_register||5.010001| mro_set_mro||5.010001| mro_set_private_data||5.010001| mul128||| mulexp10|||n munge_qwlist_to_paren_list||| my_atof2||5.007002| my_atof||5.006000| my_attrs||| my_bcopy|||n my_betoh16|||n my_betoh32|||n my_betoh64|||n my_betohi|||n my_betohl|||n my_betohs|||n my_bzero|||n my_chsize||| my_clearenv||| my_cxt_index||| my_cxt_init||| my_dirfd||5.009005| my_exit_jump||| my_exit||| my_failure_exit||5.004000| my_fflush_all||5.006000| my_fork||5.007003|n my_htobe16|||n my_htobe32|||n my_htobe64|||n my_htobei|||n my_htobel|||n my_htobes|||n my_htole16|||n my_htole32|||n my_htole64|||n my_htolei|||n my_htolel|||n my_htoles|||n my_htonl||| my_kid||| my_letoh16|||n my_letoh32|||n my_letoh64|||n my_letohi|||n my_letohl|||n my_letohs|||n my_lstat_flags||| my_lstat||5.014000| my_memcmp||5.004000|n my_memset|||n my_ntohl||| my_pclose||5.004000| my_popen_list||5.007001| my_popen||5.004000| my_setenv||| my_snprintf|5.009004||pvn my_socketpair||5.007003|n my_sprintf|5.009003||pvn my_stat_flags||| my_stat||5.014000| my_strftime||5.007002| my_strlcat|5.009004||pn my_strlcpy|5.009004||pn my_swabn|||n my_swap||| my_unexec||| my_vsnprintf||5.009004|n need_utf8|||n newANONATTRSUB||5.006000| newANONHASH||| newANONLIST||| newANONSUB||| newASSIGNOP||| newATTRSUB||5.006000| newAVREF||| newAV||| newBINOP||| newCONDOP||| newCONSTSUB|5.004050||p newCVREF||| newDEFSVOP||| newFORM||| newFOROP||5.013007| newGIVENOP||5.009003| newGIVWHENOP||| newGP||| newGVOP||| newGVREF||| newGVgen||| newHVREF||| newHVhv||5.005000| newHV||| newIO||| newLISTOP||| newLOGOP||| newLOOPEX||| newLOOPOP||| newMADPROP||| newMADsv||| newMYSUB||| newNULLLIST||| newOP||| newPADOP||| newPMOP||| newPROG||| newPVOP||| newRANGE||| newRV_inc|5.004000||p newRV_noinc|5.004000||p newRV||| newSLICEOP||| newSTATEOP||| newSUB||| newSVOP||| newSVREF||| newSV_type|5.009005||p newSVhek||5.009003| newSViv||| newSVnv||| newSVpv_share||5.013006| newSVpvf_nocontext|||vn newSVpvf||5.004000|v newSVpvn_flags|5.010001||p newSVpvn_share|5.007001||p newSVpvn_utf8|5.010001||p newSVpvn|5.004050||p newSVpvs_flags|5.010001||p newSVpvs_share|5.009003||p newSVpvs|5.009003||p newSVpv||| newSVrv||| newSVsv||| newSVuv|5.006000||p newSV||| newTOKEN||| newUNOP||| newWHENOP||5.009003| newWHILEOP||5.013007| newXS_flags||5.009004| newXSproto||5.006000| newXS||5.006000| new_collate||5.006000| new_constant||| new_ctype||5.006000| new_he||| new_logop||| new_numeric||5.006000| new_stackinfo||5.005000| new_version||5.009000| new_warnings_bitfield||| next_symbol||| nextargv||| nextchar||| ninstr|||n no_bareword_allowed||| no_fh_allowed||| no_op||| not_a_number||| nothreadhook||5.008000| nuke_stacks||| num_overflow|||n oopsAV||| oopsHV||| op_append_elem||5.013006| op_append_list||5.013006| op_clear||| op_const_sv||| op_contextualize||5.013006| op_dump||5.006000| op_free||| op_getmad_weak||| op_getmad||| op_linklist||5.013006| op_lvalue||5.013007| op_null||5.007002| op_prepend_elem||5.013006| op_refcnt_dec||| op_refcnt_inc||| op_refcnt_lock||5.009002| op_refcnt_unlock||5.009002| op_scope||5.013007| op_xmldump||| open_script||| opt_scalarhv||| pMY_CXT_|5.007003||p pMY_CXT|5.007003||p pTHX_|5.006000||p pTHX|5.006000||p packWARN|5.007003||p pack_cat||5.007003| pack_rec||| package_version||| package||| packlist||5.008001| pad_add_anon||| pad_add_name_sv||| pad_add_name||| pad_alloc||| pad_block_start||| pad_check_dup||| pad_compname_type||| pad_findlex||| pad_findmy||5.011002| pad_fixup_inner_anons||| pad_free||| pad_leavemy||| pad_new||| pad_peg|||n pad_push||| pad_reset||| pad_setsv||| pad_sv||| pad_swipe||| pad_tidy||| padlist_dup||| parse_arithexpr||5.013008| parse_barestmt||5.013007| parse_block||5.013007| parse_body||| parse_fullexpr||5.013008| parse_fullstmt||5.013005| parse_label||5.013007| parse_listexpr||5.013008| parse_stmtseq||5.013006| parse_termexpr||5.013008| parse_unicode_opts||| parser_dup||| parser_free||| path_is_absolute|||n peep||| pending_Slabs_to_ro||| perl_alloc_using|||n perl_alloc|||n perl_clone_using|||n perl_clone|||n perl_construct|||n perl_destruct||5.007003|n perl_free|||n perl_parse||5.006000|n perl_run|||n pidgone||| pm_description||| pmop_dump||5.006000| pmop_xmldump||| pmruntime||| pmtrans||| pop_scope||| populate_isa|||v pregcomp||5.009005| pregexec||| pregfree2||5.011000| pregfree||| prepend_madprops||| prescan_version||5.011004| printbuf||| printf_nocontext|||vn process_special_blocks||| ptr_table_clear||5.009005| ptr_table_fetch||5.009005| ptr_table_find|||n ptr_table_free||5.009005| ptr_table_new||5.009005| ptr_table_split||5.009005| ptr_table_store||5.009005| push_scope||| put_byte||| pv_display|5.006000||p pv_escape|5.009004||p pv_pretty|5.009004||p pv_uni_display||5.007003| qerror||| qsortsvu||| re_compile||5.009005| re_croak2||| re_dup_guts||| re_intuit_start||5.009005| re_intuit_string||5.006000| readpipe_override||| realloc||5.007002|n reentrant_free||| reentrant_init||| reentrant_retry|||vn reentrant_size||| ref_array_or_hash||| refcounted_he_chain_2hv||| refcounted_he_fetch_pvn||| refcounted_he_fetch_pvs||| refcounted_he_fetch_pv||| refcounted_he_fetch_sv||| refcounted_he_free||| refcounted_he_inc||| refcounted_he_new_pvn||| refcounted_he_new_pvs||| refcounted_he_new_pv||| refcounted_he_new_sv||| refcounted_he_value||| refkids||| refto||| ref||5.014000| reg_check_named_buff_matched||| reg_named_buff_all||5.009005| reg_named_buff_exists||5.009005| reg_named_buff_fetch||5.009005| reg_named_buff_firstkey||5.009005| reg_named_buff_iter||| reg_named_buff_nextkey||5.009005| reg_named_buff_scalar||5.009005| reg_named_buff||| reg_namedseq||| reg_node||| reg_numbered_buff_fetch||| reg_numbered_buff_length||| reg_numbered_buff_store||| reg_qr_package||| reg_recode||| reg_scan_name||| reg_skipcomment||| reg_temp_copy||| reganode||| regatom||| regbranch||| regclass_swash||5.009004| regclass||| regcppop||| regcppush||| regcurly||| regdump_extflags||| regdump||5.005000| regdupe_internal||| regexec_flags||5.005000| regfree_internal||5.009005| reghop3|||n reghop4|||n reghopmaybe3|||n reginclass||| reginitcolors||5.006000| reginsert||| regmatch||| regnext||5.005000| regpiece||| regpposixcc||| regprop||| regrepeat||| regtail_study||| regtail||| regtry||| reguni||| regwhite|||n reg||| repeatcpy|||n report_evil_fh||| report_uninit||| report_wrongway_fh||| require_pv||5.006000| require_tie_mod||| restore_magic||| rninstr|||n rpeep||| rsignal_restore||| rsignal_save||| rsignal_state||5.004000| rsignal||5.004000| run_body||| run_user_filter||| runops_debug||5.005000| runops_standard||5.005000| rv2cv_op_cv||5.013006| rvpv_dup||| rxres_free||| rxres_restore||| rxres_save||| safesyscalloc||5.006000|n safesysfree||5.006000|n safesysmalloc||5.006000|n safesysrealloc||5.006000|n same_dirent||| save_I16||5.004000| save_I32||| save_I8||5.006000| save_adelete||5.011000| save_aelem_flags||5.011000| save_aelem||5.004050| save_alloc||5.006000| save_aptr||| save_ary||| save_bool||5.008001| save_clearsv||| save_delete||| save_destructor_x||5.006000| save_destructor||5.006000| save_freeop||| save_freepv||| save_freesv||| save_generic_pvref||5.006001| save_generic_svref||5.005030| save_gp||5.004000| save_hash||| save_hdelete||5.011000| save_hek_flags|||n save_helem_flags||5.011000| save_helem||5.004050| save_hints||5.010001| save_hptr||| save_int||| save_item||| save_iv||5.005000| save_lines||| save_list||| save_long||| save_magic||| save_mortalizesv||5.007001| save_nogv||| save_op||5.005000| save_padsv_and_mortalize||5.010001| save_pptr||| save_pushi32ptr||5.010001| save_pushptri32ptr||| save_pushptrptr||5.010001| save_pushptr||5.010001| save_re_context||5.006000| save_scalar_at||| save_scalar||| save_set_svflags||5.009000| save_shared_pvref||5.007003| save_sptr||| save_svref||| save_vptr||5.006000| savepvn||| savepvs||5.009003| savepv||| savesharedpvn||5.009005| savesharedpvs||5.013006| savesharedpv||5.007003| savesharedsvpv||5.013006| savestack_grow_cnt||5.008001| savestack_grow||| savesvpv||5.009002| sawparens||| scalar_mod_type|||n scalarboolean||| scalarkids||| scalarseq||| scalarvoid||| scalar||| scan_bin||5.006000| scan_commit||| scan_const||| scan_formline||| scan_heredoc||| scan_hex||| scan_ident||| scan_inputsymbol||| scan_num||5.007001| scan_oct||| scan_pat||| scan_str||| scan_subst||| scan_trans||| scan_version||5.009001| scan_vstring||5.009005| scan_word||| screaminstr||5.005000| search_const||| seed||5.008001| sequence_num||| sequence_tail||| sequence||| set_context||5.006000|n set_numeric_local||5.006000| set_numeric_radix||5.006000| set_numeric_standard||5.006000| set_regclass_bit_fold||| set_regclass_bit||| setdefout||| share_hek_flags||| share_hek||5.004000| si_dup||| sighandler|||n simplify_sort||| skipspace0||| skipspace1||| skipspace2||| skipspace||| softref2xv||| sortcv_stacked||| sortcv_xsub||| sortcv||| sortsv_flags||5.009003| sortsv||5.007003| space_join_names_mortal||| ss_dup||| stack_grow||| start_force||| start_glob||| start_subparse||5.004000| stashpv_hvname_match||5.014000| stdize_locale||| store_cop_label||| strEQ||| strGE||| strGT||| strLE||| strLT||| strNE||| str_to_version||5.006000| strip_return||| strnEQ||| strnNE||| study_chunk||| sub_crush_depth||| sublex_done||| sublex_push||| sublex_start||| sv_2bool_flags||5.013006| sv_2bool||| sv_2cv||| sv_2io||| sv_2iuv_common||| sv_2iuv_non_preserve||| sv_2iv_flags||5.009001| sv_2iv||| sv_2mortal||| sv_2num||| sv_2nv_flags||5.013001| sv_2pv_flags|5.007002||p sv_2pv_nolen|5.006000||p sv_2pvbyte_nolen|5.006000||p sv_2pvbyte|5.006000||p sv_2pvutf8_nolen||5.006000| sv_2pvutf8||5.006000| sv_2pv||| sv_2uv_flags||5.009001| sv_2uv|5.004000||p sv_add_arena||| sv_add_backref||| sv_backoff||| sv_bless||| sv_cat_decode||5.008001| sv_catpv_flags||5.013006| sv_catpv_mg|5.004050||p sv_catpv_nomg||5.013006| sv_catpvf_mg_nocontext|||pvn sv_catpvf_mg|5.006000|5.004000|pv sv_catpvf_nocontext|||vn sv_catpvf||5.004000|v sv_catpvn_flags||5.007002| sv_catpvn_mg|5.004050||p sv_catpvn_nomg|5.007002||p sv_catpvn||| sv_catpvs_flags||5.013006| sv_catpvs_mg||5.013006| sv_catpvs_nomg||5.013006| sv_catpvs|5.009003||p sv_catpv||| sv_catsv_flags||5.007002| sv_catsv_mg|5.004050||p sv_catsv_nomg|5.007002||p sv_catsv||| sv_catxmlpvn||| sv_catxmlpv||| sv_catxmlsv||| sv_chop||| sv_clean_all||| sv_clean_objs||| sv_clear||| sv_cmp_flags||5.013006| sv_cmp_locale_flags||5.013006| sv_cmp_locale||5.004000| sv_cmp||| sv_collxfrm_flags||5.013006| sv_collxfrm||| sv_compile_2op_is_broken||| sv_compile_2op||5.008001| sv_copypv||5.007003| sv_dec_nomg||5.013002| sv_dec||| sv_del_backref||| sv_derived_from||5.004000| sv_destroyable||5.010000| sv_does||5.009004| sv_dump||| sv_dup_common||| sv_dup_inc_multiple||| sv_dup_inc||| sv_dup||| sv_eq_flags||5.013006| sv_eq||| sv_exp_grow||| sv_force_normal_flags||5.007001| sv_force_normal||5.006000| sv_free2||| sv_free_arenas||| sv_free||| sv_gets||5.004000| sv_grow||| sv_i_ncmp||| sv_inc_nomg||5.013002| sv_inc||| sv_insert_flags||5.010001| sv_insert||| sv_isa||| sv_isobject||| sv_iv||5.005000| sv_kill_backrefs||| sv_len_utf8||5.006000| sv_len||| sv_magic_portable|5.014000|5.004000|p sv_magicext||5.007003| sv_magic||| sv_mortalcopy||| sv_ncmp||| sv_newmortal||| sv_newref||| sv_nolocking||5.007003| sv_nosharing||5.007003| sv_nounlocking||| sv_nv||5.005000| sv_peek||5.005000| sv_pos_b2u_midway||| sv_pos_b2u||5.006000| sv_pos_u2b_cached||| sv_pos_u2b_flags||5.011005| sv_pos_u2b_forwards|||n sv_pos_u2b_midway|||n sv_pos_u2b||5.006000| sv_pvbyten_force||5.006000| sv_pvbyten||5.006000| sv_pvbyte||5.006000| sv_pvn_force_flags|5.007002||p sv_pvn_force||| sv_pvn_nomg|5.007003|5.005000|p sv_pvn||5.005000| sv_pvutf8n_force||5.006000| sv_pvutf8n||5.006000| sv_pvutf8||5.006000| sv_pv||5.006000| sv_recode_to_utf8||5.007003| sv_reftype||| sv_release_COW||| sv_replace||| sv_report_used||| sv_reset||| sv_rvweaken||5.006000| sv_setiv_mg|5.004050||p sv_setiv||| sv_setnv_mg|5.006000||p sv_setnv||| sv_setpv_mg|5.004050||p sv_setpvf_mg_nocontext|||pvn sv_setpvf_mg|5.006000|5.004000|pv sv_setpvf_nocontext|||vn sv_setpvf||5.004000|v sv_setpviv_mg||5.008001| sv_setpviv||5.008001| sv_setpvn_mg|5.004050||p sv_setpvn||| sv_setpvs_mg||5.013006| sv_setpvs|5.009004||p sv_setpv||| sv_setref_iv||| sv_setref_nv||| sv_setref_pvn||| sv_setref_pvs||5.013006| sv_setref_pv||| sv_setref_uv||5.007001| sv_setsv_cow||| sv_setsv_flags||5.007002| sv_setsv_mg|5.004050||p sv_setsv_nomg|5.007002||p sv_setsv||| sv_setuv_mg|5.004050||p sv_setuv|5.004000||p sv_tainted||5.004000| sv_taint||5.004000| sv_true||5.005000| sv_unglob||| sv_uni_display||5.007003| sv_unmagicext||5.013008| sv_unmagic||| sv_unref_flags||5.007001| sv_unref||| sv_untaint||5.004000| sv_upgrade||| sv_usepvn_flags||5.009004| sv_usepvn_mg|5.004050||p sv_usepvn||| sv_utf8_decode||5.006000| sv_utf8_downgrade||5.006000| sv_utf8_encode||5.006000| sv_utf8_upgrade_flags_grow||5.011000| sv_utf8_upgrade_flags||5.007002| sv_utf8_upgrade_nomg||5.007002| sv_utf8_upgrade||5.007001| sv_uv|5.005000||p sv_vcatpvf_mg|5.006000|5.004000|p sv_vcatpvfn||5.004000| sv_vcatpvf|5.006000|5.004000|p sv_vsetpvf_mg|5.006000|5.004000|p sv_vsetpvfn||5.004000| sv_vsetpvf|5.006000|5.004000|p sv_xmlpeek||| svtype||| swallow_bom||| swash_fetch||5.007002| swash_get||| swash_init||5.006000| sys_init3||5.010000|n sys_init||5.010000|n sys_intern_clear||| sys_intern_dup||| sys_intern_init||| sys_term||5.010000|n taint_env||| taint_proper||| tied_method|||v tmps_grow||5.006000| toLOWER||| toUPPER||| to_byte_substr||| to_uni_fold||5.007003| to_uni_lower_lc||5.006000| to_uni_lower||5.007003| to_uni_title_lc||5.006000| to_uni_title||5.007003| to_uni_upper_lc||5.006000| to_uni_upper||5.007003| to_utf8_case||5.007003| to_utf8_fold||5.007003| to_utf8_lower||5.007003| to_utf8_substr||| to_utf8_title||5.007003| to_utf8_upper||5.007003| token_free||| token_getmad||| tokenize_use||| tokeq||| tokereport||| too_few_arguments||| too_many_arguments||| try_amagic_bin||| try_amagic_un||| uiv_2buf|||n unlnk||| unpack_rec||| unpack_str||5.007003| unpackstring||5.008001| unreferenced_to_tmp_stack||| unshare_hek_or_pvn||| unshare_hek||| unsharepvn||5.004000| unwind_handler_stack||| update_debugger_info||| upg_version||5.009005| usage||| utf16_textfilter||| utf16_to_utf8_reversed||5.006001| utf16_to_utf8||5.006001| utf8_distance||5.006000| utf8_hop||5.006000| utf8_length||5.007001| utf8_mg_len_cache_update||| utf8_mg_pos_cache_update||| utf8_to_bytes||5.006001| utf8_to_uvchr||5.007001| utf8_to_uvuni||5.007001| utf8n_to_uvchr||| utf8n_to_uvuni||5.007001| utilize||| uvchr_to_utf8_flags||5.007003| uvchr_to_utf8||| uvuni_to_utf8_flags||5.007003| uvuni_to_utf8||5.007001| validate_suid||| varname||| vcmp||5.009000| vcroak||5.006000| vdeb||5.007003| vform||5.006000| visit||| vivify_defelem||| vivify_ref||| vload_module|5.006000||p vmess||5.006000| vnewSVpvf|5.006000|5.004000|p vnormal||5.009002| vnumify||5.009000| vstringify||5.009000| vverify||5.009003| vwarner||5.006000| vwarn||5.006000| wait4pid||| warn_nocontext|||vn warn_sv||5.013001| warner_nocontext|||vn warner|5.006000|5.004000|pv warn|||v watch||| whichsig||| with_queued_errors||| write_no_mem||| write_to_stderr||| xmldump_all_perl||| xmldump_all||| xmldump_attr||| xmldump_eval||| xmldump_form||| xmldump_indent|||v xmldump_packsubs_perl||| xmldump_packsubs||| xmldump_sub_perl||| xmldump_sub||| xmldump_vindent||| xs_apiversion_bootcheck||| xs_version_bootcheck||| yyerror||| yylex||| yyparse||| yyunlex||| yywarn||| ); if (exists $opt{'list-unsupported'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{todo}; print "$f ", '.'x(40-length($f)), " ", format_version($API{$f}{todo}), "\n"; } exit 0; } # Scan for possible replacement candidates my(%replace, %need, %hints, %warnings, %depends); my $replace = 0; my($hint, $define, $function); sub find_api { my $code = shift; $code =~ s{ / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*) | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' }{}egsx; grep { exists $API{$_} } $code =~ /(\w+)/mg; } while () { if ($hint) { my $h = $hint->[0] eq 'Hint' ? \%hints : \%warnings; if (m{^\s*\*\s(.*?)\s*$}) { for (@{$hint->[1]}) { $h->{$_} ||= ''; # suppress warning with older perls $h->{$_} .= "$1\n"; } } else { undef $hint } } $hint = [$1, [split /,?\s+/, $2]] if m{^\s*$rccs\s+(Hint|Warning):\s+(\w+(?:,?\s+\w+)*)\s*$}; if ($define) { if ($define->[1] =~ /\\$/) { $define->[1] .= $_; } else { if (exists $API{$define->[0]} && $define->[1] !~ /^DPPP_\(/) { my @n = find_api($define->[1]); push @{$depends{$define->[0]}}, @n if @n } undef $define; } } $define = [$1, $2] if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(.*)}; if ($function) { if (/^}/) { if (exists $API{$function->[0]}) { my @n = find_api($function->[1]); push @{$depends{$function->[0]}}, @n if @n } undef $function; } else { $function->[1] .= $_; } } $function = [$1, ''] if m{^DPPP_\(my_(\w+)\)}; $replace = $1 if m{^\s*$rccs\s+Replace:\s+(\d+)\s+$rcce\s*$}; $replace{$2} = $1 if $replace and m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+)}; $replace{$2} = $1 if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+).*$rccs\s+Replace\s+$rcce}; $replace{$1} = $2 if m{^\s*$rccs\s+Replace (\w+) with (\w+)\s+$rcce\s*$}; if (m{^\s*$rccs\s+(\w+(\s*,\s*\w+)*)\s+depends\s+on\s+(\w+(\s*,\s*\w+)*)\s+$rcce\s*$}) { my @deps = map { s/\s+//g; $_ } split /,/, $3; my $d; for $d (map { s/\s+//g; $_ } split /,/, $1) { push @{$depends{$d}}, @deps; } } $need{$1} = 1 if m{^#if\s+defined\(NEED_(\w+)(?:_GLOBAL)?\)}; } for (values %depends) { my %s; $_ = [sort grep !$s{$_}++, @$_]; } if (exists $opt{'api-info'}) { my $f; my $count = 0; my $match = $opt{'api-info'} =~ m!^/(.*)/$! ? $1 : "^\Q$opt{'api-info'}\E\$"; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $f =~ /$match/; print "\n=== $f ===\n\n"; my $info = 0; if ($API{$f}{base} || $API{$f}{todo}) { my $base = format_version($API{$f}{base} || $API{$f}{todo}); print "Supported at least starting from perl-$base.\n"; $info++; } if ($API{$f}{provided}) { my $todo = $API{$f}{todo} ? format_version($API{$f}{todo}) : "5.003"; print "Support by $ppport provided back to perl-$todo.\n"; print "Support needs to be explicitly requested by NEED_$f.\n" if exists $need{$f}; print "Depends on: ", join(', ', @{$depends{$f}}), ".\n" if exists $depends{$f}; print "\n$hints{$f}" if exists $hints{$f}; print "\nWARNING:\n$warnings{$f}" if exists $warnings{$f}; $info++; } print "No portability information available.\n" unless $info; $count++; } $count or print "Found no API matching '$opt{'api-info'}'."; print "\n"; exit 0; } if (exists $opt{'list-provided'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{provided}; my @flags; push @flags, 'explicit' if exists $need{$f}; push @flags, 'depend' if exists $depends{$f}; push @flags, 'hint' if exists $hints{$f}; push @flags, 'warning' if exists $warnings{$f}; my $flags = @flags ? ' ['.join(', ', @flags).']' : ''; print "$f$flags\n"; } exit 0; } my @files; my @srcext = qw( .xs .c .h .cc .cpp -c.inc -xs.inc ); my $srcext = join '|', map { quotemeta $_ } @srcext; if (@ARGV) { my %seen; for (@ARGV) { if (-e) { if (-f) { push @files, $_ unless $seen{$_}++; } else { warn "'$_' is not a file.\n" } } else { my @new = grep { -f } glob $_ or warn "'$_' does not exist.\n"; push @files, grep { !$seen{$_}++ } @new; } } } else { eval { require File::Find; File::Find::find(sub { $File::Find::name =~ /($srcext)$/i and push @files, $File::Find::name; }, '.'); }; if ($@) { @files = map { glob "*$_" } @srcext; } } if (!@ARGV || $opt{filter}) { my(@in, @out); my %xsc = map { /(.*)\.xs$/ ? ("$1.c" => 1, "$1.cc" => 1) : () } @files; for (@files) { my $out = exists $xsc{$_} || /\b\Q$ppport\E$/i || !/($srcext)$/i; push @{ $out ? \@out : \@in }, $_; } if (@ARGV && @out) { warning("Skipping the following files (use --nofilter to avoid this):\n| ", join "\n| ", @out); } @files = @in; } die "No input files given!\n" unless @files; my(%files, %global, %revreplace); %revreplace = reverse %replace; my $filename; my $patch_opened = 0; for $filename (@files) { unless (open IN, "<$filename") { warn "Unable to read from $filename: $!\n"; next; } info("Scanning $filename ..."); my $c = do { local $/; }; close IN; my %file = (orig => $c, changes => 0); # Temporarily remove C/XS comments and strings from the code my @ccom; $c =~ s{ ( ^$HS*\#$HS*include\b[^\r\n]+\b(?:\Q$ppport\E|XSUB\.h)\b[^\r\n]* | ^$HS*\#$HS*(?:define|elif|if(?:def)?)\b[^\r\n]* ) | ( ^$HS*\#[^\r\n]* | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' | / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]* ) ) }{ defined $2 and push @ccom, $2; defined $1 ? $1 : "$ccs$#ccom$cce" }mgsex; $file{ccom} = \@ccom; $file{code} = $c; $file{has_inc_ppport} = $c =~ /^$HS*#$HS*include[^\r\n]+\b\Q$ppport\E\b/m; my $func; for $func (keys %API) { my $match = $func; $match .= "|$revreplace{$func}" if exists $revreplace{$func}; if ($c =~ /\b(?:Perl_)?($match)\b/) { $file{uses_replace}{$1}++ if exists $revreplace{$func} && $1 eq $revreplace{$func}; $file{uses_Perl}{$func}++ if $c =~ /\bPerl_$func\b/; if (exists $API{$func}{provided}) { $file{uses_provided}{$func}++; if (!exists $API{$func}{base} || $API{$func}{base} > $opt{'compat-version'}) { $file{uses}{$func}++; my @deps = rec_depend($func); if (@deps) { $file{uses_deps}{$func} = \@deps; for (@deps) { $file{uses}{$_} = 0 unless exists $file{uses}{$_}; } } for ($func, @deps) { $file{needs}{$_} = 'static' if exists $need{$_}; } } } if (exists $API{$func}{todo} && $API{$func}{todo} > $opt{'compat-version'}) { if ($c =~ /\b$func\b/) { $file{uses_todo}{$func}++; } } } } while ($c =~ /^$HS*#$HS*define$HS+(NEED_(\w+?)(_GLOBAL)?)\b/mg) { if (exists $need{$2}) { $file{defined $3 ? 'needed_global' : 'needed_static'}{$2}++; } else { warning("Possibly wrong #define $1 in $filename") } } for (qw(uses needs uses_todo needed_global needed_static)) { for $func (keys %{$file{$_}}) { push @{$global{$_}{$func}}, $filename; } } $files{$filename} = \%file; } # Globally resolve NEED_'s my $need; for $need (keys %{$global{needs}}) { if (@{$global{needs}{$need}} > 1) { my @targets = @{$global{needs}{$need}}; my @t = grep $files{$_}{needed_global}{$need}, @targets; @targets = @t if @t; @t = grep /\.xs$/i, @targets; @targets = @t if @t; my $target = shift @targets; $files{$target}{needs}{$need} = 'global'; for (@{$global{needs}{$need}}) { $files{$_}{needs}{$need} = 'extern' if $_ ne $target; } } } for $filename (@files) { exists $files{$filename} or next; info("=== Analyzing $filename ==="); my %file = %{$files{$filename}}; my $func; my $c = $file{code}; my $warnings = 0; for $func (sort keys %{$file{uses_Perl}}) { if ($API{$func}{varargs}) { unless ($API{$func}{nothxarg}) { my $changes = ($c =~ s{\b(Perl_$func\s*\(\s*)(?!aTHX_?)(\)|[^\s)]*\))} { $1 . ($2 eq ')' ? 'aTHX' : 'aTHX_ ') . $2 }ge); if ($changes) { warning("Doesn't pass interpreter argument aTHX to Perl_$func"); $file{changes} += $changes; } } } else { warning("Uses Perl_$func instead of $func"); $file{changes} += ($c =~ s{\bPerl_$func(\s*)\((\s*aTHX_?)?\s*} {$func$1(}g); } } for $func (sort keys %{$file{uses_replace}}) { warning("Uses $func instead of $replace{$func}"); $file{changes} += ($c =~ s/\b$func\b/$replace{$func}/g); } for $func (sort keys %{$file{uses_provided}}) { if ($file{uses}{$func}) { if (exists $file{uses_deps}{$func}) { diag("Uses $func, which depends on ", join(', ', @{$file{uses_deps}{$func}})); } else { diag("Uses $func"); } } $warnings += hint($func); } unless ($opt{quiet}) { for $func (sort keys %{$file{uses_todo}}) { print "*** WARNING: Uses $func, which may not be portable below perl ", format_version($API{$func}{todo}), ", even with '$ppport'\n"; $warnings++; } } for $func (sort keys %{$file{needed_static}}) { my $message = ''; if (not exists $file{uses}{$func}) { $message = "No need to define NEED_$func if $func is never used"; } elsif (exists $file{needs}{$func} && $file{needs}{$func} ne 'static') { $message = "No need to define NEED_$func when already needed globally"; } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_$func\b.*$LF//mg); } } for $func (sort keys %{$file{needed_global}}) { my $message = ''; if (not exists $global{uses}{$func}) { $message = "No need to define NEED_${func}_GLOBAL if $func is never used"; } elsif (exists $file{needs}{$func}) { if ($file{needs}{$func} eq 'extern') { $message = "No need to define NEED_${func}_GLOBAL when already needed globally"; } elsif ($file{needs}{$func} eq 'static') { $message = "No need to define NEED_${func}_GLOBAL when only used in this file"; } } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_${func}_GLOBAL\b.*$LF//mg); } } $file{needs_inc_ppport} = keys %{$file{uses}}; if ($file{needs_inc_ppport}) { my $pp = ''; for $func (sort keys %{$file{needs}}) { my $type = $file{needs}{$func}; next if $type eq 'extern'; my $suffix = $type eq 'global' ? '_GLOBAL' : ''; unless (exists $file{"needed_$type"}{$func}) { if ($type eq 'global') { diag("Files [@{$global{needs}{$func}}] need $func, adding global request"); } else { diag("File needs $func, adding static request"); } $pp .= "#define NEED_$func$suffix\n"; } } if ($pp && ($c =~ s/^(?=$HS*#$HS*define$HS+NEED_\w+)/$pp/m)) { $pp = ''; $file{changes}++; } unless ($file{has_inc_ppport}) { diag("Needs to include '$ppport'"); $pp .= qq(#include "$ppport"\n) } if ($pp) { $file{changes} += ($c =~ s/^($HS*#$HS*define$HS+NEED_\w+.*?)^/$1$pp/ms) || ($c =~ s/^(?=$HS*#$HS*include.*\Q$ppport\E)/$pp/m) || ($c =~ s/^($HS*#$HS*include.*XSUB.*\s*?)^/$1$pp/m) || ($c =~ s/^/$pp/); } } else { if ($file{has_inc_ppport}) { diag("No need to include '$ppport'"); $file{changes} += ($c =~ s/^$HS*?#$HS*include.*\Q$ppport\E.*?$LF//m); } } # put back in our C comments my $ix; my $cppc = 0; my @ccom = @{$file{ccom}}; for $ix (0 .. $#ccom) { if (!$opt{cplusplus} && $ccom[$ix] =~ s!^//!!) { $cppc++; $file{changes} += $c =~ s/$rccs$ix$rcce/$ccs$ccom[$ix] $cce/; } else { $c =~ s/$rccs$ix$rcce/$ccom[$ix]/; } } if ($cppc) { my $s = $cppc != 1 ? 's' : ''; warning("Uses $cppc C++ style comment$s, which is not portable"); } my $s = $warnings != 1 ? 's' : ''; my $warn = $warnings ? " ($warnings warning$s)" : ''; info("Analysis completed$warn"); if ($file{changes}) { if (exists $opt{copy}) { my $newfile = "$filename$opt{copy}"; if (-e $newfile) { error("'$newfile' already exists, refusing to write copy of '$filename'"); } else { local *F; if (open F, ">$newfile") { info("Writing copy of '$filename' with changes to '$newfile'"); print F $c; close F; } else { error("Cannot open '$newfile' for writing: $!"); } } } elsif (exists $opt{patch} || $opt{changes}) { if (exists $opt{patch}) { unless ($patch_opened) { if (open PATCH, ">$opt{patch}") { $patch_opened = 1; } else { error("Cannot open '$opt{patch}' for writing: $!"); delete $opt{patch}; $opt{changes} = 1; goto fallback; } } mydiff(\*PATCH, $filename, $c); } else { fallback: info("Suggested changes:"); mydiff(\*STDOUT, $filename, $c); } } else { my $s = $file{changes} == 1 ? '' : 's'; info("$file{changes} potentially required change$s detected"); } } else { info("Looks good"); } } close PATCH if $patch_opened; exit 0; sub try_use { eval "use @_;"; return $@ eq '' } sub mydiff { local *F = shift; my($file, $str) = @_; my $diff; if (exists $opt{diff}) { $diff = run_diff($opt{diff}, $file, $str); } if (!defined $diff and try_use('Text::Diff')) { $diff = Text::Diff::diff($file, \$str, { STYLE => 'Unified' }); $diff = <
$tmp") { print F $str; close F; if (open F, "$prog $file $tmp |") { while () { s/\Q$tmp\E/$file.patched/; $diff .= $_; } close F; unlink $tmp; return $diff; } unlink $tmp; } else { error("Cannot open '$tmp' for writing: $!"); } return undef; } sub rec_depend { my($func, $seen) = @_; return () unless exists $depends{$func}; $seen = {%{$seen||{}}}; return () if $seen->{$func}++; my %s; grep !$s{$_}++, map { ($_, rec_depend($_, $seen)) } @{$depends{$func}}; } sub parse_version { my $ver = shift; if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) { return ($1, $2, $3); } elsif ($ver !~ /^\d+\.[\d_]+$/) { die "cannot parse version '$ver'\n"; } $ver =~ s/_//g; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "cannot parse version '$ver'\n"; } } return ($r, $v, $s); } sub format_version { my $ver = shift; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "invalid version '$ver'\n"; } $s /= 10; $ver = sprintf "%d.%03d", $r, $v; $s > 0 and $ver .= sprintf "_%02d", $s; return $ver; } return sprintf "%d.%d.%d", $r, $v, $s; } sub info { $opt{quiet} and return; print @_, "\n"; } sub diag { $opt{quiet} and return; $opt{diag} and print @_, "\n"; } sub warning { $opt{quiet} and return; print "*** ", @_, "\n"; } sub error { print "*** ERROR: ", @_, "\n"; } my %given_hints; my %given_warnings; sub hint { $opt{quiet} and return; my $func = shift; my $rv = 0; if (exists $warnings{$func} && !$given_warnings{$func}++) { my $warn = $warnings{$func}; $warn =~ s!^!*** !mg; print "*** WARNING: $func\n", $warn; $rv++; } if ($opt{hints} && exists $hints{$func} && !$given_hints{$func}++) { my $hint = $hints{$func}; $hint =~ s/^/ /mg; print " --- hint for $func ---\n", $hint; } $rv; } sub usage { my($usage) = do { local(@ARGV,$/)=($0); <> } =~ /^=head\d$HS+SYNOPSIS\s*^(.*?)\s*^=/ms; my %M = ( 'I' => '*' ); $usage =~ s/^\s*perl\s+\S+/$^X $0/; $usage =~ s/([A-Z])<([^>]+)>/$M{$1}$2$M{$1}/g; print < }; my($copy) = $self =~ /^=head\d\s+COPYRIGHT\s*^(.*?)^=\w+/ms; $copy =~ s/^(?=\S+)/ /gms; $self =~ s/^$HS+Do NOT edit.*?(?=^-)/$copy/ms; $self =~ s/^SKIP.*(?=^__DATA__)/SKIP if (\@ARGV && \$ARGV[0] eq '--unstrip') { eval { require Devel::PPPort }; \$@ and die "Cannot require Devel::PPPort, please install.\\n"; if (eval \$Devel::PPPort::VERSION < $VERSION) { die "$0 was originally generated with Devel::PPPort $VERSION.\\n" . "Your Devel::PPPort is only version \$Devel::PPPort::VERSION.\\n" . "Please install a newer version, or --unstrip will not work.\\n"; } Devel::PPPort::WriteFile(\$0); exit 0; } print <$0" or die "cannot strip $0: $!\n"; print OUT "$pl$c\n"; exit 0; } __DATA__ */ #ifndef _P_P_PORTABILITY_H_ #define _P_P_PORTABILITY_H_ #ifndef DPPP_NAMESPACE # define DPPP_NAMESPACE DPPP_ #endif #define DPPP_CAT2(x,y) CAT2(x,y) #define DPPP_(name) DPPP_CAT2(DPPP_NAMESPACE, name) #ifndef PERL_REVISION # if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION)) # define PERL_PATCHLEVEL_H_IMPLICIT # include # endif # if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL))) # include # endif # ifndef PERL_REVISION # define PERL_REVISION (5) /* Replace: 1 */ # define PERL_VERSION PATCHLEVEL # define PERL_SUBVERSION SUBVERSION /* Replace PERL_PATCHLEVEL with PERL_VERSION */ /* Replace: 0 */ # endif #endif #define _dpppDEC2BCD(dec) ((((dec)/100)<<8)|((((dec)%100)/10)<<4)|((dec)%10)) #define PERL_BCDVERSION ((_dpppDEC2BCD(PERL_REVISION)<<24)|(_dpppDEC2BCD(PERL_VERSION)<<12)|_dpppDEC2BCD(PERL_SUBVERSION)) /* It is very unlikely that anyone will try to use this with Perl 6 (or greater), but who knows. */ #if PERL_REVISION != 5 # error ppport.h only works with Perl version 5 #endif /* PERL_REVISION != 5 */ #ifndef dTHR # define dTHR dNOOP #endif #ifndef dTHX # define dTHX dNOOP #endif #ifndef dTHXa # define dTHXa(x) dNOOP #endif #ifndef pTHX # define pTHX void #endif #ifndef pTHX_ # define pTHX_ #endif #ifndef aTHX # define aTHX #endif #ifndef aTHX_ # define aTHX_ #endif #if (PERL_BCDVERSION < 0x5006000) # ifdef USE_THREADS # define aTHXR thr # define aTHXR_ thr, # else # define aTHXR # define aTHXR_ # endif # define dTHXR dTHR #else # define aTHXR aTHX # define aTHXR_ aTHX_ # define dTHXR dTHX #endif #ifndef dTHXoa # define dTHXoa(x) dTHXa(x) #endif #ifdef I_LIMITS # include #endif #ifndef PERL_UCHAR_MIN # define PERL_UCHAR_MIN ((unsigned char)0) #endif #ifndef PERL_UCHAR_MAX # ifdef UCHAR_MAX # define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX) # else # ifdef MAXUCHAR # define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR) # else # define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0) # endif # endif #endif #ifndef PERL_USHORT_MIN # define PERL_USHORT_MIN ((unsigned short)0) #endif #ifndef PERL_USHORT_MAX # ifdef USHORT_MAX # define PERL_USHORT_MAX ((unsigned short)USHORT_MAX) # else # ifdef MAXUSHORT # define PERL_USHORT_MAX ((unsigned short)MAXUSHORT) # else # ifdef USHRT_MAX # define PERL_USHORT_MAX ((unsigned short)USHRT_MAX) # else # define PERL_USHORT_MAX ((unsigned short)~(unsigned)0) # endif # endif # endif #endif #ifndef PERL_SHORT_MAX # ifdef SHORT_MAX # define PERL_SHORT_MAX ((short)SHORT_MAX) # else # ifdef MAXSHORT /* Often used in */ # define PERL_SHORT_MAX ((short)MAXSHORT) # else # ifdef SHRT_MAX # define PERL_SHORT_MAX ((short)SHRT_MAX) # else # define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1)) # endif # endif # endif #endif #ifndef PERL_SHORT_MIN # ifdef SHORT_MIN # define PERL_SHORT_MIN ((short)SHORT_MIN) # else # ifdef MINSHORT # define PERL_SHORT_MIN ((short)MINSHORT) # else # ifdef SHRT_MIN # define PERL_SHORT_MIN ((short)SHRT_MIN) # else # define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif #ifndef PERL_UINT_MAX # ifdef UINT_MAX # define PERL_UINT_MAX ((unsigned int)UINT_MAX) # else # ifdef MAXUINT # define PERL_UINT_MAX ((unsigned int)MAXUINT) # else # define PERL_UINT_MAX (~(unsigned int)0) # endif # endif #endif #ifndef PERL_UINT_MIN # define PERL_UINT_MIN ((unsigned int)0) #endif #ifndef PERL_INT_MAX # ifdef INT_MAX # define PERL_INT_MAX ((int)INT_MAX) # else # ifdef MAXINT /* Often used in */ # define PERL_INT_MAX ((int)MAXINT) # else # define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1)) # endif # endif #endif #ifndef PERL_INT_MIN # ifdef INT_MIN # define PERL_INT_MIN ((int)INT_MIN) # else # ifdef MININT # define PERL_INT_MIN ((int)MININT) # else # define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3)) # endif # endif #endif #ifndef PERL_ULONG_MAX # ifdef ULONG_MAX # define PERL_ULONG_MAX ((unsigned long)ULONG_MAX) # else # ifdef MAXULONG # define PERL_ULONG_MAX ((unsigned long)MAXULONG) # else # define PERL_ULONG_MAX (~(unsigned long)0) # endif # endif #endif #ifndef PERL_ULONG_MIN # define PERL_ULONG_MIN ((unsigned long)0L) #endif #ifndef PERL_LONG_MAX # ifdef LONG_MAX # define PERL_LONG_MAX ((long)LONG_MAX) # else # ifdef MAXLONG # define PERL_LONG_MAX ((long)MAXLONG) # else # define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1)) # endif # endif #endif #ifndef PERL_LONG_MIN # ifdef LONG_MIN # define PERL_LONG_MIN ((long)LONG_MIN) # else # ifdef MINLONG # define PERL_LONG_MIN ((long)MINLONG) # else # define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) # endif # endif #endif #if defined(HAS_QUAD) && (defined(convex) || defined(uts)) # ifndef PERL_UQUAD_MAX # ifdef ULONGLONG_MAX # define PERL_UQUAD_MAX ((unsigned long long)ULONGLONG_MAX) # else # ifdef MAXULONGLONG # define PERL_UQUAD_MAX ((unsigned long long)MAXULONGLONG) # else # define PERL_UQUAD_MAX (~(unsigned long long)0) # endif # endif # endif # ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN ((unsigned long long)0L) # endif # ifndef PERL_QUAD_MAX # ifdef LONGLONG_MAX # define PERL_QUAD_MAX ((long long)LONGLONG_MAX) # else # ifdef MAXLONGLONG # define PERL_QUAD_MAX ((long long)MAXLONGLONG) # else # define PERL_QUAD_MAX ((long long) (PERL_UQUAD_MAX >> 1)) # endif # endif # endif # ifndef PERL_QUAD_MIN # ifdef LONGLONG_MIN # define PERL_QUAD_MIN ((long long)LONGLONG_MIN) # else # ifdef MINLONGLONG # define PERL_QUAD_MIN ((long long)MINLONGLONG) # else # define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif /* This is based on code from 5.003 perl.h */ #ifdef HAS_QUAD # ifdef cray #ifndef IVTYPE # define IVTYPE int #endif #ifndef IV_MIN # define IV_MIN PERL_INT_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_INT_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UINT_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UINT_MAX #endif # ifdef INTSIZE #ifndef IVSIZE # define IVSIZE INTSIZE #endif # endif # else # if defined(convex) || defined(uts) #ifndef IVTYPE # define IVTYPE long long #endif #ifndef IV_MIN # define IV_MIN PERL_QUAD_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_QUAD_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UQUAD_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UQUAD_MAX #endif # ifdef LONGLONGSIZE #ifndef IVSIZE # define IVSIZE LONGLONGSIZE #endif # endif # else #ifndef IVTYPE # define IVTYPE long #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif # ifdef LONGSIZE #ifndef IVSIZE # define IVSIZE LONGSIZE #endif # endif # endif # endif #ifndef IVSIZE # define IVSIZE 8 #endif #ifndef PERL_QUAD_MIN # define PERL_QUAD_MIN IV_MIN #endif #ifndef PERL_QUAD_MAX # define PERL_QUAD_MAX IV_MAX #endif #ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN UV_MIN #endif #ifndef PERL_UQUAD_MAX # define PERL_UQUAD_MAX UV_MAX #endif #else #ifndef IVTYPE # define IVTYPE long #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif #endif #ifndef IVSIZE # ifdef LONGSIZE # define IVSIZE LONGSIZE # else # define IVSIZE 4 /* A bold guess, but the best we can make. */ # endif #endif #ifndef UVTYPE # define UVTYPE unsigned IVTYPE #endif #ifndef UVSIZE # define UVSIZE IVSIZE #endif #ifndef sv_setuv # define sv_setuv(sv, uv) \ STMT_START { \ UV TeMpUv = uv; \ if (TeMpUv <= IV_MAX) \ sv_setiv(sv, TeMpUv); \ else \ sv_setnv(sv, (double)TeMpUv); \ } STMT_END #endif #ifndef newSVuv # define newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv)) #endif #ifndef sv_2uv # define sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv))) #endif #ifndef SvUVX # define SvUVX(sv) ((UV)SvIVX(sv)) #endif #ifndef SvUVXx # define SvUVXx(sv) SvUVX(sv) #endif #ifndef SvUV # define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) #endif #ifndef SvUVx # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) #endif /* Hint: sv_uv * Always use the SvUVx() macro instead of sv_uv(). */ #ifndef sv_uv # define sv_uv(sv) SvUVx(sv) #endif #if !defined(SvUOK) && defined(SvIOK_UV) # define SvUOK(sv) SvIOK_UV(sv) #endif #ifndef XST_mUV # define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) ) #endif #ifndef XSRETURN_UV # define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END #endif #ifndef PUSHu # define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END #endif #ifndef XPUSHu # define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END #endif #ifdef HAS_MEMCMP #ifndef memNE # define memNE(s1,s2,l) (memcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) #endif #else #ifndef memNE # define memNE(s1,s2,l) (bcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) #endif #endif #ifndef memEQs # define memEQs(s1, l, s2) \ (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1))) #endif #ifndef memNEs # define memNEs(s1, l, s2) !memEQs(s1, l, s2) #endif #ifndef MoveD # define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifndef CopyD # define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifdef HAS_MEMSET #ifndef ZeroD # define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t)) #endif #else #ifndef ZeroD # define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d) #endif #endif #ifndef PoisonWith # define PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)) #endif #ifndef PoisonNew # define PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) #endif #ifndef PoisonFree # define PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) #endif #ifndef Poison # define Poison(d,n,t) PoisonFree(d,n,t) #endif #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif #ifndef Newxc # define Newxc(v,n,t,c) Newc(0,v,n,t,c) #endif #ifndef Newxz # define Newxz(v,n,t) Newz(0,v,n,t) #endif #ifndef PERL_UNUSED_DECL # ifdef HASATTRIBUTE # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER) # define PERL_UNUSED_DECL # else # define PERL_UNUSED_DECL __attribute__((unused)) # endif # else # define PERL_UNUSED_DECL # endif #endif #ifndef PERL_UNUSED_ARG # if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */ # include # define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x)) # else # define PERL_UNUSED_ARG(x) ((void)x) # endif #endif #ifndef PERL_UNUSED_VAR # define PERL_UNUSED_VAR(x) ((void)x) #endif #ifndef PERL_UNUSED_CONTEXT # ifdef USE_ITHREADS # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl) # else # define PERL_UNUSED_CONTEXT # endif #endif #ifndef NOOP # define NOOP /*EMPTY*/(void)0 #endif #ifndef dNOOP # define dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL #endif #ifndef NVTYPE # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) # define NVTYPE long double # else # define NVTYPE double # endif typedef NVTYPE NV; #endif #ifndef INT2PTR # if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) # define PTRV UV # define INT2PTR(any,d) (any)(d) # else # if PTRSIZE == LONGSIZE # define PTRV unsigned long # else # define PTRV unsigned # endif # define INT2PTR(any,d) (any)(PTRV)(d) # endif #endif #ifndef PTR2ul # if PTRSIZE == LONGSIZE # define PTR2ul(p) (unsigned long)(p) # else # define PTR2ul(p) INT2PTR(unsigned long,p) # endif #endif #ifndef PTR2nat # define PTR2nat(p) (PTRV)(p) #endif #ifndef NUM2PTR # define NUM2PTR(any,d) (any)PTR2nat(d) #endif #ifndef PTR2IV # define PTR2IV(p) INT2PTR(IV,p) #endif #ifndef PTR2UV # define PTR2UV(p) INT2PTR(UV,p) #endif #ifndef PTR2NV # define PTR2NV(p) NUM2PTR(NV,p) #endif #undef START_EXTERN_C #undef END_EXTERN_C #undef EXTERN_C #ifdef __cplusplus # define START_EXTERN_C extern "C" { # define END_EXTERN_C } # define EXTERN_C extern "C" #else # define START_EXTERN_C # define END_EXTERN_C # define EXTERN_C extern #endif #if defined(PERL_GCC_PEDANTIC) # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN # define PERL_GCC_BRACE_GROUPS_FORBIDDEN # endif #endif #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus) # ifndef PERL_USE_GCC_BRACE_GROUPS # define PERL_USE_GCC_BRACE_GROUPS # endif #endif #undef STMT_START #undef STMT_END #ifdef PERL_USE_GCC_BRACE_GROUPS # define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */ # define STMT_END ) #else # if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__) # define STMT_START if (1) # define STMT_END else (void)0 # else # define STMT_START do # define STMT_END while (0) # endif #endif #ifndef boolSV # define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) #endif /* DEFSV appears first in 5.004_56 */ #ifndef DEFSV # define DEFSV GvSV(PL_defgv) #endif #ifndef SAVE_DEFSV # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv)) #endif #ifndef DEFSV_set # define DEFSV_set(sv) (DEFSV = (sv)) #endif /* Older perls (<=5.003) lack AvFILLp */ #ifndef AvFILLp # define AvFILLp AvFILL #endif #ifndef ERRSV # define ERRSV get_sv("@",FALSE) #endif /* Hint: gv_stashpvn * This function's backport doesn't support the length parameter, but * rather ignores it. Portability can only be ensured if the length * parameter is used for speed reasons, but the length can always be * correctly computed from the string argument. */ #ifndef gv_stashpvn # define gv_stashpvn(str,len,create) gv_stashpv(str,create) #endif /* Replace: 1 */ #ifndef get_cv # define get_cv perl_get_cv #endif #ifndef get_sv # define get_sv perl_get_sv #endif #ifndef get_av # define get_av perl_get_av #endif #ifndef get_hv # define get_hv perl_get_hv #endif /* Replace: 0 */ #ifndef dUNDERBAR # define dUNDERBAR dNOOP #endif #ifndef UNDERBAR # define UNDERBAR DEFSV #endif #ifndef dAX # define dAX I32 ax = MARK - PL_stack_base + 1 #endif #ifndef dITEMS # define dITEMS I32 items = SP - MARK #endif #ifndef dXSTARG # define dXSTARG SV * targ = sv_newmortal() #endif #ifndef dAXMARK # define dAXMARK I32 ax = POPMARK; \ register SV ** const mark = PL_stack_base + ax++ #endif #ifndef XSprePUSH # define XSprePUSH (sp = PL_stack_base + ax - 1) #endif #if (PERL_BCDVERSION < 0x5005000) # undef XSRETURN # define XSRETURN(off) \ STMT_START { \ PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ return; \ } STMT_END #endif #ifndef XSPROTO # define XSPROTO(name) void name(pTHX_ CV* cv) #endif #ifndef SVfARG # define SVfARG(p) ((void*)(p)) #endif #ifndef PERL_ABS # define PERL_ABS(x) ((x) < 0 ? -(x) : (x)) #endif #ifndef dVAR # define dVAR dNOOP #endif #ifndef SVf # define SVf "_" #endif #ifndef UTF8_MAXBYTES # define UTF8_MAXBYTES UTF8_MAXLEN #endif #ifndef CPERLscope # define CPERLscope(x) x #endif #ifndef PERL_HASH # define PERL_HASH(hash,str,len) \ STMT_START { \ const char *s_PeRlHaSh = str; \ I32 i_PeRlHaSh = len; \ U32 hash_PeRlHaSh = 0; \ while (i_PeRlHaSh--) \ hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ (hash) = hash_PeRlHaSh; \ } STMT_END #endif #ifndef PERLIO_FUNCS_DECL # ifdef PERLIO_FUNCS_CONST # define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) # else # define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (funcs) # endif #endif /* provide these typedefs for older perls */ #if (PERL_BCDVERSION < 0x5009003) # ifdef ARGSproto typedef OP* (CPERLscope(*Perl_ppaddr_t))(ARGSproto); # else typedef OP* (CPERLscope(*Perl_ppaddr_t))(pTHX); # endif typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*); #endif #ifndef isPSXSPC # define isPSXSPC(c) (isSPACE(c) || (c) == '\v') #endif #ifndef isBLANK # define isBLANK(c) ((c) == ' ' || (c) == '\t') #endif #ifdef EBCDIC #ifndef isALNUMC # define isALNUMC(c) isalnum(c) #endif #ifndef isASCII # define isASCII(c) isascii(c) #endif #ifndef isCNTRL # define isCNTRL(c) iscntrl(c) #endif #ifndef isGRAPH # define isGRAPH(c) isgraph(c) #endif #ifndef isPRINT # define isPRINT(c) isprint(c) #endif #ifndef isPUNCT # define isPUNCT(c) ispunct(c) #endif #ifndef isXDIGIT # define isXDIGIT(c) isxdigit(c) #endif #else # if (PERL_BCDVERSION < 0x5010000) /* Hint: isPRINT * The implementation in older perl versions includes all of the * isSPACE() characters, which is wrong. The version provided by * Devel::PPPort always overrides a present buggy version. */ # undef isPRINT # endif #ifndef isALNUMC # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) #endif #ifndef isASCII # define isASCII(c) ((U8) (c) <= 127) #endif #ifndef isCNTRL # define isCNTRL(c) ((U8) (c) < ' ' || (c) == 127) #endif #ifndef isGRAPH # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) #endif #ifndef isPRINT # define isPRINT(c) (((c) >= 32 && (c) < 127)) #endif #ifndef isPUNCT # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) #endif #ifndef isXDIGIT # define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) #endif #endif #ifndef PERL_SIGNALS_UNSAFE_FLAG #define PERL_SIGNALS_UNSAFE_FLAG 0x0001 #if (PERL_BCDVERSION < 0x5008000) # define D_PPP_PERL_SIGNALS_INIT PERL_SIGNALS_UNSAFE_FLAG #else # define D_PPP_PERL_SIGNALS_INIT 0 #endif #if defined(NEED_PL_signals) static U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #elif defined(NEED_PL_signals_GLOBAL) U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #else extern U32 DPPP_(my_PL_signals); #endif #define PL_signals DPPP_(my_PL_signals) #endif /* Hint: PL_ppaddr * Calling an op via PL_ppaddr requires passing a context argument * for threaded builds. Since the context argument is different for * 5.005 perls, you can use aTHXR (supplied by ppport.h), which will * automatically be defined as the correct argument. */ #if (PERL_BCDVERSION <= 0x5005005) /* Replace: 1 */ # define PL_ppaddr ppaddr # define PL_no_modify no_modify /* Replace: 0 */ #endif #if (PERL_BCDVERSION <= 0x5004005) /* Replace: 1 */ # define PL_DBsignal DBsignal # define PL_DBsingle DBsingle # define PL_DBsub DBsub # define PL_DBtrace DBtrace # define PL_Sv Sv # define PL_bufend bufend # define PL_bufptr bufptr # define PL_compiling compiling # define PL_copline copline # define PL_curcop curcop # define PL_curstash curstash # define PL_debstash debstash # define PL_defgv defgv # define PL_diehook diehook # define PL_dirty dirty # define PL_dowarn dowarn # define PL_errgv errgv # define PL_error_count error_count # define PL_expect expect # define PL_hexdigit hexdigit # define PL_hints hints # define PL_in_my in_my # define PL_laststatval laststatval # define PL_lex_state lex_state # define PL_lex_stuff lex_stuff # define PL_linestr linestr # define PL_na na # define PL_perl_destruct_level perl_destruct_level # define PL_perldb perldb # define PL_rsfp_filters rsfp_filters # define PL_rsfp rsfp # define PL_stack_base stack_base # define PL_stack_sp stack_sp # define PL_statcache statcache # define PL_stdingv stdingv # define PL_sv_arenaroot sv_arenaroot # define PL_sv_no sv_no # define PL_sv_undef sv_undef # define PL_sv_yes sv_yes # define PL_tainted tainted # define PL_tainting tainting # define PL_tokenbuf tokenbuf /* Replace: 0 */ #endif /* Warning: PL_parser * For perl versions earlier than 5.9.5, this is an always * non-NULL dummy. Also, it cannot be dereferenced. Don't * use it if you can avoid is and unless you absolutely know * what you're doing. * If you always check that PL_parser is non-NULL, you can * define DPPP_PL_parser_NO_DUMMY to avoid the creation of * a dummy parser structure. */ #if (PERL_BCDVERSION >= 0x5009005) # ifdef DPPP_PL_parser_NO_DUMMY # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (croak("panic: PL_parser == NULL in %s:%d", \ __FILE__, __LINE__), (yy_parser *) NULL))->var) # else # ifdef DPPP_PL_parser_NO_DUMMY_WARNING # define D_PPP_parser_dummy_warning(var) # else # define D_PPP_parser_dummy_warning(var) \ warn("warning: dummy PL_" #var " used in %s:%d", __FILE__, __LINE__), # endif # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (D_PPP_parser_dummy_warning(var) &DPPP_(dummy_PL_parser)))->var) #if defined(NEED_PL_parser) static yy_parser DPPP_(dummy_PL_parser); #elif defined(NEED_PL_parser_GLOBAL) yy_parser DPPP_(dummy_PL_parser); #else extern yy_parser DPPP_(dummy_PL_parser); #endif # endif /* PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf depends on PL_parser */ /* Warning: PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf * Do not use this variable unless you know exactly what you're * doint. It is internal to the perl parser and may change or even * be removed in the future. As of perl 5.9.5, you have to check * for (PL_parser != NULL) for this variable to have any effect. * An always non-NULL PL_parser dummy is provided for earlier * perl versions. * If PL_parser is NULL when you try to access this variable, a * dummy is being accessed instead and a warning is issued unless * you define DPPP_PL_parser_NO_DUMMY_WARNING. * If DPPP_PL_parser_NO_DUMMY is defined, the code trying to access * this variable will croak with a panic message. */ # define PL_expect D_PPP_my_PL_parser_var(expect) # define PL_copline D_PPP_my_PL_parser_var(copline) # define PL_rsfp D_PPP_my_PL_parser_var(rsfp) # define PL_rsfp_filters D_PPP_my_PL_parser_var(rsfp_filters) # define PL_linestr D_PPP_my_PL_parser_var(linestr) # define PL_bufptr D_PPP_my_PL_parser_var(bufptr) # define PL_bufend D_PPP_my_PL_parser_var(bufend) # define PL_lex_state D_PPP_my_PL_parser_var(lex_state) # define PL_lex_stuff D_PPP_my_PL_parser_var(lex_stuff) # define PL_tokenbuf D_PPP_my_PL_parser_var(tokenbuf) # define PL_in_my D_PPP_my_PL_parser_var(in_my) # define PL_in_my_stash D_PPP_my_PL_parser_var(in_my_stash) # define PL_error_count D_PPP_my_PL_parser_var(error_count) #else /* ensure that PL_parser != NULL and cannot be dereferenced */ # define PL_parser ((void *) 1) #endif #ifndef mPUSHs # define mPUSHs(s) PUSHs(sv_2mortal(s)) #endif #ifndef PUSHmortal # define PUSHmortal PUSHs(sv_newmortal()) #endif #ifndef mPUSHp # define mPUSHp(p,l) sv_setpvn(PUSHmortal, (p), (l)) #endif #ifndef mPUSHn # define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n)) #endif #ifndef mPUSHi # define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i)) #endif #ifndef mPUSHu # define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u)) #endif #ifndef mXPUSHs # define mXPUSHs(s) XPUSHs(sv_2mortal(s)) #endif #ifndef XPUSHmortal # define XPUSHmortal XPUSHs(sv_newmortal()) #endif #ifndef mXPUSHp # define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn(PUSHmortal, (p), (l)); } STMT_END #endif #ifndef mXPUSHn # define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END #endif #ifndef mXPUSHi # define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END #endif #ifndef mXPUSHu # define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END #endif /* Replace: 1 */ #ifndef call_sv # define call_sv perl_call_sv #endif #ifndef call_pv # define call_pv perl_call_pv #endif #ifndef call_argv # define call_argv perl_call_argv #endif #ifndef call_method # define call_method perl_call_method #endif #ifndef eval_sv # define eval_sv perl_eval_sv #endif /* Replace: 0 */ #ifndef PERL_LOADMOD_DENY # define PERL_LOADMOD_DENY 0x1 #endif #ifndef PERL_LOADMOD_NOIMPORT # define PERL_LOADMOD_NOIMPORT 0x2 #endif #ifndef PERL_LOADMOD_IMPORT_OPS # define PERL_LOADMOD_IMPORT_OPS 0x4 #endif #ifndef G_METHOD # define G_METHOD 64 # ifdef call_sv # undef call_sv # endif # if (PERL_BCDVERSION < 0x5006000) # define call_sv(sv, flags) ((flags) & G_METHOD ? perl_call_method((char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : perl_call_sv(sv, flags)) # else # define call_sv(sv, flags) ((flags) & G_METHOD ? Perl_call_method(aTHX_ (char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : Perl_call_sv(aTHX_ sv, flags)) # endif #endif /* Replace perl_eval_pv with eval_pv */ #ifndef eval_pv #if defined(NEED_eval_pv) static SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); static #else extern SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); #endif #ifdef eval_pv # undef eval_pv #endif #define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b) #define Perl_eval_pv DPPP_(my_eval_pv) #if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL) SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error) { dSP; SV* sv = newSVpv(p, 0); PUSHMARK(sp); eval_sv(sv, G_SCALAR); SvREFCNT_dec(sv); SPAGAIN; sv = POPs; PUTBACK; if (croak_on_error && SvTRUE(GvSV(errgv))) croak(SvPVx(GvSV(errgv), na)); return sv; } #endif #endif #ifndef vload_module #if defined(NEED_vload_module) static void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); static #else extern void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); #endif #ifdef vload_module # undef vload_module #endif #define vload_module(a,b,c,d) DPPP_(my_vload_module)(aTHX_ a,b,c,d) #define Perl_vload_module DPPP_(my_vload_module) #if defined(NEED_vload_module) || defined(NEED_vload_module_GLOBAL) void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args) { dTHR; dVAR; OP *veop, *imop; OP * const modname = newSVOP(OP_CONST, 0, name); /* 5.005 has a somewhat hacky force_normal that doesn't croak on SvREADONLY() if PL_compling is true. Current perls take care in ck_require() to correctly turn off SvREADONLY before calling force_normal_flags(). This seems a better fix than fudging PL_compling */ SvREADONLY_off(((SVOP*)modname)->op_sv); modname->op_private |= OPpCONST_BARE; if (ver) { veop = newSVOP(OP_CONST, 0, ver); } else veop = NULL; if (flags & PERL_LOADMOD_NOIMPORT) { imop = sawparens(newNULLLIST()); } else if (flags & PERL_LOADMOD_IMPORT_OPS) { imop = va_arg(*args, OP*); } else { SV *sv; imop = NULL; sv = va_arg(*args, SV*); while (sv) { imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv)); sv = va_arg(*args, SV*); } } { const line_t ocopline = PL_copline; COP * const ocurcop = PL_curcop; const int oexpect = PL_expect; #if (PERL_BCDVERSION >= 0x5004000) utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0), veop, modname, imop); #else utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), modname, imop); #endif PL_expect = oexpect; PL_copline = ocopline; PL_curcop = ocurcop; } } #endif #endif #ifndef load_module #if defined(NEED_load_module) static void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); static #else extern void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); #endif #ifdef load_module # undef load_module #endif #define load_module DPPP_(my_load_module) #define Perl_load_module DPPP_(my_load_module) #if defined(NEED_load_module) || defined(NEED_load_module_GLOBAL) void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...) { va_list args; va_start(args, ver); vload_module(flags, name, ver, &args); va_end(args); } #endif #endif #ifndef newRV_inc # define newRV_inc(sv) newRV(sv) /* Replace */ #endif #ifndef newRV_noinc #if defined(NEED_newRV_noinc) static SV * DPPP_(my_newRV_noinc)(SV *sv); static #else extern SV * DPPP_(my_newRV_noinc)(SV *sv); #endif #ifdef newRV_noinc # undef newRV_noinc #endif #define newRV_noinc(a) DPPP_(my_newRV_noinc)(aTHX_ a) #define Perl_newRV_noinc DPPP_(my_newRV_noinc) #if defined(NEED_newRV_noinc) || defined(NEED_newRV_noinc_GLOBAL) SV * DPPP_(my_newRV_noinc)(SV *sv) { SV *rv = (SV *)newRV(sv); SvREFCNT_dec(sv); return rv; } #endif #endif /* Hint: newCONSTSUB * Returns a CV* as of perl-5.7.1. This return value is not supported * by Devel::PPPort. */ /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */ #if (PERL_BCDVERSION < 0x5004063) && (PERL_BCDVERSION != 0x5004005) #if defined(NEED_newCONSTSUB) static void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); static #else extern void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); #endif #ifdef newCONSTSUB # undef newCONSTSUB #endif #define newCONSTSUB(a,b,c) DPPP_(my_newCONSTSUB)(aTHX_ a,b,c) #define Perl_newCONSTSUB DPPP_(my_newCONSTSUB) #if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL) /* This is just a trick to avoid a dependency of newCONSTSUB on PL_parser */ /* (There's no PL_parser in perl < 5.005, so this is completely safe) */ #define D_PPP_PL_copline PL_copline void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv) { U32 oldhints = PL_hints; HV *old_cop_stash = PL_curcop->cop_stash; HV *old_curstash = PL_curstash; line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = D_PPP_PL_copline; PL_hints &= ~HINT_BLOCK_SCOPE; if (stash) PL_curstash = PL_curcop->cop_stash = stash; newSUB( #if (PERL_BCDVERSION < 0x5003022) start_subparse(), #elif (PERL_BCDVERSION == 0x5003022) start_subparse(0), #else /* 5.003_23 onwards */ start_subparse(FALSE, 0), #endif newSVOP(OP_CONST, 0, newSVpv((char *) name, 0)), newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */ newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv)) ); PL_hints = oldhints; PL_curcop->cop_stash = old_cop_stash; PL_curstash = old_curstash; PL_curcop->cop_line = oldline; } #endif #endif /* * Boilerplate macros for initializing and accessing interpreter-local * data from C. All statics in extensions should be reworked to use * this, if you want to make the extension thread-safe. See ext/re/re.xs * for an example of the use of these macros. * * Code that uses these macros is responsible for the following: * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts" * 2. Declare a typedef named my_cxt_t that is a structure that contains * all the data that needs to be interpreter-local. * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t. * 4. Use the MY_CXT_INIT macro such that it is called exactly once * (typically put in the BOOT: section). * 5. Use the members of the my_cxt_t structure everywhere as * MY_CXT.member. * 6. Use the dMY_CXT macro (a declaration) in all the functions that * access MY_CXT. */ #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \ defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT) #ifndef START_MY_CXT /* This must appear in all extensions that define a my_cxt_t structure, * right after the definition (i.e. at file scope). The non-threads * case below uses it to declare the data as static. */ #define START_MY_CXT #if (PERL_BCDVERSION < 0x5004068) /* Fetches the SV that keeps the per-interpreter data. */ #define dMY_CXT_SV \ SV *my_cxt_sv = get_sv(MY_CXT_KEY, FALSE) #else /* >= perl5.004_68 */ #define dMY_CXT_SV \ SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \ sizeof(MY_CXT_KEY)-1, TRUE) #endif /* < perl5.004_68 */ /* This declaration should be used within all functions that use the * interpreter-local data. */ #define dMY_CXT \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv)) /* Creates and zeroes the per-interpreter data. * (We allocate my_cxtp in a Perl SV so that it will be released when * the interpreter goes away.) */ #define MY_CXT_INIT \ dMY_CXT_SV; \ /* newSV() allocates one more than needed */ \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Zero(my_cxtp, 1, my_cxt_t); \ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) /* This macro must be used to access members of the my_cxt_t structure. * e.g. MYCXT.some_data */ #define MY_CXT (*my_cxtp) /* Judicious use of these macros can reduce the number of times dMY_CXT * is used. Use is similar to pTHX, aTHX etc. */ #define pMY_CXT my_cxt_t *my_cxtp #define pMY_CXT_ pMY_CXT, #define _pMY_CXT ,pMY_CXT #define aMY_CXT my_cxtp #define aMY_CXT_ aMY_CXT, #define _aMY_CXT ,aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE /* Clones the per-interpreter data. */ #define MY_CXT_CLONE \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) #endif #else /* single interpreter */ #ifndef START_MY_CXT #define START_MY_CXT static my_cxt_t my_cxt; #define dMY_CXT_SV dNOOP #define dMY_CXT dNOOP #define MY_CXT_INIT NOOP #define MY_CXT my_cxt #define pMY_CXT void #define pMY_CXT_ #define _pMY_CXT #define aMY_CXT #define aMY_CXT_ #define _aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE #define MY_CXT_CLONE NOOP #endif #endif #ifndef IVdf # if IVSIZE == LONGSIZE # define IVdf "ld" # define UVuf "lu" # define UVof "lo" # define UVxf "lx" # define UVXf "lX" # else # if IVSIZE == INTSIZE # define IVdf "d" # define UVuf "u" # define UVof "o" # define UVxf "x" # define UVXf "X" # endif # endif #endif #ifndef NVef # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \ defined(PERL_PRIfldbl) && (PERL_BCDVERSION != 0x5006000) /* Not very likely, but let's try anyway. */ # define NVef PERL_PRIeldbl # define NVff PERL_PRIfldbl # define NVgf PERL_PRIgldbl # else # define NVef "e" # define NVff "f" # define NVgf "g" # endif #endif #ifndef SvREFCNT_inc # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (SvREFCNT(_sv))++; \ _sv; \ }) # else # define SvREFCNT_inc(sv) \ ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL) # endif #endif #ifndef SvREFCNT_inc_simple # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_simple(sv) \ ({ \ if (sv) \ (SvREFCNT(sv))++; \ (SV *)(sv); \ }) # else # define SvREFCNT_inc_simple(sv) \ ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL) # endif #endif #ifndef SvREFCNT_inc_NN # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_NN(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ SvREFCNT(_sv)++; \ _sv; \ }) # else # define SvREFCNT_inc_NN(sv) \ (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv) # endif #endif #ifndef SvREFCNT_inc_void # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_void(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (void)(SvREFCNT(_sv)++); \ }) # else # define SvREFCNT_inc_void(sv) \ (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0) # endif #endif #ifndef SvREFCNT_inc_simple_void # define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END #endif #ifndef SvREFCNT_inc_simple_NN # define SvREFCNT_inc_simple_NN(sv) (++SvREFCNT(sv), (SV*)(sv)) #endif #ifndef SvREFCNT_inc_void_NN # define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef SvREFCNT_inc_simple_void_NN # define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef newSV_type #if defined(NEED_newSV_type) static SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); static #else extern SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); #endif #ifdef newSV_type # undef newSV_type #endif #define newSV_type(a) DPPP_(my_newSV_type)(aTHX_ a) #define Perl_newSV_type DPPP_(my_newSV_type) #if defined(NEED_newSV_type) || defined(NEED_newSV_type_GLOBAL) SV* DPPP_(my_newSV_type)(pTHX_ svtype const t) { SV* const sv = newSV(0); sv_upgrade(sv, t); return sv; } #endif #endif #if (PERL_BCDVERSION < 0x5006000) # define D_PPP_CONSTPV_ARG(x) ((char *) (x)) #else # define D_PPP_CONSTPV_ARG(x) (x) #endif #ifndef newSVpvn # define newSVpvn(data,len) ((data) \ ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \ : newSV(0)) #endif #ifndef newSVpvn_utf8 # define newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0) #endif #ifndef SVf_UTF8 # define SVf_UTF8 0 #endif #ifndef newSVpvn_flags #if defined(NEED_newSVpvn_flags) static SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); static #else extern SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); #endif #ifdef newSVpvn_flags # undef newSVpvn_flags #endif #define newSVpvn_flags(a,b,c) DPPP_(my_newSVpvn_flags)(aTHX_ a,b,c) #define Perl_newSVpvn_flags DPPP_(my_newSVpvn_flags) #if defined(NEED_newSVpvn_flags) || defined(NEED_newSVpvn_flags_GLOBAL) SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags) { SV *sv = newSVpvn(D_PPP_CONSTPV_ARG(s), len); SvFLAGS(sv) |= (flags & SVf_UTF8); return (flags & SVs_TEMP) ? sv_2mortal(sv) : sv; } #endif #endif /* Backwards compatibility stuff... :-( */ #if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen) # define NEED_sv_2pv_flags #endif #if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL) # define NEED_sv_2pv_flags_GLOBAL #endif /* Hint: sv_2pv_nolen * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen(). */ #ifndef sv_2pv_nolen # define sv_2pv_nolen(sv) SvPV_nolen(sv) #endif #ifdef SvPVbyte /* Hint: SvPVbyte * Does not work in perl-5.6.1, ppport.h implements a version * borrowed from perl-5.7.3. */ #if (PERL_BCDVERSION < 0x5007000) #if defined(NEED_sv_2pvbyte) static char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); static #else extern char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); #endif #ifdef sv_2pvbyte # undef sv_2pvbyte #endif #define sv_2pvbyte(a,b) DPPP_(my_sv_2pvbyte)(aTHX_ a,b) #define Perl_sv_2pvbyte DPPP_(my_sv_2pvbyte) #if defined(NEED_sv_2pvbyte) || defined(NEED_sv_2pvbyte_GLOBAL) char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp) { sv_utf8_downgrade(sv,0); return SvPV(sv,*lp); } #endif /* Hint: sv_2pvbyte * Use the SvPVbyte() macro instead of sv_2pvbyte(). */ #undef SvPVbyte #define SvPVbyte(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) #endif #else # define SvPVbyte SvPV # define sv_2pvbyte sv_2pv #endif #ifndef sv_2pvbyte_nolen # define sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv) #endif /* Hint: sv_pvn * Always use the SvPV() macro instead of sv_pvn(). */ /* Hint: sv_pvn_force * Always use the SvPV_force() macro instead of sv_pvn_force(). */ /* If these are undefined, they're not handled by the core anyway */ #ifndef SV_IMMEDIATE_UNREF # define SV_IMMEDIATE_UNREF 0 #endif #ifndef SV_GMAGIC # define SV_GMAGIC 0 #endif #ifndef SV_COW_DROP_PV # define SV_COW_DROP_PV 0 #endif #ifndef SV_UTF8_NO_ENCODING # define SV_UTF8_NO_ENCODING 0 #endif #ifndef SV_NOSTEAL # define SV_NOSTEAL 0 #endif #ifndef SV_CONST_RETURN # define SV_CONST_RETURN 0 #endif #ifndef SV_MUTABLE_RETURN # define SV_MUTABLE_RETURN 0 #endif #ifndef SV_SMAGIC # define SV_SMAGIC 0 #endif #ifndef SV_HAS_TRAILING_NUL # define SV_HAS_TRAILING_NUL 0 #endif #ifndef SV_COW_SHARED_HASH_KEYS # define SV_COW_SHARED_HASH_KEYS 0 #endif #if (PERL_BCDVERSION < 0x5007002) #if defined(NEED_sv_2pv_flags) static char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #ifdef sv_2pv_flags # undef sv_2pv_flags #endif #define sv_2pv_flags(a,b,c) DPPP_(my_sv_2pv_flags)(aTHX_ a,b,c) #define Perl_sv_2pv_flags DPPP_(my_sv_2pv_flags) #if defined(NEED_sv_2pv_flags) || defined(NEED_sv_2pv_flags_GLOBAL) char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_2pv(sv, lp ? lp : &n_a); } #endif #if defined(NEED_sv_pvn_force_flags) static char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #ifdef sv_pvn_force_flags # undef sv_pvn_force_flags #endif #define sv_pvn_force_flags(a,b,c) DPPP_(my_sv_pvn_force_flags)(aTHX_ a,b,c) #define Perl_sv_pvn_force_flags DPPP_(my_sv_pvn_force_flags) #if defined(NEED_sv_pvn_force_flags) || defined(NEED_sv_pvn_force_flags_GLOBAL) char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_pvn_force(sv, lp ? lp : &n_a); } #endif #endif #if (PERL_BCDVERSION < 0x5008008) || ( (PERL_BCDVERSION >= 0x5009000) && (PERL_BCDVERSION < 0x5009003) ) # define DPPP_SVPV_NOLEN_LP_ARG &PL_na #else # define DPPP_SVPV_NOLEN_LP_ARG 0 #endif #ifndef SvPV_const # define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_mutable # define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_flags # define SvPV_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) #endif #ifndef SvPV_flags_const # define SvPV_flags_const(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_const_nolen # define SvPV_flags_const_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : \ (const char*) sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_mutable # define SvPV_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_force # define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nolen # define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC) #endif #ifndef SvPV_force_mutable # define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nomg # define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) #endif #ifndef SvPV_force_nomg_nolen # define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0) #endif #ifndef SvPV_force_flags # define SvPV_force_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) #endif #ifndef SvPV_force_flags_nolen # define SvPV_force_flags_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? SvPVX(sv) : sv_pvn_force_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags)) #endif #ifndef SvPV_force_flags_mutable # define SvPV_force_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_nolen # define SvPV_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC)) #endif #ifndef SvPV_nolen_const # define SvPV_nolen_const(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN)) #endif #ifndef SvPV_nomg # define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) #endif #ifndef SvPV_nomg_const # define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0) #endif #ifndef SvPV_nomg_const_nolen # define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0) #endif #ifndef SvPV_renew # define SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \ SvPV_set((sv), (char *) saferealloc( \ (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \ } STMT_END #endif #ifndef SvMAGIC_set # define SvMAGIC_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_magic = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5009003) #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) (0 + SvPVX(sv)) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ (((XRV*) SvANY(sv))->xrv_rv = (val)); } STMT_END #endif #else #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*)((sv)->sv_u.svu_pv)) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) ((sv)->sv_u.svu_pv) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ ((sv)->sv_u.svu_rv = (val)); } STMT_END #endif #endif #ifndef SvSTASH_set # define SvSTASH_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_stash = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5004000) #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVIV*) SvANY(sv))->xiv_iv = (IV) (val)); } STMT_END #endif #else #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVUV*) SvANY(sv))->xuv_uv = (val)); } STMT_END #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(vnewSVpvf) #if defined(NEED_vnewSVpvf) static SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); static #else extern SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); #endif #ifdef vnewSVpvf # undef vnewSVpvf #endif #define vnewSVpvf(a,b) DPPP_(my_vnewSVpvf)(aTHX_ a,b) #define Perl_vnewSVpvf DPPP_(my_vnewSVpvf) #if defined(NEED_vnewSVpvf) || defined(NEED_vnewSVpvf_GLOBAL) SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args) { register SV *sv = newSV(0); sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); return sv; } #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf) # define sv_vcatpvf(sv, pat, args) sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf) # define sv_vsetpvf(sv, pat, args) sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) static void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #define Perl_sv_catpvf_mg DPPP_(my_sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) || defined(NEED_sv_catpvf_mg_GLOBAL) void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) static void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #define sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #define Perl_sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) || defined(NEED_sv_catpvf_mg_nocontext_GLOBAL) void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_catpvf_mg depends on sv_catpvf_mg_nocontext */ #ifndef sv_catpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext # else # define sv_catpvf_mg Perl_sv_catpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf_mg) # define sv_vcatpvf_mg(sv, pat, args) \ STMT_START { \ sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) static void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #define Perl_sv_setpvf_mg DPPP_(my_sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) || defined(NEED_sv_setpvf_mg_GLOBAL) void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) static void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #define sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #define Perl_sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) || defined(NEED_sv_setpvf_mg_nocontext_GLOBAL) void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_setpvf_mg depends on sv_setpvf_mg_nocontext */ #ifndef sv_setpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext # else # define sv_setpvf_mg Perl_sv_setpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf_mg) # define sv_vsetpvf_mg(sv, pat, args) \ STMT_START { \ sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif /* Hint: newSVpvn_share * The SVs created by this function only mimic the behaviour of * shared PVs without really being shared. Only use if you know * what you're doing. */ #ifndef newSVpvn_share #if defined(NEED_newSVpvn_share) static SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); static #else extern SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); #endif #ifdef newSVpvn_share # undef newSVpvn_share #endif #define newSVpvn_share(a,b,c) DPPP_(my_newSVpvn_share)(aTHX_ a,b,c) #define Perl_newSVpvn_share DPPP_(my_newSVpvn_share) #if defined(NEED_newSVpvn_share) || defined(NEED_newSVpvn_share_GLOBAL) SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash) { SV *sv; if (len < 0) len = -len; if (!hash) PERL_HASH(hash, (char*) src, len); sv = newSVpvn((char *) src, len); sv_upgrade(sv, SVt_PVIV); SvIVX(sv) = hash; SvREADONLY_on(sv); SvPOK_on(sv); return sv; } #endif #endif #ifndef SvSHARED_HASH # define SvSHARED_HASH(sv) (0 + SvUVX(sv)) #endif #ifndef HvNAME_get # define HvNAME_get(hv) HvNAME(hv) #endif #ifndef HvNAMELEN_get # define HvNAMELEN_get(hv) (HvNAME_get(hv) ? (I32)strlen(HvNAME_get(hv)) : 0) #endif #ifndef GvSVn # define GvSVn(gv) GvSV(gv) #endif #ifndef isGV_with_GP # define isGV_with_GP(gv) isGV(gv) #endif #ifndef gv_fetchpvn_flags # define gv_fetchpvn_flags(name, len, flags, svt) gv_fetchpv(name, flags, svt) #endif #ifndef gv_fetchsv # define gv_fetchsv(name, flags, svt) gv_fetchpv(SvPV_nolen_const(name), flags, svt) #endif #ifndef get_cvn_flags # define get_cvn_flags(name, namelen, flags) get_cv(name, flags) #endif #ifndef WARN_ALL # define WARN_ALL 0 #endif #ifndef WARN_CLOSURE # define WARN_CLOSURE 1 #endif #ifndef WARN_DEPRECATED # define WARN_DEPRECATED 2 #endif #ifndef WARN_EXITING # define WARN_EXITING 3 #endif #ifndef WARN_GLOB # define WARN_GLOB 4 #endif #ifndef WARN_IO # define WARN_IO 5 #endif #ifndef WARN_CLOSED # define WARN_CLOSED 6 #endif #ifndef WARN_EXEC # define WARN_EXEC 7 #endif #ifndef WARN_LAYER # define WARN_LAYER 8 #endif #ifndef WARN_NEWLINE # define WARN_NEWLINE 9 #endif #ifndef WARN_PIPE # define WARN_PIPE 10 #endif #ifndef WARN_UNOPENED # define WARN_UNOPENED 11 #endif #ifndef WARN_MISC # define WARN_MISC 12 #endif #ifndef WARN_NUMERIC # define WARN_NUMERIC 13 #endif #ifndef WARN_ONCE # define WARN_ONCE 14 #endif #ifndef WARN_OVERFLOW # define WARN_OVERFLOW 15 #endif #ifndef WARN_PACK # define WARN_PACK 16 #endif #ifndef WARN_PORTABLE # define WARN_PORTABLE 17 #endif #ifndef WARN_RECURSION # define WARN_RECURSION 18 #endif #ifndef WARN_REDEFINE # define WARN_REDEFINE 19 #endif #ifndef WARN_REGEXP # define WARN_REGEXP 20 #endif #ifndef WARN_SEVERE # define WARN_SEVERE 21 #endif #ifndef WARN_DEBUGGING # define WARN_DEBUGGING 22 #endif #ifndef WARN_INPLACE # define WARN_INPLACE 23 #endif #ifndef WARN_INTERNAL # define WARN_INTERNAL 24 #endif #ifndef WARN_MALLOC # define WARN_MALLOC 25 #endif #ifndef WARN_SIGNAL # define WARN_SIGNAL 26 #endif #ifndef WARN_SUBSTR # define WARN_SUBSTR 27 #endif #ifndef WARN_SYNTAX # define WARN_SYNTAX 28 #endif #ifndef WARN_AMBIGUOUS # define WARN_AMBIGUOUS 29 #endif #ifndef WARN_BAREWORD # define WARN_BAREWORD 30 #endif #ifndef WARN_DIGIT # define WARN_DIGIT 31 #endif #ifndef WARN_PARENTHESIS # define WARN_PARENTHESIS 32 #endif #ifndef WARN_PRECEDENCE # define WARN_PRECEDENCE 33 #endif #ifndef WARN_PRINTF # define WARN_PRINTF 34 #endif #ifndef WARN_PROTOTYPE # define WARN_PROTOTYPE 35 #endif #ifndef WARN_QW # define WARN_QW 36 #endif #ifndef WARN_RESERVED # define WARN_RESERVED 37 #endif #ifndef WARN_SEMICOLON # define WARN_SEMICOLON 38 #endif #ifndef WARN_TAINT # define WARN_TAINT 39 #endif #ifndef WARN_THREADS # define WARN_THREADS 40 #endif #ifndef WARN_UNINITIALIZED # define WARN_UNINITIALIZED 41 #endif #ifndef WARN_UNPACK # define WARN_UNPACK 42 #endif #ifndef WARN_UNTIE # define WARN_UNTIE 43 #endif #ifndef WARN_UTF8 # define WARN_UTF8 44 #endif #ifndef WARN_VOID # define WARN_VOID 45 #endif #ifndef WARN_ASSERTIONS # define WARN_ASSERTIONS 46 #endif #ifndef packWARN # define packWARN(a) (a) #endif #ifndef ckWARN # ifdef G_WARN_ON # define ckWARN(a) (PL_dowarn & G_WARN_ON) # else # define ckWARN(a) PL_dowarn # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(warner) #if defined(NEED_warner) static void DPPP_(my_warner)(U32 err, const char *pat, ...); static #else extern void DPPP_(my_warner)(U32 err, const char *pat, ...); #endif #define Perl_warner DPPP_(my_warner) #if defined(NEED_warner) || defined(NEED_warner_GLOBAL) void DPPP_(my_warner)(U32 err, const char *pat, ...) { SV *sv; va_list args; PERL_UNUSED_ARG(err); va_start(args, pat); sv = vnewSVpvf(pat, &args); va_end(args); sv_2mortal(sv); warn("%s", SvPV_nolen(sv)); } #define warner Perl_warner #define Perl_warner_nocontext Perl_warner #endif #endif /* concatenating with "" ensures that only literal strings are accepted as argument * note that STR_WITH_LEN() can't be used as argument to macros or functions that * under some configurations might be macros */ #ifndef STR_WITH_LEN # define STR_WITH_LEN(s) (s ""), (sizeof(s)-1) #endif #ifndef newSVpvs # define newSVpvs(str) newSVpvn(str "", sizeof(str) - 1) #endif #ifndef newSVpvs_flags # define newSVpvs_flags(str, flags) newSVpvn_flags(str "", sizeof(str) - 1, flags) #endif #ifndef newSVpvs_share # define newSVpvs_share(str) newSVpvn_share(str "", sizeof(str) - 1, 0) #endif #ifndef sv_catpvs # define sv_catpvs(sv, str) sv_catpvn(sv, str "", sizeof(str) - 1) #endif #ifndef sv_setpvs # define sv_setpvs(sv, str) sv_setpvn(sv, str "", sizeof(str) - 1) #endif #ifndef hv_fetchs # define hv_fetchs(hv, key, lval) hv_fetch(hv, key "", sizeof(key) - 1, lval) #endif #ifndef hv_stores # define hv_stores(hv, key, val) hv_store(hv, key "", sizeof(key) - 1, val, 0) #endif #ifndef gv_fetchpvs # define gv_fetchpvs(name, flags, svt) gv_fetchpvn_flags(name "", sizeof(name) - 1, flags, svt) #endif #ifndef gv_stashpvs # define gv_stashpvs(name, flags) gv_stashpvn(name "", sizeof(name) - 1, flags) #endif #ifndef get_cvs # define get_cvs(name, flags) get_cvn_flags(name "", sizeof(name)-1, flags) #endif #ifndef SvGETMAGIC # define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END #endif #ifndef PERL_MAGIC_sv # define PERL_MAGIC_sv '\0' #endif #ifndef PERL_MAGIC_overload # define PERL_MAGIC_overload 'A' #endif #ifndef PERL_MAGIC_overload_elem # define PERL_MAGIC_overload_elem 'a' #endif #ifndef PERL_MAGIC_overload_table # define PERL_MAGIC_overload_table 'c' #endif #ifndef PERL_MAGIC_bm # define PERL_MAGIC_bm 'B' #endif #ifndef PERL_MAGIC_regdata # define PERL_MAGIC_regdata 'D' #endif #ifndef PERL_MAGIC_regdatum # define PERL_MAGIC_regdatum 'd' #endif #ifndef PERL_MAGIC_env # define PERL_MAGIC_env 'E' #endif #ifndef PERL_MAGIC_envelem # define PERL_MAGIC_envelem 'e' #endif #ifndef PERL_MAGIC_fm # define PERL_MAGIC_fm 'f' #endif #ifndef PERL_MAGIC_regex_global # define PERL_MAGIC_regex_global 'g' #endif #ifndef PERL_MAGIC_isa # define PERL_MAGIC_isa 'I' #endif #ifndef PERL_MAGIC_isaelem # define PERL_MAGIC_isaelem 'i' #endif #ifndef PERL_MAGIC_nkeys # define PERL_MAGIC_nkeys 'k' #endif #ifndef PERL_MAGIC_dbfile # define PERL_MAGIC_dbfile 'L' #endif #ifndef PERL_MAGIC_dbline # define PERL_MAGIC_dbline 'l' #endif #ifndef PERL_MAGIC_mutex # define PERL_MAGIC_mutex 'm' #endif #ifndef PERL_MAGIC_shared # define PERL_MAGIC_shared 'N' #endif #ifndef PERL_MAGIC_shared_scalar # define PERL_MAGIC_shared_scalar 'n' #endif #ifndef PERL_MAGIC_collxfrm # define PERL_MAGIC_collxfrm 'o' #endif #ifndef PERL_MAGIC_tied # define PERL_MAGIC_tied 'P' #endif #ifndef PERL_MAGIC_tiedelem # define PERL_MAGIC_tiedelem 'p' #endif #ifndef PERL_MAGIC_tiedscalar # define PERL_MAGIC_tiedscalar 'q' #endif #ifndef PERL_MAGIC_qr # define PERL_MAGIC_qr 'r' #endif #ifndef PERL_MAGIC_sig # define PERL_MAGIC_sig 'S' #endif #ifndef PERL_MAGIC_sigelem # define PERL_MAGIC_sigelem 's' #endif #ifndef PERL_MAGIC_taint # define PERL_MAGIC_taint 't' #endif #ifndef PERL_MAGIC_uvar # define PERL_MAGIC_uvar 'U' #endif #ifndef PERL_MAGIC_uvar_elem # define PERL_MAGIC_uvar_elem 'u' #endif #ifndef PERL_MAGIC_vstring # define PERL_MAGIC_vstring 'V' #endif #ifndef PERL_MAGIC_vec # define PERL_MAGIC_vec 'v' #endif #ifndef PERL_MAGIC_utf8 # define PERL_MAGIC_utf8 'w' #endif #ifndef PERL_MAGIC_substr # define PERL_MAGIC_substr 'x' #endif #ifndef PERL_MAGIC_defelem # define PERL_MAGIC_defelem 'y' #endif #ifndef PERL_MAGIC_glob # define PERL_MAGIC_glob '*' #endif #ifndef PERL_MAGIC_arylen # define PERL_MAGIC_arylen '#' #endif #ifndef PERL_MAGIC_pos # define PERL_MAGIC_pos '.' #endif #ifndef PERL_MAGIC_backref # define PERL_MAGIC_backref '<' #endif #ifndef PERL_MAGIC_ext # define PERL_MAGIC_ext '~' #endif /* That's the best we can do... */ #ifndef sv_catpvn_nomg # define sv_catpvn_nomg sv_catpvn #endif #ifndef sv_catsv_nomg # define sv_catsv_nomg sv_catsv #endif #ifndef sv_setsv_nomg # define sv_setsv_nomg sv_setsv #endif #ifndef sv_pvn_nomg # define sv_pvn_nomg sv_pvn #endif #ifndef SvIV_nomg # define SvIV_nomg SvIV #endif #ifndef SvUV_nomg # define SvUV_nomg SvUV #endif #ifndef sv_catpv_mg # define sv_catpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catpvn_mg # define sv_catpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catsv_mg # define sv_catsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_catsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setiv_mg # define sv_setiv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setiv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setnv_mg # define sv_setnv_mg(sv, num) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setnv(TeMpSv,num); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpv_mg # define sv_setpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpvn_mg # define sv_setpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setsv_mg # define sv_setsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_setsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setuv_mg # define sv_setuv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setuv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_usepvn_mg # define sv_usepvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_usepvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef SvVSTRING_mg # define SvVSTRING_mg(sv) (SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_vstring) : NULL) #endif /* Hint: sv_magic_portable * This is a compatibility function that is only available with * Devel::PPPort. It is NOT in the perl core. * Its purpose is to mimic the 5.8.0 behaviour of sv_magic() when * it is being passed a name pointer with namlen == 0. In that * case, perl 5.8.0 and later store the pointer, not a copy of it. * The compatibility can be provided back to perl 5.004. With * earlier versions, the code will not compile. */ #if (PERL_BCDVERSION < 0x5004000) /* code that uses sv_magic_portable will not compile */ #elif (PERL_BCDVERSION < 0x5008000) # define sv_magic_portable(sv, obj, how, name, namlen) \ STMT_START { \ SV *SvMp_sv = (sv); \ char *SvMp_name = (char *) (name); \ I32 SvMp_namlen = (namlen); \ if (SvMp_name && SvMp_namlen == 0) \ { \ MAGIC *mg; \ sv_magic(SvMp_sv, obj, how, 0, 0); \ mg = SvMAGIC(SvMp_sv); \ mg->mg_len = -42; /* XXX: this is the tricky part */ \ mg->mg_ptr = SvMp_name; \ } \ else \ { \ sv_magic(SvMp_sv, obj, how, SvMp_name, SvMp_namlen); \ } \ } STMT_END #else # define sv_magic_portable(a, b, c, d, e) sv_magic(a, b, c, d, e) #endif #ifdef USE_ITHREADS #ifndef CopFILE # define CopFILE(c) ((c)->cop_file) #endif #ifndef CopFILEGV # define CopFILEGV(c) (CopFILE(c) ? gv_fetchfile(CopFILE(c)) : Nullgv) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILE(c) ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILE(c) ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) ((c)->cop_stashpv) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = ((pv) ? savepv(pv) : Nullch)) #endif #ifndef CopSTASH # define CopSTASH(c) (CopSTASHPV(c) ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME(hv) : Nullch) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) ((hv) && (CopSTASHPV(c) == HvNAME(hv) \ || (CopSTASHPV(c) && HvNAME(hv) \ && strEQ(CopSTASHPV(c), HvNAME(hv))))) #endif #else #ifndef CopFILEGV # define CopFILEGV(c) ((c)->cop_filegv) #endif #ifndef CopFILEGV_set # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav) #endif #ifndef CopFILE # define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch) #endif #ifndef CopSTASH # define CopSTASH(c) ((c)->cop_stash) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) #endif #endif /* USE_ITHREADS */ #ifndef IN_PERL_COMPILETIME # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) #endif #ifndef IN_LOCALE_RUNTIME # define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE) #endif #ifndef IN_LOCALE_COMPILETIME # define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE) #endif #ifndef IN_LOCALE # define IN_LOCALE (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) #endif #ifndef IS_NUMBER_IN_UV # define IS_NUMBER_IN_UV 0x01 #endif #ifndef IS_NUMBER_GREATER_THAN_UV_MAX # define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 #endif #ifndef IS_NUMBER_NOT_INT # define IS_NUMBER_NOT_INT 0x04 #endif #ifndef IS_NUMBER_NEG # define IS_NUMBER_NEG 0x08 #endif #ifndef IS_NUMBER_INFINITY # define IS_NUMBER_INFINITY 0x10 #endif #ifndef IS_NUMBER_NAN # define IS_NUMBER_NAN 0x20 #endif #ifndef GROK_NUMERIC_RADIX # define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send) #endif #ifndef PERL_SCAN_GREATER_THAN_UV_MAX # define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 #endif #ifndef PERL_SCAN_SILENT_ILLDIGIT # define PERL_SCAN_SILENT_ILLDIGIT 0x04 #endif #ifndef PERL_SCAN_ALLOW_UNDERSCORES # define PERL_SCAN_ALLOW_UNDERSCORES 0x01 #endif #ifndef PERL_SCAN_DISALLOW_PREFIX # define PERL_SCAN_DISALLOW_PREFIX 0x02 #endif #ifndef grok_numeric_radix #if defined(NEED_grok_numeric_radix) static bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); static #else extern bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); #endif #ifdef grok_numeric_radix # undef grok_numeric_radix #endif #define grok_numeric_radix(a,b) DPPP_(my_grok_numeric_radix)(aTHX_ a,b) #define Perl_grok_numeric_radix DPPP_(my_grok_numeric_radix) #if defined(NEED_grok_numeric_radix) || defined(NEED_grok_numeric_radix_GLOBAL) bool DPPP_(my_grok_numeric_radix)(pTHX_ const char **sp, const char *send) { #ifdef USE_LOCALE_NUMERIC #ifdef PL_numeric_radix_sv if (PL_numeric_radix_sv && IN_LOCALE) { STRLEN len; char* radix = SvPV(PL_numeric_radix_sv, len); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #else /* older perls don't have PL_numeric_radix_sv so the radix * must manually be requested from locale.h */ #include dTHR; /* needed for older threaded perls */ struct lconv *lc = localeconv(); char *radix = lc->decimal_point; if (radix && IN_LOCALE) { STRLEN len = strlen(radix); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #endif #endif /* USE_LOCALE_NUMERIC */ /* always try "." if numeric radix didn't match because * we may have data from different locales mixed */ if (*sp < send && **sp == '.') { ++*sp; return TRUE; } return FALSE; } #endif #endif #ifndef grok_number #if defined(NEED_grok_number) static int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); static #else extern int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); #endif #ifdef grok_number # undef grok_number #endif #define grok_number(a,b,c) DPPP_(my_grok_number)(aTHX_ a,b,c) #define Perl_grok_number DPPP_(my_grok_number) #if defined(NEED_grok_number) || defined(NEED_grok_number_GLOBAL) int DPPP_(my_grok_number)(pTHX_ const char *pv, STRLEN len, UV *valuep) { const char *s = pv; const char *send = pv + len; const UV max_div_10 = UV_MAX / 10; const char max_mod_10 = UV_MAX % 10; int numtype = 0; int sawinf = 0; int sawnan = 0; while (s < send && isSPACE(*s)) s++; if (s == send) { return 0; } else if (*s == '-') { s++; numtype = IS_NUMBER_NEG; } else if (*s == '+') s++; if (s == send) return 0; /* next must be digit or the radix separator or beginning of infinity */ if (isDIGIT(*s)) { /* UVs are at least 32 bits, so the first 9 decimal digits cannot overflow. */ UV value = *s - '0'; /* This construction seems to be more optimiser friendly. (without it gcc does the isDIGIT test and the *s - '0' separately) With it gcc on arm is managing 6 instructions (6 cycles) per digit. In theory the optimiser could deduce how far to unroll the loop before checking for overflow. */ if (++s < send) { int digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { /* Now got 9 digits, so need to check each time for overflow. */ digit = *s - '0'; while (digit >= 0 && digit <= 9 && (value < max_div_10 || (value == max_div_10 && digit <= max_mod_10))) { value = value * 10 + digit; if (++s < send) digit = *s - '0'; else break; } if (digit >= 0 && digit <= 9 && (s < send)) { /* value overflowed. skip the remaining digits, don't worry about setting *valuep. */ do { s++; } while (s < send && isDIGIT(*s)); numtype |= IS_NUMBER_GREATER_THAN_UV_MAX; goto skip_value; } } } } } } } } } } } } } } } } } } numtype |= IS_NUMBER_IN_UV; if (valuep) *valuep = value; skip_value: if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT; while (s < send && isDIGIT(*s)) /* optional digits after the radix */ s++; } } else if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */ /* no digits before the radix means we need digits after it */ if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); if (valuep) { /* integer approximation is valid - it's 0. */ *valuep = 0; } } else return 0; } else if (*s == 'I' || *s == 'i') { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'F' && *s != 'f')) return 0; s++; if (s < send && (*s == 'I' || *s == 'i')) { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'I' && *s != 'i')) return 0; s++; if (s == send || (*s != 'T' && *s != 't')) return 0; s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0; s++; } sawinf = 1; } else if (*s == 'N' || *s == 'n') { /* XXX TODO: There are signaling NaNs and quiet NaNs. */ s++; if (s == send || (*s != 'A' && *s != 'a')) return 0; s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; sawnan = 1; } else return 0; if (sawinf) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT; } else if (sawnan) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT; } else if (s < send) { /* we can have an optional exponent part */ if (*s == 'e' || *s == 'E') { /* The only flag we keep is sign. Blow away any "it's UV" */ numtype &= IS_NUMBER_NEG; numtype |= IS_NUMBER_NOT_INT; s++; if (s < send && (*s == '-' || *s == '+')) s++; if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); } else return 0; } } while (s < send && isSPACE(*s)) s++; if (s >= send) return numtype; if (len == 10 && memEQ(pv, "0 but true", 10)) { if (valuep) *valuep = 0; return IS_NUMBER_IN_UV; } return 0; } #endif #endif /* * The grok_* routines have been modified to use warn() instead of * Perl_warner(). Also, 'hexdigit' was the former name of PL_hexdigit, * which is why the stack variable has been renamed to 'xdigit'. */ #ifndef grok_bin #if defined(NEED_grok_bin) static UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_bin # undef grok_bin #endif #define grok_bin(a,b,c,d) DPPP_(my_grok_bin)(aTHX_ a,b,c,d) #define Perl_grok_bin DPPP_(my_grok_bin) #if defined(NEED_grok_bin) || defined(NEED_grok_bin_GLOBAL) UV DPPP_(my_grok_bin)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_2 = UV_MAX / 2; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading b or 0b. for compatibility silently suffer "b" and "0b" as valid binary numbers. */ if (len >= 1) { if (s[0] == 'b') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'b') { s+=2; len-=2; } } } for (; len-- && *s; s++) { char bit = *s; if (bit == '0' || bit == '1') { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_bin. */ redo: if (!overflowed) { if (value <= max_div_2) { value = (value << 1) | (bit - '0'); continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in binary number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 2.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount. */ value_nv += (NV)(bit - '0'); continue; } if (bit == '_' && len && allow_underscores && (bit = s[1]) && (bit == '0' || bit == '1')) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal binary digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Binary number > 0b11111111111111111111111111111111 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_hex #if defined(NEED_grok_hex) static UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_hex # undef grok_hex #endif #define grok_hex(a,b,c,d) DPPP_(my_grok_hex)(aTHX_ a,b,c,d) #define Perl_grok_hex DPPP_(my_grok_hex) #if defined(NEED_grok_hex) || defined(NEED_grok_hex_GLOBAL) UV DPPP_(my_grok_hex)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_16 = UV_MAX / 16; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; const char *xdigit; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading x or 0x. for compatibility silently suffer "x" and "0x" as valid hex numbers. */ if (len >= 1) { if (s[0] == 'x') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'x') { s+=2; len-=2; } } } for (; len-- && *s; s++) { xdigit = strchr((char *) PL_hexdigit, *s); if (xdigit) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_hex. */ redo: if (!overflowed) { if (value <= max_div_16) { value = (value << 4) | ((xdigit - PL_hexdigit) & 15); continue; } warn("Integer overflow in hexadecimal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 16.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 16-tuples. */ value_nv += (NV)((xdigit - PL_hexdigit) & 15); continue; } if (*s == '_' && len && allow_underscores && s[1] && (xdigit = strchr((char *) PL_hexdigit, s[1]))) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal hexadecimal digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Hexadecimal number > 0xffffffff non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_oct #if defined(NEED_grok_oct) static UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_oct # undef grok_oct #endif #define grok_oct(a,b,c,d) DPPP_(my_grok_oct)(aTHX_ a,b,c,d) #define Perl_grok_oct DPPP_(my_grok_oct) #if defined(NEED_grok_oct) || defined(NEED_grok_oct_GLOBAL) UV DPPP_(my_grok_oct)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_8 = UV_MAX / 8; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; for (; len-- && *s; s++) { /* gcc 2.95 optimiser not smart enough to figure that this subtraction out front allows slicker code. */ int digit = *s - '0'; if (digit >= 0 && digit <= 7) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. */ redo: if (!overflowed) { if (value <= max_div_8) { value = (value << 3) | digit; continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in octal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 8.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 8-tuples. */ value_nv += (NV)digit; continue; } if (digit == ('_' - '0') && len && allow_underscores && (digit = s[1] - '0') && (digit >= 0 && digit <= 7)) { --len; ++s; goto redo; } /* Allow \octal to work the DWIM way (that is, stop scanning * as soon as non-octal characters are seen, complain only iff * someone seems to want to use the digits eight and nine). */ if (digit == 8 || digit == 9) { if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal octal digit '%c' ignored", *s); } break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Octal number > 037777777777 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #if !defined(my_snprintf) #if defined(NEED_my_snprintf) static int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); static #else extern int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); #endif #define my_snprintf DPPP_(my_my_snprintf) #define Perl_my_snprintf DPPP_(my_my_snprintf) #if defined(NEED_my_snprintf) || defined(NEED_my_snprintf_GLOBAL) int DPPP_(my_my_snprintf)(char *buffer, const Size_t len, const char *format, ...) { dTHX; int retval; va_list ap; va_start(ap, format); #ifdef HAS_VSNPRINTF retval = vsnprintf(buffer, len, format, ap); #else retval = vsprintf(buffer, format, ap); #endif va_end(ap); if (retval < 0 || (len > 0 && (Size_t)retval >= len)) Perl_croak(aTHX_ "panic: my_snprintf buffer overflow"); return retval; } #endif #endif #if !defined(my_sprintf) #if defined(NEED_my_sprintf) static int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); static #else extern int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); #endif #define my_sprintf DPPP_(my_my_sprintf) #define Perl_my_sprintf DPPP_(my_my_sprintf) #if defined(NEED_my_sprintf) || defined(NEED_my_sprintf_GLOBAL) int DPPP_(my_my_sprintf)(char *buffer, const char* pat, ...) { va_list args; va_start(args, pat); vsprintf(buffer, pat, args); va_end(args); return strlen(buffer); } #endif #endif #ifdef NO_XSLOCKS # ifdef dJMPENV # define dXCPT dJMPENV; int rEtV = 0 # define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) # define XCPT_TRY_END JMPENV_POP; # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW JMPENV_JUMP(rEtV) # else # define dXCPT Sigjmp_buf oldTOP; int rEtV = 0 # define XCPT_TRY_START Copy(top_env, oldTOP, 1, Sigjmp_buf); rEtV = Sigsetjmp(top_env, 1); if (rEtV == 0) # define XCPT_TRY_END Copy(oldTOP, top_env, 1, Sigjmp_buf); # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW Siglongjmp(top_env, rEtV) # endif #endif #if !defined(my_strlcat) #if defined(NEED_my_strlcat) static Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); #endif #define my_strlcat DPPP_(my_my_strlcat) #define Perl_my_strlcat DPPP_(my_my_strlcat) #if defined(NEED_my_strlcat) || defined(NEED_my_strlcat_GLOBAL) Size_t DPPP_(my_my_strlcat)(char *dst, const char *src, Size_t size) { Size_t used, length, copy; used = strlen(dst); length = strlen(src); if (size > 0 && used < size - 1) { copy = (length >= size - used) ? size - used - 1 : length; memcpy(dst + used, src, copy); dst[used + copy] = '\0'; } return used + length; } #endif #endif #if !defined(my_strlcpy) #if defined(NEED_my_strlcpy) static Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); #endif #define my_strlcpy DPPP_(my_my_strlcpy) #define Perl_my_strlcpy DPPP_(my_my_strlcpy) #if defined(NEED_my_strlcpy) || defined(NEED_my_strlcpy_GLOBAL) Size_t DPPP_(my_my_strlcpy)(char *dst, const char *src, Size_t size) { Size_t length, copy; length = strlen(src); if (size > 0) { copy = (length >= size) ? size - 1 : length; memcpy(dst, src, copy); dst[copy] = '\0'; } return length; } #endif #endif #ifndef PERL_PV_ESCAPE_QUOTE # define PERL_PV_ESCAPE_QUOTE 0x0001 #endif #ifndef PERL_PV_PRETTY_QUOTE # define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE #endif #ifndef PERL_PV_PRETTY_ELLIPSES # define PERL_PV_PRETTY_ELLIPSES 0x0002 #endif #ifndef PERL_PV_PRETTY_LTGT # define PERL_PV_PRETTY_LTGT 0x0004 #endif #ifndef PERL_PV_ESCAPE_FIRSTCHAR # define PERL_PV_ESCAPE_FIRSTCHAR 0x0008 #endif #ifndef PERL_PV_ESCAPE_UNI # define PERL_PV_ESCAPE_UNI 0x0100 #endif #ifndef PERL_PV_ESCAPE_UNI_DETECT # define PERL_PV_ESCAPE_UNI_DETECT 0x0200 #endif #ifndef PERL_PV_ESCAPE_ALL # define PERL_PV_ESCAPE_ALL 0x1000 #endif #ifndef PERL_PV_ESCAPE_NOBACKSLASH # define PERL_PV_ESCAPE_NOBACKSLASH 0x2000 #endif #ifndef PERL_PV_ESCAPE_NOCLEAR # define PERL_PV_ESCAPE_NOCLEAR 0x4000 #endif #ifndef PERL_PV_ESCAPE_RE # define PERL_PV_ESCAPE_RE 0x8000 #endif #ifndef PERL_PV_PRETTY_NOCLEAR # define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR #endif #ifndef PERL_PV_PRETTY_DUMP # define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE #endif #ifndef PERL_PV_PRETTY_REGPROP # define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE #endif /* Hint: pv_escape * Note that unicode functionality is only backported to * those perl versions that support it. For older perl * versions, the implementation will fall back to bytes. */ #ifndef pv_escape #if defined(NEED_pv_escape) static char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); static #else extern char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); #endif #ifdef pv_escape # undef pv_escape #endif #define pv_escape(a,b,c,d,e,f) DPPP_(my_pv_escape)(aTHX_ a,b,c,d,e,f) #define Perl_pv_escape DPPP_(my_pv_escape) #if defined(NEED_pv_escape) || defined(NEED_pv_escape_GLOBAL) char * DPPP_(my_pv_escape)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags) { const char esc = flags & PERL_PV_ESCAPE_RE ? '%' : '\\'; const char dq = flags & PERL_PV_ESCAPE_QUOTE ? '"' : esc; char octbuf[32] = "%123456789ABCDF"; STRLEN wrote = 0; STRLEN chsize = 0; STRLEN readsize = 1; #if defined(is_utf8_string) && defined(utf8_to_uvchr) bool isuni = flags & PERL_PV_ESCAPE_UNI ? 1 : 0; #endif const char *pv = str; const char * const end = pv + count; octbuf[0] = esc; if (!(flags & PERL_PV_ESCAPE_NOCLEAR)) sv_setpvs(dsv, ""); #if defined(is_utf8_string) && defined(utf8_to_uvchr) if ((flags & PERL_PV_ESCAPE_UNI_DETECT) && is_utf8_string((U8*)pv, count)) isuni = 1; #endif for (; pv < end && (!max || wrote < max) ; pv += readsize) { const UV u = #if defined(is_utf8_string) && defined(utf8_to_uvchr) isuni ? utf8_to_uvchr((U8*)pv, &readsize) : #endif (U8)*pv; const U8 c = (U8)u & 0xFF; if (u > 255 || (flags & PERL_PV_ESCAPE_ALL)) { if (flags & PERL_PV_ESCAPE_FIRSTCHAR) chsize = my_snprintf(octbuf, sizeof octbuf, "%"UVxf, u); else chsize = my_snprintf(octbuf, sizeof octbuf, "%cx{%"UVxf"}", esc, u); } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) { chsize = 1; } else { if (c == dq || c == esc || !isPRINT(c)) { chsize = 2; switch (c) { case '\\' : /* fallthrough */ case '%' : if (c == esc) octbuf[1] = esc; else chsize = 1; break; case '\v' : octbuf[1] = 'v'; break; case '\t' : octbuf[1] = 't'; break; case '\r' : octbuf[1] = 'r'; break; case '\n' : octbuf[1] = 'n'; break; case '\f' : octbuf[1] = 'f'; break; case '"' : if (dq == '"') octbuf[1] = '"'; else chsize = 1; break; default: chsize = my_snprintf(octbuf, sizeof octbuf, pv < end && isDIGIT((U8)*(pv+readsize)) ? "%c%03o" : "%c%o", esc, c); } } else { chsize = 1; } } if (max && wrote + chsize > max) { break; } else if (chsize > 1) { sv_catpvn(dsv, octbuf, chsize); wrote += chsize; } else { char tmp[2]; my_snprintf(tmp, sizeof tmp, "%c", c); sv_catpvn(dsv, tmp, 1); wrote++; } if (flags & PERL_PV_ESCAPE_FIRSTCHAR) break; } if (escaped != NULL) *escaped= pv - str; return SvPVX(dsv); } #endif #endif #ifndef pv_pretty #if defined(NEED_pv_pretty) static char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); static #else extern char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); #endif #ifdef pv_pretty # undef pv_pretty #endif #define pv_pretty(a,b,c,d,e,f,g) DPPP_(my_pv_pretty)(aTHX_ a,b,c,d,e,f,g) #define Perl_pv_pretty DPPP_(my_pv_pretty) #if defined(NEED_pv_pretty) || defined(NEED_pv_pretty_GLOBAL) char * DPPP_(my_pv_pretty)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags) { const U8 dq = (flags & PERL_PV_PRETTY_QUOTE) ? '"' : '%'; STRLEN escaped; if (!(flags & PERL_PV_PRETTY_NOCLEAR)) sv_setpvs(dsv, ""); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, "<"); if (start_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(start_color)); pv_escape(dsv, str, count, max, &escaped, flags | PERL_PV_ESCAPE_NOCLEAR); if (end_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(end_color)); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, ">"); if ((flags & PERL_PV_PRETTY_ELLIPSES) && escaped < count) sv_catpvs(dsv, "..."); return SvPVX(dsv); } #endif #endif #ifndef pv_display #if defined(NEED_pv_display) static char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); static #else extern char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); #endif #ifdef pv_display # undef pv_display #endif #define pv_display(a,b,c,d,e) DPPP_(my_pv_display)(aTHX_ a,b,c,d,e) #define Perl_pv_display DPPP_(my_pv_display) #if defined(NEED_pv_display) || defined(NEED_pv_display_GLOBAL) char * DPPP_(my_pv_display)(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) { pv_pretty(dsv, pv, cur, pvlim, NULL, NULL, PERL_PV_PRETTY_DUMP); if (len > cur && pv[cur] == '\0') sv_catpvs(dsv, "\\0"); return SvPVX(dsv); } #endif #endif #endif /* _P_P_PORTABILITY_H_ */ /* End of File ppport.h */ di-4.52/C/Perl/README0000644000175000017500000000075514421556642012130 0ustar bllbllFilesys-di version 0.01 ======================== Perl XS does not seem to have a long long type, so there may be a loss of precision in the conversion of long long to double. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Test COPYRIGHT AND LICENSE Copyright (C) 2016 by Brad Lanam Distributed with 'di'. See the LICENSE file at the top level. di-4.52/C/Perl/MANIFEST0000644000175000017500000000012314421556642012366 0ustar bllbllChanges di.xs Makefile.PL MANIFEST ppport.h README t/diskspace.t lib/Filesys/di.pm di-4.52/C/Perl/t/0000755000175000017500000000000014421556642011504 5ustar bllblldi-4.52/C/Perl/t/diskspace.t0000644000175000017500000000157714421556642013651 0ustar bllbll# Before 'make install' is performed this script should be runnable with # 'make test'. After 'make install' it should work as 'perl Filesys-di.t' ######################### use strict; use warnings; use Test::More; BEGIN { use_ok( 'Filesys::di', qw(diskspace) ); } #use Data::Dumper; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. my $h = diskspace (''); my @a = keys %{$h}; ok ($#a > 0, 'standard'); $h = diskspace ('-d 1 -f buvp'); @a = keys %{$h}; my $path = '/'; if (! exists($h->{$path})) { $path = 'C:\\'; } my $disp = $h->{$path}->{'display'}; my $count = $#{$h->{$path}->{'display'}}; ok ($#a > 0 && $count == 3, 'with arguments'); my $val = $h->{$path}->{'display'}[1]; ok ($#a > 0 && $count == 3 && $val =~ /^\d+$/, 'has a value'); done_testing(); di-4.52/C/Perl/lib/0000755000175000017500000000000014421556642012007 5ustar bllblldi-4.52/C/Perl/lib/Filesys/0000755000175000017500000000000014421556642013425 5ustar bllblldi-4.52/C/Perl/lib/Filesys/di.pm0000644000175000017500000000352414421556642014363 0ustar bllbllpackage Filesys::di; use 5.00503; use strict; require Exporter; require DynaLoader; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Filesys::di ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); @EXPORT = qw( diskspace ); $VERSION = '0.01'; bootstrap Filesys::di $VERSION; # Preloaded methods go here. 1; __END__ # Below is stub documentation for your module. You'd better edit it! =head1 NAME Filesys::di - Perl extension for 'di' =head1 SYNOPSIS use Filesys::di; my $di = Filesys::di::diskspace (''); my $di = Filesys::di::diskspace ('-d 1 -f buvp'); =head1 DESCRIPTION Returns a reference to a hash. The hash keys are the mount points. Each hash contains the following keys: device (special device name), fstype (filesystem type), total, free, available, totalinodes, freeinodes, availableinodes, mountoptions. If a format is specified, the hash will also contain a 'display' key pointing to a reference to an array containing the display output from the 'di' program. Perl XS does not seem to have a long long type, so there may be a loss of precision in the conversion of long long to double. See the main 'di' documentation for usage. =head2 EXPORT None by default. =head1 SEE ALSO di(1) http://gentoo.com/di/ =head1 AUTHOR Brad Lanam, Ebrad.lanam.di@gmail.comE =head1 COPYRIGHT AND LICENSE Copyright 2016 Brad Lanam, Walnut Creek CA See the LICENSE file included with the 'di' distribution. =cut di-4.52/C/Perl/Changes0000644000175000017500000000012614421556642012533 0ustar bllbllRevision history for Perl extension Filesys::di. 0.01 2016-2-22 - initial version di-4.52/C/Perl/di.xs0000644000175000017500000000702214421556642012212 0ustar bllbll#define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "config.h" #include "dimain.h" #include "di.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _sys_types \ && ! defined (_DI_INC_SYS_TYPES_H) /* xenix */ # define _DI_INC_SYS_TYPES_H # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif #define DI_ARGV_SEP " " /* space, tab */ #define DI_MAX_ARGV 50 static AV * parsedisp (pTHX_ char *val) { AV *a; char *dptr; a = newAV(); dptr = strtok (val, " "); /* tab character */ while (dptr != (char *) NULL) { av_push (a, newSVpv (dptr, 0)); dptr = strtok (NULL, " "); /* tab character */ } return a; } static SV * diproc (pTHX_ char *args) { int argscount; int argc; const char *argv [DI_MAX_ARGV]; char *tptr; char **dispargs; int i; diData_t diDataOut; char *rv; diDiskInfo_t *diskInfo; diDiskInfo_t *dinfo; HV *rh; HV *dh; SV *RETVAL; argv[0] = "diskspace"; if (args == (char *) NULL || strcmp (args, "") == 0) { argc = 3; argv[1] = "-f"; argv[2] = ""; argv[3] = NULL; } else { tptr = strtok (args, DI_ARGV_SEP); argc = 1; while (tptr != (char *) NULL) { if (argc >= DI_MAX_ARGV) { break; } argv[argc++] = tptr; tptr = strtok ((char *) NULL, DI_ARGV_SEP); } } rv = dimainproc (argc, argv, 1, &diDataOut); diskInfo = diDataOut.diskInfo; dispargs = (char **) malloc (sizeof(char *) * (Size_t) diDataOut.count); if (rv != (char *) NULL) { tptr = strtok (rv, "\n"); } else { tptr = (char *) NULL; } for (i = 0; i < diDataOut.count; ++i) { dinfo = &(diskInfo [diskInfo [i].sortIndex[DI_TOT_SORT_IDX]]); if (! dinfo->doPrint) { continue; } dispargs[i] = tptr; if (rv != (char *) NULL) { tptr = strtok (NULL, "\n"); } } rh = (HV *) sv_2mortal ((SV *) newHV()); for (i = 0; i < diDataOut.count; ++i) { dinfo = &(diskInfo [diskInfo [i].sortIndex[DI_TOT_SORT_IDX]]); if (! dinfo->doPrint) { continue; } dh = newHV(); /* dh = (HV *) sv_2mortal ((SV *) newHV()); */ hv_store (dh, "device", 6, newSVpv (dinfo->special, 0), 0); hv_store (dh, "fstype", 6, newSVpv (dinfo->fsType, 0), 0); hv_store (dh, "total", 5, newSVnv (dinfo->totalSpace), 0); hv_store (dh, "free", 4, newSVnv (dinfo->freeSpace), 0); hv_store (dh, "available", 9, newSVnv (dinfo->availSpace), 0); hv_store (dh, "totalinodes", 11, newSVnv (dinfo->totalInodes), 0); hv_store (dh, "freeinodes", 10, newSVnv (dinfo->freeInodes), 0); hv_store (dh, "availableinodes", 15, newSVnv (dinfo->availInodes), 0); hv_store (dh, "mountoptions", 12, newSVpv (dinfo->options, 0), 0); if (dispargs[i] != (char *) NULL) { hv_store (dh, "display", 7, newRV ((SV *) parsedisp (aTHX_ dispargs[i])), 0); } hv_store (rh, dinfo->name, (I32) strlen (dinfo->name), newRV ((SV *) dh), 0); } RETVAL = newRV ((SV *) rh); free (rv); free (dispargs); cleanup (&diDataOut); return RETVAL; } MODULE = Filesys::di PACKAGE = Filesys::di SV * diskspace (char *args) PROTOTYPE: $ CODE: RETVAL = diproc (aTHX_ args); OUTPUT: RETVAL di-4.52/C/options.h0000644000175000017500000000171614421556642012210 0ustar bllbll#ifndef DI_INC_OPTIONS_H #define DI_INC_OPTIONS_H /* * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #define DI_VAL_512 512.0 #define DI_VAL_1000 1000.0 #define DI_DISP_1000_IDX 0 #define DI_VAL_1024 1024.0 #define DI_DISP_1024_IDX 1 /* these are indexes into the dispTable array... */ #define DI_ONE_K 0 #define DI_ONE_MEG 1 #define DI_ONE_GIG 2 #define DI_ONE_TERA 3 #define DI_ONE_PETA 4 #define DI_ONE_EXA 5 #define DI_ONE_ZETTA 6 #define DI_ONE_YOTTA 7 #define DI_DISP_HR -20.0 #define DI_DISP_HR_2 -21.0 # if defined (__cplusplus) || defined (c_plusplus) extern "C" { # endif extern int getDIOptions (int , const char * const [], diData_t *); # if defined (__cplusplus) || defined (c_plusplus) } # endif #endif /* DI_INC_OPTIONS_H */ di-4.52/C/trimchar.c0000644000175000017500000000101314421556642012307 0ustar bllbll/* * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #include "di.h" #if _hdr_stdio # include #endif #if _hdr_stdlib # include #endif #if _hdr_string # include #endif #if _hdr_strings # include #endif void trimChar (char *str, int ch) { int len; len = (int) strlen (str); if (len > 0) { --len; } if (len >= 0) { if (str [len] == ch) { str [len] = '\0'; } } } di-4.52/C/dimntopt.h0000644000175000017500000000675014421556642012356 0ustar bllbll#ifndef DI_INC_DIMNTOPT_H_ #define DI_INC_DIMNTOPT_H_ /* * Copyright 2011-2018 Brad Lanam, Walnut Creek, CA * Copyright 2023 Brad Lanam, Pleasant Hill, CA */ #include "config.h" #if _hdr_mntent \ && ! defined (DI_INC_MNTENT) /* Linux, kFreeBSD, HP-UX */ # define DI_INC_MNTENT 1 # include /* MNTOPT_... */ #endif #if _sys_mount \ && ! defined (DI_INC_SYS_MOUNT) /* FreeBSD, OpenBSD, NetBSD, HP-UX */ # define DI_INC_SYS_MOUNT 1 # include /* MNT_...; M_... (hp-ux) */ #endif #if _sys_mnttab /* SCO_SV, UnixWare */ # include /* required for mntent.h */ #endif #if _sys_mntent /* Solaris, SCO_SV, UnixWare */ # include /* MNTOPT_... */ #endif #if _sys_fstypes /* NetBSD */ # include #endif #if _sys_vmount /* AIX */ # include /* MNT_... */ #endif #if _hdr_mnttab /* SysV.3 */ # include #endif /********************************************************/ /* remap mount flags */ #if defined (B_FS_IS_READONLY) # define MNT_RDONLY B_FS_IS_READONLY #endif #if defined (FS_IS_READONLY) # define MNT_RDONLY FS_IS_READONLY #endif #if defined (M_RDONLY) # define MNT_RDONLY M_RDONLY #endif #if defined (MNT_READONLY) # define MNT_RDONLY MNT_READONLY #endif #if defined (M_RONLY) # define MNT_RDONLY M_RONLY #endif #if defined (M_SYNCHRONOUS) # define MNT_SYNCHRONOUS M_SYNCHRONOUS #endif #if defined (M_NOEXEC) # define MNT_NOEXEC M_NOEXEC #endif #if defined (M_NOSUID) # define MNT_NOSUID M_NOSUID #endif #if defined (M_NODEV) # define MNT_NODEV M_NODEV #endif #if defined (M_NOATIMES) # define MNT_NOATIMES M_NOATIMES #endif #if defined (M_GRPID) # define MNT_GRPID M_GRPID #endif #if defined (M_SECURE) # define MNT_SECURE M_SECURE #endif #if defined (M_MLSD) # define MNT_MLSD M_MLSD #endif #if defined (M_SMSYNC2) # define MNT_SMSYNC2 M_SMSYNC2 #endif #if defined (M_LOCAL) # define MNT_LOCAL M_LOCAL #endif #if defined (M_FORCE) # define MNT_FORCE M_FORCE #endif #if defined (M_SYNC) # define MNT_SYNC M_SYNC #endif #if defined (M_NOCACHE) # define MNT_NOCACHE M_NOCACHE #endif #if defined (B_FS_IS_REMOVABLE) # define MNT_REMOVABLE B_FS_IS_REMOVABLE #endif #if defined (FS_IS_REMOVABLE) # define MNT_REMOVABLE FS_IS_REMOVABLE #endif #if defined (B_FS_IS_PERSISTENT) # define MNT_PERSISTENT B_FS_IS_PERSISTENT #endif #if defined (FS_IS_PERSISTENT) # define MNT_PERSISTENT FS_IS_PERSISTENT #endif #if defined (B_FS_IS_SHARED) # define MNT_SHARED B_FS_IS_SHARED #endif #if defined (FS_IS_SHARED) # define MNT_SHARED FS_IS_SHARED #endif #if defined (FS_IS_BLOCKBASED) # define MNT_BLOCKBASED FS_IS_BLOCKBASED #endif #if defined (B_FS_HAS_MIME) # define MNT_HAS_MIME B_FS_HAS_MIME #endif #if defined (FS_HAS_MIME) # define MNT_HAS_MIME FS_HAS_MIME #endif #if defined (B_FS_HAS_ATTR) # define MNT_HAS_ATTR B_FS_HAS_ATTR #endif #if defined (FS_HAS_ATTR) # define MNT_HAS_ATTR FS_HAS_ATTR #endif #if defined (B_FS_HAS_QUERY) # define MNT_HAS_QUERY B_FS_HAS_QUERY #endif #if defined (FS_HAS_QUERY) # define MNT_HAS_QUERY FS_HAS_QUERY #endif #if defined (MNTOPT_IGNORE) # define DI_MNTOPT_IGNORE MNTOPT_IGNORE #else # define DI_MNTOPT_IGNORE "ignore" #endif #if defined (MNTOPT_RO) # define DI_MNTOPT_RO MNTOPT_RO #else # define DI_MNTOPT_RO "ro" #endif #if defined (MNTOPT_DEV) # define DI_MNTOPT_DEV MNTOPT_DEV #else # define DI_MNTOPT_DEV "dev=" #endif #endif /* DI_INC_DIMNTOPT_H_ */ di-4.52/mktar.sh0000755000175000017500000000071014421556642011630 0ustar bllbll#!/bin/sh ver=`grep DI_VERSION C/version.h | sed -e 's/"$//' -e 's/.*"//'` PKG=di cwd=`pwd` dir="${PKG}-${ver}" rm -rf $dir > /dev/null 2>&1 mkdir $dir chmod 755 $dir sed 's,[/]*[ ].*$,,' MANIFEST | while read f; do if [ -d $f ]; then mkdir $dir/$f chmod 755 $dir/$f else d=`dirname $f` cp $f $dir/$d fi done cp -r mkconfig $dir chmod -R a+r $dir tar cf - $dir | gzip -9 > $dir.tar.gz rm -rf $dir > /dev/null 2>&1 exit 0 di-4.52/po/0000755000175000017500000000000014421556642010573 5ustar bllblldi-4.52/po/es.po0000644000175000017500000001160014421556642011540 0ustar bllbll# msgid "" msgstr "" "Project-Id-Version: di $Revision$\n" "POT-Creation-Date: 2010-03-08 00:05-0800\n" "PO-Revision-Date: 2010-03-08 00:05-0800\n" "Last-Translator: David Sastre Medina \n" "Language-Team: Español \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" # domain "di" msgid " m - megabytes, g - gigabytes, t - terabytes, h - human readable).\n" msgstr " m - megabytes, g - gigabytes, t - terabytes, h - legible).\n" msgid " [-I include-fstyp-list] [file [...]]\n" msgstr " [-I incluir-lista-tipos-de-sf] [fichero [...]]\n" msgid " 2 - percentage of user-available space in use.\n" msgstr " 2 - porcentaje de espacio disponible de usuario en uso.\n" msgid " F - free file slots P - percentage file slots used\n" msgstr " F - inodos libres P - porcentaje de inodos usados\n" msgid "See manual page for more options.\n" msgstr "Vea página de manual para más opciones.\n" msgid " b - total kbytes B - kbytes available for use\n" msgstr " b - kbytes totales B - kbytes disponibles para uso\n" msgid " f - kbytes free v - kbytes available\n" msgstr " f - kbytes libres v - kbytes disponibles\n" msgid " i - total file slots (i-nodes) U - used file slots\n" msgstr " i - total inodos (i-nodes) U - inodos usados\n" msgid " m - mount point M - mount point, full length\n" msgstr " m - punto de montaje M - punto de montaje, nombre largo\n" msgid " p - percentage not avail. for use 1 - percentage used\n" msgstr " p - porcentaje no disponible 1 - porcentaje usado\n" msgid " s - filesystem name S - filesystem name, full length\n" msgstr " s - nombre de sistema de ficheros S - nombre de sistemas de ficheros, nombre largo\n" msgid " t - disk partition type T - partition type, full length\n" msgstr " t - tipo de partición en disco T - tipo de partición, nombre completo\n" msgid " u - used kbytes c - calculated kbytes in use\n" msgstr " u - kbytes usados c - cálculo de kbytes en uso\n" msgid " -I x : include only file system types in \n" msgstr " -I x : incluir sólo los tipos de sistemas de ficheros en \n" msgid " -a : print all mounted devices\n" msgstr " -a : mostrar todos los dispositivos montados\n" msgid " -d x : size to print blocks in (512 - POSIX, k - kbytes,\n" msgstr " -d x : tamaño de bloque a mostrar (512 - POSIX, k - kbytes,\n" msgid " -f x : use format string \n" msgstr " -f x : usar formato \n" msgid " -x x : exclude file system types in \n" msgstr " -x x : excluir tipos de sistemas de ficheros en \n" msgid " -l : display local filesystems only\n" msgstr " -l : mostrar sistemas de ficheros locales\n" msgid " -n : don't print header\n" msgstr " -n : no mostrar cabecera\n" msgid " -t : print totals\n" msgstr " -t : mostrar totales\n" msgid " Format string values:\n" msgstr " Valores de formato de cadena:\n" #, no-c-format msgid "%IFree" msgstr "%ILibre" #, no-c-format msgid "%IUsed" msgstr "%IUsado" #, no-c-format msgid "%Used" msgstr "%Usado" msgid "Capacity" msgstr "Capacidad" #, no-c-format msgid "%Free" msgstr "%Libre" msgid "Avail" msgstr "Dispon" msgid "Available" msgstr "Disponible" msgid "Exas" msgstr "Exas" msgid "Exbis" msgstr "Exbis" msgid "Filesystem" msgstr "Sistema de ficheros" msgid "Free" msgstr "Libre" msgid "Gigs" msgstr "Gigs" msgid "Inodes" msgstr "Inodos" msgid "IUsed" msgstr "IUsado" msgid "512-blocks" msgstr "512-bloques" msgid "KBytes" msgstr "KBytes" msgid "1024-blocks" msgstr "1024-bloques" msgid "Megs" msgstr "Megs" msgid "Mebis" msgstr "Mebis" msgid "Mount" msgstr "Mountado" msgid "Mounted On" msgstr "Montado En" msgid "Mount Time" msgstr "Momento de Montaje" msgid "Options" msgstr "Opciones" msgid "Petas" msgstr "Petas" msgid "Pebis" msgstr "Pebis" msgid "Size" msgstr "Tamaño" msgid "Teras" msgstr "Teras" msgid "Tebis" msgstr "Tebis" msgid "Total" msgstr "Total" msgid "Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n" msgstr "Uso: di [-ant] [-d tamaño-display] [-f formato] [-x excluir-lista-tipos-de-sf]\n" msgid "Used" msgstr "Usado" msgid "Yottas" msgstr "Yottas" msgid "Yobis" msgstr "Yobis" msgid "Zettas" msgstr "Zettas" msgid "Zebis" msgstr "Zebis" #, c-format msgid "di version %s Default Format: %s\n" msgstr "di version %s Formato por Defecto: %s\n" #, c-format msgid "di version %s Default Format: %s\n" msgstr "di version %s Formato por Defecto: %s\n" #, no-c-format msgid "fs Type" msgstr "Tipo de sf" msgid "fsType" msgstr "Tipo de sf" di-4.52/po/en.po0000644000175000017500000001130414421556642011534 0ustar bllbll# msgid "" msgstr "" "Project-Id-Version: di $Revision$\n" "POT-Creation-Date: 2007-01-17 14:23-0800\n" "PO-Revision-Date: 2007-01-17 14:23-0800\n" "Last-Translator: Brad Lanam \n" "Language-Team: English \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" # domain "di" msgid " m - megabytes, g - gigabytes, t - terabytes, h - human readable).\n" msgstr " m - megabytes, g - gigabytes, t - terabytes, h - human readable).\n" msgid " [-I include-fstyp-list] [file [...]]\n" msgstr " [-I include-fstyp-list] [file [...]]\n" msgid " 2 - percentage of user-available space in use.\n" msgstr " 2 - percentage of user-available space in use.\n" msgid " F - free file slots P - percentage file slots used\n" msgstr " F - free file slots P - percentage file slots used\n" msgid "See manual page for more options.\n" msgstr "See manual page for more options.\n" msgid " b - total kbytes B - kbytes available for use\n" msgstr " b - total kbytes B - kbytes available for use\n" msgid " f - kbytes free v - kbytes available\n" msgstr " f - kbytes free v - kbytes available\n" msgid " i - total file slots (i-nodes) U - used file slots\n" msgstr " i - total file slots (i-nodes) U - used file slots\n" msgid " m - mount point M - mount point, full length\n" msgstr " m - mount point M - mount point, full length\n" msgid " p - percentage not avail. for use 1 - percentage used\n" msgstr " p - percentage not avail. for use 1 - percentage used\n" msgid " s - filesystem name S - filesystem name, full length\n" msgstr " s - filesystem name S - filesystem name, full length\n" msgid " t - disk partition type T - partition type, full length\n" msgstr " t - disk partition type T - partition type, full length\n" msgid " u - used kbytes c - calculated kbytes in use\n" msgstr " u - used kbytes c - calculated kbytes in use\n" msgid " -I x : include only file system types in \n" msgstr " -I x : include only file system types in \n" msgid " -a : print all mounted devices\n" msgstr " -a : print all mounted devices\n" msgid " -d x : size to print blocks in (512 - POSIX, k - kbytes,\n" msgstr " -d x : size to print blocks in (512 - POSIX, k - kbytes,\n" msgid " -f x : use format string \n" msgstr " -f x : use format string \n" msgid " -x x : exclude file system types in \n" msgstr " -x x : exclude file system types in \n" msgid " -l : display local filesystems only\n" msgstr " -l : display local filesystems only\n" msgid " -n : don't print header\n" msgstr " -n : don't print header\n" msgid " -t : print totals\n" msgstr " -t : print totals\n" msgid " Format string values:\n" msgstr " Format string values:\n" #, no-c-format msgid "%IFree" msgstr "%IFree" #, no-c-format msgid "%IUsed" msgstr "%IUsed" #, no-c-format msgid "%Used" msgstr "%Used" msgid "Capacity" msgstr "Capacity" #, no-c-format msgid "%Free" msgstr "%Free" msgid "Avail" msgstr "Avail" msgid "Available" msgstr "Available" msgid "Exas" msgstr "Exas" msgid "Exbis" msgstr "Exbis" msgid "Filesystem" msgstr "Filesystem" msgid "Free" msgstr "Free" msgid "Gigs" msgstr "Gigs" msgid "Inodes" msgstr "Inodes" msgid "IUsed" msgstr "IUsed" msgid "512-blocks" msgstr "512-blocks" msgid "KBytes" msgstr "KBytes" msgid "1024-blocks" msgstr "1024-blocks" msgid "Megs" msgstr "Megs" msgid "Mebis" msgstr "Mebis" msgid "Mount" msgstr "Mount" msgid "Mounted On" msgstr "Mounted On" msgid "Mount Time" msgstr "Mount Time" msgid "Options" msgstr "Options" msgid "Petas" msgstr "Petas" msgid "Pebis" msgstr "Pebis" msgid "Size" msgstr "Size" msgid "Teras" msgstr "Teras" msgid "Tebis" msgstr "Tebis" msgid "Total" msgstr "Total" msgid "Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n" msgstr "Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n" msgid "Used" msgstr "Used" msgid "Yottas" msgstr "Yottas" msgid "Yobis" msgstr "Yobis" msgid "Zettas" msgstr "Zettas" msgid "Zebis" msgstr "Zebis" #, c-format msgid "di version %s Default Format: %s\n" msgstr "di version %s Default Format: %s\n" #, c-format msgid "di version %s Default Format: %s\n" msgstr "di version %s Default Format: %s\n" #, no-c-format msgid "fs Type" msgstr "fs Type" msgid "fsType" msgstr "fsType" di-4.52/po/de.po0000644000175000017500000001140014421556642011517 0ustar bllbll# msgid "" msgstr "" "Project-Id-Version: di $Revision$\n" "POT-Creation-Date: 2007-01-17 14:23-0800\n" "PO-Revision-Date: 2007-01-17 14:23-0800\n" "Last-Translator: Hartmut Haase \n" "Language-Team: German \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" # domain "di" msgid " m - megabytes, g - gigabytes, t - terabytes, h - human readable).\n" msgstr " m - Megabyte, g - Gigabyte, t - Terabyte, h - lesbar).\n" msgid " [-I include-fstyp-list] [file [...]]\n" msgstr " [-I include-fstyp-list] [Datei [...]]\n" msgid " 2 - percentage of user-available space in use.\n" msgstr " 2 - Prozent des benutzten verfügbaren Platzes.\n" msgid " F - free file slots P - percentage file slots used\n" msgstr " F - Dateislots freigeben P - Prozent der benutzten Dateislots\n" msgid "See manual page for more options.\n" msgstr "Siehe man-Seite für weitere Optionen.\n" msgid " b - total kbytes B - kbytes available for use\n" msgstr " b - KB gesamt B - verfügbare KB\n" msgid " f - kbytes free v - kbytes available\n" msgstr " f - KB frei v - verfügbare KB\n" msgid " i - total file slots (i-nodes) U - used file slots\n" msgstr " i - Dateislots gesamt (i-nodes) U - benutzte Dateislots\n" msgid " m - mount point M - mount point, full length\n" msgstr " m - Mountpunkt M - Mountpunkt, volle Länge\n" msgid " p - percentage not avail. for use 1 - percentage used\n" msgstr " p - Prozent nicht benutzbar 1 - Prozent benutzt\n" msgid " s - filesystem name S - filesystem name, full length\n" msgstr " s - Dateisystemname S - Dateisystemname, volle Länge\n" msgid " t - disk partition type T - partition type, full length\n" msgstr " t - Plattenpartitionstyp T - Partitionstyp, volle Länge\n" msgid " u - used kbytes c - calculated kbytes in use\n" msgstr " u - benutzte KB c - benutzte KB (berechnet)\n" msgid " -I x : include only file system types in \n" msgstr " -I x : nur Dateisystemtypen in einfügen\n" msgid " -a : print all mounted devices\n" msgstr " -a : alle eingehängten Geräte auflisten\n" msgid " -d x : size to print blocks in (512 - POSIX, k - kbytes,\n" msgstr " -d x : Größe der angezeigten Blöcke (512 - POSIX, k - KB,\n" msgid " -f x : use format string \n" msgstr " -f x : benutze Formatzeichen \n" msgid " -x x : exclude file system types in \n" msgstr " -x x : Dateisystemtyp in ignorieren\n" msgid " -l : display local filesystems only\n" msgstr " -l : nur lokale Dateisysteme anzeigen\n" msgid " -n : don't print header\n" msgstr " -n : keine Kopf drucken\n" msgid " -t : print totals\n" msgstr " -t : Summen drucken\n" msgid " Format string values:\n" msgstr " Formatzeichenkette:\n" #, no-c-format msgid "%IFree" msgstr "%IFrei" #, no-c-format msgid "%IUsed" msgstr "%IBen." #, no-c-format msgid "%Used" msgstr "%Ben." #, no-c-format msgid "Capacity" msgstr "Benutzt%" #, no-c-format msgid "%Free" msgstr "%Frei" msgid "Avail" msgstr "Verfügb." msgid "Available" msgstr "Verfügbar" msgid "Exas" msgstr "Exas" msgid "Exbis" msgstr "Exbis" msgid "Filesystem" msgstr "Dateisystem" msgid "Free" msgstr "Frei" msgid "Gigs" msgstr "GB" msgid "Gibis" msgstr "GB" msgid "Inodes" msgstr "Inodes" msgid "IUsed" msgstr "IBenutzt" msgid "512-blocks" msgstr "512-Blöcke" msgid "KBytes" msgstr "KB" msgid "1024-blocks" msgstr "1024-Blöcke" msgid "Megs" msgstr "MB" msgid "Mebis" msgstr "MB" msgid "Mount" msgstr "Mountpunkt" msgid "Mounted On" msgstr "Eingehängt auf" msgid "Mount Time" msgstr "Mountzeit" msgid "Options" msgstr "Optionen" msgid "Petas" msgstr "Petas" msgid "Pebis" msgstr "Pebis" msgid "Size" msgstr "Größe" msgid "Teras" msgstr "TB" msgid "Tebis" msgstr "TB" msgid "Total" msgstr "Gesamt" msgid "Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n" msgstr "Aufruf: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n" msgid "Used" msgstr "Benutzt" msgid "Yottas" msgstr "Yottas" msgid "Yobis" msgstr "Yobis" msgid "Zettas" msgstr "Zettas" msgid "Zebis" msgstr "Zebis" #, c-format msgid "di version %s Default Format: %s\n" msgstr "di version %s Standardformat: %s\n" #, c-format msgid "di version %s Default Format: %s\n" msgstr "di version %s Standardformat: %s\n" #, no-c-format msgid "fs Type" msgstr "D.typ" msgid "fsType" msgstr "D.typ"