Repository: fastfetch-cli/fastfetch
Branch: dev
Commit: 56eabbe2cb96
Files: 1400
Total size: 5.0 MB
Directory structure:
gitextract_aqn42s14/
├── .codespellrc
├── .editorconfig
├── .gitattributes
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report_crash.yml
│ │ ├── bug_report_general.yml
│ │ ├── bug_report_logo.yml
│ │ ├── feature_request.yml
│ │ └── logo_request.yml
│ ├── pull_request_template.md
│ ├── stale.yml
│ └── workflows/
│ └── ci.yml
├── .gitignore
├── CHANGELOG.md
├── CMakeLists.txt
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README-cn.md
├── README.md
├── completions/
│ ├── fastfetch.bash
│ ├── fastfetch.fish
│ └── fastfetch.zsh
├── debian/
│ ├── changelog.tpl
│ ├── compat
│ ├── control
│ ├── copyright
│ ├── publish.sh
│ ├── rules
│ └── watch
├── doc/
│ ├── fastfetch.1.in
│ └── json_schema.json
├── presets/
│ ├── all.jsonc
│ ├── archey.jsonc
│ ├── ci.jsonc
│ ├── examples/
│ │ ├── 10.jsonc
│ │ ├── 11.jsonc
│ │ ├── 12.jsonc
│ │ ├── 13.jsonc
│ │ ├── 14.jsonc
│ │ ├── 15.jsonc
│ │ ├── 16.jsonc
│ │ ├── 17.jsonc
│ │ ├── 18.jsonc
│ │ ├── 19.jsonc
│ │ ├── 2.jsonc
│ │ ├── 20.jsonc
│ │ ├── 21.jsonc
│ │ ├── 22.jsonc
│ │ ├── 23.jsonc
│ │ ├── 24.jsonc
│ │ ├── 25.jsonc
│ │ ├── 26.jsonc
│ │ ├── 27.jsonc
│ │ ├── 28.jsonc
│ │ ├── 29.jsonc
│ │ ├── 3.jsonc
│ │ ├── 30.jsonc
│ │ ├── 31.jsonc
│ │ ├── 32.jsonc
│ │ ├── 4.jsonc
│ │ ├── 5.jsonc
│ │ ├── 6.jsonc
│ │ ├── 7.jsonc
│ │ ├── 8.jsonc
│ │ └── 9.jsonc
│ ├── neofetch.jsonc
│ ├── paleofetch.jsonc
│ └── screenfetch.jsonc
├── run.sh
├── scripts/
│ ├── gen-amdgpuids.py
│ ├── gen-man.py
│ └── gen-pciids.py
├── src/
│ ├── 3rdparty/
│ │ ├── display-library/
│ │ │ ├── adl_defines.h
│ │ │ ├── adl_sdk.h
│ │ │ ├── adl_structures.h
│ │ │ └── repo.json
│ │ ├── widecharwidth/
│ │ │ ├── repo.json
│ │ │ └── widechar_width_c.h
│ │ └── yyjson/
│ │ ├── repo.json
│ │ ├── yyjson.c
│ │ └── yyjson.h
│ ├── common/
│ │ ├── FFPlatform.h
│ │ ├── FFcheckmacros.h
│ │ ├── FFlist.h
│ │ ├── FFstrbuf.h
│ │ ├── apple/
│ │ │ ├── Info.plist.in
│ │ │ ├── cf_helpers.c
│ │ │ ├── cf_helpers.h
│ │ │ ├── osascript.h
│ │ │ ├── osascript.m
│ │ │ ├── smc_temps.c
│ │ │ └── smc_temps.h
│ │ ├── argType.h
│ │ ├── arrayUtils.h
│ │ ├── base64.h
│ │ ├── binary.h
│ │ ├── color.h
│ │ ├── commandoption.h
│ │ ├── dbus.h
│ │ ├── debug.h
│ │ ├── duration.h
│ │ ├── edidHelper.h
│ │ ├── ffdata.h
│ │ ├── font.h
│ │ ├── format.h
│ │ ├── frequency.h
│ │ ├── haiku/
│ │ │ ├── version.cpp
│ │ │ └── version.h
│ │ ├── impl/
│ │ │ ├── FFPlatform.c
│ │ │ ├── FFPlatform_private.h
│ │ │ ├── FFPlatform_unix.c
│ │ │ ├── FFPlatform_windows.c
│ │ │ ├── FFlist.c
│ │ │ ├── FFstrbuf.c
│ │ │ ├── base64.c
│ │ │ ├── binary_apple.c
│ │ │ ├── binary_linux.c
│ │ │ ├── binary_windows.c
│ │ │ ├── commandoption.c
│ │ │ ├── dbus.c
│ │ │ ├── debug_windows.c
│ │ │ ├── duration.c
│ │ │ ├── edidHelper.c
│ │ │ ├── font.c
│ │ │ ├── format.c
│ │ │ ├── frequency.c
│ │ │ ├── init.c
│ │ │ ├── io_unix.c
│ │ │ ├── io_windows.c
│ │ │ ├── jsonconfig.c
│ │ │ ├── kmod_apple.c
│ │ │ ├── kmod_bsd.c
│ │ │ ├── kmod_linux.c
│ │ │ ├── kmod_nbsd.c
│ │ │ ├── kmod_nosupport.c
│ │ │ ├── kmod_sunos.c
│ │ │ ├── kmod_windows.c
│ │ │ ├── library.c
│ │ │ ├── memrchr.c
│ │ │ ├── netif.c
│ │ │ ├── netif_apple.c
│ │ │ ├── netif_bsd.c
│ │ │ ├── netif_gnu.c
│ │ │ ├── netif_haiku.c
│ │ │ ├── netif_linux.c
│ │ │ ├── netif_windows.c
│ │ │ ├── networking_common.c
│ │ │ ├── networking_linux.c
│ │ │ ├── networking_windows.c
│ │ │ ├── option.c
│ │ │ ├── parsing.c
│ │ │ ├── path.c
│ │ │ ├── percent.c
│ │ │ ├── printing.c
│ │ │ ├── processing_linux.c
│ │ │ ├── processing_windows.c
│ │ │ ├── properties.c
│ │ │ ├── settings.c
│ │ │ ├── size.c
│ │ │ ├── smbiosHelper.c
│ │ │ ├── sysctl.c
│ │ │ ├── temps.c
│ │ │ ├── time.c
│ │ │ └── wcwidth.c
│ │ ├── init.h
│ │ ├── io.h
│ │ ├── jsonconfig.h
│ │ ├── kmod.h
│ │ ├── library.h
│ │ ├── mallocHelper.h
│ │ ├── memrchr.h
│ │ ├── netif.h
│ │ ├── networking.h
│ │ ├── option.h
│ │ ├── parsing.h
│ │ ├── path.h
│ │ ├── percent.h
│ │ ├── printing.h
│ │ ├── processing.h
│ │ ├── properties.h
│ │ ├── settings.h
│ │ ├── size.h
│ │ ├── smbiosHelper.h
│ │ ├── stringUtils.h
│ │ ├── sysctl.h
│ │ ├── temps.h
│ │ ├── textModifier.h
│ │ ├── thread.h
│ │ ├── time.h
│ │ ├── unused.h
│ │ ├── wcwidth.h
│ │ └── windows/
│ │ ├── c-logo.sh
│ │ ├── com.cpp
│ │ ├── com.hpp
│ │ ├── getline.c
│ │ ├── getline.h
│ │ ├── manifest.xml
│ │ ├── nt.h
│ │ ├── perflib_.h
│ │ ├── registry.c
│ │ ├── registry.h
│ │ ├── unicode.c
│ │ ├── unicode.h
│ │ ├── unicode.hpp
│ │ ├── util.hpp
│ │ ├── variant.cpp
│ │ ├── variant.hpp
│ │ ├── version.c
│ │ ├── version.h
│ │ ├── version.rc
│ │ ├── wmi.cpp
│ │ └── wmi.hpp
│ ├── data/
│ │ ├── help.json
│ │ └── structure.txt
│ ├── detection/
│ │ ├── battery/
│ │ │ ├── battery.h
│ │ │ ├── battery_android.c
│ │ │ ├── battery_apple.c
│ │ │ ├── battery_bsd.c
│ │ │ ├── battery_haiku.c
│ │ │ ├── battery_linux.c
│ │ │ ├── battery_nbsd.c
│ │ │ ├── battery_nosupport.c
│ │ │ ├── battery_obsd.c
│ │ │ └── battery_windows.c
│ │ ├── bios/
│ │ │ ├── bios.h
│ │ │ ├── bios_android.c
│ │ │ ├── bios_apple.c
│ │ │ ├── bios_bsd.c
│ │ │ ├── bios_linux.c
│ │ │ ├── bios_nbsd.c
│ │ │ ├── bios_nosupport.c
│ │ │ └── bios_windows.c
│ │ ├── bluetooth/
│ │ │ ├── bluetooth.h
│ │ │ ├── bluetooth_apple.m
│ │ │ ├── bluetooth_bsd.c
│ │ │ ├── bluetooth_haiku.cpp
│ │ │ ├── bluetooth_linux.c
│ │ │ ├── bluetooth_nosupport.c
│ │ │ ├── bluetooth_windows.c
│ │ │ └── bluetooth_windows.cpp
│ │ ├── bluetoothradio/
│ │ │ ├── bluetoothradio.c
│ │ │ ├── bluetoothradio.h
│ │ │ ├── bluetoothradio_apple.m
│ │ │ ├── bluetoothradio_linux.c
│ │ │ ├── bluetoothradio_nosupport.c
│ │ │ └── bluetoothradio_windows.c
│ │ ├── board/
│ │ │ ├── board.h
│ │ │ ├── board_android.c
│ │ │ ├── board_apple.c
│ │ │ ├── board_bsd.c
│ │ │ ├── board_linux.c
│ │ │ ├── board_nbsd.c
│ │ │ ├── board_nosupport.c
│ │ │ └── board_windows.c
│ │ ├── bootmgr/
│ │ │ ├── bootmgr.c
│ │ │ ├── bootmgr.h
│ │ │ ├── bootmgr_apple.c
│ │ │ ├── bootmgr_bsd.c
│ │ │ ├── bootmgr_linux.c
│ │ │ ├── bootmgr_nosupport.c
│ │ │ ├── bootmgr_windows.c
│ │ │ └── efi_helper.h
│ │ ├── brightness/
│ │ │ ├── brightness.h
│ │ │ ├── brightness_apple.c
│ │ │ ├── brightness_bsd.c
│ │ │ ├── brightness_linux.c
│ │ │ ├── brightness_nbsd.c
│ │ │ ├── brightness_nosupport.c
│ │ │ ├── brightness_obsd.c
│ │ │ └── brightness_windows.cpp
│ │ ├── btrfs/
│ │ │ ├── btrfs.h
│ │ │ ├── btrfs_linux.c
│ │ │ └── btrfs_nosupport.c
│ │ ├── camera/
│ │ │ ├── camera.h
│ │ │ ├── camera_android.c
│ │ │ ├── camera_apple.m
│ │ │ ├── camera_linux.c
│ │ │ ├── camera_nosupport.c
│ │ │ └── camera_windows.cpp
│ │ ├── chassis/
│ │ │ ├── chassis.c
│ │ │ ├── chassis.h
│ │ │ ├── chassis_apple.c
│ │ │ ├── chassis_bsd.c
│ │ │ ├── chassis_linux.c
│ │ │ ├── chassis_nbsd.c
│ │ │ ├── chassis_nosupport.c
│ │ │ └── chassis_windows.c
│ │ ├── command/
│ │ │ ├── command.c
│ │ │ └── command.h
│ │ ├── cpu/
│ │ │ ├── cpu.c
│ │ │ ├── cpu.h
│ │ │ ├── cpu_apple.c
│ │ │ ├── cpu_arm.h
│ │ │ ├── cpu_bsd.c
│ │ │ ├── cpu_haiku.c
│ │ │ ├── cpu_linux.c
│ │ │ ├── cpu_nbsd.c
│ │ │ ├── cpu_nosupport.c
│ │ │ ├── cpu_obsd.c
│ │ │ ├── cpu_sunos.c
│ │ │ └── cpu_windows.c
│ │ ├── cpucache/
│ │ │ ├── cpucache.h
│ │ │ ├── cpucache_apple.c
│ │ │ ├── cpucache_linux.c
│ │ │ ├── cpucache_nosupport.c
│ │ │ ├── cpucache_shared.c
│ │ │ └── cpucache_windows.c
│ │ ├── cpuusage/
│ │ │ ├── cpuusage.c
│ │ │ ├── cpuusage.h
│ │ │ ├── cpuusage_apple.c
│ │ │ ├── cpuusage_bsd.c
│ │ │ ├── cpuusage_haiku.c
│ │ │ ├── cpuusage_linux.c
│ │ │ ├── cpuusage_nosupport.c
│ │ │ ├── cpuusage_sunos.c
│ │ │ └── cpuusage_windows.c
│ │ ├── cursor/
│ │ │ ├── cursor.h
│ │ │ ├── cursor_apple.m
│ │ │ ├── cursor_linux.c
│ │ │ ├── cursor_nosupport.c
│ │ │ └── cursor_windows.c
│ │ ├── de/
│ │ │ ├── de.h
│ │ │ ├── de_linux.c
│ │ │ └── de_nosupport.c
│ │ ├── disk/
│ │ │ ├── disk.c
│ │ │ ├── disk.h
│ │ │ ├── disk_bsd.c
│ │ │ ├── disk_haiku.cpp
│ │ │ ├── disk_linux.c
│ │ │ ├── disk_nosupport.c
│ │ │ ├── disk_sunos.c
│ │ │ └── disk_windows.c
│ │ ├── diskio/
│ │ │ ├── diskio.c
│ │ │ ├── diskio.h
│ │ │ ├── diskio_apple.c
│ │ │ ├── diskio_bsd.c
│ │ │ ├── diskio_linux.c
│ │ │ ├── diskio_nbsd.c
│ │ │ ├── diskio_nosupport.c
│ │ │ ├── diskio_obsd.c
│ │ │ ├── diskio_sunos.c
│ │ │ └── diskio_windows.c
│ │ ├── displayserver/
│ │ │ ├── displayserver.c
│ │ │ ├── displayserver.h
│ │ │ ├── displayserver_android.c
│ │ │ ├── displayserver_apple.c
│ │ │ ├── displayserver_haiku.cpp
│ │ │ ├── displayserver_windows.c
│ │ │ └── linux/
│ │ │ ├── common.c
│ │ │ ├── displayserver_linux.c
│ │ │ ├── displayserver_linux.h
│ │ │ ├── drm.c
│ │ │ ├── wayland/
│ │ │ │ ├── global-output.c
│ │ │ │ ├── kde-output-device-v2-client-protocol.h
│ │ │ │ ├── kde-output-device-v2-protocol.c
│ │ │ │ ├── kde-output-order-v1-client-protocol.h
│ │ │ │ ├── kde-output-order-v1-protocol.c
│ │ │ │ ├── kde-output.c
│ │ │ │ ├── wayland.c
│ │ │ │ ├── wayland.h
│ │ │ │ ├── wlr-output-management-unstable-v1-client-protocol.h
│ │ │ │ ├── wlr-output-management-unstable-v1-protocol.c
│ │ │ │ ├── xdg-output-unstable-v1-client-protocol.h
│ │ │ │ ├── xdg-output-unstable-v1-protocol.c
│ │ │ │ └── zwlr-output.c
│ │ │ ├── wmde.c
│ │ │ ├── xcb.c
│ │ │ └── xlib.c
│ │ ├── dns/
│ │ │ ├── dns.h
│ │ │ ├── dns_apple.c
│ │ │ ├── dns_linux.c
│ │ │ └── dns_windows.c
│ │ ├── editor/
│ │ │ ├── editor.c
│ │ │ └── editor.h
│ │ ├── font/
│ │ │ ├── font.c
│ │ │ ├── font.h
│ │ │ ├── font_apple.m
│ │ │ ├── font_haiku.cpp
│ │ │ ├── font_linux.c
│ │ │ ├── font_nosupport.c
│ │ │ └── font_windows.c
│ │ ├── gamepad/
│ │ │ ├── gamepad.h
│ │ │ ├── gamepad_apple.c
│ │ │ ├── gamepad_bsd.c
│ │ │ ├── gamepad_haiku.cpp
│ │ │ ├── gamepad_linux.c
│ │ │ ├── gamepad_nosupport.c
│ │ │ └── gamepad_windows.c
│ │ ├── gpu/
│ │ │ ├── adl.h
│ │ │ ├── asahi_drm.h
│ │ │ ├── gpu.c
│ │ │ ├── gpu.h
│ │ │ ├── gpu_amd.c
│ │ │ ├── gpu_android.c
│ │ │ ├── gpu_apple.c
│ │ │ ├── gpu_apple.m
│ │ │ ├── gpu_bsd.c
│ │ │ ├── gpu_driver_specific.h
│ │ │ ├── gpu_drm.c
│ │ │ ├── gpu_gnu.c
│ │ │ ├── gpu_haiku.c
│ │ │ ├── gpu_intel.c
│ │ │ ├── gpu_linux.c
│ │ │ ├── gpu_mthreads.c
│ │ │ ├── gpu_nbsd.c
│ │ │ ├── gpu_nosupport.c
│ │ │ ├── gpu_nvidia.c
│ │ │ ├── gpu_obsd.c
│ │ │ ├── gpu_pci.c
│ │ │ ├── gpu_sunos.c
│ │ │ ├── gpu_windows.c
│ │ │ ├── gpu_wsl.cpp
│ │ │ ├── igcl.h
│ │ │ ├── intel_drm.h
│ │ │ ├── mtml.h
│ │ │ ├── nvapi.h
│ │ │ └── nvml.h
│ │ ├── gtk_qt/
│ │ │ ├── gtk.c
│ │ │ ├── gtk_qt.h
│ │ │ └── qt.c
│ │ ├── host/
│ │ │ ├── host.h
│ │ │ ├── host_android.c
│ │ │ ├── host_apple.c
│ │ │ ├── host_bsd.c
│ │ │ ├── host_linux.c
│ │ │ ├── host_mac.c
│ │ │ ├── host_nbsd.c
│ │ │ ├── host_nosupport.c
│ │ │ ├── host_obsd.c
│ │ │ └── host_windows.c
│ │ ├── icons/
│ │ │ ├── icons.h
│ │ │ ├── icons_linux.c
│ │ │ ├── icons_nosupport.c
│ │ │ └── icons_windows.c
│ │ ├── initsystem/
│ │ │ ├── initsystem.h
│ │ │ ├── initsystem_haiku.c
│ │ │ ├── initsystem_linux.c
│ │ │ └── initsystem_nosupport.c
│ │ ├── keyboard/
│ │ │ ├── keyboard.h
│ │ │ ├── keyboard_apple.c
│ │ │ ├── keyboard_bsd.c
│ │ │ ├── keyboard_haiku.cpp
│ │ │ ├── keyboard_linux.c
│ │ │ ├── keyboard_nosupport.c
│ │ │ └── keyboard_windows.c
│ │ ├── libc/
│ │ │ ├── libc.h
│ │ │ ├── libc_android.c
│ │ │ ├── libc_apple.c
│ │ │ ├── libc_bsd.c
│ │ │ ├── libc_linux.c
│ │ │ ├── libc_nosupport.c
│ │ │ └── libc_windows.cpp
│ │ ├── lm/
│ │ │ ├── lm.h
│ │ │ ├── lm_linux.c
│ │ │ └── lm_nosupport.c
│ │ ├── loadavg/
│ │ │ ├── loadavg.h
│ │ │ ├── loadavg_bsd.c
│ │ │ ├── loadavg_linux.c
│ │ │ ├── loadavg_nosupport.c
│ │ │ └── loadavg_sunos.c
│ │ ├── locale/
│ │ │ ├── locale.h
│ │ │ ├── locale_linux.c
│ │ │ └── locale_windows.c
│ │ ├── localip/
│ │ │ ├── localip.h
│ │ │ ├── localip_linux.c
│ │ │ └── localip_windows.c
│ │ ├── media/
│ │ │ ├── media.c
│ │ │ ├── media.h
│ │ │ ├── media_apple.m
│ │ │ ├── media_linux.c
│ │ │ ├── media_nosupport.c
│ │ │ ├── media_windows.c
│ │ │ ├── media_windows.dll.cpp
│ │ │ └── media_windows.dll.h
│ │ ├── memory/
│ │ │ ├── memory.h
│ │ │ ├── memory_apple.c
│ │ │ ├── memory_bsd.c
│ │ │ ├── memory_haiku.c
│ │ │ ├── memory_linux.c
│ │ │ ├── memory_nbsd.c
│ │ │ ├── memory_nosupport.c
│ │ │ ├── memory_obsd.c
│ │ │ ├── memory_sunos.c
│ │ │ └── memory_windows.c
│ │ ├── mouse/
│ │ │ ├── mouse.h
│ │ │ ├── mouse_apple.c
│ │ │ ├── mouse_bsd.c
│ │ │ ├── mouse_haiku.cpp
│ │ │ ├── mouse_linux.c
│ │ │ ├── mouse_nosupport.c
│ │ │ └── mouse_windows.c
│ │ ├── netio/
│ │ │ ├── netio.c
│ │ │ ├── netio.h
│ │ │ ├── netio_apple.c
│ │ │ ├── netio_bsd.c
│ │ │ ├── netio_haiku.cpp
│ │ │ ├── netio_linux.c
│ │ │ ├── netio_nosupport.c
│ │ │ ├── netio_sunos.c
│ │ │ └── netio_windows.c
│ │ ├── opencl/
│ │ │ ├── opencl.c
│ │ │ └── opencl.h
│ │ ├── opengl/
│ │ │ ├── opengl.h
│ │ │ ├── opengl_apple.c
│ │ │ ├── opengl_haiku.cpp
│ │ │ ├── opengl_linux.c
│ │ │ ├── opengl_shared.c
│ │ │ └── opengl_windows.c
│ │ ├── os/
│ │ │ ├── os.c
│ │ │ ├── os.h
│ │ │ ├── os_android.c
│ │ │ ├── os_apple.m
│ │ │ ├── os_haiku.c
│ │ │ ├── os_linux.c
│ │ │ ├── os_nbsd.c
│ │ │ ├── os_obsd.c
│ │ │ ├── os_sunos.c
│ │ │ └── os_windows.c
│ │ ├── packages/
│ │ │ ├── packages.c
│ │ │ ├── packages.h
│ │ │ ├── packages_apple.c
│ │ │ ├── packages_bsd.c
│ │ │ ├── packages_haiku.c
│ │ │ ├── packages_linux.c
│ │ │ ├── packages_nbsd.c
│ │ │ ├── packages_nix.c
│ │ │ ├── packages_nosupport.c
│ │ │ ├── packages_obsd.c
│ │ │ ├── packages_sunos.c
│ │ │ └── packages_windows.c
│ │ ├── physicaldisk/
│ │ │ ├── physicaldisk.h
│ │ │ ├── physicaldisk_apple.c
│ │ │ ├── physicaldisk_bsd.c
│ │ │ ├── physicaldisk_haiku.c
│ │ │ ├── physicaldisk_linux.c
│ │ │ ├── physicaldisk_nosupport.c
│ │ │ ├── physicaldisk_sunos.c
│ │ │ └── physicaldisk_windows.c
│ │ ├── physicalmemory/
│ │ │ ├── physicalmemory.c
│ │ │ ├── physicalmemory.h
│ │ │ ├── physicalmemory_apple.m
│ │ │ ├── physicalmemory_linux.c
│ │ │ └── physicalmemory_nosupport.c
│ │ ├── poweradapter/
│ │ │ ├── poweradapter.h
│ │ │ ├── poweradapter_apple.c
│ │ │ ├── poweradapter_linux.c
│ │ │ └── poweradapter_nosupport.c
│ │ ├── processes/
│ │ │ ├── processes.h
│ │ │ ├── processes_bsd.c
│ │ │ ├── processes_haiku.c
│ │ │ ├── processes_linux.c
│ │ │ ├── processes_nbsd.c
│ │ │ ├── processes_nosupport.c
│ │ │ ├── processes_obsd.c
│ │ │ └── processes_windows.c
│ │ ├── publicip/
│ │ │ ├── publicip.c
│ │ │ └── publicip.h
│ │ ├── sound/
│ │ │ ├── audio_oss_sunos.h
│ │ │ ├── sound.h
│ │ │ ├── sound_apple.c
│ │ │ ├── sound_bsd.c
│ │ │ ├── sound_haiku.cpp
│ │ │ ├── sound_linux.c
│ │ │ ├── sound_nbsd.c
│ │ │ ├── sound_nosupport.c
│ │ │ ├── sound_obsd.c
│ │ │ ├── sound_sunos.c
│ │ │ └── sound_windows.cpp
│ │ ├── swap/
│ │ │ ├── swap.h
│ │ │ ├── swap_apple.c
│ │ │ ├── swap_bsd.c
│ │ │ ├── swap_haiku.c
│ │ │ ├── swap_linux.c
│ │ │ ├── swap_nosupport.c
│ │ │ ├── swap_obsd.c
│ │ │ ├── swap_sunos.c
│ │ │ └── swap_windows.c
│ │ ├── terminalfont/
│ │ │ ├── terminalfont.c
│ │ │ ├── terminalfont.h
│ │ │ ├── terminalfont_android.c
│ │ │ ├── terminalfont_apple.m
│ │ │ ├── terminalfont_linux.c
│ │ │ └── terminalfont_windows.c
│ │ ├── terminalshell/
│ │ │ ├── terminalshell.c
│ │ │ ├── terminalshell.h
│ │ │ ├── terminalshell_linux.c
│ │ │ └── terminalshell_windows.c
│ │ ├── terminalsize/
│ │ │ ├── terminalsize.h
│ │ │ ├── terminalsize_linux.c
│ │ │ └── terminalsize_windows.c
│ │ ├── terminaltheme/
│ │ │ ├── terminaltheme.c
│ │ │ └── terminaltheme.h
│ │ ├── theme/
│ │ │ ├── theme.h
│ │ │ ├── theme_apple.c
│ │ │ ├── theme_linux.c
│ │ │ ├── theme_nosupport.c
│ │ │ └── theme_windows.c
│ │ ├── tpm/
│ │ │ ├── tpm.h
│ │ │ ├── tpm_apple.c
│ │ │ ├── tpm_bsd.c
│ │ │ ├── tpm_linux.c
│ │ │ ├── tpm_nosupport.c
│ │ │ └── tpm_windows.c
│ │ ├── uptime/
│ │ │ ├── uptime.h
│ │ │ ├── uptime_bsd.c
│ │ │ ├── uptime_haiku.c
│ │ │ ├── uptime_linux.c
│ │ │ ├── uptime_sunos.c
│ │ │ └── uptime_windows.c
│ │ ├── users/
│ │ │ ├── users.h
│ │ │ ├── users_linux.c
│ │ │ ├── users_nosupport.c
│ │ │ ├── users_obsd.c
│ │ │ └── users_windows.c
│ │ ├── version/
│ │ │ ├── version.c
│ │ │ └── version.h
│ │ ├── vulkan/
│ │ │ ├── vulkan.c
│ │ │ └── vulkan.h
│ │ ├── wallpaper/
│ │ │ ├── wallpaper.h
│ │ │ ├── wallpaper_apple.m
│ │ │ ├── wallpaper_linux.c
│ │ │ ├── wallpaper_nosupport.c
│ │ │ └── wallpaper_windows.c
│ │ ├── weather/
│ │ │ ├── weather.c
│ │ │ └── weather.h
│ │ ├── wifi/
│ │ │ ├── wifi.h
│ │ │ ├── wifi_android.c
│ │ │ ├── wifi_apple.m
│ │ │ ├── wifi_bsd.c
│ │ │ ├── wifi_linux.c
│ │ │ ├── wifi_nbsd.c
│ │ │ ├── wifi_nosupport.c
│ │ │ ├── wifi_obsd.c
│ │ │ └── wifi_windows.c
│ │ ├── wm/
│ │ │ ├── wm.h
│ │ │ ├── wm_apple.m
│ │ │ ├── wm_linux.c
│ │ │ ├── wm_nosupport.c
│ │ │ └── wm_windows.c
│ │ ├── wmtheme/
│ │ │ ├── wmtheme.h
│ │ │ ├── wmtheme_apple.m
│ │ │ ├── wmtheme_linux.c
│ │ │ ├── wmtheme_nosupport.c
│ │ │ └── wmtheme_windows.c
│ │ └── zpool/
│ │ ├── libzfs_simplified.h
│ │ ├── zpool.c
│ │ └── zpool.h
│ ├── fastfetch.c
│ ├── fastfetch.h
│ ├── fastfetch_config.h.in
│ ├── fastfetch_datatext.h.in
│ ├── flashfetch.c
│ ├── logo/
│ │ ├── ascii/
│ │ │ ├── adelie.txt
│ │ │ ├── aeon.txt
│ │ │ ├── aeros.txt
│ │ │ ├── aerynos.txt
│ │ │ ├── afterglow.txt
│ │ │ ├── aix.txt
│ │ │ ├── almalinux.txt
│ │ │ ├── alpine.txt
│ │ │ ├── alpine2.txt
│ │ │ ├── alpine2_small.txt
│ │ │ ├── alpine3_small.txt
│ │ │ ├── alpine_small.txt
│ │ │ ├── alter.txt
│ │ │ ├── altlinux.txt
│ │ │ ├── amazon.txt
│ │ │ ├── amazon_linux.txt
│ │ │ ├── amiga.txt
│ │ │ ├── amogos.txt
│ │ │ ├── anarchy.txt
│ │ │ ├── android.txt
│ │ │ ├── android_small.txt
│ │ │ ├── anduinos.txt
│ │ │ ├── antergos.txt
│ │ │ ├── antix.txt
│ │ │ ├── anushos.txt
│ │ │ ├── aoscos.txt
│ │ │ ├── aoscos_old.txt
│ │ │ ├── aoscosretro.txt
│ │ │ ├── aoscosretro_small.txt
│ │ │ ├── aperture.txt
│ │ │ ├── apricity.txt
│ │ │ ├── arch.txt
│ │ │ ├── arch2.txt
│ │ │ ├── arch3.txt
│ │ │ ├── arch_old.txt
│ │ │ ├── arch_small.txt
│ │ │ ├── archbox.txt
│ │ │ ├── archcraft.txt
│ │ │ ├── archcraft2.txt
│ │ │ ├── archlabs.txt
│ │ │ ├── archstrike.txt
│ │ │ ├── arco.txt
│ │ │ ├── arco_small.txt
│ │ │ ├── arkane.txt
│ │ │ ├── armbian.txt
│ │ │ ├── armbian2.txt
│ │ │ ├── arselinux.txt
│ │ │ ├── artix.txt
│ │ │ ├── artix2.txt
│ │ │ ├── artix2_small.txt
│ │ │ ├── artix_small.txt
│ │ │ ├── arya.txt
│ │ │ ├── asahi.txt
│ │ │ ├── asahi2.txt
│ │ │ ├── aster.txt
│ │ │ ├── asteroidos.txt
│ │ │ ├── astos.txt
│ │ │ ├── astra_linux.txt
│ │ │ ├── athenaos.txt
│ │ │ ├── athenaos_old.txt
│ │ │ ├── aurora.txt
│ │ │ ├── axos.txt
│ │ │ ├── azos.txt
│ │ │ ├── bedrock.txt
│ │ │ ├── bedrock_small.txt
│ │ │ ├── biglinux.txt
│ │ │ ├── bitrig.txt
│ │ │ ├── blackarch.txt
│ │ │ ├── blackmesa.txt
│ │ │ ├── blackpanther.txt
│ │ │ ├── blag.txt
│ │ │ ├── blankon.txt
│ │ │ ├── bluelight.txt
│ │ │ ├── bodhi.txt
│ │ │ ├── bonsai.txt
│ │ │ ├── bredos.txt
│ │ │ ├── bsd.txt
│ │ │ ├── bunsenlabs.txt
│ │ │ ├── cachyos.txt
│ │ │ ├── cachyos_small.txt
│ │ │ ├── calculate.txt
│ │ │ ├── calinixos.txt
│ │ │ ├── calinixos_small.txt
│ │ │ ├── carbs.txt
│ │ │ ├── cbl_mariner.txt
│ │ │ ├── celos.txt
│ │ │ ├── center.txt
│ │ │ ├── centos.txt
│ │ │ ├── centos_small.txt
│ │ │ ├── cereus.txt
│ │ │ ├── chakra.txt
│ │ │ ├── chaletos.txt
│ │ │ ├── chapeau.txt
│ │ │ ├── chimera_linux.txt
│ │ │ ├── chonkysealos.txt
│ │ │ ├── chrom.txt
│ │ │ ├── cleanjaro.txt
│ │ │ ├── cleanjaro_small.txt
│ │ │ ├── clear_linux.txt
│ │ │ ├── clearos.txt
│ │ │ ├── clover.txt
│ │ │ ├── cobalt.txt
│ │ │ ├── codex.txt
│ │ │ ├── condres.txt
│ │ │ ├── cosmic.txt
│ │ │ ├── crux.txt
│ │ │ ├── crux_small.txt
│ │ │ ├── crystal.txt
│ │ │ ├── cucumber.txt
│ │ │ ├── cuerdos.txt
│ │ │ ├── cutefishos.txt
│ │ │ ├── cuteos.txt
│ │ │ ├── cyberos.txt
│ │ │ ├── cycledream.txt
│ │ │ ├── dahlia.txt
│ │ │ ├── darkos.txt
│ │ │ ├── debian.txt
│ │ │ ├── debian_small.txt
│ │ │ ├── deepin.txt
│ │ │ ├── desaos.txt
│ │ │ ├── devuan.txt
│ │ │ ├── devuan_small.txt
│ │ │ ├── dietpi.txt
│ │ │ ├── dracos.txt
│ │ │ ├── dragonfly.txt
│ │ │ ├── dragonfly_old.txt
│ │ │ ├── dragonfly_small.txt
│ │ │ ├── drauger.txt
│ │ │ ├── droidian.txt
│ │ │ ├── elbrus.txt
│ │ │ ├── elementary.txt
│ │ │ ├── elementary_small.txt
│ │ │ ├── elive.txt
│ │ │ ├── emmabuntus.txt
│ │ │ ├── emperoros.txt
│ │ │ ├── encryptos.txt
│ │ │ ├── endeavouros.txt
│ │ │ ├── endeavouros_small.txt
│ │ │ ├── endless.txt
│ │ │ ├── enso.txt
│ │ │ ├── eshanizedos.txt
│ │ │ ├── eurolinux.txt
│ │ │ ├── evolutionos.txt
│ │ │ ├── evolutionos_old.txt
│ │ │ ├── evolutionos_small.txt
│ │ │ ├── eweos.txt
│ │ │ ├── exherbo.txt
│ │ │ ├── exodia_predator.txt
│ │ │ ├── fastfetch.txt
│ │ │ ├── fedora.txt
│ │ │ ├── fedora2_small.txt
│ │ │ ├── fedora_coreos.txt
│ │ │ ├── fedora_kinoite.txt
│ │ │ ├── fedora_old.txt
│ │ │ ├── fedora_sericea.txt
│ │ │ ├── fedora_silverblue.txt
│ │ │ ├── fedora_small.txt
│ │ │ ├── femboyos.txt
│ │ │ ├── feren.txt
│ │ │ ├── filotimo.txt
│ │ │ ├── finnix.txt
│ │ │ ├── floflis.txt
│ │ │ ├── freebsd.txt
│ │ │ ├── freebsd_small.txt
│ │ │ ├── freemint.txt
│ │ │ ├── frugalware.txt
│ │ │ ├── funtoo.txt
│ │ │ ├── furreto.txt
│ │ │ ├── galliumos.txt
│ │ │ ├── garuda.txt
│ │ │ ├── garuda_dragon.txt
│ │ │ ├── garuda_small.txt
│ │ │ ├── gentoo.txt
│ │ │ ├── gentoo_small.txt
│ │ │ ├── ghostbsd.txt
│ │ │ ├── ghostfreak.txt
│ │ │ ├── glaucus.txt
│ │ │ ├── gnewsense.txt
│ │ │ ├── gnome.txt
│ │ │ ├── gnu.txt
│ │ │ ├── gobolinux.txt
│ │ │ ├── goldendoglinux.txt
│ │ │ ├── grapheneos.txt
│ │ │ ├── grombyang.txt
│ │ │ ├── guix.txt
│ │ │ ├── guix_small.txt
│ │ │ ├── gxde.txt
│ │ │ ├── haiku.txt
│ │ │ ├── haiku2.txt
│ │ │ ├── haiku_small.txt
│ │ │ ├── hamonikr.txt
│ │ │ ├── hardclanz.txt
│ │ │ ├── harmonyos.txt
│ │ │ ├── hash.txt
│ │ │ ├── hce.txt
│ │ │ ├── heliumos.txt
│ │ │ ├── huayra.txt
│ │ │ ├── hybrid.txt
│ │ │ ├── hydroos.txt
│ │ │ ├── hyperbola.txt
│ │ │ ├── hyperbola_small.txt
│ │ │ ├── hypros.txt
│ │ │ ├── iglunix.txt
│ │ │ ├── instantos.txt
│ │ │ ├── interix.txt
│ │ │ ├── irix.txt
│ │ │ ├── ironclad.txt
│ │ │ ├── itc.txt
│ │ │ ├── januslinux.txt
│ │ │ ├── kaisen.txt
│ │ │ ├── kali.txt
│ │ │ ├── kali_small.txt
│ │ │ ├── kalpa_desktop.txt
│ │ │ ├── kaos.txt
│ │ │ ├── kdelinux.txt
│ │ │ ├── kdeneon.txt
│ │ │ ├── kernelos.txt
│ │ │ ├── kibojoe.txt
│ │ │ ├── kiss.txt
│ │ │ ├── kiss2.txt
│ │ │ ├── kogaion.txt
│ │ │ ├── korora.txt
│ │ │ ├── krassos.txt
│ │ │ ├── kslinux.txt
│ │ │ ├── kubuntu.txt
│ │ │ ├── kylin.txt
│ │ │ ├── lainos.txt
│ │ │ ├── langitketujuh.txt
│ │ │ ├── laxeros.txt
│ │ │ ├── lede.txt
│ │ │ ├── lfs.txt
│ │ │ ├── libreelec.txt
│ │ │ ├── lilidog.txt
│ │ │ ├── lingmo.txt
│ │ │ ├── linspire.txt
│ │ │ ├── linux.txt
│ │ │ ├── linux_small.txt
│ │ │ ├── linuxlite.txt
│ │ │ ├── linuxlite_small.txt
│ │ │ ├── linuxmint.txt
│ │ │ ├── linuxmint2.txt
│ │ │ ├── linuxmint_old.txt
│ │ │ ├── linuxmint_small.txt
│ │ │ ├── live_raizo.txt
│ │ │ ├── lliurex.txt
│ │ │ ├── lmde.txt
│ │ │ ├── locos.txt
│ │ │ ├── lubuntu.txt
│ │ │ ├── lunar.txt
│ │ │ ├── macaronios.txt
│ │ │ ├── macos.txt
│ │ │ ├── macos2.txt
│ │ │ ├── macos2_small.txt
│ │ │ ├── macos3.txt
│ │ │ ├── macos_small.txt
│ │ │ ├── mageia.txt
│ │ │ ├── mageia_small.txt
│ │ │ ├── magix.txt
│ │ │ ├── magpieos.txt
│ │ │ ├── mainsailos.txt
│ │ │ ├── mainsailos_small.txt
│ │ │ ├── mandriva.txt
│ │ │ ├── manjaro.txt
│ │ │ ├── manjaro_small.txt
│ │ │ ├── massos.txt
│ │ │ ├── matuusos.txt
│ │ │ ├── maui.txt
│ │ │ ├── mauna.txt
│ │ │ ├── meowix.txt
│ │ │ ├── mer.txt
│ │ │ ├── midnightbsd.txt
│ │ │ ├── midos.txt
│ │ │ ├── midos_old.txt
│ │ │ ├── minimal.txt
│ │ │ ├── minix.txt
│ │ │ ├── miracle_linux.txt
│ │ │ ├── mos.txt
│ │ │ ├── msys2.txt
│ │ │ ├── mx.txt
│ │ │ ├── mx2.txt
│ │ │ ├── mx_small.txt
│ │ │ ├── namib.txt
│ │ │ ├── nekos.txt
│ │ │ ├── neptune.txt
│ │ │ ├── netbsd.txt
│ │ │ ├── netbsd2.txt
│ │ │ ├── netbsd_small.txt
│ │ │ ├── nethydra.txt
│ │ │ ├── netrunner.txt
│ │ │ ├── nexalinux.txt
│ │ │ ├── nitrux.txt
│ │ │ ├── nixos.txt
│ │ │ ├── nixos_old.txt
│ │ │ ├── nixos_old_small.txt
│ │ │ ├── nixos_small.txt
│ │ │ ├── nobara.txt
│ │ │ ├── nomadbsd.txt
│ │ │ ├── nuros.txt
│ │ │ ├── nurunner.txt
│ │ │ ├── nutyx.txt
│ │ │ ├── obarun.txt
│ │ │ ├── obrevenge.txt
│ │ │ ├── obsidianos.txt
│ │ │ ├── omnios.txt
│ │ │ ├── openbsd.txt
│ │ │ ├── openbsd_small.txt
│ │ │ ├── openeuler.txt
│ │ │ ├── openindiana.txt
│ │ │ ├── openkylin.txt
│ │ │ ├── openmamba.txt
│ │ │ ├── openmandriva.txt
│ │ │ ├── openstage.txt
│ │ │ ├── opensuse.txt
│ │ │ ├── opensuse_leap.txt
│ │ │ ├── opensuse_leap_old.txt
│ │ │ ├── opensuse_microos.txt
│ │ │ ├── opensuse_slowroll.txt
│ │ │ ├── opensuse_small.txt
│ │ │ ├── opensuse_tumbleweed.txt
│ │ │ ├── opensuse_tumbleweed2.txt
│ │ │ ├── opensuse_tumbleweed_old.txt
│ │ │ ├── opensuse_tumbleweed_small.txt
│ │ │ ├── openwrt.txt
│ │ │ ├── opnsense.txt
│ │ │ ├── oracle.txt
│ │ │ ├── orchid.txt
│ │ │ ├── orchid_small.txt
│ │ │ ├── oreon.txt
│ │ │ ├── os2warp.txt
│ │ │ ├── os_elbrus.txt
│ │ │ ├── osmc.txt
│ │ │ ├── pacbsd.txt
│ │ │ ├── panwah.txt
│ │ │ ├── parabola.txt
│ │ │ ├── parabola_small.txt
│ │ │ ├── parch.txt
│ │ │ ├── pardus.txt
│ │ │ ├── parrot.txt
│ │ │ ├── parsix.txt
│ │ │ ├── pcbsd.txt
│ │ │ ├── pclinuxos.txt
│ │ │ ├── pearos.txt
│ │ │ ├── pengwin.txt
│ │ │ ├── pentoo.txt
│ │ │ ├── peppermint.txt
│ │ │ ├── peropesis.txt
│ │ │ ├── phyos.txt
│ │ │ ├── pikaos.txt
│ │ │ ├── pisi.txt
│ │ │ ├── pnm_linux.txt
│ │ │ ├── pop.txt
│ │ │ ├── pop_small.txt
│ │ │ ├── porteus.txt
│ │ │ ├── postmarketos.txt
│ │ │ ├── postmarketos_small.txt
│ │ │ ├── prismlinux.txt
│ │ │ ├── prismlinux_small.txt
│ │ │ ├── proxmox.txt
│ │ │ ├── puffos.txt
│ │ │ ├── puppy.txt
│ │ │ ├── pureos.txt
│ │ │ ├── pureos_small.txt
│ │ │ ├── q4os.txt
│ │ │ ├── qts.txt
│ │ │ ├── qubes.txt
│ │ │ ├── qubyt.txt
│ │ │ ├── quibian.txt
│ │ │ ├── quirinux.txt
│ │ │ ├── radix.txt
│ │ │ ├── raspbian.txt
│ │ │ ├── raspbian_small.txt
│ │ │ ├── ravynos.txt
│ │ │ ├── rebornos.txt
│ │ │ ├── rebornos_small.txt
│ │ │ ├── redcore.txt
│ │ │ ├── redos.txt
│ │ │ ├── redos_small.txt
│ │ │ ├── redstar.txt
│ │ │ ├── refracta.txt
│ │ │ ├── regata.txt
│ │ │ ├── regolith.txt
│ │ │ ├── rengeos.txt
│ │ │ ├── rhaymos.txt
│ │ │ ├── rhel.txt
│ │ │ ├── rhel_old.txt
│ │ │ ├── rhel_small.txt
│ │ │ ├── rhino.txt
│ │ │ ├── rocky.txt
│ │ │ ├── rocky_small.txt
│ │ │ ├── rosa.txt
│ │ │ ├── sabayon.txt
│ │ │ ├── sabotage.txt
│ │ │ ├── sailfish.txt
│ │ │ ├── salentos.txt
│ │ │ ├── salientos.txt
│ │ │ ├── salix.txt
│ │ │ ├── sambabox.txt
│ │ │ ├── sasanqua.txt
│ │ │ ├── scientific.txt
│ │ │ ├── secureblue.txt
│ │ │ ├── semc.txt
│ │ │ ├── septor.txt
│ │ │ ├── serene.txt
│ │ │ ├── serpent_os.txt
│ │ │ ├── sharklinux.txt
│ │ │ ├── shastraos.txt
│ │ │ ├── shebang.txt
│ │ │ ├── siduction.txt
│ │ │ ├── skiffos.txt
│ │ │ ├── slackel.txt
│ │ │ ├── slackware.txt
│ │ │ ├── slackware_small.txt
│ │ │ ├── sleeperos.txt
│ │ │ ├── sleeperos_small.txt
│ │ │ ├── slitaz.txt
│ │ │ ├── smartos.txt
│ │ │ ├── snigdhaos.txt
│ │ │ ├── soda.txt
│ │ │ ├── solaris.txt
│ │ │ ├── solaris_small.txt
│ │ │ ├── solus.txt
│ │ │ ├── source_mage.txt
│ │ │ ├── sparky.txt
│ │ │ ├── spoinkos.txt
│ │ │ ├── star.txt
│ │ │ ├── steamdeck.txt
│ │ │ ├── steamdeck_small.txt
│ │ │ ├── steamos.txt
│ │ │ ├── stock_linux.txt
│ │ │ ├── sulin.txt
│ │ │ ├── summitos.txt
│ │ │ ├── suse.txt
│ │ │ ├── swagarch.txt
│ │ │ ├── t2.txt
│ │ │ ├── t2_small.txt
│ │ │ ├── tails.txt
│ │ │ ├── tatra.txt
│ │ │ ├── tearch.txt
│ │ │ ├── templeos.txt
│ │ │ ├── tileos.txt
│ │ │ ├── torizoncore.txt
│ │ │ ├── trisquel.txt
│ │ │ ├── truenas_scale.txt
│ │ │ ├── tuxedo_os.txt
│ │ │ ├── twister.txt
│ │ │ ├── ublinux.txt
│ │ │ ├── ublinux_small.txt
│ │ │ ├── ubuntu.txt
│ │ │ ├── ubuntu_budgie.txt
│ │ │ ├── ubuntu_cinnamon.txt
│ │ │ ├── ubuntu_gnome.txt
│ │ │ ├── ubuntu_kylin.txt
│ │ │ ├── ubuntu_mate.txt
│ │ │ ├── ubuntu_old.txt
│ │ │ ├── ubuntu_old2.txt
│ │ │ ├── ubuntu_old2_small.txt
│ │ │ ├── ubuntu_small.txt
│ │ │ ├── ubuntu_studio.txt
│ │ │ ├── ubuntu_sway.txt
│ │ │ ├── ubuntu_touch.txt
│ │ │ ├── ubuntu_unity.txt
│ │ │ ├── ultramarine.txt
│ │ │ ├── ultramarine_small.txt
│ │ │ ├── unifi.txt
│ │ │ ├── univalent.txt
│ │ │ ├── univention.txt
│ │ │ ├── unknown.txt
│ │ │ ├── uos.txt
│ │ │ ├── urukos.txt
│ │ │ ├── uwuntu.txt
│ │ │ ├── valhalla.txt
│ │ │ ├── vanilla.txt
│ │ │ ├── vanilla2.txt
│ │ │ ├── vanilla_small.txt
│ │ │ ├── venom.txt
│ │ │ ├── venom_small.txt
│ │ │ ├── vincentos.txt
│ │ │ ├── vnux.txt
│ │ │ ├── void.txt
│ │ │ ├── void2.txt
│ │ │ ├── void2_small.txt
│ │ │ ├── void_small.txt
│ │ │ ├── vzlinux.txt
│ │ │ ├── wii_linux.txt
│ │ │ ├── windows.txt
│ │ │ ├── windows_11.txt
│ │ │ ├── windows_11_small.txt
│ │ │ ├── windows_2025.txt
│ │ │ ├── windows_8.txt
│ │ │ ├── windows_95.txt
│ │ │ ├── wolfos.txt
│ │ │ ├── xcp_ng.txt
│ │ │ ├── xenia.txt
│ │ │ ├── xenia_old.txt
│ │ │ ├── xeroarch.txt
│ │ │ ├── xferience.txt
│ │ │ ├── xinux.txt
│ │ │ ├── xray_os.txt
│ │ │ ├── xubuntu.txt
│ │ │ ├── yiffos.txt
│ │ │ ├── zorin.txt
│ │ │ ├── zos.txt
│ │ │ └── zraxyl.txt
│ │ ├── builtin.c
│ │ ├── image/
│ │ │ ├── im6.c
│ │ │ ├── im7.c
│ │ │ ├── image.c
│ │ │ └── image.h
│ │ ├── logo.c
│ │ └── logo.h
│ ├── modules/
│ │ ├── battery/
│ │ │ ├── battery.c
│ │ │ ├── battery.h
│ │ │ └── option.h
│ │ ├── bios/
│ │ │ ├── bios.c
│ │ │ ├── bios.h
│ │ │ └── option.h
│ │ ├── bluetooth/
│ │ │ ├── bluetooth.c
│ │ │ ├── bluetooth.h
│ │ │ └── option.h
│ │ ├── bluetoothradio/
│ │ │ ├── bluetoothradio.c
│ │ │ ├── bluetoothradio.h
│ │ │ └── option.h
│ │ ├── board/
│ │ │ ├── board.c
│ │ │ ├── board.h
│ │ │ └── option.h
│ │ ├── bootmgr/
│ │ │ ├── bootmgr.c
│ │ │ ├── bootmgr.h
│ │ │ └── option.h
│ │ ├── break/
│ │ │ ├── break.c
│ │ │ ├── break.h
│ │ │ └── option.h
│ │ ├── brightness/
│ │ │ ├── brightness.c
│ │ │ ├── brightness.h
│ │ │ └── option.h
│ │ ├── btrfs/
│ │ │ ├── btrfs.c
│ │ │ ├── btrfs.h
│ │ │ └── option.h
│ │ ├── camera/
│ │ │ ├── camera.c
│ │ │ ├── camera.h
│ │ │ └── option.h
│ │ ├── chassis/
│ │ │ ├── chassis.c
│ │ │ ├── chassis.h
│ │ │ └── option.h
│ │ ├── colors/
│ │ │ ├── colors.c
│ │ │ ├── colors.h
│ │ │ └── option.h
│ │ ├── command/
│ │ │ ├── command.c
│ │ │ ├── command.h
│ │ │ └── option.h
│ │ ├── cpu/
│ │ │ ├── cpu.c
│ │ │ ├── cpu.h
│ │ │ └── option.h
│ │ ├── cpucache/
│ │ │ ├── cpucache.c
│ │ │ ├── cpucache.h
│ │ │ └── option.h
│ │ ├── cpuusage/
│ │ │ ├── cpuusage.c
│ │ │ ├── cpuusage.h
│ │ │ └── option.h
│ │ ├── cursor/
│ │ │ ├── cursor.c
│ │ │ ├── cursor.h
│ │ │ └── option.h
│ │ ├── custom/
│ │ │ ├── custom.c
│ │ │ ├── custom.h
│ │ │ └── option.h
│ │ ├── datetime/
│ │ │ ├── datetime.c
│ │ │ ├── datetime.h
│ │ │ └── option.h
│ │ ├── de/
│ │ │ ├── de.c
│ │ │ ├── de.h
│ │ │ └── option.h
│ │ ├── disk/
│ │ │ ├── disk.c
│ │ │ ├── disk.h
│ │ │ └── option.h
│ │ ├── diskio/
│ │ │ ├── diskio.c
│ │ │ ├── diskio.h
│ │ │ └── option.h
│ │ ├── display/
│ │ │ ├── display.c
│ │ │ ├── display.h
│ │ │ └── option.h
│ │ ├── dns/
│ │ │ ├── dns.c
│ │ │ ├── dns.h
│ │ │ └── option.h
│ │ ├── editor/
│ │ │ ├── editor.c
│ │ │ ├── editor.h
│ │ │ └── option.h
│ │ ├── font/
│ │ │ ├── font.c
│ │ │ ├── font.h
│ │ │ └── option.h
│ │ ├── gamepad/
│ │ │ ├── gamepad.c
│ │ │ ├── gamepad.h
│ │ │ └── option.h
│ │ ├── gpu/
│ │ │ ├── gpu.c
│ │ │ ├── gpu.h
│ │ │ └── option.h
│ │ ├── host/
│ │ │ ├── host.c
│ │ │ ├── host.h
│ │ │ └── option.h
│ │ ├── icons/
│ │ │ ├── icons.c
│ │ │ ├── icons.h
│ │ │ └── option.h
│ │ ├── initsystem/
│ │ │ ├── initsystem.c
│ │ │ ├── initsystem.h
│ │ │ └── option.h
│ │ ├── kernel/
│ │ │ ├── kernel.c
│ │ │ ├── kernel.h
│ │ │ └── option.h
│ │ ├── keyboard/
│ │ │ ├── keyboard.c
│ │ │ ├── keyboard.h
│ │ │ └── option.h
│ │ ├── lm/
│ │ │ ├── lm.c
│ │ │ ├── lm.h
│ │ │ └── option.h
│ │ ├── loadavg/
│ │ │ ├── loadavg.c
│ │ │ ├── loadavg.h
│ │ │ └── option.h
│ │ ├── locale/
│ │ │ ├── locale.c
│ │ │ ├── locale.h
│ │ │ └── option.h
│ │ ├── localip/
│ │ │ ├── localip.c
│ │ │ ├── localip.h
│ │ │ └── option.h
│ │ ├── logo/
│ │ │ ├── logo.c
│ │ │ ├── logo.h
│ │ │ └── option.h
│ │ ├── media/
│ │ │ ├── media.c
│ │ │ ├── media.h
│ │ │ └── option.h
│ │ ├── memory/
│ │ │ ├── memory.c
│ │ │ ├── memory.h
│ │ │ └── option.h
│ │ ├── modules.c
│ │ ├── modules.h
│ │ ├── monitor/
│ │ │ ├── monitor.c
│ │ │ ├── monitor.h
│ │ │ └── option.h
│ │ ├── mouse/
│ │ │ ├── mouse.c
│ │ │ ├── mouse.h
│ │ │ └── option.h
│ │ ├── netio/
│ │ │ ├── netio.c
│ │ │ ├── netio.h
│ │ │ └── option.h
│ │ ├── opencl/
│ │ │ ├── opencl.c
│ │ │ ├── opencl.h
│ │ │ └── option.h
│ │ ├── opengl/
│ │ │ ├── opengl.c
│ │ │ ├── opengl.h
│ │ │ └── option.h
│ │ ├── options.h
│ │ ├── os/
│ │ │ ├── option.h
│ │ │ ├── os.c
│ │ │ └── os.h
│ │ ├── packages/
│ │ │ ├── option.h
│ │ │ ├── packages.c
│ │ │ └── packages.h
│ │ ├── physicaldisk/
│ │ │ ├── option.h
│ │ │ ├── physicaldisk.c
│ │ │ └── physicaldisk.h
│ │ ├── physicalmemory/
│ │ │ ├── option.h
│ │ │ ├── physicalmemory.c
│ │ │ └── physicalmemory.h
│ │ ├── player/
│ │ │ ├── option.h
│ │ │ ├── player.c
│ │ │ └── player.h
│ │ ├── poweradapter/
│ │ │ ├── option.h
│ │ │ ├── poweradapter.c
│ │ │ └── poweradapter.h
│ │ ├── processes/
│ │ │ ├── option.h
│ │ │ ├── processes.c
│ │ │ └── processes.h
│ │ ├── publicip/
│ │ │ ├── option.h
│ │ │ ├── publicip.c
│ │ │ └── publicip.h
│ │ ├── separator/
│ │ │ ├── option.h
│ │ │ ├── separator.c
│ │ │ └── separator.h
│ │ ├── shell/
│ │ │ ├── option.h
│ │ │ ├── shell.c
│ │ │ └── shell.h
│ │ ├── sound/
│ │ │ ├── option.h
│ │ │ ├── sound.c
│ │ │ └── sound.h
│ │ ├── swap/
│ │ │ ├── option.h
│ │ │ ├── swap.c
│ │ │ └── swap.h
│ │ ├── terminal/
│ │ │ ├── option.h
│ │ │ ├── terminal.c
│ │ │ └── terminal.h
│ │ ├── terminalfont/
│ │ │ ├── option.h
│ │ │ ├── terminalfont.c
│ │ │ └── terminalfont.h
│ │ ├── terminalsize/
│ │ │ ├── option.h
│ │ │ ├── terminalsize.c
│ │ │ └── terminalsize.h
│ │ ├── terminaltheme/
│ │ │ ├── option.h
│ │ │ ├── terminaltheme.c
│ │ │ └── terminaltheme.h
│ │ ├── theme/
│ │ │ ├── option.h
│ │ │ ├── theme.c
│ │ │ └── theme.h
│ │ ├── title/
│ │ │ ├── option.h
│ │ │ ├── title.c
│ │ │ └── title.h
│ │ ├── tpm/
│ │ │ ├── option.h
│ │ │ ├── tpm.c
│ │ │ └── tpm.h
│ │ ├── uptime/
│ │ │ ├── option.h
│ │ │ ├── uptime.c
│ │ │ └── uptime.h
│ │ ├── users/
│ │ │ ├── option.h
│ │ │ ├── users.c
│ │ │ └── users.h
│ │ ├── version/
│ │ │ ├── option.h
│ │ │ ├── version.c
│ │ │ └── version.h
│ │ ├── vulkan/
│ │ │ ├── option.h
│ │ │ ├── vulkan.c
│ │ │ └── vulkan.h
│ │ ├── wallpaper/
│ │ │ ├── option.h
│ │ │ ├── wallpaper.c
│ │ │ └── wallpaper.h
│ │ ├── weather/
│ │ │ ├── option.h
│ │ │ ├── weather.c
│ │ │ └── weather.h
│ │ ├── wifi/
│ │ │ ├── option.h
│ │ │ ├── wifi.c
│ │ │ └── wifi.h
│ │ ├── wm/
│ │ │ ├── option.h
│ │ │ ├── wm.c
│ │ │ └── wm.h
│ │ ├── wmtheme/
│ │ │ ├── option.h
│ │ │ ├── wmtheme.c
│ │ │ └── wmtheme.h
│ │ └── zpool/
│ │ ├── option.h
│ │ ├── zpool.c
│ │ └── zpool.h
│ └── options/
│ ├── display.c
│ ├── display.h
│ ├── general.c
│ ├── general.h
│ ├── logo.c
│ └── logo.h
└── tests/
├── color.c
├── duration.c
├── format.c
├── list.c
├── strbuf.c
├── testlogo-hardcolors.fflogo
└── testlogo-softcolors.fflogo
================================================
FILE CONTENTS
================================================
================================================
FILE: .codespellrc
================================================
[codespell]
check-filenames =
builtin = clear,rare,usage,informal
skip = */.git,*/cmake-build-*,*/.idea,*/completions,*/presets,*/screenshots,*/tests,*/3rdparty,*/logo/ascii,./src/detection/gpu/asahi_drm.h
ignore-words-list = iterm,compiletime,unknwn,pengwin,siduction,master,slave,sur,doas,conexant,ags,bu
================================================
FILE: .editorconfig
================================================
root = true
[*]
end_of_line = lf
indent_style = space
tab_width = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.txt]
insert_final_newline = false
[*.yml]
tab_width = 2
================================================
FILE: .gitattributes
================================================
*.h linguist-language=c
*.c linguist-language=c
================================================
FILE: .github/FUNDING.yml
================================================
github: LinusDierheimer
ko_fi: carterli
custom: https://paypal.me/zhangsongcui
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report_crash.yml
================================================
name: Crash Bug Report
description: If fastfetch crashes or freezes
title: "[BUG] "
labels: ["bug", "crash", "triage"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report! We will try hard to solve the issue.
However since platforms and hardwares vary greatly, it can be hard to find the root cause of an issue.
Providing the following information may help us greatly. Thanks in advance!
- type: checkboxes
attributes:
label: Read the FAQ first
description: Please check if the issue is already covered in the FAQ.
options:
- label: I have checked the FAQ but the issue is not covered
required: true
- type: checkboxes
attributes:
label: Not a known issue
description: Please check if the issue is already known and being worked on.
options:
- label: I have checked the existing issues but the issue is not covered
required: true
- label: My issue is not about crashing on Fedora and KDE 6.6
required: true
- type: markdown
attributes:
value: "### General description of the bug"
- type: textarea
attributes:
label: Description
description: A clear and concise description of what the bug is.
placeholder: I was trying to [...] but [...]
validations:
required: true
- type: input
attributes:
label: Version used
description: Fastfetch version used. Please use the latest version (found in the [releases](https://github.com/fastfetch-cli/fastfetch/releases)) if possible.
placeholder: Result of `fastfetch --version`
validations:
required: true
- type: dropdown
attributes:
label: Bug prevalence
description: How often does the bug occur?
options:
-
- Always
- Sometimes
- Rarely
- Once
- Other
validations:
required: true
- type: dropdown
attributes:
label: Regression
description: Did it work in an older version?
options:
-
- Not sure
- 'Yes'
- 'No'
validations:
required: true
- type: dropdown
attributes:
label: Installation
description: Where did you install fastfetch from?
options:
-
- GitHub Releases
- GitHub Actions (nightly)
- Built from source
- Package manager
validations:
required: true
- type: input
attributes:
label: Package manager
description: Which package manager did you use if applicable?
placeholder: e.g. `apt`, `pacman`, `brew`, `scoop`
- type: markdown
attributes:
value: '### Often helpful information'
- type: textarea
attributes:
label: Screenshots
description: If applicable, add screenshots to help explain your problem.
- type: textarea
attributes:
label: Configuration
description: If applicable, paste your configuration file here.
placeholder: cat ~/.config/fastfetch/config.jsonc
render: jsonc
- type: markdown
attributes:
value: |
Paste the stacktrace here. You may get it with:
```shell
# You may need Ctrl+C to stop the process if it freezes
gdb -q -ex 'set confirm off' -ex run -ex 'bt full' -ex quit --args /path/to/fastfetch
```
If you are able to identify which module crashed, the strace can be helpful too
```shell
strace /path/to/fastfetch --multithreading false -s {MODULE} --pipe
```
If you cannot do the instructions above, please upload the core dump file if available.
- type: textarea
attributes:
label: Stacktrace
description: Paste the stacktrace or core dump file here.
render: text
validations:
required: true
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report_general.yml
================================================
name: General Bug Report
description: If something is not working as expected (wrong output, missing info, etc)
title: "[BUG] "
labels: ["bug", "triage"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report! We will try hard to solve the issue.
However since platforms and hardwares vary greatly, it can be hard to find the root cause of an issue.
Providing the following information may help us greatly. Thanks in advance!
- type: checkboxes
attributes:
label: Read the FAQ first
description: Please check if the issue is already covered in the FAQ.
options:
- label: I have checked the FAQ but the issue is not covered
required: true
- type: markdown
attributes:
value: "### General description of the bug"
- type: textarea
attributes:
label: Description
description: A clear and concise description of what the bug is.
placeholder: I was trying to [...] but [...]
validations:
required: true
- type: input
attributes:
label: Version used
description: Fastfetch version used. Please use the latest version (found in the [releases](https://github.com/fastfetch-cli/fastfetch/releases)) if possible.
placeholder: Result of `fastfetch --version`
validations:
required: true
- type: dropdown
attributes:
label: Bug prevalence
description: How often does the bug occur?
options:
-
- Always
- Sometimes
- Rarely
- Once
- Other
validations:
required: true
- type: dropdown
attributes:
label: Regression
description: Did it work in an older version?
options:
-
- Not sure
- 'Yes'
- 'No'
validations:
required: true
- type: dropdown
attributes:
label: Installation
description: Where did you install fastfetch from?
options:
-
- GitHub Releases
- GitHub Actions (nightly)
- Built from source
- Package manager
validations:
required: true
- type: input
attributes:
label: Package manager
description: Which package manager did you use if applicable?
placeholder: e.g. `apt`, `pacman`, `brew`, `scoop`
- type: markdown
attributes:
value: '### Often helpful information'
- type: textarea
attributes:
label: Screenshots
description: If applicable, add screenshots to help explain your problem.
- type: textarea
attributes:
label: Configuration
description: If applicable, paste your configuration file here.
placeholder: cat ~/.config/fastfetch/config.jsonc
render: jsonc
- type: textarea
attributes:
label: System information
description: Output of `fastfetch -c all.jsonc --stat --format json`
placeholder: |
Note that this output will contain you public IP.
If it is not relevant for the issue, feel free to remove it before uploading.
render: jsonc
validations:
required: true
- type: textarea
attributes:
label: Features built-in
description: Output of `fastfetch --list-features`
render: text
validations:
required: true
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report_logo.yml
================================================
name: Logo Bug Report
description: If my image logo is not displayed correctly
title: "[BUG] "
labels: ["bug", "logo", "triage"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report! We will try hard to solve the issue.
However since platforms and hardwares vary greatly, it can be hard to find the root cause of an issue.
Providing the following information may help us greatly. Thanks in advance!
- type: checkboxes
attributes:
label: Read the FAQ first
description: Please check if the issue is already covered in the FAQ.
options:
- label: I have checked the FAQ but the issue is not covered
required: true
- type: markdown
attributes:
value: "### General description of the bug"
- type: textarea
attributes:
label: Description
description: A clear and concise description of what the bug is.
placeholder: I was trying to [...] but [...]
validations:
required: true
- type: input
attributes:
label: Version used
description: Fastfetch version used. Please use the latest version (found in the [releases](https://github.com/fastfetch-cli/fastfetch/releases)) if possible.
placeholder: Result of `fastfetch --version`
validations:
required: true
- type: dropdown
attributes:
label: Bug prevalence
description: How often does the bug occur?
options:
-
- Always
- Sometimes
- Rarely
- Once
- Other
validations:
required: true
- type: dropdown
attributes:
label: Regression
description: Did it work in an older version?
options:
-
- Not sure
- 'Yes'
- 'No'
validations:
required: true
- type: dropdown
attributes:
label: Installation
description: Where did you install fastfetch from?
options:
-
- GitHub Releases
- GitHub Actions (nightly)
- Built from source
- Package manager
validations:
required: true
- type: input
attributes:
label: Package manager
description: Which package manager did you use if applicable?
placeholder: e.g. `apt`, `pacman`, `brew`, `scoop`
- type: markdown
attributes:
value: '### Often helpful information'
- type: textarea
attributes:
label: Screenshots
description: If applicable, add screenshots to help explain your problem.
- type: textarea
attributes:
label: Configuration
description: If applicable, paste your configuration file here.
placeholder: cat ~/.config/fastfetch/config.jsonc
render: jsonc
- type: markdown
attributes:
value: |
#### If an image or logo didn't show
Please make sure your terminal supports the image protocol you used.
Note that GNOME Terminal doesn't support any image protocols as of now
Some tips:
1. Try `fastfetch --show-errors` to see if there are any errors.
2. Try `fastfetch --logo-width {WIDTH} --logo-height {HEIGHT}`. Some protocols may require a image size being set.
- type: input
attributes:
label: Image protocol
description: The image protocol you used
validations:
required: true
- type: input
attributes:
label: Terminal
description: The terminal you used
validations:
required: true
- type: textarea
attributes:
label: Image tried
description: Upload the image file, or paste the image URL here
validations:
required: true
- type: textarea
attributes:
label: Error message
description: Error message printed by `fastfetch -s none --show-errors`, if any
- type: textarea
attributes:
label: Features built-in
description: Output of `fastfetch --list-features`
render: text
validations:
required: true
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.yml
================================================
name: Feature Request
description: Suggest an idea for this project
title: "[FEAT] "
labels: ["enhancement"]
body:
- type: markdown
attributes:
value: |
Fastfetch is a system information tool. We only accept hardware or system level software feature requests.
For most personal uses, I recommend using `Command` module to detect it yourself, which can be used to grab output from a custom shell script:
```jsonc
// This module shows the git version
{
"modules": [
{
"type": "command",
"key": "Git",
"text": "git version",
"format": "{~12}" // cut the first 12 characters
}
]
}
```
- type: textarea
attributes:
label: Description
description: A clear and concise description of what the feature is.
validations:
required: true
- type: textarea
attributes:
label: Motivation
description: Why do you want this feature? Why doesn't `Command` module suffice for you?
validations:
required: true
- type: textarea
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
================================================
FILE: .github/ISSUE_TEMPLATE/logo_request.yml
================================================
name: Logo Request
description: Request a new ASCII logo for your favorite distro
title: "[LOGO] "
labels: ["logo request"]
body:
- type: markdown
attributes:
value: |
Tip: You can display a logo in fastfetch without adding it to fastfetch's official repo.
For highly customized, personal logos, we recommend keeping them locally.
Please refer to https://github.com/fastfetch-cli/fastfetch/wiki/Migrate-Neofetch-Logo-To-Fastfetch
- type: textarea
attributes:
label: OS
description: Paste the contents of `/etc/os-release` and `/etc/lsb-release` here. If neither file exists, describe how to identify the distro.
placeholder: cat /etc/os-release
validations:
required: true
- type: input
attributes:
label: Distro Website
description: To help prevent spam and verify the request, a distro website is required, and a downloadable ISO must be available on that site.
placeholder: https://example.com
validations:
required: true
- type: textarea
attributes:
label: ASCII Art
description: The ASCII logo should not take up too much space (smaller than 50x20 characters, W x H). Please also include the color codes if they are not available in `os-release`.
placeholder: Paste ASCII art here
validations:
required: true
- type: input
attributes:
label: Original Image URL
description: If the ASCII art is based on an image, please provide a link to the original image file.
placeholder: Image URL from the distro website mentioned above
- type: checkboxes
attributes:
label: Checklist
options:
- label: The ASCII art is smaller than 50x20 characters (W x H).
required: true
- label: The ASCII art includes color codes, or the color codes are available in `os-release`.
required: true
- label: The ASCII art has no internal padding (spaces at the start and/or end of lines).
required: true
================================================
FILE: .github/pull_request_template.md
================================================
## Summary
## Related issue (required for new logos for new distros)
Closes #
## Changes
-
## Checklist
- [ ] I have tested my changes locally.
================================================
FILE: .github/stale.yml
================================================
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- keepalive
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
- push
- pull_request
env:
CMAKE_BUILD_TYPE: ${{ vars.CMAKE_BUILD_TYPE || 'RelWithDebInfo' }}
jobs:
spellcheck:
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: Install codespell
shell: bash
run: |
sudo apt-get update || true
sudo apt-get install -y codespell
- name: Run Spellchecker
run: codespell
no-features-test:
name: No-features-test
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: uname -a
run: uname -a
- name: configure project
run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr . -DENABLE_VULKAN=OFF -DENABLE_WAYLAND=OFF -DENABLE_XCB_RANDR=OFF -DENABLE_XCB=OFF -DENABLE_XRANDR=OFF -DENABLE_X11=OFF -DENABLE_DRM=OFF -DENABLE_DRM_AMDGPU=OFF -DENABLE_GIO=OFF -DENABLE_DCONF=OFF -DENABLE_DBUS=OFF -DENABLE_SQLITE3=OFF -DENABLE_RPM=OFF -DENABLE_IMAGEMAGICK7=OFF -DENABLE_IMAGEMAGICK6=OFF -DENABLE_CHAFA=OFF -DENABLE_ZLIB=OFF -DENABLE_EGL=OFF -DENABLE_GLX=OFF -DENABLE_OPENCL=OFF -DENABLE_FREETYPE=OFF -DENABLE_PULSE=OFF -DENABLE_DDCUTIL=OFF -DENABLE_ELF=OFF -DENABLE_DIRECTX_HEADERS=OFF -DENABLE_THREADS=OFF
- name: build project
run: cmake --build . --target package --verbose -j4
- name: list features
run: ./fastfetch --list-features
- name: run fastfetch
run: time ./fastfetch -c presets/ci.jsonc --stat false
- name: run fastfetch --format json
run: time ./fastfetch -c presets/ci.jsonc --format json
- name: run flashfetch
run: time ./flashfetch
- name: print dependencies
run: ldd fastfetch
- name: run tests
run: ctest --output-on-failure
linux-hosts:
name: Linux-${{ matrix.arch }}
runs-on: ${{ matrix.runs-on }}
permissions:
security-events: write
contents: read
strategy:
matrix:
include:
- arch: amd64
runs-on: ubuntu-22.04
- arch: aarch64
runs-on: ubuntu-22.04-arm
outputs:
ffversion: ${{ steps.ffversion.outputs.ffversion }}
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: uname -a
run: uname -a
- name: cat /etc/os-release
run: cat /etc/os-release
- name: cat /proc/cpuinfo
run: cat /proc/cpuinfo
- name: add gcc-13 repo
run: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- name: install required packages
run: sudo apt-get update && sudo apt-get install -y gcc-13 g++-13 libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev ocl-icd-opencl-dev libpulse-dev libdrm-dev libelf-dev libddcutil-dev directx-headers-dev rpm ninja-build
- name: install linuxbrew packages
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
/home/linuxbrew/.linuxbrew/bin/brew install imagemagick chafa --ignore-dependencies
- name: Initialize CodeQL
if: matrix.arch == 'amd64'
uses: github/codeql-action/init@v4
with:
languages: c
- name: configure project
run: CC=gcc-13 CXX=g++-13 PKG_CONFIG_PATH=/home/linuxbrew/.linuxbrew/lib/pkgconfig:$PKG_CONFIG_PATH cmake -GNinja -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On -DCMAKE_INSTALL_PREFIX=/usr .
- name: build project
run: cmake --build . --target package --verbose -j4
- name: perform CodeQL analysis
if: matrix.arch == 'amd64'
uses: github/codeql-action/analyze@v4
- name: list features
run: ./fastfetch --list-features
- name: run fastfetch
run: time ./fastfetch -c presets/ci.jsonc --stat false
- name: run fastfetch --format json
run: time ./fastfetch -c presets/ci.jsonc --format json
- name: run flashfetch
run: time ./flashfetch
- name: print dependencies
run: ldd fastfetch
- name: run tests
run: ctest --output-on-failure
- name: get fastfetch version
id: ffversion
run: echo "ffversion=$(./fastfetch --version-raw)" >> $GITHUB_OUTPUT
- name: polyfill glibc
run: |
wget https://github.com/CarterLi/polyfill-glibc/releases/download/v0.0.1/polyfill-glibc-${{ matrix.arch }} -O polyfill-glibc
chmod +x polyfill-glibc
strip fastfetch && ./polyfill-glibc fastfetch --target-glibc=2.17
strip flashfetch && ./polyfill-glibc flashfetch --target-glibc=2.17
echo 'set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-polyfilled")' >> CPackConfig.cmake
echo 'set(CPACK_PACKAGE_RELOCATABLE OFF)' >> CPackConfig.cmake
echo 'set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.17)")' >> CPackConfig.cmake
echo 'set(CPACK_RPM_SPEC_MORE_DEFINE "%global __os_install_post %{nil}")' >> CPackConfig.cmake
cpack -V
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-linux-${{ matrix.arch }}
path: ./fastfetch-*.*
linux-i686:
name: Linux-i686
runs-on: ubuntu-22.04
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: uname -a
run: uname -a
- name: cat /etc/os-release
run: cat /etc/os-release
- name: cat /proc/cpuinfo
run: cat /proc/cpuinfo
- name: add gcc-13 repo
run: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- name: install required packages
run: sudo apt-get update && sudo apt-get install -y gcc-13 gcc-13-multilib libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev ocl-icd-opencl-dev libpulse-dev libdrm-dev libelf-dev libddcutil-dev rpm ninja-build
- name: install linuxbrew packages
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
/home/linuxbrew/.linuxbrew/bin/brew install imagemagick chafa --ignore-dependencies
- name: cmake version
run: cmake --version
- name: configure project
run: CC=gcc-13 PKG_CONFIG_PATH=/home/linuxbrew/.linuxbrew/lib/pkgconfig:$PKG_CONFIG_PATH cmake -DCMAKE_C_FLAGS="-m32 -march=i686 -mtune=i686" -DCMAKE_SYSTEM_PROCESSOR_OVERRIDE=i686 -DCPACK_DEBIAN_PACKAGE_ARCHITECTURE=i386 -GNinja -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_DIRECTX_HEADERS=Off .
- name: build project
run: cmake --build . --target package --verbose -j4
- name: check deb package
run: dpkg -I fastfetch-*.deb
- name: list features
run: ./fastfetch --list-features
- name: run fastfetch
run: time ./fastfetch -c presets/ci.jsonc --stat false
- name: run fastfetch --format json
run: time ./fastfetch -c presets/ci.jsonc --format json
- name: run flashfetch
run: time ./flashfetch
- name: print dependencies
run: ldd fastfetch
- name: run tests
run: ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-linux-i686
path: ./fastfetch-*.*
linux-armv7l:
name: Linux-armv7l
runs-on: ubuntu-24.04
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: uraimo/run-on-arch-action@v3
id: runcmd
with:
arch: armv7
distro: ubuntu22.04
githubToken: ${{ github.token }}
run: |
uname -a
apt-get update && apt-get install -y software-properties-common ca-certificates gpg curl
add-apt-repository -y ppa:ubuntu-toolchain-r/test
curl -L https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null
echo -e 'Acquire::https::Verify-Peer "false";\nAcquire::https::Verify-Host "false";' >> /etc/apt/apt.conf.d/99ignore-certificates
apt-get update && apt-get install -y cmake make gcc-13 libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev ocl-icd-opencl-dev libpulse-dev libdrm-dev libelf-dev rpm
CC=gcc-13 cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_DIRECTX_HEADERS=Off -DCMAKE_INSTALL_PREFIX=/usr .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-linux-armv7l
path: ./fastfetch-*.*
linux-armv6l:
name: Linux-armv6l
runs-on: ubuntu-24.04
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: uraimo/run-on-arch-action@v3
id: runcmd
with:
arch: armv6
distro: bookworm
githubToken: ${{ github.token }}
run: |
uname -a
apt-get update && apt-get install -y wget
apt-get install -y cmake make gcc libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev ocl-icd-opencl-dev libpulse-dev libdrm-dev libelf-dev rpm
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_DIRECTX_HEADERS=Off -DCMAKE_INSTALL_PREFIX=/usr .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-linux-armv6l
path: ./fastfetch-*.*
linux-vms:
name: Linux-${{ matrix.arch }}
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
strategy:
matrix:
include:
- arch: riscv64
- arch: ppc64le
- arch: s390x
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: uraimo/run-on-arch-action@v3
id: runcmd
with:
arch: ${{ matrix.arch }}
distro: ubuntu22.04
githubToken: ${{ github.token }}
run: |
uname -a
apt-get update && apt-get install -y software-properties-common
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get update && apt-get install -y cmake make gcc-13 libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev ocl-icd-opencl-dev libpulse-dev libdrm-dev libchafa-dev libelf-dev rpm
CC=gcc-13 cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_DIRECTX_HEADERS=Off -DCMAKE_INSTALL_PREFIX=/usr .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-linux-${{ matrix.arch }}
path: ./fastfetch-*.*
musl-amd64:
name: Musl-amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: setup alpine linux
uses: jirutka/setup-alpine@master
- name: install dependencies
run: |
cat /etc/alpine-release
uname -a
apk add cmake samurai vulkan-loader-dev libxcb-dev libxrandr-dev rpm-dev wayland-dev libdrm-dev dconf-dev imagemagick-dev chafa-dev zlib-dev dbus-dev mesa-dev opencl-dev sqlite-dev networkmanager-dev pulseaudio-dev ddcutil-dev elfutils-dev gcc g++
shell: alpine.sh --root {0}
- name: build
run: |
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr -DIS_MUSL=ON -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On -GNinja .
cmake --build . --target package --verbose -j4
shell: alpine.sh {0}
- name: run
run: |
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
shell: alpine.sh {0}
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-musl-amd64
path: ./fastfetch-*.*
macos-hosts:
name: macOS-${{ matrix.arch }}
runs-on: ${{ matrix.runs-on }}
permissions:
security-events: write
contents: read
strategy:
matrix:
include:
- arch: amd64
runs-on: macos-15-intel
- arch: aarch64
runs-on: macos-latest
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: uname -a
run: uname -a
- name: install required packages
run: |
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install --overwrite vulkan-loader vulkan-headers molten-vk imagemagick chafa
- name: configure project
run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
- name: build project
run: cmake --build . --target package --verbose -j4
- name: list features
run: ./fastfetch --list-features
- name: run fastfetch
run: time ./fastfetch -c presets/ci.jsonc --stat false
- name: run fastfetch --format json
run: time ./fastfetch -c presets/ci.jsonc --format json
- name: run flashfetch
run: time ./flashfetch
- name: print dependencies
run: otool -L fastfetch
- name: run tests
run: ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-macos-${{ matrix.arch }}
path: ./fastfetch-*.*
omnios-amd64:
runs-on: ubuntu-latest
name: OmniOS-amd64
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: vmactions/omnios-vm@v1
with:
usesh: true
envs: 'CMAKE_BUILD_TYPE'
prepare: |
uname -a
pkg update --accept
pkg install gcc14 cmake git pkg-config glib2 dbus sqlite-3 imagemagick ninja
run: |
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -GNinja .
cmake --build . --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
echo 'set(CPACK_PACKAGE_FILE_NAME "fastfetch-omnios-amd64")' >> CPackConfig.cmake
cpack -V
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-omnios-amd64
path: ./fastfetch-*.*
solaris-amd64:
runs-on: ubuntu-latest
name: Solaris-amd64
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: vmactions/solaris-vm@v1
with:
usesh: true
envs: 'CMAKE_BUILD_TYPE'
release: "11.4-gcc-14"
prepare: |
uname -a
pkg install cmake git pkg-config glib2 dbus sqlite-3 imagemagick ninja dconf mesa
run: |
export PKG_CONFIG_PATH=/usr/lib/64/pkgconfig
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -GNinja .
cmake --build . --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
echo 'set(CPACK_PACKAGE_FILE_NAME "fastfetch-solaris-amd64")' >> CPackConfig.cmake
cpack -V
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-solaris-amd64
path: ./fastfetch-*.*
freebsd-amd64:
name: FreeBSD-amd64
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: cross-platform-actions/action@master
with:
operating_system: freebsd
architecture: x86-64
cpu_count: 4
shell: bash
version: '15.0'
environment_variables: 'CMAKE_BUILD_TYPE'
run: |
uname -a
sudo pkg update
sudo pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl egl opencl ocl-icd v4l_compat chafa
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-freebsd-amd64
path: ./fastfetch-*.*
openbsd-amd64:
name: OpenBSD-amd64
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: cross-platform-actions/action@master
with:
operating_system: openbsd
architecture: x86-64
cpu_count: 4
shell: bash
version: '7.8'
environment_variables: 'CMAKE_BUILD_TYPE'
run: |
uname -a
sudo pkg_add -u
sudo pkg_add -r llvm-21.1.2p0 cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 imagemagick chafa
CC=clang-21 cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-openbsd-amd64
path: ./fastfetch-*.*
netbsd-amd64:
name: NetBSD-amd64
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: cross-platform-actions/action@master
with:
operating_system: netbsd
architecture: x86-64
cpu_count: 4
shell: bash
version: '10.1'
environment_variables: 'CMAKE_BUILD_TYPE'
run: |
uname -a
sudo pkgin -y install clang cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick
CC=clang cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-netbsd-amd64
path: ./fastfetch-*.*
dragonfly-amd64:
name: DragonFly-amd64
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: vmactions/dragonflybsd-vm@v1
with:
usesh: yes
envs: 'CMAKE_BUILD_TYPE'
prepare: |
uname -a
pkg update
pkg install -y llvm cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl egl opencl ocl-icd v4l_compat chafa libelf
run: |
env CC=clang cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-dragonfly-amd64
path: ./fastfetch-*.*
haiku-amd64:
name: Haiku-amd64
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: run VM
uses: cross-platform-actions/action@master
with:
operating_system: haiku
version: 'r1beta5'
architecture: x86-64
cpu_count: 4
shell: bash
environment_variables: 'CMAKE_BUILD_TYPE'
run: |
uname -a
pkgman install -y git dbus_devel mesa_devel libelf_devel imagemagick_devel opencl_headers ocl_icd_devel vulkan_devel zlib_devel chafa_devel cmake gcc make pkgconfig python3.10 || pkgman install -y git dbus_devel mesa_devel libelf_devel imagemagick_devel opencl_headers ocl_icd_devel vulkan_devel zlib_devel chafa_devel cmake gcc make pkgconfig python3.10
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On .
cmake --build . --target package --verbose -j4
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ctest --output-on-failure
- name: upload artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-haiku-amd64
path: ./fastfetch-*.*
windows-hosts:
name: Windows-${{ matrix.arch }}
runs-on: ${{ matrix.runs-on }}
permissions:
security-events: write
contents: read
strategy:
matrix:
include:
- arch: amd64
runs-on: windows-latest
msystem: CLANG64
msystem-lower: clang64
msys-arch: x86_64
- arch: aarch64
runs-on: windows-11-arm
msystem: CLANGARM64
msystem-lower: clangarm64
msys-arch: aarch64
defaults:
run:
shell: msys2 {0}
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: setup-msys2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.msystem }}
update: true
install: git mingw-w64-clang-${{ matrix.msys-arch }}-7zip mingw-w64-clang-${{ matrix.msys-arch }}-cmake mingw-w64-clang-${{ matrix.msys-arch }}-clang mingw-w64-clang-${{ matrix.msys-arch }}-vulkan-loader mingw-w64-clang-${{ matrix.msys-arch }}-vulkan-headers mingw-w64-clang-${{ matrix.msys-arch }}-opencl-icd mingw-w64-clang-${{ matrix.msys-arch }}-opencl-headers mingw-w64-clang-${{ matrix.msys-arch }}-cppwinrt mingw-w64-clang-${{ matrix.msys-arch }}-imagemagick mingw-w64-clang-${{ matrix.msys-arch }}-chafa
- name: print msys version
run: uname -a
- name: configure project
run: env PKG_CONFIG_PATH=/${{ matrix.msystem-lower }}/lib/pkgconfig/:$PKG_CONFIG_PATH cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
- name: build project
run: cmake --build . --verbose -j4
- name: copy necessary dlls
run: cp /${{ matrix.msystem-lower }}/bin/{OpenCL,vulkan-1}.dll .
- name: list features
run: ./fastfetch --list-features
- name: run fastfetch
run: time ./fastfetch -c presets/ci.jsonc --stat false
- name: run fastfetch --format json
run: time ./fastfetch -c presets/ci.jsonc --format json
- name: run flashfetch
run: time ./flashfetch
- name: print dependencies
run: ldd fastfetch
- name: run tests
run: ctest --output-on-failure
- if: github.event_name == 'push' && github.repository == 'fastfetch-cli/fastfetch'
id: upload-unsigned-artifact
name: upload artifacts for signing
uses: actions/upload-artifact@v7
with:
name: fastfetch-windows-${{ matrix.arch }}
path: |
*.dll
fastfetch.exe
flashfetch.exe
- if: github.event_name == 'push' && github.repository == 'fastfetch-cli/fastfetch'
name: submit signing request
uses: signpath/github-action-submit-signing-request@v1
with:
api-token: '${{ secrets.SIGNPATH_API_TOKEN }}'
organization-id: '${{ vars.SIGNPATH_ORG_ID }}'
project-slug: 'fastfetch'
signing-policy-slug: ${{ github.ref == 'refs/heads/master' && 'release-signing' || 'test-signing' }}
github-artifact-id: '${{ steps.upload-unsigned-artifact.outputs.artifact-id }}'
wait-for-completion: true
output-artifact-directory: '.'
- name: create zip archive
run: 7z a -tzip -mx9 -bd -y fastfetch-windows-${{ matrix.arch }}.zip LICENSE *.dll fastfetch.exe flashfetch.exe presets
- name: create 7z archive
run: 7z a -t7z -mx9 -bd -y fastfetch-windows-${{ matrix.arch }}.7z LICENSE *.dll fastfetch.exe flashfetch.exe presets
- name: upload true artifacts
uses: actions/upload-artifact@v7
with:
name: fastfetch-windows-${{ matrix.arch }}
path: ./fastfetch-windows-${{ matrix.arch }}.*
overwrite: true
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'fastfetch-cli/fastfetch'
name: Release
runs-on: ubuntu-latest
needs:
- linux-hosts
- linux-i686
- linux-armv7l
- linux-armv6l
- linux-vms
- musl-amd64
- macos-hosts
- freebsd-amd64
- openbsd-amd64
- netbsd-amd64
- dragonfly-amd64
- solaris-amd64
- omnios-amd64
- haiku-amd64
- windows-hosts
permissions:
contents: write
steps:
- name: get latest release version
id: get_version_release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
- name: download artifacts
if: needs.linux-hosts.outputs.ffversion != steps.get_version_release.outputs.release
uses: actions/download-artifact@v8
- name: create release
if: needs.linux-hosts.outputs.ffversion != steps.get_version_release.outputs.release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.linux-hosts.outputs.ffversion }}
commit: ${{ github.sha }}
artifactErrorsFailBuild: true
artifacts: fastfetch-*/fastfetch-*
body: "Please refer to [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ needs.linux-hosts.outputs.ffversion }}/CHANGELOG.md) for details."
- name: download source tarballs
if: needs.linux-hosts.outputs.ffversion != steps.get_version_release.outputs.release
run: |
for i in 1 2 3 4 5; do curl -L --remote-name-all --output-dir fastfetch-source --create-dirs https://github.com/${{ github.repository }}/archive/refs/tags/${{ needs.linux-hosts.outputs.ffversion }}.{tar.gz,zip} && break || sleep 5; done
ls fastfetch-*/*
- name: generate release notes
if: needs.linux-hosts.outputs.ffversion != steps.get_version_release.outputs.release
run: |
echo "Please refer to [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ needs.linux-hosts.outputs.ffversion }}/CHANGELOG.md) for details." > fastfetch-release-notes.md
echo -e "\n---\n\nSHA256SUMs
\n\n\`\`\`" >> fastfetch-release-notes.md
sha256sum fastfetch-*/* >> fastfetch-release-notes.md
echo -e "\`\`\`\n " >> fastfetch-release-notes.md
echo -e "\nSHA512SUMs
\n\n\`\`\`" >> fastfetch-release-notes.md
sha512sum fastfetch-*/* >> fastfetch-release-notes.md
echo -e "\`\`\`\n " >> fastfetch-release-notes.md
- name: update release body
if: needs.linux-hosts.outputs.ffversion != steps.get_version_release.outputs.release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.linux-hosts.outputs.ffversion }}
commit: ${{ github.sha }}
bodyFile: fastfetch-release-notes.md
allowUpdates: true
================================================
FILE: .gitignore
================================================
build/
.vs/
.vscode/
.cache/
.kdev4/
.DS_Store
cscope.*
tags
fastfetch.kdev4
*.user
*.user.*
*.swp
================================================
FILE: CHANGELOG.md
================================================
# 2.60.0
Changes:
* The CMake option `ENABLE_WIN7_COMPAT:BOOLEAN` now defaults to `OFF` and will be removed in v2.61.0, effectively dropping support for Windows 7 in the next release.
* This follows the Windows 7 deprecation notice introduced in v2.57.0.
* `wm.detectPlugin` now defaults to `true` (WM)
Features:
* Adds `{cwd}` for custom title formatting, which displays the current working directory (Title)
* Adds support for detecting the Zed version (#2200, Editor)
* Adds support for detecting `moss` packages (Packages, Linux)
* Adds support for detecting komorebi, FancyWM, and GlazeWM (WM, Windows)
* Adds support for WM plugin version detection on macOS (WM, macOS)
* Adds support for retrieving the executable path on OpenBSD (#2195, OpenBSD)
Bugfixes:
* Fixes a potential segmentation fault caused by dereferencing a negative index (#2198)
* Fixes `tempSensor` parsing so that it accepts only string values (#2202, CPU)
* Fixes an issue that unexpectedly caused fewer devices to be reported (Keyboard, Linux)
* Improves WM detection on LXQt by querying WM settings only when no WM has already been detected (#2199, WM, Linux)
* Fixes memory leaks in DBus connection handling and in the OpenGL EGL context lifecycle
* Fixes niri version detection on Fedora (WM, Linux)
* Includes various internal cleanups and optimizations
Logos:
* Adds `RengeOS` (#2170)
* Adds `Emmabuntüs` (#2207)
* Updates Artix Linux (#2157)
* Updates Linux Mint (#2186)
* Renames `Refracted Devuan` to `Refracta`
* Renames `ExodiaPredator` to `ExodiaOS`
# 2.59.0
Changes:
* Fastfetch no longer relies on the unreliable environment variables `$USER` or `%USERPROFILE%` to determine the current username (Title)
* People who set `$USER` to customize the Fastfetch title should use `{ "type": "title", "format": "your-custom-user-name" }` to achieve the same result.
* Fastfetch no longer tries to probe inaccessible remote disk drives on Windows (Disk, Windows)
* People who have remote drives may use `{ "type": "disk", "hideFolders": "X:\\" }` to ignore problematic ones.
* This change removes some ugly hacks from the codebase and matches the behavior on `*nix`.
Features:
* Adds Oracle Solaris support (#2176, SunOS)
* Adds UID / SID detection (Title)
* In custom format: `{user-id}`
* Switches to native GPU detection on GNU/Hurd and removes the `libpciaccess` dependency (GPU, Hurd)
* Improves memory size detection on macOS (Memory, macOS)
* Avoids relying on `hw.memsize_usable` by default, which may not be available on older macOS versions
* Improves Windows disk detection accuracy and performance (Disk, Windows)
* Adds more ARM CPU parts and removes duplicated cases (CPU, ARM)
Logos:
* Adds 6-color support to the NixOS logo (including the small variant) (#2180)
# 2.58.0
An early release to fix compatibility issues with KDE Plasma 6.6.
Breaking changes:
* The `de.slowVersionDetection` option has been removed. Slow version detection is now always enabled, as required on non-FHS-compliant distros (e.g., NixOS). (#2149, DE, Linux)
Features:
* Adds the `--structure-disabled ` command-line flag to temporarily disable module structure printing.
* For example: `fastfetch --structure-disabled colors` removes the color blocks from the default output.
* Supports chassis type detection on Linux ARM devices when reported via the device tree (Chassis, Linux)
* Supports Bedrock Linux version detection (#2155, OS, Linux)
* Honors the `DBPath` and `RootDir` settings in `pacman.conf` when detecting Pacman packages (#2154, Packages, Linux)
Bugfixes:
* Fixes a crash issue on KDE Plasma 6.6 (Display, Linux)
* Fixes the Command module not working with `--dynamic-interval` (#2152, Command)
* Fixes Quartz Compositor version detection. It now correctly reports the version of `WindowServer` (`SkyLight`) instead of `WindowManager`. (WM, macOS)
Logos:
* Adds Kiss2
# 2.57.1
Features:
* Tiny performance improvements (Windows)
* Improves the reliability of hostname retrieval (Title, Windows)
Bugfixes:
* Fixes potential compilation issues on Linux (#2142, Linux)
* Fixes compilation errors on macOS when building with older SDKs (#2140, macOS)
* Fixes compilation issues when building with `-DENABLE_SYSTEM_YYJSON=ON` (#2143)
Logos:
* Updates PrismLinux and adds a small variant
# 2.57.0
Deprecation notice:
* Support for Windows 7 (and 8.x) is deprecated and will be removed in a future release. Extended support for Windows 7 (and 8.1) ended on January 10, 2023. These versions do not officially support ANSI escape codes (running fastfetch on them requires a third-party terminal such as ConEmu). In addition, Windows 7 lacks some APIs used by fastfetch. Fastfetch currently loads these APIs dynamically at runtime to maintain compatibility, but this adds complexity to the codebase and increases the maintenance burden.
* A CMake flag `ENABLE_WIN7_COMPAT:BOOLEAN` has been introduced (defaults to `ON` for now). If set to `OFF`, Windows 7 compatibility code is excluded, and the resulting binaries will support only Windows 10 (version 1607 and later) and Windows 11.
* The main prebuilt Windows binaries on the Release page (`fastfetch-windows-amd64.*`) are built with `ENABLE_WIN7_COMPAT=OFF`. These are the binaries used by `scoop` and `winget`. Users who need Windows 7 (or 8.x) support can download the `-win7` variant instead.
* ~~The `ENABLE_WIN7_COMPAT` CMake option and the `-win7` variant binaries are planned to be removed in 2.60.0~~.
Features:
* Supports COSMIC DE version detection (DE, Linux)
* Supports niri version detection (#2121, WM, Linux)
* Supports cosmic-term version and terminal font detection (Terminal / TerminalFont, Linux)
* Supports urxvt font detection (TerminalFont, Linux) (#2105)
* Improves xterm font detection by checking `xterm.vt100.faceName` (TerminalFont, Linux)
* Supports Secure Boot detection (Bootmgr, macOS)
* Supports DPI scale factor detection on Windows 7 (Display, Windows)
* Supports xterm 256-color codes in color configuration
* In `display.color`: "`@`" (e.g., "`@34`" for color index `34`)
* In `*.format` strings: "`#@`" (e.g., "`#@34`" for color index `34`)
* Improves uptime accuracy on Windows 10+ (Uptime, Windows)
* Adds a new module `Logo` to query built-in logo raw data in JSON output (Logo)
* Usage: `fastfetch -s logo -l -j # Supported in JSON format only`
* Supports shell version detection even if the binary has been deleted (#2136, Shell, Linux)
* Overall code refinements and optimizations
Bugfixes:
* Skips local / loopback routes when detecting network interfaces (LocalIP, Linux) (#2127)
* Fixes CPU speed detection on s390x (CPU, Linux) (#2129)
* Fixes GPU detection error handling and supports case-insensitive PCI ID parsing (GPU, Windows)
* Fixes some networking issues and memory leaks (Networking)
* Fixes `exePath` reporting relative paths on macOS (Shell, macOS)
Logos:
* Adds openSUSE Tumbleweed braille logo
* Adds Xinux
* Renames HydraPWK to NetHydra
* Fixes colors of deepin and UOS
* Fixes colors of macOS and variants
# 2.56.1
Features:
* Improves compatibility with KDE Plasma 6.5 (#2093, Display)
* Adds a `tempSensor` option to specify the sensor name used for CPU temperature detection (CPU)
* Example: `{ "type": "cpu", "tempSensor": "hwmon0" /* Use /sys/class/hwmon/hwmon0 for temperature detection */ }`
* Refines Memory usage detection on macOS to match Activity Monitor more closely (Memory, macOS)
* Minor optimizations
Bugfixes:
* Fixes cache line size detection (CPU, macOS)
Logos:
* Removes Opak
* Updates GXDE
# 2.56.0
Features:
* Enhances config file loading. `--config` and `-c` with relative path now also searches paths defined in `fastfetch --list-config-paths` (typically `~/.config/fastfetch/`)
* This allows users to use `fastfetch -c my-config` without needing to specify the full path.
* Adds NUMA node count detection (CPU)
* Exposed via `{numa-nodes}` in custom format
* Supported on Linux, FreeBSD and Windows
* Supports the newest Alacritty config format (#2070, TerminalFont)
* Detects driver specific info for Zhaoxin GPUs (GPU, Linux)
* Detects Android OEM UI for certain OSes (DE, Android)
* Improves users detection on Linux (#2064, Users, Linux)
* Adds systemd fallback when utmp is unavailable
* Fixes resource leaks
* Always reports the newest session info
* Adds kiss package manager support (#2072, Packages, Linux)
* Reports `sshd` if `$SSH_TTY` is not available (Terminal)
* Zpool module rewrite (#2051, Zpool)
* Adds new Zpool properties: allocated, guid, readOnly
* Zpool module now uses runtime lookup for properties to ensure portability
* Adds NetBSD (requires `sudo`) and macOS support
* Adds `splitLines` option for Command module, which splits the output into sub modules, each containing one line of the output (Command)
```
* Command output:
Line 1
Line 2
Line 3
* Old behavior:
Command: Line 1
Line 2
Line 3
* With `"splitLines": true`:
Command 1: Line 1
Command 2: Line 2
Command 3: Line 3
```
Bugfixes:
* Fixes {m,o}ksh version detection on Linux (Shell)
* Fixes Alacritty config parsing for TOML format (#2070, TerminalFont)
* Improves builtin logo printing for piping and buffering (#2065, Logo)
* Uses absolute path when detecting shell and terminal version if available (#2067, TerminalShell)
Logos:
* Updates Codex Linux logo (#2071)
* Adds OS/2 Warp logo (#2062)
* Adds Amiga logo (#2061)
# 2.55.1
Bugfixes:
* Fix parallel command execution breaks randomly (#2056 / #2058, Command)
* Regression from v2.55.0
* Fix `dylib` searching path on macOS (macOS)
* Regression from v2.55.0
* Fix an uninitialized field (#2057, Display)
# 2.55.0
Changes:
* Commands are now executed in parallel by default to improve performance (#2045, Command)
* This behavior can be disabled in the config file with `"parallel": false` if it causes problems with certain scripts
* Folder/filesystem hiding is moved to the detection stage; hidden entries are no longer probed, improving performance (#2043, Disk)
Features:
* Adds `command.parallel` and `command.useStdErr` config options (Command)
* `parallel`: set to `false` to disable parallel execution (see Changes above)
* `useStdErr`: set to `true` to use stderr output instead of stdout
* Adds the command-line flag `--dynamic-interval ` to enable dynamic output auto-refresh (#2041)
* Due to internal limitations, some modules do not support dynamic updates (notably Display and Media)
* Adds support for using the current playing media's cover art as a logo source (Media / Logo)
* Usage: `"logo": { "type": "", "source": "media-cover" }` in JSON config; or `-- media-cover` in command line
* Supports local sources only
* Adds native GPU detection support on OpenBSD and NetBSD (instead of depending on `libpciaccess`) (GPU)
* No functional changes
* Root privileges are required to access PCI config space on OpenBSD (as always)
* Adds GPU detection support on GNU/Hurd (GPU)
* Requires building with `libpciaccess`
* Shows Debian point release on Raspberry Pi OS (#2032, OS, Linux)
* Adds `Brush` shell version detection (Shell)
* Improves Mac family detection via prefix matching (Host)
Bugfixes:
* Ignores `run-parts` during terminal/shell detection (#2048, Terminal / Shell, Linux)
* Fixes fish version detection when `LC_ALL` is set (#2014, Shell, Linux)
* Hides the module when no desktop icons are found (#2023, Icons, Windows)
* Skips auxiliary display controllers to prevent the module from reporting duplicate entries (#2034, GPU, Linux)
* Refines Apple rpath handling; fixes building for the Homebrew version on macOS (#1998, CMake)
Logos:
* Adds Vincent OS and MacaroniOS
# 2.54.0
Windows binaries in Release page are now signed by SignPath.
Changes:
* Moves macOS and Windows design language detection from the DE module to the Theme module
Features:
* Adds `--json` and `-j` command line flags as a shortcut for `--format json`
* Various improvements to the OS module (OS)
* Displays point releases for Debian
* Displays code names for Ubuntu
* Displays build ID for macOS
* Displays code names for Windows (previously shown in the Kernel module)
* Adds basic support for Wine (Windows)
* Adds basic support for hppa and sh architectures (CPU, Linux)
* Improves T-Head SoC name detection from the device tree (#1997, CPU, Linux)
* Supports glob patterns in `Disk.hideFolders` (Disk)
* For example, `/boot/*` will match both `/boot/efi` and `/boot/firmware`
* Adds brightness-level detection for external monitor support on Intel macOS (Brightness, macOS)
* Adds configurable spacing between icon and text in keys
* `display.key.type: "both-N"` where N is `0-4`
* Useful for non-monospaced Nerd Fonts
* Adds detection support for modern Samsung Exynos SoCs (CPU, Android)
* Adds a new CMake option `-DENABLE_WORDEXP=` to enable or disable using `wordexp(3)` for acquiring logo file paths (`logo.source`)
* Enabled by default for compatibility
* Disabling this option reverts to using `glob(3)`, which is less functional but more secure
Bugfixes:
* Avoids integer overflow when calculating swap size (#1988, Swap, Windows)
* Trims whitespace from full user name (Title, macOS)
* Fixes default font size for Ghostty (#1986, TerminalFont, Linux)
* Works around an issue that could report impossibly high memory usage in rare cases (#1988, Memory, Linux)
* Fixes incorrect glibc dependency in polyfilled DEB packages (#1983, Linux)
* Fixes corrupted binaries in polyfilled RPM packages (#1990, Linux)
* Fixes crashes on ancient Android kernels (#1993, Disk, Android)
* Fixes incorrect usage of `glob(3)` (OpenBSD)
* Prefers resolutions reported by RandR mode info, fixing incorrect resolutions on XFCE when DPI scaling is enabled (Display, Linux)
* Various code cleanups and minor fixes
Logos:
* Adds secureblue, PrismLinux, EmperorOS and Zraxyl
* Updates T2
# 2.53.0
Changes:
* JSON property `length` in `Separator` module has been renamed to `times` for clarity (Separator)
Features:
* Adds IPv6 type selection (#1459, LocalIP)
* For example: `{ "type": "localip", "showIpv6": "ula" /* Show ULA only */ }`
* Adds more ARM CPU part IDs (CPU, Linux)
* Improves Ghostty font config parsing with fallback font detection (#1967, TerminalFont)
* Replaces statx(2) call with syscall(2) for better compatibility (Disk, Linux)
* Allows array input for disk folder and filesystem options (Disk)
* For example: `{ "type": "disk", "folders": ["/", "/home"] }`
* Adds support for ignoring input devices by name prefix (#1950, Keyboard / Mouse / Gamepad)
* For example: `{ "type": "keyboard", "ignores": ["Apple ", "Corsair "] }`
* Adds support for (B)SSID detection on macOS Tahoe (Wifi, macOS)
* Please don't expect it to work on later macOS versions
* Improves Ubuntu flavor detection (#1975, OS, Linux)
* Refines ARMv8.4-A detection to require LSE2 (CPU, Windows)
* Detects the latest Dimensity & Snapdragon SoC names (CPU, Android)
Bugfixes:
* Handles zero temperature data (#1960, CPU, Windows)
* Fixes `dlopen libzfs.so failed` error on Proxmox 9 (#1973, Zpool, Linux)
Logos:
* Removes Starry Linux
* Adds TempleOS
* Updates ObsidianOS
# 2.52.0
Changes:
* New optional build dependencies on Android
* main: chafa dbus glib imagemagick libelf libxcb libxrandr pulseaudio zlib
* x11: dconf (Optional)
* Dependency on `libxfconf` is removed. XFCE related detection now uses `libdbus` instead (Linux)
* The default format of `Display` module is updated to `{width}x{height} @ {scale-factor}x in {inch}", {refresh-rate} Hz`
* Replaced scaled resolution with scale factor for shorter texts and avoiding potential confusion.
Bugfixes:
* Fixes linking on 32-bit Android (#1939)
* Skips network interfaces without IPs unless MAC address is requested (#1949, LocalIP)
* Fixes unexpected padding when setting `logo.width` with chafa logos (#1947, Logo)
* Regression from v2.51.0
* Improves Wallpaper detection on XFCE4 (Wallpaper, Linux)
* Ignores process `Relay(xxx)` when detecting terminal on WSL2 (Terminal, Linux)
Features:
* Enables X11-related info (i.e., WM/DE) detection on Android (Global, Android)
* This requires many dependencies. See above.
* Adds scale factors detection for X11 (Display, Linux)
* X11 doesn't natively report scale factor as Wayland does. Instead, Fastfetch tries to detect `Xft.dpi` (DPI used by X FreeType for scaling fonts), which is usually set by the WM when DPI scaling is enabled.
* It's not always accurate. For example, XFCE4 has a separate config for text scaling, which is unaffected by the global DPI scaling setting.
* Adds `display.fraction.trailingZeros: [always|never]` option for fraction formatting
* The default value of `display.fraction.ndigits` is changed from `-1` (unlimited) to `2` for usability.
* Used for displaying scale factor in Display module mentioned above, alongside other places for printing raw fraction numbers.
* Informs users that module-specific CLI options are no longer supported and provide guidance for transitioning to JSON config
* Adds CPU name detection support for IA64 (CPU, Linux)
* Support Btrfs allocation profile detection (#1941, Btrfs, Linux)
# 2.51.1
Bugfixes:
* Fix building on macOS 14 or older; no functional changes (CPU, macOS)
# 2.51.0
Changes:
* Fastfetch now requires [yyjson 0.12](https://github.com/ibireme/yyjson/releases/tag/0.12.0) to build when using `-DENABLE_SYSTEM_YYJSON=ON`.
* The Disk module no longer shows hyperlink mountpoints by default, which cause issues on some real consoles (Disk)
* Instead, the custom key for the Disk module now supports `{mountpoint-link}` and `{name-link}` to show hyperlinks for mountpoints and names. For example, `{ "type": "disk", "key": "Disk ({mountpoint-link})" }` can be used to restore the old behavior.
Features:
* Adds `succeeded` module condition to JSONC config. When set to `false`, the module will only run if the last module failed (#1908)
* Useful for displaying fallback placeholders when a module fails. For example:
```jsonc
{
"host",
// If fastfetch fails to detect host info, display "DIY PC" instead
{
"type": "custom",
"condition": {
"succeeded": false
},
"key": "Host",
"format": "DIY PC"
}
}
```
* By upgrading to yyjson 0.12, fastfetch now adds [JSON5](https://json5.org/) format support for configuration files (#1907)
* [JSON5](https://json5.org/) is a superset of JSONC that allows unquoted keys, single quotes, multi-line strings, etc., and is fully compatible with JSONC and strict JSON.
* To use JSON5, simply name your config file with a `.json5` extension. The `.jsonc` extension is still supported and used as the default extension for better IDE syntax highlighting support.
* Fastfetch has been ported to [`GNU/Hurd`](https://www.gnu.org/software/hurd/) (#1895)
* Thanks to the efforts of @yelninei!
* Built-in logos now honor `logo.width` (#1905)
* When its value is larger than the actual logo width, the logo will be padded with spaces to the right
* Adds Trinity DE version detection (#1917, DE, Linux)
* Adds formatted free and available disk size fields (#1929, Disk)
* `{size-free}`: free size of the disk
* `{size-available}`: available size of the disk
* See [askubuntu.com](https://askubuntu.com/questions/249387/df-h-used-space-avail-free-space-is-less-than-the-total-size-of-home) for the difference between free and available size
* Adds [x86_64 micro-architecture level](https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels) detection (#1928, CPU)
* Useful when installing software that requires or is optimized for specific CPU features. E.g., [CachyOS](https://wiki.cachyos.org/features/optimized_repos/)
* Exposed via `{march}` in custom format
* Adds [Aarch64 micro-architecture level](https://en.wikipedia.org/wiki/AArch64#Profiles) detection (CPU)
* Supported on Linux (including Android), macOS and Windows
* This is not fully accurate because there are many optional features across different levels, and not all levels are detectable.
* Exposed via `{march}` in custom format.
* Adds shepherd detection support (InitSystem, Linux)
Bugfixes:
* Refines GPU detection logic to correctly handle virtual devices (#1920, GPU, Windows)
* Fixes possible default route detection failure when the route table is very large (#1919, LocalIP, Linux)
* Fastfetch now correctly parses `hwdata/pci.ids` files alongside `pciids/pci.ids` on FreeBSD when detecting GPU names (#1924, GPU, FreeBSD)
* Fixes twin WM detection (#1917, WM, Linux)
* Various fixes for Android support
* Corrects WM name for Android (WM, Android)
* Fixes battery temperature detection when running in ADB (Battery, Android)
* Adds CPU and GPU temperature detection support (CPU, Android)
Logos:
* Adds AerynOS
# 2.50.2
Bugfixes:
* Fixes linglong package detection V2 (#1903, Packages, Linux)
* Fixes building with `-DENABLE_SYSTEM_YYJSON=ON` (#1904)
* Fixes `showMac` does not honor `defaultRouteOnly` (#1902, LocalIP, Linux)
* Fixes failing to acquire default route on Linux in certain cases (#1902, LocalIP, Linux)
# 2.50.1
Bugfixes:
* Fixes percentage bar not displaying correctly in certain cases
* Fixes linglong package detection on Debian 13 (#1899, Packages, Linux)
# 2.50.0
Changes:
* Keys in JSON configuration files are now case-sensitive, as stated in v2.49.0.
* This is a breaking change, but it should not affect most users as long as your config file passes JSON schema validation.
* All module config flags have been removed, as stated in v2.49.0.
* To configure modules via the command line, use: `echo '{"modules": [{"type":"custom","format":"Hello Fastfetch!"}]}' | fastfetch -c -`.
* The percent bar config `display.bar.*` options have been replaced with a more organized, nested object structure.
* `display.bar.charElapsed` has been renamed to `display.bar.char.elapsed`.
* `display.bar.charTotal` has been renamed to `display.bar.char.total`.
* `display.bar.borderLeft` has been renamed to `display.bar.border.left`.
* `display.bar.borderRight` has been renamed to `display.bar.border.right`.
* The undocumented flag `--load-config` has been removed.
* Use `--config` or `-c` instead.
* Flashfetch, a simplified fastfetch variant that used a hardcoded module list with direct function calls to reduce startup overhead, has been changed to a version that aims to match neofetch's behavior as closely as possible, for demonstration purposes.
* Flashfetch is intended to be built from source (like [st](https://st.suckless.org/)). We do not provide prebuilt binaries in distributions.
Features:
* Added support for reading JSON config from stdin using `--config -` or `-c -`.
* Added `display.bar.border.{leftElapsed,rightElapsed}` for using the border as part of the bar content. (#1875)
* `display.bar.border: null` has been added as a shorthand to disable bar borders.
* Added `display.bar.color.{elapsed,total,border}` to customize the color of the elapsed, total, and border sections of the percent bar.
* `display.bar.color: null` has been added as a shorthand to disable bar colors.
* Improved Bedrock Linux detection (#1881, OS / Disk, Linux)
* Added the command flag `--gen-config-full`, which generates a JSON config file containing all optional module options.
* Improved the default IP address display when `localip.showAllIPs` is not set (LocalIP)
* For IPv4, the preferred source address (if detected) is shown.
* For IPv6, the first GUA or ULA that is not deprecated or temporary is shown.
* Added support for interface speed detection on SunOS (LocalIP, SunOS)
* Added detection support for Xlibre (#1888, WM, Linux)
* Improved the accuracy of color detection (Cursor, macOS)
* Improved the proformance of `Nix` package manager detection on macOS by porting optimizations form Linux port (#1893, Packages, macOS)
Bugfixes:
* Fixed custom object inheriting a key from the previous custom object if the key is blank (#1477)
* Fixed a possible segfault when parsing color strings in the JSON config (#1878)
* Fixed GPU driver detection when DRM is used (GPU, FreeBSD)
* Fixed default route detection on DragonFly BSD (LocalIP, DFBSD)
* Fixed lliurex detection (#1882, OS, Linux)
* Fixed compatibility with `-ffast-math` (#1894)
* Fixed physical GPU sometimes being ignored (#1896, GPU, Windows)
Logos:
* Added ObsidianOS (#1890)
# 2.49.0
Deprecation Notice:
* In fastfetch v2, the JSONC configuration format has been introduced, while command line configuration flags are kept for compatibility. Although they have the same effects, they use two different code paths, and as the number of flags grows, the codebase is becoming increasingly difficult to maintain.
* Removal of module config flags is planned for **v2.50.0**, which will also fix a long-standing issue #1477.
* Removal of most other config flags is also planned for later versions.
* Keys of JSON configuration files will be all case-sensitive. Currently they are inconsistent. Planned for **v2.50.0**.
Changes:
* Due to more restrictive permissions in macOS Tahoe, SSID detection on macOS 26+ requires root privileges. `` will be displayed otherwise.
Features:
* Improve `nouveau` driver support for `--gpu-driver-specific` (GPU, Linux)
* VRAM size detection
* GPU temperature detection
* Core count detection (when available)
* Improve Scoop package manager detection (Packages, Windows)
* Support [`scoop-global`](https://github.com/ScoopInstaller/Install?tab=readme-ov-file#advanced-installation)
* Read Scoop's config file to find the installation path of Scoop
* Improve ARM SoC detection (CPU, Android)
* Make SoC detection more lenient. Higher chance to match at the cost of accuracy.
* Add more Snapdragon SoC names
* Support labwc WM version detection, used for XFCE4 on Wayland (WM, Linux)
* Improve accuracy of GPU temperature detection for Intel dedicated GPUs on Windows (GPU, Windows)
* Parse unicode escaped strings generated by qt5ct (#1864, Font, Linux)
* Add `--{duration,percent,size,freq,temp}-space-before-unit [always|never]` options to add a space before the unit when printing duration, percent, size, frequency and temperature values
* Add `--duration-abbreviation` to abbreviate duration values in custom format
* For example: `1 day, 2 hours, 3 mins` will be displayed as `1d 2h 3m`
* Add `--percent-width` to pad the percent value with spaces to a fixed width
* For example: `--percent-width 3` will display ` 50%` instead of `50%`; useful for aligning percent values in custom format
Bugfixes:
* Improve accuracy of Flatpak count detection (#1856, Packages, Linux)
* Remove qi package manager support (#1858, Packages, Linux)
* Fix LocalIP module on Windows (LocalIP, Windows)
* Fix default route detection when multiple network interfaces are connected
* Fix link speed calculation
* Fix interface status when the interface is up but not connected (Wifi, Linux)
* Fix variable names in custom format (#1861)
* `full-path` to `path` (Editor)
* `session` to `session-name` (Users)
* `name` to `project-name` (Version)
* Fix wrong /s assignment in custom format (#1871, DiskIO)
Logos:
* Add `Aeon`
* Remove `Evolinx`
# 2.48.1
Features:
* Add support for detecting Openbox WM version (WM, Linux)
* Improve reliability of child process spawning on Windows (Windows)
* Add a new option `--packages-combined`, which combines related package managers into single counts (#1851, Packages)
* For example: if you have both `flatpak-system` and `flatpak-user` packages installed, they will be combined into a single `flatpak` count with `--packages-combined` enabled.
* Add `modules[n].condition` to conditionally enable modules on different platforms
* Useful when sharing configuration files across platforms
* For example:
```jsonc
{
"type": "custom",
"format": "This string will be printed on Intel macOS only",
"condition": {
"system": "macOS", // Can be an array, optional
"arch": "x86_64" // Can be an array, optional too
}
}
```
Bugfixes:
* Revert the change of `posix_spawn` in v2.48.0 for Android and OpenBSD (Android / OpenBSD)
* Fix completion for Android 7 (Required by Termux)
# 2.48.0
Features:
* Add support for detecting Fedora variants (#1830, OS, Linux)
* Currently supported variants: CoreOS, Kinoite, Sericea, Silverblue
* Optimize GPU detection on Windows when `--gpu-driver-specific` is not used (GPU, Windows)
* Improve accuracy of GPU type detection. Previously it was guessed based on the dedicated vmem size, which causes issues on newer AMD integrated GPUs such as 9000 HX and AI 9 HX series. Supported on Windows 8.1 or later.
* Add support for generic frequency detection of GPU 3D engine on Windows 11 22H2 or later.
* Improve performance. GPU temperature detection is significantly improved when `--gpu-driver-specific` is not used.
* Improve performance and security when spawning child processes by replacing `fork-exec` with `posix_spawn` (*nix)
* Improve accuracy of sound device detection on macOS (Sound, macOS)
* Trim leading and trailing whitespaces in disk serial numbers (PhysicalDisk)
* Add `/etc/profiles/per-user` detection for Nix user packages (#1782, Packages, Linux)
* Introduce `years` (whole years as integer), `days-of-year` (days since the last anniversary) and `years-fraction` (years as fraction, e.g. 1.5 means 1 year and 6 months) formatting placeholder to `Disk` (since disk creation), `Users` (since user login) and `Uptime` (since system boot) modules
* For example: `fastfetch -s disk --disk-key 'OS Installation' --disk-format '{years} years {days-of-year} days'`
* Add `--fraction-ndigits` option to specify the number of digits after the decimal point when displaying ordinary fractional values
* Typically used with `{years-fraction}` above
* This option does not affect percentage values, sizes, etc, which are controlled by individual options.
Bugfixes:
* Fix compilation issues when not using `-DBINARY_LINK_TYPE=dlopen`
* Regression from v2.47.0
* Note: this option was added for debugging purposes only and is not recommended for production use
* Replace `MTLDevice::hasUnifiedMemory` with `MTLDevice::location` for GPU type Detection (GPU, macOS)
* This should resolve the issue where discrete GPUs were detected as integrated GPUs on Intel MacBooks with multi-GPU configurations.
* Prevent text files from being loaded as image files (#1843, Logo)
Logos:
* Add Minimal System
* Add AxOS
* Rename Ada to Xray OS
# 2.47.0
Features:
* Various improvements for Solaris / OpenIndiana support
* Support BIOS (UEFI or legacy) type detection (BIOS)
* Support physical disk detection (PhysicalDisk)
* Remove leading `-` from login shells (Shell)
* Improve GPU detection performance (GPU)
* Drop `libpciaccess` dependency
* Use native API to detect sound devices (Sound)
* Drop `PulseAudio` dependency
* Improve DietPi OS and Raspberry Pi OS detection (#1816, OS, Linux)
* Force reporting version 26 on macOS Tahoe (OS, macOS)
* Append version string to Ubuntu variants (OS, Linux)
* Improve performance of media detection for macOS 15.4+ (Media, macOS)
* Increase `PROC_FILE_BUFFSIZ` to avoid possible short reads (Linux)
* Fix potential bugs in `DiskIO`, `NetIO` and `CPUUsage` modules
* Improve accuracy of CPU usage calculations by including interrupt and softirq times (CPUUsage, Linux / *BSD)
* Ignore `init` and `systemd` processes when detecting terminals (Terminal, Linux)
* Improve accuracy of CPU usage detection on Windows 10+ with perflib, which matches values reported by Task Manager (CPUUsage, Windows)
Bugfixes:
* Fix `pci.ids` file location (#1819, GPU, OpenBSD)
* Fix compiling on FreeBSD when `libdrm` support is disabled (#1820, GPU, FreeBSD)
Logos:
* Improve visibility on white-background terminals for some logos by replacing white with the default foreground color
* According to Wikipedia, the default foreground color is implementation-defined. It's usually black for white themes and white for dark themes. However, some terminals, notably Konsole with the default theme, use a different color, which may cause issues with some logos.
* Add Xubuntu
# 2.46.0
Features:
* Support Rio terminal font detection (#1789, TerminalFont, Linux)
* Support GPU detection by DRM on FreeBSD (GPU, FreeBSD)
* Enable by `--gpu-detection-method auto`
* Require proper DRM drivers installed and loaded
* Support PowerPC CPU detection on NetBSD (#1802, CPU, NetBSD)
* Support Aerospace WM detection (#1796, WM, macOS)
* Improve Raspberry Pi OS for RPI5 detection (#1773, OS, Linux)
* Support Linux Binary Compatibility detection on FreeBSD (#1786, Host, Linux)
* Use `board-id` as board name if available (Board, macOS)
* Intel only
* Support shared VRAM usage detection for AMD GPUs (GPU, Linux)
* Use `perflib.h` instead of `pdh.h` for CPU temperature querying to get rid of `pdh.dll` dependency (#1787, CPU, Windows)
* Support GPU info detection for old ATI radeon driver (#1810, GPU, Linux)
* Add macOS 26 Tahoe support (macOS)
* Report macOS 26 code name (OS)
* Report Liquid Glass DE on macOS 26+ (DE)
* Detect Metal 4 support (GPU)
Bugfixes:
* Fix packages counting by ignoring hidden folders (Packages, OpenBSD)
* Fix Hyprland version detection (WM, FreeBSD)
* Don't show `Please insert a disk into drive D:` error dialogs (#1805, Disk, Windows)
* Hide `/boot/firmware` by default (Disk, Linux)
Logos:
* Rename Hydra Framework to HydraPwk (#1812)
* Add AnushOS (#1806)
* Add HarmonyOS (#1804)
* Add GhostFreak (#1801)
* Add TrueNAS Scale (#1795)
* Add Fedora2_small (#1785)
* Add xenia_old; update colors of xenia (#1797)
* Improve colors of bedrock_small (#1790)
* Add Kalpa Desktop (#1807)
# 2.45.0
Features:
* Support OnePlus marketing name detection (#1768, Host, Android)
* Recognize additional GPU vendors (GPU, Linux)
* Support CTWM, FVWM and I3 window manager version detection (WM)
* Support KDE version detection on *BSD (DE, FreeBSD)
* Support `"logo": { "type": "command-raw" }` to run a command and display its output as logo (#1780, Logo)
* Useful for displaying custom logos generated by other programs such as `pokeget`: `{ "type": "command-raw", "source": "pokeget random --hide-name" }`
* Supported in JSONC config file only. `pokeget random --hide-name | fastfetch --file-raw -` should be used in shell.
* Acquire SMBIOS information on DragonFly BSD from `/dev/mem`; legacy BIOS only (PhysicalMemory, DragonFly)
* Support swap usage detection on DragonFly BSD (Swap, DragonFly)
* Support `--swap-separate` to display detailed swap devices on separate lines (Swap)
Bugfixes
* Fix MacBook Air model name (#1779, Host, macOS)
* Don't ignore sshfs mountpoints (#1776, Disk, Linux / FreeBSD)
* Fix dnf package count detection (#1777, Packages, Linux)
Logos:
* Add Starry Linux (#1771)
* Add rhel_small (#1774)
* Update color palette of voidlinux (#1775)
* Add void2
* Update Xenia Linux (#1783)
# 2.44.0
Features:
* Add option `--disk-hide-folders` and `--disk-hide-fs` to hide specific mountpoints and filesystems in Disk module (Disk)
* `--disk-hide-folders` defaults to `/efi:/boot:/boot/efi` on Linux and *BSD. Previously these EFI-related folders were hardcoded to be hidden on Linux.
Bugfixes:
* Fix Apple Terminal compatibility with `--stat` (macOS, #1755)
* Ignore `/usr/bin/script` when detecting shell and terminal (Terminal / Shell, #1761)
* Fix compatibility with KDE Plasma 6.4 which is in beta currently (Display, Linux, #1765)
Logos:
* Add Kylin (#1760)
* Add UBLinux (#1764)
# 2.43.0
Features:
* Support physical core count and package count detection on Solaris (CPU, SunOS)
* Improve physical core count detection on FreeBSD (CPU, FreeBSD)
* Add option to hide unknown GPUs (GPU)
* Detect VRAM type of AMD GPUs on Linux (GPU, Linux)
* Support playing media detection on macOS 15.4 (#1737, Media, macOS)
* Whether it works on newer versions is unknown
* Detect player name for Windows UMP apps (Media, Windows)
Bugfixes:
* Fix disk usage detection on 32-bit Linux (#1734, Disk, Linux)
* Fix compiling on Asahi Linux (GPU, Linux)
* Fix duplicated playback status (Media, Linux)
* Don't show 255 in custom format when muted on macOS (#1750, Sound, macOS)
* Remove shared memory detection for AMD GPUs, which doesn't work as expected (GPU, Windows)
Logos:
* new AthenaOS
* add Hydra Framework
# 2.42.0
Changes:
* Normalize the module name `Bios` to `BIOS` (#1721)
* No configuration file changes are required because fastfetch parses module names case-insensitively.
Bugfixes:
* Disable disk type detection for virtual disks (PhysicalDisk, Linux, #1669)
* Fix incorrect CPU temperature reporting (CPU, OpenBSD)
* Fix setting `logo.chafa.symbols` in JSON configuration (Logo, #1709)
* Fix non-normalized time display (Uptime, #1720)
* Miscellaneous minor fixes
Features:
* Add CPU temperature detection support (CPU, SunOS)
* Improve CPU frequency detection (CPU, NetBSD)
* Add Wi-Fi detection support (Wifi, NetBSD)
* Add Webcam detection support (Camera, OpenBSD)
* Requires root privileges
Logos:
* Remove GoralixOS logo (#1699)
* Add Aurora logo (#1700)
* Add Codex Linux logo (#1701)
# 2.41.0
Changes:
* Due to [the deprecation](https://github.com/actions/runner-images/issues/11101), Linux x86_64 binaries are now built with Ubuntu 22.04 (Glibc 2.35, Debian 12)
* You can always build fastfetch yourself on your own. Please don't report bugs related to this change.
Features:
* Support physical core count detection on non-x86 platforms (CPU, Linux / FreeBSD)
* Support CPU frequency detection on PPC64 (CPU, FreeBSD)
* Support soar packages count detection (Packages, Linux)
* Support `~` path expanding on Windows (Logo, Windows)
* Support retrieving full user name (Title)
* Exposed with `--title-format '{full-user-name}'`
* Improve CPU (thermal zone) temperature detection on Windows (CPU, Windows)
* Administrator privileges are no longer needed
* Support base Wifi info detection on OpenBSD (Wifi, OpenBSD)
* To be tested
* Support GPU temperature detection for Intel dGPU on Linux (GPU, Linux)
* To be tested
* Add new ARM CPU part numbers (CPU, Linux)
* Add base implementation of Bluetooth device detection (Bluetooth, NetBSD, #1690)
* Some small improvements
Logo:
* Add anduinos
* Add 2 more Alpine logos
# 2.40.4
Bugfixes:
* Fix loading presets config on Windows (Windows, #1682)
* Regression of v2.40.0
* Remove the prefix `v` of Hyprland version on Arch Linux (WM, Linux)
# 2.40.3
Bugfixes:
* Fix loading example configs from presets directory (#1672)
* Regression of v2.40.2
* Mark kitty image protocol support for warp terminal on macOS too (Logo)
# 2.40.2
Changes:
* Since v2.40.0, we've been loading config files from the directory where the fastfetch binary is located. However, this approach may lead to loading unexpected files. For example, `fastfetch -c groups` would attempt to load `/usr/bin/groups`. Therefore, we now enforce the `.jsonc` extension when loading config files. Examples:
1. `-c filename`: loads `filename.jsonc`
2. `-c filename.jsonc`: loads `filename.jsonc`
3. `-c filename.json`: loads `filename.json` and enforces strict JSON syntax (no comments or trailing commas)
4. `-c filename.ext`: loads `filename.ext.jsonc` (`.jsonc` extension is enforced)
Features:
* Mark kitty image protocol support for warp terminal (Logo)
* Documentation improvements
# 2.40.1
Bugfixes:
* Fix compiling error on old intel platform (TPM, macOS)
* Fix `--file-raw -` no longer working (Logo, #1659)
* Regression of v2.40.0
# 2.40.0
Changes:
* In `key-format` of `LocalIP` module, `{name}` has been renamed to `{ifname}` for consistency (LocalIP, #1639)
Features:
* Support Warp Terminal font detection (TerminalFont, Windows)
* Support more AMD GPU information using ADL SDK, including memory type detection (GPU, Windows)
* Support Intel dGPU memory type detection (GPU, Windows)
* Support Nvidia VMEM type detection via NVAPI (GPU, Windows, #993)
* Support Boot manager detection for OpenBSD and NetBSD (Bootmgr, OpenBSD / NetBSD)
* Use `SystemConfiguration` for DNS entries detection (DNS, macOS)
* Add `systemd-resolved` support for DNS module (DNS, Linux, #1646)
* Improve performance and accuracy of Wifi detection on FreeBSD using ioctl (Wifi, FreeBSD)
* Support remaining time reporting for batteries on NetBSD (Battery, NetBSD)
* Add new Mac models support (Host, macOS)
* Load config from fastfetch binary path with `--config` option (#1649)
* Support TPM detection on macOS (TPM, macOS)
* Support IPv6 client address report (Users, Linux / Windows)
* Support default route detection for IPv6 (LocalIP, Linux)
* Round seconds to the nearest minute to match the behavior of `uptime` command (Uptime)
Bugfixes:
* Fix `outputColor` not working when `length` is set in Separator module (#1644)
* Fix CPU detection on PowerPC platforms (#1640, CPU, Linux)
* Fix battery manufacture date detection (Battery, macOS)
* Fix battery critical state detection (Battery, Linux)
* Fix Warp Terminal PID detection (Terminal, macOS)
* Remove disk creation time detection support on SunOS as ctim is file status change timestamp, not creation time (Disk, SunOS)
* Fall back to KDGKBINFO if `usbhid` fails (Keyboard, FreeBSD)
* Fix multiple paging file support (Swap, Windows)
* Fix memleaks, code smells in multiple modules
* Fix boot time calculation on NetBSD (Uptime, NetBSD)
* Temporarily fix Hyprland version detection (WM, Linux, #1657)
Logo:
* Fix opensuse-tumbleweed_small (#1636)
* Change WiiLinuxNgx to more generic name with aliases Wii-Linux and WiiLinux (#1633)
* Change name of Xray-OS to Ada (#1651)
* Change Nexa Linux logo (#1653)
# 2.39.1
Bugfixes:
* Fix a regression that PublicIP detection fails randomly (PublicIP, #1629)
# 2.39.0
Changes:
* OSMesa backend for OpenGL detection is removed (#1618)
* Fastfetch no longer tries to use the private framework `Apple80211` to acquire SSID for Wifi module, which is only useful for macOS Sonoma (Wifi, macOS)
Features:
* Improve accuracy of HDR support on Windows 11 24H2 (Display, Windows)
* Improve performance of SSID detection on macOS Sequoia (Wifi, macOS, #1597)
* Support warp terminal version detection on Windows (Terminal, Windows)
* Support default route detection on OpenBSD & DragonFly BSD (LocalIP, OpenBSD / DragonFly)
* Improve bash completion script
* Improve performance of networking (PublicIP / Weather)
* Support pkgsrc package manager detection on Linux (Packages, Linux)
Logo:
* Add Common Torizon OS
* Change FoxOS to WolfOS
* Add Bredos
* Add NetBSD2
# 2.38.0
Bugfixes:
* Fix empty battery slots handling (Battery, Haiku, #1575)
* Fix `{day-pretty}` output in custom format (DateTime, Windows)
* Fix VanillaOS detection (OS, Linux)
* Fix secure boot testing (Bootmgr, Linux, #1584)
* Fix the SI unit "kB" in help message (#1589)
* Fix segfault on macOS 10.15 when using the binary downloaded from Github Releases (Camera, macOS, #1594)
Features:
* Support Chassis module in macOS (Chassis, macOS)
* Allow customize key format with kernel name and distro name (OS)
* Add missing `{icon}` in custom key format (Battery)
* Add missing `{mountpoint}` and `{mount-from}` in custom output format (Disk, #1577)
* Support percentage num & bar in custom format (GPU, #1583)
* Support `pisi` package manager detection (Packages, Linux)
* Support termite terminal font detection (TerminalFont, Linux)
* Report monitor type in Brightness module (Brightness)
Logo:
* Add `opensuse-tumbleweed_small`
* Add `Bedrock_small`
* Add `fastfetch`
* Remove some unnecessary distro names
# 2.37.0
Changes:
* Option `--escape-bedrock` is removed. The function is always enabled now.
Features:
* Support for Haiku is greatly improved (Haiku)
* CPU, GPU, Disk, Sound, Terminal, Terminal Font, Init System, Battery, Mouse, Keyboard, NetIO, CPU Usage, Physical Disk and OpenGL should work on Haiku now
* SMBIOS related modules (Host, Bios, Board, Chassis, Physical Memory) should work in platforms with legacy BIOS system.
* Support for Gamepad and Bluetooth are WIP.
* Some bugs are found and fixed.
* Remove `python-requests` dependency in `scripts/gen-*.py`.
* Add cmake option `-DENABLE_EMBEDDED_AMDGPUIDS=BOOL` (disabled by default)
* If enabled, fastfetch will embed the newest [`amdgpu.ids`](https://gitlab.freedesktop.org/mesa/drm/-/blob/main/data/amdgpu.ids?ref_type=heads) file into fastfetch binary.
* Weather module now honors `display.temp.unit` option (#1560, Weather)
* Support Physical Memory module in NetBSD (PhysicalMemory, NetBSD)
* Requires root permission
* Improve non-intel CPU detection in NetBSD (#1573, CPU, NetBSD)
Bugfixes:
* Fix building in macOS 10.13 (GPU, macOS)
* Properly round percent values when detecting volume (#1558, Sound)
* Fix Physical Memory module doesn't work in `--format json` mode
* Add some missing variable inits (GPU, Linux)
* Fix `--localip-default-route-only false` not working with `--gen-config` (#1570, LocalIP)
Logo:
* Update Rosa linux
* Add Haiku2
# 2.36.1
Changes:
* To use [the native arm64 runner of Github Action](https://github.blog/changelog/2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview/), Linux aarch64 binary is built with Ubuntu 22.04 (Glibc 2.35, Debian 12).
Bugfixes:
* Chimera Linux logo is now displayed correctly (#1554, Logo)
* Regression of 2.36.0
* Fix building on Haiku
Logo:
* Fix ALT Linux
# 2.36.0
Bugfixes:
* Trim leading slash for login shells (Shell, OpenBSD)
* Prefer SOC name if available over CPU name (CPU, Linux)
Features:
* Use kernel API to detect sound devices (Sound, NetBSD)
* Use sndio for sound server detection on OpenBSD (Sound, OpenBSD)
* Add minimal implementation for Haiku (#1538, Haiku)
* Support CPU & GPU temperature detection for M4x (CPU / GPU, macOS)
* Support VMEM size detection for old Nvidia cards (GPU, Linux)
* Use [recommendedMaxWorkingSetSize](https://developer.apple.com/documentation/metal/mtldevice/recommendedmaxworkingsetsize) as total GPU mem size (GPU, macOS)
* Support Physical core count and CPU package count detection for loongarch (CPU, Linux)
* Split ID_LIKE when used for distro matching (#1540, Logo)
* Capitalize `{type}`'s first letter in custom format (#1543, Display)
* Support model name detection for s390x (CPU, Linux)
* Support more Armbian variants detection (#1547, OS, Linux)
* Support the syntax of `{$ENV_VAR}` in custom format, which will be replaced by the value of the environment variable `ENV_VAR` (#1541)
* This is another way to pass 3rd-party data to fastfetch besides `Custom` module.
* Improve performance of Tilix version detection (Terminal, Linux)
Logo:
* Update arch_old
* Add Nexa Linux
* Add filotimo
* Update some distro names
# 2.35.0
Bugfixes:
* Suppress output of EGL again (#1513, GPU, Linux)
* Regression of 2.34.0
Features:
* Show SOC name reported in `cpuinfo` if available (#1510, CPU, Linux)
* Change package manager name of NetBSD from `pkg` to `pkgsrc` (#1515, Packages, NetBSD)
* Detect SOC name on RISCV (#1519, CPU, Linux)
* Report marketing name of new QS8Es (CPU, Android)
* Acquire acquire more os info from lsb-release if missing from os-release (#1521)
* CMake: add option `-DCUSTOM_LSB_RELEASE_PATH` to specify the path of `lsb-release` file
* `-DCUSTOM_OS_RELEASE_PATH` has been supported since `v2.11.4`
* Report more SOC names on Android (CPU, Android)
* Support duration printing in custom format (Disk / Users)
* For example:
```jsonc
{
"modules": [
{
"key": "OS Installation Date", // No longer need to write bash scripts
"type": "disk",
"folders": "/", // Different OSes may need to specify different folders
"format": "{create-time:10} [{days} days]" // Reports the creation date of the root folder
}
]
}
```
Logo:
* Add Arch_old
* Update key color of NetBSD_small
* Fix OpenBSD and many other ascii logos (#1522)
# 2.34.1
An early release to fix KDE Plasma 6.3 compatibility. Hopefully it can be accepted by package managers before KDE 6.3 is officially released.
To package managers: if you find fastfetch bugs, it's highly appreciated if you can report them to the upstream, so that all users can benefit from the fix, instead of maintaining out-of-tree patches. Thanks!
Features:
* Report vendor name when detecting GPUs by OpenGL
* Note: the vendor name is actually the creator of the OpenGL driver (such as `Mesa`) and may not be the same as the GPU vendor.
Bugfixes:
* Fix Ghostty termfont detection (#1495, TerminalFont, macOS)
* Fix compatibility with KDE Plasma 6.3 (#1504, Display, Linux)
* Make memory usage detection logic consistent with other systems (Memory, OpenBSD / NetBSD)
* Report media file name if media title is not available (Media)
* Fix max frequency detection for CPUs with both performance and efficiency cores (CPU, FreeBSD)
Logo:
* Add HeliumOS
* Add Oreon
* Update SnigdhaOS
# 2.34.0
Changes:
* We now print distro pretty name if available (OS)
* This is a long requested feature. However, it may break some distros. File a bug with the content of `/etc/os-release` if it breaks your distro.
Bugfixes:
* Fix thunderbolt version of new MBPs (#1465, Host, macOS)
* Fix backlight name detection on FreeBSD (Brightness, FreeBSD)
* Fix Terminal detection when running fastfetch in `pk-command-not-found` (#1467, Terminal, Linux)
* Relax detection of terminals in NixOS (#1479, Terminal, Linux)
* Should fix konsole, ghostty and maybe others
* Fix core count output in multi-package platforms (CPU)
* Don't suppress the output of `preRun` (#1489)
* Fix battery percentage detection (Battery, NetBSD)
Features:
* Support ghostty terminal font detection (TerminalFont, Linux / macOS)
* Support `kitty-icat` image protocol, which uses `kitten icat` to generate image data
* Pros: support tmux; support gif animations; good performance
* Cons: due to the limitation of `kitten icat`, we need to clear the screen before displaying the image logo
* Support WM version detection (WM)
* In Linux, Hyprland & sway are supported currently
* Improve performance when stdout is redirected (TerminalSize)
* Report thermal zone temp if CPU temp is not available (CPU, Linux)
* Report sound server (Pipewire or PulseAudio) if available (#1454, Sound, Linux)
* Enable OpenGL & OpenCL detection on Android (OpenGL / OpenCL, Android)
* Detect & report MediaTek Dimensity 9000+ SOC name (CPU, Android)
* Support appman (am-user) package manager detection (Packages, Linux)
Logo:
* Add Lubuntu
* Update Xray_os
* Add SnigdhaOS
* Add Rhino Linux
# 2.33.0
Changes:
* Introduce a new CMake flag `-DBUILD_FLASHFETCH=OFF` to disable building flashfetch binaries
* Package managers are encouraged to enable it. See for detail
Bugfixes:
* Fix interconnect type detection (#1453, PhysicalDisk, Linux)
* Regression of v2.28
* Don't report `proot` as terminal (Terminal, Android)
* Remove a debug output (DiskIO, OpenBSD)
* Fix media detection for some players (#1461, Media, Linux)
* Regression of v2.32
Features:
* Use `$POWERSHELL_VERSION` as PowerShell version if available (Shell, Windows)
* Fetching Windows PowerShell version can be very slow. Add `$env:POWERSHELL_VERSION = $PSVersionTable.PSVersion.ToString()` in `$PROFILE` before running `fastfetch` to improve the performance of `Shell` module
* Add support for ubuntu-based armbian detection (#1447, OS, Linux)
* Improve performance of Bluetooth detection (Bluetooth)
* We no longer report disconnected bluetooth devices in `--format json` when `--bluetooth-show-disconnected` isn't specified
* Support brightness level detection for builtin displays (Brightness, OpenBSD / NetBSD)
* Requires root permission on OpenBSD
* Support battery level detection (Battery, OpenBSD / NetBSD)
* Support CPU temperature detection in NetBSD (CPU, NetBSD)
* Hard code path of `libvulkan.so` for Android
* So that users don't need to install the vulkan-loader wrapper of termux
Logo:
* Add NurOS
* Add GoralixOS
# 2.32.1
A hotfix for OpenBSD. No changes to other platforms.
Bugfixes:
* Fix package count detection on OpenBSD (Packages, OpenBSD)
# 2.32.0
Bugfixes:
* Fix `pci.ids` file location on OpenBSD (GPU, OpenBSD)
* It's normally unused because enumerating PCI devices on OpenBSD requires root privileges
* Fix bssid formatting (Wifi, Linux)
* Fix Linux Lite distro detection (#1434, OS, Linux)
* Suppress XE driver warnings from Mesa (#1435, OpenGL, Linux)
* Fix format parameter name (#1443, Version)
* Don't report useless information when Wifi is disabled (Wifi, FreeBSD)
* Currently there are issues when the SSID contains whitespaces. More fixes are expected in the future.
* Always use physical size reported by X11 server to avoid inconsistent results (#1444, Display, Linux)
Features:
* Randomly select one if the logo source expands to multiple files (#1426, Logo)
* Report mac product name when running Linux in MacBook (Host, Linux / FreeBSD)
* Use screen size reported in DTD if make sense (Display)
* Detect Virtualized Apple Silicon CPUs (CPU, Linux)
* Add detection support for fvwm and ctwm (WM, OpenBSD / NetBSD)
* Add Armbian-unofficial detection (OS, Linux)
* Prefer surfaceless display when connect EGL (OpenGL)
* Improve accuracy of WM detection on FreeBSD (WM, FreeBSD)
* Add ratpoison window manager (WM, Linux)
Logo:
* Update Linux Lite
* Add Serpent OS
* Add Ultramarine Small
* Update Debian
# 2.31.0
Bugfixes:
* Improve performance of media detection; fix musikcube detection (Media, Linux)
* After the change, `general.processingTimeout` will also control the timeout of dbus remote calls
* Fix invalid variable names (#1408, Users)
* Change physical size detection to use basic display parameters (#1406)
* Fix possible sigfaults when detecting displays (#1393)
* Fix Nvidia card type detection
* Fix wl-restart parsing (#1422, WM, Linux)
* Fix syntax error in completion file (#1421)
* Fix hunging when using `ssh-agent` as command text (#1418, Command, macOS)
Features:
* Remove support of xcb & xlib and xrandr extension is always required (Display)
* Support preferred resolution & refresh rate detection
* On macOS there is no preferred resolution reported and maximum available resolution is reported instead.
* `--display-format {preferred-width}x{preferred-height}@{preferred-refresh-rate}`
* Report scale factor in custom format (Display)
* `--display-format {scale-factor}`
* Detect current Wi-Fi channel and maximum frequency (Wifi)
* Report processor package count (#1413, CPU)
* Remove duplicate whitespaces in CPU name
* Support sakura terminal version & font detection (Terminal / TerminalFont, Linux)
Logo:
* Fix LMDE
* Update MidOS
* Add Windows Server 2025
# 2.30.1
Bugfixes:
* Fix the destination where `fastfetch.1` is generated (#1403)
# 2.30.0
Changes:
* Percent: bar type must be enabled in `percent.type` before using percent bar in custom format
Features:
* Port to MidnightBSD; add mport package manager support
* Support bluetooth battery detection for macOS and Windows (Bluetooth, macOS / Windows)
* Support M4 model detection (Host, macOS)
* Support CPU temperature detection on OpenBSD (CPU, OpenBSD)
* Display Android icon in Android devices (OS, Android)
* Support qi package manager detection (Packages, Linux)
* Detect WM / DE by enumerating running processes (WM / DE, NetBSD)
* Generate manual pages from `help.json` (Doc)
* Detect marketing name of vivo smartphone (Host, Android)
* Add txDrops detection if supported (NetIO, *BSD)
* Support tilix version detection (Terminal, Linux)
* Support percent type config in module level. Example:
```jsonc
{
"type": "memory",
"percent": {
"green": 20, // [0%, 20%) will be displayed in green
"yellow": 40, // [20, 40) will be displayed in yellow and [40, 100] will be displayed in red
"type": [ // Display percent value in monochrome bar, same as 10
"bar",
"bar-monochrome"
]
}
}
```
Bugfixes:
* Don't display `()` in key if display name is not available (Display)
* Fix & normalize bluetooth mac address detection (Bluetooth, macOS / Windows)
* Don't print index in multi-battery devices (Battery)
* Fix segfault in macOS (#1388, macOS)
* Fix `CFStringGetCString() failed` errors (#1394, Media, macOS)
* Fix CPU frequency detection on Apple M4 (#1394, CPU, macOS)
* Fix exe path detection on macOS (Shell / Terminal, macOS)
* Fix logo fails to load from symlinked files on macOS (#1395, Logo, macOS)
* Fix 32-bit truncation (NetIO, macOS)
Logos:
* Fix Lilidog
* Add MidnightBSD
* Add Unifi
* Add Cosmic DE
* Update openSUSE Tumbleweed
# 2.29.0
Changes:
* Due to [the upstream removal of MSYS2 CLANG32 environment](https://www.msys2.org/news/#2024-09-23-starting-to-drop-the-clang32-environment), we dropped fastfetch-windows-i686 support. v2.27.1 was the last version supporting it.
* Note: fastfetch built with MSVCRT has known bug that DateTime module doesn't work because of its bad support of [strftime](https://en.cppreference.com/w/c/chrono/strftime). Don't use it.
Features:
* Port to NetBSD and DragonFly BSD
* Fastfetch now supports all major BSD variants
* Support DiskIO, NetIO, GPU and Users module on OpenBSD
* Report SD8E SOC name (CPU, Android)
* On Windows, try loading dlls from current exe path (Windows)
* Fix Media module when installed with winget
Bugfixes:
* Fix the VIM version detection on Ubuntu (Editor, Linux)
* Improve performance of OS version detection on Proxmox (#1370, OS, Linux)
Logo:
* Update OpenSuse Tumbleweed
* Add XCP-ng
* Add SummitOS
* Add Lilidog
* Update PikaOS
* Update OpenSUSE Leap
* Update aperture
# 2.28.0
Features:
* Add new module `Mouse` and `Keyboard` which display connected mice and keyboards
* Support remaining time detection (Battery)
* Report if AC is connected (Battery, Linux)
* Report platform API used for display detection for debugging (Display)
* Report Wine version when running in Wine (Kernel, Windows)
* Add option `waitTime` in modules `CPUUsage`, `DiskIO` and `NetIO`
Bugfixes:
* Fix used memory size detection (Memory, OpenBSD)
* Don't report invalid fragmentation percentage when fails to detect it (Zpool)
* Fix unexpected errors when running fastfetch in parallel (#1346, Windows)
* Don't report obviously invalid temperature values (PhysicalDisk, Linux)
Logos:
* Add eweOS
* Add MidOS
* Update XeroArch
# 2.27.1
Bugfixes:
* Fix invalid display name detection on GNOME, wayland (Display, Linux)
# 2.27.0
Changes:
* We now print `"` instead of `″` when displaying diagonal length in inches, so that the character can be correctly displayed in Linux console (Display)
* All detection code of `monitor` module is merged into `display` module. Now `monitor` just prints the same information as `display` with different format. Notably:
* The resolution reported by `monitor` module is now current resolution instead of native / maximum resolution. PPI is calculated based on current resolution too.
* The refresh rate reported by `monitor` module is the current refresh rate.
Features:
* Add basic, highly experimental support of OpenBSD (OpenBSD)
* Improve support for Raspberry pi (CPU / GPU, Linux)
* Detect SOC name, instead of displaying components used in the SOC, if available (CPU, Linux)
* Add option `--brightness-compact` to display multiple brightness values in one line (Brightness)
* Add `day-pretty` (#1305, DateTime)
* Support network interface adapter flag detection (#1315, LocalIP)
* Enable it with `--localip-show-flags`
Bugfixes:
* Remove trailing newline in GPU name for Raspberry pi (#1303, GPU, Linux)
* Fix a possible buffer overflow (GPU, Linux)
* Fix CPU temp incorrectly reported as 0 celsius (#1308, CPU, Linux)
* Correctly report `TPM device is not found` error (#1314, TPM, Windows)
* Fix errors when triggering shell completion with python3 uninstalled (#1310)
* To package managers: as shell completion scripts of fastfetch use python3, it should be added as an optional dependency of fastfetch
* Fix possible crashes when detecting term font of kitty (#1321, TerminalFont, Linux)
Logos:
* Add XeroArch
* Add ValhallaOS
# 2.26.1
Features:
* Allow to disable pacstall packager detection in CMake
Bugfixes:
* Fix uninitialized variables (GPU, Windows)
# 2.26.0
Changes:
* To be consistent to other platforms, CPU frequency detection on Linux no longer checks `bios_limit`
Features:
* Detect GPU index (#1267, GPU)
* Count Flatpak runtime packages (#1085, Packages, Linux)
* Support pacstall package manager (Packages, Linux)
* Support CU core count, max frequency, VMEM usage detection for AMD cards on Linux (GPU, Linux)
* Requires `--gpu-driver-specific`
* Support EU core count, VMEM size detection Intel cards on Linux (GPU, Linux)
* Requires `--gpu-driver-specific`. VMEM usage detection requires root permissions.
* Add new module `TPM` to print TPM (Trusted Platform Module) version if available (TPM)
* Support GPU driver version detection (GPU, macOS)
* Add new CMake option `-DENABLE_EMBEDDED_PCIIDS=ON`.
* If enabled, fastfetch will download the newest [`pci.ids`](https://pci-ids.ucw.cz/) file, [transform it into C code](https://github.com/fastfetch-cli/fastfetch/blob/dev/scripts/gen-pciids.py) and compile it into fastfetch binaries.
Bugfixes:
* Fix font size detecton of foot terminal (#1276, TerminalFont, Linux)
* Ignore `su` and `sudo` when detecting terminal (#1283, Terminal, Linux)
* Always print inches in integer (Display)
* Fix Wifi connection protocol detection on macOS Sequoia (Wifi, macOS)
* Fix hanging when font name is long when detecting kitty term font (#1289, TerminalFont)
* Detect all enabled or connected connectors (#1301, Display, Linux)
Logos:
* Add FoxOS
* Add GXDE OS
# 2.25.0
Features:
* Moore Threads GPU add support to query number of cores (#1259, GPU)
* Cache detection result based on last modification time (Packages)
* Add cmake options to disable certain package managers at compile time
* Package managers are encouraged to disable some package managers by passing `-DPACKAGES_DISABLE_` when running `cmake`. For example, when building for Arch Linux, `-DPACKAGES_DISABLE_APK=ON -DPACKAGES_DISABLE_DPKG=ON -DPACKAGES_DISABLE_RPM=ON ...` should be specified.
* See all available options by [running `cmake -L | grep PACKAGES_DISABLE_`](https://github.com/fastfetch-cli/fastfetch/blob/dev/CMakeLists.txt#L91)
* This option does NOT remove the detection code. It just disables the detection at runtime. One can still use `--packages-disabled ""` to enable all package managers.
* Add new option `--show-localip-{speed,mtu}` (LocalIP)
* Add new module `Btrfs`, which prints all mounted Btrfs volumes, like `Zpool` module (#1262, Linux)
* Improve Wifi module support for macOS Sequoia (Wifi, macOS)
* Currently it uses `system_profiler` which costs about 2 seconds on my MBP. I suggest disabling it for now until a better solution is found.
Bugfixes:
* Fix invalid CPU temperature detection on FreeBSD (#1260, CPU, FreeBSD)
* Remove `showPeCoreCount` support on FreeBSD (#1260, CPU, FreeBSD)
* Don't use Wifi speed as Ethernet speed (LocalIP, FreeBSD)
* Fix compiling with old linux headers (Camera, Linux)
* Fix detecting public ipv6 address (PublicIP, Windows)
Logo:
* Fix parrot logo detection
* Rename TorizonCore to Torizon OS
# 2.24.0
Changes:
* Support of `--lib-XXX` is removed
* If fastfetch fails to load some `.so` `.dylib` libraries, `LD_LIBRARY_PATH` should be used.
Features:
* Support sixel image protocol on Windows (Logo, Windows)
* Requires imagemagick7 to be installed. MSYS2 is recommended.
* Improve terminal query on Windows (Windows)
* TerminalSize, TerminalTheme
* Detect more ARM microarchitectures and SOC names (CPU, Linux)
* Detect the number of online cores (CPU, FreeBSD)
* Support board name detection for Asahi Linux (Board, Linux)
* Add new option `--command-param` to customize the parameters when running shell
* Support syntax of sub string in `---format`: `{variable~startIndex,endIndex}`
* See `fastfetch -h format` for detail
Bugfixes:
* Fix tests building when system yyjson is used (#1244)
* Fix dinit detection; support dinit version detection (#1245, InitSystem, Linux)
* Fix signal quality, refresh rate and maybe others in custom format (#1241)
* Fix boot time calculation (#1249, Uptime, Linux)
* Fix custom format for boolean values
* `{?false-value}This should not print{?}{?true-value}This should print{?}` will print `This should print`
* Fix possible hanging when running fastfetch in screen 5.0 (TerminalTheme, macOS)
Logos:
* Add Lliurex
# 2.23.0
Features:
* Support unity version detection (DE, Linux)
* Print model name in Battery keys if available (Battery)
* Add module `Zpool`
* Improve performance (Shell / Terminal, Linux)
* Support syntax of padded strings in `---format`. `{variablepadlength}` are supported.
* If pad length is greater than the length of the variable, the variable will be padded with spaces.
* `fastfetch -l none -s command --command-text 'echo 12345' --command-format 'output({1<20})'` prints `Command: output(12345 )`
* `fastfetch -l none -s command --command-text 'echo 12345' --command-format 'output({1>20})'` prints `Command: output( 12345)`
* If pad length is less than the length of the variable, the variable will be truncated.
Bugfixes:
* Fix broken `--list-presets`
* Update zsh completion script
* Don't print `*` if `defaultRouteOnly` is set (NetIO)
* Fix Camera module incorrectly disabled on FreeBSD (Camera, FreeBSD)
* Fix hanging on screen 5.0 (Terminal)
* Improve image logo support on Windows (Logo, Windows)
Logos:
* Update AmogOS
* Add Magix
* Make ubuntu logo colorable
* Add Steam Deck Logo
* add Huawei Cloud EulerOS
# 2.22.0
Features:
* Small performance improvements (Terminal, Editor)
* Improve arm32 and loongarch support (CPU, Linux)
* Ignore the parent process if env `$FFTS_IGNORE_PARENT` is set to `1` (Shell)
* Add code name of Apple M4 (CPU, Linux)
* Add ethernet speed rate detection support (LocalIP)
* Add zsh completion script
* Add Linglong package manager detection support (Packages, Linux)
Bugfixes:
* Fix building on macOS 10.14
* Fix tmux in linux TTY (Colors)
* Fix hang in WSL when custom format is used (Disk, Linux)
* Fix `/proc/loadavg` parsing (Loadavg, Linux)
* Disable use of `LC_NUMERIC` locale settings to fix parsing of decimal numbers
* Fix possible segfault (DiskIO, Linux)
* Honor `preciseRefreshRate` in custom format (Display)
Logos:
* Add Lingmo OS
* Add Sleeper OS
# 2.21.3
Bugfixes:
* Fix bad Intel Arc GPU name detection, which was supposed to be fixed in the last version but the change was reverted accidentally (#1177, GPU, Linux)
* Fix arm32 CPU name detection no longer work. Regression of 2.21.2 (CPU, Linux)
# 2.21.2
Features:
* Support `--stat ` to display long running modules in yellow or red
Bugfixes:
* Fix bad Intel Arc GPU name and type detection (GPU, Linux)
* Fix uninited struct fields (GPU, Linux)
* Skip cpu model smbios detection on ARM platforms (CPU, Linux)
* Always use `CurrentControlSet` instead of `ControlSet001` when querying registry (Windows)
* Fix NVIDIA GPUs are missing in GPU detection sometimes (GPU, Windows)
* Fixing detection of `pthread_timedjoin_np` (Linux)
Logos:
* Add HyprOS
* Add GoldenDog Linux
# 2.21.1
Hotfix for a regression that breaks WM detection when running `startx` from TTY (Regression from 2.21.0, #1172 / #1162)
Changes:
* On Linux, FreeBSD and SunOS, a new recommended dependency `libelf` is introduced to extract strings in ELF binary, used for
* st term font detection when the term font is compiled directly into the binary
* fast path of systemd version detection
Features:
* Improve performance of
* kitty version detection (Terminal, Linux)
* st term font detection (TerminalFont, Linux)
* systemd version detection (InitSystem, Linux)
Bugfixes:
* Fix building error without `linux/wireless.h` (Wifi, Linux)
* Fix wrong GPU max frequency on Asahi Linux (GPU, Linux)
* Don't rely `$XDG_SESSION_TYPE` for detecting wm protocol (#1172 / #1162, WM, Linux)
* Fix light color doesn't work on Linux console (Colors, Linux)
* `LC_ALL`, if set, overrides every other locale-related environment variable (Locale)
* Increase timeout of DBus calls (Linux)
Logos:
* Add vanilla_small and vanilla2
* Add LFS (Linux From Scratch)
# 2.21.0
Changes:
* We no longer use `libnm` for Wifi detection on Linux. Instead, we use `libdbus` to communicate with NetworkManager directly
* To package managers: libnm dependency should be removed
Features:
* Add module `BluetoothRadio` that prints bluetooth radios installed on the system
* Don't confuse with module `Bluetooth` which lists connected bluetooth devices
* Detect more information when `--gpu-driver-specific` is used (GPU)
* Detect which type of nvidia driver (open source or proprietary) is used (GPU, Linux)
* `--gpu-driver-specific` adds supports for Moore Threads GPU (#1142, GPU, Linux / Windows)
* Use SetupAPI for detecting GPUs to support GPU detection when running fastfetch as a Windows Service (GPU, Windows)
* See https://github.com/gpustack/gpustack/pull/97#issuecomment-2264699787 for detail
* Detect playback status (Media, Linux)
Bugfixes:
* Don't try to connect display server in tty mode (Linux, #1110)
* Improve ssh detection
* Fix max frequency printing in custom format (CPU)
* Fix displaying random characters when detecting kitty term font (#1136 / #1145, TerminalFont, Linux)
* Make sure to detect all physical memory devices (#1137)
* Don't detect `wl-restart` as WM (#1135, WM, Linux)
* Use PCI bus ID to match Nvidia cards; fix multi-GPU detection (GPU)
* Ignore invalid GPU (#1066, GPU, macOS)
* Print error when invalid color code is found (#1138)
* Fix invalid refresh rate detection on old macOS versions (Display, macOS)
* Fix disk size detection on 32-bit systems (Disk, BSD)
* Don't ignore disabled GPUs (#1140, GPU, Linux)
* Fix GPU type detection on FreeBSD (GPU, FreeBSD)
* Remove shell version detection for unknown shells (#1144, Shell)
* Don't detect hyfetch as shell on NixOS (Shell, NixOS)
Logos:
* Update EndeavourOS_small
* Add QTS
# 2.20.0
This release fixes regression of `2.19.0` on M1 MacBook Air. It also introduces a new option `--key-type icon` to display predefined icons in keys (requires newest nerd font). See `fastfetch -h key-type` for detail.
Changes:
* JSON option `display.keyWidth` has been renamed to `display.key.width`
* Previously: `{ "display": { "keyWidth": 3 } }`
* Now: `{ "display": { "key": { "width": 3 } } }`
* Windows Terminal font detection **in WSL** has been removed due to [issue #1113](https://github.com/fastfetch-cli/fastfetch/issues/1113)
Features:
* Add option `display.key.type: ` to print icons in keys
* Supported value `string`, `icon` and `both`. Default to `string` (don't display icons)
* Example: `{ "display": { "key": { "type": "icon" } } }`
* Add option `display.key.paddingLeft: ` to print left padding (whitespaces) in keys
* Example: `{ "display": { "key": { "paddingLeft": 2 } } }`
* Add option `modules.keyIcon` to set icon for specified module
* Example: `{ "modules": { "type": "command", "keyIcon": "🔑" } }`
* Report system mono font name for Terminator if used (TerminalFont, Linux)
* Don't require logo height to be set when using `--logo-position right`
* Report Snapdragon SOC marketing name for newer Android phones (CPU, Android)
* Detect MTK SOC part name (CPU, Android)
Bugfixes:
* Don't wake up suspended GPUs when using `--ds-force-drm` (Display, Linux)
* Fix printing editor type in JSON result (Editor)
* Fix `--logo-padding-*` not working correctly (#1121, Logo)
* Fix possible segfault when detecting GPU frequency (#1121, macOS, GPU)
# 2.19.1
Bugfixes
* Fix frequency value printing when using custom format (#1111, CPU / GPU)
* Fix display detection for XiaoMi Android phone (Display, Android)
Features:
* Display if HDR mode is enabled for screens (Display)
* Supported in Windows and Linux (KDE) correctly
# 2.19.0
Changes:
* JSON option `modules.cpu.freqNdigits` has been renamed and moved to `display.freq.ndigits`
* Previously: `{ "modules": { "type": "cpu", "freqNdigits": 2 } }`
* Now: `{ "display": { "freq": { "ndigits": 2 } } }`
* This option now affects GPU frequency too
* By default, frequencies are displayed in *GHz*. Set `display.freq.ndigits` to `-1` to display them in *MHz*
* JSON option `display.binaryPrefix` has been moved to `display.size.binaryPrefix`
* Previously: `{ "display": { "binaryPrefix": "IEC" } }`
* Now: `{ "display": { "size": { "binaryPrefix": "IEC" } } }`
Features:
* Print physical diagonal length if supported (Display)
* Detect display type in X11 mode (Display)
* Assume displays connected via DisplayPort are external monitors (Display, Linux)
* Support GPU frequency detection for Intel XE driver (GPU, Linux)
* Detect init system on Android (InitSystem, Android)
* Use background to display color blocks (Colors)
* To fix weird vertical black lines in some terminals and match the behavior of neofetch (#1094)
* Can be reverted to old behavior with `--colors-symbol block`
* Support Zed terminal version detection (Terminal)
* Improve wezterm font detection (TerminalFont)
* Add option `--separator-length`
* Support GPU frequency detection for Apple Silicon (GPU, macOS)
* Detect maximum refresh rate (#1101, Monitor)
* Detect if HDR mode is supported and enabled (Windows, Display / Monitor)
* Support physical monitor info detection for FreeBSD and SunOS (Monitor)
* Support defining constant strings in JSON config file, which can be used to dedupe formattion strings
```jsonc
{
"display": {
"constants": [
"Hello", // {$1}
"world" // {$2}
]
},
"modules": [
{
"type": "custom",
"format": "{$1} {$2}!" // print "Hello world!"
},
{
"type": "custom",
"format": "{$2} {$1}" // print "world Hello"
}
]
}
```
Bugfixes:
* Fix some presets
* Better detection for XTerm terminal fonts (#1095, TerminalFont, Linux)
* Remove debug output (#1097, Windows)
* Fix flag `--gpu-hide-type` doesn't work (#1098, GPU)
* Fix wrong date on Raspbian 10 (#1108, DateTime, Linux)
* Use `brightness` instead of `actuall_brightness` when detecting current brightness level (Brightness, Linux)
* Ref: https://bugzilla.kernel.org/show_bug.cgi?id=203905
* Fix buffer overflow with long font family names when detecting kitty term font (TerminalFont)
* Fix some typos
Logos:
* Update void_small
* Add ALT Linux
# 2.18.1
Fix a regression introduced in v2.18.0
Changes:
* `--ts-version` has been renamed to `--detect-version`
* `general.detectVersion` in JSON config file
Bugfixes:
* Fix and improve GPU driver detection (#1084, GPU, Linux)
# 2.18.0
Changes:
* `yyjson 0.10.0` is required
* Fastfetch no longer prints `*` (which means it's the default route) if `defaultRouteOnly` is set (LocalIP)
Bugfixes:
* Fix some memory leaks
* Fix compatibility with old Python versions
* Don't detect frequency for AMD cards (GPU, Linux)
* Fix possible hang with discrete AMD cards (#1077)
* Don't print colors in `--pipe` mode (Separator)
* Don't print `(null)` in property `locator` (PhysicalMemory)
* Ignore disabled PCI devices (GPU)
* Fix flag `--opengl-library` doesn't work (OpenGL)
Features:
* Detect revision of USB drives (#1048, Disk)
* Support fractional scale factor detection (Display, Linux)
* Support primary display detection for KDE and GNOME (Display, Linux)
* Support percent bar in custom formatting
* Print signal quality by default (Wifi)
* Detect used OpenGL library version (OpenGL)
* Support detecting OpenGL version by `EGL` (ANGLE) on Windows (OpenGL)
Logos:
* Add Arkane Linux
* Add Opak
# 2.17.2
Changes:
* Flatpak package count no longer takes runtime packages into account (Packages, Linux)
Bugfixes:
* Fix formattion with multiple batteries (Battery)
* Fix incorrect size value for large memory sticks (PhysicalMemory)
* Fix spelling of `Qt` and `LXQt`
* Fix building on SunOS if imagemagick support is enabled (Logo, SunOS)
* Fix typos
Features:
* Support Ptyxis terminal version and font detection (Terminal / TerminalFont, Linux)
* Improve Cinnamon version detection (DE)
* Support `cinnamon-wayland` (WMTheme)
* `--ts-version false` will disable editor version detection (Editor)
# 2.17.1
Hotfix for a regression that breaks Qt font detection
Bugfixes:
* Don't generate and install `libffwinrt.dll.a` on MinGW (Windows)
* Fix building on Windows when imagemagick support is enabled (Logo, Windows)
* Don't print GPU frequency with `--gpu-temp` for Nvidia cards (#1052, GPU)
* `--gpu-driver-specific` needs to be specified
* Print formatted size when `--gpu-format` is used (#1052, GPU)
* Ignore QVariant format; fix unreadable Qt font (#1053, Theme, Linux)
* Fix segfaults with `--show-errors` and an invalid module (#1055)
# 2.17.0
Changes:
* CMake option `ENABLE_PROPRIETARY_GPU_DRIVER_API` is removed. The GPU driver APIs are now enabled by default.
* The option was introduced to reduce the license concerns. Since all non MIT proprietary code has been rewritten manually from scratch, it is no longer necessary.
* See for detail
* Option `--logo-separate true` is changed to `--logo-position top` for better readability
* Builtin ascii logos can be positioned on the right side now with`--logo-position right`
Features:
* Add support for `--gpu-detection-method opencl` which uses OpenCL to detect GPUs.
* Support detecting CPU cache size by using SMBIOS as fallback (CPUCache)
* Support GPU detection (SunOS)
* Support GPU type detection with AMD GPU driver (GPU, Windows)
* Add fast path of version and font detection for kitty (Terminal / TerminalFont)
* Make sure `stdin` and `stdout` are TTYs when querying terminal
* So modules like `TerminalSize` should work when `stdin` or `stdout` is redirected
* Support argument truncation in `---format` (#1043)
* See `fastfetch --help format` for detail
* Improve Qt theme detection (#1047, Theme, Linux)
* Add new JSON config option `general.preRun`, which is executed before fastfetch prints output.
* It can be used to generate a temp logo file. For example
```jsonc
{
"general": {
"preRun": "kitten icat --align=left /path/to/image > /tmp/logo.kitty"
},
"logo": {
"source": "/tmp/logo.kitty",
"type": "raw"
}
}
```
Bugfixes:
* Fix invalid path (#1031, LM, Linux)
* Fix VMEM detection for Nvidia GPU (requires `--gpu-driver-specific`) (GPU)
* Fix AMD `--gpu-driver-specific` for AMD cards (#1032, GPU, Windows)
* Use Coordinated Universal Time rather than timezone-varying local date (#1046)
Logo:
* Fix colors of Asahi Linux
# 2.16.0
This release added basic support for SunOS (Solaris, illumos). The binaries provided in the release lack a few useful features (such as Display detection). People who use SunOS should consider building fastfetch themselves.
Changes:
* Fastfetch now prefers `/etc/os-release` over `/etc/lsb-release` when detecting distro info.
* This may break some distros (notably some debian based distros). File a bug with the content of `os-release` and `lsb-release` if it breaks your distro.
Features:
* Support Media detection in Windows (Media / Player, Windows)
* Requires Windows 10 and later
* Add new option `--users-myself-only` to display current login user only (Users)
* Add code name of macOS Sequoia (OS, macOS)
* Add new module `DNS` to show active DNS servers (DNS)
* Add new option `--loadavg-compact`. Defaults to true (Loadavg)
* Use `--loadavg-compact false` to display load averages in different lines
* Detect MTU size (LocalIP)
* Support version detection of pluma, which is the default editor of OpenIndiana (Editor)
* Print used OGL library, eg EGL, GLX or OSMesa (OpenGL)
Bugfixes:
* Report error if cache size is unavailable (CPUCache, Android)
* Trim white spaces in device name (Sound, Linux, #1005)
* Fix `display.bar.border{Left,Right}` doesn't work in JSON config files (Config)
* Fix invalid call to `realpath(3)` (Platform, Linux)
* Fix result calculation (CPUUsage, FreeBSD)
Logos:
* Add Mauna
* Add Tuxdeo
* Add Manjaro ARM
* Add RedOS
* Add Arch3
# 2.15.0
Changes:
* `--bar-border ` has been changed to `--bar-border-left ` and `--bar-border-right `, which are used for customizing the style of bar border.
* `--bar-border-left '' --bar-border-right ''` can be used to disable the border
Features:
* Add ability to skip installing license with INSTALL_LICENSE option (CMake)
* Make it possible to shorten the theme and icons output (Theme / Icons)
* Support `-l '?'` to show a question mark
* Add new module `CPUCache` to display CPU cache sizes (CPUCache)
* In `---format`, `{#keys}` and `{#title}` can be used to reference the color of keys and title
* Improve speed of Guix package detection (Packages, Linux)
* Assume wm plugins are daemon processes to improve performance (WM, macOS)
Bugfixes:
* Remove shebangs from completions (#980)
* Fix while chars not visible in terminal of light theme (Logo)
* Normalize bright colors to fix color display in Apple Terminal (#991, Colors)
* Correctly capitalize GNOME (#997, DE, Linux)
* Fix segfault on system using turkish language (#995, InitSystem, Linux)
* Fix kubuntu detection (#1000, OS, Linux)
* Don't display duplicate entries (OS, Linux)
# 2.14.0
Features:
* Support monochrome bar type (#960)
* Support editor version detection on Windows (Editor, Windows)
* Apply default color palettes in `--file` and `--data` (Logo)
* Print all presets in `--list-presets` for better Windows support (Windows)
* Support for guix package manager detection (Packages, Linux)
* Support named variable placeholders in custom module formattion string (#796)
* `--title-format '{user-name-colored}{at-symbol-colored}{host-name-colored}'` is now equivalent to `--title-format '{6}{7}{8}'`
* Support named color placeholders in custom module formattion string
* `---format '{#red}'` is now equivalent to `---format '{#31}'`
* `'{#red}'` or `'{#31}'` is preferred over `\u001b[31m` because is more readable and `--pipe` aware (will be ignored in pipe mode)
* Supported in `Custom` module too
* See `fastfetch -h format` for detail
* Add new module `InitSystem`, which detects the name of init system
* i.e. process name of pid1. `init`, `systemd`, etc
* Add option `--color-separator` to set the color of key-value separators
* Support Guix package manager count (#792, Packages, Linux)
* Improve python based shell detection (#977, Shell, macOS)
* Print error reason when vulkan init fails (Vulkan)
Bugfixes:
* Don't detect `.conf` files in `--list-config-paths`
* Don't try to detect terminals in MSYS shell with process backtracing (Windows)
* Fix `outputColor` doesn't work if module keys are disabled
Logos:
* Add Cereus Linux
* Re-add special handling of Loc-OS
# 2.13.2
Another hotfix release :(
Bugfixes:
* Remove DRM driver version detection feature, which caused a performance regression for nouveau drivers (#956, Display, Linux)
* Fix compatibility for old python versions. Regression of `2.13.0`
* Don't use `*-unknown` as display name for Wayland protocol (Display, Linux)
Features:
* Add new module `Editor` which prints information of the default editor, i.e. $VISUAL or $EDITOR (#430, Editor)
Logos:
* Added CuerdOS
* Remove special handling of Loc-OS
# 2.13.1
Fix a regression introduced in v2.13.0
Bugfixes:
* Fix CPU frequency not displayed if `bios_limit` is not available (CPU, Linux)
Features:
* Add `--cpu-show-pe-core-count` to detect and display core count for performance / efficiency cores (CPU, FreeBSD)
# 2.13.0
Changes:
* Option `--gpu-force-vulkan ` has been changed to `--gpu-detection-method `
* Use `--gpu-detection-method vulkan` to get the old behavior
* See `fastfetch -h gpu-detection-method` for detail
* In Linux, BIOS limited CPU frequency is printed by default to match the behavior of neofetch (CPU, Linux, #947)
Features:
* Add new module `Bootmgr` which prints information of stage 2 bootloader (grub, system-boot, etc)
* Requires root permission to work on Windows and FreeBSD
* Requires booting in UEFI mode
* Add package manager lpkg and lpkg-build support (Packages, Linux)
* Improve macOS 10.13 compatibility (macOS)
* Detect core count for performance / efficiency cores (CPU)
* Test it with `fastfetch -s cpu --cpu-format '{9}'`
* Support min / max frequency and physical core count detection in FreeBSD, if kernel supports it (CPU, FreeBSD)
* Detect DRM driver version if DRM detection method is used (GPU, Linux)
Bugfixes:
* Don't detect `clifm` and `valgrind` as a terminal (Terminal, Linux)
* Improve stability (PhysicalMemory, FreeBSD)
* Fix bssid & status detection (Wifi, FreeBSD)
* Ensure createTime is correctly initialized (Disk, FreeBSD / macOS)
* Fix `--cpu-freq-ndigits` not working if `--cpu-format` is used
* Fix `nix-user` package count detection (Packages, Linux)
* Fix some memory leaks
Logos:
* Fix Manjaro logo not displayed
* Add SpoinkOS
* Add Loc-OS
* Add Furreto Linux
* Fix TorizonCore logo colors
* Fix KDE neon logo not displayed
# 2.12.0
Changes:
* The long deprecated flag based config files are removed.
* They can still be used with `xargs fastfetch < /path/to/config.conf`
* `--gen-config` can be used to migrate them to json based config files
* The long deprecated options `--set` and `--set-keyless` are removed.
* `Kernel` module now prints kernel name by default
Features:
* Support `st` terminal font detection for font configuration compiled in `st` binary (TerminalFont, Linux)
* Add option `--color-output` to change output color of all modules except `Title`, `Separator`
* `display.color.output` in JSONC config file
* Add option `---output-color` to change output color of one specified module, which overrides the global option `--color-output`
* Add option `--publicip-ipv6` to print IPv6 address (PublicIP)
* Add new module `Loadavg` to print load averages (Loadavg)
* Add new module `PhysicalMemory` to print information of physical memory devices (PhysicalMemory)
* Requires root permission to work on Linux and FreeBSD
* Support specifying `--logo-width` only for `--kitty-direct` and `--iterm` (Logo)
* Add option `--localip-show-all-ips` to show all IPs assigned to the same interface (LocalIP)
* Default to `false`
* Improve compatibility with `(*term)` (#909, Terminal, macOS)
* Support GPU core count and frequency detection for Asahi Linux (GPU, Linux)
Bugfixes:
* Rename option `--temperature-unit` to `--temp-unit` as documented in help messages
* Fix alternate logo doesn't work with `{ "type": "builtin" }` (#914, Logo)
Logos:
* Fix DahliaOS detection
* Add openSUSE Slowroll
* Add macOS3
* Add Quirinux
# 2.11.5
Bugfix:
* Fix logo printing for OpenMandriva (#896)
* Remove `--os-file` in help messages
# 2.11.4
Changes:
* Fastfetch will print a colorless ascii logo in `--pipe` mode for better `lolcat` compatibility. `fastfetch | lolcat` should work and no `--pipe false` needed.
* Previously the logo would be disabled in `--pipe` mode.
* Use `--pipe -l none` to get the old beheavior
* `--os-file` was removed and CMake option `-DCUSTOM_OS_RELEASE_PATH=/path/to/os-release` was introduced for configuring at compile time by package managers if needed. This option should not used in most cases.
Bugfixes:
* Fix possible out-of-bound memory access (#868)
* Fix Apple Terminal detection (#878, macOS, Terminal)
* Fix deprecation warning for macOS 14.0 hopefully (#860, macOS, Camera)
* Fix memory leaks when passing informative options (#888)
* Fix JSON config `size.ndigits` doesn't work
Features:
* Enable `--pipe` mode if environment variable `$NO_COLOR` is set
* Support Armbian and Proxmox distro detection (OS, Linux)
Logo:
* Add Armbian
# 2.11.3
Hotfix for nix (https://github.com/NixOS/nixpkgs/issues/308849#issuecomment-2093962376)
Features:
* Add cmake option `CUSTOM_AMDGPU_IDS_PATH` for specifying custom path of `amdgpu.ids`
Bugfixes:
* Fix hanging when detecting disconnected network drive (Disk, Windows)
* Ensure line ending is printed when printing image logo errors (Logo)
* Revert image logo limitation change in 2.11.2; allow image logo in SSH session and tmux again (#861, Logo)
* Fix doubled output in custom formation (PhysicalDisk, Windows)
# 2.11.2
Hotfix for Debian 11
Changes:
* Error messages when trying to print image logo will only be printed with `--show-errors`
* When generating JSON output, fastfetch will generate an empty array when no result is detected, instead of an error.
Bugfixes:
* Fix segfault in Debian 11 and some old kernels. Regression introduced in 2.11.0 (#845, GPU, Linux)
* Don't try detecting version of raw `sh` shell (#849, Shell, Linux)
* Trim `\r` on Windows
Features:
* Check xdg state home for nix user packages (#837, Packages, Linux)
* Disable image logos in ssh and tmux sessions (#839)
* Support MX Linux distro detection (#847, OS, Linux)
Logo:
* Add KernelOS
* Fix name of DraugerOS
* Add missing `FF_LOGO_LINE_TYPE_SMALL_BIT` flags
* Add MX2
# 2.11.1
Hotfix for Android
Bugfixes:
* Fix uninitialized variables which can cause crashes (#760 #838, Battery, Android)
* Don't detect hyfetch as shell when used as backend of [hyfetch](https://github.com/hykilpikonna/hyfetch)
* Fix incorrect information in man page (#828)
Features:
* Support sorcery package manager detection (Packages, Linux)
* Make `--custom-format` optional (Custom)
* Make `/` an alias of `C:\` for `--disk-folders` (Disk, Windows)
* Build for Linux armv7
Logo:
* Fix colors of Source Mage logo
# 2.11.0
Changes:
* Default `hideCursor` to false. It doesn't make much difference but makes user's terminal unusable if fastfetch is not exited correctly.
* Linux amd64 binaries are built with Ubuntu 20.04 again (#808)
Bugfixes:
* Fix swap usage detection in x86-32 build (Windows, Swap)
* Fix minimum cmake version support (#810)
* Fix wifi detection on platforms that don't use NetworkManager (#811, Wifi, Linux)
* Fix NixOS wrapped process name (#814, Terminal, Linux)
* Fix GPU type detection for AMD cards (#816, GPU, Linux)
* Silence system deprecation warnings (#822, Camera, macOS)
Features:
* Add basic support DE detection support for UKUI (DE, Linux)
* Support printing total number of nix / flatpak / brew packages (Packages)
* See `fastfetch -h packages-format` for detail
* Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows)
* This requires Intel Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only.
* Improve performance of nix packages detection (Packages, Linux)
* Make config specified in JSONC overridable by command line flags
* Note this change only make global config overridable; module configs are still not
* Suggest increasing `--processing-timeout` when child process timeouts
* Only detect folders that specified by `--disk-folders`
* Previously `--disk-folders` only omits unmatched disks from output
* This option can be used to improve detection performance by ignoring slow network drives
# 2.10.2
Bugfixes:
* Fix a regression that detect x11 as wayland (#805, WM, Linux)
# 2.10.1
Bugfixes:
* Fix build with `-DENABLE_DBUS=OFF` (Linux)
# 2.10.0
Changes:
* We now always detect max frequency of GPUs for consistent, instead of current frequency
Features:
* Improve display detection for wlroots based WMs. Fastfetch now correctly reports fractional scale factors in hyprland (Display, Linux)
* Improve GPU detection on Linux (GPU, Linux)
* Support GPU memory usage detection for AMD GPUs
* Support GPU frequency detection for Intel GPUs
* Improve performance of GNOME version detection (DE, Linux)
* Improve performance of kitty version detection (Terminal, Linux)
* Detect refresh rate when using `--ds-force-drm sysfs-only` (Display, Linux)
* Add option `--ts-version` to disable terminal and shell version detection. Mainly for benchmarking purposes
* Improve performance of detecting WSL version (Host, Linux)
Bugfixes:
* Correctly detect `/bin/sh` as current shell if it's used as default shell (#798, Shell, Linux)
* Work around an issue which CPU module reports incorrect CPU frequency that is too high (#800, CPU, Linux)
* Don't print ANSI escape codes in `--pipe` mode
# 2.9.2
Changes:
* To make use of the newly introduced `yyjson` flag `YYJSON_WRITE_NEWLINE_AT_END`, fastfetch now requires `yyjson` 0.9.0 or later
Features:
* Always add a final new-line when generating JSON output
* Detect partition create time, which can be used as OS installation time (Disk)
* Print time string when generating JSON result instead of UNIX epoch time number, which is more human-readable
Bugfixes:
* Fix a memory leak
* Better portable mode detection of Windows Terminal (TerminalFont, Windows)
* Fix parsing of option `--packages-disabled` (Packages)
* Don't use command `time` as a shell (Shell)
Logos:
* Add openSUSE MicroOS
* Fix color of AOSC OS
# 2.9.1
Features:
* Support weston-terminal (missed commit in v2.9.0) (TerminalFont, Linux)
* Support hyprcursor detection (#776, Cursor, Linux)
Bugfixes:
* Fix `fastfetch --gen-config` raises SIGSEGV when `~/.config/fastfetch` doesn't exist. Regression of `2.9.0` (#778)
# 2.9.0
Features:
* Support Lxterminal version detection (Terminal, Linux)
* Support weston-terminal version detection (Terminal, Linux)
* Support `am` package manager detection (#771, Packages, Linux)
* Support network prefix length detection for IPv6 (LocalIP)
* Display all IPs when multiple IPs are assigned to the same interface (LocalIP)
* Add option `--localip-show-prefix-len` to show network prefix length for both IPv4 and IPv6. Defaults to `true` (LocalIP)
Bugfixes:
* Fix network prefix length detection when the value is greater than 24 (#773, LocalIP, Linux)
* For xfce4-terminal, use system mono font if no config file is found (TerminalFont, Linux)
# 2.8.10
Bugfixes:
* Don't display 0.00 GHz (CPU, FreeBSD)
* Don't detect manufactor of Qualcomm as ARM (CPU, Android)
* Ignore `chezmoi` (Terminal, Linux)
* Trim trailing possible whitespaces (PublicIP)
* Fix detection compatibility for KDE 6 (Font, Linux)
* Always use Metal API to detect vmem size (GPU, macOS)
Features:
* Improve stability; print more useful error message; avoid misuse (PublicIP / Weather)
* Use MS-DOS device name as mountFrom result, instead of useless GUID volume name (Windows, Disk)
* Some adjustments to Terminal detection (Terminal, Windows)
* Don't pretty print CMD
* Print conhost as Windows Console
* Don't detect `wininit` as Terminal
Logo:
* Fix color of Arco Linux
# 2.8.9
Bugfixes:
* Don't detect `SessionLeader` as terminal, actually (Terminal, Linux)
* Fix blurry chafa result when specifying both width and height (#757, Logo)
Features:
* Support new MacBook Air (Host, macOS)
* Distinguish min frequency and base frequency (CPU)
Logo:
* Fix proxmox
# 2.8.8
Bugfixes:
* Fix old fish version compatibility (#744)
* Fix truncated texts in `--help format` (#745)
* Fix old vulkan-header and libdrm library compatibility (#748, Linux)
* Fix possible segfaults in `--help *-format` (#749)
* Fix invalid resolution detection when using libdrm (Linux, Display)
* Fix segfault when `/sys/devices/system/cpu/cpufreq/` doesn't exist (#750, CPU, Linux)
* Don't detect `SessionLeader` as terminal (Terminal, Linux)
* Fix detection of client IP (Users, Linux)
# 2.8.7
Bugfixes:
* Fix max CPU frequency detection for some cases (CPU, Linux)
* Fix some memory leaks
* Fix ddcutil 2.1 compatibility (Brightness, Linux)
* Workaround `permission denied` error when reading `/proc/uptime` (Uptime, Android)
Features:
* Support zellij version detection (Linux, Terminal)
Logo:
* Fix PostMarketOS
# 2.8.6
Changes:
* Due to newly introduced configs, JSONC option `{ "temperatureUnit": "C" }` has been changed to `{ "temp": { "unit": "C" } }`
Bugfixes:
* Fix incorrect GPU name detection for Intel iGPU on Linux (#736, GPU, Linux)
Features:
* Support additional temperature formatting options (#737)
* `{ "temp": { "ndigits": 1 } }`
* `{ "temp": { "color": { "green": "green", "yellow": "yellow", "red": "red" } } }`
* Support specifying custom `pci.ids` path for Linux (GPU, Linux)
* Support warp-linux terminal version & terminal font detection (Terminal, Linux)
# 2.8.5
Bugfixes:
* Fix uninitialized variables
# 2.8.4
Bugfixes:
* Fix segfault if we fail to find `Vendor ID` in `lscpu` (#718, CPU, Linux)
* Fix multi-device bcachefs filesystem compatibility (#731, Disk, Linux)
Features:
* Support portable Windows Terminal settings (#720, Terminal, Windows)
* Support `--color-block-width` and `--color-block-range` (#721, Colors)
* Support `--diskio-detect-total` to show total bytes read/written (DiskIO)
* Support `--netio-detect-total` to show total bytes received/sent (NetIO)
* Support `--packages-disabled` to disable specified package manager (#729, Packages)
* Support `--display-order` to sort multiple displays in a specific order (Display)
* Support `--display-compact-type original-with-refresh-rate` to show refresh rates in compact (oneline) mode (Display)
# 2.8.3
Bugfixes:
* Fix GPU name detection for AMD graphic cards (GPU, Linux / FreeBSD)
# 2.8.2
Changes:
* The linux binaries are now built with glibc 2.35, which means they no longer support Debian 11 and Ubuntu 20.04. Users using these distros may download the artifacts `fastfetch-linux-old` from GitHub Actions.
Features:
* Rewrite GPU module, drop libpci dependency (GPU, Linux)
* Detect marketing name of Apple Silicon CPUs for asahi linux (CPU, Linux)
* Add new module `Camera`, which prints the name and resolution of connected cameras
Bugfixes:
* Fix compatibility with packages installed by flatpak (Terminal, Linux)
* Don't show an empty battery if no battery is detected (macOS, Battery)
* Don't show `not connected` if no power adapter is found (macOS / Linux, PowerAdapter)
* Make format of battery status be consistent with other platforms (Linux, Battery)
Logo:
* Print Asahi logo in asahi linux (Logo, Linux)
* Add Asahi2, z/OS, Tatra, PikaOS
# 2.7.1
Features:
* Config presets in app folder now work with symlinks
Bugfixes:
* Fix a possible segfault when detecting terminal (Terminal, Linux)
# 2.7.0
Features:
* Add new module `TerminalTheme`, which prints the foreground and background color of the current terminal window. Currently doesn't work on Windows.
* Allow command substitution when expanding paths. For example, now it's possible to use `"source": "$(ls ~/path/to/images/*.png | shuf -n 1)"` in JSONC config file to randomly choose an image to display. (#698)
* Use native methods instead of pciutils to detect GPUs in FreeBSD. (GPU, FreeBSD)
Bugfixes:
* Fix text formatting (Wifi, Linux)
* Fix terminal detection in some cases (Terminal)
* Remove trailing `\0` in JSON results (FreeBSD)
* Fix uninitialized variables (GPU, Linux)
* Fix a possible segfault (OpenCL)
Logo:
* Add ASCII logos for fedora immutable variants (#700)
# 2.6.3
Bugfixes:
* Fix module not working (Bluetooth)
# 2.6.2
Bugfixes:
* Fix building for GCC in Windows (Windows)
# 2.6.1
Features:
* Improve xonsh shell detection (Shell)
* Support colored percentage values (Bluetooth / Gamepad / Sound)
* Add `---percent-[green|yellow]` options to specify threshold of percentage colors
* eg. `--disk-percent-green 20 --disk-percent-yellow 50` will show green if disk usage is less than 20%, yellow if disk usage is less then 50%, and red otherwise.
* Add `--percent-color-[green|yellow|red]` options to specify color of different percent value states.
* eg. `--percent-color-green blue` will show blue color if percent value falls in green state.
* Improve Intel macbook support (macOS)
Bugfixes:
* Fix segfault in CPU module when running in aarch64 machine without `lscpu` installed (CPU, Linux)
* Don't use `login` as terminal process (Terminal, Linux)
* Silence warnings when building in 32bit machines.
* Create sub folders when writing config file (#690)
* Improve user specific locale detection; fix locale detection in Windows 7 (Locale)
* Fix GPU type detection (GPU, macOS)
# 2.6.0
Changes:
* Remove support of option `--battery-dir`. We detect a lot of things in `/sys/class/*` and only module `Battery` supports specifying a custom directory for some reason, which is weird.
* Remove `--chassis-use-wmi` which is no longer used.
Features:
* Add `ENABLE_PROPRIETARY_GPU_DRIVER_API` cmake option to disable using of proprietary GPU driver APIs (GPU)
* Support wallpaper detection for macOS Sonoma (Wallpaper, macOS)
* Support power adapter detection for Asahi Linux (PowerAdapter, Linux)
* Support battery serial number and manufacturer date detection (Battery)
* Support host serial number and UUID detection (Host)
* Support battery level detection for gamepads where possible (Gamepad)
* Support maximum CPU clock detection. Previously base clock was printed (CPU, Windows)
* Support manufacture date and serial number detection for physical monitors (Monitor)
* Support ash (default shell of BusyBox) version detection (Shell, Linux)
* Sound module in FreeBSD now uses native `ioctl`s. Pulseaudio dependency is no longer used.
* Locale module in Windows now prints the same format as in Linux and other posix systems.
Bugfixes:
* Fix overall memory leaks (macOS)
* Remove trailing `\0` in JSON results (FreeBSD)
* Fix physical monitor detection with Nvidia drivers (Monitor, Linux)
* Don't print llvmpipe in vulkan module (Vulkan)
* Fix system yyjson usage in `fastfetch.c`. Previously embedded `3rdparty/yyjson/yyjson.h` was used in `fastfetch.c` even if `ENABLE_SYSTEM_YYJSON` was set (CMake)
* Fix locale module printing unexpected results in specific environments (Locale)
* Fix battery temperature detection in Windows. Note only smart batteries report temperatures but few laptops uses smart battery (Battery, Windows)
* Print device name if no backlight name is available, so we don't print empty parentheses (Brightness, FreeBSD)
# 2.5.0
Changes:
* `--gpu-use-nvml` has been renamed to `--gpu-driver-specific` due to using of `IGCL` and `AGS`
* We now detect external partitions more conservatively in Linux. USB partitions will not be detected as external always ( eg. The Linux kernel itself is installed in a USB drive )
Features:
* Support more authentication type detection for macOS Sonoma (Wifi, macOS)
* Default preset names to `.jsonc`. For example, `fastfetch -c all` will load `presets/all.jsonc` (#666)
* Use Intel Graphics Control Library (IGCL) to detect more GPU information. Windows only (GPU, Windows)
* Improve support of Asahi Linux (Brightness / CPU / GPU / Disk, Linux)
* Support more properties of physical disks (PhysicalDisk)
* Support SSD temperature detection with `--physicaldisk-temp` (PhysicalDisk)
* Support partition label detection (Disk, FreeBSD)
* Support platform specific graphic API version detection (GPU, macOS / Windows)
Bugfixes:
* Fix Windows partition detection for WSL2 (Linux, Disk)
* Fix Btrfs subvolumes being detected as external partitions some times (Linux, Disk)
* Fix battery cycle counts in some places (Battery)
* Fix CodeWhisperer compatibility (#676, Terminal, macOS)
# 2.4.0
**We are deprecating flags based config files (will be removed in v3.0.0). We suggest you migrate to json based config files.** One may use `-c /path/to/config.conf --gen-config` to migrate existing flag based config files.
Changes:
* All flag based presets are removed
Features:
* Improve performance of detecting rpm and pkg package count (Packages, Linux / FreeBSD)
* Support Apple M3X temperature detection (CPU / GPU, macOS)
* `--ds-force-drm` support a new option `sysfs-only`
* Improve xfce4 version detection
* Detect WM and DE by enumerating running processes (WM / DE, FreeBSD)
* Add a new module `Physical Disk`, which detects product name, full size, serial number and so on.
Bugfixes:
* Fix crashes sometimes when `--logo-padding-top` is not set (Logo)
* Fix memory usage counting algorithm (Memory, macOS)
* Fix the behavior of `--no-buffer` in Windows
* Fix possible segfault in some devices (Display, Linux)
* Fix segfaults on first use of new images with Sixel flag (Image)
Logo:
* Remove unnecessary escaping for Adelie logo
* Add EshanizedOS
# 2.3.4
Bugfixes:
* Fix `--help` doesn't work when built without python
Features:
* Use `MemAvailable` if available (Memory, Linux)
* Improve performance of detecting dpkg package count (Packages, Linux)
# 2.3.3
Bugfixes:
* Fix `--help` doesn't work in Windows and some other platforms
# 2.3.2
Bugfixes:
* Fix fish completion script, and install the script correctly
Logo:
* Fix Xray-OS logo name
# 2.3.1
Bugfixes:
* Fix man page install location
# 2.3.0
**We are deprecating flags based config files (will be removed in v3.0.0). We suggest you migrate to json based config files.**
Config related changes:
* The deprecated flag `--gen-config conf` is removed
* Flag `--gen-config` now does the same thing as `--migrate-config`, which can be used as config migration and default config file generation. Flag `--migrate-config` is removed
* Fastfetch now searches for config files in the order of `fastfetch --list-config-paths`, and won't load other config if one is found.
* The undocumented flag `--load-user-config` is removed. As an alternative, `--config none` can be used to disable loading config files.
* `--config` (previously named `--load-config`) is now supported for command line arguments only. If specified, other config files won't be loaded, which works like other programs.
* Config files will always be loaded before other command line flags being parsed. That is to say, command line flags will always override options defined in config files.
* the value of GPUType `integrated` contained a typo and was fixed. Existing config files may need to be updated.
Features:
* Support Oils and elvish shell version detection (Shell)
* Support Windows Server Core (Windows)
* Better ddcutil 2.x compatibility (Brightness, Linux)
* Add completion support for fish (natively) and nushell (via [carapace-bin](https://github.com/rsteube/carapace-bin))
* Support nix in macOS (Packages, macOS)
* Print module description for `--list-modules`
* Support `alacritty.toml` (TerminalFont)
* Support board detection on macOS. It simplily prints machine model identifier as for now (Board, macOS)
* Add general method to query product name (Host, macOS)
* Use `libdrm` as a better fall back for detecting displays, which correctly detects current mode; supports refresh rate detection and maybe also faster than using `/sys/class/drm` (Display, Linux)
* Support physical disk size detection (DiskIO)
* Support physical disk name and type detection (DiskIO, FreeBSD)
Bugfixes:
* End `va_list` before returning (@VoltrexKeyva)
* Don't use background color when printing blocks (Color)
* Fix lots of typos
* Fix compatibility with Linux containers (Linux)
* Don't report disabled monitors when using DRM (Linux)
* Fix bad performance in some cases when using X11 (Display, Linux)
* Fix some memory leaks
* Fix used swap space detection (Swap, FreeBSD)
* Don't leak fds to child processes (Linux)
* Fix possible issues when reading procfs (Linux, @apocelipes)
Logos:
* Add Adelie, Ironclad
* Update parch
# 2.2.3
Features:
* Update the latest mac models (Host, macOS)
Bugfixes:
* Fix local ips detection on Android. Regression from `2.0.0` (LocalIP, Android)
* Fix terminal detection on NixOS (Terminal)
# 2.2.2
Changes:
* `--percent-type` now defaults to 9 (colored percentage numbers)
* `fastfetch` now prints LocalIp module by default
Features:
* LocalIP module now prints netmask in CIDR format for IPv4 (LocalIP)
* Bios module now detects system firmware type (Bios)
* Improve detection of `Battery`
* Detect cycle count on supported platforms
* Detect temperature on Linux when supported
* Status detection on macOS has been adjusted to be consistent with other platforms
* Linux binaries are built with imagemagick7 support
Bugfixes:
* Fix uninitialized variables (#609)
* Fix spelling of `--preserve-aspect-ratio` (#614)
Logos:
* Update NixOS_small
# 2.2.1
Hotfix release for #606
Bugfixes:
* Fix broken presets due to the breaking changes introduced in 2.2.0
Features:
* Pretty print `fastfetch --help`
# 2.2.0
This release introduces a new option `--migrate-config`, which migrates old flag based config file to new JSONC format
Changes:
* `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration.
* Display keys `percent*` and `size*` in JSON config are restructured. e.g. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }`
* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version)
* Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version)
* The global flag `--allow-slow-operations` is split into some explicit flags in different modules
* `--packages-winget`: control whether `winget` packages count should be detected. Note it's a very slow operation, please enable it with caution.
* `--chassis-use-wmi`: control whether `WMI` query should be used to detect chassis type, which detects more information, but slower. This flag only affects `--chassis-format` and `--format json`.
* `--battery-use-setup-api`: control whether `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower.
* `--wm-detect-plugin`: control whether WM plugins should be detected. Note it's implemented with global processes enumeration and can report false results.
* `--de-slow-version-detection`: control DE version should be detected with slow operations. It's usually not necessary and only provided as a backup.
* `--localip-default-route-only` and `--netio-default-route-only` defaults to true to avoid large number of results
Features:
* Quirks for MIPS platforms (CPU, Linux)
* Use devicetree path for OBP hosts (Host, Linux)
* Detect `tmux: server` as tmux (Terminal, Linux)
* Support urxvt version detection (Terminal, Linux)
* Support st version detection (Terminal, Linux)
* Support st terminal font detection (TerminalFont, Linux)
* Support xfce4-terminal 1.1.0+ terminal font detection (TerminalFont, Linux)
* Add option `--migrate-config `
* Support Nvidia GPU temp and cuda core count detection via nvml. Use `--gpu-use-nvml` to enable it (GPU)
* Try supporting Wifi authentication type detection in macOS Sonoma. Please file a feature request if you get `to be supported (num)` with result of `/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep auth` (Wifi, macOS)
Bugfixes:
* Better GPU memory and type detection (GPU, Windows)
* Don't print display type twice (Display)
* Detect BSSID instead of Wifi MAC address to align with other platforms (Wifi, macOS)
* Remove support of used GPU memory detection, which is not reliable and only supported with `--gpu-force-vulkan`. (GPU)
* Fix flag `--brightness-ddcci-sleep` (Brightness, Linux)
* Fix hanging if a child process prints to both stdout and stderr (Linux)
Logos:
* Add Black Mesa
* Add cycledream
* Add Evolinx
* Add azos
* Add Interix
# 2.1.2
Bugfixes:
* Fix icon detection on Windows. It shows enabled system icons in desktop (`This PC`, `Recycle Bin`, etc) (Icon, Windows)
* Fix compatibility with ddcutil 2.0 (Brightness, Linux)
* Fix a compile warning (CPUUsage, FreeBSD)
# 2.1.1
Features:
* Support opkg (Packages, Linux)
* Support GNOME Console terminal version and font detection (Terminal, Linux)
* Add `--cpu-freq-ndigits` to set number of digits for CPU frequency (CPU)
* New module to detect physical disk I/O usage (DiskIO)
* Add `--cpuusage-separate` to display CPU usage per CPU logical core
* Add `--brightness-ddcci-sleep` to set the sleep times (in ms) when sending DDC/CI requests (Brightness, #580)
Bugfixes:
* Fix possible crashes on Windows 7 (Disk, Windows)
* Fix possible crashes caused by uninitialized strings (Users, Windows)
* Improve support of `--help *-format` and several bugs are found and fixed
* Don't incorrectly print `No active sound devices found` when using a non-controllable sound device (Sound, macOS)
* Fix implementation processes counting (Processes, Linux)
* Work around a issue that SSID cannot be detected on macOS Sonoma (Wifi, macOS)
Logo:
* Add Chimera Linux
* Add EndeavourSmall
* Add Xenia
* Add MainsailOS
* Fix phyOS
# 2.1.0
This release introduces a new output format: JSON result
Changes:
* Users module detects and prints user login time by default. Specifying `--users-compact` to disable it
* Fastfetch now requires yyjson 0.8.0 or later, which is embedded in fastfetch source tree. If you build fastfetch with `-DENABLE_SYSTEM_YYJSON` cmake option, you must upgrade your yyjson package
* Reduced information supported by `--terminal-format`, `--shell-format`
* Some config presets (`devinfo` and `verbose`) are obsolete and removed. They are barely maintained and can be replaced with `--format json` now.
* Custom strings in `--module-key` and `--module-format` are no longer trimmed.
* `/boot` is hidden by default (FreeBSD, Disk)
Features:
* Add `--format json`, which prints system information as JSON format
* Add fast path for xfce4 version detection (DE, FreeBSD)
* Support contour terminal version and font detection (Terminal / TerminalFont)
* Support `kitty-direct` / `iterm` without specifying logo width / height. Note: in this case, the entre screen will be cleared.
* Support new flag `--logo-separate`. If true, print modules at bottom of the logo
* Support Apple Silicon CPU frequency detection (CPU, macOS)
* Support user login time detection (Users)
* Support winget package manager detection, guarded behind `--allow-slow-operations` (Packages, Windows)
* Print monitor type (built-in or external) (Display)
* Support full GPU detection in WSL (Linux, GPU)
* Add `--module-key " "` as a special case for hiding keys
* Support `--title-format`. See `fastfetch --help title-format` for detail
* Support `--colors-key` (Colors)
* Add `-c` as a shortcut of `--load-config`. Note it was used as the shortcut of `--color` before 2.0.5
* Support Windows Service Pack version detection (Kernel, Windows)
* Support Debian point releases detection (OS, Linux)
* Add new module `NetIO` which prints network throughput (usage) of specified interface. Note this module costs about 1 second to finish.
* Use `lscpu` to detect CPU name for ARM CPUs (CPU, Linux)
Bugfixes:
* Fix fastfetch hanging in specific environment (#561)
* Fix short read when reading from stdin (Logo)
* Fix `poll() timeout or failed` error when image is very large (Logo)
* Fix Termux Monet terminal version detection (Terminal)
* Fix zpool volumes detection (Disk, Linux)
* Fix external volumes detection (Disk, Linux)
* Fix snap package number detection on systems other than Ubuntu (Packages, Linux)
* Fix dpkg / apt package number detection (Packages, Linux)
* Fix bluetooth mac address detection (Bluetooth, Windows)
Logo:
* Add Afterglow
* Add Elbrus
* Update EvolutionOS
* Update AOSC OS
* Update Ubuntu_old
* Update Windows 11_small
* Add Amazon Linux
* Add LainOS
* Fix colors of Slackware
# 2.0.5
Bugfixes:
* Fix segfault when using libxrandr (#544, Display, Linux)
* Don't print 0px (#544, Cursor)
Features:
* Add option `--disk-use-available` (#543)
* Add option `--disk-show-readonly`
# 2.0.4
Bugfixes:
* Fix building on 32-bit FreeBSD (Memory, FreeBSD)
* Fix `--file-raw` doesn't work (Logo)
Features:
* Trait `-` as an alias for `/dev/stdin`. Available for `--file`, `--file-raw` and `--raw` (Logo)
# 2.0.3
Bugfixes:
* Fix typo in config parsing for --color-title (#534)
* Fix percent formatting for `--*-format` (#535)
* Fix loading presets for homebrew (macOS)
Features:
* Add option `--percent-ndigits`
* Add command flag `--config` as an alias of `--load-config`
* Windows packages now include presets (Windows)
# 2.0.2
Bugfixes:
* Workaround [a compiler bug of GCC](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282) (Windows)
* Fix presets not detected by file name (#529)
Logo:
* Add Tuxedo OS
# 2.0.1
First stable release of Fastfetch V2
Changes:
* Unescape strings only when parsing `.conf` files
* Previously: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\: *`. Note the backslashes are unescaped twice (once by shell and once by fastfetch).
* Now: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\\: *`
* Remove option shortcut `-c` (alias of `--color`), which is more commonly used as alias of `--config`
* Rename `--recache` to `--logo-recache` (which is used for regenerate image logo cache). Remove option shortcut `-r` (alias of `--recache`).
* Detecting brightness of external displays with DDC/CI is no longer guarded behind `--allow-slow-operations` (Brightness)
Features:
* Add `--key-width` for aligning the left edge of values, supported both for global `--key-width` and specific module `--module-key-width`
* Add `--bar-char-elapsed`, `--bar-char-total`, `--bar-width` and `--bar-border` options
* Add CMake option `ENABLE_SYSTEM_YYJSON`, which allow building fastfetch with system-provided yyjson (for package managers)
* Add new module `Version`, which prints fastfetch version (like `fastfetch --version`)
Bugfixes:
* Fix label detection. Use `--disk-key 'Disk ({2})'` to display it (Disk, Linux)
* Fix some module options were not inited
* Fix terminal version and font detection on NixOS (Terminal, Linux)
# 2.0.0-beta
Fastfetch v2 introduces a new configuration file format: JSON config. Please refer to for details.
Changes:
* Drop the dependency of cJSON. We now use [yyjson](https://ibireme.github.io/yyjson/doc/doxygen/html/index.html) to parse JSON documents.
* Remove `--shell-version` and `--terminal-version`. They are always enabled (Terminal / Shell)
* Remove `--*-error-format`, which seems to be useless
* Remove `--display-detect-name`. Display name is always detected, and will be printed if multiple displays are detected
* Deprecate `--set` and `--set-keyless`; they may be removed in future releases. Use JSON config with Custom module instead
* Remove the special handling of Command module (it can be set once in the triditional `config.conf`). Use JSON config with Command module instead
* Change `--wm-theme-*` to `--wmtheme-*`. Affect `key` and `format` (WMTheme)
* Change `--terminal-font-*` to `--terminalfont-*`. Affect `key` and `format` (TerminalFont)
* Module `Command` uses `/bin/sh` as the default shell on systems other than Windows (Command)
* Fix M2 CPU temperature detection (CPU, macOS)
* Detect monitor name when available, instead of using DRM connector name (Display / Brightness, Linux)
Features:
* FreeBSD support is improved greatly, and actually tested in a physical machine
* Add `--no-buffer` option for easier debugging. CMake option `ENABLE_BUFFER` is removed and always enabled.
* Support `--*-key-color` option to change the key color of specified module
* Support `--colors-symbol` and `--colors-padding-left` (Colors)
* Add LM (Login Manager) module. Currently requires systemd installed (thus Linux only)
* Add `--wmi-timeout` option (Windows)
* Add `--logo-type small` to search for small logos
* Support detecting brightness of external displays with DDC/CI (guard behind `--allow-slow-operations`) (Brightness)
* Add option `--size-ndigits` and `--size-max-prefix` (#494)
* Add option `--processing-timeout` to the timeout when waiting for child processes.
* Public IP module prints the IP location if `--publicip-url` is not set (PublicIP)
* Add option `--localip-default-route-only` (LocalIP)
* Add option `--weather-location` (Weather)
* Support iTerm non-ascii font detection (Terminal, macOS)
* Add option `--title-color-user`, `--title-color-at` and `--title-color-host` (Title)
* Add Exherbo logo and package manager count (Packages, Linux, #503)
* Add module `Terminal Size` which prints the number of terminal width and height in characters and pixels
* Add new option `--temperature-unit`
* Better CPU and Host detection for Android (Android)
* Support yakuake terminal version & font detection (Terminal, Linux)
* Add new option `--bright-color` which can be used to disable the default bright color of keys, title and ASCII logo.
* Add module `Monitor` which prints physical parameters (native resolutions and dimensions) of connected monitors
* Support path with environment variables for `--logo-source` and `--load-config`.
Bugfixes:
* Fix possible hanging (TerminalFont, #493)
* Fix heap-buffer-overflow reading (DisplayServer, Linux)
* Fix false errors when built without libnm support (Wifi, Linux)
* Properly detect CPU on POWER (CPU, Linux)
* Fix compatibility with Fig (Terminal, macOS)
* Fix option `--title-fqdn` doesn't work (Title)
* Fix used spaces calculation (Disk, Linux / BSD / macOS, #508)
* Fix `--brightness-format` (Brightness)
* Fix specifying `--set-keyless` with the same key second time won't override the value set before (#517)
* Fix specifying `--color` second time won't clear the value set before (#517)
Logo:
* Change the special handling of `kitty` protocol with `.png` image file to a new image protocol `kitty-direct`. This is the fastest image protocol because fastfetch doesn't need to pre-encode the image to base64 or something and the image content doesn't need to be transmitted via tty. Note:
1. Although konsole was said to support `kitty` image protocol, it doesn't support `kitty-direct`
2. wezterm support more image formats other than `.png` (tested with `.jpg` and `.webp`)
* Port all logos supported by neo(wo)fetch. Fastfetch now has 350 builtin logos in total.
# 1.12.2
Features:
* Support terminator terminal version detection (Linux, Terminal)
* Support `pkgtool` package manager detection (Linux, Packages)
* Support `Far` shell version detection (Windows, Shell)
Bugfixes:
* Fix ConEmu terminal detection in some special cases (Windows, Terminal, #488)
* Fix incorrect Host on M2 Mac Studio with M2 Max CPU (macOS, Host, #490)
# 1.12.1
Bugfixes:
* Fix compiling error on Apple Slicon (Bios, macOS)
# 1.12.0
This release backports some changes from dev branch, and fixes 2 crashing issues
Features:
* Support KDE / LXQt / MATE / Cinnamon wallpaper detection (Wallpaper, Linux)
* Support QTerminal version & terminal font detection
* Support MATE Terminal version & terminal font detection
* Set `--pipe true` automatically if stdout is not a tty
* Detect new macs released on WWDC 2023 (macOS, Host)
* Count cached memory as free memory (FreeBSD, Memory)
* Support sound detection (FreeBSD, Sound)
Bugfixes:
* Fix DE detection on Windows 8.1 (Windows, DE)
* Fix `--logo-padding-left` doesn't work when `--logo-padding-top` is set (Logo)
* Fix KDE version detection on Fedora (DE)
* Include limits.h when needed (Linux, #472)
* Fix Windows drives detection in WSL (Linux, Disk)
* Fix CPU temp detection (FreeBSD, CPU)
* Fix disk detection (Android, Disk)
* Fix GNOME Terminal version and font detection (FreeBSD, TerminalFont)
* Fix crash on newer wayland desktops (Linux, Display, #477)
* Fix vendor detection for Intel GPU (macOS, GPU)
* Fix possible crashes on Windows Server (Windows, GPU, #484)
Logo:
* Add bsd, freebsd_small, ghostbsd
* Make Windows 11 logo colorable
# 1.11.3
Bugfixes:
* Fix a segfault bug, regression of `1.11.1` (Linux, wmtheme, #467)
# 1.11.2
This release should be the last version of fastfetch 1.x (if no serious bugs found, hopefully)
Features:
* Support display name, type, rotation detection on Wayland (Linux, Display)
* Print more useful display name instead of intel_backlight (Linux, Brightness)
* Icons module supports Windows (Windows, Icons)
* Add Wallpaper module which shows the current wallpaper image path
* Add mac address detection `--localip-show-mac` (LocalIP, #451)
Bugfixes:
* Fix GNOME version detection on Fedora (DE)
* Fix Windows drives detection in WSL (Disk)
Changes:
* In order to make Icons module consistent between different platforms, `--icons-format` no longer supports individual GTK / Qt icon params.
* `--theme-format` no longer supports individual GTK / plasma theme params.
* `--local-ip-*` and `--public-ip-*` have been changed to `--localip-*` and `--publicip-*`
* `--localip-compact-type` is no longer supported. Fastfetch now display IPs as `--localip-compat-type multiline` by default, with `--local-compact true` can be set as an alias of `--localip-compact-type oneline`
* `--localip-v6first` is no longer supported.
# 1.11.1
Features:
* Support xonsh detection (TerminalShell)
* Support Tabby version / terminal font detection (TerminalFont)
Bugfixes:
* Fix name of Pro Controller (Gamepad, Windows)
* Fix compile error with imagemagick enabled (Windows)
* Fix copy-and-paste errors (Gamepad)
* Flatpak: Fix user package count
* Flatpak: Count runtime packages too (#441)
* Fix flatpak package count (#441)
* Don't print white color blocks with `--pipe` (#450)
* Fix iTerm being detected as iTermServer-* sometimes
* Fix sound device volume being incorrectly detected as muted sometimes (Sound)
* Fix memleaks reported by LeakSanitizer (Linux)
* Fix potential memory corruption bug in unicode.c (Windows)
Logo:
* Update Windows 11 ASCII logo to look more visually consistent (#445)
* Add another font color index to arch icon (#446)
* Add SteamOS
* Add macOS small / small2
# 1.11.0
Features:
* Support linuxbrew (Packages, Linux)
* Support foot terminal (#431, Linux)
* Support cursor size detection on Windows (Cursor, Windows)
* Support cursor detection on macOS (Cursor, macOS)
* Support display name, display type and decimal refresh rate detection (Display, macOS / Windows)
* Support `--display-compact-type` to display multiple resolutions in one line (Display)
* Support flatpak-user (Packages, Linux, #436)
* Support `--gpu-force-vulkan` to force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations` (GPU)
Bugfixes:
* Fix date time format
* Fix compiling with musl (Wifi, Linux, #429)
* Don't exit if libpci is failed to init (GPU, Linux, #433)
* Names of most well-known gamepads are correctly printed instead of `Wireless Controller` on Windows
Logo:
* Small update for nobara logo (#435, @regulargvy13)
# 1.10.3
Bugfixes:
* Fix uninitialized variables (GPU, Windows)
* Fix compiling errors (Windows)
Improvements:
* Improve performance (WmTheme amd Font, Windows and macOS)
* Enable nonblocking public-ip / weather detection (Android)
# 1.10.2
Bugfixes:
* Handle `kAudioObjectPropertyElementMain` for macOS **SDK** < 12 (#425, @nandahkrishna)
* Add missing `NULL` for `ffProcessAppendStdOut` (#421)
# 1.10.1
New release for debugging #421
# 1.10.0
Notable Changes:
* With the support of Win32 platform, original Windows 64bit artifact file is renamed to Win64 to avoid possible confusion
Features:
* Bluetooth module
* Sound module
* Gamepad module
* Support colored percentage numbers output (#409)
* Support `--localip-compact-type` option (#408)
* Terminator terminal font detection (@Zerogiven, #415)
* Windows 32bit compatibility
* Support global configuration in MSYS2 environment (Windows)
* Support GPU driver version detection on Windows 11
* Support scaled resolution detection for wayland (Linux)
Bugfixes:
* Fix build with older libnm versions
* Fix a rare case that fails to detect terminal
* Fix Muffin detection (@Zerogiven, #411)
* Fix IPv6 detection (Windows)
* Fix scoop package count detection when scoop is installed in non-default path (Windows, #417)
* Fix UB reported by clang
* Honor $SCOOP when detecting scoop packages (#417)
Other:
* Simplified wmtheme output format (Windows)
* Improved GPU detection performance on Windows 11
* Latest Mac model identifier support (macOS)
# 1.9.1
Bugfixes:
* Fix builds on s390x (@jonathanspw, #402)
* Fix zero refresh rate on some monitors (macOS)
* Fix default formatting of Wifi module
# 1.9.0
Notable Changes:
* fastfetch no longer creates a sample config file silently. Use `--gen-config` to generate one.
* fastfetch now search for user config file in the order of `fastfetch --list-config-paths`
* Unknown disks are hidden by default.
* `Resolution` module is renamed to `Display`. (#393)
Features:
* `--logo-padding-top` option (@CarterLi, #372)
* Raw image file as logo support (@CarterLi)
* Look for config files in `$APPDATA` ([RoamingAppData](https://superuser.com/questions/21458/why-are-there-directories-called-local-locallow-and-roaming-under-users-user#answer-21462)) (Windows)
* Look for config files in `~/Library/Preferences` (macOS)
* Add `--list-config-paths` option which list search paths of config files
* Add `--list-data-paths` option which list search paths for presets and logos
* Add `Brightness` module support
* Add `Battery` module support for FreeBSD
* Add `--disk-show-unknown` option for Disk module
* Add `--disk-show-subvolumes` option for Disk module
* Add `--gpu-hide-integrated` option (#379)
* Add `--gpu-hide-discrete` option (#379)
* Detect terminal version when available
* Support `WezTerm` terminal font detection (requires [`wezterm` executable](https://wezfurlong.org/wezterm/cli/general.html) being available)
* Add `--shell-version` and `--terminal-version` options to disable shell / terminal version detection
* Enhance `--percent-type` to allow hiding other texts (#387)
* Add Wifi module support for Linux
* Detect scaled resolutions (Windows, macOS)
* Optimise font module printing (Windows)
* Detect pacman package count inside MSYS2 environment (Windows)
* Add Wifi / Battery module support for Android
* Disk name support for Linux
Logos:
* Raspbian (@IamNoRobot, #373)
Bugfixes:
* `--logo-type` now does accept `iterm` too (@CarterLi, #374)
* Fix mintty terminal font detection (Windows)
* Fix bug that line buffering doesn't work properly (Windows)
* Fix rpm package count detection (Linux)
* Fix cpu temp detection (Linux)
Other:
* Fixed a Typo in iterm error message (@jessebot, #376)
* Don't try to load config file in `/etc` (Windows)
# 1.8.2
Bugfixes:
* Fix memleaks Users module (Windows)
* Fix shell detection when installed with scoop (Windows)
* Don't use libcJSON as wlanapi's dll name (Windows)
* Align artifact names to other platforms (Windows)
# 1.8.1
Notable Changes:
* `Song` was used as an alias to `Media` module. It's removed to avoid confusion. All song related flags (`--song-key`, etc) should change to media (`--media-key`, etc). (@CarterLi)
Bugfixes:
* Mountpoint paths on linux get decoded correctly (#364)
* Color parsing once again works (@IanManske, #365)
* Using a custom key with a placeholder for the local ip module now does work correctly if multiple interfaces are present (#368)
# 1.8.0
This release introduces Windows support! Fastfetch now fully support all major desktop OSes (Linux, macOS, Windows and FreeBSD)
Notable Changes:
* Bios / Board / Chassis modules are split against Host module for performance reasons
* Caching is removed. Option `--nocache` is removed accordingly
Features:
* Windows (7 and newer) is officially and fully supported
* FreeBSD support is improved greatly (Bios, Cpu Temp, Cpu Usage, Disk, Host, Processes, Swap, Terminal / Shell, Uptime)
* Adds a new flag `--stat`, which prints time usage for individual modules
* Adds Wifi module which supports Windows and macOS
* Adds data source option for logo printing
* Detects Homebrew Cellar and Cask separately
* Detects WSL version
* Detects disk based on mount point
* Exposes more chafa configs
* Improves performance for Cpu Usage, Public IP, Weather modules
* Improves performance for Kitty image protocol when both image width / height specified
* Improves performance for large file loading
* Improves performance for macOS WM and Host detection
* Improves shell and terminal detection on macOS
* Supports Deepin Terminal terminal font
* Supports GPU detection on Android
* Supports Kitty Terminal terminal font
* Supports bar output for percentage values
* Supports Bios module on macOS
* Supports eopkg package manager detection
* Supports iTerm image logo protocol
* Supports image logo printing on macOS
* Supports tcsh version detection
* Vulkan module on macOS no longer requires vulkan-loader to work
Logos:
* Alpine
* CRUX
* EndeavourOS
* Enso
* Garuda small
* Nobara
* OpenMandriva
* Parabola GNU/Linux-libre
* Rocky
* Rosa
* Solus
* Univalent
* Vanilla OS
Bugfixes:
* Fixes disk size detection on 32bit Linux (#337)
* Fixes cpu freq detection in WSL
* Fixes internal bug of FFstrbuf
* Fixes some memory leaks
* Fixes segfault if 0 is given as argument index
* Lots of code refactors
# 1.7.5
Fixes a crash on linux that could happen when getting zsh version (#285)
# 1.7.4
The last element in the default structure (currently the color blocks) is now printed again (#283)
# 1.7.3
A lot of small improvements for MacOS & BSD platforms.
Features:
* BSD is now officially supported (#228)
* MacPorts package manager support (@SladeGetz, #234)
* Battery support for MacOS (@CarterLi, #235)
* Processes, swap & terminal font support for MacOS(@CarterLi, #237)
* Media support for MacOS (@CarterLi, #242)
* Player support for MacOS (@CarterLi, #245)
* WM theme support for MacOS (@CarterLi, #246)
* CPU usage support for MacOS (@CarterLi, #247)
* Power Adapter module (@CarterLi, #249)
* Windows terminal font for WSL (@CarterLi, #254)
* Temps & Font support for MacOS (@CarterLi, #258)
* Terminal font support for Termux (@CarterLi, #263)
* Weather module (@CarterLi, #266)
Logos
* Crystal linux (@AloneER0, #239)
* FreeBSD (@draumaz, #244)
* New Ubuntu (@AloneER0, #259)
Bugfixes:
* Don't segfault in GPU code on Intel Macs (@CarterLi, #236)
* Don't use hardcoded size units in presets (@dr460nf1r3, #255)
* Don't crash with some format strings (#252)
* --logo none keeps key color now (#264)
# 1.7.2
Fixes the bash completions
# 1.7.1
This release brings a lot of bug fixes and improvements for MacOS. Big thanks to @CarterLi for the help on this!
Features:
* The color of the title and the keys can now be configured individually, using `--color-keys` and `--color-title` respectively. Some distros have different defaults now, similar to neofetch
* Swap module, similar to the Memory module, but for swap. Add `Swap` to your structure to enable it (#225)
Logos:
* Slackware (#227)
Bugfixes:
* Used disk space is now calculated much more accurately
* On Linux, GPU names are no longer truncated, if they are longer than 32 characters (#224)
* On Linux, NVIDIA GPUs once again have a proper name
* On M1 platforms, showing the GPU name no longer crashes the program (#222)
* Brew package count does now work on M1 platforms too
* The Vulkan module now does work on MacOS too
* The OpenGL and OpenCL modules now work on MacOS too (@CarterLi, #226)
* The LocalIp module now works on MacOS too (@CarterLi, #232)
* Detecting custom WMs on MacOS does now work
Other:
* GitHub actions now builds a dmg file for MacOS, as you can see in the release page
# 1.7.0
This release brings support for MacOS!
The basics things are working, but it is far from feature parity with Linux.
I developed this in a VM, so bugs on real hardware are likely.
If you have a Mac and no idea what to do with your free time, i am very happy to accept pull requests / work on issues.
A lot of things were changed under the hood to make this possible, which should bring better performance and stability on all platforms.
Besides that, the following things have changed:
Features:
* The binary prefix used can now be configured, and is used consistently across all modules. Set `--binary-prefix` to `iec` (default), `si` or `jedec`.
* AMD GPUs now have a much better name, if the file `/usr/share/libdrm/amdgpu.ids` exists. For example my dedicated GPU, which was displayed as `AMD/ATI Radeon RX 5600 OEM/5600 XT / 5700/5700 XT`, is now `AMD Radeon RX 5600M`.
Logos:
* MacOS
* CachyOS small (@sirlucjan, #220)
* MSYS2 (#219)
Bugfixes:
* the `--file` option, which can be used to display the contents of a file as the logo, is now working again.
# 1.6.5
Fixes parsing quoted values in config files
# 1.6.4
Releasing this, so fedora can package fastfetch. Thanks to @jonathanspw for doing that!
Features:
* --set-keyless option (#215)
* Replace `\n`, `\t`, `\e` and `\\` in user provided strings, just like c would do it (#215)
* APK (Alpine Package Keeper) support (@mxkrsv, #216)
Logos:
* Alma Linux (@jonathanspw, #214)
Bugfixes:
* replace deprecated gethostbyname call with getaddrinfo (#217)
# 1.6.3
Fixes installing presets in their own directory (@ceamac, #212)
# 1.6.2
Releasing this, so void linux can package fastfetch.
Logos:
* Rosa linux (#206)
* KISS linux (@draumaz, #207)
* LangitKetujuh (@hervyqa, #208)
Bugfixes:
* Using musl as libc does work now (#210)
* XBPS packages are once again printed (#209)
* configured target dirs are applied to install directories too
* empty XDG_* env vars don't cause a crash anymore
# 1.6.1
Fixes build on android (#205)
# 1.6.0
Features:
* Detect Qt on more DEs than just KDE Plasma. The [Plasma] category was therefore renamed to [Qt]
* Alacritty font detection
* Load `/etc/fastfetch/config.conf` before user config
* Disk: print one decimal point if size < 100GB
* `--title-fqdn` option, to print fully qualified domain name instead of host name in title
Logos:
* updated old NixOS logo
Bugfixes:
* Correctly detect GTK on DEs that store their settings in dconf
* Correctly detect NixOS packages
* Mutter WM detected once again
* Show full NixOS version in OS output
* Don't segfault if an invalid structure is given
* WSL doesn't output GPU anymore, as the name is always meaningless
================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
VERSION 2.60.0
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
)
set(PROJECT_LICENSE "MIT license")
if(DEFINED CMAKE_SYSTEM_PROCESSOR_OVERRIDE) # Used by github actions for i686 build
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR_OVERRIDE} CACHE INTERNAL "")
endif()
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CMAKE_SYSTEM_PROCESSOR "amd64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
endif()
message(STATUS "Build for system processor: ${CMAKE_SYSTEM_PROCESSOR}")
###################
# Target Platform #
###################
if(ANDROID)
set(LINUX FALSE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
set(FreeBSD TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
set(OpenBSD TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "MidnightBSD")
set(FreeBSD TRUE CACHE BOOL "..." FORCE)
set(MidnightBSD TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NetBSD")
set(NetBSD TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
set(FreeBSD TRUE CACHE BOOL "..." FORCE)
set(DragonFly TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
set(SunOS TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
set(Haiku TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
set(GNU TRUE CACHE BOOL "..." FORCE)
elseif(NOT APPLE AND NOT WIN32)
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()
#############################
# Compile time dependencies #
#############################
set(THREADS_PREFER_PTHREAD_FLAG NOT WIN32)
find_package(Threads)
find_package(PkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(WARNING "pkg-config not found, library detection might be limited")
endif()
include(CheckIncludeFile)
#####################
# Configure options #
#####################
include(CMakeDependentOption)
cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku OR GNU" OFF)
cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR GNU" OFF)
cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX OR FreeBSD OR GNU" OFF)
cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR Haiku OR GNU" OFF)
cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX OR GNU" OFF)
cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR ANDROID OR WIN32 OR SunOS OR Haiku OR GNU" OFF)
cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF)
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR WIN32 OR SunOS OR Haiku OR GNU" OFF)
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku OR GNU" OFF)
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR ANDROID OR GNU" OFF)
cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly OR Haiku OR GNU" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
option(ENABLE_ZLIB "Enable zlib" ON)
option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
option(ENABLE_LTO "Enable link-time optimization in release mode if supported" ON)
option(BUILD_FLASHFETCH "Build flashfetch" ON) # Also build the flashfetch binary
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
option(IS_MUSL "Build with musl libc" OFF) # Used by Github Actions
option(INSTALL_LICENSE "Install license into /usr/share/licenses" ON)
option(ENABLE_EMBEDDED_PCIIDS "Embed pci.ids into fastfetch, requires `python`" OFF)
option(ENABLE_EMBEDDED_AMDGPUIDS "Embed amdgpu.ids into fastfetch, requires `python`" OFF)
option(ENABLE_WORDEXP "Enable using of wordexp(3) if available, instead of glob(3)" ON)
option(ENABLE_LIBZFS "Enable libzfs" ON)
if(WIN32 AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
option(ENABLE_WIN81_COMPAT "Enable legacy Windows compatibility (Windows 8.1 and later; Windows 7 unsupported)" ON)
endif()
if(APPLE)
option(ENABLE_APPLE_MEMSIZE_USABLE "Use usable memory size as total memory size in Memory module, to match other systems" OFF)
endif()
set(BINARY_LINK_TYPE_OPTIONS dlopen dynamic static)
set(BINARY_LINK_TYPE dlopen CACHE STRING "How to link fastfetch")
set_property(CACHE BINARY_LINK_TYPE PROPERTY STRINGS ${BINARY_LINK_TYPE_OPTIONS})
if(NOT BINARY_LINK_TYPE IN_LIST BINARY_LINK_TYPE_OPTIONS)
message(FATAL_ERROR "BINARY_LINK_TYPE must be one of ${BINARY_LINK_TYPE_OPTIONS}")
endif()
set(PACKAGE_MANAGERS AM APK BREW CHOCO DPKG EMERGE EOPKG FLATPAK GUIX LINGLONG LPKG LPKGBUILD MACPORTS NIX OPKG PACMAN PACSTALL PALUDIS PISI PKG PKGTOOL RPM SCOOP SNAP SOAR SORCERY WINGET XBPS)
foreach(package_manager ${PACKAGE_MANAGERS})
if(package_manager STREQUAL "WINGET")
option(PACKAGES_DISABLE_${package_manager} "Disable ${package_manager} package manager detection by default" ON)
else()
option(PACKAGES_DISABLE_${package_manager} "Disable ${package_manager} package manager detection by default" OFF)
endif()
endforeach()
if (LINUX)
set(CUSTOM_PCI_IDS_PATH "" CACHE STRING "Custom path to file pci.ids, defaults to `/usr/share/hwdata/pci.ids`")
set(CUSTOM_AMDGPU_IDS_PATH "" CACHE STRING "Custom path to file amdgpu.ids, defaults to `/usr/share/libdrm/amdgpu.ids`")
set(CUSTOM_OS_RELEASE_PATH "" CACHE STRING "Custom path to file os-release, defaults to `/etc/os-release`")
endif()
####################
# Compiler options #
####################
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if(ENABLE_THREADS)
if(CMAKE_USE_WIN32_THREADS_INIT)
message(STATUS "Threads type: Win32 thread")
elseif(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Threads type: pthread")
endif()
else()
message(STATUS "Threads type: disabled")
endif()
set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=return-type -Werror=vla")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion")
if(WIN32 OR Haiku OR ENABLE_DIRECTX_HEADERS)
enable_language(CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
endif()
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--tsaware -Wl,--build-id")
if(ENABLE_WIN81_COMPAT)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,console,--major-os-version,6,--minor-os-version,3")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,console,--major-os-version,10,--minor-os-version,0")
endif()
elseif(APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-arc")
endif()
set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer")
if(ENABLE_ASAN)
message(STATUS "Address sanitizer enabled (DEBUG only)")
set(FASTFETCH_FLAGS_DEBUG "${FASTFETCH_FLAGS_DEBUG} -fsanitize=address")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -fstack-protector-all -fno-delete-null-pointer-checks")
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -rdynamic")
endif()
if(ENABLE_LTO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling LTO")
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
#######################
# Target FS structure #
#######################
if(NOT TARGET_DIR_ROOT)
if(NOT ANDROID)
set(TARGET_DIR_ROOT "")
else()
set(TARGET_DIR_ROOT "/data/data/com.termux/files/usr")
endif()
endif()
if(NOT TARGET_DIR_USR)
if(NOT ANDROID)
set(TARGET_DIR_USR "${TARGET_DIR_ROOT}/usr")
else()
set(TARGET_DIR_USR "${TARGET_DIR_ROOT}")
endif()
endif()
if(NOT TARGET_DIR_HOME)
if(APPLE)
set(TARGET_DIR_HOME "${TARGET_DIR_ROOT}/Users")
elseif(ANDROID)
set(TARGET_DIR_HOME "/data/data/com.termux/files/home")
else()
set(TARGET_DIR_HOME "${TARGET_DIR_ROOT}/home")
endif()
endif()
if(NOT TARGET_DIR_ETC)
set(TARGET_DIR_ETC "${TARGET_DIR_ROOT}/etc")
endif()
message(STATUS "Target dirs: ROOT=\"${TARGET_DIR_ROOT}\" USR=\"${TARGET_DIR_USR}\" HOME=\"${TARGET_DIR_HOME}\" ETC=\"${TARGET_DIR_ETC}\"")
#https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${TARGET_DIR_USR}" CACHE PATH "..." FORCE)
endif()
if(NOT CMAKE_INSTALL_SYSCONFDIR)
set(CMAKE_INSTALL_SYSCONFDIR "${TARGET_DIR_ETC}" CACHE PATH "..." FORCE)
endif()
#################
# Tweak version #
#################
if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_VERSION_GIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "-[0-9]+" PROJECT_VERSION_TWEAK "${PROJECT_VERSION_GIT}")
endif()
if(PROJECT_VERSION_TWEAK)
string(REGEX MATCH "[0-9]+" PROJECT_VERSION_TWEAK_NUM "${PROJECT_VERSION_TWEAK}")
else()
set(PROJECT_VERSION_TWEAK_NUM 0)
endif()
#############
# Text data #
#############
function(fastfetch_encode_c_string STR OUTVAR)
string(REGEX REPLACE "\n$" "" TEMP "${STR}") # Remove trailing newline
string(REPLACE "\\" "\\\\" TEMP "${TEMP}") # Escape backslashes
string(REPLACE "\n" "\\n" TEMP "${TEMP}") # Replace newlines with \n
string(REPLACE "\"" "\\\"" TEMP "${TEMP}") # Replace quotes with \"
set(${OUTVAR} "\"${TEMP}\"" PARENT_SCOPE)
endfunction(fastfetch_encode_c_string)
function(fastfetch_load_text FILENAME OUTVAR)
file(READ "${FILENAME}" TEMP)
fastfetch_encode_c_string("${TEMP}" TEMP)
set(${OUTVAR} "${TEMP}" PARENT_SCOPE)
endfunction(fastfetch_load_text)
find_package(Python)
if(Python_FOUND)
message(STATUS "Minifying 'help.json'")
execute_process(COMMAND ${Python_EXECUTABLE} -c "import json,sys;json.dump(json.load(sys.stdin),sys.stdout,separators=(',',':'))"
INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/src/data/help.json"
OUTPUT_VARIABLE DATATEXT_JSON_HELP)
if(DATATEXT_JSON_HELP STREQUAL "")
message(ERROR "DATATEXT_JSON_HELP is empty, which should not happen!")
endif()
else()
message(WARNING "Python3 is not found, 'help.json' will not be minified")
file(READ "src/data/help.json" DATATEXT_JSON_HELP)
endif()
if(ENABLE_EMBEDDED_PCIIDS AND NOT EXISTS "${PROJECT_BINARY_DIR}/fastfetch_pciids.c.inc")
if(Python_FOUND)
if(NOT EXISTS "${PROJECT_BINARY_DIR}/pci.ids")
message(STATUS "'${PROJECT_BINARY_DIR}/pci.ids' is missing, downloading...")
file(DOWNLOAD "https://pci-ids.ucw.cz/v2.2/pci.ids" "${PROJECT_BINARY_DIR}/pci.ids")
endif()
message(STATUS "Generating 'fastfetch_pciids.c.inc'")
execute_process(COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-pciids.py" "${PROJECT_BINARY_DIR}/pci.ids"
OUTPUT_FILE "${PROJECT_BINARY_DIR}/fastfetch_pciids.c.inc"
RESULT_VARIABLE PYTHON_PCIIDS_RETCODE)
if(NOT PYTHON_PCIIDS_RETCODE EQUAL 0)
file(REMOVE "${PROJECT_BINARY_DIR}/fastfetch_pciids.c.inc")
message(WARNING "Failed to generate 'fastfetch_pciids.c.inc'")
set(ENABLE_EMBEDDED_PCIIDS OFF)
endif()
else()
message(WARNING "Python3 is not found, 'fastfetch_pciids.c.inc' will not be generated")
set(ENABLE_EMBEDDED_PCIIDS OFF)
endif()
endif()
if(ENABLE_EMBEDDED_AMDGPUIDS AND NOT EXISTS "${PROJECT_BINARY_DIR}/fastfetch_amdgpuids.c.inc")
if(Python_FOUND)
if(NOT EXISTS "${PROJECT_BINARY_DIR}/amdgpu.ids")
message(STATUS "'${PROJECT_BINARY_DIR}/amdgpu.ids' is missing, downloading...")
file(DOWNLOAD "https://gitlab.freedesktop.org/mesa/drm/-/raw/main/data/amdgpu.ids" "${PROJECT_BINARY_DIR}/amdgpu.ids")
endif()
message(STATUS "Generating 'fastfetch_amdgpuids.c.inc'")
execute_process(COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-amdgpuids.py" "${PROJECT_BINARY_DIR}/amdgpu.ids"
OUTPUT_FILE "${PROJECT_BINARY_DIR}/fastfetch_amdgpuids.c.inc"
RESULT_VARIABLE PYTHON_AMDGPUIDS_RETCODE)
if(NOT PYTHON_AMDGPUIDS_RETCODE EQUAL 0)
file(REMOVE "${PROJECT_BINARY_DIR}/fastfetch_amdgpuids.c.inc")
message(WARNING "Failed to generate 'fastfetch_amdgpuids.c.inc'")
set(ENABLE_EMBEDDED_AMDGPUIDS OFF)
endif()
else()
message(WARNING "Python3 is not found, 'fastfetch_amdgpuids.c.inc' will not be generated")
set(ENABLE_EMBEDDED_AMDGPUIDS OFF)
endif()
endif()
if(Python_FOUND)
message(STATUS "Generating 'fastfetch.1'")
execute_process(COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-man.py"
OUTPUT_FILE "${PROJECT_BINARY_DIR}/fastfetch.1"
RESULT_VARIABLE PYTHON_MANPAGE_RETCODE)
if(NOT PYTHON_MANPAGE_RETCODE EQUAL 0)
message(FATAL_ERROR "Failed to generate 'fastfetch.1'")
endif()
else()
message(WARNING "Python3 is not found, use basic 'fastfetch.1.in' instead")
string(TIMESTAMP FASTFETCH_BUILD_DATE "%d %B %Y" UTC)
configure_file(doc/fastfetch.1.in fastfetch.1 @ONLY)
endif()
fastfetch_encode_c_string("${DATATEXT_JSON_HELP}" DATATEXT_JSON_HELP)
fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
configure_file(src/fastfetch_config.h.in fastfetch_config.h @ONLY)
configure_file(src/fastfetch_datatext.h.in fastfetch_datatext.h @ONLY)
if(APPLE)
configure_file(src/common/apple/Info.plist.in Info.plist @ONLY)
endif()
####################
# Ascii image data #
####################
file(GLOB LOGO_FILES CONFIGURE_DEPENDS "src/logo/ascii/*.txt")
set(LOGO_BUILTIN_H "#pragma once\n#pragma GCC diagnostic ignored \"-Wtrigraphs\"\n\n")
foreach(file ${LOGO_FILES})
fastfetch_load_text("${file}" content)
get_filename_component(file "${file}" NAME_WE)
string(TOUPPER "${file}" file)
set(LOGO_BUILTIN_H "${LOGO_BUILTIN_H}#define FASTFETCH_DATATEXT_LOGO_${file} ${content}\n")
endforeach()
file(GENERATE OUTPUT logo_builtin.h CONTENT "${LOGO_BUILTIN_H}")
#######################
# libfastfetch target #
#######################
set(LIBFASTFETCH_SRC
src/common/impl/commandoption.c
src/common/impl/duration.c
src/common/impl/font.c
src/common/impl/format.c
src/common/impl/frequency.c
src/common/impl/init.c
src/common/impl/jsonconfig.c
src/common/impl/library.c
src/common/impl/netif.c
src/common/impl/networking_common.c
src/common/impl/option.c
src/common/impl/parsing.c
src/common/impl/percent.c
src/common/impl/printing.c
src/common/impl/properties.c
src/common/impl/settings.c
src/common/impl/size.c
src/common/impl/temps.c
src/common/impl/time.c
src/common/impl/edidHelper.c
src/common/impl/base64.c
src/common/impl/FFlist.c
src/common/impl/FFstrbuf.c
src/common/impl/path.c
src/common/impl/FFPlatform.c
src/common/impl/smbiosHelper.c
src/detection/bluetoothradio/bluetoothradio.c
src/detection/bootmgr/bootmgr.c
src/detection/chassis/chassis.c
src/detection/cpu/cpu.c
src/detection/cpuusage/cpuusage.c
src/detection/command/command.c
src/detection/disk/disk.c
src/detection/diskio/diskio.c
src/detection/displayserver/displayserver.c
src/detection/editor/editor.c
src/detection/font/font.c
src/detection/gpu/gpu.c
src/detection/media/media.c
src/detection/netio/netio.c
src/detection/opencl/opencl.c
src/detection/opengl/opengl_shared.c
src/detection/os/os.c
src/detection/packages/packages.c
src/detection/physicalmemory/physicalmemory.c
src/detection/publicip/publicip.c
src/detection/terminaltheme/terminaltheme.c
src/detection/terminalfont/terminalfont.c
src/detection/terminalshell/terminalshell.c
src/detection/version/version.c
src/detection/vulkan/vulkan.c
src/detection/weather/weather.c
src/detection/zpool/zpool.c
src/logo/builtin.c
src/logo/image/im6.c
src/logo/image/im7.c
src/logo/image/image.c
src/logo/logo.c
src/modules/battery/battery.c
src/modules/bios/bios.c
src/modules/bluetooth/bluetooth.c
src/modules/bluetoothradio/bluetoothradio.c
src/modules/board/board.c
src/modules/bootmgr/bootmgr.c
src/modules/brightness/brightness.c
src/modules/break/break.c
src/modules/btrfs/btrfs.c
src/modules/camera/camera.c
src/modules/chassis/chassis.c
src/modules/colors/colors.c
src/modules/cpu/cpu.c
src/modules/cpucache/cpucache.c
src/modules/cpuusage/cpuusage.c
src/modules/cursor/cursor.c
src/modules/custom/custom.c
src/modules/command/command.c
src/modules/datetime/datetime.c
src/modules/de/de.c
src/modules/disk/disk.c
src/modules/diskio/diskio.c
src/modules/dns/dns.c
src/modules/editor/editor.c
src/modules/font/font.c
src/modules/gpu/gpu.c
src/modules/host/host.c
src/modules/icons/icons.c
src/modules/initsystem/initsystem.c
src/modules/gamepad/gamepad.c
src/modules/kernel/kernel.c
src/modules/keyboard/keyboard.c
src/modules/lm/lm.c
src/modules/loadavg/loadavg.c
src/modules/locale/locale.c
src/modules/localip/localip.c
src/modules/logo/logo.c
src/modules/memory/memory.c
src/modules/monitor/monitor.c
src/modules/netio/netio.c
src/modules/opencl/opencl.c
src/modules/opengl/opengl.c
src/modules/os/os.c
src/modules/packages/packages.c
src/modules/physicaldisk/physicaldisk.c
src/modules/physicalmemory/physicalmemory.c
src/modules/processes/processes.c
src/modules/player/player.c
src/modules/poweradapter/poweradapter.c
src/modules/publicip/publicip.c
src/modules/display/display.c
src/modules/separator/separator.c
src/modules/shell/shell.c
src/modules/sound/sound.c
src/modules/swap/swap.c
src/modules/media/media.c
src/modules/mouse/mouse.c
src/modules/terminal/terminal.c
src/modules/terminaltheme/terminaltheme.c
src/modules/terminalfont/terminalfont.c
src/modules/terminalsize/terminalsize.c
src/modules/theme/theme.c
src/modules/title/title.c
src/modules/tpm/tpm.c
src/modules/uptime/uptime.c
src/modules/users/users.c
src/modules/version/version.c
src/modules/vulkan/vulkan.c
src/modules/wallpaper/wallpaper.c
src/modules/weather/weather.c
src/modules/wifi/wifi.c
src/modules/wm/wm.c
src/modules/wmtheme/wmtheme.c
src/modules/zpool/zpool.c
src/modules/modules.c
src/options/display.c
src/options/logo.c
src/options/general.c
)
if(LINUX)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_linux.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_linux.c
src/detection/battery/battery_linux.c
src/detection/bios/bios_linux.c
src/detection/board/board_linux.c
src/detection/bootmgr/bootmgr_linux.c
src/detection/brightness/brightness_linux.c
src/detection/btrfs/btrfs_linux.c
src/detection/chassis/chassis_linux.c
src/detection/cpu/cpu_linux.c
src/detection/cpucache/cpucache_linux.c
src/detection/cpuusage/cpuusage_linux.c
src/detection/cursor/cursor_linux.c
src/detection/bluetooth/bluetooth_linux.c
src/detection/bluetoothradio/bluetoothradio_linux.c
src/detection/disk/disk_linux.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_linux.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_linux.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/kde-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_linux.c
src/detection/gpu/gpu_drm.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_linux.c
src/detection/host/host_mac.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_linux.c
src/detection/libc/libc_linux.c
src/detection/lm/lm_linux.c
src/detection/loadavg/loadavg_linux.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_linux.c
src/detection/media/media_linux.c
src/detection/memory/memory_linux.c
src/detection/mouse/mouse_linux.c
src/detection/netio/netio_linux.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
src/detection/packages/packages_linux.c
src/detection/packages/packages_nix.c
src/detection/poweradapter/poweradapter_linux.c
src/detection/processes/processes_linux.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_linux.c
src/detection/swap/swap_linux.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_linux.c
src/detection/uptime/uptime_linux.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_linux.c
src/detection/wm/wm_linux.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_linux.c
)
elseif(ANDROID)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_linux.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_linux.c
src/detection/battery/battery_android.c
src/detection/bios/bios_android.c
src/detection/bluetooth/bluetooth_nosupport.c
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/board/board_android.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nosupport.c
src/detection/cpu/cpu_linux.c
src/detection/cpucache/cpucache_linux.c
src/detection/cursor/cursor_linux.c
src/detection/cpuusage/cpuusage_linux.c
src/detection/disk/disk_linux.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_linux.c
src/detection/physicalmemory/physicalmemory_nosupport.c
src/detection/diskio/diskio_linux.c
src/detection/displayserver/displayserver_android.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/gtk_qt/gtk.c
src/detection/gtk_qt/qt.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_android.c
src/detection/host/host_android.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_android.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_linux.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_linux.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_linux.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_android.c
src/detection/packages/packages_linux.c
src/detection/packages/packages_nix.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_linux.c
src/detection/sound/sound_linux.c
src/detection/swap/swap_linux.c
src/detection/terminalfont/terminalfont_android.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_linux.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_android.c
src/detection/wm/wm_linux.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_android.c
)
elseif(FreeBSD)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_bsd.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/sysctl.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_bsd.c
src/detection/battery/battery_bsd.c
src/detection/bios/bios_bsd.c
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/board/board_bsd.c
src/detection/bootmgr/bootmgr_bsd.c
src/detection/brightness/brightness_bsd.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_bsd.c
src/detection/cpu/cpu_bsd.c
src/detection/cpucache/cpucache_shared.c
src/detection/cpuusage/cpuusage_bsd.c
src/detection/cursor/cursor_linux.c
src/detection/disk/disk_bsd.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_bsd.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_bsd.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/kde-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_bsd.c
src/detection/gpu/gpu_drm.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_bsd.c
src/detection/host/host_mac.c
src/detection/lm/lm_linux.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_bsd.c
src/detection/libc/libc_bsd.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_bsd.c
src/detection/media/media_linux.c
src/detection/memory/memory_bsd.c
src/detection/mouse/mouse_bsd.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
src/detection/packages/packages_bsd.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_bsd.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_bsd.c
src/detection/swap/swap_bsd.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_bsd.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wm/wm_linux.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_linux.c
)
if(DragonFly)
list(APPEND LIBFASTFETCH_SRC
src/detection/bluetooth/bluetooth_nosupport.c
src/detection/wifi/wifi_nosupport.c
)
else()
list(APPEND LIBFASTFETCH_SRC
src/detection/bluetooth/bluetooth_bsd.c
src/detection/wifi/wifi_bsd.c
)
endif()
elseif(NetBSD)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_bsd.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/sysctl.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_nbsd.c
src/detection/battery/battery_nbsd.c
src/detection/bios/bios_nbsd.c
src/detection/bluetooth/bluetooth_bsd.c
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/board/board_nbsd.c
src/detection/bootmgr/bootmgr_bsd.c
src/detection/brightness/brightness_nbsd.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nbsd.c
src/detection/cpu/cpu_nbsd.c
src/detection/cpucache/cpucache_shared.c
src/detection/cpuusage/cpuusage_bsd.c
src/detection/cursor/cursor_linux.c
src/detection/disk/disk_bsd.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_nosupport.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_nbsd.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/kde-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_nbsd.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_nbsd.c
src/detection/lm/lm_linux.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_nosupport.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_nbsd.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_nbsd.c
src/detection/packages/packages_nbsd.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_nbsd.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_nbsd.c
src/detection/swap/swap_obsd.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_nbsd.c
src/detection/wm/wm_linux.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_linux.c
)
elseif(OpenBSD)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_bsd.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/sysctl.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/smbiosHelper.c
src/common/impl/kmod_nosupport.c
src/detection/battery/battery_obsd.c
src/detection/bios/bios_windows.c
src/detection/bluetooth/bluetooth_nosupport.c
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_bsd.c
src/detection/brightness/brightness_obsd.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_obsd.c
src/detection/cpucache/cpucache_shared.c
src/detection/cpuusage/cpuusage_bsd.c
src/detection/cursor/cursor_linux.c
src/detection/disk/disk_bsd.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_nosupport.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_obsd.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/kde-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_pci.c
src/detection/gpu/gpu_obsd.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_obsd.c
src/detection/lm/lm_nosupport.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_nosupport.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_obsd.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_obsd.c
src/detection/packages/packages_obsd.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_obsd.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_obsd.c
src/detection/swap/swap_obsd.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_obsd.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_obsd.c
src/detection/wm/wm_linux.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_linux.c
)
elseif(APPLE)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/io_unix.c
src/common/impl/netif_apple.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/sysctl.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_apple.c
src/common/impl/kmod_apple.c
src/common/apple/cf_helpers.c
src/common/apple/osascript.m
src/common/apple/smc_temps.c
src/detection/battery/battery_apple.c
src/detection/bios/bios_apple.c
src/detection/bluetooth/bluetooth_apple.m
src/detection/bluetoothradio/bluetoothradio_apple.m
src/detection/board/board_apple.c
src/detection/bootmgr/bootmgr_apple.c
src/detection/brightness/brightness_apple.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_apple.c
src/detection/cpu/cpu_apple.c
src/detection/cpucache/cpucache_apple.c
src/detection/cpuusage/cpuusage_apple.c
src/detection/cursor/cursor_apple.m
src/detection/disk/disk_bsd.c
src/detection/dns/dns_apple.c
src/detection/physicaldisk/physicaldisk_apple.c
src/detection/physicalmemory/physicalmemory_apple.m
src/detection/diskio/diskio_apple.c
src/detection/displayserver/displayserver_apple.c
src/detection/font/font_apple.m
src/detection/gpu/gpu_apple.c
src/detection/gpu/gpu_apple.m
src/detection/host/host_apple.c
src/detection/host/host_mac.c
src/detection/icons/icons_nosupport.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_apple.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_bsd.c
src/detection/libc/libc_apple.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_apple.c
src/detection/media/media_apple.m
src/detection/memory/memory_apple.c
src/detection/mouse/mouse_apple.c
src/detection/netio/netio_apple.c
src/detection/opengl/opengl_apple.c
src/detection/os/os_apple.m
src/detection/packages/packages_apple.c
src/detection/packages/packages_nix.c
src/detection/poweradapter/poweradapter_apple.c
src/detection/processes/processes_bsd.c
src/detection/sound/sound_apple.c
src/detection/swap/swap_apple.c
src/detection/terminalfont/terminalfont_apple.m
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_apple.c
src/detection/tpm/tpm_apple.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_apple.m
src/detection/wifi/wifi_apple.m
src/detection/wm/wm_apple.m
src/detection/de/de_nosupport.c
src/detection/wmtheme/wmtheme_apple.m
src/detection/camera/camera_apple.m
)
elseif(WIN32)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/io_windows.c
src/common/impl/netif_windows.c
src/common/impl/networking_windows.c
src/common/impl/processing_windows.c
src/common/impl/FFPlatform_windows.c
src/common/impl/binary_windows.c
src/common/impl/debug_windows.c
src/common/impl/kmod_windows.c
src/common/windows/getline.c
src/common/windows/com.cpp
src/common/windows/registry.c
src/common/windows/unicode.c
src/common/windows/wmi.cpp
src/common/windows/variant.cpp
src/common/windows/version.c
src/detection/battery/battery_windows.c
src/detection/bios/bios_windows.c
src/detection/bluetooth/bluetooth_windows.c
src/detection/bluetooth/bluetooth_windows.cpp
src/detection/bluetoothradio/bluetoothradio_windows.c
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_windows.c
src/detection/brightness/brightness_windows.cpp
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_windows.c
src/detection/cpucache/cpucache_windows.c
src/detection/cpuusage/cpuusage_windows.c
src/detection/cursor/cursor_windows.c
src/detection/disk/disk_windows.c
src/detection/physicaldisk/physicaldisk_windows.c
src/detection/diskio/diskio_windows.c
src/detection/displayserver/displayserver_windows.c
src/detection/dns/dns_windows.c
src/detection/font/font_windows.c
src/detection/gpu/gpu_windows.c
src/detection/host/host_mac.c
src/detection/host/host_windows.c
src/detection/icons/icons_windows.c
src/detection/initsystem/initsystem_nosupport.c
src/detection/keyboard/keyboard_windows.c
src/detection/libc/libc_windows.cpp
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_nosupport.c
src/detection/locale/locale_windows.c
src/detection/localip/localip_windows.c
src/detection/gamepad/gamepad_windows.c
src/detection/media/media_windows.c
src/detection/memory/memory_windows.c
src/detection/mouse/mouse_windows.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/netio/netio_windows.c
src/detection/opengl/opengl_windows.c
src/detection/os/os_windows.c
src/detection/packages/packages_windows.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_windows.c
src/detection/sound/sound_windows.cpp
src/detection/swap/swap_windows.c
src/detection/terminalfont/terminalfont_windows.c
src/detection/terminalshell/terminalshell_windows.c
src/detection/terminalsize/terminalsize_windows.c
src/detection/theme/theme_windows.c
src/detection/tpm/tpm_windows.c
src/detection/uptime/uptime_windows.c
src/detection/users/users_windows.c
src/detection/wallpaper/wallpaper_windows.c
src/detection/wifi/wifi_windows.c
src/detection/wm/wm_windows.c
src/detection/de/de_nosupport.c
src/detection/wmtheme/wmtheme_windows.c
src/detection/camera/camera_windows.cpp
)
elseif(SunOS)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_apple.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_sunos.c
src/detection/battery/battery_nosupport.c
src/detection/bios/bios_windows.c
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_sunos.c
src/detection/cpucache/cpucache_shared.c
src/detection/cpuusage/cpuusage_sunos.c
src/detection/cursor/cursor_linux.c
src/detection/bluetooth/bluetooth_nosupport.c
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/disk/disk_sunos.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_sunos.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_sunos.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/kde-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_sunos.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_windows.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_nosupport.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_sunos.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_sunos.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_sunos.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_sunos.c
src/detection/packages/packages_sunos.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_linux.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_sunos.c
src/detection/swap/swap_sunos.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_sunos.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_nosupport.c
src/detection/wm/wm_nosupport.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_nosupport.c
)
elseif(Haiku)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_haiku.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_nosupport.c
src/common/haiku/version.cpp
src/detection/battery/battery_haiku.c
src/detection/bios/bios_windows.c
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_haiku.c
src/detection/cpucache/cpucache_shared.c
src/detection/cpuusage/cpuusage_haiku.c
src/detection/cursor/cursor_nosupport.c
src/detection/bluetooth/bluetooth_haiku.cpp
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/disk/disk_haiku.cpp
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_haiku.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_nosupport.c
src/detection/displayserver/displayserver_haiku.cpp
src/detection/font/font_haiku.cpp
src/detection/gpu/gpu_haiku.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_windows.c
src/detection/icons/icons_nosupport.c
src/detection/initsystem/initsystem_haiku.c
src/detection/keyboard/keyboard_haiku.cpp
src/detection/libc/libc_nosupport.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_nosupport.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_haiku.cpp
src/detection/media/media_linux.c
src/detection/memory/memory_haiku.c
src/detection/mouse/mouse_haiku.cpp
src/detection/netio/netio_haiku.cpp
src/detection/opengl/opengl_haiku.cpp
src/detection/os/os_haiku.c
src/detection/packages/packages_haiku.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_haiku.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_haiku.cpp
src/detection/swap/swap_haiku.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_nosupport.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_haiku.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_nosupport.c
src/detection/wifi/wifi_nosupport.c
src/detection/wm/wm_nosupport.c
src/detection/de/de_nosupport.c
src/detection/wmtheme/wmtheme_nosupport.c
src/detection/camera/camera_nosupport.c
)
elseif(GNU)
list(APPEND LIBFASTFETCH_SRC
src/common/impl/dbus.c
src/common/impl/io_unix.c
src/common/impl/netif_gnu.c
src/common/impl/networking_linux.c
src/common/impl/processing_linux.c
src/common/impl/FFPlatform_unix.c
src/common/impl/binary_linux.c
src/common/impl/kmod_nosupport.c
src/detection/battery/battery_nosupport.c
src/detection/bios/bios_nosupport.c
src/detection/board/board_nosupport.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nosupport.c
src/detection/cpu/cpu_linux.c
src/detection/cpucache/cpucache_nosupport.c
src/detection/cpuusage/cpuusage_linux.c
src/detection/cursor/cursor_linux.c
src/detection/bluetooth/bluetooth_linux.c
src/detection/bluetoothradio/bluetoothradio_linux.c
src/detection/disk/disk_linux.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_nosupport.c
src/detection/physicalmemory/physicalmemory_nosupport.c
src/detection/diskio/diskio_nosupport.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/common.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_gnu.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_nosupport.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_linux.c
src/detection/lm/lm_linux.c
src/detection/loadavg/loadavg_linux.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_linux.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_nosupport.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
src/detection/packages/packages_linux.c
src/detection/packages/packages_nix.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_linux.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_linux.c
src/detection/swap/swap_linux.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_linux.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_nosupport.c
src/detection/wm/wm_linux.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_nosupport.c
)
endif()
if(ENABLE_DIRECTX_HEADERS)
message(STATUS "Enabling DirectX headers for WSL")
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_wsl.cpp)
endif()
# Proprietary GPU driver APIs
if(LINUX OR FreeBSD OR WIN32)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_nvidia.c)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_mthreads.c)
endif()
if(WIN32)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_intel.c)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_amd.c)
endif()
include(CheckFunctionExists)
check_function_exists(wcwidth HAVE_WCWIDTH)
if(NOT HAVE_WCWIDTH)
list(APPEND LIBFASTFETCH_SRC src/common/impl/wcwidth.c)
endif()
if(NOT WIN32)
check_function_exists(pipe2 HAVE_PIPE2)
endif()
check_function_exists(memrchr HAVE_MEMRCHR)
if(NOT HAVE_MEMRCHR)
list(APPEND LIBFASTFETCH_SRC src/common/impl/memrchr.c)
endif()
if(ENABLE_SYSTEM_YYJSON)
find_package(yyjson)
if(yyjson_FOUND)
message(STATUS "System provided yyjson is used")
else()
message(FATAL_ERROR "ENABLE_SYSTEM_YYJSON is set but system provided yyjson is not found")
endif()
else()
list(APPEND LIBFASTFETCH_SRC
src/3rdparty/yyjson/yyjson.c
)
endif()
add_library(libfastfetch OBJECT
${LIBFASTFETCH_SRC}
)
include(CheckCSourceCompiles)
check_c_source_compiles("int main(void){int arr[1];return _Countof(arr);}" COMPILER_SUPPORTS_COUNT_OF)
if(COMPILER_SUPPORTS_COUNT_OF)
message(STATUS "_Countof is supported by the compiler")
target_compile_definitions(libfastfetch PUBLIC FF_SUPPORTS_COUNT_OF=1)
else()
message(STATUS "_Countof is NOT supported by the compiler")
endif()
if(yyjson_FOUND)
target_compile_definitions(libfastfetch PUBLIC FF_USE_SYSTEM_YYJSON=1)
target_link_libraries(libfastfetch PUBLIC yyjson::yyjson)
# `target_link_libraries(yyjson::yyjson)` sets rpath implicitly
endif()
# Used for dlopen finding dylibs installed by homebrew
# `/opt/homebrew/lib` is not on in dlopen search path by default
if(APPLE AND BINARY_LINK_TYPE STREQUAL "dlopen")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,/usr/local/lib")
endif()
if(ANDROID)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/vendor/lib64 -Wl,-rpath,/system/lib64")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/vendor/lib -Wl,-rpath,/system/lib")
endif()
endif()
if(LINUX AND EXISTS "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1")
execute_process(COMMAND "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1"
ERROR_VARIABLE LD_MUSL_RESULT)
if("${LD_MUSL_RESULT}" MATCHES "Version ([0-9]+\\.[0-9]+\\.[0-9]+)")
target_compile_definitions(libfastfetch PUBLIC FF_MUSL_VERSION="${CMAKE_MATCH_1}")
endif()
endif()
if(APPLE AND EXISTS "/usr/bin/otool")
execute_process(COMMAND /usr/bin/otool -L /usr/bin/otool
OUTPUT_VARIABLE OTOOL_OTOOL_RESULT)
if("${OTOOL_OTOOL_RESULT}" MATCHES "libSystem\\.B\\.dylib \\(.*current version ([0-9]+\\.[0-9]+\\.[0-9]+)\\)")
target_compile_definitions(libfastfetch PUBLIC FF_LIBSYSTEM_VERSION="${CMAKE_MATCH_1}")
endif()
endif()
if(MidnightBSD AND EXISTS "/usr/bin/objdump")
execute_process(COMMAND /bin/sh -c "/usr/bin/objdump -T /lib/libc.so.* | grep 'FBSD_[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1"
OUTPUT_VARIABLE OBJDUMP_T_RESULT)
if("${OBJDUMP_T_RESULT}" MATCHES "FBSD_([0-9]+\\.[0-9]+)")
message(STATUS "Found FBSD ${CMAKE_MATCH_1}")
target_compile_definitions(libfastfetch PUBLIC FF_FBSD_VERSION="${CMAKE_MATCH_1}")
endif()
elseif(FreeBSD AND EXISTS "/usr/local/bin/objdump")
execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'FBSD_[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1"
OUTPUT_VARIABLE OBJDUMP_T_RESULT)
if("${OBJDUMP_T_RESULT}" MATCHES "FBSD_([0-9]+\\.[0-9]+)")
message(STATUS "Found FBSD ${CMAKE_MATCH_1}")
target_compile_definitions(libfastfetch PUBLIC FF_FBSD_VERSION="${CMAKE_MATCH_1}")
endif()
elseif(DragonFly AND EXISTS "/usr/local/bin/objdump")
execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'DF[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1"
OUTPUT_VARIABLE OBJDUMP_T_RESULT)
if("${OBJDUMP_T_RESULT}" MATCHES "DF([0-9]+\\.[0-9]+)")
message(STATUS "Found DF ${CMAKE_MATCH_1}")
target_compile_definitions(libfastfetch PUBLIC FF_DF_VERSION="${CMAKE_MATCH_1}")
endif()
endif()
if(LINUX)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _TIME_BITS=64) # "$<$:_FORTIFY_SOURCE=3>"
elseif(ANDROID)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _FILE_OFFSET_BITS=64 "$<$:__BIONIC_FORTIFY>" "$<$:__BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED>")
elseif(WIN32)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0A00 NOMINMAX UNICODE) # "$<$:_FORTIFY_SOURCE=3>"
elseif(APPLE)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE)
elseif(OpenBSD)
target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R6/lib") # detect x11 lib path automatically
elseif(DragonFly)
target_compile_definitions(libfastfetch PUBLIC __FreeBSD__)
elseif(SunOS)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE)
elseif(NetBSD)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib") # ditto
elseif(Haiku)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
elseif(GNU)
# On Hurd PATH_MAX is not defined. Set an arbitrary limit as workaround.
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE PATH_MAX=4096 O_PATH=0)
endif()
if(APPLE)
if(ENABLE_APPLE_MEMSIZE_USABLE)
target_compile_definitions(libfastfetch PUBLIC FF_APPLE_MEMSIZE_USABLE=1)
else()
target_compile_definitions(libfastfetch PUBLIC FF_APPLE_MEMSIZE_USABLE=0)
endif()
endif()
if(WIN32)
check_function_exists(_msize HAVE_MSVC_MSIZE)
if(HAVE_MSVC_MSIZE)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MSVC_MSIZE=1)
endif()
if(ENABLE_WIN81_COMPAT)
target_compile_definitions(libfastfetch PUBLIC FF_WIN81_COMPAT=1)
else()
target_compile_definitions(libfastfetch PUBLIC FF_WIN81_COMPAT=0)
endif()
else()
check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
if(HAVE_MALLOC_USABLE_SIZE)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MALLOC_USABLE_SIZE=1)
else()
check_function_exists(malloc_size HAVE_MALLOC_SIZE)
if(HAVE_MALLOC_SIZE)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MALLOC_SIZE=1)
endif()
endif()
endif()
if(FreeBSD OR OpenBSD OR NetBSD)
include(CheckStructHasMember)
set(CMAKE_REQUIRED_DEFINITIONS "-D_IFI_OQDROPS=1")
CHECK_STRUCT_HAS_MEMBER("struct if_data" ifi_oqdrops net/if.h HAVE_IFI_OQDROPS LANGUAGE C)
if(HAVE_IFI_OQDROPS)
target_compile_definitions(libfastfetch PUBLIC _IFI_OQDROPS FF_HAVE_IFI_OQDROPS)
endif()
unset(CMAKE_REQUIRED_DEFINITIONS)
endif()
if(HAVE_WCWIDTH)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_WCWIDTH)
endif()
if(HAVE_PIPE2)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_PIPE2)
endif()
if(NOT "${CUSTOM_PCI_IDS_PATH}" STREQUAL "")
message(STATUS "Custom file path of pci.ids: ${CUSTOM_PCI_IDS_PATH}")
target_compile_definitions(libfastfetch PRIVATE FF_CUSTOM_PCI_IDS_PATH=${CUSTOM_PCI_IDS_PATH})
endif()
if(NOT "${CUSTOM_AMDGPU_IDS_PATH}" STREQUAL "")
message(STATUS "Custom file path of amdgpu.ids: ${CUSTOM_AMDGPU_IDS_PATH}")
target_compile_definitions(libfastfetch PRIVATE FF_CUSTOM_AMDGPU_IDS_PATH=${CUSTOM_AMDGPU_IDS_PATH})
endif()
if(NOT "${CUSTOM_OS_RELEASE_PATH}" STREQUAL "")
message(STATUS "Custom file path of os_release: ${CUSTOM_OS_RELEASE_PATH}")
target_compile_definitions(libfastfetch PRIVATE FF_CUSTOM_OS_RELEASE_PATH=${CUSTOM_OS_RELEASE_PATH})
endif()
if(NOT "${CUSTOM_LSB_RELEASE_PATH}" STREQUAL "")
message(STATUS "Custom file path of lsb_release: ${CUSTOM_LSB_RELEASE_PATH}")
target_compile_definitions(libfastfetch PRIVATE FF_CUSTOM_LSB_RELEASE_PATH=${CUSTOM_LSB_RELEASE_PATH})
endif()
if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
message(STATUS "Enabling custom link type: ${BINARY_LINK_TYPE}")
target_compile_definitions(libfastfetch PRIVATE FF_DISABLE_DLOPEN=1)
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")
endif()
endif()
function(ff_lib_enable VARNAME PKGCONFIG_NAMES CMAKE_NAME)
if(NOT ENABLE_${VARNAME})
return()
endif()
if(PKG_CONFIG_FOUND)
pkg_search_module(${VARNAME} QUIET ${PKGCONFIG_NAMES})
endif()
if(NOT ${VARNAME}_FOUND)
find_package(${CMAKE_NAME} QUIET)
set(${VARNAME}_FOUND ${${CMAKE_NAME}_FOUND})
set(${VARNAME}_INCLUDE_DIRS ${${CMAKE_NAME}_INCLUDE_DIRS})
set(${VARNAME}_LIBRARIES ${${CMAKE_NAME}_LIBRARIES})
set(${VARNAME}_CFLAGS_OTHER ${${CMAKE_NAME}_CFLAGS_OTHER})
endif()
if(NOT ${VARNAME}_FOUND)
message(STATUS "Library: missing: ${VARNAME}")
return()
endif()
message(STATUS "Library: found ${VARNAME}")
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_${VARNAME}=1)
target_include_directories(libfastfetch PRIVATE ${${VARNAME}_INCLUDE_DIRS})
if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
target_link_directories(libfastfetch PUBLIC ${${VARNAME}_LIBRARY_DIRS})
target_link_libraries(libfastfetch PRIVATE ${${VARNAME}_LIBRARIES})
endif()
foreach(FLAG ${${VARNAME}_CFLAGS_OTHER})
if(FLAG MATCHES "-D.*")
string(SUBSTRING ${FLAG} 2 -1 FLAG)
target_compile_definitions(libfastfetch PRIVATE ${FLAG})
endif()
endforeach()
endfunction()
ff_lib_enable(VULKAN
"vulkan"
"Vulkan"
)
ff_lib_enable(WAYLAND
"wayland-client"
"WaylandClient"
)
ff_lib_enable(XCB_RANDR
"xcb-randr"
"XcbRandr"
)
ff_lib_enable(XRANDR
"xrandr"
"XRandr"
)
ff_lib_enable(DRM
"libdrm"
"Libdrm"
)
ff_lib_enable(DRM_AMDGPU
"libdrm_amdgpu"
"Libdrm_Amdgpu"
)
ff_lib_enable(GIO
"gio-2.0"
"GIO"
)
ff_lib_enable(DCONF
"dconf"
"DConf"
)
ff_lib_enable(DBUS
"dbus-1"
"DBus"
)
ff_lib_enable(SQLITE3
"sqlite3"
"SQLite3"
)
ff_lib_enable(RPM
"rpm"
"RPM"
)
ff_lib_enable(IMAGEMAGICK7
"MagickCore-7.Q16HDRI;MagickCore-7.Q16;MagickCore-7;/usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16HDRI.pc;/usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16.pc;/usr/lib/imagemagick7/pkgconfig/MagickCore-7.pc"
"ImageMagick7"
)
ff_lib_enable(IMAGEMAGICK6
"MagickCore-6.Q16HDRI;MagickCore-6.Q16;MagickCore-6;/usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16HDRI.pc;/usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16.pc;/usr/lib/imagemagick6/pkgconfig/MagickCore-6.pc"
"ImageMagick6"
)
ff_lib_enable(ZLIB
"zlib"
"ZLIB"
)
ff_lib_enable(CHAFA
"chafa>=1.10"
"Chafa"
)
ff_lib_enable(EGL
"egl"
"EGL"
)
if(NOT OpenBSD AND NOT NetBSD)
ff_lib_enable(GLX
"glx"
"GLX"
)
else()
ff_lib_enable(GLX
"gl"
"GL"
)
endif()
ff_lib_enable(OPENCL
"OpenCL"
"OpenCL"
)
ff_lib_enable(FREETYPE
"freetype2"
"FreeType2"
)
ff_lib_enable(PULSE
"libpulse"
"Pulse"
)
ff_lib_enable(DDCUTIL
"ddcutil"
"Ddcutil"
)
ff_lib_enable(ELF
"libelf"
"libelf"
)
ff_lib_enable(DIRECTX_HEADERS
"DirectX-Headers"
"DirectX-Headers"
)
if(ENABLE_THREADS)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_THREADS=1)
if(CMAKE_USE_PTHREADS_INIT) #Threads::Threads is not set for WIN32
target_link_libraries(libfastfetch PRIVATE Threads::Threads)
endif()
endif()
if(ENABLE_EMBEDDED_PCIIDS)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_EMBEDDED_PCIIDS=1)
endif()
if(ENABLE_EMBEDDED_AMDGPUIDS)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_EMBEDDED_AMDGPUIDS=1)
endif()
if(ENABLE_LIBZFS)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LIBZFS=1)
if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
target_link_libraries(libfastfetch
PRIVATE "zfs"
)
endif()
endif()
if(NOT HAVE_MEMRCHR)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_CUSTOM_MEMRCHR=1)
endif()
if(LINUX)
target_link_libraries(libfastfetch
PRIVATE "m"
)
if(ENABLE_DIRECTX_HEADERS)
if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
target_link_libraries(libfastfetch
PRIVATE "/usr/lib/wsl/lib/libdxcore.so"
)
endif()
endif()
elseif(APPLE)
target_link_libraries(libfastfetch
PRIVATE "-framework AVFoundation"
PRIVATE "-framework Cocoa"
PRIVATE "-framework CoreFoundation"
PRIVATE "-framework CoreAudio"
PRIVATE "-framework CoreMedia"
PRIVATE "-framework CoreVideo"
PRIVATE "-framework CoreWLAN"
PRIVATE "-framework IOBluetooth"
PRIVATE "-framework IOKit"
PRIVATE "-framework Metal"
PRIVATE "-framework OpenGL"
PRIVATE "-framework OpenCL"
PRIVATE "-framework SystemConfiguration"
PRIVATE "-weak_framework CoreDisplay"
PRIVATE "-F /System/Library/PrivateFrameworks"
PRIVATE "-weak_framework DisplayServices"
PRIVATE "-weak_framework MediaRemote"
)
elseif(WIN32)
target_link_libraries(libfastfetch
PRIVATE "gdi32"
PRIVATE "iphlpapi"
PRIVATE "ole32"
PRIVATE "oleaut32"
PRIVATE "ws2_32"
PRIVATE "ntdll"
PRIVATE "version"
PRIVATE "hid"
PRIVATE "wtsapi32"
PRIVATE "cfgmgr32"
PRIVATE "winbrand"
PRIVATE "secur32"
)
if(NOT ENABLE_WIN81_COMPAT)
target_link_libraries(libfastfetch
PRIVATE "mincore"
)
endif()
elseif(FreeBSD)
target_link_libraries(libfastfetch
PRIVATE "m"
PRIVATE "usbhid"
PRIVATE "bluetooth"
)
if(NOT DragonFly)
target_link_libraries(libfastfetch
PRIVATE "geom"
)
else()
target_link_libraries(libfastfetch
PRIVATE "devstat"
)
endif()
elseif(OpenBSD)
target_link_libraries(libfastfetch
PRIVATE "m"
PRIVATE "kvm"
PRIVATE "sndio"
)
elseif(NetBSD)
target_link_libraries(libfastfetch
PRIVATE "bluetooth"
PRIVATE "m"
PRIVATE "prop"
)
elseif(SunOS)
target_link_libraries(libfastfetch
PRIVATE "m"
PRIVATE "socket"
PRIVATE "kstat"
PRIVATE "proc"
PRIVATE "devinfo"
)
elseif(GNU)
target_link_libraries(libfastfetch
PRIVATE "m"
)
elseif(ANDROID)
target_link_libraries(libfastfetch
PRIVATE "m"
)
if(ENABLE_WORDEXP)
# https://github.com/termux/termux-packages/pull/7056
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
if(HAVE_LIBANDROID_WORDEXP_STATIC)
target_link_libraries(libfastfetch
PRIVATE -l:libandroid-wordexp.a
)
else()
CHECK_LIBRARY_EXISTS(android-wordexp wordexp "" HAVE_LIBANDROID_WORDEXP)
if(HAVE_LIBANDROID_WORDEXP)
target_link_libraries(libfastfetch
PRIVATE android-wordexp
)
endif()
endif()
endif()
elseif(Haiku)
target_link_libraries(libfastfetch
PRIVATE "network"
PRIVATE "bnetapi"
PRIVATE "media"
PRIVATE "device"
PRIVATE "bluetooth"
PRIVATE "GL"
PRIVATE "be"
PRIVATE "gnu"
)
endif()
target_include_directories(libfastfetch
PUBLIC ${PROJECT_BINARY_DIR}
PUBLIC ${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(libfastfetch
PRIVATE ${CMAKE_DL_LIBS}
)
target_compile_options(libfastfetch PRIVATE
$<$:-fno-exceptions -fno-rtti>)
if(WIN32)
set(CMAKE_CXX_STANDARD 20)
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX("winrt/Windows.Foundation.h" HAVE_WINRT)
if(HAVE_WINRT)
add_library(ffwinrt MODULE src/detection/media/media_windows.dll.cpp)
target_link_libraries(ffwinrt PRIVATE "RuntimeObject")
target_compile_definitions(ffwinrt PRIVATE WIN32_LEAN_AND_MEAN=1 WINRT_LEAN_AND_MEAN=1)
target_link_options(ffwinrt
PRIVATE "-static" # stdc++, winpthread, gcc_s, etc.
)
endif()
set(CMAKE_CXX_STANDARD 17)
endif()
if(FreeBSD)
set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include")
endif()
if(LINUX OR FreeBSD OR OpenBSD OR NetBSD)
CHECK_INCLUDE_FILE("linux/videodev2.h" HAVE_LINUX_VIDEODEV2)
if(HAVE_LINUX_VIDEODEV2)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LINUX_VIDEODEV2=1)
endif()
endif()
if(LINUX)
CHECK_INCLUDE_FILE("linux/wireless.h" HAVE_LINUX_WIRELESS)
if(HAVE_LINUX_WIRELESS)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LINUX_WIRELESS=1)
endif()
endif()
if(NOT WIN32)
CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX)
if(HAVE_UTMPX)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_UTMPX=1)
endif()
if(ENABLE_WORDEXP)
CHECK_INCLUDE_FILE("wordexp.h" HAVE_WORDEXP)
if(HAVE_WORDEXP)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WORDEXP=1)
message(STATUS "wordexp.h found, wordexp support enabled")
else()
set(ENABLE_WORDEXP OFF)
endif()
endif()
if(NOT ENABLE_WORDEXP)
message(STATUS "wordexp.h not found or disabled, glob used instead")
endif()
if(ENABLE_THREADS AND CMAKE_USE_PTHREADS_INIT)
CHECK_INCLUDE_FILE("pthread_np.h" HAVE_PTHREAD_NP)
if(HAVE_PTHREAD_NP)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_PTHREAD_NP=1)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} pthread_np.h)
endif()
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} Threads::Threads)
check_function_exists("pthread_timedjoin_np" HAVE_TIMEDJOIN_NP)
if(HAVE_TIMEDJOIN_NP)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_TIMEDJOIN_NP=1)
else()
message(WARNING "pthread_timedjoin_np was not found; networking timeout will not work")
endif()
endif()
endif()
set(PACKAGES_DISABLE_LIST "")
foreach(package_manager ${PACKAGE_MANAGERS})
if(PACKAGES_DISABLE_${package_manager})
list(APPEND PACKAGES_DISABLE_LIST "${package_manager}")
endif()
endforeach()
if("${PACKAGES_DISABLE_LIST}" STREQUAL "")
set(PACKAGES_DISABLE_LIST "FF_PACKAGES_FLAG_NONE")
else()
message(STATUS "Disabled package managers: ${PACKAGES_DISABLE_LIST}")
list(TRANSFORM PACKAGES_DISABLE_LIST PREPEND "FF_PACKAGES_FLAG_")
list(TRANSFORM PACKAGES_DISABLE_LIST APPEND "_BIT")
list(JOIN PACKAGES_DISABLE_LIST " | " PACKAGES_DISABLE_LIST)
endif()
target_compile_definitions(libfastfetch PRIVATE FF_PACKAGES_DISABLE_LIST=${PACKAGES_DISABLE_LIST})
######################
# Executable targets #
######################
add_executable(fastfetch
src/fastfetch.c
)
target_compile_definitions(fastfetch
PRIVATE FASTFETCH_TARGET_BINARY_NAME=fastfetch
)
target_link_libraries(fastfetch
PRIVATE libfastfetch
)
# Prevent fastfetch from linking to libstdc++
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
set_target_properties(fastfetch PROPERTIES LINKER_LANGUAGE C)
if(WIN32)
target_sources(fastfetch
PRIVATE src/common/windows/version.rc
)
elseif(APPLE)
target_link_options(fastfetch
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist
)
endif()
if(BINARY_LINK_TYPE STREQUAL "static")
target_link_options(fastfetch PRIVATE "-static")
endif()
# Apply all above parameters to flashfetch if it is built
if (BUILD_FLASHFETCH)
add_executable(flashfetch
src/flashfetch.c
)
target_compile_definitions(flashfetch
PRIVATE FASTFETCH_TARGET_BINARY_NAME=flashfetch
)
target_link_libraries(flashfetch
PRIVATE libfastfetch
)
set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
if(WIN32)
target_sources(flashfetch
PRIVATE src/common/windows/version.rc
)
elseif(APPLE)
target_link_options(flashfetch
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist
)
endif()
if(BINARY_LINK_TYPE STREQUAL "static")
target_link_options(flashfetch PRIVATE "-static")
endif()
endif()
###################
# Testing targets #
###################
if (BUILD_TESTS)
add_executable(fastfetch-test-strbuf
tests/strbuf.c
)
target_link_libraries(fastfetch-test-strbuf
PRIVATE libfastfetch
)
add_executable(fastfetch-test-list
tests/list.c
)
target_link_libraries(fastfetch-test-list
PRIVATE libfastfetch
)
add_executable(fastfetch-test-format
tests/format.c
)
target_link_libraries(fastfetch-test-format
PRIVATE libfastfetch
)
add_executable(fastfetch-test-color
tests/color.c
)
target_link_libraries(fastfetch-test-color
PRIVATE libfastfetch
)
add_executable(fastfetch-test-duration
tests/duration.c
)
target_link_libraries(fastfetch-test-duration
PRIVATE libfastfetch
)
enable_testing()
add_test(NAME test-strbuf COMMAND fastfetch-test-strbuf)
add_test(NAME test-list COMMAND fastfetch-test-list)
add_test(NAME test-format COMMAND fastfetch-test-format)
add_test(NAME test-color COMMAND fastfetch-test-color)
add_test(NAME test-duration COMMAND fastfetch-test-duration)
endif()
##################
# install target #
##################
include(GNUInstallDirs)
install(
TARGETS fastfetch
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
if (TARGET flashfetch)
install(
TARGETS flashfetch
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
if (TARGET ffwinrt)
install(
TARGETS ffwinrt
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
install(
FILES "${CMAKE_SOURCE_DIR}/completions/${CMAKE_PROJECT_NAME}.bash"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions"
RENAME "${CMAKE_PROJECT_NAME}"
)
install(
FILES "${CMAKE_SOURCE_DIR}/completions/${CMAKE_PROJECT_NAME}.zsh"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions"
RENAME "_${CMAKE_PROJECT_NAME}"
)
install(
FILES "${CMAKE_SOURCE_DIR}/completions/${CMAKE_PROJECT_NAME}.fish"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/fish/vendor_completions.d"
RENAME "${CMAKE_PROJECT_NAME}.fish"
)
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/presets"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}"
)
if(INSTALL_LICENSE)
install(
FILES "${CMAKE_SOURCE_DIR}/LICENSE"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}"
)
endif()
install(
FILES "${PROJECT_BINARY_DIR}/fastfetch.1"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
)
##################
# package target #
##################
set(CPACK_GENERATOR "TGZ;ZIP")
if(APPLE)
string(TOLOWER "${CMAKE_PROJECT_NAME}-macos-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME) # use macos instead of darwin
elseif(IS_MUSL)
string(TOLOWER "${CMAKE_PROJECT_NAME}-musl-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
else()
string(TOLOWER "${CMAKE_PROJECT_NAME}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
endif()
if(LINUX)
find_program(HAVE_DPKG "dpkg")
if(HAVE_DPKG)
set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB")
set(CPACK_DEBIAN_PACKAGE_SECTION, "utils")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
if(NOT IS_MUSL)
EXECUTE_PROCESS(
COMMAND getconf GNU_LIBC_VERSION
OUTPUT_VARIABLE GLIBC_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GLIBC_VERSION)
STRING(REPLACE "glibc " "" GLIBC_VERSION ${GLIBC_VERSION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= ${GLIBC_VERSION})")
message(STATUS "found glibc ${GLIBC_VERSION}")
else()
message(WARNING "Could not determine glibc version. If `musl` is used, `-DIS_MUSL=ON` should be set")
endif()
endif()
endif()
if(NOT IS_MUSL)
find_program(HAVE_RPMBUILD "rpmbuild")
if(HAVE_RPMBUILD)
set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
endif()
endif()
elseif(FreeBSD AND NOT DragonFly)
set(CPACK_FREEBSD_PACKAGE_LICENSE "MIT")
set(CPACK_GENERATOR "${CPACK_GENERATOR};FREEBSD")
endif()
set(CPACK_SET_DESTDIR ON)
set(CPACK_PACKAGE_CONTACT "Carter Li ")
set(CPACK_PACKAGE_DESCRIPTION "\
fastfetch is a neofetch-like tool for fetching system information and displaying them in a pretty way. \
It is written mostly in C to achieve much better performance.\
")
include(CPack)
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official email address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[INSERT CONTACT METHOD].
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2021-2023 Linus Dierheimer
Copyright (c) 2022-2026 Carter Li
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README-cn.md
================================================
# Fastfetch
Fastfetch 是一款类似 neofetch 的系统信息展示工具,主要用 C 编写,强调性能和可定制性。支持 Linux、macOS、Windows 7+、Android、FreeBSD、OpenBSD、NetBSD、DragonFly、Haiku、SunOS。
示例配置见 presets/examples,更多截图与平台说明见 Wiki。
## 安装
Linux(部分):
- Debian 13+ / Ubuntu: apt install fastfetch
- Arch: pacman -S fastfetch
- Fedora: dnf install fastfetch
- openSUSE: zypper install fastfetch
- Linuxbrew:brew install fastfetch
- 各发行版打包状态:https://repology.org/project/fastfetch/versions
macOS:
- Homebrew:brew install fastfetch
- MacPorts:sudo port install fastfetch
Windows:
- scoop install fastfetch
- choco install fastfetch
- winget install fastfetch
- MSYS2:pacman -S mingw-w64---fastfetch
BSD:
- FreeBSD:pkg install fastfetch
- NetBSD:pkgin in fastfetch
- OpenBSD:pkg_add fastfetch
Android(Termux):
- pkg install fastfetch
Nightly 构建:
- https://nightly.link/fastfetch-cli/fastfetch/workflows/ci/dev?preview
## 源码构建
基本上是 `cmake . && make`。详见 Wiki:https://github.com/fastfetch-cli/fastfetch/wiki/Building
## 使用
- 默认运行:`fastfetch`
- 查看所有可用模块示例:`fastfetch -c all.jsonc`
- 以 JSON 输出指定模块:`fastfetch -s [:] --format json`
- 完整命令行帮助:`fastfetch --help`
- 生成最小配置:`fastfetch --gen-config []`
- 生成完整配置:`fastfetch --gen-config-full`
- 请使用支持 JSON schema 的编辑器(如 VSCode)编辑配置文件!
- 如果你连接 Github 有网络困难(智能提示不生效),可将配置文件中的 `$schema` 的值替换为 `https://gitee.com/carterl/fastfetch/raw/dev/doc/json_schema.json`
## 定制
- 配置使用 JSONC,语法与选项见 Wiki:https://github.com/fastfetch-cli/fastfetch/wiki/Configuration
- 预设示例位于 presets,可用 `-c ` 加载
- Logo 选项与图像显示见文档:https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options
- 模块格式化(示例,仅显示 GPU 名称):
```jsonc
{
"modules": [
{ "type": "gpu", "format": "{name}" }
]
}
```
详见:https://github.com/fastfetch-cli/fastfetch/wiki/Format-String-Guide
## 反馈与支持
- 使用问题:Discussions https://github.com/fastfetch-cli/fastfetch/discussions
- 疑似缺陷:Issues https://github.com/fastfetch-cli/fastfetch/issues(请填写模版)
## 赞助
================================================
FILE: README.md
================================================
# Fastfetch
[](https://github.com/fastfetch-cli/fastfetch/actions)
[](https://github.com/fastfetch-cli/fastfetch/blob/dev/LICENSE)
[](https://github.com/fastfetch-cli/fastfetch/graphs/contributors)
[](https://github.com/fastfetch-cli/fastfetch/blob/dev/CMakeLists.txt#L5)
[](https://github.com/fastfetch-cli/fastfetch/commits)
[](https://formulae.brew.sh/formula/fastfetch#default)
[](https://github.com/fastfetch-cli/fastfetch/releases)
[](https://github.com/fastfetch-cli/fastfetch/releases)
[](https://repology.org/project/fastfetch/versions)
[](https://repology.org/project/fastfetch/versions)
[](https://deepwiki.com/fastfetch-cli/fastfetch)
[](README-cn.md)
Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for fetching system information and displaying it in a visually appealing way. It is written mainly in C, with a focus on performance and customizability. Currently, it supports Linux, macOS, Windows 8.1+, Android, FreeBSD, OpenBSD, NetBSD, DragonFly, Haiku and SunOS (illumos, Solaris).
According configuration files for examples are located [here](https://github.com/fastfetch-cli/fastfetch/tree/dev/presets/examples).
There are [screenshots on different platforms](https://github.com/fastfetch-cli/fastfetch/wiki).
## Installation
### Linux
Some distributions package outdated versions of fastfetch. Older versions receive no support, so please always try to use the latest version.
* Ubuntu: [`ppa:zhangsongcui3371/fastfetch`](https://launchpad.net/~zhangsongcui3371/+archive/ubuntu/fastfetch) (Ubuntu 22.04 or newer; latest version)
* Debian / Ubuntu: `apt install fastfetch` (Debian 13 or newer; Ubuntu 25.04 or newer)
* Debian / Ubuntu: Download `fastfetch-linux-.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and double-click it (for Ubuntu 20.04 or newer and Debian 11 or newer).
* Arch Linux: `pacman -S fastfetch`
* Fedora: `dnf install fastfetch`
* Gentoo: `emerge --ask app-misc/fastfetch`
* Alpine: `apk add --upgrade fastfetch`
* NixOS: `nix-shell -p fastfetch`
* openSUSE: `zypper install fastfetch`
* ALT Linux: `apt-get install fastfetch`
* Exherbo: `cave resolve --execute app-misc/fastfetch`
* Solus: `eopkg install fastfetch`
* Slackware: `sbopkg -i fastfetch`
* Void Linux: `xbps-install fastfetch`
* Venom Linux: `scratch install fastfetch`
You may need `sudo`, `doas`, or `sup` to run these commands.
If fastfetch is not packaged for your distribution or an outdated version is packaged, [linuxbrew](https://brew.sh/) is a good alternative: `brew install fastfetch`
### macOS
* [Homebrew](https://formulae.brew.sh/formula/fastfetch#default): `brew install fastfetch`
* [MacPorts](https://ports.macports.org/port/fastfetch/): `sudo port install fastfetch`
### Windows
* [scoop](https://scoop.sh/#/apps?q=fastfetch): `scoop install fastfetch`
* [Chocolatey](https://community.chocolatey.org/packages/fastfetch): `choco install fastfetch`
* [winget](https://github.com/microsoft/winget-pkgs/tree/master/manifests/f/Fastfetch-cli/Fastfetch): `winget install fastfetch`
* [MSYS2 MinGW](https://packages.msys2.org/base/mingw-w64-fastfetch): `pacman -S mingw-w64---fastfetch`
You may also download the program directly from [the GitHub releases page](https://github.com/fastfetch-cli/fastfetch/releases/latest) in the form of an archive file.
### BSD systems
* FreeBSD: `pkg install fastfetch`
* NetBSD: `pkgin in fastfetch`
* OpenBSD: `pkg_add fastfetch` (Snapshots only)
* DragonFly BSD: `pkg install fastfetch` (Snapshots only)
### Android (Termux)
* `pkg install fastfetch`
### Nightly
## Build from source
See the Wiki: https://github.com/fastfetch-cli/fastfetch/wiki/Building
## Usage
* Run with default configuration: `fastfetch`
* Run with [all supported modules](https://github.com/fastfetch-cli/fastfetch/wiki/Support+Status#available-modules) to find what interests you: `fastfetch -c all.jsonc`
* View all data that fastfetch detects: `fastfetch -s [:][:] --format json`
* Display help messages: `fastfetch --help`
* Generate a minimal config file: `fastfetch [-s [:]] --gen-config []`
* Use: `--gen-config-full` to generate a full config file with all optional options
## Customization
Fastfetch uses JSONC (JSON with comments) for configuration. [See the Wiki for details](https://github.com/fastfetch-cli/fastfetch/wiki/Configuration). There are some premade config files in the [`presets`](presets) directory, including those used for the screenshots above. You can load them using `-c `. These files can serve as examples of the configuration syntax.
Logos can also be heavily customized; see the [logo documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options) for more information.
### WARNING
Fastfetch supports a `Command` module that can run arbitrary shell commands. If you copy-paste a config file from an untrusted source, it may contain malicious commands that can harm your system or compromise your privacy. Please always review the config file before using it.
## FAQ
### Q: Neofetch is good enough. Why do I need fastfetch?
1. Fastfetch is actively maintained.
2. Fastfetch is faster, as the name suggests.
3. Fastfetch has a greater number of features, though by default it only has a few modules enabled; use `fastfetch -c all` to discover what you want.
4. Fastfetch is more configurable. You can find more information in the Wiki: .
5. Fastfetch is more polished. For example, neofetch prints `555 MiB` in the Memory module and `23 G` in the Disk module, whereas fastfetch prints `555.00 MiB` and `22.97 GiB` respectively.
6. Fastfetch is more accurate. For example, [neofetch never actually supports the Wayland protocol](https://github.com/dylanaraps/neofetch/pull/2395).
### Q: Fastfetch shows my local IP address. Does it leak my privacy?
A local IP address (10.x.x.x, 172.x.x.x, 192.168.x.x) has nothing to do with privacy. It only has meaning if you are on the same network, for example, if you connect to the same Wi-Fi network.
Actually, the `Local IP` module is the most useful module for me personally. I (@CarterLi) have several VMs installed to test fastfetch and often need to SSH into them. With fastfetch running on shell startup, I never need to type `ip addr` manually.
If you really don't like it, you can disable the `Local IP` module in `config.jsonc`.
### Q: Where is the config file? I can't find it.
Fastfetch does not generate a config file automatically. You can use `fastfetch --gen-config` to generate one. The config file will be saved in `~/.config/fastfetch/config.jsonc` by default. See the [Wiki for details](https://github.com/fastfetch-cli/fastfetch/wiki/Configuration).
### Q: The configuration is so complex. Where is the documentation?
Fastfetch uses JSON (with comments) for configuration. I suggest using an IDE with JSON schema support (like VSCode) to edit it.
Alternatively, you can refer to the presets in the [`presets` directory](https://github.com/fastfetch-cli/fastfetch/tree/dev/presets).
The **correct** way to edit the configuration:
This is an example that [changes size prefix from MiB / GiB to MB / GB](https://github.com/fastfetch-cli/fastfetch/discussions/1014). Editor used: [helix](https://github.com/helix-editor/helix)
[](https://asciinema.org/a/1uF6sTPGKrHKI1MVaFcikINSQ)
### Q: I WANT THE DOCUMENTATION!
[Here is the documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Json-Schema). It is generated from the [JSON schema](https://github.com/fastfetch-cli/fastfetch/blob/dev/doc/json_schema.json), but you might not find it very user-friendly.
### Q: How can I customize the module output?
Fastfetch uses `format` to generate output. For example, to make the `GPU` module show only the GPU name (leaving other information undisplayed), you can use:
```jsonc
{
"modules": [
{
"type": "gpu",
"format": "{name}" // See `fastfetch -h gpu-format` for details
}
]
}
```
...which is equivalent to `fastfetch -s gpu --gpu-format '{name}'`
See `fastfetch -h format` for information on basic usage. For module-specific formatting, see `fastfetch -h -format`
### Q: I have my own ASCII art / image file. How can I show it with fastfetch?
Try `fastfetch -l /path/to/logo`. See the [logo documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options) for details.
If you just want to display the distro name in [FIGlet text](https://github.com/pwaller/pyfiglet):
```bash
# install pyfiglet and jq first
pyfiglet -s -f small_slant $(fastfetch -s os --format json | jq -r '.[0].result.name') && fastfetch -l none
```

### Q: My image logo behaves strangely. How can I fix it?
See the troubleshooting section:
### Q: Fastfetch runs in black and white on shell startup. Why?
This issue usually occurs when using fastfetch with `p10k`. There are known incompatibilities between fastfetch and p10k instant prompt.
The p10k documentation clearly states that you should NOT print anything to stdout after `p10k-instant-prompt` is initialized. You should put `fastfetch` before the initialization of `p10k-instant-prompt` (recommended).
You can always use `fastfetch --pipe false` to force fastfetch to run in colorful mode.
### Q: Why do fastfetch and neofetch show different memory usage results?
See [#1096](https://github.com/fastfetch-cli/fastfetch/issues/1096).
### Q: Fastfetch shows fewer dpkg packages than neofetch. Is it a bug?
Neofetch incorrectly counts `rc` packages (packages that have been removed but still have configuration files remaining). See bug: https://github.com/dylanaraps/neofetch/issues/2278
### Q: I use Debian / Ubuntu / Debian-derived distro. My GPU is detected as `XXXX Device XXXX (VGA compatible)`. Is this a bug?
Try upgrading `pci.ids`: Download and overwrite the file `/usr/share/hwdata/pci.ids`. For AMD GPUs, you should also upgrade `amdgpu.ids`: Download and overwrite the file `/usr/share/libdrm/amdgpu.ids`
Alternatively, you may try using `fastfetch --gpu-driver-specific`, which will make fastfetch attempt to ask the driver for the GPU name if supported.
### Q: I get the error `Authorization required, but no authorization protocol specified` when running fastfetch as root
Try `export XAUTHORITY=$HOME/.Xauthority`
### Q: Fastfetch cannot detect my awesome 3rd-party macOS window manager!
Try `fastfetch --wm-detect-plugin`. See also [#984](https://github.com/fastfetch-cli/fastfetch/issues/984)
### Q: How can I change the colors of my ASCII logo?
Try `fastfetch --logo-color-[1-9] `, where `[1-9]` is the index of color placeholders.
For example: `fastfetch --logo-color-1 red --logo-color-2 green`.
In JSONC, you can use:
```jsonc
{
"logo": {
"color": {
"1": "red",
"2": "green"
}
}
}
```
### Q: How do I hide a key?
Set the key to a white space.
```jsonc
{
"key": " "
}
```
### Q: How can I display images on Windows?
As of April 2025:
#### mintty and Wezterm
mintty (used by Bash on Windows and MSYS2) and Wezterm (nightly build only) support the iTerm image protocol on Windows.
In `config.jsonc`:
```json
{
"logo": {
"type": "iterm",
"source": "C:/path/to/image.png",
"width":
}
}
```
#### Windows Terminal
Windows Terminal supports the sixel image protocol only.
* If you installed fastfetch through MSYS2:
1. Install imagemagick: `pacman -S mingw-w64--x86_64-imagemagick`
2. In `config.jsonc`:
```jsonc
{
"logo": {
"type": "sixel", // DO NOT USE "auto"
"source": "C:/path/to/image.png", // Do NOT use `~` as fastfetch is a native Windows program and doesn't apply cygwin path conversion
"width": , // Optional
"height": // Optional
}
}
```
* If you installed fastfetch via scoop or downloaded the binary directly from the GitHub Releases page:
1. Convert your image manually to sixel format using [any online image conversion service](https://www.google.com/search?q=convert+image+to+sixel)
2. In `config.jsonc`:
```jsonc
{
"logo": {
"type": "raw", // DO NOT USE "auto"
"source": "C:/path/to/image.sixel",
"width": , // Required
"height": // Required
}
}
```
### Q: I want feature A / B / C. Will fastfetch support it?
Fastfetch is a system information tool. We only accept hardware or system-level software feature requests. For most personal uses, I recommend using the `Command` module to implement custom functionality, which can be used to grab output from a custom shell script:
```jsonc
// This module shows the default editor
{
"modules": [
{
"type": "command",
"text": "$EDITOR --version | head -1",
"key": "Editor"
}
]
}
```
Otherwise, please open a feature request in [GitHub Issues](https://github.com/fastfetch-cli/fastfetch/issues).
### Q: I have questions. Where can I get help?
* For usage questions, please start a discussion in [GitHub Discussions](https://github.com/fastfetch-cli/fastfetch/discussions).
* For possible bugs, please open an issue in [GitHub Issues](https://github.com/fastfetch-cli/fastfetch/issues). Be sure to fill out the bug report template carefully to help developers investigate.
## Donate
If you find Fastfetch useful, please consider donating.
* Current maintainer: [@CarterLi](https://paypal.me/zhangsongcui)
* Original author: [@LinusDierheimer](https://github.com/sponsors/LinusDierheimer)
## Code signing
* Free code signing provided by [SignPath.io](https://about.signpath.io/), certificate by [SignPath Foundation](https://signpath.org/)
* This program will not transfer any information to other networked systems unless specifically requested by the user or the person installing or operating it
## Star History
Give us a star to show your support!
================================================
FILE: completions/fastfetch.bash
================================================
#!/usr/bin/env bash
_fastfetch() {
# Use Bash built-in variables directly
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
# Check if Python is available
if ! command -v python3 &>/dev/null; then
return
fi
# Handle standard completion cases
case "$prev" in
--color|--color-keys|--color-title|--color-output|--color-separator|--*-color|--*-key-color|--*-output-color|--logo-color-[1-9]|--percent-color-*|--temp-color-*)
local -a colors=("black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" "default")
COMPREPLY=($(compgen -W "${colors[*]}" -- "$cur"))
return
;;
--logo|-l)
local -a logos
readarray -t logos < <(fastfetch --list-logos autocompletion 2>/dev/null)
logos+=("none" "small")
COMPREPLY=($(compgen -W "${logos[*]}" -- "$cur"))
return
;;
--config|-c)
local -a presets
readarray -t presets < <(fastfetch --list-presets autocompletion 2>/dev/null)
presets+=("none")
COMPREPLY=($(compgen -W "${presets[*]}" -- "$cur"))
# Also allow file path completion
if type _filedir &>/dev/null; then
_filedir
elif type compgen &>/dev/null; then
COMPREPLY+=($(compgen -f -- "$cur"))
fi
return
;;
--structure|-s)
# Get all module names in lowercase only
local -a structures
readarray -t structures < <(fastfetch --list-modules autocompletion 2>/dev/null | cut -d':' -f1 | tr '[:upper:]' '[:lower:]')
COMPREPLY=($(compgen -W "${structures[*]}" -- "$cur"))
return
;;
--help|-h)
local -a modules
readarray -t modules < <(fastfetch --list-modules autocompletion 2>/dev/null)
# Convert to lowercase and keep only module names
local -a module_names=()
for module in "${modules[@]}"; do
module_names+=($(echo "$module" | cut -d':' -f1 | tr '[:upper:]' '[:lower:]')-format)
done
module_names+=("format" "color")
COMPREPLY=($(compgen -W "${module_names[*]}" -- "$cur"))
return
;;
--format)
COMPREPLY=($(compgen -W "json default" -- "$cur"))
return
;;
--*-format)
# Format string completion, handle spaces
return
;;
--*path*|--*file*|--gen-config*|--*data*)
# File path completion
if type _filedir &>/dev/null; then
_filedir
elif type compgen &>/dev/null; then
COMPREPLY=($(compgen -f -- "$cur"))
fi
return
;;
esac
# If not a special option, generate all possible options
if [[ "$cur" == -* ]]; then
local -a opts
readarray -t opts < <(python3 - "$cur" <<'EOF'
import json
import sys
import subprocess
def main(current):
try:
# Use fastfetch --help-raw to get option data
output = subprocess.check_output(['fastfetch', '--help-raw'], stderr=subprocess.DEVNULL)
data = json.loads(output)
for category in data.values():
for flag in category:
if flag.get("pseudo", False):
continue
if "short" in flag:
print(f"-{flag['short']}")
if "long" in flag:
if flag["long"] == "logo-color-[1-9]":
for i in range(1, 10):
print(f"--logo-color-{i}")
else:
print(f"--{flag['long']}")
except Exception:
# If error occurs, return no options
pass
if __name__ == "__main__":
main(sys.argv[1])
EOF
)
COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
fi
return 0
}
# Register completion
complete -F _fastfetch fastfetch
================================================
FILE: completions/fastfetch.fish
================================================
if not type -q fastfetch
exit
end
command -q python3
if test $status -ne 0
exit
end
complete -c fastfetch -f
function __fastfetch_complete_bool
echo -e "true\tBool"
echo -e "false\tBool"
end
function __fastfetch_complete_color
echo -e "black\tColor"
echo -e "red\tColor"
echo -e "green\tColor"
echo -e "yellow\tColor"
echo -e "blue\tColor"
echo -e "magenta\tColor"
echo -e "cyan\tColor"
echo -e "white\tColor"
echo -e "default\tColor"
end
function __fastfetch_complete_command
for line in (fastfetch --list-modules autocompletion)
set -l pair (string split -m 2 : $line)
set -l module (string lower $pair[1])
echo -e "$module-format\tModule format"
end
echo -e "format\tCustom format"
echo -e "color\tColor format"
end
function __fastfetch_complete_config
for line in (fastfetch --list-presets autocompletion)
echo -e "$line\tPreset"
end
echo -e "none\tDisable loading config file"
end
function __fastfetch_complete_logo
for line in (fastfetch --list-logos autocompletion)
echo -e "$line\tBuiltin logo"
end
echo -e "none\tDon't print logo"
echo -e "small\tPrint small ascii logo if available"
end
function __fastfetch_complete_structure
for line in (fastfetch --list-modules autocompletion)
set -l pair (string split -m 2 : $line)
echo -e "$pair[1]\t$pair[2]"
end
end
echo '
import json, subprocess, sys
def main():
data: dict[str, list[dict]] = json.loads(subprocess.check_output(["fastfetch", "--help-raw"]))
for key in data:
for flag in data[key]:
if flag["long"] == "logo-color-[1-9]":
for i in range(1, 10):
print(f"""complete -c fastfetch -d "{flag["desc"]}" -l "logo-color-{i}" -x -a "(__fastfetch_complete_color)" """)
continue
if flag.get("pseudo", False):
continue
command_prefix = f"""complete -c fastfetch -d "{flag["desc"]}" -l "{flag["long"]}\""""
if "short" in flag:
command_prefix += f""" -o {flag["short"]}"""
if "arg" in flag:
type: str = flag["arg"]["type"]
if type == "bool":
print(f"{command_prefix} -x -a \"(__fastfetch_complete_bool)\"")
elif type == "color":
print(f"{command_prefix} -x -a \"(__fastfetch_complete_color)\"")
elif type == "command":
print(f"{command_prefix} -x -a \"(__fastfetch_complete_command)\"")
elif type == "config":
print(f"{command_prefix} -x -a \"(__fastfetch_complete_config)\"")
elif type == "enum":
temp: str = " ".join(flag["arg"]["enum"])
print(f"{command_prefix} -x -a \"{temp}\"")
elif type == "logo":
print(f"{command_prefix} -x -a \"(__fastfetch_complete_logo)\"")
elif type == "structure":
print(f"{command_prefix} -x -a \"(__fish_complete_list : __fastfetch_complete_structure)\"")
elif type == "path":
print(f"{command_prefix} -r -F")
else:
print(f"{command_prefix} -x")
else:
print(f"{command_prefix} -f")
if __name__ == "__main__":
try:
main()
except:
sys.exit(1)
' | python3 | source
================================================
FILE: completions/fastfetch.zsh
================================================
#compdef fastfetch
function _fastfetch() {
whence python3 &> /dev/null
if [ $? -ne 0 ]
then
return
fi
local state
local -a opts=("${(f)$(
python3 <colors")
elif type == "command":
print(f"{command_prefix}::module:->modules")
elif type == "config":
print(f"{command_prefix}:preset:->presets")
elif type == "enum":
temp: str = " ".join(flag["arg"]["enum"])
print(f'{command_prefix}:type:({temp})')
elif type == "logo":
print(f"{command_prefix}:logo:->logos")
elif type == "structure":
print(f"{command_prefix}:structure:->structures")
elif type == "path":
print(f"{command_prefix}::path:_files")
else:
print(f"{command_prefix}:")
else:
print(f"{command_prefix}")
if __name__ == "__main__":
try:
main()
except Exception:
sys.exit(1)
EOF
)}")
_arguments "$opts[@]"
case $state in
colors)
local -a colors=(black red green yellow blue magenta cyan white default)
_describe 'color' colors
;;
modules)
local -a modules=("${(f)$(fastfetch --list-modules autocompletion)}")
modules=(${(L)^modules[@]%%:*}-format format color)
_describe 'module' modules
;;
presets)
local -a presets=(
"${(f)$(fastfetch --list-presets autocompletion)}"
"none:Disable loading config file"
)
_describe 'preset' presets || _files
;;
structures)
local -a structures=("${(f)$(fastfetch --list-modules autocompletion)}")
_describe 'structure' structures
;;
logos)
local -a logos=(
"${(f)$(fastfetch --list-logos autocompletion)}"
"none:Don't print logo"
"small:Print small ascii logo if available"
)
_describe 'logo' logos
;;
esac
}
_fastfetch "$@"
================================================
FILE: debian/changelog.tpl
================================================
fastfetch (2.58.0~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.58.0
-- Carter Li Thu, 22 Jan 2026 15:30:58 +0800
fastfetch (2.57.1~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.57.1
-- Carter Li Wed, 14 Jan 2026 14:00:17 +0800
fastfetch (2.57.0~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.57.0
-- Carter Li Mon, 12 Jan 2026 10:11:21 +0800
fastfetch (2.56.1~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.56.1
-- Carter Li Thu, 18 Dec 2025 14:57:36 +0800
fastfetch (2.56.0~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.56.0
-- Carter Li Mon, 08 Dec 2025 09:21:58 +0800
fastfetch (2.55.1~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.55.1
-- Carter Li Mon, 17 Nov 2025 10:15:44 +0800
fastfetch (2.55.0~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.55.0
-- Carter Li Wed, 12 Nov 2025 09:15:24 +0800
fastfetch (2.54.1~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Fix building on plucky
-- Carter Li Mon, 20 Oct 2025 14:27:02 +0800
fastfetch (2.54.0~#UBUNTU_CODENAME#) #UBUNTU_CODENAME#; urgency=medium
* Update to 2.54.0
* Test independent changelog entries for different Ubuntu releases
-- Carter Li Mon, 20 Oct 2025 10:47:02 +0800
fastfetch (2.53.0) jammy; urgency=medium
* Update to 2.53.0
-- Carter Li Tue, 23 Sep 2025 09:58:48 +0800
fastfetch (2.52.0) jammy; urgency=medium
* Update to 2.52.0
-- Carter Li Fri, 05 Sep 2025 14:59:44 +0800
fastfetch (2.51.0) jammy; urgency=medium
* Update to 2.51.0
-- Carter Li Fri, 29 Aug 2025 08:55:03 +0800
fastfetch (2.50.2) jammy; urgency=medium
* Update to 2.50.2
-- Carter Li Thu, 21 Aug 2025 10:33:07 +0800
fastfetch (2.49.0) jammy; urgency=medium
* Update to 2.49.0
-- Carter Li Thu, 31 Jul 2025 14:32:59 +0800
fastfetch (2.48.0) jammy; urgency=medium
* Update to 2.48.0
-- Carter Li Thu, 17 Jul 2025 16:16:52 +0800
fastfetch (2.47.0) jammy; urgency=medium
* Update to 2.47.0
-- Carter Li Thu, 03 Jul 2025 14:51:45 +0800
fastfetch (2.46.0) jammy; urgency=medium
* Update to 2.46.0
-- Carter Li Fri, 20 Jun 2025 15:01:21 +0800
fastfetch (2.45.0) jammy; urgency=medium
* Update to 2.45.0
-- Carter Li Thu, 05 Jun 2025 10:56:38 +0800
fastfetch (2.44.0) jammy; urgency=medium
* Update to 2.44.0
-- Carter Li Mon, 26 May 2025 14:59:01 +0800
fastfetch (2.43.0) jammy; urgency=medium
* Update to 2.43.0
-- Carter Li Wed, 14 May 2025 09:49:50 +0800
fastfetch (2.42.0) jammy; urgency=medium
* Update to 2.42.0
-- Carter Li Wed, 30 Apr 2025 14:08:57 +0800
fastfetch (2.41.0) jammy; urgency=medium
* Update to 2.41.0
-- Carter Li Wed, 16 Apr 2025 13:42:58 +0800
fastfetch (2.40.4) jammy; urgency=medium
* Update to 2.40.4
-- Carter Li Thu, 10 Apr 2025 15:38:21 +0800
fastfetch (2.40.3) jammy; urgency=medium
* Update to 2.40.3
-- Carter Li Mon, 07 Apr 2025 09:29:27 +0800
fastfetch (2.40.0) jammy; urgency=medium
* Update to 2.40.0
-- Carter Li Thu, 03 Apr 2025 08:46:54 +0800
fastfetch (2.39.1) jammy; urgency=medium
* Update to 2.39.1
-- Carter Li Fri, 21 Mar 2025 11:02:19 +0800
fastfetch (2.39.0ubuntu1) jammy; urgency=medium
* Remove unwanted debugging code
-- Carter Li Thu, 20 Mar 2025 10:39:22 +0800
fastfetch (2.39.0) jammy; urgency=medium
* Update to 2.39.0
-- Carter Li Thu, 20 Mar 2025 10:35:18 +0800
fastfetch (2.38.0) jammy; urgency=medium
* Update to 2.38.0
-- Carter Li Wed, 05 Mar 2025 14:56:24 +0800
fastfetch (2.37.0) jammy; urgency=medium
* Update to 2.37.0
-- Carter Li Wed, 19 Feb 2025 15:43:42 +0800
fastfetch (2.36.1) jammy; urgency=medium
* Update to 2.36.1
-- Carter Li Tue, 11 Feb 2025 13:39:55 +0800
fastfetch (2.36.0) jammy; urgency=medium
* Update to 2.36.0
-- Carter Li Mon, 10 Feb 2025 10:13:53 +0800
fastfetch (2.35.0) jammy; urgency=medium
* Update to 2.35.0
-- Carter Li Sun, 26 Jan 2025 10:15:22 +0800
fastfetch (2.34.1) jammy; urgency=medium
* Update to 2.34.1
-- Carter Li Mon, 13 Jan 2025 16:06:22 +0800
fastfetch (2.34.0) jammy; urgency=medium
* Update to 2.34.0
-- Carter Li Thu, 09 Jan 2025 09:03:17 +0800
fastfetch (2.33.0) jammy; urgency=medium
* Update to 2.33.0
-- Carter Li Thu, 26 Dec 2024 09:42:27 +0800
fastfetch (2.32.0) jammy; urgency=medium
* Update to 2.32.0
-- Carter Li Wed, 18 Dec 2024 10:39:06 +0800
fastfetch (2.31.0) jammy; urgency=medium
* Update to 2.31.0
-- Carter Li Wed, 04 Dec 2024 08:41:40 +0800
fastfetch (2.30.1) jammy; urgency=medium
* Update to 2.30.1
-- Carter Li Mon, 18 Nov 2024 15:40:48 +0800
fastfetch (2.30.0) jammy; urgency=medium
* Update to 2.30.0
-- Carter Li Mon, 18 Nov 2024 09:30:58 +0800
fastfetch (2.29.0) jammy; urgency=medium
* Update to 2.29.0
-- Carter Li Mon, 04 Nov 2024 15:05:02 +0800
fastfetch (2.28.0) jammy; urgency=medium
* Update to 2.28.0
-- Carter Li Wed, 23 Oct 2024 10:18:59 +0800
fastfetch (2.27.1) jammy; urgency=medium
* Update to 2.27.1
-- Carter Li Sun, 06 Oct 2024 12:55:18 +0800
fastfetch (2.26.1ubuntu1) jammy; urgency=medium
* Update correct code
-- Carter Li Mon, 30 Sep 2024 00:21:20 +0800
fastfetch (2.26.1) jammy; urgency=medium
* Update to 2.26.1
-- Carter Li Sun, 29 Sep 2024 16:15:31 +0800
fastfetch (2.26.0) jammy; urgency=medium
* Update to 2.26.0
-- Carter Li Sun, 29 Sep 2024 13:31:25 +0800
fastfetch (2.25.0) jammy; urgency=medium
* Update to 2.25.0
-- Carter Li Thu, 19 Sep 2024 10:28:38 +0800
fastfetch (2.24.0) jammy; urgency=medium
* Update to 2.24.0
-- Carter Li Wed, 11 Sep 2024 13:50:02 +0800
fastfetch (2.23.0) jammy; urgency=medium
* Update to 2.23.0
-- Carter Li Tue, 03 Sep 2024 18:44:11 +0800
fastfetch (2.22.0) jammy; urgency=medium
* Update to 2.22.0
-- Carter Li Mon, 26 Aug 2024 18:53:35 +0800
fastfetch (2.21.3) jammy; urgency=medium
* Update to 2.21.3
-- Carter Li Thu, 15 Aug 2024 16:14:52 +0800
fastfetch (2.21.2) jammy; urgency=medium
* Update to 2.21.2
-- Carter Li Wed, 14 Aug 2024 14:42:07 +0800
fastfetch (2.21.1) jammy; urgency=medium
* Update to 2.21.1
-- Carter Li Fri, 09 Aug 2024 14:27:10 +0800
fastfetch (2.21.0) jammy; urgency=medium
* Update to 2.21.0
-- Carter Li Mon, 05 Aug 2024 14:35:43 +0800
fastfetch (2.20.0) jammy; urgency=medium
* Update to 2.20.0
-- Carter Li Fri, 26 Jul 2024 14:02:50 +0800
fastfetch (2.19.1) jammy; urgency=medium
* Update to 2.19.1
-- Carter Li Tue, 23 Jul 2024 10:25:14 +0800
fastfetch (2.19.0) jammy; urgency=medium
* Update to 2.19.0
-- Carter Li Mon, 22 Jul 2024 14:17:55 +0800
fastfetch (2.18.1) jammy; urgency=medium
* Update to 2.18.1
-- Carter Li Thu, 11 Jul 2024 14:32:15 +0800
fastfetch (2.18.0) jammy; urgency=medium
* Update to 2.18.0
-- Carter Li Wed, 10 Jul 2024 16:46:32 +0800
fastfetch (2.17.2) jammy; urgency=medium
* Update to 2.17.2
-- Carter Li Thu, 04 Jul 2024 10:22:44 +0800
fastfetch (2.17.1) jammy; urgency=medium
* Update to 2.17.1
-- Carter Li Mon, 01 Jul 2024 08:56:29 +0800
fastfetch (2.17.0) jammy; urgency=medium
* Update to 2.17.0
-- Carter Li Fri, 28 Jun 2024 13:43:18 +0800
fastfetch (2.16.0) jammy; urgency=medium
* Update to 2.16.0
-- Carter Li Wed, 19 Jun 2024 14:53:43 +0800
fastfetch (2.15.0) jammy; urgency=medium
* Update to 2.15.0
-- Carter Li Fri, 07 Jun 2024 13:52:43 +0800
fastfetch (2.14.0) jammy; urgency=medium
* Update to 2.14.0
-- Carter Li Thu, 30 May 2024 14:27:54 +0800
fastfetch (2.13.2) jammy; urgency=medium
* Update to 2.13.2
-- Carter Li Fri, 24 May 2024 13:48:59 +0800
fastfetch (2.13.1) jammy; urgency=medium
* Update to 2.13.1
-- Carter Li Tue, 21 May 2024 15:10:37 +0800
fastfetch (2.12.0) jammy; urgency=medium
* Update to 2.12.0
-- Carter Li Tue, 14 May 2024 16:33:33 +0800
fastfetch (2.11.5) jammy; urgency=medium
* Update to 2.11.5
-- Carter Li Tue, 07 May 2024 09:30:05 +0800
fastfetch (2.11.3) jammy; urgency=medium
* Update to 2.11.3
-- Carter Li Mon, 06 May 2024 08:46:45 +0800
fastfetch (2.10.2) jammy; urgency=medium
* Update to 2.10.2
-- Carter Li Tue, 23 Apr 2024 15:18:23 +0800
fastfetch (2.10.1) jammy; urgency=medium
* Update to 2.10.1
-- Carter Li Tue, 23 Apr 2024 09:55:02 +0800
fastfetch (2.9.2) jammy; urgency=medium
* Update to 2.9.2
-- Carter Li Tue, 16 Apr 2024 16:32:40 +0800
fastfetch (2.9.1) jammy; urgency=medium
* Update to 2.9.1
-- Carter Li Mon, 08 Apr 2024 09:34:30 +0800
fastfetch (2.8.10) jammy; urgency=medium
* Update to 2.8.10
-- Carter Li Mon, 25 Mar 2024 15:01:53 +0800
fastfetch (2.8.9) jammy; urgency=medium
* Update to 2.8.9
-- Carter Li Fri, 15 Mar 2024 10:49:42 +0800
fastfetch (2.8.8) jammy; urgency=medium
* Update to 2.8.8
-- Carter Li Fri, 08 Mar 2024 09:59:41 +0800
fastfetch (2.8.6) jammy; urgency=medium
* Update to 2.8.6
-- Carter Li Wed, 28 Feb 2024 10:01:40 +0800
fastfetch (2.8.4) jammy; urgency=medium
* Update to 2.8.4
-- Carter Li Fri, 23 Feb 2024 16:14:57 +0800
fastfetch (2.7.1ubuntu2) jammy; urgency=medium
* Ignore .git
-- Carter Li Wed, 07 Feb 2024 14:23:23 +0800
fastfetch (2.7.1ubuntu1) jammy; urgency=medium
* Update build scripts
-- Carter Li Wed, 07 Feb 2024 13:53:37 +0800
fastfetch (2.7.1) jammy; urgency=medium
* Initial release.
-- Carter Li Tue, 06 Feb 2024 15:01:11 +0800
================================================
FILE: debian/compat
================================================
12
================================================
FILE: debian/control
================================================
Source: fastfetch
Section: universe/utils
Priority: optional
Maintainer: Carter Li
Build-Depends: libelf-dev, libvulkan-dev, libwayland-dev, libxrandr-dev, libxcb-randr0-dev, libdconf-dev, libdbus-1-dev, libmagickcore-dev, libsqlite3-dev, librpm-dev, libegl-dev, libglx-dev, ocl-icd-opencl-dev, libpulse-dev, libdrm-dev, libddcutil-dev, libchafa-dev, directx-headers-dev, pkgconf, cmake (>= 3.12), debhelper (>= 11.2), dh-cmake, dh-cmake-compat (= 1), dh-sequence-cmake, dh-sequence-ctest, ninja-build, python3-setuptools
Standards-Version: 4.0.0
Homepage: https://github.com/fastfetch-cli/fastfetch
Package: fastfetch
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Fastfetch is a neofetch-like tool for fetching system information and displaying them in a pretty way.
It is written mainly in C, with performance and customizability in mind.
================================================
FILE: debian/copyright
================================================
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: fastfetch
Source: https://github.com/fastfetch-cli/fastfetch
Files: *
Copyright: 2024 fastfetch-cli
License: Expat
Files: src/3rdparty/yyjson/*
Copyright: 2020 YaoYuan
License: Expat
================================================
FILE: debian/publish.sh
================================================
#!/usr/bin/env bash
# WARNING: DO NOT RUN THIS SCRIPT UNLESS YOU KNOW WHAT YOU ARE DOING.
set -euo pipefail
command -v debuild >/dev/null 2>&1 || { echo "debuild not found. Install devscripts." >&2; exit 1; }
command -v dput >/dev/null 2>&1 || { echo "dput not found." >&2; exit 1; }
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)"
OUT_DIR="$(dirname "$ROOT_DIR")"
PPA="ppa:zhangsongcui3371/fastfetch"
CODENAMES=( jammy noble plucky questing resolute )
DRY_RUN=0
if [[ -d "$OUT_DIR/build" ]]; then
echo "Output directory exists: $OUT_DIR/build" >&2
echo "Please move or delete it before proceeding." >&2
exit 1
fi
TEMPLATE="$ROOT_DIR/debian/changelog.tpl"
CHANGELOG_DEBIAN="$ROOT_DIR/debian/changelog"
if [[ ! -f "$TEMPLATE" ]]; then
echo "Template not found: $TEMPLATE" >&2
exit 1
fi
if ! grep -q '#UBUNTU_CODENAME#' "$TEMPLATE"; then
echo "Template missing placeholder: #UBUNTU_CODENAME#" >&2
exit 1
fi
echo "IMPORTANT: Before proceeding, please ensure that 'debian/changelog.tpl' is up-to-date"
echo " with the correct version number, release notes, and maintainer information."
echo
echo " The template must contain a placeholder like '#UBUNTU_CODENAME#' for the codename."
echo
read -p "Have you reviewed and updated 'debian/changelog.tpl'? (y/N): " -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
cleanup() {
rm -f "$CHANGELOG_DEBIAN"
rm -f "$ROOT_DIR/debian/files"
}
trap cleanup EXIT
shopt -s nullglob
for codename in "${CODENAMES[@]}"; do
echo "==> Publishing distro: $codename"
sed "s/#UBUNTU_CODENAME#/${codename}/g" "$TEMPLATE" > "$CHANGELOG_DEBIAN"
( cd "$ROOT_DIR" && debuild -S -i -I )
changes=( "$OUT_DIR"/fastfetch_*~${codename}_source.changes )
if [[ ${#changes[@]} -ne 1 ]]; then
echo "Unable to uniquely identify .changes for '$codename' in: $OUT_DIR" >&2
printf 'Found:\n'; printf ' %s\n' "${changes[@]}" >&2 || true
exit 1
fi
if [[ $DRY_RUN -eq 1 ]]; then
echo "[DRY-RUN] dput \"$PPA\" \"${changes[0]}\""
else
dput "$PPA" "${changes[0]}"
fi
rm -f "$OUT_DIR"/fastfetch_*~${codename}_source.{changes,dsc,tar.*}
echo "<== Done: $codename"
done
================================================
FILE: debian/rules
================================================
#!/usr/bin/make -f
%:
dh $@ --buildsystem=cmake+ninja
override_dh_ctest_configure:
dh_ctest_configure -- -DSET_TWEAK=OFF -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
================================================
FILE: debian/watch
================================================
version=4
opts="filenamemangle=s%.*/@ANY_VERSION@%@PACKAGE@-$1.tar.gz%,searchmode=plain" \
https://api.github.com/repos/fastfetch-cli/fastfetch/releases?per_page=100 \
https://api.github.com/repos/fastfetch-cli/fastfetch/tarball/@ANY_VERSION@
================================================
FILE: doc/fastfetch.1.in
================================================
.TH FASTFETCH 1 "@FASTFETCH_BUILD_DATE@" "@CMAKE_PROJECT_NAME@ @CMAKE_PROJECT_VERSION@"
.SH NAME
fastfetch \- a fast and customizable system information tool similar to neofetch
.SH SYNOPSIS
.B fastfetch
.I [options...]
.SH DESCRIPTION
Fastfetch is a tool for displaying system information in a visually appealing way. Written primarily in C, it focuses on performance and customizability while providing functionality similar to neofetch.
It supports Linux, Android, *BSD, macOS, Haiku, and Windows 7 or newer.
.SH "EXIT STATUS"
Fastfetch returns zero on successful execution. Any errors result in a non-zero exit code.
.SH OPTIONS
.SS "Informative Options"
.TP
.B \-h, \-\-help \fI[command]
Display help information for all available options or for a specific command
.TP
.B \-v, \-\-version
Display the version of fastfetch
.TP
.B \-\-version\-raw
Display the raw version string (major.minor.patch)
.TP
.B \-\-list\-config\-paths
List search paths for configuration files
.TP
.B \-\-list\-data\-paths
List search paths for presets and logos
.TP
.B \-\-list\-logos
List available logos that can be loaded with \fI\-\-logo
.TP
.B \-\-list\-modules
List all available modules
.TP
.B \-\-list\-presets
List available presets that can be loaded with \fI\-\-config
.TP
.B \-\-list\-features
List the features that fastfetch was compiled with (mainly for development)
.TP
.B \-\-print\-logos
Display all available logos
.TP
.B \-\-print\-structure
Display the default structure
.TP
.B \-\-format \fI
Set the output format. Available options are:
.RS
.IP \(bu 2
\fIdefault\fR: Default human-readable format
.IP \(bu 2
\fIjson\fR: JSON format for machine processing
.RE
.SS "Config Options"
.TP
.B \-c, \-\-config \fI
Use the specified config file or preset. Specify \fInone\fR to disable further config loading. See the CONFIGURATION section for details on config files.
.TP
.B \-\-gen\-config \fI[path]
Generate a config file with options specified on the command line. If \fIpath\fR is not specified, it defaults to \fB~/.config/fastfetch/config.jsonc\fR. If \fIpath\fR is "\-", the configuration will be written to stdout.
.TP
.B \-\-gen\-config\-force \fI[path]
Same as \fB\-\-gen\-config\fR, but overwrites any existing file at the destination path.
.TP
.SS "Logo Options"
.TP
.B \-l, \-\-logo \fI
Set the logo to display. Can be the name of a built-in logo or a path to an image file. Use \fInone\fR to disable the logo.
.TP
.B \-\-logo\-type \fI
Set the type of the logo specified with \fI\-\-logo\fR. Available types include \fIauto\fR, \fIbuiltin\fR, \fIfile\fR, \fIsixel\fR, \fIkitty\fR, and others. See \fB\-\-help logo\-type\fR for details.
.TP
.B \-\-logo\-width \fI
Set the width of the logo in characters (for image logos)
.TP
.B \-\-logo\-height \fI
Set the height of the logo in characters (for image logos)
.TP
.B \-\-logo\-color\-[1\-9] \fI
Override specific colors in the logo
.SS "Display Options"
.TP
.B \-s, \-\-structure \fI
Set the structure of the fetch (a colon-separated list of module names)
.TP
.B \-\-color \fI
Set the color of keys and title. See \fB\-\-help color\fR for available colors.
.TP
.B \-\-color\-keys \fI
Set the color of keys only
.TP
.B \-\-color\-title \fI
Set the color of the title only
.TP
.B \-\-separator \fI
Set the separator between key and value (default: ": ")
.TP
.B \-\-key\-width \fI
Align the width of keys to \fI\fR characters
.TP
.B \-\-show\-errors
Display errors when they occur (default: false)
.TP
.B \-\-pipe
Disable colors (automatically detected based on whether stdout is a terminal)
To list all available options including module-specific options, use \fB\-\-help\fR.
.SH CONFIGURATION
.SS "Fetch Structure"
The structure defines which modules to display and in what order. It consists of module names separated by colons (:).
For example: \fBtitle:separator:os:kernel:uptime\fR
To list all available modules, use \fB\-\-list\-modules\fR
.SS "Config Files"
Fastfetch uses JSONC for configuration files. JSONC is JSON with support for comments (// and /* */). Configuration files must have the .jsonc extension.
You can generate a default config file using \fB\-\-gen\-config\fR. By default, the config file is saved at \fB~/.config/fastfetch/config.jsonc\fR.
The configuration/preset files are searched in the following locations (in order):
.RS
.IP 1. 4
Relative to the current working directory
.IP 2. 4
Relative to ~/.local/share/fastfetch/presets/
.IP 3. 4
Relative to /usr/share/fastfetch/presets/
.RE
For detailed information on logo options, module configuration, and formatting, visit:
.RS
\fIhttps://github.com/fastfetch-cli/fastfetch/wiki/Configuration\fR
.RE
Fastfetch provides several built-in presets. List them with \fB\-\-list\-presets\fR.
.SS "JSON Schema"
A JSON schema is available for editor intelligence when editing the configuration file. Add the following line at the beginning of your config file:
.PP
\fB"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"\fR
.SH EXAMPLES
.TP
Basic usage:
.RS
\fBfastfetch\fR
.RE
.TP
Use a specific logo:
.RS
\fBfastfetch \-\-logo arch\fR
.RE
.TP
Custom structure:
.RS
\fBfastfetch \-\-structure title:os:kernel:uptime:memory\fR
.RE
.TP
Generate a config file:
.RS
\fBfastfetch \-\-gen\-config\fR
.RE
.TP
Use a preset:
.RS
\fBfastfetch \-\-config neofetch\fR
.RE
.SH "SEE ALSO"
.BR neofetch (1)
.SH BUGS
Please report bugs to: \fIhttps://github.com/fastfetch\-cli/fastfetch/issues\fR
.SH AUTHORS
Fastfetch is developed by a team of contributors on GitHub.
Visit \fIhttps://github.com/fastfetch-cli/fastfetch\fR for more information.
================================================
FILE: doc/json_schema.json
================================================
{
"$schema": "https://json-schema.org/draft-07/schema",
"$defs": {
"colors": {
"oneOf": [
{
"type": "string",
"$comment": "https://github.com/fastfetch-cli/fastfetch/wiki/Color-Format-Specification",
"examples": [
"reset_", "bright_", "dim_", "italic_", "underline_", "blink_", "inverse_", "hidden_", "strike_", "light_",
"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "default"
]
},
{
"type": "null",
"$comment": "Disable default color"
}
]
},
"key": {
"description": "Key of the module\nOne whitespace character (` `) can be used to hide the key",
"type": "string",
"minLength": 1
},
"keyColor": {
"description": "Color of the module key to override the global setting `display.color.key`",
"$ref": "#/$defs/colors"
},
"keyWidth": {
"description": "Width of the module key to override the global setting `display.keyWidth`",
"type": "integer",
"minimum": 1
},
"keyIcon": {
"description": "Set the icon to be displayed by `display.keyType: \"icon\"`",
"type": "string"
},
"outputColor": {
"description": "Output color of the module to override the global setting `display.color.output`",
"$ref": "#/$defs/colors"
},
"percentType": {
"description": "Set the percentage output type",
"oneOf": [
{
"type": "number",
"description": "0 to use global setting, 1 for percentage number, 2 for multi-color bar, 3 for both, 6 for bar only, 9 for colored number, 10 for monochrome bar",
"minimum": 0,
"maximum": 255,
"default": 9
},
{
"type": "array",
"description": "Array of string flags",
"items": {
"enum": [
"num",
"bar",
"hide-others",
"num-color",
"bar-monochrome"
]
},
"uniqueItems": true,
"default": [
"num",
"num-color"
]
}
]
},
"percent": {
"description": "Thresholds for percentage colors",
"type": "object",
"additionalProperties": false,
"properties": {
"green": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"description": "Values less than green will be shown in green"
},
"yellow": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"description": "Values greater than green and less than yellow will be shown in yellow.\nValues greater than yellow will be shown in red"
},
"type": {
"$ref": "#/$defs/percentType"
}
}
},
"temperature": {
"description": "Detect and display temperature if supported",
"oneOf": [
{
"type": "boolean",
"default": false
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"green": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"description": "Values (in celsius) less than green will be shown in green"
},
"yellow": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"description": "Values (in celsius) greater than green and less than yellow will be shown in yellow.\nValues greater than yellow will be shown in red"
}
}
}
]
},
"systems": {
"type": "string",
"enum": [
"Android",
"Linux",
"DragonFly",
"MidnightBSD",
"FreeBSD",
"macOS",
"Windows",
"SunOS",
"OpenBSD",
"NetBSD",
"Haiku"
]
},
"architectures": {
"type": "string",
"enum": [
"x86_64",
"i386",
"ia64",
"aarch64",
"arm",
"mips",
"powerpc",
"riscv",
"s390x",
"loongarch",
"sparc",
"alpha",
"hppa",
"m68k"
]
},
"conditions": {
"description": "Only show the module if conditions are met",
"type": "object",
"additionalProperties": false,
"properties": {
"system": {
"description": "System name to match",
"oneOf": [
{
"$ref": "#/$defs/systems"
},
{
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/$defs/systems"
},
"description": "Array of system names to match"
},
{
"type": "null",
"description": "Null to disable this condition"
}
]
},
"!system": {
"description": "System name to not match",
"oneOf": [
{
"$ref": "#/$defs/systems"
},
{
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/$defs/systems"
},
"description": "Array of system names to not match"
},
{
"type": "null",
"description": "Null to disable this condition"
}
]
},
"arch": {
"description": "Architecture to match",
"oneOf": [
{
"$ref": "#/$defs/architectures"
},
{
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/$defs/architectures"
},
"description": "Array of architectures to match"
},
{
"type": "null",
"description": "Null to disable this condition"
}
]
},
"!arch": {
"description": "Architecture to not match",
"oneOf": [
{
"$ref": "#/$defs/architectures"
},
{
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/$defs/architectures"
},
"description": "Array of architectures to not match"
},
{
"type": "null",
"description": "Null to disable this condition"
}
]
},
"succeeded": {
"description": "Whether the module succeeded in the last run",
"oneOf": [
{
"type": "boolean",
"description": "True to only show the module if it succeeded, false to only show it if it failed"
},
{
"type": "null",
"description": "Null to disable this condition"
}
]
}
}
},
"spaceBeforeUnit": {
"type": "string",
"description": "Whether to put a space before the unit",
"oneOf": [
{
"const": "default",
"description": "Use the default behavior of the module"
},
{
"const": "always",
"description": "Always add a space before the unit"
},
{
"const": "never",
"description": "Never add a space before the unit"
}
]
},
"batteryFormat": {
"description": "Output format of the module `Battery`. See Wiki for formatting syntax\n 1. {manufacturer}: Battery manufacturer\n 2. {model-name}: Battery model name\n 3. {technology}: Battery technology\n 4. {capacity}: Battery capacity (percentage num)\n 5. {status}: Battery status\n 6. {temperature}: Battery temperature (formatted)\n 7. {cycle-count}: Battery cycle count\n 8. {serial}: Battery serial number\n 9. {manufacture-date}: Battery manufactor date\n 10. {capacity-bar}: Battery capacity (percentage bar)\n 11. {time-days}: Battery time remaining days\n 12. {time-hours}: Battery time remaining hours\n 13. {time-minutes}: Battery time remaining minutes\n 14. {time-seconds}: Battery time remaining seconds\n 15. {time-formatted}: Battery time remaining (formatted)",
"type": "string"
},
"biosFormat": {
"description": "Output format of the module `BIOS`. See Wiki for formatting syntax\n 1. {date}: Bios date\n 2. {release}: Bios release\n 3. {vendor}: Bios vendor\n 4. {version}: Bios version\n 5. {type}: Firmware type",
"type": "string"
},
"bluetoothFormat": {
"description": "Output format of the module `Bluetooth`. See Wiki for formatting syntax\n 1. {name}: Name\n 2. {address}: Address\n 3. {type}: Type\n 4. {battery-percentage}: Battery percentage number\n 5. {connected}: Is connected\n 6. {battery-percentage-bar}: Battery percentage bar",
"type": "string"
},
"bluetoothradioFormat": {
"description": "Output format of the module `BluetoothRadio`. See Wiki for formatting syntax\n 1. {name}: Radio name for discovering\n 2. {address}: Address\n 3. {lmp-version}: LMP version\n 4. {lmp-subversion}: LMP subversion\n 5. {version}: Bluetooth version\n 6. {vendor}: Vendor\n 7. {discoverable}: Discoverable\n 8. {connectable}: Connectable / Pairable",
"type": "string"
},
"boardFormat": {
"description": "Output format of the module `Board`. See Wiki for formatting syntax\n 1. {name}: Board name\n 2. {vendor}: Board vendor\n 3. {version}: Board version\n 4. {serial}: Board serial number",
"type": "string"
},
"bootmgrFormat": {
"description": "Output format of the module `Bootmgr`. See Wiki for formatting syntax\n 1. {name}: Name / description\n 2. {firmware-path}: Firmware file path\n 3. {firmware-name}: Firmware file name\n 4. {secure-boot}: Is secure boot enabled\n 5. {order}: Boot order",
"type": "string"
},
"brightnessFormat": {
"description": "Output format of the module `Brightness`. See Wiki for formatting syntax\n 1. {percentage}: Screen brightness (percentage num)\n 2. {name}: Screen name\n 3. {max}: Maximum brightness value\n 4. {min}: Minimum brightness value\n 5. {current}: Current brightness value\n 6. {percentage-bar}: Screen brightness (percentage bar)\n 7. {is-builtin}: Is built-in screen",
"type": "string"
},
"btrfsFormat": {
"description": "Output format of the module `Btrfs`. See Wiki for formatting syntax\n 1. {name}: Name / Label\n 2. {uuid}: UUID\n 3. {devices}: Associated devices\n 4. {features}: Enabled features\n 5. {used}: Size used\n 6. {allocated}: Size allocated\n 7. {total}: Size total\n 8. {used-percentage}: Used percentage num\n 9. {allocated-percentage}: Allocated percentage num\n 10. {used-percentage-bar}: Used percentage bar\n 11. {allocated-percentage-bar}: Allocated percentage bar\n 12. {node-size}: Node size\n 13. {sector-size}: Sector size",
"type": "string"
},
"cameraFormat": {
"description": "Output format of the module `Camera`. See Wiki for formatting syntax\n 1. {name}: Device name\n 2. {vendor}: Vendor\n 3. {colorspace}: Color space\n 4. {id}: Identifier\n 5. {width}: Width (in px)\n 6. {height}: Height (in px)",
"type": "string"
},
"chassisFormat": {
"description": "Output format of the module `Chassis`. See Wiki for formatting syntax\n 1. {type}: Chassis type\n 2. {vendor}: Chassis vendor\n 3. {version}: Chassis version\n 4. {serial}: Chassis serial number",
"type": "string"
},
"commandFormat": {
"description": "Output format of the module `Command`. See Wiki for formatting syntax\n 1. {result}: Command result",
"type": "string"
},
"cpuFormat": {
"description": "Output format of the module `CPU`. See Wiki for formatting syntax\n 1. {name}: Name\n 2. {vendor}: Vendor\n 3. {cores-physical}: Physical core count\n 4. {cores-logical}: Logical core count\n 5. {cores-online}: Online core count\n 6. {freq-base}: Base frequency (formatted)\n 7. {freq-max}: Max frequency (formatted)\n 8. {temperature}: Temperature (formatted)\n 9. {core-types}: Logical core count grouped by frequency\n 10. {packages}: Processor package count\n 11. {march}: CPU microarchitecture\n 12. {numa-nodes}: NUMA node count",
"type": "string"
},
"cpucacheFormat": {
"description": "Output format of the module `CPUCache`. See Wiki for formatting syntax\n 1. {result}: Separate result\n 2. {sum}: Sum result",
"type": "string"
},
"cpuusageFormat": {
"description": "Output format of the module `CPUUsage`. See Wiki for formatting syntax\n 1. {avg}: CPU usage (percentage num, average)\n 2. {max}: CPU usage (percentage num, maximum)\n 3. {max-index}: CPU core index of maximum usage\n 4. {min}: CPU usage (percentage num, minimum)\n 5. {min-index}: CPU core index of minimum usage\n 6. {avg-bar}: CPU usage (percentage bar, average)\n 7. {max-bar}: CPU usage (percentage bar, maximum)\n 8. {min-bar}: CPU usage (percentage bar, minimum)",
"type": "string"
},
"cursorFormat": {
"description": "Output format of the module `Cursor`. See Wiki for formatting syntax\n 1. {theme}: Cursor theme\n 2. {size}: Cursor size",
"type": "string"
},
"datetimeFormat": {
"description": "Output format of the module `DateTime`. See Wiki for formatting syntax\n 1. {year}: Year\n 2. {year-short}: Last two digits of year\n 3. {month}: Month\n 4. {month-pretty}: Month with leading zero\n 5. {month-name}: Month name\n 6. {month-name-short}: Month name short\n 7. {week}: Week number on year\n 8. {weekday}: Weekday\n 9. {weekday-short}: Weekday short\n 10. {day-in-year}: Day in year\n 11. {day-in-month}: Day in month\n 12. {day-in-week}: Day in week\n 13. {hour}: Hour\n 14. {hour-pretty}: Hour with leading zero\n 15. {hour-12}: Hour 12h format\n 16. {hour-12-pretty}: Hour 12h format with leading zero\n 17. {minute}: Minute\n 18. {minute-pretty}: Minute with leading zero\n 19. {second}: Second\n 20. {second-pretty}: Second with leading zero\n 21. {offset-from-utc}: Offset from UTC in the ISO 8601 format\n 22. {timezone-name}: Locale-dependent timezone name or abbreviation\n 23. {day-pretty}: Day in month with leading zero",
"type": "string"
},
"deFormat": {
"description": "Output format of the module `DE`. See Wiki for formatting syntax\n 1. {process-name}: DE process name\n 2. {pretty-name}: DE pretty name\n 3. {version}: DE version",
"type": "string"
},
"displayFormat": {
"description": "Output format of the module `Display`. See Wiki for formatting syntax\n 1. {width}: Screen configured width (in pixels)\n 2. {height}: Screen configured height (in pixels)\n 3. {refresh-rate}: Screen configured refresh rate (in Hz)\n 4. {scaled-width}: Screen scaled width (in pixels)\n 5. {scaled-height}: Screen scaled height (in pixels)\n 6. {name}: Screen name\n 7. {type}: Screen type (Built-in or External)\n 8. {rotation}: Screen rotation (in degrees)\n 9. {is-primary}: True if being the primary screen\n 10. {physical-width}: Screen physical width (in millimeters)\n 11. {physical-height}: Screen physical height (in millimeters)\n 12. {inch}: Physical diagonal length in inches\n 13. {ppi}: Pixels per inch (PPI)\n 14. {bit-depth}: Bits per color channel\n 15. {hdr-enabled}: True if high dynamic range (HDR) mode is enabled\n 16. {manufacture-year}: Year of manufacturing\n 17. {manufacture-week}: Nth week of manufacturing in the year\n 18. {serial}: Serial number\n 19. {platform-api}: The platform API used when detecting the display\n 20. {hdr-compatible}: True if the display is HDR compatible\n 21. {scale-factor}: HiDPI scale factor\n 22. {preferred-width}: Screen preferred width (in pixels)\n 23. {preferred-height}: Screen preferred height (in pixels)\n 24. {preferred-refresh-rate}: Screen preferred refresh rate (in Hz)",
"type": "string"
},
"diskFormat": {
"description": "Output format of the module `Disk`. See Wiki for formatting syntax\n 1. {size-used}: Size used\n 2. {size-total}: Size total\n 3. {size-percentage}: Size percentage num\n 4. {files-used}: Files used\n 5. {files-total}: Files total\n 6. {files-percentage}: Files percentage num\n 7. {is-external}: True if external volume\n 8. {is-hidden}: True if hidden volume\n 9. {filesystem}: Filesystem\n 10. {name}: Label / name\n 11. {is-readonly}: True if read-only\n 12. {create-time}: Create time in local timezone\n 13. {size-percentage-bar}: Size percentage bar\n 14. {files-percentage-bar}: Files percentage bar\n 15. {days}: Days after creation\n 16. {hours}: Hours after creation\n 17. {minutes}: Minutes after creation\n 18. {seconds}: Seconds after creation\n 19. {milliseconds}: Milliseconds after creation\n 20. {mountpoint}: Mount point / drive letter\n 21. {mount-from}: Mount from (device path)\n 22. {years}: Years integer after creation\n 23. {days-of-year}: Days of year after creation\n 24. {years-fraction}: Years fraction after creation\n 25. {size-free}: Size free\n 26. {size-available}: Size available",
"type": "string"
},
"diskioFormat": {
"description": "Output format of the module `DiskIO`. See Wiki for formatting syntax\n 1. {size-read}: Size of data read [per second] (formatted)\n 2. {size-written}: Size of data written [per second] (formatted)\n 3. {name}: Device name\n 4. {dev-path}: Device raw file path\n 5. {bytes-read}: Size of data read [per second] (in bytes)\n 6. {bytes-written}: Size of data written [per second] (in bytes)\n 7. {read-count}: Number of reads\n 8. {write-count}: Number of writes",
"type": "string"
},
"dnsFormat": {
"description": "Output format of the module `DNS`. See Wiki for formatting syntax\n 1. {result}: DNS result",
"type": "string"
},
"editorFormat": {
"description": "Output format of the module `Editor`. See Wiki for formatting syntax\n 1. {type}: Type (Visual / Editor)\n 2. {name}: Name\n 3. {exe-name}: Exe name of real path\n 4. {path}: Full path of real path\n 5. {version}: Version",
"type": "string"
},
"fontFormat": {
"description": "Output format of the module `Font`. See Wiki for formatting syntax\n 1. {font1}: Font 1\n 2. {font2}: Font 2\n 3. {font3}: Font 3\n 4. {font4}: Font 4\n 5. {combined}: Combined fonts for display",
"type": "string"
},
"gamepadFormat": {
"description": "Output format of the module `Gamepad`. See Wiki for formatting syntax\n 1. {name}: Name\n 2. {serial}: Serial number\n 3. {battery-percentage}: Battery percentage num\n 4. {battery-percentage-bar}: Battery percentage bar",
"type": "string"
},
"gpuFormat": {
"description": "Output format of the module `GPU`. See Wiki for formatting syntax\n 1. {vendor}: GPU vendor\n 2. {name}: GPU name\n 3. {driver}: GPU driver\n 4. {temperature}: GPU temperature\n 5. {core-count}: GPU core count\n 6. {type}: GPU type\n 7. {dedicated-total}: GPU total dedicated memory\n 8. {dedicated-used}: GPU used dedicated memory\n 9. {shared-total}: GPU total shared memory\n 10. {shared-used}: GPU used shared memory\n 11. {platform-api}: The platform API used when detecting the GPU\n 12. {frequency}: Current frequency in GHz\n 13. {index}: GPU vendor specific index\n 14. {dedicated-percentage-num}: Dedicated memory usage percentage num\n 15. {dedicated-percentage-bar}: Dedicated memory usage percentage bar\n 16. {shared-percentage-num}: Shared memory usage percentage num\n 17. {shared-percentage-bar}: Shared memory usage percentage bar\n 18. {core-usage-num}: Core usage percentage num\n 19. {core-usage-bar}: Core usage percentage bar\n 20. {memory-type}: Memory type (Windows only)",
"type": "string"
},
"hostFormat": {
"description": "Output format of the module `Host`. See Wiki for formatting syntax\n 1. {family}: Product family\n 2. {name}: Product name\n 3. {version}: Product version\n 4. {sku}: Product sku\n 5. {vendor}: Product vendor\n 6. {serial}: Product serial number\n 7. {uuid}: Product uuid",
"type": "string"
},
"iconsFormat": {
"description": "Output format of the module `Icons`. See Wiki for formatting syntax\n 1. {icons1}: Icons part 1\n 2. {icons2}: Icons part 2",
"type": "string"
},
"initsystemFormat": {
"description": "Output format of the module `InitSystem`. See Wiki for formatting syntax\n 1. {name}: Init system name\n 2. {exe}: Init system exe path\n 3. {version}: Init system version path\n 4. {pid}: Init system pid",
"type": "string"
},
"kernelFormat": {
"description": "Output format of the module `Kernel`. See Wiki for formatting syntax\n 1. {sysname}: Sysname\n 2. {release}: Release\n 3. {version}: Version\n 4. {arch}: Architecture\n 5. {display-version}: Display version\n 6. {page-size}: Page size",
"type": "string"
},
"keyboardFormat": {
"description": "Output format of the module `Keyboard`. See Wiki for formatting syntax\n 1. {name}: Name\n 2. {serial}: Serial number",
"type": "string"
},
"lmFormat": {
"description": "Output format of the module `LM`. See Wiki for formatting syntax\n 1. {service}: LM service\n 2. {type}: LM type\n 3. {version}: LM version",
"type": "string"
},
"loadavgFormat": {
"description": "Output format of the module `Loadavg`. See Wiki for formatting syntax\n 1. {loadavg1}: Load average over 1min\n 2. {loadavg2}: Load average over 5min\n 3. {loadavg3}: Load average over 15min",
"type": "string"
},
"localeFormat": {
"description": "Output format of the module `Locale`. See Wiki for formatting syntax\n 1. {result}: Locale code",
"type": "string"
},
"localipFormat": {
"description": "Output format of the module `LocalIp`. See Wiki for formatting syntax\n 1. {ipv4}: IPv4 address\n 2. {ipv6}: IPv6 address\n 3. {mac}: MAC address\n 4. {ifname}: Interface name\n 5. {is-default-route}: Is default route\n 6. {mtu}: MTU size in bytes\n 7. {speed}: Link speed (formatted)\n 8. {flags}: Interface flags",
"type": "string"
},
"mediaFormat": {
"description": "Output format of the module `Media`. See Wiki for formatting syntax\n 1. {combined}: Pretty media name\n 2. {title}: Media name\n 3. {artist}: Artist name\n 4. {album}: Album name\n 5. {status}: Status",
"type": "string"
},
"memoryFormat": {
"description": "Output format of the module `Memory`. See Wiki for formatting syntax\n 1. {used}: Used size\n 2. {total}: Total size\n 3. {percentage}: Percentage used (num)\n 4. {percentage-bar}: Percentage used (bar)",
"type": "string"
},
"monitorFormat": {
"description": "Output format of the module `Monitor`. See Wiki for formatting syntax\n 1. {name}: Display name\n 2. {width}: Native resolution width in pixels\n 3. {height}: Native resolution height in pixels\n 4. {physical-width}: Physical width in millimeters\n 5. {physical-height}: Physical height in millimeters\n 6. {inch}: Physical diagonal length in inches\n 7. {ppi}: Pixels per inch (PPI)\n 8. {manufacture-year}: Year of manufacturing\n 9. {manufacture-week}: Nth week of manufacturing in the year\n 10. {serial}: Serial number\n 11. {refresh-rate}: Maximum refresh rate in Hz\n 12. {hdr-compatible}: True if the display is HDR compatible",
"type": "string"
},
"mouseFormat": {
"description": "Output format of the module `Mouse`. See Wiki for formatting syntax\n 1. {name}: Mouse name\n 2. {serial}: Mouse serial number",
"type": "string"
},
"netioFormat": {
"description": "Output format of the module `NetIO`. See Wiki for formatting syntax\n 1. {rx-size}: Size of data received [per second] (formatted)\n 2. {tx-size}: Size of data sent [per second] (formatted)\n 3. {ifname}: Interface name\n 4. {is-default-route}: Is default route\n 5. {rx-bytes}: Size of data received [per second] (in bytes)\n 6. {tx-bytes}: Size of data sent [per second] (in bytes)\n 7. {rx-packets}: Number of packets received [per second]\n 8. {tx-packets}: Number of packets sent [per second]\n 9. {rx-errors}: Number of errors received [per second]\n 10. {tx-errors}: Number of errors sent [per second]\n 11. {rx-drops}: Number of packets dropped when receiving [per second]\n 12. {tx-drops}: Number of packets dropped when sending [per second]",
"type": "string"
},
"openclFormat": {
"description": "Output format of the module `OpenCL`. See Wiki for formatting syntax\n 1. {version}: Platform version\n 2. {name}: Platform name\n 3. {vendor}: Platform vendor",
"type": "string"
},
"openglFormat": {
"description": "Output format of the module `OpenGL`. See Wiki for formatting syntax\n 1. {version}: OpenGL version\n 2. {renderer}: OpenGL renderer\n 3. {vendor}: OpenGL vendor\n 4. {slv}: OpenGL shading language version\n 5. {library}: OpenGL library used",
"type": "string"
},
"osFormat": {
"description": "Output format of the module `OS`. See Wiki for formatting syntax\n 1. {sysname}: Name of the kernel\n 2. {name}: Name of the OS\n 3. {pretty-name}: Pretty name of the OS, if available\n 4. {id}: ID of the OS\n 5. {id-like}: ID like of the OS\n 6. {variant}: Variant of the OS\n 7. {variant-id}: Variant ID of the OS\n 8. {version}: Version of the OS\n 9. {version-id}: Version ID of the OS\n 10. {codename}: Version codename of the OS\n 11. {build-id}: Build ID of the OS\n 12. {arch}: Architecture of the OS",
"type": "string"
},
"packagesFormat": {
"description": "Output format of the module `Packages`. See Wiki for formatting syntax\n 1. {all}: Number of all packages\n 2. {pacman}: Number of pacman packages\n 3. {pacman-branch}: Pacman branch on manjaro\n 4. {dpkg}: Number of dpkg packages\n 5. {rpm}: Number of rpm packages\n 6. {emerge}: Number of emerge packages\n 7. {eopkg}: Number of eopkg packages\n 8. {xbps}: Number of xbps packages\n 9. {nix-system}: Number of nix-system packages\n 10. {nix-user}: Number of nix-user packages\n 11. {nix-default}: Number of nix-default packages\n 12. {apk}: Number of apk packages\n 13. {pkg}: Number of pkg packages\n 14. {flatpak-system}: Number of flatpak-system app packages\n 15. {flatpak-user}: Number of flatpak-user app packages\n 16. {snap}: Number of snap packages\n 17. {brew}: Number of brew packages\n 18. {brew-cask}: Number of brew-cask packages\n 19. {macports}: Number of macports packages\n 20. {scoop-user}: Number of scoop-user packages\n 21. {scoop-global}: Number of scoop-global packages\n 22. {choco}: Number of choco packages\n 23. {pkgtool}: Number of pkgtool packages\n 24. {paludis}: Number of paludis packages\n 25. {winget}: Number of winget packages\n 26. {opkg}: Number of opkg packages\n 27. {am-system}: Number of am-system packages\n 28. {sorcery}: Number of sorcery packages\n 29. {lpkg}: Number of lpkg packages\n 30. {lpkgbuild}: Number of lpkgbuild packages\n 31. {guix-system}: Number of guix-system packages\n 32. {guix-user}: Number of guix-user packages\n 33. {guix-home}: Number of guix-home packages\n 34. {linglong}: Number of linglong packages\n 35. {pacstall}: Number of pacstall packages\n 36. {mport}: Number of mport packages\n 37. {am-user}: Number of am-user (aka appman) packages\n 38. {pkgsrc}: Number of pkgsrc packages\n 39. {hpkg-system}: Number of hpkg-system packages\n 40. {hpkg-user}: Number of hpkg-user packages\n 41. {pisi}: Number of pisi packages\n 42. {soar}: Number of soar packages\n 43. {kiss}: Number of kiss packages\n 44. {moss}: Number of moss packages\n 45. {nix-all}: Total number of all nix packages\n 46. {flatpak-all}: Total number of all flatpak app packages\n 47. {brew-all}: Total number of all brew packages\n 48. {guix-all}: Total number of all guix packages\n 49. {hpkg-all}: Total number of all hpkg packages",
"type": "string"
},
"physicaldiskFormat": {
"description": "Output format of the module `PhysicalDisk`. See Wiki for formatting syntax\n 1. {size}: Device size (formatted)\n 2. {name}: Device name\n 3. {interconnect}: Device interconnect type\n 4. {dev-path}: Device raw file path\n 5. {serial}: Serial number\n 6. {physical-type}: Device kind (SSD or HDD)\n 7. {removable-type}: Device kind (Removable or Fixed)\n 8. {readonly-type}: Device kind (Read-only or Read-write)\n 9. {revision}: Product revision\n 10. {temperature}: Device temperature (formatted)",
"type": "string"
},
"physicalmemoryFormat": {
"description": "Output format of the module `PhysicalMemory`. See Wiki for formatting syntax\n 1. {bytes}: Size (in bytes)\n 2. {size}: Size formatted\n 3. {max-speed}: Max speed (in MT/s)\n 4. {running-speed}: Running speed (in MT/s)\n 5. {type}: Type (DDR4, DDR5, etc.)\n 6. {form-factor}: Form factor (SODIMM, DIMM, etc.)\n 7. {locator}: Bank/Device Locator (BANK0/SIMM0, BANK0/SIMM1, etc.)\n 8. {vendor}: Vendor\n 9. {serial}: Serial number\n 10. {part-number}: Part number\n 11. {is-ecc-enabled}: True if ECC enabled\n 12. {is-installed}: True if a memory module is installed in the slot",
"type": "string"
},
"playerFormat": {
"description": "Output format of the module `Player`. See Wiki for formatting syntax\n 1. {player}: Pretty player name\n 2. {name}: Player name\n 3. {id}: Player Identifier\n 4. {url}: URL name",
"type": "string"
},
"poweradapterFormat": {
"description": "Output format of the module `PowerAdapter`. See Wiki for formatting syntax\n 1. {watts}: Power adapter watts\n 2. {name}: Power adapter name\n 3. {manufacturer}: Power adapter manufacturer\n 4. {model}: Power adapter model\n 5. {description}: Power adapter description\n 6. {serial}: Power adapter serial number",
"type": "string"
},
"processesFormat": {
"description": "Output format of the module `Processes`. See Wiki for formatting syntax\n 1. {result}: Process count",
"type": "string"
},
"publicipFormat": {
"description": "Output format of the module `PublicIp`. See Wiki for formatting syntax\n 1. {ip}: Public IP address\n 2. {location}: Location",
"type": "string"
},
"shellFormat": {
"description": "Output format of the module `Shell`. See Wiki for formatting syntax\n 1. {process-name}: Shell process name\n 2. {exe}: The first argument of the command line when running the shell\n 3. {exe-name}: Shell base name of arg0\n 4. {version}: Shell version\n 5. {pid}: Shell pid\n 6. {pretty-name}: Shell pretty name\n 7. {exe-path}: Shell full exe path\n 8. {tty}: Shell tty used",
"type": "string"
},
"soundFormat": {
"description": "Output format of the module `Sound`. See Wiki for formatting syntax\n 1. {is-main}: Is main sound device\n 2. {name}: Device name\n 3. {volume-percentage}: Volume (in percentage num)\n 4. {identifier}: Identifier\n 5. {volume-percentage-bar}: Volume (in percentage bar)\n 6. {platform-api}: Platform API used",
"type": "string"
},
"swapFormat": {
"description": "Output format of the module `Swap`. See Wiki for formatting syntax\n 1. {used}: Used size\n 2. {total}: Total size\n 3. {percentage}: Percentage used (num)\n 4. {percentage-bar}: Percentage used (bar)\n 5. {name}: Name",
"type": "string"
},
"terminalFormat": {
"description": "Output format of the module `Terminal`. See Wiki for formatting syntax\n 1. {process-name}: Terminal process name\n 2. {exe}: The first argument of the command line when running the terminal\n 3. {exe-name}: Terminal base name of arg0\n 4. {pid}: Terminal pid\n 5. {pretty-name}: Terminal pretty name\n 6. {version}: Terminal version\n 7. {exe-path}: Terminal full exe path\n 8. {tty}: Terminal tty / pts used",
"type": "string"
},
"terminalfontFormat": {
"description": "Output format of the module `TerminalFont`. See Wiki for formatting syntax\n 1. {combined}: Terminal font combined\n 2. {name}: Terminal font name\n 3. {size}: Terminal font size\n 4. {styles}: Terminal font styles",
"type": "string"
},
"terminalsizeFormat": {
"description": "Output format of the module `TerminalSize`. See Wiki for formatting syntax\n 1. {rows}: Terminal rows\n 2. {columns}: Terminal columns\n 3. {width}: Terminal width (in pixels)\n 4. {height}: Terminal height (in pixels)",
"type": "string"
},
"terminalthemeFormat": {
"description": "Output format of the module `TerminalTheme`. See Wiki for formatting syntax\n 1. {fg-color}: Terminal foreground color\n 2. {fg-type}: Terminal foreground type (Dark / Light)\n 3. {bg-color}: Terminal background color\n 4. {bg-type}: Terminal background type (Dark / Light)",
"type": "string"
},
"titleFormat": {
"description": "Output format of the module `Title`. See Wiki for formatting syntax\n 1. {user-name}: User name\n 2. {host-name}: Host name\n 3. {home-dir}: Home directory\n 4. {exe-path}: Executable path of current process\n 5. {user-shell}: User's default shell\n 6. {user-name-colored}: User name (colored)\n 7. {at-symbol-colored}: @ symbol (colored)\n 8. {host-name-colored}: Host name (colored)\n 9. {full-user-name}: Full user name\n 10. {user-id}: UID (*nix) / SID (Windows)\n 11. {pid}: PID of current process\n 12. {cwd}: CWD with home dir replaced by `~`",
"type": "string"
},
"themeFormat": {
"description": "Output format of the module `Theme`. See Wiki for formatting syntax\n 1. {theme1}: Theme part 1\n 2. {theme2}: Theme part 2",
"type": "string"
},
"tpmFormat": {
"description": "Output format of the module `TPM`. See Wiki for formatting syntax\n 1. {version}: TPM device version\n 2. {description}: TPM general description",
"type": "string"
},
"uptimeFormat": {
"description": "Output format of the module `Uptime`. See Wiki for formatting syntax\n 1. {days}: Days after boot\n 2. {hours}: Hours after boot\n 3. {minutes}: Minutes after boot\n 4. {seconds}: Seconds after boot\n 5. {milliseconds}: Milliseconds after boot\n 6. {boot-time}: Boot time in local timezone\n 7. {years}: Years integer after boot\n 8. {days-of-year}: Days of year after boot\n 9. {years-fraction}: Years fraction after boot\n 10. {formatted}: Formatted uptime",
"type": "string"
},
"usersFormat": {
"description": "Output format of the module `Users`. See Wiki for formatting syntax\n 1. {name}: User name\n 2. {host-name}: Host name\n 3. {session-name}: Session name\n 4. {client-ip}: Client IP\n 5. {login-time}: Login Time in local timezone\n 6. {days}: Days after login\n 7. {hours}: Hours after login\n 8. {minutes}: Minutes after login\n 9. {seconds}: Seconds after login\n 10. {milliseconds}: Milliseconds after login\n 11. {years}: Years integer after login\n 12. {days-of-year}: Days of year after login\n 13. {years-fraction}: Years fraction after login",
"type": "string"
},
"versionFormat": {
"description": "Output format of the module `Version`. See Wiki for formatting syntax\n 1. {project-name}: Project name\n 2. {version}: Version\n 3. {version-tweak}: Version tweak\n 4. {build-type}: Build type (debug or release)\n 5. {sysname}: System name\n 6. {arch}: Architecture\n 7. {cmake-built-type}: CMake build type when compiling (Debug, Release, RelWithDebInfo, MinSizeRel)\n 8. {compile-time}: Date time when compiling\n 9. {compiler}: Compiler used when compiling\n 10. {libc}: Libc used when compiling",
"type": "string"
},
"vulkanFormat": {
"description": "Output format of the module `Vulkan`. See Wiki for formatting syntax\n 1. {driver}: Driver name\n 2. {api-version}: API version\n 3. {conformance-version}: Conformance version\n 4. {instance-version}: Instance version",
"type": "string"
},
"wallpaperFormat": {
"description": "Output format of the module `Wallpaper`. See Wiki for formatting syntax\n 1. {file-name}: File name\n 2. {full-path}: Full path",
"type": "string"
},
"weatherFormat": {
"description": "Output format of the module `Weather`. See Wiki for formatting syntax\n 1. {result}: Weather result",
"type": "string"
},
"wmFormat": {
"description": "Output format of the module `WM`. See Wiki for formatting syntax\n 1. {process-name}: WM process name\n 2. {pretty-name}: WM pretty name\n 3. {protocol-name}: WM protocol name\n 4. {plugin-name}: WM plugin name\n 5. {version}: WM version",
"type": "string"
},
"wifiFormat": {
"description": "Output format of the module `Wifi`. See Wiki for formatting syntax\n 1. {inf-desc}: Interface description\n 2. {inf-status}: Interface status\n 3. {status}: Connection status\n 4. {ssid}: Connection SSID\n 5. {bssid}: Connection BSSID\n 6. {protocol}: Connection protocol\n 7. {signal-quality}: Connection signal quality (percentage num)\n 8. {rx-rate}: Connection RX rate\n 9. {tx-rate}: Connection TX rate\n 10. {security}: Connection Security algorithm\n 11. {signal-quality-bar}: Connection signal quality (percentage bar)\n 12. {channel}: Connection channel number\n 13. {band}: Connection channel band in GHz",
"type": "string"
},
"wmthemeFormat": {
"description": "Output format of the module `WMTheme`. See Wiki for formatting syntax\n 1. {result}: WM theme",
"type": "string"
},
"zpoolFormat": {
"description": "Output format of the module `Zpool`. See Wiki for formatting syntax\n 1. {name}: Zpool name\n 2. {guid}: Zpool guid\n 3. {state}: Zpool state\n 4. {used}: Size used\n 5. {allocated}: Size allocated\n 6. {total}: Size total\n 7. {used-percentage}: Size used percentage num\n 8. {allocated-percentage}: Size allocated percentage num\n 9. {fragmentation-percentage}: Fragmentation percentage num\n 10. {used-percentage-bar}: Size used percentage bar\n 11. {allocated-percentage-bar}: Size allocated percentage bar\n 12. {fragmentation-percentage-bar}: Fragmentation percentage bar\n 13. {is-readonly}: Is read-only",
"type": "string"
}
},
"type": "object",
"additionalProperties": false,
"title": "JSON config",
"description": "JSON config file for fastfetch. Usually located at `~/.config/fastfetch/config.jsonc`",
"properties": {
"$schema": {
"type": "string",
"description": "JSON schema URL, for JSON validation and IDE intelligence",
"format": "uri",
"default": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"
},
"logo": {
"description": "Fastfetch logo configurations\nSee also https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options",
"oneOf": [
{
"description": "Disable logo",
"type": "null",
"const": null
},
{
"description": "Set the source file of the logo or built-in ASCII art name",
"type": "string"
},
{
"description": "Fastfetch logo configurations",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Set the type of the logo",
"oneOf": [
{
"const": "auto",
"description": "If something is given, first try built-in, then file. Otherwise detect logo"
},
{
"const": "builtin",
"description": "Built-in ASCII art"
},
{
"const": "small",
"description": "Built-in ASCII art, small version (not all logos support this option)"
},
{
"const": "file",
"description": "Text file, printed with color code replacement"
},
{
"const": "file-raw",
"description": "Text file, printed as is"
},
{
"const": "data",
"description": "Text data, printed with color code replacement"
},
{
"const": "data-raw",
"description": "Text data, printed as is"
},
{
"const": "sixel",
"description": "Image file, printed as sixel codes"
},
{
"const": "kitty",
"description": "Image file, printed using kitty graphics protocol"
},
{
"const": "kitty-direct",
"description": "Image file, tells the terminal emulator to read image data from the specified file"
},
{
"const": "kitty-icat",
"description": "Image file, uses `kitten icat` to display the image. Requires binary `kitten` to be installed"
},
{
"const": "iterm",
"description": "Image file, uses `iTerm` image protocol"
},
{
"const": "chafa",
"description": "Image file, prints `ASCII` art image generated by `libchafa`"
},
{
"const": "raw",
"description": "Image file, printed as `raw` binary string image"
},
{
"const": "none",
"description": "Disable logo printing"
}
],
"default": "auto"
},
"source": {
"type": "string",
"description": "Set the source file of the logo"
},
"color": {
"type": "object",
"additionalProperties": false,
"description": "Override colors in the logo",
"properties": {
"1": {
"description": "Color 1",
"$ref": "#/$defs/colors"
},
"2": {
"description": "Color 2",
"$ref": "#/$defs/colors"
},
"3": {
"description": "Color 3",
"$ref": "#/$defs/colors"
},
"4": {
"description": "Color 4",
"$ref": "#/$defs/colors"
},
"5": {
"description": "Color 5",
"$ref": "#/$defs/colors"
},
"6": {
"description": "Color 6",
"$ref": "#/$defs/colors"
},
"7": {
"description": "Color 7",
"$ref": "#/$defs/colors"
},
"8": {
"description": "Color 8",
"$ref": "#/$defs/colors"
},
"9": {
"description": "Color 9",
"$ref": "#/$defs/colors"
}
}
},
"width": {
"oneOf": [
{
"type": "null",
"description": "Auto detect width (default)"
},
{
"type": "integer",
"description": "Set the width of the logo (in characters). Required for some image protocols",
"minimum": 1
}
]
},
"height": {
"oneOf": [
{
"type": "null",
"description": "Auto detect width (default)"
},
{
"type": "integer",
"description": "Set the height of the logo (in characters). Required for some image protocols",
"minimum": 1
}
]
},
"padding": {
"type": "object",
"additionalProperties": false,
"description": "Set the padding of the logo",
"properties": {
"top": {
"type": "integer",
"description": "Set the top padding of the logo",
"minimum": 0
},
"left": {
"type": "integer",
"description": "Set the left padding of the logo",
"minimum": 0
},
"right": {
"type": "integer",
"description": "Set the right padding of the logo",
"minimum": 0
}
}
},
"printRemaining": {
"type": "boolean",
"description": "Whether to print the remaining logo if it has more lines than modules to display",
"default": true
},
"preserveAspectRatio": {
"type": "boolean",
"description": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol only",
"default": false
},
"recache": {
"type": "boolean",
"description": "If true, regenerate image logo cache",
"default": false
},
"position": {
"type": "string",
"description": "Set the position where the logo should be displayed",
"enum": [
"left",
"top",
"right"
],
"default": "left"
},
"chafa": {
"type": "object",
"additionalProperties": false,
"description": "Chafa configuration. See chafa documentation for details",
"properties": {
"fgOnly": {
"type": "boolean",
"description": "Produce character-cell output using foreground colors only",
"default": false
},
"symbols": {
"type": "string",
"description": "Specify character symbols to employ in final output"
},
"canvasMode": {
"type": "string",
"description": "Determine how colors are used in the output. This value maps to enum ChafaCanvasMode.",
"oneOf": [
{
"const": "TRUECOLOR",
"description": "Use 24-bit true colors"
},
{
"const": "INDEXED_256",
"description": "Use 256 colors"
},
{
"const": "INDEXED_240",
"description": "Use 240 colors, but avoid using the lower 16 whose values vary between terminal environments"
},
{
"const": "INDEXED_16",
"description": "Use 16 colors using the aixterm ANSI extension"
},
{
"const": "FGBG_BGFG",
"description": "Use default foreground and background colors, plus inversion"
},
{
"const": "FGBG",
"description": "Use default foreground and background colors. No ANSI codes will be used"
},
{
"const": "INDEXED_8",
"description": "Use 8 colors, compatible with original ANSI X3.64"
},
{
"const": "INDEXED_16_8",
"description": "Use 16 FG colors (8 of which enabled with bold/bright) and 8 BG colors"
}
]
},
"colorSpace": {
"type": "string",
"description": "Set color space used for quantization. This value maps to enum ChafaColorSpace.",
"oneOf": [
{
"const": "RGB",
"description": "RGB color space. Fast but imprecise"
},
{
"const": "DIN99D",
"description": "DIN99d color space. Slower, but good perceptual color precision"
}
]
},
"ditherMode": {
"type": "string",
"description": "Set output dither mode (No effect with 24-bit color). This value maps to enum ChafaDitherMode.",
"oneOf": [
{
"const": "NONE",
"description": "No dithering"
},
{
"const": "ORDERED",
"description": "Ordered dithering (Bayer or similar)"
},
{
"const": "DIFFUSION",
"description": "Error diffusion dithering (Floyd-Steinberg or similar)"
}
]
}
}
}
}
}
]
},
"general": {
"description": "Fastfetch general configurations",
"type": "object",
"additionalProperties": false,
"properties": {
"thread": {
"type": "boolean",
"description": "Use separate threads for HTTP requests",
"default": true
},
"escapeBedrock": {
"type": "boolean",
"description": "On Bedrock Linux, whether to escape the bedrock jail",
"default": true
},
"playerName": {
"type": "string",
"description": "The name of the player to use for Media and Player modules. Linux only"
},
"dsForceDrm": {
"description": "Force display detection to use DRM. Linux only",
"oneOf": [
{
"type": "boolean",
"const": false,
"description": "Try `wayland`, then `x11`, then `drm`"
},
{
"type": "string",
"description": "Use `/sys/class/drm` only",
"const": "sysfs-only"
},
{
"type": "boolean",
"const": true,
"description": "Try `libdrm` first, then `sysfs` if libdrm fails"
}
],
"default": false
},
"wmiTimeout": {
"type": "integer",
"description": "Set the timeout (ms) for WMI queries, `-1` for no timeout. Windows only",
"default": 5000
},
"processingTimeout": {
"type": "integer",
"description": "Set the timeout (ms) when waiting for child processes, `-1` for no timeout",
"default": 5000
},
"preRun": {
"type": "string",
"description": "Set the command to be executed before printing logos",
"default": ""
},
"detectVersion": {
"type": "boolean",
"description": "Whether to detect and display component versions. Mainly for benchmarking",
"default": true
}
}
},
"display": {
"description": "Configure how things should be displayed",
"type": "object",
"additionalProperties": false,
"properties": {
"stat": {
"description": "Show time usage (in ms) for individual modules with optional threshold",
"oneOf": [
{
"type": "boolean",
"default": false
},
{
"type": "integer",
"minimum": 1
}
]
},
"pipe": {
"type": "boolean",
"description": "Whether to disable colors (auto-detected based on isatty(1) by default)",
"default": false
},
"showErrors": {
"type": "boolean",
"description": "Print occurring errors to the console. False to ignore errored modules",
"default": false
},
"disableLinewrap": {
"type": "boolean",
"description": "Whether to disable line wrap during execution",
"default": true
},
"hideCursor": {
"type": "boolean",
"description": "Whether to hide the cursor during execution",
"default": true
},
"separator": {
"type": "string",
"description": "Set the separator between key and value",
"default": ": "
},
"color": {
"description": "Set the color of the keys and title",
"oneOf": [
{
"description": "Set both the colors of keys and title",
"$ref": "#/$defs/colors"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"keys": {
"description": "Set the color of the keys",
"$ref": "#/$defs/colors"
},
"title": {
"description": "Set the color of the title",
"$ref": "#/$defs/colors"
},
"output": {
"description": "Set the color of the module output",
"$ref": "#/$defs/colors"
},
"separator": {
"description": "Set the color of the key-value separator",
"$ref": "#/$defs/colors"
}
}
}
]
},
"brightColor": {
"description": "Set if the keys, title and ASCII logo should be printed in bright color",
"type": "boolean",
"default": true
},
"key": {
"type": "object",
"additionalProperties": false,
"description": "Set how module keys should be displayed",
"properties": {
"width": {
"description": "Align the width of keys to number of characters, 0 to disable",
"type": "integer",
"minimum": 0,
"default": 0
},
"type": {
"type": "string",
"description": "Set whether to show builtin icon before string keys",
"oneOf": [
{
"const": "none",
"description": "Disable keys"
},
{
"const": "string",
"description": "Show string keys"
},
{
"const": "icon",
"description": "Show builtin icon (requires newest nerd font)"
},
{
"const": "both",
"description": "Show both icon and string keys (alias of `both-1`)"
},
{
"const": "both-0",
"description": "Show both icon and string with no spaces between them"
},
{
"const": "both-1",
"description": "Show both icon and string with a space between them"
},
{
"const": "both-2",
"description": "Show both icon and string with 2 spaces between them"
},
{
"const": "both-3",
"description": "Show both icon and string with 3 spaces between them"
},
{
"const": "both-4",
"description": "Show both icon and string with 4 spaces between them"
}
],
"default": "string"
},
"paddingLeft": {
"type": "integer",
"description": "Set the left padding of keys",
"minimum": 0,
"default": 0
}
}
},
"size": {
"type": "object",
"additionalProperties": false,
"description": "Set how size values should be displayed",
"properties": {
"binaryPrefix": {
"type": "string",
"description": "Set the binary prefix to use when formatting sizes",
"oneOf": [
{
"const": "iec",
"description": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)"
},
{
"const": "si",
"description": "1000 Bytes = 1 kB, 1000 kB = 1 MB, ..."
},
{
"const": "jedec",
"description": "1024 Bytes = 1 KB, 1024 KB = 1 MB, ..."
}
],
"default": "iec"
},
"maxPrefix": {
"type": "string",
"description": "Set the largest binary prefix to use when formatting sizes",
"enum": ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
"default": "YB"
},
"ndigits": {
"type": "integer",
"description": "Set the number of digits to keep after the decimal point when formatting sizes",
"minimum": 0,
"maximum": 9,
"default": 2
},
"spaceBeforeUnit": {
"$ref": "#/$defs/spaceBeforeUnit"
}
}
},
"temp": {
"type": "object",
"additionalProperties": false,
"description": "Set how temperature values should be displayed",
"properties": {
"unit": {
"type": "string",
"description": "Set the unit of temperature",
"oneOf": [
{
"const": "C",
"description": "Celsius"
},
{
"const": "F",
"description": "Fahrenheit"
},
{
"const": "K",
"description": "Kelvin"
},
{
"const": "D",
"description": "Default (alias for Celsius)"
}
],
"default": "D"
},
"ndigits": {
"type": "integer",
"description": "Set the number of digits to keep after the decimal point when formatting temperature values",
"minimum": 0,
"maximum": 9,
"default": 1
},
"color": {
"type": "object",
"additionalProperties": false,
"description": "Set colors used in different states of temperature values",
"properties": {
"green": {
"description": "Color used in green state",
"$ref": "#/$defs/colors",
"default": "green"
},
"yellow": {
"description": "Color used in yellow state",
"$ref": "#/$defs/colors",
"default": "light_yellow"
},
"red": {
"description": "Color used in red state",
"$ref": "#/$defs/colors",
"default": "light_red"
}
}
},
"spaceBeforeUnit": {
"$ref": "#/$defs/spaceBeforeUnit"
}
}
},
"bar": {
"type": "object",
"additionalProperties": false,
"description": "Set the bar configuration",
"properties": {
"char": {
"type": "object",
"additionalProperties": false,
"description": "Set the characters used in the bar",
"properties": {
"elapsed": {
"type": "string",
"description": "Set the character to use in elapsed part",
"default": "■"
},
"total": {
"type": "string",
"description": "Set the character to use in total part",
"default": "-"
}
}
},
"border": {
"oneOf": [
{
"type": "null",
"description": "Disable bar borders"
},
{
"type": "object",
"additionalProperties": false,
"description": "Set the string to use of borders of percentage bars",
"properties": {
"left": {
"type": "string",
"description": "Set the string to use at left border",
"default": "[ "
},
"right": {
"type": "string",
"description": "Set the string to use at right border",
"default": " ]"
},
"leftElapsed": {
"type": "string",
"description": "If both leftElapsed and rightElapsed are set, the border will be used as parts of bar content",
"default": ""
},
"rightElapsed": {
"type": "string",
"description": "If both leftElapsed and rightElapsed are set, the border will be used as parts of bar content",
"default": ""
}
}
}
]
},
"color": {
"oneOf": [
{
"type": "null",
"description": "Disable color in percentage bars"
},
{
"type": "object",
"additionalProperties": false,
"description": "Set the color to use of percentage bars",
"properties": {
"elapsed": {
"description": "Color to use in the elapsed part of percentage bars\nBy default, auto selected by percent.color.{green,yellow,red}",
"$ref": "#/$defs/colors",
"default": "auto"
},
"total": {
"description": "Color to use in the total part of percentage bars",
"$ref": "#/$defs/colors",
"default": "light_white"
},
"border": {
"description": "Color to use in the borders of percentage bars",
"$ref": "#/$defs/colors",
"default": "light_white"
}
}
}
]
},
"width": {
"type": "integer",
"description": "Set the width of the bar, in number of characters",
"minimum": 1,
"default": 10
}
}
},
"percent": {
"type": "object",
"additionalProperties": false,
"description": "Set how percentage values should be displayed",
"properties": {
"type": {
"$ref": "#/$defs/percentType"
},
"ndigits": {
"type": "number",
"description": "Set the number of digits to keep after the decimal point when formatting percentage numbers",
"minimum": 0,
"maximum": 9,
"default": 0
},
"color": {
"type": "object",
"additionalProperties": false,
"description": "Set colors used in different states of percentage bars and numbers",
"properties": {
"green": {
"description": "Color used in green state",
"$ref": "#/$defs/colors",
"default": "green"
},
"yellow": {
"description": "Color used in yellow state",
"$ref": "#/$defs/colors",
"default": "light_yellow"
},
"red": {
"description": "Color used in red state",
"$ref": "#/$defs/colors",
"default": "light_red"
}
}
},
"spaceBeforeUnit": {
"$ref": "#/$defs/spaceBeforeUnit"
},
"width": {
"type": "integer",
"description": "Set the width of the percentage number, in number of characters",
"minimum": 0,
"default": 0
}
}
},
"freq": {
"type": "object",
"additionalProperties": false,
"description": "Set how frequency values should be displayed",
"properties": {
"ndigits": {
"description": "Set the number of decimal places to display when formatting frequency values",
"oneOf": [
{
"type": "integer",
"minimum": 0,
"maximum": 9,
"description": "Integer value displays the frequency in GHz with specified decimal places"
},
{
"type": "null",
"description": "Null value display the frequency as integer MHz"
}
],
"default": 2
},
"spaceBeforeUnit": {
"$ref": "#/$defs/spaceBeforeUnit"
}
}
},
"duration": {
"type": "object",
"description": "Set how duration values should be displayed",
"properties": {
"abbreviation": {
"type": "boolean",
"description": "Set whether to abbreviate duration values\nIf true, the output will be in the form of \"1h 2m\" instead of \"1 hour, 2 mins\"",
"default": false
},
"spaceBeforeUnit": {
"$ref": "#/$defs/spaceBeforeUnit"
}
}
},
"fraction": {
"type": "object",
"additionalProperties": false,
"description": "Set how ordinary fraction numbers should be displayed",
"properties": {
"ndigits": {
"oneOf": [
{
"type": "number",
"description": "Set the number of digits to keep after the decimal point when formatting ordinary fraction numbers",
"minimum": 0,
"maximum": 9
},
{
"type": "null",
"description": "The number of digits will be automatically determined based on the value"
}
],
"default": 2
},
"trailingZeros": {
"description": "Set when to keep trailing zeros",
"oneOf": [
{
"type": "null",
"description": "Same as `default`"
},
{
"const": "default",
"description": "Use the behavior defined internally"
},
{
"const": "always",
"description": "Always keep trailing zeros"
},
{
"const": "never",
"description": "Never keep trailing zeros"
}
],
"default": null
}
}
},
"noBuffer": {
"type": "boolean",
"description": "Whether to disable the stdout application buffer",
"default": false
},
"constants": {
"type": "array",
"description": "List of strings to be used in custom format of modules",
"items": {
"type": "string"
}
}
}
},
"modules": {
"description": "Fastfetch modules to run",
"type": "array",
"items": {
"anyOf": [
{
"type": "string",
"description": "Run module with default configurations",
"enum": [
"battery",
"bios",
"bluetooth",
"bluetoothradio",
"board",
"bootmgr",
"break",
"brightness",
"btrfs",
"camera",
"chassis",
"cpu",
"cpucache",
"cpuusage",
"command",
"colors",
"cursor",
"datetime",
"display",
"disk",
"diskio",
"de",
"dns",
"editor",
"font",
"gamepad",
"gpu",
"host",
"icons",
"initsystem",
"keyboard",
"kernel",
"lm",
"loadavg",
"locale",
"localip",
"media",
"memory",
"monitor",
"mouse",
"netio",
"opencl",
"opengl",
"os",
"packages",
"physicaldisk",
"physicalmemory",
"player",
"poweradapter",
"processes",
"publicip",
"separator",
"shell",
"sound",
"swap",
"terminal",
"terminalfont",
"terminalsize",
"terminaltheme",
"title",
"theme",
"tpm",
"uptime",
"users",
"version",
"vulkan",
"wallpaper",
"weather",
"wm",
"wifi",
"wmtheme",
"zpool"
]
},
{
"type": "object",
"description": "Run module with custom configurations",
"required": [
"type"
],
"properties": {
"type": {
"type": "string"
}
},
"oneOf": [
{
"title": "Break",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "break",
"description": "Print a empty line"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Battery",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "battery",
"description": "Print battery capacity, status, etc"
},
"useSetupApi": {
"description": "Set if `CM API` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only",
"type": "boolean",
"default": false
},
"temp": {
"$ref": "#/$defs/temperature"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/batteryFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "BIOS",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print information of 1st-stage bootloader (name, version, release date, etc)",
"const": "bios"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/biosFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Bluetooth",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "List (connected) bluetooth devices",
"const": "bluetooth"
},
"showDisconnected": {
"description": "Set if disconnected bluetooth devices should be printed",
"type": "boolean",
"default": false
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/bluetoothFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Bluetooth Radio",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "List bluetooth radios width supported version and vendor",
"const": "bluetoothradio"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/bluetoothradioFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Board",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print motherboard name and other info",
"const": "board"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/boardFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Boot Manager",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print information of 2nd-stage bootloader (name, firmware, etc)",
"const": "bootmgr"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/bootmgrFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Brightness",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "brightness",
"description": "Print current brightness level of your monitors"
},
"percent": {
"$ref": "#/$defs/percent"
},
"ddcciSleep": {
"type": "integer",
"description": "Set the sleep times (in ms) when sending DDC/CI requests.\nSee for detail",
"minimum": 0,
"maximum": 400,
"default": 10
},
"compact": {
"description": "Set if multiple results should be printed in one line",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/brightnessFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "BTRFS",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "btrfs",
"description": "Print Linux BTRFS volumes"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/btrfsFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Camera",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print available cameras",
"const": "camera"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/cameraFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Chassis",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "chassis",
"description": "Print chassis type (desktop, laptop, etc)"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/chassisFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "CPU",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print CPU name, frequency, etc",
"const": "cpu"
},
"temp": {
"$ref": "#/$defs/temperature"
},
"tempSensor": {
"description": "Set the temperature sensor to use for CPU temperature detection\n* Linux: `hwmon` or `thermal` path name (eg. `hwmon0`, `thermal_zone0)`\n* macOS: SMC sensor key (eg. `Tp01`)\n* Windows: thermal zone key (eg. `\\_TZ.CPUZ`)\n* FreeBSD: sysctl key (eg. `dev.cpu.0.temperature`)\n* NetBSD: sysmon sensor key (eg. `coretemp0`)",
"type": "string"
},
"showPeCoreCount": {
"description": "Detect and display CPU frequency of different core types (eg. Pcore and Ecore) if supported",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/cpuFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "CPU Cache",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "cpucache",
"description": "Print CPU cache sizes"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/cpucacheFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "CPU Usage",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "cpuusage",
"description": "Print CPU usage. Costs some time to collect data"
},
"percent": {
"$ref": "#/$defs/percent"
},
"separate": {
"type": "boolean",
"description": "Display CPU usage per CPU logical core, instead of an average result",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). CPU usage = (inUseEnd - inUseStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/cpuusageFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Colors",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Display the terminal's 16-color palette",
"const": "colors"
},
"symbol": {
"description": "Set the symbol to use",
"type": "string",
"oneOf": [
{
"const": "block",
"description": "\u2588\u2588\u2588"
},
{
"const": "background",
"description": "(whitespaces with background)"
},
{
"const": "circle",
"description": "\u25cf"
},
{
"const": "diamond",
"description": "\u25c6"
},
{
"const": "triangle",
"description": "\u25b2"
},
{
"const": "square",
"description": "\u25a0"
},
{
"const": "star",
"description": "\u2605"
}
],
"default": "background"
},
"paddingLeft": {
"description": "Set the number of white spaces to print before the symbol",
"type": "integer",
"minimum": 0,
"default": 0
},
"block": {
"description": "Set behavior of block printing",
"type": "object",
"additionalProperties": false,
"properties": {
"width": {
"description": "Set the block width in spaces",
"type": "integer",
"minimum": 1,
"default": 3
},
"range": {
"description": "Set the range of colors in the blocks to print",
"type": "array",
"items": {
"type": "integer",
"minimum": 0,
"maximum": 15
},
"minItems": 2,
"maxItems": 2
}
}
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Command",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Running custom shell scripts",
"const": "command"
},
"shell": {
"description": "Set the shell program to execute the command text\nDefault: cmd for Windows, /bin/sh for *nix",
"type": "string"
},
"param": {
"description": "Set the parameter used when starting the shell\nIf set to an empty string, it will be ignored\nDefault: /c for Windows, -c for *nix",
"type": "string"
},
"text": {
"description": "Set the command text to be executed",
"type": "string"
},
"useStdErr": {
"description": "Set if stderr should be used instead of stdout for command output",
"type": "boolean",
"default": false
},
"parallel": {
"description": "Set if the command should be executed in parallel with other commands\nImprove performance when using multiple commands, but may cause issues with some commands",
"type": "boolean",
"default": true
},
"splitLines": {
"description": "Set if the command output should be split into multiple lines",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/commandFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Cursor",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "cursor",
"description": "Print cursor style name"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/cursorFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Custom",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print a custom string, with or without key",
"const": "custom"
},
"key": {
"description": "Leave empty not to print the key",
"type": "string"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"description": "Text to print",
"type": "string"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Date Time",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "datetime",
"description": "Print current date and time"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/datetimeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Display",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print resolutions, refresh rates, etc",
"const": "display"
},
"compactType": {
"description": "Set if all displays should be printed in one line",
"oneOf": [
{
"const": null,
"description": "Disable compact mode"
},
{
"const": "none",
"description": "Disable compact mode (kept for compatibility)"
},
{
"const": "original",
"description": "Print original resolutions"
},
{
"const": "scaled",
"description": "Print scaled resolutions"
},
{
"const": "original-with-refresh-rate",
"description": "Print original resolutions with refresh rates"
},
{
"const": "scaled-with-refresh-rate",
"description": "Print scaled resolutions with refresh rates"
}
],
"default": null
},
"preciseRefreshRate": {
"description": "Set if decimal refresh rates should not be rounded into integers when printing",
"type": "boolean",
"default": false
},
"order": {
"description": "Set the order should be used when printing",
"oneOf": [
{
"const": null,
"description": "Use the default order"
},
{
"const": "none",
"description": "Use the detected order (kept for compatibility)"
},
{
"const": "asc",
"description": "Sort by display name in ascending order"
},
{
"const": "desc",
"description": "Sort by display name in descending order"
}
],
"default": null
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/displayFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Disk",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print partitions, space usage, disk type, etc",
"const": "disk"
},
"folders": {
"description": "A list of folder paths for the disk output\nDefault: auto detection using mount-points\nThis option overrides other `show*` options",
"oneOf": [
{
"type": "string",
"description": "A colon (semicolon on Windows) separated list of folder paths to get disk usage from",
"default": "/"
},
{
"type": "array",
"description": "An array of folder paths to get disk usage from",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
]
},
"hideFolders": {
"description": "A list of folder paths (or glob patterns) to hide from the disk output",
"oneOf": [
{
"type": "string",
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output"
},
{
"type": "array",
"description": "An array of folder paths to hide from the disk output",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
],
"default": "/efi:/boot:/boot/*"
},
"hideFS": {
"description": "A list of file systems to hide from the disk output",
"oneOf": [
{
"type": "string",
"description": "A colon separated list of file systems to hide from the disk output"
},
{
"type": "array",
"description": "An array of file systems to hide from the disk output",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
]
},
"showRegular": {
"type": "boolean",
"description": "Set if regular volume should be printed",
"default": true
},
"showExternal": {
"type": "boolean",
"description": "Set if external volume should be printed",
"default": true
},
"showHidden": {
"type": "boolean",
"description": "Set if hidden volumes should be printed",
"default": false
},
"showSubvolumes": {
"type": "boolean",
"description": "Set if subvolumes should be printed",
"default": false
},
"showReadOnly": {
"type": "boolean",
"description": "Set if read only volumes should be printed",
"default": false
},
"showUnknown": {
"type": "boolean",
"description": "Set if unknown (unable to detect sizes) volumes should be printed",
"default": false
},
"useAvailable": {
"type": "boolean",
"description": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes\nMay be required for macOS to display correct results",
"default": false
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/diskFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "DiskIO",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print physical disk I/O throughput",
"const": "diskio"
},
"namePrefix": {
"description": "Show disks with given name prefix only",
"type": "string"
},
"detectTotal": {
"description": "Detect total bytes instead of current rate",
"type": "boolean",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). Disk I/O = (totalBytesEnd - totalBytesStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/diskioFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Desktop Environment",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "de",
"description": "Print desktop environment name"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/deFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "DNS",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "dns",
"description": "Print DNS servers"
},
"showType": {
"oneOf": [
{
"const": "ipv4",
"description": "Show IPv4 addresses only"
},
{
"const": "ipv6",
"description": "Show IPv6 addresses only"
},
{
"const": "both",
"description": "Show both IPv4 and IPv6 addresses"
}
],
"default": "both",
"description": "Specify the type of DNS servers should be detected"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/dnsFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Editor",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "editor",
"description": "Print information of the default editor ($VISUAL or $EDITOR)"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/editorFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Font",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "font",
"description": "Print system font names"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/fontFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Gamepad",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "gamepad",
"description": "List connected gamepads"
},
"ignores": {
"type": "array",
"description": "An array of case-insensitive device name prefixes to ignore",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/gamepadFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "GPU",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print GPU names, graphic memory size, type, etc",
"const": "gpu"
},
"temp": {
"$ref": "#/$defs/temperature"
},
"driverSpecific": {
"description": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)\nRequires the latest GPU drivers to be installed.",
"type": "boolean",
"default": false
},
"detectionMethod": {
"description": "Force using a specified method to detect GPUs",
"type": "string",
"oneOf": [
{
"const": "auto",
"description": "Query platform-specific graphics APIs.\nRequires proper GPU drivers to be installed.\nSupported on Linux, FreeBSD, Windows and macOS"
},
{
"const": "pci",
"description": "Search PCI devices, which does not require GPU drivers to be installed.\nNot supported on Windows and macOS"
},
{
"const": "vulkan",
"description": "Use Vulkan API.\nSlow and requires proper Vulkan drivers to be installed.\nUsed for Android"
},
{
"const": "opencl",
"description": "Use OpenCL API.\nSlow and requires proper OpenCL drivers to be installed"
},
{
"const": "opengl",
"description": "Use OpenGL API.\nSlow and only detects one GPU.\nUsed for OpenBSD"
}
],
"default": ""
},
"hideType": {
"description": "Specify the type of GPUs should not be printed",
"oneOf": [
{
"const": null,
"description": "Do not hide any GPUs"
},
{
"const": "none",
"description": "Do not hide any GPUs (kept for compatibility)"
},
{
"const": "integrated",
"description": "Hide integrated GPUs"
},
{
"const": "discrete",
"description": "Hide discrete GPUs"
},
{
"const": "unknown",
"description": "Hide unknown (unrecognized) GPUs"
}
],
"default": null
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/gpuFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Host",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "host",
"description": "Print product name of your computer"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/hostFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Icons",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "icons",
"description": "Print icon style name"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/iconsFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Init System",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "initsystem",
"description": "Print init system (pid 1) name and version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/initsystemFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Kernel",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "kernel",
"description": "Print system kernel version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/kernelFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Keyboard",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "keyboard",
"description": "List (connected) keyboards"
},
"ignores": {
"type": "array",
"description": "An array of case-insensitive device name prefixes to ignore",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/keyboardFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Login Manager",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "lm",
"description": "Print login manager (desktop manager) name and version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/lmFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Local IP",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "List local IP addresses (v4 or v6), MAC addresses, etc",
"const": "localip"
},
"showIpv4": {
"description": "Show IPv4 addresses",
"type": "boolean",
"default": true
},
"showIpv6": {
"description": "Show IPv6 addresses",
"oneOf": [
{
"const": true,
"description": "Show the most useful IPv6 addresses"
},
{
"const": false,
"description": "Do not show IPv6 addresses"
},
{
"const": "gua",
"description": "Show only global unicast IPv6 addresses (2000::/3)"
},
{
"const": "ula",
"description": "Show only unique local IPv6 addresses (fc00::/7)"
},
{
"const": "lla",
"description": "Show only link-local IPv6 addresses (fe80::/10)"
},
{
"const": "unknown",
"description": "Show only IPv6 addresses that are not gua, ula or lla"
}
],
"default": false
},
"showSpeed": {
"description": "Show ethernet rx speed",
"type": "boolean",
"default": false
},
"showMtu": {
"description": "Show MTU",
"type": "boolean",
"default": false
},
"showMac": {
"description": "Show MAC addresses",
"type": "boolean",
"default": false
},
"showLoop": {
"description": "Show loop back addresses (127.0.0.1)",
"type": "boolean",
"default": false
},
"showPrefixLen": {
"description": "Show network prefix length (/N)",
"type": "boolean",
"default": true
},
"showAllIps": {
"description": "Show all IPs bound to the same interface.\nBy default only the firstly detected IP is shown",
"type": "boolean",
"default": false
},
"showFlags": {
"description": "Show the interface's flags",
"type": "boolean",
"default": false
},
"compact": {
"description": "Show all IPs in one line",
"type": "boolean",
"default": false
},
"namePrefix": {
"description": "Show IPs with given name prefix only",
"type": "string"
},
"defaultRouteOnly": {
"description": "Show ips that are used for default routing only\nDoesn't work on Android",
"type": "boolean",
"default": true
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/localipFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Loadavg",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "loadavg",
"description": "Print system load averages"
},
"ndigits": {
"type": "integer",
"description": "Set the number of digits to keep after the decimal point",
"minimum": 0,
"maximum": 9,
"default": 2
},
"compact": {
"type": "boolean",
"description": "Show values in one line",
"default": true
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/loadavgFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Locale",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "locale",
"description": "Print system locale name"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/localeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Logo",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "logo",
"description": "Query built-in logo for JSON output"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Media",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "media",
"description": "Print song name of currently playing"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/mediaFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Memory",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "memory",
"description": "Print system memory usage info"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/memoryFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Mouse",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "mouse",
"description": "List connected mouses"
},
"ignores": {
"type": "array",
"description": "An array of case-insensitive device name prefixes to ignore",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/mouseFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Monitor",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "monitor",
"description": "Alias of Display module (for backwards compatibility, deprecated)"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/monitorFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "NetIO",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print network I/O throughput",
"const": "netio"
},
"namePrefix": {
"description": "Show IPs with given name prefix only",
"type": "string"
},
"defaultRouteOnly": {
"description": "Show ips that are used for default routing only\nDoesn't work on Android",
"type": "boolean",
"default": true
},
"detectTotal": {
"description": "Detect total bytes instead of current rate",
"type": "boolean",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). Net I/O = (totalBytesEnd - totalBytesStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/netioFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "OpenCL",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "opencl",
"description": "Print highest OpenCL version supported by the GPU"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/openclFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "OpenGL",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print highest OpenGL version supported by the GPU",
"const": "opengl"
},
"library": {
"description": "Set the OpenGL context creation library to use",
"oneOf": [
{
"const": "auto",
"description": "Prefer EGL on *nix; prefer platform-specific implementation on others"
},
{
"const": "egl",
"description": "Use EGL, which works on TTY"
},
{
"const": "glx",
"description": "Use GLX, requires X session (*nix only)"
}
],
"default": "auto"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/openglFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Operating System",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "os",
"description": "Print OS / or Linux distro name and version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/osFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Packages",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "packages",
"description": "List installed package managers and count of installed packages"
},
"disabled": {
"oneOf": [
{
"description": "List of package managers to be disabled when detecting\nWarning: Some detection methods can be very slow.",
"type": "array",
"items": {
"type": "string",
"enum": [
"am",
"apk",
"brew",
"choco",
"dpkg",
"emerge",
"eopkg",
"flatpak",
"guix",
"hpkg",
"linglong",
"lpkg",
"lpkgbuild",
"macports",
"mport",
"nix",
"opkg",
"pacman",
"pacstall",
"paludis",
"pisi",
"pkg",
"pkgtool",
"rpm",
"scoop",
"snap",
"sorcery",
"winget",
"xbps"
],
"uniqueItems": true
}
},
{
"description": "Enable all package managers",
"type": "null"
}
],
"default": ["winget"]
},
"combined": {
"description": "Whether to combine related package managers into single counts (e.g., nix-system + nix-user = nix)",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/packagesFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Physical Disk",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print physical disk information",
"const": "physicaldisk"
},
"namePrefix": {
"description": "Show disks with given name prefix only",
"type": "string"
},
"temp": {
"$ref": "#/$defs/temperature"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/physicaldiskFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Physical Memory",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "physicalmemory",
"description": "Print system physical memory devices"
},
"showEmptySlots": {
"description": "Set if uninstalled memory slots should be printed",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/physicalmemoryFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Player",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "player",
"description": "Print music player name"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/playerFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Power Adapter",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "poweradapter",
"description": "Print power adapter name and charging watts"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/poweradapterFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Processes",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "processes",
"description": "Count running processes"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/processesFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Public IP",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print your public IP address, etc",
"const": "publicip"
},
"url": {
"description": "The URL of public IP detection server to be used. Only HTTP protocol is supported",
"type": "string",
"format": "url",
"default": "http://ipinfo.io/ip"
},
"timeout": {
"description": "Time in milliseconds to wait for the public ip server to respond.\n0 to disable timeout",
"type": "integer",
"minimum": 0,
"default": 0
},
"ipv6": {
"description": "Whether to use IPv6 for public IP detection server",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/publicipFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Separator",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print a separator line",
"const": "separator"
},
"string": {
"description": "Set the string to be printed by the separator line",
"type": "string",
"default": "-"
},
"outputColor": {
"description": "Set the color of the separator line",
"$ref": "#/$defs/outputColor"
},
"times": {
"description": "Set the times of separator string to repeat, or 0 to auto-detect",
"type": "integer",
"minimum": 0,
"default": 0
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Shell",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "shell",
"description": "Print current shell name and version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/shellFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Sound",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print sound devices, volume, etc",
"const": "sound"
},
"soundType": {
"description": "Set what type of sound devices should be printed",
"type": "string",
"oneOf": [
{
"const": "main",
"description": "Print only main sound devices"
},
{
"const": "active",
"description": "Print only active sound devices"
},
{
"const": "all",
"description": "Print all sound devices"
}
],
"default": "main"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/soundFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Swap",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "swap",
"description": "Print swap (paging file) space usage"
},
"separate": {
"type": "boolean",
"description": "Set if detailed swap devices should be reported on separate lines instead of a summary",
"default": false
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/swapFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Terminal",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "terminal",
"description": "Print current terminal name and version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/terminalFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Terminal Font",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "terminalfont",
"description": "Print font name and size used by current terminal"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/terminalfontFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Terminal Size",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "terminalsize",
"description": "Print current terminal size"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/terminalsizeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Terminal Theme",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "terminaltheme",
"description": "Print current terminal theme (foreground and background colors)"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/terminalthemeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Theme",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "theme",
"description": "Print current theme of desktop environment"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/themeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Title",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print title, which contains your user name, hostname",
"const": "title"
},
"fqdn": {
"type": "boolean",
"description": "Set if the title should use fully qualified domain name",
"default": false
},
"color": {
"description": "Set colors of the different part of title",
"type": "object",
"additionalProperties": false,
"properties": {
"user": {
"description": "Set color of the user name (left part)",
"$ref": "#/$defs/colors"
},
"at": {
"description": "Set color of the @ symbol (middle part)",
"$ref": "#/$defs/colors"
},
"host": {
"description": "Set color of the host name (right part)",
"$ref": "#/$defs/colors"
}
}
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/titleFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "TPM",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "tpm",
"description": "Print info of Trusted Platform Module (TPM) Security Device"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/tpmFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Users",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "users",
"description": "Print users currently logged in"
},
"compact": {
"type": "boolean",
"description": "Show all active users in one line",
"default": false
},
"myselfOnly": {
"type": "boolean",
"description": "Show only the current user",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/usersFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Uptime",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "uptime",
"description": "Print how long system has been running"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/uptimeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Version",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "version",
"description": "Print Fastfetch version"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/versionFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Vulkan",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "vulkan",
"description": "Print highest Vulkan version supported by the GPU"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/vulkanFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Wallpaper",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "wallpaper",
"description": "Print image file path of current wallpaper"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/wallpaperFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Weather",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"description": "Print weather information",
"const": "weather"
},
"location": {
"description": "The location to display\nMust be URI encoded (e.g., a whitespace must be encoded as \"+\")",
"type": "string"
},
"timeout": {
"description": "Time in milliseconds to wait for the weather server to respond.\n0 to disable timeout",
"type": "integer",
"minimum": 0,
"default": 0
},
"outputFormat": {
"description": "The output weather format to be used (must be URI encoded)",
"type": "string",
"default": "%t+-+%C+(%l)"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/weatherFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Wi-Fi",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "wifi",
"description": "Print connected Wi-Fi info (SSID, connection and security protocol)"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/wifiFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Window Manager",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "wm",
"description": "Print window manager name and version"
},
"detectPlugin": {
"description": "Set if window manager plugin should be detected on supported platforms",
"type": "boolean",
"default": true
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/wmFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "WM Theme",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "wmtheme",
"description": "Print current theme of window manager"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/wmthemeFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
},
{
"title": "Zpool",
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "zpool",
"description": "Print ZFS storage pools"
},
"percent": {
"$ref": "#/$defs/percent"
},
"key": {
"$ref": "#/$defs/key"
},
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyIcon": {
"$ref": "#/$defs/keyIcon"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"outputColor": {
"$ref": "#/$defs/outputColor"
},
"format": {
"$ref": "#/$defs/zpoolFormat"
},
"condition": {
"$ref": "#/$defs/conditions"
}
}
}
]
}
]
}
}
}
}
================================================
FILE: presets/all.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"padding": {
"top": 2
}
},
"modules": [
"title",
"separator",
"os",
"host",
"bios",
"bootmgr",
"board",
"chassis",
"kernel",
"initsystem",
"uptime",
"loadavg",
"processes",
"packages",
"shell",
"editor",
"display",
"brightness",
"monitor",
"lm",
"de",
"wm",
"wmtheme",
"theme",
"icons",
"font",
"cursor",
"wallpaper",
"terminal",
"terminalfont",
"terminalsize",
"terminaltheme",
{
"type": "cpu",
"showPeCoreCount": true,
"temp": true
},
"cpucache",
"cpuusage",
{
"type": "gpu",
"driverSpecific": true,
"temp": true
},
"memory",
"physicalmemory",
{
"type": "swap",
"separate": true
},
"disk",
"btrfs",
"zpool",
{
"type": "battery",
"temp": true
},
"poweradapter",
"player",
"media",
{
"type": "publicip",
"timeout": 1000
},
{
"type": "localip",
"showIpv6": true,
"showMac": true,
"showSpeed": true,
"showMtu": true,
"showLoop": true,
"showFlags": true,
"showAllIps": true
},
"dns",
"wifi",
"datetime",
"locale",
"vulkan",
"opengl",
"opencl",
"users",
"bluetooth",
"bluetoothradio",
"sound",
"camera",
"gamepad",
"mouse",
"keyboard",
{
"type": "weather",
"timeout": 1000
},
"netio",
"diskio",
{
"type": "physicaldisk",
"temp": true
},
"tpm",
"version",
"break",
"colors"
]
}
================================================
FILE: presets/archey.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"modules": [
{
"type": "title",
"key": "User",
"format": "{user-name}"
},
{
"type": "title",
"key": "Hostname",
"format": "{host-name}"
},
{
"type": "host",
"key": "Model"
},
{
"type": "os",
"format": "{pretty-name} {version-id} {arch}"
},
"kernel",
"uptime",
{
"type": "loadavg",
"key": "Load Average"
},
"processes",
{
"type": "wm",
"key": "Window Manager"
},
{
"type": "de",
"key": "Desktop Environment"
},
"shell",
{
"type": "terminal",
"format": "{pretty-name} {version} {#37}█{#97}█ {#36}█{#96}█ {#35}█{#95}█ {#34}█{#94}█ {#33}█{#93}█ {#32}█{#92}█ {#31}█{#91}█ {#30}█{#90}█"
},
{
"type": "packages",
"format": "{all}"
},
{
"type": "cpu",
"key": "Temperature",
"temp": true,
"format": "{temperature}"
},
{
"type": "cpu",
"key": "CPU",
"format": "{cores-logical} x {name}"
},
{
"type": "gpu",
"format": "{name}"
},
{
"type": "memory",
"key": "RAM"
},
{
"type": "disk",
"key": "Disk",
"folders": "/"
},
{
"type": "localip",
"key": "LAN IP",
"showIpv6": true,
"showPrefixLen": false
},
{
"type": "publicip",
"key": "WAN IP",
"timeout": 1000
}
]
}
================================================
FILE: presets/ci.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"display": {
"stat": true,
"pipe": true,
"showErrors": true,
"noBuffer": true
},
"logo": null,
"modules": [
"title",
"separator",
"os",
"host",
"bios",
"bootmgr",
"board",
"chassis",
"kernel",
"initsystem",
"uptime",
"loadavg",
"processes",
"packages",
"shell",
"editor",
"display",
"brightness",
"monitor",
"lm",
"de",
"wm",
"wmtheme",
"theme",
"icons",
"font",
"cursor",
"wallpaper",
"terminal",
"terminalfont",
"terminalsize",
"terminaltheme",
{
"type": "cpu",
"showPeCoreCount": true,
"temp": true
},
"cpucache",
"cpuusage",
{
"type": "gpu",
"driverSpecific": true,
"temp": true
},
"memory",
"physicalmemory",
{
"type": "swap",
"separate": true
},
"disk",
"btrfs",
"zpool",
{
"type": "battery",
"temp": true
},
"poweradapter",
"player",
"media",
{
"type": "publicip",
"timeout": 1000
},
{
"type": "localip",
"showIpv6": true,
"showMac": true,
"showSpeed": true,
"showMtu": true,
"showLoop": true,
"showFlags": true,
"showAllIps": true
},
"dns",
"wifi",
"datetime",
"locale",
"vulkan",
"opengl",
"opencl",
"users",
// "bluetooth", // doesn't work on macOS because it requires bluetooth permissions
// "bluetoothradio",
"sound",
"camera",
"gamepad",
"mouse",
"keyboard",
{
"type": "weather",
"timeout": 1000
},
"netio",
"diskio",
{
"type": "physicaldisk",
"temp": true
},
"tpm",
"version",
"logo",
"break",
"colors"
]
}
================================================
FILE: presets/examples/10.jsonc
================================================
// Load with --config examples/2.jsonc
// Note that you must replace the image path to an existing image to display it.
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"padding": {
"top": 2
}
},
"display": {
"separator": " -> ",
"constants": [
"──────────────────────────────"
]
},
"modules": [
{
"type": "custom",
"format": "┌{$1}{$1}┐",
"outputColor": "90"
},
{
"type": "title",
"keyWidth": 10
},
{
"type": "custom",
"format": "└{$1}{$1}┘",
"outputColor": "90"
},
{
"type": "custom",
"format": " {#90} {#31} {#32} {#33} {#34} {#35} {#36} {#37} {#38} {#39} {#38} {#37} {#36} {#35} {#34} {#33} {#32} {#31} {#90}"
},
{
"type": "custom",
"format": "┌{$1}{$1}┐",
"outputColor": "90"
},
{
"type": "os",
"key": "{icon} OS",
"keyColor": "yellow"
},
{
"type": "kernel",
"key": "│ ├",
"keyColor": "yellow"
},
{
"type": "packages",
"key": "│ ├",
"keyColor": "yellow"
},
{
"type": "shell",
"key": "│ └",
"keyColor": "yellow"
},
{
"type": "wm",
"key": " DE/WM",
"keyColor": "blue"
},
{
"type": "lm",
"key": "│ ├",
"keyColor": "blue"
},
{
"type": "wmtheme",
"key": "│ ├",
"keyColor": "blue"
},
{
"type": "icons",
"key": "│ ├",
"keyColor": "blue"
},
{
"type": "terminal",
"key": "│ ├",
"keyColor": "blue"
},
{
"type": "wallpaper",
"key": "│ └",
"keyColor": "blue"
},
{
"type": "host",
"key": " PC",
"keyColor": "green"
},
{
"type": "cpu",
"key": "│ ├",
"keyColor": "green"
},
{
"type": "gpu",
"key": "│ ├",
"keyColor": "green"
},
{
"type": "disk",
"key": "│ ├",
"keyColor": "green"
},
{
"type": "memory",
"key": "│ ├",
"keyColor": "green"
},
{
"type": "swap",
"key": "│ ├",
"keyColor": "green"
},
{
"type": "uptime",
"key": "│ ├",
"keyColor": "green"
},
{
"type": "display",
"key": "│ └",
"keyColor": "green"
},
{
"type": "sound",
"key": " SND",
"keyColor": "cyan"
},
{
"type": "player",
"key": "│ ├",
"keyColor": "cyan"
},
{
"type": "media",
"key": "│ └",
"keyColor": "cyan"
},
{
"type": "custom",
"format": "└{$1}{$1}┘",
"outputColor": "90"
},
"break",
{
"type": "custom",
"format": " {#90} {#31} {#32} {#33} {#34} {#35} {#36} {#37} {#38} {#39} {#38} {#37} {#36} {#35} {#34} {#33} {#32} {#31} {#90}"
}
]
}
================================================
FILE: presets/examples/11.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"separator": "-> ",
"color": {
"separator": "red"
}
},
"modules": [
{
"key": "Distro ",
"type": "os"
},
{
"key": "Shell ",
"type": "shell"
},
{
"key": "Terminal ",
"type": "terminal"
},
{
"key": "Display ",
"type": "display"
},
{
"key": "Backlight ",
"type": "brightness"
},
"break",
{
"type": "colors",
"paddingLeft": 6,
"symbol": "circle"
}
]
}
================================================
FILE: presets/examples/12.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "none"
},
"display": {
"separator": "-> ",
"color": {
"separator": "1" // Bold
},
"constants": [
"───────────────────────────"
],
"key": {
"type": "both",
"paddingLeft": 4
}
},
"modules": [
{
"type": "title",
"format": " {user-name-colored}{at-symbol-colored}{host-name-colored}"
},
"break",
{
"type": "custom",
"format": "┌{$1} {#1}System Information{#} {$1}┐"
},
"break",
{
"key": "OS ",
"keyColor": "red",
"type": "os"
},
{
"key": "Machine ",
"keyColor": "green",
"type": "host"
},
{
"key": "Kernel ",
"keyColor": "magenta",
"type": "kernel"
},
{
"key": "Uptime ",
"keyColor": "red",
"type": "uptime"
},
{
"key": "Resolution ",
"keyColor": "yellow",
"type": "display",
"compactType": "original-with-refresh-rate"
},
{
"key": "WM ",
"keyColor": "blue",
"type": "wm"
},
{
"key": "DE ",
"keyColor": "green",
"type": "de"
},
{
"key": "Shell ",
"keyColor": "cyan",
"type": "shell"
},
{
"key": "Terminal ",
"keyColor": "red",
"type": "terminal"
},
{
"key": "CPU ",
"keyColor": "yellow",
"type": "cpu"
},
{
"key": "GPU ",
"keyColor": "blue",
"type": "gpu"
},
{
"key": "Memory ",
"keyColor": "magenta",
"type": "memory"
},
{
"key": "Local IP ",
"keyColor": "red",
"type": "localip",
"compact": true
},
{
"key": "Public IP ",
"keyColor": "cyan",
"type": "publicip",
"timeout": 1000
},
"break",
{
"type": "custom",
"format": "└{$1}────────────────────{$1}┘"
},
"break",
{
"type": "colors",
"paddingLeft": 34,
"symbol": "circle"
}
]
}
================================================
FILE: presets/examples/13.jsonc
================================================
// Inspired by Catnap
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"top": 1
}
},
"display": {
"separator": " "
},
"modules": [
{
"key": "╭───────────╮",
"type": "custom"
},
{
"key": "│ {#31} user {#keys}│",
"type": "title",
"format": "{user-name}"
},
{
"key": "│ {#32} hname {#keys}│",
"type": "title",
"format": "{host-name}"
},
{
"key": "│ {#33} uptime {#keys}│",
"type": "uptime"
},
{
"key": "│ {#34}{icon} distro {#keys}│",
"type": "os"
},
{
"key": "│ {#35} kernel {#keys}│",
"type": "kernel"
},
{
"key": "│ {#36} desktop {#keys}│",
"type": "de"
},
{
"key": "│ {#31} term {#keys}│",
"type": "terminal"
},
{
"key": "│ {#32} shell {#keys}│",
"type": "shell"
},
{
"key": "│ {#33} cpu {#keys}│",
"type": "cpu",
"showPeCoreCount": true
},
{
"key": "│ {#34} disk {#keys}│",
"type": "disk",
"folders": "/"
},
{
"key": "│ {#35} memory {#keys}│",
"type": "memory"
},
{
"key": "│ {#36} network {#keys}│",
"type": "localip",
"format": "{ipv4} ({ifname})"
},
{
"key": "├───────────┤",
"type": "custom"
},
{
"key": "│ {#39} colors {#keys}│",
"type": "colors",
"symbol": "circle"
},
{
"key": "╰───────────╯",
"type": "custom"
}
]
}
================================================
FILE: presets/examples/14.jsonc
================================================
// Inspired by Catnap
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"separator": "",
"key": {
"width": 15
}
},
"modules": [
{
// draw borders first to make colors of left and right border consistant
"key": " user",
"type": "title",
"format": "{user-name}",
"keyColor": "31"
},
{
"key": " hname",
"type": "title",
"format": "{host-name}",
"keyColor": "32"
},
{
"key": " uptime",
"type": "uptime",
"keyColor": "33"
},
{
"key": "{icon} distro",
"type": "os",
"keyColor": "34"
},
{
"key": " kernel",
"type": "kernel",
"keyColor": "35"
},
{
"key": " desktop",
"type": "de",
"keyColor": "36"
},
{
"key": " term",
"type": "terminal",
"keyColor": "31"
},
{
"key": " shell",
"type": "shell",
"keyColor": "32"
},
{
"key": " cpu",
"type": "cpu",
"showPeCoreCount": true,
"keyColor": "33"
},
{
"key": " disk",
"type": "disk",
"folders": "/",
"keyColor": "34"
},
{
"key": " memory",
"type": "memory",
"keyColor": "35"
},
{
"key": " network",
"type": "localip",
"format": "{ipv4} ({ifname})",
"keyColor": "36"
},
{
"key": " colors",
"type": "colors",
"symbol": "circle",
"keyColor": "39"
}
]
}
================================================
FILE: presets/examples/15.jsonc
================================================
// Inspired by Catnap
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"top": 1
}
},
"display": {
"separator": " "
},
"modules": [
{
"key": "•••••••••••••",
"type": "custom"
},
{
"key": "• {#31} user {#keys}•",
"type": "title",
"format": "{user-name}"
},
{
"key": "• {#32} hname {#keys}•",
"type": "title",
"format": "{host-name}"
},
{
"key": "• {#33} uptime {#keys}•",
"type": "uptime"
},
{
"key": "• {#34}{icon} distro {#keys}•",
"type": "os"
},
{
"key": "• {#35} kernel {#keys}•",
"type": "kernel"
},
{
"key": "• {#36} desktop {#keys}•",
"type": "de"
},
{
"key": "• {#31} term {#keys}•",
"type": "terminal"
},
{
"key": "• {#32} shell {#keys}•",
"type": "shell"
},
{
"key": "• {#33} cpu {#keys}•",
"type": "cpu",
"showPeCoreCount": true
},
{
"key": "• {#34} disk {#keys}•",
"type": "disk",
"folders": "/"
},
{
"key": "• {#35} memory {#keys}•",
"type": "memory"
},
{
"key": "• {#36} network {#keys}•",
"type": "localip",
"format": "{ipv4} ({ifname})"
},
{
"key": "•••••••••••••",
"type": "custom"
},
{
"key": "• {#39} colors {#keys}•",
"type": "colors",
"symbol": "circle"
},
{
"key": "•••••••••••••",
"type": "custom"
}
]
}
================================================
FILE: presets/examples/16.jsonc
================================================
// Inspired by Catnap
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"top": 1
}
},
"display": {
"separator": " "
},
"modules": [
{
"key": "╔═══════════╗",
"type": "custom"
},
{
"key": "║ {#31} user {#keys}║",
"type": "title",
"format": "{user-name}"
},
{
"key": "║ {#32} hname {#keys}║",
"type": "title",
"format": "{host-name}"
},
{
"key": "║ {#33} uptime {#keys}║",
"type": "uptime"
},
{
"key": "║ {#34}{icon} distro {#keys}║",
"type": "os"
},
{
"key": "║ {#35} kernel {#keys}║",
"type": "kernel"
},
{
"key": "║ {#36} desktop {#keys}║",
"type": "de"
},
{
"key": "║ {#31} term {#keys}║",
"type": "terminal"
},
{
"key": "║ {#32} shell {#keys}║",
"type": "shell"
},
{
"key": "║ {#33} cpu {#keys}║",
"type": "cpu",
"showPeCoreCount": true
},
{
"key": "║ {#34} disk {#keys}║",
"type": "disk",
"folders": "/"
},
{
"key": "║ {#35} memory {#keys}║",
"type": "memory"
},
{
"key": "║ {#36} network {#keys}║",
"type": "localip",
"format": "{ipv4} ({ifname})"
},
{
"key": "╠═══════════╣",
"type": "custom"
},
{
"key": "║ {#39} colors {#keys}║",
"type": "colors",
"symbol": "circle"
},
{
"key": "╚═══════════╝",
"type": "custom"
}
]
}
================================================
FILE: presets/examples/17.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"top": 1,
"right": 2
}
},
"display": {
"separator": "> ",
"color": {
"separator": "red"
},
"constants": [
"───────────────────────────────────────────────────────────────────────────",
"│\u001b[75C│\u001b[75D"
]
},
"modules": [
{
"format": "{#1}{#keys}╭{$1}╮\u001b[76D {user-name-colored}{at-symbol-colored}{host-name-colored} 🖥 ",
"type": "title"
},
{
"key": "{$2}{#31} kernel ",
"type": "kernel"
},
{
"key": "{$2}{#32} uptime ",
"type": "uptime"
},
{
"key": "{$2}{#33}{icon} distro ",
"type": "os"
},
{
"key": "{$2}{#34} desktop ",
"type": "de"
},
{
"key": "{$2}{#35} term ",
"type": "terminal"
},
{
"key": "{$2}{#36} shell ",
"type": "shell"
},
{
"key": "{$2}{#35} cpu ",
"type": "cpu",
"showPeCoreCount": true,
"temp": true
},
{
"key": "{$2}{#34} gpu ",
"type": "gpu"
},
{
"key": "{$2}{#33} disk ",
"type": "disk",
"folders": "/"
},
{
"key": "{$2}{#32} memory ",
"type": "memory"
},
{
"key": "{$2}{#31} network ",
"type": "localip",
"format": "{ipv4} ({ifname})"
},
{
"format": "{#1}{#keys}├{$1}┤",
"type": "custom"
},
{
"key": "{$2}{#39} colors ",
"type": "colors",
"symbol": "circle"
},
{
"format": "{#1}{#keys}╰{$1}╯",
"type": "custom"
}
]
}
================================================
FILE: presets/examples/18.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"top": 1,
"right": 2
}
},
"display": {
"separator": "> ",
"color": {
"separator": "red"
},
"constants": [
"═══════════════════════════════════════════════════════════════════════════",
"║\u001b[75C║\u001b[75D"
]
},
"modules": [
{
"format": "{#1}{#keys}╔{$1}╗\u001b[76D {user-name-colored}{at-symbol-colored}{host-name-colored} 💻 ",
"type": "title"
},
{
"key": "{$2}{#31} kernel ",
"type": "kernel"
},
{
"key": "{$2}{#32} uptime ",
"type": "uptime"
},
{
"key": "{$2}{#33}{icon} distro ",
"type": "os"
},
{
"key": "{$2}{#34} desktop ",
"type": "de"
},
{
"key": "{$2}{#35} term ",
"type": "terminal"
},
{
"key": "{$2}{#36} shell ",
"type": "shell"
},
{
"key": "{$2}{#35} cpu ",
"type": "cpu",
"showPeCoreCount": true,
"temp": true
},
{
"key": "{$2}{#34} gpu ",
"type": "gpu"
},
{
"key": "{$2}{#33} disk ",
"type": "disk",
"folders": "/"
},
{
"key": "{$2}{#32} memory ",
"type": "memory"
},
{
"key": "{$2}{#31} network ",
"type": "localip",
"format": "{ipv4} ({ifname})"
},
{
"format": "{#1}{#keys}╠{$1}╣",
"type": "custom"
},
{
"key": "{$2}{#39} colors ",
"type": "colors",
"symbol": "circle"
},
{
"format": "{#1}{#keys}╚{$1}╝",
"type": "custom"
}
]
}
================================================
FILE: presets/examples/19.jsonc
================================================
// _____ _____ _____ _____ _____ _____ _____ _____ _____
// | __| _ | __|_ _| __| __|_ _| | | |
// | __| |__ | | | | __| __| | | | --| |
// |__| |__|__|_____| |_| |__| |_____| |_| |_____|__|__|
//
// By CarterLi - https://github.com/CarterLi
// Homepage - https://github.com/fastfetch-cli/fastfetch
// config.jsonc - ニリ @niri-san
// pokemon-colorscripts - https://gitlab.com/phoneybadger/pokemon-colorscripts
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"source": " _____ _____ _____ _____ _____ _____ _____ _____ _____\n| __| _ | __|_ _| __| __|_ _| | | |\n| __| |__ | | | | __| __| | | | --| |\n|__| |__|__|_____| |_| |__| |_____| |_| |_____|__|__|",
"type": "data",
"position": "top",
"padding": {
"right": 2
}
},
"display": {
"separator": " - "
},
"modules": [
{
"type": "custom", // HardwareInfo
"format": "• {#green}SYSTEM INFORMATION"
},
{
"type": "host",
"key": "HOST",
"format": "{name}{?vendor} ({vendor}){?}",
"keyColor": "green"
},
{
"type": "chassis",
"key": "COMPUTER TYPE",
"keyColor": "green"
},
{
"type": "cpu",
"key": "CPU",
"keyColor": "green"
},
{
"type": "gpu",
"key": "GPU",
"keyColor": "green"
},
{
"type": "memory",
"key": "MEMORY USED",
"keyColor": "green"
},
{
"type": "swap",
"key": "SWAP USED",
"keyColor": "green"
},
{
"type": "disk",
"key": "DISK",
"folders": "/",
"keyColor": "green"
},
{
"type": "custom", // SoftwareInfo
"format": "• {#red}SOFTWARE INFORMATION"
},
{
"type": "os",
"key": "DISTRO",
"keyColor": "red"
},
{
"type": "disk",
"folders": "/", // Use "/System/Volumes/VM" or something else on macOS
"format": "{create-time}",
"key": "INSTALLED DATE",
"keyColor": "red"
},
{
"type": "kernel",
"key": "KERNEL",
"keyColor": "red"
},
{
"type": "packages",
"key": "PACKAGES",
"keyColor": "red"
},
{
"type": "uptime",
"key": "UPTIME",
"keyColor": "red"
},
{
"type": "custom", // DisplayInfo
"format": "• {#blue}DISPLAY INFORMATION"
},
{
"type": "de",
"key": "DESKTOP ENVIRONMENT",
"keyColor": "blue"
},
{
"type": "lm",
"key": "LOGIN MANAGER",
"format": "{type}",
"keyColor": "blue"
},
{
"type": "wm",
"key": "WM",
"keyColor": "blue"
},
{
"type": "wmtheme",
"key": "WM THEME",
"keyColor": "blue"
},
{
"type": "display",
"key": "MONITOR ({name})",
"keyColor": "blue",
"format": "{width}x{height} @ {refresh-rate} Hz - {physical-width}x{physical-height} mm ({inch} inches, {ppi} ppi)"
},
{
"type": "custom", // DesignInfo
"format": "• {#yellow}DESIGN INFORMATION"
},
{
"type": "wallpaper",
"key": "WALLPAPER",
"keyColor": "yellow"
},
{
"type": "theme",
"key": "KDE THEME",
"format": "{1}",
"keyColor": "yellow"
},
{
"type": "icons",
"key": "ICON THEME",
"format": "{1}",
"keyColor": "yellow"
},
{
"type": "font",
"key": "FONT",
"format": "{?1}{1} [Qt]{?}{/1}Unknown", // Remove "[Qt]" if not using Qt
"keyColor": "yellow"
},
{
"type": "terminalfont",
"key": "TERMINAL FONT",
"keyColor": "yellow"
},
{
"type": "cursor",
"key": "CURSOR",
"keyColor": "yellow"
},
{
"type": "custom", // OtherInfo
"format": "• {#cyan}VARIOUS INFORMATION"
},
{
"type": "media",
"key": "NOW PLAYING",
"format": "{?artist}{artist} - {?}{title}",
"keyColor": "cyan"
},
{
"type": "weather",
"key": "WEATHER",
"timeout": 1000,
"keyColor": "cyan"
},
{
"type": "version",
"key": "INFO",
"keyColor": "cyan"
},
"break",
"colors",
"break"
]
}
================================================
FILE: presets/examples/2.jsonc
================================================
// Load with --config examples/2.jsonc
// Note that you must replace the image path to an existing image to display it.
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
// "logo": {
// "type": "iterm",
// "source": "~/Desktop/apple1.png",
// "width": 28,
// "height": 12
// },
"display": {
"separator": " ",
"constants": [
"─────────────────" // {$1}, used in Custom module
],
"key": {
"type": "icon",
"paddingLeft": 2
}
},
"modules": [
{
"type": "custom", // HardwareStart
// {#1} is equivalent to `\u001b[1m`. {#} is equivalent to `\u001b[m`
"format": "┌{$1} {#1}Hardware Information{#} {$1}┐"
},
"host",
"cpu",
"gpu",
"disk",
"memory",
"swap",
"display",
"brightness",
"battery",
"poweradapter",
"bluetooth",
"sound",
"gamepad",
{
"type": "custom", // SoftwareStart
"format": "├{$1} {#1}Software Information{#} {$1}┤"
},
{
"type": "title",
"keyIcon": "",
"key": "Title", // Title module has no key by default, so that icon is not displayed
"format": "{user-name}@{host-name}"
},
"os",
"kernel",
"lm",
"de",
"wm",
"shell",
"terminal",
"terminalfont",
"theme",
"icons",
"wallpaper",
"packages",
"uptime",
"media",
{
"type": "localip",
"compact": true
},
{
"type": "publicip",
"timeout": 1000
},
{
"type": "wifi",
"format": "{ssid}"
},
"locale",
{
"type": "custom", // InformationEnd
"format": "└{$1}──────────────────────{$1}┘"
},
{
"type": "colors",
"paddingLeft": 2,
"symbol": "circle"
}
]
}
================================================
FILE: presets/examples/20.jsonc
================================================
// Inspired by https://github.com/usgraphics/TR-100
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": null,
"display": {
"pipe": true,
"key": {
"width": 16
},
"separator": "│ ",
"percent": {
"type": ["bar", "hide-others"]
},
"bar": {
"border": null,
"char": {
"elapsed": "█",
"total": "░"
},
"width": 40
},
"constants": [
"\u001b[42C"
]
},
"modules": [
{
"type": "custom",
"format": "┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐"
},
{
"type": "custom",
"format": "├┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┤"
},
{
"type": "version",
"key": " ",
"format": "│ FASTFETCH v{version} │"
},
{
"type": "custom",
"format": "│ TR-100 MACHINE REPORT │"
},
{
"type": "custom",
"format": "├────────────┬──────────────────────────────────────────┤"
},
{
"type": "os",
"key": "│ OS │{$1}"
},
{
"type": "kernel",
"key": "│ KERNEL │{$1}"
},
{
"type": "custom",
"format": "├────────────┼──────────────────────────────────────────┤"
},
{
"type": "title",
"key": "│ HOSTNAME │{$1}",
"format": "{host-name}"
},
{
"type": "localip",
"key": "│ CLIENT IP │{$1}",
"format": "{ipv4}"
},
{
"type": "localip",
"key": "│ MAC ADDR │{$1}",
"format": "{mac} ({ifname})",
"showIpv4": false,
"showMac": true
},
{
"type": "dns",
"key": "│ DNS │{$1}",
"showType": "ipv4"
},
{
"type": "title",
"key": "│ USER │{$1}",
"format": "{user-name}"
},
{
"type": "host",
"key": "│ MACHINE │{$1}",
"format": "{name}"
},
{
"type": "custom",
"format": "├────────────┼──────────────────────────────────────────┤"
},
{
"type": "cpu",
"key": "│ PROCESSOR │{$1}",
"format": "{name}"
},
{
"type": "cpu",
"key": "│ CORES │{$1}",
"format": "{cores-physical} PHYSICAL CORES / {cores-logical} THREADS",
"showPeCoreCount": false
},
{
"type": "cpu",
"key": "│ CPU FREQ │{$1}",
"format": "{freq-max}{/freq-max}{freq-base}{/}"
},
{
"type": "loadavg",
"compact": false,
"key": "│ LOAD {duration>2}m │{$1}" // pad duration to 2 chars
},
{
"type": "custom",
"format": "├────────────┼──────────────────────────────────────────┤"
},
{
"type": "memory",
"key": "│ MEMORY │{$1}",
"format": "{used} / {total} [{percentage}]",
"percent": {
"type": ["num"]
}
},
{
"type": "memory",
"key": "│ USAGE │{$1}",
"format": "",
"percent": {
"type": ["bar", "hide-others"]
}
},
{
"type": "custom",
"format": "├────────────┼──────────────────────────────────────────┤"
},
{
"type": "disk",
"key": "│ VOLUME │{$1}",
"format": "{size-used} / {size-total} [{size-percentage}]",
"folders": "/",
"percent": {
"type": ["num"]
}
},
{
"type": "disk",
"key": "│ DISK USAGE │{$1}",
"format": "",
"percent": {
"type": ["bar", "hide-others"]
}
},
{
"type": "custom",
"format": "├────────────┼──────────────────────────────────────────┤"
},
{
"type": "users",
"key": "│ LAST LOGIN │{$1}",
"format": "{login-time}{?client-ip} ({client-ip})",
"myselfOnly": true
},
{
"type": "uptime",
"key": "│ UPTIME │{$1}"
},
{
"type": "custom",
"format": "└────────────┴──────────────────────────────────────────┘"
}
]
}
================================================
FILE: presets/examples/21.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"constants": [
"██ "
]
},
"modules": [
{
"key": "{$1}Distro",
"keyColor": "38;5;210",
"type": "os"
},
{
"key": "{$1}Kernel",
"keyColor": "38;5;84",
"type": "kernel"
},
{
"key": "{$1}Shell",
"keyColor": "38;5;147",
"type": "shell"
},
{
"key": "{$1}Packages",
"keyColor": "38;5;200",
"type": "packages"
},
{
"key": "{$1}WM",
"keyColor": "38;5;44",
"type": "wm"
},
{
"key": "{$1}CPU",
"keyColor": "38;5;75",
"type": "cpu"
},
{
"key": "{$1}Memory",
"keyColor": "38;5;123",
"type": "memory"
}
]
}
================================================
FILE: presets/examples/22.jsonc
================================================
// Designed for Arch Linux
// Modified from: https://github.com/fastfetch-cli/fastfetch/pull/1025#issuecomment-2177566138
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"source": "arch3",
"color": {
"1": "red",
"2": "yellow"
}
},
"display": {
"color": {
"separator": "blue"
},
"separator": " | ",
"constants": [
">-----------<+>---------------------------------------------<"
]
},
"modules": [
{
"type": "kernel",
"key": " /\\rch Linux",
"keyColor": "magenta"
},
{
"type": "custom",
"format": "{$1}",
"outputColor": "separator"
},
{
"type": "uptime",
"key": " Uptime ",
"keyColor": "green"
},
{
"type": "shell",
"key": " Shell ",
"keyColor": "green"
},
{
"type": "terminal",
"key": " Terminal ",
"keyColor": "green"
},
{
"type": "terminalfont",
"key": " Font ",
"keyColor": "green"
},
{
"type": "packages",
"key": " Packages ",
"keyColor": "green"
},
{
"type": "localip",
"key": " Local IP ",
"keyColor": "green"
},
{
"type": "custom",
"format": "{$1}",
"outputColor": "separator"
},
{
"type": "display",
"key": " Display ",
"keyColor": "cyan"
},
{
"type": "cpu",
"key": " CPU ",
"keyColor": "cyan"
},
{
"type": "gpu",
"key": " GPU ",
"keyColor": "cyan"
},
{
"type": "memory",
"key": " RAM ",
"keyColor": "cyan"
},
{
"type": "swap",
"key": " SWAP ",
"keyColor": "cyan"
},
{
"type": "disk",
"key": " Disk ",
"keyColor": "cyan"
},
{
"type": "battery",
"key": " Battery ",
"keyColor": "cyan"
},
{
"type": "custom",
"format": "{$1}",
"outputColor": "separator"
},
"break",
{
"type": "colors",
"paddingLeft": 15
}
]
}
================================================
FILE: presets/examples/23.jsonc
================================================
// designed for presenting Vanilla Linux
// inspired from imstilllearnin's Vanilla Logo Ultra
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"color": {
"output": "cyan"
},
"separator": ""
},
"modules": [
{
"type": "kernel",
"key": "[_Kernel___> ",
"keyColor": "blue"
},
{
"type": "packages",
"outputColor": "white",
"key": " [_Packages_> ",
"keyColor": "green"
},
{
"type": "localip",
"outputColor": "white",
"key": " [_Local_IP_> ",
"keyColor": "green"
},
{
"type": "memory",
"format": "[{3}] {1} / {2}",
"key": " [_RAM______> ",
"keyColor": "magenta"
},
{
"type": "swap",
"format": "[{3}] {1} / {2}",
"key": " [_SWAP_____> ",
"keyColor": "magenta"
},
{
"type": "disk",
"format": "[{3}] {1} / {2} {9}",
"key": " [_Disk_____> ",
"keyColor": "magenta"
},
{
"type": "battery",
"format": "[{4}] {5}",
"key": " [_Battery__> ",
"keyColor": "magenta"
},
"break",
{
"type": "colors",
"paddingLeft": 9,
"symbol": "circle"
}
]
}
================================================
FILE: presets/examples/24.jsonc
================================================
// By jan-rex
// Modified from: https://github.com/fastfetch-cli/fastfetch/discussions/1269
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"padding": {
"top": 2
}
},
"display": {
"separator": "",
"constants": [
// CONSTANT {$1} - COLOR BACKGROUND FOR KEY
"\u001b[48;2;43;43;69m",
// CONSTANT {$2} - COLOR BACKGROUND FOR OUTPUT
"\u001b[48;2;56;59;78m",
// CONSTANT {$3} - VERTICAL BARS AT START AND 75th CHARACTERS FORWARD AND BACKWARD
"\u001b[90m│ │\u001b[60D\u001b[39m",
]
},
"modules": [
// CUSTOM - Top UI bar
{
"type": "custom",
"key": "{#90}{$1}╭─────────────╮",
"format": "{#90}{$2}╭────────────────────────────────────────────────────────────╮",
},
{
"type": "title",
"key": "{#90}{$1}│ {#92}User {#90}│",
"format": "{$2}{$3}{user-name} {#2}[{home-dir}]"
},
{
"type": "users",
"key": "{#90}{$1}│ {#92}Users {#90}│",
"myselfOnly": false,
"format": "{$2}{$3}{1}@{host-name}{/host-name}localhost{/}{?client-ip} {#2}[IP:{client-ip}]{?} [Login time: {login-time}]"
},
{
"type": "datetime",
"key": "{#90}{$1}│ {#92}Datetime {#90}│",
"format": "{$2}{$3}{year}-{month-pretty}-{day-in-month} {hour-pretty}:{minute-pretty}:{second-pretty} [{weekday}] [W{week}] [UTC{offset-from-utc}]"
},
{
"type": "title",
"key": "{#90}{$1}│ {#93}Host {#90}│",
"format": "{$2}{$3}{host-name}"
},
{
"type": "host",
"key": "{#90}{$1}│ {#93}Machine {#90}│",
"format": "{$2}{$3}{name} {#2}{version}"
},
{
"type": "os",
"key": "{#90}{$1}│ {#93}OS {#90}│",
"format": "{$2}{$3}{?pretty-name}{pretty-name}{?}{/pretty-name}{name}{/} {codename} {#2}[v{version}] [{arch}]"
},
{
"type": "kernel",
"key": "{#90}{$1}│ {#93}Kernel {#90}│",
"format": "{$2}{$3}{sysname} {#2}[v{release}]"
},
{
"type": "uptime",
"key": "{#90}{$1}│ {#93}Uptime {#90}│",
"format": "{$2}{$3}{?days}{days} Days + {?}{hours}:{minutes}:{seconds}"
},
{
"type": "cpu",
"key": "{#90}{$1}│ {#91}CPU {#90}│",
"showPeCoreCount": true,
"temp": true,
"format": "{$2}{$3}{name} {#2}[C:{core-types}] [{freq-max}]"
},
{
"type": "gpu",
"key": "{#90}{$1}│ {#91}GPU {#90}│",
"detectionMethod": "auto",
"driverSpecific": true,
"format": "{$2}{$3}{name} {#2}[C:{core-count}]{?frequency} [{frequency}]{?} [{type}]"
},
{
"type": "memory",
"key": "{#90}{$1}│ {#91}Memory {#90}│",
"format": "{$2}{$3}{used} / {total} ({percentage}{$2})"
},
{
"type": "disk",
"key": "{#90}{$1}│ {#91}Disk {#90}│",
"format": "{$2}{$3}{size-used} / {size-total} ({size-percentage}{$2})"
},
{
"type": "poweradapter",
"key": "{#90}{$1}│ {#91}Power {#90}│",
"format": "{$2}{$3}{name}"
},
{
"type": "terminal",
"key": "{#90}{$1}│ {#95}Terminal {#90}│",
"format": "{$2}{$3}{pretty-name} {#2}[{version}] [PID:{pid}]"
},
{
"type": "terminalfont",
"key": "{#90}{$1}│ {#95}Font {#90}│",
"format": "{$2}{$3}{name} {#2}[{size}]"
},
{
"type": "shell",
"key": "{#90}{$1}│ {#95}Shell {#90}│",
"format": "{$2}{$3}{pretty-name} {#2}[v{version}] [PID:{pid}]"
},
{
// localip IPv4
"type": "localip",
"key": "{#90}{$1}│ {#94}Local IPv4 {#90}│",
"showPrefixLen": true,
"showIpv4": true,
"showIpv6": false,
"showMtu": true,
"format": "{$2}{$3}{ifname}: {ipv4} {#2}[MTU:{mtu}]"
},
{
// localip IPv6
"type": "localip",
"key": "{#90}{$1}│ {#94}Local IPv6 {#90}│",
"showPrefixLen": true,
"showIpv4": false,
"showIpv6": true,
"showMtu": true,
"format": "{$2}{$3}{ifname}: {ipv6} {#2}[MTU:{mtu}]"
},
{
"type": "publicip",
"key": "{#90}{$1}│ {#94}Public IPv4 {#90}│",
"ipv6": false,
"format": "{$2}{$3}{ip} {#2}[{location}]"
},
{
"type": "publicip",
"key": "{#90}{$1}│ {#94}Public IPv6 {#90}│",
"ipv6": true,
"format": "{$2}{$3}{ip} {#2}[{location}]"
},
// CUSTOM - Button UI bar
{
"type": "custom",
"key": "{#90}{$1}╰─────────────╯",
"format": "{#90}{$2}╰────────────────────────────────────────────────────────────╯",
}
]
}
================================================
FILE: presets/examples/25.jsonc
================================================
// Based on #1576
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"display": {
"color": {
"keys": "blue"
},
"separator": "",
// Constants are reusable strings referenced by {$1}, {$2}, etc.
// These contain ANSI escape codes for cursor positioning
"constants": [
"──────────────────────────────────────────────", // {$1} - horizontal line for inner borders
"\u001b[47D", // {$2} - move cursor left 47 columns
"\u001b[47C", // {$3} - move cursor right 47 columns
"\u001b[46C", // {$4} - move cursor right 46 columns
"══════════════════════════════════════════════" // {$5} - horizontal line for outer borders
],
"brightColor": false
},
"modules": [
{
"type": "version",
"key": "╔═══════════════╦═{$5}╗\u001b[41D",
"format": "\u001b[1m{#keys} {1} - {2} "
},
{
"type": "os",
// Key format breakdown for OS module:
// "║ {icon} \u001b[s{sysname}\u001b[u\u001b[10C│{$3}║{$2}"
//
// ║ - Left border of key block
// {icon} - OS icon (defined internally by fastfetch)
// \u001b[s - ANSI escape: save cursor position (ESC[s)
// {sysname} - Format variable: system name (e.g., "Linux", "Darwin")
// \u001b[u - ANSI escape: restore cursor to saved position (ESC[u)
// Necessary because the length of `{sysname}` differs between different platforms
// \u001b[10C - ANSI escape: move cursor right 10 columns (ESC[10C)
// │ - Right border of key block (always 10 columns from left border)
// {$3} - Reference to constants[2]: move cursor right 47 columns
// ║ - Right border of value block
// {$2} - Reference to constants[1]: move cursor left 47 columns
//
// This creates a fixed-width layout where the key block is exactly 10 columns wide,
// regardless of the actual content length. The cursor manipulation ensures proper
// alignment for the table-like structure.
"key": "║ {icon} \u001b[s{sysname}\u001b[u\u001b[10C║{$3}║{$2}"
},
{
"type": "datetime",
"key": "║ {icon} Fetched ║{$3}║{$2}",
"format": "{year}-{month-pretty}-{day-pretty} {hour-pretty}:{minute-pretty}:{second-pretty} {timezone-name}"
},
{
"type": "locale",
"key": "║ {icon} Locale ║{$3}║{$2}"
},
// Hardware section with cyan color theme
{
"type": "custom",
"key": "║{#cyan}┌──────────────┬{$1}┐{#keys}║\u001b[37D",
"format": "{#bright_cyan} Hardware "
},
{
"type": "chassis",
// Similar structure but with cyan color formatting:
// │{#cyan}│ - Left border with cyan color
// {icon} - Chassis icon
// Chassis - Fixed label text
// │{$4}│{#keys}║{$2} - Positioning and borders for value area
"key": "║{#cyan}│ {icon} Chassis │{$4}│{#keys}║{$2}"
},
{
"type": "memory",
"key": "║{#cyan}│ {icon} RAM │{$4}│{#keys}║{$2}"
},
{
"type": "swap",
"key": "║{#cyan}│ {icon} SWAP │{$4}│{#keys}║{$2}"
},
{
"type": "cpu",
"key": "║{#cyan}│ {icon} CPU │{$4}│{#keys}║{$2}",
"showPeCoreCount": true
},
{
"type": "gpu",
"key": "║{#cyan}│ {icon} GPU │{$4}│{#keys}║{$2}"
},
{
"type": "disk",
"key": "║{#cyan}│ {icon} Disk │{$4}│{#keys}║{$2}",
"format": "{size-used} \/ {size-total} ({size-percentage}) - {filesystem}",
},
{
"type": "battery",
"key": "║{#cyan}│ {icon} Battery │{$4}│{#keys}║{$2}"
},
{
"type": "custom",
"key": "║{#cyan}└──────────────┴{$1}┘{#keys}║",
"format": ""
},
// Desktop section with green color theme
{
"type": "custom",
"key": "║{#green}┌──────────────┬{$1}┐{#keys}║\u001b[37D",
"format": "{#bright_green} Desktop "
},
{
"type": "de",
"key": "║{#green}│ {icon} Desktop │{$4}│{#keys}║{$2}"
},
{
"type": "wm",
"key": "║{#green}│ {icon} Session │{$4}│{#keys}║{$2}"
},
{
"type": "display",
"key": "║{#green}│ {icon} Display │{$4}│{#keys}║{$2}",
"compactType": "original-with-refresh-rate"
},
{
"type": "gpu",
"key": "║{#green}│ {icon} G-Driver │{$4}│{#keys}║{$2}",
"format": "{driver}"
},
{
"type": "custom",
"key": "║{#green}└──────────────┴{$1}┘{#keys}║",
"format": ""
},
// Terminal section with yellow color theme
{
"type": "custom",
"key": "║{#yellow}┌──────────────┬{$1}┐{#keys}║\u001b[37D",
"format": "{#bright_yellow} Terminal "
},
{
"type": "shell",
"key": "║{#yellow}│ {icon} Shell │{$4}│{#keys}║{$2}"
},
{
"type": "terminal",
"key": "║{#yellow}│ {icon} Terminal │{$4}│{#keys}║{$2}"
},
{
"type": "terminalfont",
"key": "║{#yellow}│ {icon} Term Font │{$4}│{#keys}║{$2}"
},
{
"type": "terminaltheme",
"key": "║{#yellow}│ {icon} Colors │{$4}│{#keys}║{$2}"
},
{
"type": "packages",
"key": "║{#yellow}│ {icon} Packages │{$4}│{#keys}║{$2}"
},
{
"type": "custom",
"key": "║{#yellow}└──────────────┴{$1}┘{#keys}║",
"format": ""
},
// Development section with red color theme
{
"type": "custom",
"key": "║{#red}┌──────────────┬{$1}┐{#keys}║\u001b[39D",
"format": "{#bright_red} Development "
},
{
"type": "command",
"keyIcon": "", // Custom icon override
"key": "║{#red}│ {icon} Rust │{$4}│{#keys}║{$2}",
"text": "rustc --version",
"format": "rustc {~6,13}" // Print 6th to 13th characters (version number)
},
{
"type": "command",
"condition": {
"!system": "Windows" // Posix version
},
"keyIcon": "",
"key": "║{#red}│ {icon} Clang │{$4}│{#keys}║{$2}",
"text": "clang --version | sed -n 's/.*version \\([0-9][0-9.]*\\).*/\\1/p'",
"format": "clang {}"
},
{
"type": "command",
"condition": {
"system": "Windows" // Windows version
},
"keyIcon": "",
"key": "║{#red}│ {icon} Clang │{$4}│{#keys}║{$2}",
"text": "clang --version | findstr version", // Finds the line with "version"
"format": "clang {~-6}" // Prints the last 6 characters (version number)
},
{
"type": "command",
"keyIcon": "",
"key": "║{#red}│ {icon} NodeJS │{$4}│{#keys}║{$2}",
"text": "node --version",
"format": "node {~1}" // {~1} removes first character (v)
},
{
"type": "command",
"keyIcon": "",
"key": "║{#red}│ {icon} Go │{$4}│{#keys}║{$2}",
"text": "go version | cut -d' ' -f3",
"format": "go {~2}" // {~2} removes first 2 characters (go)
},
{
"type": "command",
"keyIcon": "",
"key": "║{#red}│ {icon} Zig │{$4}│{#keys}║{$2}",
"text": "zig version",
"format": "zig {}"
},
{
"type": "editor",
"key": "║{#red}│ {icon} Editor │{$4}│{#keys}║{$2}"
},
{
"type": "command",
"keyIcon": "",
"key": "║{#red}│ {icon} Git │{$4}│{#keys}║{$2}",
"text": "git version",
"format": "git {~12}"
},
{
"type": "font",
"key": "║{#red}│ {icon} Interface │{$4}│{#keys}║{$2}"
},
{
"type": "custom",
"key": "║{#red}└──────────────┴{$1}┘{#keys}║",
"format": ""
},
// Uptime section with magenta color theme
{
"type": "custom",
"key": "║{#magenta}┌──────────────┬{$1}┐{#keys}║\u001b[36D",
"format": "{#bright_magenta} Uptime "
},
{
"type": "uptime",
"key": "║{#magenta}│ {icon} Uptime │{$4}│{#keys}║{$2}"
},
{
"type": "users",
"myselfOnly": true, // Only show current user
"keyIcon": "",
"key": "║{#magenta}│ {icon} Login │{$4}│{#keys}║{$2}"
},
{
"condition": { // Conditional module: only show on non-macOS
"!system": "macOS"
},
"type": "disk",
"keyIcon": "",
"key": "║{#magenta}│ {icon} OS Age │{$4}│{#keys}║{$2}",
"folders": "/", // Check root filesystem
"format": "{create-time:10} [{days} days]" // Show creation time and age in days
},
{
"condition": { // Conditional module: only show on macOS
"system": "macOS"
},
"type": "disk",
"keyIcon": "",
"key": "║{#magenta}│ {icon} OS Age │{$4}│{#keys}║{$2}",
"folders": "/System/Volumes/VM", // Work around for APFS on macOS
"format": "{create-time:10} [{days} days]"
},
{
"type": "custom",
"key": "║{#magenta}└──────────────┴{$1}┘{#keys}║",
"format": ""
},
{
"type": "custom",
"key": "╚═════════════════{$5}╝", // Bottom border of the entire layout
"format": ""
},
// End with color palette and line break
"break", // Add a blank line
"colors" // Display color palette
]
}
/*
Key Format Structure Explanation:
The key format uses a combination of:
1. Unicode box drawing characters (│ ┌ ┐ └ ┘ ┬ ┴) for borders
2. ANSI escape codes for cursor positioning (\u001b[...)
3. Format variables ({icon}, {sysname}, etc.)
4. Constant references ({$1}, {$2}, etc.)
5. Color formatting ({#color})
ANSI Escape Codes Used:
- \u001b[s - Save cursor position (ESC[s)
- \u001b[u - Restore cursor position (ESC[u)
- \u001b[nC - Move cursor right n columns (ESC[nC)
- \u001b[nD - Move cursor left n columns (ESC[nD)
This creates a table-like layout with fixed column widths and proper alignment,
regardless of the actual content length in each field.
For more ANSI escape code reference, see:
https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#cursor-controls
*/
================================================
FILE: presets/examples/26.jsonc
================================================
// Modified from: 24.jsonc
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"padding": {
"top": 2
}
},
"display": {
"separator": "",
"constants": [
// CONSTANT {$1} - VERTICAL BARS AT START AND 75th CHARACTERS FORWARD AND BACKWARD
"\u001b[90m│ │\u001b[60D\u001b[39m"
]
},
"modules": [
// CUSTOM - Top UI bar
{
"type": "custom",
"key": "{#90}╭ Keys ───────╮",
"format": "{#90}╭ Values ────────────────────────────────────────────────────╮",
},
{
"type": "title",
"key": "{#90}│ {#92}User {#90}│",
"format": "{$1}{user-name} {#2}[{home-dir}]"
},
{
"type": "users",
"key": "{#90}│ {#92}Users {#90}│",
"myselfOnly": false,
"format": "{$1}{1}@{host-name}{/host-name}localhost{/}{?client-ip} {#2}[IP:{client-ip}]{?} [Login time: {login-time}]"
},
{
"type": "datetime",
"key": "{#90}│ {#92}Datetime {#90}│",
"format": "{$1}{year}-{month-pretty}-{day-in-month} {hour-pretty}:{minute-pretty}:{second-pretty} {#2}[{weekday}] [W{week}] [UTC{offset-from-utc}]"
},
{
"type": "title",
"key": "{#90}│ {#93}Host {#90}│",
"format": "{$1}{host-name}"
},
{
"type": "host",
"key": "{#90}│ {#93}Machine {#90}│",
"format": "{$1}{name} {#2}{version}"
},
{
"type": "os",
"key": "{#90}│ {#93}OS {#90}│",
"format": "{$1}{?pretty-name}{pretty-name}{?}{/pretty-name}{name}{/} {codename} {#2}[v{version}] [{arch}]"
},
{
"type": "kernel",
"key": "{#90}│ {#93}Kernel {#90}│",
"format": "{$1}{sysname} {#2}[v{release}]"
},
{
"type": "uptime",
"key": "{#90}│ {#93}Uptime {#90}│",
"format": "{$1}{?days}{days} Days + {?}{hours}:{minutes}:{seconds}"
},
{
"type": "cpu",
"key": "{#90}│ {#91}CPU {#90}│",
"showPeCoreCount": true,
"temp": true,
"format": "{$1}{name} {#2}[C:{core-types}] [{freq-max}]"
},
{
"type": "gpu",
"key": "{#90}│ {#91}GPU {#90}│",
"detectionMethod": "auto",
"driverSpecific": true,
"format": "{$1}{name} {#2}[C:{core-count}]{?frequency} [{frequency}]{?} {#2}[{type}]"
},
{
"type": "memory",
"key": "{#90}│ {#91}Memory {#90}│",
"format": "{$1}{used} / {total} ({percentage})"
},
{
"type": "disk",
"key": "{#90}│ {#91}Disk {#90}│",
"format": "{$1}{size-used} / {size-total} ({size-percentage})"
},
{
"type": "poweradapter",
"key": "{#90}│ {#91}Power {#90}│",
"format": "{$1}{name}"
},
{
"type": "terminal",
"key": "{#90}│ {#95}Terminal {#90}│",
"format": "{$1}{pretty-name} {#2}[{version}] [PID:{pid}]"
},
{
"type": "terminalfont",
"key": "{#90}│ {#95}Font {#90}│",
"format": "{$1}{name} {#2}[{size}]"
},
{
"type": "shell",
"key": "{#90}│ {#95}Shell {#90}│",
"format": "{$1}{pretty-name} {#2}[v{version}] [PID:{pid}]"
},
{
// localip IPv4
"type": "localip",
"key": "{#90}│ {#94}Local IPv4 {#90}│",
"showPrefixLen": true,
"showIpv4": true,
"showIpv6": false,
"showMtu": true,
"format": "{$1}{ifname}: {ipv4} {#2}[MTU:{mtu}]"
},
{
// localip IPv6
"type": "localip",
"key": "{#90}│ {#94}Local IPv6 {#90}│",
"showPrefixLen": true,
"showIpv4": false,
"showIpv6": true,
"showMtu": true,
"format": "{$1}{ifname}: {ipv6} {#2}[MTU:{mtu}]"
},
{
"type": "publicip",
"key": "{#90}│ {#94}Public IPv4 {#90}│",
"ipv6": false,
"format": "{$1}{ip} {#2}[{location}]"
},
{
"type": "publicip",
"key": "{#90}│ {#94}Public IPv6 {#90}│",
"ipv6": true,
"format": "{$1}{ip} {#2}[{location}]"
},
// CUSTOM - Button UI bar
{
"type": "custom",
"key": "{#90}╰─────────────╯",
"format": "{#90}╰────────────────────────────────────────────────────────────╯",
},
"break",
{
"type": "custom",
"key": " ",
"format": "{#90}╭ Colors ───────────────────────────────────────────────────────────────────╮",
},
{
"type": "custom",
"format": "{#90}│ {#40} {#41} {#42} {#43} {#44} {#45} {#46} {#47} {#} {#90}│",
},
{
"type": "custom",
"format": "{#90}│ {#100} {#101} {#102} {#103} {#104} {#105} {#106} {#107} {#} {#90}│",
},
{
"type": "custom",
"format": "{#90}╰───────────────────────────────────────────────────────────────────────────╯",
},
]
}
================================================
FILE: presets/examples/27.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"top": 1
}
},
"display": {
"separator": " "
},
"modules": [
"break",
"title",
{
"type": "os",
"key": "os ",
"keyColor": "red"
},
{
"type": "kernel",
"key": "kernel",
"keyColor": "green"
},
{
"type": "host",
"format": "{vendor} {family}",
"key": "host ",
"keyColor": "yellow"
},
{
"type": "packages",
"key": "pkgs ",
"keyColor": "blue"
},
{
"type": "uptime",
"format": "{?days}{days}d {?}{hours}h {minutes}m",
"key": "uptime",
"keyColor": "magenta"
},
{
"type": "memory",
"key": "memory",
"keyColor": "cyan"
},
"break"
]
}
================================================
FILE: presets/examples/28.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"separator": " ",
"key": {
"type": "both"
},
"bar": {
"border": {
"left": "\uee00",
"leftElapsed": "\uee03",
"right": "\uee02",
"rightElapsed": "\uee05"
},
"char": {
"total": "\uee01",
"elapsed": "\uee04"
},
"color": {
"total": null
}
},
"percent": {
"type": [
"bar",
"bar-monochrome"
]
}
},
"modules": [
"title",
"separator",
{
"type": "memory",
"key": "MEM"
},
{
"type": "swap",
"key": "SWP"
},
{
"type": "disk",
"folders": "/",
"key": "DSK"
},
{
"type": "battery",
"key": "BAT"
},
{
"type": "brightness",
"key": "BGT"
},
{
"type": "colors",
"paddingLeft": 6,
"symbol": "circle"
}
]
}
================================================
FILE: presets/examples/29.jsonc
================================================
// #1887
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": null,
"display": {
"constants": [
"\u001b[s\u001b[33C│\u001b[u",
" » "
],
"separator": "",
"percent": {
"type": ["num", "bar"]
},
"brightColor": false,
"bar": {
"border": {
"left": "[",
"leftElapsed": "[",
"right": "]",
"rightElapsed": "]"
},
"char": {
"elapsed": "─",
"total": "─"
},
"color": {
"elapsed": "default",
"total": "light_black"
},
"width": 16
},
"color": {
"separator": "default",
"keys": "default",
"output": "default"
}
},
"modules": [
"title",
{
"type": "custom",
"format": "┌────「 {#1}OS{#} 」────────────────────────────┐"
},
{
"type": "os",
"key": "│ {icon}{$2}{$1}"
},
{
"type": "disk",
"folders": "/",
"key": "│ {$1}",
"format": "{size-percentage-bar} {size-percentage}"
},
{
"type": "disk",
"folders": "/",
"key": "│ {$1}",
"format": "{size-used} / {size-total}"
},
{
"type": "custom",
"format": "└────────────────────────────────────────┘"
},
"break",
{
"type": "custom",
"format": "┌────「 {#1}UI{#} 」────────────────────────────┐"
},
{
"type": "wm",
"key": "│ {icon}{$2}{$1}"
},
{
"type": "wmtheme",
"key": "│ {icon}{$2}{$1}"
},
{
"type": "custom",
"key": "│ {$1}"
},
{
"type": "display",
"key": "│ {icon}{$2}{$1}",
"format": "{width}x{height} @ {refresh-rate} Hz"
},
{
"type": "custom",
"key": "│ {$1}"
},
{
"type": "terminal",
"key": "│ {icon}{$2}{$1}"
},
{
"type": "terminalfont",
"key": "│ {icon}{$2}{$1}"
},
{
"type": "custom",
"format": "└────────────────────────────────────────┘"
},
"break",
{
"type": "custom",
"format": "┌────「 {#1}HW{#} 」────────────────────────────┐"
},
{
"type": "cpu",
"key": "│ {icon}{$2}{$1}",
"format": "{name}"
},
{
"type": "gpu",
"key": "│ {icon}{$2}{$1}",
"format": "{name}"
},
{
"type": "custom",
"key": "│ {$1}"
},
{
"type": "memory",
"key": "│ {icon}{$2}{$1}",
"format": "{percentage-bar} {percentage}"
},
{
"type": "memory",
"key": "│ {$1}",
"format": "{used} / {total}"
},
{
"type": "custom",
"format": "└────────────────────────────────────────┘"
}
]
}
================================================
FILE: presets/examples/3.jsonc
================================================
// Load with --config examples/3.jsonc
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"size": {
"binaryPrefix": "si"
}
},
"modules": [
"vulkan",
"opengl",
"opencl",
"memory",
{
"type": "disk",
"folders": "/:/home:/boot:/efi"
},
"localip"
]
}
================================================
FILE: presets/examples/30.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": null,
"display": {
"key": {
"type": "both",
"paddingLeft": 6,
"width": 17
}
},
"modules": [
{
"type": "custom",
"format": "|---------------------: {#1}Hardware{#} : ---------------------|"
},
"break",
{
"keyColor": "green",
"type": "host"
},
{
"keyColor": "green",
"type": "cpu"
},
{
"keyColor": "yellow",
"type": "memory"
},
{
"keyColor": "yellow",
"type": "swap"
},
{
"type": "custom",
"keyIcon": "",
"key": "Disks"
},
{
"type": "disk",
"key": " ",
"format": " [{mountpoint}] - {size-used} / {size-total} ({size-percentage})"
},
"break",
{
"type": "title",
"format": "|-------------------------------------------------------|\u001b[40D: {#1}{user-name} @ {host-name}{#} :"
},
"break",
{
"type": "os",
"keyColor": "cyan"
},
{
"type": "kernel",
"keyColor": "cyan"
},
{
"type": "packages",
"keyColor": "red",
"key": "Pkgs"
},
{
"type": "shell",
"keyColor": "red"
},
{
"type": "terminal",
"key": "Term",
"keyColor": "red"
},
{
"type": "locale",
"keyColor": "magenta"
},
"break",
{
"type": "custom",
"format": "|---------------------: {#1}Software{#} : ---------------------|"
},
"break",
{
"type": "colors",
"symbol": "circle",
"paddingLeft": 8
}
]
}
================================================
FILE: presets/examples/31.jsonc
================================================
// Modified from https://github.com/fastfetch-cli/fastfetch/discussions/2133
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"source": "\u001b[?25l\u001b[0m\u001b[38;2;0;0;0;48;2;23;23;23m▇\u001b[48;2;24;24;24m▇▇▇▇▇\u001b[38;2;6;2;4;48;2;39;20;29m▅\u001b[38;2;45;17;30;48;2;5;4;4m▁\u001b[38;2;57;23;43;48;2;5;3;4m▁\u001b[38;2;46;17;34;48;2;4;3;4m▁\u001b[38;2;49;19;37;48;2;7;5;6m▁\u001b[38;2;52;20;41;48;2;13;8;10m▄\u001b[38;2;96;79;131;48;2;52;23;42m▗\u001b[38;2;153;160;221;48;2;83;63;97m▅\u001b[38;2;162;178;235;48;2;95;103;133m▇\u001b[38;2;158;173;227;48;2;93;103;135m▇\u001b[38;2;165;183;244;48;2;94;104;138m▇\u001b[38;2;166;184;248;48;2;96;103;138m▇\u001b[38;2;164;180;243;48;2;94;102;137m▇\u001b[38;2;162;178;240m▇\u001b[38;2;164;180;247;48;2;93;101;137m▇\u001b[38;2;163;181;247;48;2;94;102;138m▇\u001b[38;2;163;180;245;48;2;94;101;139m▇\u001b[38;2;164;180;246;48;2;95;102;139m▇\u001b[38;2;165;179;248;48;2;94;102;139m▇\u001b[38;2;164;179;248;48;2;95;101;139m▇\u001b[38;2;163;179;247;48;2;94;101;139m▇\u001b[38;2;163;178;247;48;2;93;100;138m▇\u001b[38;2;163;179;246;48;2;95;100;136m▇\u001b[38;2;27;17;22;48;2;144;151;202m▝\u001b[38;2;94;74;108;48;2;50;21;40m▁\u001b[38;2;55;17;43;48;2;19;9;14m▄\u001b[38;2;51;16;41;48;2;9;5;7m▂\u001b[38;2;4;1;3;48;2;23;23;24m▇\u001b[38;2;4;1;2;48;2;24;24;24m▇\u001b[38;2;45;15;33;48;2;4;3;3m▁\u001b[38;2;48;17;36;48;2;10;5;6m▁\u001b[38;2;0;0;0;48;2;24;24;24m▇\u001b[48;2;23;23;23m▇\u001b[48;2;24;24;24m▇▇▇\u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[38;2;24;11;18;48;2;2;1;2m▁\u001b[38;2;44;18;32;48;2;6;3;4m▅\u001b[38;2;42;13;28;48;2;50;21;38m╴\u001b[38;2;55;25;45;48;2;53;23;42m╴\u001b[38;2;54;24;44;48;2;56;22;45m▄\u001b[38;2;56;23;45;48;2;55;24;48m▘\u001b[38;2;54;25;48;48;2;55;23;46m╴\u001b[38;2;90;82;131;48;2;66;41;72m▗\u001b[38;2;116;115;169;48;2;151;155;218m▚\u001b[38;2;107;106;151;48;2;150;158;205m╼\u001b[38;2;137;142;194;48;2;164;166;200m╹\u001b[38;2;128;121;155;48;2;186;187;218m▏\u001b[38;2;170;166;177;48;2;186;189;219m▁\u001b[38;2;158;158;196;48;2;162;177;234m╴\u001b[38;2;130;129;169;48;2;156;168;222m╱\u001b[38;2;163;182;247;48;2;163;180;244m┊\u001b[38;2;164;183;248;48;2;162;181;246m▆\u001b[38;2;164;183;249;48;2;162;181;247m▄\u001b[38;2;163;181;248;48;2;163;181;245m╴\u001b[38;2;148;152;200;48;2;156;168;225m╴\u001b[38;2;162;181;245;48;2;163;181;247m╼\u001b[38;2;155;156;191;48;2;162;179;242m╺\u001b[38;2;172;176;214;48;2;194;194;226m▏\u001b[38;2;145;143;163;48;2;187;190;225m╶\u001b[38;2;116;116;151;48;2;169;174;217m▏\u001b[38;2;171;172;203;48;2;161;176;238m▁\u001b[38;2;152;162;215;48;2;114;104;145m▇\u001b[38;2;133;126;167;48;2;52;18;45m▖\u001b[38;2;56;20;48;48;2;55;19;46m╴\u001b[38;2;55;20;46;48;2;56;20;46m╸\u001b[38;2;55;18;47;48;2;56;20;47m▝\u001b[38;2;55;18;44;48;2;55;19;45m╹\u001b[38;2;44;14;35;48;2;50;18;42m╵\u001b[38;2;12;4;9;48;2;46;16;36m▝\u001b[38;2;34;12;25;48;2;2;0;1m▖\u001b[48;2;0;0;0m \u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[38;2;109;75;91;48;2;15;6;11m▗\u001b[38;2;154;127;138;48;2;64;36;49m▖\u001b[38;2;57;26;45;48;2;42;17;32m▇\u001b[38;2;43;18;30;48;2;53;24;40m╶\u001b[38;2;57;27;44;48;2;55;25;42m╴\u001b[38;2;56;26;48;48;2;56;26;46m━\u001b[38;2;39;17;29;48;2;54;24;43m▁\u001b[38;2;51;24;43;48;2;89;75;111m▋\u001b[38;2;107;100;153;48;2;90;82;126m▝\u001b[38;2;234;232;241;48;2;140;125;150m▗\u001b[38;2;125;97;98;48;2;224;218;222m▗\u001b[38;2;219;190;204;48;2;190;175;186m╴\u001b[38;2;149;148;174;48;2;188;193;225m╴\u001b[38;2;118;118;152;48;2;162;170;215m╻\u001b[38;2;117;116;154;48;2;160;171;224m╻\u001b[38;2;119;119;160;48;2;163;179;238m▗\u001b[38;2;138;144;205;48;2;165;181;245m▏\u001b[38;2;165;184;246;48;2;165;183;249m▂\u001b[38;2;165;185;246m▂\u001b[38;2;166;185;244;48;2;165;184;248m▃\u001b[38;2;136;139;184;48;2;163;177;231m┃\u001b[38;2;147;157;202;48;2;161;176;233m╴\u001b[38;2;167;182;240;48;2;165;183;247m▁\u001b[38;2;164;180;239;48;2;169;176;210m▇\u001b[38;2;153;155;189;48;2;192;197;228m╾\u001b[38;2;148;123;123;48;2;194;182;195m┕\u001b[38;2;155;137;136;48;2;217;208;219m▏\u001b[38;2;207;204;230;48;2;156;156;192m▊\u001b[38;2;160;169;221;48;2;124;118;156m▇\u001b[38;2;112;96;128;48;2;61;30;56m▏\u001b[38;2;48;14;35;48;2;51;19;42m╴\u001b[38;2;57;22;48;48;2;57;22;47m╴\u001b[38;2;58;23;46m▁\u001b[38;2;45;16;36;48;2;54;21;43m┎\u001b[38;2;43;17;33;48;2;53;21;43m╵\u001b[38;2;151;120;136;48;2;69;37;56m▗\u001b[38;2;108;77;93;48;2;17;7;12m▖\u001b[48;2;0;0;0m \u001b[38;2;0;0;1m▗\u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[38;2;27;17;26m▝\u001b[38;2;49;25;40;48;2;150;122;134m▍\u001b[38;2;118;92;100;48;2;63;34;49m▘\u001b[38;2;59;31;47;48;2;57;29;46m▖\u001b[38;2;59;28;46;48;2;58;28;46m╵\u001b[38;2;37;15;26;48;2;55;25;42m╹\u001b[38;2;58;27;45;48;2;44;16;31m▉\u001b[38;2;39;16;30;48;2;49;23;39m┆\u001b[38;2;57;30;50;48;2;91;78;114m▋\u001b[38;2;86;74;115;48;2;95;86;131m┊\u001b[38;2;102;95;139;48;2;185;174;200m▂\u001b[38;2;170;163;199;48;2;101;84;108m▚\u001b[38;2;171;187;245;48;2;166;178;229m╴\u001b[38;2;147;158;201;48;2;167;183;238m╴\u001b[38;2;136;137;173;48;2;165;179;229m┃\u001b[38;2;105;97;144;48;2;155;166;216m┃\u001b[38;2;168;182;234;48;2;91;81;122m▋\u001b[38;2;114;112;170;48;2;162;175;235m▖\u001b[38;2;162;175;236;48;2;165;182;242m╻\u001b[38;2;160;176;234;48;2;166;184;243m╷\u001b[38;2;166;185;245m▉\u001b[38;2;95;91;129;48;2;161;170;224m┃\u001b[38;2;125;127;165;48;2;162;172;224m│\u001b[38;2;117;120;156;48;2;163;175;223m│\u001b[38;2;102;100;149;48;2;164;178;235m╷\u001b[38;2;167;185;244;48;2;166;184;245m╴\u001b[38;2;162;175;230;48;2;157;157;195m▇\u001b[38;2;127;110;128;48;2;173;175;215m▘\u001b[38;2;190;187;226;48;2;152;154;194m▊\u001b[38;2;174;186;239;48;2;167;187;246m▏\u001b[38;2;165;178;231;48;2;102;88;115m▊\u001b[38;2;41;14;33;48;2;49;20;40m╷\u001b[38;2;44;16;35;48;2;58;24;49m▎\u001b[38;2;58;23;48;48;2;37;10;24m▊\u001b[38;2;50;21;37;48;2;59;24;48m▏\u001b[38;2;59;25;48;48;2;58;24;50m▅\u001b[38;2;65;32;53;48;2;127;97;109m▊\u001b[38;2;149;121;137;48;2;84;57;70m▉\u001b[38;2;39;15;27;48;2;4;1;2m▏\u001b[48;2;0;0;0m \u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[38;2;0;0;1m╵\u001b[38;2;109;85;92;48;2;36;21;29m▝\u001b[38;2;58;33;47;48;2;61;30;47m▇\u001b[38;2;59;32;50;48;2;59;32;47m┒\u001b[38;2;47;21;35;48;2;55;28;43m╶\u001b[38;2;54;25;41;48;2;58;30;46m▏\u001b[38;2;57;28;46;48;2;71;46;67m▋\u001b[38;2;94;75;106;48;2;59;32;54m▆\u001b[38;2;51;31;53;48;2;97;88;130m▘\u001b[38;2;87;78;121;48;2;102;95;149m▏\u001b[38;2;103;96;151;48;2;90;81;126m▉\u001b[38;2;97;88;135;48;2;150;158;209m▍\u001b[38;2;124;124;160;48;2;156;167;213m╴\u001b[38;2;127;120;140;48;2;166;177;220m╻\u001b[38;2;121;102;114;48;2;169;156;177m╹\u001b[38;2;181;188;221;48;2;109;96;131m▎\u001b[38;2;161;172;220;48;2;107;89;112m▊\u001b[38;2;143;149;208;48;2;103;92;145m▝\u001b[38;2;104;103;158;48;2;155;166;224m╻\u001b[38;2;166;181;233;48;2;112;110;152m▋\u001b[38;2;140;146;202;48;2;166;182;239m▏\u001b[38;2;166;177;222;48;2;107;100;150m▎\u001b[38;2;165;170;211;48;2;111;102;142m▌\u001b[38;2;146;111;114;48;2;168;164;197m┍\u001b[38;2;164;161;194;48;2;107;101;141m▊\u001b[38;2;108;99;144;48;2;160;175;231m▖\u001b[38;2;117;119;161;48;2;159;172;223m┕\u001b[38;2;129;131;184;48;2;167;183;236m▖\u001b[38;2;146;152;193;48;2;162;176;225m╸\u001b[38;2;170;190;244;48;2;168;188;244m▂\u001b[38;2;158;167;207;48;2;76;62;82m▉\u001b[38;2;99;78;114;48;2;64;34;60m▅\u001b[38;2;80;59;88;48;2;59;28;52m▖\u001b[38;2;60;27;49;48;2;59;25;48m╴\u001b[38;2;52;19;38;48;2;55;22;44m╴\u001b[38;2;60;26;49;48;2;59;26;48m▃\u001b[38;2;59;26;48;48;2;60;26;49m╵\u001b[38;2;134;107;115;48;2;57;37;45m▘\u001b[38;2;0;0;1;48;2;0;0;0m╵ \u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;1;48;2;0;0;0m╸ \u001b[38;2;48;30;39;48;2;5;3;4m▝\u001b[38;2;59;34;48;48;2;59;35;47m╴\u001b[38;2;59;36;48;48;2;59;34;48m╷\u001b[38;2;42;16;29;48;2;54;30;43m╹\u001b[38;2;60;33;49;48;2;60;32;49m▃\u001b[38;2;57;31;51;48;2;99;78;108m▍\u001b[38;2;102;81;116;48;2;101;81;114m╵\u001b[38;2;69;52;73;48;2;88;76;108m╻\u001b[38;2;105;100;152;48;2;83;75;115m▋\u001b[38;2;104;98;151;48;2;86;77;114m▋\u001b[38;2;102;94;135;48;2;75;65;95m▚\u001b[38;2;117;91;94;48;2;166;158;184m╻\u001b[38;2;174;150;157;48;2;157;125;125m┣\u001b[38;2;164;121;108;48;2;202;155;147m▃\u001b[38;2;92;62;55;48;2;157;122;119m▂\u001b[38;2;155;158;202;48;2;125;100;115m╹\u001b[38;2;187;145;138;48;2;121;98;127m▖\u001b[38;2;101;91;147;48;2;103;95;147m╵\u001b[38;2;152;159;207;48;2;125;99;109m▊\u001b[38;2;109;90;125;48;2;154;154;196m▍\u001b[38;2;169;143;149;48;2;110;90;120m▏\u001b[38;2;123;88;86;48;2;151;126;144m▂\u001b[38;2;101;74;62;48;2;206;176;176m▂\u001b[38;2;98;73;59;48;2;199;168;163m▁\u001b[38;2;141;96;81;48;2;147;114;119m╻\u001b[38;2;169;183;235;48;2;131;116;151m▝\u001b[38;2;112;110;152;48;2;142;149;197m▚\u001b[38;2;174;192;240;48;2;163;180;230m╵\u001b[38;2;171;190;240;48;2;171;190;243m╲\u001b[38;2;173;184;226;48;2;100;85;108m▎\u001b[38;2;100;80;111;48;2;99;80;115m▏\u001b[38;2;98;77;111;48;2;58;28;54m▊\u001b[38;2;60;28;51;48;2;60;27;50m▅\u001b[38;2;41;12;32;48;2;57;25;47m╹\u001b[38;2;60;27;50;48;2;61;28;48m▘\u001b[38;2;60;26;51;48;2;58;26;47m╵\u001b[38;2;33;16;26;48;2;2;0;1m▘\u001b[48;2;0;0;0m \u001b[0m\n\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[48;2;0;0;1m▉\u001b[38;2;2;1;1;48;2;43;28;36m▖\u001b[38;2;49;26;37;48;2;55;32;45m┌\u001b[38;2;47;24;36;48;2;58;34;48m▏\u001b[38;2;59;35;49;48;2;55;32;46m▉\u001b[38;2;56;31;50;48;2;102;85;113m▎\u001b[38;2;99;82;112;48;2;99;81;111m▎\u001b[38;2;103;83;110;48;2;89;71;98m┊\u001b[38;2;89;75;108;48;2;94;88;128m▃\u001b[38;2;99;95;141;48;2;90;83;124m▇\u001b[38;2;85;73;107;48;2;94;85;125m┃\u001b[38;2;82;56;72;48;2;121;102;130m╹\u001b[38;2;170;129;124;48;2;194;148;138m▏\u001b[38;2;125;91;82;48;2;220;193;186m▘\u001b[38;2;198;176;170;48;2;145;83;80m▋\u001b[38;2;232;207;202;48;2;104;52;53m▗\u001b[38;2;234;208;202;48;2;148;102;99m▆\u001b[38;2;230;199;192;48;2;132;101;113m▄\u001b[38;2;132;111;138;48;2;220;176;169m▉\u001b[38;2;214;177;169;48;2;147;111;118m▅\u001b[38;2;235;205;199;48;2;143;100;98m▅\u001b[38;2;229;208;204;48;2;134;87;81m▇\u001b[38;2;215;180;178;48;2;112;34;37m▂\u001b[38;2;106;67;64;48;2;223;202;196m▘\u001b[38;2;237;209;204;48;2;139;95;88m▆\u001b[38;2;122;99;120;48;2;187;161;170m▝\u001b[38;2;142;146;195;48;2;98;89;129m▖\u001b[38;2;110;105;156;48;2;168;183;235m▎\u001b[38;2;134;130;157;48;2;161;173;211m▁\u001b[38;2;116;108;135;48;2;93;74;102m▏\u001b[38;2;100;81;114;48;2;100;80;113m╸\u001b[38;2;98;79;112;48;2;57;37;57m▉\u001b[38;2;49;16;39;48;2;62;28;51m▏\u001b[38;2;61;27;50;48;2;52;22;38m▉\u001b[38;2;48;20;33;48;2;56;27;44m╴\u001b[38;2;61;31;47;48;2;14;7;11m▘\u001b[48;2;0;0;0m \u001b[0m\n\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[38;2;43;28;35;48;2;5;3;3m▝\u001b[38;2;57;39;48;48;2;54;34;45m╴\u001b[38;2;59;35;48;48;2;51;27;41m▉\u001b[38;2;35;10;26;48;2;100;83;110m▏\u001b[38;2;99;85;113;48;2;97;82;111m▍\u001b[38;2;85;68;93;48;2;93;76;104m╻\u001b[38;2;99;81;112;48;2;96;79;108m╵\u001b[38;2;83;66;91;48;2;96;86;123m╸\u001b[38;2;75;65;93;48;2;93;89;130m▖\u001b[38;2;101;100;149;48;2;100;98;147m┊\u001b[38;2;90;75;95;48;2;108;96;127m┕\u001b[38;2;101;77;88;48;2;213;184;173m▖\u001b[38;2;245;224;216;48;2;239;217;207m╵\u001b[38;2;245;223;214;48;2;243;222;212m▌\u001b[38;2;243;221;211;48;2;239;219;210m▃\u001b[38;2;243;220;211;48;2;241;219;210m╴\u001b[38;2;191;154;140;48;2;235;206;196m╻\u001b[38;2;243;219;210;48;2;243;220;212m▘\u001b[38;2;243;220;212;48;2;245;219;215m▇\u001b[38;2;243;219;211;48;2;245;219;213m▃\u001b[38;2;241;218;209;48;2;245;221;216m▁\u001b[38;2;166;140;133;48;2;241;218;212m▂\u001b[38;2;144;145;172;48;2;187;177;187m╶\u001b[38;2;144;154;201;48;2;171;186;231m▁\u001b[38;2;142;149;193;48;2;161;173;223m▁\u001b[38;2;87;73;103;48;2;157;159;182m▌\u001b[38;2;126;121;137;48;2;97;77;106m▘\u001b[38;2;100;80;112;48;2;88;66;94m▋\u001b[38;2;99;80;115;48;2;99;80;114m╹\u001b[38;2;97;77;109;48;2;50;22;46m▉\u001b[38;2;57;24;45;48;2;62;30;51m▏\u001b[38;2;14;6;9;48;2;56;29;45m▗\u001b[38;2;1;0;1;48;2;33;18;26m▇\u001b[48;2;0;0;0m \u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;0;48;2;0;0;0m \u001b[48;2;2;2;2m╴\u001b[38;2;166;152;177;48;2;32;25;30m▗\u001b[38;2;160;149;172;48;2;10;5;6m▅\u001b[38;2;66;58;65;48;2;9;7;8m▏\u001b[38;2;37;27;32;48;2;1;0;0m▝\u001b[38;2;22;14;17;48;2;55;35;46m▂\u001b[38;2;98;83;109;48;2;56;36;51m▝\u001b[38;2;51;34;47;48;2;95;82;108m▁\u001b[38;2;67;55;70;48;2;91;76;102m▁\u001b[38;2;101;87;117;48;2;98;84;110m╴\u001b[38;2;100;85;114;48;2;97;82;109m╴\u001b[38;2;64;51;70;48;2;92;77;103m┖\u001b[38;2;94;81;111;48;2;74;65;89m▉\u001b[38;2;68;58;68;48;2;96;92;132m▂\u001b[38;2;116;100;123;48;2;110;81;85m▆\u001b[38;2;130;66;58;48;2;202;169;153m▂\u001b[38;2;219;188;169;48;2;240;218;205m▁\u001b[38;2;239;221;206;48;2;243;221;210m▂\u001b[38;2;244;222;212;48;2;240;218;207m╵\u001b[38;2;154;108;101;48;2;225;198;186m╹\u001b[38;2;227;203;193;48;2;238;215;205m╻\u001b[38;2;242;219;209;48;2;242;220;210m▄\u001b[38;2;241;218;207;48;2;242;219;210m▁\u001b[38;2;181;129;118;48;2;222;194;184m▁\u001b[38;2;145;74;66;48;2;166;132;133m▖\u001b[38;2;92;76;95;48;2;149;149;180m┎\u001b[38;2;61;53;72;48;2;123;122;169m▄\u001b[38;2;130;134;174;48;2;91;74;101m▘\u001b[38;2;87;69;85;48;2;98;79;106m╹\u001b[38;2;100;81;113;48;2;98;79;109m╵\u001b[38;2;69;49;65;48;2;95;75;103m▁\u001b[38;2;53;27;45;48;2;97;77;107m▁\u001b[38;2;99;78;109;48;2;59;32;51m▘\u001b[38;2;5;2;3;48;2;51;26;40m▗\u001b[38;2;0;0;0;48;2;3;1;2m╵\u001b[48;2;1;0;0m┊\u001b[38;2;128;108;125;48;2;2;0;1m▄\u001b[38;2;140;121;146;48;2;2;1;2m▃\u001b[38;2;0;0;0;48;2;4;3;4m╴\u001b[48;2;0;0;0m \u001b[0m\n\u001b[7m\u001b[38;2;0;0;0m \u001b[0m\u001b[38;2;0;0;0;48;2;2;1;2m╴\u001b[38;2;7;5;6;48;2;89;75;96m▘\u001b[38;2;100;88;115;48;2;115;104;128m▇\u001b[38;2;100;89;114;48;2;156;149;176m▅\u001b[38;2;141;128;144;48;2;25;17;20m▋\u001b[38;2;54;38;48;48;2;0;0;0m▂\u001b[38;2;56;39;51;48;2;1;0;0m▂\u001b[38;2;57;40;49;48;2;12;8;10m▂\u001b[38;2;57;37;50;48;2;18;12;15m▂\u001b[38;2;0;0;0;48;2;36;22;28m━\u001b[38;2;105;75;79;48;2;18;10;13m▁\u001b[38;2;192;174;183;48;2;27;17;21m▂\u001b[38;2;213;205;220;48;2;72;47;56m▃\u001b[38;2;188;176;181;48;2;64;19;20m▖\u001b[38;2;134;23;22;48;2;65;19;19m▆\u001b[38;2;92;57;57;48;2;177;164;175m▌\u001b[38;2;120;30;32;48;2;187;172;180m▝\u001b[38;2;193;163;176;48;2;132;53;49m▂\u001b[38;2;118;26;22;48;2;220;194;178m▄\u001b[38;2;166;93;81;48;2;235;215;200m▂\u001b[38;2;237;210;190;48;2;239;219;207m▁\u001b[38;2;239;220;211;48;2;236;216;203m╵\u001b[38;2;149;78;71;48;2;238;214;203m▃\u001b[38;2;113;12;12;48;2;201;156;154m╼\u001b[38;2;209;194;197;48;2;152;68;69m▄\u001b[38;2;224;216;213;48;2;184;144;144m▇\u001b[38;2;164;57;18;48;2;174;155;153m▆\u001b[38;2;234;70;2;48;2;142;55;30m╴\u001b[38;2;238;227;219;48;2;85;44;48m▂\u001b[38;2;240;230;232;48;2;44;26;29m▁\u001b[38;2;108;80;80;48;2;15;7;11m▁\u001b[38;2;10;4;6;48;2;42;22;32m▆\u001b[38;2;62;35;49;48;2;12;6;9m▁\u001b[38;2;64;37;51;48;2;7;3;4m▁\u001b[38;2;56;28;45;48;2;0;0;0m▁\u001b[38;2;29;10;20m▁\u001b[38;2;24;16;17;48;2;138;119;136m▍\u001b[38;2;89;70;94;48;2;158;142;171m▗\u001b[38;2;100;82;110;48;2;135;120;145m▆\u001b[38;2;12;7;11;48;2;94;75;101m▝\u001b[38;2;0;0;0;48;2;3;1;2m┊\u001b[0m\n\u001b[38;2;0;0;0;48;2;1;1;1m╴\u001b[38;2;6;5;6;48;2;87;76;97m▘\u001b[38;2;99;90;117;48;2;101;90;117m▇\u001b[38;2;99;89;117;48;2;99;89;115m▎\u001b[38;2;59;45;58;48;2;97;84;109m▗\u001b[38;2;52;37;47;48;2;56;39;50m▏\u001b[38;2;47;30;40;48;2;57;39;48m╴\u001b[38;2;211;205;201;48;2;62;42;52m▂\u001b[38;2;222;224;219;48;2;58;38;47m▄\u001b[38;2;235;241;236;48;2;77;52;60m▅\u001b[38;2;238;246;239;48;2;122;97;100m▆\u001b[38;2;239;244;236;48;2;212;195;194m▇\u001b[38;2;141;98;78;48;2;229;233;227m▃\u001b[38;2;181;62;13;48;2;170;162;160m▅\u001b[38;2;186;57;10;48;2;87;23;20m▆\u001b[38;2;200;183;178;48;2;122;34;30m▃\u001b[38;2;176;167;175;48;2;204;198;210m╶\u001b[38;2;109;95;97;48;2;197;193;205m▝\u001b[38;2;123;113;115;48;2;200;194;208m▘\u001b[38;2;213;209;228;48;2;163;101;111m▇\u001b[38;2;207;196;214;48;2;119;16;19m▆\u001b[38;2;120;32;34;48;2;195;151;128m▇\u001b[38;2;186;157;169;48;2;140;58;58m▅\u001b[38;2;220;215;227;48;2;172;102;110m▇\u001b[38;2;84;65;58;48;2;217;211;214m╺\u001b[38;2;119;97;91;48;2;204;198;190m┛\u001b[38;2;206;199;191;48;2;231;229;223m╸\u001b[38;2;114;45;24;48;2;216;212;208m▝\u001b[38;2;144;116;109;48;2;177;57;11m▖\u001b[38;2;197;72;22;48;2;208;194;182m▆\u001b[38;2;160;70;38;48;2;230;227;217m▃\u001b[38;2;183;168;151;48;2;239;236;229m▁\u001b[38;2;241;241;237;48;2;126;101;108m▆\u001b[38;2;236;235;231;48;2;79;50;61m▅\u001b[38;2;239;239;236;48;2;77;50;62m▃\u001b[38;2;212;202;203;48;2;64;37;50m▂\u001b[38;2;49;24;35;48;2;66;39;53m╴\u001b[38;2;62;36;51;48;2;93;74;86m▇\u001b[38;2;69;45;61;48;2;111;92;113m▅\u001b[38;2;100;81;112;48;2;100;82;111m▋\u001b[38;2;101;83;115m▝\u001b[38;2;6;4;6;48;2;84;68;89m▝\u001b[0m\n\u001b[38;2;5;3;5;48;2;82;74;92m▘\u001b[38;2;100;91;116;48;2;99;91;116m╴\u001b[38;2;99;90;117;48;2;97;88;112m╵\u001b[38;2;59;47;57;48;2;94;85;107m▃\u001b[38;2;56;39;49;48;2;65;48;57m╵\u001b[38;2;220;221;210;48;2;87;65;72m▄\u001b[38;2;236;244;235;48;2;159;142;141m▇\u001b[38;2;238;248;243;48;2;237;248;240m╍\u001b[38;2;238;248;242m╸\u001b[38;2;235;248;239;48;2;235;246;236m╵\u001b[38;2;122;70;48;48;2;221;228;215m▃\u001b[38;2;186;63;14;48;2;170;159;145m▆\u001b[38;2;125;39;11;48;2;218;69;4m▗\u001b[38;2;227;222;210;48;2;184;78;35m▃\u001b[38;2;236;241;232;48;2;161;118;106m▆\u001b[38;2;238;248;240;48;2;237;247;238m┊\u001b[38;2;225;229;233;48;2;236;245;238m▝\u001b[38;2;224;228;233;48;2;193;190;204m▇\u001b[38;2;184;182;192;48;2;210;210;222m╺\u001b[38;2;185;185;194;48;2;205;206;221m┐\u001b[38;2;209;211;231;48;2;212;214;228m╴\u001b[38;2;236;241;238;48;2;217;215;230m▃\u001b[38;2;236;241;236;48;2;222;221;230m▆\u001b[38;2;221;221;211;48;2;230;233;225m╷\u001b[38;2;196;193;184;48;2;231;234;228m╴\u001b[38;2;233;238;233;48;2;217;219;211m▇\u001b[38;2;236;242;235;48;2;237;243;237m╲\u001b[38;2;236;244;237;48;2;238;243;239m▃\u001b[38;2;239;244;240;48;2;233;236;231m╴\u001b[38;2;226;226;220;48;2;137;73;53m▄\u001b[38;2;96;25;7;48;2;193;69;20m╴\u001b[38;2;212;64;3;48;2;132;86;72m▇\u001b[38;2;181;73;30;48;2;234;229;216m▆\u001b[38;2;116;71;57;48;2;240;239;228m▖\u001b[38;2;239;241;237;48;2;241;245;240m▃\u001b[38;2;242;245;241;48;2;241;244;239m╺\u001b[38;2;241;243;239;48;2;196;182;182m▇\u001b[38;2;232;231;228;48;2;108;83;92m▅\u001b[38;2;164;147;148;48;2;65;39;51m▖\u001b[38;2;67;45;59;48;2;92;72;95m▃\u001b[38;2;101;80;110;48;2;98;79;106m╴\u001b[38;2;101;82;112;48;2;104;85;113m▉\u001b[0m\n\u001b[38;2;65;63;77;48;2;99;92;116m▏\u001b[38;2;55;42;50;48;2;90;82;101m▗\u001b[38;2;51;37;46;48;2;69;59;72m▇\u001b[38;2;53;36;45;48;2;61;45;52m┊\u001b[38;2;110;95;90;48;2;213;206;194m▚\u001b[38;2;187;185;173;48;2;236;244;232m▏\u001b[38;2;237;249;240;48;2;236;249;237m▝\u001b[38;2;236;249;238;48;2;237;248;241m▃\u001b[38;2;236;247;235;48;2;235;247;236m┊\u001b[38;2;199;200;187;48;2;115;70;51m▌\u001b[38;2;157;47;7;48;2;224;70;3m▏\u001b[38;2;233;73;0;48;2;230;73;2m╵\u001b[38;2;117;45;25;48;2;204;192;180m▋\u001b[48;2;236;246;236m \u001b[38;2;238;246;239;48;2;236;247;239m▝\u001b[38;2;233;247;235;48;2;236;247;238m▂\u001b[38;2;235;246;236;48;2;236;246;238m▅\u001b[38;2;234;245;234;48;2;235;246;237m╍\u001b[38;2;234;246;234;48;2;235;245;237m▅\u001b[38;2;234;244;235;48;2;229;233;232m▇\u001b[38;2;209;208;194;48;2;226;230;219m╵\u001b[38;2;195;194;179;48;2;233;239;228m─\u001b[38;2;204;202;187;48;2;230;234;223m╸\u001b[38;2;236;244;239;48;2;235;241;233m╴\u001b[38;2;235;243;234;48;2;235;243;236m▍\u001b[38;2;235;244;232m▅\u001b[38;2;235;243;233;48;2;237;243;236m▅\u001b[38;2;235;242;236m▅\u001b[38;2;236;242;234;48;2;238;243;237m▃\u001b[38;2;237;242;232;48;2;238;243;236m▅\u001b[38;2;229;224;215;48;2;129;45;20m▍\u001b[38;2;235;72;1;48;2;234;72;0m╴\u001b[38;2;236;71;0m╵\u001b[38;2;152;47;13;48;2;172;151;134m▊\u001b[38;2;237;240;235;48;2;237;236;228m╵\u001b[38;2;234;237;231;48;2;237;240;235m▃\u001b[38;2;232;235;231;48;2;236;239;235m▂\u001b[38;2;230;233;228;48;2;236;238;232m▃\u001b[38;2;122;101;93;48;2;210;204;196m▄\u001b[38;2;208;198;185;48;2;76;50;59m▖\u001b[38;2;61;36;50;48;2;75;54;71m▇\u001b[38;2;70;49;66;48;2;101;82;111m▖\u001b[0m\n\u001b[38;2;58;46;54;48;2;90;84;100m▗\u001b[38;2;41;27;33;48;2;53;40;46m┎\u001b[38;2;58;44;51;48;2;60;45;52m╴\u001b[38;2;236;223;202;48;2;104;87;79m╱\u001b[38;2;202;195;183;48;2;97;84;76m▗\u001b[38;2;234;246;233;48;2;232;241;228m╵\u001b[38;2;233;244;231;48;2;234;247;236m▄\u001b[38;2;132;139;141;48;2;224;236;224m▁\u001b[38;2;77;78;109;48;2;217;225;213m▅\u001b[38;2;52;53;100;48;2;95;43;29m▆\u001b[38;2;57;50;94;48;2;209;72;6m▆\u001b[38;2;55;52;98;48;2;168;55;9m▅\u001b[38;2;229;237;223;48;2;83;72;91m▝\u001b[38;2;242;243;231;48;2;234;246;234m▏\u001b[38;2;236;247;236;48;2;234;248;235m▘\u001b[38;2;234;248;234;48;2;234;247;234m╍\u001b[38;2;234;247;234;48;2;234;245;235m▄\u001b[38;2;234;244;234;48;2;234;246;235m┷\u001b[38;2;232;243;233;48;2;234;245;234m┬\u001b[38;2;233;243;233;48;2;241;248;236m▉\u001b[38;2;216;213;200;48;2;150;130;113m▏\u001b[38;2;219;207;188;48;2;143;120;104m┠\u001b[38;2;148;124;108;48;2;191;187;165m▇\u001b[38;2;229;217;200;48;2;235;242;231m▏\u001b[38;2;233;243;233;48;2;234;242;235m▌\u001b[38;2;233;241;232;48;2;234;242;233m┊\u001b[38;2;234;243;232m┳\u001b[38;2;233;241;233;48;2;234;241;235m▆\u001b[38;2;236;241;233;48;2;234;242;233m╴\u001b[38;2;234;241;234;48;2;236;241;232m▂\u001b[38;2;226;225;216;48;2;77;44;62m▌\u001b[38;2;71;48;87;48;2;224;75;7m▅\u001b[38;2;61;49;95;48;2;206;67;6m▅\u001b[38;2;62;49;97;48;2;154;50;15m▆\u001b[38;2;70;62;103;48;2;199;197;189m▆\u001b[38;2;79;72;103;48;2;216;218;210m▃\u001b[38;2;156;154;153;48;2;224;227;219m▁\u001b[38;2;219;223;213;48;2;225;229;221m▅\u001b[38;2;196;193;187;48;2;124;108;107m▌\u001b[38;2;174;156;142;48;2;87;67;63m▝\u001b[38;2;160;143;127;48;2;67;42;51m▖\u001b[38;2;79;58;76;48;2;56;33;46m▝\u001b[0m\n\u001b[38;2;75;67;76;48;2;47;38;41m▘\u001b[38;2;35;34;34;48;2;58;43;48m▂\u001b[38;2;80;66;68;48;2;175;168;153m▊\u001b[38;2;193;182;167;48;2;111;103;90m╶\u001b[38;2;60;62;59;48;2;223;230;212m▂\u001b[38;2;57;59;55;48;2;231;244;226m▂\u001b[38;2;52;51;65;48;2;190;196;189m▄\u001b[38;2;56;54;100;48;2;54;55;84m╴\u001b[38;2;34;34;38;48;2;51;55;101m▂\u001b[38;2;33;33;36;48;2;47;50;93m▂\u001b[38;2;49;52;94;48;2;20;21;36m▝\u001b[38;2;34;34;37;48;2;53;55;99m▂\u001b[38;2;56;50;76;48;2;170;159;151m▊\u001b[38;2;60;62;60;48;2;236;248;234m▂\u001b[38;2;60;63;60;48;2;236;249;236m▂\u001b[48;2;236;249;235m▂\u001b[48;2;235;248;235m▂\u001b[38;2;60;63;61;48;2;235;248;236m▂\u001b[38;2;60;62;60;48;2;235;248;235m▂\u001b[48;2;235;247;235m▂\u001b[38;2;60;62;61;48;2;236;247;236m▂\u001b[48;2;236;247;235m▂\u001b[38;2;60;62;60;48;2;237;244;235m▂\u001b[38;2;61;62;61;48;2;236;245;236m▂\u001b[38;2;60;62;60;48;2;236;244;237m▂\u001b[48;2;236;244;234m▂▂\u001b[48;2;235;244;236m▂\u001b[48;2;235;244;234m▂\u001b[38;2;60;61;60;48;2;235;243;235m▂\u001b[38;2;188;188;183;48;2;62;49;78m▌\u001b[38;2;35;34;39;48;2;59;51;104m▂\u001b[38;2;18;17;26;48;2;44;41;80m▗\u001b[38;2;21;19;31;48;2;48;45;84m▖\u001b[38;2;34;34;39;48;2;57;50;101m▂\u001b[38;2;34;34;38;48;2;56;48;95m▂\u001b[38;2;52;47;92;48;2;58;52;79m╴\u001b[38;2;45;44;44;48;2;175;172;168m▂\u001b[38;2;56;56;55;48;2;215;217;205m▂\u001b[38;2;206;203;196;48;2;120;113;108m╾\u001b[38;2;95;76;69;48;2;158;147;133m▋\u001b[38;2;145;123;118;48;2;68;50;55m╴\u001b[0m",
"type": "data-raw"
},
"display": {
"separator": "▌",
"key": {
"width": 18
},
"bar": {
"border": null,
"char": {
"elapsed": "█",
"total": "░"
},
"width": 35
}
},
"modules": [
{
"type": "custom",
"format": "{#@196}╔════════════════════════════════════════════════════════╗"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}███╗ ██╗███████╗██████╗ ██╗ ██╗ {#@220}EVA-00 SYSTEM {#@196}║"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}████╗ ██║██╔════╝██╔══██╗██║ ██║ {#@220}MAGI INTERFACE {#@196} ║"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}██╔██╗ ██║█████╗ ██████╔╝██║ ██║ {#@196}║"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}██║╚██╗██║██╔══╝ ██╔══██╗╚██╗ ██╔╝ {#@208}CLASSIFIED {#@196} ║"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}██║ ╚████║███████╗██║ ██║ ╚████╔╝ {#@208}ACCESS ONLY {#@196} ║"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═══╝ {#@196} ║"
},
{
"type": "custom",
"format": "{#@196}╚════════════════════════════════════════════════════════╝"
},
{
"type": "custom",
"format": "{#@208}╔══●{#@166}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━●══╗"
},
{
"type": "custom",
"format": "{#@208}║ {#@46}00101{#@208} ●{#@166}────{#@208}● NERVE CONNECTION INTERFACE ●{#@166}────{#@208}● {#@46}00102{#@196} ║"
},
{
"type": "custom",
"format": "{#@208}╚══●{#@166}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━●══╝"
},
{
"type": "custom",
"format": "{#@208}▰{#@166}▰{#@208}▰{#@166}▰{#@208} BORDER LINE {#@166}▰{#@208}▰{#@166}▰{#@208}▰ {#@46}[{#@220}SYSTEM CONFIG{#@46}]"
},
{
"type": "os",
"key": "{#@46}│ OS "
},
{
"type": "kernel",
"key": "{#@46}│ KERNEL "
},
{
"type": "uptime",
"key": "{#@46}│ UPTIME "
},
{
"type": "custom",
"format": "{#@208}▰{#@166}▰{#@208}▰{#@166}▰{#@208}▰ ABSOLUTE {#@166}▰{#@208}▰{#@166}▰{#@208}▰{#@166}▰ {#@196}[{#@220}FIRST CHILD{#@196}] {#@51}REI AYANAMI"
},
{
"type": "users",
"key": "{#@46}│ DESIGNATION ",
"format": "{name}, since {login-time}",
"myselfOnly": true
},
{
"type": "localip",
"key": "{#@46}│ NEURAL-LINK ",
"format": "{ipv4}"
},
{
"type": "custom",
"format": "{#@196}▰{#@208}▰{#@196}▰{#@208}▰{#@196}▰ DANGER {#@208}▰{#@196}▰{#@208}▰{#@196}▰{#@208}▰ {#@220}[{#@196}UNIT-00{#@220}] {#@51}CORE STATUS"
},
{
"type": "cpu",
"key": "{#@220}│ CPU-CORE ",
"format": "{name}"
},
{
"type": "cpu",
"key": "{#@220}│ SYNC-RATE ",
"format": "{cores-physical}C / {cores-logical}T"
},
{
"type": "custom",
"format": "{#@196}▰{#@208}▰{#@196}▰{#@208}▰{#@196} WARNING {#@208}▰{#@196}▰{#@208}▰{#@196}▰ {#@220}[{#@51}LCL{#@220}] {#@208}[{#@51}A.T. FIELD{#@208}]"
},
{
"type": "memory",
"key": "{#@208}{#@166}{#@208}{#@220}│ LCL-LEVEL ",
"format": "{used} / {total} (RAM)"
},
{
"type": "memory",
"key": "{#@208}{#@166}{#@208}{#@220}│ A.T.FIELD ",
"percent": {
"type": [
"bar",
"hide-others"
]
}
},
{
"type": "disk",
"folders": "/",
"key": "{#@208}{#@166}{#@208}{#@220}│ ENTRY-PLUG ",
"format": "{size-used} / {size-total} (DISK)"
},
{
"type": "disk",
"folders": "/",
"key": "{#@208}{#@166}{#@208}{#@220}│ PLUG-DEPTH ",
"percent": {
"type": [
"bar",
"hide-others"
]
}
},
{
"type": "custom",
"format": "{#@196}╔═════════════════════════════════════════════════════════╗"
},
{
"type": "custom",
"format": "{#@196}║ {#@46}[SYSTEMS NOMINAL] {#@208}MAGI: {#@46} ONLINE {#@208} STATUS: {#@46} OK {#@196} ║"
},
{
"type": "custom",
"format": "{#@196}╚═════════════════════════════════════════════════════════╝"
},
{
"type": "custom",
"format": "{#@46} PILOT REI AYANAMI - READY FOR DEPLOYMENT"
},
{
"type": "custom",
"format": "{#@208} 綾波レイ (I am not a doll. I am me.)"
}
]
}
================================================
FILE: presets/examples/32.jsonc
================================================
// Inspired by microfetch
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"general": {
"detectVersion": false
},
"display": {
"separator": " ",
"brightColor": false,
"key": {
"type": "both-2"
}
},
"modules": [
{
"type": "title",
"format": "{user-name-colored}{#light_red}@{host-name-colored} {#}{cwd}"
},
{
"type": "os",
"key": "System "
},
{
"type": "kernel",
"key": "Kernel "
},
{
"type": "shell",
"key": "Shell "
},
{
"type": "uptime",
"key": "Uptime "
},
{
"type": "wm",
"key": "Desktop "
},
{
"type": "memory",
"key": "Memory "
},
{
"type": "disk",
"key": "Storage (/) ",
"folders": "/"
},
{
"type": "colors",
"key": "Colors ",
"symbol": "circle"
}
]
}
================================================
FILE: presets/examples/4.jsonc
================================================
// Load with --config examples/4.jsonc
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small",
"padding": {
"right": 1
}
},
"display": {
"size": {
"binaryPrefix": "si"
},
"color": "blue",
"separator": " "
},
"modules": [
{
"type": "datetime",
"key": "Date",
"format": "{1}-{3}-{11}"
},
{
"type": "datetime",
"key": "Time",
"format": "{14}:{17}:{20}"
},
"break",
"player",
"media"
]
}
================================================
FILE: presets/examples/5.jsonc
================================================
// Load with --config examples/5.jsonc
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": null,
"display": {
"color": "magenta"
},
"modules": [
{
"type": "theme",
"key": "T"
},
{
"type": "icons",
"key": "I"
},
{
"type": "font",
"key": "F"
},
{
"type": "cursor",
"key": "C"
}
]
}
================================================
FILE: presets/examples/6.jsonc
================================================
// Load with --config examples/2.jsonc
// Note that you must replace the image path to an existing image to display it.
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"display": {
"separator": " "
},
"modules": [
{
"type": "host",
"key": "╭─",
"keyColor": "green"
},
{
"type": "cpu",
"key": "├─",
"keyColor": "green"
},
{
"type": "gpu",
"key": "├─",
"keyColor": "green"
},
{
"type": "disk",
"key": "├─",
"keyColor": "green"
},
{
"type": "memory",
"key": "├─",
"keyColor": "green"
},
{
"type": "swap",
"key": "├─",
"keyColor": "green"
},
{
"type": "display",
"key": "├─",
"keyColor": "green"
},
{
"type": "brightness",
"key": "├─",
"keyColor": "green"
},
{
"type": "battery",
"key": "├─",
"keyColor": "green"
},
{
"type": "poweradapter",
"key": "├─",
"keyColor": "green"
},
{
"type": "gamepad",
"key": "├─",
"keyColor": "green"
},
{
"type": "bluetooth",
"key": "├─",
"keyColor": "green"
},
{
"type": "sound",
"key": "╰─",
"keyColor": "green"
},
"break",
{
"type": "shell",
"key": "╭─",
"keyColor": "yellow"
},
{
"type": "terminal",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "terminalfont",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "lm",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "de",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "wm",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "theme",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "icons",
"key": "├─",
"keyColor": "yellow"
},
{
"type": "wallpaper",
"key": "╰─",
"keyColor": "yellow"
},
"break",
{
"type": "title",
"key": "╭─",
"format": "{user-name}@{host-name}",
"keyColor": "blue"
},
{
"type": "os",
"key": "├─{icon}", // Just get your distro's logo off nerdfonts.com
"keyColor": "blue"
},
{
"type": "kernel",
"key": "├─",
"keyColor": "blue"
},
{
"type": "packages",
"key": "├─",
"keyColor": "blue"
},
{
"type": "uptime",
"key": "├─",
"keyColor": "blue"
},
{
"type": "media",
"key": "├─",
"keyColor": "blue"
},
{
"type": "localip",
"key": "├─",
"compact": true,
"keyColor": "blue"
},
{
"type": "publicip",
"key": "├─",
"keyColor": "blue",
"timeout": 1000
},
{
"type": "wifi",
"key": "├─",
"format": "{ssid}",
"keyColor": "blue"
},
{
"type": "locale",
"key": "╰─",
"keyColor": "blue"
}
]
}
================================================
FILE: presets/examples/7.jsonc
================================================
// Load with --config examples/2.jsonc
// Note that you must replace the image path to an existing image to display it.
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"padding": {
"top": 2
}
},
"display": {
"separator": " -> "
},
"modules": [
"title",
"separator",
{
"type": "os",
"key": " OS",
"keyColor": "yellow",
"format": "{2}"
},
{
"type": "os",
"key": "├{icon}", // Just get your distro's logo off nerdfonts.com
"keyColor": "yellow"
},
{
"type": "kernel",
"key": "├",
"keyColor": "yellow"
},
{
"type": "packages",
"key": "├",
"keyColor": "yellow"
},
{
"type": "shell",
"key": "└",
"keyColor": "yellow"
},
"break",
{
"type": "wm",
"key": " DE/WM",
"keyColor": "blue"
},
{
"type": "lm",
"key": "├",
"keyColor": "blue"
},
{
"type": "wmtheme",
"key": "├",
"keyColor": "blue"
},
{
"type": "icons",
"key": "├",
"keyColor": "blue"
},
{
"type": "terminal",
"key": "├",
"keyColor": "blue"
},
{
"type": "wallpaper",
"key": "└",
"keyColor": "blue"
},
"break",
{
"type": "host",
"key": " PC",
"keyColor": "green"
},
{
"type": "cpu",
"key": "├",
"keyColor": "green"
},
{
"type": "gpu",
"key": "├",
"keyColor": "green"
},
{
"type": "disk",
"key": "├",
"keyColor": "green"
},
{
"type": "memory",
"key": "├",
"keyColor": "green"
},
{
"type": "swap",
"key": "├",
"keyColor": "green"
},
{
"type": "display",
"key": "├",
"keyColor": "green"
},
{
"type": "uptime",
"key": "└",
"keyColor": "green"
},
"break",
{
"type": "sound",
"key": " SOUND",
"keyColor": "cyan"
},
{
"type": "player",
"key": "├",
"keyColor": "cyan"
},
{
"type": "media",
"key": "└",
"keyColor": "cyan"
},
"break",
"colors"
]
}
================================================
FILE: presets/examples/8.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"separator": " ",
"color": {
"keys": "magenta"
},
"size": {
"ndigits": 0,
"maxPrefix": "MB"
},
"key": {
"type": "icon"
}
},
"modules": [
{
"type": "title",
"color": {
"user": "green",
"at": "red",
"host": "blue"
}
},
"os",
"kernel",
"memory",
"packages",
"uptime",
{
"type": "colors",
"key": "Colors", // For printing icon
"block": {
"range": [1, 6]
}
}
]
}
================================================
FILE: presets/examples/9.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"key": {
"width": 11
},
"bar": {
"char": {
"elapsed": "=",
"total": "-"
},
"width": 13
},
"percent": {
"type": 2
}
},
"modules": [
"title",
"separator",
"memory",
"swap",
{
"type": "disk",
"folders": "/"
},
{
"type": "battery",
"key": "Battery"
},
{
"type": "colors",
"paddingLeft": 10,
"symbol": "circle"
}
]
}
================================================
FILE: presets/neofetch.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"display": {
"size": {
"maxPrefix": "MB",
"ndigits": 0,
"spaceBeforeUnit": "never"
},
"freq": {
"ndigits": 3,
"spaceBeforeUnit": "never"
}
},
"modules": [
"title",
"separator",
"os",
"host",
{
"type": "kernel",
"format": "{release}"
},
"uptime",
{
"type": "packages",
"combined": true
},
"shell",
{
"type": "display",
"compactType": "original",
"key": "Resolution"
},
"de",
"wm",
"wmtheme",
"theme",
"icons",
"terminal",
{
"type": "terminalfont",
"format": "{/name}{-}{/}{name}{?size} {size}{?}"
},
"cpu",
{
"type": "gpu",
"key": "GPU",
"format": "{name}"
},
{
"type": "memory",
"format": "{used} / {total}"
},
"break",
"colors"
]
}
================================================
FILE: presets/paleofetch.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"modules": [
"title",
"separator",
"os",
{
"type": "host",
"format": "{/2}{-}{/}{2}{?3} {3}{?}"
},
"kernel",
"uptime",
{
"type": "battery",
"format": "{/4}{-}{/}{4}{?5} [{5}]{?}"
},
"break",
"packages",
"shell",
"display",
"terminal",
"break",
"cpu",
{
"type": "gpu",
"key": "GPU"
},
"memory",
"break",
"colors"
]
}
================================================
FILE: presets/screenfetch.jsonc
================================================
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"modules": [
"title",
"os",
"kernel",
"uptime",
{
"type": "packages",
"format": "{all}"
},
"shell",
{
"type": "display",
"key": "Resolution",
"compactType": "original"
},
"de",
"wm",
"wmtheme",
{
"type": "terminalfont",
"key": "font"
},
{
"type": "disk",
"folders": "/",
"key": "Disk"
},
"cpu",
"gpu",
{
"type": "memory",
"key": "RAM"
}
]
}
================================================
FILE: run.sh
================================================
#!/usr/bin/env sh
set -e
mkdir -p build/
cd build/
cmake ..
kernel_name="$(uname -s)"
case "${kernel_name}" in
"Linux" | "MINGW"*)
cmake_build_args="-j$(nproc)"
;;
"Darwin" | *"BSD" | "DragonFly")
cmake_build_args="-j$(sysctl -n hw.ncpu)"
;;
*)
cmake_build_args=""
;;
esac
cmake --build . --target fastfetch "${cmake_build_args}"
./fastfetch "$@"
================================================
FILE: scripts/gen-amdgpuids.py
================================================
#!/usr/bin/env python3
import sys
def main(amdgpu_ids_path: str):
with open(amdgpu_ids_path, 'r') as f:
full_text = f.read()
if full_text == '':
sys.exit('Error: pci.ids file is empty')
products = []
for line in full_text.split('\n'):
if not line or line[0] == '#' or not ',\t' in line:
continue
device, revision, name = line.split(',\t', maxsplit=2)
products.append((device, revision, name))
code = """\
// SPDX-License-Identifier: MIT
// https://opensource.org/license/mit
// Generated from https://gitlab.freedesktop.org/mesa/drm/-/raw/main/data/amdgpu.ids
#include
#include
typedef struct FFArmGpuProduct
{
const uint32_t id; // device << 8 | revision
const char* name;
} FFArmGpuProduct;
const FFArmGpuProduct ffAmdGpuProducts[] = {
"""
for device, revision, name in products:
code += f" {{ 0x{device} << 8 | 0x{revision}, \"{name}\" }},\n"
code += "};\n"
print(code)
if __name__ == '__main__':
len(sys.argv) == 2 or sys.exit('Usage: gen-amdgpuids.py ')
main(sys.argv[1])
================================================
FILE: scripts/gen-man.py
================================================
#!/usr/bin/env python3
"""
Python script to generate a comprehensive man page for the command `fastfetch`.
The generated man page content will be printed to stdout,
so you will need to pipe it to a file if you want to save it.
Example: python3 gen-man.py > fastfetch.1
The command options are generated using a JSON file.
For the JSON file format, see:
https://github.com/fastfetch-cli/fastfetch/blob/dev/src/data/help.json
"""
from json import load
from datetime import datetime, timezone
from time import time
from re import search
from os import environ, path
###### Text Decorations Tags ######
startUnderline = r"\fI" # start underline text tag
endUnderline = r"\fR" # end underline text tag
startBold = r"\fB" # start bold text tag
endBold = r"\fR" # end bold text tag
###### Parameters ######
# path to the current directory
pathToCurrentDir = path.dirname(__file__)
# path to the JSON option file
pathToHelpFile = path.join(pathToCurrentDir, "../src/data/help.json")
# man page section
manSection = 1
# title (center header)
titlePage = "FASTFETCH"
# date (center footer)
# format : "Month (abbreviation) Day Year"
todayDate = datetime.fromtimestamp(
int(environ.get("SOURCE_DATE_EPOCH", time())),
tz=timezone.utc,
).strftime("%b %d %Y")
# file to fastfetch version (left footer)
pathToVersionFile = path.join(pathToCurrentDir, "../CMakeLists.txt")
###### Sections Text ######
# text displayed in the "NAME" section
nameSection = r"fastfetch \- A fast and feature-rich system information tool similar to neofetch"
# text displayed in the "DESCRIPTION" section
descriptionSection = r"""
Fastfetch is a tool for displaying system information in a visually appealing way. Written primarily in C, it focuses on performance and customizability while providing functionality similar to neofetch.
It supports Linux, Android, FreeBSD, macOS, and Windows 7 or newer.
"""
# text displayed at the beginning of the "OPTIONS" section
optionSection = r"""
Options are parsed in a case-insensitive manner. For example, \fB--logo-type\fR and \fB--LOGO-TYPE\fR are treated identically.
Arguments in square brackets are optional. Optional boolean arguments default to 'true' when specified without a value.
For more detailed information about a specific option, use:
\fBfastfetch -h \fR
Any combination of options can be made permanent by generating a configuration file:
\fBfastfetch --gen-config\fR
"""
# text displayed in the "CONFIGURATION"
configurationSection = f"""
.SS Fetch Structure
The structure defines which modules to display and in what order. It consists of module names separated by colons (:).
For example: {startBold}title:separator:os:kernel:uptime{endBold}
To list all available modules, use {startBold}--list-modules{endBold}
.SS Config Files
Fastfetch uses JSONC (JSON with Comments) for configuration files. These files must have the .jsonc extension.
You can generate a default config file using {startBold}--gen-config{endBold}. By default, the config file is saved at {startBold}~/.config/fastfetch/config.jsonc{endBold}.
The configuration/preset files are searched in the following locations (in order):
{startBold}1.{endBold} Relative to the current working directory
{startBold}2.{endBold} Relative to ~/.local/share/fastfetch/presets/
{startBold}3.{endBold} Relative to /usr/share/fastfetch/presets/
For detailed information on logo options, module configuration, and formatting, visit:
{startBold}https://github.com/fastfetch-cli/fastfetch/wiki/Configuration{endBold}
Fastfetch provides several built-in presets. List them with {startBold}--list-presets{endBold}.
.SS JSON Schema
A JSON schema is available for editor intelligence when editing the configuration file. Add the following line at the beginning of your config file:
{startBold}"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"{endBold}
"""
# text displayed in the "EXAMPLE" section
exampleSection = f"""
.SS Basic Usage
{startBold}fastfetch{endBold}
.SS Use a specific logo
{startBold}fastfetch --logo arch{endBold}
.SS Custom structure
{startBold}fastfetch --structure title:os:kernel:uptime:memory{endBold}
.SS Generate a config file
{startBold}fastfetch --gen-config{endBold}
.SS Use a preset
{startBold}fastfetch --config neofetch{endBold}
.SS Config File Example
.nf
// ~/.config/fastfetch/config.jsonc
{{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {{
"type": "auto",
"source": "arch"
}},
"display": {{
"separator": ": ",
"color": {{
"keys": "blue",
"title": "red"
}},
"key": {{
"width": 12
}}
}},
"modules": [
"title",
"separator",
"os",
"kernel",
"uptime",
{{
"type": "memory",
"format": "{{used}}/{{total}} ({{used_percent}}%)"
}}
]
}}
.fi
"""
# text displayed in the "BUGS" section
bugSection = "Please report bugs to: https://github.com/fastfetch-cli/fastfetch/issues"
# text displayed in the "AUTHORS" section
authorsSection = "Fastfetch is developed by a team of contributors on GitHub.\nVisit https://github.com/fastfetch-cli/fastfetch for more information."
###### Argument decoration ######
### optional arguments tags ###
# if an optional argument is displayed as [?optArg] (with "optArg" underlined)
# this value should be f"[?{startUnderline}"
startOptionalArgument = f"[{startUnderline}"
# if an optional argument is displayed as [?optArg] (with "optArg underlined")
# this value should be f"{endUnderline}]"
endOptionalArgument = f"{endUnderline}]"
### mandatory arguments tags ###
startMandatoryArgument = f"{startUnderline}"
endMandatoryArgument = f"{endUnderline}"
def main():
# importing the JSON file
with open(pathToHelpFile, 'r') as jsonFile:
helpFileData = load(jsonFile) # json.load
######## Start printing the generated .1 file ########
###### header, footer & config #####
print(f".TH FASTFETCH {manSection} ", end=" ")
print(f"\"{todayDate}\"", end=" ")
# version number
with open(pathToVersionFile, 'r') as versionFile:
# research version number in file with regex
for line in versionFile:
researchVersion = search(r"^\s*VERSION (\d+\.\d+\.\d+)$", line)
if (researchVersion):
print(f"\"Fastfetch {researchVersion.group(1)}\"", end=" ")
break
print(f"\"{titlePage}\"")
###### Name ######
print(".SH NAME")
print(nameSection)
##### Synopsis ######
print(".SH SYNOPSIS")
print(".B fastfetch")
print(f"[{startUnderline}OPTIONS{endUnderline}...]")
###### Description ######
print(".SH DESCRIPTION")
print(descriptionSection)
###### Configuration ######
print(".SH CONFIGURATION")
print(configurationSection)
###### Options ######
print(".SH OPTIONS")
print(optionSection)
print()
# loop through every options sections
for key, value in helpFileData.items():
# print new subsection
print(f".SS {key}")
# loop through every option in a section
for option in value:
# list of existing keys for this option
keyList = option.keys()
# start a new "option" entry
print(".TP")
print(startBold, end="")
# short option (-opt)
if "short" in keyList:
print(fr"\-{ option['short'] }", end="")
# if also have a long option, print a comma
if "long" in keyList:
print(", ", end="")
# long option (--option)
if "long" in keyList:
print(fr"\-\-{ option['long'] }", end="")
print(endBold, end=" ")
# arguments
if "arg" in keyList:
# if argument is optional, print "[arg]"
if "optional" in option["arg"].keys() and option["arg"]["optional"]:
print(startOptionalArgument + option['arg']['type'] + endOptionalArgument, end="")
# if argument is mandatory, print "arg"
else:
print(startMandatoryArgument + option['arg']['type'] + endMandatoryArgument, end="")
# description
print()
# If desc is a list, join with newlines and proper spacing
if isinstance(option['desc'], list):
desc_text = "\n ".join(option['desc'])
print(f" {desc_text}")
else:
print(f" {option['desc']}")
# Add remarks if available
if "remark" in keyList:
print()
if isinstance(option['remark'], list):
for remark in option['remark']:
print(f" {remark}")
else:
print(f" {option['remark']}")
print()
###### Examples ######
print(".SH EXAMPLES")
print(exampleSection)
###### See Also ######
print(".SH \"SEE ALSO\"")
print(".BR neofetch (1)")
###### Bugs ######
print(".SH BUGS")
print(bugSection)
###### Authors ######
print(".SH AUTHORS")
print(authorsSection)
if __name__ == "__main__":
main()
================================================
FILE: scripts/gen-pciids.py
================================================
#!/usr/bin/env python3
import sys
class PciDeviceModel:
def __init__(self, id: int, name: str):
self.id = id
self.name = name
class PciVendorModel:
def __init__(self, id: int, name: str):
self.id = id
self.name = name
self.devices = []
def main(keep_vendor_list: set, pci_ids_path: str):
vendors = []
with open(pci_ids_path, 'r') as f:
full_text = f.read()
if full_text == '':
sys.exit('Error: pci.ids file is empty')
dev_list_text = full_text[:full_text.rfind('\n\n\n')] # remove known classes
for line in dev_list_text.split('\n'):
if not line or line[0] == '#':
continue
if line[0] != '\t':
id, name = line.split(' ', maxsplit=1)
vendors.append(PciVendorModel(int(id, 16), name))
elif line[1] != '\t':
id, name = line[1:].split(' ', maxsplit=1)
vendors[-1].devices.append(PciDeviceModel(int(id, 16), name))
code = """\
// SPDX-License-Identifier: BSD-3-Clause
// https://opensource.org/license/BSD-3-Clause
// Generated from https://pci-ids.ucw.cz/v2.2/pci.ids
#include
#include
typedef struct FFPciDevice
{
const uint32_t id;
const char* name;
} FFPciDevice;
typedef struct FFPciVendor
{
const uint32_t id;
const char* name;
const FFPciDevice* devices;
const uint32_t nDevices;
} FFPciVendor;
"""
if keep_vendor_list:
vendors = [vendor for vendor in vendors if vendor.id in keep_vendor_list]
for vendor in vendors:
if vendor.devices:
piece = ',\n '.join('{{ 0x{:04X}, "{}" }}'.format(device.id, device.name.replace('"', '\\"')) for device in vendor.devices)
code += f"""
// {vendor.name}
static const FFPciDevice pciDevices_{vendor.id:04X}[] = {{
{piece},
{{}},
}};
"""
piece = ',\n '.join('{{ 0x{:04X}, "{}", {}, {} }}'.format(vendor.id, vendor.name.replace('"', '\\"'), vendor.devices and f"pciDevices_{vendor.id:04X}" or "NULL", len(vendor.devices)) for vendor in vendors)
code += f"""
const FFPciVendor ffPciVendors[] = {{
{piece},
{{}},
}};"""
print(code)
if __name__ == '__main__':
len(sys.argv) == 2 or sys.exit('Usage: gen-pciids.py ')
# From
main({
0x106b, # Apple
0x1002, 0x1022, # AMD
0x8086, 0x8087, 0x03e7, # Intel
0x0955, 0x10de, 0x12d2, # Nvidia
0x1ed5, # MThreads
0x5143, # Qualcomm
0x14c3, # MTK
0x15ad, # VMware
0x1af4, # RedHat
0x1ab8, # Parallel
0x1414, # Microsoft
0x108e, # Oracle
}, sys.argv[1])
================================================
FILE: src/3rdparty/display-library/adl_defines.h
================================================
//
// Copyright (c) 2016 - 2022 Advanced Micro Devices, Inc. All rights reserved.
//
// MIT LICENSE:
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/// \file adl_defines.h
/// \brief Contains all definitions exposed by ADL for \ALL platforms.\n Included in ADL SDK
///
/// This file contains all definitions used by ADL.
/// The ADL definitions include the following:
/// \li ADL error codes
/// \li Enumerations for the ADLDisplayInfo structure
/// \li Maximum limits
///
#ifndef ADL_DEFINES_H_
#define ADL_DEFINES_H_
/// \defgroup DEFINES Constants and Definitions
/// @{
/// \defgroup define_misc Miscellaneous Constant Definitions
/// @{
/// \name General Definitions
/// @{
/// Defines ADL_TRUE
#define ADL_TRUE 1
/// Defines ADL_FALSE
#define ADL_FALSE 0
/// Defines the maximum string length
#define ADL_MAX_CHAR 4096
/// Defines the maximum string length
#define ADL_MAX_PATH 256
/// Defines the maximum number of supported adapters
#define ADL_MAX_ADAPTERS 250
/// Defines the maxumum number of supported displays
#define ADL_MAX_DISPLAYS 150
/// Defines the maxumum string length for device name
#define ADL_MAX_DEVICENAME 32
/// Defines for all adapters
#define ADL_ADAPTER_INDEX_ALL -1
/// Defines APIs with iOption none
#define ADL_MAIN_API_OPTION_NONE 0
/// @}
/// \name Definitions for iOption parameter used by
/// ADL_Display_DDCBlockAccess_Get()
/// @{
/// Switch to DDC line 2 before sending the command to the display.
#define ADL_DDC_OPTION_SWITCHDDC2 0x00000001
/// Save command in the registry under a unique key, corresponding to parameter \b iCommandIndex
#define ADL_DDC_OPTION_RESTORECOMMAND 0x00000002
/// Combine write-read DDC block access command.
#define ADL_DDC_OPTION_COMBOWRITEREAD 0x00000010
/// Direct DDC access to the immediate device connected to graphics card.
/// MST with this option set: DDC command is sent to first branch.
/// MST with this option not set: DDC command is sent to the end node sink device.
#define ADL_DDC_OPTION_SENDTOIMMEDIATEDEVICE 0x00000020
/// @}
/// \name Values for
/// ADLI2C.iAction used with ADL_Display_WriteAndReadI2C()
/// @{
#define ADL_DL_I2C_ACTIONREAD 0x00000001
#define ADL_DL_I2C_ACTIONWRITE 0x00000002
#define ADL_DL_I2C_ACTIONREAD_REPEATEDSTART 0x00000003
#define ADL_DL_I2C_ACTIONIS_PRESENT 0x00000004
/// @}
/// @} //Misc
/// \defgroup define_adl_results Result Codes
/// This group of definitions are the various results returned by all ADL functions \n
/// @{
/// All OK, but need to wait
#define ADL_OK_WAIT 4
/// All OK, but need restart
#define ADL_OK_RESTART 3
/// All OK but need mode change
#define ADL_OK_MODE_CHANGE 2
/// All OK, but with warning
#define ADL_OK_WARNING 1
/// ADL function completed successfully
#define ADL_OK 0
/// Generic Error. Most likely one or more of the Escape calls to the driver failed!
#define ADL_ERR -1
/// ADL not initialized
#define ADL_ERR_NOT_INIT -2
/// One of the parameter passed is invalid
#define ADL_ERR_INVALID_PARAM -3
/// One of the parameter size is invalid
#define ADL_ERR_INVALID_PARAM_SIZE -4
/// Invalid ADL index passed
#define ADL_ERR_INVALID_ADL_IDX -5
/// Invalid controller index passed
#define ADL_ERR_INVALID_CONTROLLER_IDX -6
/// Invalid display index passed
#define ADL_ERR_INVALID_DIPLAY_IDX -7
/// Function not supported by the driver
#define ADL_ERR_NOT_SUPPORTED -8
/// Null Pointer error
#define ADL_ERR_NULL_POINTER -9
/// Call can't be made due to disabled adapter
#define ADL_ERR_DISABLED_ADAPTER -10
/// Invalid Callback
#define ADL_ERR_INVALID_CALLBACK -11
/// Display Resource conflict
#define ADL_ERR_RESOURCE_CONFLICT -12
//Failed to update some of the values. Can be returned by set request that include multiple values if not all values were successfully committed.
#define ADL_ERR_SET_INCOMPLETE -20
/// There's no Linux XDisplay in Linux Console environment
#define ADL_ERR_NO_XDISPLAY -21
/// escape call failed becuse of incompatiable driver found in driver store
#define ADL_ERR_CALL_TO_INCOMPATIABLE_DRIVER -22
/// not running as administrator
#define ADL_ERR_NO_ADMINISTRATOR_PRIVILEGES -23
/// Feature Sync Start api is not called yet
#define ADL_ERR_FEATURESYNC_NOT_STARTED -24
/// Adapter is in an invalid power state
#define ADL_ERR_INVALID_POWER_STATE -25
/// @}
///
/// \defgroup define_display_type Display Type
/// Define Monitor/CRT display type
/// @{
/// Define Monitor display type
#define ADL_DT_MONITOR 0
/// Define TV display type
#define ADL_DT_TELEVISION 1
/// Define LCD display type
#define ADL_DT_LCD_PANEL 2
/// Define DFP display type
#define ADL_DT_DIGITAL_FLAT_PANEL 3
/// Define Componment Video display type
#define ADL_DT_COMPONENT_VIDEO 4
/// Define Projector display type
#define ADL_DT_PROJECTOR 5
/// @}
/// \defgroup define_display_connection_type Display Connection Type
/// @{
/// Define unknown display output type
#define ADL_DOT_UNKNOWN 0
/// Define composite display output type
#define ADL_DOT_COMPOSITE 1
/// Define SVideo display output type
#define ADL_DOT_SVIDEO 2
/// Define analog display output type
#define ADL_DOT_ANALOG 3
/// Define digital display output type
#define ADL_DOT_DIGITAL 4
/// @}
/// \defgroup define_color_type Display Color Type and Source
/// Define Display Color Type and Source
/// @{
#define ADL_DISPLAY_COLOR_BRIGHTNESS (1 << 0)
#define ADL_DISPLAY_COLOR_CONTRAST (1 << 1)
#define ADL_DISPLAY_COLOR_SATURATION (1 << 2)
#define ADL_DISPLAY_COLOR_HUE (1 << 3)
#define ADL_DISPLAY_COLOR_TEMPERATURE (1 << 4)
/// Color Temperature Source is EDID
#define ADL_DISPLAY_COLOR_TEMPERATURE_SOURCE_EDID (1 << 5)
/// Color Temperature Source is User
#define ADL_DISPLAY_COLOR_TEMPERATURE_SOURCE_USER (1 << 6)
/// @}
/// \defgroup define_adjustment_capabilities Display Adjustment Capabilities
/// Display adjustment capabilities values. Returned by ADL_Display_AdjustCaps_Get
/// @{
#define ADL_DISPLAY_ADJUST_OVERSCAN (1 << 0)
#define ADL_DISPLAY_ADJUST_VERT_POS (1 << 1)
#define ADL_DISPLAY_ADJUST_HOR_POS (1 << 2)
#define ADL_DISPLAY_ADJUST_VERT_SIZE (1 << 3)
#define ADL_DISPLAY_ADJUST_HOR_SIZE (1 << 4)
#define ADL_DISPLAY_ADJUST_SIZEPOS (ADL_DISPLAY_ADJUST_VERT_POS | ADL_DISPLAY_ADJUST_HOR_POS | ADL_DISPLAY_ADJUST_VERT_SIZE | ADL_DISPLAY_ADJUST_HOR_SIZE)
#define ADL_DISPLAY_CUSTOMMODES (1<<5)
#define ADL_DISPLAY_ADJUST_UNDERSCAN (1<<6)
/// @}
///Down-scale support
#define ADL_DISPLAY_CAPS_DOWNSCALE (1 << 0)
/// Sharpness support
#define ADL_DISPLAY_CAPS_SHARPNESS (1 << 0)
/// \defgroup define_desktop_config Desktop Configuration Flags
/// These flags are used by ADL_DesktopConfig_xxx
/// \deprecated This API has been deprecated because it was only used for RandR 1.1 (Red Hat 5.x) distributions which is now not supported.
/// @{
#define ADL_DESKTOPCONFIG_UNKNOWN 0 /* UNKNOWN desktop config */
#define ADL_DESKTOPCONFIG_SINGLE (1 << 0) /* Single */
#define ADL_DESKTOPCONFIG_CLONE (1 << 2) /* Clone */
#define ADL_DESKTOPCONFIG_BIGDESK_H (1 << 4) /* Big Desktop Horizontal */
#define ADL_DESKTOPCONFIG_BIGDESK_V (1 << 5) /* Big Desktop Vertical */
#define ADL_DESKTOPCONFIG_BIGDESK_HR (1 << 6) /* Big Desktop Reverse Horz */
#define ADL_DESKTOPCONFIG_BIGDESK_VR (1 << 7) /* Big Desktop Reverse Vert */
#define ADL_DESKTOPCONFIG_RANDR12 (1 << 8) /* RandR 1.2 Multi-display */
/// @}
/// needed for ADLDDCInfo structure
#define ADL_MAX_DISPLAY_NAME 256
/// \defgroup define_edid_flags Values for ulDDCInfoFlag
/// defines for ulDDCInfoFlag EDID flag
/// @{
#define ADL_DISPLAYDDCINFOEX_FLAG_PROJECTORDEVICE (1 << 0)
#define ADL_DISPLAYDDCINFOEX_FLAG_EDIDEXTENSION (1 << 1)
#define ADL_DISPLAYDDCINFOEX_FLAG_DIGITALDEVICE (1 << 2)
#define ADL_DISPLAYDDCINFOEX_FLAG_HDMIAUDIODEVICE (1 << 3)
#define ADL_DISPLAYDDCINFOEX_FLAG_SUPPORTS_AI (1 << 4)
#define ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC601 (1 << 5)
#define ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC709 (1 << 6)
/// @}
/// \defgroup define_displayinfo_connector Display Connector Type
/// defines for ADLDisplayInfo.iDisplayConnector
/// @{
#define ADL_DISPLAY_CONTYPE_UNKNOWN 0
#define ADL_DISPLAY_CONTYPE_VGA 1
#define ADL_DISPLAY_CONTYPE_DVI_D 2
#define ADL_DISPLAY_CONTYPE_DVI_I 3
#define ADL_DISPLAY_CONTYPE_ATICVDONGLE_NTSC 4
#define ADL_DISPLAY_CONTYPE_ATICVDONGLE_JPN 5
#define ADL_DISPLAY_CONTYPE_ATICVDONGLE_NONI2C_JPN 6
#define ADL_DISPLAY_CONTYPE_ATICVDONGLE_NONI2C_NTSC 7
#define ADL_DISPLAY_CONTYPE_PROPRIETARY 8
#define ADL_DISPLAY_CONTYPE_HDMI_TYPE_A 10
#define ADL_DISPLAY_CONTYPE_HDMI_TYPE_B 11
#define ADL_DISPLAY_CONTYPE_SVIDEO 12
#define ADL_DISPLAY_CONTYPE_COMPOSITE 13
#define ADL_DISPLAY_CONTYPE_RCA_3COMPONENT 14
#define ADL_DISPLAY_CONTYPE_DISPLAYPORT 15
#define ADL_DISPLAY_CONTYPE_EDP 16
#define ADL_DISPLAY_CONTYPE_WIRELESSDISPLAY 17
#define ADL_DISPLAY_CONTYPE_USB_TYPE_C 18
/// @}
/// TV Capabilities and Standards
/// \defgroup define_tv_caps TV Capabilities and Standards
/// \deprecated Dropping support for TV displays
/// @{
#define ADL_TV_STANDARDS (1 << 0)
#define ADL_TV_SCART (1 << 1)
/// TV Standards Definitions
#define ADL_STANDARD_NTSC_M (1 << 0)
#define ADL_STANDARD_NTSC_JPN (1 << 1)
#define ADL_STANDARD_NTSC_N (1 << 2)
#define ADL_STANDARD_PAL_B (1 << 3)
#define ADL_STANDARD_PAL_COMB_N (1 << 4)
#define ADL_STANDARD_PAL_D (1 << 5)
#define ADL_STANDARD_PAL_G (1 << 6)
#define ADL_STANDARD_PAL_H (1 << 7)
#define ADL_STANDARD_PAL_I (1 << 8)
#define ADL_STANDARD_PAL_K (1 << 9)
#define ADL_STANDARD_PAL_K1 (1 << 10)
#define ADL_STANDARD_PAL_L (1 << 11)
#define ADL_STANDARD_PAL_M (1 << 12)
#define ADL_STANDARD_PAL_N (1 << 13)
#define ADL_STANDARD_PAL_SECAM_D (1 << 14)
#define ADL_STANDARD_PAL_SECAM_K (1 << 15)
#define ADL_STANDARD_PAL_SECAM_K1 (1 << 16)
#define ADL_STANDARD_PAL_SECAM_L (1 << 17)
/// @}
/// \defgroup define_video_custom_mode Video Custom Mode flags
/// Component Video Custom Mode flags. This is used by the iFlags parameter in ADLCustomMode
/// @{
#define ADL_CUSTOMIZEDMODEFLAG_MODESUPPORTED (1 << 0)
#define ADL_CUSTOMIZEDMODEFLAG_NOTDELETETABLE (1 << 1)
#define ADL_CUSTOMIZEDMODEFLAG_INSERTBYDRIVER (1 << 2)
#define ADL_CUSTOMIZEDMODEFLAG_INTERLACED (1 << 3)
#define ADL_CUSTOMIZEDMODEFLAG_BASEMODE (1 << 4)
/// @}
/// \defgroup define_ddcinfoflag Values used for DDCInfoFlag
/// ulDDCInfoFlag field values used by the ADLDDCInfo structure
/// @{
#define ADL_DISPLAYDDCINFOEX_FLAG_PROJECTORDEVICE (1 << 0)
#define ADL_DISPLAYDDCINFOEX_FLAG_EDIDEXTENSION (1 << 1)
#define ADL_DISPLAYDDCINFOEX_FLAG_DIGITALDEVICE (1 << 2)
#define ADL_DISPLAYDDCINFOEX_FLAG_HDMIAUDIODEVICE (1 << 3)
#define ADL_DISPLAYDDCINFOEX_FLAG_SUPPORTS_AI (1 << 4)
#define ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC601 (1 << 5)
#define ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC709 (1 << 6)
/// @}
/// \defgroup define_cv_dongle Values used by ADL_CV_DongleSettings_xxx
/// The following is applicable to ADL_DISPLAY_CONTYPE_ATICVDONGLE_JP and ADL_DISPLAY_CONTYPE_ATICVDONGLE_NONI2C_D only
/// \deprecated Dropping support for Component Video displays
/// @{
#define ADL_DISPLAY_CV_DONGLE_D1 (1 << 0)
#define ADL_DISPLAY_CV_DONGLE_D2 (1 << 1)
#define ADL_DISPLAY_CV_DONGLE_D3 (1 << 2)
#define ADL_DISPLAY_CV_DONGLE_D4 (1 << 3)
#define ADL_DISPLAY_CV_DONGLE_D5 (1 << 4)
/// The following is applicable to ADL_DISPLAY_CONTYPE_ATICVDONGLE_NA and ADL_DISPLAY_CONTYPE_ATICVDONGLE_NONI2C only
#define ADL_DISPLAY_CV_DONGLE_480I (1 << 0)
#define ADL_DISPLAY_CV_DONGLE_480P (1 << 1)
#define ADL_DISPLAY_CV_DONGLE_540P (1 << 2)
#define ADL_DISPLAY_CV_DONGLE_720P (1 << 3)
#define ADL_DISPLAY_CV_DONGLE_1080I (1 << 4)
#define ADL_DISPLAY_CV_DONGLE_1080P (1 << 5)
#define ADL_DISPLAY_CV_DONGLE_16_9 (1 << 6)
#define ADL_DISPLAY_CV_DONGLE_720P50 (1 << 7)
#define ADL_DISPLAY_CV_DONGLE_1080I25 (1 << 8)
#define ADL_DISPLAY_CV_DONGLE_576I25 (1 << 9)
#define ADL_DISPLAY_CV_DONGLE_576P50 (1 << 10)
#define ADL_DISPLAY_CV_DONGLE_1080P24 (1 << 11)
#define ADL_DISPLAY_CV_DONGLE_1080P25 (1 << 12)
#define ADL_DISPLAY_CV_DONGLE_1080P30 (1 << 13)
#define ADL_DISPLAY_CV_DONGLE_1080P50 (1 << 14)
/// @}
/// \defgroup define_formats_ovr Formats Override Settings
/// Display force modes flags
/// @{
///
#define ADL_DISPLAY_FORMAT_FORCE_720P 0x00000001
#define ADL_DISPLAY_FORMAT_FORCE_1080I 0x00000002
#define ADL_DISPLAY_FORMAT_FORCE_1080P 0x00000004
#define ADL_DISPLAY_FORMAT_FORCE_720P50 0x00000008
#define ADL_DISPLAY_FORMAT_FORCE_1080I25 0x00000010
#define ADL_DISPLAY_FORMAT_FORCE_576I25 0x00000020
#define ADL_DISPLAY_FORMAT_FORCE_576P50 0x00000040
#define ADL_DISPLAY_FORMAT_FORCE_1080P24 0x00000080
#define ADL_DISPLAY_FORMAT_FORCE_1080P25 0x00000100
#define ADL_DISPLAY_FORMAT_FORCE_1080P30 0x00000200
#define ADL_DISPLAY_FORMAT_FORCE_1080P50 0x00000400
///< Below are \b EXTENDED display mode flags
#define ADL_DISPLAY_FORMAT_CVDONGLEOVERIDE 0x00000001
#define ADL_DISPLAY_FORMAT_CVMODEUNDERSCAN 0x00000002
#define ADL_DISPLAY_FORMAT_FORCECONNECT_SUPPORTED 0x00000004
#define ADL_DISPLAY_FORMAT_RESTRICT_FORMAT_SELECTION 0x00000008
#define ADL_DISPLAY_FORMAT_SETASPECRATIO 0x00000010
#define ADL_DISPLAY_FORMAT_FORCEMODES 0x00000020
#define ADL_DISPLAY_FORMAT_LCDRTCCOEFF 0x00000040
/// @}
/// Defines used by OD5
#define ADL_PM_PARAM_DONT_CHANGE 0
/// The following defines Bus types
/// @{
#define ADL_BUSTYPE_PCI 0 /* PCI bus */
#define ADL_BUSTYPE_AGP 1 /* AGP bus */
#define ADL_BUSTYPE_PCIE 2 /* PCI Express bus */
#define ADL_BUSTYPE_PCIE_GEN2 3 /* PCI Express 2nd generation bus */
#define ADL_BUSTYPE_PCIE_GEN3 4 /* PCI Express 3rd generation bus */
#define ADL_BUSTYPE_PCIE_GEN4 5 /* PCI Express 4th generation bus */
/// @}
/// \defgroup define_ws_caps Workstation Capabilities
/// Workstation values
/// @{
/// This value indicates that the workstation card supports active stereo though stereo output connector
#define ADL_STEREO_SUPPORTED (1 << 2)
/// This value indicates that the workstation card supports active stereo via "blue-line"
#define ADL_STEREO_BLUE_LINE (1 << 3)
/// This value is used to turn off stereo mode.
#define ADL_STEREO_OFF 0
/// This value indicates that the workstation card supports active stereo. This is also used to set the stereo mode to active though the stereo output connector
#define ADL_STEREO_ACTIVE (1 << 1)
/// This value indicates that the workstation card supports auto-stereo monitors with horizontal interleave. This is also used to set the stereo mode to use the auto-stereo monitor with horizontal interleave
#define ADL_STEREO_AUTO_HORIZONTAL (1 << 30)
/// This value indicates that the workstation card supports auto-stereo monitors with vertical interleave. This is also used to set the stereo mode to use the auto-stereo monitor with vertical interleave
#define ADL_STEREO_AUTO_VERTICAL (1 << 31)
/// This value indicates that the workstation card supports passive stereo, ie. non stereo sync
#define ADL_STEREO_PASSIVE (1 << 6)
/// This value indicates that the workstation card supports auto-stereo monitors with vertical interleave. This is also used to set the stereo mode to use the auto-stereo monitor with vertical interleave
#define ADL_STEREO_PASSIVE_HORIZ (1 << 7)
/// This value indicates that the workstation card supports auto-stereo monitors with vertical interleave. This is also used to set the stereo mode to use the auto-stereo monitor with vertical interleave
#define ADL_STEREO_PASSIVE_VERT (1 << 8)
/// This value indicates that the workstation card supports auto-stereo monitors with Samsung.
#define ADL_STEREO_AUTO_SAMSUNG (1 << 11)
/// This value indicates that the workstation card supports auto-stereo monitors with Tridility.
#define ADL_STEREO_AUTO_TSL (1 << 12)
/// This value indicates that the workstation card supports DeepBitDepth (10 bpp)
#define ADL_DEEPBITDEPTH_10BPP_SUPPORTED (1 << 5)
/// This value indicates that the workstation supports 8-Bit Grayscale
#define ADL_8BIT_GREYSCALE_SUPPORTED (1 << 9)
/// This value indicates that the workstation supports CUSTOM TIMING
#define ADL_CUSTOM_TIMING_SUPPORTED (1 << 10)
/// Load balancing is supported.
#define ADL_WORKSTATION_LOADBALANCING_SUPPORTED 0x00000001
/// Load balancing is available.
#define ADL_WORKSTATION_LOADBALANCING_AVAILABLE 0x00000002
/// Load balancing is disabled.
#define ADL_WORKSTATION_LOADBALANCING_DISABLED 0x00000000
/// Load balancing is Enabled.
#define ADL_WORKSTATION_LOADBALANCING_ENABLED 0x00000001
/// @}
/// \defgroup define_adapterspeed speed setting from the adapter
/// @{
#define ADL_CONTEXT_SPEED_UNFORCED 0 /* default asic running speed */
#define ADL_CONTEXT_SPEED_FORCEHIGH 1 /* asic running speed is forced to high */
#define ADL_CONTEXT_SPEED_FORCELOW 2 /* asic running speed is forced to low */
#define ADL_ADAPTER_SPEEDCAPS_SUPPORTED (1 << 0) /* change asic running speed setting is supported */
/// @}
/// \defgroup define_glsync Genlock related values
/// GL-Sync port types (unique values)
/// @{
/// Unknown port of GL-Sync module
#define ADL_GLSYNC_PORT_UNKNOWN 0
/// BNC port of of GL-Sync module
#define ADL_GLSYNC_PORT_BNC 1
/// RJ45(1) port of of GL-Sync module
#define ADL_GLSYNC_PORT_RJ45PORT1 2
/// RJ45(2) port of of GL-Sync module
#define ADL_GLSYNC_PORT_RJ45PORT2 3
// GL-Sync Genlock settings mask (bit-vector)
/// None of the ADLGLSyncGenlockConfig members are valid
#define ADL_GLSYNC_CONFIGMASK_NONE 0
/// The ADLGLSyncGenlockConfig.lSignalSource member is valid
#define ADL_GLSYNC_CONFIGMASK_SIGNALSOURCE (1 << 0)
/// The ADLGLSyncGenlockConfig.iSyncField member is valid
#define ADL_GLSYNC_CONFIGMASK_SYNCFIELD (1 << 1)
/// The ADLGLSyncGenlockConfig.iSampleRate member is valid
#define ADL_GLSYNC_CONFIGMASK_SAMPLERATE (1 << 2)
/// The ADLGLSyncGenlockConfig.lSyncDelay member is valid
#define ADL_GLSYNC_CONFIGMASK_SYNCDELAY (1 << 3)
/// The ADLGLSyncGenlockConfig.iTriggerEdge member is valid
#define ADL_GLSYNC_CONFIGMASK_TRIGGEREDGE (1 << 4)
/// The ADLGLSyncGenlockConfig.iScanRateCoeff member is valid
#define ADL_GLSYNC_CONFIGMASK_SCANRATECOEFF (1 << 5)
/// The ADLGLSyncGenlockConfig.lFramelockCntlVector member is valid
#define ADL_GLSYNC_CONFIGMASK_FRAMELOCKCNTL (1 << 6)
// GL-Sync Framelock control mask (bit-vector)
/// Framelock is disabled
#define ADL_GLSYNC_FRAMELOCKCNTL_NONE 0
/// Framelock is enabled
#define ADL_GLSYNC_FRAMELOCKCNTL_ENABLE ( 1 << 0)
#define ADL_GLSYNC_FRAMELOCKCNTL_DISABLE ( 1 << 1)
#define ADL_GLSYNC_FRAMELOCKCNTL_SWAP_COUNTER_RESET ( 1 << 2)
#define ADL_GLSYNC_FRAMELOCKCNTL_SWAP_COUNTER_ACK ( 1 << 3)
#define ADL_GLSYNC_FRAMELOCKCNTL_VERSION_KMD (1 << 4)
#define ADL_GLSYNC_FRAMELOCKCNTL_STATE_ENABLE ( 1 << 0)
#define ADL_GLSYNC_FRAMELOCKCNTL_STATE_KMD (1 << 4)
// GL-Sync Framelock counters mask (bit-vector)
#define ADL_GLSYNC_COUNTER_SWAP ( 1 << 0 )
// GL-Sync Signal Sources (unique values)
/// GL-Sync signal source is undefined
#define ADL_GLSYNC_SIGNALSOURCE_UNDEFINED 0x00000100
/// GL-Sync signal source is Free Run
#define ADL_GLSYNC_SIGNALSOURCE_FREERUN 0x00000101
/// GL-Sync signal source is the BNC GL-Sync port
#define ADL_GLSYNC_SIGNALSOURCE_BNCPORT 0x00000102
/// GL-Sync signal source is the RJ45(1) GL-Sync port
#define ADL_GLSYNC_SIGNALSOURCE_RJ45PORT1 0x00000103
/// GL-Sync signal source is the RJ45(2) GL-Sync port
#define ADL_GLSYNC_SIGNALSOURCE_RJ45PORT2 0x00000104
// GL-Sync Signal Types (unique values)
/// GL-Sync signal type is unknown
#define ADL_GLSYNC_SIGNALTYPE_UNDEFINED 0
/// GL-Sync signal type is 480I
#define ADL_GLSYNC_SIGNALTYPE_480I 1
/// GL-Sync signal type is 576I
#define ADL_GLSYNC_SIGNALTYPE_576I 2
/// GL-Sync signal type is 480P
#define ADL_GLSYNC_SIGNALTYPE_480P 3
/// GL-Sync signal type is 576P
#define ADL_GLSYNC_SIGNALTYPE_576P 4
/// GL-Sync signal type is 720P
#define ADL_GLSYNC_SIGNALTYPE_720P 5
/// GL-Sync signal type is 1080P
#define ADL_GLSYNC_SIGNALTYPE_1080P 6
/// GL-Sync signal type is 1080I
#define ADL_GLSYNC_SIGNALTYPE_1080I 7
/// GL-Sync signal type is SDI
#define ADL_GLSYNC_SIGNALTYPE_SDI 8
/// GL-Sync signal type is TTL
#define ADL_GLSYNC_SIGNALTYPE_TTL 9
/// GL_Sync signal type is Analog
#define ADL_GLSYNC_SIGNALTYPE_ANALOG 10
// GL-Sync Sync Field options (unique values)
///GL-Sync sync field option is undefined
#define ADL_GLSYNC_SYNCFIELD_UNDEFINED 0
///GL-Sync sync field option is Sync to Field 1 (used for Interlaced signal types)
#define ADL_GLSYNC_SYNCFIELD_BOTH 1
///GL-Sync sync field option is Sync to Both fields (used for Interlaced signal types)
#define ADL_GLSYNC_SYNCFIELD_1 2
// GL-Sync trigger edge options (unique values)
/// GL-Sync trigger edge is undefined
#define ADL_GLSYNC_TRIGGEREDGE_UNDEFINED 0
/// GL-Sync trigger edge is the rising edge
#define ADL_GLSYNC_TRIGGEREDGE_RISING 1
/// GL-Sync trigger edge is the falling edge
#define ADL_GLSYNC_TRIGGEREDGE_FALLING 2
/// GL-Sync trigger edge is both the rising and the falling edge
#define ADL_GLSYNC_TRIGGEREDGE_BOTH 3
// GL-Sync scan rate coefficient/multiplier options (unique values)
/// GL-Sync scan rate coefficient/multiplier is undefined
#define ADL_GLSYNC_SCANRATECOEFF_UNDEFINED 0
/// GL-Sync scan rate coefficient/multiplier is 5
#define ADL_GLSYNC_SCANRATECOEFF_x5 1
/// GL-Sync scan rate coefficient/multiplier is 4
#define ADL_GLSYNC_SCANRATECOEFF_x4 2
/// GL-Sync scan rate coefficient/multiplier is 3
#define ADL_GLSYNC_SCANRATECOEFF_x3 3
/// GL-Sync scan rate coefficient/multiplier is 5:2 (SMPTE)
#define ADL_GLSYNC_SCANRATECOEFF_x5_DIV_2 4
/// GL-Sync scan rate coefficient/multiplier is 2
#define ADL_GLSYNC_SCANRATECOEFF_x2 5
/// GL-Sync scan rate coefficient/multiplier is 3 : 2
#define ADL_GLSYNC_SCANRATECOEFF_x3_DIV_2 6
/// GL-Sync scan rate coefficient/multiplier is 5 : 4
#define ADL_GLSYNC_SCANRATECOEFF_x5_DIV_4 7
/// GL-Sync scan rate coefficient/multiplier is 1 (default)
#define ADL_GLSYNC_SCANRATECOEFF_x1 8
/// GL-Sync scan rate coefficient/multiplier is 4 : 5
#define ADL_GLSYNC_SCANRATECOEFF_x4_DIV_5 9
/// GL-Sync scan rate coefficient/multiplier is 2 : 3
#define ADL_GLSYNC_SCANRATECOEFF_x2_DIV_3 10
/// GL-Sync scan rate coefficient/multiplier is 1 : 2
#define ADL_GLSYNC_SCANRATECOEFF_x1_DIV_2 11
/// GL-Sync scan rate coefficient/multiplier is 2 : 5 (SMPTE)
#define ADL_GLSYNC_SCANRATECOEFF_x2_DIV_5 12
/// GL-Sync scan rate coefficient/multiplier is 1 : 3
#define ADL_GLSYNC_SCANRATECOEFF_x1_DIV_3 13
/// GL-Sync scan rate coefficient/multiplier is 1 : 4
#define ADL_GLSYNC_SCANRATECOEFF_x1_DIV_4 14
/// GL-Sync scan rate coefficient/multiplier is 1 : 5
#define ADL_GLSYNC_SCANRATECOEFF_x1_DIV_5 15
// GL-Sync port (signal presence) states (unique values)
/// GL-Sync port state is undefined
#define ADL_GLSYNC_PORTSTATE_UNDEFINED 0
/// GL-Sync port is not connected
#define ADL_GLSYNC_PORTSTATE_NOCABLE 1
/// GL-Sync port is Idle
#define ADL_GLSYNC_PORTSTATE_IDLE 2
/// GL-Sync port has an Input signal
#define ADL_GLSYNC_PORTSTATE_INPUT 3
/// GL-Sync port is Output
#define ADL_GLSYNC_PORTSTATE_OUTPUT 4
// GL-Sync LED types (used index within ADL_Workstation_GLSyncPortState_Get returned ppGlSyncLEDs array) (unique values)
/// Index into the ADL_Workstation_GLSyncPortState_Get returned ppGlSyncLEDs array for the one LED of the BNC port
#define ADL_GLSYNC_LEDTYPE_BNC 0
/// Index into the ADL_Workstation_GLSyncPortState_Get returned ppGlSyncLEDs array for the Left LED of the RJ45(1) or RJ45(2) port
#define ADL_GLSYNC_LEDTYPE_RJ45_LEFT 0
/// Index into the ADL_Workstation_GLSyncPortState_Get returned ppGlSyncLEDs array for the Right LED of the RJ45(1) or RJ45(2) port
#define ADL_GLSYNC_LEDTYPE_RJ45_RIGHT 1
// GL-Sync LED colors (unique values)
/// GL-Sync LED undefined color
#define ADL_GLSYNC_LEDCOLOR_UNDEFINED 0
/// GL-Sync LED is unlit
#define ADL_GLSYNC_LEDCOLOR_NOLIGHT 1
/// GL-Sync LED is yellow
#define ADL_GLSYNC_LEDCOLOR_YELLOW 2
/// GL-Sync LED is red
#define ADL_GLSYNC_LEDCOLOR_RED 3
/// GL-Sync LED is green
#define ADL_GLSYNC_LEDCOLOR_GREEN 4
/// GL-Sync LED is flashing green
#define ADL_GLSYNC_LEDCOLOR_FLASH_GREEN 5
// GL-Sync Port Control (refers one GL-Sync Port) (unique values)
/// Used to configure the RJ54(1) or RJ42(2) port of GL-Sync is as Idle
#define ADL_GLSYNC_PORTCNTL_NONE 0x00000000
/// Used to configure the RJ54(1) or RJ42(2) port of GL-Sync is as Output
#define ADL_GLSYNC_PORTCNTL_OUTPUT 0x00000001
// GL-Sync Mode Control (refers one Display/Controller) (bitfields)
/// Used to configure the display to use internal timing (not genlocked)
#define ADL_GLSYNC_MODECNTL_NONE 0x00000000
/// Bitfield used to configure the display as genlocked (either as Timing Client or as Timing Server)
#define ADL_GLSYNC_MODECNTL_GENLOCK 0x00000001
/// Bitfield used to configure the display as Timing Server
#define ADL_GLSYNC_MODECNTL_TIMINGSERVER 0x00000002
// GL-Sync Mode Status
/// Display is currently not genlocked
#define ADL_GLSYNC_MODECNTL_STATUS_NONE 0x00000000
/// Display is currently genlocked
#define ADL_GLSYNC_MODECNTL_STATUS_GENLOCK 0x00000001
/// Display requires a mode switch
#define ADL_GLSYNC_MODECNTL_STATUS_SETMODE_REQUIRED 0x00000002
/// Display is capable of being genlocked
#define ADL_GLSYNC_MODECNTL_STATUS_GENLOCK_ALLOWED 0x00000004
#define ADL_MAX_GLSYNC_PORTS 8
#define ADL_MAX_GLSYNC_PORT_LEDS 8
/// @}
/// \defgroup define_crossfirestate CrossfireX state of a particular adapter CrossfireX combination
/// @{
#define ADL_XFIREX_STATE_NOINTERCONNECT ( 1 << 0 ) /* Dongle / cable is missing */
#define ADL_XFIREX_STATE_DOWNGRADEPIPES ( 1 << 1 ) /* CrossfireX can be enabled if pipes are downgraded */
#define ADL_XFIREX_STATE_DOWNGRADEMEM ( 1 << 2 ) /* CrossfireX cannot be enabled unless mem downgraded */
#define ADL_XFIREX_STATE_REVERSERECOMMENDED ( 1 << 3 ) /* Card reversal recommended, CrossfireX cannot be enabled. */
#define ADL_XFIREX_STATE_3DACTIVE ( 1 << 4 ) /* 3D client is active - CrossfireX cannot be safely enabled */
#define ADL_XFIREX_STATE_MASTERONSLAVE ( 1 << 5 ) /* Dongle is OK but master is on slave */
#define ADL_XFIREX_STATE_NODISPLAYCONNECT ( 1 << 6 ) /* No (valid) display connected to master card. */
#define ADL_XFIREX_STATE_NOPRIMARYVIEW ( 1 << 7 ) /* CrossfireX is enabled but master is not current primary device */
#define ADL_XFIREX_STATE_DOWNGRADEVISMEM ( 1 << 8 ) /* CrossfireX cannot be enabled unless visible mem downgraded */
#define ADL_XFIREX_STATE_LESSTHAN8LANE_MASTER ( 1 << 9 ) /* CrossfireX can be enabled however performance not optimal due to <8 lanes */
#define ADL_XFIREX_STATE_LESSTHAN8LANE_SLAVE ( 1 << 10 ) /* CrossfireX can be enabled however performance not optimal due to <8 lanes */
#define ADL_XFIREX_STATE_PEERTOPEERFAILED ( 1 << 11 ) /* CrossfireX cannot be enabled due to failed peer to peer test */
#define ADL_XFIREX_STATE_MEMISDOWNGRADED ( 1 << 16 ) /* Notification that memory is currently downgraded */
#define ADL_XFIREX_STATE_PIPESDOWNGRADED ( 1 << 17 ) /* Notification that pipes are currently downgraded */
#define ADL_XFIREX_STATE_XFIREXACTIVE ( 1 << 18 ) /* CrossfireX is enabled on current device */
#define ADL_XFIREX_STATE_VISMEMISDOWNGRADED ( 1 << 19 ) /* Notification that visible FB memory is currently downgraded */
#define ADL_XFIREX_STATE_INVALIDINTERCONNECTION ( 1 << 20 ) /* Cannot support current inter-connection configuration */
#define ADL_XFIREX_STATE_NONP2PMODE ( 1 << 21 ) /* CrossfireX will only work with clients supporting non P2P mode */
#define ADL_XFIREX_STATE_DOWNGRADEMEMBANKS ( 1 << 22 ) /* CrossfireX cannot be enabled unless memory banks downgraded */
#define ADL_XFIREX_STATE_MEMBANKSDOWNGRADED ( 1 << 23 ) /* Notification that memory banks are currently downgraded */
#define ADL_XFIREX_STATE_DUALDISPLAYSALLOWED ( 1 << 24 ) /* Extended desktop or clone mode is allowed. */
#define ADL_XFIREX_STATE_P2P_APERTURE_MAPPING ( 1 << 25 ) /* P2P mapping was through peer aperture */
#define ADL_XFIREX_STATE_P2PFLUSH_REQUIRED ADL_XFIREX_STATE_P2P_APERTURE_MAPPING /* For back compatible */
#define ADL_XFIREX_STATE_XSP_CONNECTED ( 1 << 26 ) /* There is CrossfireX side port connection between GPUs */
#define ADL_XFIREX_STATE_ENABLE_CF_REBOOT_REQUIRED ( 1 << 27 ) /* System needs a reboot bofore enable CrossfireX */
#define ADL_XFIREX_STATE_DISABLE_CF_REBOOT_REQUIRED ( 1 << 28 ) /* System needs a reboot after disable CrossfireX */
#define ADL_XFIREX_STATE_DRV_HANDLE_DOWNGRADE_KEY ( 1 << 29 ) /* Indicate base driver handles the downgrade key updating */
#define ADL_XFIREX_STATE_CF_RECONFIG_REQUIRED ( 1 << 30 ) /* CrossfireX need to be reconfigured by CCC because of a LDA chain broken */
#define ADL_XFIREX_STATE_ERRORGETTINGSTATUS ( 1 << 31 ) /* Could not obtain current status */
/// @}
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_ADJUSTMENT_PIXELFORMAT adjustment values
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
/// \defgroup define_pixel_formats Pixel Formats values
/// This group defines the various Pixel Formats that a particular digital display can support. \n
/// Since a display can support multiple formats, these values can be bit-or'ed to indicate the various formats \n
/// @{
#define ADL_DISPLAY_PIXELFORMAT_UNKNOWN 0
#define ADL_DISPLAY_PIXELFORMAT_RGB (1 << 0)
#define ADL_DISPLAY_PIXELFORMAT_YCRCB444 (1 << 1) //Limited range
#define ADL_DISPLAY_PIXELFORMAT_YCRCB422 (1 << 2) //Limited range
#define ADL_DISPLAY_PIXELFORMAT_RGB_LIMITED_RANGE (1 << 3)
#define ADL_DISPLAY_PIXELFORMAT_RGB_FULL_RANGE ADL_DISPLAY_PIXELFORMAT_RGB //Full range
#define ADL_DISPLAY_PIXELFORMAT_YCRCB420 (1 << 4)
/// @}
/// \defgroup define_contype Connector Type Values
/// ADLDisplayConfig.ulConnectorType defines
/// @{
#define ADL_DL_DISPLAYCONFIG_CONTYPE_UNKNOWN 0
#define ADL_DL_DISPLAYCONFIG_CONTYPE_CV_NONI2C_JP 1
#define ADL_DL_DISPLAYCONFIG_CONTYPE_CV_JPN 2
#define ADL_DL_DISPLAYCONFIG_CONTYPE_CV_NA 3
#define ADL_DL_DISPLAYCONFIG_CONTYPE_CV_NONI2C_NA 4
#define ADL_DL_DISPLAYCONFIG_CONTYPE_VGA 5
#define ADL_DL_DISPLAYCONFIG_CONTYPE_DVI_D 6
#define ADL_DL_DISPLAYCONFIG_CONTYPE_DVI_I 7
#define ADL_DL_DISPLAYCONFIG_CONTYPE_HDMI_TYPE_A 8
#define ADL_DL_DISPLAYCONFIG_CONTYPE_HDMI_TYPE_B 9
#define ADL_DL_DISPLAYCONFIG_CONTYPE_DISPLAYPORT 10
/// @}
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_DISPLAYINFO_ Definitions
// for ADLDisplayInfo.iDisplayInfoMask and ADLDisplayInfo.iDisplayInfoValue
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
/// \defgroup define_displayinfomask Display Info Mask Values
/// @{
#define ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED 0x00000001
#define ADL_DISPLAY_DISPLAYINFO_DISPLAYMAPPED 0x00000002
#define ADL_DISPLAY_DISPLAYINFO_NONLOCAL 0x00000004
#define ADL_DISPLAY_DISPLAYINFO_FORCIBLESUPPORTED 0x00000008
#define ADL_DISPLAY_DISPLAYINFO_GENLOCKSUPPORTED 0x00000010
#define ADL_DISPLAY_DISPLAYINFO_MULTIVPU_SUPPORTED 0x00000020
#define ADL_DISPLAY_DISPLAYINFO_LDA_DISPLAY 0x00000040
#define ADL_DISPLAY_DISPLAYINFO_MODETIMING_OVERRIDESSUPPORTED 0x00000080
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_SINGLE 0x00000100
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_CLONE 0x00000200
/// Legacy support for XP
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_2VSTRETCH 0x00000400
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_2HSTRETCH 0x00000800
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_EXTENDED 0x00001000
/// More support manners
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_NSTRETCH1GPU 0x00010000
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_NSTRETCHNGPU 0x00020000
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_RESERVED2 0x00040000
#define ADL_DISPLAY_DISPLAYINFO_MANNER_SUPPORTED_RESERVED3 0x00080000
/// Projector display type
#define ADL_DISPLAY_DISPLAYINFO_SHOWTYPE_PROJECTOR 0x00100000
/// @}
///////////////////////////////////////////////////////////////////////////
// ADL_ADAPTER_DISPLAY_MANNER_SUPPORTED_ Definitions
// for ADLAdapterDisplayCap of ADL_Adapter_Display_Cap()
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
/// \defgroup define_adaptermanner Adapter Manner Support Values
/// @{
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_NOTACTIVE 0x00000001
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_SINGLE 0x00000002
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_CLONE 0x00000004
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_NSTRETCH1GPU 0x00000008
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_NSTRETCHNGPU 0x00000010
/// Legacy support for XP
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_2VSTRETCH 0x00000020
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_2HSTRETCH 0x00000040
#define ADL_ADAPTER_DISPLAYCAP_MANNER_SUPPORTED_EXTENDED 0x00000080
#define ADL_ADAPTER_DISPLAYCAP_PREFERDISPLAY_SUPPORTED 0x00000100
#define ADL_ADAPTER_DISPLAYCAP_BEZEL_SUPPORTED 0x00000200
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_DISPLAYMAP_MANNER_ Definitions
// for ADLDisplayMap.iDisplayMapMask and ADLDisplayMap.iDisplayMapValue
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
#define ADL_DISPLAY_DISPLAYMAP_MANNER_RESERVED 0x00000001
#define ADL_DISPLAY_DISPLAYMAP_MANNER_NOTACTIVE 0x00000002
#define ADL_DISPLAY_DISPLAYMAP_MANNER_SINGLE 0x00000004
#define ADL_DISPLAY_DISPLAYMAP_MANNER_CLONE 0x00000008
#define ADL_DISPLAY_DISPLAYMAP_MANNER_RESERVED1 0x00000010 // Removed NSTRETCH
#define ADL_DISPLAY_DISPLAYMAP_MANNER_HSTRETCH 0x00000020
#define ADL_DISPLAY_DISPLAYMAP_MANNER_VSTRETCH 0x00000040
#define ADL_DISPLAY_DISPLAYMAP_MANNER_VLD 0x00000080
/// @}
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_DISPLAYMAP_OPTION_ Definitions
// for iOption in function ADL_Display_DisplayMapConfig_Get
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
#define ADL_DISPLAY_DISPLAYMAP_OPTION_GPUINFO 0x00000001
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_DISPLAYTARGET_ Definitions
// for ADLDisplayTarget.iDisplayTargetMask and ADLDisplayTarget.iDisplayTargetValue
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
#define ADL_DISPLAY_DISPLAYTARGET_PREFERRED 0x00000001
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_POSSIBLEMAPRESULT_VALID Definitions
// for ADLPossibleMapResult.iPossibleMapResultMask and ADLPossibleMapResult.iPossibleMapResultValue
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
#define ADL_DISPLAY_POSSIBLEMAPRESULT_VALID 0x00000001
#define ADL_DISPLAY_POSSIBLEMAPRESULT_BEZELSUPPORTED 0x00000002
#define ADL_DISPLAY_POSSIBLEMAPRESULT_OVERLAPSUPPORTED 0x00000004
///////////////////////////////////////////////////////////////////////////
// ADL_DISPLAY_MODE_ Definitions
// for ADLMode.iModeMask, ADLMode.iModeValue, and ADLMode.iModeFlag
// (bit-vector)
///////////////////////////////////////////////////////////////////////////
/// \defgroup define_displaymode Display Mode Values
/// @{
#define ADL_DISPLAY_MODE_COLOURFORMAT_565 0x00000001
#define ADL_DISPLAY_MODE_COLOURFORMAT_8888 0x00000002
#define ADL_DISPLAY_MODE_ORIENTATION_SUPPORTED_000 0x00000004
#define ADL_DISPLAY_MODE_ORIENTATION_SUPPORTED_090 0x00000008
#define ADL_DISPLAY_MODE_ORIENTATION_SUPPORTED_180 0x00000010
#define ADL_DISPLAY_MODE_ORIENTATION_SUPPORTED_270 0x00000020
#define ADL_DISPLAY_MODE_REFRESHRATE_ROUNDED 0x00000040
#define ADL_DISPLAY_MODE_REFRESHRATE_ONLY 0x00000080
#define ADL_DISPLAY_MODE_PROGRESSIVE_FLAG 0
#define ADL_DISPLAY_MODE_INTERLACED_FLAG 2
/// @}
///////////////////////////////////////////////////////////////////////////
// ADL_OSMODEINFO Definitions
///////////////////////////////////////////////////////////////////////////
/// \defgroup define_osmode OS Mode Values
/// @{
#define ADL_OSMODEINFOXPOS_DEFAULT -640
#define ADL_OSMODEINFOYPOS_DEFAULT 0
#define ADL_OSMODEINFOXRES_DEFAULT 640
#define ADL_OSMODEINFOYRES_DEFAULT 480
#define ADL_OSMODEINFOXRES_DEFAULT800 800
#define ADL_OSMODEINFOYRES_DEFAULT600 600
#define ADL_OSMODEINFOREFRESHRATE_DEFAULT 60
#define ADL_OSMODEINFOCOLOURDEPTH_DEFAULT 8
#define ADL_OSMODEINFOCOLOURDEPTH_DEFAULT16 16
#define ADL_OSMODEINFOCOLOURDEPTH_DEFAULT24 24
#define ADL_OSMODEINFOCOLOURDEPTH_DEFAULT32 32
#define ADL_OSMODEINFOORIENTATION_DEFAULT 0
#define ADL_OSMODEINFOORIENTATION_DEFAULT_WIN7 DISPLAYCONFIG_ROTATION_FORCE_UINT32
#define ADL_OSMODEFLAG_DEFAULT 0
/// @}
///////////////////////////////////////////////////////////////////////////
// ADLThreadingModel Enumeration
///////////////////////////////////////////////////////////////////////////
/// \defgroup thread_model
/// Used with \ref ADL_Main_ControlX2_Create and \ref ADL2_Main_ControlX2_Create to specify how ADL handles API calls when executed by multiple threads concurrently.
/// \brief Declares ADL threading behavior.
/// @{
typedef enum ADLThreadingModel
{
ADL_THREADING_UNLOCKED = 0, /*!< Default behavior. ADL will not enforce serialization of ADL API executions by multiple threads. Multiple threads will be allowed to enter to ADL at the same time. Note that ADL library is not guaranteed to be thread-safe. Client that calls ADL_Main_Control_Create have to provide its own mechanism for ADL calls serialization. */
ADL_THREADING_LOCKED /*!< ADL will enforce serialization of ADL API when called by multiple threads. Only single thread will be allowed to enter ADL API at the time. This option makes ADL calls thread-safe. You shouldn't use this option if ADL calls will be executed on Linux on x-server rendering thread. It can cause the application to hung. */
}ADLThreadingModel;
/// @}
///////////////////////////////////////////////////////////////////////////
// ADLPurposeCode Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLPurposeCode
{
ADL_PURPOSECODE_NORMAL = 0,
ADL_PURPOSECODE_HIDE_MODE_SWITCH,
ADL_PURPOSECODE_MODE_SWITCH,
ADL_PURPOSECODE_ATTATCH_DEVICE,
ADL_PURPOSECODE_DETACH_DEVICE,
ADL_PURPOSECODE_SETPRIMARY_DEVICE,
ADL_PURPOSECODE_GDI_ROTATION,
ADL_PURPOSECODE_ATI_ROTATION
};
///////////////////////////////////////////////////////////////////////////
// ADLAngle Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLAngle
{
ADL_ANGLE_LANDSCAPE = 0,
ADL_ANGLE_ROTATERIGHT = 90,
ADL_ANGLE_ROTATE180 = 180,
ADL_ANGLE_ROTATELEFT = 270,
};
///////////////////////////////////////////////////////////////////////////
// ADLOrientationDataType Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLOrientationDataType
{
ADL_ORIENTATIONTYPE_OSDATATYPE,
ADL_ORIENTATIONTYPE_NONOSDATATYPE
};
///////////////////////////////////////////////////////////////////////////
// ADLPanningMode Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLPanningMode
{
ADL_PANNINGMODE_NO_PANNING = 0,
ADL_PANNINGMODE_AT_LEAST_ONE_NO_PANNING = 1,
ADL_PANNINGMODE_ALLOW_PANNING = 2,
};
///////////////////////////////////////////////////////////////////////////
// ADLLARGEDESKTOPTYPE Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLLARGEDESKTOPTYPE
{
ADL_LARGEDESKTOPTYPE_NORMALDESKTOP = 0,
ADL_LARGEDESKTOPTYPE_PSEUDOLARGEDESKTOP = 1,
ADL_LARGEDESKTOPTYPE_VERYLARGEDESKTOP = 2
};
///////////////////////////////////////////////////////////////////////////
// ADLPlatform Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLPlatForm
{
GRAPHICS_PLATFORM_DESKTOP = 0,
GRAPHICS_PLATFORM_MOBILE = 1
};
///////////////////////////////////////////////////////////////////////////
// ADLGraphicCoreGeneration Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLGraphicCoreGeneration
{
ADL_GRAPHIC_CORE_GENERATION_UNDEFINED = 0,
ADL_GRAPHIC_CORE_GENERATION_PRE_GCN = 1,
ADL_GRAPHIC_CORE_GENERATION_GCN = 2,
ADL_GRAPHIC_CORE_GENERATION_RDNA = 3
};
// Other Definitions for internal use
// Values for ADL_Display_WriteAndReadI2CRev_Get()
#define ADL_I2C_MAJOR_API_REV 0x00000001
#define ADL_I2C_MINOR_DEFAULT_API_REV 0x00000000
#define ADL_I2C_MINOR_OEM_API_REV 0x00000001
// Values for ADL_Display_WriteAndReadI2C()
#define ADL_DL_I2C_LINE_OEM 0x00000001
#define ADL_DL_I2C_LINE_OD_CONTROL 0x00000002
#define ADL_DL_I2C_LINE_OEM2 0x00000003
#define ADL_DL_I2C_LINE_OEM3 0x00000004
#define ADL_DL_I2C_LINE_OEM4 0x00000005
#define ADL_DL_I2C_LINE_OEM5 0x00000006
#define ADL_DL_I2C_LINE_OEM6 0x00000007
#define ADL_DL_I2C_LINE_GPIO 0x00000008
// Max size of I2C data buffer
#define ADL_DL_I2C_MAXDATASIZE 0x00000018
#define ADL_DL_I2C_MAXWRITEDATASIZE 0x0000000C
#define ADL_DL_I2C_MAXADDRESSLENGTH 0x00000006
#define ADL_DL_I2C_MAXOFFSETLENGTH 0x00000004
// I2C clock speed in KHz
#define ADL_DL_I2C_SPEED_50K 50
#define ADL_DL_I2C_SPEED_100K 100
#define ALD_DL_I2C_SPEED_400K 400
#define ADL_DL_I2C_SPEED_1M 1000
#define ADL_DL_I2C_SPEED_2M 2300
/// Values for ADLDisplayProperty.iPropertyType
#define ADL_DL_DISPLAYPROPERTY_TYPE_UNKNOWN 0
#define ADL_DL_DISPLAYPROPERTY_TYPE_EXPANSIONMODE 1
#define ADL_DL_DISPLAYPROPERTY_TYPE_USEUNDERSCANSCALING 2
/// Enables ITC processing for HDMI panels that are capable of the feature
#define ADL_DL_DISPLAYPROPERTY_TYPE_ITCFLAGENABLE 9
#define ADL_DL_DISPLAYPROPERTY_TYPE_DOWNSCALE 11
#define ADL_DL_DISPLAYPROPERTY_TYPE_INTEGER_SCALING 12
/// Values for ADLDisplayContent.iContentType
/// Certain HDMI panels that support ITC have support for a feature such that, the display on the panel
/// can be adjusted to optimize the view of the content being displayed, depending on the type of content.
#define ADL_DL_DISPLAYCONTENT_TYPE_GRAPHICS 1
#define ADL_DL_DISPLAYCONTENT_TYPE_PHOTO 2
#define ADL_DL_DISPLAYCONTENT_TYPE_CINEMA 4
#define ADL_DL_DISPLAYCONTENT_TYPE_GAME 8
//values for ADLDisplayProperty.iExpansionMode
#define ADL_DL_DISPLAYPROPERTY_EXPANSIONMODE_CENTER 0
#define ADL_DL_DISPLAYPROPERTY_EXPANSIONMODE_FULLSCREEN 1
#define ADL_DL_DISPLAYPROPERTY_EXPANSIONMODE_ASPECTRATIO 2
///\defgroup define_dither_states Dithering options
/// @{
/// Dithering disabled.
#define ADL_DL_DISPLAY_DITHER_DISABLED 0
/// Use default driver settings for dithering. Note that the default setting could be dithering disabled.
#define ADL_DL_DISPLAY_DITHER_DRIVER_DEFAULT 1
/// Temporal dithering to 6 bpc. Note that if the input is 12 bits, the two least significant bits will be truncated.
#define ADL_DL_DISPLAY_DITHER_FM6 2
/// Temporal dithering to 8 bpc.
#define ADL_DL_DISPLAY_DITHER_FM8 3
/// Temporal dithering to 10 bpc.
#define ADL_DL_DISPLAY_DITHER_FM10 4
/// Spatial dithering to 6 bpc. Note that if the input is 12 bits, the two least significant bits will be truncated.
#define ADL_DL_DISPLAY_DITHER_DITH6 5
/// Spatial dithering to 8 bpc.
#define ADL_DL_DISPLAY_DITHER_DITH8 6
/// Spatial dithering to 10 bpc.
#define ADL_DL_DISPLAY_DITHER_DITH10 7
/// Spatial dithering to 6 bpc. Random number generators are reset every frame, so the same input value of a certain pixel will always be dithered to the same output value. Note that if the input is 12 bits, the two least significant bits will be truncated.
#define ADL_DL_DISPLAY_DITHER_DITH6_NO_FRAME_RAND 8
/// Spatial dithering to 8 bpc. Random number generators are reset every frame, so the same input value of a certain pixel will always be dithered to the same output value.
#define ADL_DL_DISPLAY_DITHER_DITH8_NO_FRAME_RAND 9
/// Spatial dithering to 10 bpc. Random number generators are reset every frame, so the same input value of a certain pixel will always be dithered to the same output value.
#define ADL_DL_DISPLAY_DITHER_DITH10_NO_FRAME_RAND 10
/// Truncation to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN6 11
/// Truncation to 8 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN8 12
/// Truncation to 10 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN10 13
/// Truncation to 10 bpc followed by spatial dithering to 8 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN10_DITH8 14
/// Truncation to 10 bpc followed by spatial dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN10_DITH6 15
/// Truncation to 10 bpc followed by temporal dithering to 8 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN10_FM8 16
/// Truncation to 10 bpc followed by temporal dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN10_FM6 17
/// Truncation to 10 bpc followed by spatial dithering to 8 bpc and temporal dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN10_DITH8_FM6 18
/// Spatial dithering to 10 bpc followed by temporal dithering to 8 bpc.
#define ADL_DL_DISPLAY_DITHER_DITH10_FM8 19
/// Spatial dithering to 10 bpc followed by temporal dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_DITH10_FM6 20
/// Truncation to 8 bpc followed by spatial dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN8_DITH6 21
/// Truncation to 8 bpc followed by temporal dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_TRUN8_FM6 22
/// Spatial dithering to 8 bpc followed by temporal dithering to 6 bpc.
#define ADL_DL_DISPLAY_DITHER_DITH8_FM6 23
#define ADL_DL_DISPLAY_DITHER_LAST ADL_DL_DISPLAY_DITHER_DITH8_FM6
/// @}
/// Display Get Cached EDID flag
#define ADL_MAX_EDIDDATA_SIZE 256 // number of UCHAR
#define ADL_MAX_OVERRIDEEDID_SIZE 512 // number of UCHAR
#define ADL_MAX_EDID_EXTENSION_BLOCKS 3
#define ADL_DL_CONTROLLER_OVERLAY_ALPHA 0
#define ADL_DL_CONTROLLER_OVERLAY_ALPHAPERPIX 1
#define ADL_DL_DISPLAY_DATA_PACKET__INFO_PACKET_RESET 0x00000000
#define ADL_DL_DISPLAY_DATA_PACKET__INFO_PACKET_SET 0x00000001
#define ADL_DL_DISPLAY_DATA_PACKET__INFO_PACKET_SCAN 0x00000002
///\defgroup define_display_packet Display Data Packet Types
/// @{
#define ADL_DL_DISPLAY_DATA_PACKET__TYPE__AVI 0x00000001
#define ADL_DL_DISPLAY_DATA_PACKET__TYPE__GAMMUT 0x00000002
#define ADL_DL_DISPLAY_DATA_PACKET__TYPE__VENDORINFO 0x00000004
#define ADL_DL_DISPLAY_DATA_PACKET__TYPE__HDR 0x00000008
#define ADL_DL_DISPLAY_DATA_PACKET__TYPE__SPD 0x00000010
/// @}
// matrix types
#define ADL_GAMUT_MATRIX_SD 1 // SD matrix i.e. BT601
#define ADL_GAMUT_MATRIX_HD 2 // HD matrix i.e. BT709
///\defgroup define_clockinfo_flags Clock flags
/// Used by ADLAdapterODClockInfo.iFlag
/// @{
#define ADL_DL_CLOCKINFO_FLAG_FULLSCREEN3DONLY 0x00000001
#define ADL_DL_CLOCKINFO_FLAG_ALWAYSFULLSCREEN3D 0x00000002
#define ADL_DL_CLOCKINFO_FLAG_VPURECOVERYREDUCED 0x00000004
#define ADL_DL_CLOCKINFO_FLAG_THERMALPROTECTION 0x00000008
/// @}
// Supported GPUs
// ADL_Display_PowerXpressActiveGPU_Get()
#define ADL_DL_POWERXPRESS_GPU_INTEGRATED 1
#define ADL_DL_POWERXPRESS_GPU_DISCRETE 2
// Possible values for lpOperationResult
// ADL_Display_PowerXpressActiveGPU_Get()
#define ADL_DL_POWERXPRESS_SWITCH_RESULT_STARTED 1 // Switch procedure has been started - Windows platform only
#define ADL_DL_POWERXPRESS_SWITCH_RESULT_DECLINED 2 // Switch procedure cannot be started - All platforms
#define ADL_DL_POWERXPRESS_SWITCH_RESULT_ALREADY 3 // System already has required status - All platforms
#define ADL_DL_POWERXPRESS_SWITCH_RESULT_DEFERRED 5 // Switch was deferred and requires an X restart - Linux platform only
// PowerXpress support version
// ADL_Display_PowerXpressVersion_Get()
#define ADL_DL_POWERXPRESS_VERSION_MAJOR 2 // Current PowerXpress support version 2.0
#define ADL_DL_POWERXPRESS_VERSION_MINOR 0
#define ADL_DL_POWERXPRESS_VERSION (((ADL_DL_POWERXPRESS_VERSION_MAJOR) << 16) | ADL_DL_POWERXPRESS_VERSION_MINOR)
//values for ADLThermalControllerInfo.iThermalControllerDomain
#define ADL_DL_THERMAL_DOMAIN_OTHER 0
#define ADL_DL_THERMAL_DOMAIN_GPU 1
//values for ADLThermalControllerInfo.iFlags
#define ADL_DL_THERMAL_FLAG_INTERRUPT 1
#define ADL_DL_THERMAL_FLAG_FANCONTROL 2
///\defgroup define_fanctrl Fan speed cotrol
/// Values for ADLFanSpeedInfo.iFlags
/// @{
#define ADL_DL_FANCTRL_SUPPORTS_PERCENT_READ 1
#define ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE 2
#define ADL_DL_FANCTRL_SUPPORTS_RPM_READ 4
#define ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE 8
/// @}
//values for ADLFanSpeedValue.iSpeedType
#define ADL_DL_FANCTRL_SPEED_TYPE_PERCENT 1
#define ADL_DL_FANCTRL_SPEED_TYPE_RPM 2
//values for ADLFanSpeedValue.iFlags
#define ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED 1
// MVPU interfaces
#define ADL_DL_MAX_MVPU_ADAPTERS 4
#define MVPU_ADAPTER_0 0x00000001
#define MVPU_ADAPTER_1 0x00000002
#define MVPU_ADAPTER_2 0x00000004
#define MVPU_ADAPTER_3 0x00000008
#define ADL_DL_MAX_REGISTRY_PATH 256
//values for ADLMVPUStatus.iStatus
#define ADL_DL_MVPU_STATUS_OFF 0
#define ADL_DL_MVPU_STATUS_ON 1
// values for ASIC family
///\defgroup define_Asic_type Detailed asic types
/// Defines for Adapter ASIC family type
/// @{
#define ADL_ASIC_UNDEFINED 0
#define ADL_ASIC_DISCRETE (1 << 0)
#define ADL_ASIC_INTEGRATED (1 << 1)
#define ADL_ASIC_WORKSTATION (1 << 2)
#define ADL_ASIC_FIREMV (1 << 3)
#define ADL_ASIC_XGP (1 << 4)
#define ADL_ASIC_FUSION (1 << 5)
#define ADL_ASIC_FIRESTREAM (1 << 6)
#define ADL_ASIC_EMBEDDED (1 << 7)
// Backward compatibility
#define ADL_ASIC_FIREGL ADL_ASIC_WORKSTATION
/// @}
///\defgroup define_detailed_timing_flags Detailed Timimg Flags
/// Defines for ADLDetailedTiming.sTimingFlags field
/// @{
#define ADL_DL_TIMINGFLAG_DOUBLE_SCAN 0x0001
//sTimingFlags is set when the mode is INTERLACED, if not PROGRESSIVE
#define ADL_DL_TIMINGFLAG_INTERLACED 0x0002
//sTimingFlags is set when the Horizontal Sync is POSITIVE, if not NEGATIVE
#define ADL_DL_TIMINGFLAG_H_SYNC_POLARITY 0x0004
//sTimingFlags is set when the Vertical Sync is POSITIVE, if not NEGATIVE
#define ADL_DL_TIMINGFLAG_V_SYNC_POLARITY 0x0008
/// @}
///\defgroup define_modetiming_standard Timing Standards
/// Defines for ADLDisplayModeInfo.iTimingStandard field
/// @{
#define ADL_DL_MODETIMING_STANDARD_CVT 0x00000001 // CVT Standard
#define ADL_DL_MODETIMING_STANDARD_GTF 0x00000002 // GFT Standard
#define ADL_DL_MODETIMING_STANDARD_DMT 0x00000004 // DMT Standard
#define ADL_DL_MODETIMING_STANDARD_CUSTOM 0x00000008 // User-defined standard
#define ADL_DL_MODETIMING_STANDARD_DRIVER_DEFAULT 0x00000010 // Remove Mode from overriden list
#define ADL_DL_MODETIMING_STANDARD_CVT_RB 0x00000020 // CVT-RB Standard
/// @}
// \defgroup define_xserverinfo driver x-server info
/// These flags are used by ADL_XServerInfo_Get()
// @
/// Xinerama is active in the x-server, Xinerama extension may report it to be active but it
/// may not be active in x-server
#define ADL_XSERVERINFO_XINERAMAACTIVE (1<<0)
/// RandR 1.2 is supported by driver, RandR extension may report version 1.2
/// but driver may not support it
#define ADL_XSERVERINFO_RANDR12SUPPORTED (1<<1)
// @
///\defgroup define_eyefinity_constants Eyefinity Definitions
/// @{
#define ADL_CONTROLLERVECTOR_0 1 // ADL_CONTROLLERINDEX_0 = 0, (1 << ADL_CONTROLLERINDEX_0)
#define ADL_CONTROLLERVECTOR_1 2 // ADL_CONTROLLERINDEX_1 = 1, (1 << ADL_CONTROLLERINDEX_1)
#define ADL_DISPLAY_SLSGRID_ORIENTATION_000 0x00000001
#define ADL_DISPLAY_SLSGRID_ORIENTATION_090 0x00000002
#define ADL_DISPLAY_SLSGRID_ORIENTATION_180 0x00000004
#define ADL_DISPLAY_SLSGRID_ORIENTATION_270 0x00000008
#define ADL_DISPLAY_SLSGRID_CAP_OPTION_RELATIVETO_LANDSCAPE 0x00000001
#define ADL_DISPLAY_SLSGRID_CAP_OPTION_RELATIVETO_CURRENTANGLE 0x00000002
#define ADL_DISPLAY_SLSGRID_PORTAIT_MODE 0x00000004
#define ADL_DISPLAY_SLSGRID_KEEPTARGETROTATION 0x00000080
#define ADL_DISPLAY_SLSGRID_SAMEMODESLS_SUPPORT 0x00000010
#define ADL_DISPLAY_SLSGRID_MIXMODESLS_SUPPORT 0x00000020
#define ADL_DISPLAY_SLSGRID_DISPLAYROTATION_SUPPORT 0x00000040
#define ADL_DISPLAY_SLSGRID_DESKTOPROTATION_SUPPORT 0x00000080
#define ADL_DISPLAY_SLSMAP_SLSLAYOUTMODE_FIT 0x0100
#define ADL_DISPLAY_SLSMAP_SLSLAYOUTMODE_FILL 0x0200
#define ADL_DISPLAY_SLSMAP_SLSLAYOUTMODE_EXPAND 0x0400
#define ADL_DISPLAY_SLSMAP_IS_SLS 0x1000
#define ADL_DISPLAY_SLSMAP_IS_SLSBUILDER 0x2000
#define ADL_DISPLAY_SLSMAP_IS_CLONEVT 0x4000
#define ADL_DISPLAY_SLSMAPCONFIG_GET_OPTION_RELATIVETO_LANDSCAPE 0x00000001
#define ADL_DISPLAY_SLSMAPCONFIG_GET_OPTION_RELATIVETO_CURRENTANGLE 0x00000002
#define ADL_DISPLAY_SLSMAPCONFIG_CREATE_OPTION_RELATIVETO_LANDSCAPE 0x00000001
#define ADL_DISPLAY_SLSMAPCONFIG_CREATE_OPTION_RELATIVETO_CURRENTANGLE 0x00000002
#define ADL_DISPLAY_SLSMAPCONFIG_REARRANGE_OPTION_RELATIVETO_LANDSCAPE 0x00000001
#define ADL_DISPLAY_SLSMAPCONFIG_REARRANGE_OPTION_RELATIVETO_CURRENTANGLE 0x00000002
#define ADL_SLS_SAMEMODESLS_SUPPORT 0x0001
#define ADL_SLS_MIXMODESLS_SUPPORT 0x0002
#define ADL_SLS_DISPLAYROTATIONSLS_SUPPORT 0x0004
#define ADL_SLS_DESKTOPROTATIONSLS_SUPPORT 0x0008
#define ADL_SLS_TARGETS_INVALID 0x0001
#define ADL_SLS_MODES_INVALID 0x0002
#define ADL_SLS_ROTATIONS_INVALID 0x0004
#define ADL_SLS_POSITIONS_INVALID 0x0008
#define ADL_SLS_LAYOUTMODE_INVALID 0x0010
#define ADL_DISPLAY_SLSDISPLAYOFFSET_VALID 0x0002
#define ADL_DISPLAY_SLSGRID_RELATIVETO_LANDSCAPE 0x00000010
#define ADL_DISPLAY_SLSGRID_RELATIVETO_CURRENTANGLE 0x00000020
/// The bit mask identifies displays is currently in bezel mode.
#define ADL_DISPLAY_SLSMAP_BEZELMODE 0x00000010
/// The bit mask identifies displays from this map is arranged.
#define ADL_DISPLAY_SLSMAP_DISPLAYARRANGED 0x00000002
/// The bit mask identifies this map is currently in used for the current adapter.
#define ADL_DISPLAY_SLSMAP_CURRENTCONFIG 0x00000004
///For onlay active SLS map info
#define ADL_DISPLAY_SLSMAPINDEXLIST_OPTION_ACTIVE 0x00000001
///For Bezel
#define ADL_DISPLAY_BEZELOFFSET_STEPBYSTEPSET 0x00000004
#define ADL_DISPLAY_BEZELOFFSET_COMMIT 0x00000008
typedef enum SLS_ImageCropType {
Fit = 1,
Fill = 2,
Expand = 3
}SLS_ImageCropType;
typedef enum DceSettingsType {
DceSetting_HdmiLq,
DceSetting_DpSettings,
DceSetting_Protection
} DceSettingsType;
typedef enum DpLinkRate {
DPLinkRate_Unknown,
DPLinkRate_RBR,
DPLinkRate_2_16Gbps,
DPLinkRate_2_43Gbps,
DPLinkRate_HBR,
DPLinkRate_4_32Gbps,
DPLinkRate_HBR2,
DPLinkRate_HBR3,
DPLinkRate_UHBR10,
DPLinkRate_UHBR13D5,
DPLinkRate_UHBR20
} DpLinkRate;
/// @}
///\defgroup define_powerxpress_constants PowerXpress Definitions
/// @{
/// The bit mask identifies PX caps for ADLPXConfigCaps.iPXConfigCapMask and ADLPXConfigCaps.iPXConfigCapValue
#define ADL_PX_CONFIGCAPS_SPLASHSCREEN_SUPPORT 0x0001
#define ADL_PX_CONFIGCAPS_CF_SUPPORT 0x0002
#define ADL_PX_CONFIGCAPS_MUXLESS 0x0004
#define ADL_PX_CONFIGCAPS_PROFILE_COMPLIANT 0x0008
#define ADL_PX_CONFIGCAPS_NON_AMD_DRIVEN_DISPLAYS 0x0010
#define ADL_PX_CONFIGCAPS_FIXED_SUPPORT 0x0020
#define ADL_PX_CONFIGCAPS_DYNAMIC_SUPPORT 0x0040
#define ADL_PX_CONFIGCAPS_HIDE_AUTO_SWITCH 0x0080
/// The bit mask identifies PX schemes for ADLPXSchemeRange
#define ADL_PX_SCHEMEMASK_FIXED 0x0001
#define ADL_PX_SCHEMEMASK_DYNAMIC 0x0002
/// PX Schemes
typedef enum ADLPXScheme
{
ADL_PX_SCHEME_INVALID = 0,
ADL_PX_SCHEME_FIXED = ADL_PX_SCHEMEMASK_FIXED,
ADL_PX_SCHEME_DYNAMIC = ADL_PX_SCHEMEMASK_DYNAMIC
}ADLPXScheme;
/// Just keep the old definitions for compatibility, need to be removed later
typedef enum PXScheme
{
PX_SCHEME_INVALID = 0,
PX_SCHEME_FIXED = 1,
PX_SCHEME_DYNAMIC = 2
} PXScheme;
/// @}
///\defgroup define_appprofiles For Application Profiles
/// @{
#define ADL_APP_PROFILE_FILENAME_LENGTH 256
#define ADL_APP_PROFILE_TIMESTAMP_LENGTH 32
#define ADL_APP_PROFILE_VERSION_LENGTH 32
#define ADL_APP_PROFILE_PROPERTY_LENGTH 64
enum ApplicationListType
{
ADL_PX40_MRU,
ADL_PX40_MISSED,
ADL_PX40_DISCRETE,
ADL_PX40_INTEGRATED,
ADL_MMD_PROFILED,
ADL_PX40_TOTAL
};
typedef enum ADLProfilePropertyType
{
ADL_PROFILEPROPERTY_TYPE_BINARY = 0,
ADL_PROFILEPROPERTY_TYPE_BOOLEAN,
ADL_PROFILEPROPERTY_TYPE_DWORD,
ADL_PROFILEPROPERTY_TYPE_QWORD,
ADL_PROFILEPROPERTY_TYPE_ENUMERATED,
ADL_PROFILEPROPERTY_TYPE_STRING
}ADLProfilePropertyType;
//Virtual display type returning virtual display type and for request for creating a dummy target ID (xInput or remote play)
typedef enum ADL_VIRTUALDISPLAY_TYPE
{
ADL_VIRTUALDISPLAY_NONE = 0,
ADL_VIRTUALDISPLAY_XINPUT = 1, //Requested for xInput
ADL_VIRTUALDISPLAY_REMOTEPLAY = 2, //Requested for emulated display during remote play
ADL_VIRTUALDISPLAY_GENERIC = 10 //Generic virtual display, af a type different than any of the above special ones
}ADL_VIRTUALDISPLAY_TYPE;
/// @}
///\defgroup define_dp12 For Display Port 1.2
/// @{
/// Maximum Relative Address Link
#define ADL_MAX_RAD_LINK_COUNT 15
/// @}
///\defgroup defines_gamutspace Driver Supported Gamut Space
/// @{
/// The flags desribes that gamut is related to source or to destination and to overlay or to graphics
#define ADL_GAMUT_REFERENCE_SOURCE (1 << 0)
#define ADL_GAMUT_GAMUT_VIDEO_CONTENT (1 << 1)
/// The flags are used to describe the source of gamut and how read information from struct ADLGamutData
#define ADL_CUSTOM_WHITE_POINT (1 << 0)
#define ADL_CUSTOM_GAMUT (1 << 1)
#define ADL_GAMUT_REMAP_ONLY (1 << 2)
/// The define means the predefined gamut values .
///Driver uses to find entry in the table and apply appropriate gamut space.
#define ADL_GAMUT_SPACE_CCIR_709 (1 << 0)
#define ADL_GAMUT_SPACE_CCIR_601 (1 << 1)
#define ADL_GAMUT_SPACE_ADOBE_RGB (1 << 2)
#define ADL_GAMUT_SPACE_CIE_RGB (1 << 3)
#define ADL_GAMUT_SPACE_CUSTOM (1 << 4)
#define ADL_GAMUT_SPACE_CCIR_2020 (1 << 5)
#define ADL_GAMUT_SPACE_APPCTRL (1 << 6)
/// Predefine white point values are structed similar to gamut .
#define ADL_WHITE_POINT_5000K (1 << 0)
#define ADL_WHITE_POINT_6500K (1 << 1)
#define ADL_WHITE_POINT_7500K (1 << 2)
#define ADL_WHITE_POINT_9300K (1 << 3)
#define ADL_WHITE_POINT_CUSTOM (1 << 4)
///gamut and white point coordinates are from 0.0 -1.0 and divider is used to find the real value .
/// X float = X int /divider
#define ADL_GAMUT_WHITEPOINT_DIVIDER 10000
///gamma a0 coefficient uses the following divider:
#define ADL_REGAMMA_COEFFICIENT_A0_DIVIDER 10000000
///gamma a1 ,a2,a3 coefficients use the following divider:
#define ADL_REGAMMA_COEFFICIENT_A1A2A3_DIVIDER 1000
///describes whether the coefficients are from EDID or custom user values.
#define ADL_EDID_REGAMMA_COEFFICIENTS (1 << 0)
///Used for struct ADLRegamma. Feature if set use gamma ramp, if missing use regamma coefficents
#define ADL_USE_GAMMA_RAMP (1 << 4)
///Used for struct ADLRegamma. If the gamma ramp flag is used then the driver could apply de gamma corretion to the supplied curve and this depends on this flag
#define ADL_APPLY_DEGAMMA (1 << 5)
///specifies that standard SRGB gamma should be applied
#define ADL_EDID_REGAMMA_PREDEFINED_SRGB (1 << 1)
///specifies that PQ gamma curve should be applied
#define ADL_EDID_REGAMMA_PREDEFINED_PQ (1 << 2)
///specifies that PQ gamma curve should be applied, lower max nits
#define ADL_EDID_REGAMMA_PREDEFINED_PQ_2084_INTERIM (1 << 3)
///specifies that 3.6 gamma should be applied
#define ADL_EDID_REGAMMA_PREDEFINED_36 (1 << 6)
///specifies that BT709 gama should be applied
#define ADL_EDID_REGAMMA_PREDEFINED_BT709 (1 << 7)
///specifies that regamma should be disabled, and application controls regamma content (of the whole screen)
#define ADL_EDID_REGAMMA_PREDEFINED_APPCTRL (1 << 8)
/// @}
/// \defgroup define_ddcinfo_pixelformats DDCInfo Pixel Formats
/// @{
/// defines for iPanelPixelFormat in struct ADLDDCInfo2
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB656 0x00000001L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB666 0x00000002L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB888 0x00000004L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB101010 0x00000008L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB161616 0x00000010L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB_RESERVED1 0x00000020L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB_RESERVED2 0x00000040L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_RGB_RESERVED3 0x00000080L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_XRGB_BIAS101010 0x00000100L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR444_8BPCC 0x00000200L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR444_10BPCC 0x00000400L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR444_12BPCC 0x00000800L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR422_8BPCC 0x00001000L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR422_10BPCC 0x00002000L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR422_12BPCC 0x00004000L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR420_8BPCC 0x00008000L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR420_10BPCC 0x00010000L
#define ADL_DISPLAY_DDCINFO_PIXEL_FORMAT_YCBCR420_12BPCC 0x00020000L
/// @}
/// \defgroup define_source_content_TF ADLSourceContentAttributes transfer functions (gamma)
/// @{
/// defines for iTransferFunction in ADLSourceContentAttributes
#define ADL_TF_sRGB 0x0001 ///< sRGB
#define ADL_TF_BT709 0x0002 ///< BT.709
#define ADL_TF_PQ2084 0x0004 ///< PQ2084
#define ADL_TF_PQ2084_INTERIM 0x0008 ///< PQ2084-Interim
#define ADL_TF_LINEAR_0_1 0x0010 ///< Linear 0 - 1
#define ADL_TF_LINEAR_0_125 0x0020 ///< Linear 0 - 125
#define ADL_TF_DOLBYVISION 0x0040 ///< DolbyVision
#define ADL_TF_GAMMA_22 0x0080 ///< Plain 2.2 gamma curve
/// @}
/// \defgroup define_source_content_CS ADLSourceContentAttributes color spaces
/// @{
/// defines for iColorSpace in ADLSourceContentAttributes
#define ADL_CS_sRGB 0x0001 ///< sRGB
#define ADL_CS_BT601 0x0002 ///< BT.601
#define ADL_CS_BT709 0x0004 ///< BT.709
#define ADL_CS_BT2020 0x0008 ///< BT.2020
#define ADL_CS_ADOBE 0x0010 ///< Adobe RGB
#define ADL_CS_P3 0x0020 ///< DCI-P3
#define ADL_CS_scRGB_MS_REF 0x0040 ///< scRGB (MS Reference)
#define ADL_CS_DISPLAY_NATIVE 0x0080 ///< Display Native
#define ADL_CS_APP_CONTROL 0x0100 ///< Application Controlled
#define ADL_CS_DOLBYVISION 0x0200 ///< DolbyVision
/// @}
/// \defgroup define_HDR_support ADLDDCInfo2 HDR support options
/// @{
/// defines for iSupportedHDR in ADLDDCInfo2
#define ADL_HDR_CEA861_3 0x0001 ///< HDR10/CEA861.3 HDR supported
#define ADL_HDR_DOLBYVISION 0x0002 ///< \deprecated DolbyVision HDR supported
#define ADL_HDR_FREESYNC_HDR 0x0004 ///< FreeSync HDR supported
/// @}
/// \defgroup define_FreesyncFlags ADLDDCInfo2 Freesync HDR flags
/// @{
/// defines for iFreesyncFlags in ADLDDCInfo2
#define ADL_HDR_FREESYNC_BACKLIGHT_SUPPORT 0x0001 ///< Global backlight control supported
#define ADL_HDR_FREESYNC_LOCAL_DIMMING 0x0002 ///< Local dimming supported
/// @}
/// \defgroup define_source_content_flags ADLSourceContentAttributes flags
/// @{
/// defines for iFlags in ADLSourceContentAttributes
#define ADL_SCA_LOCAL_DIMMING_DISABLE 0x0001 ///< Disable local dimming
/// @}
/// \defgroup define_dbd_state Deep Bit Depth
/// @{
/// defines for ADL_Workstation_DeepBitDepth_Get and ADL_Workstation_DeepBitDepth_Set functions
// This value indicates that the deep bit depth state is forced off
#define ADL_DEEPBITDEPTH_FORCEOFF 0
/// This value indicates that the deep bit depth state is set to auto, the driver will automatically enable the
/// appropriate deep bit depth state depending on what connected display supports.
#define ADL_DEEPBITDEPTH_10BPP_AUTO 1
/// This value indicates that the deep bit depth state is forced on to 10 bits per pixel, this is regardless if the display
/// supports 10 bpp.
#define ADL_DEEPBITDEPTH_10BPP_FORCEON 2
/// defines for ADLAdapterConfigMemory of ADL_Adapter_ConfigMemory_Get
/// If this bit is set, it indicates that the Deep Bit Depth pixel is set on the display
#define ADL_ADAPTER_CONFIGMEMORY_DBD (1 << 0)
/// If this bit is set, it indicates that the display is rotated (90, 180 or 270)
#define ADL_ADAPTER_CONFIGMEMORY_ROTATE (1 << 1)
/// If this bit is set, it indicates that passive stereo is set on the display
#define ADL_ADAPTER_CONFIGMEMORY_STEREO_PASSIVE (1 << 2)
/// If this bit is set, it indicates that the active stereo is set on the display
#define ADL_ADAPTER_CONFIGMEMORY_STEREO_ACTIVE (1 << 3)
/// If this bit is set, it indicates that the tear free vsync is set on the display
#define ADL_ADAPTER_CONFIGMEMORY_ENHANCEDVSYNC (1 << 4)
#define ADL_ADAPTER_CONFIGMEMORY_TEARFREEVSYNC (1 << 4)
/// @}
/// \defgroup define_adl_validmemoryrequiredfields Memory Type
/// @{
/// This group defines memory types in ADLMemoryRequired struct \n
/// Indicates that this is the visible memory
#define ADL_MEMORYREQTYPE_VISIBLE (1 << 0)
/// Indicates that this is the invisible memory.
#define ADL_MEMORYREQTYPE_INVISIBLE (1 << 1)
/// Indicates that this is amount of visible memory per GPU that should be reserved for all other allocations.
#define ADL_MEMORYREQTYPE_GPURESERVEDVISIBLE (1 << 2)
/// @}
/// \defgroup define_adapter_tear_free_status
/// Used in ADL_Adapter_TEAR_FREE_Set and ADL_Adapter_TFD_Get functions to indicate the tear free
/// desktop status.
/// @{
/// Tear free desktop is enabled.
#define ADL_ADAPTER_TEAR_FREE_ON 1
/// Tear free desktop can't be enabled due to a lack of graphic adapter memory.
#define ADL_ADAPTER_TEAR_FREE_NOTENOUGHMEM -1
/// Tear free desktop can't be enabled due to quad buffer stereo being enabled.
#define ADL_ADAPTER_TEAR_FREE_OFF_ERR_QUADBUFFERSTEREO -2
/// Tear free desktop can't be enabled due to MGPU-SLS being enabled.
#define ADL_ADAPTER_TEAR_FREE_OFF_ERR_MGPUSLD -3
/// Tear free desktop is disabled.
#define ADL_ADAPTER_TEAR_FREE_OFF 0
/// @}
/// \defgroup define_adapter_crossdisplay_platforminfo
/// Used in ADL_Adapter_CrossDisplayPlatformInfo_Get function to indicate the Crossdisplay platform info.
/// @{
/// CROSSDISPLAY platform.
#define ADL_CROSSDISPLAY_PLATFORM (1 << 0)
/// CROSSDISPLAY platform for Lasso station.
#define ADL_CROSSDISPLAY_PLATFORM_LASSO (1 << 1)
/// CROSSDISPLAY platform for docking station.
#define ADL_CROSSDISPLAY_PLATFORM_DOCKSTATION (1 << 2)
/// @}
/// \defgroup define_adapter_crossdisplay_option
/// Used in ADL_Adapter_CrossdisplayInfoX2_Set function to indicate cross display options.
/// @{
/// Checking if 3D application is runnning. If yes, not to do switch, return ADL_OK_WAIT; otherwise do switch.
#define ADL_CROSSDISPLAY_OPTION_NONE 0
/// Force switching without checking for running 3D applications
#define ADL_CROSSDISPLAY_OPTION_FORCESWITCH (1 << 0)
/// @}
/// \defgroup define_adapter_states Adapter Capabilities
/// These defines the capabilities supported by an adapter. It is used by \ref ADL_Adapter_ConfigureState_Get
/// @{
/// Indicates that the adapter is headless (i.e. no displays can be connected to it)
#define ADL_ADAPTERCONFIGSTATE_HEADLESS ( 1 << 2 )
/// Indicates that the adapter is configured to define the main rendering capabilities. For example, adapters
/// in Crossfire(TM) configuration, this bit would only be set on the adapter driving the display(s).
#define ADL_ADAPTERCONFIGSTATE_REQUISITE_RENDER ( 1 << 0 )
/// Indicates that the adapter is configured to be used to unload some of the rendering work for a particular
/// requisite rendering adapter. For eample, for adapters in a Crossfire configuration, this bit would be set
/// on all adapters that are currently not driving the display(s)
#define ADL_ADAPTERCONFIGSTATE_ANCILLARY_RENDER ( 1 << 1 )
/// Indicates that scatter gather feature enabled on the adapter
#define ADL_ADAPTERCONFIGSTATE_SCATTERGATHER ( 1 << 4 )
/// @}
/// \defgroup define_controllermode_ulModifiers
/// These defines the detailed actions supported by set viewport. It is used by \ref ADL_Display_ViewPort_Set
/// @{
/// Indicate that the viewport set will change the view position
#define ADL_CONTROLLERMODE_CM_MODIFIER_VIEW_POSITION 0x00000001
/// Indicate that the viewport set will change the view PanLock
#define ADL_CONTROLLERMODE_CM_MODIFIER_VIEW_PANLOCK 0x00000002
/// Indicate that the viewport set will change the view size
#define ADL_CONTROLLERMODE_CM_MODIFIER_VIEW_SIZE 0x00000008
/// @}
/// \defgroup defines for Mirabilis
/// These defines are used for the Mirabilis feature
/// @{
///
/// Indicates the maximum number of audio sample rates
#define ADL_MAX_AUDIO_SAMPLE_RATE_COUNT 16
/// @}
///////////////////////////////////////////////////////////////////////////
// ADLMultiChannelSplitStateFlag Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLMultiChannelSplitStateFlag
{
ADLMultiChannelSplit_Unitialized = 0,
ADLMultiChannelSplit_Disabled = 1,
ADLMultiChannelSplit_Enabled = 2,
ADLMultiChannelSplit_SaveProfile = 3
};
///////////////////////////////////////////////////////////////////////////
// ADLSampleRate Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLSampleRate
{
ADLSampleRate_32KHz =0,
ADLSampleRate_44P1KHz,
ADLSampleRate_48KHz,
ADLSampleRate_88P2KHz,
ADLSampleRate_96KHz,
ADLSampleRate_176P4KHz,
ADLSampleRate_192KHz,
ADLSampleRate_384KHz, //DP1.2
ADLSampleRate_768KHz, //DP1.2
ADLSampleRate_Undefined
};
/// \defgroup define_overdrive6_capabilities
/// These defines the capabilities supported by Overdrive 6. It is used by \ref ADL_Overdrive6_Capabilities_Get
/// @{
/// Indicate that core (engine) clock can be changed.
#define ADL_OD6_CAPABILITY_SCLK_CUSTOMIZATION 0x00000001
/// Indicate that memory clock can be changed.
#define ADL_OD6_CAPABILITY_MCLK_CUSTOMIZATION 0x00000002
/// Indicate that graphics activity reporting is supported.
#define ADL_OD6_CAPABILITY_GPU_ACTIVITY_MONITOR 0x00000004
/// Indicate that power limit can be customized.
#define ADL_OD6_CAPABILITY_POWER_CONTROL 0x00000008
/// Indicate that SVI2 Voltage Control is supported.
#define ADL_OD6_CAPABILITY_VOLTAGE_CONTROL 0x00000010
/// Indicate that OD6+ percentage adjustment is supported.
#define ADL_OD6_CAPABILITY_PERCENT_ADJUSTMENT 0x00000020
/// Indicate that Thermal Limit Unlock is supported.
#define ADL_OD6_CAPABILITY_THERMAL_LIMIT_UNLOCK 0x00000040
///Indicate that Fan speed needs to be displayed in RPM
#define ADL_OD6_CAPABILITY_FANSPEED_IN_RPM 0x00000080
/// @}
/// \defgroup define_overdrive6_supported_states
/// These defines the power states supported by Overdrive 6. It is used by \ref ADL_Overdrive6_Capabilities_Get
/// @{
/// Indicate that overdrive is supported in the performance state. This is currently the only state supported.
#define ADL_OD6_SUPPORTEDSTATE_PERFORMANCE 0x00000001
/// Do not use. Reserved for future use.
#define ADL_OD6_SUPPORTEDSTATE_POWER_SAVING 0x00000002
/// @}
/// \defgroup define_overdrive6_getstateinfo
/// These defines the power states to get information about. It is used by \ref ADL_Overdrive6_StateInfo_Get
/// @{
/// Get default clocks for the performance state.
#define ADL_OD6_GETSTATEINFO_DEFAULT_PERFORMANCE 0x00000001
/// Do not use. Reserved for future use.
#define ADL_OD6_GETSTATEINFO_DEFAULT_POWER_SAVING 0x00000002
/// Get clocks for current state. Currently this is the same as \ref ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE
/// since only performance state is supported.
#define ADL_OD6_GETSTATEINFO_CURRENT 0x00000003
/// Get the modified clocks (if any) for the performance state. If clocks were not modified
/// through Overdrive 6, then this will return the same clocks as \ref ADL_OD6_GETSTATEINFO_DEFAULT_PERFORMANCE.
#define ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE 0x00000004
/// Do not use. Reserved for future use.
#define ADL_OD6_GETSTATEINFO_CUSTOM_POWER_SAVING 0x00000005
/// @}
/// \defgroup define_overdrive6_getstate and define_overdrive6_getmaxclockadjust
/// These defines the power states to get information about. It is used by \ref ADL_Overdrive6_StateEx_Get and \ref ADL_Overdrive6_MaxClockAdjust_Get
/// @{
/// Get default clocks for the performance state. Only performance state is currently supported.
#define ADL_OD6_STATE_PERFORMANCE 0x00000001
/// @}
/// \defgroup define_overdrive6_setstate
/// These define which power state to set customized clocks on. It is used by \ref ADL_Overdrive6_State_Set
/// @{
/// Set customized clocks for the performance state.
#define ADL_OD6_SETSTATE_PERFORMANCE 0x00000001
/// Do not use. Reserved for future use.
#define ADL_OD6_SETSTATE_POWER_SAVING 0x00000002
/// @}
/// \defgroup define_overdrive6_thermalcontroller_caps
/// These defines the capabilities of the GPU thermal controller. It is used by \ref ADL_Overdrive6_ThermalController_Caps
/// @{
/// GPU thermal controller is supported.
#define ADL_OD6_TCCAPS_THERMAL_CONTROLLER 0x00000001
/// GPU fan speed control is supported.
#define ADL_OD6_TCCAPS_FANSPEED_CONTROL 0x00000002
/// Fan speed percentage can be read.
#define ADL_OD6_TCCAPS_FANSPEED_PERCENT_READ 0x00000100
/// Fan speed can be set by specifying a percentage value.
#define ADL_OD6_TCCAPS_FANSPEED_PERCENT_WRITE 0x00000200
/// Fan speed RPM (revolutions-per-minute) can be read.
#define ADL_OD6_TCCAPS_FANSPEED_RPM_READ 0x00000400
/// Fan speed can be set by specifying an RPM value.
#define ADL_OD6_TCCAPS_FANSPEED_RPM_WRITE 0x00000800
/// @}
/// \defgroup define_overdrive6_fanspeed_type
/// These defines the fan speed type being reported. It is used by \ref ADL_Overdrive6_FanSpeed_Get
/// @{
/// Fan speed reported in percentage.
#define ADL_OD6_FANSPEED_TYPE_PERCENT 0x00000001
/// Fan speed reported in RPM.
#define ADL_OD6_FANSPEED_TYPE_RPM 0x00000002
/// Fan speed has been customized by the user, and fan is not running in automatic mode.
#define ADL_OD6_FANSPEED_USER_DEFINED 0x00000100
/// @}
/// \defgroup define_overdrive_EventCounter_type
/// These defines the EventCounter type being reported. It is used by \ref ADL2_OverdriveN_CountOfEvents_Get ,can be used on older OD version supported ASICs also.
/// @{
#define ADL_ODN_EVENTCOUNTER_THERMAL 0
#define ADL_ODN_EVENTCOUNTER_VPURECOVERY 1
/// @}
///////////////////////////////////////////////////////////////////////////
// ADLODNControlType Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLODNControlType
{
ODNControlType_Current = 0,
ODNControlType_Default,
ODNControlType_Auto,
ODNControlType_Manual
};
enum ADLODNDPMMaskType
{
ADL_ODN_DPM_CLOCK = 1 << 0,
ADL_ODN_DPM_VDDC = 1 << 1,
ADL_ODN_DPM_MASK = 1 << 2,
};
//ODN features Bits for ADLODNCapabilitiesX2
enum ADLODNFeatureControl
{
ADL_ODN_SCLK_DPM = 1 << 0,
ADL_ODN_MCLK_DPM = 1 << 1,
ADL_ODN_SCLK_VDD = 1 << 2,
ADL_ODN_MCLK_VDD = 1 << 3,
ADL_ODN_FAN_SPEED_MIN = 1 << 4,
ADL_ODN_FAN_SPEED_TARGET = 1 << 5,
ADL_ODN_ACOUSTIC_LIMIT_SCLK = 1 << 6,
ADL_ODN_TEMPERATURE_FAN_MAX = 1 << 7,
ADL_ODN_TEMPERATURE_SYSTEM = 1 << 8,
ADL_ODN_POWER_LIMIT = 1 << 9,
ADL_ODN_SCLK_AUTO_LIMIT = 1 << 10,
ADL_ODN_MCLK_AUTO_LIMIT = 1 << 11,
ADL_ODN_SCLK_DPM_MASK_ENABLE = 1 << 12,
ADL_ODN_MCLK_DPM_MASK_ENABLE = 1 << 13,
ADL_ODN_MCLK_UNDERCLOCK_ENABLE = 1 << 14,
ADL_ODN_SCLK_DPM_THROTTLE_NOTIFY = 1 << 15,
ADL_ODN_POWER_UTILIZATION = 1 << 16,
ADL_ODN_PERF_TUNING_SLIDER = 1 << 17,
ADL_ODN_REMOVE_WATTMAN_PAGE = 1 << 31 // Internal Only
};
//If any new feature is added, PPLIB only needs to add ext feature ID and Item ID(Seeting ID). These IDs should match the drive defined in CWDDEPM.h
enum ADLODNExtFeatureControl
{
ADL_ODN_EXT_FEATURE_MEMORY_TIMING_TUNE = 1 << 0,
ADL_ODN_EXT_FEATURE_FAN_ZERO_RPM_CONTROL = 1 << 1,
ADL_ODN_EXT_FEATURE_AUTO_UV_ENGINE = 1 << 2, //Auto under voltage
ADL_ODN_EXT_FEATURE_AUTO_OC_ENGINE = 1 << 3, //Auto OC Enine
ADL_ODN_EXT_FEATURE_AUTO_OC_MEMORY = 1 << 4, //Auto OC memory
ADL_ODN_EXT_FEATURE_FAN_CURVE = 1 << 5 //Fan curve
};
//If any new feature is added, PPLIB only needs to add ext feature ID and Item ID(Seeting ID).These IDs should match the drive defined in CWDDEPM.h
enum ADLODNExtSettingId
{
ADL_ODN_PARAMETER_AC_TIMING = 0,
ADL_ODN_PARAMETER_FAN_ZERO_RPM_CONTROL,
ADL_ODN_PARAMETER_AUTO_UV_ENGINE,
ADL_ODN_PARAMETER_AUTO_OC_ENGINE,
ADL_ODN_PARAMETER_AUTO_OC_MEMORY,
ADL_ODN_PARAMETER_FAN_CURVE_TEMPERATURE_1,
ADL_ODN_PARAMETER_FAN_CURVE_SPEED_1,
ADL_ODN_PARAMETER_FAN_CURVE_TEMPERATURE_2,
ADL_ODN_PARAMETER_FAN_CURVE_SPEED_2,
ADL_ODN_PARAMETER_FAN_CURVE_TEMPERATURE_3,
ADL_ODN_PARAMETER_FAN_CURVE_SPEED_3,
ADL_ODN_PARAMETER_FAN_CURVE_TEMPERATURE_4,
ADL_ODN_PARAMETER_FAN_CURVE_SPEED_4,
ADL_ODN_PARAMETER_FAN_CURVE_TEMPERATURE_5,
ADL_ODN_PARAMETER_FAN_CURVE_SPEED_5,
ADL_ODN_POWERGAUGE,
ODN_COUNT
} ;
//OD8 Capability features bits
enum ADLOD8FeatureControl
{
ADL_OD8_GFXCLK_LIMITS = 1 << 0,
ADL_OD8_GFXCLK_CURVE = 1 << 1,
ADL_OD8_UCLK_MAX = 1 << 2,
ADL_OD8_POWER_LIMIT = 1 << 3,
ADL_OD8_ACOUSTIC_LIMIT_SCLK = 1 << 4, //FanMaximumRpm
ADL_OD8_FAN_SPEED_MIN = 1 << 5, //FanMinimumPwm
ADL_OD8_TEMPERATURE_FAN = 1 << 6, //FanTargetTemperature
ADL_OD8_TEMPERATURE_SYSTEM = 1 << 7, //MaxOpTemp
ADL_OD8_MEMORY_TIMING_TUNE = 1 << 8,
ADL_OD8_FAN_ZERO_RPM_CONTROL = 1 << 9 ,
ADL_OD8_AUTO_UV_ENGINE = 1 << 10, //Auto under voltage
ADL_OD8_AUTO_OC_ENGINE = 1 << 11, //Auto overclock engine
ADL_OD8_AUTO_OC_MEMORY = 1 << 12, //Auto overclock memory
ADL_OD8_FAN_CURVE = 1 << 13, //Fan curve
ADL_OD8_WS_AUTO_FAN_ACOUSTIC_LIMIT = 1 << 14, //Workstation Manual Fan controller
ADL_OD8_GFXCLK_QUADRATIC_CURVE = 1 << 15,
ADL_OD8_OPTIMIZED_GPU_POWER_MODE = 1 << 16,
ADL_OD8_ODVOLTAGE_LIMIT = 1 << 17,
ADL_OD8_ADV_OC_LIMITS = 1 << 18, //Advanced OC limits.
ADL_OD8_PER_ZONE_GFX_VOLTAGE_OFFSET = 1 << 19, //Per Zone gfx voltage offset feature
ADL_OD8_AUTO_CURVE_OPTIMIZER = 1 << 20, //Auto per zone tuning.
ADL_OD8_GFX_VOLTAGE_LIMIT = 1 << 21, //Voltage limit slider
ADL_OD8_TDC_LIMIT = 1 << 22, //TDC slider
ADL_OD8_FULL_CONTROL_MODE = 1 << 23, //Full control
ADL_OD8_POWER_SAVING_FEATURE_CONTROL = 1 << 24, //Power saving feature control
ADL_OD8_POWER_GAUGE = 1 << 25 //Power Gauge
};
typedef enum ADLOD8SettingId
{
OD8_GFXCLK_FMAX = 0,
OD8_GFXCLK_FMIN,
OD8_GFXCLK_FREQ1,
OD8_GFXCLK_VOLTAGE1,
OD8_GFXCLK_FREQ2,
OD8_GFXCLK_VOLTAGE2,
OD8_GFXCLK_FREQ3,
OD8_GFXCLK_VOLTAGE3,
OD8_UCLK_FMAX,
OD8_POWER_PERCENTAGE,
OD8_FAN_MIN_SPEED,
OD8_FAN_ACOUSTIC_LIMIT,
OD8_FAN_TARGET_TEMP,
OD8_OPERATING_TEMP_MAX,
OD8_AC_TIMING,
OD8_FAN_ZERORPM_CONTROL,
OD8_AUTO_UV_ENGINE_CONTROL,
OD8_AUTO_OC_ENGINE_CONTROL,
OD8_AUTO_OC_MEMORY_CONTROL,
OD8_FAN_CURVE_TEMPERATURE_1,
OD8_FAN_CURVE_SPEED_1,
OD8_FAN_CURVE_TEMPERATURE_2,
OD8_FAN_CURVE_SPEED_2,
OD8_FAN_CURVE_TEMPERATURE_3,
OD8_FAN_CURVE_SPEED_3,
OD8_FAN_CURVE_TEMPERATURE_4,
OD8_FAN_CURVE_SPEED_4,
OD8_FAN_CURVE_TEMPERATURE_5,
OD8_FAN_CURVE_SPEED_5,
OD8_WS_FAN_AUTO_FAN_ACOUSTIC_LIMIT,
OD8_GFXCLK_CURVE_COEFFICIENT_A, // As part of the agreement with UI team, the min/max voltage limits for the
OD8_GFXCLK_CURVE_COEFFICIENT_B, // quadratic curve graph will be stored in the min and max limits of
OD8_GFXCLK_CURVE_COEFFICIENT_C, // coefficient a, b and c. A, b and c themselves do not have limits.
OD8_GFXCLK_CURVE_VFT_FMIN,
OD8_UCLK_FMIN,
OD8_FAN_ZERO_RPM_STOP_TEMPERATURE,
OD8_OPTIMZED_POWER_MODE,
OD8_OD_VOLTAGE,// RSX - voltage offset feature
OD8_ADV_OC_LIMITS_SETTING,
OD8_PER_ZONE_GFX_VOLTAGE_OFFSET_POINT_1,
OD8_PER_ZONE_GFX_VOLTAGE_OFFSET_POINT_2,
OD8_PER_ZONE_GFX_VOLTAGE_OFFSET_POINT_3,
OD8_PER_ZONE_GFX_VOLTAGE_OFFSET_POINT_4,
OD8_PER_ZONE_GFX_VOLTAGE_OFFSET_POINT_5,
OD8_PER_ZONE_GFX_VOLTAGE_OFFSET_POINT_6,
OD8_AUTO_CURVE_OPTIMIZER_SETTING,
OD8_GFX_VOLTAGE_LIMIT_SETTING,
OD8_TDC_PERCENTAGE,
OD8_FULL_CONTROL_MODE_SETTING,
OD8_IDLE_POWER_SAVING_FEATURE_CONTROL,
OD8_RUNTIME_POWER_SAVING_FEATURE_CONTROL,
OD8_POWER_GAUGE,
OD8_COUNT
} ADLOD8SettingId;
//Define Performance Metrics Log max sensors number
#define ADL_PMLOG_MAX_SENSORS 256
/// \deprecated Replaced with ADL_PMLOG_SENSORS
typedef enum ADLSensorType
{
SENSOR_MAXTYPES = 0,
PMLOG_CLK_GFXCLK = 1, // Current graphic clock value in MHz
PMLOG_CLK_MEMCLK = 2, // Current memory clock value in MHz
PMLOG_CLK_SOCCLK = 3,
PMLOG_CLK_UVDCLK1 = 4,
PMLOG_CLK_UVDCLK2 = 5,
PMLOG_CLK_VCECLK = 6,
PMLOG_CLK_VCNCLK = 7,
PMLOG_TEMPERATURE_EDGE = 8, // Current edge of the die temperature value in C
PMLOG_TEMPERATURE_MEM = 9,
PMLOG_TEMPERATURE_VRVDDC = 10,
PMLOG_TEMPERATURE_VRMVDD = 11,
PMLOG_TEMPERATURE_LIQUID = 12,
PMLOG_TEMPERATURE_PLX = 13,
PMLOG_FAN_RPM = 14, // Current fan RPM value
PMLOG_FAN_PERCENTAGE = 15, // Current ratio of fan RPM and max RPM
PMLOG_SOC_VOLTAGE = 16,
PMLOG_SOC_POWER = 17,
PMLOG_SOC_CURRENT = 18,
PMLOG_INFO_ACTIVITY_GFX = 19, // Current graphic activity level in percentage
PMLOG_INFO_ACTIVITY_MEM = 20, // Current memory activity level in percentage
PMLOG_GFX_VOLTAGE = 21, // Current graphic voltage in mV
PMLOG_MEM_VOLTAGE = 22,
PMLOG_ASIC_POWER = 23, // Current ASIC power draw in Watt
PMLOG_TEMPERATURE_VRSOC = 24,
PMLOG_TEMPERATURE_VRMVDD0 = 25,
PMLOG_TEMPERATURE_VRMVDD1 = 26,
PMLOG_TEMPERATURE_HOTSPOT = 27, // Current center of the die temperature value in C
PMLOG_TEMPERATURE_GFX = 28,
PMLOG_TEMPERATURE_SOC = 29,
PMLOG_GFX_POWER = 30,
PMLOG_GFX_CURRENT = 31,
PMLOG_TEMPERATURE_CPU = 32,
PMLOG_CPU_POWER = 33,
PMLOG_CLK_CPUCLK = 34,
PMLOG_THROTTLER_STATUS = 35, // A bit map of GPU throttle information. If a bit is set, the bit represented type of thorttling occurred in the last metrics sampling period
PMLOG_CLK_VCN1CLK1 = 36,
PMLOG_CLK_VCN1CLK2 = 37,
PMLOG_SMART_POWERSHIFT_CPU = 38,
PMLOG_SMART_POWERSHIFT_DGPU = 39,
PMLOG_BUS_SPEED = 40, // Current PCIE bus speed running
PMLOG_BUS_LANES = 41, // Current PCIE bus lanes using
PMLOG_TEMPERATURE_LIQUID0 = 42,
PMLOG_TEMPERATURE_LIQUID1 = 43,
PMLOG_CLK_FCLK = 44,
PMLOG_THROTTLER_STATUS_CPU = 45,
PMLOG_SSPAIRED_ASICPOWER = 46, // apuPower
PMLOG_SSTOTAL_POWERLIMIT = 47, // Total Power limit
PMLOG_SSAPU_POWERLIMIT = 48, // APU Power limit
PMLOG_SSDGPU_POWERLIMIT = 49, // DGPU Power limit
PMLOG_TEMPERATURE_HOTSPOT_GCD = 50,
PMLOG_TEMPERATURE_HOTSPOT_MCD = 51,
PMLOG_THROTTLER_TEMP_EDGE_PERCENTAGE = 52,
PMLOG_THROTTLER_TEMP_HOTSPOT_PERCENTAGE = 53,
PMLOG_THROTTLER_TEMP_HOTSPOT_GCD_PERCENTAGE = 54,
PMLOG_THROTTLER_TEMP_HOTSPOT_MCD_PERCENTAGE = 55,
PMLOG_THROTTLER_TEMP_MEM_PERCENTAGE = 56,
PMLOG_THROTTLER_TEMP_VR_GFX_PERCENTAGE = 57,
PMLOG_THROTTLER_TEMP_VR_MEM0_PERCENTAGE = 58,
PMLOG_THROTTLER_TEMP_VR_MEM1_PERCENTAGE = 59,
PMLOG_THROTTLER_TEMP_VR_SOC_PERCENTAGE = 60,
PMLOG_THROTTLER_TEMP_LIQUID0_PERCENTAGE = 61,
PMLOG_THROTTLER_TEMP_LIQUID1_PERCENTAGE = 62,
PMLOG_THROTTLER_TEMP_PLX_PERCENTAGE = 63,
PMLOG_THROTTLER_TDC_GFX_PERCENTAGE = 64,
PMLOG_THROTTLER_TDC_SOC_PERCENTAGE = 65,
PMLOG_THROTTLER_TDC_USR_PERCENTAGE = 66,
PMLOG_THROTTLER_PPT0_PERCENTAGE = 67,
PMLOG_THROTTLER_PPT1_PERCENTAGE = 68,
PMLOG_THROTTLER_PPT2_PERCENTAGE = 69,
PMLOG_THROTTLER_PPT3_PERCENTAGE = 70,
PMLOG_THROTTLER_FIT_PERCENTAGE = 71,
PMLOG_THROTTLER_GFX_APCC_PLUS_PERCENTAGE = 72,
PMLOG_BOARD_POWER = 73,
PMLOG_MAX_SENSORS_REAL
} ADLSensorType;
//Throttle Status
typedef enum ADL_THROTTLE_NOTIFICATION
{
ADL_PMLOG_THROTTLE_POWER = 1 << 0,
ADL_PMLOG_THROTTLE_THERMAL = 1 << 1,
ADL_PMLOG_THROTTLE_CURRENT = 1 << 2,
} ADL_THROTTLE_NOTIFICATION;
typedef enum ADL_PMLOG_SENSORS
{
ADL_SENSOR_MAXTYPES = 0,
ADL_PMLOG_CLK_GFXCLK = 1,
ADL_PMLOG_CLK_MEMCLK = 2,
ADL_PMLOG_CLK_SOCCLK = 3,
ADL_PMLOG_CLK_UVDCLK1 = 4,
ADL_PMLOG_CLK_UVDCLK2 = 5,
ADL_PMLOG_CLK_VCECLK = 6,
ADL_PMLOG_CLK_VCNCLK = 7,
ADL_PMLOG_TEMPERATURE_EDGE = 8,
ADL_PMLOG_TEMPERATURE_MEM = 9,
ADL_PMLOG_TEMPERATURE_VRVDDC = 10,
ADL_PMLOG_TEMPERATURE_VRMVDD = 11,
ADL_PMLOG_TEMPERATURE_LIQUID = 12,
ADL_PMLOG_TEMPERATURE_PLX = 13,
ADL_PMLOG_FAN_RPM = 14,
ADL_PMLOG_FAN_PERCENTAGE = 15,
ADL_PMLOG_SOC_VOLTAGE = 16,
ADL_PMLOG_SOC_POWER = 17,
ADL_PMLOG_SOC_CURRENT = 18,
ADL_PMLOG_INFO_ACTIVITY_GFX = 19,
ADL_PMLOG_INFO_ACTIVITY_MEM = 20,
ADL_PMLOG_GFX_VOLTAGE = 21,
ADL_PMLOG_MEM_VOLTAGE = 22,
ADL_PMLOG_ASIC_POWER = 23,
ADL_PMLOG_TEMPERATURE_VRSOC = 24,
ADL_PMLOG_TEMPERATURE_VRMVDD0 = 25,
ADL_PMLOG_TEMPERATURE_VRMVDD1 = 26,
ADL_PMLOG_TEMPERATURE_HOTSPOT = 27,
ADL_PMLOG_TEMPERATURE_GFX = 28,
ADL_PMLOG_TEMPERATURE_SOC = 29,
ADL_PMLOG_GFX_POWER = 30,
ADL_PMLOG_GFX_CURRENT = 31,
ADL_PMLOG_TEMPERATURE_CPU = 32,
ADL_PMLOG_CPU_POWER = 33,
ADL_PMLOG_CLK_CPUCLK = 34,
ADL_PMLOG_THROTTLER_STATUS = 35, // GFX
ADL_PMLOG_CLK_VCN1CLK1 = 36,
ADL_PMLOG_CLK_VCN1CLK2 = 37,
ADL_PMLOG_SMART_POWERSHIFT_CPU = 38,
ADL_PMLOG_SMART_POWERSHIFT_DGPU = 39,
ADL_PMLOG_BUS_SPEED = 40,
ADL_PMLOG_BUS_LANES = 41,
ADL_PMLOG_TEMPERATURE_LIQUID0 = 42,
ADL_PMLOG_TEMPERATURE_LIQUID1 = 43,
ADL_PMLOG_CLK_FCLK = 44,
ADL_PMLOG_THROTTLER_STATUS_CPU = 45,
ADL_PMLOG_SSPAIRED_ASICPOWER = 46, // apuPower
ADL_PMLOG_SSTOTAL_POWERLIMIT = 47, // Total Power limit
ADL_PMLOG_SSAPU_POWERLIMIT = 48, // APU Power limit
ADL_PMLOG_SSDGPU_POWERLIMIT = 49, // DGPU Power limit
ADL_PMLOG_TEMPERATURE_HOTSPOT_GCD = 50,
ADL_PMLOG_TEMPERATURE_HOTSPOT_MCD = 51,
ADL_PMLOG_THROTTLER_TEMP_EDGE_PERCENTAGE = 52,
ADL_PMLOG_THROTTLER_TEMP_HOTSPOT_PERCENTAGE = 53,
ADL_PMLOG_THROTTLER_TEMP_HOTSPOT_GCD_PERCENTAGE = 54,
ADL_PMLOG_THROTTLER_TEMP_HOTSPOT_MCD_PERCENTAGE = 55,
ADL_PMLOG_THROTTLER_TEMP_MEM_PERCENTAGE = 56,
ADL_PMLOG_THROTTLER_TEMP_VR_GFX_PERCENTAGE = 57,
ADL_PMLOG_THROTTLER_TEMP_VR_MEM0_PERCENTAGE = 58,
ADL_PMLOG_THROTTLER_TEMP_VR_MEM1_PERCENTAGE = 59,
ADL_PMLOG_THROTTLER_TEMP_VR_SOC_PERCENTAGE = 60,
ADL_PMLOG_THROTTLER_TEMP_LIQUID0_PERCENTAGE = 61,
ADL_PMLOG_THROTTLER_TEMP_LIQUID1_PERCENTAGE = 62,
ADL_PMLOG_THROTTLER_TEMP_PLX_PERCENTAGE = 63,
ADL_PMLOG_THROTTLER_TDC_GFX_PERCENTAGE = 64,
ADL_PMLOG_THROTTLER_TDC_SOC_PERCENTAGE = 65,
ADL_PMLOG_THROTTLER_TDC_USR_PERCENTAGE = 66,
ADL_PMLOG_THROTTLER_PPT0_PERCENTAGE = 67,
ADL_PMLOG_THROTTLER_PPT1_PERCENTAGE = 68,
ADL_PMLOG_THROTTLER_PPT2_PERCENTAGE = 69,
ADL_PMLOG_THROTTLER_PPT3_PERCENTAGE = 70,
ADL_PMLOG_THROTTLER_FIT_PERCENTAGE = 71,
ADL_PMLOG_THROTTLER_GFX_APCC_PLUS_PERCENTAGE = 72,
ADL_PMLOG_BOARD_POWER = 73,
ADL_PMLOG_MAX_SENSORS_REAL
} ADL_PMLOG_SENSORS;
/// \defgroup define_ecc_mode_states
/// These defines the ECC(Error Correction Code) state. It is used by \ref ADL_Workstation_ECC_Get,ADL_Workstation_ECC_Set
/// @{
/// Error Correction is OFF.
#define ECC_MODE_OFF 0
/// Error Correction is ECCV2.
#define ECC_MODE_ON 2
/// Error Correction is HBM.
#define ECC_MODE_HBM 3
/// @}
/// \defgroup define_board_layout_flags
/// These defines are the board layout flags state which indicates what are the valid properties of \ref ADLBoardLayoutInfo . It is used by \ref ADL_Adapter_BoardLayout_Get
/// @{
/// Indicates the number of slots is valid.
#define ADL_BLAYOUT_VALID_NUMBER_OF_SLOTS 0x1
/// Indicates the slot sizes are valid. Size of the slot consists of the length and width.
#define ADL_BLAYOUT_VALID_SLOT_SIZES 0x2
/// Indicates the connector offsets are valid.
#define ADL_BLAYOUT_VALID_CONNECTOR_OFFSETS 0x4
/// Indicates the connector lengths is valid.
#define ADL_BLAYOUT_VALID_CONNECTOR_LENGTHS 0x8
/// @}
/// \defgroup define_max_constants
/// These defines are the maximum value constants.
/// @{
/// Indicates the Maximum supported slots on board.
#define ADL_ADAPTER_MAX_SLOTS 4
/// Indicates the Maximum supported connectors on slot.
#define ADL_ADAPTER_MAX_CONNECTORS 10
/// Indicates the Maximum supported properties of connection
#define ADL_MAX_CONNECTION_TYPES 32
/// Indicates the Maximum relative address link count.
#define ADL_MAX_RELATIVE_ADDRESS_LINK_COUNT 15
/// Indicates the Maximum size of EDID data block size
#define ADL_MAX_DISPLAY_EDID_DATA_SIZE 1024
/// Indicates the Maximum count of Error Records.
#define ADL_MAX_ERROR_RECORDS_COUNT 256
/// Indicates the maximum number of power states supported
#define ADL_MAX_POWER_POLICY 6
/// @}
/// \defgroup define_connection_types
/// These defines are the connection types constants which indicates what are the valid connection type of given connector. It is used by \ref ADL_Adapter_SupportedConnections_Get
/// @{
/// Indicates the VGA connection type is valid.
#define ADL_CONNECTION_TYPE_VGA 0
/// Indicates the DVI_I connection type is valid.
#define ADL_CONNECTION_TYPE_DVI 1
/// Indicates the DVI_SL connection type is valid.
#define ADL_CONNECTION_TYPE_DVI_SL 2
/// Indicates the HDMI connection type is valid.
#define ADL_CONNECTION_TYPE_HDMI 3
/// Indicates the DISPLAY PORT connection type is valid.
#define ADL_CONNECTION_TYPE_DISPLAY_PORT 4
/// Indicates the Active dongle DP->DVI(single link) connection type is valid.
#define ADL_CONNECTION_TYPE_ACTIVE_DONGLE_DP_DVI_SL 5
/// Indicates the Active dongle DP->DVI(double link) connection type is valid.
#define ADL_CONNECTION_TYPE_ACTIVE_DONGLE_DP_DVI_DL 6
/// Indicates the Active dongle DP->HDMI connection type is valid.
#define ADL_CONNECTION_TYPE_ACTIVE_DONGLE_DP_HDMI 7
/// Indicates the Active dongle DP->VGA connection type is valid.
#define ADL_CONNECTION_TYPE_ACTIVE_DONGLE_DP_VGA 8
/// Indicates the Passive dongle DP->HDMI connection type is valid.
#define ADL_CONNECTION_TYPE_PASSIVE_DONGLE_DP_HDMI 9
/// Indicates the Active dongle DP->VGA connection type is valid.
#define ADL_CONNECTION_TYPE_PASSIVE_DONGLE_DP_DVI 10
/// Indicates the MST type is valid.
#define ADL_CONNECTION_TYPE_MST 11
/// Indicates the active dongle, all types.
#define ADL_CONNECTION_TYPE_ACTIVE_DONGLE 12
/// Indicates the Virtual Connection Type.
#define ADL_CONNECTION_TYPE_VIRTUAL 13
/// Macros for generating bitmask from index.
#define ADL_CONNECTION_BITMAST_FROM_INDEX(index) (1 << index)
/// @}
/// \defgroup define_connection_properties
/// These defines are the connection properties which indicates what are the valid properties of given connection type. It is used by \ref ADL_Adapter_SupportedConnections_Get
/// @{
/// Indicates the property Bitrate is valid.
#define ADL_CONNECTION_PROPERTY_BITRATE 0x1
/// Indicates the property number of lanes is valid.
#define ADL_CONNECTION_PROPERTY_NUMBER_OF_LANES 0x2
/// Indicates the property 3D caps is valid.
#define ADL_CONNECTION_PROPERTY_3DCAPS 0x4
/// Indicates the property output bandwidth is valid.
#define ADL_CONNECTION_PROPERTY_OUTPUT_BANDWIDTH 0x8
/// Indicates the property colordepth is valid.
#define ADL_CONNECTION_PROPERTY_COLORDEPTH 0x10
/// @}
/// \defgroup define_lanecount_constants
/// These defines are the Lane count constants which will be used in DP & etc.
/// @{
/// Indicates if lane count is unknown
#define ADL_LANECOUNT_UNKNOWN 0
/// Indicates if lane count is 1
#define ADL_LANECOUNT_ONE 1
/// Indicates if lane count is 2
#define ADL_LANECOUNT_TWO 2
/// Indicates if lane count is 4
#define ADL_LANECOUNT_FOUR 4
/// Indicates if lane count is 8
#define ADL_LANECOUNT_EIGHT 8
/// Indicates default value of lane count
#define ADL_LANECOUNT_DEF ADL_LANECOUNT_FOUR
/// @}
/// \defgroup define_linkrate_constants
/// These defines are the link rate constants which will be used in DP & etc.
/// @{
/// Indicates if link rate is unknown
#define ADL_LINK_BITRATE_UNKNOWN 0
/// Indicates if link rate is 1.62Ghz
#define ADL_LINK_BITRATE_1_62_GHZ 0x06
/// Indicates if link rate is 2.7Ghz
#define ADL_LINK_BITRATE_2_7_GHZ 0x0A
/// Indicates if link rate is 5.4Ghz
#define ADL_LINK_BITRATE_5_4_GHZ 0x14
/// Indicates if link rate is 8.1Ghz
#define ADL_LINK_BITRATE_8_1_GHZ 0x1E
/// Indicates default value of link rate
#define ADL_LINK_BITRATE_DEF ADL_LINK_BITRATE_2_7_GHZ
/// @}
/// \defgroup define_colordepth_constants
/// These defines are the color depth constants which will be used in DP & etc.
/// @{
#define ADL_CONNPROP_S3D_ALTERNATE_TO_FRAME_PACK 0x00000001
/// @}
/// \defgroup define_colordepth_constants
/// These defines are the color depth constants which will be used in DP & etc.
/// @{
/// Indicates if color depth is unknown
#define ADL_COLORDEPTH_UNKNOWN 0
/// Indicates if color depth is 666
#define ADL_COLORDEPTH_666 1
/// Indicates if color depth is 888
#define ADL_COLORDEPTH_888 2
/// Indicates if color depth is 101010
#define ADL_COLORDEPTH_101010 3
/// Indicates if color depth is 121212
#define ADL_COLORDEPTH_121212 4
/// Indicates if color depth is 141414
#define ADL_COLORDEPTH_141414 5
/// Indicates if color depth is 161616
#define ADL_COLORDEPTH_161616 6
/// Indicates default value of color depth
#define ADL_COLOR_DEPTH_DEF ADL_COLORDEPTH_888
/// @}
/// \defgroup define_emulation_status
/// These defines are the status of emulation
/// @{
/// Indicates if real device is connected.
#define ADL_EMUL_STATUS_REAL_DEVICE_CONNECTED 0x1
/// Indicates if emulated device is presented.
#define ADL_EMUL_STATUS_EMULATED_DEVICE_PRESENT 0x2
/// Indicates if emulated device is used.
#define ADL_EMUL_STATUS_EMULATED_DEVICE_USED 0x4
/// In case when last active real/emulated device used (when persistence is enabled but no emulation enforced then persistence will use last connected/emulated device).
#define ADL_EMUL_STATUS_LAST_ACTIVE_DEVICE_USED 0x8
/// @}
/// \defgroup define_emulation_mode
/// These defines are the modes of emulation
/// @{
/// Indicates if no emulation is used
#define ADL_EMUL_MODE_OFF 0
/// Indicates if emulation is used when display connected
#define ADL_EMUL_MODE_ON_CONNECTED 1
/// Indicates if emulation is used when display dis connected
#define ADL_EMUL_MODE_ON_DISCONNECTED 2
/// Indicates if emulation is used always
#define ADL_EMUL_MODE_ALWAYS 3
/// @}
/// \defgroup define_emulation_query
/// These defines are the modes of emulation
/// @{
/// Indicates Data from real device
#define ADL_QUERY_REAL_DATA 0
/// Indicates Emulated data
#define ADL_QUERY_EMULATED_DATA 1
/// Indicates Data currently in use
#define ADL_QUERY_CURRENT_DATA 2
/// @}
/// \defgroup define_persistence_state
/// These defines are the states of persistence
/// @{
/// Indicates persistence is disabled
#define ADL_EDID_PERSISTANCE_DISABLED 0
/// Indicates persistence is enabled
#define ADL_EDID_PERSISTANCE_ENABLED 1
/// @}
/// \defgroup define_connector_types Connector Type
/// defines for ADLConnectorInfo.iType
/// @{
/// Indicates unknown Connector type
#define ADL_CONNECTOR_TYPE_UNKNOWN 0
/// Indicates VGA Connector type
#define ADL_CONNECTOR_TYPE_VGA 1
/// Indicates DVI-D Connector type
#define ADL_CONNECTOR_TYPE_DVI_D 2
/// Indicates DVI-I Connector type
#define ADL_CONNECTOR_TYPE_DVI_I 3
/// Indicates Active Dongle-NA Connector type
#define ADL_CONNECTOR_TYPE_ATICVDONGLE_NA 4
/// Indicates Active Dongle-JP Connector type
#define ADL_CONNECTOR_TYPE_ATICVDONGLE_JP 5
/// Indicates Active Dongle-NONI2C Connector type
#define ADL_CONNECTOR_TYPE_ATICVDONGLE_NONI2C 6
/// Indicates Active Dongle-NONI2C-D Connector type
#define ADL_CONNECTOR_TYPE_ATICVDONGLE_NONI2C_D 7
/// Indicates HDMI-Type A Connector type
#define ADL_CONNECTOR_TYPE_HDMI_TYPE_A 8
/// Indicates HDMI-Type B Connector type
#define ADL_CONNECTOR_TYPE_HDMI_TYPE_B 9
/// Indicates Display port Connector type
#define ADL_CONNECTOR_TYPE_DISPLAYPORT 10
/// Indicates EDP Connector type
#define ADL_CONNECTOR_TYPE_EDP 11
/// Indicates MiniDP Connector type
#define ADL_CONNECTOR_TYPE_MINI_DISPLAYPORT 12
/// Indicates Virtual Connector type
#define ADL_CONNECTOR_TYPE_VIRTUAL 13
/// Indicates USB type C Connector type
#define ADL_CONNECTOR_TYPE_USB_TYPE_C 14
/// @}
/// \defgroup define_freesync_usecase
/// These defines are to specify use cases in which FreeSync should be enabled
/// They are a bit mask. To specify FreeSync for more than one use case, the input value
/// should be set to include multiple bits set
/// @{
/// Indicates FreeSync is enabled for Static Screen case
#define ADL_FREESYNC_USECASE_STATIC 0x1
/// Indicates FreeSync is enabled for Video use case
#define ADL_FREESYNC_USECASE_VIDEO 0x2
/// Indicates FreeSync is enabled for Gaming use case
#define ADL_FREESYNC_USECASE_GAMING 0x4
/// @}
/// \defgroup define_freesync_caps
/// These defines are used to retrieve FreeSync display capabilities.
/// GPU support flag also indicates whether the display is
/// connected to a GPU that actually supports FreeSync
/// @{
#define ADL_FREESYNC_CAP_SUPPORTED (1 << 0)
#define ADL_FREESYNC_CAP_GPUSUPPORTED (1 << 1)
#define ADL_FREESYNC_CAP_DISPLAYSUPPORTED (1 << 2)
#define ADL_FREESYNC_CAP_CURRENTMODESUPPORTED (1 << 3)
#define ADL_FREESYNC_CAP_NOCFXORCFXSUPPORTED (1 << 4)
#define ADL_FREESYNC_CAP_NOGENLOCKORGENLOCKSUPPORTED (1 << 5)
#define ADL_FREESYNC_CAP_BORDERLESSWINDOWSUPPORTED (1 << 6)
/// @}
/// \defgroup define_freesync_labelIndex
/// These defines are used to retrieve which FreeSync label to use
/// @{
#define ADL_FREESYNC_LABEL_UNSUPPORTED 0
#define ADL_FREESYNC_LABEL_FREESYNC 1
#define ADL_FREESYNC_LABEL_ADAPTIVE_SYNC 2
#define ADL_FREESYNC_LABEL_VRR 3
#define ADL_FREESYNC_LABEL_FREESYNC_PREMIUM 4
#define ADL_FREESYNC_LABEL_FREESYNC_PREMIUM_PRO 5
/// @}
/// Freesync Power optimization masks
/// @{
#define ADL_FREESYNC_POWEROPTIMIZATION_SUPPORTED_MASK (1 << 0)
#define ADL_FREESYNC_POWEROPTIMIZATION_ENABLED_MASK (1 << 1)
#define ADL_FREESYNC_POWEROPTIMIZATION_DEFAULT_VALUE_MASK (1 << 2)
/// @}
/// \defgroup define_MST_CommandLine_execute
/// @{
/// Indicates the MST command line for branch message if the bit is set. Otherwise, it is display message
#define ADL_MST_COMMANDLINE_PATH_MSG 0x1
/// Indicates the MST command line to send message in broadcast way it the bit is set
#define ADL_MST_COMMANDLINE_BROADCAST 0x2
/// @}
/// \defgroup define_Adapter_CloneTypes_Get
/// @{
/// Indicates there is crossGPU clone with non-AMD dispalys
#define ADL_CROSSGPUDISPLAYCLONE_AMD_WITH_NONAMD 0x1
/// Indicates there is crossGPU clone
#define ADL_CROSSGPUDISPLAYCLONE 0x2
/// @}
/// \defgroup define_D3DKMT_HANDLE
/// @{
/// Handle can be used to create Device Handle when using CreateDevice()
typedef unsigned int ADL_D3DKMT_HANDLE;
/// @}
// End Bracket for Constants and Definitions. Add new groups ABOVE this line!
/// @}
typedef enum ADL_RAS_ERROR_INJECTION_MODE
{
ADL_RAS_ERROR_INJECTION_MODE_SINGLE = 1,
ADL_RAS_ERROR_INJECTION_MODE_MULTIPLE = 2
}ADL_RAS_ERROR_INJECTION_MODE;
typedef enum ADL_RAS_BLOCK_ID
{
ADL_RAS_BLOCK_ID_UMC = 0,
ADL_RAS_BLOCK_ID_SDMA,
ADL_RAS_BLOCK_ID_GFX_HUB,
ADL_RAS_BLOCK_ID_MMHUB,
ADL_RAS_BLOCK_ID_ATHUB,
ADL_RAS_BLOCK_ID_PCIE_BIF,
ADL_RAS_BLOCK_ID_HDP,
ADL_RAS_BLOCK_ID_XGMI_WAFL,
ADL_RAS_BLOCK_ID_DF,
ADL_RAS_BLOCK_ID_SMN,
ADL_RAS_BLOCK_ID_SEM,
ADL_RAS_BLOCK_ID_MP0,
ADL_RAS_BLOCK_ID_MP1,
ADL_RAS_BLOCK_ID_FUSE
}ADL_RAS_BLOCK_ID;
typedef enum ADL_MEM_SUB_BLOCK_ID
{
ADL_RAS__UMC_HBM = 0,
ADL_RAS__UMC_SRAM = 1
}ADL_MEM_SUB_BLOCK_ID;
typedef enum _ADL_RAS_ERROR_TYPE
{
ADL_RAS_ERROR__NONE = 0,
ADL_RAS_ERROR__PARITY = 1,
ADL_RAS_ERROR__SINGLE_CORRECTABLE = 2,
ADL_RAS_ERROR__PARITY_SINGLE_CORRECTABLE = 3,
ADL_RAS_ERROR__MULTI_UNCORRECTABLE = 4,
ADL_RAS_ERROR__PARITY_MULTI_UNCORRECTABLE = 5,
ADL_RAS_ERROR__SINGLE_CORRECTABLE_MULTI_UNCORRECTABLE = 6,
ADL_RAS_ERROR__PARITY_SINGLE_CORRECTABLE_MULTI_UNCORRECTABLE = 7,
ADL_RAS_ERROR__POISON = 8,
ADL_RAS_ERROR__PARITY_POISON = 9,
ADL_RAS_ERROR__SINGLE_CORRECTABLE_POISON = 10,
ADL_RAS_ERROR__PARITY_SINGLE_CORRECTABLE_POISON = 11,
ADL_RAS_ERROR__MULTI_UNCORRECTABLE_POISON = 12,
ADL_RAS_ERROR__PARITY_MULTI_UNCORRECTABLE_POISON = 13,
ADL_RAS_ERROR__SINGLE_CORRECTABLE_MULTI_UNCORRECTABLE_POISON = 14,
ADL_RAS_ERROR__PARITY_SINGLE_CORRECTABLE_MULTI_UNCORRECTABLE_POISON = 15
}ADL_RAS_ERROR_TYPE;
typedef enum ADL_RAS_INJECTION_METHOD
{
ADL_RAS_ERROR__UMC_METH_COHERENT = 0,
ADL_RAS_ERROR__UMC_METH_SINGLE_SHOT = 1,
ADL_RAS_ERROR__UMC_METH_PERSISTENT = 2,
ADL_RAS_ERROR__UMC_METH_PERSISTENT_DISABLE = 3
}ADL_RAS_INJECTION_METHOD;
// Driver event types
typedef enum ADL_DRIVER_EVENT_TYPE
{
ADL_EVENT_ID_AUTO_FEATURE_COMPLETED = 30,
ADL_EVENT_ID_FEATURE_AVAILABILITY = 31,
} ADL_DRIVER_EVENT_TYPE;
//UIFeature Ids
typedef enum ADL_UIFEATURES_GROUP
{
ADL_UIFEATURES_GROUP_DVR = 0,
ADL_UIFEATURES_GROUP_TURBOSYNC = 1,
ADL_UIFEATURES_GROUP_FRAMEMETRICSMONITOR = 2,
ADL_UIFEATURES_GROUP_FRTC = 3,
ADL_UIFEATURES_GROUP_XVISION = 4,
ADL_UIFEATURES_GROUP_BLOCKCHAIN = 5,
ADL_UIFEATURES_GROUP_GAMEINTELLIGENCE = 6,
ADL_UIFEATURES_GROUP_CHILL = 7,
ADL_UIFEATURES_GROUP_DELAG = 8,
ADL_UIFEATURES_GROUP_BOOST = 9,
ADL_UIFEATURES_GROUP_USU = 10,
ADL_UIFEATURES_GROUP_XGMI = 11,
ADL_UIFEATURES_GROUP_PROVSR = 12,
ADL_UIFEATURES_GROUP_SMA = 13,
ADL_UIFEATURES_GROUP_CAMERA = 14,
ADL_UIFEATURES_GROUP_FRTCPRO = 15
} ADL_UIFEATURES_GROUP;
/// Maximum brightness supported by Radeon LED interface
#define ADL_RADEON_LED_MAX_BRIGHTNESS 2
/// Maximum speed supported by Radeon LED interface
#define ADL_RADEON_LED_MAX_SPEED 4
/// Maximum RGB supported by Radeon LED interface
#define ADL_RADEON_LED_MAX_RGB 255
/// Maximum MORSE code supported string
#define ADL_RADEON_LED_MAX_MORSE_CODE 260
/// Maximum LED ROW ON GRID
#define ADL_RADEON_LED_MAX_LED_ROW_ON_GRID 7
/// Maximum LED COLUMN ON GRID
#define ADL_RADEON_LED_MAX_LED_COLUMN_ON_GRID 24
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief
///
///
///
///
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef enum ADL_RADEON_USB_LED_BAR_CONTROLS
{
RadeonLEDBarControl_OFF = 0,
RadeonLEDBarControl_Static,
RadeonLEDBarControl_Rainbow,
RadeonLEDBarControl_Swirl,
RadeonLEDBarControl_Chase,
RadeonLEDBarControl_Bounce,
RadeonLEDBarControl_MorseCode,
RadeonLEDBarControl_ColorCycle,
RadeonLEDBarControl_Breathing,
RadeonLEDBarControl_CustomPattern,
RadeonLEDBarControl_MAX
}ADL_RADEON_USB_LED_BAR_CONTROLS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief
///
///
///
///
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef unsigned int RadeonLEDBARSupportedControl;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief
///
///
///
///
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef enum ADL_RADEON_USB_LED_CONTROL_CONFIGS
{
RadeonLEDPattern_Speed = 0,
RadeonLEDPattern_Brightness,
RadeonLEDPattern_Direction,
RadeonLEDPattern_Color,
RadeonLEDPattern_MAX
}ADL_RADEON_USB_LED_CONTROL_CONFIGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief
///
///
///
///
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef unsigned int RadeonLEDBARSupportedConfig;
//User blob feature settings
typedef enum ADL_USER_SETTINGS
{
ADL_USER_SETTINGS_ENHANCEDSYNC = 1 << 0, //notify Enhanced Sync settings change
ADL_USER_SETTINGS_CHILL_PROFILE = 1 << 1, //notify Chill settings change
ADL_USER_SETTINGS_DELAG_PROFILE = 1 << 2, //notify Delag settings change
ADL_USER_SETTINGS_BOOST_PROFILE = 1 << 3, //notify Boost settings change
ADL_USER_SETTINGS_USU_PROFILE = 1 << 4, //notify USU settings change
ADL_USER_SETTINGS_CVDC_PROFILE = 1 << 5, //notify Color Vision Deficiency Corretion settings change
ADL_USER_SETTINGS_SCE_PROFILE = 1 << 6,
ADL_USER_SETTINGS_PROVSR = 1 << 7
} ADL_USER_SETTINGS;
#define ADL_REG_DEVICE_FUNCTION_1 0x00000001
#endif /* ADL_DEFINES_H_ */
================================================
FILE: src/3rdparty/display-library/adl_sdk.h
================================================
//
// Copyright (c) 2016 - 2022 Advanced Micro Devices, Inc. All rights reserved.
//
// MIT LICENSE:
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/// \file adl_sdk.h
/// \brief Contains the definition of the Memory Allocation Callback.\n Included in ADL SDK
///
/// \n\n
/// This file contains the definition of the Memory Allocation Callback.\n
/// It also includes definitions of the respective structures and constants.\n
/// This is the only header file to be included in a C/C++ project using ADL
#ifndef ADL_SDK_H_
#define ADL_SDK_H_
#include "adl_structures.h"
#if defined (LINUX)
#define __stdcall
#endif /* (LINUX) */
/// Memory Allocation Call back
typedef void* ( __stdcall *ADL_MAIN_MALLOC_CALLBACK )( int );
#define ADL_SDK_MAJOR_VERSION 17
#define ADL_SDK_MINOR_VERSION 1
#endif /* ADL_SDK_H_ */
================================================
FILE: src/3rdparty/display-library/adl_structures.h
================================================
//
// Copyright (c) 2016 - 2022 Advanced Micro Devices, Inc. All rights reserved.
//
// MIT LICENSE:
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/// \file adl_structures.h
///\brief This file contains the structure declarations that are used by the public ADL interfaces for \ALL platforms.\n Included in ADL SDK
///
/// All data structures used in AMD Display Library (ADL) public interfaces should be defined in this header file.
///
#ifndef ADL_STRUCTURES_H_
#define ADL_STRUCTURES_H_
#include "adl_defines.h"
#include
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the graphics adapter.
///
/// This structure is used to store various information about the graphics adapter. This
/// information can be returned to the user. Alternatively, it can be used to access various driver calls to set
/// or fetch various settings upon the user's request.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct AdapterInfo
{
/// \ALL_STRUCT_MEM
/// Size of the structure.
int iSize;
/// The ADL index handle. One GPU may be associated with one or two index handles
int iAdapterIndex;
/// The unique device ID associated with this adapter.
char strUDID[ADL_MAX_PATH];
/// The BUS number associated with this adapter.
int iBusNumber;
/// The driver number associated with this adapter.
int iDeviceNumber;
/// The function number.
int iFunctionNumber;
/// The vendor ID associated with this adapter.
int iVendorID;
/// Adapter name.
char strAdapterName[ADL_MAX_PATH];
/// Display name. For example, "\\\\Display0" for Windows or ":0:0" for Linux.
char strDisplayName[ADL_MAX_PATH];
/// Present or not; 1 if present and 0 if not present.It the logical adapter is present, the display name such as \\\\.\\Display1 can be found from OS
int iPresent;
#if defined (_WIN32) || defined (_WIN64)
/// \WIN_STRUCT_MEM
/// Exist or not; 1 is exist and 0 is not present.
int iExist;
/// Driver registry path.
char strDriverPath[ADL_MAX_PATH];
/// Driver registry path Ext for.
char strDriverPathExt[ADL_MAX_PATH];
/// PNP string from Windows.
char strPNPString[ADL_MAX_PATH];
/// It is generated from EnumDisplayDevices.
int iOSDisplayIndex;
#endif /* (_WIN32) || (_WIN64) */
#if defined (LINUX)
/// \LNX_STRUCT_MEM
/// Internal X screen number from GPUMapInfo (DEPRICATED use XScreenInfo)
int iXScreenNum;
/// Internal driver index from GPUMapInfo
int iDrvIndex;
/// \deprecated Internal x config file screen identifier name. Use XScreenInfo instead.
char strXScreenConfigName[ADL_MAX_PATH];
#endif /* (LINUX) */
} AdapterInfo, *LPAdapterInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the Linux X screen information.
///
/// This structure is used to store the current screen number and xorg.conf ID name assoicated with an adapter index.
/// This structure is updated during ADL_Main_Control_Refresh or ADL_ScreenInfo_Update.
/// Note: This structure should be used in place of iXScreenNum and strXScreenConfigName in AdapterInfo as they will be
/// deprecated.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
#if defined (LINUX)
typedef struct XScreenInfo
{
/// Internal X screen number from GPUMapInfo.
int iXScreenNum;
/// Internal x config file screen identifier name.
char strXScreenConfigName[ADL_MAX_PATH];
} XScreenInfo, *LPXScreenInfo;
#endif /* (LINUX) */
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an controller mode
///
/// This structure is used to store information of an controller mode
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdapterCaps
{
/// AdapterID for this adapter
int iAdapterID;
/// Number of controllers for this adapter
int iNumControllers;
/// Number of displays for this adapter
int iNumDisplays;
/// Number of overlays for this adapter
int iNumOverlays;
/// Number of GLSyncConnectors
int iNumOfGLSyncConnectors;
/// The bit mask identifies the adapter caps
int iCapsMask;
/// The bit identifies the adapter caps \ref define_adapter_caps
int iCapsValue;
}ADLAdapterCaps;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing additional information about the ASIC memory
///
/// This structure is used to store additional information about the ASIC memory. This
/// information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMemoryInfo2
{
/// Memory size in bytes.
long long iMemorySize;
/// Memory type in string.
char strMemoryType[ADL_MAX_PATH];
/// Highest default performance level Memory bandwidth in Mbytes/s
long long iMemoryBandwidth;
/// HyperMemory size in bytes.
long long iHyperMemorySize;
/// Invisible Memory size in bytes.
long long iInvisibleMemorySize;
/// Visible Memory size in bytes.
long long iVisibleMemorySize;
} ADLMemoryInfo2, *LPADLMemoryInfo2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing additional information about the ASIC memory
///
/// This structure is used to store additional information about the ASIC memory. This
/// information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMemoryInfo3
{
/// Memory size in bytes.
long long iMemorySize;
/// Memory type in string.
char strMemoryType[ADL_MAX_PATH];
/// Highest default performance level Memory bandwidth in Mbytes/s
long long iMemoryBandwidth;
/// HyperMemory size in bytes.
long long iHyperMemorySize;
/// Invisible Memory size in bytes.
long long iInvisibleMemorySize;
/// Visible Memory size in bytes.
long long iVisibleMemorySize;
/// Vram vendor ID
long long iVramVendorRevId;
} ADLMemoryInfo3, *LPADLMemoryInfo3;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing additional information about the ASIC memory
///
/// This structure is used to store additional information about the ASIC memory. This
/// information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMemoryInfoX4
{
/// Memory size in bytes.
long long iMemorySize;
/// Memory type in string.
char strMemoryType[ADL_MAX_PATH];
/// Highest default performance level Memory bandwidth in Mbytes/s
long long iMemoryBandwidth;
/// HyperMemory size in bytes.
long long iHyperMemorySize;
/// Invisible Memory size in bytes.
long long iInvisibleMemorySize;
/// Visible Memory size in bytes.
long long iVisibleMemorySize;
/// Vram vendor ID
long long iVramVendorRevId;
/// Memory Bandiwidth that is calculated and finalized on the driver side, grab and go.
long long iMemoryBandwidthX2;
/// Memory Bit Rate that is calculated and finalized on the driver side, grab and go.
long long iMemoryBitRateX2;
} ADLMemoryInfoX4, *LPADLMemoryInfoX4;
///////////////////////////////////////////////////////////////////////////
// ADLvRamVendor Enumeration
///////////////////////////////////////////////////////////////////////////
enum ADLvRamVendors
{
ADLvRamVendor_Unsupported = 0x0,
ADLvRamVendor_SAMSUNG,
ADLvRamVendor_INFINEON,
ADLvRamVendor_ELPIDA,
ADLvRamVendor_ETRON,
ADLvRamVendor_NANYA,
ADLvRamVendor_HYNIX,
ADLvRamVendor_MOSEL,
ADLvRamVendor_WINBOND,
ADLvRamVendor_ESMT,
ADLvRamVendor_MICRON = 0xF,
ADLvRamVendor_Undefined
};
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about components of ASIC GCN architecture
///
/// Elements of GCN info are compute units, number of Tex (Texture filtering units) , number of ROPs (render back-ends).
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGcnInfo
{
int CuCount; //Number of compute units on the ASIC.
int TexCount; //Number of texture mapping units.
int RopCount; //Number of Render backend Units.
int ASICFamilyId; //Such SI, VI. See /inc/asic_reg/atiid.h for family ids
int ASICRevisionId; //Such as Ellesmere, Fiji. For example - VI family revision ids are stored in /inc/asic_reg/vi_id.h
}ADLGcnInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related virtual segment config information.
///
/// This structure is used to store information related virtual segment config
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLVirtualSegmentSettingsOutput
{
int virtualSegmentSupported; // 1 - subsequent values are valid
int virtualSegmentDefault; //virtual segment default, 1: enable, 0: disable
int virtualSegmentCurrent; //virtual segment current, 1: enable, 0: disable
int iMinSizeInMB; //minimum value
int iMaxSizeInMB; //maximum value
int icurrentSizeInMB; //last configured otherwise same as factory default
int idefaultSizeInMB; //factory default
int iMask; //fileds for extension in the future
int iValue; //fileds for extension in the future
} ADLVirtualSegmentSettingsOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about the Chipset.
///
/// This structure is used to store various information about the Chipset. This
/// information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLChipSetInfo
{
int iBusType; ///< Bus type.
int iBusSpeedType; ///Maximum Bus Speed of the current platform
int iMaxPCIELaneWidth; ///< Number of PCIE lanes.
int iCurrentPCIELaneWidth; ///< Current PCIE Lane Width
int iSupportedAGPSpeeds; ///< Bit mask or AGP transfer speed.
int iCurrentAGPSpeed; ///< Current AGP speed
} ADLChipSetInfo, *LPADLChipSetInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the ASIC memory.
///
/// This structure is used to store various information about the ASIC memory. This
/// information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMemoryInfo
{
/// Memory size in bytes.
long long iMemorySize;
/// Memory type in string.
char strMemoryType[ADL_MAX_PATH];
/// Memory bandwidth in Mbytes/s.
long long iMemoryBandwidth;
} ADLMemoryInfo, *LPADLMemoryInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about memory required by type
///
/// This structure is returned by ADL_Adapter_ConfigMemory_Get, which given a desktop and display configuration
/// will return the Memory used.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMemoryRequired
{
long long iMemoryReq; /// Memory in bytes required
int iType; /// Type of Memory \ref define_adl_validmemoryrequiredfields
int iDisplayFeatureValue; /// Display features \ref define_adl_visiblememoryfeatures that are using this type of memory
} ADLMemoryRequired, *LPADLMemoryRequired;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the features associated with a display
///
/// This structure is a parameter to ADL_Adapter_ConfigMemory_Get, which given a desktop and display configuration
/// will return the Memory used.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMemoryDisplayFeatures
{
int iDisplayIndex; /// ADL Display index
int iDisplayFeatureValue; /// features that the display is using \ref define_adl_visiblememoryfeatures
} ADLMemoryDisplayFeatures, *LPADLMemoryDisplayFeatures;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing DDC information.
///
/// This structure is used to store various DDC information that can be returned to the user.
/// Note that all fields of type int are actually defined as unsigned int types within the driver.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDDCInfo
{
/// Size of the structure
int ulSize;
/// Indicates whether the attached display supports DDC. If this field is zero on return, no other DDC information fields will be used.
int ulSupportsDDC;
/// Returns the manufacturer ID of the display device. Should be zeroed if this information is not available.
int ulManufacturerID;
/// Returns the product ID of the display device. Should be zeroed if this information is not available.
int ulProductID;
/// Returns the name of the display device. Should be zeroed if this information is not available.
char cDisplayName[ADL_MAX_DISPLAY_NAME];
/// Returns the maximum Horizontal supported resolution. Should be zeroed if this information is not available.
int ulMaxHResolution;
/// Returns the maximum Vertical supported resolution. Should be zeroed if this information is not available.
int ulMaxVResolution;
/// Returns the maximum supported refresh rate. Should be zeroed if this information is not available.
int ulMaxRefresh;
/// Returns the display device preferred timing mode's horizontal resolution.
int ulPTMCx;
/// Returns the display device preferred timing mode's vertical resolution.
int ulPTMCy;
/// Returns the display device preferred timing mode's refresh rate.
int ulPTMRefreshRate;
/// Return EDID flags.
int ulDDCInfoFlag;
} ADLDDCInfo, *LPADLDDCInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing DDC information.
///
/// This structure is used to store various DDC information that can be returned to the user.
/// Note that all fields of type int are actually defined as unsigned int types within the driver.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDDCInfo2
{
/// Size of the structure
int ulSize;
/// Indicates whether the attached display supports DDC. If this field is zero on return, no other DDC
/// information fields will be used.
int ulSupportsDDC;
/// Returns the manufacturer ID of the display device. Should be zeroed if this information is not available.
int ulManufacturerID;
/// Returns the product ID of the display device. Should be zeroed if this information is not available.
int ulProductID;
/// Returns the name of the display device. Should be zeroed if this information is not available.
char cDisplayName[ADL_MAX_DISPLAY_NAME];
/// Returns the maximum Horizontal supported resolution. Should be zeroed if this information is not available.
int ulMaxHResolution;
/// Returns the maximum Vertical supported resolution. Should be zeroed if this information is not available.
int ulMaxVResolution;
/// Returns the maximum supported refresh rate. Should be zeroed if this information is not available.
int ulMaxRefresh;
/// Returns the display device preferred timing mode's horizontal resolution.
int ulPTMCx;
/// Returns the display device preferred timing mode's vertical resolution.
int ulPTMCy;
/// Returns the display device preferred timing mode's refresh rate.
int ulPTMRefreshRate;
/// Return EDID flags.
int ulDDCInfoFlag;
/// Returns 1 if the display supported packed pixel, 0 otherwise
int bPackedPixelSupported;
/// Returns the Pixel formats the display supports \ref define_ddcinfo_pixelformats
int iPanelPixelFormat;
/// Return EDID serial ID.
int ulSerialID;
/// Return minimum monitor luminance data
int ulMinLuminanceData;
/// Return average monitor luminance data
int ulAvgLuminanceData;
/// Return maximum monitor luminance data
int ulMaxLuminanceData;
/// Bit vector of supported transfer functions \ref define_source_content_TF
int iSupportedTransferFunction;
/// Bit vector of supported color spaces \ref define_source_content_CS
int iSupportedColorSpace;
/// Display Red Chromaticity X coordinate multiplied by 10000
int iNativeDisplayChromaticityRedX;
/// Display Red Chromaticity Y coordinate multiplied by 10000
int iNativeDisplayChromaticityRedY;
/// Display Green Chromaticity X coordinate multiplied by 10000
int iNativeDisplayChromaticityGreenX;
/// Display Green Chromaticity Y coordinate multiplied by 10000
int iNativeDisplayChromaticityGreenY;
/// Display Blue Chromaticity X coordinate multiplied by 10000
int iNativeDisplayChromaticityBlueX;
/// Display Blue Chromaticity Y coordinate multiplied by 10000
int iNativeDisplayChromaticityBlueY;
/// Display White Point X coordinate multiplied by 10000
int iNativeDisplayChromaticityWhitePointX;
/// Display White Point Y coordinate multiplied by 10000
int iNativeDisplayChromaticityWhitePointY;
/// Display diffuse screen reflectance 0-1 (100%) in units of 0.01
int iDiffuseScreenReflectance;
/// Display specular screen reflectance 0-1 (100%) in units of 0.01
int iSpecularScreenReflectance;
/// Bit vector of supported color spaces \ref define_HDR_support
int iSupportedHDR;
/// Bit vector for freesync flags
int iFreesyncFlags;
/// Return minimum monitor luminance without dimming data
int ulMinLuminanceNoDimmingData;
int ulMaxBacklightMaxLuminanceData;
int ulMinBacklightMaxLuminanceData;
int ulMaxBacklightMinLuminanceData;
int ulMinBacklightMinLuminanceData;
// Reserved for future use
int iReserved[4];
} ADLDDCInfo2, *LPADLDDCInfo2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information controller Gamma settings.
///
/// This structure is used to store the red, green and blue color channel information for the.
/// controller gamma setting. This information is returned by ADL, and it can also be used to
/// set the controller gamma setting.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGamma
{
/// Red color channel gamma value.
float fRed;
/// Green color channel gamma value.
float fGreen;
/// Blue color channel gamma value.
float fBlue;
} ADLGamma, *LPADLGamma;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about component video custom modes.
///
/// This structure is used to store the component video custom mode.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLCustomMode
{
/// Custom mode flags. They are returned by the ADL driver.
int iFlags;
/// Custom mode width.
int iModeWidth;
/// Custom mode height.
int iModeHeight;
/// Custom mode base width.
int iBaseModeWidth;
/// Custom mode base height.
int iBaseModeHeight;
/// Custom mode refresh rate.
int iRefreshRate;
} ADLCustomMode, *LPADLCustomMode;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing Clock information for OD5 calls.
///
/// This structure is used to retrieve clock information for OD5 calls.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGetClocksOUT
{
long ulHighCoreClock;
long ulHighMemoryClock;
long ulHighVddc;
long ulCoreMin;
long ulCoreMax;
long ulMemoryMin;
long ulMemoryMax;
long ulActivityPercent;
long ulCurrentCoreClock;
long ulCurrentMemoryClock;
long ulReserved;
} ADLGetClocksOUT;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing HDTV information for display calls.
///
/// This structure is used to retrieve HDTV information information for display calls.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayConfig
{
/// Size of the structure
long ulSize;
/// HDTV connector type.
long ulConnectorType;
/// HDTV capabilities.
long ulDeviceData;
/// Overridden HDTV capabilities.
long ulOverridedDeviceData;
/// Reserved field
long ulReserved;
} ADLDisplayConfig;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display device.
///
/// This structure is used to store display device information
/// such as display index, type, name, connection status, mapped adapter and controller indexes,
/// whether or not multiple VPUs are supported, local display connections or not (through Lasso), etc.
/// This information can be returned to the user. Alternatively, it can be used to access various driver calls to set
/// or fetch various display device related settings upon the user's request.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayID
{
/// The logical display index belonging to this adapter.
int iDisplayLogicalIndex;
///\brief The physical display index.
/// For example, display index 2 from adapter 2 can be used by current adapter 1.\n
/// So current adapter may enumerate this adapter as logical display 7 but the physical display
/// index is still 2.
int iDisplayPhysicalIndex;
/// The persistent logical adapter index for the display.
int iDisplayLogicalAdapterIndex;
///\brief The persistent physical adapter index for the display.
/// It can be the current adapter or a non-local adapter. \n
/// If this adapter index is different than the current adapter,
/// the Display Non Local flag is set inside DisplayInfoValue.
int iDisplayPhysicalAdapterIndex;
} ADLDisplayID, *LPADLDisplayID;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display device.
///
/// This structure is used to store various information about the display device. This
/// information can be returned to the user, or used to access various driver calls to set
/// or fetch various display-device-related settings upon the user's request
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayInfo
{
/// The DisplayID structure
ADLDisplayID displayID;
///\deprecated The controller index to which the display is mapped.\n Will not be used in the future\n
int iDisplayControllerIndex;
/// The display's EDID name.
char strDisplayName[ADL_MAX_PATH];
/// The display's manufacturer name.
char strDisplayManufacturerName[ADL_MAX_PATH];
/// The Display type. For example: CRT, TV, CV, DFP.
int iDisplayType;
/// The display output type. For example: HDMI, SVIDEO, COMPONMNET VIDEO.
int iDisplayOutputType;
/// The connector type for the device.
int iDisplayConnector;
///\brief The bit mask identifies the number of bits ADLDisplayInfo is currently using. \n
/// It will be the sum all the bit definitions in ADL_DISPLAY_DISPLAYINFO_xxx.
int iDisplayInfoMask;
/// The bit mask identifies the display status. \ref define_displayinfomask
int iDisplayInfoValue;
} ADLDisplayInfo, *LPADLDisplayInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display port MST device.
///
/// This structure is used to store various MST information about the display port device. This
/// information can be returned to the user, or used to access various driver calls to
/// fetch various display-device-related settings upon the user's request
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayDPMSTInfo
{
/// The ADLDisplayID structure
ADLDisplayID displayID;
/// total bandwidth available on the DP connector
int iTotalAvailableBandwidthInMpbs;
/// bandwidth allocated to this display
int iAllocatedBandwidthInMbps;
// info from DAL DpMstSinkInfo
/// string identifier for the display
char strGlobalUniqueIdentifier[ADL_MAX_PATH];
/// The link count of relative address, rad[0] upto rad[linkCount] are valid
int radLinkCount;
/// The physical connector ID, used to identify the physical DP port
int iPhysicalConnectorID;
/// Relative address, address scheme starts from source side
char rad[ADL_MAX_RAD_LINK_COUNT];
} ADLDisplayDPMSTInfo, *LPADLDisplayDPMSTInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the display mode definition used per controller.
///
/// This structure is used to store the display mode definition used per controller.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayMode
{
/// Vertical resolution (in pixels).
int iPelsHeight;
/// Horizontal resolution (in pixels).
int iPelsWidth;
/// Color depth.
int iBitsPerPel;
/// Refresh rate.
int iDisplayFrequency;
} ADLDisplayMode;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing detailed timing parameters.
///
/// This structure is used to store the detailed timing parameters.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDetailedTiming
{
/// Size of the structure.
int iSize;
/// Timing flags. \ref define_detailed_timing_flags
short sTimingFlags;
/// Total width (columns).
short sHTotal;
/// Displayed width.
short sHDisplay;
/// Horizontal sync signal offset.
short sHSyncStart;
/// Horizontal sync signal width.
short sHSyncWidth;
/// Total height (rows).
short sVTotal;
/// Displayed height.
short sVDisplay;
/// Vertical sync signal offset.
short sVSyncStart;
/// Vertical sync signal width.
short sVSyncWidth;
/// Pixel clock value.
short sPixelClock;
/// Overscan right.
short sHOverscanRight;
/// Overscan left.
short sHOverscanLeft;
/// Overscan bottom.
short sVOverscanBottom;
/// Overscan top.
short sVOverscanTop;
short sOverscan8B;
short sOverscanGR;
} ADLDetailedTiming;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing display mode information.
///
/// This structure is used to store the display mode information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayModeInfo
{
/// Timing standard of the current mode. \ref define_modetiming_standard
int iTimingStandard;
/// Applicable timing standards for the current mode.
int iPossibleStandard;
/// Refresh rate factor.
int iRefreshRate;
/// Num of pixels in a row.
int iPelsWidth;
/// Num of pixels in a column.
int iPelsHeight;
/// Detailed timing parameters.
ADLDetailedTiming sDetailedTiming;
} ADLDisplayModeInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about display property.
///
/// This structure is used to store the display property for the current adapter.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayProperty
{
/// Must be set to sizeof the structure
int iSize;
/// Must be set to \ref ADL_DL_DISPLAYPROPERTY_TYPE_EXPANSIONMODE or \ref ADL_DL_DISPLAYPROPERTY_TYPE_USEUNDERSCANSCALING
int iPropertyType;
/// Get or Set \ref ADL_DL_DISPLAYPROPERTY_EXPANSIONMODE_CENTER or \ref ADL_DL_DISPLAYPROPERTY_EXPANSIONMODE_FULLSCREEN or \ref ADL_DL_DISPLAYPROPERTY_EXPANSIONMODE_ASPECTRATIO or \ref ADL_DL_DISPLAYPROPERTY_TYPE_ITCFLAGENABLE
int iExpansionMode;
/// Display Property supported? 1: Supported, 0: Not supported
int iSupport;
/// Display Property current value
int iCurrent;
/// Display Property Default value
int iDefault;
} ADLDisplayProperty;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Clock.
///
/// This structure is used to store the clock information for the current adapter
/// such as core clock and memory clock info.
///\nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLClockInfo
{
/// Core clock in 10 KHz.
int iCoreClock;
/// Memory clock in 10 KHz.
int iMemoryClock;
} ADLClockInfo, *LPADLClockInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about I2C.
///
/// This structure is used to store the I2C information for the current adapter.
/// This structure is used by the ADL_Display_WriteAndReadI2C() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLI2C
{
/// Size of the structure
int iSize;
/// Numerical value representing hardware I2C.
int iLine;
/// The 7-bit I2C slave device address, shifted one bit to the left.
int iAddress;
/// The offset of the data from the address.
int iOffset;
/// Read from or write to slave device. \ref ADL_DL_I2C_ACTIONREAD or \ref ADL_DL_I2C_ACTIONWRITE or \ref ADL_DL_I2C_ACTIONREAD_REPEATEDSTART
int iAction;
/// I2C clock speed in KHz.
int iSpeed;
/// A numerical value representing the number of bytes to be sent or received on the I2C bus.
int iDataSize;
/// Address of the characters which are to be sent or received on the I2C bus.
char *pcData;
} ADLI2C;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about EDID data.
///
/// This structure is used to store the information about EDID data for the adapter.
/// This structure is used by the ADL_Display_EdidData_Get() and ADL_Display_EdidData_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayEDIDData
{
/// Size of the structure
int iSize;
/// Set to 0
int iFlag;
/// Size of cEDIDData. Set by ADL_Display_EdidData_Get() upon return
int iEDIDSize;
/// 0, 1 or 2. If set to 3 or above an error ADL_ERR_INVALID_PARAM is generated
int iBlockIndex;
/// EDID data
char cEDIDData[ADL_MAX_EDIDDATA_SIZE];
/// Reserved
int iReserved[4];
}ADLDisplayEDIDData;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about input of controller overlay adjustment.
///
/// This structure is used to store the information about input of controller overlay adjustment for the adapter.
/// This structure is used by the ADL_Display_ControllerOverlayAdjustmentCaps_Get, ADL_Display_ControllerOverlayAdjustmentData_Get, and
/// ADL_Display_ControllerOverlayAdjustmentData_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLControllerOverlayInput
{
/// Should be set to the sizeof the structure
int iSize;
///\ref ADL_DL_CONTROLLER_OVERLAY_ALPHA or \ref ADL_DL_CONTROLLER_OVERLAY_ALPHAPERPIX
int iOverlayAdjust;
/// Data.
int iValue;
/// Should be 0.
int iReserved;
} ADLControllerOverlayInput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about overlay adjustment.
///
/// This structure is used to store the information about overlay adjustment for the adapter.
/// This structure is used by the ADLControllerOverlayInfo() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdjustmentinfo
{
/// Default value
int iDefault;
/// Minimum value
int iMin;
/// Maximum Value
int iMax;
/// Step value
int iStep;
} ADLAdjustmentinfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about controller overlay information.
///
/// This structure is used to store information about controller overlay info for the adapter.
/// This structure is used by the ADL_Display_ControllerOverlayAdjustmentCaps_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLControllerOverlayInfo
{
/// Should be set to the sizeof the structure
int iSize;
/// Data.
ADLAdjustmentinfo sOverlayInfo;
/// Should be 0.
int iReserved[3];
} ADLControllerOverlayInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync module information.
///
/// This structure is used to retrieve GL-Sync module information for
/// Workstation Framelock/Genlock.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGLSyncModuleID
{
/// Unique GL-Sync module ID.
int iModuleID;
/// GL-Sync GPU port index (to be passed into ADLGLSyncGenlockConfig.lSignalSource and ADLGlSyncPortControl.lSignalSource).
int iGlSyncGPUPort;
/// GL-Sync module firmware version of Boot Sector.
int iFWBootSectorVersion;
/// GL-Sync module firmware version of User Sector.
int iFWUserSectorVersion;
} ADLGLSyncModuleID , *LPADLGLSyncModuleID;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync ports capabilities.
///
/// This structure is used to retrieve hardware capabilities for the ports of the GL-Sync module
/// for Workstation Framelock/Genlock (such as port type and number of associated LEDs).
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGLSyncPortCaps
{
/// Port type. Bitfield of ADL_GLSYNC_PORTTYPE_* \ref define_glsync
int iPortType;
/// Number of LEDs associated for this port.
int iNumOfLEDs;
}ADLGLSyncPortCaps, *LPADLGLSyncPortCaps;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync Genlock settings.
///
/// This structure is used to get and set genlock settings for the GPU ports of the GL-Sync module
/// for Workstation Framelock/Genlock.\n
/// \see define_glsync
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGLSyncGenlockConfig
{
/// Specifies what fields in this structure are valid \ref define_glsync
int iValidMask;
/// Delay (ms) generating a sync signal.
int iSyncDelay;
/// Vector of framelock control bits. Bitfield of ADL_GLSYNC_FRAMELOCKCNTL_* \ref define_glsync
int iFramelockCntlVector;
/// Source of the sync signal. Either GL_Sync GPU Port index or ADL_GLSYNC_SIGNALSOURCE_* \ref define_glsync
int iSignalSource;
/// Use sampled sync signal. A value of 0 specifies no sampling.
int iSampleRate;
/// For interlaced sync signals, the value can be ADL_GLSYNC_SYNCFIELD_1 or *_BOTH \ref define_glsync
int iSyncField;
/// The signal edge that should trigger synchronization. ADL_GLSYNC_TRIGGEREDGE_* \ref define_glsync
int iTriggerEdge;
/// Scan rate multiplier applied to the sync signal. ADL_GLSYNC_SCANRATECOEFF_* \ref define_glsync
int iScanRateCoeff;
}ADLGLSyncGenlockConfig, *LPADLGLSyncGenlockConfig;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync port information.
///
/// This structure is used to get status of the GL-Sync ports (BNC or RJ45s)
/// for Workstation Framelock/Genlock.
/// \see define_glsync
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGlSyncPortInfo
{
/// Type of GL-Sync port (ADL_GLSYNC_PORT_*).
int iPortType;
/// The number of LEDs for this port. It's also filled within ADLGLSyncPortCaps.
int iNumOfLEDs;
/// Port state ADL_GLSYNC_PORTSTATE_* \ref define_glsync
int iPortState;
/// Scanned frequency for this port (vertical refresh rate in milliHz; 60000 means 60 Hz).
int iFrequency;
/// Used for ADL_GLSYNC_PORT_BNC. It is ADL_GLSYNC_SIGNALTYPE_* \ref define_glsync
int iSignalType;
/// Used for ADL_GLSYNC_PORT_RJ45PORT*. It is GL_Sync GPU Port index or ADL_GLSYNC_SIGNALSOURCE_*. \ref define_glsync
int iSignalSource;
} ADLGlSyncPortInfo, *LPADLGlSyncPortInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync port control settings.
///
/// This structure is used to configure the GL-Sync ports (RJ45s only)
/// for Workstation Framelock/Genlock.
/// \see define_glsync
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGlSyncPortControl
{
/// Port to control ADL_GLSYNC_PORT_RJ45PORT1 or ADL_GLSYNC_PORT_RJ45PORT2 \ref define_glsync
int iPortType;
/// Port control data ADL_GLSYNC_PORTCNTL_* \ref define_glsync
int iControlVector;
/// Source of the sync signal. Either GL_Sync GPU Port index or ADL_GLSYNC_SIGNALSOURCE_* \ref define_glsync
int iSignalSource;
} ADLGlSyncPortControl;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync mode of a display.
///
/// This structure is used to get and set GL-Sync mode settings for a display connected to
/// an adapter attached to a GL-Sync module for Workstation Framelock/Genlock.
/// \see define_glsync
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGlSyncMode
{
/// Mode control vector. Bitfield of ADL_GLSYNC_MODECNTL_* \ref define_glsync
int iControlVector;
/// Mode status vector. Bitfield of ADL_GLSYNC_MODECNTL_STATUS_* \ref define_glsync
int iStatusVector;
/// Index of GL-Sync connector used to genlock the display/controller.
int iGLSyncConnectorIndex;
} ADLGlSyncMode, *LPADLGlSyncMode;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing GL-Sync mode of a display.
///
/// This structure is used to get and set GL-Sync mode settings for a display connected to
/// an adapter attached to a GL-Sync module for Workstation Framelock/Genlock.
/// \see define_glsync
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGlSyncMode2
{
/// Mode control vector. Bitfield of ADL_GLSYNC_MODECNTL_* \ref define_glsync
int iControlVector;
/// Mode status vector. Bitfield of ADL_GLSYNC_MODECNTL_STATUS_* \ref define_glsync
int iStatusVector;
/// Index of GL-Sync connector used to genlock the display/controller.
int iGLSyncConnectorIndex;
/// Index of the display to which this GLSync applies to.
int iDisplayIndex;
} ADLGlSyncMode2, *LPADLGlSyncMode2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the packet info of a display.
///
/// This structure is used to get and set the packet information of a display.
/// This structure is used by ADLDisplayDataPacket.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLInfoPacket
{
char hb0;
char hb1;
char hb2;
/// sb0~sb27
char sb[28];
}ADLInfoPacket;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the AVI packet info of a display.
///
/// This structure is used to get and set AVI the packet info of a display.
/// This structure is used by ADLDisplayDataPacket.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAVIInfoPacket //Valid user defined data/
{
/// byte 3, bit 7
char bPB3_ITC;
/// byte 5, bit [7:4].
char bPB5;
}ADLAVIInfoPacket;
// Overdrive clock setting structure definition.
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the Overdrive clock setting.
///
/// This structure is used to get the Overdrive clock setting.
/// This structure is used by ADLAdapterODClockInfo.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODClockSetting
{
/// Deafult clock
int iDefaultClock;
/// Current clock
int iCurrentClock;
/// Maximum clcok
int iMaxClock;
/// Minimum clock
int iMinClock;
/// Requested clcock
int iRequestedClock;
/// Step
int iStepClock;
} ADLODClockSetting;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the Overdrive clock information.
///
/// This structure is used to get the Overdrive clock information.
/// This structure is used by the ADL_Display_ODClockInfo_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdapterODClockInfo
{
/// Size of the structure
int iSize;
/// Flag \ref define_clockinfo_flags
int iFlags;
/// Memory Clock
ADLODClockSetting sMemoryClock;
/// Engine Clock
ADLODClockSetting sEngineClock;
} ADLAdapterODClockInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the Overdrive clock configuration.
///
/// This structure is used to set the Overdrive clock configuration.
/// This structure is used by the ADL_Display_ODClockConfig_Set() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdapterODClockConfig
{
/// Size of the structure
int iSize;
/// Flag \ref define_clockinfo_flags
int iFlags;
/// Memory Clock
int iMemoryClock;
/// Engine Clock
int iEngineClock;
} ADLAdapterODClockConfig;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about current power management related activity.
///
/// This structure is used to store information about current power management related activity.
/// This structure (Overdrive 5 interfaces) is used by the ADL_PM_CurrentActivity_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPMActivity
{
/// Must be set to the size of the structure
int iSize;
/// Current engine clock.
int iEngineClock;
/// Current memory clock.
int iMemoryClock;
/// Current core voltage.
int iVddc;
/// GPU utilization.
int iActivityPercent;
/// Performance level index.
int iCurrentPerformanceLevel;
/// Current PCIE bus speed.
int iCurrentBusSpeed;
/// Number of PCIE bus lanes.
int iCurrentBusLanes;
/// Maximum number of PCIE bus lanes.
int iMaximumBusLanes;
/// Reserved for future purposes.
int iReserved;
} ADLPMActivity;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about thermal controller.
///
/// This structure is used to store information about thermal controller.
/// This structure is used by ADL_PM_ThermalDevices_Enum.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLThermalControllerInfo
{
/// Must be set to the size of the structure
int iSize;
/// Possible valies: \ref ADL_DL_THERMAL_DOMAIN_OTHER or \ref ADL_DL_THERMAL_DOMAIN_GPU.
int iThermalDomain;
/// GPU 0, 1, etc.
int iDomainIndex;
/// Possible valies: \ref ADL_DL_THERMAL_FLAG_INTERRUPT or \ref ADL_DL_THERMAL_FLAG_FANCONTROL
int iFlags;
} ADLThermalControllerInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about thermal controller temperature.
///
/// This structure is used to store information about thermal controller temperature.
/// This structure is used by the ADL_PM_Temperature_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLTemperature
{
/// Must be set to the size of the structure
int iSize;
/// Temperature in millidegrees Celsius.
int iTemperature;
} ADLTemperature;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about thermal controller fan speed.
///
/// This structure is used to store information about thermal controller fan speed.
/// This structure is used by the ADL_PM_FanSpeedInfo_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFanSpeedInfo
{
/// Must be set to the size of the structure
int iSize;
/// \ref define_fanctrl
int iFlags;
/// Minimum possible fan speed value in percents.
int iMinPercent;
/// Maximum possible fan speed value in percents.
int iMaxPercent;
/// Minimum possible fan speed value in RPM.
int iMinRPM;
/// Maximum possible fan speed value in RPM.
int iMaxRPM;
} ADLFanSpeedInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about fan speed reported by thermal controller.
///
/// This structure is used to store information about fan speed reported by thermal controller.
/// This structure is used by the ADL_Overdrive5_FanSpeed_Get() and ADL_Overdrive5_FanSpeed_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFanSpeedValue
{
/// Must be set to the size of the structure
int iSize;
/// Possible valies: \ref ADL_DL_FANCTRL_SPEED_TYPE_PERCENT or \ref ADL_DL_FANCTRL_SPEED_TYPE_RPM
int iSpeedType;
/// Fan speed value
int iFanSpeed;
/// The only flag for now is: \ref ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED
int iFlags;
} ADLFanSpeedValue;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the range of Overdrive parameter.
///
/// This structure is used to store information about the range of Overdrive parameter.
/// This structure is used by ADLODParameters.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODParameterRange
{
/// Minimum parameter value.
int iMin;
/// Maximum parameter value.
int iMax;
/// Parameter step value.
int iStep;
} ADLODParameterRange;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive parameters.
///
/// This structure is used to store information about Overdrive parameters.
/// This structure is used by the ADL_Overdrive5_ODParameters_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODParameters
{
/// Must be set to the size of the structure
int iSize;
/// Number of standard performance states.
int iNumberOfPerformanceLevels;
/// Indicates whether the GPU is capable to measure its activity.
int iActivityReportingSupported;
/// Indicates whether the GPU supports discrete performance levels or performance range.
int iDiscretePerformanceLevels;
/// Reserved for future use.
int iReserved;
/// Engine clock range.
ADLODParameterRange sEngineClock;
/// Memory clock range.
ADLODParameterRange sMemoryClock;
/// Core voltage range.
ADLODParameterRange sVddc;
} ADLODParameters;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive level.
///
/// This structure is used to store information about Overdrive level.
/// This structure is used by ADLODPerformanceLevels.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODPerformanceLevel
{
/// Engine clock.
int iEngineClock;
/// Memory clock.
int iMemoryClock;
/// Core voltage.
int iVddc;
} ADLODPerformanceLevel;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive performance levels.
///
/// This structure is used to store information about Overdrive performance levels.
/// This structure is used by the ADL_Overdrive5_ODPerformanceLevels_Get() and ADL_Overdrive5_ODPerformanceLevels_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODPerformanceLevels
{
/// Must be set to sizeof( \ref ADLODPerformanceLevels ) + sizeof( \ref ADLODPerformanceLevel ) * (ADLODParameters.iNumberOfPerformanceLevels - 1)
int iSize;
int iReserved;
/// Array of performance state descriptors. Must have ADLODParameters.iNumberOfPerformanceLevels elements.
ADLODPerformanceLevel aLevels [1];
} ADLODPerformanceLevels;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the proper CrossfireX chains combinations.
///
/// This structure is used to store information about the CrossfireX chains combination for a particular adapter.
/// This structure is used by the ADL_Adapter_Crossfire_Caps(), ADL_Adapter_Crossfire_Get(), and ADL_Adapter_Crossfire_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLCrossfireComb
{
/// Number of adapters in this combination.
int iNumLinkAdapter;
/// A list of ADL indexes of the linked adapters in this combination.
int iAdaptLink[3];
} ADLCrossfireComb;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing CrossfireX state and error information.
///
/// This structure is used to store state and error information about a particular adapter CrossfireX combination.
/// This structure is used by the ADL_Adapter_Crossfire_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLCrossfireInfo
{
/// Current error code of this CrossfireX combination.
int iErrorCode;
/// Current \ref define_crossfirestate
int iState;
/// If CrossfireX is supported by this combination. The value is either \ref ADL_TRUE or \ref ADL_FALSE.
int iSupported;
} ADLCrossfireInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about the BIOS.
///
/// This structure is used to store various information about the Chipset. This
/// information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLBiosInfo
{
char strPartNumber[ADL_MAX_PATH]; ///< Part number.
char strVersion[ADL_MAX_PATH]; ///< Version number.
char strDate[ADL_MAX_PATH]; ///< BIOS date in yyyy/mm/dd hh:mm format.
} ADLBiosInfo, *LPADLBiosInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about adapter location.
///
/// This structure is used to store information about adapter location.
/// This structure is used by ADLMVPUStatus.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdapterLocation
{
/// PCI Bus number : 8 bits
int iBus;
/// Device number : 5 bits
int iDevice;
/// Function number : 3 bits
int iFunction;
} ADLAdapterLocation,ADLBdf;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing version information
///
/// This structure is used to store software version information, description of the display device and a web link to the latest installed Catalyst drivers.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLVersionsInfo
{
/// Driver Release (Packaging) Version (e.g. 8.71-100128n-094835E-ATI)
char strDriverVer[ADL_MAX_PATH];
/// Catalyst Version(e.g. "10.1").
char strCatalystVersion[ADL_MAX_PATH];
/// Web link to an XML file with information about the latest AMD drivers and locations (e.g. "http://www.amd.com/us/driverxml" )
char strCatalystWebLink[ADL_MAX_PATH];
} ADLVersionsInfo, *LPADLVersionsInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing version information
///
/// This structure is used to store software version information, description of the display device and a web link to the latest installed Catalyst drivers.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLVersionsInfoX2
{
/// Driver Release (Packaging) Version (e.g. "16.20.1035-160621a-303814C")
char strDriverVer[ADL_MAX_PATH];
/// Catalyst Version(e.g. "15.8").
char strCatalystVersion[ADL_MAX_PATH];
/// Crimson Version(e.g. "16.6.2").
char strCrimsonVersion[ADL_MAX_PATH];
/// Web link to an XML file with information about the latest AMD drivers and locations (e.g. "http://support.amd.com/drivers/xml/driver_09_us.xml" )
char strCatalystWebLink[ADL_MAX_PATH];
} ADLVersionsInfoX2, *LPADLVersionsInfoX2;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about MultiVPU capabilities.
///
/// This structure is used to store information about MultiVPU capabilities.
/// This structure is used by the ADL_Display_MVPUCaps_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMVPUCaps
{
/// Must be set to sizeof( ADLMVPUCaps ).
int iSize;
/// Number of adapters.
int iAdapterCount;
/// Bits set for all possible MVPU masters. \ref MVPU_ADAPTER_0 .. \ref MVPU_ADAPTER_3
int iPossibleMVPUMasters;
/// Bits set for all possible MVPU slaves. \ref MVPU_ADAPTER_0 .. \ref MVPU_ADAPTER_3
int iPossibleMVPUSlaves;
/// Registry path for each adapter.
char cAdapterPath[ADL_DL_MAX_MVPU_ADAPTERS][ADL_DL_MAX_REGISTRY_PATH];
} ADLMVPUCaps;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about MultiVPU status.
///
/// This structure is used to store information about MultiVPU status.
/// Ths structure is used by the ADL_Display_MVPUStatus_Get() function.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMVPUStatus
{
/// Must be set to sizeof( ADLMVPUStatus ).
int iSize;
/// Number of active adapters.
int iActiveAdapterCount;
/// MVPU status.
int iStatus;
/// PCI Bus/Device/Function for each active adapter participating in MVPU.
ADLAdapterLocation aAdapterLocation[ADL_DL_MAX_MVPU_ADAPTERS];
} ADLMVPUStatus;
// Displays Manager structures
///////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about the activatable source.
///
/// This structure is used to store activatable source information
/// This information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLActivatableSource
{
/// The Persistent logical Adapter Index.
int iAdapterIndex;
/// The number of Activatable Sources.
int iNumActivatableSources;
/// The bit mask identifies the number of bits ActivatableSourceValue is using. (Not currnetly used)
int iActivatableSourceMask;
/// The bit mask identifies the status. (Not currnetly used)
int iActivatableSourceValue;
} ADLActivatableSource, *LPADLActivatableSource;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about display mode.
///
/// This structure is used to store the display mode for the current adapter
/// such as X, Y positions, screen resolutions, orientation,
/// color depth, refresh rate, progressive or interlace mode, etc.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMode
{
/// Adapter index.
int iAdapterIndex;
/// Display IDs.
ADLDisplayID displayID;
/// Screen position X coordinate.
int iXPos;
/// Screen position Y coordinate.
int iYPos;
/// Screen resolution Width.
int iXRes;
/// Screen resolution Height.
int iYRes;
/// Screen Color Depth. E.g., 16, 32.
int iColourDepth;
/// Screen refresh rate. Could be fractional E.g. 59.97
float fRefreshRate;
/// Screen orientation. E.g., 0, 90, 180, 270.
int iOrientation;
/// Vista mode flag indicating Progressive or Interlaced mode.
int iModeFlag;
/// The bit mask identifying the number of bits this Mode is currently using. It is the sum of all the bit definitions defined in \ref define_displaymode
int iModeMask;
/// The bit mask identifying the display status. The detailed definition is in \ref define_displaymode
int iModeValue;
} ADLMode, *LPADLMode;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about display target information.
///
/// This structure is used to store the display target information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayTarget
{
/// The Display ID.
ADLDisplayID displayID;
/// The display map index identify this manner and the desktop surface.
int iDisplayMapIndex;
/// The bit mask identifies the number of bits DisplayTarget is currently using. It is the sum of all the bit definitions defined in \ref ADL_DISPLAY_DISPLAYTARGET_PREFERRED.
int iDisplayTargetMask;
/// The bit mask identifies the display status. The detailed definition is in \ref ADL_DISPLAY_DISPLAYTARGET_PREFERRED.
int iDisplayTargetValue;
} ADLDisplayTarget, *LPADLDisplayTarget;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display SLS bezel Mode information.
///
/// This structure is used to store the display SLS bezel Mode information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct tagADLBezelTransientMode
{
/// Adapter Index
int iAdapterIndex;
/// SLS Map Index
int iSLSMapIndex;
/// The mode index
int iSLSModeIndex;
/// The mode
ADLMode displayMode;
/// The number of bezel offsets belongs to this map
int iNumBezelOffset;
/// The first bezel offset array index in the native mode array
int iFirstBezelOffsetArrayIndex;
/// The bit mask identifies the bits this structure is currently using. It will be the total OR of all the bit definitions.
int iSLSBezelTransientModeMask;
/// The bit mask identifies the display status. The detail definition is defined below.
int iSLSBezelTransientModeValue;
} ADLBezelTransientMode, *LPADLBezelTransientMode;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about the adapter display manner.
///
/// This structure is used to store adapter display manner information
/// This information can be returned to the user. Alternatively, it can be used to access various driver calls to
/// fetch various display device related display manner settings upon the user's request.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdapterDisplayCap
{
/// The Persistent logical Adapter Index.
int iAdapterIndex;
/// The bit mask identifies the number of bits AdapterDisplayCap is currently using. Sum all the bits defined in ADL_ADAPTER_DISPLAYCAP_XXX
int iAdapterDisplayCapMask;
/// The bit mask identifies the status. Refer to ADL_ADAPTER_DISPLAYCAP_XXX
int iAdapterDisplayCapValue;
} ADLAdapterDisplayCap, *LPADLAdapterDisplayCap;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about display mapping.
///
/// This structure is used to store the display mapping data such as display manner.
/// For displays with horizontal or vertical stretch manner,
/// this structure also stores the display order, display row, and column data.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayMap
{
/// The current display map index. It is the OS desktop index. For example, if the OS index 1 is showing clone mode, the display map will be 1.
int iDisplayMapIndex;
/// The Display Mode for the current map
ADLMode displayMode;
/// The number of display targets belongs to this map\n
int iNumDisplayTarget;
/// The first target array index in the Target array\n
int iFirstDisplayTargetArrayIndex;
/// The bit mask identifies the number of bits DisplayMap is currently using. It is the sum of all the bit definitions defined in ADL_DISPLAY_DISPLAYMAP_MANNER_xxx.
int iDisplayMapMask;
///The bit mask identifies the display status. The detailed definition is in ADL_DISPLAY_DISPLAYMAP_MANNER_xxx.
int iDisplayMapValue;
} ADLDisplayMap, *LPADLDisplayMap;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about the display device possible map for one GPU
///
/// This structure is used to store the display device possible map
/// This information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPossibleMap
{
/// The current PossibleMap index. Each PossibleMap is assigned an index
int iIndex;
/// The adapter index identifying the GPU for which to validate these Maps & Targets
int iAdapterIndex;
/// Number of display Maps for this GPU to be validated
int iNumDisplayMap;
/// The display Maps list to validate
ADLDisplayMap* displayMap;
/// the number of display Targets for these display Maps
int iNumDisplayTarget;
/// The display Targets list for these display Maps to be validated.
ADLDisplayTarget* displayTarget;
} ADLPossibleMap, *LPADLPossibleMap;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about display possible mapping.
///
/// This structure is used to store the display possible mapping's controller index for the current display.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPossibleMapping
{
int iDisplayIndex; ///< The display index. Each display is assigned an index.
int iDisplayControllerIndex; ///< The controller index to which display is mapped.
int iDisplayMannerSupported; ///< The supported display manner.
} ADLPossibleMapping, *LPADLPossibleMapping;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing information about the validated display device possible map result.
///
/// This structure is used to store the validated display device possible map result
/// This information can be returned to the user.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPossibleMapResult
{
/// The current display map index. It is the OS Desktop index. For example, OS Index 1 showing clone mode. The Display Map will be 1.
int iIndex;
// The bit mask identifies the number of bits PossibleMapResult is currently using. It will be the sum all the bit definitions defined in ADL_DISPLAY_POSSIBLEMAPRESULT_VALID.
int iPossibleMapResultMask;
/// The bit mask identifies the possible map result. The detail definition is defined in ADL_DISPLAY_POSSIBLEMAPRESULT_XXX.
int iPossibleMapResultValue;
} ADLPossibleMapResult, *LPADLPossibleMapResult;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display SLS Grid information.
///
/// This structure is used to store the display SLS Grid information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSLSGrid
{
/// The Adapter index.
int iAdapterIndex;
/// The grid index.
int iSLSGridIndex;
/// The grid row.
int iSLSGridRow;
/// The grid column.
int iSLSGridColumn;
/// The grid bit mask identifies the number of bits DisplayMap is currently using. Sum of all bits defined in ADL_DISPLAY_SLSGRID_ORIENTATION_XXX
int iSLSGridMask;
/// The grid bit value identifies the display status. Refer to ADL_DISPLAY_SLSGRID_ORIENTATION_XXX
int iSLSGridValue;
} ADLSLSGrid, *LPADLSLSGrid;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display SLS Map information.
///
/// This structure is used to store the display SLS Map information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSLSMap
{
/// The Adapter Index
int iAdapterIndex;
/// The current display map index. It is the OS Desktop index. For example, OS Index 1 showing clone mode. The Display Map will be 1.
int iSLSMapIndex;
/// Indicate the current grid
ADLSLSGrid grid;
/// OS surface index
int iSurfaceMapIndex;
/// Screen orientation. E.g., 0, 90, 180, 270
int iOrientation;
/// The number of display targets belongs to this map
int iNumSLSTarget;
/// The first target array index in the Target array
int iFirstSLSTargetArrayIndex;
/// The number of native modes belongs to this map
int iNumNativeMode;
/// The first native mode array index in the native mode array
int iFirstNativeModeArrayIndex;
/// The number of bezel modes belongs to this map
int iNumBezelMode;
/// The first bezel mode array index in the native mode array
int iFirstBezelModeArrayIndex;
/// The number of bezel offsets belongs to this map
int iNumBezelOffset;
/// The first bezel offset array index in the
int iFirstBezelOffsetArrayIndex;
/// The bit mask identifies the number of bits DisplayMap is currently using. Sum all the bit definitions defined in ADL_DISPLAY_SLSMAP_XXX.
int iSLSMapMask;
/// The bit mask identifies the display map status. Refer to ADL_DISPLAY_SLSMAP_XXX
int iSLSMapValue;
} ADLSLSMap, *LPADLSLSMap;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display SLS Offset information.
///
/// This structure is used to store the display SLS Offset information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSLSOffset
{
/// The Adapter Index
int iAdapterIndex;
/// The current display map index. It is the OS Desktop index. For example, OS Index 1 showing clone mode. The Display Map will be 1.
int iSLSMapIndex;
/// The Display ID.
ADLDisplayID displayID;
/// SLS Bezel Mode Index
int iBezelModeIndex;
/// SLS Bezel Offset X
int iBezelOffsetX;
/// SLS Bezel Offset Y
int iBezelOffsetY;
/// SLS Display Width
int iDisplayWidth;
/// SLS Display Height
int iDisplayHeight;
/// The bit mask identifies the number of bits Offset is currently using.
int iBezelOffsetMask;
/// The bit mask identifies the display status.
int iBezelffsetValue;
} ADLSLSOffset, *LPADLSLSOffset;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display SLS Mode information.
///
/// This structure is used to store the display SLS Mode information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSLSMode
{
/// The Adapter Index
int iAdapterIndex;
/// The current display map index. It is the OS Desktop index. For example, OS Index 1 showing clone mode. The Display Map will be 1.
int iSLSMapIndex;
/// The mode index
int iSLSModeIndex;
/// The mode for this map.
ADLMode displayMode;
/// The bit mask identifies the number of bits Mode is currently using.
int iSLSNativeModeMask;
/// The bit mask identifies the display status.
int iSLSNativeModeValue;
} ADLSLSMode, *LPADLSLSMode;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the display Possible SLS Map information.
///
/// This structure is used to store the display Possible SLS Map information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPossibleSLSMap
{
/// The current display map index. It is the OS Desktop index.
/// For example, OS Index 1 showing clone mode. The Display Map will be 1.
int iSLSMapIndex;
/// Number of display map to be validated.
int iNumSLSMap;
/// The display map list for validation
ADLSLSMap* lpSLSMap;
/// the number of display map config to be validated.
int iNumSLSTarget;
/// The display target list for validation.
ADLDisplayTarget* lpDisplayTarget;
} ADLPossibleSLSMap, *LPADLPossibleSLSMap;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the SLS targets.
///
/// This structure is used to store the SLS targets information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSLSTarget
{
/// the logic adapter index
int iAdapterIndex;
/// The SLS map index
int iSLSMapIndex;
/// The target ID
ADLDisplayTarget displayTarget;
/// Target postion X in SLS grid
int iSLSGridPositionX;
/// Target postion Y in SLS grid
int iSLSGridPositionY;
/// The view size width, height and rotation angle per SLS Target
ADLMode viewSize;
/// The bit mask identifies the bits in iSLSTargetValue are currently used
int iSLSTargetMask;
/// The bit mask identifies status info. It is for function extension purpose
int iSLSTargetValue;
} ADLSLSTarget, *LPADLSLSTarget;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the Adapter offset stepping size.
///
/// This structure is used to store the Adapter offset stepping size information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLBezelOffsetSteppingSize
{
/// the logic adapter index
int iAdapterIndex;
/// The SLS map index
int iSLSMapIndex;
/// Bezel X stepping size offset
int iBezelOffsetSteppingSizeX;
/// Bezel Y stepping size offset
int iBezelOffsetSteppingSizeY;
/// Identifies the bits this structure is currently using. It will be the total OR of all the bit definitions.
int iBezelOffsetSteppingSizeMask;
/// Bit mask identifies the display status.
int iBezelOffsetSteppingSizeValue;
} ADLBezelOffsetSteppingSize, *LPADLBezelOffsetSteppingSize;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the overlap offset info for all the displays for each SLS mode.
///
/// This structure is used to store the no. of overlapped modes for each SLS Mode once user finishes the configuration from Overlap Widget
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSLSOverlappedMode
{
/// the SLS mode for which the overlap is configured
ADLMode SLSMode;
/// the number of target displays in SLS.
int iNumSLSTarget;
/// the first target array index in the target array
int iFirstTargetArrayIndex;
}ADLSLSTargetOverlap, *LPADLSLSTargetOverlap;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about driver supported PowerExpress Config Caps
///
/// This structure is used to store the driver supported PowerExpress Config Caps
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPXConfigCaps
{
/// The Persistent logical Adapter Index.
int iAdapterIndex;
/// The bit mask identifies the number of bits PowerExpress Config Caps is currently using. It is the sum of all the bit definitions defined in ADL_PX_CONFIGCAPS_XXXX /ref define_powerxpress_constants.
int iPXConfigCapMask;
/// The bit mask identifies the PowerExpress Config Caps value. The detailed definition is in ADL_PX_CONFIGCAPS_XXXX /ref define_powerxpress_constants.
int iPXConfigCapValue;
} ADLPXConfigCaps, *LPADLPXConfigCaps;
/////////////////////////////////////////////////////////////////////////////////////////
///\brief Enum containing PX or HG type
///
/// This enum is used to get PX or hG type
///
/// \nosubgrouping
//////////////////////////////////////////////////////////////////////////////////////////
typedef enum ADLPxType
{
//Not AMD related PX/HG or not PX or HG at all
ADL_PX_NONE = 0,
//A+A PX
ADL_SWITCHABLE_AMDAMD = 1,
// A+A HG
ADL_HG_AMDAMD = 2,
//A+I PX
ADL_SWITCHABLE_AMDOTHER = 3,
//A+I HG
ADL_HG_AMDOTHER = 4,
}ADLPxType;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an application
///
/// This structure is used to store basic information of an application
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLApplicationData
{
/// Path Name
char strPathName[ADL_MAX_PATH];
/// File Name
char strFileName[ADL_APP_PROFILE_FILENAME_LENGTH];
/// Creation timestamp
char strTimeStamp[ADL_APP_PROFILE_TIMESTAMP_LENGTH];
/// Version
char strVersion[ADL_APP_PROFILE_VERSION_LENGTH];
}ADLApplicationData;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an application
///
/// This structure is used to store basic information of an application
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLApplicationDataX2
{
/// Path Name
wchar_t strPathName[ADL_MAX_PATH];
/// File Name
wchar_t strFileName[ADL_APP_PROFILE_FILENAME_LENGTH];
/// Creation timestamp
wchar_t strTimeStamp[ADL_APP_PROFILE_TIMESTAMP_LENGTH];
/// Version
wchar_t strVersion[ADL_APP_PROFILE_VERSION_LENGTH];
}ADLApplicationDataX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an application
///
/// This structure is used to store basic information of an application including process id
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLApplicationDataX3
{
/// Path Name
wchar_t strPathName[ADL_MAX_PATH];
/// File Name
wchar_t strFileName[ADL_APP_PROFILE_FILENAME_LENGTH];
/// Creation timestamp
wchar_t strTimeStamp[ADL_APP_PROFILE_TIMESTAMP_LENGTH];
/// Version
wchar_t strVersion[ADL_APP_PROFILE_VERSION_LENGTH];
//Application Process id
unsigned int iProcessId;
}ADLApplicationDataX3;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information of a property of an application profile
///
/// This structure is used to store property information of an application profile
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct PropertyRecord
{
/// Property Name
char strName [ADL_APP_PROFILE_PROPERTY_LENGTH];
/// Property Type
ADLProfilePropertyType eType;
/// Data Size in bytes
int iDataSize;
/// Property Value, can be any data type
unsigned char uData[1];
}PropertyRecord;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an application profile
///
/// This structure is used to store information of an application profile
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLApplicationProfile
{
/// Number of properties
int iCount;
/// Buffer to store all property records
PropertyRecord record[1];
}ADLApplicationProfile;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an OD5 Power Control feature
///
/// This structure is used to store information of an Power Control feature
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPowerControlInfo
{
/// Minimum value.
int iMinValue;
/// Maximum value.
int iMaxValue;
/// The minimum change in between minValue and maxValue.
int iStepValue;
} ADLPowerControlInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an controller mode
///
/// This structure is used to store information of an controller mode
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLControllerMode
{
/// This falg indicates actions that will be applied by set viewport
/// The value can be a combination of ADL_CONTROLLERMODE_CM_MODIFIER_VIEW_POSITION,
/// ADL_CONTROLLERMODE_CM_MODIFIER_VIEW_PANLOCK and ADL_CONTROLLERMODE_CM_MODIFIER_VIEW_SIZE
int iModifiers;
/// Horizontal view starting position
int iViewPositionCx;
/// Vertical view starting position
int iViewPositionCy;
/// Horizontal left panlock position
int iViewPanLockLeft;
/// Horizontal right panlock position
int iViewPanLockRight;
/// Vertical top panlock position
int iViewPanLockTop;
/// Vertical bottom panlock position
int iViewPanLockBottom;
/// View resolution in pixels (width)
int iViewResolutionCx;
/// View resolution in pixels (hight)
int iViewResolutionCy;
}ADLControllerMode;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about a display
///
/// This structure is used to store information about a display
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayIdentifier
{
/// ADL display index
long ulDisplayIndex;
/// manufacturer ID of the display
long ulManufacturerId;
/// product ID of the display
long ulProductId;
/// serial number of the display
long ulSerialNo;
} ADLDisplayIdentifier;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 clock range
///
/// This structure is used to store information about Overdrive 6 clock range
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6ParameterRange
{
/// The starting value of the clock range
int iMin;
/// The ending value of the clock range
int iMax;
/// The minimum increment between clock values
int iStep;
} ADLOD6ParameterRange;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 capabilities
///
/// This structure is used to store information about Overdrive 6 capabilities
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6Capabilities
{
/// Contains a bitmap of the OD6 capability flags. Possible values: \ref ADL_OD6_CAPABILITY_SCLK_CUSTOMIZATION,
/// \ref ADL_OD6_CAPABILITY_MCLK_CUSTOMIZATION, \ref ADL_OD6_CAPABILITY_GPU_ACTIVITY_MONITOR
int iCapabilities;
/// Contains a bitmap indicating the power states
/// supported by OD6. Currently only the performance state
/// is supported. Possible Values: \ref ADL_OD6_SUPPORTEDSTATE_PERFORMANCE
int iSupportedStates;
/// Number of levels. OD6 will always use 2 levels, which describe
/// the minimum to maximum clock ranges.
/// The 1st level indicates the minimum clocks, and the 2nd level
/// indicates the maximum clocks.
int iNumberOfPerformanceLevels;
/// Contains the hard limits of the sclk range. Overdrive
/// clocks cannot be set outside this range.
ADLOD6ParameterRange sEngineClockRange;
/// Contains the hard limits of the mclk range. Overdrive
/// clocks cannot be set outside this range.
ADLOD6ParameterRange sMemoryClockRange;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6Capabilities;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 clock values.
///
/// This structure is used to store information about Overdrive 6 clock values.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6PerformanceLevel
{
/// Engine (core) clock.
int iEngineClock;
/// Memory clock.
int iMemoryClock;
} ADLOD6PerformanceLevel;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 clocks.
///
/// This structure is used to store information about Overdrive 6 clocks. This is a
/// variable-sized structure. iNumberOfPerformanceLevels indicate how many elements
/// are contained in the aLevels array.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6StateInfo
{
/// Number of levels. OD6 uses clock ranges instead of discrete performance levels.
/// iNumberOfPerformanceLevels is always 2. The 1st level indicates the minimum clocks
/// in the range. The 2nd level indicates the maximum clocks in the range.
int iNumberOfPerformanceLevels;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
/// Variable-sized array of levels.
/// The number of elements in the array is specified by iNumberofPerformanceLevels.
ADLOD6PerformanceLevel aLevels [1];
} ADLOD6StateInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about current Overdrive 6 performance status.
///
/// This structure is used to store information about current Overdrive 6 performance status.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6CurrentStatus
{
/// Current engine clock in 10 KHz.
int iEngineClock;
/// Current memory clock in 10 KHz.
int iMemoryClock;
/// Current GPU activity in percent. This
/// indicates how "busy" the GPU is.
int iActivityPercent;
/// Not used. Reserved for future use.
int iCurrentPerformanceLevel;
/// Current PCI-E bus speed
int iCurrentBusSpeed;
/// Current PCI-E bus # of lanes
int iCurrentBusLanes;
/// Maximum possible PCI-E bus # of lanes
int iMaximumBusLanes;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6CurrentStatus;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 thermal contoller capabilities
///
/// This structure is used to store information about Overdrive 6 thermal controller capabilities
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6ThermalControllerCaps
{
/// Contains a bitmap of thermal controller capability flags. Possible values: \ref ADL_OD6_TCCAPS_THERMAL_CONTROLLER, \ref ADL_OD6_TCCAPS_FANSPEED_CONTROL,
/// \ref ADL_OD6_TCCAPS_FANSPEED_PERCENT_READ, \ref ADL_OD6_TCCAPS_FANSPEED_PERCENT_WRITE, \ref ADL_OD6_TCCAPS_FANSPEED_RPM_READ, \ref ADL_OD6_TCCAPS_FANSPEED_RPM_WRITE
int iCapabilities;
/// Minimum fan speed expressed as a percentage
int iFanMinPercent;
/// Maximum fan speed expressed as a percentage
int iFanMaxPercent;
/// Minimum fan speed expressed in revolutions-per-minute
int iFanMinRPM;
/// Maximum fan speed expressed in revolutions-per-minute
int iFanMaxRPM;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6ThermalControllerCaps;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 fan speed information
///
/// This structure is used to store information about Overdrive 6 fan speed information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6FanSpeedInfo
{
/// Contains a bitmap of the valid fan speed type flags. Possible values: \ref ADL_OD6_FANSPEED_TYPE_PERCENT, \ref ADL_OD6_FANSPEED_TYPE_RPM, \ref ADL_OD6_FANSPEED_USER_DEFINED
int iSpeedType;
/// Contains current fan speed in percent (if valid flag exists in iSpeedType)
int iFanSpeedPercent;
/// Contains current fan speed in RPM (if valid flag exists in iSpeedType)
int iFanSpeedRPM;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6FanSpeedInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 fan speed value
///
/// This structure is used to store information about Overdrive 6 fan speed value
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6FanSpeedValue
{
/// Indicates the units of the fan speed. Possible values: \ref ADL_OD6_FANSPEED_TYPE_PERCENT, \ref ADL_OD6_FANSPEED_TYPE_RPM
int iSpeedType;
/// Fan speed value (units as indicated above)
int iFanSpeed;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6FanSpeedValue;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 PowerControl settings.
///
/// This structure is used to store information about Overdrive 6 PowerControl settings.
/// PowerControl is the feature which allows the performance characteristics of the GPU
/// to be adjusted by changing the PowerTune power limits.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6PowerControlInfo
{
/// The minimum PowerControl adjustment value
int iMinValue;
/// The maximum PowerControl adjustment value
int iMaxValue;
/// The minimum difference between PowerControl adjustment values
int iStepValue;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6PowerControlInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 PowerControl settings.
///
/// This structure is used to store information about Overdrive 6 PowerControl settings.
/// PowerControl is the feature which allows the performance characteristics of the GPU
/// to be adjusted by changing the PowerTune power limits.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6VoltageControlInfo
{
/// The minimum VoltageControl adjustment value
int iMinValue;
/// The maximum VoltageControl adjustment value
int iMaxValue;
/// The minimum difference between VoltageControl adjustment values
int iStepValue;
/// Value for future extension
int iExtValue;
/// Mask for future extension
int iExtMask;
} ADLOD6VoltageControlInfo;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing ECC statistics namely SEC counts and DED counts
/// Single error count - count of errors that can be corrected
/// Doubt Error Detect - count of errors that cannot be corrected
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLECCData
{
// Single error count - count of errors that can be corrected
int iSec;
// Double error detect - count of errors that cannot be corrected
int iDed;
} ADLECCData;
/// \brief Handle to ADL client context.
///
/// ADL clients obtain context handle from initial call to \ref ADL2_Main_Control_Create.
/// Clients have to pass the handle to each subsequent ADL call and finally destroy
/// the context with call to \ref ADL2_Main_Control_Destroy
/// \nosubgrouping
typedef void *ADL_CONTEXT_HANDLE;
/// \brief Handle to ADL Frame Monitor Token.
///
/// Frame Monitor clients obtain handle from initial call to \ref ADL2_Adapter_FrameMetrics_FrameDuration_Enable
/// Clients have to pass the handle to each subsequent ADL call to \ref ADL2_Adapter_FrameMetrics_FrameDuration_Get
/// and finally destroy the token with call to \ref ADL2_Adapter_FrameMetrics_FrameDuration_Disable
/// \nosubgrouping
typedef void *ADL_FRAME_DURATION_HANDLE;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the display mode definition used per controller.
///
/// This structure is used to store the display mode definition used per controller.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayModeX2
{
/// Horizontal resolution (in pixels).
int iWidth;
/// Vertical resolution (in lines).
int iHeight;
/// Interlaced/Progressive. The value will be set for Interlaced as ADL_DL_TIMINGFLAG_INTERLACED. If not set it is progressive. Refer define_detailed_timing_flags.
int iScanType;
/// Refresh rate.
int iRefreshRate;
/// Timing Standard. Refer define_modetiming_standard.
int iTimingStandard;
} ADLDisplayModeX2;
typedef enum ADLAppProcessState
{
APP_PROC_INVALID = 0, // Invalid Application
APP_PROC_PREMPTION = 1, // The Application is being set up for Process Creation
APP_PROC_CREATION = 2, // The Application's Main Process is created by the OS
APP_PROC_READ = 3, // The Application's Data is ready to be read
APP_PROC_WAIT = 4, // The Application is waiting for Timeout or Notification to Resume
APP_PROC_RUNNING = 5, // The Application is running
APP_PROC_TERMINATE = 6 // The Application is about to terminate
}ADLAppProcessState;
typedef enum ADLAppInterceptionListType
{
ADL_INVALID_FORMAT = 0,
ADL_IMAGEFILEFORMAT = 1,
ADL_ENVVAR = 2
}ADLAppInterceptionListType;
typedef struct ADLAppInterceptionInfo
{
wchar_t AppName[ADL_MAX_PATH]; // the file name of the application or env var
unsigned int ProcessId;
ADLAppInterceptionListType AppFormat;
ADLAppProcessState AppState;
} ADLAppInterceptionInfo;
typedef enum ADL_AP_DATABASE // same as _SHARED_AP_DATABASE in "inc/shared/shared_escape.h"
{
ADL_AP_DATABASE__SYSTEM,
ADL_AP_DATABASE__USER,
ADL_AP_DATABASE__OEM
} ADL_AP_DATABASE;
typedef struct ADLAppInterceptionInfoX2
{
wchar_t AppName[ADL_MAX_PATH]; // the file name of the application or env var
unsigned int ProcessId;
unsigned int WaitForResumeNeeded;
wchar_t CommandLine[ADL_MAX_PATH]; // The command line on app start/stop event
ADLAppInterceptionListType AppFormat;
ADLAppProcessState AppState;
} ADLAppInterceptionInfoX2;
typedef struct ADLAppInterceptionInfoX3
{
wchar_t AppName[ADL_MAX_PATH]; // the file name of the application or env var
unsigned int ProcessId;
unsigned int WaitForResumeNeeded;
unsigned int RayTracingStatus; // returns the Ray Tracing status if it is enabled atleast once in session.
wchar_t CommandLine[ADL_MAX_PATH]; // The command line on app start/stop event
ADLAppInterceptionListType AppFormat;
ADLAppProcessState AppState;
} ADLAppInterceptionInfoX3;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information info for a property record in a profile
///
/// This structure is used to store info for a property record in a profile
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPropertyRecordCreate
{
/// Name of the property
wchar_t * strPropertyName;
/// Data type of the property
ADLProfilePropertyType eType;
// Value of the property
wchar_t * strPropertyValue;
} ADLPropertyRecordCreate;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information info for an application record
///
/// This structure is used to store info for an application record
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLApplicationRecord
{
/// Title of the application
wchar_t * strTitle;
/// File path of the application
wchar_t * strPathName;
/// File name of the application
wchar_t * strFileName;
/// File versin the application
wchar_t * strVersion;
/// Nostes on the application
wchar_t * strNotes;
/// Driver area which the application uses
wchar_t * strArea;
/// Name of profile assigned to the application
wchar_t * strProfileName;
// Source where this application record come from
ADL_AP_DATABASE recordSource;
} ADLApplicationRecord;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 extension capabilities
///
/// This structure is used to store information about Overdrive 6 extension capabilities
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6CapabilitiesEx
{
/// Contains a bitmap of the OD6 extension capability flags. Possible values: \ref ADL_OD6_CAPABILITY_SCLK_CUSTOMIZATION,
/// \ref ADL_OD6_CAPABILITY_MCLK_CUSTOMIZATION, \ref ADL_OD6_CAPABILITY_GPU_ACTIVITY_MONITOR,
/// \ref ADL_OD6_CAPABILITY_POWER_CONTROL, \ref ADL_OD6_CAPABILITY_VOLTAGE_CONTROL, \ref ADL_OD6_CAPABILITY_PERCENT_ADJUSTMENT,
//// \ref ADL_OD6_CAPABILITY_THERMAL_LIMIT_UNLOCK
int iCapabilities;
/// The Power states that support clock and power customization. Only performance state is currently supported.
/// Possible Values: \ref ADL_OD6_SUPPORTEDSTATE_PERFORMANCE
int iSupportedStates;
/// Returns the hard limits of the SCLK overdrive adjustment range. Overdrive clocks should not be adjusted outside of this range. The values are specified as +/- percentages.
ADLOD6ParameterRange sEngineClockPercent;
/// Returns the hard limits of the MCLK overdrive adjustment range. Overdrive clocks should not be adjusted outside of this range. The values are specified as +/- percentages.
ADLOD6ParameterRange sMemoryClockPercent;
/// Returns the hard limits of the Power Limit adjustment range. Power limit should not be adjusted outside this range. The values are specified as +/- percentages.
ADLOD6ParameterRange sPowerControlPercent;
/// Reserved for future expansion of the structure.
int iExtValue;
/// Reserved for future expansion of the structure.
int iExtMask;
} ADLOD6CapabilitiesEx;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 extension state information
///
/// This structure is used to store information about Overdrive 6 extension state information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6StateEx
{
/// The current engine clock adjustment value, specified as a +/- percent.
int iEngineClockPercent;
/// The current memory clock adjustment value, specified as a +/- percent.
int iMemoryClockPercent;
/// The current power control adjustment value, specified as a +/- percent.
int iPowerControlPercent;
/// Reserved for future expansion of the structure.
int iExtValue;
/// Reserved for future expansion of the structure.
int iExtMask;
} ADLOD6StateEx;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive 6 extension recommended maximum clock adjustment values
///
/// This structure is used to store information about Overdrive 6 extension recommended maximum clock adjustment values
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD6MaxClockAdjust
{
/// The recommended maximum engine clock adjustment in percent, for the specified power limit value.
int iEngineClockMax;
/// The recommended maximum memory clock adjustment in percent, for the specified power limit value.
/// Currently the memory is independent of the Power Limit setting, so iMemoryClockMax will always return the maximum
/// possible adjustment value. This field is here for future enhancement in case we add a dependency between Memory Clock
/// adjustment and Power Limit setting.
int iMemoryClockMax;
/// Reserved for future expansion of the structure.
int iExtValue;
/// Reserved for future expansion of the structure.
int iExtMask;
} ADLOD6MaxClockAdjust;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the Connector information
///
/// this structure is used to get the connector information like length, positions & etc.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLConnectorInfo
{
///index of the connector(0-based)
int iConnectorIndex;
///used for disply identification/ordering
int iConnectorId;
///index of the slot, 0-based index.
int iSlotIndex;
///Type of the connector. \ref define_connector_types
int iType;
///Position of the connector(in millimeters), from the right side of the slot.
int iOffset;
///Length of the connector(in millimeters).
int iLength;
} ADLConnectorInfo;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the slot information
///
/// this structure is used to get the slot information like length of the slot, no of connectors on the slot & etc.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLBracketSlotInfo
{
///index of the slot, 0-based index.
int iSlotIndex;
///length of the slot(in millimeters).
int iLength;
///width of the slot(in millimeters).
int iWidth;
} ADLBracketSlotInfo;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing MST branch information
///
/// this structure is used to store the MST branch information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMSTRad
{
///depth of the link.
int iLinkNumber;
/// Relative address, address scheme starts from source side
char rad[ADL_MAX_RAD_LINK_COUNT];
} ADLMSTRad;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing port information
///
/// this structure is used to get the display or MST branch information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDevicePort
{
///index of the connector.
int iConnectorIndex;
///Relative MST address. If MST RAD contains 0 it means DP or Root of the MST topology. For non DP connectors MST RAD is ignored.
ADLMSTRad aMSTRad;
} ADLDevicePort;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing supported connection types and properties
///
/// this structure is used to get the supported connection types and supported properties of given connector
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSupportedConnections
{
///Bit vector of supported connections. Bitmask is defined in constants section. \ref define_connection_types
int iSupportedConnections;
///Array of bitvectors. Each bit vector represents supported properties for one connection type. Index of this array is connection type (bit number in mask).
int iSupportedProperties[ADL_MAX_CONNECTION_TYPES];
} ADLSupportedConnections;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing connection state of the connector
///
/// this structure is used to get the current Emulation status and mode of the given connector
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLConnectionState
{
///The value is bit vector. Each bit represents status. See masks constants for details. \ref define_emulation_status
int iEmulationStatus;
///It contains information about current emulation mode. See constants for details. \ref define_emulation_mode
int iEmulationMode;
///If connection is active it will contain display id, otherwise CWDDEDI_INVALID_DISPLAY_INDEX
int iDisplayIndex;
} ADLConnectionState;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing connection properties information
///
/// this structure is used to retrieve the properties of connection type
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLConnectionProperties
{
//Bit vector. Represents actual properties. Supported properties for specific connection type. \ref define_connection_properties
int iValidProperties;
//Bitrate(in MHz). Could be used for MST branch, DP or DP active dongle. \ref define_linkrate_constants
int iBitrate;
//Number of lanes in DP connection. \ref define_lanecount_constants
int iNumberOfLanes;
//Color depth(in bits). \ref define_colordepth_constants
int iColorDepth;
//3D capabilities. It could be used for some dongles. For instance: alternate framepack. Value of this property is bit vector.
int iStereo3DCaps;
///Output Bandwidth. Could be used for MST branch, DP or DP Active dongle. \ref define_linkrate_constants
int iOutputBandwidth;
} ADLConnectionProperties;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing connection information
///
/// this structure is used to retrieve the data from driver which includes
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLConnectionData
{
///Connection type. based on the connection type either iNumberofPorts or IDataSize,EDIDdata is valid, \ref define_connection_types
int iConnectionType;
///Specifies the connection properties.
ADLConnectionProperties aConnectionProperties;
///Number of ports
int iNumberofPorts;
///Number of Active Connections
int iActiveConnections;
///actual size of EDID data block size.
int iDataSize;
///EDID Data
char EdidData[ADL_MAX_DISPLAY_EDID_DATA_SIZE];
} ADLConnectionData;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an controller mode including Number of Connectors
///
/// This structure is used to store information of an controller mode
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLAdapterCapsX2
{
/// AdapterID for this adapter
int iAdapterID;
/// Number of controllers for this adapter
int iNumControllers;
/// Number of displays for this adapter
int iNumDisplays;
/// Number of overlays for this adapter
int iNumOverlays;
/// Number of GLSyncConnectors
int iNumOfGLSyncConnectors;
/// The bit mask identifies the adapter caps
int iCapsMask;
/// The bit identifies the adapter caps \ref define_adapter_caps
int iCapsValue;
/// Number of Connectors for this adapter
int iNumConnectors;
}ADLAdapterCapsX2;
typedef enum ADL_ERROR_RECORD_SEVERITY
{
ADL_GLOBALLY_UNCORRECTED = 1,
ADL_LOCALLY_UNCORRECTED = 2,
ADL_DEFFERRED = 3,
ADL_CORRECTED = 4
}ADL_ERROR_RECORD_SEVERITY;
typedef union _ADL_ECC_EDC_FLAG
{
struct
{
unsigned int isEccAccessing : 1;
unsigned int reserved : 31;
}bits;
unsigned int u32All;
}ADL_ECC_EDC_FLAG;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about EDC Error Record
///
/// This structure is used to store EDC Error Record
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLErrorRecord
{
// Severity of error
ADL_ERROR_RECORD_SEVERITY Severity;
// Is the counter valid?
int countValid;
// Counter value, if valid
unsigned int count;
// Is the location information valid?
int locationValid;
// Physical location of error
unsigned int CU; // CU number on which error occurred, if known
char StructureName[32]; // e.g. LDS, TCC, etc.
// Time of error record creation (e.g. time of query, or time of poison interrupt)
char tiestamp[32];
unsigned int padding[3];
}ADLErrorRecord;
typedef enum ADL_EDC_BLOCK_ID
{
ADL_EDC_BLOCK_ID_SQCIS = 1,
ADL_EDC_BLOCK_ID_SQCDS = 2,
ADL_EDC_BLOCK_ID_SGPR = 3,
ADL_EDC_BLOCK_ID_VGPR = 4,
ADL_EDC_BLOCK_ID_LDS = 5,
ADL_EDC_BLOCK_ID_GDS = 6,
ADL_EDC_BLOCK_ID_TCL1 = 7,
ADL_EDC_BLOCK_ID_TCL2 = 8
}ADL_EDC_BLOCK_ID;
typedef enum ADL_ERROR_INJECTION_MODE
{
ADL_ERROR_INJECTION_MODE_SINGLE = 1,
ADL_ERROR_INJECTION_MODE_MULTIPLE = 2,
ADL_ERROR_INJECTION_MODE_ADDRESS = 3
}ADL_ERROR_INJECTION_MODE;
typedef union _ADL_ERROR_PATTERN
{
struct
{
unsigned long EccInjVector : 16;
unsigned long EccInjEn : 9;
unsigned long EccBeatEn : 4;
unsigned long EccChEn : 4;
unsigned long reserved : 31;
} bits;
unsigned long long u64Value;
} ADL_ERROR_PATTERN;
typedef struct ADL_ERROR_INJECTION_DATA
{
unsigned long long errorAddress;
ADL_ERROR_PATTERN errorPattern;
}ADL_ERROR_INJECTION_DATA;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about EDC Error Injection
///
/// This structure is used to store EDC Error Injection
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLErrorInjection
{
ADL_EDC_BLOCK_ID blockId;
ADL_ERROR_INJECTION_MODE errorInjectionMode;
}ADLErrorInjection;
typedef struct ADLErrorInjectionX2
{
ADL_EDC_BLOCK_ID blockId;
ADL_ERROR_INJECTION_MODE errorInjectionMode;
ADL_ERROR_INJECTION_DATA errorInjectionData;
}ADLErrorInjectionX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing per display FreeSync capability information.
///
/// This structure is used to store the FreeSync capability of both the display and
/// the GPU the display is connected to.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFreeSyncCap
{
/// FreeSync capability flags. \ref define_freesync_caps
int iCaps;
/// Reports minimum FreeSync refresh rate supported by the display in micro hertz
int iMinRefreshRateInMicroHz;
/// Reports maximum FreeSync refresh rate supported by the display in micro hertz
int iMaxRefreshRateInMicroHz;
/// Index of FreeSync Label to use: ADL_FREESYNC_LABEL_*
unsigned char ucLabelIndex;
/// Reserved
char cReserved[3];
int iReserved[4];
} ADLFreeSyncCap;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing per display Display Connectivty Experience Settings
///
/// This structure is used to store the Display Connectivity Experience settings of a
/// display
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDceSettings
{
DceSettingsType type; // Defines which structure is in the union below
union
{
struct
{
bool qualityDetectionEnabled;
} HdmiLq;
struct
{
DpLinkRate linkRate; // Read-only
unsigned int numberOfActiveLanes; // Read-only
unsigned int numberofTotalLanes; // Read-only
int relativePreEmphasis; // Allowable values are -2 to +2
int relativeVoltageSwing; // Allowable values are -2 to +2
int persistFlag;
} DpLink;
struct
{
bool linkProtectionEnabled; // Read-only
} Protection;
} Settings;
int iReserved[15];
} ADLDceSettings;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Graphic Core
///
/// This structure is used to get Graphic Core Info
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGraphicCoreInfo
{
/// indicate the graphic core generation
int iGCGen;
union
{
/// Total number of CUs. Valid for GCN (iGCGen == GCN)
int iNumCUs;
/// Total number of WGPs. Valid for RDNA (iGCGen == RDNA)
int iNumWGPs;
};
union
{
/// Number of processing elements per CU. Valid for GCN (iGCGen == GCN)
int iNumPEsPerCU;
/// Number of processing elements per WGP. Valid for RDNA (iGCGen == RDNA)
int iNumPEsPerWGP;
};
/// Total number of SIMDs. Valid for Pre GCN (iGCGen == Pre-GCN)
int iNumSIMDs;
/// Total number of ROPs. Valid for both GCN and Pre GCN
int iNumROPs;
/// reserved for future use
int iReserved[11];
}ADLGraphicCoreInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N clock range
///
/// This structure is used to store information about Overdrive N clock range
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNParameterRange
{
/// The starting value of the clock range
int iMode;
/// The starting value of the clock range
int iMin;
/// The ending value of the clock range
int iMax;
/// The minimum increment between clock values
int iStep;
/// The default clock values
int iDefault;
} ADLODNParameterRange;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N capabilities
///
/// This structure is used to store information about Overdrive N capabilities
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNCapabilities
{
/// Number of levels which describe the minimum to maximum clock ranges.
/// The 1st level indicates the minimum clocks, and the 2nd level
/// indicates the maximum clocks.
int iMaximumNumberOfPerformanceLevels;
/// Contains the hard limits of the sclk range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange sEngineClockRange;
/// Contains the hard limits of the mclk range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange sMemoryClockRange;
/// Contains the hard limits of the vddc range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange svddcRange;
/// Contains the hard limits of the power range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange power;
/// Contains the hard limits of the power range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange powerTuneTemperature;
/// Contains the hard limits of the Temperature range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange fanTemperature;
/// Contains the hard limits of the Fan range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange fanSpeed;
/// Contains the hard limits of the Fan range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange minimumPerformanceClock;
} ADLODNCapabilities;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N capabilities
///
/// This structure is used to store information about Overdrive N capabilities
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNCapabilitiesX2
{
/// Number of levels which describe the minimum to maximum clock ranges.
/// The 1st level indicates the minimum clocks, and the 2nd level
/// indicates the maximum clocks.
int iMaximumNumberOfPerformanceLevels;
/// bit vector, which tells what are the features are supported.
/// \ref: ADLODNFEATURECONTROL
int iFlags;
/// Contains the hard limits of the sclk range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange sEngineClockRange;
/// Contains the hard limits of the mclk range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange sMemoryClockRange;
/// Contains the hard limits of the vddc range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange svddcRange;
/// Contains the hard limits of the power range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange power;
/// Contains the hard limits of the power range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange powerTuneTemperature;
/// Contains the hard limits of the Temperature range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange fanTemperature;
/// Contains the hard limits of the Fan range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange fanSpeed;
/// Contains the hard limits of the Fan range. Overdrive
/// clocks cannot be set outside this range.
ADLODNParameterRange minimumPerformanceClock;
/// Contains the hard limits of the throttleNotification
ADLODNParameterRange throttleNotificaion;
/// Contains the hard limits of the Auto Systemclock
ADLODNParameterRange autoSystemClock;
} ADLODNCapabilitiesX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive level.
///
/// This structure is used to store information about Overdrive level.
/// This structure is used by ADLODPerformanceLevels.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNPerformanceLevel
{
/// clock.
int iClock;
/// VDCC.
int iVddc;
/// enabled
int iEnabled;
} ADLODNPerformanceLevel;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N performance levels.
///
/// This structure is used to store information about Overdrive performance levels.
/// This structure is used by the ADL_OverdriveN_ODPerformanceLevels_Get() and ADL_OverdriveN_ODPerformanceLevels_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNPerformanceLevels
{
int iSize;
//Automatic/manual
int iMode;
/// Must be set to sizeof( \ref ADLODPerformanceLevels ) + sizeof( \ref ADLODPerformanceLevel ) * (ADLODParameters.iNumberOfPerformanceLevels - 1)
int iNumberOfPerformanceLevels;
/// Array of performance state descriptors. Must have ADLODParameters.iNumberOfPerformanceLevels elements.
ADLODNPerformanceLevel aLevels[1];
} ADLODNPerformanceLevels;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N Fan Speed.
///
/// This structure is used to store information about Overdrive Fan control .
/// This structure is used by the ADL_OverdriveN_ODPerformanceLevels_Get() and ADL_OverdriveN_ODPerformanceLevels_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNFanControl
{
int iMode;
int iFanControlMode;
int iCurrentFanSpeedMode;
int iCurrentFanSpeed;
int iTargetFanSpeed;
int iTargetTemperature;
int iMinPerformanceClock;
int iMinFanLimit;
} ADLODNFanControl;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N power limit.
///
/// This structure is used to store information about Overdrive power limit.
/// This structure is used by the ADL_OverdriveN_ODPerformanceLevels_Get() and ADL_OverdriveN_ODPerformanceLevels_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNPowerLimitSetting
{
int iMode;
int iTDPLimit;
int iMaxOperatingTemperature;
} ADLODNPowerLimitSetting;
typedef struct ADLODNPerformanceStatus
{
int iCoreClock;
int iMemoryClock;
int iDCEFClock;
int iGFXClock;
int iUVDClock;
int iVCEClock;
int iGPUActivityPercent;
int iCurrentCorePerformanceLevel;
int iCurrentMemoryPerformanceLevel;
int iCurrentDCEFPerformanceLevel;
int iCurrentGFXPerformanceLevel;
int iUVDPerformanceLevel;
int iVCEPerformanceLevel;
int iCurrentBusSpeed;
int iCurrentBusLanes;
int iMaximumBusLanes;
int iVDDC;
int iVDDCI;
} ADLODNPerformanceStatus;
///\brief Structure containing information about Overdrive level.
///
/// This structure is used to store information about Overdrive level.
/// This structure is used by ADLODPerformanceLevels.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNPerformanceLevelX2
{
/// clock.
int iClock;
/// VDCC.
int iVddc;
/// enabled
int iEnabled;
/// MASK
int iControl;
} ADLODNPerformanceLevelX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive N performance levels.
///
/// This structure is used to store information about Overdrive performance levels.
/// This structure is used by the ADL_OverdriveN_ODPerformanceLevels_Get() and ADL_OverdriveN_ODPerformanceLevels_Set() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLODNPerformanceLevelsX2
{
int iSize;
//Automatic/manual
int iMode;
/// Must be set to sizeof( \ref ADLODPerformanceLevels ) + sizeof( \ref ADLODPerformanceLevel ) * (ADLODParameters.iNumberOfPerformanceLevels - 1)
int iNumberOfPerformanceLevels;
/// Array of performance state descriptors. Must have ADLODParameters.iNumberOfPerformanceLevels elements.
ADLODNPerformanceLevelX2 aLevels[1];
} ADLODNPerformanceLevelsX2;
typedef enum ADLODNCurrentPowerType
{
ODN_GPU_TOTAL_POWER = 0,
ODN_GPU_PPT_POWER,
ODN_GPU_SOCKET_POWER,
ODN_GPU_CHIP_POWER
} ADLODNCurrentPowerType;
// in/out: CWDDEPM_CURRENTPOWERPARAMETERS
typedef struct ADLODNCurrentPowerParameters
{
int size;
ADLODNCurrentPowerType powerType;
int currentPower;
} ADLODNCurrentPowerParameters;
//ODN Ext range data structure
typedef struct ADLODNExtSingleInitSetting
{
int mode;
int minValue;
int maxValue;
int step;
int defaultValue;
} ADLODNExtSingleInitSetting;
//OD8 Ext range data structure
typedef struct ADLOD8SingleInitSetting
{
int featureID;
int minValue;
int maxValue;
int defaultValue;
} ADLOD8SingleInitSetting;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive8 initial setting
///
/// This structure is used to store information about Overdrive8 initial setting
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD8InitSetting
{
int count;
int overdrive8Capabilities;
ADLOD8SingleInitSetting od8SettingTable[OD8_COUNT];
} ADLOD8InitSetting;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive8 current setting
///
/// This structure is used to store information about Overdrive8 current setting
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD8CurrentSetting
{
int count;
int Od8SettingTable[OD8_COUNT];
} ADLOD8CurrentSetting;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Overdrive8 set setting
///
/// This structure is used to store information about Overdrive8 set setting
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLOD8SingleSetSetting
{
int value;
int requested; // 0 - default , 1 - requested
int reset; // 0 - do not reset , 1 - reset setting back to default
} ADLOD8SingleSetSetting;
typedef struct ADLOD8SetSetting
{
int count;
ADLOD8SingleSetSetting od8SettingTable[OD8_COUNT];
} ADLOD8SetSetting;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Performance Metrics data
///
/// This structure is used to store information about Performance Metrics data output
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSingleSensorData
{
int supported;
int value;
} ADLSingleSensorData;
typedef struct ADLPMLogDataOutput
{
int size;
ADLSingleSensorData sensors[ADL_PMLOG_MAX_SENSORS];
}ADLPMLogDataOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about PPLog settings.
///
/// This structure is used to store information about PPLog settings.
/// This structure is used by the ADL2_PPLogSettings_Set() and ADL2_PPLogSettings_Get() functions.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPPLogSettings
{
int BreakOnAssert;
int BreakOnWarn;
int LogEnabled;
int LogFieldMask;
int LogDestinations;
int LogSeverityEnabled;
int LogSourceMask;
int PowerProfilingEnabled;
int PowerProfilingTimeInterval;
}ADLPPLogSettings;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related Frames Per Second for AC and DC.
///
/// This structure is used to store information related AC and DC Frames Per Second settings
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFPSSettingsOutput
{
/// size
int ulSize;
/// FPS Monitor is enabled in the AC state if 1
int bACFPSEnabled;
/// FPS Monitor is enabled in the DC state if 1
int bDCFPSEnabled;
/// Current Value of FPS Monitor in AC state
int ulACFPSCurrent;
/// Current Value of FPS Monitor in DC state
int ulDCFPSCurrent;
/// Maximum FPS Threshold allowed in PPLib for AC
int ulACFPSMaximum;
/// Minimum FPS Threshold allowed in PPLib for AC
int ulACFPSMinimum;
/// Maximum FPS Threshold allowed in PPLib for DC
int ulDCFPSMaximum;
/// Minimum FPS Threshold allowed in PPLib for DC
int ulDCFPSMinimum;
} ADLFPSSettingsOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related Frames Per Second for AC and DC.
///
/// This structure is used to store information related AC and DC Frames Per Second settings
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFPSSettingsInput
{
/// size
int ulSize;
/// Settings are for Global FPS (used by CCC)
int bGlobalSettings;
/// Current Value of FPS Monitor in AC state
int ulACFPSCurrent;
/// Current Value of FPS Monitor in DC state
int ulDCFPSCurrent;
/// Reserved
int ulReserved[6];
} ADLFPSSettingsInput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related power management logging.
///
/// This structure is used to store support information for power management logging.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
enum { ADL_PMLOG_MAX_SUPPORTED_SENSORS = 256 };
typedef struct ADLPMLogSupportInfo
{
/// list of sensors defined by ADL_PMLOG_SENSORS
unsigned short usSensors[ADL_PMLOG_MAX_SUPPORTED_SENSORS];
/// Reserved
int ulReserved[16];
} ADLPMLogSupportInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information to start power management logging.
///
/// This structure is used as input to ADL2_Adapter_PMLog_Start
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPMLogStartInput
{
/// list of sensors defined by ADL_PMLOG_SENSORS
unsigned short usSensors[ADL_PMLOG_MAX_SUPPORTED_SENSORS];
/// Sample rate in milliseconds
unsigned long ulSampleRate;
/// Reserved
int ulReserved[15];
} ADLPMLogStartInput;
typedef struct ADLPMLogData
{
/// Structure version
unsigned int ulVersion;
/// Current driver sample rate
unsigned int ulActiveSampleRate;
/// Timestamp of last update
unsigned long long ulLastUpdated;
/// 2D array of senesor and values
unsigned int ulValues[ADL_PMLOG_MAX_SUPPORTED_SENSORS][2];
/// Reserved
unsigned int ulReserved[256];
} ADLPMLogData;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information to start power management logging.
///
/// This structure is returned as output from ADL2_Adapter_PMLog_Start
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPMLogStartOutput
{
/// Pointer to memory address containing logging data
union
{
void* pLoggingAddress;
unsigned long long ptr_LoggingAddress;
};
/// Reserved
int ulReserved[14];
} ADLPMLogStartOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information to query limts of power management logging.
///
/// This structure is returned as output from ADL2_Adapter_PMLog_SensorLimits_Get
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPMLogSensorLimits
{
int SensorLimits[ADL_PMLOG_MAX_SENSORS][2]; //index 0: min, 1: max
} ADLPMLogSensorLimits;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Get Error Counts Information
///
/// This structure is used to store RAS Error Counts Get Input Information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASGetErrorCountsInput
{
unsigned int Reserved[16];
} ADLRASGetErrorCountsInput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Get Error Counts Information
///
/// This structure is used to store RAS Error Counts Get Output Information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASGetErrorCountsOutput
{
unsigned int CorrectedErrors; // includes both DRAM and SRAM ECC
unsigned int UnCorrectedErrors; // includes both DRAM and SRAM ECC
unsigned int Reserved[14];
} ADLRASGetErrorCountsOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Get Error Counts Information
///
/// This structure is used to store RAS Error Counts Get Information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASGetErrorCounts
{
unsigned int InputSize;
ADLRASGetErrorCountsInput Input;
unsigned int OutputSize;
ADLRASGetErrorCountsOutput Output;
} ADLRASGetErrorCounts;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Error Counts Reset Information
///
/// This structure is used to store RAS Error Counts Reset Input Information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASResetErrorCountsInput
{
unsigned int Reserved[8];
} ADLRASResetErrorCountsInput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Error Counts Reset Information
///
/// This structure is used to store RAS Error Counts Reset Output Information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASResetErrorCountsOutput
{
unsigned int Reserved[8];
} ADLRASResetErrorCountsOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Error Counts Reset Information
///
/// This structure is used to store RAS Error Counts Reset Information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASResetErrorCounts
{
unsigned int InputSize;
ADLRASResetErrorCountsInput Input;
unsigned int OutputSize;
ADLRASResetErrorCountsOutput Output;
} ADLRASResetErrorCounts;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Error Injection information
///
/// This structure is used to store RAS Error Injection input information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASErrorInjectonInput
{
unsigned long long Address;
ADL_RAS_INJECTION_METHOD Value;
ADL_RAS_BLOCK_ID BlockId;
ADL_RAS_ERROR_TYPE InjectErrorType;
ADL_MEM_SUB_BLOCK_ID SubBlockIndex;
unsigned int padding[9];
} ADLRASErrorInjectonInput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Error Injection information
///
/// This structure is used to store RAS Error Injection output information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASErrorInjectionOutput
{
unsigned int ErrorInjectionStatus;
unsigned int padding[15];
} ADLRASErrorInjectionOutput;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related RAS Error Injection information
///
/// This structure is used to store RAS Error Injection information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLRASErrorInjection
{
unsigned int InputSize;
ADLRASErrorInjectonInput Input;
unsigned int OutputSize;
ADLRASErrorInjectionOutput Output;
} ADLRASErrorInjection;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about an application
///
/// This structure is used to store basic information of a recently ran or currently running application
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSGApplicationInfo
{
/// Application file name
wchar_t strFileName[ADL_MAX_PATH];
/// Application file path
wchar_t strFilePath[ADL_MAX_PATH];
/// Application version
wchar_t strVersion[ADL_MAX_PATH];
/// Timestamp at which application has run
long long int timeStamp;
/// Holds whether the applicaition profile exists or not
unsigned int iProfileExists;
/// The GPU on which application runs
unsigned int iGPUAffinity;
/// The BDF of the GPU on which application runs
ADLBdf GPUBdf;
} ADLSGApplicationInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related Frames Per Second for AC and DC.
///
/// This structure is used to store information related AC and DC Frames Per Second settings
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
enum { ADLPreFlipPostProcessingInfoInvalidLUTIndex = 0xFFFFFFFF };
enum ADLPreFlipPostProcessingLUTAlgorithm
{
ADLPreFlipPostProcessingLUTAlgorithm_Default = 0,
ADLPreFlipPostProcessingLUTAlgorithm_Full,
ADLPreFlipPostProcessingLUTAlgorithm_Approximation
};
typedef struct ADLPreFlipPostProcessingInfo
{
/// size
int ulSize;
/// Current active state
int bEnabled;
/// Current selected LUT index. 0xFFFFFFF returned if nothing selected.
int ulSelectedLUTIndex;
/// Current selected LUT Algorithm
int ulSelectedLUTAlgorithm;
/// Reserved
int ulReserved[12];
} ADLPreFlipPostProcessingInfo;
typedef struct ADL_ERROR_REASON
{
int boost; //ON, when boost is Enabled
int delag; //ON, when delag is Enabled
int chill; //ON, when chill is Enabled
int proVsr; //ON, when proVsr is Enabled
}ADL_ERROR_REASON;
typedef struct ADL_ERROR_REASON2
{
int boost; //ON, when boost is Enabled
int delag; //ON, when delag is Enabled
int chill; //ON, when chill is Enabled
int proVsr; //ON, when proVsr is Enabled
int upscale; //ON, when RSR is Enabled
}ADL_ERROR_REASON2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about DELAG Settings change reason
///
/// Elements of DELAG settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_DELAG_NOTFICATION_REASON
{
int HotkeyChanged; //Set when Hotkey value is changed
int GlobalEnableChanged; //Set when Global enable value is changed
int GlobalLimitFPSChanged; //Set when Global enable value is changed
}ADL_DELAG_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about DELAG Settings
///
/// Elements of DELAG settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_DELAG_SETTINGS
{
int Hotkey; // Hotkey value
int GlobalEnable; //Global enable value
int GlobalLimitFPS; //Global Limit FPS
int GlobalLimitFPS_MinLimit; //Gloabl Limit FPS slider min limit value
int GlobalLimitFPS_MaxLimit; //Gloabl Limit FPS slider max limit value
int GlobalLimitFPS_Step; //Gloabl Limit FPS step value
}ADL_DELAG_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about BOOST Settings change reason
///
/// Elements of BOOST settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_BOOST_NOTFICATION_REASON
{
int HotkeyChanged; //Set when Hotkey value is changed
int GlobalEnableChanged; //Set when Global enable value is changed
int GlobalMinResChanged; //Set when Global min resolution value is changed
}ADL_BOOST_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about BOOST Settings
///
/// Elements of BOOST settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_BOOST_SETTINGS
{
int Hotkey; // Hotkey value
int GlobalEnable; //Global enable value
int GlobalMinRes; //Gloabl Min Resolution value
int GlobalMinRes_MinLimit; //Gloabl Min Resolution slider min limit value
int GlobalMinRes_MaxLimit; //Gloabl Min Resolution slider max limit value
int GlobalMinRes_Step; //Gloabl Min Resolution step value
}ADL_BOOST_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about ProVSR Settings change reason
///
/// Elements of ProVSR settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_PROVSR_NOTFICATION_REASON
{
int HotkeyChanged; //Set when Hotkey value is changed
int GlobalEnableChanged; //Set when Global enable value is changed
}ADL_PROVSR_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Pro VSR Settings
///
/// Elements of ProVSR settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_PROVSR_SETTINGS
{
int Hotkey; // Hotkey value
int GlobalEnable; //Global enable value
}ADL_PROVSR_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about Image Boost(OGL) Settings change reason
///
/// Elements of Image Boost settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_IMAGE_BOOST_NOTFICATION_REASON
{
int HotkeyChanged; //Set when Hotkey value is changed
int GlobalEnableChanged; //Set when Global enable value is changed
}ADL_IMAGE_BOOST_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about OGL IMAGE BOOST Settings
///
/// Elements of OGL IMAGE BOOST settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_IMAGE_BOOST_SETTINGS
{
int Hotkey; // Hotkey value
int GlobalEnable; //Global enable value
}ADL_IMAGE_BOOST_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about RIS Settings change reason
///
/// Elements of RIS settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_RIS_NOTFICATION_REASON
{
unsigned int GlobalEnableChanged; //Set when Global enable value is changed
unsigned int GlobalSharpeningDegreeChanged; //Set when Global sharpening Degree value is changed
}ADL_RIS_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about RIS Settings
///
/// Elements of RIS settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_RIS_SETTINGS
{
int GlobalEnable; //Global enable value
int GlobalSharpeningDegree; //Global sharpening value
int GlobalSharpeningDegree_MinLimit; //Gloabl sharpening slider min limit value
int GlobalSharpeningDegree_MaxLimit; //Gloabl sharpening slider max limit value
int GlobalSharpeningDegree_Step; //Gloabl sharpening step value
}ADL_RIS_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about CHILL Settings change reason
///
/// Elements of Chiil settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_CHILL_NOTFICATION_REASON
{
int HotkeyChanged; //Set when Hotkey value is changed
int GlobalEnableChanged; //Set when Global enable value is changed
int GlobalMinFPSChanged; //Set when Global min FPS value is changed
int GlobalMaxFPSChanged; //Set when Global max FPS value is changed
}ADL_CHILL_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about CHILL Settings
///
/// Elements of Chill settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_CHILL_SETTINGS
{
int Hotkey; // Hotkey value
int GlobalEnable; //Global enable value
int GlobalMinFPS; //Global Min FPS value
int GlobalMaxFPS; //Global Max FPS value
int GlobalFPS_MinLimit; //Gloabl FPS slider min limit value
int GlobalFPS_MaxLimit; //Gloabl FPS slider max limit value
int GlobalFPS_Step; //Gloabl FPS Slider step value
}ADL_CHILL_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about DRIVERUPSCALE Settings change reason
///
/// Elements of DRIVERUPSCALE settings changed reason.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_DRIVERUPSCALE_NOTFICATION_REASON
{
int ModeOverrideEnabledChanged; //Set when Global min resolution value is changed
int GlobalEnabledChanged; //Set when Global enable value is changed
}ADL_DRIVERUPSCALE_NOTFICATION_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about DRIVERUPSCALE Settings
///
/// Elements of DRIVERUPSCALE settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_DRIVERUPSCALE_SETTINGS
{
int ModeOverrideEnabled;
int GlobalEnabled;
}ADL_DRIVERUPSCALE_SETTINGS;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure Containing R G B values for Radeon USB LED Bar
///
/// Elements of RGB Values.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_RADEON_LED_COLOR_CONFIG
{
unsigned short R : 8; // Red Value
unsigned short G : 8; // Green Value
unsigned short B : 8; // Blue Value
}ADL_RADEON_LED_COLOR_CONFIG;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure Containing All Generic LED configuration for user requested LED pattern. The driver will apply the confgiuration as requested
///
/// Elements of Radeon USB LED configuration.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_RADEON_LED_PATTERN_CONFIG_GENERIC
{
short brightness : 8; // Brightness of LED
short speed : 8; // Speed of LED pattern
bool directionCounterClockWise; //Direction of LED Pattern
ADL_RADEON_LED_COLOR_CONFIG colorConfig; // RGB value of LED pattern
char morseCodeText[ADL_RADEON_LED_MAX_MORSE_CODE]; // Morse Code user input for Morse Code LED pattern
char morseCodeTextOutPut[ADL_RADEON_LED_MAX_MORSE_CODE]; // Driver set output representation of Morse Code
int morseCodeTextOutPutLen; // Length of Morse Code output
}ADL_RADEON_LED_PATTERN_CONFIG_GENERIC;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure Containing All custom grid pattern LED configuration for user requested LED grid pattern. The driver will apply the confgiuration as requested
///
/// Elements of Radeon USB LED custom grid configuration.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_RADEON_LED_CUSTOM_LED_CONFIG
{
short brightness : 8; // Brightness of LED
ADL_RADEON_LED_COLOR_CONFIG colorConfig[ADL_RADEON_LED_MAX_LED_ROW_ON_GRID][ADL_RADEON_LED_MAX_LED_COLUMN_ON_GRID]; // Full grid array representation of Radeon LED to be populated by user
}ADL_RADEON_LED_CUSTOM_GRID_LED_CONFIG;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure Containing All Radeon USB LED requests and controls.
///
/// Elements of Radeon USB LED Controls.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_RADEON_LED_PATTERN_CONFIG
{
ADL_RADEON_USB_LED_BAR_CONTROLS control; //Requested LED pattern
union
{
ADL_RADEON_LED_PATTERN_CONFIG_GENERIC genericPararmeters; //Requested pattern configuration settings
ADL_RADEON_LED_CUSTOM_GRID_LED_CONFIG customGridConfig; //Requested custom grid configuration settings
};
}ADL_RADEON_LED_PATTERN_CONFIG;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about the graphics adapter with extended caps
///
/// This structure is used to store various information about the graphics adapter. This
/// information can be returned to the user. Alternatively, it can be used to access various driver calls to set
/// or fetch various settings upon the user's request.
/// This AdapterInfoX2 struct extends the AdapterInfo struct in adl_structures.h
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct AdapterInfoX2
{
/// \ALL_STRUCT_MEM
/// Size of the structure.
int iSize;
/// The ADL index handle. One GPU may be associated with one or two index handles
int iAdapterIndex;
/// The unique device ID associated with this adapter.
char strUDID[ADL_MAX_PATH];
/// The BUS number associated with this adapter.
int iBusNumber;
/// The driver number associated with this adapter.
int iDeviceNumber;
/// The function number.
int iFunctionNumber;
/// The vendor ID associated with this adapter.
int iVendorID;
/// Adapter name.
char strAdapterName[ADL_MAX_PATH];
/// Display name. For example, "\\\\Display0"
char strDisplayName[ADL_MAX_PATH];
/// Present or not; 1 if present and 0 if not present.It the logical adapter is present, the display name such as \\\\.\\Display1 can be found from OS
int iPresent;
/// Exist or not; 1 is exist and 0 is not present.
int iExist;
/// Driver registry path.
char strDriverPath[ADL_MAX_PATH];
/// Driver registry path Ext for.
char strDriverPathExt[ADL_MAX_PATH];
/// PNP string from Windows.
char strPNPString[ADL_MAX_PATH];
/// It is generated from EnumDisplayDevices.
int iOSDisplayIndex;
/// The bit mask identifies the adapter info
int iInfoMask;
/// The bit identifies the adapter info \ref define_adapter_info
int iInfoValue;
} AdapterInfoX2, *LPAdapterInfoX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about driver gamut space , whether it is related to source or to destination, overlay or graphics
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGamutReference
{
/// mask whether it is related to source or to destination, overlay or graphics
int iGamutRef;
}ADLGamutReference;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about driver supported gamut spaces , capability method
///
/// This structure is used to get driver all supported gamut spaces
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGamutInfo
{
///Any combination of following ADL_GAMUT_SPACE_CCIR_709 - ADL_GAMUT_SPACE_CUSTOM
int SupportedGamutSpace;
///Any combination of following ADL_WHITE_POINT_5000K - ADL_WHITE_POINT_CUSTOM
int SupportedWhitePoint;
} ADLGamutInfo;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about driver point coordinates
///
/// This structure is used to store the driver point coodinates for gamut and white point
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLPoint
{
/// x coordinate
int iX;
/// y coordinate
int iY;
} ADLPoint;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about driver supported gamut coordinates
///
/// This structure is used to store the driver supported supported gamut coordinates
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGamutCoordinates
{
/// red channel chromasity coordinate
ADLPoint Red;
/// green channel chromasity coordinate
ADLPoint Green;
/// blue channel chromasity coordinate
ADLPoint Blue;
} ADLGamutCoordinates;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about driver current gamut space , parent struct for ADLGamutCoordinates and ADLWhitePoint
/// This structure is used to get/set driver supported gamut space
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLGamutData
{
///used as mask and could be 4 options
///BIT_0 If flag ADL_GAMUT_REFERENCE_SOURCE is asserted set operation is related to gamut source ,
///if not gamut destination
///BIT_1 If flag ADL_GAMUT_GAMUT_VIDEO_CONTENT is asserted
///BIT_2,BIT_3 used as mask and could be 4 options custom (2) + predefined (2)
///0. Gamut predefined, white point predefined -> 0 | 0
///1. Gamut predefined, white point custom -> 0 | ADL_CUSTOM_WHITE_POINT
///2. White point predefined, gamut custom -> 0 | ADL_CUSTOM_GAMUT
///3. White point custom, gamut custom -> ADL_CUSTOM_GAMUT | ADL_CUSTOM_WHITE_POINT
int iFeature;
///one of ADL_GAMUT_SPACE_CCIR_709 - ADL_GAMUT_SPACE_CIE_RGB
int iPredefinedGamut;
///one of ADL_WHITE_POINT_5000K - ADL_WHITE_POINT_9300K
int iPredefinedWhitePoint;
///valid when in mask avails ADL_CUSTOM_WHITE_POINT
ADLPoint CustomWhitePoint;
///valid when in mask avails ADL_CUSTOM_GAMUT
ADLGamutCoordinates CustomGamut;
} ADLGamutData;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing detailed timing parameters.
///
/// This structure is used to store the detailed timing parameters.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDetailedTimingX2
{
/// Size of the structure.
int iSize;
/// Timing flags. \ref define_detailed_timing_flags
int sTimingFlags;
/// Total width (columns).
int sHTotal;
/// Displayed width.
int sHDisplay;
/// Horizontal sync signal offset.
int sHSyncStart;
/// Horizontal sync signal width.
int sHSyncWidth;
/// Total height (rows).
int sVTotal;
/// Displayed height.
int sVDisplay;
/// Vertical sync signal offset.
int sVSyncStart;
/// Vertical sync signal width.
int sVSyncWidth;
/// Pixel clock value.
int sPixelClock;
/// Overscan right.
short sHOverscanRight;
/// Overscan left.
short sHOverscanLeft;
/// Overscan bottom.
short sVOverscanBottom;
/// Overscan top.
short sVOverscanTop;
short sOverscan8B;
short sOverscanGR;
} ADLDetailedTimingX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing display mode information.
///
/// This structure is used to store the display mode information.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLDisplayModeInfoX2
{
/// Timing standard of the current mode. \ref define_modetiming_standard
int iTimingStandard;
/// Applicable timing standards for the current mode.
int iPossibleStandard;
/// Refresh rate factor.
int iRefreshRate;
/// Num of pixels in a row.
int iPelsWidth;
/// Num of pixels in a column.
int iPelsHeight;
/// Detailed timing parameters.
ADLDetailedTimingX2 sDetailedTiming;
} ADLDisplayModeInfoX2;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about I2C.
///
/// This structure is used to store the I2C information for the current adapter.
/// This structure is used by \ref ADL_Display_WriteAndReadI2CLargePayload
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLI2CLargePayload
{
/// Size of the structure
int iSize;
/// Numerical value representing hardware I2C.
int iLine;
/// The 7-bit I2C slave device address.
int iAddress;
/// The offset of the data from the address.
int iOffset;
/// Read from or write to slave device. \ref ADL_DL_I2C_ACTIONREAD or \ref ADL_DL_I2C_ACTIONWRITE
int iAction;
/// I2C clock speed in KHz.
int iSpeed;
/// I2C option flags. \ref define_ADLI2CLargePayload
int iFlags;
/// A numerical value representing the number of bytes to be sent or received on the I2C bus.
int iDataSize;
/// Address of the characters which are to be sent or received on the I2C bus.
char *pcData;
} ADLI2CLargePayload;
/// Size in bytes of the Feature Name
#define ADL_FEATURE_NAME_LENGTH 16
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing the Multimedia Feature Name
///
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFeatureName
{
/// The Feature Name
char FeatureName[ADL_FEATURE_NAME_LENGTH];
} ADLFeatureName, *LPADLFeatureName;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about MM Feature Capabilities.
///
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFeatureCaps
{
/// The Feature Name
ADLFeatureName Name;
// char strFeatureName[ADL_FEATURE_NAME_LENGTH];
/// Group ID. All Features in the same group are shown sequentially in the same UI Page.
int iGroupID;
/// Visual ID. Places one or more features in a Group Box. If zero, no Group Box is added.
int iVisualID;
/// Page ID. All Features with the same Page ID value are shown together on the same UI page.
int iPageID;
/// Feature Property Mask. Indicates which are the valid bits for iFeatureProperties.
int iFeatureMask;
/// Feature Property Values. See definitions for ADL_FEATURE_PROPERTIES_XXX
int iFeatureProperties;
/// Apperance of the User-Controlled Boolean.
int iControlType;
/// Style of the User-Controlled Boolean.
int iControlStyle;
/// Apperance of the Adjustment Controls.
int iAdjustmentType;
/// Style of the Adjustment Controls.
int iAdjustmentStyle;
/// Default user-controlled boolean value. Valid only if ADLFeatureCaps supports user-controlled boolean.
int bDefault;
/// Minimum integer value. Valid only if ADLFeatureCaps indicates support for integers.
int iMin;
/// Maximum integer value. Valid only if ADLFeatureCaps indicates support for integers.
int iMax;
/// Step integer value. Valid only if ADLFeatureCaps indicates support for integers.
int iStep;
/// Default integer value. Valid only if ADLFeatureCaps indicates support for integers.
int iDefault;
/// Minimum float value. Valid only if ADLFeatureCaps indicates support for floats.
float fMin;
/// Maximum float value. Valid only if ADLFeatureCaps indicates support for floats.
float fMax;
/// Step float value. Valid only if ADLFeatureCaps indicates support for floats.
float fStep;
/// Default float value. Valid only if ADLFeatureCaps indicates support for floats.
float fDefault;
/// The Mask for available bits for enumerated values.(If ADLFeatureCaps supports ENUM values)
int EnumMask;
} ADLFeatureCaps, *LPADLFeatureCaps;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about MM Feature Values.
///
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLFeatureValues
{
/// The Feature Name
ADLFeatureName Name;
// char strFeatureName[ADL_FEATURE_NAME_LENGTH];
/// User controlled Boolean current value. Valid only if ADLFeatureCaps supports Boolean.
int bCurrent;
/// Current integer value. Valid only if ADLFeatureCaps indicates support for integers.
int iCurrent;
/// Current float value. Valid only if ADLFeatureCaps indicates support for floats.
float fCurrent;
/// The States for the available bits for enumerated values.
int EnumStates;
} ADLFeatureValues, *LPADLFeatureValues;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing HDCP Settings info
///
/// This structure is used to store the HDCP settings of a
/// display
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLHDCPSettings
{
int iHDCPProtectionVersion; // Version, starting from 1
int iHDCPCaps; //Caps used to ensure at least one protection scheme is supported, 1 is HDCP1X and 2 is HDCP22
int iAllowAll; //Allow all is true, disable all is false
int iHDCPVale;
int iHDCPMask;
} ADLHDCPSettings;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing Mantle App info
///
/// This structure is used to store the Mantle Driver information
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLMantleAppInfo
{
/// mantle api version
int apiVersion;
/// mantle driver version
long driverVersion;
/// mantle vendroe id
long vendorId;
/// mantle device id
long deviceId;
/// mantle gpu type;
int gpuType;
/// gpu name
char gpuName[256];
/// mem size
int maxMemRefsPerSubmission;
/// virtual mem size
long long virtualMemPageSize;
/// mem update
long long maxInlineMemoryUpdateSize;
/// bound descriptot
long maxBoundDescriptorSets;
/// thread group size
long maxThreadGroupSize;
/// time stamp frequency
long long timestampFrequency;
/// color target
long multiColorTargetClears;
}ADLMantleAppInfo, *LPADLMantleAppInfo;
////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about SDIData
///This structure is used to store information about the state of the SDI whether it is on
///or off and the current size of the segment or aperture size.
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSDIData
{
/// The SDI state, ADL_SDI_ON or ADL_SDI_OFF, for the current SDI mode
int iSDIState;
/// Size of the memory segment for SDI (in MB).
int iSizeofSDISegment;
} ADLSDIData, *LPADLSDIData;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about FRTCPRO Settings
///
/// Elements of FRTCPRO settings.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_FRTCPRO_Settings
{
int DefaultState; //The default status for FRTC pro
int CurrentState; //The current enable/disable status for FRTC pro
unsigned int DefaultValue; //The default FPS value for FRTC pro.
unsigned int CurrentValue; //The current FPS value for FRTC pro.
unsigned int maxSupportedFps; //The max value for FRTC pro.
unsigned int minSupportedFps; //The min value for FRTC pro.
}ADL_FRTCPRO_Settings, *LPADLFRTCProSettings;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information about FRTCPRO Settings changed reason
///
/// Reason of FRTCPRO changed.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_FRTCPRO_CHANGED_REASON
{
int StateChanged; // FRTCPro state changed
int ValueChanged; // FRTCPro value changed
}ADL_FRTCPRO_CHANGED_REASON;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure containing the display mode definition used per controller.
///
/// This structure is used to store the display mode definition used per controller.
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADL_DL_DISPLAY_MODE
{
int iPelsHeight; // Vertical resolution (in pixels).
int iPelsWidth; // Horizontal resolution (in pixels).
int iBitsPerPel; // Color depth.
int iDisplayFrequency; // Refresh rate.
} ADL_DL_DISPLAY_MODE;
/////////////////////////////////////////////////////////////////////////////////////////////
///\brief Structure containing information related DCE support
///
/// This structure is used to store a bit vector of possible DCE support
///
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef union _ADLDCESupport
{
struct
{
unsigned int PrePhasis : 1;
unsigned int voltageSwing : 1;
unsigned int reserved : 30;
}bits;
unsigned int u32All;
}ADLDCESupport;
/////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Structure for Smart shift 2.0 settings
///
/// This structure is used to return the smart shift settings
/// \nosubgrouping
////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ADLSmartShiftSettings
{
int iMinRange;
int iMaxRange;
int iDefaultMode; //Refer to CWDDEPM_ODN_CONTROL_TYPE
int iDefaultValue;
int iCurrentMode;
int iCurrentValue;
int iFlags; //refer to define_smartshift_bits
}ADLSmartShiftSettings, *LPADLSmartShiftSettings;
#endif /* ADL_STRUCTURES_H_ */
================================================
FILE: src/3rdparty/display-library/repo.json
================================================
{
"home": "https://github.com/GPUOpen-LibrariesAndSDKs/display-library",
"license": "MIT (embeded in source)",
"version": "ADL SDK 17.1",
"author": "Advanced Micro Devices, Inc"
}
================================================
FILE: src/3rdparty/widecharwidth/repo.json
================================================
{
"home": "https://github.com/ridiculousfish/widecharwidth",
"license": "Public domain",
"version": "Unicode 17",
"author": "ridiculousfish"
}
================================================
FILE: src/3rdparty/widecharwidth/widechar_width_c.h
================================================
/**
* widechar_width_c.h for Unicode 17.0.0
* See https://github.com/ridiculousfish/widecharwidth/
*
* SHA1 file hashes:
* (
* the hashes for generate.py and the template are git object hashes,
* use `git log --all --find-object=` in the widecharwidth repository
* to see which commit they correspond to,
* or run `git hash-object` on the file to compare.
* The other hashes are simple `sha1sum` style hashes.
* )
*
* generate.py: b35da43f176cc0d5880c67356ebb064048c5bac4
* template.js: 1985fb56796d6d9627f9c5290d5dee9f9364bcf4
* UnicodeData.txt: 50dffef1b7d1f97b72e4c2adceb9b2245f0f34ba
* EastAsianWidth.txt: 2cadc5034b6206ad84b75898a1d4186bb38fc12b
* emoji-data.txt: 3d123e12f70f63e609c4281ce83dfdd9ac7443d2
*/
#ifndef WIDECHAR_WIDTH_H
#define WIDECHAR_WIDTH_H
#include
#include
#include
#ifndef widechar_ARRAY_SIZE
#define widechar_ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
/* Special width values */
enum {
widechar_nonprint = -1, // The character is not printable.
widechar_combining = -2, // The character is a zero-width combiner.
widechar_ambiguous = -3, // The character is East-Asian ambiguous width.
widechar_private_use = -4, // The character is for private use.
widechar_unassigned = -5, // The character is unassigned.
widechar_widened_in_9 = -6, // Width is 1 in Unicode 8, 2 in Unicode 9+.
widechar_non_character = -7 // The character is a noncharacter.
};
/* An inclusive range of characters. */
struct widechar_range {
uint32_t lo;
uint32_t hi;
};
/* Simple ASCII characters - used a lot, so we check them first. */
static const struct widechar_range widechar_ascii_table[] = {
{0x00020, 0x0007E}
};
/* Private usage range. */
static const struct widechar_range widechar_private_table[] = {
{0x0E000, 0x0F8FF},
{0xF0000, 0xFFFFD},
{0x100000, 0x10FFFD}
};
/* Nonprinting characters. */
static const struct widechar_range widechar_nonprint_table[] = {
{0x00000, 0x0001F},
{0x0007F, 0x0009F},
{0x000AD, 0x000AD},
{0x00600, 0x00605},
{0x0061C, 0x0061C},
{0x006DD, 0x006DD},
{0x0070F, 0x0070F},
{0x00890, 0x00891},
{0x008E2, 0x008E2},
{0x0180E, 0x0180E},
{0x0200B, 0x0200F},
{0x02028, 0x0202E},
{0x02060, 0x02064},
{0x02066, 0x0206F},
{0x0D800, 0x0DFFF},
{0x0FEFF, 0x0FEFF},
{0x0FFF9, 0x0FFFB},
{0x110BD, 0x110BD},
{0x110CD, 0x110CD},
{0x13430, 0x1343F},
{0x1BCA0, 0x1BCA3},
{0x1D173, 0x1D17A},
{0xE0001, 0xE0001},
{0xE0020, 0xE007F}
};
/* Width 0 combining marks. */
static const struct widechar_range widechar_combining_table[] = {
{0x00300, 0x0036F},
{0x00483, 0x00489},
{0x00591, 0x005BD},
{0x005BF, 0x005BF},
{0x005C1, 0x005C2},
{0x005C4, 0x005C5},
{0x005C7, 0x005C7},
{0x00610, 0x0061A},
{0x0064B, 0x0065F},
{0x00670, 0x00670},
{0x006D6, 0x006DC},
{0x006DF, 0x006E4},
{0x006E7, 0x006E8},
{0x006EA, 0x006ED},
{0x00711, 0x00711},
{0x00730, 0x0074A},
{0x007A6, 0x007B0},
{0x007EB, 0x007F3},
{0x007FD, 0x007FD},
{0x00816, 0x00819},
{0x0081B, 0x00823},
{0x00825, 0x00827},
{0x00829, 0x0082D},
{0x00859, 0x0085B},
{0x00897, 0x0089F},
{0x008CA, 0x008E1},
{0x008E3, 0x00903},
{0x0093A, 0x0093C},
{0x0093E, 0x0094F},
{0x00951, 0x00957},
{0x00962, 0x00963},
{0x00981, 0x00983},
{0x009BC, 0x009BC},
{0x009BE, 0x009C4},
{0x009C7, 0x009C8},
{0x009CB, 0x009CD},
{0x009D7, 0x009D7},
{0x009E2, 0x009E3},
{0x009FE, 0x009FE},
{0x00A01, 0x00A03},
{0x00A3C, 0x00A3C},
{0x00A3E, 0x00A42},
{0x00A47, 0x00A48},
{0x00A4B, 0x00A4D},
{0x00A51, 0x00A51},
{0x00A70, 0x00A71},
{0x00A75, 0x00A75},
{0x00A81, 0x00A83},
{0x00ABC, 0x00ABC},
{0x00ABE, 0x00AC5},
{0x00AC7, 0x00AC9},
{0x00ACB, 0x00ACD},
{0x00AE2, 0x00AE3},
{0x00AFA, 0x00AFF},
{0x00B01, 0x00B03},
{0x00B3C, 0x00B3C},
{0x00B3E, 0x00B44},
{0x00B47, 0x00B48},
{0x00B4B, 0x00B4D},
{0x00B55, 0x00B57},
{0x00B62, 0x00B63},
{0x00B82, 0x00B82},
{0x00BBE, 0x00BC2},
{0x00BC6, 0x00BC8},
{0x00BCA, 0x00BCD},
{0x00BD7, 0x00BD7},
{0x00C00, 0x00C04},
{0x00C3C, 0x00C3C},
{0x00C3E, 0x00C44},
{0x00C46, 0x00C48},
{0x00C4A, 0x00C4D},
{0x00C55, 0x00C56},
{0x00C62, 0x00C63},
{0x00C81, 0x00C83},
{0x00CBC, 0x00CBC},
{0x00CBE, 0x00CC4},
{0x00CC6, 0x00CC8},
{0x00CCA, 0x00CCD},
{0x00CD5, 0x00CD6},
{0x00CE2, 0x00CE3},
{0x00CF3, 0x00CF3},
{0x00D00, 0x00D03},
{0x00D3B, 0x00D3C},
{0x00D3E, 0x00D44},
{0x00D46, 0x00D48},
{0x00D4A, 0x00D4D},
{0x00D57, 0x00D57},
{0x00D62, 0x00D63},
{0x00D81, 0x00D83},
{0x00DCA, 0x00DCA},
{0x00DCF, 0x00DD4},
{0x00DD6, 0x00DD6},
{0x00DD8, 0x00DDF},
{0x00DF2, 0x00DF3},
{0x00E31, 0x00E31},
{0x00E34, 0x00E3A},
{0x00E47, 0x00E4E},
{0x00EB1, 0x00EB1},
{0x00EB4, 0x00EBC},
{0x00EC8, 0x00ECE},
{0x00F18, 0x00F19},
{0x00F35, 0x00F35},
{0x00F37, 0x00F37},
{0x00F39, 0x00F39},
{0x00F3E, 0x00F3F},
{0x00F71, 0x00F84},
{0x00F86, 0x00F87},
{0x00F8D, 0x00F97},
{0x00F99, 0x00FBC},
{0x00FC6, 0x00FC6},
{0x0102B, 0x0103E},
{0x01056, 0x01059},
{0x0105E, 0x01060},
{0x01062, 0x01064},
{0x01067, 0x0106D},
{0x01071, 0x01074},
{0x01082, 0x0108D},
{0x0108F, 0x0108F},
{0x0109A, 0x0109D},
{0x0135D, 0x0135F},
{0x01712, 0x01715},
{0x01732, 0x01734},
{0x01752, 0x01753},
{0x01772, 0x01773},
{0x017B4, 0x017D3},
{0x017DD, 0x017DD},
{0x0180B, 0x0180D},
{0x0180F, 0x0180F},
{0x01885, 0x01886},
{0x018A9, 0x018A9},
{0x01920, 0x0192B},
{0x01930, 0x0193B},
{0x01A17, 0x01A1B},
{0x01A55, 0x01A5E},
{0x01A60, 0x01A7C},
{0x01A7F, 0x01A7F},
{0x01AB0, 0x01ADD},
{0x01AE0, 0x01AEB},
{0x01B00, 0x01B04},
{0x01B34, 0x01B44},
{0x01B6B, 0x01B73},
{0x01B80, 0x01B82},
{0x01BA1, 0x01BAD},
{0x01BE6, 0x01BF3},
{0x01C24, 0x01C37},
{0x01CD0, 0x01CD2},
{0x01CD4, 0x01CE8},
{0x01CED, 0x01CED},
{0x01CF4, 0x01CF4},
{0x01CF7, 0x01CF9},
{0x01DC0, 0x01DFF},
{0x020D0, 0x020F0},
{0x02CEF, 0x02CF1},
{0x02D7F, 0x02D7F},
{0x02DE0, 0x02DFF},
{0x0302A, 0x0302F},
{0x03099, 0x0309A},
{0x0A66F, 0x0A672},
{0x0A674, 0x0A67D},
{0x0A69E, 0x0A69F},
{0x0A6F0, 0x0A6F1},
{0x0A802, 0x0A802},
{0x0A806, 0x0A806},
{0x0A80B, 0x0A80B},
{0x0A823, 0x0A827},
{0x0A82C, 0x0A82C},
{0x0A880, 0x0A881},
{0x0A8B4, 0x0A8C5},
{0x0A8E0, 0x0A8F1},
{0x0A8FF, 0x0A8FF},
{0x0A926, 0x0A92D},
{0x0A947, 0x0A953},
{0x0A980, 0x0A983},
{0x0A9B3, 0x0A9C0},
{0x0A9E5, 0x0A9E5},
{0x0AA29, 0x0AA36},
{0x0AA43, 0x0AA43},
{0x0AA4C, 0x0AA4D},
{0x0AA7B, 0x0AA7D},
{0x0AAB0, 0x0AAB0},
{0x0AAB2, 0x0AAB4},
{0x0AAB7, 0x0AAB8},
{0x0AABE, 0x0AABF},
{0x0AAC1, 0x0AAC1},
{0x0AAEB, 0x0AAEF},
{0x0AAF5, 0x0AAF6},
{0x0ABE3, 0x0ABEA},
{0x0ABEC, 0x0ABED},
{0x0FB1E, 0x0FB1E},
{0x0FE00, 0x0FE0F},
{0x0FE20, 0x0FE2F},
{0x101FD, 0x101FD},
{0x102E0, 0x102E0},
{0x10376, 0x1037A},
{0x10A01, 0x10A03},
{0x10A05, 0x10A06},
{0x10A0C, 0x10A0F},
{0x10A38, 0x10A3A},
{0x10A3F, 0x10A3F},
{0x10AE5, 0x10AE6},
{0x10D24, 0x10D27},
{0x10D69, 0x10D6D},
{0x10EAB, 0x10EAC},
{0x10EFA, 0x10EFF},
{0x10F46, 0x10F50},
{0x10F82, 0x10F85},
{0x11000, 0x11002},
{0x11038, 0x11046},
{0x11070, 0x11070},
{0x11073, 0x11074},
{0x1107F, 0x11082},
{0x110B0, 0x110BA},
{0x110C2, 0x110C2},
{0x11100, 0x11102},
{0x11127, 0x11134},
{0x11145, 0x11146},
{0x11173, 0x11173},
{0x11180, 0x11182},
{0x111B3, 0x111C0},
{0x111C9, 0x111CC},
{0x111CE, 0x111CF},
{0x1122C, 0x11237},
{0x1123E, 0x1123E},
{0x11241, 0x11241},
{0x112DF, 0x112EA},
{0x11300, 0x11303},
{0x1133B, 0x1133C},
{0x1133E, 0x11344},
{0x11347, 0x11348},
{0x1134B, 0x1134D},
{0x11357, 0x11357},
{0x11362, 0x11363},
{0x11366, 0x1136C},
{0x11370, 0x11374},
{0x113B8, 0x113C0},
{0x113C2, 0x113C2},
{0x113C5, 0x113C5},
{0x113C7, 0x113CA},
{0x113CC, 0x113D0},
{0x113D2, 0x113D2},
{0x113E1, 0x113E2},
{0x11435, 0x11446},
{0x1145E, 0x1145E},
{0x114B0, 0x114C3},
{0x115AF, 0x115B5},
{0x115B8, 0x115C0},
{0x115DC, 0x115DD},
{0x11630, 0x11640},
{0x116AB, 0x116B7},
{0x1171D, 0x1172B},
{0x1182C, 0x1183A},
{0x11930, 0x11935},
{0x11937, 0x11938},
{0x1193B, 0x1193E},
{0x11940, 0x11940},
{0x11942, 0x11943},
{0x119D1, 0x119D7},
{0x119DA, 0x119E0},
{0x119E4, 0x119E4},
{0x11A01, 0x11A0A},
{0x11A33, 0x11A39},
{0x11A3B, 0x11A3E},
{0x11A47, 0x11A47},
{0x11A51, 0x11A5B},
{0x11A8A, 0x11A99},
{0x11B60, 0x11B67},
{0x11C2F, 0x11C36},
{0x11C38, 0x11C3F},
{0x11C92, 0x11CA7},
{0x11CA9, 0x11CB6},
{0x11D31, 0x11D36},
{0x11D3A, 0x11D3A},
{0x11D3C, 0x11D3D},
{0x11D3F, 0x11D45},
{0x11D47, 0x11D47},
{0x11D8A, 0x11D8E},
{0x11D90, 0x11D91},
{0x11D93, 0x11D97},
{0x11EF3, 0x11EF6},
{0x11F00, 0x11F01},
{0x11F03, 0x11F03},
{0x11F34, 0x11F3A},
{0x11F3E, 0x11F42},
{0x11F5A, 0x11F5A},
{0x13440, 0x13440},
{0x13447, 0x13455},
{0x1611E, 0x1612F},
{0x16AF0, 0x16AF4},
{0x16B30, 0x16B36},
{0x16F4F, 0x16F4F},
{0x16F51, 0x16F87},
{0x16F8F, 0x16F92},
{0x16FE4, 0x16FE4},
{0x16FF0, 0x16FF1},
{0x1BC9D, 0x1BC9E},
{0x1CF00, 0x1CF2D},
{0x1CF30, 0x1CF46},
{0x1D165, 0x1D169},
{0x1D16D, 0x1D172},
{0x1D17B, 0x1D182},
{0x1D185, 0x1D18B},
{0x1D1AA, 0x1D1AD},
{0x1D242, 0x1D244},
{0x1DA00, 0x1DA36},
{0x1DA3B, 0x1DA6C},
{0x1DA75, 0x1DA75},
{0x1DA84, 0x1DA84},
{0x1DA9B, 0x1DA9F},
{0x1DAA1, 0x1DAAF},
{0x1E000, 0x1E006},
{0x1E008, 0x1E018},
{0x1E01B, 0x1E021},
{0x1E023, 0x1E024},
{0x1E026, 0x1E02A},
{0x1E08F, 0x1E08F},
{0x1E130, 0x1E136},
{0x1E2AE, 0x1E2AE},
{0x1E2EC, 0x1E2EF},
{0x1E4EC, 0x1E4EF},
{0x1E5EE, 0x1E5EF},
{0x1E6E3, 0x1E6E3},
{0x1E6E6, 0x1E6E6},
{0x1E6EE, 0x1E6EF},
{0x1E6F5, 0x1E6F5},
{0x1E8D0, 0x1E8D6},
{0x1E944, 0x1E94A},
{0xE0100, 0xE01EF}
};
/* Width 0 combining letters. */
static const struct widechar_range widechar_combiningletters_table[] = {
{0x01160, 0x011FF},
{0x0D7B0, 0x0D7FF}
};
/* Width 2 characters. */
static const struct widechar_range widechar_doublewide_table[] = {
{0x01100, 0x0115F},
{0x02329, 0x0232A},
{0x02630, 0x02637},
{0x0268A, 0x0268F},
{0x02E80, 0x02E99},
{0x02E9B, 0x02EF3},
{0x02F00, 0x02FD5},
{0x02FF0, 0x0303E},
{0x03041, 0x03096},
{0x03099, 0x030FF},
{0x03105, 0x0312F},
{0x03131, 0x0318E},
{0x03190, 0x031E5},
{0x031EF, 0x0321E},
{0x03220, 0x03247},
{0x03250, 0x0A48C},
{0x0A490, 0x0A4C6},
{0x0A960, 0x0A97C},
{0x0AC00, 0x0D7A3},
{0x0F900, 0x0FAFF},
{0x0FE10, 0x0FE19},
{0x0FE30, 0x0FE52},
{0x0FE54, 0x0FE66},
{0x0FE68, 0x0FE6B},
{0x0FF01, 0x0FF60},
{0x0FFE0, 0x0FFE6},
{0x16FE0, 0x16FE4},
{0x16FF0, 0x16FF6},
{0x17000, 0x18CD5},
{0x18CFF, 0x18D1E},
{0x18D80, 0x18DF2},
{0x1AFF0, 0x1AFF3},
{0x1AFF5, 0x1AFFB},
{0x1AFFD, 0x1AFFE},
{0x1B000, 0x1B122},
{0x1B132, 0x1B132},
{0x1B150, 0x1B152},
{0x1B155, 0x1B155},
{0x1B164, 0x1B167},
{0x1B170, 0x1B2FB},
{0x1D300, 0x1D356},
{0x1D360, 0x1D376},
{0x1F200, 0x1F200},
{0x1F202, 0x1F202},
{0x1F210, 0x1F219},
{0x1F21B, 0x1F22E},
{0x1F230, 0x1F231},
{0x1F237, 0x1F237},
{0x1F23B, 0x1F23B},
{0x1F240, 0x1F248},
{0x1F260, 0x1F265},
{0x1F57A, 0x1F57A},
{0x1F5A4, 0x1F5A4},
{0x1F6D1, 0x1F6D2},
{0x1F6D5, 0x1F6D8},
{0x1F6DC, 0x1F6DF},
{0x1F6F4, 0x1F6FC},
{0x1F7E0, 0x1F7EB},
{0x1F7F0, 0x1F7F0},
{0x1F90C, 0x1F90F},
{0x1F919, 0x1F93A},
{0x1F93C, 0x1F945},
{0x1F947, 0x1F97F},
{0x1F985, 0x1F9BF},
{0x1F9C1, 0x1F9FF},
{0x1FA70, 0x1FA7C},
{0x1FA80, 0x1FA8A},
{0x1FA8E, 0x1FAC6},
{0x1FAC8, 0x1FAC8},
{0x1FACD, 0x1FADC},
{0x1FADF, 0x1FAEA},
{0x1FAEF, 0x1FAF8},
{0x20000, 0x2FFFD},
{0x30000, 0x3FFFD}
};
/* Ambiguous-width characters. */
static const struct widechar_range widechar_ambiguous_table[] = {
{0x000A1, 0x000A1},
{0x000A4, 0x000A4},
{0x000A7, 0x000A8},
{0x000AA, 0x000AA},
{0x000AD, 0x000AE},
{0x000B0, 0x000B4},
{0x000B6, 0x000BA},
{0x000BC, 0x000BF},
{0x000C6, 0x000C6},
{0x000D0, 0x000D0},
{0x000D7, 0x000D8},
{0x000DE, 0x000E1},
{0x000E6, 0x000E6},
{0x000E8, 0x000EA},
{0x000EC, 0x000ED},
{0x000F0, 0x000F0},
{0x000F2, 0x000F3},
{0x000F7, 0x000FA},
{0x000FC, 0x000FC},
{0x000FE, 0x000FE},
{0x00101, 0x00101},
{0x00111, 0x00111},
{0x00113, 0x00113},
{0x0011B, 0x0011B},
{0x00126, 0x00127},
{0x0012B, 0x0012B},
{0x00131, 0x00133},
{0x00138, 0x00138},
{0x0013F, 0x00142},
{0x00144, 0x00144},
{0x00148, 0x0014B},
{0x0014D, 0x0014D},
{0x00152, 0x00153},
{0x00166, 0x00167},
{0x0016B, 0x0016B},
{0x001CE, 0x001CE},
{0x001D0, 0x001D0},
{0x001D2, 0x001D2},
{0x001D4, 0x001D4},
{0x001D6, 0x001D6},
{0x001D8, 0x001D8},
{0x001DA, 0x001DA},
{0x001DC, 0x001DC},
{0x00251, 0x00251},
{0x00261, 0x00261},
{0x002C4, 0x002C4},
{0x002C7, 0x002C7},
{0x002C9, 0x002CB},
{0x002CD, 0x002CD},
{0x002D0, 0x002D0},
{0x002D8, 0x002DB},
{0x002DD, 0x002DD},
{0x002DF, 0x002DF},
{0x00300, 0x0036F},
{0x00391, 0x003A1},
{0x003A3, 0x003A9},
{0x003B1, 0x003C1},
{0x003C3, 0x003C9},
{0x00401, 0x00401},
{0x00410, 0x0044F},
{0x00451, 0x00451},
{0x02010, 0x02010},
{0x02013, 0x02016},
{0x02018, 0x02019},
{0x0201C, 0x0201D},
{0x02020, 0x02022},
{0x02024, 0x02027},
{0x02030, 0x02030},
{0x02032, 0x02033},
{0x02035, 0x02035},
{0x0203B, 0x0203B},
{0x0203E, 0x0203E},
{0x02074, 0x02074},
{0x0207F, 0x0207F},
{0x02081, 0x02084},
{0x020AC, 0x020AC},
{0x02103, 0x02103},
{0x02105, 0x02105},
{0x02109, 0x02109},
{0x02113, 0x02113},
{0x02116, 0x02116},
{0x02121, 0x02122},
{0x02126, 0x02126},
{0x0212B, 0x0212B},
{0x02153, 0x02154},
{0x0215B, 0x0215E},
{0x02160, 0x0216B},
{0x02170, 0x02179},
{0x02189, 0x02189},
{0x02190, 0x02199},
{0x021B8, 0x021B9},
{0x021D2, 0x021D2},
{0x021D4, 0x021D4},
{0x021E7, 0x021E7},
{0x02200, 0x02200},
{0x02202, 0x02203},
{0x02207, 0x02208},
{0x0220B, 0x0220B},
{0x0220F, 0x0220F},
{0x02211, 0x02211},
{0x02215, 0x02215},
{0x0221A, 0x0221A},
{0x0221D, 0x02220},
{0x02223, 0x02223},
{0x02225, 0x02225},
{0x02227, 0x0222C},
{0x0222E, 0x0222E},
{0x02234, 0x02237},
{0x0223C, 0x0223D},
{0x02248, 0x02248},
{0x0224C, 0x0224C},
{0x02252, 0x02252},
{0x02260, 0x02261},
{0x02264, 0x02267},
{0x0226A, 0x0226B},
{0x0226E, 0x0226F},
{0x02282, 0x02283},
{0x02286, 0x02287},
{0x02295, 0x02295},
{0x02299, 0x02299},
{0x022A5, 0x022A5},
{0x022BF, 0x022BF},
{0x02312, 0x02312},
{0x02460, 0x024E9},
{0x024EB, 0x0254B},
{0x02550, 0x02573},
{0x02580, 0x0258F},
{0x02592, 0x02595},
{0x025A0, 0x025A1},
{0x025A3, 0x025A9},
{0x025B2, 0x025B3},
{0x025B6, 0x025B7},
{0x025BC, 0x025BD},
{0x025C0, 0x025C1},
{0x025C6, 0x025C8},
{0x025CB, 0x025CB},
{0x025CE, 0x025D1},
{0x025E2, 0x025E5},
{0x025EF, 0x025EF},
{0x02605, 0x02606},
{0x02609, 0x02609},
{0x0260E, 0x0260F},
{0x0261C, 0x0261C},
{0x0261E, 0x0261E},
{0x02640, 0x02640},
{0x02642, 0x02642},
{0x02660, 0x02661},
{0x02663, 0x02665},
{0x02667, 0x0266A},
{0x0266C, 0x0266D},
{0x0266F, 0x0266F},
{0x0269E, 0x0269F},
{0x026BF, 0x026BF},
{0x026C6, 0x026CD},
{0x026CF, 0x026D3},
{0x026D5, 0x026E1},
{0x026E3, 0x026E3},
{0x026E8, 0x026E9},
{0x026EB, 0x026F1},
{0x026F4, 0x026F4},
{0x026F6, 0x026F9},
{0x026FB, 0x026FC},
{0x026FE, 0x026FF},
{0x0273D, 0x0273D},
{0x02776, 0x0277F},
{0x02B56, 0x02B59},
{0x03248, 0x0324F},
{0x0E000, 0x0F8FF},
{0x0FE00, 0x0FE0F},
{0x0FFFD, 0x0FFFD},
{0x1F100, 0x1F10A},
{0x1F110, 0x1F12D},
{0x1F130, 0x1F169},
{0x1F170, 0x1F18D},
{0x1F18F, 0x1F190},
{0x1F19B, 0x1F1AC},
{0xE0100, 0xE01EF},
{0xF0000, 0xFFFFD},
{0x100000, 0x10FFFD}
};
/* Unassigned characters. */
static const struct widechar_range widechar_unassigned_table[] = {
{0x00378, 0x00379},
{0x00380, 0x00383},
{0x0038B, 0x0038B},
{0x0038D, 0x0038D},
{0x003A2, 0x003A2},
{0x00530, 0x00530},
{0x00557, 0x00558},
{0x0058B, 0x0058C},
{0x00590, 0x00590},
{0x005C8, 0x005CF},
{0x005EB, 0x005EE},
{0x005F5, 0x005FF},
{0x0070E, 0x0070E},
{0x0074B, 0x0074C},
{0x007B2, 0x007BF},
{0x007FB, 0x007FC},
{0x0082E, 0x0082F},
{0x0083F, 0x0083F},
{0x0085C, 0x0085D},
{0x0085F, 0x0085F},
{0x0086B, 0x0086F},
{0x00892, 0x00896},
{0x00984, 0x00984},
{0x0098D, 0x0098E},
{0x00991, 0x00992},
{0x009A9, 0x009A9},
{0x009B1, 0x009B1},
{0x009B3, 0x009B5},
{0x009BA, 0x009BB},
{0x009C5, 0x009C6},
{0x009C9, 0x009CA},
{0x009CF, 0x009D6},
{0x009D8, 0x009DB},
{0x009DE, 0x009DE},
{0x009E4, 0x009E5},
{0x009FF, 0x00A00},
{0x00A04, 0x00A04},
{0x00A0B, 0x00A0E},
{0x00A11, 0x00A12},
{0x00A29, 0x00A29},
{0x00A31, 0x00A31},
{0x00A34, 0x00A34},
{0x00A37, 0x00A37},
{0x00A3A, 0x00A3B},
{0x00A3D, 0x00A3D},
{0x00A43, 0x00A46},
{0x00A49, 0x00A4A},
{0x00A4E, 0x00A50},
{0x00A52, 0x00A58},
{0x00A5D, 0x00A5D},
{0x00A5F, 0x00A65},
{0x00A77, 0x00A80},
{0x00A84, 0x00A84},
{0x00A8E, 0x00A8E},
{0x00A92, 0x00A92},
{0x00AA9, 0x00AA9},
{0x00AB1, 0x00AB1},
{0x00AB4, 0x00AB4},
{0x00ABA, 0x00ABB},
{0x00AC6, 0x00AC6},
{0x00ACA, 0x00ACA},
{0x00ACE, 0x00ACF},
{0x00AD1, 0x00ADF},
{0x00AE4, 0x00AE5},
{0x00AF2, 0x00AF8},
{0x00B00, 0x00B00},
{0x00B04, 0x00B04},
{0x00B0D, 0x00B0E},
{0x00B11, 0x00B12},
{0x00B29, 0x00B29},
{0x00B31, 0x00B31},
{0x00B34, 0x00B34},
{0x00B3A, 0x00B3B},
{0x00B45, 0x00B46},
{0x00B49, 0x00B4A},
{0x00B4E, 0x00B54},
{0x00B58, 0x00B5B},
{0x00B5E, 0x00B5E},
{0x00B64, 0x00B65},
{0x00B78, 0x00B81},
{0x00B84, 0x00B84},
{0x00B8B, 0x00B8D},
{0x00B91, 0x00B91},
{0x00B96, 0x00B98},
{0x00B9B, 0x00B9B},
{0x00B9D, 0x00B9D},
{0x00BA0, 0x00BA2},
{0x00BA5, 0x00BA7},
{0x00BAB, 0x00BAD},
{0x00BBA, 0x00BBD},
{0x00BC3, 0x00BC5},
{0x00BC9, 0x00BC9},
{0x00BCE, 0x00BCF},
{0x00BD1, 0x00BD6},
{0x00BD8, 0x00BE5},
{0x00BFB, 0x00BFF},
{0x00C0D, 0x00C0D},
{0x00C11, 0x00C11},
{0x00C29, 0x00C29},
{0x00C3A, 0x00C3B},
{0x00C45, 0x00C45},
{0x00C49, 0x00C49},
{0x00C4E, 0x00C54},
{0x00C57, 0x00C57},
{0x00C5B, 0x00C5B},
{0x00C5E, 0x00C5F},
{0x00C64, 0x00C65},
{0x00C70, 0x00C76},
{0x00C8D, 0x00C8D},
{0x00C91, 0x00C91},
{0x00CA9, 0x00CA9},
{0x00CB4, 0x00CB4},
{0x00CBA, 0x00CBB},
{0x00CC5, 0x00CC5},
{0x00CC9, 0x00CC9},
{0x00CCE, 0x00CD4},
{0x00CD7, 0x00CDB},
{0x00CDF, 0x00CDF},
{0x00CE4, 0x00CE5},
{0x00CF0, 0x00CF0},
{0x00CF4, 0x00CFF},
{0x00D0D, 0x00D0D},
{0x00D11, 0x00D11},
{0x00D45, 0x00D45},
{0x00D49, 0x00D49},
{0x00D50, 0x00D53},
{0x00D64, 0x00D65},
{0x00D80, 0x00D80},
{0x00D84, 0x00D84},
{0x00D97, 0x00D99},
{0x00DB2, 0x00DB2},
{0x00DBC, 0x00DBC},
{0x00DBE, 0x00DBF},
{0x00DC7, 0x00DC9},
{0x00DCB, 0x00DCE},
{0x00DD5, 0x00DD5},
{0x00DD7, 0x00DD7},
{0x00DE0, 0x00DE5},
{0x00DF0, 0x00DF1},
{0x00DF5, 0x00E00},
{0x00E3B, 0x00E3E},
{0x00E5C, 0x00E80},
{0x00E83, 0x00E83},
{0x00E85, 0x00E85},
{0x00E8B, 0x00E8B},
{0x00EA4, 0x00EA4},
{0x00EA6, 0x00EA6},
{0x00EBE, 0x00EBF},
{0x00EC5, 0x00EC5},
{0x00EC7, 0x00EC7},
{0x00ECF, 0x00ECF},
{0x00EDA, 0x00EDB},
{0x00EE0, 0x00EFF},
{0x00F48, 0x00F48},
{0x00F6D, 0x00F70},
{0x00F98, 0x00F98},
{0x00FBD, 0x00FBD},
{0x00FCD, 0x00FCD},
{0x00FDB, 0x00FFF},
{0x010C6, 0x010C6},
{0x010C8, 0x010CC},
{0x010CE, 0x010CF},
{0x01249, 0x01249},
{0x0124E, 0x0124F},
{0x01257, 0x01257},
{0x01259, 0x01259},
{0x0125E, 0x0125F},
{0x01289, 0x01289},
{0x0128E, 0x0128F},
{0x012B1, 0x012B1},
{0x012B6, 0x012B7},
{0x012BF, 0x012BF},
{0x012C1, 0x012C1},
{0x012C6, 0x012C7},
{0x012D7, 0x012D7},
{0x01311, 0x01311},
{0x01316, 0x01317},
{0x0135B, 0x0135C},
{0x0137D, 0x0137F},
{0x0139A, 0x0139F},
{0x013F6, 0x013F7},
{0x013FE, 0x013FF},
{0x0169D, 0x0169F},
{0x016F9, 0x016FF},
{0x01716, 0x0171E},
{0x01737, 0x0173F},
{0x01754, 0x0175F},
{0x0176D, 0x0176D},
{0x01771, 0x01771},
{0x01774, 0x0177F},
{0x017DE, 0x017DF},
{0x017EA, 0x017EF},
{0x017FA, 0x017FF},
{0x0181A, 0x0181F},
{0x01879, 0x0187F},
{0x018AB, 0x018AF},
{0x018F6, 0x018FF},
{0x0191F, 0x0191F},
{0x0192C, 0x0192F},
{0x0193C, 0x0193F},
{0x01941, 0x01943},
{0x0196E, 0x0196F},
{0x01975, 0x0197F},
{0x019AC, 0x019AF},
{0x019CA, 0x019CF},
{0x019DB, 0x019DD},
{0x01A1C, 0x01A1D},
{0x01A5F, 0x01A5F},
{0x01A7D, 0x01A7E},
{0x01A8A, 0x01A8F},
{0x01A9A, 0x01A9F},
{0x01AAE, 0x01AAF},
{0x01ADE, 0x01ADF},
{0x01AEC, 0x01AFF},
{0x01B4D, 0x01B4D},
{0x01BF4, 0x01BFB},
{0x01C38, 0x01C3A},
{0x01C4A, 0x01C4C},
{0x01C8B, 0x01C8F},
{0x01CBB, 0x01CBC},
{0x01CC8, 0x01CCF},
{0x01CFB, 0x01CFF},
{0x01F16, 0x01F17},
{0x01F1E, 0x01F1F},
{0x01F46, 0x01F47},
{0x01F4E, 0x01F4F},
{0x01F58, 0x01F58},
{0x01F5A, 0x01F5A},
{0x01F5C, 0x01F5C},
{0x01F5E, 0x01F5E},
{0x01F7E, 0x01F7F},
{0x01FB5, 0x01FB5},
{0x01FC5, 0x01FC5},
{0x01FD4, 0x01FD5},
{0x01FDC, 0x01FDC},
{0x01FF0, 0x01FF1},
{0x01FF5, 0x01FF5},
{0x01FFF, 0x01FFF},
{0x02065, 0x02065},
{0x02072, 0x02073},
{0x0208F, 0x0208F},
{0x0209D, 0x0209F},
{0x020C2, 0x020CF},
{0x020F1, 0x020FF},
{0x0218C, 0x0218F},
{0x0242A, 0x0243F},
{0x0244B, 0x0245F},
{0x02B74, 0x02B75},
{0x02CF4, 0x02CF8},
{0x02D26, 0x02D26},
{0x02D28, 0x02D2C},
{0x02D2E, 0x02D2F},
{0x02D68, 0x02D6E},
{0x02D71, 0x02D7E},
{0x02D97, 0x02D9F},
{0x02DA7, 0x02DA7},
{0x02DAF, 0x02DAF},
{0x02DB7, 0x02DB7},
{0x02DBF, 0x02DBF},
{0x02DC7, 0x02DC7},
{0x02DCF, 0x02DCF},
{0x02DD7, 0x02DD7},
{0x02DDF, 0x02DDF},
{0x02E5E, 0x02E7F},
{0x02E9A, 0x02E9A},
{0x02EF4, 0x02EFF},
{0x02FD6, 0x02FEF},
{0x03040, 0x03040},
{0x03097, 0x03098},
{0x03100, 0x03104},
{0x03130, 0x03130},
{0x0318F, 0x0318F},
{0x031E6, 0x031EE},
{0x0321F, 0x0321F},
{0x03401, 0x04DBE},
{0x04E01, 0x09FFE},
{0x0A48D, 0x0A48F},
{0x0A4C7, 0x0A4CF},
{0x0A62C, 0x0A63F},
{0x0A6F8, 0x0A6FF},
{0x0A7DD, 0x0A7F0},
{0x0A82D, 0x0A82F},
{0x0A83A, 0x0A83F},
{0x0A878, 0x0A87F},
{0x0A8C6, 0x0A8CD},
{0x0A8DA, 0x0A8DF},
{0x0A954, 0x0A95E},
{0x0A97D, 0x0A97F},
{0x0A9CE, 0x0A9CE},
{0x0A9DA, 0x0A9DD},
{0x0A9FF, 0x0A9FF},
{0x0AA37, 0x0AA3F},
{0x0AA4E, 0x0AA4F},
{0x0AA5A, 0x0AA5B},
{0x0AAC3, 0x0AADA},
{0x0AAF7, 0x0AB00},
{0x0AB07, 0x0AB08},
{0x0AB0F, 0x0AB10},
{0x0AB17, 0x0AB1F},
{0x0AB27, 0x0AB27},
{0x0AB2F, 0x0AB2F},
{0x0AB6C, 0x0AB6F},
{0x0ABEE, 0x0ABEF},
{0x0ABFA, 0x0ABFF},
{0x0AC01, 0x0D7A2},
{0x0D7A4, 0x0D7AF},
{0x0D7C7, 0x0D7CA},
{0x0D7FC, 0x0D7FF},
{0x0FA6E, 0x0FA6F},
{0x0FADA, 0x0FAFF},
{0x0FB07, 0x0FB12},
{0x0FB18, 0x0FB1C},
{0x0FB37, 0x0FB37},
{0x0FB3D, 0x0FB3D},
{0x0FB3F, 0x0FB3F},
{0x0FB42, 0x0FB42},
{0x0FB45, 0x0FB45},
{0x0FE1A, 0x0FE1F},
{0x0FE53, 0x0FE53},
{0x0FE67, 0x0FE67},
{0x0FE6C, 0x0FE6F},
{0x0FE75, 0x0FE75},
{0x0FEFD, 0x0FEFE},
{0x0FF00, 0x0FF00},
{0x0FFBF, 0x0FFC1},
{0x0FFC8, 0x0FFC9},
{0x0FFD0, 0x0FFD1},
{0x0FFD8, 0x0FFD9},
{0x0FFDD, 0x0FFDF},
{0x0FFE7, 0x0FFE7},
{0x0FFEF, 0x0FFF8},
{0x1000C, 0x1000C},
{0x10027, 0x10027},
{0x1003B, 0x1003B},
{0x1003E, 0x1003E},
{0x1004E, 0x1004F},
{0x1005E, 0x1007F},
{0x100FB, 0x100FF},
{0x10103, 0x10106},
{0x10134, 0x10136},
{0x1018F, 0x1018F},
{0x1019D, 0x1019F},
{0x101A1, 0x101CF},
{0x101FE, 0x1027F},
{0x1029D, 0x1029F},
{0x102D1, 0x102DF},
{0x102FC, 0x102FF},
{0x10324, 0x1032C},
{0x1034B, 0x1034F},
{0x1037B, 0x1037F},
{0x1039E, 0x1039E},
{0x103C4, 0x103C7},
{0x103D6, 0x103FF},
{0x1049E, 0x1049F},
{0x104AA, 0x104AF},
{0x104D4, 0x104D7},
{0x104FC, 0x104FF},
{0x10528, 0x1052F},
{0x10564, 0x1056E},
{0x1057B, 0x1057B},
{0x1058B, 0x1058B},
{0x10593, 0x10593},
{0x10596, 0x10596},
{0x105A2, 0x105A2},
{0x105B2, 0x105B2},
{0x105BA, 0x105BA},
{0x105BD, 0x105BF},
{0x105F4, 0x105FF},
{0x10737, 0x1073F},
{0x10756, 0x1075F},
{0x10768, 0x1077F},
{0x10786, 0x10786},
{0x107B1, 0x107B1},
{0x107BB, 0x107FF},
{0x10806, 0x10807},
{0x10809, 0x10809},
{0x10836, 0x10836},
{0x10839, 0x1083B},
{0x1083D, 0x1083E},
{0x10856, 0x10856},
{0x1089F, 0x108A6},
{0x108B0, 0x108DF},
{0x108F3, 0x108F3},
{0x108F6, 0x108FA},
{0x1091C, 0x1091E},
{0x1093A, 0x1093E},
{0x1095A, 0x1097F},
{0x109B8, 0x109BB},
{0x109D0, 0x109D1},
{0x10A04, 0x10A04},
{0x10A07, 0x10A0B},
{0x10A14, 0x10A14},
{0x10A18, 0x10A18},
{0x10A36, 0x10A37},
{0x10A3B, 0x10A3E},
{0x10A49, 0x10A4F},
{0x10A59, 0x10A5F},
{0x10AA0, 0x10ABF},
{0x10AE7, 0x10AEA},
{0x10AF7, 0x10AFF},
{0x10B36, 0x10B38},
{0x10B56, 0x10B57},
{0x10B73, 0x10B77},
{0x10B92, 0x10B98},
{0x10B9D, 0x10BA8},
{0x10BB0, 0x10BFF},
{0x10C49, 0x10C7F},
{0x10CB3, 0x10CBF},
{0x10CF3, 0x10CF9},
{0x10D28, 0x10D2F},
{0x10D3A, 0x10D3F},
{0x10D66, 0x10D68},
{0x10D86, 0x10D8D},
{0x10D90, 0x10E5F},
{0x10E7F, 0x10E7F},
{0x10EAA, 0x10EAA},
{0x10EAE, 0x10EAF},
{0x10EB2, 0x10EC1},
{0x10EC8, 0x10ECF},
{0x10ED9, 0x10EF9},
{0x10F28, 0x10F2F},
{0x10F5A, 0x10F6F},
{0x10F8A, 0x10FAF},
{0x10FCC, 0x10FDF},
{0x10FF7, 0x10FFF},
{0x1104E, 0x11051},
{0x11076, 0x1107E},
{0x110C3, 0x110CC},
{0x110CE, 0x110CF},
{0x110E9, 0x110EF},
{0x110FA, 0x110FF},
{0x11135, 0x11135},
{0x11148, 0x1114F},
{0x11177, 0x1117F},
{0x111E0, 0x111E0},
{0x111F5, 0x111FF},
{0x11212, 0x11212},
{0x11242, 0x1127F},
{0x11287, 0x11287},
{0x11289, 0x11289},
{0x1128E, 0x1128E},
{0x1129E, 0x1129E},
{0x112AA, 0x112AF},
{0x112EB, 0x112EF},
{0x112FA, 0x112FF},
{0x11304, 0x11304},
{0x1130D, 0x1130E},
{0x11311, 0x11312},
{0x11329, 0x11329},
{0x11331, 0x11331},
{0x11334, 0x11334},
{0x1133A, 0x1133A},
{0x11345, 0x11346},
{0x11349, 0x1134A},
{0x1134E, 0x1134F},
{0x11351, 0x11356},
{0x11358, 0x1135C},
{0x11364, 0x11365},
{0x1136D, 0x1136F},
{0x11375, 0x1137F},
{0x1138A, 0x1138A},
{0x1138C, 0x1138D},
{0x1138F, 0x1138F},
{0x113B6, 0x113B6},
{0x113C1, 0x113C1},
{0x113C3, 0x113C4},
{0x113C6, 0x113C6},
{0x113CB, 0x113CB},
{0x113D6, 0x113D6},
{0x113D9, 0x113E0},
{0x113E3, 0x113FF},
{0x1145C, 0x1145C},
{0x11462, 0x1147F},
{0x114C8, 0x114CF},
{0x114DA, 0x1157F},
{0x115B6, 0x115B7},
{0x115DE, 0x115FF},
{0x11645, 0x1164F},
{0x1165A, 0x1165F},
{0x1166D, 0x1167F},
{0x116BA, 0x116BF},
{0x116CA, 0x116CF},
{0x116E4, 0x116FF},
{0x1171B, 0x1171C},
{0x1172C, 0x1172F},
{0x11747, 0x117FF},
{0x1183C, 0x1189F},
{0x118F3, 0x118FE},
{0x11907, 0x11908},
{0x1190A, 0x1190B},
{0x11914, 0x11914},
{0x11917, 0x11917},
{0x11936, 0x11936},
{0x11939, 0x1193A},
{0x11947, 0x1194F},
{0x1195A, 0x1199F},
{0x119A8, 0x119A9},
{0x119D8, 0x119D9},
{0x119E5, 0x119FF},
{0x11A48, 0x11A4F},
{0x11AA3, 0x11AAF},
{0x11AF9, 0x11AFF},
{0x11B0A, 0x11B5F},
{0x11B68, 0x11BBF},
{0x11BE2, 0x11BEF},
{0x11BFA, 0x11BFF},
{0x11C09, 0x11C09},
{0x11C37, 0x11C37},
{0x11C46, 0x11C4F},
{0x11C6D, 0x11C6F},
{0x11C90, 0x11C91},
{0x11CA8, 0x11CA8},
{0x11CB7, 0x11CFF},
{0x11D07, 0x11D07},
{0x11D0A, 0x11D0A},
{0x11D37, 0x11D39},
{0x11D3B, 0x11D3B},
{0x11D3E, 0x11D3E},
{0x11D48, 0x11D4F},
{0x11D5A, 0x11D5F},
{0x11D66, 0x11D66},
{0x11D69, 0x11D69},
{0x11D8F, 0x11D8F},
{0x11D92, 0x11D92},
{0x11D99, 0x11D9F},
{0x11DAA, 0x11DAF},
{0x11DDC, 0x11DDF},
{0x11DEA, 0x11EDF},
{0x11EF9, 0x11EFF},
{0x11F11, 0x11F11},
{0x11F3B, 0x11F3D},
{0x11F5B, 0x11FAF},
{0x11FB1, 0x11FBF},
{0x11FF2, 0x11FFE},
{0x1239A, 0x123FF},
{0x1246F, 0x1246F},
{0x12475, 0x1247F},
{0x12544, 0x12F8F},
{0x12FF3, 0x12FFF},
{0x13456, 0x1345F},
{0x143FB, 0x143FF},
{0x14647, 0x160FF},
{0x1613A, 0x167FF},
{0x16A39, 0x16A3F},
{0x16A5F, 0x16A5F},
{0x16A6A, 0x16A6D},
{0x16ABF, 0x16ABF},
{0x16ACA, 0x16ACF},
{0x16AEE, 0x16AEF},
{0x16AF6, 0x16AFF},
{0x16B46, 0x16B4F},
{0x16B5A, 0x16B5A},
{0x16B62, 0x16B62},
{0x16B78, 0x16B7C},
{0x16B90, 0x16D3F},
{0x16D7A, 0x16E3F},
{0x16E9B, 0x16E9F},
{0x16EB9, 0x16EBA},
{0x16ED4, 0x16EFF},
{0x16F4B, 0x16F4E},
{0x16F88, 0x16F8E},
{0x16FA0, 0x16FDF},
{0x16FE5, 0x16FEF},
{0x16FF7, 0x16FFF},
{0x17001, 0x187FE},
{0x18CD6, 0x18CFE},
{0x18D01, 0x18D1D},
{0x18D1F, 0x18D7F},
{0x18DF3, 0x1AFEF},
{0x1AFF4, 0x1AFF4},
{0x1AFFC, 0x1AFFC},
{0x1AFFF, 0x1AFFF},
{0x1B123, 0x1B131},
{0x1B133, 0x1B14F},
{0x1B153, 0x1B154},
{0x1B156, 0x1B163},
{0x1B168, 0x1B16F},
{0x1B2FC, 0x1BBFF},
{0x1BC6B, 0x1BC6F},
{0x1BC7D, 0x1BC7F},
{0x1BC89, 0x1BC8F},
{0x1BC9A, 0x1BC9B},
{0x1BCA4, 0x1CBFF},
{0x1CCFD, 0x1CCFF},
{0x1CEB4, 0x1CEB9},
{0x1CED1, 0x1CEDF},
{0x1CEF1, 0x1CEFF},
{0x1CF2E, 0x1CF2F},
{0x1CF47, 0x1CF4F},
{0x1CFC4, 0x1CFFF},
{0x1D0F6, 0x1D0FF},
{0x1D127, 0x1D128},
{0x1D1EB, 0x1D1FF},
{0x1D246, 0x1D2BF},
{0x1D2D4, 0x1D2DF},
{0x1D2F4, 0x1D2FF},
{0x1D357, 0x1D35F},
{0x1D379, 0x1D3FF},
{0x1D455, 0x1D455},
{0x1D49D, 0x1D49D},
{0x1D4A0, 0x1D4A1},
{0x1D4A3, 0x1D4A4},
{0x1D4A7, 0x1D4A8},
{0x1D4AD, 0x1D4AD},
{0x1D4BA, 0x1D4BA},
{0x1D4BC, 0x1D4BC},
{0x1D4C4, 0x1D4C4},
{0x1D506, 0x1D506},
{0x1D50B, 0x1D50C},
{0x1D515, 0x1D515},
{0x1D51D, 0x1D51D},
{0x1D53A, 0x1D53A},
{0x1D53F, 0x1D53F},
{0x1D545, 0x1D545},
{0x1D547, 0x1D549},
{0x1D551, 0x1D551},
{0x1D6A6, 0x1D6A7},
{0x1D7CC, 0x1D7CD},
{0x1DA8C, 0x1DA9A},
{0x1DAA0, 0x1DAA0},
{0x1DAB0, 0x1DEFF},
{0x1DF1F, 0x1DF24},
{0x1DF2B, 0x1DFFF},
{0x1E007, 0x1E007},
{0x1E019, 0x1E01A},
{0x1E022, 0x1E022},
{0x1E025, 0x1E025},
{0x1E02B, 0x1E02F},
{0x1E06E, 0x1E08E},
{0x1E090, 0x1E0FF},
{0x1E12D, 0x1E12F},
{0x1E13E, 0x1E13F},
{0x1E14A, 0x1E14D},
{0x1E150, 0x1E28F},
{0x1E2AF, 0x1E2BF},
{0x1E2FA, 0x1E2FE},
{0x1E300, 0x1E4CF},
{0x1E4FA, 0x1E5CF},
{0x1E5FB, 0x1E5FE},
{0x1E600, 0x1E6BF},
{0x1E6DF, 0x1E6DF},
{0x1E6F6, 0x1E6FD},
{0x1E700, 0x1E7DF},
{0x1E7E7, 0x1E7E7},
{0x1E7EC, 0x1E7EC},
{0x1E7EF, 0x1E7EF},
{0x1E7FF, 0x1E7FF},
{0x1E8C5, 0x1E8C6},
{0x1E8D7, 0x1E8FF},
{0x1E94C, 0x1E94F},
{0x1E95A, 0x1E95D},
{0x1E960, 0x1EC70},
{0x1ECB5, 0x1ED00},
{0x1ED3E, 0x1EDFF},
{0x1EE04, 0x1EE04},
{0x1EE20, 0x1EE20},
{0x1EE23, 0x1EE23},
{0x1EE25, 0x1EE26},
{0x1EE28, 0x1EE28},
{0x1EE33, 0x1EE33},
{0x1EE38, 0x1EE38},
{0x1EE3A, 0x1EE3A},
{0x1EE3C, 0x1EE41},
{0x1EE43, 0x1EE46},
{0x1EE48, 0x1EE48},
{0x1EE4A, 0x1EE4A},
{0x1EE4C, 0x1EE4C},
{0x1EE50, 0x1EE50},
{0x1EE53, 0x1EE53},
{0x1EE55, 0x1EE56},
{0x1EE58, 0x1EE58},
{0x1EE5A, 0x1EE5A},
{0x1EE5C, 0x1EE5C},
{0x1EE5E, 0x1EE5E},
{0x1EE60, 0x1EE60},
{0x1EE63, 0x1EE63},
{0x1EE65, 0x1EE66},
{0x1EE6B, 0x1EE6B},
{0x1EE73, 0x1EE73},
{0x1EE78, 0x1EE78},
{0x1EE7D, 0x1EE7D},
{0x1EE7F, 0x1EE7F},
{0x1EE8A, 0x1EE8A},
{0x1EE9C, 0x1EEA0},
{0x1EEA4, 0x1EEA4},
{0x1EEAA, 0x1EEAA},
{0x1EEBC, 0x1EEEF},
{0x1EEF2, 0x1EFFF},
{0x1F02C, 0x1F02F},
{0x1F094, 0x1F09F},
{0x1F0AF, 0x1F0B0},
{0x1F0C0, 0x1F0C0},
{0x1F0D0, 0x1F0D0},
{0x1F0F6, 0x1F0FF},
{0x1F1AE, 0x1F1E5},
{0x1F203, 0x1F20F},
{0x1F23C, 0x1F23F},
{0x1F249, 0x1F24F},
{0x1F252, 0x1F25F},
{0x1F266, 0x1F2FF},
{0x1F6D9, 0x1F6DB},
{0x1F6ED, 0x1F6EF},
{0x1F6FD, 0x1F6FF},
{0x1F7DA, 0x1F7DF},
{0x1F7EC, 0x1F7EF},
{0x1F7F1, 0x1F7FF},
{0x1F80C, 0x1F80F},
{0x1F848, 0x1F84F},
{0x1F85A, 0x1F85F},
{0x1F888, 0x1F88F},
{0x1F8AE, 0x1F8AF},
{0x1F8BC, 0x1F8BF},
{0x1F8C2, 0x1F8CF},
{0x1F8D9, 0x1F8FF},
{0x1FA58, 0x1FA5F},
{0x1FA6E, 0x1FA6F},
{0x1FA7D, 0x1FA7F},
{0x1FA8B, 0x1FA8D},
{0x1FAC7, 0x1FAC7},
{0x1FAC9, 0x1FACC},
{0x1FADD, 0x1FADE},
{0x1FAEB, 0x1FAEE},
{0x1FAF9, 0x1FAFF},
{0x1FB93, 0x1FB93},
{0x1FBFB, 0x1FFFD},
{0x20001, 0x2A6DE},
{0x2A6E0, 0x2A6FF},
{0x2A701, 0x2B73E},
{0x2B741, 0x2B81C},
{0x2B81E, 0x2B81F},
{0x2B821, 0x2CEAC},
{0x2CEAE, 0x2CEAF},
{0x2CEB1, 0x2EBDF},
{0x2EBE1, 0x2EBEF},
{0x2EBF1, 0x2EE5C},
{0x2EE5E, 0x2F7FF},
{0x2FA1E, 0x2FFFD},
{0x30001, 0x31349},
{0x3134B, 0x3134F},
{0x31351, 0x323AE},
{0x323B1, 0x33478},
{0x3347A, 0x3FFFD},
{0x40000, 0x4FFFD},
{0x50000, 0x5FFFD},
{0x60000, 0x6FFFD},
{0x70000, 0x7FFFD},
{0x80000, 0x8FFFD},
{0x90000, 0x9FFFD},
{0xA0000, 0xAFFFD},
{0xB0000, 0xBFFFD},
{0xC0000, 0xCFFFD},
{0xD0000, 0xDFFFD},
{0xE0000, 0xE0000},
{0xE0002, 0xE001F},
{0xE0080, 0xE00FF},
{0xE01F0, 0xEFFFD}
};
/* Non-characters. */
static const struct widechar_range widechar_nonchar_table[] = {
{0x0FDD0, 0x0FDEF},
{0x0FFFE, 0x0FFFF},
{0x1FFFE, 0x1FFFF},
{0x2FFFE, 0x2FFFF},
{0x3FFFE, 0x3FFFF},
{0x4FFFE, 0x4FFFF},
{0x5FFFE, 0x5FFFF},
{0x6FFFE, 0x6FFFF},
{0x7FFFE, 0x7FFFF},
{0x8FFFE, 0x8FFFF},
{0x9FFFE, 0x9FFFF},
{0xAFFFE, 0xAFFFF},
{0xBFFFE, 0xBFFFF},
{0xCFFFE, 0xCFFFF},
{0xDFFFE, 0xDFFFF},
{0xEFFFE, 0xEFFFF},
{0xFFFFE, 0xFFFFF},
{0x10FFFE, 0x10FFFF}
};
/* Characters that were widened from width 1 to 2 in Unicode 9. */
static const struct widechar_range widechar_widened_table[] = {
{0x0231A, 0x0231B},
{0x023E9, 0x023EC},
{0x023F0, 0x023F0},
{0x023F3, 0x023F3},
{0x025FD, 0x025FE},
{0x02614, 0x02615},
{0x02648, 0x02653},
{0x0267F, 0x0267F},
{0x02693, 0x02693},
{0x026A1, 0x026A1},
{0x026AA, 0x026AB},
{0x026BD, 0x026BE},
{0x026C4, 0x026C5},
{0x026CE, 0x026CE},
{0x026D4, 0x026D4},
{0x026EA, 0x026EA},
{0x026F2, 0x026F3},
{0x026F5, 0x026F5},
{0x026FA, 0x026FA},
{0x026FD, 0x026FD},
{0x02705, 0x02705},
{0x0270A, 0x0270B},
{0x02728, 0x02728},
{0x0274C, 0x0274C},
{0x0274E, 0x0274E},
{0x02753, 0x02755},
{0x02757, 0x02757},
{0x02795, 0x02797},
{0x027B0, 0x027B0},
{0x027BF, 0x027BF},
{0x02B1B, 0x02B1C},
{0x02B50, 0x02B50},
{0x02B55, 0x02B55},
{0x1F004, 0x1F004},
{0x1F0CF, 0x1F0CF},
{0x1F18E, 0x1F18E},
{0x1F191, 0x1F19A},
{0x1F201, 0x1F201},
{0x1F21A, 0x1F21A},
{0x1F22F, 0x1F22F},
{0x1F232, 0x1F236},
{0x1F238, 0x1F23A},
{0x1F250, 0x1F251},
{0x1F300, 0x1F320},
{0x1F32D, 0x1F335},
{0x1F337, 0x1F37C},
{0x1F37E, 0x1F393},
{0x1F3A0, 0x1F3CA},
{0x1F3CF, 0x1F3D3},
{0x1F3E0, 0x1F3F0},
{0x1F3F4, 0x1F3F4},
{0x1F3F8, 0x1F43E},
{0x1F440, 0x1F440},
{0x1F442, 0x1F4FC},
{0x1F4FF, 0x1F53D},
{0x1F54B, 0x1F54E},
{0x1F550, 0x1F567},
{0x1F595, 0x1F596},
{0x1F5FB, 0x1F64F},
{0x1F680, 0x1F6C5},
{0x1F6CC, 0x1F6CC},
{0x1F6D0, 0x1F6D0},
{0x1F6EB, 0x1F6EC},
{0x1F910, 0x1F918},
{0x1F980, 0x1F984},
{0x1F9C0, 0x1F9C0}
};
static inline bool widechar_in_table(const struct widechar_range* arr, size_t len, uint32_t c) {
size_t lo=0;
size_t hi=len;
if(c < arr[0].lo) return(0);
if(c > arr[len-1].hi) return(0);
while(1) {
size_t mid = ((hi-lo)/2)+lo;
if( (c >= arr[mid].lo) && (c <= arr[mid].hi)) {
return(1);
}
if(mid == lo) return(0);
if (c < arr[mid].lo) {
hi = mid;
} else {
lo = mid;
}
}
return(0);
}
/* Return the width of character c, or a special negative value. */
int widechar_wcwidth(uint32_t c) {
if (widechar_in_table(widechar_ascii_table, widechar_ARRAY_SIZE(widechar_ascii_table), c))
return 1;
if (widechar_in_table(widechar_private_table, widechar_ARRAY_SIZE(widechar_private_table), c))
return widechar_private_use;
if (widechar_in_table(widechar_nonprint_table, widechar_ARRAY_SIZE(widechar_nonprint_table), c))
return widechar_nonprint;
if (widechar_in_table(widechar_nonchar_table, widechar_ARRAY_SIZE(widechar_nonchar_table), c))
return widechar_non_character;
if (widechar_in_table(widechar_combining_table, widechar_ARRAY_SIZE(widechar_combining_table), c))
return widechar_combining;
if (widechar_in_table(widechar_combiningletters_table, widechar_ARRAY_SIZE(widechar_combiningletters_table), c))
return widechar_combining;
if (widechar_in_table(widechar_doublewide_table, widechar_ARRAY_SIZE(widechar_doublewide_table), c))
return 2;
if (widechar_in_table(widechar_ambiguous_table, widechar_ARRAY_SIZE(widechar_ambiguous_table), c))
return widechar_ambiguous;
if (widechar_in_table(widechar_unassigned_table, widechar_ARRAY_SIZE(widechar_unassigned_table), c))
return widechar_unassigned;
if (widechar_in_table(widechar_widened_table, widechar_ARRAY_SIZE(widechar_widened_table), c))
return widechar_widened_in_9;
return 1;
}
#endif // WIDECHAR_WIDTH_H
================================================
FILE: src/3rdparty/yyjson/repo.json
================================================
{
"home": "https://github.com/ibireme/yyjson",
"license": "MIT ( embed in source )",
"version": "0.12.0",
"author": "ibireme"
}
================================================
FILE: src/3rdparty/yyjson/yyjson.c
================================================
/*==============================================================================
Copyright (c) 2020 YaoYuan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*============================================================================*/
#include "yyjson.h"
#include /* for `HUGE_VAL/INFINIY/NAN` macros, no libm required */
/*==============================================================================
* MARK: - Warning Suppress (Private)
*============================================================================*/
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wunused-label"
# pragma clang diagnostic ignored "-Wunused-macros"
# pragma clang diagnostic ignored "-Wunused-variable"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wunused-function"
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wunused-label"
# pragma GCC diagnostic ignored "-Wunused-macros"
# pragma GCC diagnostic ignored "-Wunused-variable"
#elif defined(_MSC_VER)
# pragma warning(disable:4100) /* unreferenced formal parameter */
# pragma warning(disable:4101) /* unreferenced variable */
# pragma warning(disable:4102) /* unreferenced label */
# pragma warning(disable:4127) /* conditional expression is constant */
# pragma warning(disable:4706) /* assignment within conditional expression */
#endif
/*==============================================================================
* MARK: - Version (Public)
*============================================================================*/
uint32_t yyjson_version(void) {
return YYJSON_VERSION_HEX;
}
/*==============================================================================
* MARK: - Flags (Private)
*============================================================================*/
/* msvc intrinsic */
#if YYJSON_MSC_VER >= 1400
# include
# if defined(_M_AMD64) || defined(_M_ARM64)
# define MSC_HAS_BIT_SCAN_64 1
# pragma intrinsic(_BitScanForward64)
# pragma intrinsic(_BitScanReverse64)
# else
# define MSC_HAS_BIT_SCAN_64 0
# endif
# if defined(_M_AMD64) || defined(_M_ARM64) || \
defined(_M_IX86) || defined(_M_ARM)
# define MSC_HAS_BIT_SCAN 1
# pragma intrinsic(_BitScanForward)
# pragma intrinsic(_BitScanReverse)
# else
# define MSC_HAS_BIT_SCAN 0
# endif
# if defined(_M_AMD64)
# define MSC_HAS_UMUL128 1
# pragma intrinsic(_umul128)
# else
# define MSC_HAS_UMUL128 0
# endif
#else
# define MSC_HAS_BIT_SCAN_64 0
# define MSC_HAS_BIT_SCAN 0
# define MSC_HAS_UMUL128 0
#endif
/* gcc builtin */
#if yyjson_has_builtin(__builtin_clzll) || yyjson_gcc_available(3, 4, 0)
# define GCC_HAS_CLZLL 1
#else
# define GCC_HAS_CLZLL 0
#endif
#if yyjson_has_builtin(__builtin_ctzll) || yyjson_gcc_available(3, 4, 0)
# define GCC_HAS_CTZLL 1
#else
# define GCC_HAS_CTZLL 0
#endif
/* int128 type */
#if defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16) && \
(defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER))
# define YYJSON_HAS_INT128 1
#else
# define YYJSON_HAS_INT128 0
#endif
/* IEEE 754 floating-point binary representation */
#if defined(__STDC_IEC_559__) || defined(__STDC_IEC_60559_BFP__)
# define YYJSON_HAS_IEEE_754 1
#elif FLT_RADIX == 2 && \
FLT_MANT_DIG == 24 && FLT_DIG == 6 && \
FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128 && \
FLT_MIN_10_EXP == -37 && FLT_MAX_10_EXP == 38 && \
DBL_MANT_DIG == 53 && DBL_DIG == 15 && \
DBL_MIN_EXP == -1021 && DBL_MAX_EXP == 1024 && \
DBL_MIN_10_EXP == -307 && DBL_MAX_10_EXP == 308
# define YYJSON_HAS_IEEE_754 1
#else
# define YYJSON_HAS_IEEE_754 0
# undef YYJSON_DISABLE_FAST_FP_CONV
# define YYJSON_DISABLE_FAST_FP_CONV 1
#endif
/*
Correct rounding in double number computations.
On the x86 architecture, some compilers may use x87 FPU instructions for
floating-point arithmetic. The x87 FPU loads all floating point number as
80-bit double-extended precision internally, then rounds the result to original
precision, which may produce inaccurate results. For a more detailed
explanation, see the paper: https://arxiv.org/abs/cs/0701192
Here are some examples of double precision calculation error:
2877.0 / 1e6 == 0.002877, but x87 returns 0.0028770000000000002
43683.0 * 1e21 == 4.3683e25, but x87 returns 4.3683000000000004e25
Here are some examples of compiler flags to generate x87 instructions on x86:
clang -m32 -mno-sse
gcc/icc -m32 -mfpmath=387
msvc /arch:SSE or /arch:IA32
If we are sure that there's no similar error described above, we can define the
YYJSON_DOUBLE_MATH_CORRECT as 1 to enable the fast path calculation. This is
not an accurate detection, it's just try to avoid the error at compile-time.
An accurate detection can be done at run-time:
bool is_double_math_correct(void) {
volatile double r = 43683.0;
r *= 1e21;
return r == 4.3683e25;
}
See also: utils.h in https://github.com/google/double-conversion/
*/
#if !defined(FLT_EVAL_METHOD) && defined(__FLT_EVAL_METHOD__)
# define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#endif
#if defined(FLT_EVAL_METHOD) && FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1
# define YYJSON_DOUBLE_MATH_CORRECT 0
#elif defined(i386) || defined(__i386) || defined(__i386__) || \
defined(_X86_) || defined(__X86__) || defined(_M_IX86) || \
defined(__I86__) || defined(__IA32__) || defined(__THW_INTEL)
# if (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP == 2) || \
(defined(__SSE2_MATH__) && __SSE2_MATH__)
# define YYJSON_DOUBLE_MATH_CORRECT 1
# else
# define YYJSON_DOUBLE_MATH_CORRECT 0
# endif
#elif defined(__mc68000__) || defined(__pnacl__) || defined(__native_client__)
# define YYJSON_DOUBLE_MATH_CORRECT 0
#else
# define YYJSON_DOUBLE_MATH_CORRECT 1
#endif
/*
Detect the endianness at compile-time.
YYJSON_ENDIAN == YYJSON_BIG_ENDIAN
YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN
*/
#define YYJSON_BIG_ENDIAN 4321
#define YYJSON_LITTLE_ENDIAN 1234
#if yyjson_has_include()
# include /* POSIX */
#endif
#if yyjson_has_include()
# include /* Linux */
#elif yyjson_has_include()
# include /* BSD, Android */
#elif yyjson_has_include()
# include /* BSD, Darwin */
#endif
#if defined(BYTE_ORDER) && BYTE_ORDER
# if defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN
# elif defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)
# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN
# endif
#elif defined(__BYTE_ORDER) && __BYTE_ORDER
# if defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN)
# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN
# elif defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN)
# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN
# endif
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__
# if defined(__ORDER_BIG_ENDIAN__) && \
(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN
# elif defined(__ORDER_LITTLE_ENDIAN__) && \
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN
# endif
#elif (defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \
defined(__i386) || defined(__i386__) || \
defined(_X86_) || defined(__X86__) || \
defined(_M_IX86) || defined(__THW_INTEL__) || \
defined(__x86_64) || defined(__x86_64__) || \
defined(__amd64) || defined(__amd64__) || \
defined(_M_AMD64) || defined(_M_X64) || \
defined(_M_ARM) || defined(_M_ARM64) || \
defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \
defined(__EMSCRIPTEN__) || defined(__wasm__) || \
defined(__loongarch__)
# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN
#elif (defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \
defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \
defined(__or1k__) || defined(__OR1K__)
# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN
#else
# define YYJSON_ENDIAN 0 /* unknown endian, detect at run-time */
#endif
/*
This macro controls how yyjson handles unaligned memory accesses.
By default, yyjson uses `memcpy()` for memory copying. This allows the compiler
to optimize the code and emit unaligned memory access instructions when
supported by the target architecture.
However, on some older compilers or architectures where `memcpy()` is not
well-optimized and may result in unnecessary function calls, defining this
macro as 1 may help. In such cases, yyjson switches to manual byte-by-byte
access, which can potentially improve performance.
An example of the generated assembly code for ARM can be found here:
https://godbolt.org/z/334jjhxPT
This flag is already enabled for common architectures in the following code,
so manual configuration is usually unnecessary. If unsure, you can check the
generated assembly or run benchmarks to make an informed decision.
*/
#ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
# if defined(__ia64) || defined(_IA64) || defined(__IA64__) || \
defined(__ia64__) || defined(_M_IA64) || defined(__itanium__)
# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* Itanium */
# elif (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) && \
(defined(__GNUC__) || defined(__clang__)) && \
(!defined(__ARM_FEATURE_UNALIGNED) || !__ARM_FEATURE_UNALIGNED)
# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* ARM */
# elif defined(__sparc) || defined(__sparc__)
# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* SPARC */
# elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* MIPS */
# elif defined(__m68k__) || defined(M68000)
# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* M68K */
# else
# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 0
# endif
#endif
/*
Estimated initial ratio of the JSON data (data_size / value_count).
For example:
data: {"id":12345678,"name":"Harry"}
data_size: 30
value_count: 5
ratio: 6
yyjson uses dynamic memory with a growth factor of 1.5 when reading and writing
JSON, the ratios below are used to determine the initial memory size.
A too large ratio will waste memory, and a too small ratio will cause multiple
memory growths and degrade performance. Currently, these ratios are generated
with some commonly used JSON datasets.
*/
#define YYJSON_READER_ESTIMATED_PRETTY_RATIO 16
#define YYJSON_READER_ESTIMATED_MINIFY_RATIO 6
#define YYJSON_WRITER_ESTIMATED_PRETTY_RATIO 32
#define YYJSON_WRITER_ESTIMATED_MINIFY_RATIO 18
/* The initial and maximum size of the memory pool's chunk in yyjson_mut_doc. */
#define YYJSON_MUT_DOC_STR_POOL_INIT_SIZE 0x100
#define YYJSON_MUT_DOC_STR_POOL_MAX_SIZE 0x10000000
#define YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE (0x10 * sizeof(yyjson_mut_val))
#define YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE (0x1000000 * sizeof(yyjson_mut_val))
/* The minimum size of the dynamic allocator's chunk. */
#define YYJSON_ALC_DYN_MIN_SIZE 0x1000
/* Default value for compile-time options. */
#ifndef YYJSON_DISABLE_READER
#define YYJSON_DISABLE_READER 0
#endif
#ifndef YYJSON_DISABLE_WRITER
#define YYJSON_DISABLE_WRITER 0
#endif
#ifndef YYJSON_DISABLE_INCR_READER
#define YYJSON_DISABLE_INCR_READER 0
#endif
#ifndef YYJSON_DISABLE_UTILS
#define YYJSON_DISABLE_UTILS 0
#endif
#ifndef YYJSON_DISABLE_FAST_FP_CONV
#define YYJSON_DISABLE_FAST_FP_CONV 0
#endif
#ifndef YYJSON_DISABLE_NON_STANDARD
#define YYJSON_DISABLE_NON_STANDARD 0
#endif
#ifndef YYJSON_DISABLE_UTF8_VALIDATION
#define YYJSON_DISABLE_UTF8_VALIDATION 0
#endif
/*==============================================================================
* MARK: - Macros (Private)
*============================================================================*/
/* Macros used for loop unrolling and other purpose. */
#define repeat2(x) { x x }
#define repeat4(x) { x x x x }
#define repeat8(x) { x x x x x x x x }
#define repeat16(x) { x x x x x x x x x x x x x x x x }
#define repeat2_incr(x) { x(0) x(1) }
#define repeat4_incr(x) { x(0) x(1) x(2) x(3) }
#define repeat8_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) }
#define repeat16_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \
x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) }
#define repeat_in_1_18(x) { x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) \
x(9) x(10) x(11) x(12) x(13) x(14) x(15) x(16) \
x(17) x(18) }
/* Macros used to provide branch prediction information for compiler. */
#undef likely
#define likely(x) yyjson_likely(x)
#undef unlikely
#define unlikely(x) yyjson_unlikely(x)
/* Macros used to provide inline information for compiler. */
#undef static_inline
#define static_inline static yyjson_inline
#undef static_noinline
#define static_noinline static yyjson_noinline
/* Macros for min and max. */
#undef yyjson_min
#define yyjson_min(x, y) ((x) < (y) ? (x) : (y))
#undef yyjson_max
#define yyjson_max(x, y) ((x) > (y) ? (x) : (y))
/* Used to write u64 literal for C89 which doesn't support "ULL" suffix. */
#undef U64
#define U64(hi, lo) ((((u64)hi##UL) << 32U) + lo##UL)
#undef U32
#define U32(hi) ((u32)(hi##UL))
/* Used to cast away (remove) const qualifier. */
#define constcast(type) (type)(void *)(size_t)(const void *)
/*
Compiler barriers for single variables.
These macros inform GCC that a read or write access to the given memory
location will occur, preventing certain compiler optimizations or reordering
around the access to 'val'. They do not emit any actual instructions.
This is useful when GCC's default optimization strategies are suboptimal and
precise control over memory access patterns is required.
These barriers are not needed when using Clang or MSVC.
*/
#if YYJSON_IS_REAL_GCC
# define gcc_load_barrier(val) __asm__ volatile(""::"m"(val))
# define gcc_store_barrier(val) __asm__ volatile("":"=m"(val))
# define gcc_full_barrier(val) __asm__ volatile("":"=m"(val):"m"(val))
#else
# define gcc_load_barrier(val)
# define gcc_store_barrier(val)
# define gcc_full_barrier(val)
#endif
/*==============================================================================
* MARK: - Constants (Private)
*============================================================================*/
/* Common error messages. */
#define MSG_FOPEN "failed to open file"
#define MSG_FREAD "failed to read file"
#define MSG_FWRITE "failed to write file"
#define MSG_FCLOSE "failed to close file"
#define MSG_MALLOC "failed to allocate memory"
#define MSG_CHAR_T "invalid literal, expected 'true'"
#define MSG_CHAR_F "invalid literal, expected 'false'"
#define MSG_CHAR_N "invalid literal, expected 'null'"
#define MSG_CHAR "unexpected character, expected a JSON value"
#define MSG_ARR_END "unexpected character, expected ',' or ']'"
#define MSG_OBJ_KEY "unexpected character, expected a string key"
#define MSG_OBJ_SEP "unexpected character, expected ':' after key"
#define MSG_OBJ_END "unexpected character, expected ',' or '}'"
#define MSG_GARBAGE "unexpected content after document"
#define MSG_NOT_END "unexpected end of data"
#define MSG_COMMENT "unclosed multiline comment"
#define MSG_COMMA "trailing comma is not allowed"
#define MSG_NAN_INF "nan or inf number is not allowed"
#define MSG_ERR_TYPE "invalid JSON value type"
#define MSG_ERR_BOM "UTF-8 byte order mark (BOM) is not supported"
#define MSG_ERR_UTF8 "invalid utf-8 encoding in string"
#define MSG_ERR_UTF16 "UTF-16 encoding is not supported"
#define MSG_ERR_UTF32 "UTF-32 encoding is not supported"
/* U64 constant values */
#undef U64_MAX
#define U64_MAX U64(0xFFFFFFFF, 0xFFFFFFFF)
#undef I64_MAX
#define I64_MAX U64(0x7FFFFFFF, 0xFFFFFFFF)
#undef USIZE_MAX
#define USIZE_MAX ((usize)(~(usize)0))
/* Maximum number of digits for reading u32/u64/usize safety (not overflow). */
#undef U32_SAFE_DIG
#define U32_SAFE_DIG 9 /* u32 max is 4294967295, 10 digits */
#undef U64_SAFE_DIG
#define U64_SAFE_DIG 19 /* u64 max is 18446744073709551615, 20 digits */
#undef USIZE_SAFE_DIG
#define USIZE_SAFE_DIG (sizeof(usize) == 8 ? U64_SAFE_DIG : U32_SAFE_DIG)
/* Inf bits (positive) */
#define F64_BITS_INF U64(0x7FF00000, 0x00000000)
/* NaN bits (quiet NaN, no payload, no sign) */
#if defined(__hppa__) || (defined(__mips__) && !defined(__mips_nan2008))
#define F64_BITS_NAN U64(0x7FF7FFFF, 0xFFFFFFFF)
#else
#define F64_BITS_NAN U64(0x7FF80000, 0x00000000)
#endif
/* maximum significant digits count in decimal when reading double number */
#define F64_MAX_DEC_DIG 768
/* maximum decimal power of double number (1.7976931348623157e308) */
#define F64_MAX_DEC_EXP 308
/* minimum decimal power of double number (4.9406564584124654e-324) */
#define F64_MIN_DEC_EXP (-324)
/* maximum binary power of double number */
#define F64_MAX_BIN_EXP 1024
/* minimum binary power of double number */
#define F64_MIN_BIN_EXP (-1021)
/* float/double number bits */
#define F32_BITS 32
#define F64_BITS 64
/* float/double number exponent part bits */
#define F32_EXP_BITS 8
#define F64_EXP_BITS 11
/* float/double number significand part bits */
#define F32_SIG_BITS 23
#define F64_SIG_BITS 52
/* float/double number significand part bits (with 1 hidden bit) */
#define F32_SIG_FULL_BITS 24
#define F64_SIG_FULL_BITS 53
/* float/double number significand bit mask */
#define F32_SIG_MASK U32(0x007FFFFF)
#define F64_SIG_MASK U64(0x000FFFFF, 0xFFFFFFFF)
/* float/double number exponent bit mask */
#define F32_EXP_MASK U32(0x7F800000)
#define F64_EXP_MASK U64(0x7FF00000, 0x00000000)
/* float/double number exponent bias */
#define F32_EXP_BIAS 127
#define F64_EXP_BIAS 1023
/* float/double number significant digits count in decimal */
#define F32_DEC_DIG 9
#define F64_DEC_DIG 17
/* buffer length required for float/double number writer */
#define FP_BUF_LEN 40
/* maximum length of a number in incremental parsing */
#define INCR_NUM_MAX_LEN 1024
/*==============================================================================
* MARK: - Types (Private)
*============================================================================*/
/** Type define for primitive types. */
typedef float f32;
typedef double f64;
typedef int8_t i8;
typedef uint8_t u8;
typedef int16_t i16;
typedef uint16_t u16;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef size_t usize;
/** 128-bit integer, used by floating-point number reader and writer. */
#if YYJSON_HAS_INT128
__extension__ typedef __int128 i128;
__extension__ typedef unsigned __int128 u128;
#endif
/** 16/32/64-bit vector */
typedef struct v16 { char c[2]; } v16;
typedef struct v32 { char c[4]; } v32;
typedef struct v64 { char c[8]; } v64;
/** 16/32/64-bit vector union */
typedef union v16_uni { v16 v; u16 u; } v16_uni;
typedef union v32_uni { v32 v; u32 u; } v32_uni;
typedef union v64_uni { v64 v; u64 u; } v64_uni;
/*==============================================================================
* MARK: - Load/Store Utils (Private)
*============================================================================*/
#define byte_move_idx(x) ((char *)dst)[x] = ((const char *)src)[x];
#define byte_move_src(x) ((char *)tmp)[x] = ((const char *)src)[x];
#define byte_move_dst(x) ((char *)dst)[x] = ((const char *)tmp)[x];
/** Same as `memcpy(dst, src, 2)`, no overlap. */
static_inline void byte_copy_2(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(dst, src, 2);
#else
repeat2_incr(byte_move_idx)
#endif
}
/** Same as `memcpy(dst, src, 4)`, no overlap. */
static_inline void byte_copy_4(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(dst, src, 4);
#else
repeat4_incr(byte_move_idx)
#endif
}
/** Same as `memcpy(dst, src, 8)`, no overlap. */
static_inline void byte_copy_8(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(dst, src, 8);
#else
repeat8_incr(byte_move_idx)
#endif
}
/** Same as `memcpy(dst, src, 16)`, no overlap. */
static_inline void byte_copy_16(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(dst, src, 16);
#else
repeat16_incr(byte_move_idx)
#endif
}
/** Same as `memmove(dst, src, 2)`, allows overlap. */
static_inline void byte_move_2(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
u16 tmp;
memcpy(&tmp, src, 2);
memcpy(dst, &tmp, 2);
#else
char tmp[2];
repeat2_incr(byte_move_src)
repeat2_incr(byte_move_dst)
#endif
}
/** Same as `memmove(dst, src, 4)`, allows overlap. */
static_inline void byte_move_4(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
u32 tmp;
memcpy(&tmp, src, 4);
memcpy(dst, &tmp, 4);
#else
char tmp[4];
repeat4_incr(byte_move_src)
repeat4_incr(byte_move_dst)
#endif
}
/** Same as `memmove(dst, src, 8)`, allows overlap. */
static_inline void byte_move_8(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
u64 tmp;
memcpy(&tmp, src, 8);
memcpy(dst, &tmp, 8);
#else
char tmp[8];
repeat8_incr(byte_move_src)
repeat8_incr(byte_move_dst)
#endif
}
/** Same as `memmove(dst, src, 16)`, allows overlap. */
static_inline void byte_move_16(void *dst, const void *src) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
char *pdst = (char *)dst;
const char *psrc = (const char *)src;
u64 tmp1, tmp2;
memcpy(&tmp1, psrc, 8);
memcpy(&tmp2, psrc + 8, 8);
memcpy(pdst, &tmp1, 8);
memcpy(pdst + 8, &tmp2, 8);
#else
char tmp[16];
repeat16_incr(byte_move_src)
repeat16_incr(byte_move_dst)
#endif
}
/** Same as `memmove(dst, src, n)`, but only `dst <= src` and `n <= 16`. */
static_inline void byte_move_forward(void *dst, void *src, usize n) {
char *d = (char *)dst, *s = (char *)src;
n += (n % 2); /* round up to even */
if (n == 16) { byte_move_16(d, s); return; }
if (n >= 8) { byte_move_8(d, s); n -= 8; d += 8; s += 8; }
if (n >= 4) { byte_move_4(d, s); n -= 4; d += 4; s += 4; }
if (n >= 2) { byte_move_2(d, s); }
}
/** Same as `memcmp(buf, pat, 2) == 0`. */
static_inline bool byte_match_2(void *buf, const char *pat) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
v16_uni u1, u2;
memcpy(&u1, buf, 2);
memcpy(&u2, pat, 2);
return u1.u == u2.u;
#else
return ((char *)buf)[0] == ((const char *)pat)[0] &&
((char *)buf)[1] == ((const char *)pat)[1];
#endif
}
/** Same as `memcmp(buf, pat, 4) == 0`. */
static_inline bool byte_match_4(void *buf, const char *pat) {
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
v32_uni u1, u2;
memcpy(&u1, buf, 4);
memcpy(&u2, pat, 4);
return u1.u == u2.u;
#else
return ((char *)buf)[0] == ((const char *)pat)[0] &&
((char *)buf)[1] == ((const char *)pat)[1] &&
((char *)buf)[2] == ((const char *)pat)[2] &&
((char *)buf)[3] == ((const char *)pat)[3];
#endif
}
/** Loads 2 bytes from `src` as a u16 (native-endian). */
static_inline u16 byte_load_2(const void *src) {
v16_uni uni;
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(&uni, src, 2);
#else
uni.v.c[0] = ((const char *)src)[0];
uni.v.c[1] = ((const char *)src)[1];
#endif
return uni.u;
}
/** Loads 3 bytes from `src` as a u32 (native-endian). */
static_inline u32 byte_load_3(const void *src) {
v32_uni uni;
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(&uni, src, 2);
uni.v.c[2] = ((const char *)src)[2];
uni.v.c[3] = 0;
#else
uni.v.c[0] = ((const char *)src)[0];
uni.v.c[1] = ((const char *)src)[1];
uni.v.c[2] = ((const char *)src)[2];
uni.v.c[3] = 0;
#endif
return uni.u;
}
/** Loads 4 bytes from `src` as a u32 (native-endian). */
static_inline u32 byte_load_4(const void *src) {
v32_uni uni;
#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
memcpy(&uni, src, 4);
#else
uni.v.c[0] = ((const char *)src)[0];
uni.v.c[1] = ((const char *)src)[1];
uni.v.c[2] = ((const char *)src)[2];
uni.v.c[3] = ((const char *)src)[3];
#endif
return uni.u;
}
/*==============================================================================
* MARK: - Character Utils (Private)
* These lookup tables were generated by `misc/make_tables.c`.
*============================================================================*/
/* char_table1 */
#define CHAR_TYPE_ASCII (1 << 0) /* Except: ["\], [0x00-0x1F, 0x80-0xFF] */
#define CHAR_TYPE_ASCII_SQ (1 << 1) /* Except: ['\], [0x00-0x1F, 0x80-0xFF] */
#define CHAR_TYPE_SPACE (1 << 2) /* Whitespace: [ \t\n\r] */
#define CHAR_TYPE_SPACE_EXT (1 << 3) /* Whitespace: [ \t\n\r\v\f], JSON5 */
#define CHAR_TYPE_NUM (1 << 4) /* Number: [.-+0-9] */
#define CHAR_TYPE_COMMENT (1 << 5) /* Comment: [/] */
/* char_table2 */
#define CHAR_TYPE_EOL (1 << 0) /* End of line: [\r\n] */
#define CHAR_TYPE_EOL_EXT (1 << 1) /* End of line: [\r\n], JSON5 */
#define CHAR_TYPE_ID_START (1 << 2) /* ID start: [_$A-Za-z\], U+0080+ */
#define CHAR_TYPE_ID_NEXT (1 << 3) /* ID next: [_$A-Za-z0-9\], U+0080+ */
#define CHAR_TYPE_ID_ASCII (1 << 4) /* ID next ASCII: [_$A-Za-z0-9] */
/* char_table3 */
#define CHAR_TYPE_SIGN (1 << 0) /* [-+] */
#define CHAR_TYPE_DIGIT (1 << 1) /* [0-9] */
#define CHAR_TYPE_NONZERO (1 << 2) /* [1-9] */
#define CHAR_TYPE_EXP (1 << 3) /* [eE] */
#define CHAR_TYPE_DOT (1 << 4) /* [.] */
static const u8 char_table1[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0C, 0x0C, 0x08, 0x08, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x03, 0x02, 0x03, 0x03, 0x03, 0x03, 0x01,
0x03, 0x03, 0x03, 0x13, 0x03, 0x13, 0x13, 0x23,
0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
0x13, 0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x00, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const u8 char_table2[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x1C, 0x1C, 0x1C, 0x00, 0x0C, 0x00, 0x00, 0x1C,
0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C
};
static const u8 char_table3[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x10, 0x00,
0x02, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/** Match a whitespace: [ \t\n\r]. */
static_inline bool char_is_space(u8 c) {
return !!(char_table1[c] & CHAR_TYPE_SPACE);
}
/** Match an extended whitespace: [ \t\n\r\\v\\f], JSON5 whitespace. */
static_inline bool char_is_space_ext(u8 c) {
return !!(char_table1[c] & CHAR_TYPE_SPACE_EXT);
}
/** Match a JSON number: [.-+0-9]. */
static_inline bool char_is_num(u8 c) {
return !!(char_table1[c] & CHAR_TYPE_NUM);
}
/** Match an ASCII character in string: ["\], [0x00-0x1F, 0x80-0xFF]. */
static_inline bool char_is_ascii_skip(u8 c) {
return !!(char_table1[c] & CHAR_TYPE_ASCII);
}
/** Match an ASCII character single-quoted: ['\], [0x00-0x1F, 0x80-0xFF]. */
static_inline bool char_is_ascii_skip_sq(u8 c) {
return !!(char_table1[c] & CHAR_TYPE_ASCII_SQ);
}
/** Match a trivia character: extended whitespace or comment. */
static_inline bool char_is_trivia(u8 c) {
return !!(char_table1[c] & (CHAR_TYPE_SPACE_EXT | CHAR_TYPE_COMMENT));
}
/** Match a line end character: [\r\n]. */
static_inline bool char_is_eol(u8 c) {
return !!(char_table2[c] & CHAR_TYPE_EOL);
}
/** Match an extended line end character: [\r\n], JSON5 line terminator. */
static_inline bool char_is_eol_ext(u8 c) {
return !!(char_table2[c] & CHAR_TYPE_EOL_EXT);
}
/** Match an identifier name start: [_$A-Za-z\], U+0080+. */
static_inline bool char_is_id_start(u8 c) {
return !!(char_table2[c] & CHAR_TYPE_ID_START);
}
/** Match an identifier name next: [_$A-Za-z0-9\], U+0080+. */
static_inline bool char_is_id_next(u8 c) {
return !!(char_table2[c] & CHAR_TYPE_ID_NEXT);
}
/** Match an identifier name ASCII: [_$A-Za-z0-9]. */
static_inline bool char_is_id_ascii(u8 c) {
return !!(char_table2[c] & CHAR_TYPE_ID_ASCII);
}
/** Match a sign: [+-] */
static_inline bool char_is_sign(u8 d) {
return !!(char_table3[d] & CHAR_TYPE_SIGN);
}
/** Match a none-zero digit: [1-9] */
static_inline bool char_is_nonzero(u8 d) {
return !!(char_table3[d] & CHAR_TYPE_NONZERO);
}
/** Match a digit: [0-9] */
static_inline bool char_is_digit(u8 d) {
return !!(char_table3[d] & CHAR_TYPE_DIGIT);
}
/** Match an exponent sign: [eE]. */
static_inline bool char_is_exp(u8 d) {
return !!(char_table3[d] & CHAR_TYPE_EXP);
}
/** Match a floating point indicator: [.eE]. */
static_inline bool char_is_fp(u8 d) {
return !!(char_table3[d] & (CHAR_TYPE_DOT | CHAR_TYPE_EXP));
}
/** Match a digit or floating point indicator: [0-9.eE]. */
static_inline bool char_is_digit_or_fp(u8 d) {
return !!(char_table3[d] & (CHAR_TYPE_DIGIT | CHAR_TYPE_DOT |
CHAR_TYPE_EXP));
}
/** Match a JSON container: `{` or `[`. */
static_inline bool char_is_ctn(u8 c) {
return (c & 0xDF) == 0x5B; /* '[': 0x5B, '{': 0x7B */
}
/** Convert ASCII letter to lowercase; valid only for [A-Za-z]. */
static_inline u8 char_to_lower(u8 c) {
return c | 0x20;
}
/** Match UTF-8 byte order mask. */
static_inline bool is_utf8_bom(const u8 *cur) {
return byte_load_3(cur) == byte_load_3("\xEF\xBB\xBF");
}
/** Match UTF-16 byte order mask. */
static_inline bool is_utf16_bom(const u8 *cur) {
return byte_load_2(cur) == byte_load_2("\xFE\xFF") ||
byte_load_2(cur) == byte_load_2("\xFF\xFE");
}
/** Match UTF-32 byte order mask, need length check to avoid zero padding. */
static_inline bool is_utf32_bom(const u8 *cur) {
return byte_load_4(cur) == byte_load_4("\x00\x00\xFE\xFF") ||
byte_load_4(cur) == byte_load_4("\xFF\xFE\x00\x00");
}
/** Get the extended line end length. Used with `char_is_eol_ext`. */
static_inline usize ext_eol_len(const u8 *cur) {
if (cur[0] < 0x80) return 1;
if (cur[1] == 0x80 && (cur[2] == 0xA8 || cur[2] == 0xA9)) return 3;
return 0;
}
/** Get the extended whitespace length. Used with `char_is_space_ext`. */
static_inline usize ext_space_len(const u8 *cur) {
if (cur[0] < 0x80) {
return 1;
} else if (byte_load_2(cur) == byte_load_2("\xC2\xA0")) {
return 2;
} else if (byte_load_2(cur) == byte_load_2("\xE2\x80")) {
if (cur[2] >= 0x80 && cur[2] <= 0x8A) return 3;
if (cur[2] == 0xA8 || cur[2] == 0xA9 || cur[2] == 0xAF) return 3;
} else {
u32 uni = byte_load_3(cur);
if (uni == byte_load_3("\xE1\x9A\x80") ||
uni == byte_load_3("\xE2\x81\x9F") ||
uni == byte_load_3("\xE3\x80\x80") ||
uni == byte_load_3("\xEF\xBB\xBF")) return 3;
}
return 0;
}
/*==============================================================================
* MARK: - Hex Character Reader (Private)
* This function is used by JSON reader to read escaped characters.
*============================================================================*/
/**
This table is used to convert 4 hex character sequence to a number.
A valid hex character [0-9A-Fa-f] will mapped to it's raw number [0x00, 0x0F],
an invalid hex character will mapped to [0xF0].
(generate with misc/make_tables.c)
*/
static const u8 hex_conv_table[256] = {
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0
};
/** Load 4 hex characters to `u16`, return true on valid input. */
static_inline bool hex_load_4(const u8 *src, u16 *dst) {
u16 c0 = hex_conv_table[src[0]];
u16 c1 = hex_conv_table[src[1]];
u16 c2 = hex_conv_table[src[2]];
u16 c3 = hex_conv_table[src[3]];
u16 t0 = (u16)((c0 << 8) | c2);
u16 t1 = (u16)((c1 << 8) | c3);
*dst = (u16)((t0 << 4) | t1);
return ((t0 | t1) & (u16)0xF0F0) == 0;
}
/** Load 2 hex characters to `u8`, return true on valid input. */
static_inline bool hex_load_2(const u8 *src, u8 *dst) {
u8 c0 = hex_conv_table[src[0]];
u8 c1 = hex_conv_table[src[1]];
*dst = (u8)((c0 << 4) | c1);
return ((c0 | c1) & 0xF0) == 0;
}
/** Match a hexadecimal numeric character: [0-9a-fA-F]. */
static_inline bool char_is_hex(u8 c) {
return hex_conv_table[c] != 0xF0;
}
/*==============================================================================
* MARK: - UTF8 Validation (Private)
* Each Unicode code point is encoded using 1 to 4 bytes in UTF-8.
* Validation is performed using a 4-byte mask and pattern-based approach,
* which requires the input data to be padded with four zero bytes at the end.
*============================================================================*/
/* Macro for concatenating four u8 into a u32 and keeping the byte order. */
#if YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN
# define utf8_seq_def(name, a, b, c, d) \
static const u32 utf8_seq_##name = 0x##d##c##b##a##UL;
# define utf8_seq(name) utf8_seq_##name
#elif YYJSON_ENDIAN == YYJSON_BIG_ENDIAN
# define utf8_seq_def(name, a, b, c, d) \
static const u32 utf8_seq_##name = 0x##a##b##c##d##UL;
# define utf8_seq(name) utf8_seq_##name
#else
# define utf8_seq_def(name, a, b, c, d) \
static const v32_uni utf8_uni_##name = {{ 0x##a, 0x##b, 0x##c, 0x##d }};
# define utf8_seq(name) utf8_uni_##name.u
#endif
/*
1-byte sequence (U+0000 to U+007F)
bit min [.......0] (U+0000)
bit max [.1111111] (U+007F)
bit mask [x.......] (80)
bit pattern [0.......] (00)
*/
utf8_seq_def(b1_mask, 80, 00, 00, 00)
utf8_seq_def(b1_patt, 00, 00, 00, 00)
#define is_utf8_seq1(uni) ( \
((uni & utf8_seq(b1_mask)) == utf8_seq(b1_patt)) )
/*
2-byte sequence (U+0080 to U+07FF)
bit min [......10 ..000000] (U+0080)
bit max [...11111 ..111111] (U+07FF)
bit mask [xxx..... xx......] (E0 C0)
bit pattern [110..... 10......] (C0 80)
bit require [...xxxx. ........] (1E 00)
*/
utf8_seq_def(b2_mask, E0, C0, 00, 00)
utf8_seq_def(b2_patt, C0, 80, 00, 00)
utf8_seq_def(b2_requ, 1E, 00, 00, 00)
#define is_utf8_seq2(uni) ( \
((uni & utf8_seq(b2_mask)) == utf8_seq(b2_patt)) && \
((uni & utf8_seq(b2_requ))) )
/*
3-byte sequence (U+0800 to U+FFFF)
bit min [........ ..100000 ..000000] (U+0800)
bit max [....1111 ..111111 ..111111] (U+FFFF)
bit mask [xxxx.... xx...... xx......] (F0 C0 C0)
bit pattern [1110.... 10...... 10......] (E0 80 80)
bit require [....xxxx ..x..... ........] (0F 20 00)
3-byte invalid sequence, reserved for surrogate halves (U+D800 to U+DFFF)
bit min [....1101 ..100000 ..000000] (U+D800)
bit max [....1101 ..111111 ..111111] (U+DFFF)
bit mask [....xxxx ..x..... ........] (0F 20 00)
bit pattern [....1101 ..1..... ........] (0D 20 00)
*/
utf8_seq_def(b3_mask, F0, C0, C0, 00)
utf8_seq_def(b3_patt, E0, 80, 80, 00)
utf8_seq_def(b3_requ, 0F, 20, 00, 00)
utf8_seq_def(b3_erro, 0D, 20, 00, 00)
#define is_utf8_seq3(uni) ( \
((uni & utf8_seq(b3_mask)) == utf8_seq(b3_patt)) && \
((tmp = (uni & utf8_seq(b3_requ)))) && \
((tmp != utf8_seq(b3_erro))) )
/*
4-byte sequence (U+10000 to U+10FFFF)
bit min [........ ...10000 ..000000 ..000000] (U+10000)
bit max [.....100 ..001111 ..111111 ..111111] (U+10FFFF)
bit mask [xxxxx... xx...... xx...... xx......] (F8 C0 C0 C0)
bit pattern [11110... 10...... 10...... 10......] (F0 80 80 80)
bit require [.....xxx ..xx.... ........ ........] (07 30 00 00)
bit require 1 [.....x.. ........ ........ ........] (04 00 00 00)
bit require 2 [......xx ..xx.... ........ ........] (03 30 00 00)
*/
utf8_seq_def(b4_mask, F8, C0, C0, C0)
utf8_seq_def(b4_patt, F0, 80, 80, 80)
utf8_seq_def(b4_requ, 07, 30, 00, 00)
utf8_seq_def(b4_req1, 04, 00, 00, 00)
utf8_seq_def(b4_req2, 03, 30, 00, 00)
#define is_utf8_seq4(uni) ( \
((uni & utf8_seq(b4_mask)) == utf8_seq(b4_patt)) && \
((tmp = (uni & utf8_seq(b4_requ)))) && \
((tmp & utf8_seq(b4_req1)) == 0 || (tmp & utf8_seq(b4_req2)) == 0) )
/*==============================================================================
* MARK: - Power10 Lookup Table (Private)
* These data are used by the floating-point number reader and writer.
*============================================================================*/
#if !YYJSON_DISABLE_FAST_FP_CONV
/** Maximum pow10 exponent that can be represented exactly as a float64. */
#define F64_POW10_MAX_EXACT_EXP 22
/** Cached pow10 table. */
static const f64 f64_pow10_table[F64_POW10_MAX_EXACT_EXP + 1] = {
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12,
1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22
};
/** Maximum pow10 exponent that can be represented exactly as a uint64. */
#define U64_POW10_MAX_EXACT_EXP 19
/** Table: [ 10^0, ..., 10^19 ] (generate with misc/make_tables.c) */
static const u64 u64_pow10_table[U64_POW10_MAX_EXACT_EXP + 1] = {
U64(0x00000000, 0x00000001), U64(0x00000000, 0x0000000A),
U64(0x00000000, 0x00000064), U64(0x00000000, 0x000003E8),
U64(0x00000000, 0x00002710), U64(0x00000000, 0x000186A0),
U64(0x00000000, 0x000F4240), U64(0x00000000, 0x00989680),
U64(0x00000000, 0x05F5E100), U64(0x00000000, 0x3B9ACA00),
U64(0x00000002, 0x540BE400), U64(0x00000017, 0x4876E800),
U64(0x000000E8, 0xD4A51000), U64(0x00000918, 0x4E72A000),
U64(0x00005AF3, 0x107A4000), U64(0x00038D7E, 0xA4C68000),
U64(0x002386F2, 0x6FC10000), U64(0x01634578, 0x5D8A0000),
U64(0x0DE0B6B3, 0xA7640000), U64(0x8AC72304, 0x89E80000)
};
/** Minimum decimal exponent in pow10_sig_table. */
#define POW10_SIG_TABLE_MIN_EXP -343
/** Maximum decimal exponent in pow10_sig_table. */
#define POW10_SIG_TABLE_MAX_EXP 324
/** Minimum exact decimal exponent in pow10_sig_table */
#define POW10_SIG_TABLE_MIN_EXACT_EXP 0
/** Maximum exact decimal exponent in pow10_sig_table */
#define POW10_SIG_TABLE_MAX_EXACT_EXP 55
/** Normalized significant 128 bits of pow10, no rounded up (size: 10.4KB).
This lookup table is used by both the double number reader and writer.
(generate with misc/make_tables.c) */
static const u64 pow10_sig_table[] = {
U64(0xBF29DCAB, 0xA82FDEAE), U64(0x7432EE87, 0x3880FC33), /* ~= 10^-343 */
U64(0xEEF453D6, 0x923BD65A), U64(0x113FAA29, 0x06A13B3F), /* ~= 10^-342 */
U64(0x9558B466, 0x1B6565F8), U64(0x4AC7CA59, 0xA424C507), /* ~= 10^-341 */
U64(0xBAAEE17F, 0xA23EBF76), U64(0x5D79BCF0, 0x0D2DF649), /* ~= 10^-340 */
U64(0xE95A99DF, 0x8ACE6F53), U64(0xF4D82C2C, 0x107973DC), /* ~= 10^-339 */
U64(0x91D8A02B, 0xB6C10594), U64(0x79071B9B, 0x8A4BE869), /* ~= 10^-338 */
U64(0xB64EC836, 0xA47146F9), U64(0x9748E282, 0x6CDEE284), /* ~= 10^-337 */
U64(0xE3E27A44, 0x4D8D98B7), U64(0xFD1B1B23, 0x08169B25), /* ~= 10^-336 */
U64(0x8E6D8C6A, 0xB0787F72), U64(0xFE30F0F5, 0xE50E20F7), /* ~= 10^-335 */
U64(0xB208EF85, 0x5C969F4F), U64(0xBDBD2D33, 0x5E51A935), /* ~= 10^-334 */
U64(0xDE8B2B66, 0xB3BC4723), U64(0xAD2C7880, 0x35E61382), /* ~= 10^-333 */
U64(0x8B16FB20, 0x3055AC76), U64(0x4C3BCB50, 0x21AFCC31), /* ~= 10^-332 */
U64(0xADDCB9E8, 0x3C6B1793), U64(0xDF4ABE24, 0x2A1BBF3D), /* ~= 10^-331 */
U64(0xD953E862, 0x4B85DD78), U64(0xD71D6DAD, 0x34A2AF0D), /* ~= 10^-330 */
U64(0x87D4713D, 0x6F33AA6B), U64(0x8672648C, 0x40E5AD68), /* ~= 10^-329 */
U64(0xA9C98D8C, 0xCB009506), U64(0x680EFDAF, 0x511F18C2), /* ~= 10^-328 */
U64(0xD43BF0EF, 0xFDC0BA48), U64(0x0212BD1B, 0x2566DEF2), /* ~= 10^-327 */
U64(0x84A57695, 0xFE98746D), U64(0x014BB630, 0xF7604B57), /* ~= 10^-326 */
U64(0xA5CED43B, 0x7E3E9188), U64(0x419EA3BD, 0x35385E2D), /* ~= 10^-325 */
U64(0xCF42894A, 0x5DCE35EA), U64(0x52064CAC, 0x828675B9), /* ~= 10^-324 */
U64(0x818995CE, 0x7AA0E1B2), U64(0x7343EFEB, 0xD1940993), /* ~= 10^-323 */
U64(0xA1EBFB42, 0x19491A1F), U64(0x1014EBE6, 0xC5F90BF8), /* ~= 10^-322 */
U64(0xCA66FA12, 0x9F9B60A6), U64(0xD41A26E0, 0x77774EF6), /* ~= 10^-321 */
U64(0xFD00B897, 0x478238D0), U64(0x8920B098, 0x955522B4), /* ~= 10^-320 */
U64(0x9E20735E, 0x8CB16382), U64(0x55B46E5F, 0x5D5535B0), /* ~= 10^-319 */
U64(0xC5A89036, 0x2FDDBC62), U64(0xEB2189F7, 0x34AA831D), /* ~= 10^-318 */
U64(0xF712B443, 0xBBD52B7B), U64(0xA5E9EC75, 0x01D523E4), /* ~= 10^-317 */
U64(0x9A6BB0AA, 0x55653B2D), U64(0x47B233C9, 0x2125366E), /* ~= 10^-316 */
U64(0xC1069CD4, 0xEABE89F8), U64(0x999EC0BB, 0x696E840A), /* ~= 10^-315 */
U64(0xF148440A, 0x256E2C76), U64(0xC00670EA, 0x43CA250D), /* ~= 10^-314 */
U64(0x96CD2A86, 0x5764DBCA), U64(0x38040692, 0x6A5E5728), /* ~= 10^-313 */
U64(0xBC807527, 0xED3E12BC), U64(0xC6050837, 0x04F5ECF2), /* ~= 10^-312 */
U64(0xEBA09271, 0xE88D976B), U64(0xF7864A44, 0xC633682E), /* ~= 10^-311 */
U64(0x93445B87, 0x31587EA3), U64(0x7AB3EE6A, 0xFBE0211D), /* ~= 10^-310 */
U64(0xB8157268, 0xFDAE9E4C), U64(0x5960EA05, 0xBAD82964), /* ~= 10^-309 */
U64(0xE61ACF03, 0x3D1A45DF), U64(0x6FB92487, 0x298E33BD), /* ~= 10^-308 */
U64(0x8FD0C162, 0x06306BAB), U64(0xA5D3B6D4, 0x79F8E056), /* ~= 10^-307 */
U64(0xB3C4F1BA, 0x87BC8696), U64(0x8F48A489, 0x9877186C), /* ~= 10^-306 */
U64(0xE0B62E29, 0x29ABA83C), U64(0x331ACDAB, 0xFE94DE87), /* ~= 10^-305 */
U64(0x8C71DCD9, 0xBA0B4925), U64(0x9FF0C08B, 0x7F1D0B14), /* ~= 10^-304 */
U64(0xAF8E5410, 0x288E1B6F), U64(0x07ECF0AE, 0x5EE44DD9), /* ~= 10^-303 */
U64(0xDB71E914, 0x32B1A24A), U64(0xC9E82CD9, 0xF69D6150), /* ~= 10^-302 */
U64(0x892731AC, 0x9FAF056E), U64(0xBE311C08, 0x3A225CD2), /* ~= 10^-301 */
U64(0xAB70FE17, 0xC79AC6CA), U64(0x6DBD630A, 0x48AAF406), /* ~= 10^-300 */
U64(0xD64D3D9D, 0xB981787D), U64(0x092CBBCC, 0xDAD5B108), /* ~= 10^-299 */
U64(0x85F04682, 0x93F0EB4E), U64(0x25BBF560, 0x08C58EA5), /* ~= 10^-298 */
U64(0xA76C5823, 0x38ED2621), U64(0xAF2AF2B8, 0x0AF6F24E), /* ~= 10^-297 */
U64(0xD1476E2C, 0x07286FAA), U64(0x1AF5AF66, 0x0DB4AEE1), /* ~= 10^-296 */
U64(0x82CCA4DB, 0x847945CA), U64(0x50D98D9F, 0xC890ED4D), /* ~= 10^-295 */
U64(0xA37FCE12, 0x6597973C), U64(0xE50FF107, 0xBAB528A0), /* ~= 10^-294 */
U64(0xCC5FC196, 0xFEFD7D0C), U64(0x1E53ED49, 0xA96272C8), /* ~= 10^-293 */
U64(0xFF77B1FC, 0xBEBCDC4F), U64(0x25E8E89C, 0x13BB0F7A), /* ~= 10^-292 */
U64(0x9FAACF3D, 0xF73609B1), U64(0x77B19161, 0x8C54E9AC), /* ~= 10^-291 */
U64(0xC795830D, 0x75038C1D), U64(0xD59DF5B9, 0xEF6A2417), /* ~= 10^-290 */
U64(0xF97AE3D0, 0xD2446F25), U64(0x4B057328, 0x6B44AD1D), /* ~= 10^-289 */
U64(0x9BECCE62, 0x836AC577), U64(0x4EE367F9, 0x430AEC32), /* ~= 10^-288 */
U64(0xC2E801FB, 0x244576D5), U64(0x229C41F7, 0x93CDA73F), /* ~= 10^-287 */
U64(0xF3A20279, 0xED56D48A), U64(0x6B435275, 0x78C1110F), /* ~= 10^-286 */
U64(0x9845418C, 0x345644D6), U64(0x830A1389, 0x6B78AAA9), /* ~= 10^-285 */
U64(0xBE5691EF, 0x416BD60C), U64(0x23CC986B, 0xC656D553), /* ~= 10^-284 */
U64(0xEDEC366B, 0x11C6CB8F), U64(0x2CBFBE86, 0xB7EC8AA8), /* ~= 10^-283 */
U64(0x94B3A202, 0xEB1C3F39), U64(0x7BF7D714, 0x32F3D6A9), /* ~= 10^-282 */
U64(0xB9E08A83, 0xA5E34F07), U64(0xDAF5CCD9, 0x3FB0CC53), /* ~= 10^-281 */
U64(0xE858AD24, 0x8F5C22C9), U64(0xD1B3400F, 0x8F9CFF68), /* ~= 10^-280 */
U64(0x91376C36, 0xD99995BE), U64(0x23100809, 0xB9C21FA1), /* ~= 10^-279 */
U64(0xB5854744, 0x8FFFFB2D), U64(0xABD40A0C, 0x2832A78A), /* ~= 10^-278 */
U64(0xE2E69915, 0xB3FFF9F9), U64(0x16C90C8F, 0x323F516C), /* ~= 10^-277 */
U64(0x8DD01FAD, 0x907FFC3B), U64(0xAE3DA7D9, 0x7F6792E3), /* ~= 10^-276 */
U64(0xB1442798, 0xF49FFB4A), U64(0x99CD11CF, 0xDF41779C), /* ~= 10^-275 */
U64(0xDD95317F, 0x31C7FA1D), U64(0x40405643, 0xD711D583), /* ~= 10^-274 */
U64(0x8A7D3EEF, 0x7F1CFC52), U64(0x482835EA, 0x666B2572), /* ~= 10^-273 */
U64(0xAD1C8EAB, 0x5EE43B66), U64(0xDA324365, 0x0005EECF), /* ~= 10^-272 */
U64(0xD863B256, 0x369D4A40), U64(0x90BED43E, 0x40076A82), /* ~= 10^-271 */
U64(0x873E4F75, 0xE2224E68), U64(0x5A7744A6, 0xE804A291), /* ~= 10^-270 */
U64(0xA90DE353, 0x5AAAE202), U64(0x711515D0, 0xA205CB36), /* ~= 10^-269 */
U64(0xD3515C28, 0x31559A83), U64(0x0D5A5B44, 0xCA873E03), /* ~= 10^-268 */
U64(0x8412D999, 0x1ED58091), U64(0xE858790A, 0xFE9486C2), /* ~= 10^-267 */
U64(0xA5178FFF, 0x668AE0B6), U64(0x626E974D, 0xBE39A872), /* ~= 10^-266 */
U64(0xCE5D73FF, 0x402D98E3), U64(0xFB0A3D21, 0x2DC8128F), /* ~= 10^-265 */
U64(0x80FA687F, 0x881C7F8E), U64(0x7CE66634, 0xBC9D0B99), /* ~= 10^-264 */
U64(0xA139029F, 0x6A239F72), U64(0x1C1FFFC1, 0xEBC44E80), /* ~= 10^-263 */
U64(0xC9874347, 0x44AC874E), U64(0xA327FFB2, 0x66B56220), /* ~= 10^-262 */
U64(0xFBE91419, 0x15D7A922), U64(0x4BF1FF9F, 0x0062BAA8), /* ~= 10^-261 */
U64(0x9D71AC8F, 0xADA6C9B5), U64(0x6F773FC3, 0x603DB4A9), /* ~= 10^-260 */
U64(0xC4CE17B3, 0x99107C22), U64(0xCB550FB4, 0x384D21D3), /* ~= 10^-259 */
U64(0xF6019DA0, 0x7F549B2B), U64(0x7E2A53A1, 0x46606A48), /* ~= 10^-258 */
U64(0x99C10284, 0x4F94E0FB), U64(0x2EDA7444, 0xCBFC426D), /* ~= 10^-257 */
U64(0xC0314325, 0x637A1939), U64(0xFA911155, 0xFEFB5308), /* ~= 10^-256 */
U64(0xF03D93EE, 0xBC589F88), U64(0x793555AB, 0x7EBA27CA), /* ~= 10^-255 */
U64(0x96267C75, 0x35B763B5), U64(0x4BC1558B, 0x2F3458DE), /* ~= 10^-254 */
U64(0xBBB01B92, 0x83253CA2), U64(0x9EB1AAED, 0xFB016F16), /* ~= 10^-253 */
U64(0xEA9C2277, 0x23EE8BCB), U64(0x465E15A9, 0x79C1CADC), /* ~= 10^-252 */
U64(0x92A1958A, 0x7675175F), U64(0x0BFACD89, 0xEC191EC9), /* ~= 10^-251 */
U64(0xB749FAED, 0x14125D36), U64(0xCEF980EC, 0x671F667B), /* ~= 10^-250 */
U64(0xE51C79A8, 0x5916F484), U64(0x82B7E127, 0x80E7401A), /* ~= 10^-249 */
U64(0x8F31CC09, 0x37AE58D2), U64(0xD1B2ECB8, 0xB0908810), /* ~= 10^-248 */
U64(0xB2FE3F0B, 0x8599EF07), U64(0x861FA7E6, 0xDCB4AA15), /* ~= 10^-247 */
U64(0xDFBDCECE, 0x67006AC9), U64(0x67A791E0, 0x93E1D49A), /* ~= 10^-246 */
U64(0x8BD6A141, 0x006042BD), U64(0xE0C8BB2C, 0x5C6D24E0), /* ~= 10^-245 */
U64(0xAECC4991, 0x4078536D), U64(0x58FAE9F7, 0x73886E18), /* ~= 10^-244 */
U64(0xDA7F5BF5, 0x90966848), U64(0xAF39A475, 0x506A899E), /* ~= 10^-243 */
U64(0x888F9979, 0x7A5E012D), U64(0x6D8406C9, 0x52429603), /* ~= 10^-242 */
U64(0xAAB37FD7, 0xD8F58178), U64(0xC8E5087B, 0xA6D33B83), /* ~= 10^-241 */
U64(0xD5605FCD, 0xCF32E1D6), U64(0xFB1E4A9A, 0x90880A64), /* ~= 10^-240 */
U64(0x855C3BE0, 0xA17FCD26), U64(0x5CF2EEA0, 0x9A55067F), /* ~= 10^-239 */
U64(0xA6B34AD8, 0xC9DFC06F), U64(0xF42FAA48, 0xC0EA481E), /* ~= 10^-238 */
U64(0xD0601D8E, 0xFC57B08B), U64(0xF13B94DA, 0xF124DA26), /* ~= 10^-237 */
U64(0x823C1279, 0x5DB6CE57), U64(0x76C53D08, 0xD6B70858), /* ~= 10^-236 */
U64(0xA2CB1717, 0xB52481ED), U64(0x54768C4B, 0x0C64CA6E), /* ~= 10^-235 */
U64(0xCB7DDCDD, 0xA26DA268), U64(0xA9942F5D, 0xCF7DFD09), /* ~= 10^-234 */
U64(0xFE5D5415, 0x0B090B02), U64(0xD3F93B35, 0x435D7C4C), /* ~= 10^-233 */
U64(0x9EFA548D, 0x26E5A6E1), U64(0xC47BC501, 0x4A1A6DAF), /* ~= 10^-232 */
U64(0xC6B8E9B0, 0x709F109A), U64(0x359AB641, 0x9CA1091B), /* ~= 10^-231 */
U64(0xF867241C, 0x8CC6D4C0), U64(0xC30163D2, 0x03C94B62), /* ~= 10^-230 */
U64(0x9B407691, 0xD7FC44F8), U64(0x79E0DE63, 0x425DCF1D), /* ~= 10^-229 */
U64(0xC2109436, 0x4DFB5636), U64(0x985915FC, 0x12F542E4), /* ~= 10^-228 */
U64(0xF294B943, 0xE17A2BC4), U64(0x3E6F5B7B, 0x17B2939D), /* ~= 10^-227 */
U64(0x979CF3CA, 0x6CEC5B5A), U64(0xA705992C, 0xEECF9C42), /* ~= 10^-226 */
U64(0xBD8430BD, 0x08277231), U64(0x50C6FF78, 0x2A838353), /* ~= 10^-225 */
U64(0xECE53CEC, 0x4A314EBD), U64(0xA4F8BF56, 0x35246428), /* ~= 10^-224 */
U64(0x940F4613, 0xAE5ED136), U64(0x871B7795, 0xE136BE99), /* ~= 10^-223 */
U64(0xB9131798, 0x99F68584), U64(0x28E2557B, 0x59846E3F), /* ~= 10^-222 */
U64(0xE757DD7E, 0xC07426E5), U64(0x331AEADA, 0x2FE589CF), /* ~= 10^-221 */
U64(0x9096EA6F, 0x3848984F), U64(0x3FF0D2C8, 0x5DEF7621), /* ~= 10^-220 */
U64(0xB4BCA50B, 0x065ABE63), U64(0x0FED077A, 0x756B53A9), /* ~= 10^-219 */
U64(0xE1EBCE4D, 0xC7F16DFB), U64(0xD3E84959, 0x12C62894), /* ~= 10^-218 */
U64(0x8D3360F0, 0x9CF6E4BD), U64(0x64712DD7, 0xABBBD95C), /* ~= 10^-217 */
U64(0xB080392C, 0xC4349DEC), U64(0xBD8D794D, 0x96AACFB3), /* ~= 10^-216 */
U64(0xDCA04777, 0xF541C567), U64(0xECF0D7A0, 0xFC5583A0), /* ~= 10^-215 */
U64(0x89E42CAA, 0xF9491B60), U64(0xF41686C4, 0x9DB57244), /* ~= 10^-214 */
U64(0xAC5D37D5, 0xB79B6239), U64(0x311C2875, 0xC522CED5), /* ~= 10^-213 */
U64(0xD77485CB, 0x25823AC7), U64(0x7D633293, 0x366B828B), /* ~= 10^-212 */
U64(0x86A8D39E, 0xF77164BC), U64(0xAE5DFF9C, 0x02033197), /* ~= 10^-211 */
U64(0xA8530886, 0xB54DBDEB), U64(0xD9F57F83, 0x0283FDFC), /* ~= 10^-210 */
U64(0xD267CAA8, 0x62A12D66), U64(0xD072DF63, 0xC324FD7B), /* ~= 10^-209 */
U64(0x8380DEA9, 0x3DA4BC60), U64(0x4247CB9E, 0x59F71E6D), /* ~= 10^-208 */
U64(0xA4611653, 0x8D0DEB78), U64(0x52D9BE85, 0xF074E608), /* ~= 10^-207 */
U64(0xCD795BE8, 0x70516656), U64(0x67902E27, 0x6C921F8B), /* ~= 10^-206 */
U64(0x806BD971, 0x4632DFF6), U64(0x00BA1CD8, 0xA3DB53B6), /* ~= 10^-205 */
U64(0xA086CFCD, 0x97BF97F3), U64(0x80E8A40E, 0xCCD228A4), /* ~= 10^-204 */
U64(0xC8A883C0, 0xFDAF7DF0), U64(0x6122CD12, 0x8006B2CD), /* ~= 10^-203 */
U64(0xFAD2A4B1, 0x3D1B5D6C), U64(0x796B8057, 0x20085F81), /* ~= 10^-202 */
U64(0x9CC3A6EE, 0xC6311A63), U64(0xCBE33036, 0x74053BB0), /* ~= 10^-201 */
U64(0xC3F490AA, 0x77BD60FC), U64(0xBEDBFC44, 0x11068A9C), /* ~= 10^-200 */
U64(0xF4F1B4D5, 0x15ACB93B), U64(0xEE92FB55, 0x15482D44), /* ~= 10^-199 */
U64(0x99171105, 0x2D8BF3C5), U64(0x751BDD15, 0x2D4D1C4A), /* ~= 10^-198 */
U64(0xBF5CD546, 0x78EEF0B6), U64(0xD262D45A, 0x78A0635D), /* ~= 10^-197 */
U64(0xEF340A98, 0x172AACE4), U64(0x86FB8971, 0x16C87C34), /* ~= 10^-196 */
U64(0x9580869F, 0x0E7AAC0E), U64(0xD45D35E6, 0xAE3D4DA0), /* ~= 10^-195 */
U64(0xBAE0A846, 0xD2195712), U64(0x89748360, 0x59CCA109), /* ~= 10^-194 */
U64(0xE998D258, 0x869FACD7), U64(0x2BD1A438, 0x703FC94B), /* ~= 10^-193 */
U64(0x91FF8377, 0x5423CC06), U64(0x7B6306A3, 0x4627DDCF), /* ~= 10^-192 */
U64(0xB67F6455, 0x292CBF08), U64(0x1A3BC84C, 0x17B1D542), /* ~= 10^-191 */
U64(0xE41F3D6A, 0x7377EECA), U64(0x20CABA5F, 0x1D9E4A93), /* ~= 10^-190 */
U64(0x8E938662, 0x882AF53E), U64(0x547EB47B, 0x7282EE9C), /* ~= 10^-189 */
U64(0xB23867FB, 0x2A35B28D), U64(0xE99E619A, 0x4F23AA43), /* ~= 10^-188 */
U64(0xDEC681F9, 0xF4C31F31), U64(0x6405FA00, 0xE2EC94D4), /* ~= 10^-187 */
U64(0x8B3C113C, 0x38F9F37E), U64(0xDE83BC40, 0x8DD3DD04), /* ~= 10^-186 */
U64(0xAE0B158B, 0x4738705E), U64(0x9624AB50, 0xB148D445), /* ~= 10^-185 */
U64(0xD98DDAEE, 0x19068C76), U64(0x3BADD624, 0xDD9B0957), /* ~= 10^-184 */
U64(0x87F8A8D4, 0xCFA417C9), U64(0xE54CA5D7, 0x0A80E5D6), /* ~= 10^-183 */
U64(0xA9F6D30A, 0x038D1DBC), U64(0x5E9FCF4C, 0xCD211F4C), /* ~= 10^-182 */
U64(0xD47487CC, 0x8470652B), U64(0x7647C320, 0x0069671F), /* ~= 10^-181 */
U64(0x84C8D4DF, 0xD2C63F3B), U64(0x29ECD9F4, 0x0041E073), /* ~= 10^-180 */
U64(0xA5FB0A17, 0xC777CF09), U64(0xF4681071, 0x00525890), /* ~= 10^-179 */
U64(0xCF79CC9D, 0xB955C2CC), U64(0x7182148D, 0x4066EEB4), /* ~= 10^-178 */
U64(0x81AC1FE2, 0x93D599BF), U64(0xC6F14CD8, 0x48405530), /* ~= 10^-177 */
U64(0xA21727DB, 0x38CB002F), U64(0xB8ADA00E, 0x5A506A7C), /* ~= 10^-176 */
U64(0xCA9CF1D2, 0x06FDC03B), U64(0xA6D90811, 0xF0E4851C), /* ~= 10^-175 */
U64(0xFD442E46, 0x88BD304A), U64(0x908F4A16, 0x6D1DA663), /* ~= 10^-174 */
U64(0x9E4A9CEC, 0x15763E2E), U64(0x9A598E4E, 0x043287FE), /* ~= 10^-173 */
U64(0xC5DD4427, 0x1AD3CDBA), U64(0x40EFF1E1, 0x853F29FD), /* ~= 10^-172 */
U64(0xF7549530, 0xE188C128), U64(0xD12BEE59, 0xE68EF47C), /* ~= 10^-171 */
U64(0x9A94DD3E, 0x8CF578B9), U64(0x82BB74F8, 0x301958CE), /* ~= 10^-170 */
U64(0xC13A148E, 0x3032D6E7), U64(0xE36A5236, 0x3C1FAF01), /* ~= 10^-169 */
U64(0xF18899B1, 0xBC3F8CA1), U64(0xDC44E6C3, 0xCB279AC1), /* ~= 10^-168 */
U64(0x96F5600F, 0x15A7B7E5), U64(0x29AB103A, 0x5EF8C0B9), /* ~= 10^-167 */
U64(0xBCB2B812, 0xDB11A5DE), U64(0x7415D448, 0xF6B6F0E7), /* ~= 10^-166 */
U64(0xEBDF6617, 0x91D60F56), U64(0x111B495B, 0x3464AD21), /* ~= 10^-165 */
U64(0x936B9FCE, 0xBB25C995), U64(0xCAB10DD9, 0x00BEEC34), /* ~= 10^-164 */
U64(0xB84687C2, 0x69EF3BFB), U64(0x3D5D514F, 0x40EEA742), /* ~= 10^-163 */
U64(0xE65829B3, 0x046B0AFA), U64(0x0CB4A5A3, 0x112A5112), /* ~= 10^-162 */
U64(0x8FF71A0F, 0xE2C2E6DC), U64(0x47F0E785, 0xEABA72AB), /* ~= 10^-161 */
U64(0xB3F4E093, 0xDB73A093), U64(0x59ED2167, 0x65690F56), /* ~= 10^-160 */
U64(0xE0F218B8, 0xD25088B8), U64(0x306869C1, 0x3EC3532C), /* ~= 10^-159 */
U64(0x8C974F73, 0x83725573), U64(0x1E414218, 0xC73A13FB), /* ~= 10^-158 */
U64(0xAFBD2350, 0x644EEACF), U64(0xE5D1929E, 0xF90898FA), /* ~= 10^-157 */
U64(0xDBAC6C24, 0x7D62A583), U64(0xDF45F746, 0xB74ABF39), /* ~= 10^-156 */
U64(0x894BC396, 0xCE5DA772), U64(0x6B8BBA8C, 0x328EB783), /* ~= 10^-155 */
U64(0xAB9EB47C, 0x81F5114F), U64(0x066EA92F, 0x3F326564), /* ~= 10^-154 */
U64(0xD686619B, 0xA27255A2), U64(0xC80A537B, 0x0EFEFEBD), /* ~= 10^-153 */
U64(0x8613FD01, 0x45877585), U64(0xBD06742C, 0xE95F5F36), /* ~= 10^-152 */
U64(0xA798FC41, 0x96E952E7), U64(0x2C481138, 0x23B73704), /* ~= 10^-151 */
U64(0xD17F3B51, 0xFCA3A7A0), U64(0xF75A1586, 0x2CA504C5), /* ~= 10^-150 */
U64(0x82EF8513, 0x3DE648C4), U64(0x9A984D73, 0xDBE722FB), /* ~= 10^-149 */
U64(0xA3AB6658, 0x0D5FDAF5), U64(0xC13E60D0, 0xD2E0EBBA), /* ~= 10^-148 */
U64(0xCC963FEE, 0x10B7D1B3), U64(0x318DF905, 0x079926A8), /* ~= 10^-147 */
U64(0xFFBBCFE9, 0x94E5C61F), U64(0xFDF17746, 0x497F7052), /* ~= 10^-146 */
U64(0x9FD561F1, 0xFD0F9BD3), U64(0xFEB6EA8B, 0xEDEFA633), /* ~= 10^-145 */
U64(0xC7CABA6E, 0x7C5382C8), U64(0xFE64A52E, 0xE96B8FC0), /* ~= 10^-144 */
U64(0xF9BD690A, 0x1B68637B), U64(0x3DFDCE7A, 0xA3C673B0), /* ~= 10^-143 */
U64(0x9C1661A6, 0x51213E2D), U64(0x06BEA10C, 0xA65C084E), /* ~= 10^-142 */
U64(0xC31BFA0F, 0xE5698DB8), U64(0x486E494F, 0xCFF30A62), /* ~= 10^-141 */
U64(0xF3E2F893, 0xDEC3F126), U64(0x5A89DBA3, 0xC3EFCCFA), /* ~= 10^-140 */
U64(0x986DDB5C, 0x6B3A76B7), U64(0xF8962946, 0x5A75E01C), /* ~= 10^-139 */
U64(0xBE895233, 0x86091465), U64(0xF6BBB397, 0xF1135823), /* ~= 10^-138 */
U64(0xEE2BA6C0, 0x678B597F), U64(0x746AA07D, 0xED582E2C), /* ~= 10^-137 */
U64(0x94DB4838, 0x40B717EF), U64(0xA8C2A44E, 0xB4571CDC), /* ~= 10^-136 */
U64(0xBA121A46, 0x50E4DDEB), U64(0x92F34D62, 0x616CE413), /* ~= 10^-135 */
U64(0xE896A0D7, 0xE51E1566), U64(0x77B020BA, 0xF9C81D17), /* ~= 10^-134 */
U64(0x915E2486, 0xEF32CD60), U64(0x0ACE1474, 0xDC1D122E), /* ~= 10^-133 */
U64(0xB5B5ADA8, 0xAAFF80B8), U64(0x0D819992, 0x132456BA), /* ~= 10^-132 */
U64(0xE3231912, 0xD5BF60E6), U64(0x10E1FFF6, 0x97ED6C69), /* ~= 10^-131 */
U64(0x8DF5EFAB, 0xC5979C8F), U64(0xCA8D3FFA, 0x1EF463C1), /* ~= 10^-130 */
U64(0xB1736B96, 0xB6FD83B3), U64(0xBD308FF8, 0xA6B17CB2), /* ~= 10^-129 */
U64(0xDDD0467C, 0x64BCE4A0), U64(0xAC7CB3F6, 0xD05DDBDE), /* ~= 10^-128 */
U64(0x8AA22C0D, 0xBEF60EE4), U64(0x6BCDF07A, 0x423AA96B), /* ~= 10^-127 */
U64(0xAD4AB711, 0x2EB3929D), U64(0x86C16C98, 0xD2C953C6), /* ~= 10^-126 */
U64(0xD89D64D5, 0x7A607744), U64(0xE871C7BF, 0x077BA8B7), /* ~= 10^-125 */
U64(0x87625F05, 0x6C7C4A8B), U64(0x11471CD7, 0x64AD4972), /* ~= 10^-124 */
U64(0xA93AF6C6, 0xC79B5D2D), U64(0xD598E40D, 0x3DD89BCF), /* ~= 10^-123 */
U64(0xD389B478, 0x79823479), U64(0x4AFF1D10, 0x8D4EC2C3), /* ~= 10^-122 */
U64(0x843610CB, 0x4BF160CB), U64(0xCEDF722A, 0x585139BA), /* ~= 10^-121 */
U64(0xA54394FE, 0x1EEDB8FE), U64(0xC2974EB4, 0xEE658828), /* ~= 10^-120 */
U64(0xCE947A3D, 0xA6A9273E), U64(0x733D2262, 0x29FEEA32), /* ~= 10^-119 */
U64(0x811CCC66, 0x8829B887), U64(0x0806357D, 0x5A3F525F), /* ~= 10^-118 */
U64(0xA163FF80, 0x2A3426A8), U64(0xCA07C2DC, 0xB0CF26F7), /* ~= 10^-117 */
U64(0xC9BCFF60, 0x34C13052), U64(0xFC89B393, 0xDD02F0B5), /* ~= 10^-116 */
U64(0xFC2C3F38, 0x41F17C67), U64(0xBBAC2078, 0xD443ACE2), /* ~= 10^-115 */
U64(0x9D9BA783, 0x2936EDC0), U64(0xD54B944B, 0x84AA4C0D), /* ~= 10^-114 */
U64(0xC5029163, 0xF384A931), U64(0x0A9E795E, 0x65D4DF11), /* ~= 10^-113 */
U64(0xF64335BC, 0xF065D37D), U64(0x4D4617B5, 0xFF4A16D5), /* ~= 10^-112 */
U64(0x99EA0196, 0x163FA42E), U64(0x504BCED1, 0xBF8E4E45), /* ~= 10^-111 */
U64(0xC06481FB, 0x9BCF8D39), U64(0xE45EC286, 0x2F71E1D6), /* ~= 10^-110 */
U64(0xF07DA27A, 0x82C37088), U64(0x5D767327, 0xBB4E5A4C), /* ~= 10^-109 */
U64(0x964E858C, 0x91BA2655), U64(0x3A6A07F8, 0xD510F86F), /* ~= 10^-108 */
U64(0xBBE226EF, 0xB628AFEA), U64(0x890489F7, 0x0A55368B), /* ~= 10^-107 */
U64(0xEADAB0AB, 0xA3B2DBE5), U64(0x2B45AC74, 0xCCEA842E), /* ~= 10^-106 */
U64(0x92C8AE6B, 0x464FC96F), U64(0x3B0B8BC9, 0x0012929D), /* ~= 10^-105 */
U64(0xB77ADA06, 0x17E3BBCB), U64(0x09CE6EBB, 0x40173744), /* ~= 10^-104 */
U64(0xE5599087, 0x9DDCAABD), U64(0xCC420A6A, 0x101D0515), /* ~= 10^-103 */
U64(0x8F57FA54, 0xC2A9EAB6), U64(0x9FA94682, 0x4A12232D), /* ~= 10^-102 */
U64(0xB32DF8E9, 0xF3546564), U64(0x47939822, 0xDC96ABF9), /* ~= 10^-101 */
U64(0xDFF97724, 0x70297EBD), U64(0x59787E2B, 0x93BC56F7), /* ~= 10^-100 */
U64(0x8BFBEA76, 0xC619EF36), U64(0x57EB4EDB, 0x3C55B65A), /* ~= 10^-99 */
U64(0xAEFAE514, 0x77A06B03), U64(0xEDE62292, 0x0B6B23F1), /* ~= 10^-98 */
U64(0xDAB99E59, 0x958885C4), U64(0xE95FAB36, 0x8E45ECED), /* ~= 10^-97 */
U64(0x88B402F7, 0xFD75539B), U64(0x11DBCB02, 0x18EBB414), /* ~= 10^-96 */
U64(0xAAE103B5, 0xFCD2A881), U64(0xD652BDC2, 0x9F26A119), /* ~= 10^-95 */
U64(0xD59944A3, 0x7C0752A2), U64(0x4BE76D33, 0x46F0495F), /* ~= 10^-94 */
U64(0x857FCAE6, 0x2D8493A5), U64(0x6F70A440, 0x0C562DDB), /* ~= 10^-93 */
U64(0xA6DFBD9F, 0xB8E5B88E), U64(0xCB4CCD50, 0x0F6BB952), /* ~= 10^-92 */
U64(0xD097AD07, 0xA71F26B2), U64(0x7E2000A4, 0x1346A7A7), /* ~= 10^-91 */
U64(0x825ECC24, 0xC873782F), U64(0x8ED40066, 0x8C0C28C8), /* ~= 10^-90 */
U64(0xA2F67F2D, 0xFA90563B), U64(0x72890080, 0x2F0F32FA), /* ~= 10^-89 */
U64(0xCBB41EF9, 0x79346BCA), U64(0x4F2B40A0, 0x3AD2FFB9), /* ~= 10^-88 */
U64(0xFEA126B7, 0xD78186BC), U64(0xE2F610C8, 0x4987BFA8), /* ~= 10^-87 */
U64(0x9F24B832, 0xE6B0F436), U64(0x0DD9CA7D, 0x2DF4D7C9), /* ~= 10^-86 */
U64(0xC6EDE63F, 0xA05D3143), U64(0x91503D1C, 0x79720DBB), /* ~= 10^-85 */
U64(0xF8A95FCF, 0x88747D94), U64(0x75A44C63, 0x97CE912A), /* ~= 10^-84 */
U64(0x9B69DBE1, 0xB548CE7C), U64(0xC986AFBE, 0x3EE11ABA), /* ~= 10^-83 */
U64(0xC24452DA, 0x229B021B), U64(0xFBE85BAD, 0xCE996168), /* ~= 10^-82 */
U64(0xF2D56790, 0xAB41C2A2), U64(0xFAE27299, 0x423FB9C3), /* ~= 10^-81 */
U64(0x97C560BA, 0x6B0919A5), U64(0xDCCD879F, 0xC967D41A), /* ~= 10^-80 */
U64(0xBDB6B8E9, 0x05CB600F), U64(0x5400E987, 0xBBC1C920), /* ~= 10^-79 */
U64(0xED246723, 0x473E3813), U64(0x290123E9, 0xAAB23B68), /* ~= 10^-78 */
U64(0x9436C076, 0x0C86E30B), U64(0xF9A0B672, 0x0AAF6521), /* ~= 10^-77 */
U64(0xB9447093, 0x8FA89BCE), U64(0xF808E40E, 0x8D5B3E69), /* ~= 10^-76 */
U64(0xE7958CB8, 0x7392C2C2), U64(0xB60B1D12, 0x30B20E04), /* ~= 10^-75 */
U64(0x90BD77F3, 0x483BB9B9), U64(0xB1C6F22B, 0x5E6F48C2), /* ~= 10^-74 */
U64(0xB4ECD5F0, 0x1A4AA828), U64(0x1E38AEB6, 0x360B1AF3), /* ~= 10^-73 */
U64(0xE2280B6C, 0x20DD5232), U64(0x25C6DA63, 0xC38DE1B0), /* ~= 10^-72 */
U64(0x8D590723, 0x948A535F), U64(0x579C487E, 0x5A38AD0E), /* ~= 10^-71 */
U64(0xB0AF48EC, 0x79ACE837), U64(0x2D835A9D, 0xF0C6D851), /* ~= 10^-70 */
U64(0xDCDB1B27, 0x98182244), U64(0xF8E43145, 0x6CF88E65), /* ~= 10^-69 */
U64(0x8A08F0F8, 0xBF0F156B), U64(0x1B8E9ECB, 0x641B58FF), /* ~= 10^-68 */
U64(0xAC8B2D36, 0xEED2DAC5), U64(0xE272467E, 0x3D222F3F), /* ~= 10^-67 */
U64(0xD7ADF884, 0xAA879177), U64(0x5B0ED81D, 0xCC6ABB0F), /* ~= 10^-66 */
U64(0x86CCBB52, 0xEA94BAEA), U64(0x98E94712, 0x9FC2B4E9), /* ~= 10^-65 */
U64(0xA87FEA27, 0xA539E9A5), U64(0x3F2398D7, 0x47B36224), /* ~= 10^-64 */
U64(0xD29FE4B1, 0x8E88640E), U64(0x8EEC7F0D, 0x19A03AAD), /* ~= 10^-63 */
U64(0x83A3EEEE, 0xF9153E89), U64(0x1953CF68, 0x300424AC), /* ~= 10^-62 */
U64(0xA48CEAAA, 0xB75A8E2B), U64(0x5FA8C342, 0x3C052DD7), /* ~= 10^-61 */
U64(0xCDB02555, 0x653131B6), U64(0x3792F412, 0xCB06794D), /* ~= 10^-60 */
U64(0x808E1755, 0x5F3EBF11), U64(0xE2BBD88B, 0xBEE40BD0), /* ~= 10^-59 */
U64(0xA0B19D2A, 0xB70E6ED6), U64(0x5B6ACEAE, 0xAE9D0EC4), /* ~= 10^-58 */
U64(0xC8DE0475, 0x64D20A8B), U64(0xF245825A, 0x5A445275), /* ~= 10^-57 */
U64(0xFB158592, 0xBE068D2E), U64(0xEED6E2F0, 0xF0D56712), /* ~= 10^-56 */
U64(0x9CED737B, 0xB6C4183D), U64(0x55464DD6, 0x9685606B), /* ~= 10^-55 */
U64(0xC428D05A, 0xA4751E4C), U64(0xAA97E14C, 0x3C26B886), /* ~= 10^-54 */
U64(0xF5330471, 0x4D9265DF), U64(0xD53DD99F, 0x4B3066A8), /* ~= 10^-53 */
U64(0x993FE2C6, 0xD07B7FAB), U64(0xE546A803, 0x8EFE4029), /* ~= 10^-52 */
U64(0xBF8FDB78, 0x849A5F96), U64(0xDE985204, 0x72BDD033), /* ~= 10^-51 */
U64(0xEF73D256, 0xA5C0F77C), U64(0x963E6685, 0x8F6D4440), /* ~= 10^-50 */
U64(0x95A86376, 0x27989AAD), U64(0xDDE70013, 0x79A44AA8), /* ~= 10^-49 */
U64(0xBB127C53, 0xB17EC159), U64(0x5560C018, 0x580D5D52), /* ~= 10^-48 */
U64(0xE9D71B68, 0x9DDE71AF), U64(0xAAB8F01E, 0x6E10B4A6), /* ~= 10^-47 */
U64(0x92267121, 0x62AB070D), U64(0xCAB39613, 0x04CA70E8), /* ~= 10^-46 */
U64(0xB6B00D69, 0xBB55C8D1), U64(0x3D607B97, 0xC5FD0D22), /* ~= 10^-45 */
U64(0xE45C10C4, 0x2A2B3B05), U64(0x8CB89A7D, 0xB77C506A), /* ~= 10^-44 */
U64(0x8EB98A7A, 0x9A5B04E3), U64(0x77F3608E, 0x92ADB242), /* ~= 10^-43 */
U64(0xB267ED19, 0x40F1C61C), U64(0x55F038B2, 0x37591ED3), /* ~= 10^-42 */
U64(0xDF01E85F, 0x912E37A3), U64(0x6B6C46DE, 0xC52F6688), /* ~= 10^-41 */
U64(0x8B61313B, 0xBABCE2C6), U64(0x2323AC4B, 0x3B3DA015), /* ~= 10^-40 */
U64(0xAE397D8A, 0xA96C1B77), U64(0xABEC975E, 0x0A0D081A), /* ~= 10^-39 */
U64(0xD9C7DCED, 0x53C72255), U64(0x96E7BD35, 0x8C904A21), /* ~= 10^-38 */
U64(0x881CEA14, 0x545C7575), U64(0x7E50D641, 0x77DA2E54), /* ~= 10^-37 */
U64(0xAA242499, 0x697392D2), U64(0xDDE50BD1, 0xD5D0B9E9), /* ~= 10^-36 */
U64(0xD4AD2DBF, 0xC3D07787), U64(0x955E4EC6, 0x4B44E864), /* ~= 10^-35 */
U64(0x84EC3C97, 0xDA624AB4), U64(0xBD5AF13B, 0xEF0B113E), /* ~= 10^-34 */
U64(0xA6274BBD, 0xD0FADD61), U64(0xECB1AD8A, 0xEACDD58E), /* ~= 10^-33 */
U64(0xCFB11EAD, 0x453994BA), U64(0x67DE18ED, 0xA5814AF2), /* ~= 10^-32 */
U64(0x81CEB32C, 0x4B43FCF4), U64(0x80EACF94, 0x8770CED7), /* ~= 10^-31 */
U64(0xA2425FF7, 0x5E14FC31), U64(0xA1258379, 0xA94D028D), /* ~= 10^-30 */
U64(0xCAD2F7F5, 0x359A3B3E), U64(0x096EE458, 0x13A04330), /* ~= 10^-29 */
U64(0xFD87B5F2, 0x8300CA0D), U64(0x8BCA9D6E, 0x188853FC), /* ~= 10^-28 */
U64(0x9E74D1B7, 0x91E07E48), U64(0x775EA264, 0xCF55347D), /* ~= 10^-27 */
U64(0xC6120625, 0x76589DDA), U64(0x95364AFE, 0x032A819D), /* ~= 10^-26 */
U64(0xF79687AE, 0xD3EEC551), U64(0x3A83DDBD, 0x83F52204), /* ~= 10^-25 */
U64(0x9ABE14CD, 0x44753B52), U64(0xC4926A96, 0x72793542), /* ~= 10^-24 */
U64(0xC16D9A00, 0x95928A27), U64(0x75B7053C, 0x0F178293), /* ~= 10^-23 */
U64(0xF1C90080, 0xBAF72CB1), U64(0x5324C68B, 0x12DD6338), /* ~= 10^-22 */
U64(0x971DA050, 0x74DA7BEE), U64(0xD3F6FC16, 0xEBCA5E03), /* ~= 10^-21 */
U64(0xBCE50864, 0x92111AEA), U64(0x88F4BB1C, 0xA6BCF584), /* ~= 10^-20 */
U64(0xEC1E4A7D, 0xB69561A5), U64(0x2B31E9E3, 0xD06C32E5), /* ~= 10^-19 */
U64(0x9392EE8E, 0x921D5D07), U64(0x3AFF322E, 0x62439FCF), /* ~= 10^-18 */
U64(0xB877AA32, 0x36A4B449), U64(0x09BEFEB9, 0xFAD487C2), /* ~= 10^-17 */
U64(0xE69594BE, 0xC44DE15B), U64(0x4C2EBE68, 0x7989A9B3), /* ~= 10^-16 */
U64(0x901D7CF7, 0x3AB0ACD9), U64(0x0F9D3701, 0x4BF60A10), /* ~= 10^-15 */
U64(0xB424DC35, 0x095CD80F), U64(0x538484C1, 0x9EF38C94), /* ~= 10^-14 */
U64(0xE12E1342, 0x4BB40E13), U64(0x2865A5F2, 0x06B06FB9), /* ~= 10^-13 */
U64(0x8CBCCC09, 0x6F5088CB), U64(0xF93F87B7, 0x442E45D3), /* ~= 10^-12 */
U64(0xAFEBFF0B, 0xCB24AAFE), U64(0xF78F69A5, 0x1539D748), /* ~= 10^-11 */
U64(0xDBE6FECE, 0xBDEDD5BE), U64(0xB573440E, 0x5A884D1B), /* ~= 10^-10 */
U64(0x89705F41, 0x36B4A597), U64(0x31680A88, 0xF8953030), /* ~= 10^-9 */
U64(0xABCC7711, 0x8461CEFC), U64(0xFDC20D2B, 0x36BA7C3D), /* ~= 10^-8 */
U64(0xD6BF94D5, 0xE57A42BC), U64(0x3D329076, 0x04691B4C), /* ~= 10^-7 */
U64(0x8637BD05, 0xAF6C69B5), U64(0xA63F9A49, 0xC2C1B10F), /* ~= 10^-6 */
U64(0xA7C5AC47, 0x1B478423), U64(0x0FCF80DC, 0x33721D53), /* ~= 10^-5 */
U64(0xD1B71758, 0xE219652B), U64(0xD3C36113, 0x404EA4A8), /* ~= 10^-4 */
U64(0x83126E97, 0x8D4FDF3B), U64(0x645A1CAC, 0x083126E9), /* ~= 10^-3 */
U64(0xA3D70A3D, 0x70A3D70A), U64(0x3D70A3D7, 0x0A3D70A3), /* ~= 10^-2 */
U64(0xCCCCCCCC, 0xCCCCCCCC), U64(0xCCCCCCCC, 0xCCCCCCCC), /* ~= 10^-1 */
U64(0x80000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^0 */
U64(0xA0000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^1 */
U64(0xC8000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^2 */
U64(0xFA000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^3 */
U64(0x9C400000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^4 */
U64(0xC3500000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^5 */
U64(0xF4240000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^6 */
U64(0x98968000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^7 */
U64(0xBEBC2000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^8 */
U64(0xEE6B2800, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^9 */
U64(0x9502F900, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^10 */
U64(0xBA43B740, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^11 */
U64(0xE8D4A510, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^12 */
U64(0x9184E72A, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^13 */
U64(0xB5E620F4, 0x80000000), U64(0x00000000, 0x00000000), /* == 10^14 */
U64(0xE35FA931, 0xA0000000), U64(0x00000000, 0x00000000), /* == 10^15 */
U64(0x8E1BC9BF, 0x04000000), U64(0x00000000, 0x00000000), /* == 10^16 */
U64(0xB1A2BC2E, 0xC5000000), U64(0x00000000, 0x00000000), /* == 10^17 */
U64(0xDE0B6B3A, 0x76400000), U64(0x00000000, 0x00000000), /* == 10^18 */
U64(0x8AC72304, 0x89E80000), U64(0x00000000, 0x00000000), /* == 10^19 */
U64(0xAD78EBC5, 0xAC620000), U64(0x00000000, 0x00000000), /* == 10^20 */
U64(0xD8D726B7, 0x177A8000), U64(0x00000000, 0x00000000), /* == 10^21 */
U64(0x87867832, 0x6EAC9000), U64(0x00000000, 0x00000000), /* == 10^22 */
U64(0xA968163F, 0x0A57B400), U64(0x00000000, 0x00000000), /* == 10^23 */
U64(0xD3C21BCE, 0xCCEDA100), U64(0x00000000, 0x00000000), /* == 10^24 */
U64(0x84595161, 0x401484A0), U64(0x00000000, 0x00000000), /* == 10^25 */
U64(0xA56FA5B9, 0x9019A5C8), U64(0x00000000, 0x00000000), /* == 10^26 */
U64(0xCECB8F27, 0xF4200F3A), U64(0x00000000, 0x00000000), /* == 10^27 */
U64(0x813F3978, 0xF8940984), U64(0x40000000, 0x00000000), /* == 10^28 */
U64(0xA18F07D7, 0x36B90BE5), U64(0x50000000, 0x00000000), /* == 10^29 */
U64(0xC9F2C9CD, 0x04674EDE), U64(0xA4000000, 0x00000000), /* == 10^30 */
U64(0xFC6F7C40, 0x45812296), U64(0x4D000000, 0x00000000), /* == 10^31 */
U64(0x9DC5ADA8, 0x2B70B59D), U64(0xF0200000, 0x00000000), /* == 10^32 */
U64(0xC5371912, 0x364CE305), U64(0x6C280000, 0x00000000), /* == 10^33 */
U64(0xF684DF56, 0xC3E01BC6), U64(0xC7320000, 0x00000000), /* == 10^34 */
U64(0x9A130B96, 0x3A6C115C), U64(0x3C7F4000, 0x00000000), /* == 10^35 */
U64(0xC097CE7B, 0xC90715B3), U64(0x4B9F1000, 0x00000000), /* == 10^36 */
U64(0xF0BDC21A, 0xBB48DB20), U64(0x1E86D400, 0x00000000), /* == 10^37 */
U64(0x96769950, 0xB50D88F4), U64(0x13144480, 0x00000000), /* == 10^38 */
U64(0xBC143FA4, 0xE250EB31), U64(0x17D955A0, 0x00000000), /* == 10^39 */
U64(0xEB194F8E, 0x1AE525FD), U64(0x5DCFAB08, 0x00000000), /* == 10^40 */
U64(0x92EFD1B8, 0xD0CF37BE), U64(0x5AA1CAE5, 0x00000000), /* == 10^41 */
U64(0xB7ABC627, 0x050305AD), U64(0xF14A3D9E, 0x40000000), /* == 10^42 */
U64(0xE596B7B0, 0xC643C719), U64(0x6D9CCD05, 0xD0000000), /* == 10^43 */
U64(0x8F7E32CE, 0x7BEA5C6F), U64(0xE4820023, 0xA2000000), /* == 10^44 */
U64(0xB35DBF82, 0x1AE4F38B), U64(0xDDA2802C, 0x8A800000), /* == 10^45 */
U64(0xE0352F62, 0xA19E306E), U64(0xD50B2037, 0xAD200000), /* == 10^46 */
U64(0x8C213D9D, 0xA502DE45), U64(0x4526F422, 0xCC340000), /* == 10^47 */
U64(0xAF298D05, 0x0E4395D6), U64(0x9670B12B, 0x7F410000), /* == 10^48 */
U64(0xDAF3F046, 0x51D47B4C), U64(0x3C0CDD76, 0x5F114000), /* == 10^49 */
U64(0x88D8762B, 0xF324CD0F), U64(0xA5880A69, 0xFB6AC800), /* == 10^50 */
U64(0xAB0E93B6, 0xEFEE0053), U64(0x8EEA0D04, 0x7A457A00), /* == 10^51 */
U64(0xD5D238A4, 0xABE98068), U64(0x72A49045, 0x98D6D880), /* == 10^52 */
U64(0x85A36366, 0xEB71F041), U64(0x47A6DA2B, 0x7F864750), /* == 10^53 */
U64(0xA70C3C40, 0xA64E6C51), U64(0x999090B6, 0x5F67D924), /* == 10^54 */
U64(0xD0CF4B50, 0xCFE20765), U64(0xFFF4B4E3, 0xF741CF6D), /* == 10^55 */
U64(0x82818F12, 0x81ED449F), U64(0xBFF8F10E, 0x7A8921A4), /* ~= 10^56 */
U64(0xA321F2D7, 0x226895C7), U64(0xAFF72D52, 0x192B6A0D), /* ~= 10^57 */
U64(0xCBEA6F8C, 0xEB02BB39), U64(0x9BF4F8A6, 0x9F764490), /* ~= 10^58 */
U64(0xFEE50B70, 0x25C36A08), U64(0x02F236D0, 0x4753D5B4), /* ~= 10^59 */
U64(0x9F4F2726, 0x179A2245), U64(0x01D76242, 0x2C946590), /* ~= 10^60 */
U64(0xC722F0EF, 0x9D80AAD6), U64(0x424D3AD2, 0xB7B97EF5), /* ~= 10^61 */
U64(0xF8EBAD2B, 0x84E0D58B), U64(0xD2E08987, 0x65A7DEB2), /* ~= 10^62 */
U64(0x9B934C3B, 0x330C8577), U64(0x63CC55F4, 0x9F88EB2F), /* ~= 10^63 */
U64(0xC2781F49, 0xFFCFA6D5), U64(0x3CBF6B71, 0xC76B25FB), /* ~= 10^64 */
U64(0xF316271C, 0x7FC3908A), U64(0x8BEF464E, 0x3945EF7A), /* ~= 10^65 */
U64(0x97EDD871, 0xCFDA3A56), U64(0x97758BF0, 0xE3CBB5AC), /* ~= 10^66 */
U64(0xBDE94E8E, 0x43D0C8EC), U64(0x3D52EEED, 0x1CBEA317), /* ~= 10^67 */
U64(0xED63A231, 0xD4C4FB27), U64(0x4CA7AAA8, 0x63EE4BDD), /* ~= 10^68 */
U64(0x945E455F, 0x24FB1CF8), U64(0x8FE8CAA9, 0x3E74EF6A), /* ~= 10^69 */
U64(0xB975D6B6, 0xEE39E436), U64(0xB3E2FD53, 0x8E122B44), /* ~= 10^70 */
U64(0xE7D34C64, 0xA9C85D44), U64(0x60DBBCA8, 0x7196B616), /* ~= 10^71 */
U64(0x90E40FBE, 0xEA1D3A4A), U64(0xBC8955E9, 0x46FE31CD), /* ~= 10^72 */
U64(0xB51D13AE, 0xA4A488DD), U64(0x6BABAB63, 0x98BDBE41), /* ~= 10^73 */
U64(0xE264589A, 0x4DCDAB14), U64(0xC696963C, 0x7EED2DD1), /* ~= 10^74 */
U64(0x8D7EB760, 0x70A08AEC), U64(0xFC1E1DE5, 0xCF543CA2), /* ~= 10^75 */
U64(0xB0DE6538, 0x8CC8ADA8), U64(0x3B25A55F, 0x43294BCB), /* ~= 10^76 */
U64(0xDD15FE86, 0xAFFAD912), U64(0x49EF0EB7, 0x13F39EBE), /* ~= 10^77 */
U64(0x8A2DBF14, 0x2DFCC7AB), U64(0x6E356932, 0x6C784337), /* ~= 10^78 */
U64(0xACB92ED9, 0x397BF996), U64(0x49C2C37F, 0x07965404), /* ~= 10^79 */
U64(0xD7E77A8F, 0x87DAF7FB), U64(0xDC33745E, 0xC97BE906), /* ~= 10^80 */
U64(0x86F0AC99, 0xB4E8DAFD), U64(0x69A028BB, 0x3DED71A3), /* ~= 10^81 */
U64(0xA8ACD7C0, 0x222311BC), U64(0xC40832EA, 0x0D68CE0C), /* ~= 10^82 */
U64(0xD2D80DB0, 0x2AABD62B), U64(0xF50A3FA4, 0x90C30190), /* ~= 10^83 */
U64(0x83C7088E, 0x1AAB65DB), U64(0x792667C6, 0xDA79E0FA), /* ~= 10^84 */
U64(0xA4B8CAB1, 0xA1563F52), U64(0x577001B8, 0x91185938), /* ~= 10^85 */
U64(0xCDE6FD5E, 0x09ABCF26), U64(0xED4C0226, 0xB55E6F86), /* ~= 10^86 */
U64(0x80B05E5A, 0xC60B6178), U64(0x544F8158, 0x315B05B4), /* ~= 10^87 */
U64(0xA0DC75F1, 0x778E39D6), U64(0x696361AE, 0x3DB1C721), /* ~= 10^88 */
U64(0xC913936D, 0xD571C84C), U64(0x03BC3A19, 0xCD1E38E9), /* ~= 10^89 */
U64(0xFB587849, 0x4ACE3A5F), U64(0x04AB48A0, 0x4065C723), /* ~= 10^90 */
U64(0x9D174B2D, 0xCEC0E47B), U64(0x62EB0D64, 0x283F9C76), /* ~= 10^91 */
U64(0xC45D1DF9, 0x42711D9A), U64(0x3BA5D0BD, 0x324F8394), /* ~= 10^92 */
U64(0xF5746577, 0x930D6500), U64(0xCA8F44EC, 0x7EE36479), /* ~= 10^93 */
U64(0x9968BF6A, 0xBBE85F20), U64(0x7E998B13, 0xCF4E1ECB), /* ~= 10^94 */
U64(0xBFC2EF45, 0x6AE276E8), U64(0x9E3FEDD8, 0xC321A67E), /* ~= 10^95 */
U64(0xEFB3AB16, 0xC59B14A2), U64(0xC5CFE94E, 0xF3EA101E), /* ~= 10^96 */
U64(0x95D04AEE, 0x3B80ECE5), U64(0xBBA1F1D1, 0x58724A12), /* ~= 10^97 */
U64(0xBB445DA9, 0xCA61281F), U64(0x2A8A6E45, 0xAE8EDC97), /* ~= 10^98 */
U64(0xEA157514, 0x3CF97226), U64(0xF52D09D7, 0x1A3293BD), /* ~= 10^99 */
U64(0x924D692C, 0xA61BE758), U64(0x593C2626, 0x705F9C56), /* ~= 10^100 */
U64(0xB6E0C377, 0xCFA2E12E), U64(0x6F8B2FB0, 0x0C77836C), /* ~= 10^101 */
U64(0xE498F455, 0xC38B997A), U64(0x0B6DFB9C, 0x0F956447), /* ~= 10^102 */
U64(0x8EDF98B5, 0x9A373FEC), U64(0x4724BD41, 0x89BD5EAC), /* ~= 10^103 */
U64(0xB2977EE3, 0x00C50FE7), U64(0x58EDEC91, 0xEC2CB657), /* ~= 10^104 */
U64(0xDF3D5E9B, 0xC0F653E1), U64(0x2F2967B6, 0x6737E3ED), /* ~= 10^105 */
U64(0x8B865B21, 0x5899F46C), U64(0xBD79E0D2, 0x0082EE74), /* ~= 10^106 */
U64(0xAE67F1E9, 0xAEC07187), U64(0xECD85906, 0x80A3AA11), /* ~= 10^107 */
U64(0xDA01EE64, 0x1A708DE9), U64(0xE80E6F48, 0x20CC9495), /* ~= 10^108 */
U64(0x884134FE, 0x908658B2), U64(0x3109058D, 0x147FDCDD), /* ~= 10^109 */
U64(0xAA51823E, 0x34A7EEDE), U64(0xBD4B46F0, 0x599FD415), /* ~= 10^110 */
U64(0xD4E5E2CD, 0xC1D1EA96), U64(0x6C9E18AC, 0x7007C91A), /* ~= 10^111 */
U64(0x850FADC0, 0x9923329E), U64(0x03E2CF6B, 0xC604DDB0), /* ~= 10^112 */
U64(0xA6539930, 0xBF6BFF45), U64(0x84DB8346, 0xB786151C), /* ~= 10^113 */
U64(0xCFE87F7C, 0xEF46FF16), U64(0xE6126418, 0x65679A63), /* ~= 10^114 */
U64(0x81F14FAE, 0x158C5F6E), U64(0x4FCB7E8F, 0x3F60C07E), /* ~= 10^115 */
U64(0xA26DA399, 0x9AEF7749), U64(0xE3BE5E33, 0x0F38F09D), /* ~= 10^116 */
U64(0xCB090C80, 0x01AB551C), U64(0x5CADF5BF, 0xD3072CC5), /* ~= 10^117 */
U64(0xFDCB4FA0, 0x02162A63), U64(0x73D9732F, 0xC7C8F7F6), /* ~= 10^118 */
U64(0x9E9F11C4, 0x014DDA7E), U64(0x2867E7FD, 0xDCDD9AFA), /* ~= 10^119 */
U64(0xC646D635, 0x01A1511D), U64(0xB281E1FD, 0x541501B8), /* ~= 10^120 */
U64(0xF7D88BC2, 0x4209A565), U64(0x1F225A7C, 0xA91A4226), /* ~= 10^121 */
U64(0x9AE75759, 0x6946075F), U64(0x3375788D, 0xE9B06958), /* ~= 10^122 */
U64(0xC1A12D2F, 0xC3978937), U64(0x0052D6B1, 0x641C83AE), /* ~= 10^123 */
U64(0xF209787B, 0xB47D6B84), U64(0xC0678C5D, 0xBD23A49A), /* ~= 10^124 */
U64(0x9745EB4D, 0x50CE6332), U64(0xF840B7BA, 0x963646E0), /* ~= 10^125 */
U64(0xBD176620, 0xA501FBFF), U64(0xB650E5A9, 0x3BC3D898), /* ~= 10^126 */
U64(0xEC5D3FA8, 0xCE427AFF), U64(0xA3E51F13, 0x8AB4CEBE), /* ~= 10^127 */
U64(0x93BA47C9, 0x80E98CDF), U64(0xC66F336C, 0x36B10137), /* ~= 10^128 */
U64(0xB8A8D9BB, 0xE123F017), U64(0xB80B0047, 0x445D4184), /* ~= 10^129 */
U64(0xE6D3102A, 0xD96CEC1D), U64(0xA60DC059, 0x157491E5), /* ~= 10^130 */
U64(0x9043EA1A, 0xC7E41392), U64(0x87C89837, 0xAD68DB2F), /* ~= 10^131 */
U64(0xB454E4A1, 0x79DD1877), U64(0x29BABE45, 0x98C311FB), /* ~= 10^132 */
U64(0xE16A1DC9, 0xD8545E94), U64(0xF4296DD6, 0xFEF3D67A), /* ~= 10^133 */
U64(0x8CE2529E, 0x2734BB1D), U64(0x1899E4A6, 0x5F58660C), /* ~= 10^134 */
U64(0xB01AE745, 0xB101E9E4), U64(0x5EC05DCF, 0xF72E7F8F), /* ~= 10^135 */
U64(0xDC21A117, 0x1D42645D), U64(0x76707543, 0xF4FA1F73), /* ~= 10^136 */
U64(0x899504AE, 0x72497EBA), U64(0x6A06494A, 0x791C53A8), /* ~= 10^137 */
U64(0xABFA45DA, 0x0EDBDE69), U64(0x0487DB9D, 0x17636892), /* ~= 10^138 */
U64(0xD6F8D750, 0x9292D603), U64(0x45A9D284, 0x5D3C42B6), /* ~= 10^139 */
U64(0x865B8692, 0x5B9BC5C2), U64(0x0B8A2392, 0xBA45A9B2), /* ~= 10^140 */
U64(0xA7F26836, 0xF282B732), U64(0x8E6CAC77, 0x68D7141E), /* ~= 10^141 */
U64(0xD1EF0244, 0xAF2364FF), U64(0x3207D795, 0x430CD926), /* ~= 10^142 */
U64(0x8335616A, 0xED761F1F), U64(0x7F44E6BD, 0x49E807B8), /* ~= 10^143 */
U64(0xA402B9C5, 0xA8D3A6E7), U64(0x5F16206C, 0x9C6209A6), /* ~= 10^144 */
U64(0xCD036837, 0x130890A1), U64(0x36DBA887, 0xC37A8C0F), /* ~= 10^145 */
U64(0x80222122, 0x6BE55A64), U64(0xC2494954, 0xDA2C9789), /* ~= 10^146 */
U64(0xA02AA96B, 0x06DEB0FD), U64(0xF2DB9BAA, 0x10B7BD6C), /* ~= 10^147 */
U64(0xC83553C5, 0xC8965D3D), U64(0x6F928294, 0x94E5ACC7), /* ~= 10^148 */
U64(0xFA42A8B7, 0x3ABBF48C), U64(0xCB772339, 0xBA1F17F9), /* ~= 10^149 */
U64(0x9C69A972, 0x84B578D7), U64(0xFF2A7604, 0x14536EFB), /* ~= 10^150 */
U64(0xC38413CF, 0x25E2D70D), U64(0xFEF51385, 0x19684ABA), /* ~= 10^151 */
U64(0xF46518C2, 0xEF5B8CD1), U64(0x7EB25866, 0x5FC25D69), /* ~= 10^152 */
U64(0x98BF2F79, 0xD5993802), U64(0xEF2F773F, 0xFBD97A61), /* ~= 10^153 */
U64(0xBEEEFB58, 0x4AFF8603), U64(0xAAFB550F, 0xFACFD8FA), /* ~= 10^154 */
U64(0xEEAABA2E, 0x5DBF6784), U64(0x95BA2A53, 0xF983CF38), /* ~= 10^155 */
U64(0x952AB45C, 0xFA97A0B2), U64(0xDD945A74, 0x7BF26183), /* ~= 10^156 */
U64(0xBA756174, 0x393D88DF), U64(0x94F97111, 0x9AEEF9E4), /* ~= 10^157 */
U64(0xE912B9D1, 0x478CEB17), U64(0x7A37CD56, 0x01AAB85D), /* ~= 10^158 */
U64(0x91ABB422, 0xCCB812EE), U64(0xAC62E055, 0xC10AB33A), /* ~= 10^159 */
U64(0xB616A12B, 0x7FE617AA), U64(0x577B986B, 0x314D6009), /* ~= 10^160 */
U64(0xE39C4976, 0x5FDF9D94), U64(0xED5A7E85, 0xFDA0B80B), /* ~= 10^161 */
U64(0x8E41ADE9, 0xFBEBC27D), U64(0x14588F13, 0xBE847307), /* ~= 10^162 */
U64(0xB1D21964, 0x7AE6B31C), U64(0x596EB2D8, 0xAE258FC8), /* ~= 10^163 */
U64(0xDE469FBD, 0x99A05FE3), U64(0x6FCA5F8E, 0xD9AEF3BB), /* ~= 10^164 */
U64(0x8AEC23D6, 0x80043BEE), U64(0x25DE7BB9, 0x480D5854), /* ~= 10^165 */
U64(0xADA72CCC, 0x20054AE9), U64(0xAF561AA7, 0x9A10AE6A), /* ~= 10^166 */
U64(0xD910F7FF, 0x28069DA4), U64(0x1B2BA151, 0x8094DA04), /* ~= 10^167 */
U64(0x87AA9AFF, 0x79042286), U64(0x90FB44D2, 0xF05D0842), /* ~= 10^168 */
U64(0xA99541BF, 0x57452B28), U64(0x353A1607, 0xAC744A53), /* ~= 10^169 */
U64(0xD3FA922F, 0x2D1675F2), U64(0x42889B89, 0x97915CE8), /* ~= 10^170 */
U64(0x847C9B5D, 0x7C2E09B7), U64(0x69956135, 0xFEBADA11), /* ~= 10^171 */
U64(0xA59BC234, 0xDB398C25), U64(0x43FAB983, 0x7E699095), /* ~= 10^172 */
U64(0xCF02B2C2, 0x1207EF2E), U64(0x94F967E4, 0x5E03F4BB), /* ~= 10^173 */
U64(0x8161AFB9, 0x4B44F57D), U64(0x1D1BE0EE, 0xBAC278F5), /* ~= 10^174 */
U64(0xA1BA1BA7, 0x9E1632DC), U64(0x6462D92A, 0x69731732), /* ~= 10^175 */
U64(0xCA28A291, 0x859BBF93), U64(0x7D7B8F75, 0x03CFDCFE), /* ~= 10^176 */
U64(0xFCB2CB35, 0xE702AF78), U64(0x5CDA7352, 0x44C3D43E), /* ~= 10^177 */
U64(0x9DEFBF01, 0xB061ADAB), U64(0x3A088813, 0x6AFA64A7), /* ~= 10^178 */
U64(0xC56BAEC2, 0x1C7A1916), U64(0x088AAA18, 0x45B8FDD0), /* ~= 10^179 */
U64(0xF6C69A72, 0xA3989F5B), U64(0x8AAD549E, 0x57273D45), /* ~= 10^180 */
U64(0x9A3C2087, 0xA63F6399), U64(0x36AC54E2, 0xF678864B), /* ~= 10^181 */
U64(0xC0CB28A9, 0x8FCF3C7F), U64(0x84576A1B, 0xB416A7DD), /* ~= 10^182 */
U64(0xF0FDF2D3, 0xF3C30B9F), U64(0x656D44A2, 0xA11C51D5), /* ~= 10^183 */
U64(0x969EB7C4, 0x7859E743), U64(0x9F644AE5, 0xA4B1B325), /* ~= 10^184 */
U64(0xBC4665B5, 0x96706114), U64(0x873D5D9F, 0x0DDE1FEE), /* ~= 10^185 */
U64(0xEB57FF22, 0xFC0C7959), U64(0xA90CB506, 0xD155A7EA), /* ~= 10^186 */
U64(0x9316FF75, 0xDD87CBD8), U64(0x09A7F124, 0x42D588F2), /* ~= 10^187 */
U64(0xB7DCBF53, 0x54E9BECE), U64(0x0C11ED6D, 0x538AEB2F), /* ~= 10^188 */
U64(0xE5D3EF28, 0x2A242E81), U64(0x8F1668C8, 0xA86DA5FA), /* ~= 10^189 */
U64(0x8FA47579, 0x1A569D10), U64(0xF96E017D, 0x694487BC), /* ~= 10^190 */
U64(0xB38D92D7, 0x60EC4455), U64(0x37C981DC, 0xC395A9AC), /* ~= 10^191 */
U64(0xE070F78D, 0x3927556A), U64(0x85BBE253, 0xF47B1417), /* ~= 10^192 */
U64(0x8C469AB8, 0x43B89562), U64(0x93956D74, 0x78CCEC8E), /* ~= 10^193 */
U64(0xAF584166, 0x54A6BABB), U64(0x387AC8D1, 0x970027B2), /* ~= 10^194 */
U64(0xDB2E51BF, 0xE9D0696A), U64(0x06997B05, 0xFCC0319E), /* ~= 10^195 */
U64(0x88FCF317, 0xF22241E2), U64(0x441FECE3, 0xBDF81F03), /* ~= 10^196 */
U64(0xAB3C2FDD, 0xEEAAD25A), U64(0xD527E81C, 0xAD7626C3), /* ~= 10^197 */
U64(0xD60B3BD5, 0x6A5586F1), U64(0x8A71E223, 0xD8D3B074), /* ~= 10^198 */
U64(0x85C70565, 0x62757456), U64(0xF6872D56, 0x67844E49), /* ~= 10^199 */
U64(0xA738C6BE, 0xBB12D16C), U64(0xB428F8AC, 0x016561DB), /* ~= 10^200 */
U64(0xD106F86E, 0x69D785C7), U64(0xE13336D7, 0x01BEBA52), /* ~= 10^201 */
U64(0x82A45B45, 0x0226B39C), U64(0xECC00246, 0x61173473), /* ~= 10^202 */
U64(0xA34D7216, 0x42B06084), U64(0x27F002D7, 0xF95D0190), /* ~= 10^203 */
U64(0xCC20CE9B, 0xD35C78A5), U64(0x31EC038D, 0xF7B441F4), /* ~= 10^204 */
U64(0xFF290242, 0xC83396CE), U64(0x7E670471, 0x75A15271), /* ~= 10^205 */
U64(0x9F79A169, 0xBD203E41), U64(0x0F0062C6, 0xE984D386), /* ~= 10^206 */
U64(0xC75809C4, 0x2C684DD1), U64(0x52C07B78, 0xA3E60868), /* ~= 10^207 */
U64(0xF92E0C35, 0x37826145), U64(0xA7709A56, 0xCCDF8A82), /* ~= 10^208 */
U64(0x9BBCC7A1, 0x42B17CCB), U64(0x88A66076, 0x400BB691), /* ~= 10^209 */
U64(0xC2ABF989, 0x935DDBFE), U64(0x6ACFF893, 0xD00EA435), /* ~= 10^210 */
U64(0xF356F7EB, 0xF83552FE), U64(0x0583F6B8, 0xC4124D43), /* ~= 10^211 */
U64(0x98165AF3, 0x7B2153DE), U64(0xC3727A33, 0x7A8B704A), /* ~= 10^212 */
U64(0xBE1BF1B0, 0x59E9A8D6), U64(0x744F18C0, 0x592E4C5C), /* ~= 10^213 */
U64(0xEDA2EE1C, 0x7064130C), U64(0x1162DEF0, 0x6F79DF73), /* ~= 10^214 */
U64(0x9485D4D1, 0xC63E8BE7), U64(0x8ADDCB56, 0x45AC2BA8), /* ~= 10^215 */
U64(0xB9A74A06, 0x37CE2EE1), U64(0x6D953E2B, 0xD7173692), /* ~= 10^216 */
U64(0xE8111C87, 0xC5C1BA99), U64(0xC8FA8DB6, 0xCCDD0437), /* ~= 10^217 */
U64(0x910AB1D4, 0xDB9914A0), U64(0x1D9C9892, 0x400A22A2), /* ~= 10^218 */
U64(0xB54D5E4A, 0x127F59C8), U64(0x2503BEB6, 0xD00CAB4B), /* ~= 10^219 */
U64(0xE2A0B5DC, 0x971F303A), U64(0x2E44AE64, 0x840FD61D), /* ~= 10^220 */
U64(0x8DA471A9, 0xDE737E24), U64(0x5CEAECFE, 0xD289E5D2), /* ~= 10^221 */
U64(0xB10D8E14, 0x56105DAD), U64(0x7425A83E, 0x872C5F47), /* ~= 10^222 */
U64(0xDD50F199, 0x6B947518), U64(0xD12F124E, 0x28F77719), /* ~= 10^223 */
U64(0x8A5296FF, 0xE33CC92F), U64(0x82BD6B70, 0xD99AAA6F), /* ~= 10^224 */
U64(0xACE73CBF, 0xDC0BFB7B), U64(0x636CC64D, 0x1001550B), /* ~= 10^225 */
U64(0xD8210BEF, 0xD30EFA5A), U64(0x3C47F7E0, 0x5401AA4E), /* ~= 10^226 */
U64(0x8714A775, 0xE3E95C78), U64(0x65ACFAEC, 0x34810A71), /* ~= 10^227 */
U64(0xA8D9D153, 0x5CE3B396), U64(0x7F1839A7, 0x41A14D0D), /* ~= 10^228 */
U64(0xD31045A8, 0x341CA07C), U64(0x1EDE4811, 0x1209A050), /* ~= 10^229 */
U64(0x83EA2B89, 0x2091E44D), U64(0x934AED0A, 0xAB460432), /* ~= 10^230 */
U64(0xA4E4B66B, 0x68B65D60), U64(0xF81DA84D, 0x5617853F), /* ~= 10^231 */
U64(0xCE1DE406, 0x42E3F4B9), U64(0x36251260, 0xAB9D668E), /* ~= 10^232 */
U64(0x80D2AE83, 0xE9CE78F3), U64(0xC1D72B7C, 0x6B426019), /* ~= 10^233 */
U64(0xA1075A24, 0xE4421730), U64(0xB24CF65B, 0x8612F81F), /* ~= 10^234 */
U64(0xC94930AE, 0x1D529CFC), U64(0xDEE033F2, 0x6797B627), /* ~= 10^235 */
U64(0xFB9B7CD9, 0xA4A7443C), U64(0x169840EF, 0x017DA3B1), /* ~= 10^236 */
U64(0x9D412E08, 0x06E88AA5), U64(0x8E1F2895, 0x60EE864E), /* ~= 10^237 */
U64(0xC491798A, 0x08A2AD4E), U64(0xF1A6F2BA, 0xB92A27E2), /* ~= 10^238 */
U64(0xF5B5D7EC, 0x8ACB58A2), U64(0xAE10AF69, 0x6774B1DB), /* ~= 10^239 */
U64(0x9991A6F3, 0xD6BF1765), U64(0xACCA6DA1, 0xE0A8EF29), /* ~= 10^240 */
U64(0xBFF610B0, 0xCC6EDD3F), U64(0x17FD090A, 0x58D32AF3), /* ~= 10^241 */
U64(0xEFF394DC, 0xFF8A948E), U64(0xDDFC4B4C, 0xEF07F5B0), /* ~= 10^242 */
U64(0x95F83D0A, 0x1FB69CD9), U64(0x4ABDAF10, 0x1564F98E), /* ~= 10^243 */
U64(0xBB764C4C, 0xA7A4440F), U64(0x9D6D1AD4, 0x1ABE37F1), /* ~= 10^244 */
U64(0xEA53DF5F, 0xD18D5513), U64(0x84C86189, 0x216DC5ED), /* ~= 10^245 */
U64(0x92746B9B, 0xE2F8552C), U64(0x32FD3CF5, 0xB4E49BB4), /* ~= 10^246 */
U64(0xB7118682, 0xDBB66A77), U64(0x3FBC8C33, 0x221DC2A1), /* ~= 10^247 */
U64(0xE4D5E823, 0x92A40515), U64(0x0FABAF3F, 0xEAA5334A), /* ~= 10^248 */
U64(0x8F05B116, 0x3BA6832D), U64(0x29CB4D87, 0xF2A7400E), /* ~= 10^249 */
U64(0xB2C71D5B, 0xCA9023F8), U64(0x743E20E9, 0xEF511012), /* ~= 10^250 */
U64(0xDF78E4B2, 0xBD342CF6), U64(0x914DA924, 0x6B255416), /* ~= 10^251 */
U64(0x8BAB8EEF, 0xB6409C1A), U64(0x1AD089B6, 0xC2F7548E), /* ~= 10^252 */
U64(0xAE9672AB, 0xA3D0C320), U64(0xA184AC24, 0x73B529B1), /* ~= 10^253 */
U64(0xDA3C0F56, 0x8CC4F3E8), U64(0xC9E5D72D, 0x90A2741E), /* ~= 10^254 */
U64(0x88658996, 0x17FB1871), U64(0x7E2FA67C, 0x7A658892), /* ~= 10^255 */
U64(0xAA7EEBFB, 0x9DF9DE8D), U64(0xDDBB901B, 0x98FEEAB7), /* ~= 10^256 */
U64(0xD51EA6FA, 0x85785631), U64(0x552A7422, 0x7F3EA565), /* ~= 10^257 */
U64(0x8533285C, 0x936B35DE), U64(0xD53A8895, 0x8F87275F), /* ~= 10^258 */
U64(0xA67FF273, 0xB8460356), U64(0x8A892ABA, 0xF368F137), /* ~= 10^259 */
U64(0xD01FEF10, 0xA657842C), U64(0x2D2B7569, 0xB0432D85), /* ~= 10^260 */
U64(0x8213F56A, 0x67F6B29B), U64(0x9C3B2962, 0x0E29FC73), /* ~= 10^261 */
U64(0xA298F2C5, 0x01F45F42), U64(0x8349F3BA, 0x91B47B8F), /* ~= 10^262 */
U64(0xCB3F2F76, 0x42717713), U64(0x241C70A9, 0x36219A73), /* ~= 10^263 */
U64(0xFE0EFB53, 0xD30DD4D7), U64(0xED238CD3, 0x83AA0110), /* ~= 10^264 */
U64(0x9EC95D14, 0x63E8A506), U64(0xF4363804, 0x324A40AA), /* ~= 10^265 */
U64(0xC67BB459, 0x7CE2CE48), U64(0xB143C605, 0x3EDCD0D5), /* ~= 10^266 */
U64(0xF81AA16F, 0xDC1B81DA), U64(0xDD94B786, 0x8E94050A), /* ~= 10^267 */
U64(0x9B10A4E5, 0xE9913128), U64(0xCA7CF2B4, 0x191C8326), /* ~= 10^268 */
U64(0xC1D4CE1F, 0x63F57D72), U64(0xFD1C2F61, 0x1F63A3F0), /* ~= 10^269 */
U64(0xF24A01A7, 0x3CF2DCCF), U64(0xBC633B39, 0x673C8CEC), /* ~= 10^270 */
U64(0x976E4108, 0x8617CA01), U64(0xD5BE0503, 0xE085D813), /* ~= 10^271 */
U64(0xBD49D14A, 0xA79DBC82), U64(0x4B2D8644, 0xD8A74E18), /* ~= 10^272 */
U64(0xEC9C459D, 0x51852BA2), U64(0xDDF8E7D6, 0x0ED1219E), /* ~= 10^273 */
U64(0x93E1AB82, 0x52F33B45), U64(0xCABB90E5, 0xC942B503), /* ~= 10^274 */
U64(0xB8DA1662, 0xE7B00A17), U64(0x3D6A751F, 0x3B936243), /* ~= 10^275 */
U64(0xE7109BFB, 0xA19C0C9D), U64(0x0CC51267, 0x0A783AD4), /* ~= 10^276 */
U64(0x906A617D, 0x450187E2), U64(0x27FB2B80, 0x668B24C5), /* ~= 10^277 */
U64(0xB484F9DC, 0x9641E9DA), U64(0xB1F9F660, 0x802DEDF6), /* ~= 10^278 */
U64(0xE1A63853, 0xBBD26451), U64(0x5E7873F8, 0xA0396973), /* ~= 10^279 */
U64(0x8D07E334, 0x55637EB2), U64(0xDB0B487B, 0x6423E1E8), /* ~= 10^280 */
U64(0xB049DC01, 0x6ABC5E5F), U64(0x91CE1A9A, 0x3D2CDA62), /* ~= 10^281 */
U64(0xDC5C5301, 0xC56B75F7), U64(0x7641A140, 0xCC7810FB), /* ~= 10^282 */
U64(0x89B9B3E1, 0x1B6329BA), U64(0xA9E904C8, 0x7FCB0A9D), /* ~= 10^283 */
U64(0xAC2820D9, 0x623BF429), U64(0x546345FA, 0x9FBDCD44), /* ~= 10^284 */
U64(0xD732290F, 0xBACAF133), U64(0xA97C1779, 0x47AD4095), /* ~= 10^285 */
U64(0x867F59A9, 0xD4BED6C0), U64(0x49ED8EAB, 0xCCCC485D), /* ~= 10^286 */
U64(0xA81F3014, 0x49EE8C70), U64(0x5C68F256, 0xBFFF5A74), /* ~= 10^287 */
U64(0xD226FC19, 0x5C6A2F8C), U64(0x73832EEC, 0x6FFF3111), /* ~= 10^288 */
U64(0x83585D8F, 0xD9C25DB7), U64(0xC831FD53, 0xC5FF7EAB), /* ~= 10^289 */
U64(0xA42E74F3, 0xD032F525), U64(0xBA3E7CA8, 0xB77F5E55), /* ~= 10^290 */
U64(0xCD3A1230, 0xC43FB26F), U64(0x28CE1BD2, 0xE55F35EB), /* ~= 10^291 */
U64(0x80444B5E, 0x7AA7CF85), U64(0x7980D163, 0xCF5B81B3), /* ~= 10^292 */
U64(0xA0555E36, 0x1951C366), U64(0xD7E105BC, 0xC332621F), /* ~= 10^293 */
U64(0xC86AB5C3, 0x9FA63440), U64(0x8DD9472B, 0xF3FEFAA7), /* ~= 10^294 */
U64(0xFA856334, 0x878FC150), U64(0xB14F98F6, 0xF0FEB951), /* ~= 10^295 */
U64(0x9C935E00, 0xD4B9D8D2), U64(0x6ED1BF9A, 0x569F33D3), /* ~= 10^296 */
U64(0xC3B83581, 0x09E84F07), U64(0x0A862F80, 0xEC4700C8), /* ~= 10^297 */
U64(0xF4A642E1, 0x4C6262C8), U64(0xCD27BB61, 0x2758C0FA), /* ~= 10^298 */
U64(0x98E7E9CC, 0xCFBD7DBD), U64(0x8038D51C, 0xB897789C), /* ~= 10^299 */
U64(0xBF21E440, 0x03ACDD2C), U64(0xE0470A63, 0xE6BD56C3), /* ~= 10^300 */
U64(0xEEEA5D50, 0x04981478), U64(0x1858CCFC, 0xE06CAC74), /* ~= 10^301 */
U64(0x95527A52, 0x02DF0CCB), U64(0x0F37801E, 0x0C43EBC8), /* ~= 10^302 */
U64(0xBAA718E6, 0x8396CFFD), U64(0xD3056025, 0x8F54E6BA), /* ~= 10^303 */
U64(0xE950DF20, 0x247C83FD), U64(0x47C6B82E, 0xF32A2069), /* ~= 10^304 */
U64(0x91D28B74, 0x16CDD27E), U64(0x4CDC331D, 0x57FA5441), /* ~= 10^305 */
U64(0xB6472E51, 0x1C81471D), U64(0xE0133FE4, 0xADF8E952), /* ~= 10^306 */
U64(0xE3D8F9E5, 0x63A198E5), U64(0x58180FDD, 0xD97723A6), /* ~= 10^307 */
U64(0x8E679C2F, 0x5E44FF8F), U64(0x570F09EA, 0xA7EA7648), /* ~= 10^308 */
U64(0xB201833B, 0x35D63F73), U64(0x2CD2CC65, 0x51E513DA), /* ~= 10^309 */
U64(0xDE81E40A, 0x034BCF4F), U64(0xF8077F7E, 0xA65E58D1), /* ~= 10^310 */
U64(0x8B112E86, 0x420F6191), U64(0xFB04AFAF, 0x27FAF782), /* ~= 10^311 */
U64(0xADD57A27, 0xD29339F6), U64(0x79C5DB9A, 0xF1F9B563), /* ~= 10^312 */
U64(0xD94AD8B1, 0xC7380874), U64(0x18375281, 0xAE7822BC), /* ~= 10^313 */
U64(0x87CEC76F, 0x1C830548), U64(0x8F229391, 0x0D0B15B5), /* ~= 10^314 */
U64(0xA9C2794A, 0xE3A3C69A), U64(0xB2EB3875, 0x504DDB22), /* ~= 10^315 */
U64(0xD433179D, 0x9C8CB841), U64(0x5FA60692, 0xA46151EB), /* ~= 10^316 */
U64(0x849FEEC2, 0x81D7F328), U64(0xDBC7C41B, 0xA6BCD333), /* ~= 10^317 */
U64(0xA5C7EA73, 0x224DEFF3), U64(0x12B9B522, 0x906C0800), /* ~= 10^318 */
U64(0xCF39E50F, 0xEAE16BEF), U64(0xD768226B, 0x34870A00), /* ~= 10^319 */
U64(0x81842F29, 0xF2CCE375), U64(0xE6A11583, 0x00D46640), /* ~= 10^320 */
U64(0xA1E53AF4, 0x6F801C53), U64(0x60495AE3, 0xC1097FD0), /* ~= 10^321 */
U64(0xCA5E89B1, 0x8B602368), U64(0x385BB19C, 0xB14BDFC4), /* ~= 10^322 */
U64(0xFCF62C1D, 0xEE382C42), U64(0x46729E03, 0xDD9ED7B5), /* ~= 10^323 */
U64(0x9E19DB92, 0xB4E31BA9), U64(0x6C07A2C2, 0x6A8346D1) /* ~= 10^324 */
};
/**
Get the cached pow10 value from `pow10_sig_table`.
@param exp10 The exponent of pow(10, e). This value must in range
`POW10_SIG_TABLE_MIN_EXP` to `POW10_SIG_TABLE_MAX_EXP`.
@param hi The highest 64 bits of pow(10, e).
@param lo The lower 64 bits after `hi`.
*/
static_inline void pow10_table_get_sig(i32 exp10, u64 *hi, u64 *lo) {
i32 idx = exp10 - (POW10_SIG_TABLE_MIN_EXP);
*hi = pow10_sig_table[idx * 2];
*lo = pow10_sig_table[idx * 2 + 1];
}
/**
Get the exponent (base 2) for highest 64 bits significand in `pow10_sig_table`.
*/
static_inline void pow10_table_get_exp(i32 exp10, i32 *exp2) {
/* e2 = floor(log2(pow(10, e))) - 64 + 1 */
/* = floor(e * log2(10) - 63) */
*exp2 = (exp10 * 217706 - 4128768) >> 16;
}
#endif
/*==============================================================================
* MARK: - Number and Bit Utils (Private)
*============================================================================*/
/** Convert bits to double. */
static_inline f64 f64_from_bits(u64 u) {
f64 f;
memcpy(&f, &u, sizeof(u));
return f;
}
/** Convert double to bits. */
static_inline u64 f64_to_bits(f64 f) {
u64 u;
memcpy(&u, &f, sizeof(u));
return u;
}
/** Convert double to bits. */
static_inline u32 f32_to_bits(f32 f) {
u32 u;
memcpy(&u, &f, sizeof(u));
return u;
}
/** Get 'infinity' bits with sign. */
static_inline u64 f64_bits_inf(bool sign) {
#if YYJSON_HAS_IEEE_754
return F64_BITS_INF | ((u64)sign << 63);
#elif defined(INFINITY)
return f64_to_bits(sign ? -INFINITY : INFINITY);
#else
return f64_to_bits(sign ? -HUGE_VAL : HUGE_VAL);
#endif
}
/** Get 'nan' bits with sign. */
static_inline u64 f64_bits_nan(bool sign) {
#if YYJSON_HAS_IEEE_754
return F64_BITS_NAN | ((u64)sign << 63);
#elif defined(NAN)
return f64_to_bits(sign ? (f64)-NAN : (f64)NAN);
#else
return f64_to_bits((sign ? -0.0 : 0.0) / 0.0);
#endif
}
/** Casting double to float, allow overflow. */
#if yyjson_has_attribute(no_sanitize)
__attribute__((no_sanitize("undefined")))
#elif yyjson_gcc_available(4, 9, 0)
__attribute__((__no_sanitize_undefined__))
#endif
static_inline f32 f64_to_f32(f64 val) {
return (f32)val;
}
/** Returns the number of leading 0-bits in value (input should not be 0). */
static_inline u32 u64_lz_bits(u64 v) {
#if GCC_HAS_CLZLL
return (u32)__builtin_clzll(v);
#elif MSC_HAS_BIT_SCAN_64
unsigned long r;
_BitScanReverse64(&r, v);
return (u32)63 - (u32)r;
#elif MSC_HAS_BIT_SCAN
unsigned long hi, lo;
bool hi_set = _BitScanReverse(&hi, (u32)(v >> 32)) != 0;
_BitScanReverse(&lo, (u32)v);
hi |= 32;
return (u32)63 - (u32)(hi_set ? hi : lo);
#else
/* branchless, use De Bruijn sequence */
/* see: https://www.chessprogramming.org/BitScan */
const u8 table[64] = {
63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2,
9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1,
17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18,
38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0
};
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v |= v >> 32;
return table[(v * U64(0x03F79D71, 0xB4CB0A89)) >> 58];
#endif
}
/** Returns the number of trailing 0-bits in value (input should not be 0). */
static_inline u32 u64_tz_bits(u64 v) {
#if GCC_HAS_CTZLL
return (u32)__builtin_ctzll(v);
#elif MSC_HAS_BIT_SCAN_64
unsigned long r;
_BitScanForward64(&r, v);
return (u32)r;
#elif MSC_HAS_BIT_SCAN
unsigned long lo, hi;
bool lo_set = _BitScanForward(&lo, (u32)(v)) != 0;
_BitScanForward(&hi, (u32)(v >> 32));
hi += 32;
return lo_set ? lo : hi;
#else
/* branchless, use De Bruijn sequence */
/* see: https://www.chessprogramming.org/BitScan */
const u8 table[64] = {
0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
};
return table[((v & (~v + 1)) * U64(0x022FDD63, 0xCC95386D)) >> 58];
#endif
}
/** Multiplies two 64-bit unsigned integers (a * b),
returns the 128-bit result as 'hi' and 'lo'. */
static_inline void u128_mul(u64 a, u64 b, u64 *hi, u64 *lo) {
#if YYJSON_HAS_INT128
u128 m = (u128)a * b;
*hi = (u64)(m >> 64);
*lo = (u64)(m);
#elif MSC_HAS_UMUL128
*lo = _umul128(a, b, hi);
#else
u32 a0 = (u32)(a), a1 = (u32)(a >> 32);
u32 b0 = (u32)(b), b1 = (u32)(b >> 32);
u64 p00 = (u64)a0 * b0, p01 = (u64)a0 * b1;
u64 p10 = (u64)a1 * b0, p11 = (u64)a1 * b1;
u64 m0 = p01 + (p00 >> 32);
u32 m00 = (u32)(m0), m01 = (u32)(m0 >> 32);
u64 m1 = p10 + m00;
u32 m10 = (u32)(m1), m11 = (u32)(m1 >> 32);
*hi = p11 + m01 + m11;
*lo = ((u64)m10 << 32) | (u32)p00;
#endif
}
/** Multiplies two 64-bit unsigned integers and add a value (a * b + c),
returns the 128-bit result as 'hi' and 'lo'. */
static_inline void u128_mul_add(u64 a, u64 b, u64 c, u64 *hi, u64 *lo) {
#if YYJSON_HAS_INT128
u128 m = (u128)a * b + c;
*hi = (u64)(m >> 64);
*lo = (u64)(m);
#else
u64 h, l, t;
u128_mul(a, b, &h, &l);
t = l + c;
h += (u64)(((t < l) | (t < c)));
*hi = h;
*lo = t;
#endif
}
/*==============================================================================
* MARK: - File Utils (Private)
* These functions are used to read and write JSON files.
*============================================================================*/
#define YYJSON_FOPEN_E
#if !defined(_MSC_VER) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
# if __GLIBC_PREREQ(2, 7)
# undef YYJSON_FOPEN_E
# define YYJSON_FOPEN_E "e" /* glibc extension to enable O_CLOEXEC */
# endif
#endif
static_inline FILE *fopen_safe(const char *path, const char *mode) {
#if YYJSON_MSC_VER >= 1400
FILE *file = NULL;
if (fopen_s(&file, path, mode) != 0) return NULL;
return file;
#else
return fopen(path, mode);
#endif
}
static_inline FILE *fopen_readonly(const char *path) {
return fopen_safe(path, "rb" YYJSON_FOPEN_E);
}
static_inline FILE *fopen_writeonly(const char *path) {
return fopen_safe(path, "wb" YYJSON_FOPEN_E);
}
static_inline usize fread_safe(void *buf, usize size, FILE *file) {
#if YYJSON_MSC_VER >= 1400
return fread_s(buf, size, 1, size, file);
#else
return fread(buf, 1, size, file);
#endif
}
/*==============================================================================
* MARK: - Size Utils (Private)
* These functions are used for memory allocation.
*============================================================================*/
/** Returns whether the size is overflow after increment. */
static_inline bool size_add_is_overflow(usize size, usize add) {
return size > (size + add);
}
/** Returns whether the size is power of 2 (size should not be 0). */
static_inline bool size_is_pow2(usize size) {
return (size & (size - 1)) == 0;
}
/** Align size upwards (may overflow). */
static_inline usize size_align_up(usize size, usize align) {
if (size_is_pow2(align)) {
return (size + (align - 1)) & ~(align - 1);
} else {
return size + align - (size + align - 1) % align - 1;
}
}
/** Align size downwards. */
static_inline usize size_align_down(usize size, usize align) {
if (size_is_pow2(align)) {
return size & ~(align - 1);
} else {
return size - (size % align);
}
}
/** Align address upwards (may overflow). */
static_inline void *mem_align_up(void *mem, usize align) {
usize size;
memcpy(&size, &mem, sizeof(usize));
size = size_align_up(size, align);
memcpy(&mem, &size, sizeof(usize));
return mem;
}
/*==============================================================================
* MARK: - Default Memory Allocator (Private)
* This is a simple libc memory allocator wrapper.
*============================================================================*/
static void *default_malloc(void *ctx, usize size) {
return malloc(size);
}
static void *default_realloc(void *ctx, void *ptr, usize old_size, usize size) {
return realloc(ptr, size);
}
static void default_free(void *ctx, void *ptr) {
free(ptr);
}
static const yyjson_alc YYJSON_DEFAULT_ALC = {
default_malloc, default_realloc, default_free, NULL
};
/*==============================================================================
* MARK: - Null Memory Allocator (Private)
* This allocator is just a placeholder to ensure that the internal
* malloc/realloc/free function pointers are not null.
*============================================================================*/
static void *null_malloc(void *ctx, usize size) {
return NULL;
}
static void *null_realloc(void *ctx, void *ptr, usize old_size, usize size) {
return NULL;
}
static void null_free(void *ctx, void *ptr) {
return;
}
static const yyjson_alc YYJSON_NULL_ALC = {
null_malloc, null_realloc, null_free, NULL
};
/*==============================================================================
* MARK: - Pool Memory Allocator (Public)
* This allocator is initialized with a fixed-size buffer.
* The buffer is split into multiple memory chunks for memory allocation.
*============================================================================*/
/** memory chunk header */
typedef struct pool_chunk {
usize size; /* chunk memory size, include chunk header */
struct pool_chunk *next; /* linked list, nullable */
/* char mem[]; flexible array member */
} pool_chunk;
/** allocator ctx header */
typedef struct pool_ctx {
usize size; /* total memory size, include ctx header */
pool_chunk *free_list; /* linked list, nullable */
/* pool_chunk chunks[]; flexible array member */
} pool_ctx;
/** align up the input size to chunk size */
static_inline void pool_size_align(usize *size) {
*size = size_align_up(*size, sizeof(pool_chunk)) + sizeof(pool_chunk);
}
static void *pool_malloc(void *ctx_ptr, usize size) {
/* assert(size != 0) */
pool_ctx *ctx = (pool_ctx *)ctx_ptr;
pool_chunk *next, *prev = NULL, *cur = ctx->free_list;
if (unlikely(size >= ctx->size)) return NULL;
pool_size_align(&size);
while (cur) {
if (cur->size < size) {
/* not enough space, try next chunk */
prev = cur;
cur = cur->next;
continue;
}
if (cur->size >= size + sizeof(pool_chunk) * 2) {
/* too much space, split this chunk */
next = (pool_chunk *)(void *)((u8 *)cur + size);
next->size = cur->size - size;
next->next = cur->next;
cur->size = size;
} else {
/* just enough space, use whole chunk */
next = cur->next;
}
if (prev) prev->next = next;
else ctx->free_list = next;
return (void *)(cur + 1);
}
return NULL;
}
static void pool_free(void *ctx_ptr, void *ptr) {
/* assert(ptr != NULL) */
pool_ctx *ctx = (pool_ctx *)ctx_ptr;
pool_chunk *cur = ((pool_chunk *)ptr) - 1;
pool_chunk *prev = NULL, *next = ctx->free_list;
while (next && next < cur) {
prev = next;
next = next->next;
}
if (prev) prev->next = cur;
else ctx->free_list = cur;
cur->next = next;
if (next && ((u8 *)cur + cur->size) == (u8 *)next) {
/* merge cur to higher chunk */
cur->size += next->size;
cur->next = next->next;
}
if (prev && ((u8 *)prev + prev->size) == (u8 *)cur) {
/* merge cur to lower chunk */
prev->size += cur->size;
prev->next = cur->next;
}
}
static void *pool_realloc(void *ctx_ptr, void *ptr,
usize old_size, usize size) {
/* assert(ptr != NULL && size != 0 && old_size < size) */
pool_ctx *ctx = (pool_ctx *)ctx_ptr;
pool_chunk *cur = ((pool_chunk *)ptr) - 1, *prev, *next, *tmp;
/* check size */
if (unlikely(size >= ctx->size)) return NULL;
pool_size_align(&old_size);
pool_size_align(&size);
if (unlikely(old_size == size)) return ptr;
/* find next and prev chunk */
prev = NULL;
next = ctx->free_list;
while (next && next < cur) {
prev = next;
next = next->next;
}
if ((u8 *)cur + cur->size == (u8 *)next && cur->size + next->size >= size) {
/* merge to higher chunk if they are contiguous */
usize free_size = cur->size + next->size - size;
if (free_size > sizeof(pool_chunk) * 2) {
tmp = (pool_chunk *)(void *)((u8 *)cur + size);
if (prev) prev->next = tmp;
else ctx->free_list = tmp;
tmp->next = next->next;
tmp->size = free_size;
cur->size = size;
} else {
if (prev) prev->next = next->next;
else ctx->free_list = next->next;
cur->size += next->size;
}
return ptr;
} else {
/* fallback to malloc and memcpy */
void *new_ptr = pool_malloc(ctx_ptr, size - sizeof(pool_chunk));
if (new_ptr) {
memcpy(new_ptr, ptr, cur->size - sizeof(pool_chunk));
pool_free(ctx_ptr, ptr);
}
return new_ptr;
}
}
bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, usize size) {
pool_chunk *chunk;
pool_ctx *ctx;
if (unlikely(!alc)) return false;
*alc = YYJSON_NULL_ALC;
if (size < sizeof(pool_ctx) * 4) return false;
ctx = (pool_ctx *)mem_align_up(buf, sizeof(pool_ctx));
if (unlikely(!ctx)) return false;
size -= (usize)((u8 *)ctx - (u8 *)buf);
size = size_align_down(size, sizeof(pool_ctx));
chunk = (pool_chunk *)(ctx + 1);
chunk->size = size - sizeof(pool_ctx);
chunk->next = NULL;
ctx->size = size;
ctx->free_list = chunk;
alc->malloc = pool_malloc;
alc->realloc = pool_realloc;
alc->free = pool_free;
alc->ctx = (void *)ctx;
return true;
}
/*==============================================================================
* MARK: - Dynamic Memory Allocator (Public)
* This allocator allocates memory on demand and does not immediately release
* unused memory. Instead, it places the unused memory into a freelist for
* potential reuse in the future. It is only when the entire allocator is
* destroyed that all previously allocated memory is released at once.
*============================================================================*/
/** memory chunk header */
typedef struct dyn_chunk {
usize size; /* chunk size, include header */
struct dyn_chunk *next;
/* char mem[]; flexible array member */
} dyn_chunk;
/** allocator ctx header */
typedef struct {
dyn_chunk free_list; /* dummy header, sorted from small to large */
dyn_chunk used_list; /* dummy header */
} dyn_ctx;
/** align up the input size to chunk size */
static_inline bool dyn_size_align(usize *size) {
usize alc_size = *size + sizeof(dyn_chunk);
alc_size = size_align_up(alc_size, YYJSON_ALC_DYN_MIN_SIZE);
if (unlikely(alc_size < *size)) return false; /* overflow */
*size = alc_size;
return true;
}
/** remove a chunk from list (the chunk must already be in the list) */
static_inline void dyn_chunk_list_remove(dyn_chunk *list, dyn_chunk *chunk) {
dyn_chunk *prev = list, *cur;
for (cur = prev->next; cur; cur = cur->next) {
if (cur == chunk) {
prev->next = cur->next;
cur->next = NULL;
return;
}
prev = cur;
}
}
/** add a chunk to list header (the chunk must not be in the list) */
static_inline void dyn_chunk_list_add(dyn_chunk *list, dyn_chunk *chunk) {
chunk->next = list->next;
list->next = chunk;
}
static void *dyn_malloc(void *ctx_ptr, usize size) {
/* assert(size != 0) */
const yyjson_alc def = YYJSON_DEFAULT_ALC;
dyn_ctx *ctx = (dyn_ctx *)ctx_ptr;
dyn_chunk *chunk, *prev;
if (unlikely(!dyn_size_align(&size))) return NULL;
/* freelist is empty, create new chunk */
if (!ctx->free_list.next) {
chunk = (dyn_chunk *)def.malloc(def.ctx, size);
if (unlikely(!chunk)) return NULL;
chunk->size = size;
chunk->next = NULL;
dyn_chunk_list_add(&ctx->used_list, chunk);
return (void *)(chunk + 1);
}
/* find a large enough chunk, or resize the largest chunk */
prev = &ctx->free_list;
while (true) {
chunk = prev->next;
if (chunk->size >= size) { /* enough size, reuse this chunk */
prev->next = chunk->next;
dyn_chunk_list_add(&ctx->used_list, chunk);
return (void *)(chunk + 1);
}
if (!chunk->next) { /* resize the largest chunk */
chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size);
if (unlikely(!chunk)) return NULL;
prev->next = NULL;
chunk->size = size;
dyn_chunk_list_add(&ctx->used_list, chunk);
return (void *)(chunk + 1);
}
prev = chunk;
}
}
static void *dyn_realloc(void *ctx_ptr, void *ptr,
usize old_size, usize size) {
/* assert(ptr != NULL && size != 0 && old_size < size) */
const yyjson_alc def = YYJSON_DEFAULT_ALC;
dyn_ctx *ctx = (dyn_ctx *)ctx_ptr;
dyn_chunk *new_chunk, *chunk = (dyn_chunk *)ptr - 1;
if (unlikely(!dyn_size_align(&size))) return NULL;
if (chunk->size >= size) return ptr;
dyn_chunk_list_remove(&ctx->used_list, chunk);
new_chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size);
if (likely(new_chunk)) {
new_chunk->size = size;
chunk = new_chunk;
}
dyn_chunk_list_add(&ctx->used_list, chunk);
return new_chunk ? (void *)(new_chunk + 1) : NULL;
}
static void dyn_free(void *ctx_ptr, void *ptr) {
/* assert(ptr != NULL) */
dyn_ctx *ctx = (dyn_ctx *)ctx_ptr;
dyn_chunk *chunk = (dyn_chunk *)ptr - 1, *prev;
dyn_chunk_list_remove(&ctx->used_list, chunk);
for (prev = &ctx->free_list; prev; prev = prev->next) {
if (!prev->next || prev->next->size >= chunk->size) {
chunk->next = prev->next;
prev->next = chunk;
break;
}
}
}
yyjson_alc *yyjson_alc_dyn_new(void) {
const yyjson_alc def = YYJSON_DEFAULT_ALC;
usize hdr_len = sizeof(yyjson_alc) + sizeof(dyn_ctx);
yyjson_alc *alc = (yyjson_alc *)def.malloc(def.ctx, hdr_len);
dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1);
if (unlikely(!alc)) return NULL;
alc->malloc = dyn_malloc;
alc->realloc = dyn_realloc;
alc->free = dyn_free;
alc->ctx = alc + 1;
memset(ctx, 0, sizeof(*ctx));
return alc;
}
void yyjson_alc_dyn_free(yyjson_alc *alc) {
const yyjson_alc def = YYJSON_DEFAULT_ALC;
dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1);
dyn_chunk *chunk, *next;
if (unlikely(!alc)) return;
for (chunk = ctx->free_list.next; chunk; chunk = next) {
next = chunk->next;
def.free(def.ctx, chunk);
}
for (chunk = ctx->used_list.next; chunk; chunk = next) {
next = chunk->next;
def.free(def.ctx, chunk);
}
def.free(def.ctx, alc);
}
/*==============================================================================
* MARK: - JSON Struct Utils (Public)
* These functions are used for creating, copying, releasing, and comparing
* JSON documents and values. They are widely used throughout this library.
*============================================================================*/
static_inline void unsafe_yyjson_str_pool_release(yyjson_str_pool *pool,
yyjson_alc *alc) {
yyjson_str_chunk *chunk = pool->chunks, *next;
while (chunk) {
next = chunk->next;
alc->free(alc->ctx, chunk);
chunk = next;
}
}
static_inline void unsafe_yyjson_val_pool_release(yyjson_val_pool *pool,
yyjson_alc *alc) {
yyjson_val_chunk *chunk = pool->chunks, *next;
while (chunk) {
next = chunk->next;
alc->free(alc->ctx, chunk);
chunk = next;
}
}
bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool,
const yyjson_alc *alc, usize len) {
yyjson_str_chunk *chunk;
usize size, max_len;
/* create a new chunk */
max_len = USIZE_MAX - sizeof(yyjson_str_chunk);
if (unlikely(len > max_len)) return false;
size = len + sizeof(yyjson_str_chunk);
size = yyjson_max(pool->chunk_size, size);
chunk = (yyjson_str_chunk *)alc->malloc(alc->ctx, size);
if (unlikely(!chunk)) return false;
/* insert the new chunk as the head of the linked list */
chunk->next = pool->chunks;
chunk->chunk_size = size;
pool->chunks = chunk;
pool->cur = (char *)chunk + sizeof(yyjson_str_chunk);
pool->end = (char *)chunk + size;
/* the next chunk is twice the size of the current one */
size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max);
if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */
pool->chunk_size = size;
return true;
}
bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool,
const yyjson_alc *alc, usize count) {
yyjson_val_chunk *chunk;
usize size, max_count;
/* create a new chunk */
max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1;
if (unlikely(count > max_count)) return false;
size = (count + 1) * sizeof(yyjson_mut_val);
size = yyjson_max(pool->chunk_size, size);
chunk = (yyjson_val_chunk *)alc->malloc(alc->ctx, size);
if (unlikely(!chunk)) return false;
/* insert the new chunk as the head of the linked list */
chunk->next = pool->chunks;
chunk->chunk_size = size;
pool->chunks = chunk;
pool->cur = (yyjson_mut_val *)(void *)((u8 *)chunk) + 1;
pool->end = (yyjson_mut_val *)(void *)((u8 *)chunk + size);
/* the next chunk is twice the size of the current one */
size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max);
if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */
pool->chunk_size = size;
return true;
}
bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, size_t len) {
usize max_size = USIZE_MAX - sizeof(yyjson_str_chunk);
if (!doc || !len || len > max_size) return false;
doc->str_pool.chunk_size = len + sizeof(yyjson_str_chunk);
return true;
}
bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) {
usize max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1;
if (!doc || !count || count > max_count) return false;
doc->val_pool.chunk_size = (count + 1) * sizeof(yyjson_mut_val);
return true;
}
void yyjson_mut_doc_free(yyjson_mut_doc *doc) {
if (doc) {
yyjson_alc alc = doc->alc;
memset(&doc->alc, 0, sizeof(alc));
unsafe_yyjson_str_pool_release(&doc->str_pool, &alc);
unsafe_yyjson_val_pool_release(&doc->val_pool, &alc);
alc.free(alc.ctx, doc);
}
}
yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc) {
yyjson_mut_doc *doc;
if (!alc) alc = &YYJSON_DEFAULT_ALC;
doc = (yyjson_mut_doc *)alc->malloc(alc->ctx, sizeof(yyjson_mut_doc));
if (!doc) return NULL;
memset(doc, 0, sizeof(yyjson_mut_doc));
doc->alc = *alc;
doc->str_pool.chunk_size = YYJSON_MUT_DOC_STR_POOL_INIT_SIZE;
doc->str_pool.chunk_size_max = YYJSON_MUT_DOC_STR_POOL_MAX_SIZE;
doc->val_pool.chunk_size = YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE;
doc->val_pool.chunk_size_max = YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE;
return doc;
}
yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, const yyjson_alc *alc) {
yyjson_mut_doc *m_doc;
yyjson_mut_val *m_val;
if (!doc || !doc->root) return NULL;
m_doc = yyjson_mut_doc_new(alc);
if (!m_doc) return NULL;
m_val = yyjson_val_mut_copy(m_doc, doc->root);
if (!m_val) {
yyjson_mut_doc_free(m_doc);
return NULL;
}
yyjson_mut_doc_set_root(m_doc, m_val);
return m_doc;
}
yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc,
const yyjson_alc *alc) {
yyjson_mut_doc *m_doc;
yyjson_mut_val *m_val;
if (!doc) return NULL;
if (!doc->root) return yyjson_mut_doc_new(alc);
m_doc = yyjson_mut_doc_new(alc);
if (!m_doc) return NULL;
m_val = yyjson_mut_val_mut_copy(m_doc, doc->root);
if (!m_val) {
yyjson_mut_doc_free(m_doc);
return NULL;
}
yyjson_mut_doc_set_root(m_doc, m_val);
return m_doc;
}
yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *m_doc,
yyjson_val *i_vals) {
/*
The immutable object or array stores all sub-values in a contiguous memory,
We copy them to another contiguous memory as mutable values,
then reconnect the mutable values with the original relationship.
*/
usize i_vals_len;
yyjson_mut_val *m_vals, *m_val;
yyjson_val *i_val, *i_end;
if (!m_doc || !i_vals) return NULL;
i_end = unsafe_yyjson_get_next(i_vals);
i_vals_len = (usize)(unsafe_yyjson_get_next(i_vals) - i_vals);
m_vals = unsafe_yyjson_mut_val(m_doc, i_vals_len);
if (!m_vals) return NULL;
i_val = i_vals;
m_val = m_vals;
for (; i_val < i_end; i_val++, m_val++) {
yyjson_type type = unsafe_yyjson_get_type(i_val);
m_val->tag = i_val->tag;
m_val->uni.u64 = i_val->uni.u64;
if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) {
const char *str = i_val->uni.str;
usize str_len = unsafe_yyjson_get_len(i_val);
m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len);
if (!m_val->uni.str) return NULL;
} else if (type == YYJSON_TYPE_ARR) {
usize len = unsafe_yyjson_get_len(i_val);
if (len > 0) {
yyjson_val *ii_val = i_val + 1, *ii_next;
yyjson_mut_val *mm_val = m_val + 1, *mm_ctn = m_val, *mm_next;
while (len-- > 1) {
ii_next = unsafe_yyjson_get_next(ii_val);
mm_next = mm_val + (ii_next - ii_val);
mm_val->next = mm_next;
ii_val = ii_next;
mm_val = mm_next;
}
mm_val->next = mm_ctn + 1;
mm_ctn->uni.ptr = mm_val;
}
} else if (type == YYJSON_TYPE_OBJ) {
usize len = unsafe_yyjson_get_len(i_val);
if (len > 0) {
yyjson_val *ii_key = i_val + 1, *ii_nextkey;
yyjson_mut_val *mm_key = m_val + 1, *mm_ctn = m_val;
yyjson_mut_val *mm_nextkey;
while (len-- > 1) {
ii_nextkey = unsafe_yyjson_get_next(ii_key + 1);
mm_nextkey = mm_key + (ii_nextkey - ii_key);
mm_key->next = mm_key + 1;
mm_key->next->next = mm_nextkey;
ii_key = ii_nextkey;
mm_key = mm_nextkey;
}
mm_key->next = mm_key + 1;
mm_key->next->next = mm_ctn + 1;
mm_ctn->uni.ptr = mm_key;
}
}
}
return m_vals;
}
static yyjson_mut_val *unsafe_yyjson_mut_val_mut_copy(yyjson_mut_doc *m_doc,
yyjson_mut_val *m_vals) {
/*
The mutable object or array stores all sub-values in a circular linked
list, so we can traverse them in the same loop. The traversal starts from
the last item, continues with the first item in a list, and ends with the
second to last item, which needs to be linked to the last item to close the
circle.
*/
yyjson_mut_val *m_val = unsafe_yyjson_mut_val(m_doc, 1);
if (unlikely(!m_val)) return NULL;
m_val->tag = m_vals->tag;
switch (unsafe_yyjson_get_type(m_vals)) {
case YYJSON_TYPE_OBJ:
case YYJSON_TYPE_ARR:
if (unsafe_yyjson_get_len(m_vals) > 0) {
yyjson_mut_val *last = (yyjson_mut_val *)m_vals->uni.ptr;
yyjson_mut_val *next = last->next, *prev;
prev = unsafe_yyjson_mut_val_mut_copy(m_doc, last);
if (!prev) return NULL;
m_val->uni.ptr = (void *)prev;
while (next != last) {
prev->next = unsafe_yyjson_mut_val_mut_copy(m_doc, next);
if (!prev->next) return NULL;
prev = prev->next;
next = next->next;
}
prev->next = (yyjson_mut_val *)m_val->uni.ptr;
}
break;
case YYJSON_TYPE_RAW:
case YYJSON_TYPE_STR: {
const char *str = m_vals->uni.str;
usize str_len = unsafe_yyjson_get_len(m_vals);
m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len);
if (!m_val->uni.str) return NULL;
break;
}
default:
m_val->uni = m_vals->uni;
break;
}
return m_val;
}
yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc,
yyjson_mut_val *val) {
if (doc && val) return unsafe_yyjson_mut_val_mut_copy(doc, val);
return NULL;
}
/* Count the number of values and the total length of the strings. */
static void yyjson_mut_stat(yyjson_mut_val *val,
usize *val_sum, usize *str_sum) {
yyjson_type type = unsafe_yyjson_get_type(val);
*val_sum += 1;
if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) {
yyjson_mut_val *child = (yyjson_mut_val *)val->uni.ptr;
usize len = unsafe_yyjson_get_len(val), i;
len <<= (u8)(type == YYJSON_TYPE_OBJ);
*val_sum += len;
for (i = 0; i < len; i++) {
yyjson_type stype = unsafe_yyjson_get_type(child);
if (stype == YYJSON_TYPE_STR || stype == YYJSON_TYPE_RAW) {
*str_sum += unsafe_yyjson_get_len(child) + 1;
} else if (stype == YYJSON_TYPE_ARR || stype == YYJSON_TYPE_OBJ) {
yyjson_mut_stat(child, val_sum, str_sum);
*val_sum -= 1;
}
child = child->next;
}
} else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) {
*str_sum += unsafe_yyjson_get_len(val) + 1;
}
}
/* Copy mutable values to immutable value pool. */
static usize yyjson_imut_copy(yyjson_val **val_ptr, char **buf_ptr,
yyjson_mut_val *mval) {
yyjson_val *val = *val_ptr;
yyjson_type type = unsafe_yyjson_get_type(mval);
if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) {
yyjson_mut_val *child = (yyjson_mut_val *)mval->uni.ptr;
usize len = unsafe_yyjson_get_len(mval), i;
usize val_sum = 1;
if (type == YYJSON_TYPE_OBJ) {
if (len) child = child->next->next;
len <<= 1;
} else {
if (len) child = child->next;
}
*val_ptr = val + 1;
for (i = 0; i < len; i++) {
val_sum += yyjson_imut_copy(val_ptr, buf_ptr, child);
child = child->next;
}
val->tag = mval->tag;
val->uni.ofs = val_sum * sizeof(yyjson_val);
return val_sum;
} else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) {
char *buf = *buf_ptr;
usize len = unsafe_yyjson_get_len(mval);
memcpy((void *)buf, (const void *)mval->uni.str, len);
buf[len] = '\0';
val->tag = mval->tag;
val->uni.str = buf;
*val_ptr = val + 1;
*buf_ptr = buf + len + 1;
return 1;
} else {
val->tag = mval->tag;
val->uni = mval->uni;
*val_ptr = val + 1;
return 1;
}
}
yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *mdoc,
const yyjson_alc *alc) {
if (!mdoc) return NULL;
return yyjson_mut_val_imut_copy(mdoc->root, alc);
}
yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *mval,
const yyjson_alc *alc) {
usize val_num = 0, str_sum = 0, hdr_size, buf_size;
yyjson_doc *doc = NULL;
yyjson_val *val_hdr = NULL;
/* This value should be NULL here. Setting a non-null value suppresses
warning from the clang analyzer. */
char *str_hdr = (char *)(void *)&str_sum;
if (!mval) return NULL;
if (!alc) alc = &YYJSON_DEFAULT_ALC;
/* traverse the input value to get pool size */
yyjson_mut_stat(mval, &val_num, &str_sum);
/* create doc and val pool */
hdr_size = size_align_up(sizeof(yyjson_doc), sizeof(yyjson_val));
buf_size = hdr_size + val_num * sizeof(yyjson_val);
doc = (yyjson_doc *)alc->malloc(alc->ctx, buf_size);
if (!doc) return NULL;
memset(doc, 0, sizeof(yyjson_doc));
val_hdr = (yyjson_val *)(void *)((char *)(void *)doc + hdr_size);
doc->root = val_hdr;
doc->alc = *alc;
/* create str pool */
if (str_sum > 0) {
str_hdr = (char *)alc->malloc(alc->ctx, str_sum);
doc->str_pool = str_hdr;
if (!str_hdr) {
alc->free(alc->ctx, (void *)doc);
return NULL;
}
}
/* copy vals and strs */
doc->val_read = yyjson_imut_copy(&val_hdr, &str_hdr, mval);
doc->dat_read = str_sum + 1;
return doc;
}
static_inline bool unsafe_yyjson_num_equals(void *lhs, void *rhs) {
yyjson_val_uni *luni = &((yyjson_val *)lhs)->uni;
yyjson_val_uni *runi = &((yyjson_val *)rhs)->uni;
yyjson_subtype lt = unsafe_yyjson_get_subtype(lhs);
yyjson_subtype rt = unsafe_yyjson_get_subtype(rhs);
if (lt == rt) return luni->u64 == runi->u64;
if (lt == YYJSON_SUBTYPE_SINT && rt == YYJSON_SUBTYPE_UINT) {
return luni->i64 >= 0 && luni->u64 == runi->u64;
}
if (lt == YYJSON_SUBTYPE_UINT && rt == YYJSON_SUBTYPE_SINT) {
return runi->i64 >= 0 && luni->u64 == runi->u64;
}
return false;
}
static_inline bool unsafe_yyjson_str_equals(void *lhs, void *rhs) {
usize len = unsafe_yyjson_get_len(lhs);
if (len != unsafe_yyjson_get_len(rhs)) return false;
return !memcmp(unsafe_yyjson_get_str(lhs),
unsafe_yyjson_get_str(rhs), len);
}
bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) {
yyjson_type type = unsafe_yyjson_get_type(lhs);
if (type != unsafe_yyjson_get_type(rhs)) return false;
switch (type) {
case YYJSON_TYPE_OBJ: {
usize len = unsafe_yyjson_get_len(lhs);
if (len != unsafe_yyjson_get_len(rhs)) return false;
if (len > 0) {
yyjson_obj_iter iter;
yyjson_obj_iter_init(rhs, &iter);
lhs = unsafe_yyjson_get_first(lhs);
while (len-- > 0) {
rhs = yyjson_obj_iter_getn(&iter, lhs->uni.str,
unsafe_yyjson_get_len(lhs));
if (!rhs) return false;
if (!unsafe_yyjson_equals(lhs + 1, rhs)) return false;
lhs = unsafe_yyjson_get_next(lhs + 1);
}
}
/* yyjson allows duplicate keys, so the check may be inaccurate */
return true;
}
case YYJSON_TYPE_ARR: {
usize len = unsafe_yyjson_get_len(lhs);
if (len != unsafe_yyjson_get_len(rhs)) return false;
if (len > 0) {
lhs = unsafe_yyjson_get_first(lhs);
rhs = unsafe_yyjson_get_first(rhs);
while (len-- > 0) {
if (!unsafe_yyjson_equals(lhs, rhs)) return false;
lhs = unsafe_yyjson_get_next(lhs);
rhs = unsafe_yyjson_get_next(rhs);
}
}
return true;
}
case YYJSON_TYPE_NUM:
return unsafe_yyjson_num_equals(lhs, rhs);
case YYJSON_TYPE_RAW:
case YYJSON_TYPE_STR:
return unsafe_yyjson_str_equals(lhs, rhs);
case YYJSON_TYPE_NULL:
case YYJSON_TYPE_BOOL:
return lhs->tag == rhs->tag;
default:
return false;
}
}
bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs) {
yyjson_type type = unsafe_yyjson_get_type(lhs);
if (type != unsafe_yyjson_get_type(rhs)) return false;
switch (type) {
case YYJSON_TYPE_OBJ: {
usize len = unsafe_yyjson_get_len(lhs);
if (len != unsafe_yyjson_get_len(rhs)) return false;
if (len > 0) {
yyjson_mut_obj_iter iter;
yyjson_mut_obj_iter_init(rhs, &iter);
lhs = (yyjson_mut_val *)lhs->uni.ptr;
while (len-- > 0) {
rhs = yyjson_mut_obj_iter_getn(&iter, lhs->uni.str,
unsafe_yyjson_get_len(lhs));
if (!rhs) return false;
if (!unsafe_yyjson_mut_equals(lhs->next, rhs)) return false;
lhs = lhs->next->next;
}
}
/* yyjson allows duplicate keys, so the check may be inaccurate */
return true;
}
case YYJSON_TYPE_ARR: {
usize len = unsafe_yyjson_get_len(lhs);
if (len != unsafe_yyjson_get_len(rhs)) return false;
if (len > 0) {
lhs = (yyjson_mut_val *)lhs->uni.ptr;
rhs = (yyjson_mut_val *)rhs->uni.ptr;
while (len-- > 0) {
if (!unsafe_yyjson_mut_equals(lhs, rhs)) return false;
lhs = lhs->next;
rhs = rhs->next;
}
}
return true;
}
case YYJSON_TYPE_NUM:
return unsafe_yyjson_num_equals(lhs, rhs);
case YYJSON_TYPE_RAW:
case YYJSON_TYPE_STR:
return unsafe_yyjson_str_equals(lhs, rhs);
case YYJSON_TYPE_NULL:
case YYJSON_TYPE_BOOL:
return lhs->tag == rhs->tag;
default:
return false;
}
}
bool yyjson_locate_pos(const char *str, size_t len, size_t pos,
size_t *line, size_t *col, size_t *chr) {
usize line_sum = 0, line_pos = 0, chr_sum = 0;
const u8 *cur = (const u8 *)str;
const u8 *end = cur + pos;
if (!str || pos > len) {
if (line) *line = 0;
if (col) *col = 0;
if (chr) *chr = 0;
return false;
}
if (pos >= 3 && is_utf8_bom(cur)) cur += 3; /* don't count BOM */
while (cur < end) {
u8 c = *cur;
chr_sum += 1;
if (likely(c < 0x80)) { /* 0xxxxxxx (0x00-0x7F) ASCII */
if (c == '\n') {
line_sum += 1;
line_pos = chr_sum;
}
cur += 1;
}
else if (c < 0xC0) cur += 1; /* 10xxxxxx (0x80-0xBF) Invalid */
else if (c < 0xE0) cur += 2; /* 110xxxxx (0xC0-0xDF) 2-byte UTF-8 */
else if (c < 0xF0) cur += 3; /* 1110xxxx (0xE0-0xEF) 3-byte UTF-8 */
else if (c < 0xF8) cur += 4; /* 11110xxx (0xF0-0xF7) 4-byte UTF-8 */
else cur += 1; /* 11111xxx (0xF8-0xFF) Invalid */
}
if (line) *line = line_sum + 1;
if (col) *col = chr_sum - line_pos + 1;
if (chr) *chr = chr_sum;
return true;
}
#if !YYJSON_DISABLE_READER /* reader begin */
/* Check read flag, avoids `always false` warning when disabled. */
#define has_flg(_flg) unlikely(has_rflag(flg, YYJSON_READ_##_flg, 0))
#define has_allow(_flg) unlikely(has_rflag(flg, YYJSON_READ_ALLOW_##_flg, 1))
#define YYJSON_READ_ALLOW_TRIVIA (YYJSON_READ_ALLOW_COMMENTS | \
YYJSON_READ_ALLOW_EXT_WHITESPACE)
static_inline bool has_rflag(yyjson_read_flag flg, yyjson_read_flag chk,
bool non_standard) {
#if YYJSON_DISABLE_NON_STANDARD
if (non_standard) return false;
#endif
return (flg & chk) != 0;
}
/*==============================================================================
* MARK: - JSON Reader Utils (Private)
* These functions are used by JSON reader to read literals and comments.
*============================================================================*/
/** Read `true` literal, `*ptr[0]` should be `t`. */
static_inline bool read_true(u8 **ptr, yyjson_val *val) {
u8 *cur = *ptr;
if (likely(byte_match_4(cur, "true"))) {
val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE;
*ptr = cur + 4;
return true;
}
return false;
}
/** Read `false` literal, `*ptr[0]` should be `f`. */
static_inline bool read_false(u8 **ptr, yyjson_val *val) {
u8 *cur = *ptr;
if (likely(byte_match_4(cur + 1, "alse"))) {
val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE;
*ptr = cur + 5;
return true;
}
return false;
}
/** Read `null` literal, `*ptr[0]` should be `n`. */
static_inline bool read_null(u8 **ptr, yyjson_val *val) {
u8 *cur = *ptr;
if (likely(byte_match_4(cur, "null"))) {
val->tag = YYJSON_TYPE_NULL;
*ptr = cur + 4;
return true;
}
return false;
}
/** Read `Inf` or `Infinity` literal (ignoring case). */
static_inline bool read_inf(u8 **ptr, u8 **pre,
yyjson_read_flag flg, yyjson_val *val) {
u8 *hdr = *ptr;
u8 *cur = *ptr;
u8 **end = ptr;
bool sign = (*cur == '-');
if (*cur == '+' && !has_allow(EXT_NUMBER)) return false;
cur += char_is_sign(*cur);
if (char_to_lower(cur[0]) == 'i' &&
char_to_lower(cur[1]) == 'n' &&
char_to_lower(cur[2]) == 'f') {
if (char_to_lower(cur[3]) == 'i') {
if (char_to_lower(cur[4]) == 'n' &&
char_to_lower(cur[5]) == 'i' &&
char_to_lower(cur[6]) == 't' &&
char_to_lower(cur[7]) == 'y') {
cur += 8;
} else {
return false;
}
} else {
cur += 3;
}
*end = cur;
if (has_flg(NUMBER_AS_RAW)) {
**pre = '\0'; /* add null-terminator for previous raw string */
*pre = cur; /* save end position for current raw string */
val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW;
val->uni.str = (const char *)hdr;
} else {
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL;
val->uni.u64 = f64_bits_inf(sign);
}
return true;
}
return false;
}
/** Read `NaN` literal (ignoring case). */
static_inline bool read_nan(u8 **ptr, u8 **pre,
yyjson_read_flag flg, yyjson_val *val) {
u8 *hdr = *ptr;
u8 *cur = *ptr;
u8 **end = ptr;
bool sign = (*cur == '-');
if (*cur == '+' && !has_allow(EXT_NUMBER)) return false;
cur += char_is_sign(*cur);
if (char_to_lower(cur[0]) == 'n' &&
char_to_lower(cur[1]) == 'a' &&
char_to_lower(cur[2]) == 'n') {
cur += 3;
*end = cur;
if (has_flg(NUMBER_AS_RAW)) {
**pre = '\0'; /* add null-terminator for previous raw string */
*pre = cur; /* save end position for current raw string */
val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW;
val->uni.str = (const char *)hdr;
} else {
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL;
val->uni.u64 = f64_bits_nan(sign);
}
return true;
}
return false;
}
/** Read `Inf`, `Infinity` or `NaN` literal (ignoring case). */
static_inline bool read_inf_or_nan(u8 **ptr, u8 **pre,
yyjson_read_flag flg, yyjson_val *val) {
if (read_inf(ptr, pre, flg, val)) return true;
if (read_nan(ptr, pre, flg, val)) return true;
return false;
}
/** Read a JSON number as raw string. */
static_noinline bool read_num_raw(u8 **ptr, u8 **pre, yyjson_read_flag flg,
yyjson_val *val, const char **msg) {
#define return_err(_pos, _msg) do { \
*msg = _msg; *end = _pos; return false; \
} while (false)
#define return_raw() do { \
val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \
val->uni.str = (const char *)hdr; \
**pre = '\0'; *pre = cur; *end = cur; return true; \
} while (false)
u8 *hdr = *ptr;
u8 *cur = *ptr;
u8 **end = ptr;
/* skip sign */
cur += (*cur == '-');
/* read first digit, check leading zero */
while (unlikely(!char_is_digit(*cur))) {
if (has_allow(EXT_NUMBER)) {
if (*cur == '+' && cur == hdr) { /* leading `+` sign */
cur++;
continue;
}
if (*cur == '.' && char_is_digit(cur[1])) { /* e.g. '.123' */
goto read_double;
}
}
if (has_allow(INF_AND_NAN)) {
if (read_inf_or_nan(ptr, pre, flg, val)) return true;
}
return_err(cur, "no digit after sign");
}
/* read integral part */
if (*cur == '0') {
cur++;
if (unlikely(char_is_digit(*cur))) {
return_err(cur - 1, "number with leading zero is not allowed");
}
if (!char_is_fp(*cur)) {
if (has_allow(EXT_NUMBER) && char_to_lower(*cur) == 'x') { /* hex */
if (!char_is_hex(*++cur)) return_err(cur, "invalid hex number");
while(char_is_hex(*cur)) cur++;
}
return_raw();
}
} else {
while (char_is_digit(*cur)) cur++;
if (!char_is_fp(*cur)) return_raw();
}
read_double:
/* read fraction part */
if (*cur == '.') {
cur++;
if (!char_is_digit(*cur)) {
if (has_allow(EXT_NUMBER)) {
if (!char_is_exp(*cur)) return_raw();
} else {
return_err(cur, "no digit after decimal point");
}
}
while (char_is_digit(*cur)) cur++;
}
/* read exponent part */
if (char_is_exp(*cur)) {
cur += 1 + char_is_sign(cur[1]);
if (!char_is_digit(*cur++)) {
return_err(cur, "no digit after exponent sign");
}
while (char_is_digit(*cur)) cur++;
}
return_raw();
#undef return_err
#undef return_raw
}
/** Read a hex number. */
static_noinline bool read_num_hex(u8 **ptr, u8 **pre, yyjson_read_flag flg,
yyjson_val *val, const char **msg) {
u8 *hdr = *ptr;
u8 *cur = *ptr;
u8 **end = ptr;
u64 sig = 0, i = 0;
bool sign;
/* skip sign and '0x' */
sign = (*cur == '-');
cur += (*cur == '-' || *cur == '+') + 2;
/* read hex */
for(; i < 16; i++) {
u8 c = hex_conv_table[cur[i]];
if (c == 0xF0) break;
sig <<= 4;
sig |= c;
}
/* check error */
if (unlikely(i == 0)) {
*msg = "invalid hex number";
return false;
}
/* check overflow */
if (unlikely(i == 16)) {
if (char_is_hex(cur[16]) || (sign && sig > ((u64)1 << 63))) {
if (!has_flg(BIGNUM_AS_RAW)) {
*msg = "hex number overflow";
return false;
}
cur += 16;
while (char_is_hex(*cur)) cur++;
**pre = '\0';
val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW;
val->uni.str = (const char *)hdr;
*pre = cur; *end = cur;
return true;
}
}
val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3);
val->uni.u64 = (u64)(sign ? (u64)(~(sig) + 1) : (u64)(sig));
*end = cur + i;
return true;
}
/**
Skip trivia (whitespace and comments).
This function should be used only when `char_is_trivia()` returns true.
@param ptr (inout) Input current position, output end position.
@param eof JSON end position.
@param flg JSON read flags.
@return true if at least one character was skipped.
false if no characters were skipped,
or if a multi-line comment is unterminated;
in the latter case, `ptr` will be set to `eof`.
*/
static_noinline bool skip_trivia(u8 **ptr, u8 *eof, yyjson_read_flag flg) {
u8 *hdr = *ptr, *cur = *ptr;
usize len;
while (cur < eof) {
u8 *loop_begin = cur;
/* skip standard whitespace */
while(char_is_space(*cur)) cur++;
/* skip extended whitespace */
if (has_allow(EXT_WHITESPACE)) {
while (char_is_space_ext(*cur)) {
cur += (len = ext_space_len(cur));
if (!len) break;
}
}
/* skip comment, do not validate encoding */
if (has_allow(COMMENTS) && cur[0] == '/') {
if (cur[1] == '/') { /* single-line comment */
cur += 2;
if (has_allow(EXT_WHITESPACE)) {
while (cur < eof) {
if (char_is_eol_ext(*cur)) {
cur += (len = ext_eol_len(cur));
if (len) break;
}
cur++;
}
} else {
while (cur < eof && !char_is_eol(*cur)) cur++;
}
} else if (cur[1] == '*') { /* multi-line comment */
cur += 2;
while (!byte_match_2(cur, "*/") && cur < eof) cur++;
if (cur == eof) {
*ptr = eof;
return false; /* unclosed comment */
}
cur += 2;
}
}
if (cur == loop_begin) break;
}
*ptr = cur;
return cur > hdr;
}
/**
Check truncated UTF-8 character.
Return true if `cur` starts a valid UTF-8 sequence that is truncated.
*/
static bool is_truncated_utf8(u8 *cur, u8 *eof) {
u8 c0, c1, c2;
usize len = (usize)(eof - cur);
if (cur >= eof || len >= 4) return false;
c0 = cur[0]; c1 = cur[1]; c2 = cur[2];
/* 1-byte UTF-8, not truncated */
if (c0 < 0x80) return false;
if (len == 1) {
/* 2-byte UTF-8, truncated */
if ((c0 & 0xE0) == 0xC0 && (c0 & 0x1E) != 0x00) return true;
/* 3-byte UTF-8, truncated */
if ((c0 & 0xF0) == 0xE0) return true;
/* 4-byte UTF-8, truncated */
if ((c0 & 0xF8) == 0xF0 && (c0 & 0x07) <= 0x04) return true;
} else if (len == 2) {
/* 3-byte UTF-8, truncated */
if ((c0 & 0xF0) == 0xE0 && (c1 & 0xC0) == 0x80) {
u8 t = (u8)(((c0 & 0x0F) << 1) | ((c1 & 0x20) >> 5));
return 0x01 <= t && t != 0x1B;
}
/* 4-byte UTF-8, truncated */
if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80) {
u8 t = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4));
return 0x01 <= t && t <= 0x10;
}
} else if (len == 3) {
/* 4 bytes UTF-8, truncated */
if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80) {
u8 t = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4));
return 0x01 <= t && t <= 0x10;
}
}
return false;
}
/**
Check truncated string.
Returns true if `cur` match `str` but is truncated.
The `str` should be lowercase ASCII letters.
*/
static bool is_truncated_str(u8 *cur, u8 *eof, const char *str,
bool case_sensitive) {
usize len = strlen(str);
if (cur + len <= eof || eof <= cur) return false;
if (case_sensitive) {
return memcmp(cur, str, (usize)(eof - cur)) == 0;
}
for (; cur < eof; cur++, str++) {
if (char_to_lower(*cur) != *(const u8 *)str) return false;
}
return true;
}
/**
Check truncated JSON on parsing errors.
Returns true if the input is valid but truncated.
*/
static_noinline bool is_truncated_end(u8 *hdr, u8 *cur, u8 *eof,
yyjson_read_code code,
yyjson_read_flag flg) {
if (cur >= eof) return true;
if (code == YYJSON_READ_ERROR_LITERAL) {
if (is_truncated_str(cur, eof, "true", true) ||
is_truncated_str(cur, eof, "false", true) ||
is_truncated_str(cur, eof, "null", true)) {
return true;
}
}
if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER ||
code == YYJSON_READ_ERROR_INVALID_NUMBER ||
code == YYJSON_READ_ERROR_LITERAL) {
if (has_allow(INF_AND_NAN)) {
if (*cur == '-') cur++;
if (is_truncated_str(cur, eof, "infinity", false) ||
is_truncated_str(cur, eof, "nan", false)) {
return true;
}
}
}
if (code == YYJSON_READ_ERROR_UNEXPECTED_CONTENT) {
if (has_allow(INF_AND_NAN)) {
if (hdr + 3 <= cur &&
is_truncated_str(cur - 3, eof, "infinity", false)) {
return true; /* e.g. infin would be read as inf + in */
}
}
}
if (code == YYJSON_READ_ERROR_INVALID_STRING) {
usize len = (usize)(eof - cur);
/* unicode escape sequence */
if (*cur == '\\') {
if (len == 1) return true;
if (len <= 5) {
if (*++cur != 'u') return false;
for (++cur; cur < eof; cur++) {
if (!char_is_hex(*cur)) return false;
}
return true;
} else if (len <= 11) {
/* incomplete surrogate pair? */
u16 hi;
if (*++cur != 'u') return false;
if (!hex_load_4(++cur, &hi)) return false;
if ((hi & 0xF800) != 0xD800) return false;
cur += 4;
if (cur >= eof) return true;
/* valid low surrogate is DC00...DFFF */
if (*cur != '\\') return false;
if (++cur >= eof) return true;
if (*cur != 'u') return false;
if (++cur >= eof) return true;
if (*cur != 'd' && *cur != 'D') return false;
if (++cur >= eof) return true;
if ((*cur < 'c' || *cur > 'f') && (*cur < 'C' || *cur > 'F'))
return false;
if (++cur >= eof) return true;
if (!char_is_hex(*cur)) return false;
return true;
}
return false;
}
/* 2 to 4 bytes UTF-8 */
if (is_truncated_utf8(cur, eof)) {
return true;
}
}
if (has_allow(COMMENTS)) {
if (code == YYJSON_READ_ERROR_INVALID_COMMENT) {
/* unclosed multiline comment */
return true;
}
if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER &&
*cur == '/' && cur + 1 == eof) {
/* truncated beginning of comment */
return true;
}
}
if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER &&
has_allow(BOM)) {
/* truncated UTF-8 BOM */
usize len = (usize)(eof - cur);
if (cur == hdr && len < 3 && !memcmp(hdr, "\xEF\xBB\xBF", len)) {
return true;
}
}
return false;
}
#if !YYJSON_DISABLE_FAST_FP_CONV /* FP_READER */
/*==============================================================================
* MARK: - BigInt For Floating Point Number Reader (Private)
*
* The bigint algorithm is used by floating-point number reader to get correctly
* rounded result for numbers with lots of digits. This part of code is rarely
* used for common numbers.
*============================================================================*/
/** Unsigned arbitrarily large integer */
typedef struct bigint {
u32 used; /* used chunks count, should not be 0 */
u64 bits[64]; /* chunks (58 is enough here) */
} bigint;
/**
Evaluate 'big += val'.
@param big A big number (can be 0).
@param val An unsigned integer (can be 0).
*/
static_inline void bigint_add_u64(bigint *big, u64 val) {
u32 idx, max;
u64 num = big->bits[0];
u64 add = num + val;
big->bits[0] = add;
if (likely((add >= num) || (add >= val))) return;
for ((void)(idx = 1), max = big->used; idx < max; idx++) {
if (likely(big->bits[idx] != U64_MAX)) {
big->bits[idx] += 1;
return;
}
big->bits[idx] = 0;
}
big->bits[big->used++] = 1;
}
/**
Evaluate 'big *= val'.
@param big A big number (can be 0).
@param val An unsigned integer (cannot be 0).
*/
static_inline void bigint_mul_u64(bigint *big, u64 val) {
u32 idx = 0, max = big->used;
u64 hi, lo, carry = 0;
for (; idx < max; idx++) {
if (big->bits[idx]) break;
}
for (; idx < max; idx++) {
u128_mul_add(big->bits[idx], val, carry, &hi, &lo);
big->bits[idx] = lo;
carry = hi;
}
if (carry) big->bits[big->used++] = carry;
}
/**
Evaluate 'big *= 2^exp'.
@param big A big number (can be 0).
@param exp An exponent integer (can be 0).
*/
static_inline void bigint_mul_pow2(bigint *big, u32 exp) {
u32 shft = exp % 64;
u32 move = exp / 64;
u32 idx = big->used;
if (unlikely(shft == 0)) {
for (; idx > 0; idx--) {
big->bits[idx + move - 1] = big->bits[idx - 1];
}
big->used += move;
while (move) big->bits[--move] = 0;
} else {
big->bits[idx] = 0;
for (; idx > 0; idx--) {
u64 num = big->bits[idx] << shft;
num |= big->bits[idx - 1] >> (64 - shft);
big->bits[idx + move] = num;
}
big->bits[move] = big->bits[0] << shft;
big->used += move + (big->bits[big->used + move] > 0);
while (move) big->bits[--move] = 0;
}
}
/**
Evaluate 'big *= 10^exp'.
@param big A big number (can be 0).
@param exp An exponent integer (cannot be 0).
*/
static_inline void bigint_mul_pow10(bigint *big, i32 exp) {
for (; exp >= U64_POW10_MAX_EXACT_EXP; exp -= U64_POW10_MAX_EXACT_EXP) {
bigint_mul_u64(big, u64_pow10_table[U64_POW10_MAX_EXACT_EXP]);
}
if (exp) {
bigint_mul_u64(big, u64_pow10_table[exp]);
}
}
/**
Compare two bigint.
@return -1 if 'a < b', +1 if 'a > b', 0 if 'a == b'.
*/
static_inline i32 bigint_cmp(bigint *a, bigint *b) {
u32 idx = a->used;
if (a->used < b->used) return -1;
if (a->used > b->used) return +1;
while (idx-- > 0) {
u64 av = a->bits[idx];
u64 bv = b->bits[idx];
if (av < bv) return -1;
if (av > bv) return +1;
}
return 0;
}
/**
Evaluate 'big = val'.
@param big A big number (can be 0).
@param val An unsigned integer (can be 0).
*/
static_inline void bigint_set_u64(bigint *big, u64 val) {
big->used = 1;
big->bits[0] = val;
}
/** Set a bigint with floating point number string. */
static_noinline void bigint_set_buf(bigint *big, u64 sig, i32 *exp,
u8 *sig_cut, u8 *sig_end, u8 *dot_pos) {
if (unlikely(!sig_cut)) {
/* no digit cut, set significant part only */
bigint_set_u64(big, sig);
return;
} else {
/* some digits were cut, read them from 'sig_cut' to 'sig_end' */
u8 *hdr = sig_cut;
u8 *cur = hdr;
u32 len = 0;
u64 val = 0;
bool dig_big_cut = false;
bool has_dot = (hdr < dot_pos) & (dot_pos < sig_end);
u32 dig_len_total = U64_SAFE_DIG + (u32)(sig_end - hdr) - has_dot;
sig -= (*sig_cut >= '5'); /* sig was rounded before */
if (dig_len_total > F64_MAX_DEC_DIG) {
dig_big_cut = true;
sig_end -= dig_len_total - (F64_MAX_DEC_DIG + 1);
sig_end -= (dot_pos + 1 == sig_end);
dig_len_total = (F64_MAX_DEC_DIG + 1);
}
*exp -= (i32)dig_len_total - U64_SAFE_DIG;
big->used = 1;
big->bits[0] = sig;
while (cur < sig_end) {
if (likely(cur != dot_pos)) {
val = val * 10 + (u8)(*cur++ - '0');
len++;
if (unlikely(cur == sig_end && dig_big_cut)) {
/* The last digit must be non-zero, */
/* set it to '1' for correct rounding. */
val = val - (val % 10) + 1;
}
if (len == U64_SAFE_DIG || cur == sig_end) {
bigint_mul_pow10(big, (i32)len);
bigint_add_u64(big, val);
val = 0;
len = 0;
}
} else {
cur++;
}
}
}
}
/*==============================================================================
* MARK: - Diy Floating Point (Private)
*============================================================================*/
/** "Do It Yourself Floating Point" struct. */
typedef struct diy_fp {
u64 sig; /* significand */
i32 exp; /* exponent, base 2 */
i32 pad; /* padding, useless */
} diy_fp;
/** Get cached rounded diy_fp with pow(10, e) The input value must in range
[POW10_SIG_TABLE_MIN_EXP, POW10_SIG_TABLE_MAX_EXP]. */
static_inline diy_fp diy_fp_get_cached_pow10(i32 exp10) {
diy_fp fp;
u64 sig_ext;
pow10_table_get_sig(exp10, &fp.sig, &sig_ext);
pow10_table_get_exp(exp10, &fp.exp);
fp.sig += (sig_ext >> 63);
return fp;
}
/** Returns fp * fp2. */
static_inline diy_fp diy_fp_mul(diy_fp fp, diy_fp fp2) {
u64 hi, lo;
u128_mul(fp.sig, fp2.sig, &hi, &lo);
fp.sig = hi + (lo >> 63);
fp.exp += fp2.exp + 64;
return fp;
}
/** Convert diy_fp to IEEE-754 raw value. */
static_inline u64 diy_fp_to_ieee_raw(diy_fp fp) {
u64 sig = fp.sig;
i32 exp = fp.exp;
u32 lz_bits;
if (unlikely(fp.sig == 0)) return 0;
lz_bits = u64_lz_bits(sig);
sig <<= lz_bits;
sig >>= F64_BITS - F64_SIG_FULL_BITS;
exp -= (i32)lz_bits;
exp += F64_BITS - F64_SIG_FULL_BITS;
exp += F64_SIG_BITS;
if (unlikely(exp >= F64_MAX_BIN_EXP)) {
/* overflow */
return F64_BITS_INF;
} else if (likely(exp >= F64_MIN_BIN_EXP - 1)) {
/* normal */
exp += F64_EXP_BIAS;
return ((u64)exp << F64_SIG_BITS) | (sig & F64_SIG_MASK);
} else if (likely(exp >= F64_MIN_BIN_EXP - F64_SIG_FULL_BITS)) {
/* subnormal */
return sig >> (F64_MIN_BIN_EXP - exp - 1);
} else {
/* underflow */
return 0;
}
}
/*==============================================================================
* MARK: - Number Reader (Private)
*============================================================================*/
/**
Read a JSON number.
1. This function assume that the floating-point number is in IEEE-754 format.
2. This function support uint64/int64/double number. If an integer number
cannot fit in uint64/int64, it will returns as a double number. If a double
number is infinite, the return value is based on flag.
3. This function (with inline attribute) may generate a lot of instructions.
*/
static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg,
yyjson_val *val, const char **msg) {
#define return_err(_pos, _msg) do { \
*msg = _msg; \
*end = _pos; \
return false; \
} while (false)
#define return_0() do { \
val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \
val->uni.u64 = 0; \
*end = cur; return true; \
} while (false)
#define return_i64(_v) do { \
val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \
val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \
*end = cur; return true; \
} while (false)
#define return_f64(_v) do { \
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \
val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \
*end = cur; return true; \
} while (false)
#define return_f64_bin(_v) do { \
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \
val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \
*end = cur; return true; \
} while (false)
#define return_inf() do { \
if (has_flg(BIGNUM_AS_RAW)) return_raw(); \
if (has_allow(INF_AND_NAN)) return_f64_bin(F64_BITS_INF); \
else return_err(hdr, "number is infinity when parsed as double"); \
} while (false)
#define return_raw() do { \
**pre = '\0'; /* add null-terminator for previous raw string */ \
val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \
val->uni.str = (const char *)hdr; \
*pre = cur; *end = cur; return true; \
} while (false)
u8 *sig_cut = NULL; /* significant part cutting position for long number */
u8 *sig_end = NULL; /* significant part ending position */
u8 *dot_pos = NULL; /* decimal point position */
u64 sig = 0; /* significant part of the number */
i32 exp = 0; /* exponent part of the number */
bool exp_sign; /* temporary exponent sign from literal part */
i64 exp_sig = 0; /* temporary exponent number from significant part */
i64 exp_lit = 0; /* temporary exponent number from exponent literal part */
u64 num; /* temporary number for reading */
u8 *tmp; /* temporary cursor for reading */
u8 *hdr = *ptr;
u8 *cur = *ptr;
u8 **end = ptr;
bool sign;
/* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */
if (has_flg(NUMBER_AS_RAW)) {
return read_num_raw(ptr, pre, flg, val, msg);
}
sign = (*hdr == '-');
cur += sign;
/* begin with a leading zero or non-digit */
while (unlikely(!char_is_nonzero(*cur))) { /* 0 or non-digit char */
if (unlikely(*cur != '0')) { /* non-digit char */
if (has_allow(EXT_NUMBER)) {
if (*cur == '+' && cur == hdr) { /* leading `+` sign */
cur++;
continue;
}
if (*cur == '.' && char_is_digit(cur[1])) { /* e.g. '.123' */
goto leading_dot;
}
}
if (has_allow(INF_AND_NAN)) {
if (read_inf_or_nan(ptr, pre, flg, val)) return true;
}
return_err(cur, "no digit after sign");
}
/* begin with 0 */
if (likely(!char_is_digit_or_fp(*++cur))) {
if (has_allow(EXT_NUMBER) && char_to_lower(*cur) == 'x') { /* hex */
return read_num_hex(ptr, pre, flg, val, msg);
}
return_0();
}
if (likely(*cur == '.')) {
leading_dot:
dot_pos = cur++;
if (unlikely(!char_is_digit(*cur))) {
if (has_allow(EXT_NUMBER)) {
if (char_is_exp(*cur)) {
goto digi_exp_more;
} else {
return_f64_bin(0);
}
}
return_err(cur, "no digit after decimal point");
}
while (unlikely(*cur == '0')) cur++;
if (likely(char_is_digit(*cur))) {
/* first non-zero digit after decimal point */
sig = (u64)(*cur - '0'); /* read first digit */
cur--;
goto digi_frac_1; /* continue read fraction part */
}
}
if (unlikely(char_is_digit(*cur))) {
return_err(cur - 1, "number with leading zero is not allowed");
}
if (unlikely(char_is_exp(*cur))) { /* 0 with any exponent is still 0 */
cur += (usize)1 + char_is_sign(cur[1]);
if (unlikely(!char_is_digit(*cur))) {
return_err(cur, "no digit after exponent sign");
}
while (char_is_digit(*++cur));
}
return_f64_bin(0);
}
/* begin with non-zero digit */
sig = (u64)(*cur - '0');
/*
Read integral part, same as the following code.
for (int i = 1; i <= 18; i++) {
num = cur[i] - '0';
if (num <= 9) sig = num + sig * 10;
else goto digi_sepr_i;
}
*/
#define expr_intg(i) \
if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \
else { goto digi_sepr_##i; }
repeat_in_1_18(expr_intg)
#undef expr_intg
cur += 19; /* skip continuous 19 digits */
if (!char_is_digit_or_fp(*cur)) {
/* this number is an integer consisting of 19 digits */
if (sign && (sig > ((u64)1 << 63))) { /* overflow */
if (has_flg(BIGNUM_AS_RAW)) return_raw();
return_f64(unsafe_yyjson_u64_to_f64(sig));
}
return_i64(sig);
}
goto digi_intg_more; /* read more digits in integral part */
/* process first non-digit character */
#define expr_sepr(i) \
digi_sepr_##i: \
if (likely(!char_is_fp(cur[i]))) { cur += i; return_i64(sig); } \
dot_pos = cur + i; \
if (likely(cur[i] == '.')) goto digi_frac_##i; \
cur += i; sig_end = cur; goto digi_exp_more;
repeat_in_1_18(expr_sepr)
#undef expr_sepr
/* read fraction part */
#define expr_frac(i) \
digi_frac_##i: \
if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \
sig = num + sig * 10; \
else { goto digi_stop_##i; }
repeat_in_1_18(expr_frac)
#undef expr_frac
cur += 20; /* skip 19 digits and 1 decimal point */
if (!char_is_digit(*cur)) goto digi_frac_end; /* fraction part end */
goto digi_frac_more; /* read more digits in fraction part */
/* significant part end */
#define expr_stop(i) \
digi_stop_##i: \
cur += i + 1; \
goto digi_frac_end;
repeat_in_1_18(expr_stop)
#undef expr_stop
/* read more digits in integral part */
digi_intg_more:
if (char_is_digit(*cur)) {
if (!char_is_digit_or_fp(cur[1])) {
/* this number is an integer consisting of 20 digits */
num = (u64)(*cur - '0');
if ((sig < (U64_MAX / 10)) ||
(sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) {
sig = num + sig * 10;
cur++;
/* convert to double if overflow */
if (sign) {
if (has_flg(BIGNUM_AS_RAW)) return_raw();
return_f64(unsafe_yyjson_u64_to_f64(sig));
}
return_i64(sig);
}
}
}
if (char_is_exp(*cur)) {
dot_pos = cur;
goto digi_exp_more;
}
if (*cur == '.') {
dot_pos = cur++;
if (unlikely(!char_is_digit(*cur))) {
if (has_allow(EXT_NUMBER)) {
goto digi_frac_end;
}
return_err(cur, "no digit after decimal point");
}
}
/* read more digits in fraction part */
digi_frac_more:
sig_cut = cur; /* too large to fit in u64, excess digits need to be cut */
sig += (*cur >= '5'); /* round */
while (char_is_digit(*++cur));
if (!dot_pos) {
if (!char_is_fp(*cur) && has_flg(BIGNUM_AS_RAW)) {
return_raw(); /* it's a large integer */
}
dot_pos = cur;
if (*cur == '.') {
if (unlikely(!char_is_digit(*++cur))) {
if (!has_allow(EXT_NUMBER)) {
return_err(cur, "no digit after decimal point");
}
}
while (char_is_digit(*cur)) cur++;
}
}
exp_sig = (i64)(dot_pos - sig_cut);
exp_sig += (dot_pos < sig_cut);
/* ignore trailing zeros */
tmp = cur - 1;
while ((*tmp == '0' || *tmp == '.') && tmp > hdr) tmp--;
if (tmp < sig_cut) {
sig_cut = NULL;
} else {
sig_end = cur;
}
if (char_is_exp(*cur)) goto digi_exp_more;
goto digi_exp_finish;
/* fraction part end */
digi_frac_end:
if (unlikely(dot_pos + 1 == cur)) {
if (!has_allow(EXT_NUMBER)) {
return_err(cur, "no digit after decimal point");
}
}
sig_end = cur;
exp_sig = -(i64)((u64)(cur - dot_pos) - 1);
if (likely(!char_is_exp(*cur))) {
if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) {
return_f64_bin(0); /* underflow */
}
exp = (i32)exp_sig;
goto digi_finish;
} else {
goto digi_exp_more;
}
/* read exponent part */
digi_exp_more:
exp_sign = (*++cur == '-');
cur += char_is_sign(*cur);
if (unlikely(!char_is_digit(*cur))) {
return_err(cur, "no digit after exponent sign");
}
while (*cur == '0') cur++;
/* read exponent literal */
tmp = cur;
while (char_is_digit(*cur)) {
exp_lit = (i64)((u8)(*cur++ - '0') + (u64)exp_lit * 10);
}
if (unlikely(cur - tmp >= U64_SAFE_DIG)) {
if (exp_sign) {
return_f64_bin(0); /* underflow */
} else {
return_inf(); /* overflow */
}
}
exp_sig += exp_sign ? -exp_lit : exp_lit;
/* validate exponent value */
digi_exp_finish:
if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) {
return_f64_bin(0); /* underflow */
}
if (unlikely(exp_sig > F64_MAX_DEC_EXP)) {
return_inf(); /* overflow */
}
exp = (i32)exp_sig;
/* all digit read finished */
digi_finish:
/*
Fast path 1:
1. The floating-point number calculation should be accurate, see the
comments of macro `YYJSON_DOUBLE_MATH_CORRECT`.
2. Correct rounding should be performed (fegetround() == FE_TONEAREST).
3. The input of floating point number calculation does not lose precision,
which means: 64 - leading_zero(input) - trailing_zero(input) < 53.
We don't check all available inputs here, because that would make the code
more complicated, and not friendly to branch predictor.
*/
#if YYJSON_DOUBLE_MATH_CORRECT
if (sig < ((u64)1 << 53) &&
exp >= -F64_POW10_MAX_EXACT_EXP &&
exp <= +F64_POW10_MAX_EXACT_EXP) {
f64 dbl = (f64)sig;
if (exp < 0) {
dbl /= f64_pow10_table[-exp];
} else {
dbl *= f64_pow10_table[+exp];
}
return_f64(dbl);
}
#endif
/*
Fast path 2:
To keep it simple, we only accept normal number here,
let the slow path to handle subnormal and infinity number.
*/
if (likely(!sig_cut &&
exp > -F64_MAX_DEC_EXP + 1 &&
exp < +F64_MAX_DEC_EXP - 20)) {
/*
The result value is exactly equal to (sig * 10^exp),
the exponent part (10^exp) can be converted to (sig2 * 2^exp2).
The sig2 can be an infinite length number, only the highest 128 bits
is cached in the pow10_sig_table.
Now we have these bits:
sig1 (normalized 64bit) : aaaaaaaa
sig2 (higher 64bit) : bbbbbbbb
sig2_ext (lower 64bit) : cccccccc
sig2_cut (extra unknown bits) : dddddddddddd....
And the calculation process is:
----------------------------------------
aaaaaaaa *
bbbbbbbbccccccccdddddddddddd....
----------------------------------------
abababababababab +
acacacacacacacac +
adadadadadadadadadad....
----------------------------------------
[hi____][lo____] +
[hi2___][lo2___] +
[unknown___________....]
----------------------------------------
The addition with carry may affect higher bits, but if there is a 0
in higher bits, the bits higher than 0 will not be affected.
`lo2` + `unknown` may get a carry bit and may affect `hi2`, the max
value of `hi2` is 0xFFFFFFFFFFFFFFFE, so `hi2` will not overflow.
`lo` + `hi2` may also get a carry bit and may affect `hi`, but only
the highest significant 53 bits of `hi` is needed. If there is a 0
in the lower bits of `hi`, then all the following bits can be dropped.
To convert the result to IEEE-754 double number, we need to perform
correct rounding:
1. if bit 54 is 0, round down,
2. if bit 54 is 1 and any bit beyond bit 54 is 1, round up,
3. if bit 54 is 1 and all bits beyond bit 54 are 0, round to even,
as the extra bits is unknown, this case will not be handled here.
*/
u64 raw;
u64 sig1, sig2, sig2_ext, hi, lo, hi2, lo2, add, bits;
i32 exp2;
u32 lz;
bool exact = false, carry, round_up;
/* convert (10^exp) to (sig2 * 2^exp2) */
pow10_table_get_sig(exp, &sig2, &sig2_ext);
pow10_table_get_exp(exp, &exp2);
/* normalize and multiply */
lz = u64_lz_bits(sig);
sig1 = sig << lz;
exp2 -= (i32)lz;
u128_mul(sig1, sig2, &hi, &lo);
/*
The `hi` is in range [0x4000000000000000, 0xFFFFFFFFFFFFFFFE],
To get normalized value, `hi` should be shifted to the left by 0 or 1.
The highest significant 53 bits is used by IEEE-754 double number,
and the bit 54 is used to detect rounding direction.
The lowest (64 - 54 - 1) bits is used to check whether it contains 0.
*/
bits = hi & (((u64)1 << (64 - 54 - 1)) - 1);
if (bits - 1 < (((u64)1 << (64 - 54 - 1)) - 2)) {
/*
(bits != 0 && bits != 0x1FF) => (bits - 1 < 0x1FF - 1)
The `bits` is not zero, so we don't need to check `round to even`
case. The `bits` contains bit `0`, so we can drop the extra bits
after `0`.
*/
exact = true;
} else {
/*
(bits == 0 || bits == 0x1FF)
The `bits` is filled with all `0` or all `1`, so we need to check
lower bits with another 64-bit multiplication.
*/
u128_mul(sig1, sig2_ext, &hi2, &lo2);
add = lo + hi2;
if (add + 1 > (u64)1) {
/*
(add != 0 && add != U64_MAX) => (add + 1 > 1)
The `add` is not zero, so we don't need to check `round to
even` case. The `add` contains bit `0`, so we can drop the
extra bits after `0`. The `hi` cannot be U64_MAX, so it will
not overflow.
*/
carry = add < lo || add < hi2;
hi += carry;
exact = true;
}
}
if (exact) {
/* normalize */
lz = hi < ((u64)1 << 63);
hi <<= lz;
exp2 -= (i32)lz;
exp2 += 64;
/* test the bit 54 and get rounding direction */
round_up = (hi & ((u64)1 << (64 - 54))) > (u64)0;
hi += (round_up ? ((u64)1 << (64 - 54)) : (u64)0);
/* test overflow */
if (hi < ((u64)1 << (64 - 54))) {
hi = ((u64)1 << 63);
exp2 += 1;
}
/* This is a normal number, convert it to IEEE-754 format. */
hi >>= F64_BITS - F64_SIG_FULL_BITS;
exp2 += F64_BITS - F64_SIG_FULL_BITS + F64_SIG_BITS;
exp2 += F64_EXP_BIAS;
raw = ((u64)exp2 << F64_SIG_BITS) | (hi & F64_SIG_MASK);
return_f64_bin(raw);
}
}
/*
Slow path: read double number exactly with diyfp.
1. Use cached diyfp to get an approximation value.
2. Use bigcomp to check the approximation value if needed.
This algorithm refers to google's double-conversion project:
https://github.com/google/double-conversion
*/
{
const i32 ERR_ULP_LOG = 3;
const i32 ERR_ULP = 1 << ERR_ULP_LOG;
const i32 ERR_CACHED_POW = ERR_ULP / 2;
const i32 ERR_MUL_FIXED = ERR_ULP / 2;
const i32 DIY_SIG_BITS = 64;
const i32 EXP_BIAS = F64_EXP_BIAS + F64_SIG_BITS;
const i32 EXP_SUBNORMAL = -EXP_BIAS + 1;
u64 fp_err;
u32 bits;
i32 order_of_magnitude;
i32 effective_significand_size;
i32 precision_digits_count;
u64 precision_bits;
u64 half_way;
u64 raw;
diy_fp fp, fp_upper;
bigint big_full, big_comp;
i32 cmp;
fp.sig = sig;
fp.exp = 0;
fp_err = sig_cut ? (u64)(ERR_ULP / 2) : (u64)0;
/* normalize */
bits = u64_lz_bits(fp.sig);
fp.sig <<= bits;
fp.exp -= (i32)bits;
fp_err <<= bits;
/* multiply and add error */
fp = diy_fp_mul(fp, diy_fp_get_cached_pow10(exp));
fp_err += (u64)ERR_CACHED_POW + (fp_err != 0) + (u64)ERR_MUL_FIXED;
/* normalize */
bits = u64_lz_bits(fp.sig);
fp.sig <<= bits;
fp.exp -= (i32)bits;
fp_err <<= bits;
/* effective significand */
order_of_magnitude = DIY_SIG_BITS + fp.exp;
if (likely(order_of_magnitude >= EXP_SUBNORMAL + F64_SIG_FULL_BITS)) {
effective_significand_size = F64_SIG_FULL_BITS;
} else if (order_of_magnitude <= EXP_SUBNORMAL) {
effective_significand_size = 0;
} else {
effective_significand_size = order_of_magnitude - EXP_SUBNORMAL;
}
/* precision digits count */
precision_digits_count = DIY_SIG_BITS - effective_significand_size;
if (unlikely(precision_digits_count + ERR_ULP_LOG >= DIY_SIG_BITS)) {
i32 shr = (precision_digits_count + ERR_ULP_LOG) - DIY_SIG_BITS + 1;
fp.sig >>= shr;
fp.exp += shr;
fp_err = (fp_err >> shr) + 1 + (u32)ERR_ULP;
precision_digits_count -= shr;
}
/* half way */
precision_bits = fp.sig & (((u64)1 << precision_digits_count) - 1);
precision_bits *= (u32)ERR_ULP;
half_way = (u64)1 << (precision_digits_count - 1);
half_way *= (u32)ERR_ULP;
/* rounding */
fp.sig >>= precision_digits_count;
fp.sig += (precision_bits >= half_way + fp_err);
fp.exp += precision_digits_count;
/* get IEEE double raw value */
raw = diy_fp_to_ieee_raw(fp);
if (unlikely(raw == F64_BITS_INF)) return_inf();
if (likely(precision_bits <= half_way - fp_err ||
precision_bits >= half_way + fp_err)) {
return_f64_bin(raw); /* number is accurate */
}
/* now the number is the correct value, or the next lower value */
/* upper boundary */
if (raw & F64_EXP_MASK) {
fp_upper.sig = (raw & F64_SIG_MASK) + ((u64)1 << F64_SIG_BITS);
fp_upper.exp = (i32)((raw & F64_EXP_MASK) >> F64_SIG_BITS);
} else {
fp_upper.sig = (raw & F64_SIG_MASK);
fp_upper.exp = 1;
}
fp_upper.exp -= F64_EXP_BIAS + F64_SIG_BITS;
fp_upper.sig <<= 1;
fp_upper.exp -= 1;
fp_upper.sig += 1; /* add half ulp */
/* compare with bigint */
bigint_set_buf(&big_full, sig, &exp, sig_cut, sig_end, dot_pos);
bigint_set_u64(&big_comp, fp_upper.sig);
if (exp >= 0) {
bigint_mul_pow10(&big_full, +exp);
} else {
bigint_mul_pow10(&big_comp, -exp);
}
if (fp_upper.exp > 0) {
bigint_mul_pow2(&big_comp, (u32)+fp_upper.exp);
} else {
bigint_mul_pow2(&big_full, (u32)-fp_upper.exp);
}
cmp = bigint_cmp(&big_full, &big_comp);
if (likely(cmp != 0)) {
/* round down or round up */
raw += (cmp > 0);
} else {
/* falls midway, round to even */
raw += (raw & 1);
}
if (unlikely(raw == F64_BITS_INF)) return_inf();
return_f64_bin(raw);
}
#undef return_err
#undef return_inf
#undef return_0
#undef return_i64
#undef return_f64
#undef return_f64_bin
#undef return_raw
}
#else /* FP_READER */
/**
Read a JSON number.
This is a fallback function if the custom number reader is disabled.
This function use libc's strtod() to read floating-point number.
*/
static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg,
yyjson_val *val, const char **msg) {
#define return_err(_pos, _msg) do { \
*msg = _msg; \
*end = _pos; \
return false; \
} while (false)
#define return_0() do { \
val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \
val->uni.u64 = 0; \
*end = cur; return true; \
} while (false)
#define return_i64(_v) do { \
val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \
val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \
*end = cur; return true; \
} while (false)
#define return_f64(_v) do { \
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \
val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \
*end = cur; return true; \
} while (false)
#define return_f64_bin(_v) do { \
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \
val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \
*end = cur; return true; \
} while (false)
#define return_inf() do { \
if (has_flg(BIGNUM_AS_RAW)) return_raw(); \
if (has_allow(INF_AND_NAN)) return_f64_bin(F64_BITS_INF); \
else return_err(hdr, "number is infinity when parsed as double"); \
} while (false)
#define return_raw() do { \
val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \
val->uni.str = (const char *)hdr; \
**pre = '\0'; *pre = cur; *end = cur; return true; \
} while (false)
u64 sig, num;
u8 *hdr = *ptr;
u8 *cur = *ptr;
u8 **end = ptr;
u8 *dot = NULL;
u8 *f64_end = NULL;
bool sign;
/* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */
if (has_flg(NUMBER_AS_RAW)) {
return read_num_raw(ptr, pre, flg, val, msg);
}
sign = (*hdr == '-');
cur += sign;
sig = (u8)(*cur - '0');
/* read first digit, check leading zero */
while (unlikely(!char_is_digit(*cur))) {
if (has_allow(EXT_NUMBER)) {
if (*cur == '+' && cur == hdr) { /* leading `+` sign */
cur++;
sig = (u8)(*cur - '0');
continue;
}
if (*cur == '.' && char_is_num(cur[1])) { /* no integer part */
goto read_double; /* e.g. '.123' */
}
}
if (has_allow(INF_AND_NAN)) {
if (read_inf_or_nan(ptr, pre, flg, val)) return true;
}
return_err(cur, "no digit after sign");
}
if (*cur == '0') {
cur++;
if (unlikely(char_is_digit(*cur))) {
return_err(cur - 1, "number with leading zero is not allowed");
}
if (!char_is_fp(*cur)) {
if (has_allow(EXT_NUMBER) &&
(*cur == 'x' || *cur == 'X')) { /* hex integer */
return read_num_hex(ptr, pre, flg, val, msg);
}
return_0();
}
goto read_double;
}
/* read continuous digits, up to 19 characters */
#define expr_intg(i) \
if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \
else { cur += i; goto intg_end; }
repeat_in_1_18(expr_intg)
#undef expr_intg
/* here are 19 continuous digits, skip them */
cur += 19;
if (char_is_digit(cur[0]) && !char_is_digit_or_fp(cur[1])) {
/* this number is an integer consisting of 20 digits */
num = (u8)(*cur - '0');
if ((sig < (U64_MAX / 10)) ||
(sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) {
sig = num + sig * 10;
cur++;
if (sign) {
if (has_flg(BIGNUM_AS_RAW)) return_raw();
return_f64(unsafe_yyjson_u64_to_f64(sig));
}
return_i64(sig);
}
}
intg_end:
/* continuous digits ended */
if (!char_is_digit_or_fp(*cur)) {
/* this number is an integer consisting of 1 to 19 digits */
if (sign && (sig > ((u64)1 << 63))) {
if (has_flg(BIGNUM_AS_RAW)) return_raw();
return_f64(unsafe_yyjson_u64_to_f64(sig));
}
return_i64(sig);
}
read_double:
/* this number should be read as double */
while (char_is_digit(*cur)) cur++;
if (!char_is_fp(*cur) && has_flg(BIGNUM_AS_RAW)) {
return_raw(); /* it's a large integer */
}
while (*cur == '.') {
/* skip fraction part */
dot = cur;
cur++;
if (!char_is_digit(*cur)) {
if (has_allow(EXT_NUMBER)) {
break;
} else {
return_err(cur, "no digit after decimal point");
}
}
cur++;
while (char_is_digit(*cur)) cur++;
break;
}
if (char_is_exp(*cur)) {
/* skip exponent part */
cur += 1 + char_is_sign(cur[1]);
if (!char_is_digit(*cur)) {
return_err(cur, "no digit after exponent sign");
}
cur++;
while (char_is_digit(*cur)) cur++;
}
/*
libc's strtod() is used to parse the floating-point number.
Note that the decimal point character used by strtod() is locale-dependent,
and the rounding direction may affected by fesetround().
For currently known locales, (en, zh, ja, ko, am, he, hi) use '.' as the
decimal point, while other locales use ',' as the decimal point.
Here strtod() is called twice for different locales, but if another thread
happens calls setlocale() between two strtod(), parsing may still fail.
*/
val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end);
if (unlikely(f64_end != cur)) {
/* replace '.' with ',' for locale */
bool cut = (*cur == ',');
if (cut) *cur = ' ';
if (dot) *dot = ',';
val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end);
/* restore ',' to '.' */
if (cut) *cur = ',';
if (dot) *dot = '.';
if (unlikely(f64_end != cur)) {
return_err(hdr, "strtod() failed to parse the number");
}
}
if (unlikely(val->uni.f64 >= HUGE_VAL || val->uni.f64 <= -HUGE_VAL)) {
return_inf();
}
val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL;
*end = cur;
return true;
#undef return_err
#undef return_0
#undef return_i64
#undef return_f64
#undef return_f64_bin
#undef return_inf
#undef return_raw
}
#endif /* FP_READER */
/*==============================================================================
* MARK: - String Reader (Private)
*============================================================================*/
/** Read unicode escape sequence. */
static_inline bool read_uni_esc(u8 **src_ptr, u8 **dst_ptr, const char **msg) {
#define return_err(_end, _msg) *msg = _msg; *src_ptr = _end; return false
u8 *src = *src_ptr;
u8 *dst = *dst_ptr;
u16 hi, lo;
u32 uni;
src += 2; /* skip `\u` */
if (unlikely(!hex_load_4(src, &hi))) {
return_err(src - 2, "invalid escaped sequence in string");
}
src += 4; /* skip hex */
if (likely((hi & 0xF800) != 0xD800)) {
/* a BMP character */
if (hi >= 0x800) {
*dst++ = (u8)(0xE0 | (hi >> 12));
*dst++ = (u8)(0x80 | ((hi >> 6) & 0x3F));
*dst++ = (u8)(0x80 | (hi & 0x3F));
} else if (hi >= 0x80) {
*dst++ = (u8)(0xC0 | (hi >> 6));
*dst++ = (u8)(0x80 | (hi & 0x3F));
} else {
*dst++ = (u8)hi;
}
} else {
/* a non-BMP character, represented as a surrogate pair */
if (unlikely((hi & 0xFC00) != 0xD800)) {
return_err(src - 6, "invalid high surrogate in string");
}
if (unlikely(!byte_match_2(src, "\\u"))) {
return_err(src - 6, "no low surrogate in string");
}
if (unlikely(!hex_load_4(src + 2, &lo))) {
return_err(src - 6, "invalid escape in string");
}
if (unlikely((lo & 0xFC00) != 0xDC00)) {
return_err(src - 6, "invalid low surrogate in string");
}
uni = ((((u32)hi - 0xD800) << 10) |
((u32)lo - 0xDC00)) + 0x10000;
*dst++ = (u8)(0xF0 | (uni >> 18));
*dst++ = (u8)(0x80 | ((uni >> 12) & 0x3F));
*dst++ = (u8)(0x80 | ((uni >> 6) & 0x3F));
*dst++ = (u8)(0x80 | (uni & 0x3F));
src += 6;
}
*src_ptr = src;
*dst_ptr = dst;
return true;
#undef return_err
}
/**
Read a JSON string.
@param quo The quote character (single quote or double quote).
@param ptr The head pointer of string before quote (inout).
@param eof JSON end position.
@param flg JSON read flag.
@param val The string value to be written.
@param msg The error message pointer.
@param con Continuation for incremental parsing.
@return Whether success.
*/
static_inline bool read_str_opt(u8 quo, u8 **ptr, u8 *eof, yyjson_read_flag flg,
yyjson_val *val, const char **msg, u8 *con[2]) {
/*
GCC may sometimes load variables into registers too early, causing
unnecessary instructions and performance degradation. This inline assembly
serves as a hint to GCC: 'This variable will be modified, so avoid loading
it too early.' Other compilers like MSVC, Clang, and ICC can generate the
expected instructions without needing this hint.
Check out this example: https://godbolt.org/z/YG6a5W5Ec
*/
#define return_err(_end, _msg) do { \
*msg = _msg; \
*end = _end; \
if (con) { con[0] = _end; con[1] = dst; } \
return false; \
} while (false)
u8 *hdr = *ptr + 1;
u8 **end = ptr;
u8 *src = hdr, *dst = NULL, *pos;
u16 hi, lo;
u32 uni, tmp;
/* Resume incremental parsing. */
if (con && unlikely(con[0])) {
src = con[0];
dst = con[1];
if (dst) goto copy_ascii;
}
skip_ascii:
/*
Most strings have no escaped characters, so we can jump them quickly.
We want to make loop unrolling, as shown in the following code. Some
compiler may not generate instructions as expected, so we rewrite it with
explicit goto statements. We hope the compiler can generate instructions
like this: https://godbolt.org/z/8vjsYq
while (true) repeat16({
if (likely((char_is_ascii_skip(*src)))) src++;
else break;
})
*/
if (quo == '"') {
#define expr_jump(i) \
if (likely(char_is_ascii_skip(src[i]))) {} \
else goto skip_ascii_stop##i;
#define expr_stop(i) \
skip_ascii_stop##i: \
src += i; \
goto skip_ascii_end;
repeat16_incr(expr_jump)
src += 16;
goto skip_ascii;
repeat16_incr(expr_stop)
#undef expr_jump
#undef expr_stop
} else {
#define expr_jump(i) \
if (likely(char_is_ascii_skip_sq(src[i]))) {} \
else goto skip_ascii_stop_sq##i;
#define expr_stop(i) \
skip_ascii_stop_sq##i: \
src += i; \
goto skip_ascii_end;
repeat16_incr(expr_jump)
src += 16;
goto skip_ascii;
repeat16_incr(expr_stop)
#undef expr_jump
#undef expr_stop
}
skip_ascii_end:
gcc_store_barrier(*src);
if (likely(*src == quo)) {
val->tag = ((u64)(src - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR |
(quo == '"' ? YYJSON_SUBTYPE_NOESC : 0);
val->uni.str = (const char *)hdr;
*src = '\0';
*end = src + 1;
if (con) con[0] = con[1] = NULL;
return true;
}
skip_utf8:
if (*src & 0x80) { /* non-ASCII character */
/*
Non-ASCII character appears here, which means that the text is likely
to be written in non-English or emoticons. According to some common
data set statistics, byte sequences of the same length may appear
consecutively. We process the byte sequences of the same length in each
loop, which is more friendly to branch prediction.
*/
pos = src;
#if YYJSON_DISABLE_UTF8_VALIDATION
while (true) repeat8({
if (likely((*src & 0xF0) == 0xE0)) src += 3;
else break;
})
if (*src < 0x80) goto skip_ascii;
while (true) repeat8({
if (likely((*src & 0xE0) == 0xC0)) src += 2;
else break;
})
while (true) repeat8({
if (likely((*src & 0xF8) == 0xF0)) src += 4;
else break;
})
#else
uni = byte_load_4(src);
while (is_utf8_seq3(uni)) {
src += 3;
uni = byte_load_4(src);
}
if (is_utf8_seq1(uni)) goto skip_ascii;
while (is_utf8_seq2(uni)) {
src += 2;
uni = byte_load_4(src);
}
while (is_utf8_seq4(uni)) {
src += 4;
uni = byte_load_4(src);
}
#endif
if (unlikely(pos == src)) {
if (has_allow(INVALID_UNICODE)) ++src;
else return_err(src, "invalid UTF-8 encoding in string");
}
goto skip_ascii;
}
/* The escape character appears, we need to copy it. */
dst = src;
copy_escape:
if (likely(*src == '\\')) {
switch (*++src) {
case '"': *dst++ = '"'; src++; break;
case '\\': *dst++ = '\\'; src++; break;
case '/': *dst++ = '/'; src++; break;
case 'b': *dst++ = '\b'; src++; break;
case 'f': *dst++ = '\f'; src++; break;
case 'n': *dst++ = '\n'; src++; break;
case 'r': *dst++ = '\r'; src++; break;
case 't': *dst++ = '\t'; src++; break;
case 'u':
src--;
if (!read_uni_esc(&src, &dst, msg)) return_err(src, *msg);
break;
default: {
if (has_allow(EXT_ESCAPE)) {
/* read extended escape (non-standard) */
switch (*src) {
case '\'': *dst++ = '\''; src++; break;
case 'a': *dst++ = '\a'; src++; break;
case 'v': *dst++ = '\v'; src++; break;
case '?': *dst++ = '\?'; src++; break;
case 'e': *dst++ = 0x1B; src++; break;
case '0':
if (!char_is_digit(src[1])) {
*dst++ = '\0'; src++; break;
}
return_err(src - 1, "octal escape is not allowed");
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return_err(src - 1, "invalid number escape");
case 'x': {
u8 c;
if (hex_load_2(src + 1, &c)) {
src += 3;
if (c <= 0x7F) { /* 1-byte ASCII */
*dst++ = c;
} else { /* 2-byte UTF-8 */
*dst++ = (u8)(0xC0 | (c >> 6));
*dst++ = (u8)(0x80 | (c & 0x3F));
}
break;
}
return_err(src - 1, "invalid hex escape");
}
case '\n': src++; break;
case '\r': src++; src += (*src == '\n'); break;
case 0xE2: /* Line terminator: U+2028, U+2029 */
if ((src[1] == 0x80 && src[2] == 0xA8) ||
(src[1] == 0x80 && src[2] == 0xA9)) {
src += 3;
}
break;
default:
break; /* skip */
}
} else if (quo == '\'' && *src == '\'') {
*dst++ = '\''; src++; break;
} else {
return_err(src - 1, "invalid escaped sequence in string");
}
}
}
} else if (likely(*src == quo)) {
val->tag = ((u64)(dst - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
val->uni.str = (const char *)hdr;
*dst = '\0';
*end = src + 1;
if (con) con[0] = con[1] = NULL;
return true;
} else {
if (!has_allow(INVALID_UNICODE)) {
return_err(src, "unexpected control character in string");
}
if (src >= eof) return_err(src, "unclosed string");
*dst++ = *src++;
}
copy_ascii:
/*
Copy continuous ASCII, loop unrolling, same as the following code:
while (true) repeat16({
if (char_is_ascii_skip(*src)) *dst++ = *src++;
else break;
})
*/
if (quo == '"') {
#define expr_jump(i) \
if (likely((char_is_ascii_skip(src[i])))) {} \
else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; }
repeat16_incr(expr_jump)
#undef expr_jump
} else {
#define expr_jump(i) \
if (likely((char_is_ascii_skip_sq(src[i])))) {} \
else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; }
repeat16_incr(expr_jump)
#undef expr_jump
}
byte_move_16(dst, src);
dst += 16; src += 16;
goto copy_ascii;
/*
The memory is copied forward since `dst < src`.
So it's safe to move one extra byte to reduce instruction count.
*/
#define expr_jump(i) \
copy_ascii_stop_##i: \
byte_move_forward(dst, src, i); \
dst += i; src += i; \
goto copy_utf8;
repeat16_incr(expr_jump)
#undef expr_jump
copy_utf8:
if (*src & 0x80) { /* non-ASCII character */
pos = src;
uni = byte_load_4(src);
#if YYJSON_DISABLE_UTF8_VALIDATION
while (true) repeat4({
if ((uni & utf8_seq(b3_mask)) == utf8_seq(b3_patt)) {
byte_copy_4(dst, &uni);
dst += 3; src += 3;
uni = byte_load_4(src);
} else break;
})
if ((uni & utf8_seq(b1_mask)) == utf8_seq(b1_patt)) goto copy_ascii;
while (true) repeat4({
if ((uni & utf8_seq(b2_mask)) == utf8_seq(b2_patt)) {
byte_copy_2(dst, &uni);
dst += 2; src += 2;
uni = byte_load_4(src);
} else break;
})
while (true) repeat4({
if ((uni & utf8_seq(b4_mask)) == utf8_seq(b4_patt)) {
byte_copy_4(dst, &uni);
dst += 4; src += 4;
uni = byte_load_4(src);
} else break;
})
#else
while (is_utf8_seq3(uni)) {
byte_copy_4(dst, &uni);
dst += 3; src += 3;
uni = byte_load_4(src);
}
if (is_utf8_seq1(uni)) goto copy_ascii;
while (is_utf8_seq2(uni)) {
byte_copy_2(dst, &uni);
dst += 2; src += 2;
uni = byte_load_4(src);
}
while (is_utf8_seq4(uni)) {
byte_copy_4(dst, &uni);
dst += 4; src += 4;
uni = byte_load_4(src);
}
#endif
if (unlikely(pos == src)) {
if (!has_allow(INVALID_UNICODE)) {
return_err(src, MSG_ERR_UTF8);
}
goto copy_ascii_stop_1;
}
goto copy_ascii;
}
goto copy_escape;
#undef return_err
}
static_inline bool read_str(u8 **ptr, u8 *eof, yyjson_read_flag flg,
yyjson_val *val, const char **msg) {
return read_str_opt('\"', ptr, eof, flg, val, msg, NULL);
}
static_inline bool read_str_con(u8 **ptr, u8 *eof, yyjson_read_flag flg,
yyjson_val *val, const char **msg, u8 **con) {
return read_str_opt('\"', ptr, eof, flg, val, msg, con);
}
static_noinline bool read_str_sq(u8 **ptr, u8 *eof, yyjson_read_flag flg,
yyjson_val *val, const char **msg) {
return read_str_opt('\'', ptr, eof, flg, val, msg, NULL);
}
/** Read unquoted key (identifier name). */
static_noinline bool read_str_id(u8 **ptr, u8 *eof, yyjson_read_flag flg,
u8 **pre, yyjson_val *val, const char **msg) {
#define return_err(_end, _msg) do { \
*msg = _msg; \
*end = _end; \
return false; \
} while (false)
#define return_suc(_str_end, _cur_end) do { \
val->tag = ((u64)(_str_end - hdr) << YYJSON_TAG_BIT) | \
(u64)(YYJSON_TYPE_STR); \
val->uni.str = (const char *)hdr; \
*pre = _str_end; *end = _cur_end; \
return true; \
} while (false)
u8 *hdr = *ptr;
u8 **end = ptr;
u8 *src = hdr, *dst = NULL;
u16 hi, lo;
u32 uni, tmp;
/* add null-terminator for previous raw string */
**pre = '\0';
skip_ascii:
#define expr_jump(i) \
if (likely(char_is_id_ascii(src[i]))) {} \
else goto skip_ascii_stop##i;
#define expr_stop(i) \
skip_ascii_stop##i: \
src += i; \
goto skip_ascii_end;
repeat16_incr(expr_jump)
src += 16;
goto skip_ascii;
repeat16_incr(expr_stop)
#undef expr_jump
#undef expr_stop
skip_ascii_end:
gcc_store_barrier(*src);
if (likely(!char_is_id_next(*src))) {
return_suc(src, src);
}
skip_utf8:
while (*src >= 0x80) {
if (has_allow(EXT_WHITESPACE)) {
if (char_is_space_ext(*src) && ext_space_len(src)) {
return_suc(src, src);
}
}
uni = byte_load_4(src);
if (is_utf8_seq2(uni)) {
src += 2;
} else if (is_utf8_seq3(uni)) {
src += 3;
} else if (is_utf8_seq4(uni)) {
src += 4;
} else {
#if !YYJSON_DISABLE_UTF8_VALIDATION
if (!has_allow(INVALID_UNICODE)) return_err(src, MSG_ERR_UTF8);
#endif
src += 1;
}
}
if (char_is_id_ascii(*src)) goto skip_ascii;
/* The escape character appears, we need to copy it. */
dst = src;
copy_escape:
if (byte_match_2(src, "\\u")) {
if (!read_uni_esc(&src, &dst, msg)) return_err(src, *msg);
} else {
if (!char_is_id_next(*src)) return_suc(dst, src);
return_err(src, "unexpected character in key");
}
copy_ascii:
/*
Copy continuous ASCII, loop unrolling, same as the following code:
while (true) repeat16({
if (char_is_ascii_skip(*src)) *dst++ = *src++;
else break;
})
*/
#define expr_jump(i) \
if (likely((char_is_id_ascii(src[i])))) {} \
else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; }
repeat16_incr(expr_jump)
#undef expr_jump
byte_move_16(dst, src);
dst += 16; src += 16;
goto copy_ascii;
#define expr_jump(i) \
copy_ascii_stop_##i: \
byte_move_forward(dst, src, i); \
dst += i; src += i; \
goto copy_utf8;
repeat16_incr(expr_jump)
#undef expr_jump
copy_utf8:
while (*src >= 0x80) { /* non-ASCII character */
if (has_allow(EXT_WHITESPACE)) {
if (char_is_space_ext(*src) && ext_space_len(src)) {
return_suc(dst, src);
}
}
uni = byte_load_4(src);
if (is_utf8_seq2(uni)) {
byte_copy_2(dst, &uni);
dst += 2; src += 2;
} else if (is_utf8_seq3(uni)) {
byte_copy_4(dst, &uni);
dst += 3; src += 3;
} else if (is_utf8_seq4(uni)) {
byte_copy_4(dst, &uni);
dst += 4; src += 4;
} else {
#if !YYJSON_DISABLE_UTF8_VALIDATION
if (!has_allow(INVALID_UNICODE)) return_err(src, MSG_ERR_UTF8);
#endif
*dst = *src;
dst += 1; src += 1;
}
}
if (char_is_id_ascii(*src)) goto copy_ascii;
goto copy_escape;
#undef return_err
#undef return_suc
}
/*==============================================================================
* MARK: - JSON Reader Implementation (Private)
*
* We use goto statements to build the finite state machine (FSM).
* The FSM's state was held by program counter (PC) and the 'goto' make the
* state transitions.
*============================================================================*/
/** Read single value JSON document. */
static_noinline yyjson_doc *read_root_single(u8 *hdr, u8 *cur, u8 *eof,
yyjson_alc alc,
yyjson_read_flag flg,
yyjson_read_err *err) {
#define return_err(_pos, _code, _msg) do { \
if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \
err->pos = (usize)(eof - hdr); \
err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \
err->msg = MSG_NOT_END; \
} else { \
err->pos = (usize)(_pos - hdr); \
err->code = YYJSON_READ_ERROR_##_code; \
err->msg = _msg; \
} \
if (val_hdr) alc.free(alc.ctx, val_hdr); \
return NULL; \
} while (false)
usize hdr_len; /* value count used by doc */
usize alc_num; /* value count capacity */
yyjson_val *val_hdr; /* the head of allocated values */
yyjson_val *val; /* current value */
yyjson_doc *doc; /* the JSON document, equals to val_hdr */
const char *msg; /* error message */
u8 raw_end[1]; /* raw end for null-terminator */
u8 *raw_ptr = raw_end;
u8 **pre = &raw_ptr; /* previous raw end pointer */
hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val);
hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0;
alc_num = hdr_len + 1; /* single value */
val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_num * sizeof(yyjson_val));
if (unlikely(!val_hdr)) goto fail_alloc;
val = val_hdr + hdr_len;
if (char_is_num(*cur)) {
if (likely(read_num(&cur, pre, flg, val, &msg))) goto doc_end;
goto fail_number;
}
if (*cur == '"') {
if (likely(read_str(&cur, eof, flg, val, &msg))) goto doc_end;
goto fail_string;
}
if (*cur == 't') {
if (likely(read_true(&cur, val))) goto doc_end;
goto fail_literal_true;
}
if (*cur == 'f') {
if (likely(read_false(&cur, val))) goto doc_end;
goto fail_literal_false;
}
if (*cur == 'n') {
if (likely(read_null(&cur, val))) goto doc_end;
if (has_allow(INF_AND_NAN)) {
if (read_nan(&cur, pre, flg, val)) goto doc_end;
}
goto fail_literal_null;
}
if (has_allow(INF_AND_NAN)) {
if (read_inf_or_nan(&cur, pre, flg, val)) goto doc_end;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto doc_end;
goto fail_string;
}
goto fail_character;
doc_end:
/* check invalid contents after json document */
if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) {
while (char_is_space(*cur)) cur++;
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (!skip_trivia(&cur, eof, flg) && cur == eof) {
goto fail_comment;
}
}
if (unlikely(cur < eof)) goto fail_garbage;
}
**pre = '\0';
doc = (yyjson_doc *)val_hdr;
doc->root = val_hdr + hdr_len;
doc->alc = alc;
doc->dat_read = (usize)(cur - hdr);
doc->val_read = 1;
doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr;
return doc;
fail_string: return_err(cur, INVALID_STRING, msg);
fail_number: return_err(cur, INVALID_NUMBER, msg);
fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC);
fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T);
fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F);
fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N);
fail_character: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR);
fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT);
fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE);
#undef return_err
}
/** Read JSON document (accept all style, but optimized for minify). */
static_inline yyjson_doc *read_root_minify(u8 *hdr, u8 *cur, u8 *eof,
yyjson_alc alc,
yyjson_read_flag flg,
yyjson_read_err *err) {
#define return_err(_pos, _code, _msg) do { \
if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \
err->pos = (usize)(eof - hdr); \
err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \
err->msg = MSG_NOT_END; \
} else { \
err->pos = (usize)(_pos - hdr); \
err->code = YYJSON_READ_ERROR_##_code; \
err->msg = _msg; \
} \
if (val_hdr) alc.free(alc.ctx, val_hdr); \
return NULL; \
} while (false)
#define val_incr() do { \
val++; \
if (unlikely(val >= val_end)) { \
usize alc_old = alc_len; \
usize val_ofs = (usize)(val - val_hdr); \
usize ctn_ofs = (usize)(ctn - val_hdr); \
alc_len += alc_len / 2; \
if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \
val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \
alc_old * sizeof(yyjson_val), \
alc_len * sizeof(yyjson_val)); \
if ((!val_tmp)) goto fail_alloc; \
val = val_tmp + val_ofs; \
ctn = val_tmp + ctn_ofs; \
val_hdr = val_tmp; \
val_end = val_tmp + (alc_len - 2); \
} \
} while (false)
usize dat_len; /* data length in bytes, hint for allocator */
usize hdr_len; /* value count used by yyjson_doc */
usize alc_len; /* value count allocated */
usize alc_max; /* maximum value count for allocator */
usize ctn_len; /* the number of elements in current container */
yyjson_val *val_hdr; /* the head of allocated values */
yyjson_val *val_end; /* the end of allocated values */
yyjson_val *val_tmp; /* temporary pointer for realloc */
yyjson_val *val; /* current JSON value */
yyjson_val *ctn; /* current container */
yyjson_val *ctn_parent; /* parent of current container */
yyjson_doc *doc; /* the JSON document, equals to val_hdr */
const char *msg; /* error message */
u8 raw_end[1]; /* raw end for null-terminator */
u8 *raw_ptr = raw_end;
u8 **pre = &raw_ptr; /* previous raw end pointer */
dat_len = has_flg(STOP_WHEN_DONE) ? 256 : (usize)(eof - cur);
hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val);
hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0;
alc_max = USIZE_MAX / sizeof(yyjson_val);
alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4;
alc_len = yyjson_min(alc_len, alc_max);
val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val));
if (unlikely(!val_hdr)) goto fail_alloc;
val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */
val = val_hdr + hdr_len;
ctn = val;
ctn_len = 0;
if (*cur++ == '{') {
ctn->tag = YYJSON_TYPE_OBJ;
ctn->uni.ofs = 0;
goto obj_key_begin;
} else {
ctn->tag = YYJSON_TYPE_ARR;
ctn->uni.ofs = 0;
goto arr_val_begin;
}
arr_begin:
/* save current container */
ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) |
(ctn->tag & YYJSON_TAG_MASK);
/* create a new array value, save parent container offset */
val_incr();
val->tag = YYJSON_TYPE_ARR;
val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn);
/* push the new array value as current container */
ctn = val;
ctn_len = 0;
arr_val_begin:
if (*cur == '{') {
cur++;
goto obj_begin;
}
if (*cur == '[') {
cur++;
goto arr_begin;
}
if (char_is_num(*cur)) {
val_incr();
ctn_len++;
if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_end;
goto fail_number;
}
if (*cur == '"') {
val_incr();
ctn_len++;
if (likely(read_str(&cur, eof, flg, val, &msg))) goto arr_val_end;
goto fail_string;
}
if (*cur == 't') {
val_incr();
ctn_len++;
if (likely(read_true(&cur, val))) goto arr_val_end;
goto fail_literal_true;
}
if (*cur == 'f') {
val_incr();
ctn_len++;
if (likely(read_false(&cur, val))) goto arr_val_end;
goto fail_literal_false;
}
if (*cur == 'n') {
val_incr();
ctn_len++;
if (likely(read_null(&cur, val))) goto arr_val_end;
if (has_allow(INF_AND_NAN)) {
if (read_nan(&cur, pre, flg, val)) goto arr_val_end;
}
goto fail_literal_null;
}
if (*cur == ']') {
cur++;
if (likely(ctn_len == 0)) goto arr_end;
if (has_allow(TRAILING_COMMAS)) goto arr_end;
while (*cur != ',') cur--;
goto fail_trailing_comma;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto arr_val_begin;
}
if (has_allow(INF_AND_NAN) &&
(*cur == 'i' || *cur == 'I' || *cur == 'N')) {
val_incr();
ctn_len++;
if (read_inf_or_nan(&cur, pre, flg, val)) goto arr_val_end;
goto fail_character_val;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
val_incr();
ctn_len++;
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto arr_val_end;
goto fail_string;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto arr_val_begin;
if (cur == eof) goto fail_comment;
}
goto fail_character_val;
arr_val_end:
if (*cur == ',') {
cur++;
goto arr_val_begin;
}
if (*cur == ']') {
cur++;
goto arr_end;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto arr_val_end;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto arr_val_end;
if (cur == eof) goto fail_comment;
}
goto fail_character_arr_end;
arr_end:
/* get parent container */
ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs);
/* save the next sibling value offset */
ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val);
ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR;
if (unlikely(ctn == ctn_parent)) goto doc_end;
/* pop parent as current container */
ctn = ctn_parent;
ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT);
if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) {
goto obj_val_end;
} else {
goto arr_val_end;
}
obj_begin:
/* push container */
ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) |
(ctn->tag & YYJSON_TAG_MASK);
val_incr();
val->tag = YYJSON_TYPE_OBJ;
/* offset to the parent */
val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn);
ctn = val;
ctn_len = 0;
obj_key_begin:
if (likely(*cur == '"')) {
val_incr();
ctn_len++;
if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_key_end;
goto fail_string;
}
if (likely(*cur == '}')) {
cur++;
if (likely(ctn_len == 0)) goto obj_end;
if (has_allow(TRAILING_COMMAS)) goto obj_end;
while (*cur != ',') cur--;
goto fail_trailing_comma;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_key_begin;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
val_incr();
ctn_len++;
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_key_end;
goto fail_string;
}
if (has_allow(UNQUOTED_KEY) && char_is_id_start(*cur)) {
val_incr();
ctn_len++;
if (read_str_id(&cur, eof, flg, pre, val, &msg)) goto obj_key_end;
goto fail_string;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_key_begin;
if (cur == eof) goto fail_comment;
}
goto fail_character_obj_key;
obj_key_end:
if (*cur == ':') {
cur++;
goto obj_val_begin;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_key_end;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_key_end;
if (cur == eof) goto fail_comment;
}
goto fail_character_obj_sep;
obj_val_begin:
if (*cur == '"') {
val++;
ctn_len++;
if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_val_end;
goto fail_string;
}
if (char_is_num(*cur)) {
val++;
ctn_len++;
if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_end;
goto fail_number;
}
if (*cur == '{') {
cur++;
goto obj_begin;
}
if (*cur == '[') {
cur++;
goto arr_begin;
}
if (*cur == 't') {
val++;
ctn_len++;
if (likely(read_true(&cur, val))) goto obj_val_end;
goto fail_literal_true;
}
if (*cur == 'f') {
val++;
ctn_len++;
if (likely(read_false(&cur, val))) goto obj_val_end;
goto fail_literal_false;
}
if (*cur == 'n') {
val++;
ctn_len++;
if (likely(read_null(&cur, val))) goto obj_val_end;
if (has_allow(INF_AND_NAN)) {
if (read_nan(&cur, pre, flg, val)) goto obj_val_end;
}
goto fail_literal_null;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_val_begin;
}
if (has_allow(INF_AND_NAN) &&
(*cur == 'i' || *cur == 'I' || *cur == 'N')) {
val++;
ctn_len++;
if (read_inf_or_nan(&cur, pre, flg, val)) goto obj_val_end;
goto fail_character_val;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
val++;
ctn_len++;
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_val_end;
goto fail_string;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_val_begin;
if (cur == eof) goto fail_comment;
}
goto fail_character_val;
obj_val_end:
if (likely(*cur == ',')) {
cur++;
goto obj_key_begin;
}
if (likely(*cur == '}')) {
cur++;
goto obj_end;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_val_end;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_val_end;
if (cur == eof) goto fail_comment;
}
goto fail_character_obj_end;
obj_end:
/* pop container */
ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs);
/* point to the next value */
ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val);
ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ;
if (unlikely(ctn == ctn_parent)) goto doc_end;
ctn = ctn_parent;
ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT);
if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) {
goto obj_val_end;
} else {
goto arr_val_end;
}
doc_end:
/* check invalid contents after json document */
if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) {
while (char_is_space(*cur)) cur++;
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (!skip_trivia(&cur, eof, flg) && cur == eof) {
goto fail_comment;
}
}
if (unlikely(cur < eof)) goto fail_garbage;
}
**pre = '\0';
doc = (yyjson_doc *)val_hdr;
doc->root = val_hdr + hdr_len;
doc->alc = alc;
doc->dat_read = (usize)(cur - hdr);
doc->val_read = (usize)((val - doc->root) + 1);
doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr;
return doc;
fail_string: return_err(cur, INVALID_STRING, msg);
fail_number: return_err(cur, INVALID_NUMBER, msg);
fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC);
fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA);
fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T);
fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F);
fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N);
fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR);
fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END);
fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY);
fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP);
fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END);
fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT);
fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE);
#undef val_incr
#undef return_err
}
/** Read JSON document (accept all style, but optimized for pretty). */
static_inline yyjson_doc *read_root_pretty(u8 *hdr, u8 *cur, u8 *eof,
yyjson_alc alc,
yyjson_read_flag flg,
yyjson_read_err *err) {
#define return_err(_pos, _code, _msg) do { \
if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \
err->pos = (usize)(eof - hdr); \
err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \
err->msg = MSG_NOT_END; \
} else { \
err->pos = (usize)(_pos - hdr); \
err->code = YYJSON_READ_ERROR_##_code; \
err->msg = _msg; \
} \
if (val_hdr) alc.free(alc.ctx, val_hdr); \
return NULL; \
} while (false)
#define val_incr() do { \
val++; \
if (unlikely(val >= val_end)) { \
usize alc_old = alc_len; \
usize val_ofs = (usize)(val - val_hdr); \
usize ctn_ofs = (usize)(ctn - val_hdr); \
alc_len += alc_len / 2; \
if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \
val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \
alc_old * sizeof(yyjson_val), \
alc_len * sizeof(yyjson_val)); \
if ((!val_tmp)) goto fail_alloc; \
val = val_tmp + val_ofs; \
ctn = val_tmp + ctn_ofs; \
val_hdr = val_tmp; \
val_end = val_tmp + (alc_len - 2); \
} \
} while (false)
usize dat_len; /* data length in bytes, hint for allocator */
usize hdr_len; /* value count used by yyjson_doc */
usize alc_len; /* value count allocated */
usize alc_max; /* maximum value count for allocator */
usize ctn_len; /* the number of elements in current container */
yyjson_val *val_hdr; /* the head of allocated values */
yyjson_val *val_end; /* the end of allocated values */
yyjson_val *val_tmp; /* temporary pointer for realloc */
yyjson_val *val; /* current JSON value */
yyjson_val *ctn; /* current container */
yyjson_val *ctn_parent; /* parent of current container */
yyjson_doc *doc; /* the JSON document, equals to val_hdr */
const char *msg; /* error message */
u8 raw_end[1]; /* raw end for null-terminator */
u8 *raw_ptr = raw_end;
u8 **pre = &raw_ptr; /* previous raw end pointer */
dat_len = has_flg(STOP_WHEN_DONE) ? 256 : (usize)(eof - cur);
hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val);
hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0;
alc_max = USIZE_MAX / sizeof(yyjson_val);
alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_PRETTY_RATIO) + 4;
alc_len = yyjson_min(alc_len, alc_max);
val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val));
if (unlikely(!val_hdr)) goto fail_alloc;
val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */
val = val_hdr + hdr_len;
ctn = val;
ctn_len = 0;
if (*cur++ == '{') {
ctn->tag = YYJSON_TYPE_OBJ;
ctn->uni.ofs = 0;
if (*cur == '\n') cur++;
goto obj_key_begin;
} else {
ctn->tag = YYJSON_TYPE_ARR;
ctn->uni.ofs = 0;
if (*cur == '\n') cur++;
goto arr_val_begin;
}
arr_begin:
/* save current container */
ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) |
(ctn->tag & YYJSON_TAG_MASK);
/* create a new array value, save parent container offset */
val_incr();
val->tag = YYJSON_TYPE_ARR;
val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn);
/* push the new array value as current container */
ctn = val;
ctn_len = 0;
if (*cur == '\n') cur++;
arr_val_begin:
#if YYJSON_IS_REAL_GCC
while (true) repeat16({
if (byte_match_2(cur, " ")) cur += 2;
else break;
})
#else
while (true) repeat16({
if (likely(byte_match_2(cur, " "))) cur += 2;
else break;
})
#endif
if (*cur == '{') {
cur++;
goto obj_begin;
}
if (*cur == '[') {
cur++;
goto arr_begin;
}
if (char_is_num(*cur)) {
val_incr();
ctn_len++;
if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_end;
goto fail_number;
}
if (*cur == '"') {
val_incr();
ctn_len++;
if (likely(read_str(&cur, eof, flg, val, &msg))) goto arr_val_end;
goto fail_string;
}
if (*cur == 't') {
val_incr();
ctn_len++;
if (likely(read_true(&cur, val))) goto arr_val_end;
goto fail_literal_true;
}
if (*cur == 'f') {
val_incr();
ctn_len++;
if (likely(read_false(&cur, val))) goto arr_val_end;
goto fail_literal_false;
}
if (*cur == 'n') {
val_incr();
ctn_len++;
if (likely(read_null(&cur, val))) goto arr_val_end;
if (has_allow(INF_AND_NAN)) {
if (read_nan(&cur, pre, flg, val)) goto arr_val_end;
}
goto fail_literal_null;
}
if (*cur == ']') {
cur++;
if (likely(ctn_len == 0)) goto arr_end;
if (has_allow(TRAILING_COMMAS)) goto arr_end;
while (*cur != ',') cur--;
goto fail_trailing_comma;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto arr_val_begin;
}
if (has_allow(INF_AND_NAN) &&
(*cur == 'i' || *cur == 'I' || *cur == 'N')) {
val_incr();
ctn_len++;
if (read_inf_or_nan(&cur, pre, flg, val)) goto arr_val_end;
goto fail_character_val;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
val_incr();
ctn_len++;
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto arr_val_end;
goto fail_string;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto arr_val_begin;
if (cur == eof) goto fail_comment;
}
goto fail_character_val;
arr_val_end:
if (byte_match_2(cur, ",\n")) {
cur += 2;
goto arr_val_begin;
}
if (*cur == ',') {
cur++;
goto arr_val_begin;
}
if (*cur == ']') {
cur++;
goto arr_end;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto arr_val_end;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto arr_val_end;
if (cur == eof) goto fail_comment;
}
goto fail_character_arr_end;
arr_end:
/* get parent container */
ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs);
/* save the next sibling value offset */
ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val);
ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR;
if (unlikely(ctn == ctn_parent)) goto doc_end;
/* pop parent as current container */
ctn = ctn_parent;
ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT);
if (*cur == '\n') cur++;
if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) {
goto obj_val_end;
} else {
goto arr_val_end;
}
obj_begin:
/* push container */
ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) |
(ctn->tag & YYJSON_TAG_MASK);
val_incr();
val->tag = YYJSON_TYPE_OBJ;
/* offset to the parent */
val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn);
ctn = val;
ctn_len = 0;
if (*cur == '\n') cur++;
obj_key_begin:
#if YYJSON_IS_REAL_GCC
while (true) repeat16({
if (byte_match_2(cur, " ")) cur += 2;
else break;
})
#else
while (true) repeat16({
if (likely(byte_match_2(cur, " "))) cur += 2;
else break;
})
#endif
if (likely(*cur == '"')) {
val_incr();
ctn_len++;
if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_key_end;
goto fail_string;
}
if (likely(*cur == '}')) {
cur++;
if (likely(ctn_len == 0)) goto obj_end;
if (has_allow(TRAILING_COMMAS)) goto obj_end;
while (*cur != ',') cur--;
goto fail_trailing_comma;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_key_begin;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
val_incr();
ctn_len++;
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_key_end;
goto fail_string;
}
if (has_allow(UNQUOTED_KEY) && char_is_id_start(*cur)) {
val_incr();
ctn_len++;
if (read_str_id(&cur, eof, flg, pre, val, &msg)) goto obj_key_end;
goto fail_string;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_key_begin;
if (cur == eof) goto fail_comment;
}
goto fail_character_obj_key;
obj_key_end:
if (byte_match_2(cur, ": ")) {
cur += 2;
goto obj_val_begin;
}
if (*cur == ':') {
cur++;
goto obj_val_begin;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_key_end;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_key_end;
if (cur == eof) goto fail_comment;
}
goto fail_character_obj_sep;
obj_val_begin:
if (*cur == '"') {
val++;
ctn_len++;
if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_val_end;
goto fail_string;
}
if (char_is_num(*cur)) {
val++;
ctn_len++;
if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_end;
goto fail_number;
}
if (*cur == '{') {
cur++;
goto obj_begin;
}
if (*cur == '[') {
cur++;
goto arr_begin;
}
if (*cur == 't') {
val++;
ctn_len++;
if (likely(read_true(&cur, val))) goto obj_val_end;
goto fail_literal_true;
}
if (*cur == 'f') {
val++;
ctn_len++;
if (likely(read_false(&cur, val))) goto obj_val_end;
goto fail_literal_false;
}
if (*cur == 'n') {
val++;
ctn_len++;
if (likely(read_null(&cur, val))) goto obj_val_end;
if (has_allow(INF_AND_NAN)) {
if (read_nan(&cur, pre, flg, val)) goto obj_val_end;
}
goto fail_literal_null;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_val_begin;
}
if (has_allow(INF_AND_NAN) &&
(*cur == 'i' || *cur == 'I' || *cur == 'N')) {
val++;
ctn_len++;
if (read_inf_or_nan(&cur, pre, flg, val)) goto obj_val_end;
goto fail_character_val;
}
if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') {
val++;
ctn_len++;
if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_val_end;
goto fail_string;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_val_begin;
if (cur == eof) goto fail_comment;
}
goto fail_character_val;
obj_val_end:
if (byte_match_2(cur, ",\n")) {
cur += 2;
goto obj_key_begin;
}
if (likely(*cur == ',')) {
cur++;
goto obj_key_begin;
}
if (likely(*cur == '}')) {
cur++;
goto obj_end;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_val_end;
}
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (skip_trivia(&cur, eof, flg)) goto obj_val_end;
if (cur == eof) goto fail_comment;
}
goto fail_character_obj_end;
obj_end:
/* pop container */
ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs);
/* point to the next value */
ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val);
ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ;
if (unlikely(ctn == ctn_parent)) goto doc_end;
ctn = ctn_parent;
ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT);
if (*cur == '\n') cur++;
if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) {
goto obj_val_end;
} else {
goto arr_val_end;
}
doc_end:
/* check invalid contents after json document */
if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) {
while (char_is_space(*cur)) cur++;
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (!skip_trivia(&cur, eof, flg) && cur == eof) {
goto fail_comment;
}
}
if (unlikely(cur < eof)) goto fail_garbage;
}
**pre = '\0';
doc = (yyjson_doc *)val_hdr;
doc->root = val_hdr + hdr_len;
doc->alc = alc;
doc->dat_read = (usize)(cur - hdr);
doc->val_read = (usize)((val - doc->root) + 1);
doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr;
return doc;
fail_string: return_err(cur, INVALID_STRING, msg);
fail_number: return_err(cur, INVALID_NUMBER, msg);
fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC);
fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA);
fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T);
fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F);
fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N);
fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR);
fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END);
fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY);
fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP);
fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END);
fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT);
fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE);
#undef val_incr
#undef return_err
}
/*==============================================================================
* MARK: - JSON Reader (Public)
*============================================================================*/
yyjson_doc *yyjson_read_opts(char *dat, usize len,
yyjson_read_flag flg,
const yyjson_alc *alc_ptr,
yyjson_read_err *err) {
#define return_err(_pos, _code, _msg) do { \
err->pos = (usize)(_pos); \
err->msg = _msg; \
err->code = YYJSON_READ_ERROR_##_code; \
if (!has_flg(INSITU) && hdr) alc.free(alc.ctx, (void *)hdr); \
return NULL; \
} while (false)
yyjson_read_err tmp_err;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
yyjson_doc *doc;
u8 *hdr = NULL, *eof, *cur;
/* validate input parameters */
if (!err) err = &tmp_err;
if (unlikely(!dat)) return_err(0, INVALID_PARAMETER, "input data is NULL");
if (unlikely(!len)) return_err(0, INVALID_PARAMETER, "input length is 0");
/* add 4-byte zero padding for input data if necessary */
if (has_flg(INSITU)) {
hdr = (u8 *)dat;
eof = (u8 *)dat + len;
cur = (u8 *)dat;
} else {
if (unlikely(len >= USIZE_MAX - YYJSON_PADDING_SIZE)) {
return_err(0, MEMORY_ALLOCATION, MSG_MALLOC);
}
hdr = (u8 *)alc.malloc(alc.ctx, len + YYJSON_PADDING_SIZE);
if (unlikely(!hdr)) {
return_err(0, MEMORY_ALLOCATION, MSG_MALLOC);
}
eof = hdr + len;
cur = hdr;
memcpy(hdr, dat, len);
}
memset(eof, 0, YYJSON_PADDING_SIZE);
if (has_allow(BOM)) {
if (len >= 3 && is_utf8_bom(cur)) cur += 3;
}
/* skip empty contents before json document */
if (unlikely(!char_is_ctn(*cur))) {
while (char_is_space(*cur)) cur++;
if (unlikely(!char_is_ctn(*cur))) {
if (has_allow(TRIVIA) && char_is_trivia(*cur)) {
if (!skip_trivia(&cur, eof, flg) && cur == eof) {
return_err(cur - hdr, INVALID_COMMENT, MSG_COMMENT);
}
}
}
if (unlikely(cur >= eof)) {
return_err(0, EMPTY_CONTENT, "input data is empty");
}
}
/* read json document */
if (likely(char_is_ctn(*cur))) {
if (char_is_space(cur[1]) && char_is_space(cur[2])) {
doc = read_root_pretty(hdr, cur, eof, alc, flg, err);
} else {
doc = read_root_minify(hdr, cur, eof, alc, flg, err);
}
} else {
doc = read_root_single(hdr, cur, eof, alc, flg, err);
}
/* check result */
if (likely(doc)) {
memset(err, 0, sizeof(yyjson_read_err));
} else {
/* RFC 8259: JSON text MUST be encoded using UTF-8 */
if (err->pos == 0 && err->code != YYJSON_READ_ERROR_MEMORY_ALLOCATION) {
if (is_utf8_bom(hdr)) err->msg = MSG_ERR_BOM;
else if (len >= 4 && is_utf32_bom(hdr)) err->msg = MSG_ERR_UTF32;
else if (len >= 2 && is_utf16_bom(hdr)) err->msg = MSG_ERR_UTF16;
}
if (!has_flg(INSITU)) alc.free(alc.ctx, hdr);
}
return doc;
#undef return_err
}
yyjson_doc *yyjson_read_file(const char *path,
yyjson_read_flag flg,
const yyjson_alc *alc_ptr,
yyjson_read_err *err) {
#define return_err(_code, _msg) do { \
err->pos = 0; \
err->msg = _msg; \
err->code = YYJSON_READ_ERROR_##_code; \
return NULL; \
} while (false)
yyjson_read_err tmp_err;
yyjson_doc *doc;
FILE *file;
if (!err) err = &tmp_err;
if (unlikely(!path)) return_err(INVALID_PARAMETER, "input path is NULL");
file = fopen_readonly(path);
if (unlikely(!file)) return_err(FILE_OPEN, MSG_FREAD);
doc = yyjson_read_fp(file, flg, alc_ptr, err);
fclose(file);
return doc;
#undef return_err
}
yyjson_doc *yyjson_read_fp(FILE *file,
yyjson_read_flag flg,
const yyjson_alc *alc_ptr,
yyjson_read_err *err) {
#define return_err(_code, _msg) do { \
err->pos = 0; \
err->msg = _msg; \
err->code = YYJSON_READ_ERROR_##_code; \
if (buf) alc.free(alc.ctx, buf); \
return NULL; \
} while (false)
yyjson_read_err tmp_err;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
yyjson_doc *doc;
long file_size = 0, file_pos;
void *buf = NULL;
usize buf_size = 0;
/* validate input parameters */
if (!err) err = &tmp_err;
if (unlikely(!file)) return_err(INVALID_PARAMETER, "input file is NULL");
/* get current position */
file_pos = ftell(file);
if (file_pos != -1) {
/* get total file size, may fail */
if (fseek(file, 0, SEEK_END) == 0) file_size = ftell(file);
/* reset to original position, may fail */
if (fseek(file, file_pos, SEEK_SET) != 0) file_size = 0;
/* get file size from current postion to end */
if (file_size > 0) file_size -= file_pos;
}
/* read file */
if (file_size > 0) {
/* read the entire file in one call */
buf_size = (usize)file_size + YYJSON_PADDING_SIZE;
buf = alc.malloc(alc.ctx, buf_size);
if (buf == NULL) {
return_err(MEMORY_ALLOCATION, MSG_MALLOC);
}
if (fread_safe(buf, (usize)file_size, file) != (usize)file_size) {
return_err(FILE_READ, MSG_FREAD);
}
} else {
/* failed to get file size, read it as a stream */
usize chunk_min = (usize)64;
usize chunk_max = (usize)512 * 1024 * 1024;
usize chunk_now = chunk_min;
usize read_size;
void *tmp;
buf_size = YYJSON_PADDING_SIZE;
while (true) {
if (buf_size + chunk_now < buf_size) { /* overflow */
return_err(MEMORY_ALLOCATION, MSG_MALLOC);
}
buf_size += chunk_now;
if (!buf) {
buf = alc.malloc(alc.ctx, buf_size);
if (!buf) return_err(MEMORY_ALLOCATION, MSG_MALLOC);
} else {
tmp = alc.realloc(alc.ctx, buf, buf_size - chunk_now, buf_size);
if (!tmp) return_err(MEMORY_ALLOCATION, MSG_MALLOC);
buf = tmp;
}
tmp = ((u8 *)buf) + buf_size - YYJSON_PADDING_SIZE - chunk_now;
read_size = fread_safe(tmp, chunk_now, file);
file_size += (long)read_size;
if (read_size != chunk_now) break;
chunk_now *= 2;
if (chunk_now > chunk_max) chunk_now = chunk_max;
}
}
/* read JSON */
memset((u8 *)buf + file_size, 0, YYJSON_PADDING_SIZE);
flg |= YYJSON_READ_INSITU;
doc = yyjson_read_opts((char *)buf, (usize)file_size, flg, &alc, err);
if (doc) {
doc->str_pool = (char *)buf;
return doc;
} else {
alc.free(alc.ctx, buf);
return NULL;
}
#undef return_err
}
const char *yyjson_read_number(const char *dat,
yyjson_val *val,
yyjson_read_flag flg,
const yyjson_alc *alc,
yyjson_read_err *err) {
#define return_err(_pos, _code, _msg) do { \
err->pos = _pos > hdr ? (usize)(_pos - hdr) : 0; \
err->msg = _msg; \
err->code = YYJSON_READ_ERROR_##_code; \
return NULL; \
} while (false)
u8 *hdr = constcast(u8 *)dat, *cur = hdr;
u8 raw_end[1]; /* raw end for null-terminator */
u8 *raw_ptr = raw_end;
u8 **pre = &raw_ptr; /* previous raw end pointer */
const char *msg;
yyjson_read_err tmp_err;
#if YYJSON_DISABLE_FAST_FP_CONV
u8 buf[128];
usize dat_len;
#endif
if (!err) err = &tmp_err;
if (unlikely(!dat)) {
return_err(cur, INVALID_PARAMETER, "input data is NULL");
}
if (unlikely(!val)) {
return_err(cur, INVALID_PARAMETER, "output value is NULL");
}
#if YYJSON_DISABLE_FAST_FP_CONV
if (!alc) alc = &YYJSON_DEFAULT_ALC;
dat_len = strlen(dat);
if (dat_len < sizeof(buf)) {
memcpy(buf, dat, dat_len + 1);
hdr = buf;
cur = hdr;
} else {
hdr = (u8 *)alc->malloc(alc->ctx, dat_len + 1);
cur = hdr;
if (unlikely(!hdr)) {
return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC);
}
memcpy(hdr, dat, dat_len + 1);
}
hdr[dat_len] = 0;
#endif
#if YYJSON_DISABLE_FAST_FP_CONV
if (!read_num(&cur, pre, flg, val, &msg)) {
if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr);
return_err(cur, INVALID_NUMBER, msg);
}
if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr);
if (yyjson_is_raw(val)) val->uni.str = dat;
return dat + (cur - hdr);
#else
if (!read_num(&cur, pre, flg, val, &msg)) {
return_err(cur, INVALID_NUMBER, msg);
}
return (const char *)cur;
#endif
#undef return_err
}
/*==============================================================================
* MARK: - Incremental JSON Reader (Public)
*============================================================================*/
#if !YYJSON_DISABLE_INCR_READER
/* labels within yyjson_incr_read() to resume incremental parsing */
#define LABEL_doc_begin 0
#define LABEL_arr_val_begin 1
#define LABEL_arr_val_end 2
#define LABEL_obj_key_begin 3
#define LABEL_obj_key_end 4
#define LABEL_obj_val_begin 5
#define LABEL_obj_val_end 6
#define LABEL_doc_end 7
/** State for incremental JSON reader, opaque in the API. */
struct yyjson_incr_state {
u32 label; /* current parser goto label */
yyjson_alc alc; /* allocator */
yyjson_read_flag flg; /* read flags */
u8 *hdr; /* JSON data header */
u8 *cur; /* current position in JSON data */
usize buf_len; /* total buffer length (without padding) */
usize hdr_len; /* value count used by yyjson_doc */
usize alc_len; /* value count allocated */
usize ctn_len; /* the number of elements in current container */
yyjson_val *val_hdr; /* the head of allocated values */
yyjson_val *val_end; /* the end of allocated values */
yyjson_val *val; /* current JSON value */
yyjson_val *ctn; /* current container */
u8 *str_con[2]; /* string parser incremental state */
};
yyjson_incr_state *yyjson_incr_new(char *buf, size_t buf_len,
yyjson_read_flag flg,
const yyjson_alc *alc_ptr) {
yyjson_incr_state *state = NULL;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
/* remove non-standard flags */
flg &= ~YYJSON_READ_JSON5;
flg &= ~YYJSON_READ_ALLOW_BOM;
flg &= ~YYJSON_READ_ALLOW_INVALID_UNICODE;
if (unlikely(!buf)) return NULL;
if (unlikely(buf_len >= USIZE_MAX - YYJSON_PADDING_SIZE)) return NULL;
state = (yyjson_incr_state *)alc.malloc(alc.ctx, sizeof(*state));
if (!state) return NULL;
memset(state, 0, sizeof(yyjson_incr_state));
state->alc = alc;
state->flg = flg;
state->buf_len = buf_len;
/* add 4-byte zero padding for input data if necessary */
if (has_flg(INSITU)) {
state->hdr = (u8 *)buf;
} else {
state->hdr = (u8 *)alc.malloc(alc.ctx, buf_len + YYJSON_PADDING_SIZE);
if (unlikely(!state->hdr)) {
alc.free(alc.ctx, state);
return NULL;
}
memcpy(state->hdr, buf, buf_len);
}
memset(state->hdr + buf_len, 0, YYJSON_PADDING_SIZE);
state->cur = state->hdr;
state->label = LABEL_doc_begin;
return state;
}
void yyjson_incr_free(yyjson_incr_state *state) {
if (state) {
yyjson_alc alc = state->alc;
memset(&state->alc, 0, sizeof(alc));
if (state->val_hdr) {
alc.free(alc.ctx, (void *)state->val_hdr);
}
if (state->hdr && !(state->flg & YYJSON_READ_INSITU)) {
alc.free(alc.ctx, state->hdr);
}
alc.free(alc.ctx, state);
}
}
yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len,
yyjson_read_err *err) {
#define return_err_inv_param(_msg) do { \
err->pos = 0; \
err->msg = _msg; \
err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; \
return NULL; \
} while (false)
#define return_err(_pos, _code, _msg) do { \
if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code, flg)) { \
goto unexpected_end; \
} else { \
err->pos = (usize)(_pos - hdr); \
err->code = YYJSON_READ_ERROR_##_code; \
err->msg = _msg; \
} \
return NULL; \
} while (false)
#define val_incr() do { \
val++; \
if (unlikely(val >= val_end)) { \
usize alc_old = alc_len; \
alc_len += alc_len / 2; \
if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \
val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \
alc_old * sizeof(yyjson_val), \
alc_len * sizeof(yyjson_val)); \
if ((!val_tmp)) goto fail_alloc; \
val = val_tmp + (usize)(val - val_hdr); \
ctn = val_tmp + (usize)(ctn - val_hdr); \
state->val = val_tmp + (usize)(state->val - val_hdr); \
state->val_hdr = val_hdr = val_tmp; \
val_end = val_tmp + (alc_len - 2); \
state->val_end = val_end; \
} \
} while (false)
/* save position where it's possible to resume incremental parsing */
#define save_incr_state(_label) do { \
state->label = LABEL_##_label; \
state->cur = cur; \
state->val = val; \
state->ctn_len = ctn_len; \
state->hdr_len = hdr_len; \
if (unlikely(cur >= end)) goto unexpected_end; \
} while (false)
#define check_maybe_truncated_number() do { \
if (unlikely(cur >= end)) { \
if (unlikely(cur > state->cur + INCR_NUM_MAX_LEN)) { \
msg = "number too long"; \
goto fail_number; \
} \
goto unexpected_end; \
} \
} while (false)
u8 *hdr = NULL, *end = NULL, *cur = NULL;
yyjson_read_flag flg;
yyjson_alc alc;
usize dat_len; /* data length in bytes, hint for allocator */
usize hdr_len; /* value count used by yyjson_doc */
usize alc_len; /* value count allocated */
usize alc_max; /* maximum value count for allocator */
usize ctn_len; /* the number of elements in current container */
yyjson_val *val_hdr; /* the head of allocated values */
yyjson_val *val_end; /* the end of allocated values */
yyjson_val *val_tmp; /* temporary pointer for realloc */
yyjson_val *val; /* current JSON value */
yyjson_val *ctn; /* current container */
yyjson_val *ctn_parent; /* parent of current container */
yyjson_doc *doc; /* the JSON document, equals to val_hdr */
const char *msg; /* error message */
yyjson_read_err tmp_err;
u8 raw_end[1]; /* raw end for null-terminator */
u8 *raw_ptr = raw_end;
u8 **pre = &raw_ptr; /* previous raw end pointer */
u8 **con = NULL; /* for incremental string parsing */
u8 saved_end = '\0'; /* saved end char */
/* validate input parameters */
if (!err) err = &tmp_err;
if (unlikely(!state)) {
return_err_inv_param("input state is NULL");
}
if (unlikely(!len)) {
return_err_inv_param("input length is 0");
}
if (unlikely(len > state->buf_len)) {
return_err_inv_param("length is greater than total input length");
}
/* restore state saved from the previous call */
hdr = state->hdr;
end = state->hdr + len;
cur = state->cur;
flg = state->flg;
alc = state->alc;
ctn_len = state->ctn_len;
hdr_len = state->hdr_len;
alc_len = state->alc_len;
val = state->val;
val_hdr = state->val_hdr;
val_end = state->val_end;
ctn = state->ctn;
con = state->str_con;
alc_max = USIZE_MAX / sizeof(yyjson_val);
/* insert null terminator to make us stop at the specified end, even if
the data contains more valid JSON */
saved_end = *end;
*end = '\0';
/* resume parsing from the last save point */
switch (state->label) {
case LABEL_doc_begin: goto doc_begin;
case LABEL_arr_val_begin: goto arr_val_begin;
case LABEL_arr_val_end: goto arr_val_end;
case LABEL_obj_key_begin: goto obj_key_begin;
case LABEL_obj_key_end: goto obj_key_end;
case LABEL_obj_val_begin: goto obj_val_begin;
case LABEL_obj_val_end: goto obj_val_end;
case LABEL_doc_end: goto doc_end;
default: return_err_inv_param("invalid incremental state");
}
doc_begin:
/* skip empty contents before json document */
if (unlikely(!char_is_ctn(*cur))) {
while (char_is_space(*cur)) cur++;
if (unlikely(cur >= end)) goto unexpected_end; /* input data is empty */
}
/* allocate memory for document */
if (!val_hdr) {
hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val);
hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0;
if (likely(char_is_ctn(*cur))) {
dat_len = has_flg(STOP_WHEN_DONE) ? 256 : state->buf_len;
alc_len = hdr_len +
(dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4;
alc_len = yyjson_min(alc_len, alc_max);
} else {
alc_len = hdr_len + 1; /* single value */
}
val_hdr = (yyjson_val *)alc.malloc(alc.ctx,
alc_len * sizeof(yyjson_val));
if (unlikely(!val_hdr)) goto fail_alloc;
val_end = val_hdr + (alc_len - 2); /* padding for kv pair reading */
val = val_hdr + hdr_len;
ctn = val;
ctn_len = 0;
state->val_hdr = val_hdr;
state->val_end = val_end;
save_incr_state(doc_begin);
}
/* read json document */
if (*cur == '{') {
cur++;
ctn->tag = YYJSON_TYPE_OBJ;
ctn->uni.ofs = 0;
goto obj_key_begin;
}
if (*cur == '[') {
cur++;
ctn->tag = YYJSON_TYPE_ARR;
ctn->uni.ofs = 0;
goto arr_val_begin;
}
if (char_is_num(*cur)) {
if (likely(read_num(&cur, pre, flg, val, &msg))) goto doc_end;
goto fail_number;
}
if (*cur == '"') {
if (likely(read_str_con(&cur, end, flg, val, &msg, con))) goto doc_end;
goto fail_string;
}
if (*cur == 't') {
if (likely(read_true(&cur, val))) goto doc_end;
goto fail_literal_true;
}
if (*cur == 'f') {
if (likely(read_false(&cur, val))) goto doc_end;
goto fail_literal_false;
}
if (*cur == 'n') {
if (likely(read_null(&cur, val))) goto doc_end;
goto fail_literal_null;
}
msg = "unexpected character, expected a valid root value";
if (cur == hdr) {
/* RFC 8259: JSON text MUST be encoded using UTF-8 */
if (is_utf8_bom(hdr)) msg = MSG_ERR_BOM;
else if (len >= 4 && is_utf32_bom(hdr)) msg = MSG_ERR_UTF32;
else if (len >= 2 && is_utf16_bom(hdr)) msg = MSG_ERR_UTF16;
}
return_err(cur, UNEXPECTED_CHARACTER, msg);
arr_begin:
/* save current container */
ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) |
(ctn->tag & YYJSON_TAG_MASK);
/* create a new array value, save parent container offset */
val_incr();
val->tag = YYJSON_TYPE_ARR;
val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn);
/* push the new array value as current container */
ctn = val;
ctn_len = 0;
arr_val_begin:
save_incr_state(arr_val_begin);
arr_val_continue:
if (*cur == '{') {
cur++;
goto obj_begin;
}
if (*cur == '[') {
cur++;
goto arr_begin;
}
if (char_is_num(*cur)) {
val_incr();
ctn_len++;
if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_maybe_end;
goto fail_number;
}
if (*cur == '"') {
val_incr();
ctn_len++;
if (likely(read_str_con(&cur, end, flg, val, &msg, con)))
goto arr_val_end;
goto fail_string;
}
if (*cur == 't') {
val_incr();
ctn_len++;
if (likely(read_true(&cur, val))) goto arr_val_end;
goto fail_literal_true;
}
if (*cur == 'f') {
val_incr();
ctn_len++;
if (likely(read_false(&cur, val))) goto arr_val_end;
goto fail_literal_false;
}
if (*cur == 'n') {
val_incr();
ctn_len++;
if (likely(read_null(&cur, val))) goto arr_val_end;
goto fail_literal_null;
}
if (*cur == ']') {
cur++;
if (likely(ctn_len == 0)) goto arr_end;
while (*cur != ',') cur--;
goto fail_trailing_comma;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto arr_val_continue;
}
goto fail_character_val;
arr_val_maybe_end:
/* if incremental parsing stops in the middle of a number, it may continue
with more digits, so arr val maybe didn't end yet */
check_maybe_truncated_number();
arr_val_end:
save_incr_state(arr_val_end);
if (*cur == ',') {
cur++;
goto arr_val_begin;
}
if (*cur == ']') {
cur++;
goto arr_end;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto arr_val_end;
}
goto fail_character_arr_end;
arr_end:
/* get parent container */
ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs);
/* save the next sibling value offset */
ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val);
ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR;
if (unlikely(ctn == ctn_parent)) goto doc_end;
/* pop parent as current container */
ctn = ctn_parent;
ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT);
if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) {
goto obj_val_end;
} else {
goto arr_val_end;
}
obj_begin:
/* push container */
ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) |
(ctn->tag & YYJSON_TAG_MASK);
val_incr();
val->tag = YYJSON_TYPE_OBJ;
/* offset to the parent */
val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn);
ctn = val;
ctn_len = 0;
obj_key_begin:
save_incr_state(obj_key_begin);
obj_key_continue:
if (likely(*cur == '"')) {
val_incr();
ctn_len++;
if (likely(read_str_con(&cur, end, flg, val, &msg, con)))
goto obj_key_end;
goto fail_string;
}
if (likely(*cur == '}')) {
cur++;
if (likely(ctn_len == 0)) goto obj_end;
while (*cur != ',') cur--;
goto fail_trailing_comma;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_key_continue;
}
goto fail_character_obj_key;
obj_key_end:
save_incr_state(obj_key_end);
if (*cur == ':') {
cur++;
goto obj_val_begin;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_key_end;
}
goto fail_character_obj_sep;
obj_val_begin:
save_incr_state(obj_val_begin);
obj_val_continue:
if (*cur == '"') {
val++;
ctn_len++;
if (likely(read_str_con(&cur, end, flg, val, &msg, con)))
goto obj_val_end;
goto fail_string;
}
if (char_is_num(*cur)) {
val++;
ctn_len++;
if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_maybe_end;
goto fail_number;
}
if (*cur == '{') {
cur++;
goto obj_begin;
}
if (*cur == '[') {
cur++;
goto arr_begin;
}
if (*cur == 't') {
val++;
ctn_len++;
if (likely(read_true(&cur, val))) goto obj_val_end;
goto fail_literal_true;
}
if (*cur == 'f') {
val++;
ctn_len++;
if (likely(read_false(&cur, val))) goto obj_val_end;
goto fail_literal_false;
}
if (*cur == 'n') {
val++;
ctn_len++;
if (likely(read_null(&cur, val))) goto obj_val_end;
goto fail_literal_null;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_val_continue;
}
goto fail_character_val;
obj_val_maybe_end:
/* if incremental parsing stops in the middle of a number, it may continue
with more digits, so obj val maybe didn't end yet */
check_maybe_truncated_number();
obj_val_end:
save_incr_state(obj_val_end);
if (likely(*cur == ',')) {
cur++;
goto obj_key_begin;
}
if (likely(*cur == '}')) {
cur++;
goto obj_end;
}
if (char_is_space(*cur)) {
while (char_is_space(*++cur));
goto obj_val_end;
}
goto fail_character_obj_end;
obj_end:
/* pop container */
ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs);
/* point to the next value */
ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val);
ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ;
if (unlikely(ctn == ctn_parent)) goto doc_end;
ctn = ctn_parent;
ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT);
if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) {
goto obj_val_end;
} else {
goto arr_val_end;
}
doc_end:
/* check invalid contents after json document */
if (unlikely(cur < end) && !has_flg(STOP_WHEN_DONE)) {
save_incr_state(doc_end);
while (char_is_space(*cur)) cur++;
if (unlikely(cur < end)) goto fail_garbage;
}
**pre = '\0';
doc = (yyjson_doc *)val_hdr;
doc->root = val_hdr + hdr_len;
doc->alc = alc;
doc->dat_read = (usize)(cur - hdr);
doc->val_read = (usize)((val - doc->root) + 1);
doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr;
state->hdr = NULL;
state->val_hdr = NULL;
memset(err, 0, sizeof(yyjson_read_err));
return doc;
unexpected_end:
err->pos = len;
/* if no nore data, stop the incr read */
if (unlikely(len >= state->buf_len)) {
err->code = YYJSON_READ_ERROR_UNEXPECTED_END;
err->msg = MSG_NOT_END;
return NULL;
}
/* save parser state in extended error struct, in addition to what was
* stored in the last save_incr_state */
err->code = YYJSON_READ_ERROR_MORE;
err->msg = "need more data";
state->val_end = val_end;
state->ctn = ctn;
state->alc_len = alc_len;
/* restore the end where we've inserted a null terminator */
*end = saved_end;
return NULL;
fail_string: return_err(cur, INVALID_STRING, msg);
fail_number: return_err(cur, INVALID_NUMBER, msg);
fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC);
fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA);
fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T);
fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F);
fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N);
fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR);
fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END);
fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY);
fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP);
fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END);
fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE);
#undef val_incr
#undef return_err
#undef return_err_inv_param
#undef save_incr_state
#undef check_maybe_truncated_number
}
#endif /* YYJSON_DISABLE_INCR_READER */
#undef has_flg
#undef has_allow
#endif /* YYJSON_DISABLE_READER */
#if !YYJSON_DISABLE_WRITER /* writer begin */
/* Check write flag, avoids `always false` warning when disabled. */
#define has_flg(_flg) unlikely(has_wflag(flg, YYJSON_WRITE_##_flg, 0))
#define has_allow(_flg) unlikely(has_wflag(flg, YYJSON_WRITE_ALLOW_##_flg, 1))
static_inline bool has_wflag(yyjson_write_flag flg, yyjson_write_flag chk,
bool non_standard) {
#if YYJSON_DISABLE_NON_STANDARD
if (non_standard) return false;
#endif
return (flg & chk) != 0;
}
/*==============================================================================
* MARK: - Integer Writer (Private)
*
* The maximum value of uint32_t is 4294967295 (10 digits),
* these digits are named as 'aabbccddee' here.
*
* Although most compilers may convert the "division by constant value" into
* "multiply and shift", manual conversion can still help some compilers
* generate fewer and better instructions.
*
* Reference:
* Division by Invariant Integers using Multiplication, 1994.
* https://gmplib.org/~tege/divcnst-pldi94.pdf
* Improved division by invariant integers, 2011.
* https://gmplib.org/~tege/division-paper.pdf
*============================================================================*/
/** Digit table from 00 to 99. */
yyjson_align(2)
static const char digit_table[200] = {
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4',
'0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
'1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
'1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
'2', '0', '2', '1', '2', '2', '2', '3', '2', '4',
'2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4',
'3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
'4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
'4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
'5', '0', '5', '1', '5', '2', '5', '3', '5', '4',
'5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4',
'6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
'7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
'7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
'8', '0', '8', '1', '8', '2', '8', '3', '8', '4',
'8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4',
'9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
};
static_inline u8 *write_u32_len_8(u32 val, u8 *buf) {
u32 aa, bb, cc, dd, aabb, ccdd; /* 8 digits: aabbccdd */
aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */
ccdd = val - aabb * 10000; /* (val % 10000) */
aa = (aabb * 5243) >> 19; /* (aabb / 100) */
cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */
bb = aabb - aa * 100; /* (aabb % 100) */
dd = ccdd - cc * 100; /* (ccdd % 100) */
byte_copy_2(buf + 0, digit_table + aa * 2);
byte_copy_2(buf + 2, digit_table + bb * 2);
byte_copy_2(buf + 4, digit_table + cc * 2);
byte_copy_2(buf + 6, digit_table + dd * 2);
return buf + 8;
}
static_inline u8 *write_u32_len_4(u32 val, u8 *buf) {
u32 aa, bb; /* 4 digits: aabb */
aa = (val * 5243) >> 19; /* (val / 100) */
bb = val - aa * 100; /* (val % 100) */
byte_copy_2(buf + 0, digit_table + aa * 2);
byte_copy_2(buf + 2, digit_table + bb * 2);
return buf + 4;
}
static_inline u8 *write_u32_len_1_to_8(u32 val, u8 *buf) {
u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz;
if (val < 100) { /* 1-2 digits: aa */
lz = val < 10; /* leading zero: 0 or 1 */
byte_copy_2(buf + 0, digit_table + val * 2 + lz);
buf -= lz;
return buf + 2;
} else if (val < 10000) { /* 3-4 digits: aabb */
aa = (val * 5243) >> 19; /* (val / 100) */
bb = val - aa * 100; /* (val % 100) */
lz = aa < 10; /* leading zero: 0 or 1 */
byte_copy_2(buf + 0, digit_table + aa * 2 + lz);
buf -= lz;
byte_copy_2(buf + 2, digit_table + bb * 2);
return buf + 4;
} else if (val < 1000000) { /* 5-6 digits: aabbcc */
aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */
bbcc = val - aa * 10000; /* (val % 10000) */
bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */
cc = bbcc - bb * 100; /* (bbcc % 100) */
lz = aa < 10; /* leading zero: 0 or 1 */
byte_copy_2(buf + 0, digit_table + aa * 2 + lz);
buf -= lz;
byte_copy_2(buf + 2, digit_table + bb * 2);
byte_copy_2(buf + 4, digit_table + cc * 2);
return buf + 6;
} else { /* 7-8 digits: aabbccdd */
aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */
ccdd = val - aabb * 10000; /* (val % 10000) */
aa = (aabb * 5243) >> 19; /* (aabb / 100) */
cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */
bb = aabb - aa * 100; /* (aabb % 100) */
dd = ccdd - cc * 100; /* (ccdd % 100) */
lz = aa < 10; /* leading zero: 0 or 1 */
byte_copy_2(buf + 0, digit_table + aa * 2 + lz);
buf -= lz;
byte_copy_2(buf + 2, digit_table + bb * 2);
byte_copy_2(buf + 4, digit_table + cc * 2);
byte_copy_2(buf + 6, digit_table + dd * 2);
return buf + 8;
}
}
static_inline u8 *write_u32_len_5_to_8(u32 val, u8 *buf) {
u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz;
if (val < 1000000) { /* 5-6 digits: aabbcc */
aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */
bbcc = val - aa * 10000; /* (val % 10000) */
bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */
cc = bbcc - bb * 100; /* (bbcc % 100) */
lz = aa < 10; /* leading zero: 0 or 1 */
byte_copy_2(buf + 0, digit_table + aa * 2 + lz);
buf -= lz;
byte_copy_2(buf + 2, digit_table + bb * 2);
byte_copy_2(buf + 4, digit_table + cc * 2);
return buf + 6;
} else { /* 7-8 digits: aabbccdd */
aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */
ccdd = val - aabb * 10000; /* (val % 10000) */
aa = (aabb * 5243) >> 19; /* (aabb / 100) */
cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */
bb = aabb - aa * 100; /* (aabb % 100) */
dd = ccdd - cc * 100; /* (ccdd % 100) */
lz = aa < 10; /* leading zero: 0 or 1 */
byte_copy_2(buf + 0, digit_table + aa * 2 + lz);
buf -= lz;
byte_copy_2(buf + 2, digit_table + bb * 2);
byte_copy_2(buf + 4, digit_table + cc * 2);
byte_copy_2(buf + 6, digit_table + dd * 2);
return buf + 8;
}
}
static_inline u8 *write_u64(u64 val, u8 *buf) {
u64 tmp, hgh;
u32 mid, low;
if (val < 100000000) { /* 1-8 digits */
buf = write_u32_len_1_to_8((u32)val, buf);
return buf;
} else if (val < (u64)100000000 * 100000000) { /* 9-16 digits */
hgh = val / 100000000; /* (val / 100000000) */
low = (u32)(val - hgh * 100000000); /* (val % 100000000) */
buf = write_u32_len_1_to_8((u32)hgh, buf);
buf = write_u32_len_8(low, buf);
return buf;
} else { /* 17-20 digits */
tmp = val / 100000000; /* (val / 100000000) */
low = (u32)(val - tmp * 100000000); /* (val % 100000000) */
hgh = (u32)(tmp / 10000); /* (tmp / 10000) */
mid = (u32)(tmp - hgh * 10000); /* (tmp % 10000) */
buf = write_u32_len_5_to_8((u32)hgh, buf);
buf = write_u32_len_4(mid, buf);
buf = write_u32_len_8(low, buf);
return buf;
}
}
/*==============================================================================
* MARK: - Number Writer (Private)
*============================================================================*/
#if !YYJSON_DISABLE_FAST_FP_CONV /* FP_WRITER */
/** Trailing zero count table for number 0 to 99.
(generate with misc/make_tables.c) */
static const u8 dec_trailing_zero_table[] = {
2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static_inline u8 *write_u64_len_1_to_16(u64 val, u8 *buf) {
u64 hgh;
u32 low;
if (val < 100000000) { /* 1-8 digits */
buf = write_u32_len_1_to_8((u32)val, buf);
return buf;
} else { /* 9-16 digits */
hgh = val / 100000000; /* (val / 100000000) */
low = (u32)(val - hgh * 100000000); /* (val % 100000000) */
buf = write_u32_len_1_to_8((u32)hgh, buf);
buf = write_u32_len_8(low, buf);
return buf;
}
}
static_inline u8 *write_u64_len_1_to_17(u64 val, u8 *buf) {
u64 hgh;
u32 mid, low, one;
if (val >= (u64)100000000 * 10000000) { /* len: 16 to 17 */
hgh = val / 100000000; /* (val / 100000000) */
low = (u32)(val - hgh * 100000000); /* (val % 100000000) */
one = (u32)(hgh / 100000000); /* (hgh / 100000000) */
mid = (u32)(hgh - (u64)one * 100000000); /* (hgh % 100000000) */
*buf = (u8)((u8)one + (u8)'0');
buf += one > 0;
buf = write_u32_len_8(mid, buf);
buf = write_u32_len_8(low, buf);
return buf;
} else if (val >= (u64)100000000){ /* len: 9 to 15 */
hgh = val / 100000000; /* (val / 100000000) */
low = (u32)(val - hgh * 100000000); /* (val % 100000000) */
buf = write_u32_len_1_to_8((u32)hgh, buf);
buf = write_u32_len_8(low, buf);
return buf;
} else { /* len: 1 to 8 */
buf = write_u32_len_1_to_8((u32)val, buf);
return buf;
}
}
/**
Write an unsigned integer with a length of 7 to 9 with trailing zero trimmed.
These digits are named as "abbccddee" here.
For example, input 123456000, output "123456".
*/
static_inline u8 *write_u32_len_7_to_9_trim(u32 val, u8 *buf) {
bool lz;
u32 tz, tz1, tz2;
u32 abbcc = val / 10000; /* (abbccddee / 10000) */
u32 ddee = val - abbcc * 10000; /* (abbccddee % 10000) */
u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */
u32 a = (abb * 41) >> 12; /* (abb / 100) */
u32 bb = abb - a * 100; /* (abb % 100) */
u32 cc = abbcc - abb * 100; /* (abbcc % 100) */
/* write abbcc */
buf[0] = (u8)(a + '0');
buf += a > 0;
lz = bb < 10 && a == 0;
byte_copy_2(buf + 0, digit_table + bb * 2 + lz);
buf -= lz;
byte_copy_2(buf + 2, digit_table + cc * 2);
if (ddee) {
u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */
u32 ee = ddee - dd * 100; /* (ddee % 100) */
byte_copy_2(buf + 4, digit_table + dd * 2);
byte_copy_2(buf + 6, digit_table + ee * 2);
tz1 = dec_trailing_zero_table[dd];
tz2 = dec_trailing_zero_table[ee];
tz = ee ? tz2 : (tz1 + 2);
buf += 8 - tz;
return buf;
} else {
tz1 = dec_trailing_zero_table[bb];
tz2 = dec_trailing_zero_table[cc];
tz = cc ? tz2 : (tz1 + tz2);
buf += 4 - tz;
return buf;
}
}
/**
Write an unsigned integer with a length of 16 or 17 with trailing zero trimmed.
These digits are named as "abbccddeeffgghhii" here.
For example, input 1234567890123000, output "1234567890123".
*/
static_inline u8 *write_u64_len_16_to_17_trim(u64 val, u8 *buf) {
u32 tz, tz1, tz2;
u32 abbccddee = (u32)(val / 100000000);
u32 ffgghhii = (u32)(val - (u64)abbccddee * 100000000);
u32 abbcc = abbccddee / 10000;
u32 ddee = abbccddee - abbcc * 10000;
u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */
u32 a = (abb * 41) >> 12; /* (abb / 100) */
u32 bb = abb - a * 100; /* (abb % 100) */
u32 cc = abbcc - abb * 100; /* (abbcc % 100) */
buf[0] = (u8)(a + '0');
buf += a > 0;
byte_copy_2(buf + 0, digit_table + bb * 2);
byte_copy_2(buf + 2, digit_table + cc * 2);
if (ffgghhii) {
u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */
u32 ee = ddee - dd * 100; /* (ddee % 100) */
u32 ffgg = (u32)(((u64)ffgghhii * 109951163) >> 40); /* (val / 10000) */
u32 hhii = ffgghhii - ffgg * 10000; /* (val % 10000) */
u32 ff = (ffgg * 5243) >> 19; /* (aabb / 100) */
u32 gg = ffgg - ff * 100; /* (aabb % 100) */
byte_copy_2(buf + 4, digit_table + dd * 2);
byte_copy_2(buf + 6, digit_table + ee * 2);
byte_copy_2(buf + 8, digit_table + ff * 2);
byte_copy_2(buf + 10, digit_table + gg * 2);
if (hhii) {
u32 hh = (hhii * 5243) >> 19; /* (ccdd / 100) */
u32 ii = hhii - hh * 100; /* (ccdd % 100) */
byte_copy_2(buf + 12, digit_table + hh * 2);
byte_copy_2(buf + 14, digit_table + ii * 2);
tz1 = dec_trailing_zero_table[hh];
tz2 = dec_trailing_zero_table[ii];
tz = ii ? tz2 : (tz1 + 2);
return buf + 16 - tz;
} else {
tz1 = dec_trailing_zero_table[ff];
tz2 = dec_trailing_zero_table[gg];
tz = gg ? tz2 : (tz1 + 2);
return buf + 12 - tz;
}
} else {
if (ddee) {
u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */
u32 ee = ddee - dd * 100; /* (ddee % 100) */
byte_copy_2(buf + 4, digit_table + dd * 2);
byte_copy_2(buf + 6, digit_table + ee * 2);
tz1 = dec_trailing_zero_table[dd];
tz2 = dec_trailing_zero_table[ee];
tz = ee ? tz2 : (tz1 + 2);
return buf + 8 - tz;
} else {
tz1 = dec_trailing_zero_table[bb];
tz2 = dec_trailing_zero_table[cc];
tz = cc ? tz2 : (tz1 + tz2);
return buf + 4 - tz;
}
}
}
/** Write exponent part in range `e-45` to `e38`. */
static_inline u8 *write_f32_exp(i32 exp, u8 *buf) {
bool lz;
byte_copy_2(buf, "e-");
buf += 2 - (exp >= 0);
exp = exp < 0 ? -exp : exp;
lz = exp < 10;
byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz);
return buf + 2 - lz;
}
/** Write exponent part in range `e-324` to `e308`. */
static_inline u8 *write_f64_exp(i32 exp, u8 *buf) {
byte_copy_2(buf, "e-");
buf += 2 - (exp >= 0);
exp = exp < 0 ? -exp : exp;
if (exp < 100) {
bool lz = exp < 10;
byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz);
return buf + 2 - lz;
} else {
u32 hi = ((u32)exp * 656) >> 16; /* exp / 100 */
u32 lo = (u32)exp - hi * 100; /* exp % 100 */
buf[0] = (u8)((u8)hi + (u8)'0');
byte_copy_2(buf + 1, digit_table + lo * 2);
return buf + 3;
}
}
/** Magic number for fast `divide by power of 10`. */
typedef struct {
u64 p10, mul;
u32 shr1, shr2;
} div_pow10_magic;
/** Generated with llvm, see https://github.com/llvm/llvm-project/
blob/main/llvm/lib/Support/DivisionByConstantInfo.cpp */
static const div_pow10_magic div_pow10_table[] = {
{ U64(0x00000000, 0x00000001), U64(0x00000000, 0x00000000), 0, 0 },
{ U64(0x00000000, 0x0000000A), U64(0xCCCCCCCC, 0xCCCCCCCD), 0, 3 },
{ U64(0x00000000, 0x00000064), U64(0x28F5C28F, 0x5C28F5C3), 2, 2 },
{ U64(0x00000000, 0x000003E8), U64(0x20C49BA5, 0xE353F7CF), 3, 4 },
{ U64(0x00000000, 0x00002710), U64(0x346DC5D6, 0x3886594B), 0, 11 },
{ U64(0x00000000, 0x000186A0), U64(0x0A7C5AC4, 0x71B47843), 5, 7 },
{ U64(0x00000000, 0x000F4240), U64(0x431BDE82, 0xD7B634DB), 0, 18 },
{ U64(0x00000000, 0x00989680), U64(0xD6BF94D5, 0xE57A42BD), 0, 23 },
{ U64(0x00000000, 0x05F5E100), U64(0xABCC7711, 0x8461CEFD), 0, 26 },
{ U64(0x00000000, 0x3B9ACA00), U64(0x0044B82F, 0xA09B5A53), 9, 11 },
{ U64(0x00000002, 0x540BE400), U64(0xDBE6FECE, 0xBDEDD5BF), 0, 33 },
{ U64(0x00000017, 0x4876E800), U64(0xAFEBFF0B, 0xCB24AAFF), 0, 36 },
{ U64(0x000000E8, 0xD4A51000), U64(0x232F3302, 0x5BD42233), 0, 37 },
{ U64(0x00000918, 0x4E72A000), U64(0x384B84D0, 0x92ED0385), 0, 41 },
{ U64(0x00005AF3, 0x107A4000), U64(0x0B424DC3, 0x5095CD81), 0, 42 },
{ U64(0x00038D7E, 0xA4C68000), U64(0x00024075, 0xF3DCEAC3), 15, 20 },
{ U64(0x002386F2, 0x6FC10000), U64(0x39A5652F, 0xB1137857), 0, 51 },
{ U64(0x01634578, 0x5D8A0000), U64(0x00005C3B, 0xD5191B53), 17, 22 },
{ U64(0x0DE0B6B3, 0xA7640000), U64(0x000049C9, 0x7747490F), 18, 24 },
{ U64(0x8AC72304, 0x89E80000), U64(0x760F253E, 0xDB4AB0d3), 0, 62 },
};
/** Divide a number by power of 10. */
static_inline void div_pow10(u64 num, u32 exp, u64 *div, u64 *mod, u64 *p10) {
u64 hi, lo;
div_pow10_magic m = div_pow10_table[exp];
u128_mul(num >> m.shr1, m.mul, &hi, &lo);
*div = hi >> m.shr2;
*mod = num - (*div * m.p10);
*p10 = m.p10;
}
/** Multiplies 64-bit integer and returns highest 64-bit rounded value. */
static_inline u32 u64_round_to_odd(u64 u, u32 cp) {
u64 hi, lo;
u32 y_hi, y_lo;
u128_mul(cp, u, &hi, &lo);
y_hi = (u32)hi;
y_lo = (u32)(lo >> 32);
return y_hi | (y_lo > 1);
}
/** Multiplies 128-bit integer and returns highest 64-bit rounded value. */
static_inline u64 u128_round_to_odd(u64 hi, u64 lo, u64 cp) {
u64 x_hi, x_lo, y_hi, y_lo;
u128_mul(cp, lo, &x_hi, &x_lo);
u128_mul_add(cp, hi, x_hi, &y_hi, &y_lo);
return y_hi | (y_lo > 1);
}
/** Convert f32 from binary to decimal (shortest but may have trailing zeros).
The input should not be 0, inf or nan. */
static_inline void f32_bin_to_dec(u32 sig_raw, u32 exp_raw,
u32 sig_bin, i32 exp_bin,
u32 *sig_dec, i32 *exp_dec) {
bool is_even, irregular, round_up, trim;
bool u0_inside, u1_inside, w0_inside, w1_inside;
u64 p10_hi, p10_lo, hi, lo;
u32 s, sp, cb, cbl, cbr, vb, vbl, vbr, upper, lower, mid;
i32 k, h;
/* Fast path, see f64_bin_to_dec(). */
while (likely(sig_raw)) {
u32 mod, dec, add_1, add_10, s_hi, s_lo;
u32 c, half_ulp, t0, t1;
/* k = floor(exp_bin * log10(2)); */
/* h = exp_bin + floor(log2(10) * -k); (h = 0/1/2/3) */
k = (i32)(exp_bin * 315653) >> 20;
h = exp_bin + ((-k * 217707) >> 16);
pow10_table_get_sig(-k, &p10_hi, &p10_lo);
/* sig_bin << (1/2/3/4) */
cb = sig_bin << (h + 1);
u128_mul(cb, p10_hi, &hi, &lo);
s_hi = (u32)(hi);
s_lo = (u32)(lo >> 32);
mod = s_hi % 10;
dec = s_hi - mod;
/* right shift 4 to fit in u32 */
c = (mod << (32 - 4)) | (s_lo >> 4);
half_ulp = (u32)(p10_hi >> (32 + 4 - h));
/* check w1, u0, w0 range */
w1_inside = (s_lo >= ((u32)1 << 31));
if (unlikely(s_lo == ((u32)1 << 31))) break;
u0_inside = (half_ulp >= c);
if (unlikely(half_ulp == c)) break;
t0 = (u32)10 << (32 - 4);
t1 = c + half_ulp;
w0_inside = (t1 >= t0);
if (unlikely(t0 - t1 <= (u32)1)) break;
trim = (u0_inside | w0_inside);
add_10 = (w0_inside ? 10 : 0);
add_1 = mod + w1_inside;
*sig_dec = dec + (trim ? add_10 : add_1);
*exp_dec = k;
return;
}
/* Schubfach algorithm, see f64_bin_to_dec(). */
irregular = (sig_raw == 0 && exp_raw > 1);
is_even = !(sig_bin & 1);
cbl = 4 * sig_bin - 2 + irregular;
cb = 4 * sig_bin;
cbr = 4 * sig_bin + 2;
/* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */
/* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */
k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20;
h = exp_bin + ((-k * 217707) >> 16) + 1;
pow10_table_get_sig(-k, &p10_hi, &p10_lo);
p10_hi += 1;
vbl = u64_round_to_odd(p10_hi, cbl << h);
vb = u64_round_to_odd(p10_hi, cb << h);
vbr = u64_round_to_odd(p10_hi, cbr << h);
lower = vbl + !is_even;
upper = vbr - !is_even;
s = vb / 4;
if (s >= 10) {
sp = s / 10;
u0_inside = (lower <= 40 * sp);
w0_inside = (upper >= 40 * sp + 40);
if (u0_inside != w0_inside) {
*sig_dec = sp * 10 + (w0_inside ? 10 : 0);
*exp_dec = k;
return;
}
}
u1_inside = (lower <= 4 * s);
w1_inside = (upper >= 4 * s + 4);
mid = 4 * s + 2;
round_up = (vb > mid) || (vb == mid && (s & 1) != 0);
*sig_dec = s + ((u1_inside != w1_inside) ? w1_inside : round_up);
*exp_dec = k;
}
/** Convert f64 from binary to decimal (shortest but may have trailing zeros).
The input should not be 0, inf or nan. */
static_inline void f64_bin_to_dec(u64 sig_raw, u32 exp_raw,
u64 sig_bin, i32 exp_bin,
u64 *sig_dec, i32 *exp_dec) {
bool is_even, irregular, round_up, trim;
bool u0_inside, u1_inside, w0_inside, w1_inside;
u64 s, sp, cb, cbl, cbr, vb, vbl, vbr, p10_hi, p10_lo, upper, lower, mid;
i32 k, h;
/*
Fast path:
For regular spacing significand 'c', there are 4 candidates:
u0 u1 c w1 w0
----|----|----|----|----|-*--|----|----|----|----|----|----|----|----
9 0 1 2 3 4 5 6 7 8 9 0 1
|___________________|___________________|
1ulp
The `1ulp` is in the range [1.0, 10.0).
If (c - 0.5ulp < u0), trim the last digit and round down.
If (c + 0.5ulp > w0), trim the last digit and round up.
If (c - 0.5ulp < u1), round down.
If (c + 0.5ulp > w1), round up.
*/
while (likely(sig_raw)) {
u64 mod, dec, add_1, add_10, s_hi, s_lo;
u64 c, half_ulp, t0, t1;
/* k = floor(exp_bin * log10(2)); */
/* h = exp_bin + floor(log2(10) * -k); (h = 0/1/2/3) */
k = (i32)(exp_bin * 315653) >> 20;
h = exp_bin + ((-k * 217707) >> 16);
pow10_table_get_sig(-k, &p10_hi, &p10_lo);
/* sig_bin << (1/2/3/4) */
cb = sig_bin << (h + 1);
u128_mul(cb, p10_lo, &s_hi, &s_lo);
u128_mul_add(cb, p10_hi, s_hi, &s_hi, &s_lo);
mod = s_hi % 10;
dec = s_hi - mod;
/* right shift 4 to fit in u64 */
c = (mod << (64 - 4)) | (s_lo >> 4);
half_ulp = p10_hi >> (4 - h);
/* check w1, u0, w0 range */
w1_inside = (s_lo >= ((u64)1 << 63));
if (unlikely(s_lo == ((u64)1 << 63))) break;
u0_inside = (half_ulp >= c);
if (unlikely(half_ulp == c)) break;
t0 = ((u64)10 << (64 - 4));
t1 = c + half_ulp;
w0_inside = (t1 >= t0);
if (unlikely(t0 - t1 <= (u64)1)) break;
trim = (u0_inside | w0_inside);
add_10 = (w0_inside ? 10 : 0);
add_1 = mod + w1_inside;
*sig_dec = dec + (trim ? add_10 : add_1);
*exp_dec = k;
return;
}
/*
Schubfach algorithm:
Raffaello Giulietti, The Schubfach way to render doubles, 2022.
https://drive.google.com/file/d/1gp5xv4CAa78SVgCeWfGqqI4FfYYYuNFb (Paper)
https://github.com/openjdk/jdk/pull/3402 (Java implementation)
https://github.com/abolz/Drachennest (C++ implementation)
*/
irregular = (sig_raw == 0 && exp_raw > 1);
is_even = !(sig_bin & 1);
cbl = 4 * sig_bin - 2 + irregular;
cb = 4 * sig_bin;
cbr = 4 * sig_bin + 2;
/* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */
/* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */
k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20;
h = exp_bin + ((-k * 217707) >> 16) + 1;
pow10_table_get_sig(-k, &p10_hi, &p10_lo);
p10_lo += 1;
vbl = u128_round_to_odd(p10_hi, p10_lo, cbl << h);
vb = u128_round_to_odd(p10_hi, p10_lo, cb << h);
vbr = u128_round_to_odd(p10_hi, p10_lo, cbr << h);
lower = vbl + !is_even;
upper = vbr - !is_even;
s = vb / 4;
if (s >= 10) {
sp = s / 10;
u0_inside = (lower <= 40 * sp);
w0_inside = (upper >= 40 * sp + 40);
if (u0_inside != w0_inside) {
*sig_dec = sp * 10 + (w0_inside ? 10 : 0);
*exp_dec = k;
return;
}
}
u1_inside = (lower <= 4 * s);
w1_inside = (upper >= 4 * s + 4);
mid = 4 * s + 2;
round_up = (vb > mid) || (vb == mid && (s & 1) != 0);
*sig_dec = s + ((u1_inside != w1_inside) ? w1_inside : round_up);
*exp_dec = k;
}
/** Convert f64 from binary to decimal (fast but not the shortest).
The input should not be 0, inf, nan. */
static_inline void f64_bin_to_dec_fast(u64 sig_raw, u32 exp_raw,
u64 sig_bin, i32 exp_bin,
u64 *sig_dec, i32 *exp_dec,
bool *round_up) {
u64 cb, p10_hi, p10_lo, s_hi, s_lo;
i32 k, h;
bool irregular, u;
irregular = (sig_raw == 0 && exp_raw > 1);
/* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */
/* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */
k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20;
h = exp_bin + ((-k * 217707) >> 16);
pow10_table_get_sig(-k, &p10_hi, &p10_lo);
/* sig_bin << (1/2/3/4) */
cb = sig_bin << (h + 1);
u128_mul(cb, p10_lo, &s_hi, &s_lo);
u128_mul_add(cb, p10_hi, s_hi, &s_hi, &s_lo);
/* round up */
u = s_lo >= (irregular ? U64(0x55555555, 0x55555555) : ((u64)1 << 63));
*sig_dec = s_hi + u;
*exp_dec = k;
*round_up = u;
return;
}
/** Write inf/nan if allowed. */
static_inline u8 *write_inf_or_nan(u8 *buf, yyjson_write_flag flg,
u64 sig_raw, bool sign) {
if (has_flg(INF_AND_NAN_AS_NULL)) {
byte_copy_4(buf, "null");
return buf + 4;
}
if (has_allow(INF_AND_NAN)) {
if (sig_raw == 0) {
buf[0] = '-';
buf += sign;
byte_copy_8(buf, "Infinity");
return buf + 8;
} else {
byte_copy_4(buf, "NaN");
return buf + 3;
}
}
return NULL;
}
/**
Write a float number (requires 40 bytes buffer).
We follow the ECMAScript specification for printing floating-point numbers,
similar to `Number.prototype.toString()`, but with the following changes:
1. Keep the negative sign of `-0.0` to preserve input information.
2. Keep decimal point to indicate the number is floating point.
3. Remove positive sign in the exponent part.
*/
static_noinline u8 *write_f32_raw(u8 *buf, u64 raw_f64,
yyjson_write_flag flg) {
u32 sig_bin, sig_dec, sig_raw;
i32 exp_bin, exp_dec, sig_len, dot_ofs;
u32 exp_raw, raw;
u8 *end;
bool sign;
/* cast double to float */
raw = f32_to_bits(f64_to_f32(f64_from_bits(raw_f64)));
/* decode raw bytes from IEEE-754 double format. */
sign = (bool)(raw >> (F32_BITS - 1));
sig_raw = raw & F32_SIG_MASK;
exp_raw = (raw & F32_EXP_MASK) >> F32_SIG_BITS;
/* return inf or nan */
if (unlikely(exp_raw == ((u32)1 << F32_EXP_BITS) - 1)) {
return write_inf_or_nan(buf, flg, sig_raw, sign);
}
/* add sign for all finite number */
buf[0] = '-';
buf += sign;
/* return zero */
if ((raw << 1) == 0) {
byte_copy_4(buf, "0.0");
return buf + 3;
}
if (likely(exp_raw != 0)) {
/* normal number */
sig_bin = sig_raw | ((u32)1 << F32_SIG_BITS);
exp_bin = (i32)exp_raw - F32_EXP_BIAS - F32_SIG_BITS;
/* fast path for small integer number without fraction */
if ((-F32_SIG_BITS <= exp_bin && exp_bin <= 0) &&
(u64_tz_bits(sig_bin) >= (u32)-exp_bin)) {
sig_dec = sig_bin >> -exp_bin; /* range: [1, 0xFFFFFF] */
buf = write_u32_len_1_to_8(sig_dec, buf);
byte_copy_2(buf, ".0");
return buf + 2;
}
/* binary to decimal */
f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec);
/* the sig length is 7 or 9 */
sig_len = 7 + (sig_dec >= (u32)10000000) + (sig_dec >= (u32)100000000);
/* the decimal point offset relative to the first digit */
dot_ofs = sig_len + exp_dec;
if (-6 < dot_ofs && dot_ofs <= 21) {
i32 num_sep_pos, dot_set_pos, pre_ofs;
u8 *num_hdr, *num_end, *num_sep, *dot_end;
bool no_pre_zero;
/* fill zeros */
memset(buf, '0', 32);
/* not prefixed with zero, e.g. 1.234, 1234.0 */
no_pre_zero = (dot_ofs > 0);
/* write the number as digits */
pre_ofs = no_pre_zero ? 0 : (2 - dot_ofs);
num_hdr = buf + pre_ofs;
num_end = write_u32_len_7_to_9_trim(sig_dec, num_hdr);
/* seperate these digits to leave a space for dot */
num_sep_pos = no_pre_zero ? dot_ofs : 0;
num_sep = num_hdr + num_sep_pos;
byte_move_8(num_sep + no_pre_zero, num_sep);
num_end += no_pre_zero;
/* write the dot */
dot_set_pos = yyjson_max(dot_ofs, 1);
buf[dot_set_pos] = '.';
/* return the ending */
dot_end = buf + dot_ofs + 2;
return yyjson_max(dot_end, num_end);
} else {
/* write with scientific notation, e.g. 1.234e56 */
end = write_u32_len_7_to_9_trim(sig_dec, buf + 1);
end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */
exp_dec += sig_len - 1;
buf[0] = buf[1];
buf[1] = '.';
return write_f32_exp(exp_dec, end);
}
} else {
/* subnormal number */
sig_bin = sig_raw;
exp_bin = 1 - F32_EXP_BIAS - F32_SIG_BITS;
/* binary to decimal */
f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec);
/* write significand part */
end = write_u32_len_1_to_8(sig_dec, buf + 1);
buf[0] = buf[1];
buf[1] = '.';
exp_dec += (i32)(end - buf) - 2;
/* trim trailing zeros */
end -= *(end - 1) == '0'; /* branchless for last zero */
end -= *(end - 1) == '0'; /* branchless for second last zero */
while (*(end - 1) == '0') end--; /* for unlikely more zeros */
end -= *(end - 1) == '.'; /* remove dot, e.g. 2.e-321 -> 2e-321 */
/* write exponent part */
return write_f32_exp(exp_dec, end);
}
}
/**
Write a double number (requires 40 bytes buffer).
We follow the ECMAScript specification for printing floating-point numbers,
similar to `Number.prototype.toString()`, but with the following changes:
1. Keep the negative sign of `-0.0` to preserve input information.
2. Keep decimal point to indicate the number is floating point.
3. Remove positive sign in the exponent part.
*/
static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) {
u64 sig_bin, sig_dec, sig_raw;
i32 exp_bin, exp_dec, sig_len, dot_ofs;
u32 exp_raw;
u8 *end;
bool sign;
/* decode raw bytes from IEEE-754 double format. */
sign = (bool)(raw >> (F64_BITS - 1));
sig_raw = raw & F64_SIG_MASK;
exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS);
/* return inf or nan */
if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) {
return write_inf_or_nan(buf, flg, sig_raw, sign);
}
/* add sign for all finite number */
buf[0] = '-';
buf += sign;
/* return zero */
if ((raw << 1) == 0) {
byte_copy_4(buf, "0.0");
return buf + 3;
}
if (likely(exp_raw != 0)) {
/* normal number */
sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS);
exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS;
/* fast path for small integer number without fraction */
if ((-F64_SIG_BITS <= exp_bin && exp_bin <= 0) &&
(u64_tz_bits(sig_bin) >= (u32)-exp_bin)) {
sig_dec = sig_bin >> -exp_bin; /* range: [1, 0x1FFFFFFFFFFFFF] */
buf = write_u64_len_1_to_16(sig_dec, buf);
byte_copy_2(buf, ".0");
return buf + 2;
}
/* binary to decimal */
f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec);
/* the sig length is 16 or 17 */
sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000);
/* the decimal point offset relative to the first digit */
dot_ofs = sig_len + exp_dec;
if (-6 < dot_ofs && dot_ofs <= 21) {
i32 num_sep_pos, dot_set_pos, pre_ofs;
u8 *num_hdr, *num_end, *num_sep, *dot_end;
bool no_pre_zero;
/* fill zeros */
memset(buf, '0', 32);
/* not prefixed with zero, e.g. 1.234, 1234.0 */
no_pre_zero = (dot_ofs > 0);
/* write the number as digits */
pre_ofs = no_pre_zero ? 0 : (2 - dot_ofs);
num_hdr = buf + pre_ofs;
num_end = write_u64_len_16_to_17_trim(sig_dec, num_hdr);
/* seperate these digits to leave a space for dot */
num_sep_pos = no_pre_zero ? dot_ofs : 0;
num_sep = num_hdr + num_sep_pos;
byte_move_16(num_sep + no_pre_zero, num_sep);
num_end += no_pre_zero;
/* write the dot */
dot_set_pos = yyjson_max(dot_ofs, 1);
buf[dot_set_pos] = '.';
/* return the ending */
dot_end = buf + dot_ofs + 2;
return yyjson_max(dot_end, num_end);
} else {
/* write with scientific notation, e.g. 1.234e56 */
end = write_u64_len_16_to_17_trim(sig_dec, buf + 1);
end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */
exp_dec += sig_len - 1;
buf[0] = buf[1];
buf[1] = '.';
return write_f64_exp(exp_dec, end);
}
} else {
/* subnormal number */
sig_bin = sig_raw;
exp_bin = 1 - F64_EXP_BIAS - F64_SIG_BITS;
/* binary to decimal */
f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec);
/* write significand part */
end = write_u64_len_1_to_17(sig_dec, buf + 1);
buf[0] = buf[1];
buf[1] = '.';
exp_dec += (i32)(end - buf) - 2;
/* trim trailing zeros */
end -= *(end - 1) == '0'; /* branchless for last zero */
end -= *(end - 1) == '0'; /* branchless for second last zero */
while (*(end - 1) == '0') end--; /* for unlikely more zeros */
end -= *(end - 1) == '.'; /* remove dot, e.g. 2.e-321 -> 2e-321 */
/* write exponent part */
return write_f64_exp(exp_dec, end);
}
}
/**
Write a double number using fixed-point notation (requires 40 bytes buffer).
We follow the ECMAScript specification for printing floating-point numbers,
similar to `Number.prototype.toFixed(prec)`, but with the following changes:
1. Keep the negative sign of `-0.0` to preserve input information.
2. Keep decimal point to indicate the number is floating point.
3. Remove positive sign in the exponent part.
4. Remove trailing zeros and reduce unnecessary precision.
*/
static_noinline u8 *write_f64_raw_fixed(u8 *buf, u64 raw, yyjson_write_flag flg,
u32 prec) {
u64 sig_bin, sig_dec, sig_raw;
i32 exp_bin, exp_dec, sig_len, dot_ofs;
u32 exp_raw;
u8 *end;
bool sign;
/* decode raw bytes from IEEE-754 double format. */
sign = (bool)(raw >> (F64_BITS - 1));
sig_raw = raw & F64_SIG_MASK;
exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS);
/* return inf or nan */
if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) {
return write_inf_or_nan(buf, flg, sig_raw, sign);
}
/* add sign for all finite number */
buf[0] = '-';
buf += sign;
/* return zero */
if ((raw << 1) == 0) {
byte_copy_4(buf, "0.0");
return buf + 3;
}
if (likely(exp_raw != 0)) {
/* normal number */
sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS);
exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS;
/* fast path for small integer number without fraction */
if ((-F64_SIG_BITS <= exp_bin && exp_bin <= 0) &&
(u64_tz_bits(sig_bin) >= (u32)-exp_bin)) {
sig_dec = sig_bin >> -exp_bin; /* range: [1, 0x1FFFFFFFFFFFFF] */
buf = write_u64_len_1_to_16(sig_dec, buf);
byte_copy_2(buf, ".0");
return buf + 2;
}
/* only `fabs(num) < 1e21` are processed here. */
if ((raw << 1) < (U64(0x444B1AE4, 0xD6E2EF50) << 1)) {
i32 num_sep_pos, dot_set_pos, pre_ofs;
u8 *num_hdr, *num_end, *num_sep;
bool round_up, no_pre_zero;
/* binary to decimal */
f64_bin_to_dec_fast(sig_raw, exp_raw, sig_bin, exp_bin,
&sig_dec, &exp_dec, &round_up);
/* the sig length is 16 or 17 */
sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000);
/* limit the length of digits after the decimal point */
if (exp_dec < -1) {
i32 sig_len_cut = -exp_dec - (i32)prec;
if (sig_len_cut > sig_len) {
byte_copy_4(buf, "0.0");
return buf + 3;
}
if (sig_len_cut > 0) {
u64 div, mod, p10;
/* remove round up */
sig_dec -= round_up;
sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000);
/* cut off some digits */
div_pow10(sig_dec, (u32)sig_len_cut, &div, &mod, &p10);
/* add round up */
sig_dec = div + (mod >= p10 / 2);
/* update exp and sig length */
exp_dec += sig_len_cut;
sig_len -= sig_len_cut;
sig_len += (sig_len >= 0) &&
(sig_dec >= div_pow10_table[sig_len].p10);
}
if (sig_len <= 0) {
byte_copy_4(buf, "0.0");
return buf + 3;
}
}
/* fill zeros */
memset(buf, '0', 32);
/* the decimal point offset relative to the first digit */
dot_ofs = sig_len + exp_dec;
/* not prefixed with zero, e.g. 1.234, 1234.0 */
no_pre_zero = (dot_ofs > 0);
/* write the number as digits */
pre_ofs = no_pre_zero ? 0 : (1 - dot_ofs);
num_hdr = buf + pre_ofs;
num_end = write_u64_len_1_to_17(sig_dec, num_hdr);
/* seperate these digits to leave a space for dot */
num_sep_pos = no_pre_zero ? dot_ofs : -dot_ofs;
num_sep = buf + num_sep_pos;
byte_move_16(num_sep + 1, num_sep);
num_end += (exp_dec < 0);
/* write the dot */
dot_set_pos = yyjson_max(dot_ofs, 1);
buf[dot_set_pos] = '.';
/* remove trailing zeros */
buf += dot_set_pos + 2;
buf = yyjson_max(buf, num_end);
buf -= *(buf - 1) == '0'; /* branchless for last zero */
buf -= *(buf - 1) == '0'; /* branchless for second last zero */
while (*(buf - 1) == '0') buf--; /* for unlikely more zeros */
buf += *(buf - 1) == '.'; /* keep a zero after dot */
return buf;
} else {
/* binary to decimal */
f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin,
&sig_dec, &exp_dec);
/* the sig length is 16 or 17 */
sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000);
/* write with scientific notation, e.g. 1.234e56 */
end = write_u64_len_16_to_17_trim(sig_dec, buf + 1);
end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */
exp_dec += sig_len - 1;
buf[0] = buf[1];
buf[1] = '.';
return write_f64_exp(exp_dec, end);
}
} else {
/* subnormal number */
byte_copy_4(buf, "0.0");
return buf + 3;
}
}
#else /* FP_WRITER */
#if YYJSON_MSC_VER >= 1400
#define snprintf_num(buf, len, fmt, dig, val) \
sprintf_s((char *)buf, len, fmt, dig, val)
#elif defined(snprintf) || (YYJSON_STDC_VER >= 199901L)
#define snprintf_num(buf, len, fmt, dig, val) \
snprintf((char *)buf, len, fmt, dig, val)
#else
#define snprintf_num(buf, len, fmt, dig, val) \
sprintf((char *)buf, fmt, dig, val)
#endif
static_noinline u8 *write_fp_reformat(u8 *buf, int len,
yyjson_write_flag flg, bool fixed) {
u8 *cur = buf;
if (unlikely(len < 1)) return NULL;
cur += (*cur == '-');
if (unlikely(!char_is_digit(*cur))) {
/* nan, inf, or bad output */
if (has_flg(INF_AND_NAN_AS_NULL)) {
byte_copy_4(buf, "null");
return buf + 4;
} else if (has_allow(INF_AND_NAN)) {
if (*cur == 'i') {
byte_copy_8(cur, "Infinity");
return cur + 8;
} else if (*cur == 'n') {
byte_copy_4(buf, "NaN");
return buf + 3;
}
}
return NULL;
} else {
/* finite number */
u8 *end = buf + len, *dot = NULL, *exp = NULL;
/*
The snprintf() function is locale-dependent. For currently known
locales, (en, zh, ja, ko, am, he, hi) use '.' as the decimal point,
while other locales use ',' as the decimal point. we need to replace
',' with '.' to avoid the locale setting.
*/
for (; cur < end; cur++) {
switch (*cur) {
case ',': *cur = '.'; /* fallthrough */
case '.': dot = cur; break;
case 'e': exp = cur; break;
default: break;
}
}
if (fixed) {
/* remove trailing zeros */
while (*(end - 1) == '0') end--;
end += *(end - 1) == '.';
} else {
if (!dot && !exp) {
/* add decimal point, e.g. 123 -> 123.0 */
byte_copy_2(end, ".0");
end += 2;
} else if (exp) {
cur = exp + 1;
/* remove positive sign in the exponent part */
if (*cur == '+') {
memmove(cur, cur + 1, (usize)(end - cur - 1));
end--;
}
cur += (*cur == '-');
/* remove leading zeros in the exponent part */
if (*cur == '0') {
u8 *hdr = cur++;
while (*cur == '0') cur++;
memmove(hdr, cur, (usize)(end - cur));
end -= (usize)(cur - hdr);
}
}
}
return end;
}
}
/** Write a double number (requires 40 bytes buffer). */
static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) {
#if defined(DBL_DECIMAL_DIG) && DBL_DECIMAL_DIG < F64_DEC_DIG
int dig = DBL_DECIMAL_DIG;
#else
int dig = F64_DEC_DIG;
#endif
f64 val = f64_from_bits(raw);
int len = snprintf_num(buf, FP_BUF_LEN, "%.*g", dig, val);
return write_fp_reformat(buf, len, flg, false);
}
/** Write a double number (requires 40 bytes buffer). */
static_noinline u8 *write_f32_raw(u8 *buf, u64 raw, yyjson_write_flag flg) {
#if defined(FLT_DECIMAL_DIG) && FLT_DECIMAL_DIG < F32_DEC_DIG
int dig = FLT_DECIMAL_DIG;
#else
int dig = F32_DEC_DIG;
#endif
f64 val = (f64)f64_to_f32(f64_from_bits(raw));
int len = snprintf_num(buf, FP_BUF_LEN, "%.*g", dig, val);
return write_fp_reformat(buf, len, flg, false);
}
/** Write a double number (requires 40 bytes buffer). */
static_noinline u8 *write_f64_raw_fixed(u8 *buf, u64 raw,
yyjson_write_flag flg, u32 prec) {
f64 val = (f64)f64_from_bits(raw);
if (-1e21 < val && val < 1e21) {
int len = snprintf_num(buf, FP_BUF_LEN, "%.*f", (int)prec, val);
return write_fp_reformat(buf, len, flg, true);
} else {
return write_f64_raw(buf, raw, flg);
}
}
#endif /* FP_WRITER */
/** Write a JSON number (requires 40 bytes buffer). */
static_inline u8 *write_num(u8 *cur, yyjson_val *val, yyjson_write_flag flg) {
if (!(val->tag & YYJSON_SUBTYPE_REAL)) {
u64 pos = val->uni.u64;
u64 neg = ~pos + 1;
usize sign = ((val->tag & YYJSON_SUBTYPE_SINT) > 0) & ((i64)pos < 0);
*cur = '-';
return write_u64(sign ? neg : pos, cur + sign);
} else {
u64 raw = val->uni.u64;
u32 val_fmt = (u32)(val->tag >> 32);
u32 all_fmt = flg;
u32 fmt = val_fmt | all_fmt;
if (likely(!(fmt >> (32 - YYJSON_WRITE_FP_FLAG_BITS)))) {
/* double to shortest */
return write_f64_raw(cur, raw, flg);
} else if (fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS)) {
/* double to fixed */
u32 val_prec = val_fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS);
u32 all_prec = all_fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS);
u32 prec = val_prec ? val_prec : all_prec;
return write_f64_raw_fixed(cur, raw, flg, prec);
} else {
if (fmt & YYJSON_WRITE_FP_TO_FLOAT) {
/* float to shortest */
return write_f32_raw(cur, raw, flg);
} else {
/* double to shortest */
return write_f64_raw(cur, raw, flg);
}
}
}
}
char *yyjson_write_number(const yyjson_val *val, char *buf) {
if (unlikely(!val || !buf)) return NULL;
switch (val->tag & YYJSON_TAG_MASK) {
case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: {
buf = (char *)write_u64(val->uni.u64, (u8 *)buf);
*buf = '\0';
return buf;
}
case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: {
u64 pos = val->uni.u64;
u64 neg = ~pos + 1;
usize sign = ((i64)pos < 0);
*buf = '-';
buf = (char *)write_u64(sign ? neg : pos, (u8 *)buf + sign);
*buf = '\0';
return buf;
}
case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: {
u64 raw = val->uni.u64;
u32 fmt = (u32)(val->tag >> 32);
u32 flg = YYJSON_WRITE_ALLOW_INF_AND_NAN;
if (likely(!(fmt >> (32 - YYJSON_WRITE_FP_FLAG_BITS)))) {
buf = (char *)write_f64_raw((u8 *)buf, raw, flg);
} else if (fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS)) {
u32 prec = fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS);
buf = (char *)write_f64_raw_fixed((u8 *)buf, raw, flg, prec);
} else {
if (fmt & YYJSON_WRITE_FP_TO_FLOAT) {
buf = (char *)write_f32_raw((u8 *)buf, raw, flg);
} else {
buf = (char *)write_f64_raw((u8 *)buf, raw, flg);
}
}
if (buf) *buf = '\0';
return buf;
}
default: return NULL;
}
}
/*==============================================================================
* MARK: - String Writer (Private)
*============================================================================*/
/** Character encode type, if (type > CHAR_ENC_ERR_1) bytes = type / 2; */
typedef u8 char_enc_type;
#define CHAR_ENC_CPY_1 0 /* 1-byte UTF-8, copy. */
#define CHAR_ENC_ERR_1 1 /* 1-byte UTF-8, error. */
#define CHAR_ENC_ESC_A 2 /* 1-byte ASCII, escaped as '\x'. */
#define CHAR_ENC_ESC_1 3 /* 1-byte UTF-8, escaped as '\uXXXX'. */
#define CHAR_ENC_CPY_2 4 /* 2-byte UTF-8, copy. */
#define CHAR_ENC_ESC_2 5 /* 2-byte UTF-8, escaped as '\uXXXX'. */
#define CHAR_ENC_CPY_3 6 /* 3-byte UTF-8, copy. */
#define CHAR_ENC_ESC_3 7 /* 3-byte UTF-8, escaped as '\uXXXX'. */
#define CHAR_ENC_CPY_4 8 /* 4-byte UTF-8, copy. */
#define CHAR_ENC_ESC_4 9 /* 4-byte UTF-8, escaped as '\uXXXX\uXXXX'. */
/** Character encode type table: don't escape unicode, don't escape '/'.
(generate with misc/make_tables.c) */
static const char_enc_type enc_table_cpy[256] = {
3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1
};
/** Character encode type table: don't escape unicode, escape '/'.
(generate with misc/make_tables.c) */
static const char_enc_type enc_table_cpy_slash[256] = {
3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1
};
/** Character encode type table: escape unicode, don't escape '/'.
(generate with misc/make_tables.c) */
static const char_enc_type enc_table_esc[256] = {
3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1
};
/** Character encode type table: escape unicode, escape '/'.
(generate with misc/make_tables.c) */
static const char_enc_type enc_table_esc_slash[256] = {
3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1
};
/** Escaped hex character table: ["00" "01" "02" ... "FD" "FE" "FF"].
(generate with misc/make_tables.c) */
yyjson_align(2)
static const u8 esc_hex_char_table[512] = {
'0', '0', '0', '1', '0', '2', '0', '3',
'0', '4', '0', '5', '0', '6', '0', '7',
'0', '8', '0', '9', '0', 'A', '0', 'B',
'0', 'C', '0', 'D', '0', 'E', '0', 'F',
'1', '0', '1', '1', '1', '2', '1', '3',
'1', '4', '1', '5', '1', '6', '1', '7',
'1', '8', '1', '9', '1', 'A', '1', 'B',
'1', 'C', '1', 'D', '1', 'E', '1', 'F',
'2', '0', '2', '1', '2', '2', '2', '3',
'2', '4', '2', '5', '2', '6', '2', '7',
'2', '8', '2', '9', '2', 'A', '2', 'B',
'2', 'C', '2', 'D', '2', 'E', '2', 'F',
'3', '0', '3', '1', '3', '2', '3', '3',
'3', '4', '3', '5', '3', '6', '3', '7',
'3', '8', '3', '9', '3', 'A', '3', 'B',
'3', 'C', '3', 'D', '3', 'E', '3', 'F',
'4', '0', '4', '1', '4', '2', '4', '3',
'4', '4', '4', '5', '4', '6', '4', '7',
'4', '8', '4', '9', '4', 'A', '4', 'B',
'4', 'C', '4', 'D', '4', 'E', '4', 'F',
'5', '0', '5', '1', '5', '2', '5', '3',
'5', '4', '5', '5', '5', '6', '5', '7',
'5', '8', '5', '9', '5', 'A', '5', 'B',
'5', 'C', '5', 'D', '5', 'E', '5', 'F',
'6', '0', '6', '1', '6', '2', '6', '3',
'6', '4', '6', '5', '6', '6', '6', '7',
'6', '8', '6', '9', '6', 'A', '6', 'B',
'6', 'C', '6', 'D', '6', 'E', '6', 'F',
'7', '0', '7', '1', '7', '2', '7', '3',
'7', '4', '7', '5', '7', '6', '7', '7',
'7', '8', '7', '9', '7', 'A', '7', 'B',
'7', 'C', '7', 'D', '7', 'E', '7', 'F',
'8', '0', '8', '1', '8', '2', '8', '3',
'8', '4', '8', '5', '8', '6', '8', '7',
'8', '8', '8', '9', '8', 'A', '8', 'B',
'8', 'C', '8', 'D', '8', 'E', '8', 'F',
'9', '0', '9', '1', '9', '2', '9', '3',
'9', '4', '9', '5', '9', '6', '9', '7',
'9', '8', '9', '9', '9', 'A', '9', 'B',
'9', 'C', '9', 'D', '9', 'E', '9', 'F',
'A', '0', 'A', '1', 'A', '2', 'A', '3',
'A', '4', 'A', '5', 'A', '6', 'A', '7',
'A', '8', 'A', '9', 'A', 'A', 'A', 'B',
'A', 'C', 'A', 'D', 'A', 'E', 'A', 'F',
'B', '0', 'B', '1', 'B', '2', 'B', '3',
'B', '4', 'B', '5', 'B', '6', 'B', '7',
'B', '8', 'B', '9', 'B', 'A', 'B', 'B',
'B', 'C', 'B', 'D', 'B', 'E', 'B', 'F',
'C', '0', 'C', '1', 'C', '2', 'C', '3',
'C', '4', 'C', '5', 'C', '6', 'C', '7',
'C', '8', 'C', '9', 'C', 'A', 'C', 'B',
'C', 'C', 'C', 'D', 'C', 'E', 'C', 'F',
'D', '0', 'D', '1', 'D', '2', 'D', '3',
'D', '4', 'D', '5', 'D', '6', 'D', '7',
'D', '8', 'D', '9', 'D', 'A', 'D', 'B',
'D', 'C', 'D', 'D', 'D', 'E', 'D', 'F',
'E', '0', 'E', '1', 'E', '2', 'E', '3',
'E', '4', 'E', '5', 'E', '6', 'E', '7',
'E', '8', 'E', '9', 'E', 'A', 'E', 'B',
'E', 'C', 'E', 'D', 'E', 'E', 'E', 'F',
'F', '0', 'F', '1', 'F', '2', 'F', '3',
'F', '4', 'F', '5', 'F', '6', 'F', '7',
'F', '8', 'F', '9', 'F', 'A', 'F', 'B',
'F', 'C', 'F', 'D', 'F', 'E', 'F', 'F'
};
/** Escaped single character table. (generate with misc/make_tables.c) */
yyjson_align(2)
static const u8 esc_single_char_table[512] = {
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'\\', 'b', '\\', 't', '\\', 'n', ' ', ' ',
'\\', 'f', '\\', 'r', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', '\\', '"', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', '\\', '/',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'\\', '\\', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
};
/** Returns the encode table with options. */
static_inline const char_enc_type *get_enc_table_with_flag(
yyjson_write_flag flg) {
if (has_flg(ESCAPE_UNICODE)) {
if (has_flg(ESCAPE_SLASHES)) {
return enc_table_esc_slash;
} else {
return enc_table_esc;
}
} else {
if (has_flg(ESCAPE_SLASHES)) {
return enc_table_cpy_slash;
} else {
return enc_table_cpy;
}
}
}
/** Write raw string. */
static_inline u8 *write_raw(u8 *cur, const u8 *raw, usize raw_len) {
memcpy(cur, raw, raw_len);
return cur + raw_len;
}
/**
Write string no-escape.
@param cur Buffer cursor.
@param str A UTF-8 string, null-terminator is not required.
@param str_len Length of string in bytes.
@return The buffer cursor after string.
*/
static_inline u8 *write_str_noesc(u8 *cur, const u8 *str, usize str_len) {
*cur++ = '"';
while (str_len >= 16) {
byte_copy_16(cur, str);
cur += 16;
str += 16;
str_len -= 16;
}
while (str_len >= 4) {
byte_copy_4(cur, str);
cur += 4;
str += 4;
str_len -= 4;
}
while (str_len) {
*cur++ = *str++;
str_len -= 1;
}
*cur++ = '"';
return cur;
}
/**
Write UTF-8 string (requires len * 6 + 2 bytes buffer).
@param cur Buffer cursor.
@param esc Escape unicode.
@param inv Allow invalid unicode.
@param str A UTF-8 string, null-terminator is not required.
@param str_len Length of string in bytes.
@param enc_table Encode type table for character.
@return The buffer cursor after string, or NULL on invalid unicode.
*/
static_inline u8 *write_str(u8 *cur, bool esc, bool inv,
const u8 *str, usize str_len,
const char_enc_type *enc_table) {
/* The replacement character U+FFFD, used to indicate invalid character. */
const v32 rep = {{ 'F', 'F', 'F', 'D' }};
const v32 pre = {{ '\\', 'u', '0', '0' }};
const u8 *src = str;
const u8 *end = str + str_len;
*cur++ = '"';
copy_ascii:
/*
Copy continuous ASCII, loop unrolling, same as the following code:
while (end > src) (
if (unlikely(enc_table[*src])) break;
*cur++ = *src++;
);
*/
#define expr_jump(i) \
if (unlikely(enc_table[src[i]])) goto stop_char_##i;
#define expr_stop(i) \
stop_char_##i: \
memcpy(cur, src, i); \
cur += i; src += i; goto copy_utf8;
while (end - src >= 16) {
repeat16_incr(expr_jump)
byte_copy_16(cur, src);
cur += 16; src += 16;
}
while (end - src >= 4) {
repeat4_incr(expr_jump)
byte_copy_4(cur, src);
cur += 4; src += 4;
}
while (end > src) {
expr_jump(0)
*cur++ = *src++;
}
*cur++ = '"';
return cur;
repeat16_incr(expr_stop)
#undef expr_jump
#undef expr_stop
copy_utf8:
if (unlikely(src + 4 > end)) {
if (end == src) goto copy_end;
if (end - src < enc_table[*src] / 2) goto err_one;
}
switch (enc_table[*src]) {
case CHAR_ENC_CPY_1: {
*cur++ = *src++;
goto copy_ascii;
}
case CHAR_ENC_CPY_2: {
#if YYJSON_DISABLE_UTF8_VALIDATION
byte_copy_2(cur, src);
#else
u32 uni = 0;
byte_copy_2(&uni, src);
if (unlikely(!is_utf8_seq2(uni))) goto err_cpy;
byte_copy_2(cur, &uni);
#endif
cur += 2;
src += 2;
goto copy_utf8;
}
case CHAR_ENC_CPY_3: {
#if YYJSON_DISABLE_UTF8_VALIDATION
if (likely(src + 4 <= end)) {
byte_copy_4(cur, src);
} else {
byte_copy_2(cur, src);
cur[2] = src[2];
}
#else
u32 uni, tmp;
if (likely(src + 4 <= end)) {
uni = byte_load_4(src);
if (unlikely(!is_utf8_seq3(uni))) goto err_cpy;
byte_copy_4(cur, src);
} else {
uni = byte_load_3(src);
if (unlikely(!is_utf8_seq3(uni))) goto err_cpy;
byte_copy_4(cur, &uni);
}
#endif
cur += 3;
src += 3;
goto copy_utf8;
}
case CHAR_ENC_CPY_4: {
#if YYJSON_DISABLE_UTF8_VALIDATION
byte_copy_4(cur, src);
#else
u32 uni, tmp;
uni = byte_load_4(src);
if (unlikely(!is_utf8_seq4(uni))) goto err_cpy;
byte_copy_4(cur, src);
#endif
cur += 4;
src += 4;
goto copy_utf8;
}
case CHAR_ENC_ESC_A: {
byte_copy_2(cur, &esc_single_char_table[*src * 2]);
cur += 2;
src += 1;
goto copy_utf8;
}
case CHAR_ENC_ESC_1: {
byte_copy_4(cur + 0, &pre);
byte_copy_2(cur + 4, &esc_hex_char_table[*src * 2]);
cur += 6;
src += 1;
goto copy_utf8;
}
case CHAR_ENC_ESC_2: {
u16 u;
#if !YYJSON_DISABLE_UTF8_VALIDATION
u32 v4 = 0;
u16 v2 = byte_load_2(src);
byte_copy_2(&v4, &v2);
if (unlikely(!is_utf8_seq2(v4))) goto err_esc;
#endif
u = (u16)(((u16)(src[0] & 0x1F) << 6) |
((u16)(src[1] & 0x3F) << 0));
byte_copy_2(cur + 0, &pre);
byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]);
byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]);
cur += 6;
src += 2;
goto copy_utf8;
}
case CHAR_ENC_ESC_3: {
u16 u;
u32 v, tmp;
#if !YYJSON_DISABLE_UTF8_VALIDATION
v = byte_load_3(src);
if (unlikely(!is_utf8_seq3(v))) goto err_esc;
#endif
u = (u16)(((u16)(src[0] & 0x0F) << 12) |
((u16)(src[1] & 0x3F) << 6) |
((u16)(src[2] & 0x3F) << 0));
byte_copy_2(cur + 0, &pre);
byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]);
byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]);
cur += 6;
src += 3;
goto copy_utf8;
}
case CHAR_ENC_ESC_4: {
u32 hi, lo, u, v, tmp;
#if !YYJSON_DISABLE_UTF8_VALIDATION
v = byte_load_4(src);
if (unlikely(!is_utf8_seq4(v))) goto err_esc;
#endif
u = ((u32)(src[0] & 0x07) << 18) |
((u32)(src[1] & 0x3F) << 12) |
((u32)(src[2] & 0x3F) << 6) |
((u32)(src[3] & 0x3F) << 0);
u -= 0x10000;
hi = (u >> 10) + 0xD800;
lo = (u & 0x3FF) + 0xDC00;
byte_copy_2(cur + 0, &pre);
byte_copy_2(cur + 2, &esc_hex_char_table[(hi >> 8) * 2]);
byte_copy_2(cur + 4, &esc_hex_char_table[(hi & 0xFF) * 2]);
byte_copy_2(cur + 6, &pre);
byte_copy_2(cur + 8, &esc_hex_char_table[(lo >> 8) * 2]);
byte_copy_2(cur + 10, &esc_hex_char_table[(lo & 0xFF) * 2]);
cur += 12;
src += 4;
goto copy_utf8;
}
case CHAR_ENC_ERR_1: {
goto err_one;
}
default: break; /* unreachable */
}
copy_end:
*cur++ = '"';
return cur;
err_one:
if (esc) goto err_esc;
else goto err_cpy;
err_cpy:
if (!inv) return NULL;
*cur++ = *src++;
goto copy_utf8;
err_esc:
if (!inv) return NULL;
byte_copy_2(cur + 0, &pre);
byte_copy_4(cur + 2, &rep);
cur += 6;
src += 1;
goto copy_utf8;
}
/*==============================================================================
* MARK: - JSON Writer Utilities (Private)
*============================================================================*/
/** Write null (requires 8 bytes buffer). */
static_inline u8 *write_null(u8 *cur) {
v64 v = {{ 'n', 'u', 'l', 'l', ',', '\n', 0, 0 }};
byte_copy_8(cur, &v);
return cur + 4;
}
/** Write bool (requires 8 bytes buffer). */
static_inline u8 *write_bool(u8 *cur, bool val) {
v64 v0 = {{ 'f', 'a', 'l', 's', 'e', ',', '\n', 0 }};
v64 v1 = {{ 't', 'r', 'u', 'e', ',', '\n', 0, 0 }};
if (val) {
byte_copy_8(cur, &v1);
} else {
byte_copy_8(cur, &v0);
}
return cur + 5 - val;
}
/** Write indent (requires level x 4 bytes buffer).
Param spaces should not larger than 4. */
static_inline u8 *write_indent(u8 *cur, usize level, usize spaces) {
while (level-- > 0) {
byte_copy_4(cur, " ");
cur += spaces;
}
return cur;
}
/** Write data to file pointer. */
static bool write_dat_to_fp(FILE *fp, u8 *dat, usize len,
yyjson_write_err *err) {
if (fwrite(dat, len, 1, fp) != 1) {
err->msg = "file writing failed";
err->code = YYJSON_WRITE_ERROR_FILE_WRITE;
return false;
}
return true;
}
/** Write data to file. */
static bool write_dat_to_file(const char *path, u8 *dat, usize len,
yyjson_write_err *err) {
#define return_err(_code, _msg) do { \
err->msg = _msg; \
err->code = YYJSON_WRITE_ERROR_##_code; \
if (file) fclose(file); \
return false; \
} while (false)
FILE *file = fopen_writeonly(path);
if (file == NULL) {
return_err(FILE_OPEN, MSG_FOPEN);
}
if (fwrite(dat, len, 1, file) != 1) {
return_err(FILE_WRITE, MSG_FWRITE);
}
if (fclose(file) != 0) {
file = NULL;
return_err(FILE_WRITE, MSG_FCLOSE);
}
return true;
#undef return_err
}
/*==============================================================================
* MARK: - JSON Writer Implementation (Private)
*============================================================================*/
typedef struct yyjson_write_ctx {
usize tag;
} yyjson_write_ctx;
static_inline void yyjson_write_ctx_set(yyjson_write_ctx *ctx,
usize size, bool is_obj) {
ctx->tag = (size << 1) | (usize)is_obj;
}
static_inline void yyjson_write_ctx_get(yyjson_write_ctx *ctx,
usize *size, bool *is_obj) {
usize tag = ctx->tag;
*size = tag >> 1;
*is_obj = (bool)(tag & 1);
}
/** Write single JSON value. */
static_inline u8 *yyjson_write_single(yyjson_val *val,
yyjson_write_flag flg,
yyjson_alc alc,
usize *dat_len,
yyjson_write_err *err) {
#define return_err(_code, _msg) do { \
if (hdr) alc.free(alc.ctx, (void *)hdr); \
*dat_len = 0; \
err->code = YYJSON_WRITE_ERROR_##_code; \
err->msg = _msg; \
return NULL; \
} while (false)
#define incr_len(_len) do { \
hdr = (u8 *)alc.malloc(alc.ctx, _len); \
if (!hdr) goto fail_alloc; \
cur = hdr; \
} while (false)
#define check_str_len(_len) do { \
if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \
goto fail_alloc; \
} while (false)
u8 *hdr = NULL, *cur;
usize str_len;
const u8 *str_ptr;
const char_enc_type *enc_table = get_enc_table_with_flag(flg);
bool cpy = (enc_table == enc_table_cpy);
bool esc = has_flg(ESCAPE_UNICODE) != 0;
bool inv = has_allow(INVALID_UNICODE) != 0;
bool newline = has_flg(NEWLINE_AT_END) != 0;
const usize end_len = 2; /* '\n' and '\0' */
switch (unsafe_yyjson_get_type(val)) {
case YYJSON_TYPE_RAW:
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len + end_len);
cur = write_raw(cur, str_ptr, str_len);
break;
case YYJSON_TYPE_STR:
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len * 6 + 2 + end_len);
if (likely(cpy) && unsafe_yyjson_get_subtype(val)) {
cur = write_str_noesc(cur, str_ptr, str_len);
} else {
cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table);
if (unlikely(!cur)) goto fail_str;
}
break;
case YYJSON_TYPE_NUM:
incr_len(FP_BUF_LEN + end_len);
cur = write_num(cur, val, flg);
if (unlikely(!cur)) goto fail_num;
break;
case YYJSON_TYPE_BOOL:
incr_len(8);
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
break;
case YYJSON_TYPE_NULL:
incr_len(8);
cur = write_null(cur);
break;
case YYJSON_TYPE_ARR:
incr_len(2 + end_len);
byte_copy_2(cur, "[]");
cur += 2;
break;
case YYJSON_TYPE_OBJ:
incr_len(2 + end_len);
byte_copy_2(cur, "{}");
cur += 2;
break;
default:
goto fail_type;
}
if (newline) *cur++ = '\n';
*cur = '\0';
*dat_len = (usize)(cur - hdr);
memset(err, 0, sizeof(yyjson_write_err));
return hdr;
fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC);
fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE);
fail_num: return_err(NAN_OR_INF, MSG_NAN_INF);
fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8);
#undef return_err
#undef check_str_len
#undef incr_len
}
/** Write JSON document minify.
The root of this document should be a non-empty container. */
static_inline u8 *yyjson_write_minify(const yyjson_val *root,
const yyjson_write_flag flg,
const yyjson_alc alc,
usize *dat_len,
yyjson_write_err *err) {
#define return_err(_code, _msg) do { \
*dat_len = 0; \
err->code = YYJSON_WRITE_ERROR_##_code; \
err->msg = _msg; \
if (hdr) alc.free(alc.ctx, hdr); \
return NULL; \
} while (false)
#define incr_len(_len) do { \
ext_len = (usize)(_len); \
if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \
usize ctx_pos = (usize)((u8 *)ctx - hdr); \
usize cur_pos = (usize)(cur - hdr); \
ctx_len = (usize)(end - (u8 *)ctx); \
alc_inc = yyjson_max(alc_len / 2, ext_len); \
alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \
if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \
goto fail_alloc; \
alc_len += alc_inc; \
tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \
if (unlikely(!tmp)) goto fail_alloc; \
ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \
memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \
ctx = ctx_tmp; \
cur = tmp + cur_pos; \
end = tmp + alc_len; \
hdr = tmp; \
} \
} while (false)
#define check_str_len(_len) do { \
if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \
goto fail_alloc; \
} while (false)
yyjson_val *val;
yyjson_type val_type;
usize ctn_len, ctn_len_tmp;
bool ctn_obj, ctn_obj_tmp, is_key;
u8 *hdr, *cur, *end, *tmp;
yyjson_write_ctx *ctx, *ctx_tmp;
usize alc_len, alc_inc, ctx_len, ext_len, str_len;
const u8 *str_ptr;
const char_enc_type *enc_table = get_enc_table_with_flag(flg);
bool cpy = (enc_table == enc_table_cpy);
bool esc = has_flg(ESCAPE_UNICODE) != 0;
bool inv = has_allow(INVALID_UNICODE) != 0;
bool newline = has_flg(NEWLINE_AT_END) != 0;
alc_len = root->uni.ofs / sizeof(yyjson_val);
alc_len = alc_len * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64;
alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx));
hdr = (u8 *)alc.malloc(alc.ctx, alc_len);
if (!hdr) goto fail_alloc;
cur = hdr;
end = hdr + alc_len;
ctx = (yyjson_write_ctx *)(void *)end;
doc_begin:
val = constcast(yyjson_val *)root;
val_type = unsafe_yyjson_get_type(val);
ctn_obj = (val_type == YYJSON_TYPE_OBJ);
ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
val++;
val_begin:
val_type = unsafe_yyjson_get_type(val);
if (val_type == YYJSON_TYPE_STR) {
is_key = ((u8)ctn_obj & (u8)~ctn_len);
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len * 6 + 16);
if (likely(cpy) && unsafe_yyjson_get_subtype(val)) {
cur = write_str_noesc(cur, str_ptr, str_len);
} else {
cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table);
if (unlikely(!cur)) goto fail_str;
}
*cur++ = is_key ? ':' : ',';
goto val_end;
}
if (val_type == YYJSON_TYPE_NUM) {
incr_len(FP_BUF_LEN);
cur = write_num(cur, val, flg);
if (unlikely(!cur)) goto fail_num;
*cur++ = ',';
goto val_end;
}
if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) ==
(YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) {
ctn_len_tmp = unsafe_yyjson_get_len(val);
ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ);
incr_len(16);
if (unlikely(ctn_len_tmp == 0)) {
/* write empty container */
*cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5));
*cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5));
*cur++ = ',';
goto val_end;
} else {
/* push context, setup new container */
yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj);
ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp;
ctn_obj = ctn_obj_tmp;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
val++;
goto val_begin;
}
}
if (val_type == YYJSON_TYPE_BOOL) {
incr_len(16);
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
cur++;
goto val_end;
}
if (val_type == YYJSON_TYPE_NULL) {
incr_len(16);
cur = write_null(cur);
cur++;
goto val_end;
}
if (val_type == YYJSON_TYPE_RAW) {
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len + 2);
cur = write_raw(cur, str_ptr, str_len);
*cur++ = ',';
goto val_end;
}
goto fail_type;
val_end:
val++;
ctn_len--;
if (unlikely(ctn_len == 0)) goto ctn_end;
goto val_begin;
ctn_end:
cur--;
*cur++ = (u8)(']' | ((u8)ctn_obj << 5));
*cur++ = ',';
if (unlikely((u8 *)ctx >= end)) goto doc_end;
yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj);
ctn_len--;
if (likely(ctn_len > 0)) {
goto val_begin;
} else {
goto ctn_end;
}
doc_end:
if (newline) {
incr_len(2);
*(cur - 1) = '\n';
cur++;
}
*--cur = '\0';
*dat_len = (usize)(cur - hdr);
memset(err, 0, sizeof(yyjson_write_err));
return hdr;
fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC);
fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE);
fail_num: return_err(NAN_OR_INF, MSG_NAN_INF);
fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8);
#undef return_err
#undef incr_len
#undef check_str_len
}
/** Write JSON document pretty.
The root of this document should be a non-empty container. */
static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
const yyjson_write_flag flg,
const yyjson_alc alc,
usize *dat_len,
yyjson_write_err *err) {
#define return_err(_code, _msg) do { \
*dat_len = 0; \
err->code = YYJSON_WRITE_ERROR_##_code; \
err->msg = _msg; \
if (hdr) alc.free(alc.ctx, hdr); \
return NULL; \
} while (false)
#define incr_len(_len) do { \
ext_len = (usize)(_len); \
if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \
usize ctx_pos = (usize)((u8 *)ctx - hdr); \
usize cur_pos = (usize)(cur - hdr); \
ctx_len = (usize)(end - (u8 *)ctx); \
alc_inc = yyjson_max(alc_len / 2, ext_len); \
alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \
if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \
goto fail_alloc; \
alc_len += alc_inc; \
tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \
if (unlikely(!tmp)) goto fail_alloc; \
ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \
memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \
ctx = ctx_tmp; \
cur = tmp + cur_pos; \
end = tmp + alc_len; \
hdr = tmp; \
} \
} while (false)
#define check_str_len(_len) do { \
if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \
goto fail_alloc; \
} while (false)
yyjson_val *val;
yyjson_type val_type;
usize ctn_len, ctn_len_tmp;
bool ctn_obj, ctn_obj_tmp, is_key, no_indent;
u8 *hdr, *cur, *end, *tmp;
yyjson_write_ctx *ctx, *ctx_tmp;
usize alc_len, alc_inc, ctx_len, ext_len, str_len, level;
const u8 *str_ptr;
const char_enc_type *enc_table = get_enc_table_with_flag(flg);
bool cpy = (enc_table == enc_table_cpy);
bool esc = has_flg(ESCAPE_UNICODE) != 0;
bool inv = has_allow(INVALID_UNICODE) != 0;
usize spaces = has_flg(PRETTY_TWO_SPACES) ? 2 : 4;
bool newline = has_flg(NEWLINE_AT_END) != 0;
alc_len = root->uni.ofs / sizeof(yyjson_val);
alc_len = alc_len * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64;
alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx));
hdr = (u8 *)alc.malloc(alc.ctx, alc_len);
if (!hdr) goto fail_alloc;
cur = hdr;
end = hdr + alc_len;
ctx = (yyjson_write_ctx *)(void *)end;
doc_begin:
val = constcast(yyjson_val *)root;
val_type = unsafe_yyjson_get_type(val);
ctn_obj = (val_type == YYJSON_TYPE_OBJ);
ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
*cur++ = '\n';
val++;
level = 1;
val_begin:
val_type = unsafe_yyjson_get_type(val);
if (val_type == YYJSON_TYPE_STR) {
is_key = (bool)((u8)ctn_obj & (u8)~ctn_len);
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
if (likely(cpy) && unsafe_yyjson_get_subtype(val)) {
cur = write_str_noesc(cur, str_ptr, str_len);
} else {
cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table);
if (unlikely(!cur)) goto fail_str;
}
*cur++ = is_key ? ':' : ',';
*cur++ = is_key ? ' ' : '\n';
goto val_end;
}
if (val_type == YYJSON_TYPE_NUM) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
incr_len(FP_BUF_LEN + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_num(cur, val, flg);
if (unlikely(!cur)) goto fail_num;
*cur++ = ',';
*cur++ = '\n';
goto val_end;
}
if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) ==
(YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
ctn_len_tmp = unsafe_yyjson_get_len(val);
ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ);
if (unlikely(ctn_len_tmp == 0)) {
/* write empty container */
incr_len(16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
*cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5));
*cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5));
*cur++ = ',';
*cur++ = '\n';
goto val_end;
} else {
/* push context, setup new container */
incr_len(32 + (no_indent ? 0 : level * 4));
yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj);
ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp;
ctn_obj = ctn_obj_tmp;
cur = write_indent(cur, no_indent ? 0 : level, spaces);
level++;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
*cur++ = '\n';
val++;
goto val_begin;
}
}
if (val_type == YYJSON_TYPE_BOOL) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
incr_len(16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
cur += 2;
goto val_end;
}
if (val_type == YYJSON_TYPE_NULL) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
incr_len(16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_null(cur);
cur += 2;
goto val_end;
}
if (val_type == YYJSON_TYPE_RAW) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len + 3 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_raw(cur, str_ptr, str_len);
*cur++ = ',';
*cur++ = '\n';
goto val_end;
}
goto fail_type;
val_end:
val++;
ctn_len--;
if (unlikely(ctn_len == 0)) goto ctn_end;
goto val_begin;
ctn_end:
cur -= 2;
*cur++ = '\n';
incr_len(level * 4);
cur = write_indent(cur, --level, spaces);
*cur++ = (u8)(']' | ((u8)ctn_obj << 5));
if (unlikely((u8 *)ctx >= end)) goto doc_end;
yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj);
ctn_len--;
*cur++ = ',';
*cur++ = '\n';
if (likely(ctn_len > 0)) {
goto val_begin;
} else {
goto ctn_end;
}
doc_end:
if (newline) {
incr_len(2);
*cur++ = '\n';
}
*cur = '\0';
*dat_len = (usize)(cur - hdr);
memset(err, 0, sizeof(yyjson_write_err));
return hdr;
fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC);
fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE);
fail_num: return_err(NAN_OR_INF, MSG_NAN_INF);
fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8);
#undef return_err
#undef incr_len
#undef check_str_len
}
/*==============================================================================
* MARK: - JSON Writer (Public)
*============================================================================*/
char *yyjson_val_write_opts(const yyjson_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
usize *dat_len,
yyjson_write_err *err) {
yyjson_write_err tmp_err;
usize tmp_dat_len;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
yyjson_val *root = constcast(yyjson_val *)val;
if (!err) err = &tmp_err;
if (!dat_len) dat_len = &tmp_dat_len;
if (unlikely(!root)) {
*dat_len = 0;
err->msg = "input JSON is NULL";
err->code = YYJSON_READ_ERROR_INVALID_PARAMETER;
return NULL;
}
if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) {
return (char *)yyjson_write_single(root, flg, alc, dat_len, err);
} else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) {
return (char *)yyjson_write_pretty(root, flg, alc, dat_len, err);
} else {
return (char *)yyjson_write_minify(root, flg, alc, dat_len, err);
}
}
char *yyjson_write_opts(const yyjson_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
usize *dat_len,
yyjson_write_err *err) {
yyjson_val *root = doc ? doc->root : NULL;
return yyjson_val_write_opts(root, flg, alc_ptr, dat_len, err);
}
bool yyjson_val_write_file(const char *path,
const yyjson_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_write_err tmp_err;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
u8 *dat;
usize dat_len = 0;
yyjson_val *root = constcast(yyjson_val *)val;
bool suc;
if (!err) err = &tmp_err;
if (unlikely(!path || !*path)) {
err->msg = "input path is invalid";
err->code = YYJSON_READ_ERROR_INVALID_PARAMETER;
return false;
}
dat = (u8 *)yyjson_val_write_opts(root, flg, &alc, &dat_len, err);
if (unlikely(!dat)) return false;
suc = write_dat_to_file(path, dat, dat_len, err);
alc.free(alc.ctx, dat);
return suc;
}
bool yyjson_val_write_fp(FILE *fp,
const yyjson_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_write_err tmp_err;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
u8 *dat;
usize dat_len = 0;
yyjson_val *root = constcast(yyjson_val *)val;
bool suc;
if (!err) err = &tmp_err;
if (unlikely(!fp)) {
err->msg = "input fp is invalid";
err->code = YYJSON_READ_ERROR_INVALID_PARAMETER;
return false;
}
dat = (u8 *)yyjson_val_write_opts(root, flg, &alc, &dat_len, err);
if (unlikely(!dat)) return false;
suc = write_dat_to_fp(fp, dat, dat_len, err);
alc.free(alc.ctx, dat);
return suc;
}
bool yyjson_write_file(const char *path,
const yyjson_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_val *root = doc ? doc->root : NULL;
return yyjson_val_write_file(path, root, flg, alc_ptr, err);
}
bool yyjson_write_fp(FILE *fp,
const yyjson_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_val *root = doc ? doc->root : NULL;
return yyjson_val_write_fp(fp, root, flg, alc_ptr, err);
}
/*==============================================================================
* MARK: - Mutable JSON Writer Implementation (Private)
*============================================================================*/
typedef struct yyjson_mut_write_ctx {
usize tag;
yyjson_mut_val *ctn;
} yyjson_mut_write_ctx;
static_inline void yyjson_mut_write_ctx_set(yyjson_mut_write_ctx *ctx,
yyjson_mut_val *ctn,
usize size, bool is_obj) {
ctx->tag = (size << 1) | (usize)is_obj;
ctx->ctn = ctn;
}
static_inline void yyjson_mut_write_ctx_get(yyjson_mut_write_ctx *ctx,
yyjson_mut_val **ctn,
usize *size, bool *is_obj) {
usize tag = ctx->tag;
*size = tag >> 1;
*is_obj = (bool)(tag & 1);
*ctn = ctx->ctn;
}
/** Get the estimated number of values for the mutable JSON document. */
static_inline usize yyjson_mut_doc_estimated_val_num(
const yyjson_mut_doc *doc) {
usize sum = 0;
yyjson_val_chunk *chunk = doc->val_pool.chunks;
while (chunk) {
sum += chunk->chunk_size / sizeof(yyjson_mut_val) - 1;
if (chunk == doc->val_pool.chunks) {
sum -= (usize)(doc->val_pool.end - doc->val_pool.cur);
}
chunk = chunk->next;
}
return sum;
}
/** Write single JSON value. */
static_inline u8 *yyjson_mut_write_single(yyjson_mut_val *val,
yyjson_write_flag flg,
yyjson_alc alc,
usize *dat_len,
yyjson_write_err *err) {
return yyjson_write_single((yyjson_val *)val, flg, alc, dat_len, err);
}
/** Write JSON document minify.
The root of this document should be a non-empty container. */
static_inline u8 *yyjson_mut_write_minify(const yyjson_mut_val *root,
usize estimated_val_num,
yyjson_write_flag flg,
yyjson_alc alc,
usize *dat_len,
yyjson_write_err *err) {
#define return_err(_code, _msg) do { \
*dat_len = 0; \
err->code = YYJSON_WRITE_ERROR_##_code; \
err->msg = _msg; \
if (hdr) alc.free(alc.ctx, hdr); \
return NULL; \
} while (false)
#define incr_len(_len) do { \
ext_len = (usize)(_len); \
if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \
usize ctx_pos = (usize)((u8 *)ctx - hdr); \
usize cur_pos = (usize)(cur - hdr); \
ctx_len = (usize)(end - (u8 *)ctx); \
alc_inc = yyjson_max(alc_len / 2, ext_len); \
alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \
if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \
goto fail_alloc; \
alc_len += alc_inc; \
tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \
if (unlikely(!tmp)) goto fail_alloc; \
ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \
memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \
ctx = ctx_tmp; \
cur = tmp + cur_pos; \
end = tmp + alc_len; \
hdr = tmp; \
} \
} while (false)
#define check_str_len(_len) do { \
if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \
goto fail_alloc; \
} while (false)
yyjson_mut_val *val, *ctn;
yyjson_type val_type;
usize ctn_len, ctn_len_tmp;
bool ctn_obj, ctn_obj_tmp, is_key;
u8 *hdr, *cur, *end, *tmp;
yyjson_mut_write_ctx *ctx, *ctx_tmp;
usize alc_len, alc_inc, ctx_len, ext_len, str_len;
const u8 *str_ptr;
const char_enc_type *enc_table = get_enc_table_with_flag(flg);
bool cpy = (enc_table == enc_table_cpy);
bool esc = has_flg(ESCAPE_UNICODE) != 0;
bool inv = has_allow(INVALID_UNICODE) != 0;
bool newline = has_flg(NEWLINE_AT_END) != 0;
alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64;
alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx));
hdr = (u8 *)alc.malloc(alc.ctx, alc_len);
if (!hdr) goto fail_alloc;
cur = hdr;
end = hdr + alc_len;
ctx = (yyjson_mut_write_ctx *)(void *)end;
doc_begin:
val = constcast(yyjson_mut_val *)root;
val_type = unsafe_yyjson_get_type(val);
ctn_obj = (val_type == YYJSON_TYPE_OBJ);
ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
ctn = val;
val = (yyjson_mut_val *)val->uni.ptr; /* tail */
val = ctn_obj ? val->next->next : val->next;
val_begin:
val_type = unsafe_yyjson_get_type(val);
if (val_type == YYJSON_TYPE_STR) {
is_key = ((u8)ctn_obj & (u8)~ctn_len);
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len * 6 + 16);
if (likely(cpy) && unsafe_yyjson_get_subtype(val)) {
cur = write_str_noesc(cur, str_ptr, str_len);
} else {
cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table);
if (unlikely(!cur)) goto fail_str;
}
*cur++ = is_key ? ':' : ',';
goto val_end;
}
if (val_type == YYJSON_TYPE_NUM) {
incr_len(FP_BUF_LEN);
cur = write_num(cur, (yyjson_val *)val, flg);
if (unlikely(!cur)) goto fail_num;
*cur++ = ',';
goto val_end;
}
if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) ==
(YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) {
ctn_len_tmp = unsafe_yyjson_get_len(val);
ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ);
incr_len(16);
if (unlikely(ctn_len_tmp == 0)) {
/* write empty container */
*cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5));
*cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5));
*cur++ = ',';
goto val_end;
} else {
/* push context, setup new container */
yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj);
ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp;
ctn_obj = ctn_obj_tmp;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
ctn = val;
val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */
val = ctn_obj ? val->next->next : val->next;
goto val_begin;
}
}
if (val_type == YYJSON_TYPE_BOOL) {
incr_len(16);
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
cur++;
goto val_end;
}
if (val_type == YYJSON_TYPE_NULL) {
incr_len(16);
cur = write_null(cur);
cur++;
goto val_end;
}
if (val_type == YYJSON_TYPE_RAW) {
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len + 2);
cur = write_raw(cur, str_ptr, str_len);
*cur++ = ',';
goto val_end;
}
goto fail_type;
val_end:
ctn_len--;
if (unlikely(ctn_len == 0)) goto ctn_end;
val = val->next;
goto val_begin;
ctn_end:
cur--;
*cur++ = (u8)(']' | ((u8)ctn_obj << 5));
*cur++ = ',';
if (unlikely((u8 *)ctx >= end)) goto doc_end;
val = ctn->next;
yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj);
ctn_len--;
if (likely(ctn_len > 0)) {
goto val_begin;
} else {
goto ctn_end;
}
doc_end:
if (newline) {
incr_len(2);
*(cur - 1) = '\n';
cur++;
}
*--cur = '\0';
*dat_len = (usize)(cur - hdr);
err->code = YYJSON_WRITE_SUCCESS;
err->msg = NULL;
return hdr;
fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC);
fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE);
fail_num: return_err(NAN_OR_INF, MSG_NAN_INF);
fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8);
#undef return_err
#undef incr_len
#undef check_str_len
}
/** Write JSON document pretty.
The root of this document should be a non-empty container. */
static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
usize estimated_val_num,
yyjson_write_flag flg,
yyjson_alc alc,
usize *dat_len,
yyjson_write_err *err) {
#define return_err(_code, _msg) do { \
*dat_len = 0; \
err->code = YYJSON_WRITE_ERROR_##_code; \
err->msg = _msg; \
if (hdr) alc.free(alc.ctx, hdr); \
return NULL; \
} while (false)
#define incr_len(_len) do { \
ext_len = (usize)(_len); \
if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \
usize ctx_pos = (usize)((u8 *)ctx - hdr); \
usize cur_pos = (usize)(cur - hdr); \
ctx_len = (usize)(end - (u8 *)ctx); \
alc_inc = yyjson_max(alc_len / 2, ext_len); \
alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \
if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \
goto fail_alloc; \
alc_len += alc_inc; \
tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \
if (unlikely(!tmp)) goto fail_alloc; \
ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \
memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \
ctx = ctx_tmp; \
cur = tmp + cur_pos; \
end = tmp + alc_len; \
hdr = tmp; \
} \
} while (false)
#define check_str_len(_len) do { \
if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \
goto fail_alloc; \
} while (false)
yyjson_mut_val *val, *ctn;
yyjson_type val_type;
usize ctn_len, ctn_len_tmp;
bool ctn_obj, ctn_obj_tmp, is_key, no_indent;
u8 *hdr, *cur, *end, *tmp;
yyjson_mut_write_ctx *ctx, *ctx_tmp;
usize alc_len, alc_inc, ctx_len, ext_len, str_len, level;
const u8 *str_ptr;
const char_enc_type *enc_table = get_enc_table_with_flag(flg);
bool cpy = (enc_table == enc_table_cpy);
bool esc = has_flg(ESCAPE_UNICODE) != 0;
bool inv = has_allow(INVALID_UNICODE) != 0;
usize spaces = has_flg(PRETTY_TWO_SPACES) ? 2 : 4;
bool newline = has_flg(NEWLINE_AT_END) != 0;
alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64;
alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx));
hdr = (u8 *)alc.malloc(alc.ctx, alc_len);
if (!hdr) goto fail_alloc;
cur = hdr;
end = hdr + alc_len;
ctx = (yyjson_mut_write_ctx *)(void *)end;
doc_begin:
val = constcast(yyjson_mut_val *)root;
val_type = unsafe_yyjson_get_type(val);
ctn_obj = (val_type == YYJSON_TYPE_OBJ);
ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
*cur++ = '\n';
ctn = val;
val = (yyjson_mut_val *)val->uni.ptr; /* tail */
val = ctn_obj ? val->next->next : val->next;
level = 1;
val_begin:
val_type = unsafe_yyjson_get_type(val);
if (val_type == YYJSON_TYPE_STR) {
is_key = (bool)((u8)ctn_obj & (u8)~ctn_len);
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
if (likely(cpy) && unsafe_yyjson_get_subtype(val)) {
cur = write_str_noesc(cur, str_ptr, str_len);
} else {
cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table);
if (unlikely(!cur)) goto fail_str;
}
*cur++ = is_key ? ':' : ',';
*cur++ = is_key ? ' ' : '\n';
goto val_end;
}
if (val_type == YYJSON_TYPE_NUM) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
incr_len(FP_BUF_LEN + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_num(cur, (yyjson_val *)val, flg);
if (unlikely(!cur)) goto fail_num;
*cur++ = ',';
*cur++ = '\n';
goto val_end;
}
if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) ==
(YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
ctn_len_tmp = unsafe_yyjson_get_len(val);
ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ);
if (unlikely(ctn_len_tmp == 0)) {
/* write empty container */
incr_len(16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
*cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5));
*cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5));
*cur++ = ',';
*cur++ = '\n';
goto val_end;
} else {
/* push context, setup new container */
incr_len(32 + (no_indent ? 0 : level * 4));
yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj);
ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp;
ctn_obj = ctn_obj_tmp;
cur = write_indent(cur, no_indent ? 0 : level, spaces);
level++;
*cur++ = (u8)('[' | ((u8)ctn_obj << 5));
*cur++ = '\n';
ctn = val;
val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */
val = ctn_obj ? val->next->next : val->next;
goto val_begin;
}
}
if (val_type == YYJSON_TYPE_BOOL) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
incr_len(16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
cur += 2;
goto val_end;
}
if (val_type == YYJSON_TYPE_NULL) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
incr_len(16 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_null(cur);
cur += 2;
goto val_end;
}
if (val_type == YYJSON_TYPE_RAW) {
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
str_len = unsafe_yyjson_get_len(val);
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
check_str_len(str_len);
incr_len(str_len + 3 + (no_indent ? 0 : level * 4));
cur = write_indent(cur, no_indent ? 0 : level, spaces);
cur = write_raw(cur, str_ptr, str_len);
*cur++ = ',';
*cur++ = '\n';
goto val_end;
}
goto fail_type;
val_end:
ctn_len--;
if (unlikely(ctn_len == 0)) goto ctn_end;
val = val->next;
goto val_begin;
ctn_end:
cur -= 2;
*cur++ = '\n';
incr_len(level * 4);
cur = write_indent(cur, --level, spaces);
*cur++ = (u8)(']' | ((u8)ctn_obj << 5));
if (unlikely((u8 *)ctx >= end)) goto doc_end;
val = ctn->next;
yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj);
ctn_len--;
*cur++ = ',';
*cur++ = '\n';
if (likely(ctn_len > 0)) {
goto val_begin;
} else {
goto ctn_end;
}
doc_end:
if (newline) {
incr_len(2);
*cur++ = '\n';
}
*cur = '\0';
*dat_len = (usize)(cur - hdr);
err->code = YYJSON_WRITE_SUCCESS;
err->msg = NULL;
return hdr;
fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC);
fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE);
fail_num: return_err(NAN_OR_INF, MSG_NAN_INF);
fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8);
#undef return_err
#undef incr_len
#undef check_str_len
}
static char *yyjson_mut_write_opts_impl(const yyjson_mut_val *val,
usize estimated_val_num,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
usize *dat_len,
yyjson_write_err *err) {
yyjson_write_err tmp_err;
usize tmp_dat_len;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
yyjson_mut_val *root = constcast(yyjson_mut_val *)val;
if (!err) err = &tmp_err;
if (!dat_len) dat_len = &tmp_dat_len;
if (unlikely(!root)) {
*dat_len = 0;
err->msg = "input JSON is NULL";
err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER;
return NULL;
}
if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) {
return (char *)yyjson_mut_write_single(root, flg, alc, dat_len, err);
} else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) {
return (char *)yyjson_mut_write_pretty(root, estimated_val_num,
flg, alc, dat_len, err);
} else {
return (char *)yyjson_mut_write_minify(root, estimated_val_num,
flg, alc, dat_len, err);
}
}
/*==============================================================================
* MARK: - Mutable JSON Writer (Public)
*============================================================================*/
char *yyjson_mut_val_write_opts(const yyjson_mut_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
usize *dat_len,
yyjson_write_err *err) {
return yyjson_mut_write_opts_impl(val, 0, flg, alc_ptr, dat_len, err);
}
char *yyjson_mut_write_opts(const yyjson_mut_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
usize *dat_len,
yyjson_write_err *err) {
yyjson_mut_val *root;
usize estimated_val_num;
if (likely(doc)) {
root = doc->root;
estimated_val_num = yyjson_mut_doc_estimated_val_num(doc);
} else {
root = NULL;
estimated_val_num = 0;
}
return yyjson_mut_write_opts_impl(root, estimated_val_num,
flg, alc_ptr, dat_len, err);
}
bool yyjson_mut_val_write_file(const char *path,
const yyjson_mut_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_write_err tmp_err;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
u8 *dat;
usize dat_len = 0;
yyjson_mut_val *root = constcast(yyjson_mut_val *)val;
bool suc;
if (!err) err = &tmp_err;
if (unlikely(!path || !*path)) {
err->msg = "input path is invalid";
err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER;
return false;
}
dat = (u8 *)yyjson_mut_val_write_opts(root, flg, &alc, &dat_len, err);
if (unlikely(!dat)) return false;
suc = write_dat_to_file(path, dat, dat_len, err);
alc.free(alc.ctx, dat);
return suc;
}
bool yyjson_mut_val_write_fp(FILE *fp,
const yyjson_mut_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_write_err tmp_err;
yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC;
u8 *dat;
usize dat_len = 0;
yyjson_mut_val *root = constcast(yyjson_mut_val *)val;
bool suc;
if (!err) err = &tmp_err;
if (unlikely(!fp)) {
err->msg = "input fp is invalid";
err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER;
return false;
}
dat = (u8 *)yyjson_mut_val_write_opts(root, flg, &alc, &dat_len, err);
if (unlikely(!dat)) return false;
suc = write_dat_to_fp(fp, dat, dat_len, err);
alc.free(alc.ctx, dat);
return suc;
}
bool yyjson_mut_write_file(const char *path,
const yyjson_mut_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_mut_val *root = doc ? doc->root : NULL;
return yyjson_mut_val_write_file(path, root, flg, alc_ptr, err);
}
bool yyjson_mut_write_fp(FILE *fp,
const yyjson_mut_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc_ptr,
yyjson_write_err *err) {
yyjson_mut_val *root = doc ? doc->root : NULL;
return yyjson_mut_val_write_fp(fp, root, flg, alc_ptr, err);
}
#undef has_flg
#undef has_allow
#endif /* YYJSON_DISABLE_WRITER */
#if !YYJSON_DISABLE_UTILS
/*==============================================================================
* MARK: - JSON Pointer API (RFC 6901) (Public)
*============================================================================*/
/**
Get a token from JSON pointer string.
@param ptr [in] string that points to current token prefix `/`
[out] string that points to next token prefix `/`, or string end
@param end [in] end of the entire JSON Pointer string
@param len [out] unescaped token length
@param esc [out] number of escaped characters in this token
@return head of the token, or NULL if syntax error
*/
static_inline const char *ptr_next_token(const char **ptr, const char *end,
usize *len, usize *esc) {
const char *hdr = *ptr + 1;
const char *cur = hdr;
/* skip unescaped characters */
while (cur < end && *cur != '/' && *cur != '~') cur++;
if (likely(cur == end || *cur != '~')) {
/* no escaped characters, return */
*ptr = cur;
*len = (usize)(cur - hdr);
*esc = 0;
return hdr;
} else {
/* handle escaped characters */
usize esc_num = 0;
while (cur < end && *cur != '/') {
if (*cur++ == '~') {
if (cur == end || (*cur != '0' && *cur != '1')) {
*ptr = cur - 1;
return NULL;
}
esc_num++;
}
}
*ptr = cur;
*len = (usize)(cur - hdr) - esc_num;
*esc = esc_num;
return hdr;
}
}
/**
Convert token string to index.
@param cur [in] token head
@param len [in] token length
@param idx [out] the index number, or USIZE_MAX if token is '-'
@return true if token is a valid array index
*/
static_inline bool ptr_token_to_idx(const char *cur, usize len, usize *idx) {
const char *end = cur + len;
usize num = 0, add;
if (unlikely(len == 0 || len > USIZE_SAFE_DIG)) return false;
if (*cur == '0') {
if (unlikely(len > 1)) return false;
*idx = 0;
return true;
}
if (*cur == '-') {
if (unlikely(len > 1)) return false;
*idx = USIZE_MAX;
return true;
}
for (; cur < end && (add = (usize)((u8)*cur - (u8)'0')) <= 9; cur++) {
num = num * 10 + add;
}
if (unlikely(num == 0 || cur < end)) return false;
*idx = num;
return true;
}
/**
Compare JSON key with token.
@param key a string key (yyjson_val or yyjson_mut_val)
@param token a JSON pointer token
@param len unescaped token length
@param esc number of escaped characters in this token
@return true if `str` is equals to `token`
*/
static_inline bool ptr_token_eq(void *key,
const char *token, usize len, usize esc) {
yyjson_val *val = (yyjson_val *)key;
if (unsafe_yyjson_get_len(val) != len) return false;
if (likely(!esc)) {
return memcmp(val->uni.str, token, len) == 0;
} else {
const char *str = val->uni.str;
for (; len-- > 0; token++, str++) {
if (*token == '~') {
if (*str != (*++token == '0' ? '~' : '/')) return false;
} else {
if (*str != *token) return false;
}
}
return true;
}
}
/**
Get a value from array by token.
@param arr an array, should not be NULL or non-array type
@param token a JSON pointer token
@param len unescaped token length
@param esc number of escaped characters in this token
@return value at index, or NULL if token is not index or index is out of range
*/
static_inline yyjson_val *ptr_arr_get(yyjson_val *arr, const char *token,
usize len, usize esc) {
yyjson_val *val = unsafe_yyjson_get_first(arr);
usize num = unsafe_yyjson_get_len(arr), idx = 0;
if (unlikely(num == 0)) return NULL;
if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL;
if (unlikely(idx >= num)) return NULL;
if (unsafe_yyjson_arr_is_flat(arr)) {
return val + idx;
} else {
while (idx-- > 0) val = unsafe_yyjson_get_next(val);
return val;
}
}
/**
Get a value from object by token.
@param obj [in] an object, should not be NULL or non-object type
@param token [in] a JSON pointer token
@param len [in] unescaped token length
@param esc [in] number of escaped characters in this token
@return value associated with the token, or NULL if no value
*/
static_inline yyjson_val *ptr_obj_get(yyjson_val *obj, const char *token,
usize len, usize esc) {
yyjson_val *key = unsafe_yyjson_get_first(obj);
usize num = unsafe_yyjson_get_len(obj);
if (unlikely(num == 0)) return NULL;
for (; num > 0; num--, key = unsafe_yyjson_get_next(key + 1)) {
if (ptr_token_eq(key, token, len, esc)) return key + 1;
}
return NULL;
}
/**
Get a value from array by token.
@param arr [in] an array, should not be NULL or non-array type
@param token [in] a JSON pointer token
@param len [in] unescaped token length
@param esc [in] number of escaped characters in this token
@param pre [out] previous (sibling) value of the returned value
@param last [out] whether index is last
@return value at index, or NULL if token is not index or index is out of range
*/
static_inline yyjson_mut_val *ptr_mut_arr_get(yyjson_mut_val *arr,
const char *token,
usize len, usize esc,
yyjson_mut_val **pre,
bool *last) {
yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; /* last (tail) */
usize num = unsafe_yyjson_get_len(arr), idx;
if (last) *last = false;
if (pre) *pre = NULL;
if (unlikely(num == 0)) {
if (last && len == 1 && (*token == '0' || *token == '-')) *last = true;
return NULL;
}
if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL;
if (last) *last = (idx == num || idx == USIZE_MAX);
if (unlikely(idx >= num)) return NULL;
while (idx-- > 0) val = val->next;
if (pre) *pre = val;
return val->next;
}
/**
Get a value from object by token.
@param obj [in] an object, should not be NULL or non-object type
@param token [in] a JSON pointer token
@param len [in] unescaped token length
@param esc [in] number of escaped characters in this token
@param pre [out] previous (sibling) key of the returned value's key
@return value associated with the token, or NULL if no value
*/
static_inline yyjson_mut_val *ptr_mut_obj_get(yyjson_mut_val *obj,
const char *token,
usize len, usize esc,
yyjson_mut_val **pre) {
yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr, *key;
usize num = unsafe_yyjson_get_len(obj);
if (pre) *pre = NULL;
if (unlikely(num == 0)) return NULL;
for (; num > 0; num--, pre_key = key) {
key = pre_key->next->next;
if (ptr_token_eq(key, token, len, esc)) {
if (pre) *pre = pre_key;
return key->next;
}
}
return NULL;
}
/**
Create a string value with JSON pointer token.
@param token [in] a JSON pointer token
@param len [in] unescaped token length
@param esc [in] number of escaped characters in this token
@param doc [in] used for memory allocation when creating value
@return new string value, or NULL if memory allocation failed
*/
static_inline yyjson_mut_val *ptr_new_key(const char *token,
usize len, usize esc,
yyjson_mut_doc *doc) {
const char *src = token;
if (likely(!esc)) {
return yyjson_mut_strncpy(doc, src, len);
} else {
const char *end = src + len + esc;
char *dst = unsafe_yyjson_mut_str_alc(doc, len + esc);
char *str = dst;
if (unlikely(!dst)) return NULL;
for (; src < end; src++, dst++) {
if (*src != '~') *dst = *src;
else *dst = (*++src == '0' ? '~' : '/');
}
*dst = '\0';
return yyjson_mut_strn(doc, str, len);
}
}
/* macros for yyjson_ptr */
#define return_err(_ret, _code, _pos, _msg) do { \
if (err) { \
err->code = YYJSON_PTR_ERR_##_code; \
err->msg = _msg; \
err->pos = (usize)(_pos); \
} \
return _ret; \
} while (false)
#define return_err_resolve(_ret, _pos) \
return_err(_ret, RESOLVE, _pos, "JSON pointer cannot be resolved")
#define return_err_syntax(_ret, _pos) \
return_err(_ret, SYNTAX, _pos, "invalid escaped character")
#define return_err_alloc(_ret) \
return_err(_ret, MEMORY_ALLOCATION, 0, "failed to create value")
yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val,
const char *ptr, size_t ptr_len,
yyjson_ptr_err *err) {
const char *hdr = ptr, *end = ptr + ptr_len, *token;
usize len, esc;
yyjson_type type;
while (true) {
token = ptr_next_token(&ptr, end, &len, &esc);
if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr);
type = unsafe_yyjson_get_type(val);
if (type == YYJSON_TYPE_OBJ) {
val = ptr_obj_get(val, token, len, esc);
} else if (type == YYJSON_TYPE_ARR) {
val = ptr_arr_get(val, token, len, esc);
} else {
val = NULL;
}
if (!val) return_err_resolve(NULL, token - hdr);
if (ptr == end) return val;
}
}
yyjson_mut_val *unsafe_yyjson_mut_ptr_getx(
yyjson_mut_val *val, const char *ptr, size_t ptr_len,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
const char *hdr = ptr, *end = ptr + ptr_len, *token;
usize len, esc;
yyjson_mut_val *ctn, *pre = NULL;
yyjson_type type;
bool idx_is_last = false;
while (true) {
token = ptr_next_token(&ptr, end, &len, &esc);
if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr);
ctn = val;
type = unsafe_yyjson_get_type(val);
if (type == YYJSON_TYPE_OBJ) {
val = ptr_mut_obj_get(val, token, len, esc, &pre);
} else if (type == YYJSON_TYPE_ARR) {
val = ptr_mut_arr_get(val, token, len, esc, &pre, &idx_is_last);
} else {
val = NULL;
}
if (ctx && (ptr == end)) {
if (type == YYJSON_TYPE_OBJ ||
(type == YYJSON_TYPE_ARR && (val || idx_is_last))) {
ctx->ctn = ctn;
ctx->pre = pre;
}
}
if (!val) return_err_resolve(NULL, token - hdr);
if (ptr == end) return val;
}
}
bool unsafe_yyjson_mut_ptr_putx(
yyjson_mut_val *val, const char *ptr, size_t ptr_len,
yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent,
bool insert_new, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
const char *hdr = ptr, *end = ptr + ptr_len, *token;
usize token_len, esc, ctn_len;
yyjson_mut_val *ctn, *key, *pre = NULL;
yyjson_mut_val *sep_ctn = NULL, *sep_key = NULL, *sep_val = NULL;
yyjson_type ctn_type;
bool idx_is_last = false;
/* skip exist parent nodes */
while (true) {
token = ptr_next_token(&ptr, end, &token_len, &esc);
if (unlikely(!token)) return_err_syntax(false, ptr - hdr);
ctn = val;
ctn_type = unsafe_yyjson_get_type(ctn);
if (ctn_type == YYJSON_TYPE_OBJ) {
val = ptr_mut_obj_get(ctn, token, token_len, esc, &pre);
} else if (ctn_type == YYJSON_TYPE_ARR) {
val = ptr_mut_arr_get(ctn, token, token_len, esc, &pre,
&idx_is_last);
} else return_err_resolve(false, token - hdr);
if (!val) break;
if (ptr == end) break; /* is last token */
}
/* create parent nodes if not exist */
if (unlikely(ptr != end)) { /* not last token */
if (!create_parent) return_err_resolve(false, token - hdr);
/* add value at last index if container is array */
if (ctn_type == YYJSON_TYPE_ARR) {
if (!idx_is_last || !insert_new) {
return_err_resolve(false, token - hdr);
}
val = yyjson_mut_obj(doc);
if (!val) return_err_alloc(false);
/* delay attaching until all operations are completed */
sep_ctn = ctn;
sep_key = NULL;
sep_val = val;
/* move to next token */
ctn = val;
val = NULL;
ctn_type = YYJSON_TYPE_OBJ;
token = ptr_next_token(&ptr, end, &token_len, &esc);
if (unlikely(!token)) return_err_resolve(false, token - hdr);
}
/* container is object, create parent nodes */
while (ptr != end) { /* not last token */
key = ptr_new_key(token, token_len, esc, doc);
if (!key) return_err_alloc(false);
val = yyjson_mut_obj(doc);
if (!val) return_err_alloc(false);
/* delay attaching until all operations are completed */
if (!sep_ctn) {
sep_ctn = ctn;
sep_key = key;
sep_val = val;
} else {
yyjson_mut_obj_add(ctn, key, val);
}
/* move to next token */
ctn = val;
val = NULL;
token = ptr_next_token(&ptr, end, &token_len, &esc);
if (unlikely(!token)) return_err_syntax(false, ptr - hdr);
}
}
/* JSON pointer is resolved, insert or replace target value */
ctn_len = unsafe_yyjson_get_len(ctn);
if (ctn_type == YYJSON_TYPE_OBJ) {
if (ctx) ctx->ctn = ctn;
if (!val || insert_new) {
/* insert new key-value pair */
key = ptr_new_key(token, token_len, esc, doc);
if (unlikely(!key)) return_err_alloc(false);
if (ctx) ctx->pre = ctn_len ? (yyjson_mut_val *)ctn->uni.ptr : key;
unsafe_yyjson_mut_obj_add(ctn, key, new_val, ctn_len);
} else {
/* replace exist value */
key = pre->next->next;
if (ctx) ctx->pre = pre;
if (ctx) ctx->old = val;
yyjson_mut_obj_put(ctn, key, new_val);
}
} else {
/* array */
if (ctx && (val || idx_is_last)) ctx->ctn = ctn;
if (insert_new) {
/* append new value */
if (val) {
pre->next = new_val;
new_val->next = val;
if (ctx) ctx->pre = pre;
unsafe_yyjson_set_len(ctn, ctn_len + 1);
} else if (idx_is_last) {
if (ctx) ctx->pre = ctn_len ?
(yyjson_mut_val *)ctn->uni.ptr : new_val;
yyjson_mut_arr_append(ctn, new_val);
} else {
return_err_resolve(false, token - hdr);
}
} else {
/* replace exist value */
if (!val) return_err_resolve(false, token - hdr);
if (ctn_len > 1) {
new_val->next = val->next;
pre->next = new_val;
if (ctn->uni.ptr == val) ctn->uni.ptr = new_val;
} else {
new_val->next = new_val;
ctn->uni.ptr = new_val;
pre = new_val;
}
if (ctx) ctx->pre = pre;
if (ctx) ctx->old = val;
}
}
/* all operations are completed, attach the new components to the target */
if (unlikely(sep_ctn)) {
if (sep_key) yyjson_mut_obj_add(sep_ctn, sep_key, sep_val);
else yyjson_mut_arr_append(sep_ctn, sep_val);
}
return true;
}
yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex(
yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
yyjson_mut_val *cur_val;
yyjson_ptr_ctx cur_ctx;
memset(&cur_ctx, 0, sizeof(cur_ctx));
if (!ctx) ctx = &cur_ctx;
cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err);
if (!cur_val) return NULL;
if (yyjson_mut_is_obj(ctx->ctn)) {
yyjson_mut_val *key = ctx->pre->next->next;
yyjson_mut_obj_put(ctx->ctn, key, new_val);
} else {
yyjson_ptr_ctx_replace(ctx, new_val);
}
ctx->old = cur_val;
return cur_val;
}
yyjson_mut_val *unsafe_yyjson_mut_ptr_removex(
yyjson_mut_val *val, const char *ptr, size_t len,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
yyjson_mut_val *cur_val;
yyjson_ptr_ctx cur_ctx;
memset(&cur_ctx, 0, sizeof(cur_ctx));
if (!ctx) ctx = &cur_ctx;
cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err);
if (cur_val) {
if (yyjson_mut_is_obj(ctx->ctn)) {
yyjson_mut_val *key = ctx->pre->next->next;
yyjson_mut_obj_put(ctx->ctn, key, NULL);
} else {
yyjson_ptr_ctx_remove(ctx);
}
ctx->pre = NULL;
ctx->old = cur_val;
}
return cur_val;
}
/* macros for yyjson_ptr */
#undef return_err
#undef return_err_resolve
#undef return_err_syntax
#undef return_err_alloc
/*==============================================================================
* MARK: - JSON Patch API (RFC 6902) (Public)
*============================================================================*/
/* JSON Patch operation */
typedef enum patch_op {
PATCH_OP_ADD, /* path, value */
PATCH_OP_REMOVE, /* path */
PATCH_OP_REPLACE, /* path, value */
PATCH_OP_MOVE, /* from, path */
PATCH_OP_COPY, /* from, path */
PATCH_OP_TEST, /* path, value */
PATCH_OP_NONE /* invalid */
} patch_op;
static patch_op patch_op_get(yyjson_val *op) {
const char *str = op->uni.str;
switch (unsafe_yyjson_get_len(op)) {
case 3:
if (!memcmp(str, "add", 3)) return PATCH_OP_ADD;
return PATCH_OP_NONE;
case 4:
if (!memcmp(str, "move", 4)) return PATCH_OP_MOVE;
if (!memcmp(str, "copy", 4)) return PATCH_OP_COPY;
if (!memcmp(str, "test", 4)) return PATCH_OP_TEST;
return PATCH_OP_NONE;
case 6:
if (!memcmp(str, "remove", 6)) return PATCH_OP_REMOVE;
return PATCH_OP_NONE;
case 7:
if (!memcmp(str, "replace", 7)) return PATCH_OP_REPLACE;
return PATCH_OP_NONE;
default:
return PATCH_OP_NONE;
}
}
/* macros for yyjson_patch */
#define return_err(_code, _msg) do { \
if (err->ptr.code == YYJSON_PTR_ERR_MEMORY_ALLOCATION) { \
err->code = YYJSON_PATCH_ERROR_MEMORY_ALLOCATION; \
err->msg = _msg; \
memset(&err->ptr, 0, sizeof(yyjson_ptr_err)); \
} else { \
err->code = YYJSON_PATCH_ERROR_##_code; \
err->msg = _msg; \
err->idx = iter.idx ? iter.idx - 1 : 0; \
} \
return NULL; \
} while (false)
#define return_err_copy() \
return_err(MEMORY_ALLOCATION, "failed to copy value")
#define return_err_key(_key) \
return_err(MISSING_KEY, "missing key " _key)
#define return_err_val(_key) \
return_err(INVALID_MEMBER, "invalid member " _key)
#define ptr_get(_ptr) yyjson_mut_ptr_getx( \
root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr)
#define ptr_add(_ptr, _val) yyjson_mut_ptr_addx( \
root, _ptr->uni.str, _ptr##_len, _val, doc, false, NULL, &err->ptr)
#define ptr_remove(_ptr) yyjson_mut_ptr_removex( \
root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr)
#define ptr_replace(_ptr, _val)yyjson_mut_ptr_replacex( \
root, _ptr->uni.str, _ptr##_len, _val, NULL, &err->ptr)
yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc,
yyjson_val *orig,
yyjson_val *patch,
yyjson_patch_err *err) {
yyjson_mut_val *root;
yyjson_val *obj;
yyjson_arr_iter iter;
yyjson_patch_err err_tmp;
if (!err) err = &err_tmp;
memset(err, 0, sizeof(*err));
memset(&iter, 0, sizeof(iter));
if (unlikely(!doc || !orig || !patch)) {
return_err(INVALID_PARAMETER, "input parameter is NULL");
}
if (unlikely(!yyjson_is_arr(patch))) {
return_err(INVALID_PARAMETER, "input patch is not array");
}
root = yyjson_val_mut_copy(doc, orig);
if (unlikely(!root)) return_err_copy();
/* iterate through the patch array */
yyjson_arr_iter_init(patch, &iter);
while ((obj = yyjson_arr_iter_next(&iter))) {
patch_op op_enum;
yyjson_val *op, *path, *from = NULL, *value;
yyjson_mut_val *val = NULL, *test;
usize path_len, from_len = 0;
if (unlikely(!unsafe_yyjson_is_obj(obj))) {
return_err(INVALID_OPERATION, "JSON patch operation is not object");
}
/* get required member: op */
op = yyjson_obj_get(obj, "op");
if (unlikely(!op)) return_err_key("`op`");
if (unlikely(!yyjson_is_str(op))) return_err_val("`op`");
op_enum = patch_op_get(op);
/* get required member: path */
path = yyjson_obj_get(obj, "path");
if (unlikely(!path)) return_err_key("`path`");
if (unlikely(!yyjson_is_str(path))) return_err_val("`path`");
path_len = unsafe_yyjson_get_len(path);
/* get required member: value, from */
switch ((int)op_enum) {
case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST:
value = yyjson_obj_get(obj, "value");
if (unlikely(!value)) return_err_key("`value`");
val = yyjson_val_mut_copy(doc, value);
if (unlikely(!val)) return_err_copy();
break;
case PATCH_OP_MOVE: case PATCH_OP_COPY:
from = yyjson_obj_get(obj, "from");
if (unlikely(!from)) return_err_key("`from`");
if (unlikely(!yyjson_is_str(from))) return_err_val("`from`");
from_len = unsafe_yyjson_get_len(from);
break;
default:
break;
}
/* perform an operation */
switch ((int)op_enum) {
case PATCH_OP_ADD: /* add(path, val) */
if (unlikely(path_len == 0)) { root = val; break; }
if (unlikely(!ptr_add(path, val))) {
return_err(POINTER, "failed to add `path`");
}
break;
case PATCH_OP_REMOVE: /* remove(path) */
if (unlikely(!ptr_remove(path))) {
return_err(POINTER, "failed to remove `path`");
}
break;
case PATCH_OP_REPLACE: /* replace(path, val) */
if (unlikely(path_len == 0)) { root = val; break; }
if (unlikely(!ptr_replace(path, val))) {
return_err(POINTER, "failed to replace `path`");
}
break;
case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */
if (unlikely(from_len == 0 && path_len == 0)) break;
val = ptr_remove(from);
if (unlikely(!val)) {
return_err(POINTER, "failed to remove `from`");
}
if (unlikely(path_len == 0)) { root = val; break; }
if (unlikely(!ptr_add(path, val))) {
return_err(POINTER, "failed to add `path`");
}
break;
case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */
val = ptr_get(from);
if (unlikely(!val)) {
return_err(POINTER, "failed to get `from`");
}
if (unlikely(path_len == 0)) { root = val; break; }
val = yyjson_mut_val_mut_copy(doc, val);
if (unlikely(!val)) return_err_copy();
if (unlikely(!ptr_add(path, val))) {
return_err(POINTER, "failed to add `path`");
}
break;
case PATCH_OP_TEST: /* test = get(path), test.eq(val) */
test = ptr_get(path);
if (unlikely(!test)) {
return_err(POINTER, "failed to get `path`");
}
if (unlikely(!yyjson_mut_equals(val, test))) {
return_err(EQUAL, "failed to test equal");
}
break;
default:
return_err(INVALID_MEMBER, "unsupported `op`");
}
}
return root;
}
yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc,
yyjson_mut_val *orig,
yyjson_mut_val *patch,
yyjson_patch_err *err) {
yyjson_mut_val *root, *obj;
yyjson_mut_arr_iter iter;
yyjson_patch_err err_tmp;
if (!err) err = &err_tmp;
memset(err, 0, sizeof(*err));
memset(&iter, 0, sizeof(iter));
if (unlikely(!doc || !orig || !patch)) {
return_err(INVALID_PARAMETER, "input parameter is NULL");
}
if (unlikely(!yyjson_mut_is_arr(patch))) {
return_err(INVALID_PARAMETER, "input patch is not array");
}
root = yyjson_mut_val_mut_copy(doc, orig);
if (unlikely(!root)) return_err_copy();
/* iterate through the patch array */
yyjson_mut_arr_iter_init(patch, &iter);
while ((obj = yyjson_mut_arr_iter_next(&iter))) {
patch_op op_enum;
yyjson_mut_val *op, *path, *from = NULL, *value;
yyjson_mut_val *val = NULL, *test;
usize path_len, from_len = 0;
if (!unsafe_yyjson_is_obj(obj)) {
return_err(INVALID_OPERATION, "JSON patch operation is not object");
}
/* get required member: op */
op = yyjson_mut_obj_get(obj, "op");
if (unlikely(!op)) return_err_key("`op`");
if (unlikely(!yyjson_mut_is_str(op))) return_err_val("`op`");
op_enum = patch_op_get((yyjson_val *)(void *)op);
/* get required member: path */
path = yyjson_mut_obj_get(obj, "path");
if (unlikely(!path)) return_err_key("`path`");
if (unlikely(!yyjson_mut_is_str(path))) return_err_val("`path`");
path_len = unsafe_yyjson_get_len(path);
/* get required member: value, from */
switch ((int)op_enum) {
case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST:
value = yyjson_mut_obj_get(obj, "value");
if (unlikely(!value)) return_err_key("`value`");
val = yyjson_mut_val_mut_copy(doc, value);
if (unlikely(!val)) return_err_copy();
break;
case PATCH_OP_MOVE: case PATCH_OP_COPY:
from = yyjson_mut_obj_get(obj, "from");
if (unlikely(!from)) return_err_key("`from`");
if (unlikely(!yyjson_mut_is_str(from))) {
return_err_val("`from`");
}
from_len = unsafe_yyjson_get_len(from);
break;
default:
break;
}
/* perform an operation */
switch ((int)op_enum) {
case PATCH_OP_ADD: /* add(path, val) */
if (unlikely(path_len == 0)) { root = val; break; }
if (unlikely(!ptr_add(path, val))) {
return_err(POINTER, "failed to add `path`");
}
break;
case PATCH_OP_REMOVE: /* remove(path) */
if (unlikely(!ptr_remove(path))) {
return_err(POINTER, "failed to remove `path`");
}
break;
case PATCH_OP_REPLACE: /* replace(path, val) */
if (unlikely(path_len == 0)) { root = val; break; }
if (unlikely(!ptr_replace(path, val))) {
return_err(POINTER, "failed to replace `path`");
}
break;
case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */
if (unlikely(from_len == 0 && path_len == 0)) break;
val = ptr_remove(from);
if (unlikely(!val)) {
return_err(POINTER, "failed to remove `from`");
}
if (unlikely(path_len == 0)) { root = val; break; }
if (unlikely(!ptr_add(path, val))) {
return_err(POINTER, "failed to add `path`");
}
break;
case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */
val = ptr_get(from);
if (unlikely(!val)) {
return_err(POINTER, "failed to get `from`");
}
if (unlikely(path_len == 0)) { root = val; break; }
val = yyjson_mut_val_mut_copy(doc, val);
if (unlikely(!val)) return_err_copy();
if (unlikely(!ptr_add(path, val))) {
return_err(POINTER, "failed to add `path`");
}
break;
case PATCH_OP_TEST: /* test = get(path), test.eq(val) */
test = ptr_get(path);
if (unlikely(!test)) {
return_err(POINTER, "failed to get `path`");
}
if (unlikely(!yyjson_mut_equals(val, test))) {
return_err(EQUAL, "failed to test equal");
}
break;
default:
return_err(INVALID_MEMBER, "unsupported `op`");
}
}
return root;
}
/* macros for yyjson_patch */
#undef return_err
#undef return_err_copy
#undef return_err_key
#undef return_err_val
#undef ptr_get
#undef ptr_add
#undef ptr_remove
#undef ptr_replace
/*==============================================================================
* MARK: - JSON Merge-Patch API (RFC 7386) (Public)
*============================================================================*/
yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc,
yyjson_val *orig,
yyjson_val *patch) {
usize idx, max;
yyjson_val *key, *orig_val, *patch_val, local_orig;
yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val;
if (unlikely(!yyjson_is_obj(patch))) {
return yyjson_val_mut_copy(doc, patch);
}
builder = yyjson_mut_obj(doc);
if (unlikely(!builder)) return NULL;
memset(&local_orig, 0, sizeof(local_orig));
if (!yyjson_is_obj(orig)) {
orig = &local_orig;
orig->tag = builder->tag;
orig->uni = builder->uni;
}
/* If orig is contributing, copy any items not modified by the patch */
if (orig != &local_orig) {
yyjson_obj_foreach(orig, idx, max, key, orig_val) {
patch_val = yyjson_obj_getn(patch,
unsafe_yyjson_get_str(key),
unsafe_yyjson_get_len(key));
if (!patch_val) {
mut_key = yyjson_val_mut_copy(doc, key);
mut_val = yyjson_val_mut_copy(doc, orig_val);
if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL;
}
}
}
/* Merge items modified by the patch. */
yyjson_obj_foreach(patch, idx, max, key, patch_val) {
/* null indicates the field is removed. */
if (unsafe_yyjson_is_null(patch_val)) {
continue;
}
mut_key = yyjson_val_mut_copy(doc, key);
orig_val = yyjson_obj_getn(orig,
unsafe_yyjson_get_str(key),
unsafe_yyjson_get_len(key));
merged_val = yyjson_merge_patch(doc, orig_val, patch_val);
if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL;
}
return builder;
}
yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc,
yyjson_mut_val *orig,
yyjson_mut_val *patch) {
usize idx, max;
yyjson_mut_val *key, *orig_val, *patch_val, local_orig;
yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val;
if (unlikely(!yyjson_mut_is_obj(patch))) {
return yyjson_mut_val_mut_copy(doc, patch);
}
builder = yyjson_mut_obj(doc);
if (unlikely(!builder)) return NULL;
memset(&local_orig, 0, sizeof(local_orig));
if (!yyjson_mut_is_obj(orig)) {
orig = &local_orig;
orig->tag = builder->tag;
orig->uni = builder->uni;
}
/* If orig is contributing, copy any items not modified by the patch */
if (orig != &local_orig) {
yyjson_mut_obj_foreach(orig, idx, max, key, orig_val) {
patch_val = yyjson_mut_obj_getn(patch,
unsafe_yyjson_get_str(key),
unsafe_yyjson_get_len(key));
if (!patch_val) {
mut_key = yyjson_mut_val_mut_copy(doc, key);
mut_val = yyjson_mut_val_mut_copy(doc, orig_val);
if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL;
}
}
}
/* Merge items modified by the patch. */
yyjson_mut_obj_foreach(patch, idx, max, key, patch_val) {
/* null indicates the field is removed. */
if (unsafe_yyjson_is_null(patch_val)) {
continue;
}
mut_key = yyjson_mut_val_mut_copy(doc, key);
orig_val = yyjson_mut_obj_getn(orig,
unsafe_yyjson_get_str(key),
unsafe_yyjson_get_len(key));
merged_val = yyjson_mut_merge_patch(doc, orig_val, patch_val);
if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL;
}
return builder;
}
#endif /* YYJSON_DISABLE_UTILS */
================================================
FILE: src/3rdparty/yyjson/yyjson.h
================================================
/*==============================================================================
Copyright (c) 2020 YaoYuan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*============================================================================*/
/**
@file yyjson.h
@date 2019-03-09
@author YaoYuan
*/
#ifndef YYJSON_H
#define YYJSON_H
/*==============================================================================
* MARK: - Header Files
*============================================================================*/
#include
#include
#include
#include
#include
#include
/*==============================================================================
* MARK: - Compile-time Options
*============================================================================*/
/*
Define as 1 to disable JSON reader at compile-time.
This disables functions with "read" in their name.
Reduces binary size by about 60%.
*/
#ifndef YYJSON_DISABLE_READER
#endif
/*
Define as 1 to disable JSON writer at compile-time.
This disables functions with "write" in their name.
Reduces binary size by about 30%.
*/
#ifndef YYJSON_DISABLE_WRITER
#endif
/*
Define as 1 to disable JSON incremental reader at compile-time.
This disables functions with "incr" in their name.
*/
#ifndef YYJSON_DISABLE_INCR_READER
#endif
/*
Define as 1 to disable JSON Pointer, JSON Patch and JSON Merge Patch supports.
This disables functions with "ptr" or "patch" in their name.
*/
#ifndef YYJSON_DISABLE_UTILS
#endif
/*
Define as 1 to disable the fast floating-point number conversion in yyjson.
Libc's `strtod/snprintf` will be used instead.
This reduces binary size by about 30%, but significantly slows down the
floating-point read/write speed.
*/
#ifndef YYJSON_DISABLE_FAST_FP_CONV
#endif
/*
Define as 1 to disable non-standard JSON features support at compile-time,
such as YYJSON_READ_ALLOW_XXX and YYJSON_WRITE_ALLOW_XXX.
This reduces binary size by about 10%, and slightly improves performance.
*/
#ifndef YYJSON_DISABLE_NON_STANDARD
#endif
/*
Define as 1 to disable UTF-8 validation at compile-time.
Use this if all input strings are guaranteed to be valid UTF-8
(e.g. language-level String types are already validated).
Disabling UTF-8 validation improves performance for non-ASCII strings by about
3% to 7%.
Note: If this flag is enabled while passing illegal UTF-8 strings,
the following errors may occur:
- Escaped characters may be ignored when parsing JSON strings.
- Ending quotes may be ignored when parsing JSON strings, causing the
string to merge with the next value.
- When serializing with `yyjson_mut_val`, the string's end may be accessed
out of bounds, potentially causing a segmentation fault.
*/
#ifndef YYJSON_DISABLE_UTF8_VALIDATION
#endif
/*
Define as 1 to improve performance on architectures that do not support
unaligned memory access.
Normally, this does not need to be set manually. See the C file for details.
*/
#ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS
#endif
/* Define as 1 to export symbols when building this library as a Windows DLL. */
#ifndef YYJSON_EXPORTS
#endif
/* Define as 1 to import symbols when using this library as a Windows DLL. */
#ifndef YYJSON_IMPORTS
#endif
/* Define as 1 to include for compilers without C99 support. */
#ifndef YYJSON_HAS_STDINT_H
#endif
/* Define as 1 to include for compilers without C99 support. */
#ifndef YYJSON_HAS_STDBOOL_H
#endif
/*==============================================================================
* MARK: - Compiler Macros
*============================================================================*/
/** compiler version (MSVC) */
#ifdef _MSC_VER
# define YYJSON_MSC_VER _MSC_VER
#else
# define YYJSON_MSC_VER 0
#endif
/** compiler version (GCC) */
#ifdef __GNUC__
# define YYJSON_GCC_VER __GNUC__
# if defined(__GNUC_PATCHLEVEL__)
# define yyjson_gcc_available(major, minor, patch) \
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \
>= (major * 10000 + minor * 100 + patch))
# else
# define yyjson_gcc_available(major, minor, patch) \
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) \
>= (major * 10000 + minor * 100 + patch))
# endif
#else
# define YYJSON_GCC_VER 0
# define yyjson_gcc_available(major, minor, patch) 0
#endif
/** real gcc check */
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \
!defined(__clang__) && !defined(__llvm__) && \
!defined(__INTEL_COMPILER) && !defined(__ICC) && \
!defined(__NVCC__) && !defined(__PGI) && !defined(__TINYC__)
# define YYJSON_IS_REAL_GCC 1
#else
# define YYJSON_IS_REAL_GCC 0
#endif
/** C version (STDC) */
#if defined(__STDC__) && (__STDC__ >= 1) && defined(__STDC_VERSION__)
# define YYJSON_STDC_VER __STDC_VERSION__
#else
# define YYJSON_STDC_VER 0
#endif
/** C++ version */
#if defined(__cplusplus)
# define YYJSON_CPP_VER __cplusplus
#else
# define YYJSON_CPP_VER 0
#endif
/** compiler builtin check (since gcc 10.0, clang 2.6, icc 2021) */
#ifndef yyjson_has_builtin
# ifdef __has_builtin
# define yyjson_has_builtin(x) __has_builtin(x)
# else
# define yyjson_has_builtin(x) 0
# endif
#endif
/** compiler attribute check (since gcc 5.0, clang 2.9, icc 17) */
#ifndef yyjson_has_attribute
# ifdef __has_attribute
# define yyjson_has_attribute(x) __has_attribute(x)
# else
# define yyjson_has_attribute(x) 0
# endif
#endif
/** compiler feature check (since clang 2.6, icc 17) */
#ifndef yyjson_has_feature
# ifdef __has_feature
# define yyjson_has_feature(x) __has_feature(x)
# else
# define yyjson_has_feature(x) 0
# endif
#endif
/** include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3) */
#ifndef yyjson_has_include
# ifdef __has_include
# define yyjson_has_include(x) __has_include(x)
# else
# define yyjson_has_include(x) 0
# endif
#endif
/** inline for compiler */
#ifndef yyjson_inline
# if YYJSON_MSC_VER >= 1200
# define yyjson_inline __forceinline
# elif defined(_MSC_VER)
# define yyjson_inline __inline
# elif yyjson_has_attribute(always_inline) || YYJSON_GCC_VER >= 4
# define yyjson_inline __inline__ __attribute__((always_inline))
# elif defined(__clang__) || defined(__GNUC__)
# define yyjson_inline __inline__
# elif defined(__cplusplus) || YYJSON_STDC_VER >= 199901L
# define yyjson_inline inline
# else
# define yyjson_inline
# endif
#endif
/** noinline for compiler */
#ifndef yyjson_noinline
# if YYJSON_MSC_VER >= 1400
# define yyjson_noinline __declspec(noinline)
# elif yyjson_has_attribute(noinline) || YYJSON_GCC_VER >= 4
# define yyjson_noinline __attribute__((noinline))
# else
# define yyjson_noinline
# endif
#endif
/** align for compiler */
#ifndef yyjson_align
# if YYJSON_MSC_VER >= 1300
# define yyjson_align(x) __declspec(align(x))
# elif yyjson_has_attribute(aligned) || defined(__GNUC__)
# define yyjson_align(x) __attribute__((aligned(x)))
# elif YYJSON_CPP_VER >= 201103L
# define yyjson_align(x) alignas(x)
# else
# define yyjson_align(x)
# endif
#endif
/** likely for compiler */
#ifndef yyjson_likely
# if yyjson_has_builtin(__builtin_expect) || \
(YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5)
# define yyjson_likely(expr) __builtin_expect(!!(expr), 1)
# else
# define yyjson_likely(expr) (expr)
# endif
#endif
/** unlikely for compiler */
#ifndef yyjson_unlikely
# if yyjson_has_builtin(__builtin_expect) || \
(YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5)
# define yyjson_unlikely(expr) __builtin_expect(!!(expr), 0)
# else
# define yyjson_unlikely(expr) (expr)
# endif
#endif
/** compile-time constant check for compiler */
#ifndef yyjson_constant_p
# if yyjson_has_builtin(__builtin_constant_p) || (YYJSON_GCC_VER >= 3)
# define YYJSON_HAS_CONSTANT_P 1
# define yyjson_constant_p(value) __builtin_constant_p(value)
# else
# define YYJSON_HAS_CONSTANT_P 0
# define yyjson_constant_p(value) 0
# endif
#endif
/** deprecate warning */
#ifndef yyjson_deprecated
# if YYJSON_MSC_VER >= 1400
# define yyjson_deprecated(msg) __declspec(deprecated(msg))
# elif yyjson_has_feature(attribute_deprecated_with_message) || \
(YYJSON_GCC_VER > 4 || (YYJSON_GCC_VER == 4 && __GNUC_MINOR__ >= 5))
# define yyjson_deprecated(msg) __attribute__((deprecated(msg)))
# elif YYJSON_GCC_VER >= 3
# define yyjson_deprecated(msg) __attribute__((deprecated))
# else
# define yyjson_deprecated(msg)
# endif
#endif
/** function export */
#ifndef yyjson_api
# if defined(_WIN32)
# if defined(YYJSON_EXPORTS) && YYJSON_EXPORTS
# define yyjson_api __declspec(dllexport)
# elif defined(YYJSON_IMPORTS) && YYJSON_IMPORTS
# define yyjson_api __declspec(dllimport)
# else
# define yyjson_api
# endif
# elif yyjson_has_attribute(visibility) || YYJSON_GCC_VER >= 4
# define yyjson_api __attribute__((visibility("default")))
# else
# define yyjson_api
# endif
#endif
/** inline function export */
#ifndef yyjson_api_inline
# define yyjson_api_inline static yyjson_inline
#endif
/** stdint (C89 compatible) */
#if (defined(YYJSON_HAS_STDINT_H) && YYJSON_HAS_STDINT_H) || \
YYJSON_MSC_VER >= 1600 || YYJSON_STDC_VER >= 199901L || \
defined(_STDINT_H) || defined(_STDINT_H_) || \
defined(__CLANG_STDINT_H) || defined(_STDINT_H_INCLUDED) || \
yyjson_has_include()
# include
#elif defined(_MSC_VER)
# if _MSC_VER < 1300
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
# else
typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
# endif
#else
# if UCHAR_MAX == 0xFFU
typedef signed char int8_t;
typedef unsigned char uint8_t;
# else
# error cannot find 8-bit integer type
# endif
# if USHRT_MAX == 0xFFFFU
typedef unsigned short uint16_t;
typedef signed short int16_t;
# elif UINT_MAX == 0xFFFFU
typedef unsigned int uint16_t;
typedef signed int int16_t;
# else
# error cannot find 16-bit integer type
# endif
# if UINT_MAX == 0xFFFFFFFFUL
typedef unsigned int uint32_t;
typedef signed int int32_t;
# elif ULONG_MAX == 0xFFFFFFFFUL
typedef unsigned long uint32_t;
typedef signed long int32_t;
# elif USHRT_MAX == 0xFFFFFFFFUL
typedef unsigned short uint32_t;
typedef signed short int32_t;
# else
# error cannot find 32-bit integer type
# endif
# if defined(__INT64_TYPE__) && defined(__UINT64_TYPE__)
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
# elif defined(__GNUC__) || defined(__clang__)
# if !defined(_SYS_TYPES_H) && !defined(__int8_t_defined)
__extension__ typedef long long int64_t;
# endif
__extension__ typedef unsigned long long uint64_t;
# elif defined(_LONG_LONG) || defined(__MWERKS__) || defined(_CRAYC) || \
defined(__SUNPRO_C) || defined(__SUNPRO_CC)
typedef long long int64_t;
typedef unsigned long long uint64_t;
# elif (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || \
defined(__WATCOM_INT64__) || defined (__alpha) || defined (__DECC)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
# else
# error cannot find 64-bit integer type
# endif
#endif
/** stdbool (C89 compatible) */
#if (defined(YYJSON_HAS_STDBOOL_H) && YYJSON_HAS_STDBOOL_H) || \
(yyjson_has_include() && !defined(__STRICT_ANSI__)) || \
YYJSON_MSC_VER >= 1800 || YYJSON_STDC_VER >= 199901L
# include
#elif !defined(__bool_true_false_are_defined)
# define __bool_true_false_are_defined 1
# if defined(__cplusplus)
# if defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define _Bool bool
# if __cplusplus < 201103L
# define bool bool
# define false false
# define true true
# endif
# endif
# else
# define bool unsigned char
# define true 1
# define false 0
# endif
#endif
/** char bit check */
#if defined(CHAR_BIT)
# if CHAR_BIT != 8
# error non 8-bit char is not supported
# endif
#endif
/**
Microsoft Visual C++ 6.0 doesn't support converting number from u64 to f64:
error C2520: conversion from unsigned __int64 to double not implemented.
*/
#ifndef YYJSON_U64_TO_F64_NO_IMPL
# if (0 < YYJSON_MSC_VER) && (YYJSON_MSC_VER <= 1200)
# define YYJSON_U64_TO_F64_NO_IMPL 1
# else
# define YYJSON_U64_TO_F64_NO_IMPL 0
# endif
#endif
/*==============================================================================
* MARK: - Compile Hint Begin
*============================================================================*/
/* extern "C" begin */
#ifdef __cplusplus
extern "C" {
#endif
/* warning suppress begin */
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wunused-parameter"
#elif defined(__GNUC__)
# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
# pragma GCC diagnostic push
# endif
# pragma GCC diagnostic ignored "-Wunused-function"
# pragma GCC diagnostic ignored "-Wunused-parameter"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable:4800) /* 'int': forcing value to 'true' or 'false' */
#endif
/*==============================================================================
* MARK: - Version
*============================================================================*/
/** The major version of yyjson. */
#define YYJSON_VERSION_MAJOR 0
/** The minor version of yyjson. */
#define YYJSON_VERSION_MINOR 12
/** The patch version of yyjson. */
#define YYJSON_VERSION_PATCH 0
/** The version of yyjson in hex: `(major << 16) | (minor << 8) | (patch)`. */
#define YYJSON_VERSION_HEX 0x000C00
/** The version string of yyjson. */
#define YYJSON_VERSION_STRING "0.12.0"
/** The version of yyjson in hex, same as `YYJSON_VERSION_HEX`. */
yyjson_api uint32_t yyjson_version(void);
/*==============================================================================
* MARK: - JSON Types
*============================================================================*/
/** Type of a JSON value (3 bit). */
typedef uint8_t yyjson_type;
/** No type, invalid. */
#define YYJSON_TYPE_NONE ((uint8_t)0) /* _____000 */
/** Raw string type, no subtype. */
#define YYJSON_TYPE_RAW ((uint8_t)1) /* _____001 */
/** Null type: `null` literal, no subtype. */
#define YYJSON_TYPE_NULL ((uint8_t)2) /* _____010 */
/** Boolean type, subtype: TRUE, FALSE. */
#define YYJSON_TYPE_BOOL ((uint8_t)3) /* _____011 */
/** Number type, subtype: UINT, SINT, REAL. */
#define YYJSON_TYPE_NUM ((uint8_t)4) /* _____100 */
/** String type, subtype: NONE, NOESC. */
#define YYJSON_TYPE_STR ((uint8_t)5) /* _____101 */
/** Array type, no subtype. */
#define YYJSON_TYPE_ARR ((uint8_t)6) /* _____110 */
/** Object type, no subtype. */
#define YYJSON_TYPE_OBJ ((uint8_t)7) /* _____111 */
/** Subtype of a JSON value (2 bit). */
typedef uint8_t yyjson_subtype;
/** No subtype. */
#define YYJSON_SUBTYPE_NONE ((uint8_t)(0 << 3)) /* ___00___ */
/** False subtype: `false` literal. */
#define YYJSON_SUBTYPE_FALSE ((uint8_t)(0 << 3)) /* ___00___ */
/** True subtype: `true` literal. */
#define YYJSON_SUBTYPE_TRUE ((uint8_t)(1 << 3)) /* ___01___ */
/** Unsigned integer subtype: `uint64_t`. */
#define YYJSON_SUBTYPE_UINT ((uint8_t)(0 << 3)) /* ___00___ */
/** Signed integer subtype: `int64_t`. */
#define YYJSON_SUBTYPE_SINT ((uint8_t)(1 << 3)) /* ___01___ */
/** Real number subtype: `double`. */
#define YYJSON_SUBTYPE_REAL ((uint8_t)(2 << 3)) /* ___10___ */
/** String that do not need to be escaped for writing (internal use). */
#define YYJSON_SUBTYPE_NOESC ((uint8_t)(1 << 3)) /* ___01___ */
/** The mask used to extract the type of a JSON value. */
#define YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */
/** The number of bits used by the type. */
#define YYJSON_TYPE_BIT ((uint8_t)3)
/** The mask used to extract the subtype of a JSON value. */
#define YYJSON_SUBTYPE_MASK ((uint8_t)0x18) /* ___11___ */
/** The number of bits used by the subtype. */
#define YYJSON_SUBTYPE_BIT ((uint8_t)2)
/** The mask used to extract the reserved bits of a JSON value. */
#define YYJSON_RESERVED_MASK ((uint8_t)0xE0) /* 111_____ */
/** The number of reserved bits. */
#define YYJSON_RESERVED_BIT ((uint8_t)3)
/** The mask used to extract the tag of a JSON value. */
#define YYJSON_TAG_MASK ((uint8_t)0xFF) /* 11111111 */
/** The number of bits used by the tag. */
#define YYJSON_TAG_BIT ((uint8_t)8)
/** Padding size for JSON reader. */
#define YYJSON_PADDING_SIZE 4
/*==============================================================================
* MARK: - Allocator
*============================================================================*/
/**
A memory allocator.
Typically you don't need to use it, unless you want to customize your own
memory allocator.
*/
typedef struct yyjson_alc {
/** Same as libc's malloc(size), should not be NULL. */
void *(*malloc)(void *ctx, size_t size);
/** Same as libc's realloc(ptr, size), should not be NULL. */
void *(*realloc)(void *ctx, void *ptr, size_t old_size, size_t size);
/** Same as libc's free(ptr), should not be NULL. */
void (*free)(void *ctx, void *ptr);
/** A context for malloc/realloc/free, can be NULL. */
void *ctx;
} yyjson_alc;
/**
A pool allocator uses fixed length pre-allocated memory.
This allocator may be used to avoid malloc/realloc calls. The pre-allocated
memory should be held by the caller. The maximum amount of memory required to
read a JSON can be calculated using the `yyjson_read_max_memory_usage()`
function, but the amount of memory required to write a JSON cannot be directly
calculated.
This is not a general-purpose allocator. It is designed to handle a single JSON
data at a time. If it is used for overly complex memory tasks, such as parsing
multiple JSON documents using the same allocator but releasing only a few of
them, it may cause memory fragmentation, resulting in performance degradation
and memory waste.
@param alc The allocator to be initialized.
If this parameter is NULL, the function will fail and return false.
If `buf` or `size` is invalid, this will be set to an empty allocator.
@param buf The buffer memory for this allocator.
If this parameter is NULL, the function will fail and return false.
@param size The size of `buf`, in bytes.
If this parameter is less than 8 words (32/64 bytes on 32/64-bit OS), the
function will fail and return false.
@return true if the `alc` has been successfully initialized.
@b Example
@code
// parse JSON with stack memory
char buf[1024];
yyjson_alc alc;
yyjson_alc_pool_init(&alc, buf, 1024);
const char *json = "{\"name\":\"Helvetica\",\"size\":16}"
yyjson_doc *doc = yyjson_read_opts(json, strlen(json), 0, &alc, NULL);
// the memory of `doc` is on the stack
@endcode
@warning This Allocator is not thread-safe.
*/
yyjson_api bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, size_t size);
/**
A dynamic allocator.
This allocator has a similar usage to the pool allocator above. However, when
there is not enough memory, this allocator will dynamically request more memory
using libc's `malloc` function, and frees it all at once when it is destroyed.
@return A new dynamic allocator, or NULL if memory allocation failed.
@note The returned value should be freed with `yyjson_alc_dyn_free()`.
@warning This Allocator is not thread-safe.
*/
yyjson_api yyjson_alc *yyjson_alc_dyn_new(void);
/**
Free a dynamic allocator which is created by `yyjson_alc_dyn_new()`.
@param alc The dynamic allocator to be destroyed.
*/
yyjson_api void yyjson_alc_dyn_free(yyjson_alc *alc);
/*==============================================================================
* MARK: - Text Locating
*============================================================================*/
/**
Locate the line and column number for a byte position in a string.
This can be used to get better description for error position.
@param str The input string.
@param len The byte length of the input string.
@param pos The byte position within the input string.
@param line A pointer to receive the line number, starting from 1.
@param col A pointer to receive the column number, starting from 1.
@param chr A pointer to receive the character index, starting from 0.
@return true on success, false if `str` is NULL or `pos` is out of bounds.
@note Line/column/character are calculated based on Unicode characters for
compatibility with text editors. For multi-byte UTF-8 characters,
the returned value may not directly correspond to the byte position.
*/
yyjson_api bool yyjson_locate_pos(const char *str, size_t len, size_t pos,
size_t *line, size_t *col, size_t *chr);
/*==============================================================================
* MARK: - JSON Structure
*============================================================================*/
/**
An immutable document for reading JSON.
This document holds memory for all its JSON values and strings. When it is no
longer used, the user should call `yyjson_doc_free()` to free its memory.
*/
typedef struct yyjson_doc yyjson_doc;
/**
An immutable value for reading JSON.
A JSON Value has the same lifetime as its document. The memory is held by its
document and and cannot be freed alone.
*/
typedef struct yyjson_val yyjson_val;
/**
A mutable document for building JSON.
This document holds memory for all its JSON values and strings. When it is no
longer used, the user should call `yyjson_mut_doc_free()` to free its memory.
*/
typedef struct yyjson_mut_doc yyjson_mut_doc;
/**
A mutable value for building JSON.
A JSON Value has the same lifetime as its document. The memory is held by its
document and and cannot be freed alone.
*/
typedef struct yyjson_mut_val yyjson_mut_val;
/*==============================================================================
* MARK: - JSON Reader API
*============================================================================*/
/** Run-time options for JSON reader. */
typedef uint32_t yyjson_read_flag;
/** Default option (RFC 8259 compliant):
- Read positive integer as uint64_t.
- Read negative integer as int64_t.
- Read floating-point number as double with round-to-nearest mode.
- Read integer which cannot fit in uint64_t or int64_t as double.
- Report error if double number is infinity.
- Report error if string contains invalid UTF-8 character or BOM.
- Report error on trailing commas, comments, inf and nan literals. */
static const yyjson_read_flag YYJSON_READ_NOFLAG = 0;
/** Read the input data in-situ.
This option allows the reader to modify and use input data to store string
values, which can increase reading speed slightly.
The caller should hold the input data before free the document.
The input data must be padded by at least `YYJSON_PADDING_SIZE` bytes.
For example: `[1,2]` should be `[1,2]\0\0\0\0`, input length should be 5. */
static const yyjson_read_flag YYJSON_READ_INSITU = 1 << 0;
/** Stop when done instead of issuing an error if there's additional content
after a JSON document. This option may be used to parse small pieces of JSON
in larger data, such as `NDJSON`. */
static const yyjson_read_flag YYJSON_READ_STOP_WHEN_DONE = 1 << 1;
/** Allow single trailing comma at the end of an object or array,
such as `[1,2,3,]`, `{"a":1,"b":2,}` (non-standard). */
static const yyjson_read_flag YYJSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2;
/** Allow C-style single-line and mult-line comments (non-standard). */
static const yyjson_read_flag YYJSON_READ_ALLOW_COMMENTS = 1 << 3;
/** Allow inf/nan number and literal, case-insensitive,
such as 1e999, NaN, inf, -Infinity (non-standard). */
static const yyjson_read_flag YYJSON_READ_ALLOW_INF_AND_NAN = 1 << 4;
/** Read all numbers as raw strings (value with `YYJSON_TYPE_RAW` type),
inf/nan literal is also read as raw with `ALLOW_INF_AND_NAN` flag. */
static const yyjson_read_flag YYJSON_READ_NUMBER_AS_RAW = 1 << 5;
/** Allow reading invalid unicode when parsing string values (non-standard).
Invalid characters will be allowed to appear in the string values, but
invalid escape sequences will still be reported as errors.
This flag does not affect the performance of correctly encoded strings.
@warning Strings in JSON values may contain incorrect encoding when this
option is used, you need to handle these strings carefully to avoid security
risks. */
static const yyjson_read_flag YYJSON_READ_ALLOW_INVALID_UNICODE = 1 << 6;
/** Read big numbers as raw strings. These big numbers include integers that
cannot be represented by `int64_t` and `uint64_t`, and floating-point
numbers that cannot be represented by finite `double`.
The flag will be overridden by `YYJSON_READ_NUMBER_AS_RAW` flag. */
static const yyjson_read_flag YYJSON_READ_BIGNUM_AS_RAW = 1 << 7;
/** Allow UTF-8 BOM and skip it before parsing if any (non-standard). */
static const yyjson_read_flag YYJSON_READ_ALLOW_BOM = 1 << 8;
/** Allow extended number formats (non-standard):
- Hexadecimal numbers, such as `0x7B`.
- Numbers with leading or trailing decimal point, such as `.123`, `123.`.
- Numbers with a leading plus sign, such as `+123`. */
static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_NUMBER = 1 << 9;
/** Allow extended escape sequences in strings (non-standard):
- Additional escapes: `\a`, `\e`, `\v`, ``\'``, `\?`, `\0`.
- Hex escapes: `\xNN`, such as `\x7B`.
- Line continuation: backslash followed by line terminator sequences.
- Unknown escape: if backslash is followed by an unsupported character,
the backslash will be removed and the character will be kept as-is.
However, `\1`-`\9` will still trigger an error. */
static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_ESCAPE = 1 << 10;
/** Allow extended whitespace characters (non-standard):
- Vertical tab `\v` and form feed `\f`.
- Line separator `\u2028` and paragraph separator `\u2029`.
- Non-breaking space `\xA0`.
- Byte order mark: `\uFEFF`.
- Other Unicode characters in the Zs (Separator, space) category. */
static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_WHITESPACE = 1 << 11;
/** Allow strings enclosed in single quotes (non-standard), such as ``'ab'``. */
static const yyjson_read_flag YYJSON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12;
/** Allow object keys without quotes (non-standard), such as `{a:1,b:2}`.
This extends the ECMAScript IdentifierName rule by allowing any
non-whitespace character with code point above `U+007F`. */
static const yyjson_read_flag YYJSON_READ_ALLOW_UNQUOTED_KEY = 1 << 13;
/** Allow JSON5 format, see: [https://json5.org].
This flag supports all JSON5 features with some additional extensions:
- Accepts more escape sequences than JSON5 (e.g. `\a`, `\e`).
- Unquoted keys are not limited to ECMAScript IdentifierName.
- Allow case-insensitive `NaN`, `Inf` and `Infinity` literals. */
static const yyjson_read_flag YYJSON_READ_JSON5 =
(1 << 2) | /* YYJSON_READ_ALLOW_TRAILING_COMMAS */
(1 << 3) | /* YYJSON_READ_ALLOW_COMMENTS */
(1 << 4) | /* YYJSON_READ_ALLOW_INF_AND_NAN */
(1 << 9) | /* YYJSON_READ_ALLOW_EXT_NUMBER */
(1 << 10) | /* YYJSON_READ_ALLOW_EXT_ESCAPE */
(1 << 11) | /* YYJSON_READ_ALLOW_EXT_WHITESPACE */
(1 << 12) | /* YYJSON_READ_ALLOW_SINGLE_QUOTED_STR */
(1 << 13); /* YYJSON_READ_ALLOW_UNQUOTED_KEY */
/** Result code for JSON reader. */
typedef uint32_t yyjson_read_code;
/** Success, no error. */
static const yyjson_read_code YYJSON_READ_SUCCESS = 0;
/** Invalid parameter, such as NULL input string or 0 input length. */
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_PARAMETER = 1;
/** Memory allocation failed. */
static const yyjson_read_code YYJSON_READ_ERROR_MEMORY_ALLOCATION = 2;
/** Input JSON string is empty. */
static const yyjson_read_code YYJSON_READ_ERROR_EMPTY_CONTENT = 3;
/** Unexpected content after document, such as `[123]abc`. */
static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CONTENT = 4;
/** Unexpected end of input, the parsed part is valid, such as `[123`. */
static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_END = 5;
/** Unexpected character inside the document, such as `[abc]`. */
static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CHARACTER = 6;
/** Invalid JSON structure, such as `[1,]`. */
static const yyjson_read_code YYJSON_READ_ERROR_JSON_STRUCTURE = 7;
/** Invalid comment, deprecated, use `UNEXPECTED_END` for unclosed comment. */
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_COMMENT = 8;
/** Invalid number, such as `123.e12`, `000`. */
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_NUMBER = 9;
/** Invalid string, such as invalid escaped character inside a string. */
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_STRING = 10;
/** Invalid JSON literal, such as `truu`. */
static const yyjson_read_code YYJSON_READ_ERROR_LITERAL = 11;
/** Failed to open a file. */
static const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12;
/** Failed to read a file. */
static const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13;
/** Incomplete input during incremental parsing; parsing state is preserved. */
static const yyjson_read_code YYJSON_READ_ERROR_MORE = 14;
/** Error information for JSON reader. */
typedef struct yyjson_read_err {
/** Error code, see `yyjson_read_code` for all possible values. */
yyjson_read_code code;
/** Error message, constant, no need to free (NULL if success). */
const char *msg;
/** Error byte position for input data (0 if success). */
size_t pos;
} yyjson_read_err;
#if !defined(YYJSON_DISABLE_READER) || !YYJSON_DISABLE_READER
/**
Read JSON with options.
This function is thread-safe when:
1. The `dat` is not modified by other threads.
2. The `alc` is thread-safe or NULL.
@param dat The JSON data (UTF-8 without BOM), null-terminator is not required.
If this parameter is NULL, the function will fail and return NULL.
The `dat` will not be modified without the flag `YYJSON_READ_INSITU`, so you
can pass a `const char *` string and case it to `char *` if you don't use
the `YYJSON_READ_INSITU` flag.
@param len The length of JSON data in bytes.
If this parameter is 0, the function will fail and return NULL.
@param flg The JSON read options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON reader.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON document, or NULL if an error occurs.
When it's no longer needed, it should be freed with `yyjson_doc_free()`.
*/
yyjson_api yyjson_doc *yyjson_read_opts(char *dat,
size_t len,
yyjson_read_flag flg,
const yyjson_alc *alc,
yyjson_read_err *err);
/**
Read a JSON file.
This function is thread-safe when:
1. The file is not modified by other threads.
2. The `alc` is thread-safe or NULL.
@param path The JSON file's path.
This should be a null-terminated string using the system's native encoding.
If this path is NULL or invalid, the function will fail and return NULL.
@param flg The JSON read options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON reader.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON document, or NULL if an error occurs.
When it's no longer needed, it should be freed with `yyjson_doc_free()`.
@warning On 32-bit operating system, files larger than 2GB may fail to read.
*/
yyjson_api yyjson_doc *yyjson_read_file(const char *path,
yyjson_read_flag flg,
const yyjson_alc *alc,
yyjson_read_err *err);
/**
Read JSON from a file pointer.
@param fp The file pointer.
The data will be read from the current position of the FILE to the end.
If this fp is NULL or invalid, the function will fail and return NULL.
@param flg The JSON read options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON reader.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON document, or NULL if an error occurs.
When it's no longer needed, it should be freed with `yyjson_doc_free()`.
@warning On 32-bit operating system, files larger than 2GB may fail to read.
*/
yyjson_api yyjson_doc *yyjson_read_fp(FILE *fp,
yyjson_read_flag flg,
const yyjson_alc *alc,
yyjson_read_err *err);
/**
Read a JSON string.
This function is thread-safe.
@param dat The JSON data (UTF-8 without BOM), null-terminator is not required.
If this parameter is NULL, the function will fail and return NULL.
@param len The length of JSON data in bytes.
If this parameter is 0, the function will fail and return NULL.
@param flg The JSON read options.
Multiple options can be combined with `|` operator. 0 means no options.
@return A new JSON document, or NULL if an error occurs.
When it's no longer needed, it should be freed with `yyjson_doc_free()`.
*/
yyjson_api_inline yyjson_doc *yyjson_read(const char *dat,
size_t len,
yyjson_read_flag flg) {
flg &= ~YYJSON_READ_INSITU; /* const string cannot be modified */
return yyjson_read_opts((char *)(void *)(size_t)(const void *)dat,
len, flg, NULL, NULL);
}
#if !defined(YYJSON_DISABLE_INCR_READER) || !YYJSON_DISABLE_INCR_READER
/** Opaque state for incremental JSON reader. */
typedef struct yyjson_incr_state yyjson_incr_state;
/**
Initialize state for incremental read.
To read a large JSON document incrementally:
1. Call `yyjson_incr_new()` to create the state for incremental reading.
2. Call `yyjson_incr_read()` repeatedly.
3. Call `yyjson_incr_free()` to free the state.
Note: The incremental JSON reader only supports standard JSON.
Flags for non-standard features (e.g. comments, trailing commas) are ignored.
@param buf The JSON data, null-terminator is not required.
If this parameter is NULL, the function will fail and return NULL.
@param buf_len The length of the JSON data in `buf`.
If use `YYJSON_READ_INSITU`, `buf_len` should not include the padding size.
@param flg The JSON read options.
Multiple options can be combined with `|` operator.
@param alc The memory allocator used by JSON reader.
Pass NULL to use the libc's default allocator.
@return A state for incremental reading.
It should be freed with `yyjson_incr_free()`.
NULL is returned if memory allocation fails.
*/
yyjson_api yyjson_incr_state *yyjson_incr_new(char *buf, size_t buf_len,
yyjson_read_flag flg,
const yyjson_alc *alc);
/**
Performs incremental read of up to `len` bytes.
If NULL is returned and `err->code` is set to `YYJSON_READ_ERROR_MORE`, it
indicates that more data is required to continue parsing. Then, call this
function again with incremented `len`. Continue until a document is returned or
an error other than `YYJSON_READ_ERROR_MORE` is returned.
Note: Parsing in very small increments is not efficient. An increment of
several kilobytes or megabytes is recommended.
@param state The state for incremental reading, created using
`yyjson_incr_new()`.
@param len The number of bytes of JSON data available to parse.
If this parameter is 0, the function will fail and return NULL.
@param err A pointer to receive error information.
@return A new JSON document, or NULL if an error occurs.
When the document is no longer needed, it should be freed with
`yyjson_doc_free()`.
*/
yyjson_api yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len,
yyjson_read_err *err);
/** Release the incremental read state and free the memory. */
yyjson_api void yyjson_incr_free(yyjson_incr_state *state);
#endif /* YYJSON_DISABLE_INCR_READER */
/**
Returns the size of maximum memory usage to read a JSON data.
You may use this value to avoid malloc() or calloc() call inside the reader
to get better performance, or read multiple JSON with one piece of memory.
@param len The length of JSON data in bytes.
@param flg The JSON read options.
@return The maximum memory size to read this JSON, or 0 if overflow.
@b Example
@code
// read multiple JSON with same pre-allocated memory
char *dat1, *dat2, *dat3; // JSON data
size_t len1, len2, len3; // JSON length
size_t max_len = MAX(len1, MAX(len2, len3));
yyjson_doc *doc;
// use one allocator for multiple JSON
size_t size = yyjson_read_max_memory_usage(max_len, 0);
void *buf = malloc(size);
yyjson_alc alc;
yyjson_alc_pool_init(&alc, buf, size);
// no more alloc() or realloc() call during reading
doc = yyjson_read_opts(dat1, len1, 0, &alc, NULL);
yyjson_doc_free(doc);
doc = yyjson_read_opts(dat2, len2, 0, &alc, NULL);
yyjson_doc_free(doc);
doc = yyjson_read_opts(dat3, len3, 0, &alc, NULL);
yyjson_doc_free(doc);
free(buf);
@endcode
@see yyjson_alc_pool_init()
*/
yyjson_api_inline size_t yyjson_read_max_memory_usage(size_t len,
yyjson_read_flag flg) {
/*
1. The max value count is (json_size / 2 + 1),
for example: "[1,2,3,4]" size is 9, value count is 5.
2. Some broken JSON may cost more memory during reading, but fail at end,
for example: "[[[[[[[[".
3. yyjson use 16 bytes per value, see struct yyjson_val.
4. yyjson use dynamic memory with a growth factor of 1.5.
The max memory size is (json_size / 2 * 16 * 1.5 + padding).
*/
size_t mul = (size_t)12 + !(flg & YYJSON_READ_INSITU);
size_t pad = 256;
size_t max = (size_t)(~(size_t)0);
if (flg & YYJSON_READ_STOP_WHEN_DONE) len = len < 256 ? 256 : len;
if (len >= (max - pad - mul) / mul) return 0;
return len * mul + pad;
}
/**
Read a JSON number.
This function is thread-safe when data is not modified by other threads.
@param dat The JSON data (UTF-8 without BOM), null-terminator is required.
If this parameter is NULL, the function will fail and return NULL.
@param val The output value where result is stored.
If this parameter is NULL, the function will fail and return NULL.
The value will hold either UINT or SINT or REAL number;
@param flg The JSON read options.
Multiple options can be combined with `|` operator. 0 means no options.
Supports `YYJSON_READ_NUMBER_AS_RAW` and `YYJSON_READ_ALLOW_INF_AND_NAN`.
@param alc The memory allocator used for long number.
It is only used when the built-in floating point reader is disabled.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return If successful, a pointer to the character after the last character
used in the conversion, NULL if an error occurs.
*/
yyjson_api const char *yyjson_read_number(const char *dat,
yyjson_val *val,
yyjson_read_flag flg,
const yyjson_alc *alc,
yyjson_read_err *err);
/** Same as `yyjson_read_number()`. */
yyjson_api_inline const char *yyjson_mut_read_number(const char *dat,
yyjson_mut_val *val,
yyjson_read_flag flg,
const yyjson_alc *alc,
yyjson_read_err *err) {
return yyjson_read_number(dat, (yyjson_val *)val, flg, alc, err);
}
#endif /* YYJSON_DISABLE_READER) */
/*==============================================================================
* MARK: - JSON Writer API
*============================================================================*/
/** Run-time options for JSON writer. */
typedef uint32_t yyjson_write_flag;
/** Default option:
- Write JSON minify.
- Report error on inf or nan number.
- Report error on invalid UTF-8 string.
- Do not escape unicode or slash. */
static const yyjson_write_flag YYJSON_WRITE_NOFLAG = 0;
/** Write JSON pretty with 4 space indent. */
static const yyjson_write_flag YYJSON_WRITE_PRETTY = 1 << 0;
/** Escape unicode as `uXXXX`, make the output ASCII only. */
static const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE = 1 << 1;
/** Escape '/' as '\/'. */
static const yyjson_write_flag YYJSON_WRITE_ESCAPE_SLASHES = 1 << 2;
/** Write inf and nan number as 'Infinity' and 'NaN' literal (non-standard). */
static const yyjson_write_flag YYJSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3;
/** Write inf and nan number as null literal.
This flag will override `YYJSON_WRITE_ALLOW_INF_AND_NAN` flag. */
static const yyjson_write_flag YYJSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4;
/** Allow invalid unicode when encoding string values (non-standard).
Invalid characters in string value will be copied byte by byte.
If `YYJSON_WRITE_ESCAPE_UNICODE` flag is also set, invalid character will be
escaped as `U+FFFD` (replacement character).
This flag does not affect the performance of correctly encoded strings. */
static const yyjson_write_flag YYJSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5;
/** Write JSON pretty with 2 space indent.
This flag will override `YYJSON_WRITE_PRETTY` flag. */
static const yyjson_write_flag YYJSON_WRITE_PRETTY_TWO_SPACES = 1 << 6;
/** Adds a newline character `\n` at the end of the JSON.
This can be helpful for text editors or NDJSON. */
static const yyjson_write_flag YYJSON_WRITE_NEWLINE_AT_END = 1 << 7;
/** The highest 8 bits of `yyjson_write_flag` and real number value's `tag`
are reserved for controlling the output format of floating-point numbers. */
#define YYJSON_WRITE_FP_FLAG_BITS 8
/** The highest 4 bits of flag are reserved for precision value. */
#define YYJSON_WRITE_FP_PREC_BITS 4
/** Write floating-point number using fixed-point notation.
- This is similar to ECMAScript `Number.prototype.toFixed(prec)`,
but with trailing zeros removed. The `prec` ranges from 1 to 15.
- This will produce shorter output but may lose some precision. */
#define YYJSON_WRITE_FP_TO_FIXED(prec) ((yyjson_write_flag)( \
(uint32_t)((uint32_t)(prec)) << (32 - 4) ))
/** Write floating-point numbers using single-precision (float).
- This casts `double` to `float` before serialization.
- This will produce shorter output, but may lose some precision.
- This flag is ignored if `YYJSON_WRITE_FP_TO_FIXED(prec)` is also used. */
#define YYJSON_WRITE_FP_TO_FLOAT ((yyjson_write_flag)(1 << (32 - 5)))
/** Result code for JSON writer */
typedef uint32_t yyjson_write_code;
/** Success, no error. */
static const yyjson_write_code YYJSON_WRITE_SUCCESS = 0;
/** Invalid parameter, such as NULL document. */
static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_PARAMETER = 1;
/** Memory allocation failure occurs. */
static const yyjson_write_code YYJSON_WRITE_ERROR_MEMORY_ALLOCATION = 2;
/** Invalid value type in JSON document. */
static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE = 3;
/** NaN or Infinity number occurs. */
static const yyjson_write_code YYJSON_WRITE_ERROR_NAN_OR_INF = 4;
/** Failed to open a file. */
static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_OPEN = 5;
/** Failed to write a file. */
static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_WRITE = 6;
/** Invalid unicode in string. */
static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_STRING = 7;
/** Error information for JSON writer. */
typedef struct yyjson_write_err {
/** Error code, see `yyjson_write_code` for all possible values. */
yyjson_write_code code;
/** Error message, constant, no need to free (NULL if success). */
const char *msg;
} yyjson_write_err;
#if !defined(YYJSON_DISABLE_WRITER) || !YYJSON_DISABLE_WRITER
/*==============================================================================
* MARK: - JSON Document Writer API
*============================================================================*/
/**
Write a document to JSON string with options.
This function is thread-safe when:
The `alc` is thread-safe or NULL.
@param doc The JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free() or alc->free().
*/
yyjson_api char *yyjson_write_opts(const yyjson_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc,
size_t *len,
yyjson_write_err *err);
/**
Write a document to JSON file with options.
This function is thread-safe when:
1. The file is not accessed by other threads.
2. The `alc` is thread-safe or NULL.
@param path The JSON file's path.
This should be a null-terminated string using the system's native encoding.
If this path is NULL or invalid, the function will fail and return false.
If this file is not empty, the content will be discarded.
@param doc The JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_write_file(const char *path,
const yyjson_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a document to file pointer with options.
@param fp The file pointer.
The data will be written to the current position of the file.
If this fp is NULL or invalid, the function will fail and return false.
@param doc The JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_write_fp(FILE *fp,
const yyjson_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a document to JSON string.
This function is thread-safe.
@param doc The JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free().
*/
yyjson_api_inline char *yyjson_write(const yyjson_doc *doc,
yyjson_write_flag flg,
size_t *len) {
return yyjson_write_opts(doc, flg, NULL, len, NULL);
}
/**
Write a document to JSON string with options.
This function is thread-safe when:
1. The `doc` is not modified by other threads.
2. The `alc` is thread-safe or NULL.
@param doc The mutable JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free() or alc->free().
*/
yyjson_api char *yyjson_mut_write_opts(const yyjson_mut_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc,
size_t *len,
yyjson_write_err *err);
/**
Write a document to JSON file with options.
This function is thread-safe when:
1. The file is not accessed by other threads.
2. The `doc` is not modified by other threads.
3. The `alc` is thread-safe or NULL.
@param path The JSON file's path.
This should be a null-terminated string using the system's native encoding.
If this path is NULL or invalid, the function will fail and return false.
If this file is not empty, the content will be discarded.
@param doc The mutable JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_mut_write_file(const char *path,
const yyjson_mut_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a document to file pointer with options.
@param fp The file pointer.
The data will be written to the current position of the file.
If this fp is NULL or invalid, the function will fail and return false.
@param doc The mutable JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_mut_write_fp(FILE *fp,
const yyjson_mut_doc *doc,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a document to JSON string.
This function is thread-safe when:
The `doc` is not modified by other threads.
@param doc The JSON document.
If this doc is NULL or has no root, the function will fail and return false.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free().
*/
yyjson_api_inline char *yyjson_mut_write(const yyjson_mut_doc *doc,
yyjson_write_flag flg,
size_t *len) {
return yyjson_mut_write_opts(doc, flg, NULL, len, NULL);
}
/*==============================================================================
* MARK: - JSON Value Writer API
*============================================================================*/
/**
Write a value to JSON string with options.
This function is thread-safe when:
The `alc` is thread-safe or NULL.
@param val The JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free() or alc->free().
*/
yyjson_api char *yyjson_val_write_opts(const yyjson_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc,
size_t *len,
yyjson_write_err *err);
/**
Write a value to JSON file with options.
This function is thread-safe when:
1. The file is not accessed by other threads.
2. The `alc` is thread-safe or NULL.
@param path The JSON file's path.
This should be a null-terminated string using the system's native encoding.
If this path is NULL or invalid, the function will fail and return false.
If this file is not empty, the content will be discarded.
@param val The JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_val_write_file(const char *path,
const yyjson_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a value to file pointer with options.
@param fp The file pointer.
The data will be written to the current position of the file.
If this path is NULL or invalid, the function will fail and return false.
@param val The JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_val_write_fp(FILE *fp,
const yyjson_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a value to JSON string.
This function is thread-safe.
@param val The JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free().
*/
yyjson_api_inline char *yyjson_val_write(const yyjson_val *val,
yyjson_write_flag flg,
size_t *len) {
return yyjson_val_write_opts(val, flg, NULL, len, NULL);
}
/**
Write a value to JSON string with options.
This function is thread-safe when:
1. The `val` is not modified by other threads.
2. The `alc` is thread-safe or NULL.
@param val The mutable JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free() or alc->free().
*/
yyjson_api char *yyjson_mut_val_write_opts(const yyjson_mut_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc,
size_t *len,
yyjson_write_err *err);
/**
Write a value to JSON file with options.
This function is thread-safe when:
1. The file is not accessed by other threads.
2. The `val` is not modified by other threads.
3. The `alc` is thread-safe or NULL.
@param path The JSON file's path.
This should be a null-terminated string using the system's native encoding.
If this path is NULL or invalid, the function will fail and return false.
If this file is not empty, the content will be discarded.
@param val The mutable JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_mut_val_write_file(const char *path,
const yyjson_mut_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a value to JSON file with options.
@param fp The file pointer.
The data will be written to the current position of the file.
If this path is NULL or invalid, the function will fail and return false.
@param val The mutable JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param alc The memory allocator used by JSON writer.
Pass NULL to use the libc's default allocator.
@param err A pointer to receive error information.
Pass NULL if you don't need error information.
@return true if successful, false if an error occurs.
@warning On 32-bit operating system, files larger than 2GB may fail to write.
*/
yyjson_api bool yyjson_mut_val_write_fp(FILE *fp,
const yyjson_mut_val *val,
yyjson_write_flag flg,
const yyjson_alc *alc,
yyjson_write_err *err);
/**
Write a value to JSON string.
This function is thread-safe when:
The `val` is not modified by other threads.
@param val The JSON root value.
If this parameter is NULL, the function will fail and return NULL.
@param flg The JSON write options.
Multiple options can be combined with `|` operator. 0 means no options.
@param len A pointer to receive output length in bytes (not including the
null-terminator). Pass NULL if you don't need length information.
@return A new JSON string, or NULL if an error occurs.
This string is encoded as UTF-8 with a null-terminator.
When it's no longer needed, it should be freed with free().
*/
yyjson_api_inline char *yyjson_mut_val_write(const yyjson_mut_val *val,
yyjson_write_flag flg,
size_t *len) {
return yyjson_mut_val_write_opts(val, flg, NULL, len, NULL);
}
/**
Write a JSON number.
@param val A JSON number value to be converted to a string.
If this parameter is invalid, the function will fail and return NULL.
@param buf A buffer to store the resulting null-terminated string.
If this parameter is NULL, the function will fail and return NULL.
For integer values, the buffer must be at least 21 bytes.
For floating-point values, the buffer must be at least 40 bytes.
@return On success, returns a pointer to the character after the last
written character. On failure, returns NULL.
@note
- This function is thread-safe and does not allocate memory
(when `YYJSON_DISABLE_FAST_FP_CONV` is not defined).
- This function will fail and return NULL only in the following cases:
1) `val` or `buf` is NULL;
2) `val` is not a number type;
3) `val` is `inf` or `nan`, and non-standard JSON is explicitly disabled
via the `YYJSON_DISABLE_NON_STANDARD` flag.
*/
yyjson_api char *yyjson_write_number(const yyjson_val *val, char *buf);
/** Same as `yyjson_write_number()`. */
yyjson_api_inline char *yyjson_mut_write_number(const yyjson_mut_val *val,
char *buf) {
return yyjson_write_number((const yyjson_val *)val, buf);
}
#endif /* YYJSON_DISABLE_WRITER */
/*==============================================================================
* MARK: - JSON Document API
*============================================================================*/
/** Returns the root value of this JSON document.
Returns NULL if `doc` is NULL. */
yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc);
/** Returns read size of input JSON data.
Returns 0 if `doc` is NULL.
For example: the read size of `[1,2,3]` is 7 bytes. */
yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc);
/** Returns total value count in this JSON document.
Returns 0 if `doc` is NULL.
For example: the value count of `[1,2,3]` is 4. */
yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc);
/** Release the JSON document and free the memory.
After calling this function, the `doc` and all values from the `doc` are no
longer available. This function will do nothing if the `doc` is NULL. */
yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc);
/*==============================================================================
* MARK: - JSON Value Type API
*============================================================================*/
/** Returns whether the JSON value is raw.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_raw(yyjson_val *val);
/** Returns whether the JSON value is `null`.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_null(yyjson_val *val);
/** Returns whether the JSON value is `true`.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_true(yyjson_val *val);
/** Returns whether the JSON value is `false`.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_false(yyjson_val *val);
/** Returns whether the JSON value is bool (true/false).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_bool(yyjson_val *val);
/** Returns whether the JSON value is unsigned integer (uint64_t).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_uint(yyjson_val *val);
/** Returns whether the JSON value is signed integer (int64_t).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_sint(yyjson_val *val);
/** Returns whether the JSON value is integer (uint64_t/int64_t).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_int(yyjson_val *val);
/** Returns whether the JSON value is real number (double).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_real(yyjson_val *val);
/** Returns whether the JSON value is number (uint64_t/int64_t/double).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_num(yyjson_val *val);
/** Returns whether the JSON value is string.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_str(yyjson_val *val);
/** Returns whether the JSON value is array.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_arr(yyjson_val *val);
/** Returns whether the JSON value is object.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_obj(yyjson_val *val);
/** Returns whether the JSON value is container (array/object).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val);
/*==============================================================================
* MARK: - JSON Value Content API
*============================================================================*/
/** Returns the JSON value's type.
Returns YYJSON_TYPE_NONE if `val` is NULL. */
yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val);
/** Returns the JSON value's subtype.
Returns YYJSON_SUBTYPE_NONE if `val` is NULL. */
yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val);
/** Returns the JSON value's tag.
Returns 0 if `val` is NULL. */
yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val);
/** Returns the JSON value's type description.
The return value should be one of these strings: "raw", "null", "string",
"array", "object", "true", "false", "uint", "sint", "real", "unknown". */
yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val);
/** Returns the content if the value is raw.
Returns NULL if `val` is NULL or type is not raw. */
yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val);
/** Returns the content if the value is bool.
Returns false if `val` is NULL or type is not bool. */
yyjson_api_inline bool yyjson_get_bool(yyjson_val *val);
/** Returns the content and cast to uint64_t.
Returns 0 if `val` is NULL or type is not integer(sint/uint). */
yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val);
/** Returns the content and cast to int64_t.
Returns 0 if `val` is NULL or type is not integer(sint/uint). */
yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val);
/** Returns the content and cast to int.
Returns 0 if `val` is NULL or type is not integer(sint/uint). */
yyjson_api_inline int yyjson_get_int(yyjson_val *val);
/** Returns the content if the value is real number, or 0.0 on error.
Returns 0.0 if `val` is NULL or type is not real(double). */
yyjson_api_inline double yyjson_get_real(yyjson_val *val);
/** Returns the content and typecast to `double` if the value is number.
Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */
yyjson_api_inline double yyjson_get_num(yyjson_val *val);
/** Returns the content if the value is string.
Returns NULL if `val` is NULL or type is not string. */
yyjson_api_inline const char *yyjson_get_str(yyjson_val *val);
/** Returns the content length (string length, array size, object size.
Returns 0 if `val` is NULL or type is not string/array/object. */
yyjson_api_inline size_t yyjson_get_len(yyjson_val *val);
/** Returns whether the JSON value is equals to a string.
Returns false if input is NULL or type is not string. */
yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str);
/** Returns whether the JSON value is equals to a string.
The `str` should be a UTF-8 string, null-terminator is not required.
Returns false if input is NULL or type is not string. */
yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str,
size_t len);
/** Returns whether two JSON values are equal (deep compare).
Returns false if input is NULL.
@note the result may be inaccurate if object has duplicate keys.
@warning This function is recursive and may cause a stack overflow
if the object level is too deep. */
yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs);
/** Set the value to raw.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_raw(yyjson_val *val,
const char *raw, size_t len);
/** Set the value to null.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_null(yyjson_val *val);
/** Set the value to bool.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num);
/** Set the value to uint.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num);
/** Set the value to sint.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num);
/** Set the value to int.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num);
/** Set the value to float.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_float(yyjson_val *val, float num);
/** Set the value to double.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_double(yyjson_val *val, double num);
/** Set the value to real.
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num);
/** Set the floating-point number's output format to fixed-point notation.
Returns false if input is NULL or `val` is not real type.
@see YYJSON_WRITE_FP_TO_FIXED flag.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_fp_to_fixed(yyjson_val *val, int prec);
/** Set the floating-point number's output format to single-precision.
Returns false if input is NULL or `val` is not real type.
@see YYJSON_WRITE_FP_TO_FLOAT flag.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_fp_to_float(yyjson_val *val, bool flt);
/** Set the value to string (null-terminated).
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str);
/** Set the value to string (with length).
Returns false if input is NULL or `val` is object or array.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_strn(yyjson_val *val,
const char *str, size_t len);
/** Marks this string as not needing to be escaped during JSON writing.
This can be used to avoid the overhead of escaping if the string contains
only characters that do not require escaping.
Returns false if input is NULL or `val` is not string.
@see YYJSON_SUBTYPE_NOESC subtype.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_set_str_noesc(yyjson_val *val, bool noesc);
/*==============================================================================
* MARK: - JSON Array API
*============================================================================*/
/** Returns the number of elements in this array.
Returns 0 if `arr` is NULL or type is not array. */
yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr);
/** Returns the element at the specified position in this array.
Returns NULL if array is NULL/empty or the index is out of bounds.
@warning This function takes a linear search time if array is not flat.
For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat. */
yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx);
/** Returns the first element of this array.
Returns NULL if `arr` is NULL/empty or type is not array. */
yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr);
/** Returns the last element of this array.
Returns NULL if `arr` is NULL/empty or type is not array.
@warning This function takes a linear search time if array is not flat.
For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat.*/
yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr);
/*==============================================================================
* MARK: - JSON Array Iterator API
*============================================================================*/
/**
A JSON array iterator.
@b Example
@code
yyjson_val *val;
yyjson_arr_iter iter = yyjson_arr_iter_with(arr);
while ((val = yyjson_arr_iter_next(&iter))) {
your_func(val);
}
@endcode
*/
typedef struct yyjson_arr_iter {
size_t idx; /**< next value's index */
size_t max; /**< maximum index (arr.size) */
yyjson_val *cur; /**< next value */
} yyjson_arr_iter;
/**
Initialize an iterator for this array.
@param arr The array to be iterated over.
If this parameter is NULL or not an array, `iter` will be set to empty.
@param iter The iterator to be initialized.
If this parameter is NULL, the function will fail and return false.
@return true if the `iter` has been successfully initialized.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr,
yyjson_arr_iter *iter);
/**
Create an iterator with an array , same as `yyjson_arr_iter_init()`.
@param arr The array to be iterated over.
If this parameter is NULL or not an array, an empty iterator will returned.
@return A new iterator for the array.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr);
/**
Returns whether the iteration has more elements.
If `iter` is NULL, this function will return false.
*/
yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter);
/**
Returns the next element in the iteration, or NULL on end.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter);
/**
Macro for iterating over an array.
It works like iterator, but with a more intuitive API.
@b Example
@code
size_t idx, max;
yyjson_val *val;
yyjson_arr_foreach(arr, idx, max, val) {
your_func(idx, val);
}
@endcode
*/
#define yyjson_arr_foreach(arr, idx, max, val) \
for ((idx) = 0, \
(max) = yyjson_arr_size(arr), \
(val) = yyjson_arr_get_first(arr); \
(idx) < (max); \
(idx)++, \
(val) = unsafe_yyjson_get_next(val))
/*==============================================================================
* MARK: - JSON Object API
*============================================================================*/
/** Returns the number of key-value pairs in this object.
Returns 0 if `obj` is NULL or type is not object. */
yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj);
/** Returns the value to which the specified key is mapped.
Returns NULL if this object contains no mapping for the key.
Returns NULL if `obj/key` is NULL, or type is not object.
The `key` should be a null-terminated UTF-8 string.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, const char *key);
/** Returns the value to which the specified key is mapped.
Returns NULL if this object contains no mapping for the key.
Returns NULL if `obj/key` is NULL, or type is not object.
The `key` should be a UTF-8 string, null-terminator is not required.
The `key_len` should be the length of the key, in bytes.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, const char *key,
size_t key_len);
/*==============================================================================
* MARK: - JSON Object Iterator API
*============================================================================*/
/**
A JSON object iterator.
@b Example
@code
yyjson_val *key, *val;
yyjson_obj_iter iter = yyjson_obj_iter_with(obj);
while ((key = yyjson_obj_iter_next(&iter))) {
val = yyjson_obj_iter_get_val(key);
your_func(key, val);
}
@endcode
If the ordering of the keys is known at compile-time, you can use this method
to speed up value lookups:
@code
// {"k1":1, "k2": 3, "k3": 3}
yyjson_val *key, *val;
yyjson_obj_iter iter = yyjson_obj_iter_with(obj);
yyjson_val *v1 = yyjson_obj_iter_get(&iter, "k1");
yyjson_val *v3 = yyjson_obj_iter_get(&iter, "k3");
@endcode
@see yyjson_obj_iter_get() and yyjson_obj_iter_getn()
*/
typedef struct yyjson_obj_iter {
size_t idx; /**< next key's index */
size_t max; /**< maximum key index (obj.size) */
yyjson_val *cur; /**< next key */
yyjson_val *obj; /**< the object being iterated */
} yyjson_obj_iter;
/**
Initialize an iterator for this object.
@param obj The object to be iterated over.
If this parameter is NULL or not an object, `iter` will be set to empty.
@param iter The iterator to be initialized.
If this parameter is NULL, the function will fail and return false.
@return true if the `iter` has been successfully initialized.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj,
yyjson_obj_iter *iter);
/**
Create an iterator with an object, same as `yyjson_obj_iter_init()`.
@param obj The object to be iterated over.
If this parameter is NULL or not an object, an empty iterator will returned.
@return A new iterator for the object.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj);
/**
Returns whether the iteration has more elements.
If `iter` is NULL, this function will return false.
*/
yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter);
/**
Returns the next key in the iteration, or NULL on end.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter);
/**
Returns the value for key inside the iteration.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key);
/**
Iterates to a specified key and returns the value.
This function does the same thing as `yyjson_obj_get()`, but is much faster
if the ordering of the keys is known at compile-time and you are using the same
order to look up the values. If the key exists in this object, then the
iterator will stop at the next key, otherwise the iterator will not change and
NULL is returned.
@param iter The object iterator, should not be NULL.
@param key The key, should be a UTF-8 string with null-terminator.
@return The value to which the specified key is mapped.
NULL if this object contains no mapping for the key or input is invalid.
@warning This function takes a linear search time if the key is not nearby.
*/
yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter,
const char *key);
/**
Iterates to a specified key and returns the value.
This function does the same thing as `yyjson_obj_getn()`, but is much faster
if the ordering of the keys is known at compile-time and you are using the same
order to look up the values. If the key exists in this object, then the
iterator will stop at the next key, otherwise the iterator will not change and
NULL is returned.
@param iter The object iterator, should not be NULL.
@param key The key, should be a UTF-8 string, null-terminator is not required.
@param key_len The the length of `key`, in bytes.
@return The value to which the specified key is mapped.
NULL if this object contains no mapping for the key or input is invalid.
@warning This function takes a linear search time if the key is not nearby.
*/
yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter,
const char *key,
size_t key_len);
/**
Macro for iterating over an object.
It works like iterator, but with a more intuitive API.
@b Example
@code
size_t idx, max;
yyjson_val *key, *val;
yyjson_obj_foreach(obj, idx, max, key, val) {
your_func(key, val);
}
@endcode
*/
#define yyjson_obj_foreach(obj, idx, max, key, val) \
for ((idx) = 0, \
(max) = yyjson_obj_size(obj), \
(key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, \
(val) = (key) + 1; \
(idx) < (max); \
(idx)++, \
(key) = unsafe_yyjson_get_next(val), \
(val) = (key) + 1)
/*==============================================================================
* MARK: - Mutable JSON Document API
*============================================================================*/
/** Returns the root value of this JSON document.
Returns NULL if `doc` is NULL. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc);
/** Sets the root value of this JSON document.
Pass NULL to clear root value of the document. */
yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc,
yyjson_mut_val *root);
/**
Set the string pool size for a mutable document.
This function does not allocate memory immediately, but uses the size when
the next memory allocation is needed.
If the caller knows the approximate bytes of strings that the document needs to
store (e.g. copy string with `yyjson_mut_strcpy` function), setting a larger
size can avoid multiple memory allocations and improve performance.
@param doc The mutable document.
@param len The desired string pool size in bytes (total string length).
@return true if successful, false if size is 0 or overflow.
*/
yyjson_api bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc,
size_t len);
/**
Set the value pool size for a mutable document.
This function does not allocate memory immediately, but uses the size when
the next memory allocation is needed.
If the caller knows the approximate number of values that the document needs to
store (e.g. create new value with `yyjson_mut_xxx` functions), setting a larger
size can avoid multiple memory allocations and improve performance.
@param doc The mutable document.
@param count The desired value pool size (number of `yyjson_mut_val`).
@return true if successful, false if size is 0 or overflow.
*/
yyjson_api bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc,
size_t count);
/** Release the JSON document and free the memory.
After calling this function, the `doc` and all values from the `doc` are no
longer available. This function will do nothing if the `doc` is NULL. */
yyjson_api void yyjson_mut_doc_free(yyjson_mut_doc *doc);
/** Creates and returns a new mutable JSON document, returns NULL on error.
If allocator is NULL, the default allocator will be used. */
yyjson_api yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc);
/** Copies and returns a new mutable document from input, returns NULL on error.
This makes a `deep-copy` on the immutable document.
If allocator is NULL, the default allocator will be used.
@note `imut_doc` -> `mut_doc`. */
yyjson_api yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc,
const yyjson_alc *alc);
/** Copies and returns a new mutable document from input, returns NULL on error.
This makes a `deep-copy` on the mutable document.
If allocator is NULL, the default allocator will be used.
@note `mut_doc` -> `mut_doc`. */
yyjson_api yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc,
const yyjson_alc *alc);
/** Copies and returns a new mutable value from input, returns NULL on error.
This makes a `deep-copy` on the immutable value.
The memory was managed by mutable document.
@note `imut_val` -> `mut_val`. */
yyjson_api yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *doc,
yyjson_val *val);
/** Copies and returns a new mutable value from input, returns NULL on error.
This makes a `deep-copy` on the mutable value.
The memory was managed by mutable document.
@note `mut_val` -> `mut_val`.
@warning This function is recursive and may cause a stack overflow
if the object level is too deep. */
yyjson_api yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc,
yyjson_mut_val *val);
/** Copies and returns a new immutable document from input,
returns NULL on error. This makes a `deep-copy` on the mutable document.
The returned document should be freed with `yyjson_doc_free()`.
@note `mut_doc` -> `imut_doc`.
@warning This function is recursive and may cause a stack overflow
if the object level is too deep. */
yyjson_api yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *doc,
const yyjson_alc *alc);
/** Copies and returns a new immutable document from input,
returns NULL on error. This makes a `deep-copy` on the mutable value.
The returned document should be freed with `yyjson_doc_free()`.
@note `mut_val` -> `imut_doc`.
@warning This function is recursive and may cause a stack overflow
if the object level is too deep. */
yyjson_api yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *val,
const yyjson_alc *alc);
/*==============================================================================
* MARK: - Mutable JSON Value Type API
*============================================================================*/
/** Returns whether the JSON value is raw.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val);
/** Returns whether the JSON value is `null`.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val);
/** Returns whether the JSON value is `true`.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val);
/** Returns whether the JSON value is `false`.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val);
/** Returns whether the JSON value is bool (true/false).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val);
/** Returns whether the JSON value is unsigned integer (uint64_t).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val);
/** Returns whether the JSON value is signed integer (int64_t).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val);
/** Returns whether the JSON value is integer (uint64_t/int64_t).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val);
/** Returns whether the JSON value is real number (double).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val);
/** Returns whether the JSON value is number (uint/sint/real).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val);
/** Returns whether the JSON value is string.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val);
/** Returns whether the JSON value is array.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val);
/** Returns whether the JSON value is object.
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val);
/** Returns whether the JSON value is container (array/object).
Returns false if `val` is NULL. */
yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val);
/*==============================================================================
* MARK: - Mutable JSON Value Content API
*============================================================================*/
/** Returns the JSON value's type.
Returns `YYJSON_TYPE_NONE` if `val` is NULL. */
yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val);
/** Returns the JSON value's subtype.
Returns `YYJSON_SUBTYPE_NONE` if `val` is NULL. */
yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val);
/** Returns the JSON value's tag.
Returns 0 if `val` is NULL. */
yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val);
/** Returns the JSON value's type description.
The return value should be one of these strings: "raw", "null", "string",
"array", "object", "true", "false", "uint", "sint", "real", "unknown". */
yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val);
/** Returns the content if the value is raw.
Returns NULL if `val` is NULL or type is not raw. */
yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val);
/** Returns the content if the value is bool.
Returns NULL if `val` is NULL or type is not bool. */
yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val);
/** Returns the content and cast to uint64_t.
Returns 0 if `val` is NULL or type is not integer(sint/uint). */
yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val);
/** Returns the content and cast to int64_t.
Returns 0 if `val` is NULL or type is not integer(sint/uint). */
yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val);
/** Returns the content and cast to int.
Returns 0 if `val` is NULL or type is not integer(sint/uint). */
yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val);
/** Returns the content if the value is real number.
Returns 0.0 if `val` is NULL or type is not real(double). */
yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val);
/** Returns the content and typecast to `double` if the value is number.
Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */
yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val);
/** Returns the content if the value is string.
Returns NULL if `val` is NULL or type is not string. */
yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val);
/** Returns the content length (string length, array size, object size.
Returns 0 if `val` is NULL or type is not string/array/object. */
yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val);
/** Returns whether the JSON value is equals to a string.
The `str` should be a null-terminated UTF-8 string.
Returns false if input is NULL or type is not string. */
yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val,
const char *str);
/** Returns whether the JSON value is equals to a string.
The `str` should be a UTF-8 string, null-terminator is not required.
Returns false if input is NULL or type is not string. */
yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val,
const char *str, size_t len);
/** Returns whether two JSON values are equal (deep compare).
Returns false if input is NULL.
@note the result may be inaccurate if object has duplicate keys.
@warning This function is recursive and may cause a stack overflow
if the object level is too deep. */
yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs,
yyjson_mut_val *rhs);
/** Set the value to raw.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val,
const char *raw, size_t len);
/** Set the value to null.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val);
/** Set the value to bool.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num);
/** Set the value to uint.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num);
/** Set the value to sint.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num);
/** Set the value to int.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num);
/** Set the value to float.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_float(yyjson_mut_val *val, float num);
/** Set the value to double.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_double(yyjson_mut_val *val, double num);
/** Set the value to real.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num);
/** Set the floating-point number's output format to fixed-point notation.
Returns false if input is NULL or `val` is not real type.
@see YYJSON_WRITE_FP_TO_FIXED flag.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_mut_set_fp_to_fixed(yyjson_mut_val *val,
int prec);
/** Set the floating-point number's output format to single-precision.
Returns false if input is NULL or `val` is not real type.
@see YYJSON_WRITE_FP_TO_FLOAT flag.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_mut_set_fp_to_float(yyjson_mut_val *val,
bool flt);
/** Set the value to string (null-terminated).
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, const char *str);
/** Set the value to string (with length).
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val,
const char *str, size_t len);
/** Marks this string as not needing to be escaped during JSON writing.
This can be used to avoid the overhead of escaping if the string contains
only characters that do not require escaping.
Returns false if input is NULL or `val` is not string.
@see YYJSON_SUBTYPE_NOESC subtype.
@warning This will modify the `immutable` value, use with caution. */
yyjson_api_inline bool yyjson_mut_set_str_noesc(yyjson_mut_val *val,
bool noesc);
/** Set the value to array.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val);
/** Set the value to array.
Returns false if input is NULL.
@warning This function should not be used on an existing object or array. */
yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val);
/*==============================================================================
* MARK: - Mutable JSON Value Creation API
*============================================================================*/
/** Creates and returns a raw value, returns NULL on error.
The `str` should be a null-terminated UTF-8 string.
@warning The input string is not copied, you should keep this string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc,
const char *str);
/** Creates and returns a raw value, returns NULL on error.
The `str` should be a UTF-8 string, null-terminator is not required.
@warning The input string is not copied, you should keep this string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc,
const char *str,
size_t len);
/** Creates and returns a raw value, returns NULL on error.
The `str` should be a null-terminated UTF-8 string.
The input string is copied and held by the document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc,
const char *str);
/** Creates and returns a raw value, returns NULL on error.
The `str` should be a UTF-8 string, null-terminator is not required.
The input string is copied and held by the document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc,
const char *str,
size_t len);
/** Creates and returns a null value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc);
/** Creates and returns a true value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc);
/** Creates and returns a false value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc);
/** Creates and returns a bool value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc,
bool val);
/** Creates and returns an unsigned integer value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc,
uint64_t num);
/** Creates and returns a signed integer value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc,
int64_t num);
/** Creates and returns a signed integer value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc,
int64_t num);
/** Creates and returns a float number value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_float(yyjson_mut_doc *doc,
float num);
/** Creates and returns a double number value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_double(yyjson_mut_doc *doc,
double num);
/** Creates and returns a real number value, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc,
double num);
/** Creates and returns a string value, returns NULL on error.
The `str` should be a null-terminated UTF-8 string.
@warning The input string is not copied, you should keep this string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc,
const char *str);
/** Creates and returns a string value, returns NULL on error.
The `str` should be a UTF-8 string, null-terminator is not required.
@warning The input string is not copied, you should keep this string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc,
const char *str,
size_t len);
/** Creates and returns a string value, returns NULL on error.
The `str` should be a null-terminated UTF-8 string.
The input string is copied and held by the document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc,
const char *str);
/** Creates and returns a string value, returns NULL on error.
The `str` should be a UTF-8 string, null-terminator is not required.
The input string is copied and held by the document. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc,
const char *str,
size_t len);
/*==============================================================================
* MARK: - Mutable JSON Array API
*============================================================================*/
/** Returns the number of elements in this array.
Returns 0 if `arr` is NULL or type is not array. */
yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr);
/** Returns the element at the specified position in this array.
Returns NULL if array is NULL/empty or the index is out of bounds.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr,
size_t idx);
/** Returns the first element of this array.
Returns NULL if `arr` is NULL/empty or type is not array. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first(yyjson_mut_val *arr);
/** Returns the last element of this array.
Returns NULL if `arr` is NULL/empty or type is not array. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last(yyjson_mut_val *arr);
/*==============================================================================
* MARK: - Mutable JSON Array Iterator API
*============================================================================*/
/**
A mutable JSON array iterator.
@warning You should not modify the array while iterating over it, but you can
use `yyjson_mut_arr_iter_remove()` to remove current value.
@b Example
@code
yyjson_mut_val *val;
yyjson_mut_arr_iter iter = yyjson_mut_arr_iter_with(arr);
while ((val = yyjson_mut_arr_iter_next(&iter))) {
your_func(val);
if (your_val_is_unused(val)) {
yyjson_mut_arr_iter_remove(&iter);
}
}
@endcode
*/
typedef struct yyjson_mut_arr_iter {
size_t idx; /**< next value's index */
size_t max; /**< maximum index (arr.size) */
yyjson_mut_val *cur; /**< current value */
yyjson_mut_val *pre; /**< previous value */
yyjson_mut_val *arr; /**< the array being iterated */
} yyjson_mut_arr_iter;
/**
Initialize an iterator for this array.
@param arr The array to be iterated over.
If this parameter is NULL or not an array, `iter` will be set to empty.
@param iter The iterator to be initialized.
If this parameter is NULL, the function will fail and return false.
@return true if the `iter` has been successfully initialized.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr,
yyjson_mut_arr_iter *iter);
/**
Create an iterator with an array , same as `yyjson_mut_arr_iter_init()`.
@param arr The array to be iterated over.
If this parameter is NULL or not an array, an empty iterator will returned.
@return A new iterator for the array.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with(
yyjson_mut_val *arr);
/**
Returns whether the iteration has more elements.
If `iter` is NULL, this function will return false.
*/
yyjson_api_inline bool yyjson_mut_arr_iter_has_next(
yyjson_mut_arr_iter *iter);
/**
Returns the next element in the iteration, or NULL on end.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next(
yyjson_mut_arr_iter *iter);
/**
Removes and returns current element in the iteration.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove(
yyjson_mut_arr_iter *iter);
/**
Macro for iterating over an array.
It works like iterator, but with a more intuitive API.
@warning You should not modify the array while iterating over it.
@b Example
@code
size_t idx, max;
yyjson_mut_val *val;
yyjson_mut_arr_foreach(arr, idx, max, val) {
your_func(idx, val);
}
@endcode
*/
#define yyjson_mut_arr_foreach(arr, idx, max, val) \
for ((idx) = 0, \
(max) = yyjson_mut_arr_size(arr), \
(val) = yyjson_mut_arr_get_first(arr); \
(idx) < (max); \
(idx)++, \
(val) = (val)->next)
/*==============================================================================
* MARK: - Mutable JSON Array Creation API
*============================================================================*/
/**
Creates and returns an empty mutable array.
@param doc A mutable document, used for memory allocation only.
@return The new array. NULL if input is NULL or memory allocation failed.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc);
/**
Creates and returns a new mutable array with the given boolean values.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of boolean values.
@param count The value count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const bool vals[3] = { true, false, true };
yyjson_mut_val *arr = yyjson_mut_arr_with_bool(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool(
yyjson_mut_doc *doc, const bool *vals, size_t count);
/**
Creates and returns a new mutable array with the given sint numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of sint numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const int64_t vals[3] = { -1, 0, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint(
yyjson_mut_doc *doc, const int64_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given uint numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of uint numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const uint64_t vals[3] = { 0, 1, 0 };
yyjson_mut_val *arr = yyjson_mut_arr_with_uint(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint(
yyjson_mut_doc *doc, const uint64_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given real numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of real numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const double vals[3] = { 0.1, 0.2, 0.3 };
yyjson_mut_val *arr = yyjson_mut_arr_with_real(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real(
yyjson_mut_doc *doc, const double *vals, size_t count);
/**
Creates and returns a new mutable array with the given int8 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of int8 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const int8_t vals[3] = { -1, 0, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_sint8(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8(
yyjson_mut_doc *doc, const int8_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given int16 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of int16 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const int16_t vals[3] = { -1, 0, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_sint16(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16(
yyjson_mut_doc *doc, const int16_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given int32 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of int32 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const int32_t vals[3] = { -1, 0, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_sint32(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32(
yyjson_mut_doc *doc, const int32_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given int64 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of int64 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const int64_t vals[3] = { -1, 0, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64(
yyjson_mut_doc *doc, const int64_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given uint8 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of uint8 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const uint8_t vals[3] = { 0, 1, 0 };
yyjson_mut_val *arr = yyjson_mut_arr_with_uint8(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8(
yyjson_mut_doc *doc, const uint8_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given uint16 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of uint16 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const uint16_t vals[3] = { 0, 1, 0 };
yyjson_mut_val *arr = yyjson_mut_arr_with_uint16(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16(
yyjson_mut_doc *doc, const uint16_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given uint32 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of uint32 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const uint32_t vals[3] = { 0, 1, 0 };
yyjson_mut_val *arr = yyjson_mut_arr_with_uint32(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32(
yyjson_mut_doc *doc, const uint32_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given uint64 numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of uint64 numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const uint64_t vals[3] = { 0, 1, 0 };
yyjson_mut_val *arr = yyjson_mut_arr_with_uint64(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64(
yyjson_mut_doc *doc, const uint64_t *vals, size_t count);
/**
Creates and returns a new mutable array with the given float numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of float numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const float vals[3] = { -1.0f, 0.0f, 1.0f };
yyjson_mut_val *arr = yyjson_mut_arr_with_float(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float(
yyjson_mut_doc *doc, const float *vals, size_t count);
/**
Creates and returns a new mutable array with the given double numbers.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of double numbers.
@param count The number count. If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const double vals[3] = { -1.0, 0.0, 1.0 };
yyjson_mut_val *arr = yyjson_mut_arr_with_double(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double(
yyjson_mut_doc *doc, const double *vals, size_t count);
/**
Creates and returns a new mutable array with the given strings, these strings
will not be copied.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of UTF-8 null-terminator strings.
If this array contains NULL, the function will fail and return NULL.
@param count The number of values in `vals`.
If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@warning The input strings are not copied, you should keep these strings
unmodified for the lifetime of this JSON document. If these strings will be
modified, you should use `yyjson_mut_arr_with_strcpy()` instead.
@b Example
@code
const char *vals[3] = { "a", "b", "c" };
yyjson_mut_val *arr = yyjson_mut_arr_with_str(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str(
yyjson_mut_doc *doc, const char **vals, size_t count);
/**
Creates and returns a new mutable array with the given strings and string
lengths, these strings will not be copied.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of UTF-8 strings, null-terminator is not required.
If this array contains NULL, the function will fail and return NULL.
@param lens A C array of string lengths, in bytes.
@param count The number of strings in `vals`.
If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@warning The input strings are not copied, you should keep these strings
unmodified for the lifetime of this JSON document. If these strings will be
modified, you should use `yyjson_mut_arr_with_strncpy()` instead.
@b Example
@code
const char *vals[3] = { "a", "bb", "c" };
const size_t lens[3] = { 1, 2, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn(
yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count);
/**
Creates and returns a new mutable array with the given strings, these strings
will be copied.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of UTF-8 null-terminator strings.
If this array contains NULL, the function will fail and return NULL.
@param count The number of values in `vals`.
If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const char *vals[3] = { "a", "b", "c" };
yyjson_mut_val *arr = yyjson_mut_arr_with_strcpy(doc, vals, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy(
yyjson_mut_doc *doc, const char **vals, size_t count);
/**
Creates and returns a new mutable array with the given strings and string
lengths, these strings will be copied.
@param doc A mutable document, used for memory allocation only.
If this parameter is NULL, the function will fail and return NULL.
@param vals A C array of UTF-8 strings, null-terminator is not required.
If this array contains NULL, the function will fail and return NULL.
@param lens A C array of string lengths, in bytes.
@param count The number of strings in `vals`.
If this value is 0, an empty array will return.
@return The new array. NULL if input is invalid or memory allocation failed.
@b Example
@code
const char *vals[3] = { "a", "bb", "c" };
const size_t lens[3] = { 1, 2, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy(
yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count);
/*==============================================================================
* MARK: - Mutable JSON Array Modification API
*============================================================================*/
/**
Inserts a value into an array at a given index.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param val The value to be inserted. Returns false if it is NULL.
@param idx The index to which to insert the new value.
Returns false if the index is out of range.
@return Whether successful.
@warning This function takes a linear search time.
*/
yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr,
yyjson_mut_val *val, size_t idx);
/**
Inserts a value at the end of the array.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param val The value to be inserted. Returns false if it is NULL.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr,
yyjson_mut_val *val);
/**
Inserts a value at the head of the array.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param val The value to be inserted. Returns false if it is NULL.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr,
yyjson_mut_val *val);
/**
Replaces a value at index and returns old value.
@param arr The array to which the value is to be replaced.
Returns false if it is NULL or not an array.
@param idx The index to which to replace the value.
Returns false if the index is out of range.
@param val The new value to replace. Returns false if it is NULL.
@return Old value, or NULL on error.
@warning This function takes a linear search time.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr,
size_t idx,
yyjson_mut_val *val);
/**
Removes and returns a value at index.
@param arr The array from which the value is to be removed.
Returns false if it is NULL or not an array.
@param idx The index from which to remove the value.
Returns false if the index is out of range.
@return Old value, or NULL on error.
@warning This function takes a linear search time.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr,
size_t idx);
/**
Removes and returns the first value in this array.
@param arr The array from which the value is to be removed.
Returns false if it is NULL or not an array.
@return The first value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first(
yyjson_mut_val *arr);
/**
Removes and returns the last value in this array.
@param arr The array from which the value is to be removed.
Returns false if it is NULL or not an array.
@return The last value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last(
yyjson_mut_val *arr);
/**
Removes all values within a specified range in the array.
@param arr The array from which the value is to be removed.
Returns false if it is NULL or not an array.
@param idx The start index of the range (0 is the first).
@param len The number of items in the range (can be 0).
@return Whether successful.
@warning This function takes a linear search time.
*/
yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr,
size_t idx, size_t len);
/**
Removes all values in this array.
@param arr The array from which all of the values are to be removed.
Returns false if it is NULL or not an array.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr);
/**
Rotates values in this array for the given number of times.
For example: `[1,2,3,4,5]` rotate 2 is `[3,4,5,1,2]`.
@param arr The array to be rotated.
@param idx Index (or times) to rotate.
@warning This function takes a linear search time.
*/
yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr,
size_t idx);
/*==============================================================================
* MARK: - Mutable JSON Array Modification Convenience API
*============================================================================*/
/**
Adds a value at the end of the array.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param val The value to be inserted. Returns false if it is NULL.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr,
yyjson_mut_val *val);
/**
Adds a `null` value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc,
yyjson_mut_val *arr);
/**
Adds a `true` value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc,
yyjson_mut_val *arr);
/**
Adds a `false` value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc,
yyjson_mut_val *arr);
/**
Adds a bool value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param val The bool value to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
bool val);
/**
Adds an unsigned integer value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param num The number to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
uint64_t num);
/**
Adds a signed integer value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param num The number to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
int64_t num);
/**
Adds an integer value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param num The number to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
int64_t num);
/**
Adds a float value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param num The number to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_float(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
float num);
/**
Adds a double value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param num The number to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_double(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
double num);
/**
Adds a double value at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param num The number to be added.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
double num);
/**
Adds a string value at the end of the array (no copy).
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param str A null-terminated UTF-8 string.
@return Whether successful.
@warning The input string is not copied, you should keep this string unmodified
for the lifetime of this JSON document.
*/
yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str);
/**
Adds a string value at the end of the array (no copy).
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param str A UTF-8 string, null-terminator is not required.
@param len The length of the string, in bytes.
@return Whether successful.
@warning The input string is not copied, you should keep this string unmodified
for the lifetime of this JSON document.
*/
yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str,
size_t len);
/**
Adds a string value at the end of the array (copied).
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param str A null-terminated UTF-8 string.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str);
/**
Adds a string value at the end of the array (copied).
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@param str A UTF-8 string, null-terminator is not required.
@param len The length of the string, in bytes.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str,
size_t len);
/**
Creates and adds a new array at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@return The new array, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc,
yyjson_mut_val *arr);
/**
Creates and adds a new object at the end of the array.
@param doc The `doc` is only used for memory allocation.
@param arr The array to which the value is to be inserted.
Returns false if it is NULL or not an array.
@return The new object, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc,
yyjson_mut_val *arr);
/*==============================================================================
* MARK: - Mutable JSON Object API
*============================================================================*/
/** Returns the number of key-value pairs in this object.
Returns 0 if `obj` is NULL or type is not object. */
yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj);
/** Returns the value to which the specified key is mapped.
Returns NULL if this object contains no mapping for the key.
Returns NULL if `obj/key` is NULL, or type is not object.
The `key` should be a null-terminated UTF-8 string.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj,
const char *key);
/** Returns the value to which the specified key is mapped.
Returns NULL if this object contains no mapping for the key.
Returns NULL if `obj/key` is NULL, or type is not object.
The `key` should be a UTF-8 string, null-terminator is not required.
The `key_len` should be the length of the key, in bytes.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj,
const char *key,
size_t key_len);
/*==============================================================================
* MARK: - Mutable JSON Object Iterator API
*============================================================================*/
/**
A mutable JSON object iterator.
@warning You should not modify the object while iterating over it, but you can
use `yyjson_mut_obj_iter_remove()` to remove current value.
@b Example
@code
yyjson_mut_val *key, *val;
yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj);
while ((key = yyjson_mut_obj_iter_next(&iter))) {
val = yyjson_mut_obj_iter_get_val(key);
your_func(key, val);
if (your_val_is_unused(key, val)) {
yyjson_mut_obj_iter_remove(&iter);
}
}
@endcode
If the ordering of the keys is known at compile-time, you can use this method
to speed up value lookups:
@code
// {"k1":1, "k2": 3, "k3": 3}
yyjson_mut_val *key, *val;
yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj);
yyjson_mut_val *v1 = yyjson_mut_obj_iter_get(&iter, "k1");
yyjson_mut_val *v3 = yyjson_mut_obj_iter_get(&iter, "k3");
@endcode
@see `yyjson_mut_obj_iter_get()` and `yyjson_mut_obj_iter_getn()`
*/
typedef struct yyjson_mut_obj_iter {
size_t idx; /**< next key's index */
size_t max; /**< maximum key index (obj.size) */
yyjson_mut_val *cur; /**< current key */
yyjson_mut_val *pre; /**< previous key */
yyjson_mut_val *obj; /**< the object being iterated */
} yyjson_mut_obj_iter;
/**
Initialize an iterator for this object.
@param obj The object to be iterated over.
If this parameter is NULL or not an array, `iter` will be set to empty.
@param iter The iterator to be initialized.
If this parameter is NULL, the function will fail and return false.
@return true if the `iter` has been successfully initialized.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj,
yyjson_mut_obj_iter *iter);
/**
Create an iterator with an object, same as `yyjson_obj_iter_init()`.
@param obj The object to be iterated over.
If this parameter is NULL or not an object, an empty iterator will returned.
@return A new iterator for the object.
@note The iterator does not need to be destroyed.
*/
yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with(
yyjson_mut_val *obj);
/**
Returns whether the iteration has more elements.
If `iter` is NULL, this function will return false.
*/
yyjson_api_inline bool yyjson_mut_obj_iter_has_next(
yyjson_mut_obj_iter *iter);
/**
Returns the next key in the iteration, or NULL on end.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next(
yyjson_mut_obj_iter *iter);
/**
Returns the value for key inside the iteration.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val(
yyjson_mut_val *key);
/**
Removes current key-value pair in the iteration, returns the removed value.
If `iter` is NULL, this function will return NULL.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove(
yyjson_mut_obj_iter *iter);
/**
Iterates to a specified key and returns the value.
This function does the same thing as `yyjson_mut_obj_get()`, but is much faster
if the ordering of the keys is known at compile-time and you are using the same
order to look up the values. If the key exists in this object, then the
iterator will stop at the next key, otherwise the iterator will not change and
NULL is returned.
@param iter The object iterator, should not be NULL.
@param key The key, should be a UTF-8 string with null-terminator.
@return The value to which the specified key is mapped.
NULL if this object contains no mapping for the key or input is invalid.
@warning This function takes a linear search time if the key is not nearby.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get(
yyjson_mut_obj_iter *iter, const char *key);
/**
Iterates to a specified key and returns the value.
This function does the same thing as `yyjson_mut_obj_getn()` but is much faster
if the ordering of the keys is known at compile-time and you are using the same
order to look up the values. If the key exists in this object, then the
iterator will stop at the next key, otherwise the iterator will not change and
NULL is returned.
@param iter The object iterator, should not be NULL.
@param key The key, should be a UTF-8 string, null-terminator is not required.
@param key_len The the length of `key`, in bytes.
@return The value to which the specified key is mapped.
NULL if this object contains no mapping for the key or input is invalid.
@warning This function takes a linear search time if the key is not nearby.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn(
yyjson_mut_obj_iter *iter, const char *key, size_t key_len);
/**
Macro for iterating over an object.
It works like iterator, but with a more intuitive API.
@warning You should not modify the object while iterating over it.
@b Example
@code
size_t idx, max;
yyjson_mut_val *key, *val;
yyjson_mut_obj_foreach(obj, idx, max, key, val) {
your_func(key, val);
}
@endcode
*/
#define yyjson_mut_obj_foreach(obj, idx, max, key, val) \
for ((idx) = 0, \
(max) = yyjson_mut_obj_size(obj), \
(key) = (max) ? ((yyjson_mut_val *)(obj)->uni.ptr)->next->next : NULL, \
(val) = (key) ? (key)->next : NULL; \
(idx) < (max); \
(idx)++, \
(key) = (val)->next, \
(val) = (key)->next)
/*==============================================================================
* MARK: - Mutable JSON Object Creation API
*============================================================================*/
/** Creates and returns a mutable object, returns NULL on error. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc);
/**
Creates and returns a mutable object with keys and values, returns NULL on
error. The keys and values are not copied. The strings should be a
null-terminated UTF-8 string.
@warning The input string is not copied, you should keep this string
unmodified for the lifetime of this JSON document.
@b Example
@code
const char *keys[2] = { "id", "name" };
const char *vals[2] = { "01", "Harry" };
yyjson_mut_val *obj = yyjson_mut_obj_with_str(doc, keys, vals, 2);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc,
const char **keys,
const char **vals,
size_t count);
/**
Creates and returns a mutable object with key-value pairs and pair count,
returns NULL on error. The keys and values are not copied. The strings should
be a null-terminated UTF-8 string.
@warning The input string is not copied, you should keep this string
unmodified for the lifetime of this JSON document.
@b Example
@code
const char *kv_pairs[4] = { "id", "01", "name", "Harry" };
yyjson_mut_val *obj = yyjson_mut_obj_with_kv(doc, kv_pairs, 2);
@endcode
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc,
const char **kv_pairs,
size_t pair_count);
/*==============================================================================
* MARK: - Mutable JSON Object Modification API
*============================================================================*/
/**
Adds a key-value pair at the end of the object.
This function allows duplicated key in one object.
@param obj The object to which the new key-value pair is to be added.
@param key The key, should be a string which is created by `yyjson_mut_str()`,
`yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`.
@param val The value to add to the object.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val);
/**
Sets a key-value pair at the end of the object.
This function may remove all key-value pairs for the given key before add.
@param obj The object to which the new key-value pair is to be added.
@param key The key, should be a string which is created by `yyjson_mut_str()`,
`yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`.
@param val The value to add to the object. If this value is null, the behavior
is same as `yyjson_mut_obj_remove()`.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val);
/**
Inserts a key-value pair to the object at the given position.
This function allows duplicated key in one object.
@param obj The object to which the new key-value pair is to be added.
@param key The key, should be a string which is created by `yyjson_mut_str()`,
`yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`.
@param val The value to add to the object.
@param idx The index to which to insert the new pair.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val,
size_t idx);
/**
Removes all key-value pair from the object with given key.
@param obj The object from which the key-value pair is to be removed.
@param key The key, should be a string value.
@return The first matched value, or NULL if no matched value.
@warning This function takes a linear search time.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj,
yyjson_mut_val *key);
/**
Removes all key-value pair from the object with given key.
@param obj The object from which the key-value pair is to be removed.
@param key The key, should be a UTF-8 string with null-terminator.
@return The first matched value, or NULL if no matched value.
@warning This function takes a linear search time.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key(
yyjson_mut_val *obj, const char *key);
/**
Removes all key-value pair from the object with given key.
@param obj The object from which the key-value pair is to be removed.
@param key The key, should be a UTF-8 string, null-terminator is not required.
@param key_len The length of the key.
@return The first matched value, or NULL if no matched value.
@warning This function takes a linear search time.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn(
yyjson_mut_val *obj, const char *key, size_t key_len);
/**
Removes all key-value pairs in this object.
@param obj The object from which all of the values are to be removed.
@return Whether successful.
*/
yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj);
/**
Replaces value from the object with given key.
If the key is not exist, or the value is NULL, it will fail.
@param obj The object to which the value is to be replaced.
@param key The key, should be a string value.
@param val The value to replace into the object.
@return Whether successful.
@warning This function takes a linear search time.
*/
yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val);
/**
Rotates key-value pairs in the object for the given number of times.
For example: `{"a":1,"b":2,"c":3,"d":4}` rotate 1 is
`{"b":2,"c":3,"d":4,"a":1}`.
@param obj The object to be rotated.
@param idx Index (or times) to rotate.
@return Whether successful.
@warning This function takes a linear search time.
*/
yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj,
size_t idx);
/*==============================================================================
* MARK: - Mutable JSON Object Modification Convenience API
*============================================================================*/
/** Adds a `null` value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key);
/** Adds a `true` value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key);
/** Adds a `false` value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key);
/** Adds a bool value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, bool val);
/** Adds an unsigned integer value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, uint64_t val);
/** Adds a signed integer value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, int64_t val);
/** Adds an int value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, int64_t val);
/** Adds a float value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_float(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, float val);
/** Adds a double value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_double(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, double val);
/** Adds a real value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, double val);
/** Adds a string value at the end of the object.
The `key` and `val` should be null-terminated UTF-8 strings.
This function allows duplicated key in one object.
@warning The key/value strings are not copied, you should keep these strings
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key, const char *val);
/** Adds a string value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
The `val` should be a UTF-8 string, null-terminator is not required.
The `len` should be the length of the `val`, in bytes.
This function allows duplicated key in one object.
@warning The key/value strings are not copied, you should keep these strings
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
const char *val, size_t len);
/** Adds a string value at the end of the object.
The `key` and `val` should be null-terminated UTF-8 strings.
The value string is copied.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
const char *val);
/** Adds a string value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
The `val` should be a UTF-8 string, null-terminator is not required.
The `len` should be the length of the `val`, in bytes.
This function allows duplicated key in one object.
@warning The key strings are not copied, you should keep these strings
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
const char *val, size_t len);
/**
Creates and adds a new array to the target object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep these strings
unmodified for the lifetime of this JSON document.
@return The new array, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key);
/**
Creates and adds a new object to the target object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep these strings
unmodified for the lifetime of this JSON document.
@return The new object, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key);
/** Adds a JSON value at the end of the object.
The `key` should be a null-terminated UTF-8 string.
This function allows duplicated key in one object.
@warning The key string is not copied, you should keep the string
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
yyjson_mut_val *val);
/** Removes all key-value pairs for the given key.
Returns the first value to which the specified key is mapped or NULL if this
object contains no mapping for the key.
The `key` should be a null-terminated UTF-8 string.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str(
yyjson_mut_val *obj, const char *key);
/** Removes all key-value pairs for the given key.
Returns the first value to which the specified key is mapped or NULL if this
object contains no mapping for the key.
The `key` should be a UTF-8 string, null-terminator is not required.
The `len` should be the length of the key, in bytes.
@warning This function takes a linear search time. */
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn(
yyjson_mut_val *obj, const char *key, size_t len);
/** Replaces all matching keys with the new key.
Returns true if at least one key was renamed.
The `key` and `new_key` should be a null-terminated UTF-8 string.
The `new_key` is copied and held by doc.
@warning This function takes a linear search time.
If `new_key` already exists, it will cause duplicate keys.
*/
yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
const char *new_key);
/** Replaces all matching keys with the new key.
Returns true if at least one key was renamed.
The `key` and `new_key` should be a UTF-8 string,
null-terminator is not required. The `new_key` is copied and held by doc.
@warning This function takes a linear search time.
If `new_key` already exists, it will cause duplicate keys.
*/
yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
size_t len,
const char *new_key,
size_t new_len);
#if !defined(YYJSON_DISABLE_UTILS) || !YYJSON_DISABLE_UTILS
/*==============================================================================
* MARK: - JSON Pointer API (RFC 6901)
* https://tools.ietf.org/html/rfc6901
*============================================================================*/
/** JSON Pointer error code. */
typedef uint32_t yyjson_ptr_code;
/** No JSON pointer error. */
static const yyjson_ptr_code YYJSON_PTR_ERR_NONE = 0;
/** Invalid input parameter, such as NULL input. */
static const yyjson_ptr_code YYJSON_PTR_ERR_PARAMETER = 1;
/** JSON pointer syntax error, such as invalid escape, token no prefix. */
static const yyjson_ptr_code YYJSON_PTR_ERR_SYNTAX = 2;
/** JSON pointer resolve failed, such as index out of range, key not found. */
static const yyjson_ptr_code YYJSON_PTR_ERR_RESOLVE = 3;
/** Document's root is NULL, but it is required for the function call. */
static const yyjson_ptr_code YYJSON_PTR_ERR_NULL_ROOT = 4;
/** Cannot set root as the target is not a document. */
static const yyjson_ptr_code YYJSON_PTR_ERR_SET_ROOT = 5;
/** The memory allocation failed and a new value could not be created. */
static const yyjson_ptr_code YYJSON_PTR_ERR_MEMORY_ALLOCATION = 6;
/** Error information for JSON pointer. */
typedef struct yyjson_ptr_err {
/** Error code, see `yyjson_ptr_code` for all possible values. */
yyjson_ptr_code code;
/** Error message, constant, no need to free (NULL if no error). */
const char *msg;
/** Error byte position for input JSON pointer (0 if no error). */
size_t pos;
} yyjson_ptr_err;
/**
A context for JSON pointer operation.
This struct stores the context of JSON Pointer operation result. The struct
can be used with three helper functions: `ctx_append()`, `ctx_replace()`, and
`ctx_remove()`, which perform the corresponding operations on the container
without re-parsing the JSON Pointer.
For example:
@code
// doc before: {"a":[0,1,null]}
// ptr: "/a/2"
val = yyjson_mut_doc_ptr_getx(doc, ptr, strlen(ptr), &ctx, &err);
if (yyjson_is_null(val)) {
yyjson_ptr_ctx_remove(&ctx);
}
// doc after: {"a":[0,1]}
@endcode
*/
typedef struct yyjson_ptr_ctx {
/**
The container (parent) of the target value. It can be either an array or
an object. If the target location has no value, but all its parent
containers exist, and the target location can be used to insert a new
value, then `ctn` is the parent container of the target location.
Otherwise, `ctn` is NULL.
*/
yyjson_mut_val *ctn;
/**
The previous sibling of the target value. It can be either a value in an
array or a key in an object. As the container is a `circular linked list`
of elements, `pre` is the previous node of the target value. If the
operation is `add` or `set`, then `pre` is the previous node of the new
value, not the original target value. If the target value does not exist,
`pre` is NULL.
*/
yyjson_mut_val *pre;
/**
The removed value if the operation is `set`, `replace` or `remove`. It can
be used to restore the original state of the document if needed.
*/
yyjson_mut_val *old;
} yyjson_ptr_ctx;
/**
Get value by a JSON Pointer.
@param doc The JSON document to be queried.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@return The value referenced by the JSON pointer.
NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc,
const char *ptr);
/**
Get value by a JSON Pointer.
@param doc The JSON document to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@return The value referenced by the JSON pointer.
NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc,
const char *ptr, size_t len);
/**
Get value by a JSON Pointer.
@param doc The JSON document to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param err A pointer to store the error information, or NULL if not needed.
@return The value referenced by the JSON pointer.
NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc,
const char *ptr, size_t len,
yyjson_ptr_err *err);
/**
Get value by a JSON Pointer.
@param val The JSON value to be queried.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@return The value referenced by the JSON pointer.
NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val,
const char *ptr);
/**
Get value by a JSON Pointer.
@param val The JSON value to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@return The value referenced by the JSON pointer.
NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val,
const char *ptr, size_t len);
/**
Get value by a JSON Pointer.
@param val The JSON value to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param err A pointer to store the error information, or NULL if not needed.
@return The value referenced by the JSON pointer.
NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val,
const char *ptr, size_t len,
yyjson_ptr_err *err);
/**
Get value by a JSON Pointer.
@param doc The JSON document to be queried.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@return The value referenced by the JSON pointer.
NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc,
const char *ptr);
/**
Get value by a JSON Pointer.
@param doc The JSON document to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@return The value referenced by the JSON pointer.
NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc,
const char *ptr,
size_t len);
/**
Get value by a JSON Pointer.
@param doc The JSON document to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return The value referenced by the JSON pointer.
NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Get value by a JSON Pointer.
@param val The JSON value to be queried.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@return The value referenced by the JSON pointer.
NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val,
const char *ptr);
/**
Get value by a JSON Pointer.
@param val The JSON value to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@return The value referenced by the JSON pointer.
NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val,
const char *ptr,
size_t len);
/**
Get value by a JSON Pointer.
@param val The JSON value to be queried.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return The value referenced by the JSON pointer.
NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Add (insert) value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@param new_val The value to be added.
@return true if JSON pointer is valid and new value is added, false otherwise.
@note The parent nodes will be created if they do not exist.
*/
yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc,
const char *ptr,
yyjson_mut_val *new_val);
/**
Add (insert) value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The value to be added.
@return true if JSON pointer is valid and new value is added, false otherwise.
@note The parent nodes will be created if they do not exist.
*/
yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val);
/**
Add (insert) value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The value to be added.
@param create_parent Whether to create parent nodes if not exist.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return true if JSON pointer is valid and new value is added, false otherwise.
*/
yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Add (insert) value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@param doc Only used to create new values when needed.
@param new_val The value to be added.
@return true if JSON pointer is valid and new value is added, false otherwise.
@note The parent nodes will be created if they do not exist.
*/
yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val,
const char *ptr,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc);
/**
Add (insert) value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param doc Only used to create new values when needed.
@param new_val The value to be added.
@return true if JSON pointer is valid and new value is added, false otherwise.
@note The parent nodes will be created if they do not exist.
*/
yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc);
/**
Add (insert) value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param doc Only used to create new values when needed.
@param new_val The value to be added.
@param create_parent Whether to create parent nodes if not exist.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return true if JSON pointer is valid and new value is added, false otherwise.
*/
yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Set value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@param new_val The value to be set, pass NULL to remove.
@return true if JSON pointer is valid and new value is set, false otherwise.
@note The parent nodes will be created if they do not exist.
If the target value already exists, it will be replaced by the new value.
*/
yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc,
const char *ptr,
yyjson_mut_val *new_val);
/**
Set value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The value to be set, pass NULL to remove.
@return true if JSON pointer is valid and new value is set, false otherwise.
@note The parent nodes will be created if they do not exist.
If the target value already exists, it will be replaced by the new value.
*/
yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val);
/**
Set value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The value to be set, pass NULL to remove.
@param create_parent Whether to create parent nodes if not exist.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return true if JSON pointer is valid and new value is set, false otherwise.
@note If the target value already exists, it will be replaced by the new value.
*/
yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Set value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@param new_val The value to be set, pass NULL to remove.
@param doc Only used to create new values when needed.
@return true if JSON pointer is valid and new value is set, false otherwise.
@note The parent nodes will be created if they do not exist.
If the target value already exists, it will be replaced by the new value.
*/
yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val,
const char *ptr,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc);
/**
Set value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The value to be set, pass NULL to remove.
@param doc Only used to create new values when needed.
@return true if JSON pointer is valid and new value is set, false otherwise.
@note The parent nodes will be created if they do not exist.
If the target value already exists, it will be replaced by the new value.
*/
yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc);
/**
Set value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The value to be set, pass NULL to remove.
@param doc Only used to create new values when needed.
@param create_parent Whether to create parent nodes if not exist.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return true if JSON pointer is valid and new value is set, false otherwise.
@note If the target value already exists, it will be replaced by the new value.
*/
yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Replace value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@param new_val The new value to replace the old one.
@return The old value that was replaced, or NULL if not found.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace(
yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val);
/**
Replace value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The new value to replace the old one.
@return The old value that was replaced, or NULL if not found.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen(
yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val);
/**
Replace value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The new value to replace the old one.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return The old value that was replaced, or NULL if not found.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex(
yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err);
/**
Replace value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@param new_val The new value to replace the old one.
@return The old value that was replaced, or NULL if not found.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace(
yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val);
/**
Replace value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The new value to replace the old one.
@return The old value that was replaced, or NULL if not found.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen(
yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val);
/**
Replace value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param new_val The new value to replace the old one.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return The old value that was replaced, or NULL if not found.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex(
yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err);
/**
Remove value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@return The removed value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove(
yyjson_mut_doc *doc, const char *ptr);
/**
Remove value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@return The removed value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen(
yyjson_mut_doc *doc, const char *ptr, size_t len);
/**
Remove value by a JSON pointer.
@param doc The target JSON document.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return The removed value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex(
yyjson_mut_doc *doc, const char *ptr, size_t len,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err);
/**
Remove value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8 with null-terminator).
@return The removed value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val,
const char *ptr);
/**
Remove value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@return The removed value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val,
const char *ptr,
size_t len);
/**
Remove value by a JSON pointer.
@param val The target JSON value.
@param ptr The JSON pointer string (UTF-8, null-terminator is not required).
@param len The length of `ptr` in bytes.
@param ctx A pointer to store the result context, or NULL if not needed.
@param err A pointer to store the error information, or NULL if not needed.
@return The removed value, or NULL on error.
*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/**
Append value by JSON pointer context.
@param ctx The context from the `yyjson_mut_ptr_xxx()` calls.
@param key New key if `ctx->ctn` is object, or NULL if `ctx->ctn` is array.
@param val New value to be added.
@return true on success or false on fail.
*/
yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx,
yyjson_mut_val *key,
yyjson_mut_val *val);
/**
Replace value by JSON pointer context.
@param ctx The context from the `yyjson_mut_ptr_xxx()` calls.
@param val New value to be replaced.
@return true on success or false on fail.
@note If success, the old value will be returned via `ctx->old`.
*/
yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx,
yyjson_mut_val *val);
/**
Remove value by JSON pointer context.
@param ctx The context from the `yyjson_mut_ptr_xxx()` calls.
@return true on success or false on fail.
@note If success, the old value will be returned via `ctx->old`.
*/
yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx);
/*==============================================================================
* MARK: - JSON Patch API (RFC 6902)
* https://tools.ietf.org/html/rfc6902
*============================================================================*/
/** Result code for JSON patch. */
typedef uint32_t yyjson_patch_code;
/** Success, no error. */
static const yyjson_patch_code YYJSON_PATCH_SUCCESS = 0;
/** Invalid parameter, such as NULL input or non-array patch. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_PARAMETER = 1;
/** Memory allocation failure occurs. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_MEMORY_ALLOCATION = 2;
/** JSON patch operation is not object type. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_OPERATION = 3;
/** JSON patch operation is missing a required key. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_MISSING_KEY = 4;
/** JSON patch operation member is invalid. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_MEMBER = 5;
/** JSON patch operation `test` not equal. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_EQUAL = 6;
/** JSON patch operation failed on JSON pointer. */
static const yyjson_patch_code YYJSON_PATCH_ERROR_POINTER = 7;
/** Error information for JSON patch. */
typedef struct yyjson_patch_err {
/** Error code, see `yyjson_patch_code` for all possible values. */
yyjson_patch_code code;
/** Index of the error operation (0 if no error). */
size_t idx;
/** Error message, constant, no need to free (NULL if no error). */
const char *msg;
/** JSON pointer error if `code == YYJSON_PATCH_ERROR_POINTER`. */
yyjson_ptr_err ptr;
} yyjson_patch_err;
/**
Creates and returns a patched JSON value (RFC 6902).
The memory of the returned value is allocated by the `doc`.
The `err` is used to receive error information, pass NULL if not needed.
Returns NULL if the patch could not be applied.
*/
yyjson_api yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc,
yyjson_val *orig,
yyjson_val *patch,
yyjson_patch_err *err);
/**
Creates and returns a patched JSON value (RFC 6902).
The memory of the returned value is allocated by the `doc`.
The `err` is used to receive error information, pass NULL if not needed.
Returns NULL if the patch could not be applied.
*/
yyjson_api yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc,
yyjson_mut_val *orig,
yyjson_mut_val *patch,
yyjson_patch_err *err);
/*==============================================================================
* MARK: - JSON Merge-Patch API (RFC 7386)
* https://tools.ietf.org/html/rfc7386
*============================================================================*/
/**
Creates and returns a merge-patched JSON value (RFC 7386).
The memory of the returned value is allocated by the `doc`.
Returns NULL if the patch could not be applied.
@warning This function is recursive and may cause a stack overflow if the
object level is too deep.
*/
yyjson_api yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc,
yyjson_val *orig,
yyjson_val *patch);
/**
Creates and returns a merge-patched JSON value (RFC 7386).
The memory of the returned value is allocated by the `doc`.
Returns NULL if the patch could not be applied.
@warning This function is recursive and may cause a stack overflow if the
object level is too deep.
*/
yyjson_api yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc,
yyjson_mut_val *orig,
yyjson_mut_val *patch);
#endif /* YYJSON_DISABLE_UTILS */
/*==============================================================================
* MARK: - JSON Structure (Implementation)
*============================================================================*/
/** Payload of a JSON value (8 bytes). */
typedef union yyjson_val_uni {
uint64_t u64;
int64_t i64;
double f64;
const char *str;
void *ptr;
size_t ofs;
} yyjson_val_uni;
/**
Immutable JSON value, 16 bytes.
*/
struct yyjson_val {
uint64_t tag; /**< type, subtype and length */
yyjson_val_uni uni; /**< payload */
};
struct yyjson_doc {
/** Root value of the document (nonnull). */
yyjson_val *root;
/** Allocator used by document (nonnull). */
yyjson_alc alc;
/** The total number of bytes read when parsing JSON (nonzero). */
size_t dat_read;
/** The total number of value read when parsing JSON (nonzero). */
size_t val_read;
/** The string pool used by JSON values (nullable). */
char *str_pool;
};
/*==============================================================================
* MARK: - Unsafe JSON Value API (Implementation)
*============================================================================*/
/*
Whether the string does not need to be escaped for serialization.
This function is used to optimize the writing speed of small constant strings.
This function works only if the compiler can evaluate it at compile time.
Clang supports it since v8.0,
earlier versions do not support constant_p(strlen) and return false.
GCC supports it since at least v4.4,
earlier versions may compile it as run-time instructions.
ICC supports it since at least v16,
earlier versions are uncertain.
@param str The C string.
@param len The returnd value from strlen(str).
*/
yyjson_api_inline bool unsafe_yyjson_is_str_noesc(const char *str, size_t len) {
#if YYJSON_HAS_CONSTANT_P && \
(!YYJSON_IS_REAL_GCC || yyjson_gcc_available(4, 4, 0))
if (yyjson_constant_p(len) && len <= 32) {
/*
Same as the following loop:
for (size_t i = 0; i < len; i++) {
char c = str[i];
if (c < ' ' || c > '~' || c == '"' || c == '\\') return false;
}
GCC evaluates it at compile time only if the string length is within 17
and -O3 (which turns on the -fpeel-loops flag) is used.
So the loop is unrolled for GCC.
*/
# define yyjson_repeat32_incr(x) \
x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \
x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) \
x(16) x(17) x(18) x(19) x(20) x(21) x(22) x(23) \
x(24) x(25) x(26) x(27) x(28) x(29) x(30) x(31)
# define yyjson_check_char_noesc(i) \
if (i < len) { \
char c = str[i]; \
if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; }
yyjson_repeat32_incr(yyjson_check_char_noesc)
# undef yyjson_repeat32_incr
# undef yyjson_check_char_noesc
return true;
}
#else
(void)str;
(void)len;
#endif
return false;
}
yyjson_api_inline double unsafe_yyjson_u64_to_f64(uint64_t num) {
#if YYJSON_U64_TO_F64_NO_IMPL
uint64_t msb = ((uint64_t)1) << 63;
if ((num & msb) == 0) {
return (double)(int64_t)num;
} else {
return ((double)(int64_t)((num >> 1) | (num & 1))) * (double)2.0;
}
#else
return (double)num;
#endif
}
yyjson_api_inline yyjson_type unsafe_yyjson_get_type(void *val) {
uint8_t tag = (uint8_t)((yyjson_val *)val)->tag;
return (yyjson_type)(tag & YYJSON_TYPE_MASK);
}
yyjson_api_inline yyjson_subtype unsafe_yyjson_get_subtype(void *val) {
uint8_t tag = (uint8_t)((yyjson_val *)val)->tag;
return (yyjson_subtype)(tag & YYJSON_SUBTYPE_MASK);
}
yyjson_api_inline uint8_t unsafe_yyjson_get_tag(void *val) {
uint8_t tag = (uint8_t)((yyjson_val *)val)->tag;
return (uint8_t)(tag & YYJSON_TAG_MASK);
}
yyjson_api_inline bool unsafe_yyjson_is_raw(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_RAW;
}
yyjson_api_inline bool unsafe_yyjson_is_null(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NULL;
}
yyjson_api_inline bool unsafe_yyjson_is_bool(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_BOOL;
}
yyjson_api_inline bool unsafe_yyjson_is_num(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NUM;
}
yyjson_api_inline bool unsafe_yyjson_is_str(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_STR;
}
yyjson_api_inline bool unsafe_yyjson_is_arr(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_ARR;
}
yyjson_api_inline bool unsafe_yyjson_is_obj(void *val) {
return unsafe_yyjson_get_type(val) == YYJSON_TYPE_OBJ;
}
yyjson_api_inline bool unsafe_yyjson_is_ctn(void *val) {
uint8_t mask = YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ;
return (unsafe_yyjson_get_tag(val) & mask) == mask;
}
yyjson_api_inline bool unsafe_yyjson_is_uint(void *val) {
const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT;
return unsafe_yyjson_get_tag(val) == patt;
}
yyjson_api_inline bool unsafe_yyjson_is_sint(void *val) {
const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT;
return unsafe_yyjson_get_tag(val) == patt;
}
yyjson_api_inline bool unsafe_yyjson_is_int(void *val) {
const uint8_t mask = YYJSON_TAG_MASK & (~YYJSON_SUBTYPE_SINT);
const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT;
return (unsafe_yyjson_get_tag(val) & mask) == patt;
}
yyjson_api_inline bool unsafe_yyjson_is_real(void *val) {
const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL;
return unsafe_yyjson_get_tag(val) == patt;
}
yyjson_api_inline bool unsafe_yyjson_is_true(void *val) {
const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE;
return unsafe_yyjson_get_tag(val) == patt;
}
yyjson_api_inline bool unsafe_yyjson_is_false(void *val) {
const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE;
return unsafe_yyjson_get_tag(val) == patt;
}
yyjson_api_inline bool unsafe_yyjson_arr_is_flat(yyjson_val *val) {
size_t ofs = val->uni.ofs;
size_t len = (size_t)(val->tag >> YYJSON_TAG_BIT);
return len * sizeof(yyjson_val) + sizeof(yyjson_val) == ofs;
}
yyjson_api_inline const char *unsafe_yyjson_get_raw(void *val) {
return ((yyjson_val *)val)->uni.str;
}
yyjson_api_inline bool unsafe_yyjson_get_bool(void *val) {
uint8_t tag = unsafe_yyjson_get_tag(val);
return (bool)((tag & YYJSON_SUBTYPE_MASK) >> YYJSON_TYPE_BIT);
}
yyjson_api_inline uint64_t unsafe_yyjson_get_uint(void *val) {
return ((yyjson_val *)val)->uni.u64;
}
yyjson_api_inline int64_t unsafe_yyjson_get_sint(void *val) {
return ((yyjson_val *)val)->uni.i64;
}
yyjson_api_inline int unsafe_yyjson_get_int(void *val) {
return (int)((yyjson_val *)val)->uni.i64;
}
yyjson_api_inline double unsafe_yyjson_get_real(void *val) {
return ((yyjson_val *)val)->uni.f64;
}
yyjson_api_inline double unsafe_yyjson_get_num(void *val) {
uint8_t tag = unsafe_yyjson_get_tag(val);
if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL)) {
return ((yyjson_val *)val)->uni.f64;
} else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT)) {
return (double)((yyjson_val *)val)->uni.i64;
} else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT)) {
return unsafe_yyjson_u64_to_f64(((yyjson_val *)val)->uni.u64);
}
return 0.0;
}
yyjson_api_inline const char *unsafe_yyjson_get_str(void *val) {
return ((yyjson_val *)val)->uni.str;
}
yyjson_api_inline size_t unsafe_yyjson_get_len(void *val) {
return (size_t)(((yyjson_val *)val)->tag >> YYJSON_TAG_BIT);
}
yyjson_api_inline yyjson_val *unsafe_yyjson_get_first(yyjson_val *ctn) {
return ctn + 1;
}
yyjson_api_inline yyjson_val *unsafe_yyjson_get_next(yyjson_val *val) {
bool is_ctn = unsafe_yyjson_is_ctn(val);
size_t ctn_ofs = val->uni.ofs;
size_t ofs = (is_ctn ? ctn_ofs : sizeof(yyjson_val));
return (yyjson_val *)(void *)((uint8_t *)val + ofs);
}
yyjson_api_inline bool unsafe_yyjson_equals_strn(void *val, const char *str,
size_t len) {
return unsafe_yyjson_get_len(val) == len &&
memcmp(((yyjson_val *)val)->uni.str, str, len) == 0;
}
yyjson_api_inline bool unsafe_yyjson_equals_str(void *val, const char *str) {
return unsafe_yyjson_equals_strn(val, str, strlen(str));
}
yyjson_api_inline void unsafe_yyjson_set_type(void *val, yyjson_type type,
yyjson_subtype subtype) {
uint8_t tag = (type | subtype);
uint64_t new_tag = ((yyjson_val *)val)->tag;
new_tag = (new_tag & (~(uint64_t)YYJSON_TAG_MASK)) | (uint64_t)tag;
((yyjson_val *)val)->tag = new_tag;
}
yyjson_api_inline void unsafe_yyjson_set_len(void *val, size_t len) {
uint64_t tag = ((yyjson_val *)val)->tag & YYJSON_TAG_MASK;
tag |= (uint64_t)len << YYJSON_TAG_BIT;
((yyjson_val *)val)->tag = tag;
}
yyjson_api_inline void unsafe_yyjson_set_tag(void *val, yyjson_type type,
yyjson_subtype subtype,
size_t len) {
uint64_t tag = (uint64_t)len << YYJSON_TAG_BIT;
tag |= (type | subtype);
((yyjson_val *)val)->tag = tag;
}
yyjson_api_inline void unsafe_yyjson_inc_len(void *val) {
uint64_t tag = ((yyjson_val *)val)->tag;
tag += (uint64_t)(1 << YYJSON_TAG_BIT);
((yyjson_val *)val)->tag = tag;
}
yyjson_api_inline void unsafe_yyjson_set_raw(void *val, const char *raw,
size_t len) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_RAW, YYJSON_SUBTYPE_NONE, len);
((yyjson_val *)val)->uni.str = raw;
}
yyjson_api_inline void unsafe_yyjson_set_null(void *val) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_NULL, YYJSON_SUBTYPE_NONE, 0);
}
yyjson_api_inline void unsafe_yyjson_set_bool(void *val, bool num) {
yyjson_subtype subtype = num ? YYJSON_SUBTYPE_TRUE : YYJSON_SUBTYPE_FALSE;
unsafe_yyjson_set_tag(val, YYJSON_TYPE_BOOL, subtype, 0);
}
yyjson_api_inline void unsafe_yyjson_set_uint(void *val, uint64_t num) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_UINT, 0);
((yyjson_val *)val)->uni.u64 = num;
}
yyjson_api_inline void unsafe_yyjson_set_sint(void *val, int64_t num) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_SINT, 0);
((yyjson_val *)val)->uni.i64 = num;
}
yyjson_api_inline void unsafe_yyjson_set_fp_to_fixed(void *val, int prec) {
((yyjson_val *)val)->tag &= ~((uint64_t)YYJSON_WRITE_FP_TO_FIXED(15) << 32);
((yyjson_val *)val)->tag |= (uint64_t)YYJSON_WRITE_FP_TO_FIXED(prec) << 32;
}
yyjson_api_inline void unsafe_yyjson_set_fp_to_float(void *val, bool flt) {
uint64_t flag = (uint64_t)YYJSON_WRITE_FP_TO_FLOAT << 32;
if (flt) ((yyjson_val *)val)->tag |= flag;
else ((yyjson_val *)val)->tag &= ~flag;
}
yyjson_api_inline void unsafe_yyjson_set_float(void *val, float num) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0);
((yyjson_val *)val)->tag |= (uint64_t)YYJSON_WRITE_FP_TO_FLOAT << 32;
((yyjson_val *)val)->uni.f64 = (double)num;
}
yyjson_api_inline void unsafe_yyjson_set_double(void *val, double num) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0);
((yyjson_val *)val)->uni.f64 = num;
}
yyjson_api_inline void unsafe_yyjson_set_real(void *val, double num) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0);
((yyjson_val *)val)->uni.f64 = num;
}
yyjson_api_inline void unsafe_yyjson_set_str_noesc(void *val, bool noesc) {
((yyjson_val *)val)->tag &= ~(uint64_t)YYJSON_SUBTYPE_MASK;
if (noesc) ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_SUBTYPE_NOESC;
}
yyjson_api_inline void unsafe_yyjson_set_strn(void *val, const char *str,
size_t len) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, YYJSON_SUBTYPE_NONE, len);
((yyjson_val *)val)->uni.str = str;
}
yyjson_api_inline void unsafe_yyjson_set_str(void *val, const char *str) {
size_t len = strlen(str);
bool noesc = unsafe_yyjson_is_str_noesc(str, len);
yyjson_subtype subtype = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE;
unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, subtype, len);
((yyjson_val *)val)->uni.str = str;
}
yyjson_api_inline void unsafe_yyjson_set_arr(void *val, size_t size) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_ARR, YYJSON_SUBTYPE_NONE, size);
}
yyjson_api_inline void unsafe_yyjson_set_obj(void *val, size_t size) {
unsafe_yyjson_set_tag(val, YYJSON_TYPE_OBJ, YYJSON_SUBTYPE_NONE, size);
}
/*==============================================================================
* MARK: - JSON Document API (Implementation)
*============================================================================*/
yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc) {
return doc ? doc->root : NULL;
}
yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc) {
return doc ? doc->dat_read : 0;
}
yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) {
return doc ? doc->val_read : 0;
}
yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc) {
if (doc) {
yyjson_alc alc = doc->alc;
memset(&doc->alc, 0, sizeof(alc));
if (doc->str_pool) alc.free(alc.ctx, doc->str_pool);
alc.free(alc.ctx, doc);
}
}
/*==============================================================================
* MARK: - JSON Value Type API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_is_raw(yyjson_val *val) {
return val ? unsafe_yyjson_is_raw(val) : false;
}
yyjson_api_inline bool yyjson_is_null(yyjson_val *val) {
return val ? unsafe_yyjson_is_null(val) : false;
}
yyjson_api_inline bool yyjson_is_true(yyjson_val *val) {
return val ? unsafe_yyjson_is_true(val) : false;
}
yyjson_api_inline bool yyjson_is_false(yyjson_val *val) {
return val ? unsafe_yyjson_is_false(val) : false;
}
yyjson_api_inline bool yyjson_is_bool(yyjson_val *val) {
return val ? unsafe_yyjson_is_bool(val) : false;
}
yyjson_api_inline bool yyjson_is_uint(yyjson_val *val) {
return val ? unsafe_yyjson_is_uint(val) : false;
}
yyjson_api_inline bool yyjson_is_sint(yyjson_val *val) {
return val ? unsafe_yyjson_is_sint(val) : false;
}
yyjson_api_inline bool yyjson_is_int(yyjson_val *val) {
return val ? unsafe_yyjson_is_int(val) : false;
}
yyjson_api_inline bool yyjson_is_real(yyjson_val *val) {
return val ? unsafe_yyjson_is_real(val) : false;
}
yyjson_api_inline bool yyjson_is_num(yyjson_val *val) {
return val ? unsafe_yyjson_is_num(val) : false;
}
yyjson_api_inline bool yyjson_is_str(yyjson_val *val) {
return val ? unsafe_yyjson_is_str(val) : false;
}
yyjson_api_inline bool yyjson_is_arr(yyjson_val *val) {
return val ? unsafe_yyjson_is_arr(val) : false;
}
yyjson_api_inline bool yyjson_is_obj(yyjson_val *val) {
return val ? unsafe_yyjson_is_obj(val) : false;
}
yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val) {
return val ? unsafe_yyjson_is_ctn(val) : false;
}
/*==============================================================================
* MARK: - JSON Value Content API (Implementation)
*============================================================================*/
yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val) {
return val ? unsafe_yyjson_get_type(val) : YYJSON_TYPE_NONE;
}
yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val) {
return val ? unsafe_yyjson_get_subtype(val) : YYJSON_SUBTYPE_NONE;
}
yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val) {
return val ? unsafe_yyjson_get_tag(val) : 0;
}
yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val) {
switch (yyjson_get_tag(val)) {
case YYJSON_TYPE_RAW | YYJSON_SUBTYPE_NONE: return "raw";
case YYJSON_TYPE_NULL | YYJSON_SUBTYPE_NONE: return "null";
case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NONE: return "string";
case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NOESC: return "string";
case YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE: return "array";
case YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE: return "object";
case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE: return "true";
case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE: return "false";
case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: return "uint";
case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: return "sint";
case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: return "real";
default: return "unknown";
}
}
yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val) {
return yyjson_is_raw(val) ? unsafe_yyjson_get_raw(val) : NULL;
}
yyjson_api_inline bool yyjson_get_bool(yyjson_val *val) {
return yyjson_is_bool(val) ? unsafe_yyjson_get_bool(val) : false;
}
yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val) {
return yyjson_is_int(val) ? unsafe_yyjson_get_uint(val) : 0;
}
yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val) {
return yyjson_is_int(val) ? unsafe_yyjson_get_sint(val) : 0;
}
yyjson_api_inline int yyjson_get_int(yyjson_val *val) {
return yyjson_is_int(val) ? unsafe_yyjson_get_int(val) : 0;
}
yyjson_api_inline double yyjson_get_real(yyjson_val *val) {
return yyjson_is_real(val) ? unsafe_yyjson_get_real(val) : 0.0;
}
yyjson_api_inline double yyjson_get_num(yyjson_val *val) {
return val ? unsafe_yyjson_get_num(val) : 0.0;
}
yyjson_api_inline const char *yyjson_get_str(yyjson_val *val) {
return yyjson_is_str(val) ? unsafe_yyjson_get_str(val) : NULL;
}
yyjson_api_inline size_t yyjson_get_len(yyjson_val *val) {
return val ? unsafe_yyjson_get_len(val) : 0;
}
yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str) {
if (yyjson_likely(val && str)) {
return unsafe_yyjson_is_str(val) &&
unsafe_yyjson_equals_str(val, str);
}
return false;
}
yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str,
size_t len) {
if (yyjson_likely(val && str)) {
return unsafe_yyjson_is_str(val) &&
unsafe_yyjson_equals_strn(val, str, len);
}
return false;
}
yyjson_api bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs);
yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) {
if (yyjson_unlikely(!lhs || !rhs)) return false;
return unsafe_yyjson_equals(lhs, rhs);
}
yyjson_api_inline bool yyjson_set_raw(yyjson_val *val,
const char *raw, size_t len) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_raw(val, raw, len);
return true;
}
yyjson_api_inline bool yyjson_set_null(yyjson_val *val) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_null(val);
return true;
}
yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_bool(val, num);
return true;
}
yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_uint(val, num);
return true;
}
yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_sint(val, num);
return true;
}
yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_sint(val, (int64_t)num);
return true;
}
yyjson_api_inline bool yyjson_set_float(yyjson_val *val, float num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_float(val, num);
return true;
}
yyjson_api_inline bool yyjson_set_double(yyjson_val *val, double num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_double(val, num);
return true;
}
yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
unsafe_yyjson_set_real(val, num);
return true;
}
yyjson_api_inline bool yyjson_set_fp_to_fixed(yyjson_val *val, int prec) {
if (yyjson_unlikely(!yyjson_is_real(val))) return false;
unsafe_yyjson_set_fp_to_fixed(val, prec);
return true;
}
yyjson_api_inline bool yyjson_set_fp_to_float(yyjson_val *val, bool flt) {
if (yyjson_unlikely(!yyjson_is_real(val))) return false;
unsafe_yyjson_set_fp_to_float(val, flt);
return true;
}
yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
if (yyjson_unlikely(!str)) return false;
unsafe_yyjson_set_str(val, str);
return true;
}
yyjson_api_inline bool yyjson_set_strn(yyjson_val *val,
const char *str, size_t len) {
if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false;
if (yyjson_unlikely(!str)) return false;
unsafe_yyjson_set_strn(val, str, len);
return true;
}
yyjson_api_inline bool yyjson_set_str_noesc(yyjson_val *val, bool noesc) {
if (yyjson_unlikely(!yyjson_is_str(val))) return false;
unsafe_yyjson_set_str_noesc(val, noesc);
return true;
}
/*==============================================================================
* MARK: - JSON Array API (Implementation)
*============================================================================*/
yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr) {
return yyjson_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0;
}
yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx) {
if (yyjson_likely(yyjson_is_arr(arr))) {
if (yyjson_likely(unsafe_yyjson_get_len(arr) > idx)) {
yyjson_val *val = unsafe_yyjson_get_first(arr);
if (unsafe_yyjson_arr_is_flat(arr)) {
return val + idx;
} else {
while (idx-- > 0) val = unsafe_yyjson_get_next(val);
return val;
}
}
}
return NULL;
}
yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr) {
if (yyjson_likely(yyjson_is_arr(arr))) {
if (yyjson_likely(unsafe_yyjson_get_len(arr) > 0)) {
return unsafe_yyjson_get_first(arr);
}
}
return NULL;
}
yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr) {
if (yyjson_likely(yyjson_is_arr(arr))) {
size_t len = unsafe_yyjson_get_len(arr);
if (yyjson_likely(len > 0)) {
yyjson_val *val = unsafe_yyjson_get_first(arr);
if (unsafe_yyjson_arr_is_flat(arr)) {
return val + (len - 1);
} else {
while (len-- > 1) val = unsafe_yyjson_get_next(val);
return val;
}
}
}
return NULL;
}
/*==============================================================================
* MARK: - JSON Array Iterator API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr,
yyjson_arr_iter *iter) {
if (yyjson_likely(yyjson_is_arr(arr) && iter)) {
iter->idx = 0;
iter->max = unsafe_yyjson_get_len(arr);
iter->cur = unsafe_yyjson_get_first(arr);
return true;
}
if (iter) memset(iter, 0, sizeof(yyjson_arr_iter));
return false;
}
yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr) {
yyjson_arr_iter iter;
yyjson_arr_iter_init(arr, &iter);
return iter;
}
yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter) {
return iter ? iter->idx < iter->max : false;
}
yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter) {
yyjson_val *val;
if (iter && iter->idx < iter->max) {
val = iter->cur;
iter->cur = unsafe_yyjson_get_next(val);
iter->idx++;
return val;
}
return NULL;
}
/*==============================================================================
* MARK: - JSON Object API (Implementation)
*============================================================================*/
yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj) {
return yyjson_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0;
}
yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj,
const char *key) {
return yyjson_obj_getn(obj, key, key ? strlen(key) : 0);
}
yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj,
const char *_key,
size_t key_len) {
if (yyjson_likely(yyjson_is_obj(obj) && _key)) {
size_t len = unsafe_yyjson_get_len(obj);
yyjson_val *key = unsafe_yyjson_get_first(obj);
while (len-- > 0) {
if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key + 1;
key = unsafe_yyjson_get_next(key + 1);
}
}
return NULL;
}
/*==============================================================================
* MARK: - JSON Object Iterator API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj,
yyjson_obj_iter *iter) {
if (yyjson_likely(yyjson_is_obj(obj) && iter)) {
iter->idx = 0;
iter->max = unsafe_yyjson_get_len(obj);
iter->cur = unsafe_yyjson_get_first(obj);
iter->obj = obj;
return true;
}
if (iter) memset(iter, 0, sizeof(yyjson_obj_iter));
return false;
}
yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj) {
yyjson_obj_iter iter;
yyjson_obj_iter_init(obj, &iter);
return iter;
}
yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter) {
return iter ? iter->idx < iter->max : false;
}
yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter) {
if (iter && iter->idx < iter->max) {
yyjson_val *key = iter->cur;
iter->idx++;
iter->cur = unsafe_yyjson_get_next(key + 1);
return key;
}
return NULL;
}
yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key) {
return key ? key + 1 : NULL;
}
yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter,
const char *key) {
return yyjson_obj_iter_getn(iter, key, key ? strlen(key) : 0);
}
yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter,
const char *key,
size_t key_len) {
if (iter && key) {
size_t idx = iter->idx;
size_t max = iter->max;
yyjson_val *cur = iter->cur;
if (yyjson_unlikely(idx == max)) {
idx = 0;
cur = unsafe_yyjson_get_first(iter->obj);
}
while (idx++ < max) {
yyjson_val *next = unsafe_yyjson_get_next(cur + 1);
if (unsafe_yyjson_equals_strn(cur, key, key_len)) {
iter->idx = idx;
iter->cur = next;
return cur + 1;
}
cur = next;
if (idx == iter->max && iter->idx < iter->max) {
idx = 0;
max = iter->idx;
cur = unsafe_yyjson_get_first(iter->obj);
}
}
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Structure (Implementation)
*============================================================================*/
/**
Mutable JSON value, 24 bytes.
The 'tag' and 'uni' field is same as immutable value.
The 'next' field links all elements inside the container to be a cycle.
*/
struct yyjson_mut_val {
uint64_t tag; /**< type, subtype and length */
yyjson_val_uni uni; /**< payload */
yyjson_mut_val *next; /**< the next value in circular linked list */
};
/**
A memory chunk in string memory pool.
*/
typedef struct yyjson_str_chunk {
struct yyjson_str_chunk *next; /* next chunk linked list */
size_t chunk_size; /* chunk size in bytes */
/* char str[]; flexible array member */
} yyjson_str_chunk;
/**
A memory pool to hold all strings in a mutable document.
*/
typedef struct yyjson_str_pool {
char *cur; /* cursor inside current chunk */
char *end; /* the end of current chunk */
size_t chunk_size; /* chunk size in bytes while creating new chunk */
size_t chunk_size_max; /* maximum chunk size in bytes */
yyjson_str_chunk *chunks; /* a linked list of chunks, nullable */
} yyjson_str_pool;
/**
A memory chunk in value memory pool.
`sizeof(yyjson_val_chunk)` should not larger than `sizeof(yyjson_mut_val)`.
*/
typedef struct yyjson_val_chunk {
struct yyjson_val_chunk *next; /* next chunk linked list */
size_t chunk_size; /* chunk size in bytes */
/* char pad[sizeof(yyjson_mut_val) - sizeof(yyjson_val_chunk)]; padding */
/* yyjson_mut_val vals[]; flexible array member */
} yyjson_val_chunk;
/**
A memory pool to hold all values in a mutable document.
*/
typedef struct yyjson_val_pool {
yyjson_mut_val *cur; /* cursor inside current chunk */
yyjson_mut_val *end; /* the end of current chunk */
size_t chunk_size; /* chunk size in bytes while creating new chunk */
size_t chunk_size_max; /* maximum chunk size in bytes */
yyjson_val_chunk *chunks; /* a linked list of chunks, nullable */
} yyjson_val_pool;
struct yyjson_mut_doc {
yyjson_mut_val *root; /**< root value of the JSON document, nullable */
yyjson_alc alc; /**< a valid allocator, nonnull */
yyjson_str_pool str_pool; /**< string memory pool */
yyjson_val_pool val_pool; /**< value memory pool */
};
/* Ensures the capacity to at least equal to the specified byte length. */
yyjson_api bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool,
const yyjson_alc *alc,
size_t len);
/* Ensures the capacity to at least equal to the specified value count. */
yyjson_api bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool,
const yyjson_alc *alc,
size_t count);
/* Allocate memory for string. */
yyjson_api_inline char *unsafe_yyjson_mut_str_alc(yyjson_mut_doc *doc,
size_t len) {
char *mem;
const yyjson_alc *alc = &doc->alc;
yyjson_str_pool *pool = &doc->str_pool;
if (yyjson_unlikely((size_t)(pool->end - pool->cur) <= len)) {
if (yyjson_unlikely(!unsafe_yyjson_str_pool_grow(pool, alc, len + 1))) {
return NULL;
}
}
mem = pool->cur;
pool->cur = mem + len + 1;
return mem;
}
yyjson_api_inline char *unsafe_yyjson_mut_strncpy(yyjson_mut_doc *doc,
const char *str, size_t len) {
char *mem = unsafe_yyjson_mut_str_alc(doc, len);
if (yyjson_unlikely(!mem)) return NULL;
memcpy((void *)mem, (const void *)str, len);
mem[len] = '\0';
return mem;
}
yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_val(yyjson_mut_doc *doc,
size_t count) {
yyjson_mut_val *val;
yyjson_alc *alc = &doc->alc;
yyjson_val_pool *pool = &doc->val_pool;
if (yyjson_unlikely((size_t)(pool->end - pool->cur) < count)) {
if (yyjson_unlikely(!unsafe_yyjson_val_pool_grow(pool, alc, count))) {
return NULL;
}
}
val = pool->cur;
pool->cur += count;
return val;
}
/*==============================================================================
* MARK: - Mutable JSON Document API (Implementation)
*============================================================================*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc) {
return doc ? doc->root : NULL;
}
yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc,
yyjson_mut_val *root) {
if (doc) doc->root = root;
}
/*==============================================================================
* MARK: - Mutable JSON Value Type API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_raw(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_null(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_true(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_false(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_bool(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_uint(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_sint(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_int(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_real(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_num(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_str(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_arr(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_obj(val) : false;
}
yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val) {
return val ? unsafe_yyjson_is_ctn(val) : false;
}
/*==============================================================================
* MARK: - Mutable JSON Value Content API (Implementation)
*============================================================================*/
yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val) {
return yyjson_get_type((yyjson_val *)val);
}
yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val) {
return yyjson_get_subtype((yyjson_val *)val);
}
yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val) {
return yyjson_get_tag((yyjson_val *)val);
}
yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val) {
return yyjson_get_type_desc((yyjson_val *)val);
}
yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val) {
return yyjson_get_raw((yyjson_val *)val);
}
yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val) {
return yyjson_get_bool((yyjson_val *)val);
}
yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val) {
return yyjson_get_uint((yyjson_val *)val);
}
yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val) {
return yyjson_get_sint((yyjson_val *)val);
}
yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val) {
return yyjson_get_int((yyjson_val *)val);
}
yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val) {
return yyjson_get_real((yyjson_val *)val);
}
yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val) {
return yyjson_get_num((yyjson_val *)val);
}
yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val) {
return yyjson_get_str((yyjson_val *)val);
}
yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val) {
return yyjson_get_len((yyjson_val *)val);
}
yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val,
const char *str) {
return yyjson_equals_str((yyjson_val *)val, str);
}
yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val,
const char *str, size_t len) {
return yyjson_equals_strn((yyjson_val *)val, str, len);
}
yyjson_api bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs,
yyjson_mut_val *rhs);
yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs,
yyjson_mut_val *rhs) {
if (yyjson_unlikely(!lhs || !rhs)) return false;
return unsafe_yyjson_mut_equals(lhs, rhs);
}
yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val,
const char *raw, size_t len) {
if (yyjson_unlikely(!val || !raw)) return false;
unsafe_yyjson_set_raw(val, raw, len);
return true;
}
yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_null(val);
return true;
}
yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_bool(val, num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_uint(val, num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_sint(val, num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_sint(val, (int64_t)num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_float(yyjson_mut_val *val, float num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_float(val, num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_double(yyjson_mut_val *val, double num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_double(val, num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_real(val, num);
return true;
}
yyjson_api_inline bool yyjson_mut_set_fp_to_fixed(yyjson_mut_val *val,
int prec) {
if (yyjson_unlikely(!yyjson_mut_is_real(val))) return false;
unsafe_yyjson_set_fp_to_fixed(val, prec);
return true;
}
yyjson_api_inline bool yyjson_mut_set_fp_to_float(yyjson_mut_val *val,
bool flt) {
if (yyjson_unlikely(!yyjson_mut_is_real(val))) return false;
unsafe_yyjson_set_fp_to_float(val, flt);
return true;
}
yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val,
const char *str) {
if (yyjson_unlikely(!val || !str)) return false;
unsafe_yyjson_set_str(val, str);
return true;
}
yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val,
const char *str, size_t len) {
if (yyjson_unlikely(!val || !str)) return false;
unsafe_yyjson_set_strn(val, str, len);
return true;
}
yyjson_api_inline bool yyjson_mut_set_str_noesc(yyjson_mut_val *val,
bool noesc) {
if (yyjson_unlikely(!yyjson_mut_is_str(val))) return false;
unsafe_yyjson_set_str_noesc(val, noesc);
return true;
}
yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_arr(val, 0);
return true;
}
yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val) {
if (yyjson_unlikely(!val)) return false;
unsafe_yyjson_set_obj(val, 0);
return true;
}
/*==============================================================================
* MARK: - Mutable JSON Value Creation API (Implementation)
*============================================================================*/
#define yyjson_mut_val_one(func) \
if (yyjson_likely(doc)) { \
yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); \
if (yyjson_likely(val)) { \
func \
return val; \
} \
} \
return NULL
#define yyjson_mut_val_one_str(func) \
if (yyjson_likely(doc && str)) { \
yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); \
if (yyjson_likely(val)) { \
func \
return val; \
} \
} \
return NULL
yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc,
const char *str) {
yyjson_mut_val_one_str({ unsafe_yyjson_set_raw(val, str, strlen(str)); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc,
const char *str,
size_t len) {
yyjson_mut_val_one_str({ unsafe_yyjson_set_raw(val, str, len); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc,
const char *str) {
yyjson_mut_val_one_str({
size_t len = strlen(str);
char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len);
if (yyjson_unlikely(!new_str)) return NULL;
unsafe_yyjson_set_raw(val, new_str, len);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc,
const char *str,
size_t len) {
yyjson_mut_val_one_str({
char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len);
if (yyjson_unlikely(!new_str)) return NULL;
unsafe_yyjson_set_raw(val, new_str, len);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc) {
yyjson_mut_val_one({ unsafe_yyjson_set_null(val); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc) {
yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, true); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc) {
yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, false); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc,
bool _val) {
yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, _val); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc,
uint64_t num) {
yyjson_mut_val_one({ unsafe_yyjson_set_uint(val, num); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc,
int64_t num) {
yyjson_mut_val_one({ unsafe_yyjson_set_sint(val, num); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc,
int64_t num) {
yyjson_mut_val_one({ unsafe_yyjson_set_sint(val, num); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_float(yyjson_mut_doc *doc,
float num) {
yyjson_mut_val_one({ unsafe_yyjson_set_float(val, num); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_double(yyjson_mut_doc *doc,
double num) {
yyjson_mut_val_one({ unsafe_yyjson_set_double(val, num); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc,
double num) {
yyjson_mut_val_one({ unsafe_yyjson_set_real(val, num); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc,
const char *str) {
yyjson_mut_val_one_str({ unsafe_yyjson_set_str(val, str); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc,
const char *str,
size_t len) {
yyjson_mut_val_one_str({ unsafe_yyjson_set_strn(val, str, len); });
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc,
const char *str) {
yyjson_mut_val_one_str({
size_t len = strlen(str);
bool noesc = unsafe_yyjson_is_str_noesc(str, len);
yyjson_subtype sub = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE;
char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len);
if (yyjson_unlikely(!new_str)) return NULL;
unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, sub, len);
val->uni.str = new_str;
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc,
const char *str,
size_t len) {
yyjson_mut_val_one_str({
char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len);
if (yyjson_unlikely(!new_str)) return NULL;
unsafe_yyjson_set_strn(val, new_str, len);
});
}
#undef yyjson_mut_val_one
#undef yyjson_mut_val_one_str
/*==============================================================================
* MARK: - Mutable JSON Array API (Implementation)
*============================================================================*/
yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr) {
return yyjson_mut_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr,
size_t idx) {
if (yyjson_likely(idx < yyjson_mut_arr_size(arr))) {
yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr;
while (idx-- > 0) val = val->next;
return val->next;
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first(
yyjson_mut_val *arr) {
if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) {
return ((yyjson_mut_val *)arr->uni.ptr)->next;
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last(
yyjson_mut_val *arr) {
if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) {
return ((yyjson_mut_val *)arr->uni.ptr);
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Array Iterator API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr,
yyjson_mut_arr_iter *iter) {
if (yyjson_likely(yyjson_mut_is_arr(arr) && iter)) {
iter->idx = 0;
iter->max = unsafe_yyjson_get_len(arr);
iter->cur = iter->max ? (yyjson_mut_val *)arr->uni.ptr : NULL;
iter->pre = NULL;
iter->arr = arr;
return true;
}
if (iter) memset(iter, 0, sizeof(yyjson_mut_arr_iter));
return false;
}
yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with(
yyjson_mut_val *arr) {
yyjson_mut_arr_iter iter;
yyjson_mut_arr_iter_init(arr, &iter);
return iter;
}
yyjson_api_inline bool yyjson_mut_arr_iter_has_next(yyjson_mut_arr_iter *iter) {
return iter ? iter->idx < iter->max : false;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next(
yyjson_mut_arr_iter *iter) {
if (iter && iter->idx < iter->max) {
yyjson_mut_val *val = iter->cur;
iter->pre = val;
iter->cur = val->next;
iter->idx++;
return iter->cur;
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove(
yyjson_mut_arr_iter *iter) {
if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) {
yyjson_mut_val *prev = iter->pre;
yyjson_mut_val *cur = iter->cur;
yyjson_mut_val *next = cur->next;
if (yyjson_unlikely(iter->idx == iter->max)) iter->arr->uni.ptr = prev;
iter->idx--;
iter->max--;
unsafe_yyjson_set_len(iter->arr, iter->max);
prev->next = next;
iter->cur = prev;
return cur;
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Array Creation API (Implementation)
*============================================================================*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc) {
if (yyjson_likely(doc)) {
yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1);
if (yyjson_likely(val)) {
val->tag = YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE;
return val;
}
}
return NULL;
}
#define yyjson_mut_arr_with_func(func) \
if (yyjson_likely(doc && ((0 < count && count < \
(~(size_t)0) / sizeof(yyjson_mut_val) && vals) || count == 0))) { \
yyjson_mut_val *arr = unsafe_yyjson_mut_val(doc, 1 + count); \
if (yyjson_likely(arr)) { \
arr->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; \
if (count > 0) { \
size_t i; \
for (i = 0; i < count; i++) { \
yyjson_mut_val *val = arr + i + 1; \
func \
val->next = val + 1; \
} \
arr[count].next = arr + 1; \
arr->uni.ptr = arr + count; \
} \
return arr; \
} \
} \
return NULL
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool(
yyjson_mut_doc *doc, const bool *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_bool(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint(
yyjson_mut_doc *doc, const int64_t *vals, size_t count) {
return yyjson_mut_arr_with_sint64(doc, vals, count);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint(
yyjson_mut_doc *doc, const uint64_t *vals, size_t count) {
return yyjson_mut_arr_with_uint64(doc, vals, count);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real(
yyjson_mut_doc *doc, const double *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_real(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8(
yyjson_mut_doc *doc, const int8_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_sint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16(
yyjson_mut_doc *doc, const int16_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_sint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32(
yyjson_mut_doc *doc, const int32_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_sint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64(
yyjson_mut_doc *doc, const int64_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_sint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8(
yyjson_mut_doc *doc, const uint8_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_uint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16(
yyjson_mut_doc *doc, const uint16_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_uint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32(
yyjson_mut_doc *doc, const uint32_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_uint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64(
yyjson_mut_doc *doc, const uint64_t *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_uint(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float(
yyjson_mut_doc *doc, const float *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_float(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double(
yyjson_mut_doc *doc, const double *vals, size_t count) {
yyjson_mut_arr_with_func({
unsafe_yyjson_set_double(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str(
yyjson_mut_doc *doc, const char **vals, size_t count) {
yyjson_mut_arr_with_func({
if (yyjson_unlikely(!vals[i])) return NULL;
unsafe_yyjson_set_str(val, vals[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn(
yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) {
if (yyjson_unlikely(count > 0 && !lens)) return NULL;
yyjson_mut_arr_with_func({
if (yyjson_unlikely(!vals[i])) return NULL;
unsafe_yyjson_set_strn(val, vals[i], lens[i]);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy(
yyjson_mut_doc *doc, const char **vals, size_t count) {
size_t len;
const char *str, *new_str;
yyjson_mut_arr_with_func({
str = vals[i];
if (yyjson_unlikely(!str)) return NULL;
len = strlen(str);
new_str = unsafe_yyjson_mut_strncpy(doc, str, len);
if (yyjson_unlikely(!new_str)) return NULL;
unsafe_yyjson_set_strn(val, new_str, len);
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy(
yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) {
size_t len;
const char *str, *new_str;
if (yyjson_unlikely(count > 0 && !lens)) return NULL;
yyjson_mut_arr_with_func({
str = vals[i];
if (yyjson_unlikely(!str)) return NULL;
len = lens[i];
new_str = unsafe_yyjson_mut_strncpy(doc, str, len);
if (yyjson_unlikely(!new_str)) return NULL;
unsafe_yyjson_set_strn(val, new_str, len);
});
}
#undef yyjson_mut_arr_with_func
/*==============================================================================
* MARK: - Mutable JSON Array Modification API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr,
yyjson_mut_val *val, size_t idx) {
if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) {
size_t len = unsafe_yyjson_get_len(arr);
if (yyjson_likely(idx <= len)) {
unsafe_yyjson_set_len(arr, len + 1);
if (len == 0) {
val->next = val;
arr->uni.ptr = val;
} else {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
if (idx == len) {
prev->next = val;
val->next = next;
arr->uni.ptr = val;
} else {
while (idx-- > 0) {
prev = next;
next = next->next;
}
prev->next = val;
val->next = next;
}
}
return true;
}
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr,
yyjson_mut_val *val) {
if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) {
size_t len = unsafe_yyjson_get_len(arr);
unsafe_yyjson_set_len(arr, len + 1);
if (len == 0) {
val->next = val;
} else {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
prev->next = val;
val->next = next;
}
arr->uni.ptr = val;
return true;
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr,
yyjson_mut_val *val) {
if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) {
size_t len = unsafe_yyjson_get_len(arr);
unsafe_yyjson_set_len(arr, len + 1);
if (len == 0) {
val->next = val;
arr->uni.ptr = val;
} else {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
prev->next = val;
val->next = next;
}
return true;
}
return false;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr,
size_t idx,
yyjson_mut_val *val) {
if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) {
size_t len = unsafe_yyjson_get_len(arr);
if (yyjson_likely(idx < len)) {
if (yyjson_likely(len > 1)) {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
while (idx-- > 0) {
prev = next;
next = next->next;
}
prev->next = val;
val->next = next->next;
if ((void *)next == arr->uni.ptr) arr->uni.ptr = val;
return next;
} else {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
val->next = val;
arr->uni.ptr = val;
return prev;
}
}
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr,
size_t idx) {
if (yyjson_likely(yyjson_mut_is_arr(arr))) {
size_t len = unsafe_yyjson_get_len(arr);
if (yyjson_likely(idx < len)) {
unsafe_yyjson_set_len(arr, len - 1);
if (yyjson_likely(len > 1)) {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
while (idx-- > 0) {
prev = next;
next = next->next;
}
prev->next = next->next;
if ((void *)next == arr->uni.ptr) arr->uni.ptr = prev;
return next;
} else {
return ((yyjson_mut_val *)arr->uni.ptr);
}
}
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first(
yyjson_mut_val *arr) {
if (yyjson_likely(yyjson_mut_is_arr(arr))) {
size_t len = unsafe_yyjson_get_len(arr);
if (len > 1) {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
prev->next = next->next;
unsafe_yyjson_set_len(arr, len - 1);
return next;
} else if (len == 1) {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
unsafe_yyjson_set_len(arr, 0);
return prev;
}
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last(
yyjson_mut_val *arr) {
if (yyjson_likely(yyjson_mut_is_arr(arr))) {
size_t len = unsafe_yyjson_get_len(arr);
if (yyjson_likely(len > 1)) {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
yyjson_mut_val *next = prev->next;
unsafe_yyjson_set_len(arr, len - 1);
while (--len > 0) prev = prev->next;
prev->next = next;
next = (yyjson_mut_val *)arr->uni.ptr;
arr->uni.ptr = prev;
return next;
} else if (len == 1) {
yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr);
unsafe_yyjson_set_len(arr, 0);
return prev;
}
}
return NULL;
}
yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr,
size_t _idx, size_t _len) {
if (yyjson_likely(yyjson_mut_is_arr(arr))) {
yyjson_mut_val *prev, *next;
bool tail_removed;
size_t len = unsafe_yyjson_get_len(arr);
if (yyjson_unlikely(_idx + _len > len)) return false;
if (yyjson_unlikely(_len == 0)) return true;
unsafe_yyjson_set_len(arr, len - _len);
if (yyjson_unlikely(len == _len)) return true;
tail_removed = (_idx + _len == len);
prev = ((yyjson_mut_val *)arr->uni.ptr);
while (_idx-- > 0) prev = prev->next;
next = prev->next;
while (_len-- > 0) next = next->next;
prev->next = next;
if (yyjson_unlikely(tail_removed)) arr->uni.ptr = prev;
return true;
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr) {
if (yyjson_likely(yyjson_mut_is_arr(arr))) {
unsafe_yyjson_set_len(arr, 0);
return true;
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr,
size_t idx) {
if (yyjson_likely(yyjson_mut_is_arr(arr) &&
unsafe_yyjson_get_len(arr) > idx)) {
yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr;
while (idx-- > 0) val = val->next;
arr->uni.ptr = (void *)val;
return true;
}
return false;
}
/*==============================================================================
* MARK: - Mutable JSON Array Modification Convenience API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr,
yyjson_mut_val *val) {
return yyjson_mut_arr_append(arr, val);
}
yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc,
yyjson_mut_val *arr) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_null(doc);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc,
yyjson_mut_val *arr) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_true(doc);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc,
yyjson_mut_val *arr) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_false(doc);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
bool _val) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_bool(doc, _val);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
uint64_t num) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_uint(doc, num);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
int64_t num) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_sint(doc, num);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
int64_t num) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_sint(doc, num);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_float(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
float num) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_float(doc, num);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_double(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
double num) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_double(doc, num);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
double num) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_real(doc, num);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_str(doc, str);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str, size_t len) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_strn(doc, str, len);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_strcpy(doc, str);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc,
yyjson_mut_val *arr,
const char *str, size_t len) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_strncpy(doc, str, len);
return yyjson_mut_arr_append(arr, val);
}
return false;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc,
yyjson_mut_val *arr) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_arr(doc);
return yyjson_mut_arr_append(arr, val) ? val : NULL;
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc,
yyjson_mut_val *arr) {
if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) {
yyjson_mut_val *val = yyjson_mut_obj(doc);
return yyjson_mut_arr_append(arr, val) ? val : NULL;
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Object API (Implementation)
*============================================================================*/
yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj) {
return yyjson_mut_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj,
const char *key) {
return yyjson_mut_obj_getn(obj, key, key ? strlen(key) : 0);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj,
const char *_key,
size_t key_len) {
size_t len = yyjson_mut_obj_size(obj);
if (yyjson_likely(len && _key)) {
yyjson_mut_val *key = ((yyjson_mut_val *)obj->uni.ptr)->next->next;
while (len-- > 0) {
if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key->next;
key = key->next->next;
}
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Object Iterator API (Implementation)
*============================================================================*/
yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj,
yyjson_mut_obj_iter *iter) {
if (yyjson_likely(yyjson_mut_is_obj(obj) && iter)) {
iter->idx = 0;
iter->max = unsafe_yyjson_get_len(obj);
iter->cur = iter->max ? (yyjson_mut_val *)obj->uni.ptr : NULL;
iter->pre = NULL;
iter->obj = obj;
return true;
}
if (iter) memset(iter, 0, sizeof(yyjson_mut_obj_iter));
return false;
}
yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with(
yyjson_mut_val *obj) {
yyjson_mut_obj_iter iter;
yyjson_mut_obj_iter_init(obj, &iter);
return iter;
}
yyjson_api_inline bool yyjson_mut_obj_iter_has_next(yyjson_mut_obj_iter *iter) {
return iter ? iter->idx < iter->max : false;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next(
yyjson_mut_obj_iter *iter) {
if (iter && iter->idx < iter->max) {
yyjson_mut_val *key = iter->cur;
iter->pre = key;
iter->cur = key->next->next;
iter->idx++;
return iter->cur;
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val(
yyjson_mut_val *key) {
return key ? key->next : NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove(
yyjson_mut_obj_iter *iter) {
if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) {
yyjson_mut_val *prev = iter->pre;
yyjson_mut_val *cur = iter->cur;
yyjson_mut_val *next = cur->next->next;
if (yyjson_unlikely(iter->idx == iter->max)) iter->obj->uni.ptr = prev;
iter->idx--;
iter->max--;
unsafe_yyjson_set_len(iter->obj, iter->max);
prev->next->next = next;
iter->cur = prev;
return cur->next;
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get(
yyjson_mut_obj_iter *iter, const char *key) {
return yyjson_mut_obj_iter_getn(iter, key, key ? strlen(key) : 0);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn(
yyjson_mut_obj_iter *iter, const char *key, size_t key_len) {
if (iter && key) {
size_t idx = 0;
size_t max = iter->max;
yyjson_mut_val *pre, *cur = iter->cur;
while (idx++ < max) {
pre = cur;
cur = cur->next->next;
if (unsafe_yyjson_equals_strn(cur, key, key_len)) {
iter->idx += idx;
if (iter->idx > max) iter->idx -= max + 1;
iter->pre = pre;
iter->cur = cur;
return cur->next;
}
}
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Object Creation API (Implementation)
*============================================================================*/
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc) {
if (yyjson_likely(doc)) {
yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1);
if (yyjson_likely(val)) {
val->tag = YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE;
return val;
}
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc,
const char **keys,
const char **vals,
size_t count) {
if (yyjson_likely(doc && ((count > 0 && keys && vals) || (count == 0)))) {
yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2);
if (yyjson_likely(obj)) {
obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ;
if (count > 0) {
size_t i;
for (i = 0; i < count; i++) {
yyjson_mut_val *key = obj + (i * 2 + 1);
yyjson_mut_val *val = obj + (i * 2 + 2);
uint64_t key_len = (uint64_t)strlen(keys[i]);
uint64_t val_len = (uint64_t)strlen(vals[i]);
key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
key->uni.str = keys[i];
val->uni.str = vals[i];
key->next = val;
val->next = val + 1;
}
obj[count * 2].next = obj + 1;
obj->uni.ptr = obj + (count * 2 - 1);
}
return obj;
}
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc,
const char **pairs,
size_t count) {
if (yyjson_likely(doc && ((count > 0 && pairs) || (count == 0)))) {
yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2);
if (yyjson_likely(obj)) {
obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ;
if (count > 0) {
size_t i;
for (i = 0; i < count; i++) {
yyjson_mut_val *key = obj + (i * 2 + 1);
yyjson_mut_val *val = obj + (i * 2 + 2);
const char *key_str = pairs[i * 2 + 0];
const char *val_str = pairs[i * 2 + 1];
uint64_t key_len = (uint64_t)strlen(key_str);
uint64_t val_len = (uint64_t)strlen(val_str);
key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
key->uni.str = key_str;
val->uni.str = val_str;
key->next = val;
val->next = val + 1;
}
obj[count * 2].next = obj + 1;
obj->uni.ptr = obj + (count * 2 - 1);
}
return obj;
}
}
return NULL;
}
/*==============================================================================
* MARK: - Mutable JSON Object Modification API (Implementation)
*============================================================================*/
yyjson_api_inline void unsafe_yyjson_mut_obj_add(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val,
size_t len) {
if (yyjson_likely(len)) {
yyjson_mut_val *prev_val = ((yyjson_mut_val *)obj->uni.ptr)->next;
yyjson_mut_val *next_key = prev_val->next;
prev_val->next = key;
val->next = next_key;
} else {
val->next = key;
}
key->next = val;
obj->uni.ptr = (void *)key;
unsafe_yyjson_set_len(obj, len + 1);
}
yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_obj_remove(
yyjson_mut_val *obj, const char *key, size_t key_len) {
size_t obj_len = unsafe_yyjson_get_len(obj);
if (obj_len) {
yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr;
yyjson_mut_val *cur_key = pre_key->next->next;
yyjson_mut_val *removed_item = NULL;
size_t i;
for (i = 0; i < obj_len; i++) {
if (unsafe_yyjson_equals_strn(cur_key, key, key_len)) {
if (!removed_item) removed_item = cur_key->next;
cur_key = cur_key->next->next;
pre_key->next->next = cur_key;
if (i + 1 == obj_len) obj->uni.ptr = pre_key;
i--;
obj_len--;
} else {
pre_key = cur_key;
cur_key = cur_key->next->next;
}
}
unsafe_yyjson_set_len(obj, obj_len);
return removed_item;
} else {
return NULL;
}
}
yyjson_api_inline bool unsafe_yyjson_mut_obj_replace(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val) {
size_t key_len = unsafe_yyjson_get_len(key);
size_t obj_len = unsafe_yyjson_get_len(obj);
if (obj_len) {
yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr;
yyjson_mut_val *cur_key = pre_key->next->next;
size_t i;
for (i = 0; i < obj_len; i++) {
if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) {
cur_key->next->tag = val->tag;
cur_key->next->uni.u64 = val->uni.u64;
return true;
} else {
cur_key = cur_key->next->next;
}
}
}
return false;
}
yyjson_api_inline void unsafe_yyjson_mut_obj_rotate(yyjson_mut_val *obj,
size_t idx) {
yyjson_mut_val *key = (yyjson_mut_val *)obj->uni.ptr;
while (idx-- > 0) key = key->next->next;
obj->uni.ptr = (void *)key;
}
yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val) {
if (yyjson_likely(yyjson_mut_is_obj(obj) &&
yyjson_mut_is_str(key) && val)) {
unsafe_yyjson_mut_obj_add(obj, key, val, unsafe_yyjson_get_len(obj));
return true;
}
return false;
}
yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val) {
bool replaced = false;
size_t key_len;
yyjson_mut_obj_iter iter;
yyjson_mut_val *cur_key;
if (yyjson_unlikely(!yyjson_mut_is_obj(obj) ||
!yyjson_mut_is_str(key))) return false;
key_len = unsafe_yyjson_get_len(key);
yyjson_mut_obj_iter_init(obj, &iter);
while ((cur_key = yyjson_mut_obj_iter_next(&iter)) != 0) {
if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) {
if (!replaced && val) {
replaced = true;
val->next = cur_key->next->next;
cur_key->next = val;
} else {
yyjson_mut_obj_iter_remove(&iter);
}
}
}
if (!replaced && val) unsafe_yyjson_mut_obj_add(obj, key, val, iter.max);
return true;
}
yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val,
size_t idx) {
if (yyjson_likely(yyjson_mut_is_obj(obj) &&
yyjson_mut_is_str(key) && val)) {
size_t len = unsafe_yyjson_get_len(obj);
if (yyjson_likely(len >= idx)) {
if (len > idx) {
void *ptr = obj->uni.ptr;
unsafe_yyjson_mut_obj_rotate(obj, idx);
unsafe_yyjson_mut_obj_add(obj, key, val, len);
obj->uni.ptr = ptr;
} else {
unsafe_yyjson_mut_obj_add(obj, key, val, len);
}
return true;
}
}
return false;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj,
yyjson_mut_val *key) {
if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key))) {
return unsafe_yyjson_mut_obj_remove(obj, key->uni.str,
unsafe_yyjson_get_len(key));
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key(
yyjson_mut_val *obj, const char *key) {
if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) {
size_t key_len = strlen(key);
return unsafe_yyjson_mut_obj_remove(obj, key, key_len);
}
return NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn(
yyjson_mut_val *obj, const char *key, size_t key_len) {
if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) {
return unsafe_yyjson_mut_obj_remove(obj, key, key_len);
}
return NULL;
}
yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj) {
if (yyjson_likely(yyjson_mut_is_obj(obj))) {
unsafe_yyjson_set_len(obj, 0);
return true;
}
return false;
}
yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj,
yyjson_mut_val *key,
yyjson_mut_val *val) {
if (yyjson_likely(yyjson_mut_is_obj(obj) &&
yyjson_mut_is_str(key) && val)) {
return unsafe_yyjson_mut_obj_replace(obj, key, val);
}
return false;
}
yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj,
size_t idx) {
if (yyjson_likely(yyjson_mut_is_obj(obj) &&
unsafe_yyjson_get_len(obj) > idx)) {
unsafe_yyjson_mut_obj_rotate(obj, idx);
return true;
}
return false;
}
/*==============================================================================
* MARK: - Mutable JSON Object Modification Convenience API (Implementation)
*============================================================================*/
#define yyjson_mut_obj_add_func(func) \
if (yyjson_likely(doc && yyjson_mut_is_obj(obj) && _key)) { \
yyjson_mut_val *key = unsafe_yyjson_mut_val(doc, 2); \
if (yyjson_likely(key)) { \
size_t len = unsafe_yyjson_get_len(obj); \
yyjson_mut_val *val = key + 1; \
size_t key_len = strlen(_key); \
bool noesc = unsafe_yyjson_is_str_noesc(_key, key_len); \
key->tag = YYJSON_TYPE_STR; \
key->tag |= noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; \
key->tag |= (uint64_t)strlen(_key) << YYJSON_TAG_BIT; \
key->uni.str = _key; \
func \
unsafe_yyjson_mut_obj_add(obj, key, val, len); \
return true; \
} \
} \
return false
yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_null(val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, true); });
}
yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, false); });
}
yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
bool _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
uint64_t _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_uint(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
int64_t _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_sint(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
int64_t _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_sint(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_float(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
float _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_float(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_double(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
double _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_double(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
double _val) {
yyjson_mut_obj_add_func({ unsafe_yyjson_set_real(val, _val); });
}
yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
const char *_val) {
if (yyjson_unlikely(!_val)) return false;
yyjson_mut_obj_add_func({
size_t val_len = strlen(_val);
bool val_noesc = unsafe_yyjson_is_str_noesc(_val, val_len);
val->tag = ((uint64_t)strlen(_val) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
val->tag |= val_noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE;
val->uni.str = _val;
});
}
yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
const char *_val,
size_t _len) {
if (yyjson_unlikely(!_val)) return false;
yyjson_mut_obj_add_func({
val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
val->uni.str = _val;
});
}
yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
const char *_val) {
if (yyjson_unlikely(!_val)) return false;
yyjson_mut_obj_add_func({
size_t _len = strlen(_val);
val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len);
if (yyjson_unlikely(!val->uni.str)) return false;
val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
});
}
yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
const char *_val,
size_t _len) {
if (yyjson_unlikely(!_val)) return false;
yyjson_mut_obj_add_func({
val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len);
if (yyjson_unlikely(!val->uni.str)) return false;
val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key) {
yyjson_mut_val *key = yyjson_mut_str(doc, _key);
yyjson_mut_val *val = yyjson_mut_arr(doc);
return yyjson_mut_obj_add(obj, key, val) ? val : NULL;
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key) {
yyjson_mut_val *key = yyjson_mut_str(doc, _key);
yyjson_mut_val *val = yyjson_mut_obj(doc);
return yyjson_mut_obj_add(obj, key, val) ? val : NULL;
}
yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
yyjson_mut_val *_val) {
if (yyjson_unlikely(!_val)) return false;
yyjson_mut_obj_add_func({
val = _val;
});
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str(yyjson_mut_val *obj,
const char *key) {
return yyjson_mut_obj_remove_strn(obj, key, key ? strlen(key) : 0);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn(
yyjson_mut_val *obj, const char *_key, size_t _len) {
if (yyjson_likely(yyjson_mut_is_obj(obj) && _key)) {
yyjson_mut_val *key;
yyjson_mut_obj_iter iter;
yyjson_mut_val *val_removed = NULL;
yyjson_mut_obj_iter_init(obj, &iter);
while ((key = yyjson_mut_obj_iter_next(&iter)) != NULL) {
if (unsafe_yyjson_equals_strn(key, _key, _len)) {
if (!val_removed) val_removed = key->next;
yyjson_mut_obj_iter_remove(&iter);
}
}
return val_removed;
}
return NULL;
}
yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
const char *new_key) {
if (!key || !new_key) return false;
return yyjson_mut_obj_rename_keyn(doc, obj, key, strlen(key),
new_key, strlen(new_key));
}
yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *key,
size_t len,
const char *new_key,
size_t new_len) {
char *cpy_key = NULL;
yyjson_mut_val *old_key;
yyjson_mut_obj_iter iter;
if (!doc || !obj || !key || !new_key) return false;
yyjson_mut_obj_iter_init(obj, &iter);
while ((old_key = yyjson_mut_obj_iter_next(&iter))) {
if (unsafe_yyjson_equals_strn((void *)old_key, key, len)) {
if (!cpy_key) {
cpy_key = unsafe_yyjson_mut_strncpy(doc, new_key, new_len);
if (!cpy_key) return false;
}
yyjson_mut_set_strn(old_key, cpy_key, new_len);
}
}
return cpy_key != NULL;
}
#if !defined(YYJSON_DISABLE_UTILS) || !YYJSON_DISABLE_UTILS
/*==============================================================================
* MARK: - JSON Pointer API (Implementation)
*============================================================================*/
#define yyjson_ptr_set_err(_code, _msg) do { \
if (err) { \
err->code = YYJSON_PTR_ERR_##_code; \
err->msg = _msg; \
err->pos = 0; \
} \
} while(false)
/* require: val != NULL, *ptr == '/', len > 0 */
yyjson_api yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val,
const char *ptr, size_t len,
yyjson_ptr_err *err);
/* require: val != NULL, *ptr == '/', len > 0 */
yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_getx(yyjson_mut_val *val,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/* require: val/new_val/doc != NULL, *ptr == '/', len > 0 */
yyjson_api bool unsafe_yyjson_mut_ptr_putx(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc,
bool create_parent, bool insert_new,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
/* require: val/err != NULL, *ptr == '/', len > 0 */
yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex(
yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err);
/* require: val/err != NULL, *ptr == '/', len > 0 */
yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_removex(yyjson_mut_val *val,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err);
yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc,
const char *ptr) {
if (yyjson_unlikely(!ptr)) return NULL;
return yyjson_doc_ptr_getn(doc, ptr, strlen(ptr));
}
yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc,
const char *ptr, size_t len) {
return yyjson_doc_ptr_getx(doc, ptr, len, NULL);
}
yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc,
const char *ptr, size_t len,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (yyjson_unlikely(!doc || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(!doc->root)) {
yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
return doc->root;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_ptr_getx(doc->root, ptr, len, err);
}
yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val,
const char *ptr) {
if (yyjson_unlikely(!ptr)) return NULL;
return yyjson_ptr_getn(val, ptr, strlen(ptr));
}
yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val,
const char *ptr, size_t len) {
return yyjson_ptr_getx(val, ptr, len, NULL);
}
yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val,
const char *ptr, size_t len,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (yyjson_unlikely(!val || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
return val;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_ptr_getx(val, ptr, len, err);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc,
const char *ptr) {
if (!ptr) return NULL;
return yyjson_mut_doc_ptr_getn(doc, ptr, strlen(ptr));
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc,
const char *ptr,
size_t len) {
return yyjson_mut_doc_ptr_getx(doc, ptr, len, NULL, NULL);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!doc || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(!doc->root)) {
yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
return doc->root;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_mut_ptr_getx(doc->root, ptr, len, ctx, err);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val,
const char *ptr) {
if (!ptr) return NULL;
return yyjson_mut_ptr_getn(val, ptr, strlen(ptr));
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val,
const char *ptr,
size_t len) {
return yyjson_mut_ptr_getx(val, ptr, len, NULL, NULL);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!val || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
return val;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err);
}
yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc,
const char *ptr,
yyjson_mut_val *new_val) {
if (yyjson_unlikely(!ptr)) return false;
return yyjson_mut_doc_ptr_addn(doc, ptr, strlen(ptr), new_val);
}
yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc,
const char *ptr,
size_t len,
yyjson_mut_val *new_val) {
return yyjson_mut_doc_ptr_addx(doc, ptr, len, new_val, true, NULL, NULL);
}
yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!doc || !ptr || !new_val)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return false;
}
if (yyjson_unlikely(len == 0)) {
if (doc->root) {
yyjson_ptr_set_err(SET_ROOT, "cannot set document's root");
return false;
} else {
doc->root = new_val;
return true;
}
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return false;
}
if (yyjson_unlikely(!doc->root && !create_parent)) {
yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL");
return false;
}
if (yyjson_unlikely(!doc->root)) {
yyjson_mut_val *root = yyjson_mut_obj(doc);
if (yyjson_unlikely(!root)) {
yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value");
return false;
}
if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc,
create_parent, true, ctx, err)) {
doc->root = root;
return true;
}
return false;
}
return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc,
create_parent, true, ctx, err);
}
yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val,
const char *ptr,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc) {
if (yyjson_unlikely(!ptr)) return false;
return yyjson_mut_ptr_addn(val, ptr, strlen(ptr), new_val, doc);
}
yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc) {
return yyjson_mut_ptr_addx(val, ptr, len, new_val, doc, true, NULL, NULL);
}
yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!val || !ptr || !new_val || !doc)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return false;
}
if (yyjson_unlikely(len == 0)) {
yyjson_ptr_set_err(SET_ROOT, "cannot set root");
return false;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return false;
}
return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val,
doc, create_parent, true, ctx, err);
}
yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc,
const char *ptr,
yyjson_mut_val *new_val) {
if (yyjson_unlikely(!ptr)) return false;
return yyjson_mut_doc_ptr_setn(doc, ptr, strlen(ptr), new_val);
}
yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val) {
return yyjson_mut_doc_ptr_setx(doc, ptr, len, new_val, true, NULL, NULL);
}
yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!doc || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return false;
}
if (yyjson_unlikely(len == 0)) {
if (ctx) ctx->old = doc->root;
doc->root = new_val;
return true;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return false;
}
if (!new_val) {
if (!doc->root) {
yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved");
return false;
}
return !!unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err);
}
if (yyjson_unlikely(!doc->root && !create_parent)) {
yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL");
return false;
}
if (yyjson_unlikely(!doc->root)) {
yyjson_mut_val *root = yyjson_mut_obj(doc);
if (yyjson_unlikely(!root)) {
yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value");
return false;
}
if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc,
create_parent, false, ctx, err)) {
doc->root = root;
return true;
}
return false;
}
return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc,
create_parent, false, ctx, err);
}
yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val,
const char *ptr,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc) {
if (yyjson_unlikely(!ptr)) return false;
return yyjson_mut_ptr_setn(val, ptr, strlen(ptr), new_val, doc);
}
yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc) {
return yyjson_mut_ptr_setx(val, ptr, len, new_val, doc, true, NULL, NULL);
}
yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val,
const char *ptr, size_t len,
yyjson_mut_val *new_val,
yyjson_mut_doc *doc,
bool create_parent,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!val || !ptr || !doc)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return false;
}
if (yyjson_unlikely(len == 0)) {
yyjson_ptr_set_err(SET_ROOT, "cannot set root");
return false;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return false;
}
if (!new_val) {
return !!unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err);
}
return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, doc,
create_parent, false, ctx, err);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace(
yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val) {
if (!ptr) return NULL;
return yyjson_mut_doc_ptr_replacen(doc, ptr, strlen(ptr), new_val);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen(
yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val) {
return yyjson_mut_doc_ptr_replacex(doc, ptr, len, new_val, NULL, NULL);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex(
yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!doc || !ptr || !new_val)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
yyjson_mut_val *root = doc->root;
if (yyjson_unlikely(!root)) {
yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved");
return NULL;
}
if (ctx) ctx->old = root;
doc->root = new_val;
return root;
}
if (yyjson_unlikely(!doc->root)) {
yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL");
return NULL;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_mut_ptr_replacex(doc->root, ptr, len, new_val,
ctx, err);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace(
yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val) {
if (!ptr) return NULL;
return yyjson_mut_ptr_replacen(val, ptr, strlen(ptr), new_val);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen(
yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val) {
return yyjson_mut_ptr_replacex(val, ptr, len, new_val, NULL, NULL);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex(
yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!val || !ptr || !new_val)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
yyjson_ptr_set_err(SET_ROOT, "cannot set root");
return NULL;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_mut_ptr_replacex(val, ptr, len, new_val, ctx, err);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove(
yyjson_mut_doc *doc, const char *ptr) {
if (!ptr) return NULL;
return yyjson_mut_doc_ptr_removen(doc, ptr, strlen(ptr));
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen(
yyjson_mut_doc *doc, const char *ptr, size_t len) {
return yyjson_mut_doc_ptr_removex(doc, ptr, len, NULL, NULL);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex(
yyjson_mut_doc *doc, const char *ptr, size_t len,
yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!doc || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(!doc->root)) {
yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
yyjson_mut_val *root = doc->root;
if (ctx) ctx->old = root;
doc->root = NULL;
return root;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val,
const char *ptr) {
if (!ptr) return NULL;
return yyjson_mut_ptr_removen(val, ptr, strlen(ptr));
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val,
const char *ptr,
size_t len) {
return yyjson_mut_ptr_removex(val, ptr, len, NULL, NULL);
}
yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val,
const char *ptr,
size_t len,
yyjson_ptr_ctx *ctx,
yyjson_ptr_err *err) {
yyjson_ptr_set_err(NONE, NULL);
if (ctx) memset(ctx, 0, sizeof(*ctx));
if (yyjson_unlikely(!val || !ptr)) {
yyjson_ptr_set_err(PARAMETER, "input parameter is NULL");
return NULL;
}
if (yyjson_unlikely(len == 0)) {
yyjson_ptr_set_err(SET_ROOT, "cannot set root");
return NULL;
}
if (yyjson_unlikely(*ptr != '/')) {
yyjson_ptr_set_err(SYNTAX, "no prefix '/'");
return NULL;
}
return unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err);
}
yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx,
yyjson_mut_val *key,
yyjson_mut_val *val) {
yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val;
if (!ctx || !ctx->ctn || !val) return false;
ctn = ctx->ctn;
if (yyjson_mut_is_obj(ctn)) {
if (!key) return false;
key->next = val;
pre_key = ctx->pre;
if (unsafe_yyjson_get_len(ctn) == 0) {
val->next = key;
ctn->uni.ptr = key;
ctx->pre = key;
} else if (!pre_key) {
pre_key = (yyjson_mut_val *)ctn->uni.ptr;
pre_val = pre_key->next;
val->next = pre_val->next;
pre_val->next = key;
ctn->uni.ptr = key;
ctx->pre = pre_key;
} else {
cur_key = pre_key->next->next;
cur_val = cur_key->next;
val->next = cur_val->next;
cur_val->next = key;
if (ctn->uni.ptr == cur_key) ctn->uni.ptr = key;
ctx->pre = cur_key;
}
} else {
pre_val = ctx->pre;
if (unsafe_yyjson_get_len(ctn) == 0) {
val->next = val;
ctn->uni.ptr = val;
ctx->pre = val;
} else if (!pre_val) {
pre_val = (yyjson_mut_val *)ctn->uni.ptr;
val->next = pre_val->next;
pre_val->next = val;
ctn->uni.ptr = val;
ctx->pre = pre_val;
} else {
cur_val = pre_val->next;
val->next = cur_val->next;
cur_val->next = val;
if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val;
ctx->pre = cur_val;
}
}
unsafe_yyjson_inc_len(ctn);
return true;
}
yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx,
yyjson_mut_val *val) {
yyjson_mut_val *ctn, *pre_key, *cur_key, *pre_val, *cur_val;
if (!ctx || !ctx->ctn || !ctx->pre || !val) return false;
ctn = ctx->ctn;
if (yyjson_mut_is_obj(ctn)) {
pre_key = ctx->pre;
pre_val = pre_key->next;
cur_key = pre_val->next;
cur_val = cur_key->next;
/* replace current value */
cur_key->next = val;
val->next = cur_val->next;
ctx->old = cur_val;
} else {
pre_val = ctx->pre;
cur_val = pre_val->next;
/* replace current value */
if (pre_val != cur_val) {
val->next = cur_val->next;
pre_val->next = val;
if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val;
} else {
val->next = val;
ctn->uni.ptr = val;
ctx->pre = val;
}
ctx->old = cur_val;
}
return true;
}
yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx) {
yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val;
size_t len;
if (!ctx || !ctx->ctn || !ctx->pre) return false;
ctn = ctx->ctn;
if (yyjson_mut_is_obj(ctn)) {
pre_key = ctx->pre;
pre_val = pre_key->next;
cur_key = pre_val->next;
cur_val = cur_key->next;
/* remove current key-value */
pre_val->next = cur_val->next;
if (ctn->uni.ptr == cur_key) ctn->uni.ptr = pre_key;
ctx->pre = NULL;
ctx->old = cur_val;
} else {
pre_val = ctx->pre;
cur_val = pre_val->next;
/* remove current key-value */
pre_val->next = cur_val->next;
if (ctn->uni.ptr == cur_val) ctn->uni.ptr = pre_val;
ctx->pre = NULL;
ctx->old = cur_val;
}
len = unsafe_yyjson_get_len(ctn) - 1;
if (len == 0) ctn->uni.ptr = NULL;
unsafe_yyjson_set_len(ctn, len);
return true;
}
#undef yyjson_ptr_set_err
/*==============================================================================
* MARK: - JSON Value at Pointer API (Implementation)
*============================================================================*/
/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is type bool.
Returns true if value at `ptr` exists and is the correct type, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_bool(
yyjson_val *root, const char *ptr, bool *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && yyjson_is_bool(val)) {
*value = unsafe_yyjson_get_bool(val);
return true;
} else {
return false;
}
}
/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer
that fits in `uint64_t`. Returns true if successful, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_uint(
yyjson_val *root, const char *ptr, uint64_t *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && val) {
uint64_t ret = val->uni.u64;
if (unsafe_yyjson_is_uint(val) ||
(unsafe_yyjson_is_sint(val) && !(ret >> 63))) {
*value = ret;
return true;
}
}
return false;
}
/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer
that fits in `int64_t`. Returns true if successful, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_sint(
yyjson_val *root, const char *ptr, int64_t *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && val) {
int64_t ret = val->uni.i64;
if (unsafe_yyjson_is_sint(val) ||
(unsafe_yyjson_is_uint(val) && ret >= 0)) {
*value = ret;
return true;
}
}
return false;
}
/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is type real.
Returns true if value at `ptr` exists and is the correct type, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_real(
yyjson_val *root, const char *ptr, double *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && yyjson_is_real(val)) {
*value = unsafe_yyjson_get_real(val);
return true;
} else {
return false;
}
}
/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is type sint,
uint or real.
Returns true if value at `ptr` exists and is the correct type, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_num(
yyjson_val *root, const char *ptr, double *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && yyjson_is_num(val)) {
*value = unsafe_yyjson_get_num(val);
return true;
} else {
return false;
}
}
/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is type string.
Returns true if value at `ptr` exists and is the correct type, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_str(
yyjson_val *root, const char *ptr, const char **value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && yyjson_is_str(val)) {
*value = unsafe_yyjson_get_str(val);
return true;
} else {
return false;
}
}
/*==============================================================================
* MARK: - Deprecated
*============================================================================*/
/** @deprecated renamed to `yyjson_doc_ptr_get` */
yyjson_deprecated("renamed to yyjson_doc_ptr_get")
yyjson_api_inline yyjson_val *yyjson_doc_get_pointer(yyjson_doc *doc,
const char *ptr) {
return yyjson_doc_ptr_get(doc, ptr);
}
/** @deprecated renamed to `yyjson_doc_ptr_getn` */
yyjson_deprecated("renamed to yyjson_doc_ptr_getn")
yyjson_api_inline yyjson_val *yyjson_doc_get_pointern(yyjson_doc *doc,
const char *ptr,
size_t len) {
return yyjson_doc_ptr_getn(doc, ptr, len);
}
/** @deprecated renamed to `yyjson_mut_doc_ptr_get` */
yyjson_deprecated("renamed to yyjson_mut_doc_ptr_get")
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointer(
yyjson_mut_doc *doc, const char *ptr) {
return yyjson_mut_doc_ptr_get(doc, ptr);
}
/** @deprecated renamed to `yyjson_mut_doc_ptr_getn` */
yyjson_deprecated("renamed to yyjson_mut_doc_ptr_getn")
yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointern(
yyjson_mut_doc *doc, const char *ptr, size_t len) {
return yyjson_mut_doc_ptr_getn(doc, ptr, len);
}
/** @deprecated renamed to `yyjson_ptr_get` */
yyjson_deprecated("renamed to yyjson_ptr_get")
yyjson_api_inline yyjson_val *yyjson_get_pointer(yyjson_val *val,
const char *ptr) {
return yyjson_ptr_get(val, ptr);
}
/** @deprecated renamed to `yyjson_ptr_getn` */
yyjson_deprecated("renamed to yyjson_ptr_getn")
yyjson_api_inline yyjson_val *yyjson_get_pointern(yyjson_val *val,
const char *ptr,
size_t len) {
return yyjson_ptr_getn(val, ptr, len);
}
/** @deprecated renamed to `yyjson_mut_ptr_get` */
yyjson_deprecated("renamed to yyjson_mut_ptr_get")
yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointer(yyjson_mut_val *val,
const char *ptr) {
return yyjson_mut_ptr_get(val, ptr);
}
/** @deprecated renamed to `yyjson_mut_ptr_getn` */
yyjson_deprecated("renamed to yyjson_mut_ptr_getn")
yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointern(yyjson_mut_val *val,
const char *ptr,
size_t len) {
return yyjson_mut_ptr_getn(val, ptr, len);
}
/** @deprecated renamed to `yyjson_mut_ptr_getn` */
yyjson_deprecated("renamed to unsafe_yyjson_ptr_getn")
yyjson_api_inline yyjson_val *unsafe_yyjson_get_pointer(yyjson_val *val,
const char *ptr,
size_t len) {
yyjson_ptr_err err;
return unsafe_yyjson_ptr_getx(val, ptr, len, &err);
}
/** @deprecated renamed to `unsafe_yyjson_mut_ptr_getx` */
yyjson_deprecated("renamed to unsafe_yyjson_mut_ptr_getx")
yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_get_pointer(
yyjson_mut_val *val, const char *ptr, size_t len) {
yyjson_ptr_err err;
return unsafe_yyjson_mut_ptr_getx(val, ptr, len, NULL, &err);
}
#endif /* YYJSON_DISABLE_UTILS */
/*==============================================================================
* MARK: - Compiler Hint End
*============================================================================*/
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__)
# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
# pragma GCC diagnostic pop
# endif
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif /* warning suppress end */
#ifdef __cplusplus
}
#endif /* extern "C" end */
#endif /* YYJSON_H */
================================================
FILE: src/common/FFPlatform.h
================================================
#pragma once
#include "common/FFstrbuf.h"
#include "common/FFlist.h"
typedef struct FFPlatformSysinfo
{
FFstrbuf name;
FFstrbuf release;
FFstrbuf version;
FFstrbuf architecture;
uint32_t pageSize;
} FFPlatformSysinfo;
typedef struct FFPlatform
{
FFstrbuf homeDir; // Trailing slash included
FFstrbuf cacheDir; // Trailing slash included
FFlist configDirs; // List of FFstrbuf, trailing slash included
FFlist dataDirs; // List of FFstrbuf, trailing slash included
FFstrbuf exePath; // The real path of current exe (empty if unavailable)
FFstrbuf cwd; // Trailing slash included
uint32_t pid;
#ifndef _WIN32
uint32_t uid;
#else
FFstrbuf sid;
#endif
FFstrbuf userName;
FFstrbuf fullUserName;
FFstrbuf hostName;
FFstrbuf userShell;
FFPlatformSysinfo sysinfo;
} FFPlatform;
void ffPlatformInit(FFPlatform* platform);
void ffPlatformDestroy(FFPlatform* platform);
================================================
FILE: src/common/FFcheckmacros.h
================================================
#pragma once
#ifdef _MSC_VER
#include
#endif
#if defined(__has_attribute) && __has_attribute(__warn_unused_result__)
#define FF_C_NODISCARD __attribute__((__warn_unused_result__))
#elif defined(_MSC_VER)
#define FF_C_NODISCARD _Check_return_
#else
#define FF_C_NODISCARD
#endif
#if defined(__has_attribute) && __has_attribute(__format__)
#define FF_C_PRINTF(formatStrIndex, argsStartIndex) __attribute__((__format__ (printf, formatStrIndex, argsStartIndex)))
#else
#define FF_C_PRINTF(formatStrIndex, argsStartIndex)
#endif
#if defined(__has_attribute) && __has_attribute(__format__)
#define FF_C_SCANF(formatStrIndex, argsStartIndex) __attribute__((__format__ (scanf, formatStrIndex, argsStartIndex)))
#else
#define FF_C_SCANF(formatStrIndex, argsStartIndex)
#endif
#if defined(__has_attribute) && __has_attribute(__nonnull__)
#define FF_C_NONNULL(argIndex, ...) __attribute__((__nonnull__(argIndex, ##__VA_ARGS__)))
#else
#define FF_C_NONNULL(argIndex, ...)
#endif
#if defined(__has_attribute) && __has_attribute(__returns_nonnull__)
#define FF_C_RETURNS_NONNULL __attribute__((__returns_nonnull__))
#else
#define FF_C_RETURNS_NONNULL
#endif
================================================
FILE: src/common/FFlist.h
================================================
#pragma once
#include "FFcheckmacros.h"
#include
#include
#include
#include
#define FF_LIST_DEFAULT_ALLOC 16
typedef struct FFlist
{
uint8_t* data;
uint32_t elementSize;
uint32_t length;
uint32_t capacity;
} FFlist;
void* ffListAdd(FFlist* list);
// Removes the first element, and copy its value to `*result`
bool ffListShift(FFlist* list, void* result);
// Removes the last element, and copy its value to `*result`
bool ffListPop(FFlist* list, void* result);
static inline void ffListInit(FFlist* list, uint32_t elementSize)
{
assert(elementSize > 0);
list->elementSize = elementSize;
list->capacity = 0;
list->length = 0;
list->data = NULL;
}
static inline void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capacity)
{
ffListInit(list, elementSize);
list->capacity = capacity;
list->data = __builtin_expect(capacity == 0, 0) ? NULL : (uint8_t*) malloc((size_t)list->capacity * list->elementSize);
}
static inline FFlist ffListCreate(uint32_t elementSize)
{
FFlist result;
ffListInit(&result, elementSize);
return result;
}
static inline void* ffListGet(const FFlist* list, uint32_t index)
{
assert(list->capacity > index);
return list->data + (index * list->elementSize);
}
FF_C_NODISCARD static inline uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*))
{
for(uint32_t i = 0; i < list->length; i++)
{
if(compFunc(ffListGet(list, i), compElement))
return i;
}
return list->length;
}
static inline bool ffListContains(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*))
{
return ffListFirstIndexComp(list, compElement, compFunc) != list->length;
}
static inline void ffListSort(FFlist* list, int(*compar)(const void*, const void*))
{
qsort(list->data, list->length, list->elementSize, compar);
}
// Move the contents of `src` into `list`, and left `src` empty
static inline void ffListInitMove(FFlist* list, FFlist* src)
{
if (src)
{
list->elementSize = src->elementSize;
list->capacity = src->capacity;
list->length = src->length;
list->data = src->data;
ffListInit(src, list->elementSize);
}
else
{
ffListInit(list, 0);
}
}
static inline void ffListDestroy(FFlist* list)
{
if (!list->data) return;
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
list->capacity = list->length = 0;
free(list->data);
list->data = NULL;
}
static inline void ffListClear(FFlist* list)
{
list->length = 0;
}
static inline void ffListReserve(FFlist* list, uint32_t newCapacity)
{
if (__builtin_expect(newCapacity <= list->capacity, false))
return;
list->data = (uint8_t*) realloc(list->data, (size_t) newCapacity * list->elementSize);
list->capacity = newCapacity;
}
#define FF_LIST_FOR_EACH(itemType, itemVarName, listVar) \
assert(sizeof(itemType) == (listVar).elementSize); \
for(itemType* itemVarName = (itemType*)(listVar).data; \
itemVarName - (itemType*)(listVar).data < (intptr_t)(listVar).length; \
++itemVarName)
#define FF_LIST_AUTO_DESTROY FFlist __attribute__((__cleanup__(ffListDestroy)))
#define FF_LIST_GET(itemType, listVar, index) \
({ \
assert(sizeof(itemType) == (listVar).elementSize); \
assert((listVar).capacity > (index)); \
(itemType*)(listVar).data + (index); \
})
#define FF_LIST_ADD(itemType, listVar) \
({ \
assert(sizeof(itemType) == (listVar).elementSize); \
(itemType*) ffListAdd(&(listVar)); \
})
#define FF_LIST_FIRST(itemType, listVar) FF_LIST_GET(itemType, listVar, 0)
#define FF_LIST_LAST(itemType, listVar) \
({ \
assert((listVar).length > 0); \
FF_LIST_GET(itemType, listVar, ((listVar).length - 1)); \
})
================================================
FILE: src/common/FFstrbuf.h
================================================
#pragma once
#include "FFcheckmacros.h"
#include
#include
#include
#include
#include
#include
#include
#ifdef FF_USE_SYSTEM_YYJSON
#include
#else
#include "3rdparty/yyjson/yyjson.h"
#endif
#ifdef _WIN32
// #include
__stdcall char* StrStrIA(const char* lpFirst, const char* lpSrch);
#define strcasestr StrStrIA
#endif
#define FASTFETCH_STRBUF_DEFAULT_ALLOC 32
// static string (allocated == 0), chars points to a string literal
// dynamic string (allocated > 0), chars points to a heap allocated buffer
typedef struct FFstrbuf
{
uint32_t allocated;
uint32_t length;
char* chars;
} FFstrbuf;
static inline void ffStrbufInit(FFstrbuf* strbuf);
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate);
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments);
void ffStrbufInitMoveNS(FFstrbuf* strbuf, uint32_t length, char* heapStr);
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free);
void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free);
void ffStrbufClear(FFstrbuf* strbuf);
static inline void ffStrbufAppend(FFstrbuf* __restrict strbuf, const FFstrbuf* __restrict value);
void ffStrbufAppendC(FFstrbuf* strbuf, char c);
void ffStrbufAppendNC(FFstrbuf* strbuf, uint32_t num, char c);
void ffStrbufAppendNS(FFstrbuf* strbuf, uint32_t length, const char* value);
void ffStrbufAppendTransformS(FFstrbuf* strbuf, const char* value, int(*transformFunc)(int));
FF_C_PRINTF(2, 3) void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments);
const char* ffStrbufAppendSUntilC(FFstrbuf* strbuf, const char* value, char until);
void ffStrbufPrependNS(FFstrbuf* strbuf, uint32_t length, const char* value);
void ffStrbufPrependC(FFstrbuf* strbuf, char c);
void ffStrbufInsertNC(FFstrbuf* strbuf, uint32_t index, uint32_t num, char c);
// Clear the content of strbuf and set new value
// NOTE: Unlike ffStrbufAppend*, ffStrbufSet* functions may NOT reserve extra space
void ffStrbufSet(FFstrbuf* strbuf, const FFstrbuf* value);
void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value);
FF_C_PRINTF(2, 3) void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
void ffStrbufTrimLeft(FFstrbuf* strbuf, char c);
void ffStrbufTrimRight(FFstrbuf* strbuf, char c);
void ffStrbufTrimLeftSpace(FFstrbuf* strbuf);
void ffStrbufTrimRightSpace(FFstrbuf* strbuf);
bool ffStrbufRemoveSubstr(FFstrbuf* strbuf, uint32_t startIndex, uint32_t endIndex);
void ffStrbufRemoveS(FFstrbuf* strbuf, const char* str);
void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, const char* strings[]);
FF_C_NODISCARD uint32_t ffStrbufNextIndexC(const FFstrbuf* strbuf, uint32_t start, char c);
FF_C_NODISCARD uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t start, const char* str);
FF_C_NODISCARD uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c);
void ffStrbufReplaceAllC(FFstrbuf* strbuf, char find, char replace);
// Returns true if the strbuf is modified
bool ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index);
bool ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index); // Not including the index
bool ffStrbufSubstrAfterFirstC(FFstrbuf* strbuf, char c);
bool ffStrbufSubstrAfterFirstS(FFstrbuf* strbuf, const char* str);
bool ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, char c);
bool ffStrbufSubstr(FFstrbuf* strbuf, uint32_t start, uint32_t end);
FF_C_NODISCARD uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c);
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end);
bool ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c);
void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file);
void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file);
FF_C_NODISCARD double ffStrbufToDouble(const FFstrbuf* strbuf, double defaultValue);
FF_C_NODISCARD int64_t ffStrbufToSInt(const FFstrbuf* strbuf, int64_t defaultValue);
FF_C_NODISCARD uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue);
void ffStrbufUpperCase(FFstrbuf* strbuf);
void ffStrbufLowerCase(FFstrbuf* strbuf);
// Function alters the buffer to extract lines or delimited segments (replaces the delimiter with '\0')
// so that buffer MUST be heap allocated (NOT a static string)
// `lineptr` must be `NULL` and `n` MUST be `0` for the first call
// Caller MUST NOT free `*lineptr`
bool ffStrbufGetdelim(char** lineptr, size_t* n, char delimiter, FFstrbuf* buffer);
void ffStrbufGetdelimRestore(char** lineptr, size_t* n, char delimiter, FFstrbuf* buffer);
/**
* @brief Read a line from a FFstrbuf.
*
* @details Behaves like getline(3) but reads from a FFstrbuf.
*
* @param[in,out] lineptr The pointer to a pointer that will be set to the start of the line
(points to buffer's internal memory address to avoid memory allocation and copy).
MUST NOT be freed by the caller, unlike `getline(3)`.
* MUST be NULL for the first call.
* @param[in,out] n The pointer to the size of the buffer of lineptr.
MUST be 0 for the first call.
* @param[in] buffer The buffer to read from.
MUST be heap allocated (NOT a static string).
*
* @return true if a line has been read, false if the end of the buffer has been reached.
*/
static inline bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer)
{
return ffStrbufGetdelim(lineptr, n, '\n', buffer);
}
/**
* @brief Restore the end of a line that was modified by ffStrbufGetline.
* @warning This function should be called before breaking an ffStrbufGetline loop if `buffer` will be used later.
*/
static inline void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer)
{
ffStrbufGetdelimRestore(lineptr, n, '\n', buffer);
}
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf);
bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator);
bool ffStrbufMatchSeparatedIgnCaseNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator);
bool ffStrbufSeparatedContainNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator);
bool ffStrbufSeparatedContainIgnCaseNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator);
int ffStrbufAppendUtf32CodePoint(FFstrbuf* strbuf, uint32_t codepoint);
void ffStrbufAppendSInt(FFstrbuf* strbuf, int64_t value);
void ffStrbufAppendUInt(FFstrbuf* strbuf, uint64_t value);
// Appends a double value to the string buffer with the specified precision (0~15).
// if `precision < 0`, let yyjson decide the precision
void ffStrbufAppendDouble(FFstrbuf* strbuf, double value, int8_t precision, bool trailingZeros);
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)
{
FFstrbuf strbuf;
ffStrbufInitA(&strbuf, allocate);
return strbuf;
}
static inline void ffStrbufInitCopy(FFstrbuf* __restrict strbuf, const FFstrbuf* __restrict src)
{
if (src->allocated == 0) // static string
*strbuf = *src;
else
{
ffStrbufInitA(strbuf, src->allocated);
ffStrbufAppend(strbuf, src);
}
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateCopy(const FFstrbuf* src)
{
FFstrbuf strbuf;
ffStrbufInitCopy(&strbuf, src);
return strbuf;
}
// Move the content of `src` into `strbuf`, and left `src` empty
static inline void ffStrbufInitMove(FFstrbuf* strbuf, FFstrbuf* src)
{
if (src)
{
*strbuf = *src;
ffStrbufInit(src);
}
else
ffStrbufInit(strbuf);
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateMove(FFstrbuf* src)
{
FFstrbuf strbuf;
ffStrbufInitMove(&strbuf, src);
return strbuf;
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateVF(const char* format, va_list arguments)
{
FFstrbuf strbuf;
ffStrbufInitVF(&strbuf, format, arguments);
return strbuf;
}
FF_C_PRINTF(2, 3)
static inline void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...)
{
va_list arguments;
va_start(arguments, format);
ffStrbufInitVF(strbuf, format, arguments);
va_end(arguments);
}
FF_C_PRINTF(1, 2)
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateF(const char* format, ...)
{
FFstrbuf strbuf;
va_list arguments;
va_start(arguments, format);
ffStrbufInitVF(&strbuf, format, arguments);
va_end(arguments);
return strbuf;
}
static inline void ffStrbufInitMoveS(FFstrbuf* strbuf, char* heapStr)
{
ffStrbufInitMoveNS(strbuf, (uint32_t) strlen(heapStr), heapStr);
}
static inline void ffStrbufDestroy(FFstrbuf* strbuf)
{
if(strbuf->allocated > 0)
free(strbuf->chars);
ffStrbufInit(strbuf);
}
FF_C_NODISCARD static inline uint32_t ffStrbufGetFree(const FFstrbuf* strbuf)
{
assert(strbuf != NULL);
if(strbuf->allocated == 0)
return 0;
return strbuf->allocated - strbuf->length - 1; // - 1 for the null byte
}
static inline void ffStrbufRecalculateLength(FFstrbuf* strbuf)
{
strbuf->length = (uint32_t) strlen(strbuf->chars);
}
static inline void ffStrbufSetS(FFstrbuf* strbuf, const char* value)
{
assert(strbuf != NULL);
if (value == NULL)
ffStrbufClear(strbuf);
else
ffStrbufSetNS(strbuf, (uint32_t) strlen(value), value);
}
static inline bool ffStrbufSetJsonVal(FFstrbuf* strbuf, yyjson_val* jsonVal)
{
assert(strbuf != NULL);
if (yyjson_is_str(jsonVal))
{
ffStrbufSetNS(strbuf, (uint32_t) unsafe_yyjson_get_len(jsonVal), unsafe_yyjson_get_str(jsonVal));
return true;
}
ffStrbufClear(strbuf);
return false;
}
static inline void ffStrbufAppendS(FFstrbuf* strbuf, const char* value)
{
if(value == NULL)
return;
ffStrbufAppendNS(strbuf, (uint32_t) strlen(value), value);
}
static inline bool ffStrbufAppendJsonVal(FFstrbuf* strbuf, yyjson_val* jsonVal)
{
if (yyjson_is_str(jsonVal))
{
ffStrbufAppendNS(strbuf, (uint32_t) unsafe_yyjson_get_len(jsonVal), unsafe_yyjson_get_str(jsonVal));
return true;
}
return false;
}
static inline void ffStrbufInit(FFstrbuf* strbuf)
{
extern char* CHAR_NULL_PTR;
strbuf->allocated = strbuf->length = 0;
strbuf->chars = CHAR_NULL_PTR;
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreate(void)
{
FFstrbuf strbuf;
ffStrbufInit(&strbuf);
return strbuf;
}
static inline void ffStrbufInitStatic(FFstrbuf* strbuf, const char* str)
{
ffStrbufInit(strbuf);
if (!str) return;
strbuf->allocated = 0;
strbuf->length = (uint32_t) strlen(str);
strbuf->chars = (char*) str;
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateStatic(const char* str)
{
FFstrbuf strbuf;
ffStrbufInitStatic(&strbuf, str);
return strbuf;
}
static inline void ffStrbufSetStatic(FFstrbuf* strbuf, const char* value)
{
if(strbuf->allocated > 0)
free(strbuf->chars);
if(value != NULL)
ffStrbufInitStatic(strbuf, value);
else
ffStrbufInit(strbuf);
}
static inline void ffStrbufInitNS(FFstrbuf* strbuf, uint32_t length, const char* str)
{
ffStrbufInit(strbuf);
ffStrbufAppendNS(strbuf, length, str);
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateNS(uint32_t length, const char* str)
{
FFstrbuf strbuf;
ffStrbufInitNS(&strbuf, length, str);
return strbuf;
}
static inline bool ffStrbufInitJsonVal(FFstrbuf* strbuf, yyjson_val* jsonVal)
{
ffStrbufInit(strbuf);
return ffStrbufAppendJsonVal(strbuf, jsonVal);
}
static inline void ffStrbufInitS(FFstrbuf* strbuf, const char* str)
{
ffStrbufInit(strbuf);
ffStrbufAppendS(strbuf, str);
}
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateS(const char* str)
{
FFstrbuf strbuf;
ffStrbufInitS(&strbuf, str);
return strbuf;
}
static inline void ffStrbufAppend(FFstrbuf* __restrict strbuf, const FFstrbuf* __restrict value)
{
assert(value != strbuf);
if(value == NULL)
return;
ffStrbufAppendNS(strbuf, value->length, value->chars);
}
static inline void ffStrbufPrepend(FFstrbuf* strbuf, FFstrbuf* value)
{
if(value == NULL)
return;
ffStrbufPrependNS(strbuf, value->length, value->chars);
}
static inline void ffStrbufPrependS(FFstrbuf* strbuf, const char* value)
{
if(value == NULL)
return;
ffStrbufPrependNS(strbuf, (uint32_t) strlen(value), value);
}
static inline FF_C_NODISCARD int ffStrbufComp(const FFstrbuf* strbuf, const FFstrbuf* comp)
{
uint32_t length = strbuf->length > comp->length ? comp->length : strbuf->length;
return memcmp(strbuf->chars, comp->chars, length + 1);
}
static inline FF_C_NODISCARD bool ffStrbufEqual(const FFstrbuf* strbuf, const FFstrbuf* comp)
{
return ffStrbufComp(strbuf, comp) == 0;
}
static inline FF_C_NODISCARD int ffStrbufCompS(const FFstrbuf* strbuf, const char* comp)
{
return strcmp(strbuf->chars, comp);
}
static inline FF_C_NODISCARD bool ffStrbufEqualS(const FFstrbuf* strbuf, const char* comp)
{
return ffStrbufCompS(strbuf, comp) == 0;
}
static inline FF_C_NODISCARD int ffStrbufIgnCaseCompS(const FFstrbuf* strbuf, const char* comp)
{
return strcasecmp(strbuf->chars, comp);
}
static inline FF_C_NODISCARD bool ffStrbufIgnCaseEqualS(const FFstrbuf* strbuf, const char* comp)
{
return ffStrbufIgnCaseCompS(strbuf, comp) == 0;
}
static inline FF_C_NODISCARD int ffStrbufIgnCaseComp(const FFstrbuf* strbuf, const FFstrbuf* comp)
{
return ffStrbufIgnCaseCompS(strbuf, comp->chars);
}
static inline FF_C_NODISCARD bool ffStrbufIgnCaseEqual(const FFstrbuf* strbuf, const FFstrbuf* comp)
{
return ffStrbufIgnCaseComp(strbuf, comp) == 0;
}
static inline FF_C_NODISCARD bool ffStrbufContainC(const FFstrbuf* strbuf, char c)
{
return memchr(strbuf->chars, c, strbuf->length) != NULL;
}
static inline FF_C_NODISCARD bool ffStrbufContainS(const FFstrbuf* strbuf, const char* str)
{
return strstr(strbuf->chars, str) != NULL;
}
static inline FF_C_NODISCARD bool ffStrbufContain(const FFstrbuf* strbuf, const FFstrbuf* str)
{
return ffStrbufContainS(strbuf, str->chars);
}
static inline FF_C_NODISCARD bool ffStrbufContainIgnCaseS(const FFstrbuf* strbuf, const char* str)
{
return strcasestr(strbuf->chars, str) != NULL;
}
static inline FF_C_NODISCARD bool ffStrbufContainIgnCase(const FFstrbuf* strbuf, const FFstrbuf* str)
{
return ffStrbufContainIgnCaseS(strbuf, str->chars);
}
static inline FF_C_NODISCARD uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, char c)
{
return ffStrbufNextIndexC(strbuf, 0, c);
}
static inline FF_C_NODISCARD uint32_t ffStrbufFirstIndex(const FFstrbuf* strbuf, const FFstrbuf* searched)
{
return ffStrbufNextIndexS(strbuf, 0, searched->chars);
}
static inline FF_C_NODISCARD uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str)
{
return ffStrbufNextIndexS(strbuf, 0, str);
}
static inline FF_C_NODISCARD uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, char c)
{
if(strbuf->length == 0)
return 0;
return ffStrbufPreviousIndexC(strbuf, strbuf->length - 1, c);
}
static inline bool ffStrbufSubstrBeforeFirstC(FFstrbuf* strbuf, char c)
{
return ffStrbufSubstrBefore(strbuf, ffStrbufFirstIndexC(strbuf, c));
}
static inline bool ffStrbufSubstrBeforeLastC(FFstrbuf* strbuf, char c)
{
return ffStrbufSubstrBefore(strbuf, ffStrbufLastIndexC(strbuf, c));
}
static inline FF_C_NODISCARD bool ffStrbufStartsWithC(const FFstrbuf* strbuf, char c)
{
return strbuf->chars[0] == c;
}
static inline FF_C_NODISCARD bool ffStrbufStartsWithSN(const FFstrbuf* strbuf, const char* start, uint32_t length)
{
if (length > strbuf->length)
return false;
return memcmp(strbuf->chars, start, length) == 0;
}
static inline FF_C_NODISCARD bool ffStrbufStartsWithS(const FFstrbuf* strbuf, const char* start)
{
return ffStrbufStartsWithSN(strbuf, start, (uint32_t) strlen(start));
}
static inline FF_C_NODISCARD bool ffStrbufStartsWith(const FFstrbuf* strbuf, const FFstrbuf* start)
{
return ffStrbufStartsWithSN(strbuf, start->chars, start->length);
}
static inline FF_C_NODISCARD bool ffStrbufStartsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t length, const char* start)
{
if(length > strbuf->length)
return false;
return strncasecmp(strbuf->chars, start, length) == 0;
}
static inline FF_C_NODISCARD bool ffStrbufStartsWithIgnCaseS(const FFstrbuf* strbuf, const char* start)
{
return ffStrbufStartsWithIgnCaseNS(strbuf, (uint32_t) strlen(start), start);
}
static inline FF_C_NODISCARD bool ffStrbufStartsWithIgnCase(const FFstrbuf* strbuf, const FFstrbuf* start)
{
return ffStrbufStartsWithIgnCaseNS(strbuf, start->length, start->chars);
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithC(const FFstrbuf* strbuf, char c)
{
return strbuf->length == 0 ? false :
strbuf->chars[strbuf->length - 1] == c;
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithNS(const FFstrbuf* strbuf, uint32_t endLength, const char* end)
{
if(endLength > strbuf->length)
return false;
return memcmp(strbuf->chars + strbuf->length - endLength, end, endLength) == 0;
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end)
{
return ffStrbufEndsWithNS(strbuf, (uint32_t) strlen(end), end);
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithFn(const FFstrbuf* strbuf, int (*const fn)(int))
{
return strbuf->length == 0 ? false :
fn(strbuf->chars[strbuf->length - 1]);
}
static inline FF_C_NODISCARD bool ffStrbufEndsWith(const FFstrbuf* strbuf, const FFstrbuf* end)
{
return ffStrbufEndsWithNS(strbuf, end->length, end->chars);
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t endLength, const char* end)
{
if(endLength > strbuf->length)
return false;
return strcasecmp(strbuf->chars + strbuf->length - endLength, end) == 0;
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end)
{
return ffStrbufEndsWithIgnCaseNS(strbuf, (uint32_t) strlen(end), end);
}
static inline FF_C_NODISCARD bool ffStrbufEndsWithIgnCase(const FFstrbuf* strbuf, const FFstrbuf* end)
{
return ffStrbufEndsWithIgnCaseNS(strbuf, end->length, end->chars);
}
static inline void ffStrbufTrim(FFstrbuf* strbuf, char c)
{
ffStrbufTrimRight(strbuf, c);
ffStrbufTrimLeft(strbuf, c);
}
static inline void ffStrbufTrimSpace(FFstrbuf* strbuf)
{
ffStrbufTrimRightSpace(strbuf);
ffStrbufTrimLeftSpace(strbuf);
}
static inline bool ffStrbufMatchSeparatedS(const FFstrbuf* strbuf, const char* comp, char separator)
{
return ffStrbufMatchSeparatedNS(strbuf, (uint32_t) strlen(comp), comp, separator);
}
static inline bool ffStrbufMatchSeparated(const FFstrbuf* strbuf, const FFstrbuf* comp, char separator)
{
return ffStrbufMatchSeparatedNS(strbuf, comp->length, comp->chars, separator);
}
static inline bool ffStrbufMatchSeparatedIgnCaseS(const FFstrbuf* strbuf, const char* comp, char separator)
{
return ffStrbufMatchSeparatedIgnCaseNS(strbuf, (uint32_t) strlen(comp), comp, separator);
}
static inline bool ffStrbufMatchSeparatedIgnCase(const FFstrbuf* strbuf, const FFstrbuf* comp, char separator)
{
return ffStrbufMatchSeparatedIgnCaseNS(strbuf, comp->length, comp->chars, separator);
}
static inline bool ffStrbufSeparatedContainS(const FFstrbuf* strbuf, const char* comp, char separator)
{
return ffStrbufSeparatedContainNS(strbuf, (uint32_t) strlen(comp), comp, separator);
}
static inline bool ffStrbufSeparatedContain(const FFstrbuf* strbuf, const FFstrbuf* comp, char separator)
{
return ffStrbufSeparatedContainNS(strbuf, comp->length, comp->chars, separator);
}
static inline bool ffStrbufSeparatedContainIgnCaseS(const FFstrbuf* strbuf, const char* comp, char separator)
{
return ffStrbufSeparatedContainIgnCaseNS(strbuf, (uint32_t) strlen(comp), comp, separator);
}
static inline bool ffStrbufSeparatedContainIgnCase(const FFstrbuf* strbuf, const FFstrbuf* comp, char separator)
{
return ffStrbufSeparatedContainIgnCaseNS(strbuf, comp->length, comp->chars, separator);
}
#define FF_STRBUF_AUTO_DESTROY FFstrbuf __attribute__((__cleanup__(ffStrbufDestroy)))
================================================
FILE: src/common/apple/Info.plist.in
================================================
CFBundleIdentifier
fastfetch
CFBundleName
@PROJECT_NAME@
CFBundleShortVersionString
@PROJECT_VERSION@
CFBundleDevelopmentRegion
English
NSBluetoothAlwaysUsageDescription
For detecting Bluetooth devices
================================================
FILE: src/common/apple/cf_helpers.c
================================================
#include "cf_helpers.h"
const char* ffCfNumGetInt64(CFTypeRef cf, int64_t* result)
{
if(CFGetTypeID(cf) == CFNumberGetTypeID())
{
if(!CFNumberGetValue((CFNumberRef)cf, kCFNumberSInt64Type, result))
return "Number type is not SInt64";
return NULL;
}
else if(CFGetTypeID(cf) == CFDataGetTypeID())
{
if(CFDataGetLength((CFDataRef)cf) != sizeof(int64_t))
return "Data length is not sizeof(int64_t)";
CFDataGetBytes((CFDataRef)cf, CFRangeMake(0, sizeof(int64_t)), (uint8_t*)result);
return NULL;
}
return "TypeID is neither 'CFNumber' nor 'CFData'";
}
const char* ffCfNumGetInt(CFTypeRef cf, int32_t* result)
{
if(CFGetTypeID(cf) == CFNumberGetTypeID())
{
if(!CFNumberGetValue((CFNumberRef)cf, kCFNumberSInt32Type, result))
return "Number type is not SInt32";
return NULL;
}
else if(CFGetTypeID(cf) == CFDataGetTypeID())
{
if(CFDataGetLength((CFDataRef)cf) != sizeof(int))
return "Data length is not sizeof(int)";
CFDataGetBytes((CFDataRef)cf, CFRangeMake(0, sizeof(int)), (uint8_t*)result);
return NULL;
}
return "TypeID is neither 'CFNumber' nor 'CFData'";
}
const char* ffCfStrGetString(CFTypeRef cf, FFstrbuf* result)
{
ffStrbufClear(result);
if (!cf)
return NULL;
if (CFGetTypeID(cf) == CFStringGetTypeID())
{
CFStringRef cfStr = (CFStringRef)cf;
const char* cstr = CFStringGetCStringPtr(cfStr, kCFStringEncodingUTF8);
if (cstr)
ffStrbufSetS(result, cstr);
else
{
uint32_t length = (uint32_t) CFStringGetLength(cfStr);
if (length == 0)
return NULL;
ffStrbufEnsureFixedLengthFree(result, (uint32_t) CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8));
if(!CFStringGetCString(cfStr, result->chars, result->allocated, kCFStringEncodingUTF8))
return "CFStringGetCString() failed";
// CFStringGetCString ensures the buffer is NUL terminated
// https://developer.apple.com/documentation/corefoundation/1542721-cfstringgetcstring
result->length = (uint32_t) strnlen(result->chars, (uint32_t)result->allocated);
}
}
else if (CFGetTypeID(cf) == CFDataGetTypeID())
{
CFDataRef cfData = (CFDataRef)cf;
uint32_t length = (uint32_t)CFDataGetLength(cfData);
if (length == 0)
return NULL;
ffStrbufEnsureFixedLengthFree(result, length + 1);
CFDataGetBytes(cfData, CFRangeMake(0, length), (uint8_t*)result->chars);
result->length = (uint32_t)strnlen(result->chars, length);
result->chars[result->length] = '\0';
}
else
return "TypeID is neither 'CFString' nor 'CFData'";
return NULL;
}
const char* ffCfDataGetDataAsString(CFTypeRef cf, FFstrbuf* result)
{
ffStrbufClear(result);
if (!cf)
return NULL;
if (CFGetTypeID(cf) == CFDataGetTypeID())
{
CFDataRef cfData = (CFDataRef)cf;
uint32_t length = (uint32_t)CFDataGetLength(cfData);
if (length == 0)
return NULL;
ffStrbufEnsureFixedLengthFree(result, length + 1);
CFDataGetBytes(cfData, CFRangeMake(0, length), (uint8_t*)result->chars);
result->length = length;
result->chars[result->length] = '\0';
}
else
return "TypeID is not 'CFData'";
return NULL;
}
const char* ffCfDictGetString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result)
{
CFTypeRef cf = (CFTypeRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
return ffCfStrGetString(cf, result);
}
const char* ffCfDictGetDataAsString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result)
{
CFTypeRef cf = (CFTypeRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
return ffCfDataGetDataAsString(cf, result);
}
const char* ffCfDictGetBool(CFDictionaryRef dict, CFStringRef key, bool* result)
{
CFBooleanRef cf = (CFBooleanRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
if(CFGetTypeID(cf) != CFBooleanGetTypeID())
return "TypeID is not 'CFBoolean'";
*result = CFBooleanGetValue(cf);
return NULL;
}
const char* ffCfDictGetInt(CFDictionaryRef dict, CFStringRef key, int* result)
{
CFTypeRef cf = (CFTypeRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
return ffCfNumGetInt(cf, result);
}
const char* ffCfDictGetInt64(CFDictionaryRef dict, CFStringRef key, int64_t* result)
{
CFTypeRef cf = (CFTypeRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
return ffCfNumGetInt64(cf, result);
}
const char* ffCfDictGetData(CFDictionaryRef dict, CFStringRef key, uint32_t offset, uint32_t size, uint8_t* result, uint32_t* length)
{
CFTypeRef cf = (CFTypeRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
if(CFGetTypeID(cf) != CFDataGetTypeID())
return "TypeID is not 'CFData'";
CFIndex trueLength = CFDataGetLength((CFDataRef)cf);
if(trueLength < offset + size)
return "Data length is less than offset + size";
if(length)
*length = (uint32_t) trueLength;
CFDataGetBytes((CFDataRef)cf, CFRangeMake(offset, size), result);
return NULL;
}
const char* ffCfDictGetDict(CFDictionaryRef dict, CFStringRef key, CFDictionaryRef* result)
{
CFDictionaryRef cf = (CFDictionaryRef)CFDictionaryGetValue(dict, key);
if (cf == NULL || CFGetTypeID(cf) != CFDictionaryGetTypeID())
return "TypeID is not 'CFDictionary'";
*result = cf;
return NULL;
}
================================================
FILE: src/common/apple/cf_helpers.h
================================================
#pragma once
#include "fastfetch.h"
#include
#include
//Return error info if failed, NULL otherwise
const char* ffCfStrGetString(CFTypeRef cf, FFstrbuf* result);
const char* ffCfNumGetInt(CFTypeRef cf, int32_t* result);
const char* ffCfNumGetInt64(CFTypeRef cf, int64_t* result);
const char* ffCfDataGetDataAsString(CFTypeRef cf, FFstrbuf* result);
const char* ffCfDictGetString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result);
const char* ffCfDictGetBool(CFDictionaryRef dict, CFStringRef key, bool* result);
const char* ffCfDictGetInt(CFDictionaryRef dict, CFStringRef key, int* result);
const char* ffCfDictGetInt64(CFDictionaryRef dict, CFStringRef key, int64_t* result);
const char* ffCfDictGetData(CFDictionaryRef dict, CFStringRef key, uint32_t offset, uint32_t size, uint8_t* result, uint32_t* length);
const char* ffCfDictGetDataAsString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result);
const char* ffCfDictGetDict(CFDictionaryRef dict, CFStringRef key, CFDictionaryRef* result);
static inline CFNumberRef ffCfCreateInt(int value)
{
return CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
}
static inline void cfReleaseWrapper(void* type)
{
assert(type);
if (*(CFTypeRef*) type)
CFRelease(*(CFTypeRef*) type);
}
#define FF_CFTYPE_AUTO_RELEASE __attribute__((__cleanup__(cfReleaseWrapper)))
static inline void wrapIoObjectRelease(io_object_t* service)
{
assert(service);
if (*service)
IOObjectRelease(*service);
}
#define FF_IOOBJECT_AUTO_RELEASE __attribute__((__cleanup__(wrapIoObjectRelease)))
================================================
FILE: src/common/apple/osascript.h
================================================
#pragma once
#include "fastfetch.h"
bool ffOsascript(const char* input, FFstrbuf* result);
================================================
FILE: src/common/apple/osascript.m
================================================
#include "osascript.h"
#import
#import
#import
bool ffOsascript(const char* input, FFstrbuf* result)
{
NSAppleScript* script = [NSAppleScript.alloc initWithSource:@(input)];
NSDictionary* errInfo = nil;
NSAppleEventDescriptor* descriptor = [script executeAndReturnError:&errInfo];
if (errInfo)
return false;
ffStrbufSetS(result, descriptor.stringValue.UTF8String);
return true;
}
================================================
FILE: src/common/apple/smc_temps.c
================================================
#include "smc_temps.h"
#include "common/apple/cf_helpers.h"
#include "common/stringUtils.h"
#include
#include
#include
static const char kSmcCmdReadBytes = 5;
static const char kSmcCmdReadKeyInfo = 9;
static const uint32_t kKernelIndexSmc = 2;
typedef struct
{
char major;
char minor;
char build;
char reserved[1];
uint16_t release;
} SmcKeyData_vers_t;
typedef struct
{
uint16_t version;
uint16_t length;
uint32_t cpuPLimit;
uint32_t gpuPLimit;
uint32_t memPLimit;
} SmcKeyData_pLimitData_t;
typedef struct
{
uint32_t dataSize;
uint32_t dataType;
char dataAttributes;
} SmcKeyData_keyInfo_t;
typedef unsigned char SmcBytes_t[32];
typedef struct
{
uint32_t key;
SmcKeyData_vers_t vers;
SmcKeyData_pLimitData_t pLimitData;
SmcKeyData_keyInfo_t keyInfo;
char result;
char status;
char data8;
uint32_t data32;
SmcBytes_t bytes;
} SmcKeyData_t;
typedef char UInt32Char_t[5];
typedef struct
{
UInt32Char_t key;
uint32_t dataSize;
UInt32Char_t dataType;
SmcBytes_t bytes;
} SmcVal_t;
static uint32_t smcStrtoul(const char *str, int size, int base)
{
uint32_t total = 0;
for (int i = 0; i < size; i++)
{
if (base == 16)
total += (uint32_t)(str[i] << (size - 1 - i) * 8);
else
total += (uint32_t)((unsigned char)(str[i]) << (size - 1 - i) * 8);
}
return total;
}
static void smcUltostr(char *str, uint32_t val)
{
str[0] = (char)(val >> 24);
str[1] = (char)(val >> 16);
str[2] = (char)(val >> 8);
str[3] = (char)val;
str[4] = '\0';
}
static const char *smcCall(io_connect_t conn, uint32_t selector, SmcKeyData_t *inputStructure, SmcKeyData_t *outputStructure)
{
size_t size = sizeof(SmcKeyData_t);
if (IOConnectCallStructMethod(conn, selector, inputStructure, size, outputStructure, &size) != kIOReturnSuccess)
return "IOConnectCallStructMethod(conn) failed";
return NULL;
}
// Provides key info, using a cache to dramatically improve the energy impact of smcFanControl
static const char *smcGetKeyInfo(io_connect_t conn, const uint32_t key, SmcKeyData_keyInfo_t *key_info)
{
SmcKeyData_t inputStructure = {0};
SmcKeyData_t outputStructure = {0};
inputStructure.key = key;
inputStructure.data8 = kSmcCmdReadKeyInfo;
const char *error = smcCall(conn, kKernelIndexSmc, &inputStructure, &outputStructure);
if (error)
return error;
*key_info = outputStructure.keyInfo;
return NULL;
}
static const char *smcReadSmcVal(io_connect_t conn, const UInt32Char_t key, SmcVal_t *val)
{
SmcKeyData_t inputStructure = {0};
SmcKeyData_t outputStructure = {0};
inputStructure.key = smcStrtoul(key, 4, 16);
strcpy(val->key, key);
const char *error = smcGetKeyInfo(conn, inputStructure.key, &outputStructure.keyInfo);
if (error)
return error;
val->dataSize = outputStructure.keyInfo.dataSize;
smcUltostr(val->dataType, outputStructure.keyInfo.dataType);
inputStructure.keyInfo.dataSize = val->dataSize;
inputStructure.data8 = kSmcCmdReadBytes;
error = smcCall(conn, kKernelIndexSmc, &inputStructure, &outputStructure);
if (error)
return error;
memcpy(val->bytes, outputStructure.bytes, sizeof(outputStructure.bytes));
return NULL;
}
static const char *smcOpen(io_connect_t *conn)
{
FF_IOOBJECT_AUTO_RELEASE io_object_t device = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("AppleSMC"));
if (!device)
return "No SMC device found";
if (IOServiceOpen(device, mach_task_self(), 0, conn) != kIOReturnSuccess)
return "IOServiceOpen() failed";
return NULL;
}
static const char *smcReadValue(io_connect_t conn, const UInt32Char_t key, double *value)
{
SmcVal_t val = {0};
const char* error = smcReadSmcVal(conn, key, &val);
if (error != NULL)
return error;
if (val.dataSize == 0)
return "Empty SMC result";
switch (val.dataType[0])
{
case 'u': // unsigned integer types
if (val.dataType[1] == 'i')
{
switch (val.dataSize)
{
case 1: *value = *(uint8_t *)(val.bytes); break;
case 2: *value = ntohs(*(uint16_t *)(val.bytes)); break;
case 4: *value = ntohl(*(uint32_t *)(val.bytes)); break;
case 8: *value = (double) ntohll(*(uint64_t *)(val.bytes)); break;
default:
return "Unsupported SMC unsigned integer data size";
}
}
else
return "Unsupported SMC unsigned data type";
break;
case 'f': // floating point types
if (ffStrEquals(val.dataType, "flt ") && val.dataSize == 4)
*value = *(float *)(val.bytes);
else if (val.dataType[1] == 'p' && val.dataSize == 2) // fixed point types
{
if (ffStrEquals(val.dataType, "fp1f"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 32768.0;
else if (ffStrEquals(val.dataType, "fp4c"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 4096.0;
else if (ffStrEquals(val.dataType, "fp5b"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 2048.0;
else if (ffStrEquals(val.dataType, "fp6a"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 1024.0;
else if (ffStrEquals(val.dataType, "fp79"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 512.0;
else if (ffStrEquals(val.dataType, "fp88"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 256.0;
else if (ffStrEquals(val.dataType, "fpa6"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 64.0;
else if (ffStrEquals(val.dataType, "fpc4"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 16.0;
else if (ffStrEquals(val.dataType, "fpe2"))
*value = ntohs(*(uint16_t *)(val.bytes)) / 4.0;
else
return "Unsupported SMC floating point data type";
}
else
return "Unsupported SMC floating point data type";
break;
case 's': // signed integer types
if (val.dataType[1] == 'i')
{
switch (val.dataSize)
{
case 1: *value = *(int8_t *)(val.bytes); break;
case 2: *value = ntohs(*(int16_t *)(val.bytes)); break;
case 4: *value = ntohl(*(int32_t *)(val.bytes)); break;
case 8: *value = (double)ntohll(*(int64_t *)(val.bytes)); break;
default: return "Unsupported SMC signed integer data size";
}
}
else if (val.dataType[1] == 'p' && val.dataSize == 2) // signed fixed point types
{
if (ffStrEquals(val.dataType, "sp1e"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 16384.0;
else if (ffStrEquals(val.dataType, "sp3c"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 4096.0;
else if (ffStrEquals(val.dataType, "sp4b"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 2048.0;
else if (ffStrEquals(val.dataType, "sp5a"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 1024.0;
else if (ffStrEquals(val.dataType, "sp69"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 512.0;
else if (ffStrEquals(val.dataType, "sp78"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 256.0;
else if (ffStrEquals(val.dataType, "sp87"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 128.0;
else if (ffStrEquals(val.dataType, "sp96"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 64.0;
else if (ffStrEquals(val.dataType, "spb4"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 16.0;
else if (ffStrEquals(val.dataType, "spf0"))
*value = (int16_t)ntohs(*(int16_t *)(val.bytes)) / 1.0;
else
return "Unsupported SMC signed integer data type";
}
else
return "Unsupported SMC signed data type";
break;
case '{': // special types like pwm
if (ffStrEquals(val.dataType, "{pwm") && val.dataSize == 2)
{
*value = (double)ntohs(*(uint16_t *)(val.bytes)) * 100 / 65536.0;
}
else
return "Unsupported SMC special data type";
break;
default:
return "Unsupported SMC data type";
}
return NULL;
}
static bool detectTemp(io_connect_t conn, const char* sensor, double* sum)
{
double temp = 0;
const char* error = smcReadValue(conn, sensor, &temp);
if (error) return false;
// https://github.com/exelban/stats/blob/14e29c4d60229c363cca9c9d25c30c87b7870830/Modules/Sensors/readers.swift#L124
if (temp < 10 || temp > 120) return false;
*sum += temp;
return true;
}
static io_connect_t conn;
const char* ffDetectSmcSpecificTemp(const char* sensor, double* result)
{
if (!conn)
{
if (smcOpen(&conn) != NULL)
conn = (io_connect_t) -1;
}
if (conn == (io_connect_t) -1)
return "Could not open SMC connection";
if (!detectTemp(conn, sensor, result))
return "Could not read SMC temperature";
return NULL;
}
const char* ffDetectSmcTemps(enum FFTempType type, double* result)
{
if (!conn)
{
if (smcOpen(&conn) != NULL)
conn = (io_connect_t) -1;
}
if (conn == (io_connect_t) -1)
return "Could not open SMC connection";
uint32_t count = 0;
*result = 0;
// https://github.com/exelban/stats/blob/master/Modules/Sensors/values.swift
switch (type)
{
case FF_TEMP_CPU_X64:
count += detectTemp(conn, "TC0D", result); // CPU diode
count += detectTemp(conn, "TC0E", result); // CPU diode virtual
count += detectTemp(conn, "TC0F", result); // CPU diode filtered
count += detectTemp(conn, "TC0P", result); // CPU proximity
break;
case FF_TEMP_CPU_M1X:
count += detectTemp(conn, "Tp09", result); // CPU efficient core 1
count += detectTemp(conn, "Tp0T", result); // CPU efficient core 2
count += detectTemp(conn, "Tp01", result); // CPU performance core 1
count += detectTemp(conn, "Tp05", result); // CPU performance core 2
count += detectTemp(conn, "Tp0D", result); // CPU performance core 3
count += detectTemp(conn, "Tp0H", result); // CPU performance core 4
count += detectTemp(conn, "Tp0L", result); // CPU performance core 5
count += detectTemp(conn, "Tp0P", result); // CPU performance core 6
count += detectTemp(conn, "Tp0X", result); // CPU performance core 7
count += detectTemp(conn, "Tp0b", result); // CPU performance core 8
break;
case FF_TEMP_CPU_M2X:
count += detectTemp(conn, "Tp1h", result); // CPU efficiency core 1
count += detectTemp(conn, "Tp1t", result); // CPU efficiency core 2
count += detectTemp(conn, "Tp1p", result); // CPU efficiency core 3
count += detectTemp(conn, "Tp1l", result); // CPU efficiency core 4
count += detectTemp(conn, "Tp01", result); // CPU performance core 1
count += detectTemp(conn, "Tp05", result); // CPU performance core 2
count += detectTemp(conn, "Tp09", result); // CPU performance core 3
count += detectTemp(conn, "Tp0D", result); // CPU performance core 4
count += detectTemp(conn, "Tp0X", result); // CPU performance core 5
count += detectTemp(conn, "Tp0b", result); // CPU performance core 6
count += detectTemp(conn, "Tp0f", result); // CPU performance core 7
count += detectTemp(conn, "Tp0j", result); // CPU performance core 8
break;
case FF_TEMP_CPU_M3X:
count += detectTemp(conn, "Te05", result); // CPU efficiency core 1
count += detectTemp(conn, "Te0L", result); // CPU efficiency core 2
count += detectTemp(conn, "Te0P", result); // CPU efficiency core 3
count += detectTemp(conn, "Te0S", result); // CPU efficiency core 4
count += detectTemp(conn, "Tf04", result); // CPU performance core 1
count += detectTemp(conn, "Tf09", result); // CPU performance core 2
count += detectTemp(conn, "Tf0A", result); // CPU performance core 3
count += detectTemp(conn, "Tf0B", result); // CPU performance core 4
count += detectTemp(conn, "Tf0D", result); // CPU performance core 5
count += detectTemp(conn, "Tf0E", result); // CPU performance core 6
count += detectTemp(conn, "Tf44", result); // CPU performance core 7
count += detectTemp(conn, "Tf49", result); // CPU performance core 8
count += detectTemp(conn, "Tf4A", result); // CPU performance core 9
count += detectTemp(conn, "Tf4B", result); // CPU performance core 10
count += detectTemp(conn, "Tf4D", result); // CPU performance core 11
count += detectTemp(conn, "Tf4E", result); // CPU performance core 12
break;
case FF_TEMP_CPU_M4X:
count += detectTemp(conn, "Te05", result); // CPU efficiency core 1
count += detectTemp(conn, "Te0S", result); // CPU efficiency core 2
count += detectTemp(conn, "Te09", result); // CPU efficiency core 3
count += detectTemp(conn, "Te0H", result); // CPU efficiency core 4
count += detectTemp(conn, "Tp01", result); // CPU performance core 1
count += detectTemp(conn, "Tp05", result); // CPU performance core 2
count += detectTemp(conn, "Tp09", result); // CPU performance core 3
count += detectTemp(conn, "Tp0D", result); // CPU performance core 4
count += detectTemp(conn, "Tp0V", result); // CPU performance core 5
count += detectTemp(conn, "Tp0Y", result); // CPU performance core 6
count += detectTemp(conn, "Tp0b", result); // CPU performance core 7
count += detectTemp(conn, "Tp0e", result); // CPU performance core 8
break;
case FF_TEMP_GPU_INTEL:
count += detectTemp(conn, "TCGC", result); // GPU Intel Graphics
goto gpu_unknown;
case FF_TEMP_GPU_AMD:
count += detectTemp(conn, "TGDD", result); // GPU AMD Radeon
goto gpu_unknown;
case FF_TEMP_GPU_UNKNOWN: // Nvidia?
gpu_unknown:
count += detectTemp(conn, "TG0D", result); // GPU diode
count += detectTemp(conn, "TG0P", result); // GPU proximity
break;
case FF_TEMP_GPU_M1X:
count += detectTemp(conn, "Tg05", result); // GPU 1
count += detectTemp(conn, "Tg0D", result); // GPU 2
count += detectTemp(conn, "Tg0L", result); // GPU 3
count += detectTemp(conn, "Tg0T", result); // GPU 4
break;
case FF_TEMP_GPU_M2X:
count += detectTemp(conn, "Tg0f", result); // GPU 1
count += detectTemp(conn, "Tg0j", result); // GPU 2
break;
case FF_TEMP_GPU_M3X:
count += detectTemp(conn, "Tf14", result); // GPU 1
count += detectTemp(conn, "Tf18", result); // GPU 2
count += detectTemp(conn, "Tf19", result); // GPU 3
count += detectTemp(conn, "Tf1A", result); // GPU 4
count += detectTemp(conn, "Tf24", result); // GPU 5
count += detectTemp(conn, "Tf28", result); // GPU 6
count += detectTemp(conn, "Tf29", result); // GPU 7
count += detectTemp(conn, "Tf2A", result); // GPU 8
break;
case FF_TEMP_GPU_M4X:
count += detectTemp(conn, "Tg0G", result); // GPU 1 (Basic)
count += detectTemp(conn, "Tg0H", result); // GPU 2 (Basic)
count += detectTemp(conn, "Tg1U", result); // GPU 1 (Pro / Max)
count += detectTemp(conn, "Tg1k", result); // GPU 2 (Pro / Max)
count += detectTemp(conn, "Tg0K", result); // GPU 3
count += detectTemp(conn, "Tg0L", result); // GPU 4
count += detectTemp(conn, "Tg0d", result); // GPU 5
count += detectTemp(conn, "Tg0e", result); // GPU 6
count += detectTemp(conn, "Tg0j", result); // GPU 7
count += detectTemp(conn, "Tg0k", result); // GPU 8
break;
case FF_TEMP_BATTERY:
count += detectTemp(conn, "TB1T", result); // Battery
count += detectTemp(conn, "TB2T", result); // Battery
break;
case FF_TEMP_MEMORY:
count += detectTemp(conn, "Tm02", result); // Memory 1
count += detectTemp(conn, "Tm06", result); // Memory 2
count += detectTemp(conn, "Tm08", result); // Memory 3
count += detectTemp(conn, "Tm09", result); // Memory 4
break;
}
if (count == 0)
return "No temperatures detected";
*result /= count;
return NULL;
}
================================================
FILE: src/common/apple/smc_temps.h
================================================
#pragma once
#include "fastfetch.h"
typedef struct FFTempValue
{
FFstrbuf name;
FFstrbuf deviceClass;
double value;
} FFTempValue;
enum FFTempType
{
FF_TEMP_CPU_X64,
FF_TEMP_CPU_M1X,
FF_TEMP_CPU_M2X,
FF_TEMP_CPU_M3X,
FF_TEMP_CPU_M4X,
FF_TEMP_GPU_INTEL,
FF_TEMP_GPU_AMD,
FF_TEMP_GPU_UNKNOWN,
FF_TEMP_GPU_M1X,
FF_TEMP_GPU_M2X,
FF_TEMP_GPU_M3X,
FF_TEMP_GPU_M4X,
FF_TEMP_BATTERY,
FF_TEMP_MEMORY,
};
const char* ffDetectSmcSpecificTemp(const char* sensor, double* result);
const char* ffDetectSmcTemps(enum FFTempType type, double* result);
================================================
FILE: src/common/argType.h
================================================
#pragma once
#include "common/FFstrbuf.h"
typedef enum __attribute__((__packed__)) FFArgType
{
FF_ARG_TYPE_NULL = 0,
FF_ARG_TYPE_UINT,
FF_ARG_TYPE_UINT64,
FF_ARG_TYPE_UINT16,
FF_ARG_TYPE_UINT8,
FF_ARG_TYPE_INT,
FF_ARG_TYPE_STRING,
FF_ARG_TYPE_STRBUF,
FF_ARG_TYPE_FLOAT,
FF_ARG_TYPE_DOUBLE,
FF_ARG_TYPE_LIST,
FF_ARG_TYPE_BOOL
} FFArgType;
#define FF_ARG(variable, var_name) { _Generic((variable), \
uint32_t: FF_ARG_TYPE_UINT, \
uint64_t: FF_ARG_TYPE_UINT64, \
uint16_t: FF_ARG_TYPE_UINT16, \
uint8_t: FF_ARG_TYPE_UINT8, \
int32_t: FF_ARG_TYPE_INT, \
char*: FF_ARG_TYPE_STRING, \
const char*: FF_ARG_TYPE_STRING, \
FFstrbuf: FF_ARG_TYPE_STRBUF, \
float: FF_ARG_TYPE_FLOAT, \
double: FF_ARG_TYPE_DOUBLE, \
FFlist: FF_ARG_TYPE_LIST, \
bool: FF_ARG_TYPE_BOOL \
), _Generic((variable), char*: (variable), const char*: (variable), default: &(variable) ), (var_name) }
================================================
FILE: src/common/arrayUtils.h
================================================
#pragma once
#include
#ifdef __has_builtin
#if !__cplusplus && FF_SUPPORTS_COUNT_OF
#define ARRAY_SIZE(x) _Countof(x)
#elif __has_builtin(__is_array)
#define ARRAY_SIZE(x) ({ static_assert(__is_array(__typeof__(x)), "Must be an array"); (uint32_t) (sizeof(x) / sizeof(*(x))); })
#elif __has_builtin(__builtin_types_compatible_p)
#define ARRAY_SIZE(x) ({ static_assert(!__builtin_types_compatible_p(__typeof__(x), __typeof__(&*(x))), "Must not be a pointer"); (uint32_t) (sizeof(x) / sizeof(*(x))); })
#endif
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) ((uint32_t) (sizeof(x) / sizeof(*(x))))
#endif
================================================
FILE: src/common/base64.h
================================================
#pragma once
#include "fastfetch.h"
void ffBase64EncodeRaw(uint32_t size, const char *str, uint32_t *out_size, char *output);
static inline FFstrbuf ffBase64EncodeStrbuf(const FFstrbuf* in)
{
FFstrbuf out = ffStrbufCreateA(10 + in->length * 4 / 3);
ffBase64EncodeRaw(in->length, in->chars, &out.length, out.chars);
assert(out.length < out.allocated);
return out;
}
bool ffBase64DecodeRaw(uint32_t size, const char *str, uint32_t *out_size, char *output);
static inline FFstrbuf ffBase64DecodeStrbuf(const FFstrbuf* in)
{
FFstrbuf out = ffStrbufCreateA(10 + in->length * 3 / 4);
ffBase64DecodeRaw(in->length, in->chars, &out.length, out.chars);
assert(out.length < out.allocated);
return out;
}
================================================
FILE: src/common/binary.h
================================================
#pragma once
#include "fastfetch.h"
/**
* Extracts string literals from a binary file
*
* @param file Path to the binary file to extract strings from
* @param cb Callback function that will be called for each string found
* Return false from callback to stop extraction
* @param userdata User-provided data passed to the callback function
* @param minLength Minimum length of strings to extract
*
* @return NULL on success, error message on failure.
* @note This function won't return an error if no strings are found.
* Always check if strings are correctly extracted after this function all.
*/
const char* ffBinaryExtractStrings(const char* file, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength);
================================================
FILE: src/common/color.h
================================================
#pragma once
#define FF_COLOR_MODE_RESET "0;"
#define FF_COLOR_MODE_BOLD "1;"
#define FF_COLOR_MODE_DIM "2;"
#define FF_COLOR_MODE_ITALIC "3;"
#define FF_COLOR_MODE_UNDERLINE "4;"
#define FF_COLOR_MODE_BLINK "5;"
#define FF_COLOR_MODE_INVERSE "7;"
#define FF_COLOR_MODE_HIDDEN "8;"
#define FF_COLOR_MODE_STRIKETHROUGH "9;"
#define FF_COLOR_FG_BLACK "30"
#define FF_COLOR_FG_RED "31"
#define FF_COLOR_FG_GREEN "32"
#define FF_COLOR_FG_YELLOW "33"
#define FF_COLOR_FG_BLUE "34"
#define FF_COLOR_FG_MAGENTA "35"
#define FF_COLOR_FG_CYAN "36"
#define FF_COLOR_FG_WHITE "37"
#define FF_COLOR_FG_DEFAULT "39"
#define FF_COLOR_FG_LIGHT_BLACK "90"
#define FF_COLOR_FG_LIGHT_RED "91"
#define FF_COLOR_FG_LIGHT_GREEN "92"
#define FF_COLOR_FG_LIGHT_YELLOW "93"
#define FF_COLOR_FG_LIGHT_BLUE "94"
#define FF_COLOR_FG_LIGHT_MAGENTA "95"
#define FF_COLOR_FG_LIGHT_CYAN "96"
#define FF_COLOR_FG_LIGHT_WHITE "97"
#define FF_COLOR_BG_BLACK "40"
#define FF_COLOR_BG_RED "41"
#define FF_COLOR_BG_GREEN "42"
#define FF_COLOR_BG_YELLOW "43"
#define FF_COLOR_BG_BLUE "44"
#define FF_COLOR_BG_MAGENTA "45"
#define FF_COLOR_BG_CYAN "46"
#define FF_COLOR_BG_WHITE "47"
#define FF_COLOR_BG_DEFAULT "49"
#define FF_COLOR_BG_LIGHT_BLACK "100"
#define FF_COLOR_BG_LIGHT_RED "101"
#define FF_COLOR_BG_LIGHT_GREEN "102"
#define FF_COLOR_BG_LIGHT_YELLOW "103"
#define FF_COLOR_BG_LIGHT_BLUE "104"
#define FF_COLOR_BG_LIGHT_MAGENTA "105"
#define FF_COLOR_BG_LIGHT_CYAN "106"
#define FF_COLOR_BG_LIGHT_WHITE "107"
#define FF_COLOR_FG_256 "38;5;"
#define FF_COLOR_BG_256 "48;5;"
#define FF_COLOR_FG_RGB "38;2;"
#define FF_COLOR_BG_RGB "48;2;"
================================================
FILE: src/common/commandoption.h
================================================
#pragma once
#include "common/ffdata.h"
void ffPrepareCommandOption(FFdata* data);
void ffPrintCommandOption(FFdata* data);
void ffMigrateCommandOptionToJsonc(FFdata* data);
bool ffParseModuleOptions(const char* key, const char* value);
================================================
FILE: src/common/dbus.h
================================================
#pragma once
#ifdef FF_HAVE_DBUS
#include
#include "common/FFstrbuf.h"
#include "common/library.h"
typedef struct FFDBusLibrary
{
FF_LIBRARY_SYMBOL(dbus_bus_get)
FF_LIBRARY_SYMBOL(dbus_message_new_method_call)
FF_LIBRARY_SYMBOL(dbus_message_append_args)
FF_LIBRARY_SYMBOL(dbus_message_iter_init)
FF_LIBRARY_SYMBOL(dbus_message_iter_get_arg_type)
FF_LIBRARY_SYMBOL(dbus_message_iter_get_basic)
FF_LIBRARY_SYMBOL(dbus_message_iter_recurse)
FF_LIBRARY_SYMBOL(dbus_message_iter_has_next)
FF_LIBRARY_SYMBOL(dbus_message_iter_next)
FF_LIBRARY_SYMBOL(dbus_message_unref)
FF_LIBRARY_SYMBOL(dbus_connection_send_with_reply_and_block)
FF_LIBRARY_SYMBOL(dbus_connection_unref)
} FFDBusLibrary;
typedef struct FFDBusData
{
const FFDBusLibrary* lib;
DBusConnection* connection;
} FFDBusData;
const char* ffDBusLoadData(DBusBusType busType, FFDBusData* data); //Returns an error message or NULL on success
bool ffDBusGetString(FFDBusData* dbus, DBusMessageIter* iter, FFstrbuf* result);
bool ffDBusGetBool(FFDBusData* dbus, DBusMessageIter* iter, bool* result);
bool ffDBusGetUint(FFDBusData* dbus, DBusMessageIter* iter, uint32_t* result);
DBusMessage* ffDBusGetMethodReply(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* method, const char* arg1, const char* arg2);
DBusMessage* ffDBusGetProperty(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property);
bool ffDBusGetPropertyString(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property, FFstrbuf* result);
bool ffDBusGetInt(FFDBusData* dbus, DBusMessageIter* iter, int32_t* result);
bool ffDBusGetPropertyUint(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property, uint32_t* result);
void ffDBusDestroyData(FFDBusData* data);
static inline DBusMessage* ffDBusGetAllProperties(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface)
{
return ffDBusGetMethodReply(dbus, busName, objectPath, "org.freedesktop.DBus.Properties", "GetAll", interface, NULL);
}
#define FF_DBUS_AUTO_DESTROY_DATA __attribute__((__cleanup__(ffDBusDestroyData)))
#endif // FF_HAVE_DBUS
================================================
FILE: src/common/debug.h
================================================
#pragma once
#include "fastfetch.h"
#include "common/time.h"
static inline const char* ffFindFileName(const char* file)
{
const char* lastSlash = __builtin_strrchr(file, '/');
#ifdef _WIN32
if (lastSlash == NULL)
lastSlash = __builtin_strrchr(file, '\\');
#endif
if (lastSlash != NULL)
return lastSlash + 1;
return file;
}
#ifndef NDEBUG
#define FF_DEBUG_PRINT(file_, line_, format_, ...) \
do { \
if (instance.config.display.debugMode) \
fprintf(stderr, "[%s%4d, %s] " format_ "\n", ffFindFileName(file_), line_, ffTimeToTimeStr(ffTimeGetNow()), ##__VA_ARGS__); \
} while (0)
#else
#define FF_DEBUG_PRINT(file_, line_, format_, ...) \
do { } while (0)
#endif
#define FF_DEBUG(format, ...) FF_DEBUG_PRINT(__FILE__, __LINE__, format, ##__VA_ARGS__)
#if _WIN32
const char* ffDebugWin32Error(unsigned long errorCode);
const char* ffDebugNtStatus(NTSTATUS status);
#endif
================================================
FILE: src/common/duration.h
================================================
#pragma once
#include "fastfetch.h"
void ffDurationAppendNum(uint64_t totalSeconds, FFstrbuf* result);
================================================
FILE: src/common/edidHelper.h
================================================
#pragma once
#include
#include "common/FFstrbuf.h"
void ffEdidGetVendorAndModel(const uint8_t edid[128], FFstrbuf* result);
bool ffEdidGetName(const uint8_t edid[128], FFstrbuf* name);
void ffEdidGetPreferredResolutionAndRefreshRate(const uint8_t edid[128], uint32_t* width, uint32_t* height, double* refreshRate);
void ffEdidGetPhysicalResolution(const uint8_t edid[128], uint32_t* width, uint32_t* height);
void ffEdidGetPhysicalSize(const uint8_t edid[128], uint32_t* width, uint32_t* height); // in mm
void ffEdidGetSerialAndManufactureDate(const uint8_t edid[128], uint32_t* serial, uint16_t* year, uint16_t* week);
bool ffEdidGetHdrCompatible(const uint8_t* edid, uint32_t length);
bool ffEdidIsValid(const uint8_t edid[128], uint32_t length);
================================================
FILE: src/common/ffdata.h
================================================
#pragma once
#include "common/FFstrbuf.h"
typedef enum __attribute__((__packed__)) FFDataResultDocType
{
FF_RESULT_DOC_TYPE_DEFAULT = 0,
FF_RESULT_DOC_TYPE_JSON,
FF_RESULT_DOC_TYPE_CONFIG,
FF_RESULT_DOC_TYPE_CONFIG_FULL,
} FFDataResultDocType;
// FFdata aggregates configuration, generation parameters, and output state used by fastfetch.
// It holds the parsed configuration document, a mutable JSON document for results, and related metadata.
typedef struct FFdata
{
yyjson_doc* configDoc; // Parsed JSON configuration document
yyjson_mut_doc* resultDoc; // Mutable JSON document for storing results
FFstrbuf structure; // Custom output structure from command line
FFstrbuf structureDisabled; // Disabled modules in the output structure from command line
FFstrbuf genConfigPath; // Path to generate configuration file
FFDataResultDocType docType; // Type of result document
bool configLoaded;
} FFdata;
================================================
FILE: src/common/font.h
================================================
#pragma once
#include "common/FFstrbuf.h"
#include "common/FFlist.h"
typedef struct FFfont
{
FFstrbuf pretty;
FFstrbuf name;
FFstrbuf size;
FFlist styles;
} FFfont;
void ffFontInit(FFfont* font);
void ffFontInitQt(FFfont* font, const char* data);
void ffFontInitPango(FFfont* font, const char* data);
void ffFontInitValues(FFfont* font, const char* name, const char* size);
void ffFontInitXlfd(FFfont* font, const char* xlfd);
void ffFontInitXft(FFfont* font, const char* xft);
void ffFontInitMoveValues(FFfont* font, FFstrbuf* name, FFstrbuf* size, FFstrbuf* style);
void ffFontInitWithSpace(FFfont* font, const char* rawName);
void ffFontDestroy(FFfont* font);
static inline void ffFontInitCopy(FFfont* font, const char* name)
{
ffFontInitValues(font, name, NULL);
}
================================================
FILE: src/common/format.h
================================================
#pragma once
#include "common/argType.h"
typedef struct FFformatarg
{
FFArgType type;
const void* value;
const char* name; // argument name, must start with an alphabet
} FFformatarg;
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments);
#define FF_PARSE_FORMAT_STRING_CHECKED(buffer, formatstr, arguments) \
ffParseFormatString((buffer), (formatstr), sizeof(arguments) / sizeof(*arguments), (arguments));
================================================
FILE: src/common/frequency.h
================================================
#pragma once
#include "fastfetch.h"
bool ffFreqAppendNum(uint32_t mhz, FFstrbuf* result);
================================================
FILE: src/common/haiku/version.cpp
================================================
extern "C" {
#include "version.h"
}
#include
#include
bool ffGetFileVersion(const char* filePath, FFstrbuf* version)
{
BFile f(filePath, B_READ_ONLY);
if (f.InitCheck() != B_OK)
return false;
BAppFileInfo fileInfo(&f);
if (f.InitCheck() != B_OK)
return false;
version_info info;
if (fileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) != B_OK)
return false;
ffStrbufSetF(version, "%d.%d.%d", (int)info.major, (int)info.middle, (int)info.minor);
return true;
}
================================================
FILE: src/common/haiku/version.h
================================================
#include "common/FFstrbuf.h"
bool ffGetFileVersion(const char* filePath, FFstrbuf* version);
================================================
FILE: src/common/impl/FFPlatform.c
================================================
#include "FFPlatform_private.h"
#include "common/stringUtils.h"
#include "common/io.h"
#include "detection/version/version.h"
void ffPlatformInit(FFPlatform* platform)
{
ffStrbufInit(&platform->homeDir);
ffStrbufInit(&platform->cacheDir);
ffListInit(&platform->configDirs, sizeof(FFstrbuf));
ffListInit(&platform->dataDirs, sizeof(FFstrbuf));
ffStrbufInit(&platform->exePath);
ffStrbufInit(&platform->cwd);
ffStrbufInit(&platform->userName);
ffStrbufInit(&platform->fullUserName);
ffStrbufInit(&platform->hostName);
ffStrbufInit(&platform->userShell);
#ifdef _WIN32
ffStrbufInit(&platform->sid);
#endif
FFPlatformSysinfo* info = &platform->sysinfo;
ffStrbufInit(&info->name);
ffStrbufInit(&info->release);
ffStrbufInit(&info->version);
ffStrbufInit(&info->architecture);
ffPlatformInitImpl(platform);
if(info->name.length == 0)
ffStrbufSetStatic(&info->name, ffVersionResult.sysName);
if(info->architecture.length == 0)
ffStrbufSetStatic(&info->architecture, ffVersionResult.architecture);
}
void ffPlatformDestroy(FFPlatform* platform)
{
ffStrbufDestroy(&platform->homeDir);
ffStrbufDestroy(&platform->cacheDir);
FF_LIST_FOR_EACH(FFstrbuf, dir, platform->configDirs)
ffStrbufDestroy(dir);
ffListDestroy(&platform->configDirs);
FF_LIST_FOR_EACH(FFstrbuf, dir, platform->dataDirs)
ffStrbufDestroy(dir);
ffListDestroy(&platform->dataDirs);
ffStrbufDestroy(&platform->exePath);
ffStrbufDestroy(&platform->cwd);
ffStrbufDestroy(&platform->userName);
ffStrbufDestroy(&platform->hostName);
ffStrbufDestroy(&platform->userShell);
ffStrbufDestroy(&platform->fullUserName);
#ifdef _WIN32
ffStrbufDestroy(&platform->sid);
#endif
FFPlatformSysinfo* info = &platform->sysinfo;
ffStrbufDestroy(&info->architecture);
ffStrbufDestroy(&info->name);
ffStrbufDestroy(&info->release);
ffStrbufDestroy(&info->version);
}
void ffPlatformPathAddAbsolute(FFlist* dirs, const char* path)
{
if (!ffPathExists(path, FF_PATHTYPE_DIRECTORY))
return;
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateS(path);
ffStrbufEnsureEndsWithC(&buffer, '/');
if (!ffListContains(dirs, &buffer, (void*) ffStrbufEqual))
ffStrbufInitMove((FFstrbuf*) ffListAdd(dirs), &buffer);
}
void ffPlatformPathAddHome(FFlist* dirs, const FFPlatform* platform, const char* suffix)
{
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateA(64);
ffStrbufAppend(&buffer, &platform->homeDir);
ffStrbufAppendS(&buffer, suffix);
ffStrbufEnsureEndsWithC(&buffer, '/');
if (ffPathExists(buffer.chars, FF_PATHTYPE_DIRECTORY) && !ffListContains(dirs, &buffer, (void*) ffStrbufEqual))
ffStrbufInitMove((FFstrbuf*) ffListAdd(dirs), &buffer);
}
================================================
FILE: src/common/impl/FFPlatform_private.h
================================================
#pragma once
#include "common/FFPlatform.h"
void ffPlatformInitImpl(FFPlatform* platform);
void ffPlatformPathAddAbsolute(FFlist* dirs, const char* path);
void ffPlatformPathAddHome(FFlist* dirs, const FFPlatform* platform, const char* suffix);
================================================
FILE: src/common/impl/FFPlatform_unix.c
================================================
#include "FFPlatform_private.h"
#include "common/FFstrbuf.h"
#include "common/arrayUtils.h"
#include "common/stringUtils.h"
#include "common/io.h"
#include "fastfetch_config.h"
#include
#include
#include
#include
#include
#ifdef __APPLE__
#include
#include
#elif defined(__FreeBSD__) || defined(__NetBSD__)
#include
#elif defined(__OpenBSD__)
#include
#include
#include "common/path.h"
#elif defined(__HAIKU__)
#include
#include
#endif
static void getExePath(FFPlatform* platform)
{
char exePath[PATH_MAX];
#if defined(__linux__) || defined (__GNU__)
ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
if (exePathLen >= 0)
exePath[exePathLen] = '\0';
#elif defined(__APPLE__)
uint32_t exePathLen = sizeof(exePath);
if (_NSGetExecutablePath(exePath, &exePathLen) == 0)
exePathLen = (uint32_t) strlen(exePath);
else
exePathLen = 0;
#elif defined(__FreeBSD__) || defined(__NetBSD__)
size_t exePathLen = sizeof(exePath);
if(sysctl(
(int[]){CTL_KERN,
#ifdef __FreeBSD__
KERN_PROC, KERN_PROC_PATHNAME, (pid_t) platform->pid
#else
KERN_PROC_ARGS, platform->pid, KERN_PROC_PATHNAME
#endif
}, 4,
exePath, &exePathLen,
NULL, 0
) < 0)
exePathLen = 0;
else
exePathLen--; // remove terminating NUL
#elif defined(__OpenBSD__)
// OpenBSD doesn't have a reliable way to get the executable path.
// Current implementation uses argv[0], which can be easily spoofed.
// See #2195
size_t exePathLen = 0;
kvm_t* kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL);
if (kd)
{
int kpCount;
struct kinfo_proc* kp = kvm_getprocs(kd, KERN_PROC_PID, (pid_t) platform->pid, sizeof(*kp), &kpCount);
if (kp && kpCount == 1)
{
char** argv = kvm_getargv(kd, kp, 0);
if (argv && argv[0])
{
char* arg0 = argv[0];
if (arg0[0])
{
if (strchr(arg0, '/') != NULL) // likely a path (absolute or relative)
{
exePathLen = strlen(arg0);
if (exePathLen < ARRAY_SIZE(exePath))
{
memcpy(exePath, arg0, exePathLen);
exePath[exePathLen] = '\0';
}
else
exePathLen = 0;
}
else
{
FF_STRBUF_AUTO_DESTROY tmpPath = ffStrbufCreate();
if (ffFindExecutableInPath(arg0, &tmpPath) == NULL && tmpPath.length < ARRAY_SIZE(exePath))
{
memcpy(exePath, tmpPath.chars, tmpPath.length + 1);
exePathLen = tmpPath.length;
}
}
if (exePathLen > 0)
{
struct stat st;
if (stat(exePath, &st) == 0 && S_ISREG(st.st_mode))
{
int cntp;
struct kinfo_file* kf = kvm_getfiles(kd, KERN_FILE_BYPID, platform->pid, sizeof(*kf), &cntp);
if (kf)
{
int i;
for (i = 0; i < cntp; i++)
{
if (kf[i].fd_fd == KERN_FILE_TEXT)
{
// KERN_FILE_TEXT is the executable file, not a shared library, and should be unique in the list.
if (st.st_dev != (dev_t)kf[i].va_fsid || st.st_ino != (ino_t)kf[i].va_fileid)
i = -1;
break;
}
}
if (i < 0)
exePathLen = 0;
}
else
{
// If we can't get the list of open files, we can't verify that the file is actually the executable
// Assume it is
}
}
else
exePathLen = 0;
}
}
}
}
kvm_close(kd);
}
#elif defined(__sun)
ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1);
if (exePathLen >= 0)
exePath[exePathLen] = '\0';
#elif defined(__HAIKU__)
size_t exePathLen = 0;
image_info info;
int32 cookie = 0;
while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
if (info.type == B_APP_IMAGE) {
exePathLen = strlcpy(exePath, info.name, sizeof(exePath));
break;
}
}
#endif
if (exePathLen > 0)
{
ffStrbufEnsureFree(&platform->exePath, PATH_MAX);
if (realpath(exePath, platform->exePath.chars))
ffStrbufRecalculateLength(&platform->exePath);
else
ffStrbufSetNS(&platform->exePath, (uint32_t) exePathLen, exePath);
}
}
static void platformPathAddEnv(FFlist* dirs, const char* env)
{
const char* envValue = getenv(env);
if(!ffStrSet(envValue))
return;
FF_STRBUF_AUTO_DESTROY value = ffStrbufCreateA(64);
ffStrbufAppendS(&value, envValue);
uint32_t startIndex = 0;
while (startIndex < value.length)
{
uint32_t colonIndex = ffStrbufNextIndexC(&value, startIndex, ':');
value.chars[colonIndex] = '\0';
if(!ffStrSet(value.chars + startIndex))
{
startIndex = colonIndex + 1;
continue;
}
ffPlatformPathAddAbsolute(dirs, value.chars + startIndex);
startIndex = colonIndex + 1;
}
}
static void getHomeDir(FFPlatform* platform, const struct passwd* pwd)
{
const char* home = pwd ? pwd->pw_dir : getenv("HOME");
ffStrbufAppendS(&platform->homeDir, home);
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
}
static void getCacheDir(FFPlatform* platform)
{
const char* cache = getenv("XDG_CACHE_HOME");
if(ffStrSet(cache))
{
ffStrbufAppendS(&platform->cacheDir, cache);
ffStrbufEnsureEndsWithC(&platform->cacheDir, '/');
}
else
{
ffStrbufAppend(&platform->cacheDir, &platform->homeDir);
ffStrbufAppendS(&platform->cacheDir, ".cache/");
}
}
static void getConfigDirs(FFPlatform* platform)
{
// Always make sure `${XDG_CONFIG_HOME:-$HOME/.config}` is the first entry
platformPathAddEnv(&platform->configDirs, "XDG_CONFIG_HOME");
ffPlatformPathAddHome(&platform->configDirs, platform, ".config/");
#if defined(__APPLE__)
ffPlatformPathAddHome(&platform->configDirs, platform, "Library/Preferences/");
ffPlatformPathAddHome(&platform->configDirs, platform, "Library/Application Support/");
#endif
#if defined(__HAIKU__)
ffPlatformPathAddHome(&platform->configDirs, platform, "config/settings/");
#endif
ffPlatformPathAddHome(&platform->configDirs, platform, "");
platformPathAddEnv(&platform->configDirs, "XDG_CONFIG_DIRS");
#if !defined(__APPLE__)
ffPlatformPathAddAbsolute(&platform->configDirs, FASTFETCH_TARGET_DIR_ETC "/xdg/");
#endif
ffPlatformPathAddAbsolute(&platform->configDirs, FASTFETCH_TARGET_DIR_ETC "/");
ffPlatformPathAddAbsolute(&platform->configDirs, FASTFETCH_TARGET_DIR_INSTALL_SYSCONF "/");
}
static void getDataDirs(FFPlatform* platform)
{
platformPathAddEnv(&platform->dataDirs, "XDG_DATA_HOME");
ffPlatformPathAddHome(&platform->dataDirs, platform, ".local/share/");
// Add ${currentExePath}/../share
if (platform->exePath.length > 0)
{
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&platform->exePath);
ffStrbufSubstrBeforeLastC(&path, '/');
ffStrbufSubstrBeforeLastC(&path, '/');
ffStrbufAppendS(&path, "/share");
ffPlatformPathAddAbsolute(&platform->dataDirs, path.chars);
}
#ifdef __APPLE__
ffPlatformPathAddHome(&platform->dataDirs, platform, "Library/Application Support/");
#endif
ffPlatformPathAddHome(&platform->dataDirs, platform, "");
platformPathAddEnv(&platform->dataDirs, "XDG_DATA_DIRS");
#ifdef _PATH_LOCALBASE
ffPlatformPathAddAbsolute(&platform->dataDirs, _PATH_LOCALBASE "/share/");
#endif
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/local/share/");
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/share/");
}
static void getUserName(FFPlatform* platform, const struct passwd* pwd)
{
if (pwd)
{
ffStrbufSetS(&platform->userName, pwd->pw_name);
ffStrbufSetS(&platform->fullUserName, pwd->pw_gecos);
ffStrbufTrimSpace(&platform->fullUserName);
}
else
{
ffStrbufSetS(&platform->userName, getenv("USER"));
}
}
static void getHostName(FFPlatform* platform, const struct utsname* uts)
{
ffStrbufAppendS(&platform->hostName, uts->nodename);
}
static void getUserShell(FFPlatform* platform, const struct passwd* pwd)
{
const char* shell = getenv("SHELL");
if(!ffStrSet(shell) && pwd)
shell = pwd->pw_shell;
ffStrbufAppendS(&platform->userShell, shell);
}
static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts)
{
ffStrbufAppendS(&info->name, uts->sysname);
ffStrbufAppendS(&info->release, uts->release);
ffStrbufAppendS(&info->version, uts->version);
#ifdef __HAIKU__
/* historical reason */
if (ffStrEquals(uts->machine, "BePC"))
ffStrbufSetStatic(&info->architecture, "i386");
else
#endif
ffStrbufAppendS(&info->architecture, uts->machine);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__)
size_t length = sizeof(info->pageSize);
sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &info->pageSize, &length, NULL, 0);
#else
info->pageSize = (uint32_t) sysconf(_SC_PAGESIZE);
#endif
}
static void getCwd(FFPlatform* platform)
{
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL)
{
ffStrbufSetS(&platform->cwd, cwd);
ffStrbufEnsureEndsWithC(&platform->cwd, '/');
}
}
void ffPlatformInitImpl(FFPlatform* platform)
{
platform->pid = (uint32_t) getpid();
platform->uid = getuid();
struct passwd* pwd = getpwuid(platform->uid);
struct utsname uts;
if(uname(&uts) < 0)
memset(&uts, 0, sizeof(uts));
getExePath(platform);
getCwd(platform);
getHomeDir(platform, pwd);
getCacheDir(platform);
getConfigDirs(platform);
getDataDirs(platform);
getUserName(platform, pwd);
getHostName(platform, &uts);
getUserShell(platform, pwd);
getSysinfo(&platform->sysinfo, &uts);
}
================================================
FILE: src/common/impl/FFPlatform_windows.c
================================================
#include "FFPlatform_private.h"
#include "common/io.h"
#include "common/library.h"
#include "common/stringUtils.h"
#include "common/windows/unicode.h"
#include "common/windows/registry.h"
#include "common/windows/nt.h"
#include
#include
#include
#include
#define SECURITY_WIN32 1 // For secext.h
#include
static void getExePath(FFPlatform* platform)
{
wchar_t exePathW[MAX_PATH];
FF_AUTO_CLOSE_FD HANDLE hPath = CreateFileW(
ffGetPeb()->ProcessParameters->ImagePathName.Buffer,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if (hPath != INVALID_HANDLE_VALUE)
{
DWORD len = GetFinalPathNameByHandleW(hPath, exePathW, MAX_PATH, FILE_NAME_NORMALIZED);
if (len > 0 && len < MAX_PATH)
{
ffStrbufSetNWS(&platform->exePath, len, exePathW);
if (ffStrbufStartsWithS(&platform->exePath, "\\\\?\\"))
ffStrbufSubstrAfter(&platform->exePath, 3);
}
}
if (platform->exePath.length == 0)
{
PCUNICODE_STRING imagePathName = &ffGetPeb()->ProcessParameters->ImagePathName;
ffStrbufSetNWS(&platform->exePath, imagePathName->Length / sizeof(wchar_t), imagePathName->Buffer);
}
ffStrbufReplaceAllC(&platform->exePath, '\\', '/');
}
static void getHomeDir(FFPlatform* platform)
{
PWSTR pPath = NULL;
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DEFAULT, NULL, &pPath)))
{
ffStrbufSetWS(&platform->homeDir, pPath);
ffStrbufReplaceAllC(&platform->homeDir, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
}
else
{
ffStrbufSetS(&platform->homeDir, getenv("USERPROFILE"));
ffStrbufReplaceAllC(&platform->homeDir, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
}
CoTaskMemFree(pPath);
}
static void getCacheDir(FFPlatform* platform)
{
PWSTR pPath = NULL;
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_LocalAppData, KF_FLAG_DEFAULT, NULL, &pPath)))
{
ffStrbufSetWS(&platform->cacheDir, pPath);
ffStrbufReplaceAllC(&platform->cacheDir, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->cacheDir, '/');
}
else
{
ffStrbufAppend(&platform->cacheDir, &platform->homeDir);
ffStrbufAppendS(&platform->cacheDir, "AppData/Local/");
}
CoTaskMemFree(pPath);
}
static void platformPathAddKnownFolder(FFlist* dirs, REFKNOWNFOLDERID folderId)
{
PWSTR pPath = NULL;
if (SUCCEEDED(SHGetKnownFolderPath(folderId, KF_FLAG_DEFAULT, NULL, &pPath)))
{
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateWS(pPath);
CoTaskMemFree(pPath);
ffStrbufReplaceAllC(&buffer, '\\', '/');
ffStrbufEnsureEndsWithC(&buffer, '/');
if (!ffListContains(dirs, &buffer, (void*) ffStrbufEqual))
ffStrbufInitMove((FFstrbuf*) ffListAdd(dirs), &buffer);
}
}
static void platformPathAddEnvSuffix(FFlist* dirs, const char* env, const char* suffix)
{
const char* value = getenv(env);
if(!ffStrSet(value))
return;
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateA(64);
ffStrbufAppendS(&buffer, value);
ffStrbufReplaceAllC(&buffer, '\\', '/');
ffStrbufEnsureEndsWithC(&buffer, '/');
if (suffix)
{
ffStrbufAppendS(&buffer, suffix);
ffStrbufEnsureEndsWithC(&buffer, '/');
}
if (ffPathExists(buffer.chars, FF_PATHTYPE_DIRECTORY) && !ffListContains(dirs, &buffer, (void*) ffStrbufEqual))
ffStrbufInitMove((FFstrbuf*) ffListAdd(dirs), &buffer);
}
static void getConfigDirs(FFPlatform* platform)
{
if(getenv("MSYSTEM"))
{
// We are in MSYS2 / Git Bash
platformPathAddEnvSuffix(&platform->configDirs, "HOME", ".config/");
platformPathAddEnvSuffix(&platform->configDirs, "HOME", NULL);
platformPathAddEnvSuffix(&platform->configDirs, "MINGW_PREFIX", "etc");
}
ffPlatformPathAddHome(&platform->configDirs, platform, ".config/");
platformPathAddKnownFolder(&platform->configDirs, &FOLDERID_ProgramData);
platformPathAddKnownFolder(&platform->configDirs, &FOLDERID_RoamingAppData);
platformPathAddKnownFolder(&platform->configDirs, &FOLDERID_LocalAppData);
ffPlatformPathAddHome(&platform->configDirs, platform, "");
}
static void getDataDirs(FFPlatform* platform)
{
if(getenv("MSYSTEM") && getenv("HOME"))
{
// We are in MSYS2 / Git Bash
platformPathAddEnvSuffix(&platform->dataDirs, "HOME", ".local/share/");
platformPathAddEnvSuffix(&platform->dataDirs, "HOME", NULL);
platformPathAddEnvSuffix(&platform->dataDirs, "MINGW_PREFIX", "share");
}
ffPlatformPathAddHome(&platform->dataDirs, platform, ".local/share/");
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_ProgramData);
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_RoamingAppData);
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_LocalAppData);
ffPlatformPathAddHome(&platform->dataDirs, platform, "");
}
static void getUserName(FFPlatform* platform)
{
wchar_t buffer[256];
DWORD size = ARRAY_SIZE(buffer);
if (GetUserNameExW(NameDisplay, buffer, &size))
ffStrbufSetWS(&platform->fullUserName, buffer);
size = ARRAY_SIZE(buffer);
if (GetUserNameW(buffer, &size)) // GetUserNameExW(10002)?
ffStrbufSetWS(&platform->userName, buffer);
else
ffStrbufSetS(&platform->userName, getenv("USERNAME"));
alignas(TOKEN_USER) char buf[SECURITY_MAX_SID_SIZE + sizeof(TOKEN_USER)];
if (NT_SUCCESS(NtQueryInformationToken(NtCurrentProcessToken(), TokenUser, buf, sizeof(buf), &size)))
{
TOKEN_USER* tokenUser = (TOKEN_USER*) buf;
UNICODE_STRING sidString = { .Buffer = buffer, .Length = 0, .MaximumLength = sizeof(buffer) };
if (NT_SUCCESS(RtlConvertSidToUnicodeString(&sidString, tokenUser->User.Sid, FALSE)))
ffStrbufSetNWS(&platform->sid, sidString.Length / sizeof(wchar_t), sidString.Buffer);
}
}
static void getHostName(FFPlatform* platform)
{
wchar_t buffer[256];
DWORD len = ARRAY_SIZE(buffer);
if (GetComputerNameExW(ComputerNameDnsHostname, buffer, &len) && len > 0)
ffStrbufSetNWS(&platform->hostName, len, buffer);
else
{
len = ARRAY_SIZE(buffer);
if (GetComputerNameExW(ComputerNameNetBIOS, buffer, &len) && len > 0)
ffStrbufSetNWS(&platform->hostName, len, buffer);
}
}
static void getUserShell(FFPlatform* platform)
{
// Works in MSYS2
const char* userShell = getenv("SHELL");
if (userShell)
{
ffStrbufAppendS(&platform->userShell, userShell);
ffStrbufReplaceAllC(&platform->userShell, '\\', '/');
}
}
static const char* detectWine(void)
{
const char * __cdecl wine_get_version(void);
void* hntdll = ffLibraryGetModule(L"ntdll.dll");
if (!hntdll) return NULL;
FF_LIBRARY_LOAD_SYMBOL_LAZY(hntdll, wine_get_version);
if (!ffwine_get_version) return NULL;
return ffwine_get_version();
}
static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
{
FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hKey, NULL))
return;
uint32_t ubr = 0;
ffRegReadValues(hKey, 2, (FFRegValueArg[]) {
FF_ARG(ubr, L"UBR"),
FF_ARG(info->version, L"BuildLabEx"),
}, NULL);
ffStrbufSetF(&info->release,
"%u.%u.%u.%u",
(unsigned) SharedUserData->NtMajorVersion,
(unsigned) SharedUserData->NtMinorVersion,
(unsigned) SharedUserData->NtBuildNumber,
(unsigned) ubr);
const char* wineVersion = detectWine();
if (wineVersion)
ffStrbufSetF(&info->name, "Wine_%s", wineVersion);
else
ffStrbufSetStatic(&info->name, "WIN32_NT");
}
static void getSystemPageSize(FFPlatformSysinfo* info)
{
SYSTEM_BASIC_INFORMATION sbi;
if (NT_SUCCESS(NtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL)))
info->pageSize = sbi.PhysicalPageSize;
else
info->pageSize = 4096;
}
static void getSystemArchitecture(FFPlatformSysinfo* info)
{
SYSTEM_PROCESSOR_INFORMATION spi;
if (NT_SUCCESS(NtQuerySystemInformation(SystemProcessorInformation, &spi, sizeof(spi), NULL)))
{
switch (spi.ProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
ffStrbufSetStatic(&info->architecture, "x86_64");
break;
case PROCESSOR_ARCHITECTURE_IA64:
ffStrbufSetStatic(&info->architecture, "ia64");
break;
case PROCESSOR_ARCHITECTURE_INTEL:
switch (spi.ProcessorLevel)
{
case 4:
ffStrbufSetStatic(&info->architecture, "i486");
break;
case 5:
ffStrbufSetStatic(&info->architecture, "i586");
break;
case 6:
ffStrbufSetStatic(&info->architecture, "i686");
break;
default:
ffStrbufSetStatic(&info->architecture, "i386");
break;
}
break;
case PROCESSOR_ARCHITECTURE_ARM64:
ffStrbufSetStatic(&info->architecture, "aarch64");
break;
case PROCESSOR_ARCHITECTURE_ARM:
ffStrbufSetStatic(&info->architecture, "arm");
break;
case PROCESSOR_ARCHITECTURE_PPC:
ffStrbufSetStatic(&info->architecture, "ppc");
break;
case PROCESSOR_ARCHITECTURE_MIPS:
ffStrbufSetStatic(&info->architecture, "mips");
break;
case PROCESSOR_ARCHITECTURE_ALPHA:
ffStrbufSetStatic(&info->architecture, "alpha");
break;
case PROCESSOR_ARCHITECTURE_ALPHA64:
ffStrbufSetStatic(&info->architecture, "alpha64");
break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default:
ffStrbufSetStatic(&info->architecture, "unknown");
break;
}
}
}
static void getCwd(FFPlatform* platform)
{
PCURDIR cwd = &ffGetPeb()->ProcessParameters->CurrentDirectory;
ffStrbufSetNWS(&platform->cwd, cwd->DosPath.Length / sizeof(WCHAR), cwd->DosPath.Buffer);
ffStrbufReplaceAllC(&platform->cwd, '\\', '/');
ffStrbufEnsureEndsWithC(&platform->cwd, '/');
}
void ffPlatformInitImpl(FFPlatform* platform)
{
platform->pid = (uint32_t) (uintptr_t) ffGetTeb()->ClientId.UniqueProcess;
getExePath(platform);
getCwd(platform);
getHomeDir(platform);
getCacheDir(platform);
getConfigDirs(platform);
getDataDirs(platform);
getUserName(platform);
getHostName(platform);
getUserShell(platform);
getSystemReleaseAndVersion(&platform->sysinfo);
getSystemArchitecture(&platform->sysinfo);
getSystemPageSize(&platform->sysinfo);
}
================================================
FILE: src/common/impl/FFlist.c
================================================
#include "common/FFlist.h"
#include
#include
void* ffListAdd(FFlist* list)
{
if(list->length == list->capacity)
ffListReserve(list, list->capacity == 0 ? FF_LIST_DEFAULT_ALLOC : list->capacity * 2);
++list->length;
return ffListGet(list, list->length - 1);
}
bool ffListShift(FFlist* list, void* result)
{
if(list->length == 0)
return false;
memcpy(result, list->data, list->elementSize);
memmove(list->data, list->data + list->elementSize, (size_t) list->elementSize * (list->length - 1));
--list->length;
return true;
}
bool ffListPop(FFlist* list, void* result)
{
if(list->length == 0)
return false;
memcpy(result, ffListGet(list, list->length - 1), list->elementSize);
--list->length;
return true;
}
================================================
FILE: src/common/impl/FFstrbuf.c
================================================
#include "common/FFstrbuf.h"
#include "common/mallocHelper.h"
#include
#include
#include
char* CHAR_NULL_PTR = "";
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate)
{
strbuf->allocated = allocate;
if(strbuf->allocated > 0)
strbuf->chars = (char*) malloc(sizeof(char) * strbuf->allocated);
//This will set the length to zero and the null byte.
ffStrbufClear(strbuf);
}
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments)
{
assert(format != NULL);
char* buffer = NULL;
int len = vasprintf(&buffer, format, arguments);
assert(len >= 0);
ffStrbufInitMoveNS(strbuf, (uint32_t)len, buffer);
}
// Takes ownership of `heapStr`. The caller must not free `heapStr` after calling this
// function; the memory will be managed and freed via the associated FFstrbuf.
void ffStrbufInitMoveNS(FFstrbuf* strbuf, uint32_t length, char* heapStr)
{
assert(heapStr != NULL);
strbuf->length = length;
size_t allocSize = ffMallocUsableSize(heapStr);
if (allocSize == 0)
allocSize = length + 1;
else if (allocSize > UINT32_MAX)
allocSize = UINT32_MAX;
strbuf->allocated = (uint32_t) allocSize;
strbuf->chars = heapStr;
}
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
{
if(ffStrbufGetFree(strbuf) >= free && !(strbuf->allocated == 0 && strbuf->length > 0))
return;
uint32_t allocate = strbuf->allocated;
if(allocate < FASTFETCH_STRBUF_DEFAULT_ALLOC)
allocate = FASTFETCH_STRBUF_DEFAULT_ALLOC;
while((strbuf->length + free + 1) > allocate) // + 1 for the null byte
allocate *= 2;
if(strbuf->allocated == 0)
{
char* newbuf = malloc(sizeof(*strbuf->chars) * allocate);
if(strbuf->length == 0)
*newbuf = '\0';
else
memcpy(newbuf, strbuf->chars, strbuf->length + 1);
strbuf->chars = newbuf;
}
else
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * allocate);
strbuf->allocated = allocate;
}
// Ensure that at least `free` bytes are available in the buffer besides the current length
// for an empty buffer, free + 1 length memory will be allocated(+1 for the NUL)
void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free)
{
uint32_t oldFree = ffStrbufGetFree(strbuf);
if (oldFree >= free && !(strbuf->allocated == 0 && strbuf->length > 0))
return;
uint32_t newCap = strbuf->allocated + (free - oldFree);
if(strbuf->allocated == 0)
{
newCap += strbuf->length + 1;
char* newbuf = malloc(sizeof(*strbuf->chars) * newCap);
if(strbuf->length == 0)
*newbuf = '\0';
else
memcpy(newbuf, strbuf->chars, strbuf->length + 1);
strbuf->chars = newbuf;
}
else
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * newCap);
strbuf->allocated = newCap;
}
void ffStrbufClear(FFstrbuf* strbuf)
{
assert(strbuf != NULL);
if(strbuf->allocated == 0)
strbuf->chars = CHAR_NULL_PTR;
else
strbuf->chars[0] = '\0';
strbuf->length = 0;
}
void ffStrbufAppendC(FFstrbuf* strbuf, char c)
{
ffStrbufEnsureFree(strbuf, 1);
strbuf->chars[strbuf->length++] = c;
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendNC(FFstrbuf* strbuf, uint32_t num, char c)
{
if (num == 0) return;
ffStrbufEnsureFree(strbuf, num);
memset(&strbuf->chars[strbuf->length], c, num);
strbuf->length += num;
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendNS(FFstrbuf* strbuf, uint32_t length, const char* value)
{
if(value == NULL || length == 0)
return;
ffStrbufEnsureFree(strbuf, length);
memcpy(&strbuf->chars[strbuf->length], value, length);
strbuf->length += length;
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendTransformS(FFstrbuf* strbuf, const char* value, int(*transformFunc)(int))
{
if(value == NULL)
return;
//Ensure capacity > 0 or the modification below will fail
uint32_t length = (uint32_t) strlen(value);
if(length == 0)
return;
ffStrbufEnsureFree(strbuf, length);
for(uint32_t i = 0; value[i] != '\0'; i++)
{
strbuf->chars[strbuf->length++] = (char) transformFunc(value[i]);
}
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments)
{
assert(format != NULL);
va_list copy;
va_copy(copy, arguments);
uint32_t free = ffStrbufGetFree(strbuf);
int written = vsnprintf(strbuf->chars + strbuf->length, strbuf->allocated > 0 ? free + 1 : 0, format, arguments);
if(written > 0 && (uint32_t) written > free)
{
ffStrbufEnsureFree(strbuf, (uint32_t) written);
written = vsnprintf(strbuf->chars + strbuf->length, (uint32_t) written + 1, format, copy);
}
va_end(copy);
if(written > 0)
strbuf->length += (uint32_t) written;
}
const char* ffStrbufAppendSUntilC(FFstrbuf* strbuf, const char* value, char until)
{
if(value == NULL)
return NULL;
const char* end = strchr(value, until);
if(end == NULL)
ffStrbufAppendS(strbuf, value);
else
ffStrbufAppendNS(strbuf, (uint32_t) (end - value), value);
return end;
}
void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...)
{
assert(format != NULL);
va_list arguments;
va_start(arguments, format);
if(strbuf->allocated == 0) {
ffStrbufInitVF(strbuf, format, arguments);
va_end(arguments);
return;
}
ffStrbufClear(strbuf);
ffStrbufAppendVF(strbuf, format, arguments);
va_end(arguments);
}
void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...)
{
assert(format != NULL);
va_list arguments;
va_start(arguments, format);
ffStrbufAppendVF(strbuf, format, arguments);
va_end(arguments);
}
void ffStrbufPrependNS(FFstrbuf* strbuf, uint32_t length, const char* value)
{
if(value == NULL || length == 0)
return;
ffStrbufEnsureFree(strbuf, length);
memmove(strbuf->chars + length, strbuf->chars, strbuf->length + 1); // + 1 for the null byte
memcpy(strbuf->chars, value, length);
strbuf->length += length;
}
void ffStrbufPrependC(FFstrbuf* strbuf, char c)
{
ffStrbufEnsureFree(strbuf, 1);
memmove(strbuf->chars + 1, strbuf->chars, strbuf->length + 1); // + 1 for the null byte
strbuf->chars[0] = c;
strbuf->length += 1;
}
void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value)
{
assert(strbuf != NULL);
if (length == 0)
{
ffStrbufClear(strbuf);
return;
}
assert(value != NULL);
if (strbuf->allocated < length + 1)
{
if (strbuf->allocated > 0)
free(strbuf->chars);
strbuf->allocated = length + 1;
strbuf->chars = malloc(sizeof(char) * strbuf->allocated);
}
memcpy(strbuf->chars, value, length);
strbuf->length = length;
strbuf->chars[length] = '\0';
}
void ffStrbufSet(FFstrbuf* strbuf, const FFstrbuf* value)
{
assert(value && value != strbuf);
if (value->length == 0)
{
ffStrbufClear(strbuf);
return;
}
if (value->allocated == 0) // static string
{
if (strbuf->allocated != 0)
{
free(strbuf->chars);
strbuf->allocated = 0;
}
strbuf->chars = value->chars;
strbuf->length = value->length;
return;
}
ffStrbufSetNS(strbuf, value->length, value->chars);
}
void ffStrbufTrimLeft(FFstrbuf* strbuf, char c)
{
if(strbuf->length == 0)
return;
uint32_t index = 0;
while(index < strbuf->length && strbuf->chars[index] == c)
++index;
if(index == 0)
return;
if(strbuf->allocated == 0)
{
//static string
strbuf->length -= index;
strbuf->chars += index;
return;
}
memmove(strbuf->chars, strbuf->chars + index, strbuf->length - index);
strbuf->length -= index;
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufTrimRight(FFstrbuf* strbuf, char c)
{
if (strbuf->length == 0)
return;
if (!ffStrbufEndsWithC(strbuf, c))
return;
do
--strbuf->length;
while (ffStrbufEndsWithC(strbuf, c));
if (strbuf->allocated == 0)
{
//static string
ffStrbufInitNS(strbuf, strbuf->length, strbuf->chars);
return;
}
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufTrimLeftSpace(FFstrbuf* strbuf)
{
if(strbuf->length == 0)
return;
uint32_t index = 0;
while(index < strbuf->length && isspace(strbuf->chars[index]))
++index;
if(index == 0)
return;
if(strbuf->allocated == 0)
{
//static string
strbuf->length -= index;
strbuf->chars += index;
return;
}
memmove(strbuf->chars, strbuf->chars + index, strbuf->length - index);
strbuf->length -= index;
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufTrimRightSpace(FFstrbuf* strbuf)
{
if (strbuf->length == 0)
return;
if (!ffStrbufEndsWithFn(strbuf, isspace))
return;
do
--strbuf->length;
while (ffStrbufEndsWithFn(strbuf, isspace));
if (strbuf->allocated == 0)
{
//static string
ffStrbufInitNS(strbuf, strbuf->length, strbuf->chars);
return;
}
strbuf->chars[strbuf->length] = '\0';
}
bool ffStrbufRemoveSubstr(FFstrbuf* strbuf, uint32_t startIndex, uint32_t endIndex)
{
if(startIndex > strbuf->length || startIndex >= endIndex)
return false;
if(endIndex > strbuf->length)
{
ffStrbufSubstrBefore(strbuf, startIndex);
return true;
}
ffStrbufEnsureFree(strbuf, 0);
memmove(strbuf->chars + startIndex, strbuf->chars + endIndex, strbuf->length - endIndex);
strbuf->length -= (endIndex - startIndex);
strbuf->chars[strbuf->length] = '\0';
return true;
}
void ffStrbufRemoveS(FFstrbuf* strbuf, const char* str)
{
uint32_t stringLength = (uint32_t) strlen(str);
for(uint32_t i = ffStrbufNextIndexS(strbuf, 0, str); i < strbuf->length; i = ffStrbufNextIndexS(strbuf, i, str))
ffStrbufRemoveSubstr(strbuf, i, i + stringLength);
}
void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, const char* strings[])
{
for(uint32_t i = 0; i < numStrings; i++)
ffStrbufRemoveS(strbuf, strings[i]);
}
uint32_t ffStrbufNextIndexC(const FFstrbuf* strbuf, uint32_t start, char c)
{
assert(start <= strbuf->length);
const char* ptr = (const char*)memchr(strbuf->chars + start, c, strbuf->length - start);
return ptr ? (uint32_t)(ptr - strbuf->chars) : strbuf->length;
}
uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t start, const char* str)
{
assert(start <= strbuf->length);
const char* ptr = strstr(strbuf->chars + start, str);
return ptr ? (uint32_t)(ptr - strbuf->chars) : strbuf->length;
}
uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c)
{
assert(start <= strbuf->length);
//We need to loop one higher than the actual index, because uint32_t is guaranteed to be >= 0, so this statement would always be true
for(uint32_t i = start + 1; i > 0; i--)
{
if(strbuf->chars[i - 1] == c)
return i - 1;
}
return strbuf->length;
}
void ffStrbufReplaceAllC(FFstrbuf* strbuf, char find, char replace)
{
if (strbuf->length == 0)
return;
ffStrbufEnsureFree(strbuf, 0);
for (
char *current_pos = memchr(strbuf->chars, find, strbuf->length);
current_pos;
current_pos = memchr(
current_pos + 1,
find,
strbuf->length - (uint32_t)(current_pos + 1 - strbuf->chars)
)
)
*current_pos = replace;
}
bool ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index)
{
if(strbuf->length <= index)
return false;
if(strbuf->allocated == 0)
{
//static string
if (index < strbuf->length)
ffStrbufInitNS(strbuf, index, strbuf->chars);
return true;
}
strbuf->length = index;
strbuf->chars[strbuf->length] = '\0';
return true;
}
bool ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index)
{
if(index >= strbuf->length)
{
ffStrbufClear(strbuf);
return true;
}
if(strbuf->allocated == 0)
{
//static string
strbuf->length -= index + 1;
strbuf->chars += index + 1;
return true;
}
memmove(strbuf->chars, strbuf->chars + index + 1, strbuf->length - index - 1);
strbuf->length -= (index + 1);
strbuf->chars[strbuf->length] = '\0';
return true;
}
bool ffStrbufSubstrAfterFirstC(FFstrbuf* strbuf, char c)
{
uint32_t index = ffStrbufFirstIndexC(strbuf, c);
if(index >= strbuf->length)
return false;
ffStrbufSubstrAfter(strbuf, index);
return true;
}
bool ffStrbufSubstrAfterFirstS(FFstrbuf* strbuf, const char* str)
{
if(*str == '\0')
return false;
uint32_t index = ffStrbufFirstIndexS(strbuf, str) + (uint32_t) strlen(str) - 1; // -1, because firstIndexS is already pointing to str[0], we want to add only the remaining length
if(index >= strbuf->length)
return false;
ffStrbufSubstrAfter(strbuf, index);
return true;
}
bool ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, char c)
{
uint32_t index = ffStrbufLastIndexC(strbuf, c);
if(index >= strbuf->length)
return false;
ffStrbufSubstrAfter(strbuf, index);
return true;
}
bool ffStrbufSubstr(FFstrbuf* strbuf, uint32_t start, uint32_t end)
{
if (__builtin_expect(start >= end, false))
{
ffStrbufClear(strbuf);
return false;
}
if (__builtin_expect(start == 0, false)) return ffStrbufSubstrBefore(strbuf, end);
if (__builtin_expect(end >= strbuf->length, false)) return ffStrbufSubstrAfter(strbuf, start - 1);
uint32_t len = end - start;
ffStrbufEnsureFixedLengthFree(strbuf, len); // In case of static string
memmove(strbuf->chars, strbuf->chars + start, len);
strbuf->length = len;
strbuf->chars[len] = '\0';
return true;
}
uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c)
{
uint32_t result = 0;
for(uint32_t i = 0; i < strbuf->length; i++)
{
if(strbuf->chars[i] == c)
result++;
}
return result;
}
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end)
{
uint32_t endLength = (uint32_t) strlen(end);
if(ffStrbufEndsWithIgnCaseNS(strbuf, endLength, end))
{
ffStrbufSubstrBefore(strbuf, strbuf->length - endLength);
return true;
}
return false;
}
bool ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c)
{
if(ffStrbufEndsWithC(strbuf, c))
return false;
ffStrbufAppendC(strbuf, c);
return true;
}
void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file)
{
fwrite(strbuf->chars, sizeof(*strbuf->chars), strbuf->length, file);
}
void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file)
{
ffStrbufWriteTo(strbuf, file);
fputc('\n', file);
}
double ffStrbufToDouble(const FFstrbuf* strbuf, double defaultValue)
{
char* str_end;
double result = strtod(strbuf->chars, &str_end);
return str_end == strbuf->chars ? defaultValue : result;
}
uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue)
{
char* str_end;
unsigned long long result = strtoull(strbuf->chars, &str_end, 10);
return str_end == strbuf->chars ? defaultValue : (uint64_t)result;
}
int64_t ffStrbufToSInt(const FFstrbuf* strbuf, int64_t defaultValue)
{
char* str_end;
long long result = strtoll(strbuf->chars, &str_end, 10);
return str_end == strbuf->chars ? defaultValue : (int64_t)result;
}
void ffStrbufAppendSInt(FFstrbuf* strbuf, int64_t value)
{
ffStrbufEnsureFree(strbuf, 21); // Required by yyjson_write_number
char* start = strbuf->chars + strbuf->length;
yyjson_val val = {};
unsafe_yyjson_set_sint(&val, value);
char* end = yyjson_write_number(&val, start);
assert(end != NULL);
strbuf->length += (uint32_t)(end - start);
}
void ffStrbufAppendUInt(FFstrbuf* strbuf, uint64_t value)
{
ffStrbufEnsureFree(strbuf, 21); // Required by yyjson_write_number
char* start = strbuf->chars + strbuf->length;
yyjson_val val = {};
unsafe_yyjson_set_uint(&val, value);
char* end = yyjson_write_number(&val, start);
assert(end != NULL);
strbuf->length += (uint32_t)(end - start);
}
void ffStrbufAppendDouble(FFstrbuf* strbuf, double value, int8_t precision, bool trailingZeros)
{
assert(precision <= 15); // yyjson_write_number supports up to 15 digits after the decimal point
ffStrbufEnsureFree(strbuf, 40); // Required by yyjson_write_number
char* start = strbuf->chars + strbuf->length;
if (precision == 0)
value = round(value);
yyjson_val val = {};
unsafe_yyjson_set_double(&val, value);
if (precision > 0)
unsafe_yyjson_set_fp_to_fixed(&val, precision);
// Write at most digits after the decimal point; doesn't append trailing zeros
char* end = yyjson_write_number(&val, start);
assert(end > start);
strbuf->length += (uint32_t)(end - start);
if (__builtin_expect(value > 1e21 || value < -1e21, false))
{
// If the value is too large, yyjson_write_number will write it in scientific notation
return;
}
if (trailingZeros)
{
if (precision > 1)
{
for (char* p = end - 1; *p != '.' && p > start; --p)
--precision;
if (precision > 0)
ffStrbufAppendNC(strbuf, (uint32_t) precision, '0');
}
else if (precision == 0 || (precision < 0 && end[-1] == '0'))
{
goto removeDecimalPoint;
}
}
else
{
if (end[-1] == '0')
{
removeDecimalPoint:
// yyjson always appends ".0" to make it a float point number. We need to remove it
strbuf->length -= 2;
strbuf->chars[strbuf->length] = '\0';
}
}
}
void ffStrbufUpperCase(FFstrbuf* strbuf)
{
for (uint32_t i = 0; i < strbuf->length; ++i)
strbuf->chars[i] = (char) toupper(strbuf->chars[i]);
}
void ffStrbufLowerCase(FFstrbuf* strbuf)
{
for (uint32_t i = 0; i < strbuf->length; ++i)
strbuf->chars[i] = (char) tolower(strbuf->chars[i]);
}
void ffStrbufInsertNC(FFstrbuf* strbuf, uint32_t index, uint32_t num, char c)
{
if(num == 0) return;
if (index >= strbuf->length)
index = strbuf->length;
ffStrbufEnsureFree(strbuf, num);
memmove(strbuf->chars + index + num, strbuf->chars + index, strbuf->length - index + 1);
memset(&strbuf->chars[index], c, num);
strbuf->length += num;
}
bool ffStrbufGetdelim(char** lineptr, size_t* n, char delimiter, FFstrbuf* buffer)
{
assert(lineptr && n && buffer);
assert(buffer->allocated > 0 || (buffer->allocated == 0 && buffer->length == 0));
assert(!*lineptr || (*lineptr >= buffer->chars && *lineptr <= buffer->chars + buffer->length));
const char* pBufferEnd = buffer->chars + buffer->length;
if (!*lineptr)
*lineptr = buffer->chars;
else
{
*lineptr += *n;
if (*lineptr >= pBufferEnd) // non-empty last line
return false;
**lineptr = delimiter;
++*lineptr;
}
if (*lineptr >= pBufferEnd) // empty last line
return false;
size_t remaining = (size_t) (pBufferEnd - *lineptr);
char* ending = memchr(*lineptr, delimiter, remaining);
if (ending)
{
*n = (size_t) (ending - *lineptr);
*ending = '\0';
}
else
*n = remaining;
return true;
}
void ffStrbufGetdelimRestore(char** lineptr, size_t* n, char delimiter, FFstrbuf* buffer)
{
assert(buffer && lineptr && n);
assert(buffer->allocated > 0 || (buffer->allocated == 0 && buffer->length == 0));
assert(!*lineptr || (*lineptr >= buffer->chars && *lineptr <= buffer->chars + buffer->length));
if (!*lineptr)
return;
*lineptr += *n;
if (*lineptr < buffer->chars + buffer->length)
**lineptr = delimiter;
}
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf)
{
if (strbuf->allocated == 0) return false; // Doesn't work with static strings
bool changed = false;
for (uint32_t i = 0; i < strbuf->length; i++)
{
if (strbuf->chars[i] != ' ') continue;
i++;
uint32_t j = i;
for (; j < strbuf->length && strbuf->chars[j] == ' '; j++);
if (j == i) continue;
memmove(&strbuf->chars[i], &strbuf->chars[j], strbuf->length - j + 1);
strbuf->length -= j - i;
changed = true;
}
return changed;
}
/// @brief Check if a separated string (comp) contains a substring (strbuf).
/// @param strbuf The substring to check.
/// @param compLength The length of the separated string to check.
/// @param comp The separated string to check.
/// @param separator The separator character.
bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator)
{
if (strbuf->length == 0)
return true;
if (compLength == 0)
return false;
for (const char* p = comp; p < comp + compLength;)
{
const char* colon = memchr(p, separator, compLength);
if (colon == NULL)
return strcmp(strbuf->chars, p) == 0;
uint32_t substrLength = (uint32_t) (colon - p);
if (strbuf->length == substrLength && memcmp(strbuf->chars, p, substrLength) == 0)
return true;
p = colon + 1;
}
return false;
}
/// @brief Case insensitive version of ffStrbufMatchSeparatedNS.
bool ffStrbufMatchSeparatedIgnCaseNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator)
{
if (strbuf->length == 0)
return true;
if (compLength == 0)
return false;
for (const char* p = comp; p < comp + compLength;)
{
const char* colon = memchr(p, separator, compLength);
if (colon == NULL)
return strcasecmp(strbuf->chars, p) == 0;
uint32_t substrLength = (uint32_t) (colon - p);
if (strbuf->length == substrLength && strncasecmp(strbuf->chars, p, substrLength) == 0)
return true;
p = colon + 1;
}
return false;
}
int ffStrbufAppendUtf32CodePoint(FFstrbuf* strbuf, uint32_t codepoint)
{
if (codepoint <= 0x7F) {
ffStrbufAppendC(strbuf, (char)codepoint);
return 1;
} else if (codepoint <= 0x7FF) {
ffStrbufAppendNS(strbuf, 2, (char[]){
(char) (0xC0 | (codepoint >> 6)),
(char) (0x80 | (codepoint & 0x3F))
});
return 2;
} else if (codepoint <= 0xFFFF) {
ffStrbufAppendNS(strbuf, 3, (char[]){
(char) (0xE0 | (codepoint >> 12)),
(char) (0x80 | ((codepoint >> 6) & 0x3F)),
(char) (0x80 | (codepoint & 0x3F))
});
return 3;
} else if (codepoint <= 0x10FFFF) {
ffStrbufAppendNS(strbuf, 4, (char[]){
(char) (0xF0 | (codepoint >> 18)),
(char) (0x80 | ((codepoint >> 12) & 0x3F)),
(char) (0x80 | ((codepoint >> 6) & 0x3F)),
(char) (0x80 | (codepoint & 0x3F))
});
return 4;
}
ffStrbufAppendS(strbuf, "�"); // U+FFFD REPLACEMENT CHARACTER
return 1;
}
/// @brief Check if a separated string (strbuf) contains a substring (comp).
/// @param strbuf The separated to check.
/// @param compLength The length of the separated string to check.
/// @param comp The substring to check.
/// @param separator The separator character.
bool ffStrbufSeparatedContainNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator)
{
uint32_t startIndex = 0;
while(startIndex < strbuf->length)
{
uint32_t colonIndex = ffStrbufNextIndexC(strbuf, startIndex, separator);
uint32_t folderLength = colonIndex - startIndex;
if (folderLength == compLength && memcmp(strbuf->chars + startIndex, comp, compLength) == 0)
return true;
startIndex = colonIndex + 1;
}
return false;
}
bool ffStrbufSeparatedContainIgnCaseNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator)
{
uint32_t startIndex = 0;
while(startIndex < strbuf->length)
{
uint32_t colonIndex = ffStrbufNextIndexC(strbuf, startIndex, separator);
uint32_t folderLength = colonIndex - startIndex;
if (folderLength == compLength && strncasecmp(strbuf->chars + startIndex, comp, compLength) == 0)
return true;
startIndex = colonIndex + 1;
}
return false;
}
================================================
FILE: src/common/impl/base64.c
================================================
#include "common/base64.h"
// https://github.com/kostya/benchmarks/blob/master/base64/test-nolib.c#L145
void ffBase64EncodeRaw(uint32_t size, const char *str, uint32_t *out_size, char *output)
{
static const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *out = output;
const char *ends = str + (size - size % 3);
while (str != ends)
{
uint32_t n = __builtin_bswap32(*(uint32_t *)str);
*out++ = chars[(n >> 26) & 63];
*out++ = chars[(n >> 20) & 63];
*out++ = chars[(n >> 14) & 63];
*out++ = chars[(n >> 8) & 63];
str += 3;
}
if (size % 3 == 1)
{
uint64_t n = (uint64_t)*str << 16;
*out++ = chars[(n >> 18) & 63];
*out++ = chars[(n >> 12) & 63];
*out++ = '=';
*out++ = '=';
}
else if (size % 3 == 2)
{
uint64_t n = (uint64_t)*str++ << 16;
n |= (uint64_t)*str << 8;
*out++ = chars[(n >> 18) & 63];
*out++ = chars[(n >> 12) & 63];
*out++ = chars[(n >> 6) & 63];
*out++ = '=';
}
*out = '\0';
*out_size = (uint32_t)(out - output);
}
static uint8_t decode_table[256];
void init_decode_table()
{
uint8_t ch = 0;
do
{
int32_t code = -1;
if (ch >= 'A' && ch <= 'Z')
code = ch - 0x41;
if (ch >= 'a' && ch <= 'z')
code = ch - 0x47;
if (ch >= '0' && ch <= '9')
code = ch + 0x04;
if (ch == '+' || ch == '-')
code = 0x3E;
if (ch == '/' || ch == '_')
code = 0x3F;
decode_table[ch] = (uint8_t) code;
} while (ch++ < 0xFF);
}
#define next_char(x) uint8_t x = decode_table[(uint8_t) *str++];
bool ffBase64DecodeRaw(uint32_t size, const char *str, uint32_t *out_size, char *output)
{
if (*(uint64_t*) decode_table == 0)
init_decode_table();
char *out = output;
while (size > 0 && (str[size - 1] == '\n' || str[size - 1] == '\r' || str[size - 1] == '='))
size--;
const char *ends = str + size - 4;
while (true)
{
if (str > ends)
break;
while (*str == '\n' || *str == '\r')
str++;
if (str > ends)
break;
next_char(a);
next_char(b);
next_char(c);
next_char(d);
*out++ = (char)(a << 2 | b >> 4);
*out++ = (char)(b << 4 | c >> 2);
*out++ = (char)(c << 6 | d >> 0);
}
uint8_t mod = (uint8_t) (ends - str + 4) % 4;
if (mod == 2)
{
next_char(a);
next_char(b);
*out++ = (char)(a << 2 | b >> 4);
}
else if (mod == 3)
{
next_char(a);
next_char(b);
next_char(c);
*out++ = (char)(a << 2 | b >> 4);
*out++ = (char)(b << 4 | c >> 2);
}
*out = '\0';
*out_size = (uint32_t) (out - output);
return true;
}
================================================
FILE: src/common/impl/binary_apple.c
================================================
#include "common/binary.h"
#include "common/io.h"
#include "common/stringUtils.h"
#include "common/mallocHelper.h"
#include
#include
#include
#include
#include
#include
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // swap_fat_arch
// Ref: https://github.com/AlexDenisov/segment_dumper/blob/master/main.c
/**
* Helper function to read data from a file at a specific offset
*/
static inline bool readData(FILE *objFile, void *buf, size_t size, off_t offset)
{
fseek(objFile, offset, SEEK_SET);
return fread(buf, 1, size, objFile) == size;
}
/**
* Handles a Mach-O section by extracting strings from the __cstring section
*
* @param objFile File handle to the Mach-O object file
* @param name Section name to check
* @param offset Offset of the section in the file
* @param size Size of the section
* @param cb Callback function to process strings
* @param userdata User data for the callback
* @param minLength Minimum string length to extract
*
* @return true to continue processing, false to stop
*/
static bool handleMachSection(FILE *objFile, const char *name, off_t offset, size_t size, bool (*cb)(const char *str, uint32_t len, void *userdata), void *userdata, uint32_t minLength)
{
if (!ffStrEquals(name, "__cstring")) return true;
FF_AUTO_FREE char* data = (char*) malloc(size);
if (!readData(objFile, data, size, offset))
return true;
for (size_t off = 0; off < size; ++off)
{
const char* p = (const char*) data + off;
if (*p == '\0') continue;
uint32_t len = (uint32_t) strlen(p);
if (len < minLength) continue;
if (*p >= ' ' && *p <= '~') // Ignore control characters
{
if (!cb(p, len, userdata)) return false;
}
off += len;
}
return true;
}
/**
* Processes a Mach-O header (32-bit or 64-bit)
*
* This function parses the load commands in a Mach-O header, looking for
* LC_SEGMENT or LC_SEGMENT_64 commands that contain the __TEXT segment.
* It then processes the sections within that segment to extract strings.
*
* @param objFile File handle to the Mach-O object file
* @param offset Offset of the Mach header in the file
* @param is_64 Whether this is a 64-bit Mach-O header
* @param cb Callback function to process strings
* @param userdata User data for the callback
* @param minLength Minimum string length to extract
*
* @return NULL on success, error message on failure
*/
static const char* dumpMachHeader(FILE *objFile, off_t offset, bool is_64, bool (*cb)(const char *str, uint32_t len, void *userdata), void *userdata, uint32_t minLength)
{
uint32_t ncmds;
off_t loadCommandsOffset = offset;
if (is_64)
{
struct mach_header_64 header;
if (!readData(objFile, &header, sizeof(header), offset))
return "read mach header failed";
ncmds = header.ncmds;
loadCommandsOffset += sizeof(header);
}
else
{
struct mach_header header;
if (!readData(objFile, &header, sizeof(header), offset))
return "read mach header failed";
ncmds = header.ncmds;
loadCommandsOffset += sizeof(header);
}
off_t commandOffset = loadCommandsOffset;
struct load_command cmd = {};
for (uint32_t i = 0U; i < ncmds; i++, commandOffset += cmd.cmdsize)
{
if (!readData(objFile, &cmd, sizeof(cmd), commandOffset))
continue;
if (cmd.cmd == LC_SEGMENT_64)
{
struct segment_command_64 segment;
if (!readData(objFile, &segment, sizeof(segment), commandOffset))
continue;
if (!ffStrEquals(segment.segname, "__TEXT")) continue;
for (uint32_t j = 0U; j < segment.nsects; j++)
{
struct section_64 section;
if (!readData(objFile, §ion, sizeof(section), (off_t) ((size_t) commandOffset + sizeof(segment) + j * sizeof(section))))
continue;
if (!handleMachSection(objFile, section.sectname, section.offset, section.size, cb, userdata, minLength))
return NULL;
}
}
else if (cmd.cmd == LC_SEGMENT)
{
struct segment_command segment;
if (!readData(objFile, &segment, sizeof(segment), commandOffset))
continue;
if (!ffStrEquals(segment.segname, "__TEXT")) continue;
for (uint32_t j = 0; j < segment.nsects; j++)
{
struct section section;
if (!readData(objFile, §ion, sizeof(section), (off_t) ((size_t) commandOffset + sizeof(segment) + j * sizeof(section))))
continue;
if (!handleMachSection(objFile, section.sectname, section.offset, section.size, cb, userdata, minLength))
return NULL;
}
}
return NULL;
}
return NULL;
}
/**
* Processes a Fat binary header (Universal binary)
*
* This function handles the fat header of a universal binary, which can contain
* multiple Mach-O binaries for different architectures. It extracts and processes
* each embedded Mach-O file.
*
* @param objFile File handle to the universal binary
* @param cb Callback function to process strings
* @param userdata User data for the callback
* @param minLength Minimum string length to extract
*
* @return NULL on success, error message on failure
*/
static const char* dumpFatHeader(FILE *objFile, bool (*cb)(const char *str, uint32_t len, void *userdata), void *userdata, uint32_t minLength)
{
struct fat_header header;
if (!readData(objFile, &header, sizeof(header), 0))
return "read fat header failed";
bool needSwap = header.magic == FAT_CIGAM || header.magic == FAT_CIGAM_64;
if (needSwap) swap_fat_header(&header, NX_UnknownByteOrder);
for (uint32_t i = 0U; i < header.nfat_arch; i++)
{
off_t machHeaderOffset = 0;
if (header.magic == FAT_MAGIC)
{
struct fat_arch arch;
if (!readData(objFile, &arch, sizeof(arch), (off_t) (sizeof(header) + i * sizeof(arch))))
continue;
if (needSwap)
swap_fat_arch(&arch, 1, NX_UnknownByteOrder);
machHeaderOffset = (off_t)arch.offset;
}
else
{
struct fat_arch_64 arch;
if (!readData(objFile, &arch, sizeof(arch), (off_t) (sizeof(header) + i * sizeof(arch))))
continue;
if (needSwap)
swap_fat_arch_64(&arch, 1, NX_UnknownByteOrder);
machHeaderOffset = (off_t)arch.offset;
}
uint32_t magic;
if (!readData(objFile, &magic, sizeof(magic), machHeaderOffset))
continue;
if (magic == MH_MAGIC_64 || magic == MH_MAGIC)
{
dumpMachHeader(objFile, machHeaderOffset, magic == MH_MAGIC_64, cb, userdata, minLength);
return NULL;
}
}
return "Unsupported fat header";
}
/**
* Extracts string literals from a Mach-O (Apple) binary file
*
* This function supports both single-architecture Mach-O files and
* universal binaries (fat binaries) containing multiple architectures.
* It locates the __cstring section in the __TEXT segment which contains
* the string literals used in the program.
*/
const char *ffBinaryExtractStrings(const char *machoFile, bool (*cb)(const char *str, uint32_t len, void *userdata), void *userdata, uint32_t minLength)
{
FF_AUTO_CLOSE_FILE FILE *objFile = fopen(machoFile, "rb");
if (objFile == NULL)
return "File could not be opened";
// Read the magic number to determine the type of binary
uint32_t magic;
if (!readData(objFile, &magic, sizeof(magic), 0))
return "read magic number failed";
// Check for supported formats
// MH_CIGAM and MH_CIGAM_64 seem to be no longer used, as `swap_mach_header` is marked as deprecated.
// However FAT_CIGAM and FAT_CIGAM_64 are still used (/usr/bin/vim).
if (magic != MH_MAGIC && magic != MH_MAGIC_64 && magic != FAT_CIGAM && magic != FAT_CIGAM_64 && magic != FAT_MAGIC && magic != FAT_MAGIC_64)
return "Unsupported format or big endian mach-o file";
// Process either a fat binary or a regular Mach-O binary
if (magic == FAT_MAGIC || magic == FAT_MAGIC_64 || magic == FAT_CIGAM || magic == FAT_CIGAM_64)
return dumpFatHeader(objFile, cb, userdata, minLength);
else
return dumpMachHeader(objFile, 0, magic == MH_MAGIC_64, cb, userdata, minLength);
}
================================================
FILE: src/common/impl/binary_linux.c
================================================
#include "common/binary.h"
#if defined(FF_HAVE_ELF) || defined(__sun) || (defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(__OpenBSD__) || defined(__NetBSD__)
#include "common/io.h"
#include "common/library.h"
#include "common/stringUtils.h"
#include // #1254
#include
/**
* Structure to hold dynamically loaded libelf function pointers
*/
struct FFElfData {
FF_LIBRARY_SYMBOL(elf_version)
FF_LIBRARY_SYMBOL(elf_begin)
FF_LIBRARY_SYMBOL(elf_getshdrstrndx)
FF_LIBRARY_SYMBOL(elf_nextscn)
FF_LIBRARY_SYMBOL(elf64_getshdr)
FF_LIBRARY_SYMBOL(elf32_getshdr)
FF_LIBRARY_SYMBOL(elf_getdata)
FF_LIBRARY_SYMBOL(elf_strptr)
FF_LIBRARY_SYMBOL(elf_end)
bool inited;
} elfData;
/**
* Extracts string literals from an ELF (Linux/Unix) binary file
*
* This function loads the libelf library dynamically, opens the ELF file,
* locates the .rodata section (which contains string literals), and
* scans it for valid strings. Each string found is passed to the
* callback function for processing.
*
* The function supports both 32-bit and 64-bit ELF formats.
*/
const char* ffBinaryExtractStrings(const char* elfFile, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength)
{
// Initialize libelf if not already done
if (!elfData.inited)
{
elfData.inited = true;
FF_LIBRARY_LOAD_MESSAGE(libelf, "libelf" FF_LIBRARY_EXTENSION, 1);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_version)
if (elfData.ffelf_version(EV_CURRENT) == EV_NONE) return "elf_version() failed";
// Load all required libelf functions
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_begin)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_getshdrstrndx)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_nextscn)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf64_getshdr)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf32_getshdr)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_getdata)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_strptr)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_end)
libelf = NULL;
}
if (elfData.ffelf_end == NULL)
return "load libelf failed";
// Open the ELF file
FF_AUTO_CLOSE_FD int fd = open(elfFile, O_RDONLY | O_CLOEXEC);
if (fd < 0) return "open() failed";
Elf* elf = elfData.ffelf_begin(fd, ELF_C_READ, NULL);
if (elf == NULL) return "elf_begin() failed";
// Get the section header string table index
size_t shstrndx = 0;
if (elfData.ffelf_getshdrstrndx(elf, &shstrndx) < 0)
{
elfData.ffelf_end(elf);
return "elf_getshdrstrndx() failed";
}
// Iterate through all sections, looking for .rodata which contains string literals
Elf_Scn* scn = NULL;
while ((scn = elfData.ffelf_nextscn(elf, scn)) != NULL)
{
// Try 64-bit section header first, then 32-bit if that fails
Elf64_Shdr* shdr64 = elfData.ffelf64_getshdr(scn);
Elf32_Shdr* shdr32 = NULL;
if (shdr64 == NULL)
{
shdr32 = elfData.ffelf32_getshdr(scn);
if (shdr32 == NULL) continue;
}
// Get the section name and check if it's .rodata
const char* name = elfData.ffelf_strptr(elf, shstrndx, shdr64 ? shdr64->sh_name : shdr32->sh_name);
if (name == NULL || !ffStrEquals(name, ".rodata")) continue;
// Get the section data
Elf_Data* data = elfData.ffelf_getdata(scn, NULL);
if (data == NULL) continue;
// Scan the section for string literals
for (size_t off = 0; off < data->d_size; ++off)
{
const char* p = (const char*) data->d_buf + off;
if (*p == '\0') continue;
uint32_t len = (uint32_t) strlen(p);
if (len < minLength) continue;
// Only process printable ASCII characters
if (*p >= ' ' && *p <= '~') // Ignore control characters
{
if (!cb(p, len, userdata)) break;
}
off += len;
}
break;
}
elfData.ffelf_end(elf);
return NULL;
}
#else
/**
* Fallback implementation when libelf is not available
*/
const char* ffBinaryExtractStrings(const char* file, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength)
{
FF_UNUSED(file, cb, userdata, minLength);
return "Fastfetch was built without libelf support";
}
#endif
================================================
FILE: src/common/impl/binary_windows.c
================================================
#include "common/binary.h"
#include "common/io.h"
#include "common/stringUtils.h"
#include "common/windows/nt.h"
#include