Author SHA1 Message Date
Claude 7920497b37 Banner: deep scarlet #c8102e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRR7XmhWoFbzJFFFqde
2026-11-06 14:00:39 +00:00
125 changed files with 29 additions and 48436 deletions

No files matched your search

-64
View File
@@ -1,64 +0,0 @@
#!/usr/bin/env bash
# nightly-pick.sh WORKFLOW...
#
# Finds the newest commit on main that has a completed run of each
# WORKFLOW (a file name in .github/workflows). It writes these lines to
# $GITHUB_OUTPUT:
#
# sha=<the commit>
# run_<workflow>=<the run ID> (for each WORKFLOW, "." and "-" as "_")
# skip=true|false (true: the nightly release has this commit)
#
# A run that is not complete is not used. Thus a run that is in progress
# does not stop the nightly release: the release uses the run before it.
# Set FORCE=true to publish again when the commit did not change.
#
# It needs GH_TOKEN and GH_REPO.
set -euo pipefail
[ $# -ge 1 ] || { echo "usage: $0 WORKFLOW..." >&2; exit 2; }
out=${GITHUB_OUTPUT:-/dev/stdout}
# the completed runs of a workflow on main (pushes and manual runs), newest first: "sha id"
runs() {
gh run list --workflow "$1" --branch main --status completed --limit 50 \
--json headSha,databaseId,event \
--jq '.[] | select(.event == "push" or .event == "workflow_dispatch") | "\(.headSha) \(.databaseId)"'
}
declare -A list
for w in "$@"; do
list[$w]=$(runs "$w")
done
sha=
while read -r s _; do
[ -n "$s" ] || continue
ok=1
for w in "$@"; do
grep -q "^$s " <<<"${list[$w]}" || { ok=0; break; }
done
if [ "$ok" = 1 ]; then sha=$s; break; fi
done <<<"${list[$1]}"
if [ -z "$sha" ]; then
echo "::error::No commit on main has a completed run of each of: $*"
exit 1
fi
echo "sha=$sha" >> "$out"
for w in "$@"; do
id=$(grep -m1 "^$sha " <<<"${list[$w]}" | cut -d' ' -f2)
echo "run_$(tr '.-' '__' <<<"$w")=$id" >> "$out"
echo "$w: run $id"
done
# (gh writes the error body of a 404 to stdout: no tag is no commit)
old=$(gh api "repos/$GH_REPO/git/ref/tags/nightly" --jq .object.sha 2>/dev/null) || old=
echo "Commit: $sha (the nightly release has: ${old:-none})"
if [ "$sha" = "$old" ] && [ "${FORCE:-false}" != true ]; then
echo "skip=true" >> "$out"
echo "No new commits on main. The nightly release does not change."
else
echo "skip=false" >> "$out"
fi
-63
View File
@@ -1,63 +0,0 @@
#!/usr/bin/env bash
# nightly-publish.sh SHA NOTES DIR
#
# Updates the "nightly" pre-release: its tag to SHA, its text from the
# file NOTES, and its files to all the files in DIR. If there is no
# release, it makes one.
#
# The script does not delete the release. If a step fails, the old
# release stays (with its old files or some new files), and the next run
# tries again.
#
# It needs GH_TOKEN and GH_REPO.
set -euo pipefail
sha=$1 notes=$2 dir=$3
shopt -s nullglob
files=("$dir"/*)
[ ${#files[@]} -gt 0 ] || { echo "::error::No files to publish in $dir"; exit 1; }
title="Nightly build ($(date -u +%Y-%m-%d), ${sha:0:7})"
# release_id: prints the ID of the "nightly" release, or nothing. (gh
# writes the error body of a 404 to stdout: on an error, print nothing.)
release_id() {
local id
id=$(gh api "repos/$GH_REPO/releases/tags/nightly" --jq .id 2>/dev/null) || id=
echo "$id"
}
# move_tag: puts the "nightly" tag at $sha, and makes the tag if it is
# not there
move_tag() {
if gh api "repos/$GH_REPO/git/ref/tags/nightly" --jq .object.sha >/dev/null 2>&1; then
gh api -X PATCH "repos/$GH_REPO/git/refs/tags/nightly" \
-f sha="$sha" -F force=true >/dev/null
else
gh api -X POST "repos/$GH_REPO/git/refs" \
-f ref=refs/tags/nightly -f sha="$sha" >/dev/null
fi
}
id=$(release_id)
if [ -z "$id" ]; then
# (no release: a new one, its tag made at $sha)
gh release create nightly "${files[@]}" \
--prerelease --latest=false --target "$sha" \
--title "$title" --notes-file "$notes"
exit 0
fi
move_tag
gh release edit nightly --prerelease --latest=false \
--title "$title" --notes-file "$notes"
gh release upload nightly "${files[@]}" --clobber
# the old files that this build did not make
keep=$(for f in "${files[@]}"; do basename "$f"; done)
gh api "repos/$GH_REPO/releases/$id/assets" --paginate --jq '.[] | "\(.id) \(.name)"' |
while read -r aid name; do
if ! grep -qxF "$name" <<<"$keep"; then
echo "Removing the old file $name"
gh api -X DELETE "repos/$GH_REPO/releases/assets/$aid"
fi
done
-26
View File
@@ -1,26 +0,0 @@
# Auto-assign new issues.
#
# This workflow starts when a person opens an issue.
# It adds the project owner (Neo-Desktop) as an assignee.
# To change the assignee, change the ASSIGNEE value below.
name: Auto-assign issues
on:
issues:
types: [opened]
permissions:
issues: write
jobs:
# Add the assignee to the issue that started this run.
assign:
runs-on: ubuntu-latest
steps:
- name: Add assignee
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSIGNEE: Neo-Desktop
REPO: ${{ github.repository }}
ISSUE: ${{ github.event.issue.number }}
run: gh issue edit "$ISSUE" --repo "$REPO" --add-assignee "$ASSIGNEE"
-429
View File
@@ -1,429 +0,0 @@
# Builds and tests the app (windows/) and the library that it uses
# (core/, ssh/): on Windows 95 to Windows 11, and on Linux and macOS over
# clang-retro MFC's portable Win32 layer (winport/)
name: Build
# The nightly release (nightly.yml) takes its files from this
# workflow's artifacts on main. Each artifact is a .tar.gz or a .zip,
# because an artifact does not keep the executable bit of a file.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
# libdmodemctl (core/) and libdmodemssh (ssh/), with no app: the
# tests, the tests with the sanitizers, and SSH against a real sshd
core:
name: Library and SSH tests (Linux)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build pkg-config
- name: Build
run: |
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build
- name: Test
run: ctest --test-dir build --output-on-failure
- name: Test with the sanitizers
run: |
cmake -S . -B build-asan -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-sanitize-recover=all"
cmake --build build-asan --target dmodemctl_test
ctest --test-dir build-asan --output-on-failure -R dmodemctl
- name: SSH against a real sshd
run: |
sudo apt-get install -y --no-install-recommends openssh-server putty-tools
sudo useradd -m dmtest
echo 'dmtest:Sesame-42' | sudo chpasswd
# a key in a file, one of PuTTY's (.ppk) and one in an agent
ssh-keygen -q -t ed25519 -N '' -f "$RUNNER_TEMP/key"
: > "$RUNNER_TEMP/empty"
puttygen -t rsa -b 2048 -o "$RUNNER_TEMP/key.ppk" --new-passphrase "$RUNNER_TEMP/empty"
ssh-keygen -q -t ecdsa -N '' -f "$RUNNER_TEMP/agentkey"
eval "$(ssh-agent -a "$RUNNER_TEMP/agent.sock")"
ssh-add "$RUNNER_TEMP/agentkey"
unset SSH_AUTH_SOCK
puttygen "$RUNNER_TEMP/key.ppk" -O public-openssh -o "$RUNNER_TEMP/ppk.pub"
cat "$RUNNER_TEMP/key.pub" "$RUNNER_TEMP/agentkey.pub" "$RUNNER_TEMP/ppk.pub" > "$RUNNER_TEMP/authorized_keys"
sudo install -d -m 700 -o dmtest ~dmtest/.ssh
sudo install -m 600 -o dmtest "$RUNNER_TEMP/authorized_keys" ~dmtest/.ssh/authorized_keys
sudo mkdir -p /run/sshd
sudo /usr/sbin/sshd -p 2222 -o ListenAddress=127.0.0.1 -o PasswordAuthentication=yes
DMODEM_SSH_TEST=127.0.0.1:2222:dmtest:Sesame-42 DMODEM_SSH_TEST_KEY="$RUNNER_TEMP/key" \
DMODEM_SSH_TEST_PPK="$RUNNER_TEMP/key.ppk" DMODEM_SSH_TEST_AGENT="$RUNNER_TEMP/agent.sock" \
build/ssh/dmodemssh_test
# Both Windows builds use clang-retro (https://clang-retro.github.io/),
# its toolchain package from its setup-toolchain action, on Linux
windows-9x:
name: Windows 95 and later, the modem built in (clang-retro, win32-picolibc)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main
id: clang-dos
- name: Packages
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y --no-install-recommends ninja-build wine wine32:i386
- name: Build
run: |
cmake -S . -B build/win9x -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake -DCLANG_RETRO_CONFIG=win32-picolibc \
-DCMAKE_CROSSCOMPILING_EMULATOR=wine
cmake --build build/win9x
- name: Test (Wine)
run: |
export WINEDEBUG=-all WINEPREFIX="$RUNNER_TEMP/wine"
wineboot -i >/dev/null 2>&1 || true
ctest --test-dir build/win9x --output-on-failure
- name: Imports (Windows 95, 98 and ME, and NT 4.0)
run: |
python3 "$CLANG_DOS/share/clang-dos/check-imports.py" build/win9x/windows/dmodem.exe
python3 "$CLANG_DOS/share/clang-dos/check-imports.py" --nt 4.0 build/win9x/windows/dmodem.exe
# (no iphlpapi.dll, which Windows 95 does not have, and no msvcrt.dll)
if "$CLANG_DOS/bin/llvm-objdump" -p build/win9x/windows/dmodem.exe |
grep -i "DLL Name: \(msvcrt\|iphlpapi\)"; then
exit 1
fi
"$CLANG_DOS/bin/llvm-nm" build/win9x/windows/dmodem.exe | grep -q dmodem_embed_start
- uses: actions/upload-artifact@v4
with:
name: dmodem-windows-9x
path: build/win9x/windows/dmodem.exe
# The app with the modem built in (external/D-Modem), on msvcrt:
# Windows 98 SE, ME, 2000 and later. (The Windows 95 build above has
# the modem too, on picolibc and libc++.)
windows-98:
name: Windows 98 SE and later, the modem built in (clang-retro, win98)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main
id: clang-dos
- name: Packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends ninja-build
- name: Build
run: |
cmake -S . -B build/win98 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake -DCLANG_RETRO_CONFIG=win98
cmake --build build/win98
- name: Imports (Windows 98 SE)
run: python3 "$CLANG_DOS/share/clang-dos/check-imports.py" build/win98/windows/dmodem.exe
- uses: actions/upload-artifact@v4
with:
name: dmodem-windows-98
path: build/win98/windows/dmodem.exe
windows:
name: Windows 7 and later (clang-retro)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main
id: clang-dos
- name: Packages
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y --no-install-recommends ninja-build wine wine32:i386
- name: Build
run: |
cmake -S . -B build/win7 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake -DCLANG_RETRO_CONFIG=win7 \
-DCMAKE_CROSSCOMPILING_EMULATOR=wine
cmake --build build/win7
- name: Test (Wine)
run: |
export WINEDEBUG=-all WINEPREFIX="$RUNNER_TEMP/wine"
wineboot -i >/dev/null 2>&1 || true
ctest --test-dir build/win7 --output-on-failure
- uses: actions/upload-artifact@v4
with:
name: dmodem-windows
path: build/win7/windows/dmodem.exe
# The Windows app for Linux and macOS (winport/), over the portable
# Win32 layer of clang-retro MFC, with the modem built in
# (external/D-Modem)
winport-linux:
name: Windows app on Linux, the modem built in (clang-retro MFC's Win32 layer)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/checkout@v4
with:
repository: clang-retro/mfc
path: mfc
submodules: recursive
- name: Packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build clang llvm libx11-dev xvfb xauth \
libusb-1.0-0-dev libasound2-dev
- name: Build
run: |
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC="$PWD/mfc" \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build --target dmodem-win32
- name: The built-in modem is in the app
run: nm build/winport/dmodem-win32 | grep -q dmodem_embed_start
- name: Smoke test (Xvfb)
run: xvfb-run -a winport/test/smoke.sh build/winport/dmodem-win32
- name: Package
run: tar -C build/winport -czf dmodem-win32-linux-x86_64.tar.gz dmodem-win32
- uses: actions/upload-artifact@v4
with:
name: dmodem-win32-linux
path: dmodem-win32-linux-x86_64.tar.gz
# arm64 for a Mac with Apple silicon, and x86_64 for an Intel Mac. The
# runner has Apple silicon: it builds the x86_64 app with
# CMAKE_OSX_ARCHITECTURES=x86_64 (winport/CMakeLists.txt).
winport-macos:
name: Windows app on macOS (${{ matrix.arch }}), the modem built in (clang-retro MFC's Win32 layer)
runs-on: macos-15
strategy:
fail-fast: false
matrix:
include:
- arch: arm64
artifact: dmodem-win32-macos
- arch: x86_64
artifact: dmodem-win32-macos-x86_64
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/checkout@v4
with:
repository: clang-retro/mfc
path: mfc
submodules: recursive
- name: Packages
run: brew install llvm
- name: Build
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC="$PWD/mfc" \
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build --target dmodem-win32 -j"$(sysctl -n hw.ncpu)"
- name: The app is for ${{ matrix.arch }} only
run: |
lipo -archs build/winport/dmodem-win32
test "$(lipo -archs build/winport/dmodem-win32)" = "${{ matrix.arch }}"
- name: The built-in modem is in the app
run: nm build/winport/dmodem-win32 | grep -q dmodem_embed_start
- name: Library tests
run: |
cmake --build build --target dmodemctl_test xfer_test -j"$(sysctl -n hw.ncpu)"
ctest --test-dir build --output-on-failure -R '^(dmodemctl|xfer)$'
- name: Package
run: tar -C build/winport -czf dmodem-win32-macos-${{ matrix.arch }}.tar.gz dmodem-win32
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: dmodem-win32-macos-${{ matrix.arch }}.tar.gz
# The app for Mac OS X 10.4 (Tiger) and later, PowerPC and Intel
# (i386), as one fat program, over the Mac OS X 10.0-10.5 port of
# clang-retro MFC (cmake/macosx-legacy.cmake). All of it builds on
# Linux: clang of clang-retro/llvm (its llvm-prebuilt release, which
# has emulated TLS for 10.4), the macosx10.4 sysroot of dos-sdk (libc++
# and Apple's MacOSX10.4u.sdk, under Apple's license), and Apple's ld64
# and ar for PowerPC (dos-sdk's scripts/build-cctools-ppc.sh, kept in
# the cache).
winport-macosx-legacy:
name: Windows app on Mac OS X 10.4 and later (PowerPC and i386), the modem built in
runs-on: ubuntu-24.04
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/checkout@v4
with:
repository: clang-retro/mfc
path: mfc
submodules: recursive
- uses: actions/checkout@v4
with:
repository: clang-retro/dos-sdk
path: dos-sdk
- name: Packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build clang automake autoconf libtool uuid-dev libssl-dev zstd
- name: clang (clang-retro/llvm, llvm-prebuilt)
run: |
asset=$(gh api repos/clang-retro/llvm/releases/tags/llvm-prebuilt --jq \
'[.assets[] | select(.name | startswith("llvm-linux-"))] | sort_by(.created_at) | last | .name')
echo "Using $asset"
gh release download llvm-prebuilt -R clang-retro/llvm -p "$asset" -O llvm.tar.zst
mkdir -p "$RUNNER_TEMP/llvm"
tar --zstd -xf llvm.tar.zst -C "$RUNNER_TEMP/llvm"
rm llvm.tar.zst
"$RUNNER_TEMP/llvm/bin/clang" --version | head -1
echo "MACOSX_LEGACY_LLVM=$RUNNER_TEMP/llvm" >> "$GITHUB_ENV"
- name: The macosx10.4 sysroot (libc++ and MacOSX10.4u.sdk)
run: |
sh dos-sdk/packaging/get-toolchain.sh -s macosx10.4 "$RUNNER_TEMP/sysroots"
echo "MACOSX_LEGACY_SYSROOT=$RUNNER_TEMP/sysroots/macosx10.4" >> "$GITHUB_ENV"
- uses: actions/cache@v4
id: cctools
with:
path: ${{ runner.temp }}/cctools-ppc
key: cctools-ppc-${{ hashFiles('dos-sdk/scripts/build-cctools-ppc.sh', 'dos-sdk/scripts/cctools-ppc-old-objects.patch') }}
- name: cctools (ld64 and ar for PowerPC)
if: steps.cctools.outputs.cache-hit != 'true'
run: |
PREFIX="$RUNNER_TEMP/cctools-ppc" SRC="$RUNNER_TEMP/cctools-port" \
sh dos-sdk/scripts/build-cctools-ppc.sh > cctools.log 2>&1 || { tail -50 cctools.log; exit 1; }
- name: Build (PowerPC and i386)
run: |
export MACOSX_LEGACY_CCTOOLS="$RUNNER_TEMP/cctools-ppc"
for arch in powerpc i386; do
cmake -S . -B build/$arch -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$PWD/cmake/macosx-legacy.cmake" \
-DMACOSX_LEGACY_ARCH=$arch -DCLANG_RETRO_MFC="$PWD/mfc" \
-DDMODEM_GUI_WINPORT=ON
cmake --build build/$arch --target dmodem-win32
done
- name: The fat program, with the built-in modem for each processor
run: |
cct="$RUNNER_TEMP/cctools-ppc/bin/powerpc-apple-darwin8-"
mkdir -p out
"${cct}lipo" -create build/powerpc/winport/dmodem-win32 build/i386/winport/dmodem-win32 \
-output out/dmodem-win32
"${cct}lipo" -info out/dmodem-win32
for arch in ppc i386; do
"${cct}lipo" out/dmodem-win32 -verify_arch $arch
"${cct}nm" -arch $arch out/dmodem-win32 | grep -q dmodem_embed_start
done
# (each part is for Mac OS X 10.4)
"${cct}otool" -arch all -l out/dmodem-win32 | grep -A2 LC_VERSION_MIN_MACOSX | grep -c "version 10.4" | grep -qx 2
- name: Package
run: tar -C out -czf dmodem-win32-macosx10.4.tar.gz dmodem-win32
- uses: actions/upload-artifact@v4
with:
name: dmodem-win32-macosx-legacy
path: dmodem-win32-macosx10.4.tar.gz
# The Windows app (windows/) on the classic Mac OS (Mac OS 9) on
# PowerPC, with the modem built in, over the Toolbox backend of
# clang-retro MFC (cmake/macos9.cmake). All of it builds on Linux:
# clang of clang-retro/llvm (llvm-prebuilt), and the C and C++
# libraries of clang-retro/mac-sdk (picolibc, GCC 15.2's libstdc++
# and LLVM's libunwind, kept in the cache).
winport-macos9:
name: Windows app on Mac OS 9 (PowerPC), the modem built in
runs-on: ubuntu-24.04
env:
GH_TOKEN: ${{ github.token }}
GCC_VERSION: 15.2.0
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/checkout@v4
with:
repository: clang-retro/mfc
path: mfc
submodules: recursive
- uses: actions/checkout@v4
with:
repository: clang-retro/mac-sdk
path: mac-sdk
- uses: actions/checkout@v4
with:
repository: clang-retro/picolibc
path: picolibc
- name: Packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build meson make zstd xz-utils
- name: clang (clang-retro/llvm, llvm-prebuilt)
run: |
asset=$(gh api repos/clang-retro/llvm/releases/tags/llvm-prebuilt --jq \
'[.assets[] | select(.name | startswith("llvm-linux-"))] | sort_by(.created_at) | last | .name')
echo "Using $asset"
echo "LLVM_ASSET=$asset" >> "$GITHUB_ENV"
gh release download llvm-prebuilt -R clang-retro/llvm -p "$asset" -O llvm.tar.zst
mkdir -p "$RUNNER_TEMP/llvm"
tar --zstd -xf llvm.tar.zst -C "$RUNNER_TEMP/llvm"
rm llvm.tar.zst
"$RUNNER_TEMP/llvm/bin/clang" --version | head -1
echo "MACOS9_LLVM=$RUNNER_TEMP/llvm" >> "$GITHUB_ENV"
echo "MACOS9_SDK=$PWD/mac-sdk" >> "$GITHUB_ENV"
echo "SDK_REV=$(git -C mac-sdk rev-parse HEAD)-$(git -C picolibc rev-parse HEAD)" >> "$GITHUB_ENV"
- uses: actions/cache@v4
id: maclibs
with:
path: mac-sdk/lib
key: mac-sdk-lib-${{ env.SDK_REV }}-${{ env.LLVM_ASSET }}-gcc${{ env.GCC_VERSION }}
- name: mac-sdk's libraries (runtime, C library, C++ library)
if: steps.maclibs.outputs.cache-hit != 'true'
run: |
# (LLVM: only compiler-rt's builtins and libunwind)
git clone -q --depth 1 --filter=blob:none --sparse \
https://github.com/clang-retro/llvm "$RUNNER_TEMP/llvm-src"
git -C "$RUNNER_TEMP/llvm-src" sparse-checkout set compiler-rt/lib/builtins libunwind
# (GCC: the release, for libstdc++)
curl -sSfL "https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" \
| tar -xJ -C "$RUNNER_TEMP"
export CLANG="$MACOS9_LLVM/bin/clang" LLVM_SRC="$RUNNER_TEMP/llvm-src"
cd mac-sdk
sh runtime/build.sh > rt.log 2>&1 || { tail -50 rt.log; exit 1; }
PICOLIBC_SRC="$GITHUB_WORKSPACE/picolibc" sh runtime/build-libc.sh > libc.log 2>&1 \
|| { tail -50 libc.log; exit 1; }
CPUS=ppc GCC_SRC="$RUNNER_TEMP/gcc-$GCC_VERSION" sh runtime/build-libstdcxx.sh > cxx.log 2>&1 \
|| { tail -50 cxx.log; exit 1; }
ls lib/ppc
- name: Build
run: |
cmake -S . -B build/os9 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$PWD/cmake/macos9.cmake" \
-DCLANG_RETRO_MFC="$PWD/mfc" \
-DDMODEM_GUI_WINPORT=ON -DDMODEM_GUI_EMBED=ON -DDMODEM_GUI_SSH=OFF
cmake --build build/os9 --target dmodem-win32
- name: Check the program
run: |
f=build/os9/winport/dmodem-win32.bin
# (MacBinary: the type APPL in the header, and the modem inside)
head -c 128 "$f" | grep -q APPL
grep -q "User-Agent" "$f"
mkdir -p out
cp "$f" out/dmodem-win32-macos9.bin
ls -l out
- uses: actions/upload-artifact@v4
with:
name: dmodem-win32-macos9
path: out/dmodem-win32-macos9.bin
@@ -1,68 +0,0 @@
# The contributor agreement (CONTRIBUTING.md): every commit in a pull
# request carries a "Signed-off-by:" line with its author's email, which
# says the author agrees to it for that commit. Merge commits are
# skipped. Pull requests opened by the repository's owner or the D-Modem
# organization's members, and by bots, are not checked. Nor are commits
# by Claude (noreply@anthropic.com) on a branch of this repository: only
# those who can push here can put them there, and the owner takes them in
# by merging (a fork's commits with that email are still checked).
#
# pull_request_target, so that the check is the base branch's copy and a
# pull request can't change it. It reads the commits through the API and
# never checks out or runs the pull request's code.
name: Contributor agreement
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
pull-requests: read
concurrency:
group: contributor-agreement-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
sign-off:
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/github-script@v8
with:
script: |
const pr = context.payload.pull_request;
const exempt = ['OWNER', 'MEMBER'];
if (pr.user.type === 'Bot' || exempt.includes(pr.author_association)) {
core.info(`Opened by ${pr.user.login} (${pr.author_association}): not checked.`);
return;
}
const commits = await github.paginate(github.rest.pulls.listCommits, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
per_page: 100,
});
const sameRepo = pr.head.repo && pr.head.repo.full_name === pr.base.repo.full_name;
const exemptAuthors = ['noreply@anthropic.com'];
const missing = [];
for (const c of commits) {
if (c.parents.length > 1) continue;
const email = (c.commit.author.email || '').toLowerCase();
if (sameRepo && exemptAuthors.includes(email)) continue;
const signed = [...c.commit.message.matchAll(/^Signed-off-by:.*<([^>]+)>\s*$/gim)]
.some(m => m[1].trim().toLowerCase() === email);
if (!signed) {
missing.push(`${c.sha.slice(0, 7)} ${c.commit.message.split('\n')[0]} (author ${email})`);
}
}
if (missing.length) {
core.setFailed(
'These commits have no "Signed-off-by:" line with their author\'s email, ' +
'which says you agree to the contributor agreement in CONTRIBUTING.md:\n ' +
missing.join('\n ') +
'\n\nTo add it: git rebase --signoff ' + pr.base.ref +
' (or git commit --amend -s for the last commit), then force-push.');
} else {
core.info(`All ${commits.length} commits are signed off.`);
}
-144
View File
@@ -1,144 +0,0 @@
# D-Modem bump: moves the external/D-Modem submodule (the built-in
# modem) to the latest main of D-Modem. It opens a pull request for the
# change, or updates the open one. Build (build.yml) builds and tests
# the app in that pull request. The workflow merges the pull request
# when all of its checks pass. Build then runs on main, and the next
# nightly release (nightly.yml) has the new app.
#
# It starts:
# - from D-Modem, when its main changes (a repository_dispatch event of
# type "d-modem-main", from D-Modem's .github/workflows/dependents.yml);
# - each day (for an event that did not come);
# - manually (Actions > D-Modem bump > Run workflow).
#
# It needs the DMODEM_BUMP_TOKEN secret (an organization secret): a
# fine-grained personal access token with Contents: read and write and
# Pull requests: read and write on D-Modem/gui. Do not use the
# workflow's own GITHUB_TOKEN: a pull request that this token opens
# starts no other workflow, thus Build does not run on it. Without the
# secret, the run gives an error and stops.
#
# The workflow waits for the checks before it merges: with no required
# checks on main, GitHub's auto-merge merges immediately. If a check
# fails, the pull request stays open for a person.
name: D-Modem bump
on:
schedule:
- cron: "47 6 * * *"
repository_dispatch:
types: [d-modem-main]
workflow_dispatch:
# (one bump at a time: a second run waits for the first)
concurrency:
group: d-modem-bump
cancel-in-progress: false
permissions:
contents: read
env:
BRANCH: bot/d-modem-bump
jobs:
bump:
runs-on: ubuntu-24.04
# (Build takes about 35 minutes; a hung step stops here, not at
# GitHub's 6 hours)
timeout-minutes: 90
steps:
- name: Token present
env:
TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
run: |
if [ -z "$TOKEN" ]; then
echo "::error::No DMODEM_BUMP_TOKEN secret (see this workflow's header)"
exit 1
fi
- uses: actions/checkout@v4
with:
token: ${{ secrets.DMODEM_BUMP_TOKEN }}
fetch-depth: 0
- name: D-Modem's latest main
id: bump
run: |
git submodule update --init external/D-Modem
old=$(git -C external/D-Modem rev-parse HEAD)
git -C external/D-Modem fetch --quiet origin main
new=$(git -C external/D-Modem rev-parse FETCH_HEAD)
echo "old=$old" >> "$GITHUB_OUTPUT"
echo "new=$new" >> "$GITHUB_OUTPUT"
if [ "$old" = "$new" ]; then
echo "Already at D-Modem main ${new:0:7}"
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git -C external/D-Modem checkout --quiet "$new"
echo "changed=true" >> "$GITHUB_OUTPUT"
{
echo 'log<<EOF'
git -C external/D-Modem log --oneline --no-merges "$old..$new" | head -50
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Commit and push
id: commit
if: steps.bump.outputs.changed == 'true'
env:
OLD: ${{ steps.bump.outputs.old }}
NEW: ${{ steps.bump.outputs.new }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$BRANCH"
git add external/D-Modem
git commit -m "Bump D-Modem to ${NEW:0:7}" \
-m "external/D-Modem: ${OLD:0:7} -> ${NEW:0:7} (D-Modem's main)." \
-m "Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
git push --force origin "$BRANCH"
echo "head=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Pull request
id: pr
if: steps.bump.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
OLD: ${{ steps.bump.outputs.old }}
NEW: ${{ steps.bump.outputs.new }}
LOG: ${{ steps.bump.outputs.log }}
run: |
body=$(printf 'Moves `external/D-Modem` to D-Modem main: [`%s..%s`](https://github.com/D-Modem/D-Modem/compare/%s...%s)\n\n```\n%s\n```\n\nOpened by the D-Modem bump workflow (`.github/workflows/d-modem-bump.yml`). It merges when the checks pass.\n' \
"${OLD:0:7}" "${NEW:0:7}" "$OLD" "$NEW" "$LOG")
title="Bump D-Modem to ${NEW:0:7}"
pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
if [ -n "$pr" ]; then
gh pr edit "$pr" --title "$title" --body "$body"
else
gh pr create --base main --head "$BRANCH" --title "$title" --body "$body"
pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
fi
echo "number=$pr" >> "$GITHUB_OUTPUT"
# (the checks need some seconds to start; then the step waits for
# all of them)
- name: Merge when the checks pass
if: steps.bump.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
PR: ${{ steps.pr.outputs.number }}
HEAD: ${{ steps.commit.outputs.head }}
run: |
for i in $(seq 1 20); do
n=$(gh pr checks "$PR" --json name --jq length 2>/dev/null || true)
[ "${n:-0}" -gt 0 ] && break
sleep 15
done
sleep 30
if ! gh pr checks "$PR" --watch --interval 30; then
echo "::warning::A check failed on pull request #$PR: it waits for a person"
exit 1
fi
gh pr merge "$PR" --merge --match-head-commit "$HEAD"
-121
View File
@@ -1,121 +0,0 @@
# Nightly: the "nightly" pre-release of the app, from the artifacts of
# the newest complete run of build.yml on main. It does not build the
# app again. It runs each time a run of build.yml on main completes,
# and once a day. Each run updates the release in place and moves its
# tag: a run that fails does not delete the release. When main has no
# new commits, the run stops and the release does not change. A manual
# run (Actions > Nightly > Run workflow) can publish again with "force".
#
# The files are not signed: Windows SmartScreen and macOS Gatekeeper
# show a warning for them. The release has only the files of this
# build: nightly-publish.sh removes the files that the build did not
# make (for example the old Linux GTK app and the old macOS SwiftUI app).
name: Nightly
on:
# (each change to main: when its build completes)
workflow_run:
workflows: [Build]
types: [completed]
branches: [main]
schedule:
- cron: "23 5 * * *"
workflow_dispatch:
inputs:
force:
description: Publish again, also when main has no new commits
type: boolean
default: false
# (one at a time: a second run waits for the first)
concurrency:
group: nightly
cancel-in-progress: false
permissions:
contents: write
actions: read
jobs:
nightly:
runs-on: ubuntu-24.04
timeout-minutes: 20
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
steps:
- uses: actions/checkout@v4
- name: The newest build of main
id: pick
run: .github/scripts/nightly-pick.sh build.yml
env:
FORCE: ${{ inputs.force || 'false' }}
- uses: actions/download-artifact@v4
if: steps.pick.outputs.skip == 'false'
with:
run-id: ${{ steps.pick.outputs.run_build_yml }}
github-token: ${{ github.token }}
path: dl
- name: Files
if: steps.pick.outputs.skip == 'false'
env:
SHA: ${{ steps.pick.outputs.sha }}
RUN: ${{ steps.pick.outputs.run_build_yml }}
run: |
mkdir out
take() { # take ARTIFACT FILE [NAME]: copy it if the build made it
if [ -f "dl/$1/$2" ]; then cp "dl/$1/$2" "out/${3:-$2}"; else echo "- \`${3:-$2}\`" >> missing; fi
}
take dmodem-windows-9x dmodem.exe dmodem-win9x.exe
take dmodem-windows-98 dmodem.exe dmodem-win98.exe
take dmodem-windows dmodem.exe dmodem-win7.exe
take dmodem-win32-linux dmodem-win32-linux-x86_64.tar.gz
take dmodem-win32-macos dmodem-win32-macos-arm64.tar.gz
take dmodem-win32-macos-x86_64 dmodem-win32-macos-x86_64.tar.gz
take dmodem-win32-macosx-legacy dmodem-win32-macosx10.4.tar.gz
take dmodem-win32-macos9 dmodem-win32-macos9.bin
(cd out && sha256sum * > SHA256SUMS)
ls -l out
{
echo "The newest build of \`main\`, from commit $SHA ([build run]($GITHUB_SERVER_URL/$GH_REPO/actions/runs/$RUN))."
echo "This is not a stable release. The files are not signed."
echo
echo "| File | What it is |"
echo "| --- | --- |"
echo "| \`dmodem-win9x.exe\` | The Windows app with the modem built in, for Windows 95, 98, ME, NT 4.0 and later (no C runtime DLL; Windows 95 needs Winsock 2) |"
echo "| \`dmodem-win98.exe\` | The Windows app with the modem built in, for Windows 98 SE, ME, 2000 and later (on msvcrt.dll) |"
echo "| \`dmodem-win7.exe\` | The Windows app for Windows 7 and later, with the modem built in |"
echo "| \`dmodem-win32-linux-x86_64.tar.gz\` | The app on Linux (X11) with the modem built in, x86_64 |"
echo "| \`dmodem-win32-macos-arm64.tar.gz\` | The app on macOS with the modem built in, arm64 (Apple silicon) |"
echo "| \`dmodem-win32-macos-x86_64.tar.gz\` | The app on macOS with the modem built in, x86_64 (Intel Mac) |"
echo "| \`dmodem-win32-macosx10.4.tar.gz\` | The app on Mac OS X 10.4 (Tiger) and later with the modem built in, one program for PowerPC and Intel (i386). Not tested on a Mac yet |"
echo "| \`dmodem-win32-macos9.bin\` | The app on Mac OS 9 (PowerPC) with the modem built in, in MacBinary. Not tested on a Mac yet |"
echo "| \`SHA256SUMS\` | The SHA-256 of each file |"
if [ -f missing ]; then
echo
echo "This build did not make these files:"
cat missing
fi
} > notes.md
# The step uses the DMODEM_BUMP_TOKEN organization secret
# (Contents: read and write on D-Modem/gui, refer to
# d-modem-bump.yml) if it is available. If that token fails (for
# example "HTTP 403: Resource not accessible by personal access
# token"), the next step tries again with the GITHUB_TOKEN of this
# workflow. The script updates the release in place, so a failed
# try does not delete it.
- name: Publish
id: publish
if: steps.pick.outputs.skip == 'false' && env.HAS_BUMP_TOKEN == 'true'
continue-on-error: true
env:
HAS_BUMP_TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN != '' }}
GH_TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
run: .github/scripts/nightly-publish.sh "${{ steps.pick.outputs.sha }}" notes.md out
- name: Publish (GITHUB_TOKEN)
if: steps.pick.outputs.skip == 'false' && steps.publish.outcome != 'success'
run: .github/scripts/nightly-publish.sh "${{ steps.pick.outputs.sha }}" notes.md out
-18
View File
@@ -1,18 +0,0 @@
# The gui site at https://d-modem.github.io/gui/, built with brand's shared
# theme and workflow (brand's docs/sites.md).
name: Pages
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true
jobs:
site:
uses: D-Modem/brand/.github/workflows/site.yml@main
-10
View File
@@ -1,10 +0,0 @@
build/
build-*/
.vs/
bin/
obj/
*.user
# the site (brand's tools/site.sh): the theme it copies in, and the built site
.site/
site/
-4
View File
@@ -1,4 +0,0 @@
[submodule "external/D-Modem"]
path = external/D-Modem
url = https://github.com/D-Modem/D-Modem.git
branch = main
-92
View File
@@ -1,92 +0,0 @@
# D-Modem's desktop app: the shared C core (libdmodemctl), and the
# Win32 app (windows/). On Windows, it builds with clang-retro
# (cmake/clang-retro.cmake), MinGW or MSVC. With DMODEM_GUI_WINPORT, the
# same app builds for Linux and macOS, over clang-retro MFC's portable
# Win32 layer (winport/). On Linux and macOS with no DMODEM_GUI_WINPORT,
# only the core, libdmodemssh and their tests build.
# With DMODEM_GUI_EMBED, the app (Windows 95 and later, and the app on
# Linux and macOS) has the modem in it (libdmodem_embed from the D-Modem
# submodule, external/D-Modem): it needs no dmodemd.
cmake_minimum_required(VERSION 3.16)
project(dmodem-gui VERSION 1.0.0 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
option(DMODEM_GUI_SSH "Build libdmodemssh (libssh) for the Remote page" ON)
option(DMODEM_GUI_WINPORT "Build the Windows app for Linux or macOS (winport/)" OFF)
set(CLANG_RETRO_MFC "" CACHE PATH "A clang-retro MFC checkout, for DMODEM_GUI_WINPORT")
# the modem built in (docs/embedded-modem.md): the app on Windows, and
# the app on Linux and macOS (winport/), when the submodule is there
# (git submodule update --init)
set(DMODEM_GUI_DMODEM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/D-Modem
CACHE PATH "The D-Modem tree, for DMODEM_GUI_EMBED")
# (all the Windows builds: clang-retro's win32-picolibc, the Windows 95
# build, has libc++ for the modem's C++17, as win98 and win7 do)
set(_embed_default OFF)
if(EXISTS ${DMODEM_GUI_DMODEM_DIR}/CMakeLists.txt)
if(WIN32 OR DMODEM_GUI_WINPORT)
set(_embed_default ON)
endif()
endif()
option(DMODEM_GUI_EMBED "Build the modem into the app (libdmodem_embed)"
${_embed_default})
if(DMODEM_GUI_EMBED AND (WIN32 OR DMODEM_GUI_WINPORT))
if(NOT EXISTS ${DMODEM_GUI_DMODEM_DIR}/CMakeLists.txt)
message(FATAL_ERROR "DMODEM_GUI_EMBED: no D-Modem in "
"${DMODEM_GUI_DMODEM_DIR} (git submodule update --init)")
endif()
enable_language(CXX)
# (D-Modem's library and its SIP alone: no programs, modules or tests)
set(DMODEM_DMODEMD ON CACHE BOOL "" FORCE)
set(DMODEM_EMBED ON CACHE BOOL "" FORCE)
set(DMODEM_TESTS OFF CACHE BOOL "" FORCE)
set(DMODEM_ASTERISK OFF CACHE BOOL "" FORCE)
set(DMODEM_FREESWITCH OFF CACHE BOOL "" FORCE)
set(DMODEM_ARI OFF CACHE BOOL "" FORCE)
# (clang-retro: D-Modem's own toolchain file has its sources take
# dmodem_retro.h, the clock_gettime() that the sysroots lack; here
# its C++ sources alone, as there)
get_directory_property(_opts COMPILE_OPTIONS)
if(CLANG_DOS)
# (the oldest Windows of the target, as D-Modem's toolchain file
# has it: the .cfg's _WIN32_WINNT, else its triple's
# windows<major>.<minor>, 9x and NT 4.0 all 0x0400)
if(NOT DMODEM_WINNT)
file(STRINGS ${CLANG_DOS}/bin/${CLANG_RETRO_CONFIG}.cfg _cfg_lines)
foreach(_l ${_cfg_lines})
if(_l MATCHES "^-D_WIN32_WINNT=(.*)$")
set(DMODEM_WINNT ${CMAKE_MATCH_1})
elseif(NOT DMODEM_WINNT AND _l MATCHES "windows([0-9]+)\\.([0-9]+)")
if(CMAKE_MATCH_1 EQUAL 4)
set(DMODEM_WINNT 0x0400)
else()
math(EXPR DMODEM_WINNT "${CMAKE_MATCH_1} * 256 + ${CMAKE_MATCH_2}"
OUTPUT_FORMAT HEXADECIMAL)
endif()
endif()
endforeach()
set(DMODEM_WINNT ${DMODEM_WINNT} CACHE STRING
"_WIN32_WINNT: the oldest Windows for the modem built in")
endif()
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-include>"
"$<$<COMPILE_LANGUAGE:CXX>:${DMODEM_GUI_DMODEM_DIR}/platforms/windows/clang-retro/dmodem_retro.h>")
set(ENV{CLANG_DOS} ${CLANG_DOS})
endif()
add_subdirectory(${DMODEM_GUI_DMODEM_DIR} d-modem EXCLUDE_FROM_ALL)
set_directory_properties(PROPERTIES COMPILE_OPTIONS "${_opts}")
endif()
add_subdirectory(core)
enable_testing()
add_subdirectory(core/test)
if(DMODEM_GUI_SSH)
add_subdirectory(ssh)
endif()
if(WIN32)
add_subdirectory(windows)
elseif(DMODEM_GUI_WINPORT)
add_subdirectory(winport)
endif()
-44
View File
@@ -1,44 +0,0 @@
# Commercial license
The D-Modem GUI is Copyright (C) 2026 D-Modem Authors and is offered
under two licenses; you choose one.
## The GNU Affero General Public License, version 3 (the default)
[LICENSE](LICENSE), AGPL-3.0-only. Free of charge, for any purpose,
commercial ones included, on the AGPL's terms. In short:
- If you distribute the D-Modem GUI, modified or not, you give the recipients
its complete source code under the AGPL.
- If you modify the D-Modem GUI and let people use it remotely (anyone using it
over a network), you offer those users
the complete source code of your modified version under the AGPL
(section 13).
## A commercial license
For those who cannot or will not meet the AGPL's terms, for example to:
- ship the D-Modem GUI, or a modified version, inside a product whose source
you do not publish;
- run a modified version of the D-Modem GUI as a service without offering its source to
the people who use it;
- combine it with code under licenses that do not mix with the AGPL.
A commercial license is granted by the D-Modem Authors, the copyright holders,
on terms agreed with you (scope, term and fee).
Neo-Desktop (<https://github.com/Neo-Desktop>) is the point of contact
for commercial licenses.
**To ask for one**, contact Neo-Desktop, or open an issue at
<https://github.com/D-Modem/gui/issues> titled "Commercial
license", saying who you are and roughly what you want to do. Keep
anything confidential out of the issue: a private channel follows from
there.
Until a commercial license is signed, the AGPL is the only license you
have.
This file explains the licensing; it is not itself a license or a
contract.
-60
View File
@@ -1,60 +0,0 @@
# Contributing
We accept contributions: issues, fixes and features. Before you send a
change, build it on the platforms that it affects ([README.md](README.md)).
Write all technical documentation in ASD-STE100 Simplified Technical English. Follow docs/STYLE.md.
## The contributor agreement
The GUI is offered under the AGPL-3.0 and, by the D-Modem Authors, under
commercial licenses ([COMMERCIAL-LICENSE.md](COMMERCIAL-LICENSE.md)).
For contributions to be part of both, each one comes with this agreement.
By submitting a contribution (a pull request, a patch or
any other code or text meant for inclusion), you agree that:
1. The contribution is your own original work, or you otherwise have
the right to submit it under these terms, and to your knowledge it
infringes no one's rights. If your employer has rights in what you
create, you have its permission to contribute, or it has waived those
rights.
2. You assign to D-Modem all copyright in your contribution, worldwide,
for the whole term of those rights. "D-Modem" here is the D-Modem
organization (<https://github.com/D-Modem>), whose rights its owner,
Neo-Desktop, holds on its behalf; the "D-Modem Authors" in the
project's copyright notices are D-Modem in this sense. Where a right
can't be assigned (moral rights, for example), you waive it, or where
it can't be waived, you agree not to assert it against D-Modem or
those who receive the project from it. If the assignment is not
effective anywhere, you instead grant D-Modem there an exclusive,
perpetual, worldwide, no-charge, royalty-free, irrevocable license to
do anything the copyright holder could do with your contribution,
including licensing it to others.
3. D-Modem may license your contribution, and works based on it, under
the AGPL-3.0 and under any other terms, commercial licenses included.
It licenses your contribution back to you: a perpetual, worldwide,
non-exclusive, no-charge, royalty-free, irrevocable license to use,
copy, modify, publicly display and perform, sublicense and distribute
it, on any terms.
4. You grant D-Modem, and those who receive the project from it, a
perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable license under any patent claims of yours that your
contribution would infringe, to make, use, sell and otherwise
transfer it as part of the project.
5. Your contribution is provided "as is", without warranties or
conditions of any kind.
Please add this line to each commit you contribute (`git commit -s`
does it):
Signed-off-by: Your Name <your@email>
It says that you agree to the above for that commit. A contribution
without it cannot be merged.
A check on each pull request looks for that line, with the email of the
commit author, on each commit. If the line is missing, use
`git rebase --signoff main` to add it. For the last commit only, you can
use `git commit --amend -s`. Then force-push. The check does not examine
pull requests from the D-Modem Authors (the owner of the repository and
the members of the D-Modem organization).
+28 -661
View File
@@ -1,661 +1,28 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
BSD 3-Clause License
Copyright (c) 2026, D-Modem
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+1 -87
View File
@@ -1,89 +1,3 @@
<img src=".github/banner.png" alt="D-Modem/gui: D-Modem on the desktop" width="100%">
# D-Modem desktop app
The D-Modem desktop app is one Win32 app for Windows, macOS and Linux. The
site of the app is <https://d-modem.github.io/gui/>.
The app has the modem built in, so it needs no dmodemd (refer to
[The built-in modem](docs/embedded-modem.md)). The app shows the modem as a
desktop program. You can dial and answer from a window, change the settings
without AT commands, and see the results of the last call. The app is a
thin Win32 shell over one small C library, libdmodemctl.
- **Modem**: the state of the call, dial, answer and hang up, and the line that the modem uses
- **Phone**: voice calls through the sound card (dial, answer, keypad), and an
answering machine that takes messages on this computer when you enable it (disabled by default)
- **Terminal**: the AT console, and the setup screens of the modem (AT!CF, AT!CT)
- **Remote**: log in to a server by SSH, Telnet or rlogin, in a separate terminal. SSH is built in, on libssh, and it uses the keys and the agent of OpenSSH and PuTTY
- **Terminal types**: the terminal emulator of the D-Modem app, ported to C: xterm, DEC VT52 to VT525, ANSI-BBS, PETSCII, ATASCII, Viewdata, Minitel and Tektronix 4014, with sixel, ReGIS and Tektronix graphics
- **HyperTerminal items**: file transfers (ZMODEM, YMODEM, XMODEM and Kermit), copy and capture, and the ASCII Setup, Terminal Settings and Call menu of HyperTerminal. Refer to [Features](docs/features.md)
- **Settings**: each modem setting as a native control, from AT!M
- **Call Stats**: the rate, modulation, error control and line figures of the last call (AT#UD, ATI11)
- **Line settings**: a SIP account, a USB modem, or a modem that already runs (dmodemd, or a hardware modem such as the MultiTech MT9234MU). **Look for a modem** finds the modem and its port
| | Windows | macOS | Linux |
| --- | --- | --- | --- |
| Toolkit | Win32, C++ | Win32, over the Cocoa layer of [clang-retro MFC](https://github.com/clang-retro/mfc) | Win32, over the X11 and Wayland layer of clang-retro MFC |
| Built with | [clang-retro](https://clang-retro.github.io/), MinGW or MSVC | clang | clang |
| Runs on | Windows 95 and later | arm64 (Apple silicon) and x86_64 (Intel Mac). Also Mac OS X 10.4 and later on PowerPC and i386, and Mac OS 9 on PowerPC | x86_64 |
The source code of the app is the same on each system. Refer to "The
Windows app on Linux and macOS" in [Design](docs/design.md).
<img src="docs/images/windows-settings.png" width="49%" alt="The Settings page of the app"> <img src="docs/images/windows-setup-screen.png" width="49%" alt="The Terminal of the app with the setup screen of the modem">
<img src="docs/images/windows-modem.png" width="49%" alt="The Modem page of the app"> <img src="docs/images/windows-phone.png" width="49%" alt="The Phone page of the app as it takes a message">
## Nightly builds
The [nightly release](https://github.com/D-Modem/gui/releases/tag/nightly)
has the app from the newest build of `main`: for Windows 95 and later, for
Windows 7 and later, for Linux, and for macOS. A workflow
(`.github/workflows/nightly.yml`) replaces the release one time each day.
When `main` has no new commits, the release does not change. When the
main branch of D-Modem changes, a workflow moves the built-in modem to it
and builds the app again (refer to [Building](docs/building.md)).
These builds are not stable releases. The files are not signed. Thus
Windows and macOS can show a warning before the app starts.
## Quick start
Linux (get [clang-retro MFC](https://github.com/clang-retro/mfc) first):
git submodule update --init
sudo apt install cmake ninja-build clang llvm libx11-dev \
libusb-1.0-0-dev libasound2-dev
cmake -S . -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build --target dmodem-win32 && ./build/winport/dmodem-win32
For Windows (with clang-retro) and macOS, refer to
[Building](docs/building.md).
## Documentation
- [The site](https://d-modem.github.io/gui/): the home page, the downloads and all the pages below
- [Features](docs/features.md): each page and menu of the app
- [Building](docs/building.md): Windows with clang-retro, and the app on Linux and macOS
- [The built-in modem](docs/embedded-modem.md): the modem inside the app, with no dmodemd
- [Design](docs/design.md): how the app is built, hardware modems (the MultiTech MT9234MU), the Windows 9x notes, and the app on Linux and macOS
- [libdmodemctl](core/include/dmodemctl.h): the API of the library
- [Documentation style](docs/STYLE.md): the rules for ASD-STE100 Simplified Technical English
## The D-Modem suite
| Repository | What it is |
| --- | --- |
| [D-Modem](https://github.com/D-Modem/D-Modem) | The open V.92 softmodem: dmodemd, libdmodem and the Asterisk, FreeSWITCH and ARI modules |
| [app](https://github.com/D-Modem/app) | The D-Modem app for Android and iOS: a dial-up modem on a SIP call |
| [gui](https://github.com/D-Modem/gui) | D-Modem on the desktop: one Win32 app for Windows, macOS and Linux |
| [hardware](https://github.com/D-Modem/hardware) | pico-serial: RP2040 serial adapters and phone-line USB sticks |
| [login](https://github.com/D-Modem/login) | dmodem-login: the login, menu and LDAP provider for dial-up callers |
| [bbs](https://github.com/D-Modem/bbs) | A bulletin board for telnet, SSH, TN3270 and modem callers |
| [brand](https://github.com/D-Modem/brand) | Logos, colours, type and the naming guide |
## Licence
AGPL-3.0-only ([LICENSE](LICENSE)), or a commercial licence from the D-Modem Authors ([COMMERCIAL-LICENSE.md](COMMERCIAL-LICENSE.md)). Contributions come with a contributor agreement ([CONTRIBUTING.md](CONTRIBUTING.md)).
# gui
-15
View File
@@ -1,15 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 500 500">
<!-- D-Modem's mark (D-Modem/brand, avatar/org-avatar.svg) on a desktop tile -->
<defs>
<linearGradient id="books" gradientUnits="userSpaceOnUse" x1="0" y1="81" x2="0" y2="419"><stop offset="0.0000" stop-color="#ff4d5e"/><stop offset="0.1667" stop-color="#ff4d5e"/><stop offset="0.1667" stop-color="#ff8a3d"/><stop offset="0.3333" stop-color="#ff8a3d"/><stop offset="0.3333" stop-color="#ffd23d"/><stop offset="0.5000" stop-color="#ffd23d"/><stop offset="0.5000" stop-color="#3ddc84"/><stop offset="0.6667" stop-color="#3ddc84"/><stop offset="0.6667" stop-color="#3d8bff"/><stop offset="0.8333" stop-color="#3d8bff"/><stop offset="0.8333" stop-color="#a66bff"/><stop offset="1.0000" stop-color="#a66bff"/></linearGradient>
<filter id="glow" x="-30%" y="-30%" width="160%" height="160%">
<feGaussianBlur stdDeviation="6" result="b"/>
<feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
</defs>
<rect x="10" y="10" width="480" height="480" rx="108" fill="#0a0f1c"/>
<g transform="translate(-15 0)">
<path d="M140 100 H240 A150 150 0 0 1 240 400 H140 Z" fill="none" stroke="url(#books)" stroke-width="38" stroke-linejoin="round" filter="url(#glow)"/>
<path d="M178.0,250.0 L178.8,246.3 L179.5,242.7 L180.3,239.1 L181.1,235.5 L181.8,232.0 L182.6,228.6 L183.4,225.2 L184.1,222.0 L184.9,218.9 L185.7,215.9 L186.4,213.1 L187.2,210.4 L188.0,207.9 L188.7,205.6 L189.5,203.4 L190.3,201.5 L191.0,199.8 L191.8,198.3 L192.6,197.0 L193.3,195.9 L194.1,195.1 L194.9,194.5 L195.6,194.1 L196.4,194.0 L197.2,194.1 L197.9,194.5 L198.7,195.1 L199.5,195.9 L200.2,197.0 L201.0,198.3 L201.8,199.8 L202.5,201.5 L203.3,203.4 L204.1,205.6 L204.8,207.9 L205.6,210.4 L206.4,213.1 L207.1,215.9 L207.9,218.9 L208.7,222.0 L209.4,225.2 L210.2,228.6 L211.0,232.0 L211.7,235.5 L212.5,239.1 L213.3,242.7 L214.0,246.3 L214.8,250.0 L215.6,253.7 L216.3,257.3 L217.1,260.9 L217.9,264.5 L218.6,268.0 L219.4,271.4 L220.2,274.8 L220.9,278.0 L221.7,281.1 L222.5,284.1 L223.2,286.9 L224.0,289.6 L224.8,292.1 L225.5,294.4 L226.3,296.6 L227.1,298.5 L227.8,300.2 L228.6,301.7 L229.4,303.0 L230.1,304.1 L230.9,304.9 L231.7,305.5 L232.4,305.9 L233.2,306.0 L234.0,305.9 L234.7,305.5 L235.5,304.9 L236.3,304.1 L237.0,303.0 L237.8,301.7 L238.6,300.2 L239.3,298.5 L240.1,296.6 L240.9,294.4 L241.6,292.1 L242.4,289.6 L243.2,286.9 L243.9,284.1 L244.7,281.1 L245.5,278.0 L246.2,274.8 L247.0,271.4 L247.8,268.0 L248.5,264.5 L249.3,260.9 L250.1,257.3 L250.8,253.7 L251.6,250.0 L252.4,246.3 L253.1,242.7 L253.9,239.1 L254.7,235.5 L255.4,232.0 L256.2,228.6 L257.0,225.2 L257.7,222.0 L258.5,218.9 L259.3,215.9 L260.0,213.1 L260.8,210.4 L261.6,207.9 L262.3,205.6 L263.1,203.4 L263.9,201.5 L264.6,199.8 L265.4,198.3 L266.2,197.0 L266.9,195.9 L267.7,195.1 L268.5,194.5 L269.2,194.1 L270.0,194.0 H288.4 V306.0 H325.2 V194.0 H362.0" fill="none" stroke="#e8f0ff" stroke-width="16" stroke-linecap="round" stroke-linejoin="round"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.9 KiB

-10
View File
@@ -1,10 +0,0 @@
# The platform file of the classic Mac OS (cmake/macos9.cmake): a POSIX
# system for CMake, over the C library of clang-retro/mac-sdk. A program
# is a MacBinary II file (.bin) that mac-sdk's tools/macapp.py links.
set(UNIX 1)
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_EXECUTABLE_SUFFIX ".bin")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
-46
View File
@@ -1,46 +0,0 @@
# CMake toolchain file for clang-retro (https://clang-retro.github.io/):
# the Windows app for Windows 95 and later, built on Linux or Windows.
#
# cmake -S . -B build/retro -DCLANG_DOS=/opt/clang-dos \
# -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake
#
# CLANG_DOS is the unpacked clang-dos toolchain package (the environment
# variable CLANG_DOS also sets it). CLANG_RETRO_CONFIG is the --config
# file of the target (default win32-picolibc: Windows 95, 98, ME, NT 4.0
# and later, with no C runtime DLL).
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 4.0)
set(CMAKE_SYSTEM_PROCESSOR i386)
if(NOT CLANG_DOS AND DEFINED ENV{CLANG_DOS})
set(CLANG_DOS "$ENV{CLANG_DOS}")
endif()
if(NOT CLANG_DOS)
message(FATAL_ERROR "Set CLANG_DOS to the clang-dos toolchain package")
endif()
set(CLANG_DOS "${CLANG_DOS}" CACHE PATH "The clang-dos toolchain package")
set(CLANG_RETRO_CONFIG win32-picolibc CACHE STRING "The clang-retro --config file (without .cfg)")
# (try_compile projects see these two)
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CLANG_DOS CLANG_RETRO_CONFIG)
if(CMAKE_HOST_WIN32)
set(_exe .exe)
else()
set(_exe "")
endif()
# (the --config file is a mandatory argument of the compilers, not a flag,
# so that a -DCMAKE_C_FLAGS of a project, or of an ExternalProject, keeps it)
set(_cfg "--config=${CLANG_DOS}/bin/${CLANG_RETRO_CONFIG}.cfg")
set(CMAKE_C_COMPILER "${CLANG_DOS}/bin/clang${_exe}" "${_cfg}")
set(CMAKE_CXX_COMPILER "${CLANG_DOS}/bin/clang++${_exe}" "${_cfg}")
set(CMAKE_RC_COMPILER "${CLANG_DOS}/bin/llvm-windres${_exe}")
set(CMAKE_AR "${CLANG_DOS}/bin/llvm-ar${_exe}")
set(CMAKE_RANLIB "${CLANG_DOS}/bin/llvm-ranlib${_exe}")
# windres runs the preprocessor of clang for the target
set(CMAKE_RC_FLAGS_INIT "--target=pe-i386 --preprocessor-arg=${_cfg}")
list(APPEND CMAKE_FIND_ROOT_PATH "${CLANG_DOS}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
-73
View File
@@ -1,73 +0,0 @@
# CMake toolchain file for the classic Mac OS on PowerPC (Mac OS 8.6 to
# 9.2). It builds the Windows app (winport/) over the Toolbox backend of
# clang-retro MFC, on Linux.
#
# cmake -S . -B build/macos9 -DCMAKE_TOOLCHAIN_FILE=cmake/macos9.cmake \
# -DMACOS9_LLVM=/opt/llvm -DMACOS9_SDK=/path/to/mac-sdk \
# -DCLANG_RETRO_MFC=/path/to/mfc -DDMODEM_GUI_WINPORT=ON
#
# You need these:
# MACOS9_LLVM clang of clang-retro/llvm (the llvm-prebuilt release)
# MACOS9_SDK a clang-retro/mac-sdk checkout, with its runtime, C and
# C++ libraries in lib/ (runtime/build.sh,
# runtime/build-libc.sh, runtime/build-libstdcxx.sh)
# CLANG_RETRO_MFC a clang-retro/mfc checkout (port/compat/macos)
# The environment variables of the same names also set them.
#
# CMake builds the static libraries. tools/macapp.py of mac-sdk links each
# program into a PowerPC application (a MacBinary II file, .bin).
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
set(CMAKE_SYSTEM_NAME MacOS9)
set(CMAKE_SYSTEM_VERSION 9.2)
set(CMAKE_SYSTEM_PROCESSOR powerpc)
foreach(_v MACOS9_LLVM MACOS9_SDK CLANG_RETRO_MFC)
if(NOT ${_v} AND DEFINED ENV{${_v}})
set(${_v} "$ENV{${_v}}")
endif()
if(NOT ${_v})
message(FATAL_ERROR "Set ${_v} (cmake/macos9.cmake)")
endif()
set(${_v} "${${_v}}" CACHE PATH "" FORCE)
# (the builds that D-Modem configures with this file see them too)
set(ENV{${_v}} "${${_v}}")
endforeach()
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES MACOS9_LLVM MACOS9_SDK CLANG_RETRO_MFC)
set(MACOS9_TARGET powerpc-apple-macos9)
set(_lib "${MACOS9_SDK}/lib")
# The headers: GCC's C++ library of mac-sdk, port/compat/macos of
# clang-retro MFC (the POSIX declarations that picolibc does not have),
# the C library, then the Toolbox. These are mandatory arguments of the
# compilers, with the target: a -DCMAKE_C_FLAGS of a project or an
# ExternalProject keeps them.
set(_common -isystem ${CLANG_RETRO_MFC}/port/compat/macos -isystem ${_lib}/include
-I${MACOS9_SDK}/include -DMAC_LIBC -D_GNU_SOURCE
-femulated-tls -ffunction-sections -fdata-sections)
set(CMAKE_C_COMPILER "${MACOS9_LLVM}/bin/clang" "--target=${MACOS9_TARGET}" ${_common})
set(CMAKE_CXX_COMPILER "${MACOS9_LLVM}/bin/clang++" "--target=${MACOS9_TARGET}"
-nostdinc++ -isystem ${_lib}/include/c++/15.2.0/${MACOS9_TARGET}
-isystem ${_lib}/include/c++/15.2.0 ${_common} -fexceptions -frtti)
set(CMAKE_AR "${MACOS9_LLVM}/bin/llvm-ar")
set(CMAKE_RANLIB "${MACOS9_LLVM}/bin/llvm-ranlib")
# The tests of CMake and of the projects compile and do not link: the
# linker is macapp.py, which makes a Mac application
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# A program: macapp.py links its objects and libraries with the C and
# C++ libraries of mac-sdk (MACOS9_APP_SIZE: the partition in KB)
set(MACOS9_APP_SIZE 16384 CACHE STRING "The partition of a program, in KB")
find_program(MACOS9_PYTHON NAMES python3 python REQUIRED)
# (macapp.py adds the C++ library only for C++ sources, not for objects:
# a C++ program names libstdc++.a and libunwind.a, which throws the
# exceptions, itself)
set(_macapp "${CMAKE_COMMAND} -E env CLANG=${MACOS9_LLVM}/bin/clang ${MACOS9_PYTHON} ${MACOS9_SDK}/tools/macapp.py --cpu ppc --size ${MACOS9_APP_SIZE} --name <TARGET_NAME> -o <TARGET> -- <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE "${_macapp}")
set(CMAKE_CXX_LINK_EXECUTABLE "${_macapp} ${_lib}/ppc/libstdc++.a ${_lib}/ppc/libunwind.a")
set(CMAKE_FIND_ROOT_PATH "${_lib}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
-99
View File
@@ -1,99 +0,0 @@
# CMake toolchain file for Mac OS X 10.4 (Tiger) and later, on 32-bit
# PowerPC or 32-bit Intel. It builds the Windows app (winport/) over the
# Mac OS X 10.0-10.5 port of clang-retro MFC, on Linux.
#
# cmake -S . -B build/ppc -DCMAKE_TOOLCHAIN_FILE=cmake/macosx-legacy.cmake \
# -DMACOSX_LEGACY_ARCH=powerpc -DMACOSX_LEGACY_LLVM=/opt/llvm \
# -DMACOSX_LEGACY_SYSROOT=/opt/clang-dos/macosx10.4 \
# -DMACOSX_LEGACY_CCTOOLS=/opt/cctools-ppc \
# -DCLANG_RETRO_MFC=/path/to/mfc -DDMODEM_GUI_WINPORT=ON
#
# You need these:
# MACOSX_LEGACY_ARCH powerpc or i386
# MACOSX_LEGACY_LLVM clang of clang-retro/llvm (the llvm-prebuilt
# release), with emulated TLS for Mac OS X 10.4
# MACOSX_LEGACY_SYSROOT the macosx10.4 sysroot of clang-retro/dos-sdk
# (packaging/get-toolchain.sh -s macosx10.4): libc++,
# and MacOSX10.4u.sdk in it
# MACOSX_LEGACY_CCTOOLS Apple's ld64 and ar for PowerPC
# (dos-sdk's scripts/build-cctools-ppc.sh)
# The environment variables of the same names also set them.
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_VERSION 8.0)
foreach(_v ARCH LLVM SYSROOT CCTOOLS)
if(NOT MACOSX_LEGACY_${_v} AND DEFINED ENV{MACOSX_LEGACY_${_v}})
set(MACOSX_LEGACY_${_v} "$ENV{MACOSX_LEGACY_${_v}}")
endif()
if(NOT MACOSX_LEGACY_${_v})
message(FATAL_ERROR "Set MACOSX_LEGACY_${_v} (cmake/macosx-legacy.cmake)")
endif()
set(MACOSX_LEGACY_${_v} "${MACOSX_LEGACY_${_v}}" CACHE STRING "" FORCE)
# (the builds that D-Modem configures with this file see them too)
set(ENV{MACOSX_LEGACY_${_v}} "${MACOSX_LEGACY_${_v}}")
endforeach()
# (try_compile projects see these)
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
MACOSX_LEGACY_ARCH MACOSX_LEGACY_LLVM MACOSX_LEGACY_SYSROOT MACOSX_LEGACY_CCTOOLS)
set(CMAKE_SYSTEM_PROCESSOR ${MACOSX_LEGACY_ARCH})
set(MACOSX_LEGACY_TARGET "${MACOSX_LEGACY_ARCH}-apple-macosx10.4")
set(MACOSX_LEGACY_SDK "${MACOSX_LEGACY_SYSROOT}/MacOSX10.4u.sdk")
set(_cct "${MACOSX_LEGACY_CCTOOLS}/bin/powerpc-apple-darwin8-")
set(CMAKE_OSX_SYSROOT "${MACOSX_LEGACY_SDK}")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.4)
set(CMAKE_OSX_ARCHITECTURES "")
# ld64 cannot read the symbol table that llvm-ar writes for PowerPC
set(CMAKE_AR "${_cct}ar")
set(CMAKE_RANLIB "${_cct}ranlib")
set(CMAKE_LIPO "${_cct}lipo")
set(CMAKE_INSTALL_NAME_TOOL "${_cct}install_name_tool")
# The C library functions that Mac OS X 10.4 does not have, such as
# clock_gettime: port/compat/macosx of clang-retro MFC (CLANG_RETRO_MFC),
# and cmake/macosx-legacy (the fixes of headers of the 10.4 SDK).
# libwinport.a has their code. _DARWIN_C_SOURCE: gmtime_r and the other
# POSIX functions also with -std=c99. And libc++ of the sysroot, with
# threads.
if(NOT CLANG_RETRO_MFC AND DEFINED ENV{CLANG_RETRO_MFC})
set(CLANG_RETRO_MFC "$ENV{CLANG_RETRO_MFC}")
endif()
if(NOT CLANG_RETRO_MFC)
message(FATAL_ERROR "Set CLANG_RETRO_MFC (cmake/macosx-legacy.cmake)")
endif()
set(ENV{CLANG_RETRO_MFC} "${CLANG_RETRO_MFC}")
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CLANG_RETRO_MFC)
# These are mandatory arguments of the compilers, with the target, not
# flags: a -DCMAKE_C_FLAGS of a project or an ExternalProject keeps them.
set(_compat -isystem ${CMAKE_CURRENT_LIST_DIR}/macosx-legacy
-isystem ${CLANG_RETRO_MFC}/port/compat/macosx
-DWINPORT_MACOSX_COMPAT -D_DARWIN_C_SOURCE)
set(_cxx -nostdinc++ -isystem ${MACOSX_LEGACY_SYSROOT}/include/c++/v1
-D__STDC_FORMAT_MACROS)
set(CMAKE_C_COMPILER "${MACOSX_LEGACY_LLVM}/bin/clang"
"--target=${MACOSX_LEGACY_TARGET}" ${_compat})
set(CMAKE_CXX_COMPILER "${MACOSX_LEGACY_LLVM}/bin/clang++"
"--target=${MACOSX_LEGACY_TARGET}" ${_cxx} ${_compat})
set(CMAKE_OBJCXX_COMPILER ${CMAKE_CXX_COMPILER})
# The builtins of the sysroot have emulated TLS and the atomic library
# functions (__atomic_fetch_add_8 and others), which libc++ and libre need
if(MACOSX_LEGACY_ARCH STREQUAL "powerpc")
set(_rt "${MACOSX_LEGACY_SYSROOT}/lib/darwin/libclang_rt.ppc_osx.a")
else()
set(_rt "${MACOSX_LEGACY_SYSROOT}/lib/darwin/libclang_rt.osx.a")
endif()
set(_ld "-fuse-ld=${_cct}ld -nostdlib++ -L${MACOSX_LEGACY_SYSROOT}/lib -lc++ -lc++abi -lunwind ${_rt}")
# (a program exports no symbols of libc++: on i386, ld64 stops at a
# pointer difference to a global weak symbol, such as std::to_string's
# to __itoa::__pow10_32 in the libc++ of the sysroot, when another object
# also has that symbol)
set(CMAKE_EXE_LINKER_FLAGS_INIT "${_ld} -Wl,-unexported_symbol,__ZNSt3__1*")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${_ld}")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "${_ld}")
list(APPEND CMAKE_FIND_ROOT_PATH "${MACOSX_LEGACY_SDK}" "${MACOSX_LEGACY_SYSROOT}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
-16
View File
@@ -1,16 +0,0 @@
/*
* net/if.h for Mac OS X 10.4 (cmake/macosx-legacy.cmake): sys/socket.h,
* then the net/if.h of the SDK.
*
* The net/if.h of the 10.4 SDK uses struct sockaddr and does not include
* sys/socket.h. POSIX lets a program include net/if.h first, and libssh
* does.
*/
#ifndef DMODEM_MACOSX_LEGACY_NET_IF_H
#define DMODEM_MACOSX_LEGACY_NET_IF_H
#include <sys/types.h>
#include <sys/socket.h>
#include_next <net/if.h>
#endif
-24
View File
@@ -1,24 +0,0 @@
/*
* signal.h for Mac OS X 10.4 (cmake/macosx-legacy.cmake): the signal.h
* of the SDK, with SIG_DFL, SIG_IGN, SIG_HOLD and SIG_ERR as pointers to
* a function with a prototype.
*
* Without _POSIX_C_SOURCE, the 10.4 SDK gives them as pointers to a
* function with no prototype. libssh compiles with
* -Werror=strict-prototypes, which stops at these.
*/
#ifndef DMODEM_MACOSX_LEGACY_SIGNAL_H
#define DMODEM_MACOSX_LEGACY_SIGNAL_H
#include_next <signal.h>
#undef SIG_DFL
#undef SIG_IGN
#undef SIG_HOLD
#undef SIG_ERR
#define SIG_DFL ((void (*)(int))0)
#define SIG_IGN ((void (*)(int))1)
#define SIG_HOLD ((void (*)(int))5)
#define SIG_ERR ((void (*)(int))-1)
#endif
-33
View File
@@ -1,33 +0,0 @@
/*
* time.h for Mac OS X 10.4 (cmake/macosx-legacy.cmake): the time.h of
* clang-retro MFC (port/compat/macosx) and of the SDK, and the
* reentrant functions of POSIX.
*
* The time.h of the 10.4 SDK does not declare gmtime_r, localtime_r,
* asctime_r and ctime_r when _POSIX_C_SOURCE is set. These functions are
* POSIX functions, and libSystem of 10.4 has them. Mbed TLS sets
* _POSIX_C_SOURCE and calls gmtime_r.
*/
#ifndef DMODEM_MACOSX_LEGACY_TIME_H
#define DMODEM_MACOSX_LEGACY_TIME_H
#include_next <time.h>
#if defined(_POSIX_C_SOURCE) && !defined(_ANSI_SOURCE)
#ifdef __cplusplus
extern "C" {
#endif
/* Converts a time to UTC in the given structure. */
struct tm *gmtime_r(const time_t *, struct tm *);
/* Converts a time to local time in the given structure. */
struct tm *localtime_r(const time_t *, struct tm *);
/* Writes a time structure as text into the given buffer. */
char *asctime_r(const struct tm *, char *);
/* Writes a time as text into the given buffer. */
char *ctime_r(const time_t *, char *);
#ifdef __cplusplus
}
#endif
#endif
#endif
-50
View File
@@ -1,50 +0,0 @@
# libdmodemctl: the part of the desktop app that does not draw, in plain
# C with no dependencies. Static by default; a DLL for a P/Invoke caller
# (-DDMODEMCTL_SHARED=ON).
option(DMODEMCTL_SHARED "Build libdmodemctl as a shared library" OFF)
set(DMODEMCTL_SOURCES
src/session.c
src/model.c
src/diag.c
src/path.c
src/vt.c
src/vt_charsets.c
src/vt_data.c
src/vt_dec.c
src/vt_fonts.c
src/vt_gfx.c
src/vt_keys.c
src/vt_machine.c
src/vt_profiles.c
src/vt_regis.c
src/vt_rip.c
src/vt_vt52.c
src/daemon.c
src/voice.c
src/net.c
src/util.c
src/xfer.c
src/xfer_hex.c
src/xfer_kermit.c
src/xfer_xy.c
src/xfer_z.c
src/zstd_codec.c)
if(DMODEMCTL_SHARED)
add_library(dmodemctl SHARED ${DMODEMCTL_SOURCES})
target_compile_definitions(dmodemctl PRIVATE DMC_BUILD_DLL)
set_target_properties(dmodemctl PROPERTIES C_VISIBILITY_PRESET hidden)
else()
add_library(dmodemctl STATIC ${DMODEMCTL_SOURCES})
endif()
target_include_directories(dmodemctl PUBLIC include)
if(MSVC)
target_compile_options(dmodemctl PRIVATE /W4 /wd4996)
else()
target_compile_options(dmodemctl PRIVATE -Wall -Wextra -Wshadow)
endif()
if(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(dmodemctl PRIVATE m Threads::Threads)
endif()
-781
View File
@@ -1,781 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* dmodemctl.h - the part of D-Modem's desktop app that is not drawing.
*
* The Win32 app (on Windows, and on Linux and macOS over clang-retro
* MFC's Win32 layer) is a thin shell over this small C library, so that
* the app is only views. The library does no I/O of its own and
* starts no threads: the app opens the modem's DTE (a TCP socket, a COM
* port), hands the bytes it reads to dmc_feed(), writes what
* dmc_output() gives it, and calls dmc_poll() from a timer. That keeps it simple to call from C, C++ (Win32), C#
* (P/Invoke) and Swift.
*
* Its parts:
* - dmc_session: the AT conversation with dmodemd: commands and their
* responses, the call's state from the result codes (RING, CONNECT,
* NO CARRIER), the escape to command mode and hanging up, and the
* stream for the app's terminal view.
* - dmc_model: the modem's settings, from AT!M, for a native settings
* page.
* - dmc_diag: the last call's statistics, from AT#UD (Microsoft's
* Unimodem diagnostics), as labelled rows.
* - dmc_vt: a terminal emulator, the app's ported to C: the AT
* console and the full-screen configurator (AT!CF), and the BBSes and
* hosts reached, as any of the terminals of the DEC VT line, xterm, a
* PC's ANSI-BBS, the Commodores', the Ataris', Viewdata, the Minitel
* and the Tektronix 4014.
* - dmc_daemon_*: starting dmodemd and reading what it prints.
* - dmc_net: a remote login's protocol (Telnet, rlogin) on a TCP
* connection the app makes, for the Remote page.
* - dmc_voice_*: voice calls on the session (V.253's voice mode: the
* call's audio both ways, 8 kHz), the answering machine that takes
* a message, and WAV files for greetings and messages.
*
* Strings are UTF-8. A const char * the library returns stays valid
* until the next call on the same object.
*/
#ifndef DMODEMCTL_H
#define DMODEMCTL_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32) && defined(DMC_BUILD_DLL)
#define DMC_API __declspec(dllexport)
#elif defined(_WIN32) && defined(DMC_USE_DLL)
#define DMC_API __declspec(dllimport)
#elif defined(__GNUC__)
#define DMC_API __attribute__((visibility("default")))
#else
#define DMC_API
#endif
/* the library's version: major * 10000 + minor * 100 + patch */
#define DMC_VERSION 10300
DMC_API int dmc_version(void);
/*
* The session
*/
typedef struct dmc_session dmc_session;
/* (the enums have no tags: Swift takes their names as plain
constants) */
/* the call's state, as the result codes tell it (dmc_state()) */
enum {
DMC_CLOSED = 0, /* no DTE open */
DMC_IDLE, /* command mode, on hook */
DMC_DIALING, /* ATD sent, no result yet */
DMC_RINGING, /* RING heard, not answered */
DMC_ANSWERING, /* ATA sent, no result yet */
DMC_ONLINE, /* CONNECT: data mode */
DMC_ONLINE_COMMAND, /* escaped (+++) during a call */
DMC_HANGING_UP, /* going back on hook */
DMC_CONFIGURATOR, /* AT!C, AT!CF or AT!CT runs */
DMC_VOICE, /* a voice call: its audio both ways */
DMC_VOICEMAIL /* the answering machine has the call */
};
/* what dmc_next_event() reports */
enum {
DMC_EV_NONE = 0,
/* a command of dmc_command()'s is done: tag, ok, text (its lines,
apart by '\n', without the echo and the final result), result
(the final result: OK, ERROR, CONNECT 33600..., or "timeout") */
DMC_EV_RESPONSE,
/* the state changed: state */
DMC_EV_STATE,
/* a result code nobody waited for (RING, NO CARRIER...): result */
DMC_EV_RESULT,
/* caller ID after a RING: text "NMBR=5551234" and the like */
DMC_EV_CALLER,
/* in a voice call, what the modem heard on the line: text its
<DLE> code ("5" a DTMF digit, "l" the far end hung up, "b" a busy
tone), result its name ("digit", "hangup", "busy") */
DMC_EV_VOICE,
/* the answering machine is done: ok 1 with a message
(dmc_voice_message()), 0 if the caller left none; text the
caller's number, if caller ID gave it */
DMC_EV_MESSAGE
};
typedef struct dmc_event {
int type;
int tag;
int ok;
int state;
const char *text;
const char *result;
} dmc_event;
/* flags of dmc_command() */
enum {
/* its echo and response kept out of the terminal stream (the app's
own queries: AT!M, AT#UD) */
DMC_QUIET = 1
};
DMC_API dmc_session *dmc_session_new(void);
DMC_API void dmc_session_free(dmc_session *s);
/* the DTE opened (state IDLE) or closed (state CLOSED); either clears
what was queued */
DMC_API void dmc_open(dmc_session *s, int64_t now_ms);
DMC_API void dmc_close(dmc_session *s);
/* bytes the modem sent */
DMC_API void dmc_feed(dmc_session *s, const char *data, int n);
/* bytes the user typed in the terminal view, sent as they are (the
session reads the command lines in them, to follow ATD, ATA, ATH and
AT!C typed by hand) */
DMC_API void dmc_type(dmc_session *s, const char *data, int n);
/* bytes to the far end as they are, during a call (a file transfer's):
not taken as typed (no escape, no command) */
DMC_API void dmc_send(dmc_session *s, const char *data, int n);
/* the time now: runs the timers (a command's timeout, the escape's
guard times); returns the ms until it next needs to be called, -1 if
only when something happens */
DMC_API int dmc_poll(dmc_session *s, int64_t now_ms);
/* bytes to write to the modem: up to max into buf, how many */
DMC_API int dmc_output(dmc_session *s, char *buf, int max);
/* how many bytes dmc_output has for the DTE now */
DMC_API int dmc_output_waiting(const dmc_session *s);
/* bytes for the terminal view: up to max into buf, how many (what the
modem sent, less the DMC_QUIET commands') */
DMC_API int dmc_terminal(dmc_session *s, char *buf, int max);
/* the next event into *ev: 1, or 0 for none */
DMC_API int dmc_next_event(dmc_session *s, dmc_event *ev);
/* an AT command (with or without the AT, no CR), queued behind any
other; timeout_ms 0 for the usual (5 s, ATD and ATA two minutes);
returns its tag (above 0) for the DMC_EV_RESPONSE, or -1 (closed,
or online) */
DMC_API int dmc_command(dmc_session *s, const char *cmd, int flags,
int timeout_ms);
/* dial a number (ATD), answer (ATA): a tag as dmc_command()'s */
DMC_API int dmc_dial(dmc_session *s, const char *number);
DMC_API int dmc_answer(dmc_session *s);
/* hang up whatever the state: online, the escape (+++, with its guard
times) and ATH; dialling, a key to stop it; else ATH */
DMC_API void dmc_hangup(dmc_session *s);
DMC_API int dmc_state(const dmc_session *s);
/* the state's name for people: "Idle", "Dialling", "Online" */
DMC_API const char *dmc_state_name(int state);
/* the last CONNECT's text ("CONNECT 33600/ARQ/V34/LAPM/V42BIS"), its
rate (0 none), the caller ID's number and name of the last RING */
DMC_API const char *dmc_connect_text(const dmc_session *s);
DMC_API int dmc_connect_rate(const dmc_session *s);
DMC_API const char *dmc_caller_number(const dmc_session *s);
DMC_API const char *dmc_caller_name(const dmc_session *s);
/*
* Voice calls
*
* A voice call is the modem in voice mode (AT+FCLASS=8) with its audio
* both ways (AT+VTR), G.711 mu-law on the DTE: the library sends ours
* at the line's pace from dmc_poll() (call it every 20 ms or so in a
* call: dmc_poll() says so) and gives the far end's to dmc_voice_read(),
* both as 16-bit samples at 8000 a second. dmc_hangup() ends a call,
* and the far end's hanging up does too (DMC_EV_VOICE "l"); either way
* the modem goes back to data mode.
*/
/* the sample rate of voice calls, messages and greetings */
#define DMC_VOICE_RATE 8000
/* dial a voice call (OK when the far end answers, BUSY, NO ANSWER);
answer the ringing call as a voice call: a tag as dmc_command()'s,
-1 if the modem is not idle (or ringing, to answer) */
DMC_API int dmc_voice_dial(dmc_session *s, const char *number);
DMC_API int dmc_voice_answer(dmc_session *s);
/* the far end's samples: up to max into pcm, how many (a second at
most is kept: the oldest are dropped if they are not read) */
DMC_API int dmc_voice_read(dmc_session *s, int16_t *pcm, int max);
/* our samples (the microphone's), sent at the line's pace; silence
when there are none, and the oldest dropped when more than a third
of a second waits */
DMC_API void dmc_voice_write(dmc_session *s, const int16_t *pcm, int n);
/* a DTMF digit (0-9, *, #, A-D) played into the call, after any
others still playing; 0, or -1 for no call or no digit */
DMC_API int dmc_voice_dtmf(dmc_session *s, char digit);
/*
* The answering machine
*
* It answers the ringing call in voice mode, plays the greeting, a
* beep, and records the caller's message: until they hang up, are
* silent for silence_s seconds, or max_s seconds have gone. Then it
* hangs up, with DMC_EV_MESSAGE. While it runs (DMC_VOICEMAIL) the
* caller can be heard with dmc_voice_read() (screening), and
* dmc_voice_pickup() makes it a voice call.
*/
/* the greeting (8 kHz samples, copied; none: the beep alone) and the
message's limits (0: 120 s and 7 s) */
DMC_API void dmc_voicemail_set(dmc_session *s, const int16_t *greeting,
int n, int max_s, int silence_s);
/* answer the ringing call with the answering machine: a tag as
dmc_voice_answer()'s */
DMC_API int dmc_voicemail_answer(dmc_session *s);
/* the answering machine answers by itself after rings RINGs (0 never,
the default) */
DMC_API void dmc_voicemail_auto(dmc_session *s, int rings);
/* the call the answering machine has, taken as a voice call (its
message dropped): 0, or -1 if it has none */
DMC_API int dmc_voice_pickup(dmc_session *s);
/* the last message's samples into *pcm (valid until the next message):
how many */
DMC_API int dmc_voice_message(const dmc_session *s, const int16_t **pcm);
/* the RINGs of the call ringing now */
DMC_API int dmc_ring_count(const dmc_session *s);
/*
* Sound files (greetings and messages)
*/
/* the 44-byte header of a WAV file of n 16-bit samples, 8 kHz, mono,
into buf (44 bytes): 44 */
DMC_API int dmc_wav_header(char *buf, int n);
/* a sound file's samples at 8 kHz, mono, 16-bit: how many, *pcm then
allocated (dmc_free() it); -1 if it is not one this reads. It reads
WAV (PCM of 8, 16, 24 or 32 bits, 32 or 64-bit floats, A-law, mu-law,
IMA and Microsoft ADPCM), AIFF and AIFF-C (PCM, floats, A-law,
mu-law) and Sun/NeXT .au, of any rate and channels. (The app reads
MP3 and the like with the ACM codecs.) */
DMC_API int dmc_audio_decode(const char *data, int n, int16_t **pcm);
/* (dmc_audio_decode's old name) */
DMC_API int dmc_wav_decode(const char *data, int n, int16_t **pcm);
DMC_API void dmc_free(void *p);
/*
* The settings model (AT!M)
*/
typedef struct dmc_model dmc_model;
enum { DMC_PICK = 0, DMC_NUMBER, DMC_TEXT };
/* the model from AT!M's response text (dmc_event.text); NULL if it is
not one */
DMC_API dmc_model *dmc_model_parse(const char *text);
DMC_API void dmc_model_free(dmc_model *m);
DMC_API int dmc_model_count(const dmc_model *m);
/* setting i's fields */
DMC_API const char *dmc_setting_key(const dmc_model *m, int i);
DMC_API int dmc_setting_kind(const dmc_model *m, int i);
DMC_API const char *dmc_setting_value(const dmc_model *m, int i);
DMC_API const char *dmc_setting_default(const dmc_model *m, int i);
DMC_API long dmc_setting_lo(const dmc_model *m, int i);
DMC_API long dmc_setting_hi(const dmc_model *m, int i);
DMC_API const char *dmc_setting_form(const dmc_model *m, int i);
DMC_API const char *dmc_setting_group(const dmc_model *m, int i);
DMC_API const char *dmc_setting_label(const dmc_model *m, int i);
DMC_API const char *dmc_setting_help(const dmc_model *m, int i);
DMC_API int dmc_setting_choices(const dmc_model *m, int i);
DMC_API const char *dmc_choice_value(const dmc_model *m, int i, int c);
DMC_API const char *dmc_choice_name(const dmc_model *m, int i, int c);
DMC_API const char *dmc_choice_label(const dmc_model *m, int i, int c);
/* the choice of setting i whose value is v, -1 none */
DMC_API int dmc_setting_choice_of(const dmc_model *m, int i,
const char *v);
/* the setting whose key is key, -1 none */
DMC_API int dmc_model_find(const dmc_model *m, const char *key);
/* the groups, in the order the settings list them */
DMC_API int dmc_model_groups(const dmc_model *m);
DMC_API const char *dmc_model_group(const dmc_model *m, int g);
/* "" if setting i takes value, else why not */
DMC_API const char *dmc_setting_check(const dmc_model *m, int i,
const char *value);
/* the command that sets setting i to value ("AT" and its form, the
value in it), "" if it does not take it */
DMC_API const char *dmc_setting_command(const dmc_model *m, int i,
const char *value);
/* setting i's value now value (after its command's OK) */
DMC_API void dmc_setting_set(dmc_model *m, int i, const char *value);
/*
* The last call's statistics (AT#UD)
*/
typedef struct dmc_diag dmc_diag;
/* the statistics from AT#UD's response text; never NULL */
DMC_API dmc_diag *dmc_diag_parse(const char *text);
DMC_API void dmc_diag_free(dmc_diag *d);
/* how many rows, each its key (the specification's, hexadecimal), its
label and its value for people ("33600 bit/s", "V.34") */
DMC_API int dmc_diag_count(const dmc_diag *d);
DMC_API int dmc_diag_key(const dmc_diag *d, int i);
DMC_API const char *dmc_diag_label(const dmc_diag *d, int i);
DMC_API const char *dmc_diag_value(const dmc_diag *d, int i);
/* the raw value of key, NULL if it was not reported */
DMC_API const char *dmc_diag_raw(const dmc_diag *d, int key);
/* there was a call to report (key 1 not "no previous call") */
DMC_API int dmc_diag_has_call(const dmc_diag *d);
/*
* The connection path
*
* The picture at the top of the Settings page of how a call is made, as
* PCOMM's "Connection Overview" draws its link: four steps, left to right,
* each with its role above its icon and what it is below, one line
* joining them. Idle, each step is as the line settings set it up (ready,
* or something still to set); starting, calling and online, as it is now.
* The words are here so that every app says the same; each draws them.
*/
typedef struct dmc_path dmc_path;
/* the line settings' kinds of line */
enum {
DMC_LINE_SIP = 0, /* dmodemd on a SIP account (or none) */
DMC_LINE_USB, /* dmodemd on a USB modem's phone line */
DMC_LINE_CODEC, /* dmodemd on a softmodem codec (ALSA) */
DMC_LINE_DEVICE, /* a modem that already runs, at a device */
DMC_LINE_TCP, /* dmodemd that already runs, over TCP */
DMC_LINE_COM /* a modem on a COM port */
};
/* a step's state: ready (set up, idle), something to set first, not in
use, starting or connecting, in the call */
enum {
DMC_STEP_READY = 0, DMC_STEP_SETUP, DMC_STEP_OFF, DMC_STEP_WORKING,
DMC_STEP_ACTIVE
};
/* what a step is, for its icon */
enum {
DMC_KIND_TERMINAL = 0, DMC_KIND_SOFTMODEM, DMC_KIND_MODEM,
DMC_KIND_SIP, DMC_KIND_USB, DMC_KIND_CODEC, DMC_KIND_SERIAL,
DMC_KIND_NETWORK, DMC_KIND_PHONE_NETWORK, DMC_KIND_SIP_ADDRESS,
DMC_KIND_PHONE_LINE
};
DMC_API dmc_path *dmc_path_new(void);
DMC_API void dmc_path_free(dmc_path *p);
/* the line settings: the kind of line (DMC_LINE_*), where it is (--usb's
device, the codec, the device's path, the TCP address, the COM port;
NULL or "" for none), and the SIP account: none (anonymous), its user
and server, taking calls (registering) */
DMC_API void dmc_path_set_line(dmc_path *p, int line, const char *where,
int sip_anonymous, const char *sip_user,
const char *sip_server, int listen);
/* now: dmodemd (or the device) started, the session's state
(dmc_state(), DMC_CLOSED for none), the CONNECT line online */
DMC_API void dmc_path_set_live(dmc_path *p, int running, int state,
const char *connect);
/* the steps: how many, each one's kind, state (DMC_STEP_*), role ("Modem",
the label above it), title ("D-Modem") and what it is ("Registers as
alice@example.com") */
DMC_API int dmc_path_steps(const dmc_path *p);
DMC_API int dmc_path_kind(const dmc_path *p, int i);
DMC_API int dmc_path_state(const dmc_path *p, int i);
DMC_API const char *dmc_path_role(const dmc_path *p, int i);
DMC_API const char *dmc_path_title(const dmc_path *p, int i);
DMC_API const char *dmc_path_detail(const dmc_path *p, int i);
/* the line from step i to the next: the lesser of the two's states
(off, then to set, working, ready, active) */
DMC_API int dmc_path_link(const dmc_path *p, int i);
/* the whole in a line: what needs setting, or what it's doing, or that
it's ready */
DMC_API const char *dmc_path_headline(const dmc_path *p);
/* some step is still to set */
DMC_API int dmc_path_needs_setup(const dmc_path *p);
/*
* The terminal screen
*
* A terminal emulator: the app's (D-Modem/app) ported to C, as one of
* many kinds of terminal (a profile): DEC's VT52 to VT525, xterm, a PC's
* ANSI-BBS (with Avatar, RIPscrip and Amiga ANSI), the Commodores'
* PETSCII, the Atari's ATASCII and ST, Viewdata, the Minitel and the
* Tektronix 4014. Bytes from the remote go to dmc_vt_feed(); what it
* answers (dmc_vt_reply()) and what keys send (dmc_vt_key_mods(),
* dmc_vt_char_bytes()) go back to it. A view draws each cell from
* dmc_vt_cell(): its character, its colours resolved, its attributes, and
* where the profile has its machine's font, the glyph's bitmap.
*/
typedef struct dmc_vt dmc_vt;
/* a cell's attributes (dmc_vt_attr) */
enum {
DMC_BOLD = 1,
DMC_UNDERLINE = 2,
DMC_REVERSE = 4
};
/* the keys dmc_vt_key() encodes (the values stay as they are: new ones
are added at the end) */
enum {
DMC_KEY_UP = 1, DMC_KEY_DOWN, DMC_KEY_RIGHT, DMC_KEY_LEFT,
DMC_KEY_HOME, DMC_KEY_END, DMC_KEY_PGUP, DMC_KEY_PGDN,
DMC_KEY_INSERT, DMC_KEY_DELETE, DMC_KEY_BACKTAB,
DMC_KEY_F1, DMC_KEY_F2, DMC_KEY_F3, DMC_KEY_F4, DMC_KEY_F5,
DMC_KEY_F6, DMC_KEY_F7, DMC_KEY_F8, DMC_KEY_F9, DMC_KEY_F10,
DMC_KEY_ENTER, DMC_KEY_BACKSPACE, DMC_KEY_TAB, DMC_KEY_ESCAPE,
DMC_KEY_F11, DMC_KEY_F12,
/* an LK201's F13-F20 (F15 its Help, F16 its Do), Find and Select */
DMC_KEY_F13, DMC_KEY_F14, DMC_KEY_F15, DMC_KEY_F16, DMC_KEY_F17,
DMC_KEY_F18, DMC_KEY_F19, DMC_KEY_F20, DMC_KEY_FIND, DMC_KEY_SELECT,
/* the DEC keypad */
DMC_KEY_PF1, DMC_KEY_PF2, DMC_KEY_PF3, DMC_KEY_PF4,
DMC_KEY_KP_0, DMC_KEY_KP_1, DMC_KEY_KP_2, DMC_KEY_KP_3, DMC_KEY_KP_4,
DMC_KEY_KP_5, DMC_KEY_KP_6, DMC_KEY_KP_7, DMC_KEY_KP_8, DMC_KEY_KP_9,
DMC_KEY_KP_MINUS, DMC_KEY_KP_COMMA, DMC_KEY_KP_PERIOD, DMC_KEY_KP_ENTER
};
/* the modifiers held with a key */
enum { DMC_MOD_SHIFT = 1, DMC_MOD_ALT = 2, DMC_MOD_CTRL = 4 };
/* the character sets the remote may speak (a profile can have its own) */
enum { DMC_CHARSET_UTF8, DMC_CHARSET_CP437, DMC_CHARSET_LATIN1 };
/* a cell as a view draws it (dmc_vt_cell) */
enum {
DMC_CELL_BOLD = 1, /* a heavy face (bold not shown as bright) */
DMC_CELL_ITALIC = 2,
DMC_CELL_UNDERLINE = 4,
DMC_CELL_DOUBLE_UNDERLINE = 8,
DMC_CELL_CURLY_UNDERLINE = 16,
DMC_CELL_STRIKE = 32,
DMC_CELL_OVERLINE = 64,
DMC_CELL_BLINK = 128, /* drawn blank in the blink's off phase */
DMC_CELL_INVISIBLE = 256, /* not drawn (its background is) */
DMC_CELL_WIDE = 512, /* two cells wide: the next is its tail */
DMC_CELL_WIDE_TAIL = 1024, /* the right half of the one before */
DMC_CELL_IMAGE = 2048, /* a picture's tile (dmc_vt_cell_image) */
DMC_CELL_GLYPH = 4096, /* drawn from a bitmap (dmc_vt_glyph_row) */
DMC_CELL_COMBINING = 8192, /* has combining marks (dmc_vt_cell_text) */
DMC_CELL_LINK = 16384 /* a hyperlink (dmc_vt_cell_link) */
};
typedef struct dmc_cell {
uint32_t ch; /* a code point (32 blank, 0 a wide tail) */
uint32_t fg, bg; /* 0xRRGGBB, resolved (bold, inverse ...) */
int flags; /* DMC_CELL_* */
} dmc_cell;
/* where a cell's tile is in a picture */
typedef struct dmc_image {
uint32_t id; /* the same while the picture is */
int width, height; /* the picture's pixels */
int cell_width, cell_height; /* its tiles' size */
int tx, ty; /* this cell's tile */
} dmc_image;
/* the line sizes (DECDWL, DECDHL) */
enum {
DMC_LINE_SINGLE, DMC_LINE_DOUBLE_WIDTH, DMC_LINE_DOUBLE_TOP,
DMC_LINE_DOUBLE_BOTTOM
};
/* a screen of cols by rows, with scrollback lines kept above it; an
xterm until dmc_vt_set_profile() */
DMC_API dmc_vt *dmc_vt_new(int cols, int rows, int scrollback);
DMC_API void dmc_vt_free(dmc_vt *t);
DMC_API void dmc_vt_resize(dmc_vt *t, int cols, int rows);
/* everything as at the start, the scrollback cleared */
DMC_API void dmc_vt_reset(dmc_vt *t);
DMC_API int dmc_vt_cols(const dmc_vt *t);
DMC_API int dmc_vt_rows(const dmc_vt *t);
/* bytes from the remote (dmc_terminal()'s) */
DMC_API void dmc_vt_feed(dmc_vt *t, const char *data, int n);
/* the screen's answers to the remote's questions (where the cursor is,
what terminal it is), to write to it as if typed */
DMC_API int dmc_vt_reply(dmc_vt *t, char *buf, int max);
/* the scrollback's size: the newest lines kept, the oldest dropped */
DMC_API void dmc_vt_set_scrollback(dmc_vt *t, int lines);
/* how many lines of scrollback there are now */
DMC_API int dmc_vt_history(const dmc_vt *t);
/* a cell: row 0 the screen's top, -1 the newest scrollback line and so
on; its character (a Unicode code point, 32 for none), colours (0 to
255 the palette, -1 the default or a 24-bit one) and attributes */
DMC_API uint32_t dmc_vt_char(const dmc_vt *t, int row, int col);
DMC_API int dmc_vt_fg(const dmc_vt *t, int row, int col);
DMC_API int dmc_vt_bg(const dmc_vt *t, int row, int col);
DMC_API int dmc_vt_attr(const dmc_vt *t, int row, int col);
/* a cell as it is drawn: 0 off the screen (c then blank) */
DMC_API int dmc_vt_cell(const dmc_vt *t, int row, int col, dmc_cell *c);
/* a cell's character with its combining marks, as UTF-8 */
DMC_API const char *dmc_vt_cell_text(dmc_vt *t, int row, int col);
/* a cell's hyperlink (OSC 8), NULL for none */
DMC_API const char *dmc_vt_cell_link(const dmc_vt *t, int row, int col);
/* the picture a cell shows a tile of: its pixels (0xAARRGGBB, width *
height, not premultiplied), NULL for none */
DMC_API const uint32_t *dmc_vt_cell_image(const dmc_vt *t, int row, int col,
dmc_image *im);
/* a row's size (DMC_LINE_*): its cells twice as wide, and for double
height the top or bottom half of them */
DMC_API int dmc_vt_line_size(const dmc_vt *t, int row);
/* a row as UTF-8 text, trailing blanks dropped */
DMC_API const char *dmc_vt_text(dmc_vt *t, int row);
/* the text from (row, col) to (row2, col2), inclusive: wrapped lines
joined, the others ended with a newline */
DMC_API const char *dmc_vt_text_range(dmc_vt *t, int row, int col, int row2,
int col2);
DMC_API int dmc_vt_cursor_row(const dmc_vt *t);
DMC_API int dmc_vt_cursor_col(const dmc_vt *t);
DMC_API int dmc_vt_cursor_visible(const dmc_vt *t);
/* DECSCUSR: 0 the view's; 1, 2 block; 3, 4 underline; 5, 6 bar */
DMC_API int dmc_vt_cursor_style(const dmc_vt *t);
/* the screen changed since the last call (and clears the mark) */
DMC_API int dmc_vt_changed(dmc_vt *t);
/* the bytes a key sends, into buf: how many (dmc_vt_key: no modifiers) */
DMC_API int dmc_vt_key(const dmc_vt *t, int key, char *buf, int max);
DMC_API int dmc_vt_key_mods(dmc_vt *t, int key, int mods, char *buf, int max);
/* the bytes a character typed (or pasted) sends, as this terminal sends
it (a Commodore's PETSCII, Ctrl's control codes, Alt as ESC) */
DMC_API int dmc_vt_char_bytes(dmc_vt *t, uint32_t cp, int mods, char *buf,
int max);
/* what Enter sends (0 CR, 1 CR LF, 2 LF) and Backspace (0x08 or 0x7f) */
DMC_API void dmc_vt_set_enter(dmc_vt *t, int mode);
DMC_API void dmc_vt_set_backspace(dmc_vt *t, int code);
/* HyperTerminal's ASCII Setup, for the received data: an LF added after
each CR (the LF of a CR LF is not doubled), each byte set to 7 bits,
and no wrap at the right margin (the last column is written again) */
#define DMC_VT_ASCII_ADD_LF 1
#define DMC_VT_ASCII_7BIT 2
#define DMC_VT_ASCII_NO_WRAP 4
DMC_API void dmc_vt_set_ascii(dmc_vt *t, int flags);
DMC_API int dmc_vt_get_ascii(const dmc_vt *t);
/* a mouse event, when the remote asked for them: button 0-2, 64 and 65
the wheel; the bytes to send (0: none) */
DMC_API int dmc_vt_mouse_wanted(const dmc_vt *t);
DMC_API int dmc_vt_mouse(dmc_vt *t, int button, int col, int row, int press,
int motion, int mods, char *buf, int max);
/* a click at (fx, fy), fractions of the screen from its top left: what
it sends (a RIPscrip button's), 0 for nothing */
DMC_API int dmc_vt_tap(dmc_vt *t, double fx, double fy, char *buf, int max);
/* the remote asked for pastes bracketed (ESC [200~ ... ESC [201~) */
DMC_API int dmc_vt_bracketed_paste(const dmc_vt *t);
/* the focus's change, when the remote asked to be told */
DMC_API int dmc_vt_focus(dmc_vt *t, int focused, char *buf, int max);
/* the kinds of terminal, in the pickers' order: their ids (kept in
settings), names, the TERM for SSH and the TERMINAL-TYPE for telnet */
DMC_API int dmc_vt_profile_count(void);
DMC_API const char *dmc_vt_profile_id(int i);
DMC_API const char *dmc_vt_profile_label(int i);
DMC_API const char *dmc_vt_profile_term(const char *id);
DMC_API const char *dmc_vt_profile_telnet(const char *id);
/* the kind of terminal it is (1), or 0 for an id not known */
DMC_API int dmc_vt_set_profile(dmc_vt *t, const char *id);
DMC_API const char *dmc_vt_get_profile(const dmc_vt *t);
/* the user's character set, for the profiles that haven't their own */
DMC_API void dmc_vt_set_charset(dmc_vt *t, int charset);
/* the columns and rows the view should fit (DECCOLM's 80 or 132, a
Commodore's 40x25), 0 for as many as fit */
DMC_API int dmc_vt_requested_cols(const dmc_vt *t);
DMC_API int dmc_vt_requested_rows(const dmc_vt *t);
/* a cell's size in pixels as the view draws it (sixel images are
measured in it, and it is reported to the remote) */
DMC_API void dmc_vt_set_cell_pixels(dmc_vt *t, int w, int h);
/* the theme: the default foreground, background and cursor (0xRRGGBB) and
the 16 colours (NULL: kept); bold shown as the bright colours */
DMC_API void dmc_vt_set_theme(dmc_vt *t, uint32_t fg, uint32_t bg,
uint32_t cursor, const uint32_t *palette16);
DMC_API void dmc_vt_set_bold_bright(dmc_vt *t, int on);
/* the screen's background, foreground and cursor as shown now (a
machine's own, or the remote's, or the theme's) */
DMC_API uint32_t dmc_vt_background(const dmc_vt *t);
DMC_API uint32_t dmc_vt_foreground(const dmc_vt *t);
DMC_API uint32_t dmc_vt_cursor_color(const dmc_vt *t);
/* the bitmap font the profile's machine had (its cell's size: 1), 0 for
the view's own font */
DMC_API int dmc_vt_glyph_cell(const dmc_vt *t, int *w, int *h);
/* whether cp is drawn from a bitmap (the machine's font, a soft
character), and its size */
DMC_API int dmc_vt_glyph(const dmc_vt *t, uint32_t cp, int *w, int *h);
/* row (0 top) of cp's bitmap, its leftmost pixel bit w - 1 */
DMC_API uint32_t dmc_vt_glyph_row(const dmc_vt *t, uint32_t cp, int row);
/* what the status line below the screen shows ("" for none: no line) */
DMC_API const char *dmc_vt_status_line(dmc_vt *t);
/* the window's title as the remote set it, and whether it changed */
DMC_API const char *dmc_vt_title(dmc_vt *t);
DMC_API int dmc_vt_title_changed(const dmc_vt *t);
/* how many times the bell rang since the last call */
DMC_API int dmc_vt_bells(dmc_vt *t);
/* ANSI music: the next note to play (1), its pitch in hundredths of a
hertz (0 a rest), how long it sounds and the silence after it */
DMC_API int dmc_vt_music(dmc_vt *t, uint32_t *hz100, int *ms, int *rest_ms);
/* what the remote sent to the printer (UTF-8), taken */
DMC_API int dmc_vt_printed(dmc_vt *t, char *buf, int max);
/* the line speed the remote asked its text be shown at (CSI * r), 0 */
DMC_API int dmc_vt_emulated_bps(const dmc_vt *t);
/* the RGB of palette colour c (0 to 15), as 0xRRGGBB */
DMC_API uint32_t dmc_vt_palette(int c);
/*
* dmodemd
*/
/* a line dmodemd printed when it started: 1 and its DTE (a pty's
path, "TCP 127.0.0.1:2323", "pipe \\.\pipe\dmodem") into buf if it is
the line that says the modem is ready, else 0 */
DMC_API int dmc_daemon_ready(const char *line, char *buf, int max);
/* a line that is an error of dmodemd's ("error: ..."): 1 */
DMC_API int dmc_daemon_error(const char *line);
/*
* Remote logins
*
* Telnet and rlogin on a TCP connection the app makes (SSH is the
* system's ssh in a pty, so it needs nothing here). Like the session it
* does no I/O: hand it what the socket read, write what dmc_net_output()
* gives, show what dmc_net_screen() gives.
*/
typedef struct dmc_net dmc_net;
enum { DMC_NET_TELNET = 1, DMC_NET_RLOGIN, DMC_NET_SSH };
/* the protocol's port (23, 513, 22) and its name ("Telnet") */
DMC_API int dmc_net_default_port(int proto);
DMC_API const char *dmc_net_name(int proto);
/* a login by Telnet or rlogin: user is rlogin's (Telnet's may be ""),
term the terminal type the server is told, the screen's size */
DMC_API dmc_net *dmc_net_new(int proto, const char *user, const char *term,
int cols, int rows);
DMC_API void dmc_net_free(dmc_net *n);
/* the connection made: rlogin's handshake, Telnet's first offers */
DMC_API void dmc_net_connected(dmc_net *n);
/* bytes the socket read */
DMC_API void dmc_net_feed(dmc_net *n, const char *data, int len);
/* an urgent (out-of-band) byte the socket read: rlogin's control byte */
DMC_API void dmc_net_urgent(dmc_net *n, int byte);
/* the bytes for the terminal: how many */
DMC_API int dmc_net_screen(dmc_net *n, char *buf, int max);
/* bytes typed */
DMC_API void dmc_net_type(dmc_net *n, const char *data, int len);
/* the bytes to write to the socket: how many */
DMC_API int dmc_net_output(dmc_net *n, char *buf, int max);
/* the screen's new size, told to the server */
DMC_API void dmc_net_resize(dmc_net *n, int cols, int rows);
/* a break to the server (Telnet's IAC BRK): 1, or 0 when the protocol has
none (rlogin) */
DMC_API int dmc_net_break(dmc_net *n);
/* ------------------------------------------------------------------
* File transfers on a terminal's line, as the Android app has them:
* ZMODEM, YMODEM, XMODEM, XMODEM-1K, Kermit, Intel HEX, Motorola
* S-records and plain text. A transfer runs on a thread of its own; the
* app feeds it what comes from the remote (in place of the terminal),
* writes what it gives to the remote, and reads its status.
*/
enum {
DMC_XFER_ZMODEM,
DMC_XFER_YMODEM,
DMC_XFER_YMODEM_G, /* YMODEM with no ACKs (an error-free line) */
DMC_XFER_XMODEM,
DMC_XFER_XMODEM_1K,
DMC_XFER_KERMIT,
DMC_XFER_INTEL_HEX,
DMC_XFER_SREC,
DMC_XFER_TEXT,
DMC_XFER_PROTOCOLS
};
/* a protocol's name ("ZMODEM"); whether it sends more than one file */
DMC_API const char *dmc_xfer_label(int protocol);
DMC_API int dmc_xfer_batch(int protocol);
/* what to type at the remote's shell for its end: remote_sends, its send
(the files' names go after it, "sz -b "), else its receive ("rz -b") */
DMC_API const char *dmc_xfer_command(int protocol, int remote_sends);
typedef struct dmc_xfer dmc_xfer;
/* how a transfer goes (all 0: as the protocol does by default) */
typedef struct dmc_xfer_options {
/* ZMODEM crash recovery: a part of a file that is in the folder is
continued, and a part received is kept when the transfer stops
(receiving); the receiver is asked to continue (sending) */
int resume;
/* plain text sent: a wait after each line, and after each
character, in ms */
int line_delay_ms, char_delay_ms;
/* ZMODEM with zstd stopped: files are not compressed (sending), and
compressed files are not taken (receiving). When it is not
stopped, zstd is used only where the other side can use it too
(D-Modem's BBS, GUI and app) */
int no_zstd;
} dmc_xfer_options;
/* files from the remote into folder (name: XMODEM's file, which it does
not name; Intel HEX's, S-records' and plain text's too) */
DMC_API dmc_xfer *dmc_xfer_receive(int protocol, const char *folder,
const char *name);
/* files to the remote (XMODEM, the hex records and plain text: the first) */
DMC_API dmc_xfer *dmc_xfer_send(int protocol, const char *const *paths,
int n);
/* the same, with options (NULL: the defaults) */
DMC_API dmc_xfer *dmc_xfer_receive_opt(int protocol, const char *folder,
const char *name,
const dmc_xfer_options *o);
DMC_API dmc_xfer *dmc_xfer_send_opt(int protocol, const char *const *paths,
int n, const dmc_xfer_options *o);
/* the file being received skipped, and the transfer goes on to the next
(ZMODEM and Kermit; the others ignore it) */
DMC_API void dmc_xfer_skip(dmc_xfer *x);
/* whether the protocol can skip a file (receiving) */
DMC_API int dmc_xfer_can_skip(int protocol);
/* whether the file now goes compressed with zstd (ZMODEM with zstd) */
DMC_API int dmc_xfer_zstd(dmc_xfer *x);
/* bytes from the remote */
DMC_API void dmc_xfer_feed(dmc_xfer *x, const char *data, int n);
/* bytes for the remote: how many */
DMC_API int dmc_xfer_output(dmc_xfer *x, char *buf, int max);
/* stopped: the other side told (ZMODEM's CANs, Kermit's E packet) */
DMC_API void dmc_xfer_cancel(dmc_xfer *x);
/* fn(ctx) called, on the transfer's thread, when it has bytes for the
remote or has ended (once until the next dmc_xfer_output): for an app
that posts itself a message to write them at once */
DMC_API void dmc_xfer_set_notify(dmc_xfer *x, void (*fn)(void *ctx), void *ctx);
typedef struct dmc_xfer_status {
int protocol, sending;
int running; /* 0: ended, result says how */
char file[256]; /* the file now */
long long bytes, size; /* size -1: not known */
int files; /* files done */
int errors; /* blocks sent again */
char result[256]; /* "" it went well, else why not */
} dmc_xfer_status;
DMC_API void dmc_xfer_get_status(dmc_xfer *x, dmc_xfer_status *st);
/* the names the received files got (i from 0; NULL past the last) */
DMC_API const char *dmc_xfer_received(dmc_xfer *x, int i);
/* once ended: what came after the transfer, for the terminal */
DMC_API int dmc_xfer_leftover(dmc_xfer *x, char *buf, int max);
/* the thread waited for, all freed */
DMC_API void dmc_xfer_free(dmc_xfer *x);
/* what a remote starts in what came: its sz (receive here), its rz (it
waits for files) or its kermit -s; *at where it starts */
enum {
DMC_XFER_DETECT_NONE,
DMC_XFER_DETECT_ZMODEM_SEND,
DMC_XFER_DETECT_ZMODEM_RECEIVE,
DMC_XFER_DETECT_KERMIT_SEND
};
DMC_API int dmc_xfer_detect(const char *data, int n, int *at);
#ifdef __cplusplus
}
#endif
#endif
-480
View File
@@ -1,480 +0,0 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
<https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Moe Ghoul>, 1 April 1990
Moe Ghoul, President of Vice
That's all there is to it!
-52
View File
@@ -1,52 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* daemon.c - reading what dmodemd prints as it starts (dmodemctl.h)
*
* On Linux, macOS, BSD and Haiku it says
* Use `/dev/ttyDM0' as modem device, Ctrl+C for termination.
* (the pty's own path, /dev/pts/3, when it may not make the link), and
* on Windows
* Use TCP 127.0.0.1:2323 as the modem, Ctrl+C for termination.
*/
#include <string.h>
#include "dmodemctl.h"
static int copy(const char *from, size_t n, char *buf, int max)
{
if (!buf || max <= 0)
return 1;
if (n >= (size_t)max)
n = (size_t)max - 1;
memcpy(buf, from, n);
buf[n] = '\0';
return 1;
}
int dmc_daemon_ready(const char *line, char *buf, int max)
{
if (!line)
return 0;
const char *p = strstr(line, "Use `");
if (p) {
p += 5;
const char *e = strchr(p, '\'');
if (e && strstr(e, "as modem device"))
return copy(p, (size_t)(e - p), buf, max);
}
p = strstr(line, "Use ");
if (p) {
p += 4;
const char *e = strstr(p, " as the modem");
if (e)
return copy(p, (size_t)(e - p), buf, max);
}
return 0;
}
int dmc_daemon_error(const char *line)
{
return line && !strncmp(line, "error:", 6);
}
-435
View File
@@ -1,435 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* diag.c - the last call's statistics from AT#UD (dmodemctl.h)
*
* AT#UD follows Microsoft's Unimodem Diagnostics Command Reference
* Specification, version 1.0 (D-Modem's docs/specs/umud10.rtf): lines
* "DIAG <2A4D3263 key=value ...>", the keys and values in hexadecimal
* and the code tables V.58's. Each key becomes a row with its label
* and its value for people.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dmodemctl.h"
#include "util.h"
/* how a key's value reads */
enum fmt {
F_HEX, /* as it is */
F_NUM, /* a count */
F_BPS, /* bit/s */
F_DBM, /* -dBm */
F_DB, /* dB */
F_MS, /* ms */
F_HZ, /* Hz */
F_BAUD, /* symbols a second */
F_BYTES, /* bytes */
F_TABLE, /* one of the code tables */
F_STRING, /* quoted octets */
F_VERSION /* digit.digit */
};
struct code {
unsigned v;
const char *label;
};
static const struct code setup[] = {
{ 0x0, "No previous call" },
{ 0x1, "No dial tone" },
{ 0x2, "Network busy (reorder)" },
{ 0x3, "Busy" },
{ 0x4, "No signal recognised" },
{ 0x5, "Voice" },
{ 0x6, "Text telephone" },
{ 0x7, "Data answer tone heard" },
{ 0x8, "Data calling tone heard" },
{ 0x9, "Fax answer tone heard" },
{ 0xA, "Fax calling tone heard" },
{ 0xB, "V.8bis" },
{ 0, NULL }
};
static const struct code media[] = {
{ 0x0, "Data" },
{ 0x1, "Fax" },
{ 0x2, "Voice" },
{ 0x3, "VoiceView" },
{ 0x4, "ASVD (V.61)" },
{ 0x5, "ASVD (V.34Q)" },
{ 0x6, "DSVD (Multi-Tech)" },
{ 0x7, "DSVD 1.2" },
{ 0x8, "DSVD (V.70)" },
{ 0x9, "Video telephony (H.324)" },
{ 0xA, "Other V.80 call" },
{ 0, NULL }
};
static const struct code dte_mode[] = {
{ 0x0, "Asynchronous" },
{ 0x1, "V.80 transparent synchronous" },
{ 0x2, "V.80 framed synchronous" },
{ 0, NULL }
};
/* V.58's gstnModulationSchemeActive, and the manufacturers' */
static const struct code modulation[] = {
{ 0x0, "V.17" }, { 0x1, "V.21" }, { 0x2, "V.22" },
{ 0x3, "V.22bis" }, { 0x4, "V.23" }, { 0x5, "V.23 (half duplex)" },
{ 0x6, "V.26bis" }, { 0x7, "V.26ter" }, { 0x8, "V.27ter" },
{ 0x9, "V.29" }, { 0xA, "V.32" }, { 0xB, "V.32bis" },
{ 0xC, "V.34" }, { 0xD, "V.34 half duplex" },
{ 0xE, "V.90 (PCM)" }, { 0xF, "V.91 (PCM both ways)" },
{ 0x80, "X2" }, { 0x81, "K56flex" }, { 0x82, "V.FC" },
{ 0x83, "V.32terbo" }, { 0x84, "Bell 212A" }, { 0x85, "Bell 103" },
{ 0, NULL }
};
static const struct code error_control[] = {
{ 0x0, "None" },
{ 0x1, "V.42 LAPM" },
{ 0x2, "MNP" },
{ 0x80, "MNP 10" },
{ 0x81, "ECP" },
{ 0x82, "ETC" },
{ 0, NULL }
};
static const struct code compression[] = {
{ 0x0, "None" },
{ 0x1, "V.42bis" },
{ 0x80, "MNP 5" },
{ 0x81, "V.44" },
{ 0x82, "zstd" },
{ 0, NULL }
};
static const struct code flow[] = {
{ 0x0, "Off" },
{ 0x1, "XON/XOFF" },
{ 0x2, "RTS/CTS" },
{ 0, NULL }
};
/* V.58's callCleared */
static const struct code cleared[] = {
{ 0x0, "Cause unknown" },
{ 0x1, "No previous call" },
{ 0x2, "Call in progress" },
{ 0x3, "Call waiting signal" },
{ 0x4, "Delayed" },
{ 0x19, "Inactivity timer" },
{ 0x1F, "DTR off stops the dial" },
{ 0x20, "DTR turned off" },
{ 0x28, "No number" },
{ 0x29, "Blacklisted number" },
{ 0x2A, "Too many attempts" },
{ 0x2B, "Extension off hook" },
{ 0x2C, "No answer in time (S7)" },
{ 0x2D, "Incoming call while dialling" },
{ 0x2E, "Loop current lost" },
{ 0x2F, "No dial tone" },
{ 0x30, "Voice" },
{ 0x31, "Reorder tone" },
{ 0x32, "SIT tone" },
{ 0x33, "Busy" },
{ 0x34, "Long space" },
{ 0x3C, "Carrier lost" },
{ 0x3D, "Training failed" },
{ 0x3E, "No modulation in common" },
{ 0x3F, "Retrain failed" },
{ 0x40, "Too many retrains" },
{ 0x41, "The other modem hung up" },
{ 0x42, "Fax detected" },
{ 0x50, "Stopped by a key" },
{ 0x51, "Hung up (ATH)" },
{ 0x52, "Reset (ATZ)" },
{ 0x5A, "Frame reject" },
{ 0x5B, "No error control" },
{ 0x5C, "Protocol violation" },
{ 0x5D, "Too many retransmissions" },
{ 0x5E, "Negotiation failed" },
{ 0x5F, "Disconnect frame received" },
{ 0x60, "SABME frame received" },
{ 0x64, "Lost synchronisation" },
{ 0, NULL }
};
struct keyinfo {
int key;
const char *label;
int fmt;
const struct code *table;
};
static const struct keyinfo keys[] = {
{ 0x00, "Report version", F_VERSION, NULL },
{ 0x01, "Call setup", F_TABLE, setup },
{ 0x02, "Mode", F_TABLE, media },
{ 0x03, "DTE interface", F_TABLE, dte_mode },
{ 0x04, "V.8 CM", F_STRING, NULL },
{ 0x05, "V.8 JM", F_STRING, NULL },
{ 0x10, "Received level", F_DBM, NULL },
{ 0x11, "Transmit level", F_DBM, NULL },
{ 0x12, "Noise level", F_DBM, NULL },
{ 0x13, "Mean squared error", F_NUM, NULL },
{ 0x14, "Near echo loss", F_DB, NULL },
{ 0x15, "Far echo loss", F_DB, NULL },
{ 0x16, "Far echo delay", F_MS, NULL },
{ 0x17, "Round trip delay", F_MS, NULL },
{ 0x18, "V.34 INFO bits", F_HEX, NULL },
{ 0x20, "Transmit modulation", F_TABLE, modulation },
{ 0x21, "Receive modulation", F_TABLE, modulation },
{ 0x22, "Transmit symbol rate", F_BAUD, NULL },
{ 0x23, "Receive symbol rate", F_BAUD, NULL },
{ 0x24, "Transmit carrier", F_HZ, NULL },
{ 0x25, "Receive carrier", F_HZ, NULL },
{ 0x26, "First transmit rate", F_BPS, NULL },
{ 0x27, "First receive rate", F_BPS, NULL },
{ 0x30, "Carrier losses", F_NUM, NULL },
{ 0x31, "Rate renegotiations", F_NUM, NULL },
{ 0x32, "Retrains asked for", F_NUM, NULL },
{ 0x33, "Retrains granted", F_NUM, NULL },
{ 0x34, "Last transmit rate", F_BPS, NULL },
{ 0x35, "Last receive rate", F_BPS, NULL },
{ 0x40, "Error control", F_TABLE, error_control },
{ 0x41, "Frame size", F_BYTES, NULL },
{ 0x42, "Link timeouts", F_NUM, NULL },
{ 0x43, "NAKs received", F_NUM, NULL },
{ 0x44, "Compression", F_TABLE, compression },
{ 0x45, "Dictionary size", F_BYTES, NULL },
{ 0x50, "Transmit flow control", F_TABLE, flow },
{ 0x51, "Receive flow control", F_TABLE, flow },
{ 0x52, "Characters sent", F_NUM, NULL },
{ 0x53, "Characters received", F_NUM, NULL },
{ 0x54, "Characters lost sending", F_NUM, NULL },
{ 0x55, "Characters lost receiving", F_NUM, NULL },
{ 0x56, "Frames sent", F_NUM, NULL },
{ 0x57, "Frames received", F_NUM, NULL },
{ 0x58, "Frames sent again", F_NUM, NULL },
{ 0x59, "Frames received in error", F_NUM, NULL },
{ 0x60, "Why the call ended", F_TABLE, cleared },
{ 0x61, "Call waiting events", F_NUM, NULL },
{ -1, NULL, 0, NULL }
};
struct row {
int key;
char *raw, *label, *value;
};
struct dmc_diag {
struct row *rows;
int n;
};
static const struct keyinfo *info(int key)
{
for (const struct keyinfo *k = keys; k->label; k++)
if (k->key == key)
return k;
return NULL;
}
static const char *code_label(const struct code *t, unsigned v)
{
for (; t->label; t++)
if (t->v == v)
return t->label;
return NULL;
}
/* a number with thousands apart by commas */
static void grouped(char *out, size_t n, unsigned long v)
{
char digits[32];
snprintf(digits, sizeof(digits), "%lu", v);
size_t len = strlen(digits), o = 0;
for (size_t i = 0; i < len && o + 2 < n; i++) {
if (i && (len - i) % 3 == 0)
out[o++] = ',';
out[o++] = digits[i];
}
out[o] = '\0';
}
static char *shown(const struct keyinfo *k, const char *raw)
{
char out[160];
unsigned long v = strtoul(raw, NULL, 16);
char num[40];
grouped(num, sizeof(num), v);
switch (k ? k->fmt : F_HEX) {
case F_NUM:
snprintf(out, sizeof(out), "%s", num);
break;
case F_BPS:
snprintf(out, sizeof(out), "%s bit/s", num);
break;
case F_DBM:
snprintf(out, sizeof(out), "%s%lu dBm", v ? "-" : "", v);
break;
case F_DB:
snprintf(out, sizeof(out), "%lu dB", v);
break;
case F_MS:
snprintf(out, sizeof(out), "%lu ms", v);
break;
case F_HZ:
snprintf(out, sizeof(out), "%lu Hz", v);
break;
case F_BAUD:
snprintf(out, sizeof(out), "%lu baud", v);
break;
case F_BYTES:
snprintf(out, sizeof(out), "%s bytes", num);
break;
case F_TABLE: {
const char *l = code_label(k->table, (unsigned)v);
if (l)
snprintf(out, sizeof(out), "%s", l);
else
snprintf(out, sizeof(out), "Code %lX", v);
break;
}
case F_VERSION:
if (strlen(raw) == 2)
snprintf(out, sizeof(out), "%c.%c", raw[0], raw[1]);
else
snprintf(out, sizeof(out), "%s", raw);
break;
case F_STRING: {
/* the octets, apart by spaces */
size_t o = 0;
for (const char *p = raw; *p && o + 4 < sizeof(out); p++) {
if (*p == '"')
continue;
if (o && (o + 1) % 3 == 0)
out[o++] = ' ';
out[o++] = *p;
}
out[o] = '\0';
break;
}
default:
snprintf(out, sizeof(out), "%s", raw);
break;
}
return dup_str(out);
}
static void add(dmc_diag *d, int key, const char *raw, size_t n)
{
/* a key again: its last value */
for (int i = 0; i < d->n; i++)
if (d->rows[i].key == key) {
free(d->rows[i].raw);
free(d->rows[i].value);
d->rows[i].raw = dup_n(raw, n);
d->rows[i].value = shown(info(key), d->rows[i].raw);
return;
}
struct row *r = realloc(d->rows, sizeof(*r) * (size_t)(d->n + 1));
if (!r)
abort();
d->rows = r;
r = &d->rows[d->n++];
const struct keyinfo *k = info(key);
char label[32];
if (!k)
snprintf(label, sizeof(label), "Key %X", key);
r->key = key;
r->raw = dup_n(raw, n);
r->label = dup_str(k ? k->label : label);
r->value = shown(k, r->raw);
}
dmc_diag *dmc_diag_parse(const char *text)
{
dmc_diag *d = calloc(1, sizeof(*d));
if (!d)
abort();
const char *p = text ? text : "";
while ((p = strstr(p, "DIAG <")) != NULL) {
p += 6;
const char *end = strchr(p, '>');
if (!end)
break;
/* the tag (2A4D3263), then key=value pairs */
while (p < end && *p != ' ')
p++;
while (p < end) {
while (p < end && *p == ' ')
p++;
const char *eq = p;
while (eq < end && *eq != '=')
eq++;
if (eq >= end)
break;
int key = (int)strtol(p, NULL, 16);
const char *v = eq + 1, *ve = v;
if (*v == '"') {
ve = strchr(v + 1, '"');
ve = ve && ve < end ? ve + 1 : end;
} else {
while (ve < end && *ve != ' ')
ve++;
}
add(d, key, v, (size_t)(ve - v));
p = ve;
}
p = end + 1;
}
return d;
}
void dmc_diag_free(dmc_diag *d)
{
if (!d)
return;
for (int i = 0; i < d->n; i++) {
free(d->rows[i].raw);
free(d->rows[i].label);
free(d->rows[i].value);
}
free(d->rows);
free(d);
}
int dmc_diag_count(const dmc_diag *d)
{
return d ? d->n : 0;
}
int dmc_diag_key(const dmc_diag *d, int i)
{
return d && i >= 0 && i < d->n ? d->rows[i].key : -1;
}
const char *dmc_diag_label(const dmc_diag *d, int i)
{
return d && i >= 0 && i < d->n ? d->rows[i].label : "";
}
const char *dmc_diag_value(const dmc_diag *d, int i)
{
return d && i >= 0 && i < d->n ? d->rows[i].value : "";
}
const char *dmc_diag_raw(const dmc_diag *d, int key)
{
for (int i = 0; d && i < d->n; i++)
if (d->rows[i].key == key)
return d->rows[i].raw;
return NULL;
}
int dmc_diag_has_call(const dmc_diag *d)
{
const char *v = dmc_diag_raw(d, 1);
return v && strtoul(v, NULL, 16) != 0;
}
-333
View File
@@ -1,333 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* model.c - the modem's settings from AT!M (dmodemctl.h)
*
* AT!M's lines, their fields apart by tabs:
*
* model 1 <settings>
* setting <key> <kind> <value> <default> <lo> <hi> <form> <group>
* <label> <help>
* choice <value> <name> <label> (a pick's, after it)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dmodemctl.h"
#include "util.h"
struct choice {
char *value, *name, *label;
};
struct setting {
char *key, *value, *def, *form, *group, *label, *help;
int kind;
long lo, hi;
struct choice *choices;
int n_choices;
};
struct dmc_model {
struct setting *s;
int n;
char **groups;
int n_groups;
dmc_buf scratch;
char why[96];
};
/* the line's fields: up to max, how many (the line cut in place) */
static int fields(char *line, char **f, int max)
{
int n = 0;
char *p = line;
while (n < max) {
f[n++] = p;
char *t = strchr(p, '\t');
if (!t)
break;
*t = '\0';
p = t + 1;
}
return n;
}
static void add_group(dmc_model *m, const char *g)
{
for (int i = 0; i < m->n_groups; i++)
if (!strcmp(m->groups[i], g))
return;
char **p = realloc(m->groups, sizeof(*p) * (size_t)(m->n_groups + 1));
if (!p)
abort();
m->groups = p;
m->groups[m->n_groups++] = dup_str(g);
}
dmc_model *dmc_model_parse(const char *text)
{
if (!text)
return NULL;
char *copy = dup_str(text);
dmc_model *m = calloc(1, sizeof(*m));
if (!m)
abort();
int seen_model = 0, declared = -1;
char *save = copy;
while (save) {
char *line = save;
char *nl = strchr(line, '\n');
if (nl) {
*nl = '\0';
save = nl + 1;
} else {
save = NULL;
}
size_t len = strlen(line);
if (len && line[len - 1] == '\r')
line[len - 1] = '\0';
char *f[12];
int n = fields(line, f, 12);
if (!strcmp(f[0], "model") && n >= 3) {
if (atoi(f[1]) != 1)
break; /* a format we do not know */
seen_model = 1;
declared = atoi(f[2]);
} else if (!strcmp(f[0], "setting") && n >= 11 && seen_model) {
struct setting *p = realloc(m->s, sizeof(*p) *
(size_t)(m->n + 1));
if (!p)
abort();
m->s = p;
struct setting *s = &m->s[m->n++];
memset(s, 0, sizeof(*s));
s->key = dup_str(f[1]);
s->kind = !strcmp(f[2], "pick") ? DMC_PICK :
!strcmp(f[2], "number") ? DMC_NUMBER : DMC_TEXT;
s->value = dup_str(f[3]);
s->def = dup_str(f[4]);
s->lo = strtol(f[5], NULL, 10);
s->hi = strtol(f[6], NULL, 10);
s->form = dup_str(f[7]);
s->group = dup_str(f[8]);
s->label = dup_str(f[9]);
s->help = dup_str(f[10]);
add_group(m, s->group);
} else if (!strcmp(f[0], "choice") && n >= 4 && m->n) {
struct setting *s = &m->s[m->n - 1];
struct choice *c = realloc(s->choices, sizeof(*c) *
(size_t)(s->n_choices + 1));
if (!c)
abort();
s->choices = c;
c = &s->choices[s->n_choices++];
c->value = dup_str(f[1]);
c->name = dup_str(f[2]);
c->label = dup_str(f[3]);
}
}
free(copy);
if (!seen_model || (declared >= 0 && declared != m->n)) {
dmc_model_free(m);
return NULL;
}
return m;
}
void dmc_model_free(dmc_model *m)
{
if (!m)
return;
for (int i = 0; i < m->n; i++) {
struct setting *s = &m->s[i];
free(s->key);
free(s->value);
free(s->def);
free(s->form);
free(s->group);
free(s->label);
free(s->help);
for (int j = 0; j < s->n_choices; j++) {
free(s->choices[j].value);
free(s->choices[j].name);
free(s->choices[j].label);
}
free(s->choices);
}
free(m->s);
for (int i = 0; i < m->n_groups; i++)
free(m->groups[i]);
free(m->groups);
buf_free(&m->scratch);
free(m);
}
int dmc_model_count(const dmc_model *m)
{
return m ? m->n : 0;
}
static const struct setting *at(const dmc_model *m, int i)
{
static const struct setting none = { "", "", "", "", "", "", "", 0,
0, 0, NULL, 0 };
return m && i >= 0 && i < m->n ? &m->s[i] : &none;
}
const char *dmc_setting_key(const dmc_model *m, int i) { return at(m, i)->key; }
int dmc_setting_kind(const dmc_model *m, int i) { return at(m, i)->kind; }
const char *dmc_setting_value(const dmc_model *m, int i) { return at(m, i)->value; }
const char *dmc_setting_default(const dmc_model *m, int i) { return at(m, i)->def; }
long dmc_setting_lo(const dmc_model *m, int i) { return at(m, i)->lo; }
long dmc_setting_hi(const dmc_model *m, int i) { return at(m, i)->hi; }
const char *dmc_setting_form(const dmc_model *m, int i) { return at(m, i)->form; }
const char *dmc_setting_group(const dmc_model *m, int i) { return at(m, i)->group; }
const char *dmc_setting_label(const dmc_model *m, int i) { return at(m, i)->label; }
const char *dmc_setting_help(const dmc_model *m, int i) { return at(m, i)->help; }
int dmc_setting_choices(const dmc_model *m, int i) { return at(m, i)->n_choices; }
static const struct choice *choice_at(const dmc_model *m, int i, int c)
{
static const struct choice none = { "", "", "" };
const struct setting *s = at(m, i);
return c >= 0 && c < s->n_choices ? &s->choices[c] : &none;
}
const char *dmc_choice_value(const dmc_model *m, int i, int c)
{
return choice_at(m, i, c)->value;
}
const char *dmc_choice_name(const dmc_model *m, int i, int c)
{
return choice_at(m, i, c)->name;
}
const char *dmc_choice_label(const dmc_model *m, int i, int c)
{
return choice_at(m, i, c)->label;
}
int dmc_setting_choice_of(const dmc_model *m, int i, const char *v)
{
const struct setting *s = at(m, i);
for (int c = 0; c < s->n_choices; c++)
if (same_ci(s->choices[c].value, v ? v : ""))
return c;
return -1;
}
int dmc_model_find(const dmc_model *m, const char *key)
{
for (int i = 0; m && i < m->n; i++)
if (!strcmp(m->s[i].key, key ? key : ""))
return i;
return -1;
}
int dmc_model_groups(const dmc_model *m)
{
return m ? m->n_groups : 0;
}
const char *dmc_model_group(const dmc_model *m, int g)
{
return m && g >= 0 && g < m->n_groups ? m->groups[g] : "";
}
/* the value a number: digits only, within lo and hi */
static int number_ok(const struct setting *s, const char *v, char *why,
size_t n)
{
if (!*v) {
snprintf(why, n, "Enter a number");
return 0;
}
for (const char *p = v; *p; p++)
if (*p < '0' || *p > '9') {
snprintf(why, n, "Enter a number");
return 0;
}
if (strlen(v) > 10) {
snprintf(why, n, "From %ld to %ld", s->lo, s->hi);
return 0;
}
long x = strtol(v, NULL, 10);
if (x < s->lo || x > s->hi) {
snprintf(why, n, "From %ld to %ld", s->lo, s->hi);
return 0;
}
return 1;
}
const char *dmc_setting_check(const dmc_model *m, int i, const char *value)
{
static char none[] = "No such setting";
if (!m || i < 0 || i >= m->n)
return none;
char *why = ((dmc_model *)m)->why;
const size_t size = sizeof(m->why);
const struct setting *s = at(m, i);
const char *v = value ? value : "";
why[0] = '\0';
switch (s->kind) {
case DMC_PICK:
if (dmc_setting_choice_of(m, i, v) < 0)
snprintf(why, size, "Not one of the choices");
break;
case DMC_NUMBER:
number_ok(s, v, why, size);
break;
default:
/* a list of numbers, apart by commas (some may be left
out, as AT takes them) */
if (!*v)
snprintf(why, size, "Enter the values");
for (const char *p = v; *p; p++)
if ((*p < '0' || *p > '9') && *p != ',') {
snprintf(why, size,
"Numbers apart by commas");
break;
}
break;
}
return why;
}
const char *dmc_setting_command(const dmc_model *m, int i, const char *value)
{
dmc_model *mm = (dmc_model *)m;
if (!m)
return "";
buf_clear(&mm->scratch);
if (*dmc_setting_check(m, i, value))
return "";
const struct setting *s = at(m, i);
const char *v = value;
/* (a pick takes its value as the modem lists it) */
if (s->kind == DMC_PICK)
v = s->choices[dmc_setting_choice_of(m, i, value)].value;
buf_adds(&mm->scratch, "AT");
for (const char *p = s->form; *p; p++) {
if (p[0] == '%' && p[1]) {
p++;
if (*p == 's')
buf_adds(&mm->scratch, v);
else
buf_addc(&mm->scratch, *p);
} else {
buf_addc(&mm->scratch, *p);
}
}
return buf_str(&mm->scratch);
}
void dmc_setting_set(dmc_model *m, int i, const char *value)
{
if (!m || i < 0 || i >= m->n)
return;
set_str(&m->s[i].value, value);
}
-359
View File
@@ -1,359 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* net.c - a remote login's protocol over a TCP connection the app makes:
* Telnet (RFC 854) and rlogin (RFC 1282). Like the session, it
* does no I/O: the app hands it what the socket read
* (dmc_net_feed), writes what dmc_net_output gives, shows what
* dmc_net_screen gives and passes on what is typed (dmc_net_type).
*
* Telnet: the server's options answered (BINARY, ECHO and
* SUPPRESS-GO-AHEAD taken; TERMINAL-TYPE and NAWS offered; the rest
* refused), each option answered once per change so that no two ends
* loop; IAC doubled both ways; a CR typed sent as CR NUL outside binary
* mode; the window's size sent (NAWS) as it changes.
*
* rlogin: the handshake (NUL, the user twice, "term/speed"), the
* server's NUL that answers it taken off the stream, and the window's
* size sent ("\377\377ss" and four 16-bit numbers) once the server has
* asked for it with the urgent byte 0x80.
*/
#include <stdlib.h>
#include <string.h>
#include "dmodemctl.h"
#include "util.h"
enum {
IAC = 255, DONT = 254, DO = 253, WONT = 252, WILL = 251, SB = 250,
SE = 240, BRK = 243,
O_BINARY = 0, O_ECHO = 1, O_SGA = 3, O_TTYPE = 24, O_NAWS = 31
};
/* where the Telnet reader is */
enum { T_DATA, T_IAC, T_OPT, T_SB, T_SB_IAC };
struct dmc_net {
int proto;
char *user, *term;
int cols, rows;
dmc_buf screen, out;
/* Telnet */
int st, verb, last_cr;
unsigned char remote[256], local[256];
dmc_buf sb;
/* Telnet: the server asked for our size (DO NAWS) */
int naws;
/* rlogin: the server's NUL seen; it asked for the window's size */
int ready, want_size;
};
DMC_API int dmc_net_default_port(int proto)
{
switch (proto) {
case DMC_NET_TELNET:
return 23;
case DMC_NET_RLOGIN:
return 513;
case DMC_NET_SSH:
return 22;
}
return 0;
}
DMC_API const char *dmc_net_name(int proto)
{
switch (proto) {
case DMC_NET_TELNET:
return "Telnet";
case DMC_NET_RLOGIN:
return "rlogin";
case DMC_NET_SSH:
return "SSH";
}
return "";
}
DMC_API dmc_net *dmc_net_new(int proto, const char *user, const char *term,
int cols, int rows)
{
dmc_net *n = calloc(1, sizeof(*n));
if (!n)
return NULL;
n->proto = proto;
n->user = dup_str(user ? user : "");
n->term = dup_str(term && *term ? term : "xterm");
n->cols = cols;
n->rows = rows;
return n;
}
DMC_API void dmc_net_free(dmc_net *n)
{
if (!n)
return;
free(n->user);
free(n->term);
buf_free(&n->screen);
buf_free(&n->out);
buf_free(&n->sb);
free(n);
}
static void put(dmc_net *n, int a, int b, int c)
{
char v[3];
v[0] = (char)a;
v[1] = (char)b;
v[2] = (char)c;
buf_add(&n->out, v, 3);
}
/* a 16-bit number, big-endian; for Telnet an 0xff in it doubled */
static void put16(dmc_net *n, int v, int telnet)
{
int i;
if (v < 0)
v = 0;
if (v > 65535)
v = 65535;
for (i = 0; i < 2; i++) {
int b = i ? v & 0xff : v >> 8;
buf_addc(&n->out, (char)b);
if (telnet && b == IAC)
buf_addc(&n->out, (char)IAC);
}
}
static void send_naws(dmc_net *n)
{
put(n, IAC, SB, O_NAWS);
put16(n, n->cols, 1);
put16(n, n->rows, 1);
buf_addc(&n->out, (char)IAC);
buf_addc(&n->out, (char)SE);
}
static void send_window(dmc_net *n)
{
buf_add(&n->out, "\377\377ss", 4);
put16(n, n->rows, 0);
put16(n, n->cols, 0);
put16(n, n->cols * 8, 0);
put16(n, n->rows * 16, 0);
}
DMC_API void dmc_net_connected(dmc_net *n)
{
if (n->proto == DMC_NET_RLOGIN) {
/* NUL, the local and the remote user, "term/speed" */
buf_addc(&n->out, '\0');
buf_add(&n->out, n->user, (int)strlen(n->user) + 1);
buf_add(&n->out, n->user, (int)strlen(n->user) + 1);
buf_adds(&n->out, n->term);
buf_add(&n->out, "/38400", 7);
} else if (n->proto == DMC_NET_TELNET) {
/* what a Telnet client offers at once: its type and size,
and no go-aheads; marked as asked, so that the server's
yes is not answered again */
put(n, IAC, WILL, O_TTYPE);
put(n, IAC, WILL, O_NAWS);
put(n, IAC, DO, O_SGA);
n->local[O_TTYPE] = n->local[O_NAWS] = 1;
n->remote[O_SGA] = 1;
}
}
/* the server's WILL, WONT, DO or DONT */
static void option(dmc_net *n, int verb, int opt)
{
int ok;
switch (verb) {
case WILL:
ok = opt == O_BINARY || opt == O_ECHO || opt == O_SGA;
if (ok != n->remote[opt] || !ok) {
n->remote[opt] = (unsigned char)ok;
put(n, IAC, ok ? DO : DONT, opt);
}
break;
case WONT:
if (n->remote[opt]) {
n->remote[opt] = 0;
put(n, IAC, DONT, opt);
}
break;
case DO:
ok = opt == O_BINARY || opt == O_SGA || opt == O_TTYPE ||
opt == O_NAWS;
if (ok != n->local[opt] || !ok) {
n->local[opt] = (unsigned char)ok;
put(n, IAC, ok ? WILL : WONT, opt);
}
/* (its size, each time it asks) */
if (ok && opt == O_NAWS) {
n->naws = 1;
send_naws(n);
}
break;
case DONT:
if (opt == O_NAWS)
n->naws = 0;
if (n->local[opt]) {
n->local[opt] = 0;
put(n, IAC, WONT, opt);
}
break;
}
}
/* the server's subnegotiation: TERMINAL-TYPE SEND answered with IS */
static void subneg(dmc_net *n)
{
const unsigned char *p = (const unsigned char *)n->sb.p;
if (n->sb.n >= 2 && p[0] == O_TTYPE && p[1] == 1) {
put(n, IAC, SB, O_TTYPE);
buf_addc(&n->out, '\0');
buf_adds(&n->out, n->term);
buf_addc(&n->out, (char)IAC);
buf_addc(&n->out, (char)SE);
}
}
static void feed_telnet(dmc_net *n, const unsigned char *p, int len)
{
int i;
for (i = 0; i < len; i++) {
int b = p[i];
switch (n->st) {
case T_DATA:
if (b == IAC)
n->st = T_IAC;
/* CR NUL is a CR: the NUL goes */
else if (!(b == 0 && n->last_cr && !n->remote[O_BINARY]))
buf_addc(&n->screen, (char)b);
break;
case T_IAC:
if (b == IAC) {
buf_addc(&n->screen, (char)IAC);
n->st = T_DATA;
} else if (b == WILL || b == WONT || b == DO ||
b == DONT) {
n->verb = b;
n->st = T_OPT;
} else if (b == SB) {
buf_clear(&n->sb);
n->st = T_SB;
} else {
/* NOP, GA, AYT and the rest: nothing to do */
n->st = T_DATA;
}
break;
case T_OPT:
option(n, n->verb, b);
n->st = T_DATA;
break;
case T_SB:
if (b == IAC)
n->st = T_SB_IAC;
else if (n->sb.n < 1024)
buf_addc(&n->sb, (char)b);
break;
case T_SB_IAC:
if (b == SE) {
subneg(n);
n->st = T_DATA;
} else {
if (b == IAC && n->sb.n < 1024)
buf_addc(&n->sb, (char)IAC);
n->st = T_SB;
}
break;
}
n->last_cr = n->st == T_DATA && b == '\r';
}
}
DMC_API void dmc_net_feed(dmc_net *n, const char *data, int len)
{
if (len <= 0)
return;
if (n->proto == DMC_NET_TELNET) {
feed_telnet(n, (const unsigned char *)data, len);
return;
}
if (n->proto == DMC_NET_RLOGIN && !n->ready) {
/* the server's NUL: the handshake taken */
n->ready = 1;
if (data[0] == '\0') {
data++;
len--;
}
}
buf_add(&n->screen, data, len);
}
DMC_API void dmc_net_urgent(dmc_net *n, int byte)
{
if (n->proto != DMC_NET_RLOGIN)
return;
/* TIOCPKT_WINDOW: the server takes window sizes, and wants ours */
if (byte & 0x80) {
n->want_size = 1;
send_window(n);
}
/* TIOCPKT_FLUSHWRITE: what it sent before is to be dropped */
if (byte & 0x02)
buf_clear(&n->screen);
}
DMC_API int dmc_net_screen(dmc_net *n, char *buf, int max)
{
return buf_take(&n->screen, buf, max);
}
DMC_API void dmc_net_type(dmc_net *n, const char *data, int len)
{
int i;
if (n->proto != DMC_NET_TELNET) {
buf_add(&n->out, data, len);
return;
}
for (i = 0; i < len; i++) {
unsigned char b = (unsigned char)data[i];
buf_addc(&n->out, (char)b);
if (b == IAC)
buf_addc(&n->out, (char)IAC);
/* a lone CR is CR NUL, outside binary mode */
if (b == '\r' && !n->local[O_BINARY] &&
(i + 1 >= len || data[i + 1] != '\n'))
buf_addc(&n->out, '\0');
}
}
DMC_API int dmc_net_output(dmc_net *n, char *buf, int max)
{
return buf_take(&n->out, buf, max);
}
DMC_API int dmc_net_break(dmc_net *n)
{
/* Telnet's BRK; rlogin has none */
if (n->proto != DMC_NET_TELNET)
return 0;
buf_addc(&n->out, (char)IAC);
buf_addc(&n->out, (char)BRK);
return 1;
}
DMC_API void dmc_net_resize(dmc_net *n, int cols, int rows)
{
if (cols == n->cols && rows == n->rows)
return;
n->cols = cols;
n->rows = rows;
if (n->proto == DMC_NET_TELNET && n->naws)
send_naws(n);
else if (n->proto == DMC_NET_RLOGIN && n->want_size)
send_window(n);
}
-266
View File
@@ -1,266 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* path.c - the connection path: the picture at the top of the Settings
* page of how a call is made, step by step (the D-Modem app's
* ConnectionPath, for the desktop's lines)
*
* dmodemd's own line: Terminal -> D-Modem -> SIP, USB modem or codec
* -> the phone network, SIP addresses, a phone line
* a modem that runs: Terminal -> its device, TCP or COM port -> the
* modem -> its phone line
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dmodemctl.h"
#define STEPS 4
typedef struct Step {
int kind, state;
const char *role;
char title[32], detail[400];
} Step;
struct dmc_path {
/* the settings */
int line, anonymous, listen;
char where[256], user[128], server[256];
/* now */
int running, state;
char connect[128];
/* what they make */
Step step[STEPS];
char headline[512];
};
static void copy(char *d, size_t n, const char *s)
{
snprintf(d, n, "%s", s ? s : "");
}
static void step(Step *s, int kind, const char *title, int state,
const char *detail)
{
s->kind = kind;
s->state = state;
copy(s->title, sizeof(s->title), title);
copy(s->detail, sizeof(s->detail), detail);
}
static int rank(int state)
{
switch (state) {
case DMC_STEP_OFF: return 0;
case DMC_STEP_SETUP: return 1;
case DMC_STEP_WORKING: return 2;
case DMC_STEP_READY: return 3;
default: return 4;
}
}
/* the steps and the headline, from the settings and now */
static void make(dmc_path *p)
{
static const char *const roles[] = { "Program", "Modem", "Line", "Reaches" };
static const char *const external[] = { "Program", "Port", "Modem", "Line" };
Step *s = p->step;
char b[400];
int own = p->line == DMC_LINE_SIP || p->line == DMC_LINE_USB ||
p->line == DMC_LINE_CODEC;
step(&s[0], DMC_KIND_TERMINAL, "Terminal", DMC_STEP_READY,
"AT commands and calls");
if (own) {
int st = p->running && p->state == DMC_CLOSED ? DMC_STEP_WORKING :
DMC_STEP_READY;
step(&s[1], DMC_KIND_SOFTMODEM, "D-Modem", st,
st == DMC_STEP_WORKING ? "Starting" :
p->running ? "Running" : "dmodemd, the V.92 softmodem");
}
switch (p->line) {
case DMC_LINE_USB:
snprintf(b, sizeof(b), "%s", *p->where && strcmp(p->where, "auto") ?
p->where : "The first one found");
step(&s[2], DMC_KIND_USB, "USB modem", DMC_STEP_READY, b);
step(&s[3], DMC_KIND_PHONE_LINE, "Phone line", DMC_STEP_READY,
"The USB modem's");
break;
case DMC_LINE_CODEC:
step(&s[2], DMC_KIND_CODEC, "Codec", *p->where ? DMC_STEP_READY :
DMC_STEP_SETUP, *p->where ? p->where : "No ALSA device set");
step(&s[3], DMC_KIND_PHONE_LINE, "Phone line", DMC_STEP_READY,
"The codec's");
break;
case DMC_LINE_DEVICE:
case DMC_LINE_TCP:
case DMC_LINE_COM: {
int set = *p->where != '\0';
int st = !set ? DMC_STEP_SETUP :
p->running && p->state == DMC_CLOSED ? DMC_STEP_WORKING :
DMC_STEP_READY;
const char *title = p->line == DMC_LINE_TCP ? "TCP" :
p->line == DMC_LINE_COM ? "COM port" : "Device";
step(&s[1], p->line == DMC_LINE_TCP ? DMC_KIND_NETWORK :
DMC_KIND_SERIAL, title, st,
set ? p->where : "Not set yet");
step(&s[2], p->line == DMC_LINE_TCP ? DMC_KIND_SOFTMODEM :
DMC_KIND_MODEM, p->line == DMC_LINE_TCP ? "D-Modem" : "Modem",
DMC_STEP_READY,
p->running && p->state != DMC_CLOSED ? "Running" :
"Already running");
step(&s[3], DMC_KIND_PHONE_LINE, "Phone line", DMC_STEP_READY,
"The modem's own");
break;
}
default:
if (p->anonymous) {
snprintf(b, sizeof(b), "Anonymous: nothing registered%s",
p->listen ? ", takes direct calls" : "");
step(&s[2], DMC_KIND_SIP, "SIP", DMC_STEP_READY, b);
step(&s[3], DMC_KIND_SIP_ADDRESS, "SIP addresses",
DMC_STEP_READY, "Dialled directly (sip:user@host)");
} else if (!*p->user || !*p->server) {
step(&s[2], DMC_KIND_SIP, "SIP", DMC_STEP_SETUP,
"No account set up");
step(&s[3], DMC_KIND_PHONE_NETWORK, "Phone network",
DMC_STEP_SETUP, "Through a SIP provider");
} else {
snprintf(b, sizeof(b), "%s %s@%s",
p->listen ? "Registers as" : "Account",
p->user, p->server);
step(&s[2], DMC_KIND_SIP, "SIP", DMC_STEP_READY, b);
snprintf(b, sizeof(b), "Through %s", p->server);
step(&s[3], DMC_KIND_PHONE_NETWORK, "Phone network",
DMC_STEP_READY, b);
}
break;
}
/* a call: each step in use lights; idle, as set up */
int now = -1;
switch (p->state) {
case DMC_ONLINE:
case DMC_ONLINE_COMMAND:
case DMC_VOICE:
case DMC_VOICEMAIL:
now = DMC_STEP_ACTIVE;
break;
case DMC_DIALING:
case DMC_ANSWERING:
case DMC_RINGING:
case DMC_HANGING_UP:
now = DMC_STEP_WORKING;
break;
}
int setup = 0;
for (int i = 0; i < STEPS; i++) {
s[i].role = own ? roles[i] : external[i];
if (now >= 0 && s[i].state != DMC_STEP_OFF &&
s[i].state != DMC_STEP_SETUP)
s[i].state = now;
if (s[i].state == DMC_STEP_SETUP && !setup) {
setup = 1;
char d[400];
copy(d, sizeof(d), s[i].detail);
if (d[0] >= 'A' && d[0] <= 'Z')
d[0] = (char)(d[0] - 'A' + 'a');
snprintf(p->headline, sizeof(p->headline),
"Not ready: %s (%s)", s[i].title, d);
}
}
if (now == DMC_STEP_ACTIVE && (p->state == DMC_VOICE ||
p->state == DMC_VOICEMAIL))
copy(p->headline, sizeof(p->headline), "In a voice call");
else if (now == DMC_STEP_ACTIVE)
snprintf(p->headline, sizeof(p->headline), "Online%s%s",
*p->connect ? ": " : "", p->connect);
else if (p->state == DMC_RINGING)
copy(p->headline, sizeof(p->headline), "Ringing");
else if (p->state == DMC_HANGING_UP)
copy(p->headline, sizeof(p->headline), "Hanging up");
else if (now == DMC_STEP_WORKING)
copy(p->headline, sizeof(p->headline), "Connecting");
else if (!setup && p->running && p->state == DMC_CLOSED)
copy(p->headline, sizeof(p->headline), "Starting the modem");
else if (!setup && p->running)
copy(p->headline, sizeof(p->headline), "Ready: the modem is running");
else if (!setup)
copy(p->headline, sizeof(p->headline),
"Ready: start the modem to dial");
}
dmc_path *dmc_path_new(void)
{
dmc_path *p = calloc(1, sizeof(*p));
if (p)
make(p);
return p;
}
void dmc_path_free(dmc_path *p)
{
free(p);
}
void dmc_path_set_line(dmc_path *p, int line, const char *where,
int sip_anonymous, const char *sip_user,
const char *sip_server, int listen)
{
p->line = line;
copy(p->where, sizeof(p->where), where);
p->anonymous = sip_anonymous != 0;
copy(p->user, sizeof(p->user), sip_user);
copy(p->server, sizeof(p->server), sip_server);
p->listen = listen != 0;
make(p);
}
void dmc_path_set_live(dmc_path *p, int running, int state,
const char *connect)
{
p->running = running != 0;
p->state = state;
copy(p->connect, sizeof(p->connect), connect);
make(p);
}
int dmc_path_steps(const dmc_path *p)
{
(void)p;
return STEPS;
}
static const Step *at(const dmc_path *p, int i)
{
static const Step none = { 0, DMC_STEP_OFF, "", "", "" };
return i >= 0 && i < STEPS ? &p->step[i] : &none;
}
int dmc_path_kind(const dmc_path *p, int i) { return at(p, i)->kind; }
int dmc_path_state(const dmc_path *p, int i) { return at(p, i)->state; }
const char *dmc_path_role(const dmc_path *p, int i) { return at(p, i)->role; }
const char *dmc_path_title(const dmc_path *p, int i) { return at(p, i)->title; }
const char *dmc_path_detail(const dmc_path *p, int i) { return at(p, i)->detail; }
int dmc_path_link(const dmc_path *p, int i)
{
int a = at(p, i)->state, b = at(p, i + 1)->state;
return rank(a) <= rank(b) ? a : b;
}
const char *dmc_path_headline(const dmc_path *p)
{
return p->headline;
}
int dmc_path_needs_setup(const dmc_path *p)
{
for (int i = 0; i < STEPS; i++)
if (p->step[i].state == DMC_STEP_SETUP)
return 1;
return 0;
}
-1420
View File
File diff suppressed because it is too large. Load diff
-136
View File
@@ -1,136 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* util.c - growable byte buffers and string helpers
*/
#include <stdlib.h>
#include <string.h>
#include "util.h"
static void grow(dmc_buf *b, int need)
{
if (b->n + need + 1 <= b->cap)
return;
int cap = b->cap ? b->cap : 64;
while (cap < b->n + need + 1)
cap *= 2;
char *p = realloc(b->p, (size_t)cap);
if (!p)
abort();
b->p = p;
b->cap = cap;
}
void buf_add(dmc_buf *b, const char *s, int n)
{
if (n <= 0)
return;
grow(b, n);
memcpy(b->p + b->n, s, (size_t)n);
b->n += n;
b->p[b->n] = '\0';
}
void buf_adds(dmc_buf *b, const char *s)
{
buf_add(b, s, (int)strlen(s));
}
void buf_addc(dmc_buf *b, char c)
{
buf_add(b, &c, 1);
}
void buf_drop(dmc_buf *b, int n)
{
if (n >= b->n) {
buf_clear(b);
return;
}
memmove(b->p, b->p + n, (size_t)(b->n - n));
b->n -= n;
b->p[b->n] = '\0';
}
void buf_pop(dmc_buf *b)
{
if (b->n > 0)
b->p[--b->n] = '\0';
}
void buf_clear(dmc_buf *b)
{
b->n = 0;
if (b->p)
b->p[0] = '\0';
}
void buf_free(dmc_buf *b)
{
free(b->p);
b->p = NULL;
b->n = b->cap = 0;
}
int buf_take(dmc_buf *b, char *out, int max)
{
int n = b->n < max ? b->n : max;
if (n <= 0)
return 0;
memcpy(out, b->p, (size_t)n);
buf_drop(b, n);
return n;
}
const char *buf_str(dmc_buf *b)
{
return b->p ? b->p : "";
}
char *dup_n(const char *s, size_t n)
{
char *p = malloc(n + 1);
if (!p)
abort();
memcpy(p, s, n);
p[n] = '\0';
return p;
}
char *dup_str(const char *s)
{
return dup_n(s ? s : "", strlen(s ? s : ""));
}
static char lower(char c)
{
return c >= 'A' && c <= 'Z' ? (char)(c - 'A' + 'a') : c;
}
int same_ci(const char *s, const char *t)
{
while (*s && *t && lower(*s) == lower(*t)) {
s++;
t++;
}
return !*s && !*t;
}
int starts_ci(const char *s, const char *p)
{
while (*p) {
if (lower(*s) != lower(*p))
return 0;
s++;
p++;
}
return 1;
}
void set_str(char **p, const char *s)
{
free(*p);
*p = dup_str(s);
}
-43
View File
@@ -1,43 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* util.h - growable byte buffers and string helpers shared by the
* library's parts
*/
#ifndef DMC_UTIL_H
#define DMC_UTIL_H
#include <stddef.h>
/* a growable run of bytes, always ended by a '\0' past n */
typedef struct dmc_buf {
char *p;
int n, cap;
} dmc_buf;
void buf_add(dmc_buf *b, const char *s, int n);
void buf_adds(dmc_buf *b, const char *s);
void buf_addc(dmc_buf *b, char c);
/* the last byte taken off (none: nothing) */
void buf_pop(dmc_buf *b);
/* the first n bytes taken out */
void buf_drop(dmc_buf *b, int n);
void buf_clear(dmc_buf *b);
void buf_free(dmc_buf *b);
/* up to max bytes moved into out: how many */
int buf_take(dmc_buf *b, char *out, int max);
/* its text ("" when empty) */
const char *buf_str(dmc_buf *b);
/* a copy of s (or of its first n bytes) */
char *dup_str(const char *s);
char *dup_n(const char *s, size_t n);
/* s and t the same, ignoring ASCII case */
int same_ci(const char *s, const char *t);
/* s begins with p, ignoring ASCII case */
int starts_ci(const char *s, const char *p);
/* *p set to a copy of s (the old one freed) */
void set_str(char **p, const char *s);
#endif
-669
View File
@@ -1,669 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* voice.c - G.711, rings of samples, tones, and WAV files (dmodemctl.h)
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "dmodemctl.h"
#include "voice.h"
/*
* G.711
*/
unsigned char ulaw_encode(int16_t x)
{
int v = x, sign = 0, exp, mant;
if (v < 0) {
v = -v;
sign = 0x80;
}
v += 0x84;
if (v > 0x7fff)
v = 0x7fff;
for (exp = 7; exp > 0 && !(v & (0x4000 >> (7 - exp))); exp--)
;
mant = (v >> (exp + 3)) & 0x0f;
return (unsigned char)~(sign | (exp << 4) | mant);
}
int16_t ulaw_decode(unsigned char u)
{
int v, exp, mant;
u = (unsigned char)~u;
exp = (u >> 4) & 7;
mant = u & 0x0f;
v = ((mant << 3) + 0x84) << exp;
v -= 0x84;
return (int16_t)((u & 0x80) ? -v : v);
}
int16_t alaw_decode(unsigned char a)
{
int v, exp, mant;
a ^= 0x55;
exp = (a >> 4) & 7;
mant = a & 0x0f;
v = exp ? ((mant << 4) + 0x108) << (exp - 1) : (mant << 4) + 8;
return (int16_t)((a & 0x80) ? v : -v);
}
/*
* Rings
*/
void ring_init(dmc_ring *r, int cap)
{
memset(r, 0, sizeof(*r));
r->p = calloc((size_t)cap, sizeof(int16_t));
if (!r->p)
abort();
r->cap = cap;
}
void ring_free(dmc_ring *r)
{
free(r->p);
memset(r, 0, sizeof(*r));
}
void ring_clear(dmc_ring *r)
{
r->head = r->n = 0;
}
void ring_put(dmc_ring *r, const int16_t *x, int n)
{
int i;
if (!r->cap)
return;
for (i = 0; i < n; i++) {
int at = (r->head + r->n) % r->cap;
r->p[at] = x ? x[i] : 0;
if (r->n < r->cap)
r->n++;
else
r->head = (r->head + 1) % r->cap;
}
}
int ring_get(dmc_ring *r, int16_t *out, int max)
{
int i, n = r->n < max ? r->n : max;
for (i = 0; i < n; i++) {
out[i] = r->p[r->head];
r->head = (r->head + 1) % r->cap;
}
r->n -= n;
return n;
}
void ring_keep(dmc_ring *r, int n)
{
if (r->n <= n)
return;
r->head = (r->head + r->n - n) % r->cap;
r->n = n;
}
/*
* Tones
*/
#define PI 3.14159265358979323846
void tone_start(dmc_tone *t, double f1, double f2, int samples,
double amp)
{
memset(t, 0, sizeof(*t));
t->k1 = 2 * PI * f1 / DMC_VOICE_RATE;
t->k2 = 2 * PI * f2 / DMC_VOICE_RATE;
t->c1 = t->c2 = 1;
t->two = f2 > 0;
t->left = samples;
t->amp = amp;
}
/* (each oscillator a unit vector turned by its step each sample) */
static double turn(double *c, double *s, double k)
{
double c0 = *c, s0 = *s, ck = cos(k), sk = sin(k), m;
*c = c0 * ck - s0 * sk;
*s = c0 * sk + s0 * ck;
/* (kept on the circle) */
m = sqrt(*c * *c + *s * *s);
if (m > 0) {
*c /= m;
*s /= m;
}
return s0;
}
int tone_next(dmc_tone *t)
{
double y;
if (t->left <= 0)
return 0;
t->left--;
y = turn(&t->c1, &t->s1, t->k1);
if (t->two)
y = (y + turn(&t->c2, &t->s2, t->k2)) / 2;
return (int)(y * t->amp);
}
int dtmf_freqs(char digit, double *lo, double *hi)
{
static const char keys[] = "123A456B789C*0#D";
static const double row[] = { 697, 770, 852, 941 };
static const double col[] = { 1209, 1336, 1477, 1633 };
const char *k;
char d = digit;
if (d >= 'a' && d <= 'd')
d = (char)(d - 'a' + 'A');
k = d ? strchr(keys, d) : NULL;
if (!k)
return -1;
*lo = row[(k - keys) / 4];
*hi = col[(k - keys) % 4];
return 0;
}
/*
* WAV files
*/
static void put16(char *p, unsigned v)
{
p[0] = (char)(v & 0xff);
p[1] = (char)((v >> 8) & 0xff);
}
static void put32(char *p, unsigned long v)
{
put16(p, (unsigned)(v & 0xffff));
put16(p + 2, (unsigned)((v >> 16) & 0xffff));
}
int dmc_wav_header(char *buf, int n)
{
unsigned long bytes = n > 0 ? (unsigned long)n * 2 : 0;
memcpy(buf, "RIFF", 4);
put32(buf + 4, 36 + bytes);
memcpy(buf + 8, "WAVEfmt ", 8);
put32(buf + 16, 16);
put16(buf + 20, 1); /* PCM */
put16(buf + 22, 1); /* mono */
put32(buf + 24, DMC_VOICE_RATE);
put32(buf + 28, DMC_VOICE_RATE * 2);
put16(buf + 32, 2);
put16(buf + 34, 16);
memcpy(buf + 36, "data", 4);
put32(buf + 40, bytes);
return 44;
}
/*
* Sound files read: WAV (PCM of 8 to 32 bits, floats, A-law, mu-law,
* IMA and Microsoft ADPCM), AIFF and AIFF-C (PCM, floats, A-law,
* mu-law), Sun/NeXT .au; any rate and channels, made 8 kHz mono
*/
/* what a file's samples are */
enum { E_PCM, E_FLOAT, E_ALAW, E_ULAW, E_IMA, E_MSADPCM };
struct sound {
int enc, bits, big, channels, block;
double rate;
const unsigned char *p;
long bytes;
/* (MS ADPCM's coefficient pairs, from its fmt chunk) */
int ncoef;
int coef[64][2];
};
static unsigned long get32be(const unsigned char *p)
{
return ((unsigned long)p[0] << 24) | ((unsigned long)p[1] << 16) |
((unsigned long)p[2] << 8) | p[3];
}
static unsigned ug16(const unsigned char *p)
{
return p[0] | ((unsigned)p[1] << 8);
}
static unsigned long ug32(const unsigned char *p)
{
return ug16(p) | ((unsigned long)ug16(p + 2) << 16);
}
/* an 80-bit IEEE extended (AIFF's rate) as a double */
static double extended(const unsigned char *p)
{
int e = ((p[0] & 0x7f) << 8 | p[1]) - 16383 - 63;
double m = (double)get32be(p + 2) * 4294967296.0 +
(double)get32be(p + 6);
double v = ldexp(m, e);
return (p[0] & 0x80) ? -v : v;
}
/* a RIFF WAVE's: 0, or -1 if it isn't one this reads */
static int parse_wav(const unsigned char *d, long n, struct sound *f)
{
const unsigned char *p = d + 12, *end = d + n;
int fmt = 0, tag = 0;
while (end - p >= 8) {
unsigned long len = ug32(p + 4);
const unsigned char *body = p + 8;
long left = (long)(end - body);
if (!memcmp(p, "fmt ", 4) && len >= 16 && left >= 16) {
tag = (int)ug16(body);
f->channels = (int)ug16(body + 2);
f->rate = ug32(body + 4);
f->block = (int)ug16(body + 12);
f->bits = (int)ug16(body + 14);
/* WAVE_FORMAT_EXTENSIBLE: its subformat's code */
if (tag == 0xfffe && len >= 26 && left >= 26)
tag = (int)ug16(body + 24);
if (tag == 2 && len >= 22 && left >= 22) {
int i, k = (int)ug16(body + 20);
if (k > 64 || (long)(22 + 4 * k) > left)
return -1;
f->ncoef = k;
for (i = 0; i < k; i++) {
f->coef[i][0] = (int16_t)ug16(body + 22 + 4 * i);
f->coef[i][1] = (int16_t)ug16(body + 24 + 4 * i);
}
}
fmt = 1;
} else if (!memcmp(p, "data", 4)) {
f->p = body;
f->bytes = len > (unsigned long)left ? left : (long)len;
break;
}
if (len > (unsigned long)left)
break;
p = body + len + (len & 1);
}
if (!fmt || !f->p)
return -1;
switch (tag) {
case 1: f->enc = E_PCM; break;
case 3: f->enc = E_FLOAT; break;
case 6: f->enc = E_ALAW; break;
case 7: f->enc = E_ULAW; break;
case 0x11: f->enc = E_IMA; break;
case 2: f->enc = E_MSADPCM; break;
default: return -1;
}
return 0;
}
/* an AIFF or AIFF-C's */
static int parse_aiff(const unsigned char *d, long n, struct sound *f)
{
const unsigned char *p = d + 12, *end = d + n;
int comm = 0, aifc = !memcmp(d + 8, "AIFC", 4);
char comp[4] = { 'N', 'O', 'N', 'E' };
while (end - p >= 8) {
unsigned long len = get32be(p + 4);
const unsigned char *body = p + 8;
long left = (long)(end - body);
if (!memcmp(p, "COMM", 4) && len >= 18 && left >= 18) {
f->channels = (int)(body[0] << 8 | body[1]);
f->bits = (int)(body[6] << 8 | body[7]);
f->rate = extended(body + 8);
if (aifc && len >= 22 && left >= 22)
memcpy(comp, body + 18, 4);
comm = 1;
} else if (!memcmp(p, "SSND", 4) && len >= 8 && left >= 8) {
unsigned long off = get32be(body);
long l = len > (unsigned long)left ? left : (long)len;
if ((long)off > l - 8)
return -1;
f->p = body + 8 + off;
f->bytes = l - 8 - (long)off;
}
if (len > (unsigned long)left)
break;
p = body + len + (len & 1);
}
if (!comm || !f->p)
return -1;
f->big = 1;
if (!memcmp(comp, "NONE", 4) || !memcmp(comp, "twos", 4)) {
f->enc = E_PCM;
} else if (!memcmp(comp, "sowt", 4)) {
f->enc = E_PCM;
f->big = 0;
} else if (!memcmp(comp, "fl32", 4) || !memcmp(comp, "FL32", 4)) {
f->enc = E_FLOAT;
f->bits = 32;
} else if (!memcmp(comp, "fl64", 4) || !memcmp(comp, "FL64", 4)) {
f->enc = E_FLOAT;
f->bits = 64;
} else if (!memcmp(comp, "ulaw", 4) || !memcmp(comp, "ULAW", 4)) {
f->enc = E_ULAW;
f->bits = 8;
} else if (!memcmp(comp, "alaw", 4) || !memcmp(comp, "ALAW", 4)) {
f->enc = E_ALAW;
f->bits = 8;
} else {
return -1;
}
/* (AIFF's 8-bit samples are signed) */
if (f->enc == E_PCM && f->bits == 8)
f->big = 2;
return 0;
}
/* a Sun/NeXT .au's */
static int parse_au(const unsigned char *d, long n, struct sound *f)
{
unsigned long off, len, enc;
if (n < 24)
return -1;
off = get32be(d + 4);
len = get32be(d + 8);
enc = get32be(d + 12);
f->rate = get32be(d + 16);
f->channels = (int)get32be(d + 20);
if (off < 24 || (long)off > n)
return -1;
f->p = d + off;
f->bytes = n - (long)off;
if (len != 0xffffffffUL && (long)len < f->bytes)
f->bytes = (long)len;
f->big = 1;
switch (enc) {
case 1: f->enc = E_ULAW; f->bits = 8; break;
case 2: f->enc = E_PCM; f->bits = 8; f->big = 2; break;
case 3: f->enc = E_PCM; f->bits = 16; break;
case 4: f->enc = E_PCM; f->bits = 24; break;
case 5: f->enc = E_PCM; f->bits = 32; break;
case 6: f->enc = E_FLOAT; f->bits = 32; break;
case 7: f->enc = E_FLOAT; f->bits = 64; break;
case 27: f->enc = E_ALAW; f->bits = 8; break;
default: return -1;
}
return 0;
}
/* a sample of width w bytes at q as 16 bits (big: 1 big-endian, 2
big-endian with 8-bit samples signed) */
static int pcm_at(const unsigned char *q, int w, int big)
{
unsigned long v = 0;
int i;
if (w == 1)
return big == 2 ? (int)(signed char)q[0] * 256 :
((int)q[0] - 128) * 256;
for (i = 0; i < w; i++)
v |= (unsigned long)q[big ? i : w - 1 - i] << (8 * (w - 1 - i));
/* (the top two bytes: the sample's sign is the top bit) */
v >>= 8 * (w - 2);
return (int16_t)(v & 0xffff);
}
static int float_at(const unsigned char *q, int w, int big)
{
unsigned char b[8];
double x;
int i;
for (i = 0; i < w; i++)
b[i] = q[big ? w - 1 - i : i];
/* (b is little-endian now, as the machines this runs on are) */
if (w == 4) {
float y;
memcpy(&y, b, 4);
x = y;
} else {
memcpy(&x, b, 8);
}
if (x != x)
return 0;
x *= 32767.0;
return x > 32767 ? 32767 : x < -32768 ? -32768 : (int)x;
}
static const int ima_steps[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34,
37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494,
544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552,
1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428,
4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487,
12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086,
29794, 32767
};
static const int ima_index[16] = { -1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8 };
static int ima_nibble(int *pred, int *idx, int nib)
{
int step = ima_steps[*idx], diff = step >> 3;
if (nib & 4) diff += step;
if (nib & 2) diff += step >> 1;
if (nib & 1) diff += step >> 2;
*pred += (nib & 8) ? -diff : diff;
if (*pred > 32767) *pred = 32767;
if (*pred < -32768) *pred = -32768;
*idx += ima_index[nib];
if (*idx < 0) *idx = 0;
if (*idx > 88) *idx = 88;
return *pred;
}
/* one channel's sample of frame i: the files' samples mixed to mono
into out (frames of them): how many frames */
static long decode_mono(const struct sound *f, int16_t *out, long cap)
{
int c, ch = f->channels;
long fr = 0;
if (f->enc == E_IMA) {
/* blocks: per channel a header (sample, index), then 4-byte
groups of 8 nibbles per channel in turn */
const unsigned char *b = f->p, *end = f->p + f->bytes;
int per = f->block > 4 * ch ? (f->block - 4 * ch) * 2 / ch + 1 : 0;
if (per <= 0 || per > 65536)
return -1;
while (end - b >= f->block && fr < cap) {
int pred[8], idx[8], i;
int16_t *o = out + fr;
long n = per < cap - fr ? per : cap - fr;
for (i = 0; i < n; i++)
o[i] = 0;
for (c = 0; c < ch; c++) {
const unsigned char *h = b + 4 * c;
pred[c] = (int16_t)ug16(h);
idx[c] = h[2] > 88 ? 88 : h[2];
}
for (c = 0; c < ch; c++) {
long k = 0;
const unsigned char *q = b + 4 * ch + 4 * c;
if (k < n)
o[k] = (int16_t)(o[k] + pred[c] / ch);
k = 1;
while (k < per && q + 4 <= b + f->block) {
int j;
for (j = 0; j < 8 && k < per; j++, k++) {
int nib = (q[j / 2] >> ((j & 1) * 4)) & 15;
int v = ima_nibble(&pred[c], &idx[c], nib);
if (k < n)
o[k] = (int16_t)(o[k] + v / ch);
}
q += 4 * ch;
}
}
fr += n;
b += f->block;
}
return fr;
}
if (f->enc == E_MSADPCM) {
static const int adapt[16] = { 230, 230, 230, 230, 307, 409,
512, 614, 768, 614, 512, 409,
307, 230, 230, 230 };
const unsigned char *b = f->p, *end = f->p + f->bytes;
int per;
if (ch > 2 || !f->ncoef || f->block < 7 * ch)
return -1;
per = (f->block - 7 * ch) * 2 / ch + 2;
while (end - b >= f->block && fr < cap) {
int pred[2], delta[2], s1[2], s2[2];
const unsigned char *q = b;
long n = per < cap - fr ? per : cap - fr, k;
int16_t *o = out + fr;
for (c = 0; c < ch; c++)
pred[c] = q[c] < f->ncoef ? q[c] : 0;
q += ch;
for (c = 0; c < ch; c++, q += 2)
delta[c] = (int16_t)ug16(q);
for (c = 0; c < ch; c++, q += 2)
s1[c] = (int16_t)ug16(q);
for (c = 0; c < ch; c++, q += 2)
s2[c] = (int16_t)ug16(q);
/* (the header's two samples: the older first) */
if (n > 0) {
long v = 0;
for (c = 0; c < ch; c++) v += s2[c];
o[0] = (int16_t)(v / ch);
}
if (n > 1) {
long v = 0;
for (c = 0; c < ch; c++) v += s1[c];
o[1] = (int16_t)(v / ch);
}
for (k = 2; k < per; k++) {
long v = 0;
for (c = 0; c < ch; c++) {
long nib_i = (k - 2) * ch + c;
int nib = (q[nib_i / 2] >> ((nib_i & 1) ? 0 : 4)) & 15;
int sn = nib & 8 ? nib - 16 : nib;
long long p = ((long long)s1[c] * f->coef[pred[c]][0] +
(long long)s2[c] * f->coef[pred[c]][1]) / 256;
p += (long long)sn * delta[c];
if (p > 32767) p = 32767;
if (p < -32768) p = -32768;
s2[c] = s1[c];
s1[c] = (int)p;
delta[c] = (int)((long)delta[c] * adapt[nib] / 256);
/* (a broken file's grows without end) */
if (delta[c] > 0x100000) delta[c] = 0x100000;
if (delta[c] < 16) delta[c] = 16;
v += (long)p;
}
if (k < n)
o[k] = (int16_t)(v / ch);
}
fr += n;
b += f->block;
}
return fr;
}
{
int w = f->bits / 8;
long frames, i;
if (w < 1 || w > 8 || (f->enc == E_PCM && w > 4) ||
(f->enc == E_FLOAT && w != 4 && w != 8) ||
((f->enc == E_ALAW || f->enc == E_ULAW) && w != 1))
return -1;
frames = f->bytes / ((long)w * ch);
if (frames > cap)
frames = cap;
for (i = 0; i < frames; i++) {
long sum = 0;
for (c = 0; c < ch; c++) {
const unsigned char *q = f->p + (i * ch + c) * w;
switch (f->enc) {
case E_ULAW: sum += ulaw_decode(*q); break;
case E_ALAW: sum += alaw_decode(*q); break;
case E_FLOAT: sum += float_at(q, w, f->big); break;
default: sum += pcm_at(q, w, f->big); break;
}
}
out[i] = (int16_t)(sum / ch);
}
return frames;
}
}
/* the most frames f could hold */
static long most_frames(const struct sound *f)
{
if (f->enc == E_IMA || f->enc == E_MSADPCM) {
if (f->block <= 0)
return 0;
return (f->bytes / f->block + 1) * ((long)f->block * 2 + 2);
}
if (f->bits < 8)
return 0;
return f->bytes / ((long)(f->bits / 8) * f->channels);
}
int dmc_audio_decode(const char *data, int n, int16_t **pcm)
{
const unsigned char *d = (const unsigned char *)data;
struct sound f;
int16_t *mono, *out;
long frames, cap, out_n, i;
int r = -1;
*pcm = NULL;
if (!data || n < 12)
return -1;
memset(&f, 0, sizeof(f));
if (!memcmp(d, "RIFF", 4) && !memcmp(d + 8, "WAVE", 4))
r = parse_wav(d, n, &f);
else if (!memcmp(d, "FORM", 4) &&
(!memcmp(d + 8, "AIFF", 4) || !memcmp(d + 8, "AIFC", 4)))
r = parse_aiff(d, n, &f);
else if (!memcmp(d, ".snd", 4))
r = parse_au(d, n, &f);
if (r || f.channels < 1 || f.channels > 8 || !(f.rate >= 1000) ||
f.rate > 384000)
return -1;
cap = most_frames(&f);
if (cap < 0 || cap > 100000000L)
return -1;
mono = malloc((size_t)(cap > 0 ? cap : 1) * sizeof(int16_t));
if (!mono)
return -1;
frames = decode_mono(&f, mono, cap);
if (frames < 0) {
free(mono);
return -1;
}
out_n = (long)((double)frames * DMC_VOICE_RATE / f.rate);
out = malloc((size_t)(out_n > 0 ? out_n : 1) * sizeof(int16_t));
if (!out) {
free(mono);
return -1;
}
for (i = 0; i < out_n; i++) {
/* (linear between the two frames around it) */
double at = (double)i * f.rate / DMC_VOICE_RATE;
long k = (long)at;
double frac = at - (double)k;
long k1 = k + 1 < frames ? k + 1 : frames - 1;
double y = (1 - frac) * mono[k] + frac * mono[k1];
out[i] = (int16_t)(y > 32767 ? 32767 : y < -32768 ? -32768 : y);
}
free(mono);
*pcm = out;
return (int)out_n;
}
int dmc_wav_decode(const char *data, int n, int16_t **pcm)
{
return dmc_audio_decode(data, n, pcm);
}
void dmc_free(void *p)
{
free(p);
}
-49
View File
@@ -1,49 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* voice.h - what the session's voice calls are made of: G.711 mu-law,
* rings of samples, the tones we play (DTMF, the beep)
*/
#ifndef DMC_VOICE_H
#define DMC_VOICE_H
#include <stdint.h>
/* G.711 mu-law, the samples on the DTE in a call (AT+VSM=4) */
unsigned char ulaw_encode(int16_t x);
int16_t ulaw_decode(unsigned char u);
/* and A-law, for WAV files */
int16_t alaw_decode(unsigned char a);
/* a ring of samples that keeps the newest cap of them */
typedef struct dmc_ring {
int16_t *p;
int cap, head, n;
} dmc_ring;
void ring_init(dmc_ring *r, int cap);
void ring_free(dmc_ring *r);
void ring_clear(dmc_ring *r);
/* n samples in: the oldest dropped when it is full */
void ring_put(dmc_ring *r, const int16_t *x, int n);
/* up to max out of it: how many */
int ring_get(dmc_ring *r, int16_t *out, int max);
/* the oldest taken out until n are left */
void ring_keep(dmc_ring *r, int n);
/* a tone of one or two frequencies, n samples long */
typedef struct dmc_tone {
double c1, s1, k1, c2, s2, k2; /* each oscillator's state, step */
int two, left;
double amp;
} dmc_tone;
void tone_start(dmc_tone *t, double f1, double f2, int samples,
double amp);
/* its next sample (0 when it has ended) */
int tone_next(dmc_tone *t);
/* a DTMF digit's two frequencies: 0, or -1 for none */
int dtmf_freqs(char digit, double *lo, double *hi);
#endif
-2270
View File
File diff suppressed because it is too large. Load diff
-325
View File
@@ -1,325 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_charsets.c - the character sets a remote may speak (UTF-8, code
* page 437, Latin-1), the G sets a DEC terminal designates (DEC Special
* Graphics, Supplemental, Technical, the national sets), and how many
* cells a character takes (wcwidth). A port of the app's Charsets.kt
* and Wcwidth.kt.
*/
#include <string.h>
#include "vtint.h"
static const uint32_t cp437_high[128] = {
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0,
};
static const uint32_t dec_graphics_tab[32] = {
0x00A0, 0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x00B0,
0x00B1, 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C,
0x23BA, 0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534,
0x252C, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00B7,
};
static const uint32_t technical_tab[94] = {
0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1, 0x23A3,
0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8, 0x23AC,
0x23B2, 0x23B3, 0x2572, 0x2571, 0x231D, 0x231F, 0x27E9, 0x0020,
0x0020, 0x0020, 0x0020, 0x2264, 0x2260, 0x2265, 0x222B, 0x2234,
0x221D, 0x221E, 0x00F7, 0x0394, 0x2207, 0x03A6, 0x0393, 0x223C,
0x2243, 0x0398, 0x00D7, 0x039B, 0x21D4, 0x21D2, 0x2261, 0x03A0,
0x03A8, 0x0020, 0x03A3, 0x0020, 0x0020, 0x221A, 0x03A9, 0x039E,
0x03A5, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227, 0x2228, 0x00AC,
0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03C6, 0x03B3, 0x03B7,
0x03B9, 0x03B8, 0x03BA, 0x03BB, 0x0020, 0x03BD, 0x2202, 0x03C0,
0x03C8, 0x03C1, 0x03C3, 0x03C4, 0x0020, 0x0192, 0x03C9, 0x03BE,
0x03C5, 0x03B6, 0x2190, 0x2191, 0x2192, 0x2193,
};
static const uint32_t vt52_tab[33] = {
0x0020, 0x0020, 0x0020, 0x2588, 0x215F, 0x00B3, 0x2075, 0x2077,
0x00B0, 0x00B1, 0x2192, 0x2026, 0x00F7, 0x2193, 0x2594, 0x1FB76,
0x1FB77, 0x1FB78, 0x1FB79, 0x1FB7A, 0x1FB7B, 0x2581, 0x2080, 0x2081,
0x2082, 0x2083, 0x2084, 0x2085, 0x2086, 0x2087, 0x2088, 0x2089,
0x00B6,
};
uint32_t cp437_decode(int b)
{
return b < 0x80 ? (uint32_t)b : cp437_high[(b - 0x80) & 0x7f];
}
int cp437_encode(uint32_t cp)
{
int i;
if (cp < 0x80)
return (int)cp;
for (i = 0; i < 128; i++)
if (cp437_high[i] == cp)
return 0x80 + i;
return '?';
}
void charset_encode(int cs, const uint32_t *cps, int n, dmc_buf *out)
{
int i;
for (i = 0; i < n; i++) {
uint32_t c = cps[i];
if (cs == CS_UTF8)
utf8_put(out, c);
else if (cs == CS_LATIN1)
buf_addc(out, (char)(c < 256 ? c : '?'));
else
buf_addc(out, (char)cp437_encode(c));
}
}
uint32_t dec_graphics(uint32_t cp)
{
return cp >= 0x5f && cp <= 0x7e ? dec_graphics_tab[cp - 0x5f] : cp;
}
/*
* The G sets: their designators (what follows ESC ( to designate them),
* size, the VT level that has them, and a national set's replacements
* (pairs: the ASCII character and what it is there, ended by 0)
*/
struct gset_info {
const char *designators[3];
int is96, level;
const uint32_t *table;
};
static const uint32_t nat_uk[] = { 0x23, 0xA3, 0 };
static const uint32_t nat_dutch[] = { 0x23, 0xA3, 0x40, 0xBE, 0x5B, 0x133, 0x5C, 0xBD, 0x5D, 0x7C, 0x7B, 0xA8, 0x7C, 0x192, 0x7D, 0xBC, 0x7E, 0xB4, 0 };
static const uint32_t nat_finnish[] = { 0x5B, 0xC4, 0x5C, 0xD6, 0x5D, 0xC5, 0x5E, 0xDC, 0x60, 0xE9, 0x7B, 0xE4, 0x7C, 0xF6, 0x7D, 0xE5, 0x7E, 0xFC, 0 };
static const uint32_t nat_french[] = { 0x23, 0xA3, 0x40, 0xE0, 0x5B, 0xB0, 0x5C, 0xE7, 0x5D, 0xA7, 0x7B, 0xE9, 0x7C, 0xF9, 0x7D, 0xE8, 0x7E, 0xA8, 0 };
static const uint32_t nat_french_canadian[] = { 0x40, 0xE0, 0x5B, 0xE2, 0x5C, 0xE7, 0x5D, 0xEA, 0x5E, 0xEE, 0x60, 0xF4, 0x7B, 0xE9, 0x7C, 0xF9, 0x7D, 0xE8, 0x7E, 0xFB, 0 };
static const uint32_t nat_german[] = { 0x40, 0xA7, 0x5B, 0xC4, 0x5C, 0xD6, 0x5D, 0xDC, 0x7B, 0xE4, 0x7C, 0xF6, 0x7D, 0xFC, 0x7E, 0xDF, 0 };
static const uint32_t nat_italian[] = { 0x23, 0xA3, 0x40, 0xA7, 0x5B, 0xB0, 0x5C, 0xE7, 0x5D, 0xE9, 0x60, 0xF9, 0x7B, 0xE0, 0x7C, 0xF2, 0x7D, 0xE8, 0x7E, 0xEC, 0 };
static const uint32_t nat_norwegian_danish[] = { 0x40, 0xC4, 0x5B, 0xC6, 0x5C, 0xD8, 0x5D, 0xC5, 0x5E, 0xDC, 0x60, 0xE4, 0x7B, 0xE6, 0x7C, 0xF8, 0x7D, 0xE5, 0x7E, 0xFC, 0 };
static const uint32_t nat_spanish[] = { 0x23, 0xA3, 0x40, 0xA7, 0x5B, 0xA1, 0x5C, 0xD1, 0x5D, 0xBF, 0x7B, 0xB0, 0x7C, 0xF1, 0x7D, 0xE7, 0 };
static const uint32_t nat_swedish[] = { 0x40, 0xC9, 0x5B, 0xC4, 0x5C, 0xD6, 0x5D, 0xC5, 0x5E, 0xDC, 0x60, 0xE9, 0x7B, 0xE4, 0x7C, 0xF6, 0x7D, 0xE5, 0x7E, 0xFC, 0 };
static const uint32_t nat_swiss[] = { 0x23, 0xF9, 0x40, 0xE0, 0x5B, 0xE9, 0x5C, 0xE7, 0x5D, 0xEA, 0x5E, 0xEE, 0x5F, 0xE8, 0x60, 0xF4, 0x7B, 0xE4, 0x7C, 0xF6, 0x7D, 0xFC, 0x7E, 0xFB, 0 };
static const uint32_t nat_portuguese[] = { 0x5B, 0xC3, 0x5C, 0xC7, 0x5D, 0xD5, 0x7B, 0xE3, 0x7C, 0xE7, 0x7D, 0xF5, 0 };
static const struct gset_info gsets[G_COUNT] = {
{ { "B", NULL, NULL }, 0, 1, NULL }, /* ASCII */
{ { "0", NULL, NULL }, 0, 1, NULL }, /* DEC_GRAPHICS */
{ { "A", NULL, NULL }, 0, 1, nat_uk }, /* UK */
{ { NULL, NULL, NULL }, 0, 1, NULL }, /* VT52_GRAPHICS */
{ { "%5", "<", NULL }, 0, 2, NULL }, /* DEC_SUPPLEMENTAL */
{ { ">", NULL, NULL }, 0, 3, NULL }, /* DEC_TECHNICAL */
{ { "A", NULL, NULL }, 1, 3, NULL }, /* LATIN1 */
{ { "4", NULL, NULL }, 0, 2, nat_dutch }, /* DUTCH */
{ { "C", "5", NULL }, 0, 2, nat_finnish }, /* FINNISH */
{ { "R", "f", NULL }, 0, 2, nat_french }, /* FRENCH */
{ { "Q", "9", NULL }, 0, 2, nat_french_canadian }, /* FRENCH_CANADIAN */
{ { "K", NULL, NULL }, 0, 2, nat_german }, /* GERMAN */
{ { "Y", NULL, NULL }, 0, 2, nat_italian }, /* ITALIAN */
{ { "E", "6", "`" }, 0, 2, nat_norwegian_danish }, /* NORWEGIAN_DANISH */
{ { "Z", NULL, NULL }, 0, 2, nat_spanish }, /* SPANISH */
{ { "H", "7", NULL }, 0, 2, nat_swedish }, /* SWEDISH */
{ { "=", NULL, NULL }, 0, 2, nat_swiss }, /* SWISS */
{ { "%6", NULL, NULL }, 0, 3, nat_portuguese }, /* PORTUGUESE */
{ { NULL, NULL, NULL }, 0, 2, NULL }, /* SOFT */
};
int gset_by_designator(const char *d, int is96)
{
int g, k;
for (g = 0; g < G_COUNT; g++) {
if (gsets[g].is96 != is96)
continue;
for (k = 0; k < 3; k++)
if (gsets[g].designators[k] &&
strcmp(gsets[g].designators[k], d) == 0)
return g;
}
return -1;
}
int gset_is96(int g)
{
return gsets[g].is96;
}
int gset_level(int g)
{
return gsets[g].level;
}
const char *gset_designator(int g)
{
return gsets[g].designators[0] ? gsets[g].designators[0] : "";
}
/* where DEC Supplemental isn't Latin-1: ¤ at 0x28, Œ Ÿ œ ÿ, and the codes
it left empty (shown blank) */
static uint32_t supplemental(uint32_t cp)
{
switch (cp) {
case 0x28: return 0xa4;
case 0x57: return 0x152;
case 0x5d: return 0x178;
case 0x77: return 0x153;
case 0x7d: return 0xff;
case 0x24: case 0x26: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
case 0x34: case 0x38: case 0x3e: case 0x50: case 0x5e: case 0x70:
case 0x7e:
return 0x20;
}
return cp + 0x80;
}
uint32_t gset_map(int g, uint32_t cp)
{
const uint32_t *t;
switch (g) {
case G_ASCII:
return cp;
case G_DEC_GRAPHICS:
return dec_graphics(cp);
case G_VT52_GRAPHICS:
return cp >= 0x5e && cp <= 0x7e ? vt52_tab[cp - 0x5e] : cp;
case G_DEC_SUPPLEMENTAL:
return cp >= 0x21 && cp <= 0x7e ? supplemental(cp) : cp;
case G_DEC_TECHNICAL:
return cp >= 0x21 && cp <= 0x7e ? technical_tab[cp - 0x21] : cp;
case G_LATIN1:
return cp >= 0x20 && cp <= 0x7f ? cp + 0x80 : cp;
}
for (t = gsets[g].table; t && *t; t += 2)
if (t[0] == cp)
return t[1];
return cp;
}
/* wcwidth: Unicode 15's tables, in (first, last) pairs */
static const uint32_t wc_zero[452] = {
0x00300, 0x0036F, 0x00483, 0x00489, 0x00591, 0x005BD, 0x005BF, 0x005BF,
0x005C1, 0x005C2, 0x005C4, 0x005C5, 0x005C7, 0x005C7, 0x00610, 0x0061A,
0x0061C, 0x0061C, 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, 0x00898, 0x0089F, 0x008CA, 0x008E1, 0x008E3, 0x00902,
0x0093A, 0x0093A, 0x0093C, 0x0093C, 0x00941, 0x00948, 0x0094D, 0x0094D,
0x00951, 0x00957, 0x00962, 0x00963, 0x00981, 0x00981, 0x009BC, 0x009BC,
0x009C1, 0x009C4, 0x009CD, 0x009CD, 0x009E2, 0x009E3, 0x009FE, 0x009FE,
0x00A01, 0x00A02, 0x00A3C, 0x00A3C, 0x00A41, 0x00A51, 0x00A70, 0x00A71,
0x00A75, 0x00A75, 0x00A81, 0x00A82, 0x00ABC, 0x00ABC, 0x00AC1, 0x00AC8,
0x00ACD, 0x00ACD, 0x00AE2, 0x00AE3, 0x00AFA, 0x00AFF, 0x00B01, 0x00B01,
0x00B3C, 0x00B3C, 0x00B3F, 0x00B3F, 0x00B41, 0x00B44, 0x00B4D, 0x00B4D,
0x00B55, 0x00B56, 0x00B62, 0x00B63, 0x00B82, 0x00B82, 0x00BC0, 0x00BC0,
0x00BCD, 0x00BCD, 0x00C00, 0x00C00, 0x00C04, 0x00C04, 0x00C3C, 0x00C3C,
0x00C3E, 0x00C40, 0x00C46, 0x00C56, 0x00C62, 0x00C63, 0x00C81, 0x00C81,
0x00CBC, 0x00CBC, 0x00CBF, 0x00CBF, 0x00CC6, 0x00CC6, 0x00CCC, 0x00CCD,
0x00CE2, 0x00CE3, 0x00D00, 0x00D01, 0x00D3B, 0x00D3C, 0x00D41, 0x00D44,
0x00D4D, 0x00D4D, 0x00D62, 0x00D63, 0x00D81, 0x00D81, 0x00DCA, 0x00DCA,
0x00DD2, 0x00DD6, 0x00E31, 0x00E31, 0x00E34, 0x00E3A, 0x00E47, 0x00E4E,
0x00EB1, 0x00EB1, 0x00EB4, 0x00EBC, 0x00EC8, 0x00ECE, 0x00F18, 0x00F19,
0x00F35, 0x00F35, 0x00F37, 0x00F37, 0x00F39, 0x00F39, 0x00F71, 0x00F7E,
0x00F80, 0x00F84, 0x00F86, 0x00F87, 0x00F8D, 0x00FBC, 0x00FC6, 0x00FC6,
0x0102D, 0x01030, 0x01032, 0x01037, 0x01039, 0x0103A, 0x0103D, 0x0103E,
0x01058, 0x01059, 0x0105E, 0x01060, 0x01071, 0x01074, 0x01082, 0x01082,
0x01085, 0x01086, 0x0108D, 0x0108D, 0x0109D, 0x0109D, 0x01160, 0x011FF,
0x0135D, 0x0135F, 0x01712, 0x01714, 0x01732, 0x01733, 0x01752, 0x01753,
0x01772, 0x01773, 0x017B4, 0x017B5, 0x017B7, 0x017BD, 0x017C6, 0x017C6,
0x017C9, 0x017D3, 0x017DD, 0x017DD, 0x0180B, 0x0180F, 0x01885, 0x01886,
0x018A9, 0x018A9, 0x01920, 0x01922, 0x01927, 0x01928, 0x01932, 0x01932,
0x01939, 0x0193B, 0x01A17, 0x01A18, 0x01A1B, 0x01A1B, 0x01A56, 0x01A56,
0x01A58, 0x01A60, 0x01A62, 0x01A62, 0x01A65, 0x01A6C, 0x01A73, 0x01A7F,
0x01AB0, 0x01ACE, 0x01B00, 0x01B03, 0x01B34, 0x01B34, 0x01B36, 0x01B3A,
0x01B3C, 0x01B3C, 0x01B42, 0x01B42, 0x01B6B, 0x01B73, 0x01B80, 0x01B81,
0x01BA2, 0x01BA5, 0x01BA8, 0x01BA9, 0x01BAB, 0x01BAD, 0x01BE6, 0x01BE6,
0x01BE8, 0x01BE9, 0x01BED, 0x01BED, 0x01BEF, 0x01BF1, 0x01C2C, 0x01C33,
0x01C36, 0x01C37, 0x01CD0, 0x01CD2, 0x01CD4, 0x01CE0, 0x01CE2, 0x01CE8,
0x01CED, 0x01CED, 0x01CF4, 0x01CF4, 0x01CF8, 0x01CF9, 0x01DC0, 0x01DFF,
0x0200B, 0x0200F, 0x0202A, 0x0202E, 0x02060, 0x02064, 0x020D0, 0x020F0,
0x02CEF, 0x02CF1, 0x02D7F, 0x02D7F, 0x02DE0, 0x02DFF, 0x0302A, 0x0302D,
0x03099, 0x0309A, 0x0A66F, 0x0A672, 0x0A674, 0x0A67D, 0x0A69E, 0x0A69F,
0x0A6F0, 0x0A6F1, 0x0A802, 0x0A802, 0x0A806, 0x0A806, 0x0A80B, 0x0A80B,
0x0A825, 0x0A826, 0x0A82C, 0x0A82C, 0x0A8C4, 0x0A8C5, 0x0A8E0, 0x0A8F1,
0x0A8FF, 0x0A8FF, 0x0A926, 0x0A92D, 0x0A947, 0x0A951, 0x0A980, 0x0A982,
0x0A9B3, 0x0A9B3, 0x0A9B6, 0x0A9B9, 0x0A9BC, 0x0A9BD, 0x0A9E5, 0x0A9E5,
0x0AA29, 0x0AA2E, 0x0AA31, 0x0AA32, 0x0AA35, 0x0AA36, 0x0AA43, 0x0AA43,
0x0AA4C, 0x0AA4C, 0x0AA7C, 0x0AA7C, 0x0AAB0, 0x0AAB0, 0x0AAB2, 0x0AAB4,
0x0AAB7, 0x0AAB8, 0x0AABE, 0x0AABF, 0x0AAC1, 0x0AAC1, 0x0AAEC, 0x0AAED,
0x0AAF6, 0x0AAF6, 0x0ABE5, 0x0ABE5, 0x0ABE8, 0x0ABE8, 0x0ABED, 0x0ABED,
0x0D7B0, 0x0D7FF, 0x0FB1E, 0x0FB1E, 0x0FE00, 0x0FE0F, 0x0FE20, 0x0FE2F,
0x0FEFF, 0x0FEFF, 0x0FFF9, 0x0FFFB, 0x101FD, 0x101FD, 0x10376, 0x1037A,
0x10A01, 0x10A0F, 0x10A38, 0x10A3F, 0x11001, 0x11001, 0x11038, 0x11046,
0x1107F, 0x11081, 0x110B3, 0x110B6, 0x110B9, 0x110BA, 0x11100, 0x11102,
0x11127, 0x1112B, 0x1112D, 0x11134, 0x1D167, 0x1D169, 0x1D173, 0x1D182,
0x1D185, 0x1D18B, 0x1D1AA, 0x1D1AD, 0x1F3FB, 0x1F3FF, 0xE0001, 0xE0001,
0xE0020, 0xE007F, 0xE0100, 0xE01EF,
};
static const uint32_t wc_wide[206] = {
0x01100, 0x0115F, 0x0231A, 0x0231B, 0x02329, 0x0232A, 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, 0x02E80, 0x03029,
0x0302E, 0x0303E, 0x03041, 0x03096, 0x0309B, 0x033FF, 0x03400, 0x04DBF,
0x04E00, 0x09FFF, 0x0A000, 0x0A4CF, 0x0A960, 0x0A97F, 0x0AC00, 0x0D7A3,
0x0F900, 0x0FAFF, 0x0FE10, 0x0FE19, 0x0FE30, 0x0FE6F, 0x0FF00, 0x0FF60,
0x0FFE0, 0x0FFE6, 0x16FE0, 0x16FE4, 0x16FF0, 0x16FF1, 0x17000, 0x18CD5,
0x18D00, 0x18D08, 0x1AFF0, 0x1B2FB, 0x1F004, 0x1F004, 0x1F0CF, 0x1F0CF,
0x1F18E, 0x1F18E, 0x1F191, 0x1F19A, 0x1F200, 0x1F202, 0x1F210, 0x1F23B,
0x1F240, 0x1F248, 0x1F250, 0x1F251, 0x1F260, 0x1F265, 0x1F300, 0x1F320,
0x1F32D, 0x1F335, 0x1F337, 0x1F37C, 0x1F37E, 0x1F393, 0x1F3A0, 0x1F3CA,
0x1F3CF, 0x1F3D3, 0x1F3E0, 0x1F3F0, 0x1F3F4, 0x1F3F4, 0x1F3F8, 0x1F3FA,
0x1F400, 0x1F43E, 0x1F440, 0x1F440, 0x1F442, 0x1F4FC, 0x1F4FF, 0x1F53D,
0x1F54B, 0x1F54E, 0x1F550, 0x1F567, 0x1F57A, 0x1F57A, 0x1F595, 0x1F596,
0x1F5A4, 0x1F5A4, 0x1F5FB, 0x1F64F, 0x1F680, 0x1F6C5, 0x1F6CC, 0x1F6CC,
0x1F6D0, 0x1F6D2, 0x1F6D5, 0x1F6D7, 0x1F6DC, 0x1F6DF, 0x1F6EB, 0x1F6EC,
0x1F6F4, 0x1F6FC, 0x1F7E0, 0x1F7EB, 0x1F7F0, 0x1F7F0, 0x1F90C, 0x1F93A,
0x1F93C, 0x1F945, 0x1F947, 0x1F9FF, 0x1FA70, 0x1FA7C, 0x1FA80, 0x1FA88,
0x1FA90, 0x1FABD, 0x1FABF, 0x1FAC5, 0x1FACE, 0x1FADB, 0x1FAE0, 0x1FAE8,
0x1FAF0, 0x1FAF8, 0x20000, 0x2FFFD, 0x30000, 0x3FFFD,
};
static int in_ranges(uint32_t cp, const uint32_t *r, int pairs)
{
int lo = 0, hi = pairs - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (cp < r[mid * 2])
hi = mid - 1;
else if (cp > r[mid * 2 + 1])
lo = mid + 1;
else
return 1;
}
return 0;
}
int wcwidth_of(uint32_t cp)
{
if (cp < 0x300)
return 1;
if (in_ranges(cp, wc_zero, (int)(sizeof(wc_zero) / sizeof(wc_zero[0]) / 2)))
return 0;
if (in_ranges(cp, wc_wide, (int)(sizeof(wc_wide) / sizeof(wc_wide[0]) / 2)))
return 2;
return 1;
}
-3707
View File
File diff suppressed because it is too large. Load diff
-2783
View File
File diff suppressed because it is too large. Load diff
-316
View File
@@ -1,316 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_fonts.c - the terminal types' fonts (the app's MachineFonts): each
* machine's own character ROM (vt_data.c's, SyncTERM's set) read in its
* own set, so a cell's code point is drawn with the glyph its machine
* drew for it; what a ROM hasn't got from Unscii's. Made when first
* asked for and kept.
*/
#include <stdlib.h>
#include <string.h>
#include "vtint.h"
/* the Atari ST's set from 0x80: Latin letters, Hebrew, Greek and
mathematics */
static const uint32_t st_high[128] = {
0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,
0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,
0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,
0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0xdf, 0x192,
0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,
0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,
0xe3, 0xf5, 0xd8, 0xf8, 0x153, 0x152, 0xc0, 0xc3,
0xd5, 0xa8, 0xb4, 0x2020, 0xb6, 0xa9, 0xae, 0x2122,
0x133, 0x132, 0x5d0, 0x5d1, 0x5d2, 0x5d3, 0x5d4, 0x5d5,
0x5d6, 0x5d7, 0x5d8, 0x5d9, 0x5db, 0x5dc, 0x5de, 0x5e0,
0x5e1, 0x5e2, 0x5e4, 0x5e6, 0x5e7, 0x5e8, 0x5e9, 0x5ea,
0x5df, 0x5da, 0x5dd, 0x5e3, 0x5e5, 0xa7, 0x2227, 0x221e,
0x3b1, 0x3b2, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4,
0x3a6, 0x398, 0x3a9, 0x3b4, 0x222e, 0x3d5, 0x2208, 0x2229,
0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248,
0xb0, 0x2022, 0xb7, 0x221a, 0x207f, 0xb2, 0xb3, 0xaf,
};
uint32_t atari_st_char(int b)
{
return b >= 0x80 && b <= 0xff ? st_high[b - 0x80] : (uint32_t)b;
}
/* teletext's English set, 0x20-0x7f: £ for #, arrows, fractions, # for
_, a dash, ‖, ÷ and a block */
uint32_t viewdata_g0(int c)
{
switch (c) {
case 0x23: return 0xa3;
case 0x5b: return 0x2190;
case 0x5c: return 0xbd;
case 0x5d: return 0x2192;
case 0x5e: return 0x2191;
case 0x5f: return '#';
case 0x60: return 0x2014;
case 0x7b: return 0xbc;
case 0x7c: return 0x2016;
case 0x7d: return 0xbe;
case 0x7e: return 0xf7;
case 0x7f: return 0x25a0;
}
return (uint32_t)c;
}
/* a font being made: its glyphs by code point, the first one put kept */
struct builder {
int h, n, cap;
uint32_t *codes;
uint8_t *rows;
};
static int b_has(const struct builder *b, uint32_t cp)
{
int i;
for (i = 0; i < b->n; i++)
if (b->codes[i] == cp)
return 1;
return 0;
}
static void b_put(struct builder *b, uint32_t cp, const uint8_t *rows)
{
if (cp == 0 || b_has(b, cp))
return;
if (b->n == b->cap) {
int cap = b->cap ? b->cap * 2 : 512;
uint32_t *c = (uint32_t *)realloc(b->codes, cap * sizeof(*c));
uint8_t *r = (uint8_t *)realloc(b->rows, (size_t)cap * b->h);
if (!c || !r) {
free(c ? c : b->codes);
free(r ? r : b->rows);
b->codes = NULL;
b->rows = NULL;
b->n = b->cap = 0;
return;
}
b->codes = c;
b->rows = r;
b->cap = cap;
}
b->codes[b->n] = cp;
memcpy(b->rows + (size_t)b->n * b->h, rows, b->h);
b->n++;
}
/* code's glyph of ROM r, h (8 or 16) rows: its own, or its 8 doubled or
its 16 halved (both rows' pixels, so a thin stroke stays) */
static void rom_glyph(int r, int code, int h, uint8_t *out)
{
const struct vt_rom *rom = &vt_roms[r];
int i;
if (h == 16 && rom->r16) {
memcpy(out, rom->r16 + code * 16, 16);
} else if (h == 8 && rom->r8) {
memcpy(out, rom->r8 + code * 8, 8);
} else if (h == 16) {
for (i = 0; i < 16; i++)
out[i] = rom->r8[code * 8 + i / 2];
} else {
for (i = 0; i < 8; i++)
out[i] = rom->r16[code * 16 + 2 * i] |
rom->r16[code * 16 + 2 * i + 1];
}
}
/* ROM r's codes from..to, each as the code point map gives it (0: none) */
static void b_rom(struct builder *b, int r, int from, int to,
uint32_t (*map)(int, const void *), const void *ctx)
{
uint8_t g[16];
int c;
for (c = from; c <= to; c++) {
uint32_t cp = map(c, ctx);
if (cp == 0 || b_has(b, cp))
continue;
rom_glyph(r, c, b->h, g);
b_put(b, cp, g);
}
}
static void b_font(struct builder *b, const struct vt_font *f)
{
int i;
if (!f || f->h != b->h)
return;
for (i = 0; i < f->n; i++)
b_put(b, f->codes[i], f->rows8 + (size_t)i * f->h);
}
static int cmp_code(const void *a, const void *b)
{
uint32_t x = *(const uint32_t *)a, y = *(const uint32_t *)b;
return x < y ? -1 : x > y;
}
/* the font made: its glyphs sorted by code point */
static const struct vt_font *b_done(struct builder *b)
{
struct vt_font *f = (struct vt_font *)calloc(1, sizeof(*f));
uint32_t *idx, *codes;
uint8_t *rows;
int i;
/* (each code and its place, sorted together) */
idx = (uint32_t *)malloc(sizeof(uint32_t) * 2 * (b->n ? b->n : 1));
codes = (uint32_t *)malloc(sizeof(uint32_t) * (b->n ? b->n : 1));
rows = (uint8_t *)malloc((size_t)(b->n ? b->n : 1) * b->h);
if (!f || !idx || !codes || !rows) {
free(f);
free(idx);
free(codes);
free(rows);
free(b->codes);
free(b->rows);
return NULL;
}
for (i = 0; i < b->n; i++) {
idx[2 * i] = b->codes[i];
idx[2 * i + 1] = (uint32_t)i;
}
qsort(idx, b->n, 2 * sizeof(uint32_t), cmp_code);
for (i = 0; i < b->n; i++) {
codes[i] = idx[2 * i];
memcpy(rows + (size_t)i * b->h,
b->rows + (size_t)idx[2 * i + 1] * b->h, b->h);
}
free(idx);
free(b->codes);
free(b->rows);
f->w = 8;
f->h = b->h;
f->n = b->n;
f->codes = codes;
f->rows8 = rows;
f->rows32 = NULL;
return f;
}
/* octet b's code point in a charset (0 for a control) */
static uint32_t octet(int b, const void *ctx)
{
int cs = *(const int *)ctx;
if (b < 0x20 || b == 0x7f)
return 0;
if (cs == CS_CP437)
return cp437_decode(b);
if (b >= 0x80 && b <= 0x9f)
return 0;
if (cs == CS_LATIN1)
return (uint32_t)b;
return b < 0x80 ? (uint32_t)b : 0;
}
static uint32_t in_set(int b, const void *ctx)
{
return ((const uint32_t *)ctx)[b];
}
static uint32_t st_map(int b, const void *ctx)
{
(void)ctx;
return atari_st_char(b);
}
static uint32_t g0_map(int b, const void *ctx)
{
(void)ctx;
return viewdata_g0(b);
}
static const struct vt_font *fallback(int h)
{
return h == 16 ? &vt_font_vga : &vt_font_8x8;
}
/* ROM r read in charset cs, h rows */
static const struct vt_font *in_charset(int r, int h, int cs)
{
struct builder b;
memset(&b, 0, sizeof(b));
b.h = h;
b_rom(&b, r, 0x20, 0xff, octet, &cs);
b_font(&b, fallback(h));
return b_done(&b);
}
static const struct vt_font *make(int which)
{
struct builder b;
memset(&b, 0, sizeof(b));
b.h = 8;
switch (which) {
case MF_VGA:
return in_charset(ROM_VGA, 16, CS_CP437);
case MF_RIPTERM:
return in_charset(ROM_RIPTERM, 8, CS_CP437);
case MF_TOPAZ:
return in_charset(ROM_TOPAZ, 8, CS_LATIN1);
case MF_C64:
case MF_C128:
b_rom(&b, which == MF_C64 ? ROM_C64_UPPER : ROM_C128_UPPER,
0, 0xff, in_set, vt_set_c64_upper);
b_rom(&b, which == MF_C64 ? ROM_C64_LOWER : ROM_C128_LOWER,
0, 0xff, in_set, vt_set_c64_lower);
break;
case MF_ATARI:
b_rom(&b, ROM_ATARI, 0, 0x7f, in_set, vt_set_atari_graphics);
break;
case MF_ATARI_ST:
b_rom(&b, ROM_ATARI_ST, 0x20, 0xff, st_map, NULL);
break;
case MF_PRESTEL:
b.h = 16;
b_rom(&b, ROM_PRESTEL, 0x20, 0x7f, g0_map, NULL);
break;
default:
return NULL;
}
b_font(&b, fallback(b.h));
return b_done(&b);
}
static const struct vt_font *made[MF_COUNT];
const struct vt_font *machine_font(int which)
{
if (which < 0 || which >= MF_COUNT)
return NULL;
if (!made[which])
made[which] = make(which);
return made[which];
}
/* SyncTERM's numbers (CSI SP D's) and the ROMs */
static const int syncterm_rom[][2] = {
{ 0, ROM_VGA }, { 26, ROM_VGA_THIN }, { 32, ROM_C64_UPPER },
{ 33, ROM_C64_LOWER }, { 34, ROM_C128_UPPER }, { 35, ROM_C128_LOWER },
{ 36, ROM_ATARI }, { 37, ROM_POT_NOODLE }, { 38, ROM_MOSOUL },
{ 39, ROM_MICROKNIGHT_PLUS }, { 40, ROM_TOPAZ_PLUS },
{ 41, ROM_MICROKNIGHT }, { 42, ROM_TOPAZ }, { 43, ROM_PRESTEL },
{ 44, ROM_ATARI_ST }
};
#define N_SYNCTERM ((int)(sizeof(syncterm_rom) / sizeof(syncterm_rom[0])))
/* each one made, by ROM, height (8 or 16) and charset */
static const struct vt_font *synctermed[ROM_COUNT][2][3];
const struct vt_font *syncterm_font(int n, int height, int charset)
{
int i, r = -1, hi = height == 16 ? 1 : 0;
for (i = 0; i < N_SYNCTERM; i++)
if (syncterm_rom[i][0] == n)
r = syncterm_rom[i][1];
if (r < 0 || charset < 0 || charset > 2)
return NULL;
if (!synctermed[r][hi][charset])
synctermed[r][hi][charset] = in_charset(r, hi ? 16 : 8, charset);
return synctermed[r][hi][charset];
}
-970
View File
@@ -1,970 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_gfx.c - the terminal's graphics: sixel images (the app's Sixel), a
* graphics terminal's picture over the screen (Raster, PictureLayer) and
* the Tektronix 4010/4014 (TektronixInterpreter).
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "vtint.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
static int clampi(int v, int lo, int hi)
{
return v < lo ? lo : v > hi ? hi : v;
}
static int maxi(int a, int b)
{
return a > b ? a : b;
}
static int mini(int a, int b)
{
return a < b ? a : b;
}
static int roundi(double v)
{
return (int)floor(v + 0.5);
}
/* ------------------------------------------------------------------ */
/* sixel */
struct sixel {
int transparent;
uint32_t own[256];
uint32_t *palette;
int max_w, max_h;
int color, x, y, repeat;
uint32_t *buf;
int buf_w, buf_h;
int width, height;
int command, params[5], nparams;
int failed;
};
static int pct(int v)
{
return (clampi(v, 0, 100) * 255 + 50) / 100;
}
static uint32_t rgb(int r, int g, int b)
{
return 0xff000000u | ((uint32_t)r << 16) | ((uint32_t)g << 8) | (uint32_t)b;
}
static int hue(double p, double q, double t)
{
double v;
if (t < 0)
t += 1.0;
if (t > 1)
t -= 1.0;
if (t < 1.0 / 6)
v = p + (q - p) * 6 * t;
else if (t < 1.0 / 2)
v = q;
else if (t < 2.0 / 3)
v = p + (q - p) * (2.0 / 3 - t) * 6;
else
v = p;
return clampi(roundi(v * 255), 0, 255);
}
uint32_t sixel_hls(int hdeg, int lpct, int spct)
{
double l = clampi(lpct, 0, 100) / 100.0, s = clampi(spct, 0, 100) / 100.0;
/* DEC's hue is the usual one turned by 240 degrees (its 0 is blue) */
double h = (((hdeg + 240) % 360) + 360) % 360 / 360.0, q, p;
if (s == 0.0) {
int v = roundi(l * 255);
return rgb(v, v, v);
}
q = l < 0.5 ? l * (1 + s) : l + s - l * s;
p = 2 * l - q;
return rgb(hue(p, q, h + 1.0 / 3), hue(p, q, h), hue(p, q, h - 1.0 / 3));
}
void sixel_default_palette(uint32_t p[256])
{
static const uint8_t vt340[48] = {
0, 0, 0, 20, 20, 80, 80, 13, 13, 20, 80, 20, 80, 20, 80, 20, 80, 80,
80, 80, 20, 53, 53, 53, 26, 26, 26, 33, 33, 60, 60, 26, 26, 33, 60, 33,
60, 33, 60, 33, 60, 60, 60, 60, 33, 80, 80, 80
};
static const int steps[6] = { 0, 95, 135, 175, 215, 255 };
int i;
for (i = 0; i < 16; i++)
p[i] = rgb(pct(vt340[i * 3]), pct(vt340[i * 3 + 1]), pct(vt340[i * 3 + 2]));
for (i = 16; i < 232; i++) {
int n = i - 16;
p[i] = rgb(steps[n / 36], steps[(n / 6) % 6], steps[n % 6]);
}
for (i = 232; i < 256; i++) {
int v = 8 + (i - 232) * 10;
p[i] = rgb(v, v, v);
}
}
struct sixel *sixel_new(int transparent, uint32_t *shared, int max_w, int max_h)
{
struct sixel *s = (struct sixel *)calloc(1, sizeof(*s));
if (!s)
return NULL;
s->transparent = transparent;
if (shared) {
s->palette = shared;
} else {
sixel_default_palette(s->own);
s->palette = s->own;
}
s->max_w = max_w > 0 ? max_w : 1;
s->max_h = max_h > 0 ? max_h : 1;
s->repeat = 1;
return s;
}
void sixel_free(struct sixel *s)
{
if (s) {
free(s->buf);
free(s);
}
}
/* the buffer made at least w x h (doubling, so that growing is cheap) */
static int grow(struct sixel *s, int w, int h)
{
int nw, nh, r;
uint32_t *nb;
if (w <= s->buf_w && h <= s->buf_h)
return 1;
if (s->failed)
return 0;
nw = maxi(s->buf_w, mini(s->max_w, maxi(maxi(w, s->buf_w * 2), 64)));
nh = maxi(s->buf_h, mini(s->max_h + 6, maxi(maxi(h, s->buf_h * 2), 64)));
nb = (uint32_t *)calloc((size_t)nw * nh, sizeof(uint32_t));
if (!nb) {
s->failed = 1;
return 0;
}
for (r = 0; r < s->buf_h; r++)
memcpy(nb + (size_t)r * nw, s->buf + (size_t)r * s->buf_w,
(size_t)s->buf_w * sizeof(uint32_t));
free(s->buf);
s->buf = nb;
s->buf_w = nw;
s->buf_h = nh;
return 1;
}
static void end_command(struct sixel *s)
{
int n;
switch (s->command) {
case '!':
s->repeat = s->params[0] > 1 ? s->params[0] : 1;
break;
case '#':
n = s->params[0] & 0xff;
if (s->nparams >= 5)
s->palette[n] = s->params[1] == 1 ?
sixel_hls(s->params[2], s->params[3], s->params[4]) :
rgb(pct(s->params[2]), pct(s->params[3]), pct(s->params[4]));
s->color = n;
break;
case '"':
if (s->nparams >= 4 && s->params[2] > 0 && s->params[3] > 0) {
int w = mini(s->params[2], s->max_w), h = mini(s->params[3], s->max_h);
if (grow(s, w, h)) {
s->width = maxi(s->width, w);
s->height = maxi(s->height, h);
}
}
break;
}
s->command = 0;
}
static void sixel_bits(struct sixel *s, int bits)
{
int n = s->repeat, b, right, px;
s->repeat = 1;
if (bits && s->y < s->max_h) {
right = mini(s->x + n, s->max_w);
if (right > s->x && grow(s, right, s->y + 6)) {
uint32_t c = s->palette[s->color];
for (b = 0; b < 6; b++) {
int row = s->y + b;
uint32_t *base;
if (!(bits & (1 << b)))
continue;
if (row >= s->max_h)
break;
base = s->buf + (size_t)row * s->buf_w;
for (px = s->x; px < right; px++)
base[px] = c;
if (row + 1 > s->height)
s->height = row + 1;
}
if (right > s->width)
s->width = right;
}
}
if (s->x < 1 << 20)
s->x += n;
}
void sixel_feed(struct sixel *s, int32_t cp)
{
if (s->command) {
if (cp >= '0' && cp <= '9') {
if (s->nparams == 0)
s->nparams = 1;
if (s->nparams <= 5) {
int *v = &s->params[s->nparams - 1];
*v = mini(*v * 10 + (cp - '0'), 99999);
}
return;
}
if (cp == ';') {
if (s->nparams == 0)
s->nparams = 1;
if (s->nparams < 5) {
s->params[s->nparams] = 0;
s->nparams++;
}
return;
}
end_command(s);
}
if (cp >= 0x3f && cp <= 0x7e) {
sixel_bits(s, cp - 0x3f);
} else if (cp == '#' || cp == '!' || cp == '"') {
s->command = cp;
s->nparams = 0;
memset(s->params, 0, sizeof(s->params));
} else if (cp == '$') {
s->x = 0;
} else if (cp == '-') {
s->x = 0;
if (s->y < 1 << 20)
s->y += 6;
}
}
struct vt_image *sixel_finish(dmc_vt *t, struct sixel *s, int cw, int ch)
{
int h, r, i;
struct vt_image *img;
(void)t;
if (s->command)
end_command(s);
h = mini(s->height, s->max_h);
if (s->width <= 0 || h <= 0 || !s->buf)
return NULL;
img = image_new(s->width, h, cw, ch, 0);
for (r = 0; r < h; r++)
memcpy(img->pixels + (size_t)r * s->width, s->buf + (size_t)r * s->buf_w,
(size_t)s->width * sizeof(uint32_t));
if (!s->transparent) {
/* the background: register 0 as the image left it */
uint32_t bg = s->palette[0];
for (i = 0; i < s->width * h; i++)
if (!img->pixels[i])
img->pixels[i] = bg;
}
return img;
}
/* ------------------------------------------------------------------ */
/* the raster */
struct raster *raster_new(int w, int h, int lw, int lh)
{
struct raster *r = (struct raster *)calloc(1, sizeof(*r));
if (!r)
return NULL;
r->width = w > 0 ? w : 1;
r->height = h > 0 ? h : 1;
r->lw = lw > 0 ? lw : 1;
r->lh = lh > 0 ? lh : 1;
r->px = (uint32_t *)calloc((size_t)r->width * r->height, sizeof(uint32_t));
if (!r->px) {
free(r);
return NULL;
}
r->mode = R_OVERLAY;
r->color = 0xffffffffu;
r->pattern = 0xff;
return r;
}
void raster_free(struct raster *r)
{
if (r) {
free(r->px);
free(r);
}
}
int raster_px(const struct raster *r, int x)
{
return (int)((long long)x * r->width / r->lw);
}
int raster_py(const struct raster *r, int y)
{
return (int)((long long)y * r->height / r->lh);
}
void raster_clear(struct raster *r, uint32_t c)
{
int i, n = r->width * r->height;
for (i = 0; i < n; i++)
r->px[i] = c;
r->dirty = 1;
}
static void put(struct raster *r, int x, int y, int on)
{
uint32_t *p;
if (x < 0 || x >= r->width || y < 0 || y >= r->height)
return;
if (r->has_clip && (x < r->clip[0] || y < r->clip[1] || x > r->clip[2] ||
y > r->clip[3]))
return;
p = &r->px[y * r->width + x];
switch (r->mode) {
case R_OVERLAY: if (on) *p = r->color; break;
case R_REPLACE: *p = on ? r->color : r->background; break;
case R_COMPLEMENT: if (on) *p = (*p ^ 0x00ffffffu) | 0xff000000u; break;
case R_ERASE: *p = r->background; break;
}
r->dirty = 1;
}
void raster_point(struct raster *r, int x, int y)
{
put(r, raster_px(r, x), raster_py(r, y), 1);
}
static void pixel_line(struct raster *r, int ax, int ay, int bx, int by)
{
int x = ax, y = ay, dx = abs(bx - ax), dy = -abs(by - ay);
int sx = ax < bx ? 1 : -1, sy = ay < by ? 1 : -1, err = dx + dy, e2;
for (;;) {
put(r, x, y, (r->pattern & (0x80 >> (r->pattern_step & 7))) != 0);
r->pattern_step++;
if (x == bx && y == by)
break;
e2 = 2 * err;
if (e2 >= dy) {
err += dy;
x += sx;
}
if (e2 <= dx) {
err += dx;
y += sy;
}
}
}
void raster_line(struct raster *r, int x0, int y0, int x1, int y1)
{
pixel_line(r, raster_px(r, x0), raster_py(r, y0), raster_px(r, x1),
raster_py(r, y1));
}
static void pixel_arc(struct raster *r, int cx, int cy, double rx, double ry,
double start, double sweep)
{
double big = rx > ry ? rx : ry;
int steps = (int)(fabs(sweep) / 360 * (big * 2 > 8.0 ? big * 2 : 8.0) * M_PI);
int lx = 0, ly = 0, i;
if (steps < 16)
steps = 16;
if (steps > 100000)
steps = 100000;
for (i = 0; i <= steps; i++) {
double a = (start + sweep * i / steps) * M_PI / 180;
int x = cx + roundi(rx * cos(a)), y = cy - roundi(ry * sin(a));
if (i > 0)
pixel_line(r, lx, ly, x, y);
lx = x;
ly = y;
}
}
void raster_arc(struct raster *r, int cx, int cy, int rad, double start,
double sweep)
{
double pr = raster_px(r, rad);
pixel_arc(r, raster_px(r, cx), raster_py(r, cy), pr, pr, start, sweep);
}
void raster_ellipse(struct raster *r, int cx, int cy, int rx, int ry,
double start, double sweep)
{
pixel_arc(r, raster_px(r, cx), raster_py(r, cy),
(double)rx * r->width / r->lw, (double)ry * r->height / r->lh,
start, sweep);
}
int raster_ellipse_points(int cx, int cy, int rx, int ry, double start,
double sweep, int *xy, int max)
{
int n = (int)(fabs(sweep) / 360 * 64), i, k = 0;
if (n < 16)
n = 16;
for (i = 0; i <= n && k < max; i++) {
double a = (start + sweep * i / n) * M_PI / 180;
xy[2 * k] = cx + roundi(rx * cos(a));
xy[2 * k + 1] = cy - roundi(ry * sin(a));
k++;
}
return k;
}
static void fill_pixel(struct raster *r, int x, int y)
{
const uint8_t *p = r->fill_pattern;
if (!p) {
put(r, x, y, 1);
return;
}
if ((p[y & 7] >> (7 - (x & 7))) & 1) {
put(r, x, y, 1);
} else if (r->fill_background) {
uint32_t c = r->color;
r->color = r->fill_background;
put(r, x, y, 1);
r->color = c;
}
}
static int cmp_int(const void *a, const void *b)
{
int x = *(const int *)a, y = *(const int *)b;
return x < y ? -1 : x > y;
}
void raster_fill(struct raster *r, const int *xy, int n)
{
int *p, *xs, top, bottom, i, y, k, x;
if (n < 3)
return;
p = (int *)malloc(sizeof(int) * 2 * (size_t)n);
xs = (int *)malloc(sizeof(int) * (size_t)n);
if (!p || !xs) {
free(p);
free(xs);
return;
}
top = 1 << 30;
bottom = -(1 << 30);
for (i = 0; i < n; i++) {
p[2 * i] = raster_px(r, xy[2 * i]);
p[2 * i + 1] = raster_py(r, xy[2 * i + 1]);
top = mini(top, p[2 * i + 1]);
bottom = maxi(bottom, p[2 * i + 1]);
}
top = maxi(top, 0);
bottom = mini(bottom, r->height - 1);
for (y = top; y <= bottom; y++) {
int nx = 0;
for (i = 0; i < n; i++) {
int x0 = p[2 * i], y0 = p[2 * i + 1];
int x1 = p[2 * ((i + 1) % n)], y1 = p[2 * ((i + 1) % n) + 1];
if (y0 == y1)
continue;
if (y >= mini(y0, y1) && y < maxi(y0, y1))
xs[nx++] = x0 + (int)((long long)(y - y0) * (x1 - x0) / (y1 - y0));
}
qsort(xs, nx, sizeof(int), cmp_int);
for (k = 0; k + 1 < nx; k += 2) {
int a = maxi(xs[k], -1), b = mini(xs[k + 1], r->width);
for (x = a; x <= b; x++)
fill_pixel(r, x, y);
}
}
free(p);
free(xs);
}
void raster_flood(struct raster *r, int x, int y, uint32_t border)
{
int sx = raster_px(r, x), sy = raster_py(r, y), w = r->width, h = r->height;
uint8_t *seen;
int *stack, n = 0, cap;
if (sx < 0 || sx >= w || sy < 0 || sy >= h || r->px[sy * w + sx] == border)
return;
seen = (uint8_t *)calloc((size_t)w * h, 1);
cap = 4096;
stack = (int *)malloc(sizeof(int) * (size_t)cap);
if (!seen || !stack) {
free(seen);
free(stack);
return;
}
#define INSIDE(i) (!seen[i] && r->px[i] != border && \
(!r->has_clip || ((i) % w >= r->clip[0] && (i) / w >= r->clip[1] && \
(i) % w <= r->clip[2] && (i) / w <= r->clip[3])))
stack[n++] = sy * w + sx;
while (n > 0) {
int i = stack[--n], row, l, rr, xx, k;
if (!INSIDE(i))
continue;
row = i / w;
l = rr = i % w;
while (l > 0 && INSIDE(row * w + l - 1))
l--;
while (rr < w - 1 && INSIDE(row * w + rr + 1))
rr++;
for (xx = l; xx <= rr; xx++)
seen[row * w + xx] = 1;
for (xx = l; xx <= rr; xx++)
fill_pixel(r, xx, row);
for (k = -1; k <= 1; k += 2) {
int ny = row + k;
if (ny < 0 || ny >= h)
continue;
for (xx = l; xx <= rr; xx++)
if (INSIDE(ny * w + xx)) {
if (n == cap) {
int *ns;
cap *= 2;
ns = (int *)realloc(stack, sizeof(int) * (size_t)cap);
if (!ns) {
free(seen);
free(stack);
return;
}
stack = ns;
}
stack[n++] = ny * w + xx;
}
}
}
#undef INSIDE
free(seen);
free(stack);
r->dirty = 1;
}
void raster_grab(const struct raster *r, int x0, int y0, int x1, int y1,
struct raster_grab *g)
{
int l = clampi(raster_px(r, mini(x0, x1)), 0, r->width - 1);
int t = clampi(raster_py(r, mini(y0, y1)), 0, r->height - 1);
int rr = clampi(raster_px(r, maxi(x0, x1) + 1), l + 1, r->width);
int b = clampi(raster_py(r, maxi(y0, y1) + 1), t + 1, r->height);
int yy;
g->width = rr - l;
g->height = b - t;
g->px = (uint32_t *)malloc(sizeof(uint32_t) * (size_t)g->width * g->height);
if (!g->px) {
g->width = g->height = 0;
return;
}
for (yy = 0; yy < g->height; yy++)
memcpy(g->px + (size_t)yy * g->width, r->px + (size_t)(t + yy) * r->width + l,
sizeof(uint32_t) * (size_t)g->width);
}
void raster_put(struct raster *r, const struct raster_grab *g, int x, int y,
int xor_)
{
int l = raster_px(r, x), t = raster_py(r, y), xx, yy;
for (yy = 0; yy < g->height; yy++)
for (xx = 0; xx < g->width; xx++) {
int dx = l + xx, dy = t + yy;
uint32_t v, *p;
if (dx < 0 || dx >= r->width || dy < 0 || dy >= r->height)
continue;
if (r->has_clip && (dx < r->clip[0] || dy < r->clip[1] ||
dx > r->clip[2] || dy > r->clip[3]))
continue;
v = g->px[yy * g->width + xx];
p = &r->px[dy * r->width + dx];
*p = xor_ ? (*p ^ v) | ((*p | v) ? 0xff000000u : 0) : v;
}
r->dirty = 1;
}
void raster_pixel_rect(const struct raster *r, int x0, int y0, int x1, int y1,
int out[4])
{
out[0] = raster_px(r, mini(x0, x1));
out[1] = raster_py(r, mini(y0, y1));
out[2] = raster_px(r, maxi(x0, x1) + 1) - 1;
out[3] = raster_py(r, maxi(y0, y1) + 1) - 1;
}
void raster_clear_rect(struct raster *r, int x0, int y0, int x1, int y1,
uint32_t c)
{
int q[4], xx, yy;
raster_pixel_rect(r, x0, y0, x1, y1, q);
for (yy = maxi(0, q[1]); yy <= mini(r->height - 1, q[3]); yy++)
for (xx = maxi(0, q[0]); xx <= mini(r->width - 1, q[2]); xx++)
r->px[yy * r->width + xx] = c;
r->dirty = 1;
}
static void glyph(struct raster *r, uint32_t cp, int x, int y,
const struct vt_font *f, int cw, int ch)
{
int left, top, w, h, xx, yy;
if (font_index(f, cp) < 0)
return;
left = raster_px(r, x);
top = raster_py(r, y);
w = maxi(1, raster_px(r, x + cw) - left);
h = maxi(1, raster_py(r, y + ch) - top);
for (yy = 0; yy < h; yy++) {
/* (shrunk: the rows it covers merged, so a thin stroke stays) */
int r0 = yy * f->h / h, r1 = maxi(r0 + 1, (yy + 1) * f->h / h), k;
uint32_t row = 0;
for (k = r0; k < r1; k++)
row |= font_row(f, cp, k);
if (!row)
continue;
for (xx = 0; xx < w; xx++) {
int c0 = xx * f->w / w, c1 = maxi(c0 + 1, (xx + 1) * f->w / w), on = 0;
for (k = c0; k < c1; k++)
if ((row >> (f->w - 1 - k)) & 1)
on = 1;
if (on)
put(r, left + xx, top + yy, 1);
}
}
}
int raster_text(struct raster *r, int x, int y, const uint32_t *cps, int n,
const struct vt_font *f, int cw, int ch)
{
int i;
if (!f)
return x + n * cw;
for (i = 0; i < n; i++) {
glyph(r, cps[i], x, y, f, cw, ch);
x += cw;
}
return x;
}
struct vt_image *raster_take(dmc_vt *t, struct raster *r, int cw, int ch)
{
struct vt_image *img = image_new(r->width, r->height, cw, ch, 1);
(void)t;
memcpy(img->pixels, r->px, sizeof(uint32_t) * (size_t)r->width * r->height);
r->dirty = 0;
return img;
}
/* ------------------------------------------------------------------ */
/* the picture layer */
static int pixel_w(const dmc_vt *t)
{
return maxi(1, t->cols * t->cell_pw);
}
static int pixel_h(const dmc_vt *t)
{
return maxi(1, t->rows * t->cell_ph);
}
static struct raster *make(struct picture_layer *l)
{
struct raster *r = raster_new(pixel_w(l->t), pixel_h(l->t), l->lw, l->lh);
if (r && l->setup)
l->setup(r, l->ctx);
return r;
}
void layer_init(struct picture_layer *l, dmc_vt *t, int lw, int lh,
void (*setup)(struct raster *, void *), void *ctx)
{
l->t = t;
l->lw = lw;
l->lh = lh;
l->setup = setup;
l->ctx = ctx;
l->r = make(l);
}
void layer_reset(struct picture_layer *l)
{
struct raster *r = make(l);
if (!r)
return;
raster_free(l->r);
l->r = r;
raster_clear(r, 0);
}
struct raster *layer_raster(struct picture_layer *l)
{
if (!l->r || pixel_w(l->t) != l->r->width || pixel_h(l->t) != l->r->height)
layer_reset(l);
return l->r;
}
void layer_flush(struct picture_layer *l)
{
struct raster *r = layer_raster(l);
if (r && r->dirty)
vt_show_picture(l->t, raster_take(l->t, r, l->t->cell_pw, l->t->cell_ph));
}
void layer_free(struct picture_layer *l)
{
raster_free(l->r);
l->r = NULL;
}
/* ------------------------------------------------------------------ */
/* the Tektronix 4010/4014 */
#define TEK_W 4096
#define TEK_H 3120
#define TEK_STEP 4
#define TEK_INK 0xffc8ffc8u
enum { TM_ALPHA, TM_GRAPH, TM_POINT, TM_INCREMENTAL };
static const int char_w[4] = { 56, 51, 34, 31 };
static const int char_h[4] = { 88, 82, 53, 48 };
static const int styles[8] = { 0xff, 0xaa, 0xe4, 0xcc, 0xf0, 0xff, 0xff, 0xff };
struct tek {
struct vt_interp in;
void (*on_exit)(void *);
void *ctx;
struct picture_layer layer;
int mode, x, y, dark, pen, size, escaped;
int hi_x, hi_y, lo_x, lo_y, extra, last_lo_y;
};
static void tek_setup(struct raster *r, void *ctx)
{
(void)ctx;
r->color = TEK_INK;
}
static void tek_home(struct tek *k)
{
k->mode = TM_ALPHA;
k->x = 0;
k->y = TEK_H - char_h[k->size];
}
static int row(int ty)
{
return TEK_H - 1 - ty;
}
static void tek_process(struct vt_interp *in, int32_t cp);
static void tek_report(struct tek *k)
{
int sx = k->x >> 2, sy = k->y >> 2;
char s[8];
s[0] = (char)(k->mode == TM_ALPHA ? 0x34 : 0x30);
s[1] = (char)(0x20 | ((sx >> 5) & 0x1f));
s[2] = (char)(0x20 | (sx & 0x1f));
s[3] = (char)(0x20 | ((sy >> 5) & 0x1f));
s[4] = (char)(0x20 | (sy & 0x1f));
s[5] = '\r';
s[6] = 0;
vt_reply(k->in.t, s);
}
static void tek_esc(struct tek *k, int c)
{
if (c == 0x0c) {
raster_clear(layer_raster(&k->layer), 0);
tek_home(k);
} else if (c == 0x05) {
tek_report(k);
} else if (c >= '8' && c <= ';') {
k->size = c - '8';
} else if (c >= 0x60 && c <= 0x67) {
layer_raster(&k->layer)->pattern = styles[(c - 0x60) & 7];
} else if (c == 0x03) {
if (k->on_exit)
k->on_exit(k->ctx);
} else if (c < 0x20) {
tek_process(&k->in, c);
}
}
static void tek_alpha(struct tek *k, int c)
{
int cw = char_w[k->size], ch = char_h[k->size];
uint32_t cp = (uint32_t)c;
switch (c) {
case 0x08: k->x = maxi(k->x - cw, 0); break;
case 0x09: k->x += cw; break;
case 0x0a:
k->y -= ch;
if (k->y < 0)
k->y = TEK_H - ch;
break;
case 0x0b: k->y = mini(k->y + ch, TEK_H - ch); break;
default:
if (c < 0x20 || c > 0x7e)
break;
if (k->x + cw > TEK_W) {
k->x = 0;
k->y -= ch;
if (k->y < 0)
k->y = TEK_H - ch;
}
if (c != 0x20)
raster_text(layer_raster(&k->layer), k->x, row(k->y + ch), &cp, 1,
&vt_font_vga, cw, ch);
k->x += cw;
}
}
static void tek_to(struct tek *k, int nx, int ny)
{
if (k->mode == TM_POINT)
raster_point(layer_raster(&k->layer), nx, row(ny));
else if (k->dark)
k->dark = 0;
else
raster_line(layer_raster(&k->layer), k->x, row(k->y), nx, row(ny));
k->x = nx;
k->y = ny;
}
static void tek_address(struct tek *k, int c)
{
int v = c & 0x1f, nx, ny;
switch (c >> 5) {
case 1:
if (k->last_lo_y)
k->hi_x = v;
else
k->hi_y = v;
k->last_lo_y = 0;
break;
case 3:
if (k->last_lo_y)
k->extra = k->lo_y;
k->lo_y = v;
k->last_lo_y = 1;
break;
case 2:
k->lo_x = v;
k->last_lo_y = 0;
nx = (k->hi_x << 7) | (k->lo_x << 2) | (k->extra & 3);
ny = (k->hi_y << 7) | (k->lo_y << 2) | ((k->extra >> 2) & 3);
k->extra = 0;
tek_to(k, nx, ny);
break;
}
}
static void tek_incremental(struct tek *k, int c)
{
int dx, dy, nx, ny;
switch (c) {
case ' ': k->pen = 0; return;
case 'P': k->pen = 1; return;
case 'D': dx = 0; dy = 1; break;
case 'E': dx = 1; dy = 1; break;
case 'A': dx = 1; dy = 0; break;
case 'I': dx = 1; dy = -1; break;
case 'H': dx = 0; dy = -1; break;
case 'J': dx = -1; dy = -1; break;
case 'B': dx = -1; dy = 0; break;
case 'F': dx = -1; dy = 1; break;
default: return;
}
nx = clampi(k->x + dx * TEK_STEP, 0, TEK_W - 1);
ny = clampi(k->y + dy * TEK_STEP, 0, TEK_H - 1);
if (k->pen)
raster_line(layer_raster(&k->layer), k->x, row(k->y), nx, row(ny));
k->x = nx;
k->y = ny;
}
static void tek_process(struct vt_interp *in, int32_t cp)
{
struct tek *k = (struct tek *)in;
int c = cp & 0x7f;
if (k->escaped) {
k->escaped = 0;
tek_esc(k, c);
return;
}
switch (c) {
case 0x1b: k->escaped = 1; break;
case 0x1d: k->mode = TM_GRAPH; k->dark = 1; break;
case 0x1c: k->mode = TM_POINT; break;
case 0x1e: k->mode = TM_INCREMENTAL; k->pen = 0; break;
case 0x1f: k->mode = TM_ALPHA; break;
case 0x07: vt_bell(in->t); break;
case 0x0d: k->mode = TM_ALPHA; k->x = 0; break;
default:
switch (k->mode) {
case TM_ALPHA: tek_alpha(k, c); break;
case TM_GRAPH: case TM_POINT: if (c >= 0x20) tek_address(k, c); break;
case TM_INCREMENTAL: tek_incremental(k, c); break;
}
}
}
static void tek_flush(struct vt_interp *in)
{
layer_flush(&((struct tek *)in)->layer);
}
static void tek_reset(struct vt_interp *in)
{
struct tek *k = (struct tek *)in;
layer_reset(&k->layer);
k->size = 0;
k->escaped = 0;
tek_home(k);
}
static void tek_destroy(struct vt_interp *in)
{
struct tek *k = (struct tek *)in;
layer_free(&k->layer);
free(k);
}
static const struct vt_interp_ops tek_ops = {
tek_process, tek_reset, NULL, NULL, NULL, NULL, NULL, NULL, tek_flush,
NULL, tek_destroy
};
struct vt_interp *tek_new(dmc_vt *t, void (*on_exit)(void *), void *ctx)
{
struct tek *k = (struct tek *)calloc(1, sizeof(*k));
if (!k)
return NULL;
k->in.ops = &tek_ops;
k->in.t = t;
k->on_exit = on_exit;
k->ctx = ctx;
layer_init(&k->layer, t, TEK_W, TEK_H, tek_setup, NULL);
tek_home(k);
return &k->in;
}
-222
View File
@@ -1,222 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_keys.c - keys as the octets a VT220 or xterm sends: the cursor keys
* in normal or application mode, xterm's modifier parameters (ESC[1;5A
* for Ctrl+Up), the DEC keypad, a VT52's, Ctrl and Alt on characters.
* A port of the app's KeyEncoder.
*/
#include <stdio.h>
#include <string.h>
#include "vtint.h"
static const char *enter_bytes(const dmc_vt *t)
{
switch (t->enter_mode) {
case 1: return "\r\n";
case 2: return "\n";
}
return "\r";
}
/* a keypad key's (NULL: not one): PF1-PF4 as SS3 P-S (a VT52's ESC
P-S); the others their characters in numeric mode, SS3 and a letter in
application mode (a VT52's ESC ? and the letter) */
static int keypad(const dmc_vt *t, int k, dmc_buf *out)
{
int app = t->app_keypad, vt52 = t->vt52_keys, letter;
char s[8];
const char *numeric;
char digit[2];
if (k >= DMC_KEY_PF1 && k <= DMC_KEY_PF4) {
snprintf(s, sizeof(s), vt52 ? "\x1b%c" : "\x1bO%c",
'P' + (k - DMC_KEY_PF1));
buf_adds(out, s);
return 1;
}
if (k >= DMC_KEY_KP_0 && k <= DMC_KEY_KP_9) {
digit[0] = (char)('0' + (k - DMC_KEY_KP_0));
digit[1] = 0;
numeric = digit;
letter = 'p' + (k - DMC_KEY_KP_0);
} else if (k == DMC_KEY_KP_MINUS) {
numeric = "-";
letter = 'm';
} else if (k == DMC_KEY_KP_COMMA) {
numeric = ",";
letter = 'l';
} else if (k == DMC_KEY_KP_PERIOD) {
numeric = ".";
letter = 'n';
} else if (k == DMC_KEY_KP_ENTER) {
numeric = enter_bytes(t);
letter = 'M';
} else {
return 0;
}
if (!app) {
buf_adds(out, numeric);
return 1;
}
snprintf(s, sizeof(s), vt52 ? "\x1b?%c" : "\x1bO%c", letter);
buf_adds(out, s);
return 1;
}
static const char *vt52_key(int k)
{
switch (k) {
case DMC_KEY_UP: return "\x1b" "A";
case DMC_KEY_DOWN: return "\x1b" "B";
case DMC_KEY_RIGHT: return "\x1b" "C";
case DMC_KEY_LEFT: return "\x1b" "D";
case DMC_KEY_F1: return "\x1bP";
case DMC_KEY_F2: return "\x1bQ";
case DMC_KEY_F3: return "\x1bR";
case DMC_KEY_F4: return "\x1bS";
}
return NULL;
}
/* a CSI n ~ key's number, 0 for none */
static int tilde_number(int k)
{
switch (k) {
case DMC_KEY_INSERT: return 2;
case DMC_KEY_DELETE: return 3;
case DMC_KEY_PGUP: return 5;
case DMC_KEY_PGDN: return 6;
case DMC_KEY_F5: return 15;
case DMC_KEY_F6: return 17;
case DMC_KEY_F7: return 18;
case DMC_KEY_F8: return 19;
case DMC_KEY_F9: return 20;
case DMC_KEY_F10: return 21;
case DMC_KEY_F11: return 23;
case DMC_KEY_F12: return 24;
case DMC_KEY_F13: return 25;
case DMC_KEY_F14: return 26;
case DMC_KEY_F15: return 28;
case DMC_KEY_F16: return 29;
case DMC_KEY_F17: return 31;
case DMC_KEY_F18: return 32;
case DMC_KEY_F19: return 33;
case DMC_KEY_F20: return 34;
case DMC_KEY_FIND: return 1;
case DMC_KEY_SELECT: return 4;
}
return 0;
}
void keys_key(const dmc_vt *t, int k, int mods, dmc_buf *out)
{
int shift = mods & M_SHIFT, alt = mods & M_ALT, ctrl = mods & M_CTRL;
int m = 1 + (shift ? 1 : 0) + (alt ? 2 : 0) + (ctrl ? 4 : 0), n;
const char *s;
char b[24];
int cursor = 0, ss3 = 0;
if (keypad(t, k, out))
return;
if (t->vt52_keys && (s = vt52_key(k)) != NULL) {
buf_adds(out, s);
return;
}
switch (k) {
case DMC_KEY_UP: cursor = 'A'; break;
case DMC_KEY_DOWN: cursor = 'B'; break;
case DMC_KEY_RIGHT: cursor = 'C'; break;
case DMC_KEY_LEFT: cursor = 'D'; break;
case DMC_KEY_HOME: cursor = 'H'; break;
case DMC_KEY_END: cursor = 'F'; break;
case DMC_KEY_F1: ss3 = 'P'; break;
case DMC_KEY_F2: ss3 = 'Q'; break;
case DMC_KEY_F3: ss3 = 'R'; break;
case DMC_KEY_F4: ss3 = 'S'; break;
}
if (cursor) {
if (m > 1)
snprintf(b, sizeof(b), "\x1b[1;%d%c", m, cursor);
else if (t->app_cursor)
snprintf(b, sizeof(b), "\x1bO%c", cursor);
else
snprintf(b, sizeof(b), "\x1b[%c", cursor);
buf_adds(out, b);
return;
}
if (ss3) {
if (m > 1)
snprintf(b, sizeof(b), "\x1b[1;%d%c", m, ss3);
else
snprintf(b, sizeof(b), "\x1bO%c", ss3);
buf_adds(out, b);
return;
}
n = tilde_number(k);
if (n) {
if (m > 1)
snprintf(b, sizeof(b), "\x1b[%d;%d~", n, m);
else
snprintf(b, sizeof(b), "\x1b[%d~", n);
buf_adds(out, b);
return;
}
switch (k) {
case DMC_KEY_TAB:
if (shift) {
buf_adds(out, "\x1b[Z");
return;
}
if (alt)
buf_addc(out, 0x1b);
buf_addc(out, '\t');
return;
case DMC_KEY_BACKTAB:
buf_adds(out, "\x1b[Z");
return;
case DMC_KEY_ENTER:
if (alt)
buf_addc(out, 0x1b);
buf_adds(out, enter_bytes(t));
return;
case DMC_KEY_BACKSPACE:
if (alt)
buf_addc(out, 0x1b);
buf_addc(out, (char)(ctrl ? 0x08 : t->backspace_code));
return;
case DMC_KEY_ESCAPE:
if (alt)
buf_addc(out, 0x1b);
buf_addc(out, 0x1b);
return;
}
}
void keys_char(uint32_t cp, int mods, dmc_buf *out)
{
uint32_t c = cp;
if (mods & M_CTRL) {
if (c >= 'a' && c <= 'z')
c = c - 'a' + 1;
else if (c >= '@' && c <= '_')
c = c - '@';
else if (c == ' ' || c == '2')
c = 0;
else if (c == '3')
c = 0x1b;
else if (c == '4')
c = 0x1c;
else if (c == '5')
c = 0x1d;
else if (c == '6')
c = 0x1e;
else if (c == '7' || c == '/')
c = 0x1f;
else if (c == '8' || c == '?')
c = 0x7f;
}
if (mods & M_ALT)
buf_addc(out, 0x1b);
utf8_put(out, c);
}
File diff suppressed because it is too large. Load diff
-254
View File
@@ -1,254 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_profiles.c - the kinds of terminal there are (the app's
* TerminalProfiles): what each calls itself to SSH, Telnet and the
* programs that ask, its answers, its machine's screen, palette and
* font, and the interpreter that reads it.
*/
#include <string.h>
#include "vtint.h"
/* ------------------------------------------------------------------ */
/* the palettes (opaque ARGB) */
/* an Amiga's ANSI colours, from its 4-bit levels */
static const uint32_t amiga_colors[16] = {
0xff000000, 0xffcc2222, 0xff22cc22, 0xffcccc22,
0xff2222cc, 0xffcc22cc, 0xff22cccc, 0xffcccccc,
0xff666666, 0xffff5555, 0xff55ff55, 0xffffff55,
0xff5555ff, 0xffff55ff, 0xff55ffff, 0xffffffff
};
/* Philip Timmermann's "Pepto" measurements of the VIC-II */
static const uint32_t pepto[16] = {
0xff000000, 0xffffffff, 0xff68372b, 0xff70a4b2,
0xff6f3d86, 0xff588d43, 0xff352879, 0xffb8c76f,
0xff6f4f25, 0xff433900, 0xff9a6759, 0xff444444,
0xff6c6c6c, 0xff9ad284, 0xff6c5eb5, 0xff959595
};
/* the VIC-20's: eight, then the lighter ones */
static const uint32_t vic20[16] = {
0xff000000, 0xffffffff, 0xffb61f21, 0xff4df0ff,
0xffb43fff, 0xff44e237, 0xff1a34ff, 0xffdcd71b,
0xffca5400, 0xffe9b072, 0xffe79293, 0xff9af7fd,
0xffe09fff, 0xff8fe493, 0xff8290ff, 0xffe5de85
};
/* the C128's VDC (RGBI), each VIC-II colour as the 80-column screen
shows it */
static const uint32_t vdc[16] = {
0xff000000, 0xffffffff, 0xffaa0000, 0xff55ffff,
0xffff55ff, 0xff00aa00, 0xff0000aa, 0xffffff55,
0xffaa00aa, 0xffaa5500, 0xffff5555, 0xff555555,
0xff00aaaa, 0xff55ff55, 0xff5555ff, 0xffaaaaaa
};
/* the Plus/4's TED */
static const uint32_t ted[16] = {
0xff000000, 0xffffffff, 0xff9c3e3e, 0xff5ab5b5,
0xff9f4ba8, 0xff5aa33e, 0xff5250c4, 0xffb5b54a,
0xffa36a2b, 0xff7d5a1b, 0xff85a33e, 0xffc7637a,
0xff3ea383, 0xff6a8cd9, 0xff4f5fb3, 0xff7ec26b
};
/* a PET's phosphor */
static const uint32_t pet_green[2] = { 0xff000000, 0xff41ff00 };
/* an Atari 8-bit's blue and light text */
static const uint32_t atari_blue[2] = { 0xff1d5dae, 0xffa8d8ff };
/* TOS's sixteen at power-up (3-bit levels) */
static const uint32_t tos[16] = {
0xffffffff, 0xffff0000, 0xff00ff00, 0xffffff00,
0xff0000ff, 0xffff00ff, 0xff00ffff, 0xffb6b6b6,
0xff6d6d6d, 0xffff6d6d, 0xff6dff6d, 0xffffff6d,
0xff6d6dff, 0xffff6dff, 0xff6dffff, 0xff000000
};
/* the ST's high resolution colour mode: TOS's first three and black */
static const uint32_t tos_med[4] = {
0xffffffff, 0xffff0000, 0xff00ff00, 0xff000000
};
/* teletext's eight */
static const uint32_t teletext[8] = {
0xff000000, 0xffff0000, 0xff00ff00, 0xffffff00,
0xff0000ff, 0xffff00ff, 0xff00ffff, 0xffffffff
};
/* a Commodore's CTRL 1-8 and C= 1-8 */
static const uint8_t cbm_ctrl[8] = {
0x90, 0x05, 0x1c, 0x9f, 0x9c, 0x1e, 0x1f, 0x9e
};
static const uint8_t cbm_cbm[8] = {
0x81, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b
};
/* ------------------------------------------------------------------ */
/* the profiles (in the struct's order: no designated initialisers, for
older compilers) */
/* a DEC terminal */
#define DEC(id, label, term, telnet, level, features, da1, da2, home) \
{ id, label, term, telnet, K_DEC, level, features, da1, da2, -1, \
home, MF_NONE, 0, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, \
0, 0, 0, 0, 0, NULL, NULL }
#define XTERM_FEATURES (F_PRINTER | F_COLOR | F_SIXEL | F_XTERM | F_TEK)
#define XTERM_DA1 "\x1b[?62;4;22c"
#define XTERM_DA2 "\x1b[>41;390;0c"
/* a BBS terminal: xterm with CTerm's additions */
#define BBS(id, label, term, kind, charset, font, syncterm, colors, n) \
{ id, label, term, "ANSI", kind, 2, XTERM_FEATURES, XTERM_DA1, \
XTERM_DA2, charset, 1, font, syncterm, colors, n, 0, 0, 0, 0, \
NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL }
/* a Commodore */
#define CBM(id, label, font, pal, cols, rows, fg, up, lo, nctrl, ncbm, \
esc, attr, tablf) \
{ id, label, "petscii", "PETSCII", K_PETSCII, 0, 0, NULL, NULL, \
-1, 0, font, 0, pal, (int)(sizeof(pal) / sizeof(pal[0])), cols, \
rows, fg, 0, up, lo, cbm_ctrl, cbm_cbm, nctrl, ncbm, esc, attr, \
tablf, NULL, ".seq" }
/* another machine */
#define MACH(id, label, term, telnet, kind, font, pal, cols, rows, fg, \
atascii, ext) \
{ id, label, term, telnet, kind, 0, 0, NULL, NULL, -1, 0, font, \
0, pal, (int)(sizeof(pal) / sizeof(pal[0])), cols, rows, fg, 0, \
NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, atascii, ext }
static const struct vt_profile xterm = DEC("xterm", "xterm",
"xterm-256color", "XTERM-256COLOR", 2, XTERM_FEATURES, XTERM_DA1,
XTERM_DA2, 1);
static const struct vt_profile ansi_bbs = BBS("ansi-bbs", "ANSI-BBS (PC)",
"ansi", K_ANSI_BBS, CS_CP437, MF_VGA, 0, NULL, 0);
static const struct vt_profile rip = BBS("rip", "RIPscrip", "rip", K_RIP,
CS_CP437, MF_RIPTERM, 45, NULL, 0);
static const struct vt_profile avatar = BBS("avatar", "Avatar (AVT/0+)",
"avatar", K_AVATAR, CS_CP437, MF_VGA, 0, NULL, 0);
static const struct vt_profile amiga = BBS("amiga", "Amiga ANSI", "amiga",
K_ANSI_BBS, CS_LATIN1, MF_TOPAZ, 42, amiga_colors, 16);
static const struct vt_profile vt52 = {
"vt52", "DEC VT52", "vt52", "DEC-VT52", K_VT52, 0, 0, NULL, NULL, -1,
0, MF_NONE, 0, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, 0, 0, 0,
0, 0, NULL, NULL
};
const struct vt_profile vt_profile_vt100 = DEC("vt100", "DEC VT100",
"vt100", "DEC-VT100", 1, 0, "\x1b[?1;2c", NULL, 0);
static const struct vt_profile vt102 = DEC("vt102", "DEC VT102", "vt102",
"DEC-VT102", 1, F_PRINTER, "\x1b[?6c", NULL, 0);
static const struct vt_profile vt220 = DEC("vt220", "DEC VT220", "vt220",
"DEC-VT220", 2, F_PRINTER, "\x1b[?62;1;2;6;7;8;9c", "\x1b[>1;10;0c", 0);
static const struct vt_profile vt320 = DEC("vt320", "DEC VT320", "vt320",
"DEC-VT320", 3, F_PRINTER, "\x1b[?63;1;2;6;7;8;9c", "\x1b[>24;10;0c",
0);
static const struct vt_profile vt340 = DEC("vt340", "DEC VT340", "vt340",
"DEC-VT340", 3, F_PRINTER | F_SIXEL | F_REGIS | F_TEK,
"\x1b[?63;1;2;3;4;6;7;8;9c", "\x1b[>19;10;0c", 0);
static const struct vt_profile vt420 = DEC("vt420", "DEC VT420", "vt420",
"DEC-VT420", 4, F_PRINTER, "\x1b[?64;1;2;6;7;8;9;15;18;21;28c",
"\x1b[>41;10;0c", 0);
static const struct vt_profile vt510 = DEC("vt510", "DEC VT510", "vt510",
"DEC-VT510", 5, F_PRINTER, "\x1b[?65;1;2;6;7;8;9;15;18;21;28c",
"\x1b[>61;10;0c", 0);
static const struct vt_profile vt520 = DEC("vt520", "DEC VT520", "vt520",
"DEC-VT520", 5, F_PRINTER, "\x1b[?65;1;2;6;7;8;9;15;18;21;28c",
"\x1b[>64;10;0c", 0);
static const struct vt_profile vt525 = DEC("vt525", "DEC VT525", "vt525",
"DEC-VT525", 5, F_PRINTER | F_COLOR,
"\x1b[?65;1;2;6;7;8;9;15;18;21;22;28c", "\x1b[>65;10;0c", 0);
static const struct vt_profile c64 = CBM("c64", "Commodore 64", MF_C64,
pepto, 40, 25, 14, vt_set_c64_upper, vt_set_c64_lower, 8, 8, 0,
AC_NONE, 0);
static const struct vt_profile c128 = CBM("c128",
"Commodore 128 (40 col.)", MF_C128, pepto, 40, 25, 14,
vt_set_c64_upper, vt_set_c64_lower, 8, 8, 1, AC_NONE, 1);
static const struct vt_profile c128_80 = CBM("c128-80",
"Commodore 128 (80 col.)", MF_C128, vdc, 80, 25, 14,
vt_set_c64_upper, vt_set_c64_lower, 8, 8, 1, AC_VDC, 1);
static const struct vt_profile plus4 = CBM("plus4", "Commodore Plus/4",
MF_C64, ted, 40, 25, 14, vt_set_c64_upper, vt_set_c64_lower, 8, 8, 1,
AC_PLUS4, 0);
static const struct vt_profile vic20p = CBM("vic20", "Commodore VIC-20",
MF_C64, vic20, 22, 23, 1, vt_set_vic_upper, vt_set_vic_lower, 8, 0, 0,
AC_NONE, 0);
static const struct vt_profile pet = CBM("pet", "Commodore PET (40 col.)",
MF_C64, pet_green, 40, 25, 1, vt_set_pet_upper, vt_set_pet_lower, 0, 0,
0, AC_NONE, 0);
static const struct vt_profile pet80 = CBM("pet80",
"Commodore PET (80 col.)", MF_C64, pet_green, 80, 25, 1,
vt_set_pet_upper, vt_set_pet_lower, 0, 0, 0, AC_NONE, 0);
static const struct vt_profile atari = MACH("atari", "Atari 8-bit",
"atascii", "ATASCII", K_ATASCII, MF_ATARI, atari_blue, 40, 24, 1,
vt_set_atari_graphics, NULL);
static const struct vt_profile atari_intl = MACH("atari-intl",
"Atari 8-bit (international)", "atascii", "ATASCII", K_ATASCII,
MF_ATARI, atari_blue, 40, 24, 1, vt_set_atari_international, NULL);
static const struct vt_profile atari_st = MACH("atari-st",
"Atari ST (80 col.)", "st52", "VT52", K_ATARI_ST, MF_ATARI_ST,
tos_med, 80, 25, 3, NULL, NULL);
static const struct vt_profile atari_st_low = MACH("atari-st-low",
"Atari ST (40 col., 16 colours)", "st52", "VT52", K_ATARI_ST,
MF_ATARI_ST, tos, 40, 25, 15, NULL, NULL);
static const struct vt_profile viewdata = MACH("viewdata",
"Viewdata (Prestel)", "viewdata", "VIEWDATA", K_VIEWDATA, MF_PRESTEL,
teletext, 40, 24, 7, NULL, ".vdt");
static const struct vt_profile minitel = MACH("minitel", "Minitel",
"minitel", "MINITEL", K_MINITEL, MF_NONE, teletext, 40, 25, 7, NULL,
".vdt");
static const struct vt_profile tek4014 = {
"tek4014", "Tektronix 4014", "tek4014", "TEK4014", K_TEK, 0, 0, NULL,
NULL, -1, 0, MF_NONE, 0, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL,
0, 0, 0, 0, 0, NULL, NULL
};
/* in the pickers' order */
const struct vt_profile *const vt_profiles[] = {
&xterm, &ansi_bbs, &rip, &avatar, &amiga, &vt52, &vt_profile_vt100,
&vt102, &vt220, &vt320, &vt340, &vt420, &vt510, &vt520, &vt525, &c64,
&c128, &c128_80, &plus4, &vic20p, &pet, &pet80, &atari, &atari_intl,
&atari_st, &atari_st_low, &viewdata, &minitel, &tek4014
};
const int vt_profile_count =
(int)(sizeof(vt_profiles) / sizeof(vt_profiles[0]));
const struct vt_profile *vt_profile_by_id(const char *id)
{
int i;
if (!id)
return NULL;
for (i = 0; i < vt_profile_count; i++)
if (!strcmp(vt_profiles[i]->id, id))
return vt_profiles[i];
return NULL;
}
/* the default: what the terminal was before profiles */
const struct vt_profile *vt_profile_default(void)
{
return &xterm;
}
struct vt_interp *profile_interp(dmc_vt *t, const struct vt_profile *p)
{
switch (p->kind) {
case K_VT52:
return vt52_new(t, G_VT52_GRAPHICS, "\x1b/K", NULL, NULL);
case K_ATARI_ST: return atari_st_new(t, p);
case K_PETSCII: return petscii_new(t, p);
case K_ATASCII: return atascii_new(t, p);
case K_VIEWDATA: return viewdata_new(t, p);
case K_MINITEL: return minitel_new(t, p);
case K_TEK: return tek_new(t, NULL, NULL);
default: return dec_new(t, p);
}
}
-1547
View File
File diff suppressed because it is too large. Load diff
-997
View File
@@ -1,997 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_rip.c - RIPscrip 1.54 (the app's RipInterpreter), TeleGrafix's
* graphics for BBSes: ANSI-BBS whose lines that start with !| are
* drawing commands on a 640x350 EGA screen (lines, rectangles, circles,
* ellipses, arcs, pies, Béziers, polygons, flood and patterned fills,
* text, the clipboard) and mouse regions and buttons that a tap sends
* the host. Ordinary text and ANSI go back to ANSI-BBS's parser (vt_dec.c)
* for the text window, 80x43 of 8x8 cells.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "vtint.h"
#define WIDTH 640
#define HEIGHT 350
#define ASPECT 0.775
#define MAX_LINE (1 << 16)
/* a run of code points */
struct cps {
uint32_t *v;
int n, cap;
};
static void cps_add(struct cps *s, uint32_t c)
{
if (s->n == s->cap) {
int cap = s->cap ? s->cap * 2 : 64;
uint32_t *v = (uint32_t *)realloc(s->v, sizeof(uint32_t) * (size_t)cap);
if (!v)
return;
s->v = v;
s->cap = cap;
}
s->v[s->n++] = c;
}
struct region {
int x0, y0, x1, y1;
uint32_t *send;
int n;
};
struct rip {
dmc_vt *t;
void (*replay)(void *, int32_t);
void *ctx;
struct picture_layer layer;
int line_start, bang, in_line, escaped, swallow_lf, replaying, enabled;
struct cps line;
int32_t held[8];
int held_n;
int color, x, y, xor_, line_pattern, thick, fill_pattern;
uint8_t user_fill[8];
int fill_color, font, font_size, vertical;
uint32_t palette[16];
int viewport[4], has_viewport;
struct raster_grab clipboard;
int has_clipboard;
struct region *regions;
int nregions, cap_regions;
int bevel, b_fore, b_surface, b_bright, b_dark;
int block[5], has_block;
};
/* an EGA colour (0-63: rgbRGB, the lower case the 1/3 bits) as ARGB */
static uint32_t ega(int v)
{
#define CH(hi, lo) ((((v) >> (hi)) & 1 ? 0xaa : 0) + (((v) >> (lo)) & 1 ? 0x55 : 0))
return 0xff000000u | ((uint32_t)CH(2, 5) << 16) |
((uint32_t)CH(1, 4) << 8) | (uint32_t)CH(0, 3);
#undef CH
}
static const int ega_start[16] = {
0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63
};
/* BGI's fill patterns 2-11 */
static const uint8_t fills[10][8] = {
{ 0xff, 0xff, 0, 0, 0xff, 0xff, 0, 0 },
{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
{ 0xe0, 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70 },
{ 0xf0, 0x78, 0x3c, 0x1e, 0x0f, 0x87, 0xc3, 0xe1 },
{ 0xa5, 0xd2, 0x69, 0xb4, 0x5a, 0x2d, 0x96, 0x4b },
{ 0xff, 0x88, 0x88, 0x88, 0xff, 0x88, 0x88, 0x88 },
{ 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 },
{ 0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33 },
{ 0x80, 0x00, 0x08, 0x00, 0x80, 0x00, 0x08, 0x00 },
{ 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 },
};
static const uint8_t hollow[8];
static int clampi(int v, int lo, int hi)
{
return v < lo ? lo : v > hi ? hi : v;
}
static int roundi(double v)
{
return (int)floor(v + 0.5);
}
static struct raster *R(struct rip *r)
{
return layer_raster(&r->layer);
}
/* ------------------------------------------------------------------ */
/* a command's arguments: MegaNums (base 36), then the text left */
struct args {
const uint32_t *s;
int n, i;
};
static int arg_w(struct args *a, int width)
{
int v = 0;
while (width-- > 0) {
uint32_t c = a->i < a->n ? a->s[a->i] : '0';
a->i++;
v *= 36;
if (c >= '0' && c <= '9')
v += (int)(c - '0');
else if (c >= 'A' && c <= 'Z')
v += (int)(c - 'A') + 10;
else if (c >= 'a' && c <= 'z')
v += (int)(c - 'a') + 10;
}
return v;
}
static int arg(struct args *a)
{
return arg_w(a, 2);
}
static const uint32_t *rest(struct args *a, int *n)
{
*n = a->i < a->n ? a->n - a->i : 0;
return a->i < a->n ? a->s + a->i : a->s;
}
/* ------------------------------------------------------------------ */
/* drawing */
/* colour register c as drawn: black transparent (the text shows through) */
static uint32_t argb(struct rip *r, int c)
{
uint32_t v = r->palette[c & 15];
return (v & 0xffffff) == 0 ? 0 : v;
}
static void set_up(struct rip *r)
{
struct raster *g = R(r);
if (!g)
return;
g->mode = r->xor_ ? R_COMPLEMENT : R_OVERLAY;
g->color = argb(r, r->color);
g->pattern = r->line_pattern;
g->fill_pattern = NULL;
g->has_clip = r->has_viewport;
if (r->has_viewport)
raster_pixel_rect(g, r->viewport[0], r->viewport[1],
r->viewport[2], r->viewport[3], g->clip);
if (g->color == 0)
g->mode = R_ERASE;
g->background = 0;
}
static void set_up_fill(struct rip *r)
{
struct raster *g;
set_up(r);
g = R(r);
if (!g)
return;
g->color = argb(r, r->fill_color);
g->mode = g->color == 0 ? R_ERASE : R_OVERLAY;
switch (r->fill_pattern) {
case 0: g->fill_pattern = hollow; break;
case 1: g->fill_pattern = NULL; break;
case 12:
memcpy(g->fill_pattern_buf, r->user_fill, 8);
g->fill_pattern = g->fill_pattern_buf;
break;
default:
g->fill_pattern = r->fill_pattern >= 2 && r->fill_pattern <= 11
? fills[r->fill_pattern - 2] : NULL;
}
g->fill_background = 0;
}
static void line(struct rip *r, int x0, int y0, int x1, int y1)
{
struct raster *g;
set_up(r);
g = R(r);
if (!g)
return;
raster_line(g, x0, y0, x1, y1);
if (r->thick == 3) {
raster_line(g, x0 + 1, y0, x1 + 1, y1);
raster_line(g, x0, y0 + 1, x1, y1 + 1);
}
}
/* lines through n points (xy pairs) */
static void polyline(struct rip *r, const int *xy, int n)
{
int i;
for (i = 1; i < n; i++)
line(r, xy[2 * i - 2], xy[2 * i - 1], xy[2 * i], xy[2 * i + 1]);
}
static void fill(struct rip *r, const int *xy, int n)
{
set_up_fill(r);
if (R(r))
raster_fill(R(r), xy, n);
}
static void box_fill(struct rip *r, int x0, int y0, int x1, int y1)
{
int q[8];
q[0] = x0; q[1] = y0;
q[2] = x1 + 1; q[3] = y0;
q[4] = x1 + 1; q[5] = y1 + 1;
q[6] = x0; q[7] = y1 + 1;
fill(r, q, 4);
}
static double sweep(int s, int e)
{
int d = ((e - s) % 360 + 360) % 360;
return d == 0 ? 360.0 : (double)d;
}
static int aspect(int rad)
{
return roundi(rad * ASPECT);
}
static void arc(struct rip *r, int cx, int cy, int s, int e, int rx, int ry)
{
set_up(r);
if (R(r))
raster_ellipse(R(r), cx, cy, rx, ry, (double)s, sweep(s, e));
}
#define MAX_ARC 80
static void pie(struct rip *r, int cx, int cy, int s, int e, int rx, int ry)
{
int xy[2 * (MAX_ARC + 2)], n;
xy[0] = cx;
xy[1] = cy;
n = 1 + raster_ellipse_points(cx, cy, rx, ry, (double)s, sweep(s, e),
xy + 2, MAX_ARC);
xy[2 * n] = cx;
xy[2 * n + 1] = cy;
n++;
fill(r, xy, n);
polyline(r, xy, n);
}
static void bezier(struct rip *r, const int *p, int n)
{
int *xy = (int *)malloc(sizeof(int) * 2 * (size_t)(n + 1)), i;
if (!xy)
return;
for (i = 0; i <= n; i++) {
double u = (double)i / n, v = 1 - u;
double a = v * v * v, b = 3 * v * v * u, c = 3 * v * u * u,
d = u * u * u;
xy[2 * i] = roundi(a * p[0] + b * p[2] + c * p[4] + d * p[6]);
xy[2 * i + 1] = roundi(a * p[1] + b * p[3] + c * p[5] + d * p[7]);
}
polyline(r, xy, n + 1);
free(xy);
}
static int cell_height(struct rip *r)
{
return r->font == 0 ? 8 * r->font_size : 10 * r->font_size;
}
/* text drawn from the position in RIPterm's 8x8 font (bigger for the
stroke fonts' sizes), the position left after it */
static void text(struct rip *r, const uint32_t *s, int n)
{
struct raster *g;
const struct vt_font *f = machine_font(MF_RIPTERM);
int cw = r->font == 0 ? 8 * r->font_size : 6 * r->font_size;
int ch = cell_height(r), i;
set_up(r);
g = R(r);
if (!g)
return;
g->mode = r->xor_ ? R_COMPLEMENT : R_OVERLAY;
for (i = 0; i < n; i++) {
raster_text(g, r->x, r->y, s + i, 1, f, cw, ch);
if (r->vertical)
r->y += ch;
else
r->x += cw;
}
}
/* ------------------------------------------------------------------ */
/* windows and regions */
static void add_region(struct rip *r, int x0, int y0, int x1, int y1,
const uint32_t *s, int n)
{
struct region *g;
if (r->nregions == r->cap_regions) {
int cap = r->cap_regions ? r->cap_regions * 2 : 16;
struct region *v = (struct region *)realloc(
r->regions, sizeof(*v) * (size_t)cap);
if (!v)
return;
r->regions = v;
r->cap_regions = cap;
}
g = &r->regions[r->nregions];
g->send = (uint32_t *)malloc(sizeof(uint32_t) * (size_t)(n ? n : 1));
if (!g->send)
return;
memcpy(g->send, s, sizeof(uint32_t) * (size_t)n);
g->n = n;
g->x0 = x0;
g->y0 = y0;
g->x1 = x1;
g->y1 = y1;
r->nregions++;
}
static void clear_regions(struct rip *r)
{
int i;
for (i = 0; i < r->nregions; i++)
free(r->regions[i].send);
r->nregions = 0;
}
static void drop_clipboard(struct rip *r)
{
if (r->has_clipboard)
free(r->clipboard.px);
r->has_clipboard = 0;
memset(&r->clipboard, 0, sizeof(r->clipboard));
}
static void text_window(struct rip *r, int x0, int y0, int x1, int y1)
{
dmc_vt *t = r->t;
int top, bottom;
(void)x1;
if (!x0 && !y0 && !x1 && !y1)
return;
top = clampi(y0, 0, t->rows - 1);
bottom = clampi(y1, top, t->rows - 1);
vt_set_region(t, top, bottom);
vt_move_cursor(t, clampi(x0, 0, t->cols - 1), top, 0);
}
/* RIP_RESET_WINDOWS: the picture, text, windows, palette and regions as
at the start */
static void reset_windows(struct rip *r)
{
dmc_vt *t = r->t;
int i;
layer_reset(&r->layer);
vt_set_region(t, 0, t->rows - 1);
vt_erase_display(t, 2, 0);
vt_move_cursor(t, 0, 0, 0);
for (i = 0; i < 16; i++)
r->palette[i] = ega(ega_start[i]);
r->has_viewport = 0;
clear_regions(r);
drop_clipboard(r);
r->color = 15;
r->x = r->y = 0;
}
/* a button (1U): its bevel, surface and label in the buttons' style, and
a region sending its host text ("icon<>label<>host") */
static void button(struct rip *r, int x0, int y0, int x1, int y1,
const uint32_t *s, int n)
{
const uint32_t *part[3] = { NULL, NULL, NULL };
int plen[3] = { 0, 0, 0 }, k = 0, i, start = 0, b;
int sc, sp, scolor, sfont, ssize, svert, q[6];
for (i = 0; i <= n && k < 3; i++) {
if (i == n || (s[i] == '<' && i + 1 < n && s[i + 1] == '>')) {
part[k] = s + start;
plen[k] = i - start;
k++;
start = i + 2;
i++;
}
}
sc = r->fill_color;
sp = r->fill_pattern;
r->fill_color = r->b_surface;
r->fill_pattern = 1;
box_fill(r, x0, y0, x1, y1);
r->fill_color = sc;
r->fill_pattern = sp;
scolor = r->color;
for (b = 0; b < r->bevel; b++) {
r->color = r->b_bright;
q[0] = x0 - b - 1; q[1] = y1 + b + 1;
q[2] = x0 - b - 1; q[3] = y0 - b - 1;
q[4] = x1 + b + 1; q[5] = y0 - b - 1;
polyline(r, q, 3);
r->color = r->b_dark;
q[0] = x1 + b + 1; q[1] = y0 - b - 1;
q[2] = x1 + b + 1; q[3] = y1 + b + 1;
q[4] = x0 - b - 1; q[5] = y1 + b + 1;
polyline(r, q, 3);
}
r->color = r->b_fore;
sfont = r->font;
ssize = r->font_size;
svert = r->vertical;
r->font = 0;
r->font_size = 1;
r->vertical = 0;
r->x = (x0 + x1) / 2 - plen[1] * 4;
r->y = (y0 + y1) / 2 - 4;
if (part[1])
text(r, part[1], plen[1]);
r->font = sfont;
r->font_size = ssize;
r->vertical = svert;
r->color = scolor;
if (plen[2] > 0)
add_region(r, x0, y0, x1, y1, part[2], plen[2]);
}
/* ------------------------------------------------------------------ */
/* the commands */
static void level0(struct rip *r, uint32_t c, struct args *a)
{
dmc_vt *t = r->t;
struct raster *g;
const uint32_t *s;
int n, x0, y0, x1, y1, i, v;
switch (c) {
case 'w':
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
text_window(r, x0, y0, x1, y1);
break;
case 'v':
for (i = 0; i < 4; i++)
r->viewport[i] = arg(a);
r->has_viewport = 1;
break;
case '*':
reset_windows(r);
break;
case 'e':
vt_erase_display(t, 2, 0);
vt_move_cursor(t, 0, t->top, 0);
break;
case 'E':
if (!(g = R(r)))
break;
if (r->has_viewport)
raster_clear_rect(g, r->viewport[0], r->viewport[1],
r->viewport[2], r->viewport[3], 0);
else
raster_clear_rect(g, 0, 0, WIDTH - 1, HEIGHT - 1, 0);
break;
case 'g':
x0 = arg(a);
y0 = arg(a);
vt_move_cursor(t, x0, t->top + y0, 0);
break;
case 'H': vt_move_cursor(t, 0, t->top, 0); break;
case '>': vt_erase_line(t, 0, 0); break;
case 'c': r->color = arg(a) & 15; break;
case 'Q':
for (i = 0; i < 16; i++)
r->palette[i] = ega(arg(a));
break;
case 'a':
i = arg(a);
v = arg(a);
if (i >= 0 && i <= 15)
r->palette[i] = ega(v);
break;
case 'W': r->xor_ = arg(a) == 1; break;
case 'm': r->x = arg(a); r->y = arg(a); break;
case 'T':
s = rest(a, &n);
text(r, s, n);
break;
case '@':
r->x = arg(a);
r->y = arg(a);
s = rest(a, &n);
text(r, s, n);
break;
case 'Y':
r->font = arg(a);
r->vertical = arg(a) == 1;
r->font_size = clampi(arg(a), 1, 10);
break;
case 'X':
x0 = arg(a);
y0 = arg(a);
set_up(r);
if ((g = R(r)))
raster_point(g, x0, y0);
break;
case 'L':
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
line(r, x0, y0, x1, y1);
break;
case 'R': {
int q[10];
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
q[0] = x0; q[1] = y0; q[2] = x1; q[3] = y0;
q[4] = x1; q[5] = y1; q[6] = x0; q[7] = y1;
q[8] = x0; q[9] = y0;
polyline(r, q, 5);
break;
}
case 'B':
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
box_fill(r, x0, y0, x1, y1);
break;
case 'C':
x0 = arg(a); y0 = arg(a); v = arg(a);
set_up(r);
if ((g = R(r)))
raster_ellipse(g, x0, y0, v, aspect(v), 0, 360);
break;
case 'A': {
int cx = arg(a), cy = arg(a), st = arg(a), e = arg(a), rad = arg(a);
arc(r, cx, cy, st, e, rad, aspect(rad));
break;
}
case 'O': case 'V': {
int cx = arg(a), cy = arg(a), st = arg(a), e = arg(a), rx = arg(a);
arc(r, cx, cy, st, e, rx, arg(a));
break;
}
case 'o': {
int cx = arg(a), cy = arg(a), rx = arg(a), ry = arg(a);
int xy[2 * MAX_ARC];
n = raster_ellipse_points(cx, cy, rx, ry, 0, 360, xy, MAX_ARC);
fill(r, xy, n);
set_up(r);
if ((g = R(r)))
raster_ellipse(g, cx, cy, rx, ry, 0, 360);
break;
}
case 'I': {
int cx = arg(a), cy = arg(a), st = arg(a), e = arg(a), rad = arg(a);
pie(r, cx, cy, st, e, rad, aspect(rad));
break;
}
case 'i': {
int cx = arg(a), cy = arg(a), st = arg(a), e = arg(a), rx = arg(a);
pie(r, cx, cy, st, e, rx, arg(a));
break;
}
case 'Z': {
int p[8];
for (i = 0; i < 8; i++)
p[i] = arg(a);
bezier(r, p, clampi(arg(a), 1, 256));
break;
}
case 'P': case 'p': case 'l': {
int *xy;
n = arg(a);
if (n < 2)
break;
xy = (int *)malloc(sizeof(int) * 2 * (size_t)(n + 1));
if (!xy)
break;
for (i = 0; i < 2 * n; i++)
xy[i] = arg(a);
if (c == 'p')
fill(r, xy, n);
if (c != 'l') {
xy[2 * n] = xy[0];
xy[2 * n + 1] = xy[1];
polyline(r, xy, n + 1);
} else {
polyline(r, xy, n);
}
free(xy);
break;
}
case 'F':
x0 = arg(a); y0 = arg(a); v = arg(a);
set_up_fill(r);
if ((g = R(r)))
raster_flood(g, x0, y0, argb(r, v));
break;
case '=': {
int style = arg(a), user = arg_w(a, 4);
r->thick = arg(a) >= 3 ? 3 : 1;
switch (style) {
case 1: r->line_pattern = 0xcc; break;
case 2: r->line_pattern = 0xe4; break;
case 3: r->line_pattern = 0xf0; break;
case 4: r->line_pattern = (user >> 8) & 0xff; break;
default: r->line_pattern = 0xff;
}
break;
}
case 'S':
r->fill_pattern = arg(a);
r->fill_color = arg(a) & 15;
break;
case 's':
for (i = 0; i < 8; i++)
r->user_fill[i] = (uint8_t)(arg(a) & 0xff);
r->fill_color = arg(a) & 15;
r->fill_pattern = 12;
break;
}
}
static void level1(struct rip *r, uint32_t c, struct args *a)
{
struct raster *g;
const uint32_t *s;
int n, x0, y0, x1, y1;
switch (c) {
case 'M':
arg(a);
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
arg(a); arg_w(a, 1); arg_w(a, 5);
s = rest(a, &n);
add_region(r, x0, y0, x1, y1, s, n);
break;
case 'K':
clear_regions(r);
break;
case 'B': {
int bevel, fore, bright, dark, surface;
arg(a); arg(a); arg(a); arg_w(a, 4);
bevel = arg(a);
fore = arg(a);
arg(a);
bright = arg(a);
dark = arg(a);
surface = arg(a);
r->bevel = bevel;
r->b_fore = fore & 15;
r->b_surface = surface & 15;
r->b_bright = bright & 15;
r->b_dark = dark & 15;
break;
}
case 'U':
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
arg(a); arg_w(a, 1); arg_w(a, 1);
s = rest(a, &n);
button(r, x0, y0, x1, y1, s, n);
break;
case 'T':
r->block[0] = arg(a);
r->block[1] = arg(a);
r->block[2] = arg(a);
r->block[3] = arg(a);
r->block[4] = r->block[1];
r->has_block = 1;
break;
case 't':
if (!r->has_block)
break;
arg_w(a, 1);
r->x = r->block[0];
r->y = r->block[4];
s = rest(a, &n);
text(r, s, n);
r->block[4] += cell_height(r);
break;
case 'E':
r->has_block = 0;
break;
case 'C':
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
if (!(g = R(r)))
break;
drop_clipboard(r);
raster_grab(g, x0, y0, x1, y1, &r->clipboard);
r->has_clipboard = 1;
break;
case 'P': {
int px = arg(a), py = arg(a), mode = arg(a);
if (r->has_clipboard && (g = R(r)))
raster_put(g, &r->clipboard, px, py, mode == 1);
break;
}
case 'G': {
struct raster_grab gr;
int dest;
x0 = arg(a); y0 = arg(a); x1 = arg(a); y1 = arg(a);
arg(a);
dest = arg(a);
if (!(g = R(r)))
break;
raster_grab(g, x0, y0, x1, y1, &gr);
raster_put(g, &gr, x0, dest, 0);
free(gr.px);
break;
}
case 'F':
/* a file query: none of the host's icons are here */
vt_reply(r->t, "0\r\n");
break;
}
}
/* one command: its level (a digit) and letter, then its MegaNums and text */
static void run(struct rip *r, const uint32_t *cmd, int n)
{
struct args a;
int level = 0, at;
if (n == 0)
return;
if (cmd[0] >= '1' && cmd[0] <= '9')
level = (int)(cmd[0] - '0');
at = level > 0 ? 1 : 0;
if (at >= n)
return;
a.s = cmd;
a.n = n;
a.i = at + 1;
if (level == 1)
level1(r, cmd[at], &a);
else if (level == 0)
level0(r, cmd[at], &a);
}
/* a RIP line's commands, split at the |s that aren't escaped, each run */
static void run_line(struct rip *r, const uint32_t *s, int n)
{
struct cps cmd = { NULL, 0, 0 };
int i = 0;
while (i < n) {
uint32_t c = s[i];
if (c == '\\' && i + 1 < n) {
cps_add(&cmd, s[i + 1]);
i += 2;
continue;
}
if (c == '|') {
run(r, cmd.v, cmd.n);
cmd.n = 0;
} else {
cps_add(&cmd, c);
}
i++;
}
run(r, cmd.v, cmd.n);
free(cmd.v);
}
/* ------------------------------------------------------------------ */
/* reading */
/* code points given to ANSI-BBS's parser after all */
static void give_back(struct rip *r, const int32_t *s, int n)
{
int i;
r->replaying = 1;
for (i = 0; i < n; i++)
r->replay(r->ctx, s[i]);
r->replaying = 0;
r->line_start = 0;
}
/* a RIP line's character: kept (a backslash's escape or continuation
honoured) until the line ends, then run */
static void gather(struct rip *r, int32_t cp)
{
if (r->escaped) {
r->escaped = 0;
if (cp == 0x0d) {
r->swallow_lf = 1;
} else if (cp != 0x0a) {
cps_add(&r->line, '\\');
cps_add(&r->line, (uint32_t)cp);
}
return;
}
switch (cp) {
case '\\':
r->escaped = 1;
break;
case 0x0d: case 0x0a: {
struct cps l = r->line;
r->in_line = 0;
r->line_start = 1;
r->swallow_lf = cp == 0x0d;
memset(&r->line, 0, sizeof(r->line));
run_line(r, l.v, l.n);
free(l.v);
break;
}
default:
if (r->line.n < MAX_LINE)
cps_add(&r->line, (uint32_t)cp);
}
}
static int digit02(int32_t c)
{
return c >= '0' && c <= '2';
}
/* ESC [ !, ESC [ 0 !, 1 !, 2 !: held until it is one (answered: RIP's
version; off; on), else given back */
static int query(struct rip *r, int32_t cp)
{
int n, i, full;
int32_t h[8];
if (r->held_n < 8)
r->held[r->held_n++] = cp;
n = r->held_n;
full = n >= 3 && r->held[n - 1] == '!' && r->held[0] == 0x1b &&
r->held[1] == '[';
for (i = 2; full && i < n - 1; i++)
if (!digit02(r->held[i]))
full = 0;
if (full) {
int arg = n == 4 ? r->held[2] : '0';
r->held_n = 0;
if (arg == '0')
rip_query(r);
else if (arg == '1')
r->enabled = 0;
else
r->enabled = 1;
return 1;
}
if ((n == 1 && r->held[0] == 0x1b) ||
(n == 2 && r->held[1] == '[') ||
(n == 3 && digit02(r->held[2])))
return 1;
memcpy(h, r->held, sizeof(int32_t) * (size_t)n);
r->held_n = 0;
give_back(r, h, n);
return 1;
}
int rip_intercept(struct rip *r, int32_t cp)
{
if (r->replaying)
return 0;
if (r->swallow_lf) {
r->swallow_lf = 0;
if (cp == 0x0a)
return 1;
}
if (r->in_line) {
gather(r, cp);
return 1;
}
if (r->held_n > 0 || cp == 0x1b)
return query(r, cp);
if (r->bang) {
static const int32_t bang = '!';
r->bang = 0;
if (cp == '|') {
r->in_line = 1;
r->line.n = 0;
return 1;
}
give_back(r, &bang, 1);
}
if (r->enabled && r->line_start && (cp == '!' || cp == 0x01 || cp == 0x02)) {
r->bang = 1;
return 1;
}
r->line_start = cp == 0x0d || cp == 0x0a;
return 0;
}
void rip_query(struct rip *r)
{
vt_reply(r->t, "RIPSCRIP015400");
}
/* a tap on a region or button (the last defined first): its host text,
^ and a letter a control */
int rip_tap(struct rip *r, double fx, double fy, dmc_buf *out)
{
int px = (int)(fx * WIDTH), py = (int)(fy * HEIGHT), k, i;
for (k = r->nregions - 1; k >= 0; k--) {
const struct region *g = &r->regions[k];
if (px < g->x0 || px > g->x1 || py < g->y0 || py > g->y1)
continue;
for (i = 0; i < g->n; i++) {
uint32_t c = g->send[i];
if (c == '^' && i + 1 < g->n) {
uint32_t u = g->send[i + 1];
if (u >= 'a' && u <= 'z')
u -= 0x20;
buf_addc(out, (char)(u & 0x1f));
i++;
continue;
}
buf_addc(out, (char)cp437_encode(c));
}
return 1;
}
return 0;
}
void rip_flush(struct rip *r)
{
layer_flush(&r->layer);
}
/* RIS: the picture, windows and regions as at the start, RIP on, the
80x43 asked for again */
void rip_reset(struct rip *r)
{
r->in_line = 0;
r->line.n = 0;
r->bang = 0;
r->escaped = 0;
r->swallow_lf = 0;
r->held_n = 0;
r->enabled = 1;
r->line_start = 1;
reset_windows(r);
r->t->requested_cols = 80;
r->t->requested_rows = 43;
}
struct rip *rip_new(dmc_vt *t, void (*replay)(void *, int32_t), void *ctx)
{
struct rip *r = (struct rip *)calloc(1, sizeof(*r));
int i;
if (!r)
return NULL;
r->t = t;
r->replay = replay;
r->ctx = ctx;
layer_init(&r->layer, t, WIDTH, HEIGHT, NULL, NULL);
r->line_start = 1;
r->enabled = 1;
r->color = 15;
r->line_pattern = 0xff;
r->thick = 1;
r->fill_pattern = 1;
memset(r->user_fill, 0xff, sizeof(r->user_fill));
r->fill_color = 15;
r->font_size = 1;
for (i = 0; i < 16; i++)
r->palette[i] = ega(ega_start[i]);
r->bevel = 2;
r->b_fore = 0;
r->b_surface = 7;
r->b_bright = 15;
r->b_dark = 8;
t->requested_cols = 80;
t->requested_rows = 43;
return r;
}
void rip_free(struct rip *r)
{
if (!r)
return;
clear_regions(r);
free(r->regions);
drop_clipboard(r);
free(r->line.v);
layer_free(&r->layer);
free(r);
}
-245
View File
@@ -1,245 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vt_vt52.c - the DEC VT52's escape sequences (the app's Vt52Interpreter):
* one character after ESC (ESC Y and two more for the cursor's place),
* no parameters, no attributes. A VT52 profile has it as its
* interpreter; a VT100 and later run one in VT52 mode until ESC < hands
* back. And an Atari ST's TOS VT52 (AtariStInterpreter), with the ST's
* own additions and its character set.
*/
#include <stdlib.h>
#include <string.h>
#include "vtint.h"
enum { V_GROUND, V_ESC, V_ROW, V_COL, V_ARG };
struct vt52 {
struct vt_interp in;
int graphics_set;
const char *identity;
void (*on_ansi)(void *);
void *ctx;
int state, arg_for, graphics, row;
struct vt_printer printer;
/* an Atari ST's */
const struct vt_profile *st;
int fg, bg, reverse;
};
#define T(v) ((v)->in.t)
static void control(struct vt52 *v, int32_t cp)
{
dmc_vt *t = T(v);
switch (cp) {
case 0x07: vt_bell(t); break;
case 0x08: vt_backspace(t); break;
case 0x09: vt_tab(t, 1); break;
case 0x0a:
if (v->printer.autop)
printer_line(&v->printer, t->cy);
vt_index(t);
break;
case 0x0d: vt_carriage_return(t); break;
}
}
static void st_restyle(struct vt52 *v)
{
T(v)->style = st_of(v->fg, v->bg, v->reverse ? A_INVERSE : 0);
}
static void esc(struct vt52 *v, int32_t cp)
{
dmc_vt *t = T(v);
if (v->st) {
switch (cp) {
case 'E':
vt_erase_display(t, 2, 0);
vt_move_cursor(t, 0, 0, 0);
return;
case 'd': vt_erase_display(t, 1, 0); return;
case 'e': t->cursor_visible = 1; return;
case 'f': t->cursor_visible = 0; return;
case 'j': vt_save_cursor(t); return;
case 'k': vt_restore_cursor(t); return;
case 'l':
vt_erase_line(t, 2, 0);
vt_carriage_return(t);
return;
case 'o': vt_erase_line(t, 1, 0); return;
case 'p': v->reverse = 1; st_restyle(v); return;
case 'q': v->reverse = 0; st_restyle(v); return;
case 'v': t->autowrap = 1; return;
case 'w': t->autowrap = 0; return;
case 'L':
vt_insert_lines(t, 1);
vt_carriage_return(t);
return;
case 'M':
vt_delete_lines(t, 1);
vt_carriage_return(t);
return;
case 'b': case 'c':
v->arg_for = cp;
v->state = V_ARG;
return;
}
}
switch (cp) {
case 'A': vt_move_cursor(t, t->cx, t->cy - 1, 0); break;
case 'B': vt_move_cursor(t, t->cx, t->cy + 1, 0); break;
case 'C': vt_move_cursor(t, t->cx + 1, t->cy, 0); break;
case 'D': vt_move_cursor(t, t->cx - 1, t->cy, 0); break;
case 'F': v->graphics = 1; break;
case 'G': v->graphics = 0; break;
case 'H': vt_move_cursor(t, 0, 0, 0); break;
case 'I': vt_reverse_index(t); break;
case 'J': vt_erase_display(t, 0, 0); break;
case 'K': vt_erase_line(t, 0, 0); break;
case 'Y': v->state = V_ROW; break;
case 'Z': vt_reply(t, v->identity); break;
case '=': t->app_keypad = 1; break;
case '>': t->app_keypad = 0; break;
case '<': if (v->on_ansi) v->on_ansi(v->ctx); break;
case '[': case '\\': break;
case '^': v->printer.autop = 1; break;
case '_': v->printer.autop = 0; break;
case 'W': printer_start(&v->printer); break;
case 'V': printer_line(&v->printer, t->cy); break;
case ']': printer_screen(&v->printer); break;
default:
if (cp == 0x1b)
v->state = V_ESC;
else if (cp < 0x20)
control(v, cp);
}
}
static void process(struct vt_interp *in, int32_t cp)
{
struct vt52 *v = (struct vt52 *)in;
dmc_vt *t = T(v);
int y, pen;
if (v->printer.controller) {
printer_feed(&v->printer, cp);
return;
}
switch (v->state) {
case V_GROUND:
if (cp == 0x1b)
v->state = V_ESC;
else if (cp < 0x20)
control(v, cp);
else if (cp == 0x7f)
;
else if (v->graphics)
vt_print(t, (int32_t)gset_map(v->graphics_set, (uint32_t)cp));
else
vt_print(t, v->st ? (int32_t)atari_st_char(cp) : cp);
break;
case V_ESC:
v->state = V_GROUND;
esc(v, cp);
break;
case V_ROW:
v->row = cp - 0x20;
v->state = V_COL;
break;
case V_ARG:
v->state = V_GROUND;
pen = cp & (v->st->ncolors - 1);
if (v->arg_for == 'b')
v->fg = pen;
else
v->bg = pen;
st_restyle(v);
break;
case V_COL:
v->state = V_GROUND;
/* (a row off the screen leaves the cursor's) */
y = v->row >= 0 && v->row < t->rows ? v->row : t->cy;
vt_move_cursor(t, cp - 0x20, y, 0);
break;
}
}
static void st_attach(struct vt52 *v)
{
dmc_vt *t = T(v);
const struct vt_profile *m = v->st;
vt_use_machine(t, m->columns, m->rows, m->colors, m->ncolors,
m->default_color, m->background);
t->autowrap = 1;
t->cursor_visible = 1;
st_restyle(v);
}
static void reset(struct vt_interp *in)
{
struct vt52 *v = (struct vt52 *)in;
v->state = V_GROUND;
v->graphics = 0;
printer_reset(&v->printer);
T(v)->vt52_keys = 1;
if (v->st) {
v->fg = v->st->default_color;
v->bg = v->st->background;
v->reverse = 0;
st_attach(v);
}
}
static void detach(struct vt_interp *in)
{
struct vt52 *v = (struct vt52 *)in;
if (v->st)
vt_release_machine(T(v));
T(v)->vt52_keys = 0;
}
static void destroy(struct vt_interp *in)
{
struct vt52 *v = (struct vt52 *)in;
printer_free(&v->printer);
free(v);
}
static const struct vt_interp_ops vt52_ops = {
process, reset, NULL, NULL, NULL, NULL, NULL, NULL, NULL, detach,
destroy
};
struct vt_interp *vt52_new(dmc_vt *t, int graphics_set, const char *identity,
void (*on_ansi)(void *), void *ctx)
{
struct vt52 *v = (struct vt52 *)calloc(1, sizeof(*v));
if (!v)
return NULL;
v->in.ops = &vt52_ops;
v->in.t = t;
v->graphics_set = graphics_set;
v->identity = identity;
v->on_ansi = on_ansi;
v->ctx = ctx;
printer_init(&v->printer, t, "\x1bX", NULL);
t->vt52_keys = 1;
return &v->in;
}
struct vt_interp *atari_st_new(dmc_vt *t, const struct vt_profile *p)
{
struct vt_interp *in = vt52_new(t, G_VT52_GRAPHICS, "\x1b/K", NULL, NULL);
struct vt52 *v = (struct vt52 *)in;
if (!v)
return NULL;
in->reads_octets = 1;
v->st = p;
v->fg = p->default_color;
v->bg = p->background;
st_attach(v);
return in;
}
-615
View File
@@ -1,615 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* vtint.h - the terminal emulator's insides (dmc_vt), shared by its
* files: the screen (vt.c), the interpreters of each family of
* terminals (vt_dec.c, vt_vt52.c, vt_machine.c, vt_gfx.c,
* vt_regis.c, vt_rip.c), the character sets and keys
* (vt_charsets.c, vt_keys.c), the profiles (vt_profiles.c) and
* the machines' fonts (vt_data.c).
*
* A C port of the D-Modem app's shared Kotlin emulator
* (D-Modem/app: shared/src/commonMain/kotlin/org/dmodem/app/terminal),
* kept close to it so that a change there can be carried here: the same
* parts, the same names where C allows, the same behaviour. C99 with
* no designated initialisers and no VLAs, for older compilers too.
*/
#ifndef DMC_VTINT_H
#define DMC_VTINT_H
#include <stddef.h>
#include <stdint.h>
#include "dmodemctl.h"
#include "util.h"
/*
* A cell's look, packed in 64 bits as the app's Style is: the foreground
* (bits 0-24), the background (25-49) and the attributes (50-63). A
* colour is an index of the 256-colour palette, ST_DEFAULT_FG or
* ST_DEFAULT_BG, or ST_RGB or'ed with a 24-bit colour.
*/
typedef uint64_t vt_style;
#define ST_DEFAULT_FG 256
#define ST_DEFAULT_BG 257
#define ST_RGB 0x1000000
enum {
A_BOLD = 1, A_FAINT = 2, A_ITALIC = 4, A_UNDERLINE = 8, A_BLINK = 16,
A_INVERSE = 32, A_INVISIBLE = 64, A_STRIKE = 128,
A_DUNDER = 256, /* SGR 21, 4:2 */
A_CURLY = 512, /* SGR 4:3 (and 4:4, 4:5) */
A_OVERLINE = 1024,
A_PROTECTED = 2048 /* DECSCA's (not a rendition) */
};
#define A_ANY_UNDER (A_UNDERLINE | A_DUNDER | A_CURLY)
#define ST_COLOR_MASK 0x1ffffffULL
#define st_of(fg, bg, attrs) \
(((vt_style)(unsigned)(fg) & ST_COLOR_MASK) | \
(((vt_style)(unsigned)(bg) & ST_COLOR_MASK) << 25) | \
((vt_style)(unsigned)(attrs) << 50))
#define st_fg(s) ((int)((s) & ST_COLOR_MASK))
#define st_bg(s) ((int)(((s) >> 25) & ST_COLOR_MASK))
#define st_attrs(s) ((int)((s) >> 50))
#define st_with_fg(s, f) st_of((f), st_bg(s), st_attrs(s))
#define st_with_bg(s, b) st_of(st_fg(s), (b), st_attrs(s))
#define st_with_attrs(s, a) st_of(st_fg(s), st_bg(s), (a))
/* the look of erased cells: only the background stays (xterm's BCE) */
#define st_erased(s) st_of(ST_DEFAULT_FG, st_bg(s), 0)
#define ST_NORMAL st_of(ST_DEFAULT_FG, ST_DEFAULT_BG, 0)
/* the right half of a wide character, in a line's chars */
#define WIDE_TAIL (-1)
/* a picture (a sixel image, a graphics terminal's screen), its pixels
ARGB (0: transparent), shared by the cells that show it */
struct vt_image {
int refs;
uint32_t id;
int width, height;
uint32_t *pixels;
/* the cell size it was placed at: its tiles are cells of that size */
int cell_w, cell_h;
/* a graphics terminal's picture over the screen, not an image in
the text */
int picture;
};
/* a hyperlink (OSC 8), shared by the cells that carry it */
struct vt_link {
int refs;
char *uri;
};
/* what few cells carry besides their character */
struct vt_extra {
uint32_t *comb; /* combining marks */
int ncomb;
struct vt_image *img; /* a picture's tile */
int tx, ty;
struct vt_link *link;
};
enum { LS_SINGLE, LS_DOUBLE_WIDTH, LS_DOUBLE_TOP, LS_DOUBLE_BOTTOM };
/* a line of cells: code points (0 never written, WIDE_TAIL), their
looks, and the few cells' extras */
struct vt_line {
int cols;
int32_t *ch;
vt_style *st;
struct vt_extra **ex; /* NULL until a cell needs one */
int wrapped;
int size; /* LS_* */
};
struct vt_line *line_new(int cols, vt_style st);
void line_free(struct vt_line *l);
struct vt_extra *line_extra(const struct vt_line *l, int i);
struct vt_extra *line_extra_for(struct vt_line *l, int i);
void line_set(struct vt_line *l, int i, int32_t cp, vt_style st);
void line_clear(struct vt_line *l, int from, int to, vt_style st);
void line_blank(struct vt_line *l, vt_style st);
void line_insert_cells(struct vt_line *l, int at, int n, vt_style st, int end);
void line_delete_cells(struct vt_line *l, int at, int n, vt_style st, int end);
void line_resize(struct vt_line *l, int n);
void line_copy_from(struct vt_line *l, const struct vt_line *o);
/* cell i's extras made those of e (copies; the picture and link shared) */
void extra_assign(struct vt_line *l, int i, const struct vt_extra *e);
/* the text from..to, trailing blanks dropped, as UTF-8 into b */
void line_text(const struct vt_line *l, int from, int to, dmc_buf *b);
struct vt_image *image_new(int w, int h, int cell_w, int cell_h, int picture);
void image_unref(struct vt_image *img);
struct vt_link *link_new(const char *uri);
void link_unref(struct vt_link *l);
void utf8_put(dmc_buf *b, uint32_t c);
/*
* Bitmap glyphs (BitmapFont): w pixels wide (8, or up to 24 for a soft
* font), h high; a row's leftmost pixel bit w - 1. The codes are sorted.
*/
struct vt_font {
int w, h, n;
const uint32_t *codes;
const uint8_t *rows8; /* n * h, when w <= 8 */
const uint32_t *rows32; /* n * h, otherwise */
};
int font_index(const struct vt_font *f, uint32_t cp);
uint32_t font_row(const struct vt_font *f, uint32_t cp, int row);
/* the machines' fonts and sets (vt_data.c, generated) */
extern const struct vt_font vt_font_8x8; /* Unscii's 8x8 */
extern const struct vt_font vt_font_vga; /* code page 437, 8x16 */
extern const uint32_t vt_set_c64_upper[256], vt_set_c64_lower[256];
extern const uint32_t vt_set_vic_upper[256], vt_set_vic_lower[256];
extern const uint32_t vt_set_pet_upper[256], vt_set_pet_lower[256];
extern const uint32_t vt_set_atari_graphics[256];
extern const uint32_t vt_set_atari_international[256];
/* the machines' character ROMs (SyncTERM's), 256 glyphs 8 wide in the
machine's own order, 8 rows, 16 or both (NULL: not that size) */
enum {
ROM_VGA, ROM_VGA_THIN, ROM_C64_UPPER, ROM_C64_LOWER, ROM_C128_UPPER,
ROM_C128_LOWER, ROM_ATARI, ROM_POT_NOODLE, ROM_MOSOUL,
ROM_MICROKNIGHT_PLUS, ROM_TOPAZ_PLUS, ROM_MICROKNIGHT, ROM_TOPAZ,
ROM_PRESTEL, ROM_ATARI_ST, ROM_RIPTERM, ROM_COUNT
};
struct vt_rom {
const uint8_t *r8, *r16;
};
extern const struct vt_rom vt_roms[ROM_COUNT];
/* the terminal types' fonts (vt_fonts.c): each ROM read in its machine's
set, Unscii's for what it hasn't got */
enum {
MF_NONE = -1, MF_VGA, MF_RIPTERM, MF_C64, MF_C128, MF_ATARI, MF_TOPAZ,
MF_ATARI_ST, MF_PRESTEL, MF_COUNT
};
const struct vt_font *machine_font(int which);
/* SyncTERM's font n (CSI SP D's), height 8 or 16 rows, its codes read as
octets of a charset (CS_*); NULL if it isn't here */
const struct vt_font *syncterm_font(int n, int height, int charset);
/* an octet in the Atari ST's set as its code point */
uint32_t atari_st_char(int b);
/* teletext's English set, 0x20-0x7f */
uint32_t viewdata_g0(int c);
/* the mosaics (teletext's 2x3 blocks): their code points and glyphs */
#define MOSAIC_BASE 0xf1000
uint32_t mosaic_code(int mask, int separated);
int mosaic_bits(int c);
extern const struct vt_font vt_font_mosaic;
/*
* Character sets (vt_charsets.c)
*/
enum { CS_UTF8, CS_CP437, CS_LATIN1 };
uint32_t cp437_decode(int b);
int cp437_encode(uint32_t cp);
/* text into octets of a set (what it can't have: '?') */
void charset_encode(int cs, const uint32_t *cps, int n, dmc_buf *out);
/* the G sets a slot can hold */
enum {
G_ASCII, G_DEC_GRAPHICS, G_UK, G_VT52_GRAPHICS, G_DEC_SUPPLEMENTAL,
G_DEC_TECHNICAL, G_LATIN1, G_DUTCH, G_FINNISH, G_FRENCH,
G_FRENCH_CANADIAN, G_GERMAN, G_ITALIAN, G_NORWEGIAN_DANISH,
G_SPANISH, G_SWEDISH, G_SWISS, G_PORTUGUESE, G_SOFT, G_COUNT
};
int gset_by_designator(const char *d, int is96);
int gset_is96(int g);
int gset_level(int g);
/* its first designator ("" for none) */
const char *gset_designator(int g);
uint32_t gset_map(int g, uint32_t cp);
uint32_t dec_graphics(uint32_t cp);
/* the cells a character takes: 0, 1 or 2 */
int wcwidth_of(uint32_t cp);
/*
* The emulator
*/
struct vt_interp;
struct vt_profile;
/* G0-G3 and the shifts, as DECSC keeps them */
struct vt_sets_saved {
uint8_t g[4];
int gl, gr;
};
struct vt_saved {
int set;
int x, y;
vt_style style;
int wrap, origin;
int have_sets;
struct vt_sets_saved sets;
};
/* a VT320's host-writable status line */
struct vt_status {
struct vt_line *line;
int x;
};
enum { MOUSE_NONE, MOUSE_X10, MOUSE_NORMAL, MOUSE_BUTTON, MOUSE_ANY };
#define VT_PAGES 6
#define VT_MAX_IMAGE 2048
#define VT_NO_COLOR 0
struct dmc_vt {
int cols, rows;
/* the scrollback: a ring, hist_n lines from hist_first */
struct vt_line **hist;
int hist_n, hist_max, hist_first;
struct vt_line **main_s, **alt_s, **screen;
/* the main screen's pages not shown (VT420), by number */
struct vt_line **pages[VT_PAGES];
int page;
int cx, cy, pending_wrap;
vt_style style;
int cursor_visible, app_cursor, app_keypad, bracketed_paste;
int reverse_video, mouse_mode, mouse_sgr, mouse_urxvt, mouse_utf8;
int focus_events, cursor_style;
int sixel_scrolling, sixel_cursor_right;
int cell_pw, cell_ph;
/* the remote's colours and the machines' palettes: 0-255, 256 fg,
257 bg, 258 cursor; VT_NO_COLOR or opaque ARGB */
uint32_t color_over[259];
int requested_cols, requested_rows;
int ice_colors, emulated_bps, leds, vt52_keys;
struct vt_link *link;
int join_next;
int autowrap, origin_mode, insert_mode, newline_mode;
/* ASCII Setup's receive items (DMC_VT_ASCII_*), and a CR just fed */
int ascii, ascii_cr;
int top, bottom;
uint8_t *tabs;
int lr_margins, left, right;
int32_t last_char;
struct vt_saved saved_main, saved_alt;
int home_on_clear;
int eight_bit_replies;
int status_type;
struct vt_status status;
const struct vt_font *soft_glyphs;
/* the font the host chose (CSI SP D), NULL: the profile's */
const struct vt_font *host_font;
const struct vt_profile *profile;
struct vt_interp *interp;
/* the decoder */
int charset; /* in use */
int user_charset; /* the user's, for profiles without their own */
int u_need;
uint32_t u_cp, u_min;
/* what the app reads */
dmc_buf reply, text, title;
int title_changed;
int bells;
uint32_t *music; /* hz * 100, ms, rest ms */
int music_n, music_cap;
dmc_buf print;
char answerback[32];
int changed;
uint32_t image_ids;
/* the keys */
int enter_mode; /* 0 CR, 1 CR LF, 2 LF */
int backspace_code; /* 0x7f or 0x08 */
/* the theme */
uint32_t theme_fg, theme_bg, theme_cursor;
uint32_t theme_pal[16];
int bold_bright;
};
/* the glyphs the cells are drawn with: the host's font, else the
profile's (NULL: the view's font) */
const struct vt_font *vt_glyphs(const dmc_vt *t);
/* the screen's operations (vt.c), as TerminalEmulator's */
struct vt_line *vt_line(const dmc_vt *t, int row);
void vt_print(dmc_vt *t, int32_t cp);
int vt_line_width(const dmc_vt *t, int y);
void vt_set_line_size(dmc_vt *t, int size);
void vt_set_column_mode(dmc_vt *t, int wide);
void vt_carriage_return(dmc_vt *t);
void vt_backspace(dmc_vt *t);
void vt_index(dmc_vt *t);
void vt_reverse_index(dmc_vt *t);
void vt_scroll_up(dmc_vt *t, int top, int bottom);
void vt_scroll_down(dmc_vt *t, int top, int bottom);
void vt_move_cursor(dmc_vt *t, int x, int y, int clamp_to_region);
void vt_cursor_position(dmc_vt *t, int x, int y);
void vt_set_margins(dmc_vt *t, int l, int r);
void vt_set_lr_margins(dmc_vt *t, int on);
void vt_set_region(dmc_vt *t, int top, int bottom);
void vt_tab(dmc_vt *t, int n);
void vt_back_tab(dmc_vt *t, int n);
void vt_set_tab(dmc_vt *t);
void vt_clear_tab(dmc_vt *t);
void vt_clear_tabs(dmc_vt *t);
void vt_erase_display(dmc_vt *t, int mode, int selective);
void vt_erase_line(dmc_vt *t, int mode, int selective);
void vt_erase_chars(dmc_vt *t, int n);
void vt_insert_chars(dmc_vt *t, int n);
void vt_delete_chars(dmc_vt *t, int n);
void vt_insert_lines(dmc_vt *t, int n);
void vt_delete_lines(dmc_vt *t, int n);
void vt_set_alt_screen(dmc_vt *t, int on, int clear);
int vt_alt_screen(const dmc_vt *t);
void vt_save_cursor(dmc_vt *t);
void vt_restore_cursor(dmc_vt *t);
void vt_alignment_test(dmc_vt *t);
void vt_soft_reset(dmc_vt *t);
void vt_full_reset(dmc_vt *t);
void vt_select_page(dmc_vt *t, int n, int home);
int vt_within_margins(const dmc_vt *t);
void vt_set_color_override(dmc_vt *t, int i, uint32_t argb);
void vt_reset_colors(dmc_vt *t, int from, int to);
uint32_t vt_color_override(const dmc_vt *t, int i);
/* the colour the screen shows for i (0-255, 256 fg, 257 bg, 258 cursor) */
uint32_t vt_shown_color(const dmc_vt *t, int i);
/* s to the remote as Latin-1 octets (C1 forms when eight_bit_replies) */
void vt_reply(dmc_vt *t, const char *s);
void vt_replyf(dmc_vt *t, const char *fmt, ...);
void vt_bell(dmc_vt *t);
void vt_add_music(dmc_vt *t, double hz, int ms, int rest_ms);
void vt_print_out(dmc_vt *t, const char *utf8);
void vt_set_title(dmc_vt *t, const char *s);
void vt_place_image(dmc_vt *t, struct vt_image *img);
void vt_show_picture(dmc_vt *t, struct vt_image *img);
void vt_tab_stops(const dmc_vt *t, dmc_buf *out);
/* a machine's size and palette on the screen, and back */
void vt_use_machine(dmc_vt *t, int cols, int rows, const uint32_t *pal,
int npal, int fg, int bg);
void vt_release_machine(dmc_vt *t);
/* the status line's text as the view shows it */
void vt_status_text(const dmc_vt *t, dmc_buf *out);
void status_print(dmc_vt *t, int32_t cp, vt_style st);
void status_move(dmc_vt *t, int col);
void status_erase(dmc_vt *t, int mode, vt_style st);
/*
* The interpreters: what reads the remote's characters
*/
struct vt_interp_ops {
void (*process)(struct vt_interp *, int32_t cp);
void (*reset)(struct vt_interp *);
void (*soft_reset)(struct vt_interp *);
/* G0-G3 for DECSC (NULL: none) */
int (*save_sets)(struct vt_interp *, struct vt_sets_saved *);
void (*restore_sets)(struct vt_interp *, const struct vt_sets_saved *);
/* a key's octets into out: 1 if it has its own (even none), 0 the
VT sequences */
int (*key)(struct vt_interp *, int key, int mods, dmc_buf *out);
int (*chr)(struct vt_interp *, uint32_t cp, int mods, dmc_buf *out);
int (*tap)(struct vt_interp *, double fx, double fy, dmc_buf *out);
void (*flush)(struct vt_interp *);
void (*detach)(struct vt_interp *);
void (*destroy)(struct vt_interp *);
};
struct vt_interp {
const struct vt_interp_ops *ops;
dmc_vt *t;
int reads_octets;
};
void interp_free(struct vt_interp *in);
/* a DEC terminal's printer port (vt_dec.c): what the remote sends to the
printer until ends[] (controller mode), lines as they're left (auto) */
struct vt_printer {
dmc_vt *t;
int controller, autop;
dmc_buf buf;
const char *ends[2];
};
void printer_init(struct vt_printer *p, dmc_vt *t, const char *end1,
const char *end2);
void printer_start(struct vt_printer *p);
void printer_feed(struct vt_printer *p, int32_t cp);
void printer_line(struct vt_printer *p, int y);
void printer_screen(struct vt_printer *p);
void printer_reset(struct vt_printer *p);
void printer_free(struct vt_printer *p);
/* the key modifiers */
enum { M_SHIFT = 1, M_ALT = 2, M_CTRL = 4 };
/* the interpreters there are */
struct vt_interp *dec_new(dmc_vt *t, const struct vt_profile *p);
struct vt_interp *vt52_new(dmc_vt *t, int graphics_set, const char *identity,
void (*on_ansi)(void *), void *ctx);
struct vt_interp *atari_st_new(dmc_vt *t, const struct vt_profile *p);
struct vt_interp *petscii_new(dmc_vt *t, const struct vt_profile *p);
struct vt_interp *atascii_new(dmc_vt *t, const struct vt_profile *p);
struct vt_interp *viewdata_new(dmc_vt *t, const struct vt_profile *p);
struct vt_interp *minitel_new(dmc_vt *t, const struct vt_profile *p);
struct vt_interp *tek_new(dmc_vt *t, void (*on_exit)(void *), void *ctx);
/*
* Profiles: the kinds of terminal
*/
enum {
K_VT52, K_DEC, K_ANSI_BBS, K_AVATAR, K_RIP, K_PETSCII, K_ATASCII,
K_ATARI_ST, K_VIEWDATA, K_MINITEL, K_TEK
};
/* what a DEC-style terminal has beyond its level's text */
enum {
F_COLOR = 1, F_SIXEL = 2, F_PRINTER = 4, F_XTERM = 8, F_TEK = 16,
F_REGIS = 32
};
/* a Commodore's attribute codes */
enum { AC_NONE, AC_VDC, AC_PLUS4 };
struct vt_profile {
const char *id, *label, *term, *telnet;
int kind;
/* a DEC terminal's */
int level;
unsigned features;
const char *da1, *da2;
int charset; /* CS_*, or -1: the user's */
int home_on_clear;
/* its cells' bitmap font (MF_*): its machine's ROM; MF_NONE: the
view's font */
int font;
/* ANSI-BBS: SyncTERM's number for its font, what CSI SP D's font 0
goes back to */
int syncterm;
/* ANSI-BBS: its sixteen colours over the theme's; a machine: its
palette */
const uint32_t *colors;
int ncolors;
/* a machine's screen */
int columns, rows, default_color, background;
/* a Commodore's */
const uint32_t *upper, *lower;
const uint8_t *ctrl_colors, *cbm_colors;
int n_ctrl, n_cbm;
int escapes, attr_codes, tab_lf;
/* an Atari's */
const uint32_t *atascii;
/* what a capture's file is called (".seq"), NULL for the app's */
const char *capture_ext;
};
extern const struct vt_profile *const vt_profiles[];
extern const int vt_profile_count;
const struct vt_profile *vt_profile_by_id(const char *id);
const struct vt_profile *vt_profile_default(void);
/* the VT100 a Minitel's Téléinformatique mode is */
extern const struct vt_profile vt_profile_vt100;
/* the interpreter for a profile */
struct vt_interp *profile_interp(dmc_vt *t, const struct vt_profile *p);
/*
* Keys (vt_keys.c): what a key sends as a VT220/xterm
*/
void keys_key(const dmc_vt *t, int key, int mods, dmc_buf *out);
void keys_char(uint32_t cp, int mods, dmc_buf *out);
/*
* Graphics (vt_gfx.c)
*/
struct sixel;
struct sixel *sixel_new(int transparent, uint32_t *shared, int max_w,
int max_h);
void sixel_feed(struct sixel *s, int32_t cp);
struct vt_image *sixel_finish(dmc_vt *t, struct sixel *s, int cw, int ch);
void sixel_free(struct sixel *s);
uint32_t sixel_hls(int h, int l, int s);
void sixel_default_palette(uint32_t p[256]);
/* a graphics terminal's picture: logical coordinates into pixels */
enum { R_OVERLAY, R_REPLACE, R_COMPLEMENT, R_ERASE };
struct raster {
int width, height, lw, lh;
uint32_t *px;
int mode;
uint32_t color, background;
int pattern;
const uint8_t *fill_pattern; /* 8 rows, NULL solid */
uint8_t fill_pattern_buf[8];
uint32_t fill_background;
int clip[4], has_clip;
int pattern_step;
int dirty;
};
struct raster *raster_new(int w, int h, int lw, int lh);
void raster_free(struct raster *r);
int raster_px(const struct raster *r, int x);
int raster_py(const struct raster *r, int y);
void raster_clear(struct raster *r, uint32_t c);
void raster_point(struct raster *r, int x, int y);
void raster_line(struct raster *r, int x0, int y0, int x1, int y1);
void raster_arc(struct raster *r, int cx, int cy, int rad, double start,
double sweep);
void raster_ellipse(struct raster *r, int cx, int cy, int rx, int ry,
double start, double sweep);
/* an elliptical arc's points (logical) into xy (pairs): how many */
int raster_ellipse_points(int cx, int cy, int rx, int ry, double start,
double sweep, int *xy, int max);
void raster_fill(struct raster *r, const int *xy, int n);
void raster_flood(struct raster *r, int x, int y, uint32_t border);
struct raster_grab {
int width, height;
uint32_t *px;
};
void raster_grab(const struct raster *r, int x0, int y0, int x1, int y1,
struct raster_grab *g);
void raster_put(struct raster *r, const struct raster_grab *g, int x, int y,
int xor_);
void raster_pixel_rect(const struct raster *r, int x0, int y0, int x1, int y1,
int out[4]);
void raster_clear_rect(struct raster *r, int x0, int y0, int x1, int y1,
uint32_t c);
int raster_text(struct raster *r, int x, int y, const uint32_t *cps, int n,
const struct vt_font *f, int cw, int ch);
struct vt_image *raster_take(dmc_vt *t, struct raster *r, int cw, int ch);
/* a picture kept the screen's size, put on it when drawn on */
struct picture_layer {
dmc_vt *t;
int lw, lh;
struct raster *r;
void (*setup)(struct raster *, void *);
void *ctx;
};
void layer_init(struct picture_layer *l, dmc_vt *t, int lw, int lh,
void (*setup)(struct raster *, void *), void *ctx);
struct raster *layer_raster(struct picture_layer *l);
void layer_reset(struct picture_layer *l);
void layer_flush(struct picture_layer *l);
void layer_free(struct picture_layer *l);
/* ReGIS (vt_regis.c) */
struct regis;
struct regis *regis_new(dmc_vt *t, uint32_t *registers);
void regis_begin(struct regis *g, int p1);
void regis_feed(struct regis *g, int32_t cp);
void regis_end(struct regis *g);
void regis_abort(struct regis *g);
void regis_flush(struct regis *g);
void regis_reset(struct regis *g);
void regis_free(struct regis *g);
/* RIPscrip (vt_rip.c), over ANSI-BBS: what it doesn't take given back
to ANSI-BBS's parser through replay */
struct rip;
struct rip *rip_new(dmc_vt *t, void (*replay)(void *, int32_t), void *ctx);
/* a code point to RIP: 1 if it took it */
int rip_intercept(struct rip *r, int32_t cp);
int rip_tap(struct rip *r, double fx, double fy, dmc_buf *out);
void rip_flush(struct rip *r);
void rip_reset(struct rip *r);
void rip_free(struct rip *r);
/* ESC [ ! : RIP's version asked */
void rip_query(struct rip *r);
/* ANSI music (vt_dec.c) */
struct ansi_music {
int tempo, octave, length;
double sounding;
};
void music_reset(struct ansi_music *m);
void music_play(dmc_vt *t, struct ansi_music *m, const char *s);
#endif
-1066
View File
File diff suppressed because it is too large. Load diff
-174
View File
@@ -1,174 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* xfer.h - the file transfers' parts (xfer*.c): a transfer runs on a
* thread of its own, its line two queues (what came from the
* remote, what goes to it) that the app's thread fills and
* drains; a failure or a cancel goes back to the thread's start
* with longjmp, the files it had open closed there.
*/
#ifndef DMC_XFER_H
#define DMC_XFER_H
#include <setjmp.h>
#include <stdio.h>
#include "dmodemctl.h"
#include "util.h"
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#else
#include <pthread.h>
#endif
#define XFER_PATH 1024
#define XFER_NAME 256
/* what may wait to go to the remote before the protocol's thread waits */
#define XFER_OUT_MAX (32 * 1024)
/* a file to send */
struct xfer_file {
char *path;
char name[XFER_NAME];
long long size; /* -1 not known */
long long mtime; /* seconds, 0 not known */
};
struct dmc_xfer {
int protocol, sending;
char folder[XFER_PATH]; /* received files' */
char xname[XFER_NAME]; /* XMODEM's (it sends no name) */
struct xfer_file *files;
int nfiles;
/* the line, and the status: the app's thread and the protocol's */
#ifdef _WIN32
CRITICAL_SECTION cs;
HANDLE ev_in, ev_out, thread;
#else
pthread_mutex_t mu;
pthread_cond_t cv_in, cv_out;
pthread_t thread;
#endif
int started;
void (*notify)(void *);
void *notify_ctx;
int notified;
dmc_buf in, out;
volatile int cancelled;
dmc_xfer_status st;
char **names;
int nnames;
/* the protocol's thread's alone */
unsigned char rbuf[4096];
int rpos, rlen;
jmp_buf jb;
char why[256];
FILE *src; /* the file being sent */
FILE *dst; /* the file being received */
char dst_path[XFER_PATH], dst_name[XFER_NAME + 16];
int keep_on_cancel; /* plain text: what came is kept */
int keep_partial; /* crash recovery: a part is kept */
dmc_xfer_options opt;
volatile int skip; /* the user skipped the file now */
volatile int zstd; /* the file now goes with zstd */
void *heap; /* freed at the end */
void *proto; /* the protocol's state (Kermit's) */
void (*proto_free)(void *); /* how it's freed (NULL: free) */
};
/* plain text's quiet that ends a receive (the tests' shorter) */
extern int xfer_text_quiet_ms;
/* the time in ms (monotonic) and a pause */
long long xfer_now(void);
void xfer_sleep(int ms);
/* a byte from the remote (0-255), -1 when none came within ms; a cancel
jumps out */
int xfer_read(dmc_xfer *x, int ms);
/* the same, -2 for a cancel instead of the jump */
int xfer_read_nc(dmc_xfer *x, int ms);
/* the next byte left waiting, -1 for none: no wait */
int xfer_peek(dmc_xfer *x);
int xfer_available(dmc_xfer *x);
/* what is waiting dropped */
void xfer_purge(dmc_xfer *x);
/* bytes to the remote (a cancel jumps out) */
void xfer_write(dmc_xfer *x, const void *data, int n);
void xfer_put(dmc_xfer *x, int c);
int xfer_is_cancelled(dmc_xfer *x);
/* the transfer failed (why) or was cancelled: back to the start */
#if defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn, format(printf, 2, 3)))
#endif
void xfer_fail(dmc_xfer *x, const char *fmt, ...);
#if defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn))
#endif
void xfer_cancelled(dmc_xfer *x, const char *why);
/* the status as it goes */
void xfer_file_start(dmc_xfer *x, const char *name, long long size);
void xfer_bytes(dmc_xfer *x, long long bytes);
void xfer_size(dmc_xfer *x, long long size);
void xfer_file_done(dmc_xfer *x);
void xfer_error(dmc_xfer *x);
long long xfer_size_now(dmc_xfer *x);
/* a received file made in the folder (its name made safe and unique):
x->dst open, x->dst_name the name it got */
void xfer_create(dmc_xfer *x, const char *name);
/* the same for crash recovery: a part of the file in the folder
continued (its length, appended to), or a new one (0); -2 when the
file is there whole (size known), and nothing opened */
long long xfer_create_resume(dmc_xfer *x, const char *name, long long size);
/* whether the file now goes compressed with zstd (ZMODEM) */
void xfer_zstd(dmc_xfer *x, int on);
/* the user's skip of the file now, taken (once) */
int xfer_skip_wanted(dmc_xfer *x);
/* the received file written */
void xfer_dst_write(dmc_xfer *x, const void *data, int n);
/* the received file whole (its time set, if mtime > 0), or dropped */
void xfer_done(dmc_xfer *x, long long mtime);
void xfer_abandon(dmc_xfer *x);
/* a file to send opened (x->src), and closed */
void xfer_open(dmc_xfer *x, const struct xfer_file *f);
void xfer_close(dmc_xfer *x);
/* up to n bytes of x->src: how many (0 at its end) */
int xfer_src_read(dmc_xfer *x, void *buf, int n);
/* the checks: CRC-16/XMODEM, and CRC-32 kept inverted (ZMODEM's) */
unsigned xfer_crc16(unsigned crc, const unsigned char *p, int n);
unsigned xfer_crc16_byte(unsigned crc, int b);
unsigned long xfer_crc32(unsigned long crc, const unsigned char *p, int n);
unsigned long xfer_crc32_byte(unsigned long crc, int b);
/* the protocols (xfer_xy.c, xfer_z.c, xfer_kermit.c, xfer_hex.c) */
void xy_receive_x(dmc_xfer *x);
void xy_receive_y(dmc_xfer *x, int g);
void xy_send_x(dmc_xfer *x, int one_k);
void xy_send_y(dmc_xfer *x, int g);
void z_receive(dmc_xfer *x);
void z_send(dmc_xfer *x);
void kermit_receive(dmc_xfer *x);
void kermit_send(dmc_xfer *x);
/* Kermit's E packet that ends it, for a cancel: its length */
int kermit_cancel_bytes(dmc_xfer *x, char *out, int max);
void hex_receive(dmc_xfer *x, int srec);
void hex_send(dmc_xfer *x, int srec);
void text_receive(dmc_xfer *x);
void text_send(dmc_xfer *x);
/* ZMODEM's starts, and what cancels it */
extern const char z_sz_start[6], z_rz_start[6];
extern const char z_cancel[20];
#endif
-522
View File
@@ -1,522 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* xfer_hex.c - Intel HEX and Motorola S-records: a binary image as lines
* of text, each a record of an address, its data and a
* checksum, for EPROM programmers, monitor ROMs and boot
* loaders, which take them on a plain serial line. No
* protocol but the records' own checksums.
*
* Intel HEX: ":" count, address, type, data, checksum (the two's
* complement of the bytes' sum); types 00 data, 01 the end, 02 an
* extended segment address (x16), 04 an extended linear address (the
* upper 16 bits), 03 and 05 a start address (taken, unused).
*
* S-records: "S" type, count (address, data and checksum's bytes),
* address, data, checksum (the one's complement of the bytes' sum); S0 a
* header, S1/S2/S3 data at 16/24/32-bit addresses, S5/S6 the count of
* data records, S7/S8/S9 the end (with a start address).
*
* Sent: the file as records, a line each (CR LF), or as it is if it is
* the format's records already. Received: the records that come, until
* the end record (or a pause once some have come), as the binary image
* they hold (gaps 0xFF, as an erased EPROM has them).
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "xfer.h"
#define RECORD_BYTES 16
/* the largest image put together (64 MB) */
#define MAX_IMAGE (64LL << 20)
#define FIRST_MS 60000
#define PAUSE_MS 10000
/* a line longer than any record: the rest of it dropped */
#define MAX_LINE 600
/* ------------------------------------------------------------------ */
/* reading records */
struct chunk {
long long addr;
size_t off;
int len;
};
struct decoder {
int srec;
int ended, records;
long long bytes, upper;
struct chunk *chunks;
int nchunks, cap;
unsigned char *data;
size_t dn, dcap;
char why[200];
};
static void dec_free(void *p)
{
struct decoder *d = (struct decoder *)p;
if (!d)
return;
free(d->chunks);
free(d->data);
free(d);
}
static int put(struct decoder *d, long long addr, const unsigned char *b, int n)
{
if (d->nchunks == d->cap) {
int cap = d->cap ? d->cap * 2 : 64;
struct chunk *c = (struct chunk *)realloc(d->chunks, sizeof(*c) * (size_t)cap);
if (!c)
return 0;
d->chunks = c;
d->cap = cap;
}
if (d->dn + (size_t)n > d->dcap) {
size_t cap = d->dcap ? d->dcap * 2 : 4096;
while (cap < d->dn + (size_t)n)
cap *= 2;
unsigned char *p = (unsigned char *)realloc(d->data, cap);
if (!p)
return 0;
d->data = p;
d->dcap = cap;
}
if (n > 0)
memcpy(d->data + d->dn, b, (size_t)n);
d->chunks[d->nchunks].addr = addr;
d->chunks[d->nchunks].off = d->dn;
d->chunks[d->nchunks].len = n;
d->nchunks++;
d->dn += (size_t)n;
d->records++;
d->bytes += n;
return 1;
}
/* the bytes the hex digits s spell, into b: how many, -1 if not hex */
static int hex_bytes(const char *s, unsigned char *b, int max)
{
int n = (int)strlen(s);
if (n % 2)
return -1;
for (int i = 0; i < n; i++)
if (!isxdigit((unsigned char)s[i]))
return -1;
if (n / 2 > max)
return -1;
for (int i = 0; i < n / 2; i++) {
char t[3] = { s[2 * i], s[2 * i + 1], 0 };
b[i] = (unsigned char)strtol(t, NULL, 16);
}
return n / 2;
}
/* a line: 1 a record of the format, 0 not one, -1 a bad one (d->why) */
static int dec_line(struct decoder *d, const char *raw)
{
char l[MAX_LINE + 1];
while (*raw && isspace((unsigned char)*raw))
raw++;
snprintf(l, sizeof(l), "%s", raw);
int ln = (int)strlen(l);
while (ln && isspace((unsigned char)l[ln - 1]))
l[--ln] = '\0';
if (d->ended || !ln)
return 0;
unsigned char b[MAX_LINE / 2 + 2];
if (!d->srec) {
if (l[0] != ':')
return 0;
int n = hex_bytes(l + 1, b, (int)sizeof(b));
if (n < 0) {
snprintf(d->why, sizeof(d->why),
"Intel HEX record %d: not hex digits", d->records + 1);
return -1;
}
if (n < 5 || n != b[0] + 5) {
snprintf(d->why, sizeof(d->why),
"Intel HEX: a record's length is wrong: %.80s", l);
return -1;
}
int sum = 0;
for (int i = 0; i < n; i++)
sum += b[i];
if (sum & 0xff) {
snprintf(d->why, sizeof(d->why),
"Intel HEX: a checksum is wrong: %.80s", l);
return -1;
}
int addr = (b[1] << 8) | b[2];
switch (b[3]) {
case 0:
if (!put(d, d->upper + addr, b + 4, b[0])) {
snprintf(d->why, sizeof(d->why), "out of memory");
return -1;
}
break;
case 1:
d->ended = 1;
break;
case 2:
d->upper = (long long)((b[4] << 8) | b[5]) << 4;
break;
case 4:
d->upper = (long long)((b[4] << 8) | b[5]) << 16;
break;
case 3:
case 5:
break;
default:
snprintf(d->why, sizeof(d->why),
"Intel HEX: an unknown record type: %.80s", l);
return -1;
}
return 1;
}
if (ln < 2 || (l[0] != 'S' && l[0] != 's') || !isdigit((unsigned char)l[1]))
return 0;
int type = l[1] - '0';
int n = hex_bytes(l + 2, b, (int)sizeof(b));
if (n < 0) {
snprintf(d->why, sizeof(d->why), "S-record %d: not hex digits",
d->records + 1);
return -1;
}
if (n == 0 || n != b[0] + 1) {
snprintf(d->why, sizeof(d->why),
"S-record: a record's length is wrong: %.80s", l);
return -1;
}
int sum = 0;
for (int i = 0; i < n; i++)
sum += b[i];
if ((sum & 0xff) != 0xff) {
snprintf(d->why, sizeof(d->why), "S-record: a checksum is wrong: %.80s", l);
return -1;
}
int ab;
switch (type) {
case 0: case 1: case 5: case 9: ab = 2; break;
case 2: case 6: case 8: ab = 3; break;
case 3: case 7: ab = 4; break;
default:
snprintf(d->why, sizeof(d->why), "S-record: an unknown type: %.80s", l);
return -1;
}
if (n < 1 + ab + 1) {
snprintf(d->why, sizeof(d->why), "S-record: too short: %.80s", l);
return -1;
}
long long addr = 0;
for (int k = 0; k < ab; k++)
addr = (addr << 8) | b[1 + k];
if (type >= 1 && type <= 3) {
if (!put(d, addr, b + 1 + ab, n - 1 - ab - 1)) {
snprintf(d->why, sizeof(d->why), "out of memory");
return -1;
}
} else if (type >= 7) {
d->ended = 1;
}
return 1;
}
/* whether text is the format's records already (every line one, the end
record among them) */
static int is_records(const char *text, size_t n, int srec)
{
struct decoder d;
memset(&d, 0, sizeof(d));
d.srec = srec;
size_t i = 0;
int ok = 1;
while (i < n && ok) {
size_t e = i;
while (e < n && text[e] != '\n' && text[e] != '\r')
e++;
if (e - i <= MAX_LINE) {
char l[MAX_LINE + 1];
memcpy(l, text + i, e - i);
l[e - i] = '\0';
int empty = 1;
for (char *p = l; *p; p++)
if (!isspace((unsigned char)*p))
empty = 0;
if (!empty && dec_line(&d, l) != 1 && !d.ended)
ok = 0;
} else {
ok = 0;
}
i = e + 1;
}
int ended = d.ended;
free(d.chunks);
free(d.data);
return ok && ended;
}
/* ------------------------------------------------------------------ */
/* writing records */
static const char digits[] = "0123456789ABCDEF";
static int hex_out(char *o, const unsigned char *b, int n)
{
for (int i = 0; i < n; i++) {
o[2 * i] = digits[b[i] >> 4];
o[2 * i + 1] = digits[b[i] & 15];
}
return 2 * n;
}
/* a line sent (count: only its length counted), CR LF after it */
static long long emit(dmc_xfer *x, const char *line, int n, int count,
long long *sent, long long total, const char *name)
{
(void)total;
(void)name;
if (!count) {
if (xfer_is_cancelled(x))
xfer_cancelled(x, "cancelled");
xfer_write(x, line, n);
xfer_write(x, "\r\n", 2);
*sent += n + 2;
xfer_bytes(x, *sent);
}
return n + 2;
}
static int intel_record(char *o, int addr, int type, const unsigned char *data, int n)
{
unsigned char b[4 + 255 + 1];
b[0] = (unsigned char)n;
b[1] = (unsigned char)(addr >> 8);
b[2] = (unsigned char)addr;
b[3] = (unsigned char)type;
if (n > 0)
memcpy(b + 4, data, (size_t)n);
int sum = 0;
for (int i = 0; i < 4 + n; i++)
sum += b[i];
b[4 + n] = (unsigned char)(-sum);
o[0] = ':';
return 1 + hex_out(o + 1, b, 5 + n);
}
static int srec_record(char *o, int type, int ab, long long addr,
const unsigned char *data, int n)
{
unsigned char b[1 + 4 + 255 + 1];
int k = 0;
b[k++] = (unsigned char)(ab + n + 1);
for (int i = 0; i < ab; i++)
b[k++] = (unsigned char)(addr >> (8 * (ab - 1 - i)));
if (n > 0)
memcpy(b + k, data, (size_t)n);
k += n;
int sum = 0;
for (int i = 0; i < k; i++)
sum += b[i];
b[k++] = (unsigned char)~sum;
o[0] = 'S';
o[1] = (char)('0' + type);
return 2 + hex_out(o + 2, b, k);
}
/* data as the format's records (S-records: a header of name first),
sent, or only counted: their length with CR LFs */
static long long encode(dmc_xfer *x, const unsigned char *data, long long dn,
int srec, const char *name, int count, long long total)
{
char l[MAX_LINE];
long long len = 0, sent = 0;
if (!srec) {
long long upper = -1;
long long i = 0;
while (i < dn) {
long long addr = i;
/* (a record doesn't cross a 64 KB boundary) */
if ((addr >> 16) != upper) {
upper = addr >> 16;
unsigned char u[2] = { (unsigned char)(upper >> 8),
(unsigned char)upper };
len += emit(x, l, intel_record(l, 0, 4, u, 2), count,
&sent, total, name);
}
long long room = 0x10000 - (addr & 0xffff);
int n = RECORD_BYTES;
if (dn - i < n)
n = (int)(dn - i);
if (room < n)
n = (int)room;
len += emit(x, l, intel_record(l, (int)(addr & 0xffff), 0,
data + i, n), count, &sent,
total, name);
i += n;
}
len += emit(x, ":00000001FF", 11, count, &sent, total, name);
return len;
}
long long last = (dn > 0 ? dn : 1) - 1;
int type, ab, end;
if (last <= 0xffff) {
type = 1; ab = 2; end = 9;
} else if (last <= 0xffffff) {
type = 2; ab = 3; end = 8;
} else {
type = 3; ab = 4; end = 7;
}
int nl = (int)strlen(name);
if (nl > 60)
nl = 60;
len += emit(x, l, srec_record(l, 0, 2, 0, (const unsigned char *)name, nl),
count, &sent, total, name);
long long i = 0, records = 0;
while (i < dn) {
int n = dn - i < RECORD_BYTES ? (int)(dn - i) : RECORD_BYTES;
len += emit(x, l, srec_record(l, type, ab, i, data + i, n), count,
&sent, total, name);
i += n;
records++;
}
if (records <= 0xffff)
len += emit(x, l, srec_record(l, 5, 2, records, NULL, 0), count,
&sent, total, name);
len += emit(x, l, srec_record(l, end, ab, 0, NULL, 0), count, &sent,
total, name);
return len;
}
/* the file's records, sent as they are: their length, or sent */
static long long send_as_is(dmc_xfer *x, const char *text, size_t n, int count,
long long total, const char *name)
{
long long len = 0, sent = 0;
size_t i = 0;
while (i < n) {
size_t e = i;
while (e < n && text[e] != '\n' && text[e] != '\r')
e++;
size_t a = i, b = e;
while (a < b && isspace((unsigned char)text[a]))
a++;
while (b > a && isspace((unsigned char)text[b - 1]))
b--;
if (b > a)
len += emit(x, text + a, (int)(b - a), count, &sent, total, name);
i = e + 1;
}
return len;
}
void hex_send(dmc_xfer *x, int srec)
{
const struct xfer_file *f = &x->files[0];
const char *label = srec ? "S-records" : "Intel HEX";
xfer_open(x, f);
size_t cap = 65536, n = 0;
unsigned char *data = (unsigned char *)malloc(cap + 1);
if (!data)
xfer_fail(x, "out of memory");
x->heap = data;
for (;;) {
if (n == cap) {
if ((long long)cap >= MAX_IMAGE)
xfer_fail(x, "%s: too big for %s", f->name, label);
unsigned char *p = (unsigned char *)realloc(data, cap * 2 + 1);
if (!p)
xfer_fail(x, "out of memory");
data = p;
x->heap = data;
cap *= 2;
}
int r = xfer_src_read(x, data + n, (int)(cap - n > 65536 ? 65536 : cap - n));
if (r <= 0)
break;
n += (size_t)r;
}
xfer_close(x);
data[n] = 0;
long long total;
if (is_records((const char *)data, n, srec)) {
total = send_as_is(x, (const char *)data, n, 1, 0, f->name);
xfer_file_start(x, f->name, total);
send_as_is(x, (const char *)data, n, 0, total, f->name);
} else {
total = encode(x, data, (long long)n, srec, f->name, 1, 0);
xfer_file_start(x, f->name, total);
encode(x, data, (long long)n, srec, f->name, 0, total);
}
xfer_bytes(x, total);
xfer_file_done(x);
}
void hex_receive(dmc_xfer *x, int srec)
{
const char *label = srec ? "S-record" : "Intel HEX";
struct decoder *d = (struct decoder *)calloc(1, sizeof(*d));
if (!d)
xfer_fail(x, "out of memory");
d->srec = srec;
x->proto = d;
x->proto_free = dec_free;
char line[MAX_LINE + 1];
int ln = 0;
xfer_file_start(x, x->xname, -1);
while (!d->ended) {
int c = xfer_read(x, d->records == 0 ? FIRST_MS : PAUSE_MS);
if (c < 0) {
if (d->records == 0)
xfer_fail(x, "no %s records came", label);
/* (a sender that sends no end record: done once it
pauses) */
break;
}
if (c == '\r' || c == '\n') {
if (ln) {
line[ln] = '\0';
if (dec_line(d, line) < 0)
xfer_fail(x, "%s", d->why);
ln = 0;
xfer_bytes(x, d->bytes);
}
} else if (ln < MAX_LINE) {
line[ln++] = (char)c;
}
}
/* the image from the lowest address to the end of the highest
record */
long long first = 0, end = 0;
for (int i = 0; i < d->nchunks; i++) {
long long a = d->chunks[i].addr, e = a + d->chunks[i].len;
if (i == 0 || a < first)
first = a;
if (i == 0 || e > end)
end = e;
}
if (end - first > MAX_IMAGE)
xfer_fail(x, "the records span %lld bytes: too many for an image",
end - first);
size_t size = (size_t)(end - first);
unsigned char *img = (unsigned char *)malloc(size ? size : 1);
if (!img)
xfer_fail(x, "out of memory");
x->heap = img;
memset(img, 0xff, size);
/* (in the order they came: a record written again wins) */
for (int i = 0; i < d->nchunks; i++)
memcpy(img + (d->chunks[i].addr - first), d->data + d->chunks[i].off,
(size_t)d->chunks[i].len);
xfer_create(x, x->xname);
xfer_dst_write(x, img, (int)size);
xfer_done(x, 0);
xfer_file_start(x, x->dst_name, (long long)size);
xfer_bytes(x, (long long)size);
xfer_file_done(x);
}
-822
View File
@@ -1,822 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* xfer_kermit.c - Kermit, both ways, stop-and-wait: packets of printable
* characters, control characters prefixed, the 8th bit
* prefixed when the line is 7-bit, runs of a byte
* counted; long packets, 1-, 2- and 3-character (CRC)
* checks, file attributes (size and time), as both sides
* agree in the S/Y exchange. A bad or missing packet is
* asked for again (NAK) up to MAX_RETRIES times; an E
* packet ends it.
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "xfer.h"
#define MARK 1
#define CR 13
#define OUR_QCTL '#'
#define REPT '~'
#define CAP_LP 2
#define CAP_AT 8
/* the long packets asked for */
#define OUR_LONG 4000
#define MAX_RETRIES 10
#define TIMEOUT 10000
#define MAX_PACKET 9100
#define tochar(v) ((v) + 32)
#define unchar(v) ((v) - 32)
#define ctl(v) ((v) ^ 64)
struct kermit {
dmc_xfer *x;
int seven_bit;
/* what's agreed: the defaults until the S/Y exchange */
int send_max, send_long, eol, npad, padc, their_qctl, qbin, rept;
int check, attributes;
volatile int seq; /* the next packet's (a cancel's E too) */
volatile int force_check1; /* during the S/Y exchange: type 1 */
int last_sent_type;
/* the packet that came */
int pseq, ptype, plen;
unsigned char pkt[MAX_PACKET + 16];
/* an ACK's data, kept */
unsigned char ack[MAX_PACKET + 16];
int ack_len;
unsigned char obuf[MAX_PACKET + 64];
};
/* CRC-16/KERMIT (CCITT, bits reflected, from 0) */
static unsigned kcrc(const unsigned char *b, int n)
{
unsigned c = 0;
for (int i = 0; i < n; i++) {
c ^= b[i];
for (int k = 0; k < 8; k++)
c = c & 1 ? (c >> 1) ^ 0x8408 : c >> 1;
}
return c & 0xffff;
}
/* the block check of type 1, 2 or 3 over n bytes into out: its length */
static int check_chars(int type, const unsigned char *b, int n, unsigned char *out)
{
int s = 0;
for (int i = 0; i < n; i++)
s += b[i];
if (type == 1) {
out[0] = (unsigned char)tochar((s + ((s & 192) >> 6)) & 63);
return 1;
}
if (type == 2) {
out[0] = (unsigned char)tochar((s >> 6) & 63);
out[1] = (unsigned char)tochar(s & 63);
return 2;
}
unsigned c = kcrc(b, n);
out[0] = (unsigned char)tochar((c >> 12) & 0x0f);
out[1] = (unsigned char)tochar((c >> 6) & 63);
out[2] = (unsigned char)tochar(c & 63);
return 3;
}
static int check1(const unsigned char *b, int n)
{
unsigned char c[3];
check_chars(1, b, n, c);
return c[0];
}
/* the check type a packet goes with: 1 for S, I and R (and in the S/Y
exchange), else the agreed one */
static int check_len(int check, int force1, int type)
{
return type == 'S' || type == 'I' || type == 'R' || force1 ? 1 : check;
}
/* a packet's bytes into out: padding, MARK, its header (an extended one
for long data), data, its check and EOL; their length */
static int packet_bytes(unsigned char *out, int npad, int padc, int eol,
int check, int force1, int seq, int type,
const unsigned char *data, int n)
{
int ct = check_len(check, force1, type), k = 0;
for (int i = 0; i < npad; i++)
out[k++] = (unsigned char)padc;
out[k++] = MARK;
int body = k;
if (n + 2 + ct <= 94) {
out[k++] = (unsigned char)tochar(n + 2 + ct);
out[k++] = (unsigned char)tochar(seq);
out[k++] = (unsigned char)type;
} else {
int lx = n + ct;
out[k++] = (unsigned char)tochar(0);
out[k++] = (unsigned char)tochar(seq);
out[k++] = (unsigned char)type;
out[k++] = (unsigned char)tochar(lx / 95);
out[k++] = (unsigned char)tochar(lx % 95);
out[k] = (unsigned char)check1(out + body, 5);
k++;
}
if (n > 0)
memcpy(out + k, data, (size_t)n);
k += n;
k += check_chars(ct, out + body, k - body, out + k);
out[k++] = (unsigned char)eol;
return k;
}
static void send_packet(struct kermit *k, int seq, int type,
const unsigned char *data, int n)
{
int len = packet_bytes(k->obuf, k->npad, k->padc, k->eol, k->check,
k->force_check1, seq, type, data, n);
xfer_write(k->x, k->obuf, len);
}
/* the next good packet into k (1), or 0 on a timeout or a bad one
(garbage before its mark skipped; a mark in the middle starts over) */
static int read_packet(struct kermit *k, int wait)
{
long long deadline = xfer_now() + wait;
unsigned char *buf = k->pkt;
#define NEXT() (xfer_now() >= deadline ? -1 : xfer_read(k->x, (int)(deadline - xfer_now())))
int c = NEXT();
for (;;) {
while (c != MARK) {
if (c < 0)
return 0;
c = NEXT();
}
int n = 0, v, restart = 0;
int hdr[3];
for (int i = 0; i < 3 && !restart; i++) {
v = NEXT();
if (v < 0)
return 0;
if (v == MARK)
restart = 1;
else
hdr[i] = buf[n++] = (unsigned char)v;
}
if (restart) {
c = MARK;
continue;
}
int len = unchar(hdr[0]), pseq = unchar(hdr[1]), type = hdr[2], rest;
if (len == 0) {
/* extended: LENX1 LENX2 HCHECK */
int xx[3];
for (int i = 0; i < 3 && !restart; i++) {
v = NEXT();
if (v < 0)
return 0;
if (v == MARK)
restart = 1;
else
xx[i] = buf[n++] = (unsigned char)v;
}
if (restart) {
c = MARK;
continue;
}
if (check1(buf, 5) != xx[2])
return 0;
rest = unchar(xx[0]) * 95 + unchar(xx[1]);
} else {
if (len < 3)
return 0;
rest = len - 2;
}
if (rest > MAX_PACKET || rest < 0)
return 0;
int header_len = n;
for (int i = 0; i < rest && !restart; i++) {
v = NEXT();
if (v < 0)
return 0;
if (v == MARK)
restart = 1;
else
buf[n++] = (unsigned char)v;
}
if (restart) {
c = MARK;
continue;
}
int ct;
if (type == 'S' || type == 'I' || type == 'R' || k->force_check1)
ct = 1;
else if (type == 'Y' && pseq == 0 && k->last_sent_type == 'S')
ct = 1; /* (an S packet's ACK: type 1 too) */
else
ct = k->check;
if (rest < ct)
return 0;
int data_end = n - ct;
unsigned char want[3];
check_chars(ct, buf, data_end, want);
if (memcmp(buf + data_end, want, (size_t)ct) != 0) {
/* (an E or N packet sent before the check type changed) */
if ((type == 'N' || type == 'E') && ct != 1 && rest >= 1) {
unsigned char w1[3];
check_chars(1, buf, n - 1, w1);
if (buf[n - 1] == w1[0]) {
k->pseq = pseq;
k->ptype = type;
k->plen = n - 1 - header_len;
memmove(buf, buf + header_len, (size_t)k->plen);
return 1;
}
}
return 0;
}
k->pseq = pseq;
k->ptype = type;
k->plen = data_end - header_len;
memmove(buf, buf + header_len, (size_t)k->plen);
return 1;
}
#undef NEXT
}
/* ------------------------------------------------------------------ */
/* the data's encoding */
static void encode_byte(struct kermit *k, unsigned char *out, int *n, int v)
{
int b = v;
if (k->qbin && (b & 0x80)) {
out[(*n)++] = (unsigned char)k->qbin;
b &= 0x7f;
}
int b7 = b & 0x7f;
if (b7 < 32 || b7 == 127) {
out[(*n)++] = OUR_QCTL;
out[(*n)++] = (unsigned char)ctl(b);
} else if (b7 == OUR_QCTL || (k->qbin && b7 == k->qbin) ||
(k->rept && b7 == k->rept)) {
out[(*n)++] = OUR_QCTL;
out[(*n)++] = (unsigned char)b;
} else {
out[(*n)++] = (unsigned char)b;
}
}
/* src's len bytes encoded into at most max characters of out (*on of
them): how many bytes they hold */
static int encode(struct kermit *k, const unsigned char *src, int len,
unsigned char *out, int max, int *on)
{
int i = 0, n = 0;
while (i < len) {
int v = src[i], run = 1;
if (k->rept)
while (i + run < len && run < 94 && src[i + run] == src[i])
run++;
unsigned char unit[8];
int un = 0;
if (run >= 3) {
unit[un++] = (unsigned char)k->rept;
unit[un++] = (unsigned char)tochar(run);
encode_byte(k, unit, &un, v);
} else {
run = 1;
encode_byte(k, unit, &un, v);
}
if (n + un > max)
break;
memcpy(out + n, unit, (size_t)un);
n += un;
i += run;
}
*on = n;
return i;
}
/* a packet's data decoded: into the received file, else into text (up
to tmax bytes); the bytes it held */
static long long decode(struct kermit *k, const unsigned char *d, int dn,
char *text, int tmax)
{
unsigned char out[4096];
int on = 0, tn = 0;
long long total = 0;
int i = 0;
while (i < dn) {
int run = 1, c = d[i++];
if (k->rept && c == k->rept && i < dn) {
run = unchar(d[i++]);
if (i >= dn)
break;
c = d[i++];
}
int hi = 0;
if (k->qbin && c == k->qbin && i < dn) {
hi = 0x80;
c = d[i++];
}
if (c == k->their_qctl && i < dn) {
c = d[i++];
int c7 = c & 0x7f;
if (c7 >= 63 && c7 <= 95)
c = ctl(c);
}
c |= hi;
for (int r = 0; r < run; r++) {
if (text) {
if (tn < tmax - 1)
text[tn++] = (char)c;
} else {
out[on++] = (unsigned char)c;
if (on == (int)sizeof(out)) {
xfer_dst_write(k->x, out, on);
on = 0;
}
}
total++;
}
}
if (text)
text[tn] = '\0';
else if (on)
xfer_dst_write(k->x, out, on);
return total;
}
/* an E packet with why sent (if it can be), and the transfer failed */
static void kfail(struct kermit *k, const char *why)
{
unsigned char e[600];
int n;
encode(k, (const unsigned char *)why, (int)strlen(why), e, (int)sizeof(e), &n);
if (!xfer_is_cancelled(k->x))
send_packet(k, k->seq, 'E', e, n);
xfer_fail(k->x, "%s", why);
}
int kermit_cancel_bytes(dmc_xfer *x, char *out, int max)
{
struct kermit *k = (struct kermit *)x->proto;
int check = k ? k->check : 1, force1 = k ? k->force_check1 : 1;
int eol = k ? k->eol : CR, seq = k ? k->seq : 0;
unsigned char b[64];
int n = packet_bytes(b, 0, 0, eol, check, force1, seq, 'E',
(const unsigned char *)"cancelled", 9);
if (n > max)
n = max;
memcpy(out, b, (size_t)n);
return n;
}
/* ------------------------------------------------------------------ */
/* the S/Y exchange */
/* our Send-Init: MAXL, TIME, NPAD, PADC, EOL, QCTL, QBIN, CHKT, REPT,
CAPAS, WINDO, MAXLX1, MAXLX2 */
static int our_params(struct kermit *k, unsigned char *b)
{
int n = 0, t = TIMEOUT / 1000;
b[n++] = tochar(94);
b[n++] = (unsigned char)tochar(t < 1 ? 1 : t > 94 ? 94 : t);
b[n++] = tochar(0);
b[n++] = ctl(0);
b[n++] = tochar(CR);
b[n++] = OUR_QCTL;
b[n++] = k->seven_bit ? '&' : 'Y';
b[n++] = '3';
b[n++] = REPT;
b[n++] = tochar(CAP_LP | CAP_AT);
b[n++] = tochar(1);
b[n++] = tochar(OUR_LONG / 95);
b[n++] = tochar(OUR_LONG % 95);
return n;
}
static int is_prefix(int c)
{
return (c >= 33 && c <= 62) || (c >= 96 && c <= 126);
}
/* their parameters, agreed with ours */
static void agree(struct kermit *k, const unsigned char *d, int dn)
{
#define AT(i) ((i) < dn ? (int)d[i] : -1)
if (AT(0) > 32) {
int m = unchar(AT(0));
k->send_max = m < 10 ? 10 : m > 94 ? 94 : m;
}
k->npad = AT(2) > 32 ? unchar(AT(2)) : 0;
k->padc = AT(3) >= 0 ? ctl(AT(3)) : 0;
k->eol = AT(4) > 32 ? unchar(AT(4)) : CR;
k->their_qctl = AT(5) > 32 ? AT(5) : '#';
int our_qbin = k->seven_bit ? '&' : 'Y', their_qbin = AT(6);
if (their_qbin == 'Y' && our_qbin != 'Y')
k->qbin = our_qbin;
else if (is_prefix(their_qbin) && (our_qbin == 'Y' || our_qbin == their_qbin))
k->qbin = their_qbin;
else
k->qbin = 0;
int their_check = AT(7) >= '1' && AT(7) <= '3' ? AT(7) - '0' : 1;
k->check = their_check;
k->rept = AT(8) == REPT ? REPT : 0;
/* the capabilities (more bytes follow while the lowest bit is set) */
int i = 9, caps = 0;
if (AT(i) > 32) {
caps = unchar(AT(i));
while (AT(i) >= 0 && (unchar(AT(i)) & 1))
i++;
}
i++;
k->attributes = (caps & CAP_AT) != 0;
k->send_long = 0;
if (caps & CAP_LP) {
/* WINDO, then MAXLX1 MAXLX2 (none: 500) */
int x1 = AT(i + 1), x2 = AT(i + 2);
k->send_long = x1 > 32 || x2 > 32 ?
unchar(x1 > 32 ? x1 : 32) * 95 + unchar(x2 > 32 ? x2 : 32) : 500;
if (k->send_long < 95)
k->send_long = 0;
if (k->send_long > OUR_LONG)
k->send_long = OUR_LONG;
}
if (k->qbin && k->qbin == k->rept)
k->rept = 0;
#undef AT
}
/* room for data in a packet (an encoded byte is up to 5 characters) */
static int room(struct kermit *k)
{
return k->send_long > 0 ? k->send_long - 5 - k->check - 2 :
k->send_max - 2 - k->check;
}
static struct kermit *k_new(dmc_xfer *x)
{
struct kermit *k = (struct kermit *)calloc(1, sizeof(*k));
if (!k)
xfer_fail(x, "out of memory");
k->x = x;
k->send_max = 80;
k->eol = CR;
k->their_qctl = '#';
k->check = 1;
k->force_check1 = 1;
k->last_sent_type = ' ';
x->proto = k;
return k;
}
/* ------------------------------------------------------------------ */
/* sending */
/* a packet sent until its ACK comes (a NAK of the next one counts): the
ACK's data in k->ack */
static void exchange(struct kermit *k, int type, const unsigned char *data, int n)
{
int tries = 0;
k->last_sent_type = type;
for (;;) {
send_packet(k, k->seq, type, data, n);
while (read_packet(k, TIMEOUT)) {
if (k->ptype == 'E') {
char t[512];
decode(k, k->pkt, k->plen, t, (int)sizeof(t));
xfer_fail(k->x, "the receiver: %s", t);
}
if (k->ptype == 'Y' && k->pseq == k->seq) {
k->seq = (k->seq + 1) & 63;
memcpy(k->ack, k->pkt, (size_t)k->plen);
k->ack_len = k->plen;
return;
}
if (k->ptype == 'N' && k->pseq == ((k->seq + 1) & 63)) {
k->seq = (k->seq + 1) & 63;
k->ack_len = 0;
return;
}
if (k->ptype == 'N')
break;
/* (an old ACK, repeated: the next one waited for) */
}
if (++tries > MAX_RETRIES)
kfail(k, "too many retries");
xfer_error(k->x);
}
}
static void attr(unsigned char *a, int *n, int tag, const char *v)
{
int l = (int)strlen(v);
a[(*n)++] = (unsigned char)tag;
a[(*n)++] = (unsigned char)tochar(l);
memcpy(a + *n, v, (size_t)l);
*n += l;
}
/* seconds as an attribute's date in local time: yyyymmdd hh:mm:ss */
static void format_date(long long sec, char *out, int n)
{
time_t t = (time_t)sec;
struct tm *tm = localtime(&t);
if (!tm) {
out[0] = '\0';
return;
}
snprintf(out, n, "%04d%02d%02d %02d:%02d:%02d", tm->tm_year + 1900,
tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
}
/* "[yy]yymmdd[ hh:mm[:ss]]", local time: seconds, 0 when it isn't one */
static long long parse_date(const char *v)
{
while (*v == ' ')
v++;
int digits = 0;
while (isdigit((unsigned char)v[digits]))
digits++;
if (digits != 8 && digits != 6)
return 0;
struct tm tm;
memset(&tm, 0, sizeof(tm));
const char *d = v;
if (digits == 8) {
tm.tm_year = (d[0] - '0') * 1000 + (d[1] - '0') * 100 +
(d[2] - '0') * 10 + (d[3] - '0') - 1900;
d += 4;
} else {
int yy = (d[0] - '0') * 10 + (d[1] - '0');
tm.tm_year = yy < 70 ? yy + 100 : yy;
d += 2;
}
tm.tm_mon = (d[0] - '0') * 10 + (d[1] - '0') - 1;
tm.tm_mday = (d[2] - '0') * 10 + (d[3] - '0');
const char *p = v + digits;
while (*p == ' ' || *p == '\t')
p++;
int h = 0, m = 0, s = 0;
if (p != v + digits && sscanf(p, "%d:%d:%d", &h, &m, &s) < 2) {
h = m = s = 0;
}
tm.tm_hour = h;
tm.tm_min = m;
tm.tm_sec = s;
tm.tm_isdst = -1;
time_t t = mktime(&tm);
return t == (time_t)-1 ? 0 : (long long)t;
}
/* a file sent: F, its attributes if agreed (A), D packets, Z (the file
skipped if the receiver refuses or stops it) */
static void send_file(struct kermit *k, const struct xfer_file *f)
{
dmc_xfer *x = k->x;
/* (the encoded packet's and the file's: in x->heap, freed at the end) */
unsigned char *enc = (unsigned char *)x->heap, *buf = enc + OUR_LONG + 64;
int n;
xfer_file_start(x, f->name, f->size);
encode(k, (const unsigned char *)f->name, (int)strlen(f->name), enc,
OUR_LONG, &n);
exchange(k, 'F', enc, n);
if (k->attributes) {
unsigned char a[200];
int an = 0;
char v[64];
attr(a, &an, '"', "B8"); /* binary, 8-bit */
if (f->size >= 0) {
snprintf(v, sizeof(v), "%lld", (f->size + 1023) / 1024);
attr(a, &an, '!', v);
snprintf(v, sizeof(v), "%lld", f->size);
attr(a, &an, '1', v);
}
if (f->mtime > 0) {
format_date(f->mtime, v, sizeof(v));
if (v[0])
attr(a, &an, '#', v);
}
exchange(k, 'A', a, an);
if (k->ack_len && k->ack[0] == 'N') {
/* refused: the file skipped */
exchange(k, 'Z', (const unsigned char *)"D", 1);
return;
}
}
xfer_open(x, f);
int have = 0, eof = 0;
long long sent = 0;
for (;;) {
while (!eof && have < OUR_LONG) {
int r = xfer_src_read(x, buf + have, OUR_LONG - have);
if (r <= 0)
eof = 1;
else
have += r;
}
if (!have)
break;
int used = encode(k, buf, have, enc, room(k), &n);
exchange(k, 'D', enc, n);
memmove(buf, buf + used, (size_t)(have - used));
have -= used;
sent += used;
xfer_bytes(x, sent);
if (k->ack_len && (k->ack[0] == 'X' || k->ack[0] == 'Z')) {
/* the receiver wants no more of this file (or of any) */
int all = k->ack[0] == 'Z';
exchange(k, 'Z', (const unsigned char *)"D", 1);
xfer_close(x);
if (all)
xfer_cancelled(x, "cancelled by the receiver");
return;
}
}
xfer_close(x);
exchange(k, 'Z', NULL, 0);
xfer_file_done(x);
}
void kermit_send(dmc_xfer *x)
{
struct kermit *k = k_new(x);
unsigned char p[32];
x->heap = malloc(OUR_LONG + 64 + OUR_LONG);
if (!x->heap)
xfer_fail(x, "out of memory");
k->seq = 0;
k->force_check1 = 1;
exchange(k, 'S', p, our_params(k, p));
agree(k, k->ack, k->ack_len);
k->force_check1 = 0;
for (int i = 0; i < x->nfiles; i++)
send_file(k, &x->files[i]);
exchange(k, 'B', NULL, 0);
}
/* ------------------------------------------------------------------ */
/* receiving */
static void ack(struct kermit *k, int seq, const unsigned char *data, int n)
{
k->last_sent_type = 'Y';
send_packet(k, seq, 'Y', data, n);
}
static void nak(struct kermit *k, int seq)
{
k->last_sent_type = 'N';
send_packet(k, seq, 'N', NULL, 0);
}
void kermit_receive(dmc_xfer *x)
{
struct kermit *k = k_new(x);
int tries = 0;
char text[600];
k->seq = 0;
k->force_check1 = 1;
/* waiting for the S (a NAK now and then, for a sender waiting) */
for (;;) {
int got = read_packet(k, TIMEOUT);
if (got && k->ptype == 'S')
break;
if (got && k->ptype == 'E') {
decode(k, k->pkt, k->plen, text, (int)sizeof(text));
xfer_fail(x, "the sender: %s", text);
}
if (++tries > MAX_RETRIES)
xfer_fail(x, "the sender didn't start");
nak(k, 0);
}
agree(k, k->pkt, k->plen);
unsigned char ours[32];
int on = our_params(k, ours);
int init_seq = k->pseq;
ack(k, init_seq, ours, on);
/* our last ACK, for when it is lost */
int last_seq = init_seq;
memcpy(k->ack, ours, (size_t)on);
k->ack_len = on;
k->force_check1 = 0;
k->seq = (init_seq + 1) & 63;
long long mtime = 0, got_bytes = 0;
tries = 0;
unsigned char reply[XFER_NAME * 2 + 16];
for (;;) {
int got = read_packet(k, TIMEOUT);
if (!got || k->pseq != k->seq) {
if (got && k->pseq == last_seq) {
/* our ACK lost: sent again */
if (k->ptype == 'S')
k->force_check1 = 1;
ack(k, last_seq, k->ack, k->ack_len);
k->force_check1 = 0;
} else if (got && k->ptype == 'E') {
decode(k, k->pkt, k->plen, text, (int)sizeof(text));
xfer_fail(x, "the sender: %s", text);
} else {
nak(k, k->seq);
}
if (++tries > MAX_RETRIES)
kfail(k, "too many retries");
xfer_error(x);
continue;
}
tries = 0;
int rn = 0;
switch (k->ptype) {
case 'F': {
decode(k, k->pkt, k->plen, text, XFER_NAME);
/* (a name sent "converted", all capitals, as C-Kermit
does: back in lower case) */
int letters = 0, lower = 0;
for (char *p = text; *p; p++) {
if (isalpha((unsigned char)*p))
letters = 1;
if (islower((unsigned char)*p))
lower = 1;
}
if (letters && !lower)
for (char *p = text; *p; p++)
*p = (char)tolower((unsigned char)*p);
xfer_create(x, text);
mtime = 0;
got_bytes = 0;
xfer_file_start(x, x->dst_name, -1);
encode(k, (const unsigned char *)x->dst_name,
(int)strlen(x->dst_name), reply, (int)sizeof(reply), &rn);
break;
}
case 'A': {
const unsigned char *a = k->pkt;
int i = 0;
while (i + 1 < k->plen) {
int tag = a[i], n = unchar(a[i + 1]);
if (n < 0 || i + 2 + n > k->plen)
break;
char v[128];
snprintf(v, sizeof(v), "%.*s", n, (const char *)a + i + 2);
if (tag == '1') {
xfer_size(x, strtoll(v, NULL, 10));
} else if (tag == '!') {
if (xfer_size_now(x) < 0)
xfer_size(x, strtoll(v, NULL, 10) * 1024);
} else if (tag == '#') {
mtime = parse_date(v);
}
i += 2 + n;
}
reply[rn++] = 'Y';
break;
}
case 'D':
if (!x->dst)
kfail(k, "data before a file's name");
got_bytes += decode(k, k->pkt, k->plen, NULL, 0);
xfer_bytes(x, got_bytes);
/* the user's skip: X in the ACK (the sender ends the
file with Z D, and the file is dropped) */
if (xfer_skip_wanted(x))
reply[rn++] = 'X';
break;
case 'Z':
if (x->dst) {
if (k->plen && k->pkt[0] == 'D') {
xfer_abandon(x);
} else {
xfer_done(x, mtime);
xfer_file_done(x);
}
}
break;
case 'B':
ack(k, k->pseq, NULL, 0);
return;
case 'E':
decode(k, k->pkt, k->plen, text, (int)sizeof(text));
xfer_fail(x, "the sender: %s", text);
case 'X':
/* text to show (a server's): taken like a file with no
name */
break;
default: {
char why[64];
snprintf(why, sizeof(why), "unexpected %c packet", k->ptype);
kfail(k, why);
}
}
int this_seq = k->pseq;
ack(k, this_seq, reply, rn);
last_seq = this_seq;
memcpy(k->ack, reply, (size_t)rn);
k->ack_len = rn;
k->seq = (k->seq + 1) & 63;
}
}
-476
View File
@@ -1,476 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* xfer_xy.c - XMODEM (128-byte blocks, a checksum or CRC; 1K blocks) and
* YMODEM (1K blocks, CRC, a batch of files each named and
* sized in block 0), both ways. A bad block is asked for
* again (NAK) up to MAX_ERRORS times; CAN CAN from the other
* side ends it.
*
* YMODEM-G: the receiver asks with G, and the sender sends
* the blocks with no wait for an ACK (for a line that
* corrects its errors, as a modem's V.42). An error ends
* the transfer, as no block can be sent again. The EOT of
* each file is still acknowledged. A sender asked with C
* does plain YMODEM.
*/
#include <stdlib.h>
#include <string.h>
#include "xfer.h"
#define SOH 0x01
#define STX 0x02
#define EOT 0x04
#define ACK 0x06
#define NAK 0x15
#define CAN 0x18
#define SUB 0x1a
#define C 'C'
#define G 'G'
#define MAX_ERRORS 10
#define TIMEOUT 10000
/* a block as it came */
struct block {
int number; /* -1: none (a timeout, a bad one, EOT) */
int size;
unsigned char data[1024];
};
/* the receiver's state */
struct rx {
int crc; /* CRC, else the checksum */
int eot; /* the sender's EOT came */
int bad; /* a damaged block came */
int g; /* YMODEM-G: no ACKs, no repeats */
};
/* YMODEM-G's end on an error: no block can come again */
static void g_fail(dmc_xfer *x)
{
xfer_write(x, "\x18\x18\x18\x18\x18", 5);
xfer_fail(x, "an error on the line (YMODEM-G cannot send a block again)");
}
static int sum8(const unsigned char *p, int n)
{
int s = 0;
for (int i = 0; i < n; i++)
s += p[i];
return s & 0xff;
}
/* a block within wait ms, its check checked; number -1 for a timeout, a
bad block (the rest of it let go by) or EOT (r->eot) */
static void read_block(dmc_xfer *x, struct rx *r, struct block *b, int use_crc,
int wait)
{
r->eot = r->bad = 0;
b->number = -1;
/* (what isn't a block's start let go by: messages, line noise) */
long long deadline = xfer_now() + wait;
int size = 0;
while (!size) {
long long left = deadline - xfer_now();
if (left <= 0)
return;
int c = xfer_read(x, (int)left);
switch (c) {
case -1: return;
case SOH: size = 128; break;
case STX: size = 1024; break;
case EOT: r->eot = 1; return;
case CAN:
if (xfer_read(x, 1000) == CAN)
xfer_cancelled(x, "cancelled by the sender");
break;
}
}
int n = xfer_read(x, 1000), nn = xfer_read(x, 1000);
if (n < 0 || nn < 0)
return;
for (int i = 0; i < size; i++) {
int c = xfer_read(x, 1000);
if (c < 0)
return;
b->data[i] = (unsigned char)c;
}
int ok;
if (use_crc) {
int hi = xfer_read(x, 1000), lo = xfer_read(x, 1000);
ok = hi >= 0 && lo >= 0 &&
xfer_crc16(0, b->data, size) == (unsigned)((hi << 8) | lo);
} else {
int s = xfer_read(x, 1000);
ok = s >= 0 && sum8(b->data, size) == s;
}
if (!ok || (n ^ nn) != 0xff) {
while (xfer_read(x, 200) >= 0)
;
r->bad = 1;
return;
}
b->number = n;
b->size = size;
}
/* the first block, asked for with C (CRC) and, for XMODEM, NAK (a
checksum) when C isn't answered */
static void start_and_read(dmc_xfer *x, struct rx *r, struct block *b, int ymodem,
int tries)
{
int crc = 1;
r->bad = 0;
for (int attempt = 0; attempt < tries; attempt++) {
if (attempt == 4 && !ymodem)
crc = 0;
/* (a damaged block 0 asked for again with NAK: a C could be
taken for its ACK and a request for the data) */
xfer_put(x, r->g ? G : crc && !(ymodem && r->bad) ? C : NAK);
read_block(x, r, b, crc, 3000);
if (b->number >= 0) {
r->crc = crc;
return;
}
}
b->number = -1;
}
/* a file's blocks into the received file, up to size bytes if known;
held (XMODEM): the last block kept back, for its padding to come off */
static void receive_file(dmc_xfer *x, struct rx *r, long long size, int ymodem,
unsigned char *held, int *held_n)
{
int expect = 1, errors = 0, eots = 0, have = 0;
long long written = 0;
struct block bb, *b = &bb;
if (held)
*held_n = -1;
if (!ymodem) {
start_and_read(x, r, b, 0, 10);
have = b->number >= 0;
}
for (;;) {
if (!have) {
read_block(x, r, b, r->crc, TIMEOUT);
if (b->number < 0) {
if (r->eot) {
/* YMODEM: the first EOT answered NAK, the
second ACK (to be sure it was one);
YMODEM-G: ACK */
eots++;
if (ymodem && eots == 1 && !r->g) {
xfer_put(x, NAK);
continue;
}
xfer_put(x, ACK);
break;
}
if (r->g)
g_fail(x);
if (++errors > MAX_ERRORS)
xfer_fail(x, "too many errors on the line");
xfer_error(x);
xfer_put(x, NAK);
continue;
}
}
have = 0;
if (b->number == (expect & 0xff)) {
int len = b->size;
if (size >= 0 && written + len > size)
len = size - written > 0 ? (int)(size - written) : 0;
if (held) {
if (*held_n >= 0)
xfer_dst_write(x, held, *held_n);
memcpy(held, b->data, (size_t)len);
*held_n = len;
} else {
xfer_dst_write(x, b->data, len);
}
written += len;
expect++;
errors = 0;
if (!r->g)
xfer_put(x, ACK);
xfer_bytes(x, written);
} else if (b->number == ((expect - 1) & 0xff)) {
/* a repeat of one already had (our ACK lost) */
xfer_put(x, ACK);
} else {
xfer_write(x, "\x18\x18\x18", 3);
xfer_fail(x, "blocks out of order");
}
}
}
void xy_receive_x(dmc_xfer *x)
{
struct rx r = { 1, 0, 0, 0 };
unsigned char held[1024];
int held_n = -1;
xfer_create(x, x->xname);
xfer_file_start(x, x->dst_name, -1);
receive_file(x, &r, -1, 0, held, &held_n);
/* the last block, its padding off */
if (held_n > 0) {
while (held_n > 0 && held[held_n - 1] == SUB)
held_n--;
xfer_dst_write(x, held, held_n);
}
xfer_done(x, 0);
xfer_file_done(x);
}
void xy_receive_y(dmc_xfer *x, int g)
{
struct rx r = { 1, 0, 0, g };
struct block bb0, *b0 = &bb0;
int got = 0;
for (;;) {
/* block 0: the file's name and size, or an empty one (the end) */
start_and_read(x, &r, b0, 1, g && got ? 2 : 10);
/* (lrzsz's sb in YMODEM-G ends with no empty block 0) */
if (b0->number < 0 && g && got)
return;
if (b0->number < 0)
xfer_fail(x, "the sender didn't start");
if (b0->number != 0)
xfer_fail(x, "no YMODEM header block");
if (b0->data[0] == 0) {
xfer_put(x, ACK);
return;
}
char name[XFER_NAME], meta[1100];
int nul = 0;
while (nul < b0->size && b0->data[nul])
nul++;
snprintf(name, sizeof(name), "%.*s", nul, (const char *)b0->data);
int m = 0;
for (int i = nul + 1; i < b0->size && b0->data[i] && m < (int)sizeof(meta) - 1; i++)
meta[m++] = (char)b0->data[i];
meta[m] = '\0';
long long size = -1, mtime = 0;
char *end;
long long v = strtoll(meta, &end, 10);
if (end != meta)
size = v;
if (*end == ' ')
mtime = strtoll(end + 1, NULL, 8);
/* (YMODEM-G: block 0 not acknowledged, G asks for the data) */
if (!g)
xfer_put(x, ACK);
xfer_create(x, name);
xfer_file_start(x, x->dst_name, size);
xfer_put(x, g ? G : C);
receive_file(x, &r, size, 1, NULL, NULL);
xfer_done(x, mtime);
xfer_file_done(x);
got++;
}
}
/* ------------------------------------------------------------------ */
/* sending */
/* C (CRC: 1) or NAK (a checksum: 0) from the receiver, G (2) when g;
-1 for none */
static int wait_for_start(dmc_xfer *x, int g)
{
long long end = xfer_now() + 60000;
while (xfer_now() < end) {
switch (xfer_read(x, TIMEOUT)) {
case G:
if (g)
return 2;
break;
case C: return 1;
case NAK: return 0;
case CAN:
if (xfer_read(x, 1000) == CAN)
xfer_cancelled(x, "cancelled by the receiver");
break;
}
}
return -1;
}
/* the receiver's answer: ACK, or NAK (also for a timeout); C an ACK for
block 0 when allow_c (receivers that ask for the data at once) */
static int answer(dmc_xfer *x, int allow_c, int wait)
{
long long deadline = xfer_now() + wait;
for (;;) {
long long left = deadline - xfer_now();
if (left <= 0)
return NAK;
switch (xfer_read(x, (int)left)) {
case -1: return NAK;
case ACK: return ACK;
case NAK: return NAK;
case C:
if (allow_c)
return ACK;
break;
case CAN:
if (xfer_read(x, 1000) == CAN)
xfer_cancelled(x, "cancelled by the receiver");
break;
}
}
}
/* block n's bytes into out: SOH or STX, its number and complement, data,
its CRC-16 or checksum: their length */
static int block_bytes(unsigned char *out, int n, const unsigned char *data,
int size, int use_crc)
{
int k = 0;
out[k++] = size == 1024 ? STX : SOH;
out[k++] = (unsigned char)(n & 0xff);
out[k++] = (unsigned char)(0xff - (n & 0xff));
memcpy(out + k, data, (size_t)size);
k += size;
if (use_crc) {
unsigned c = xfer_crc16(0, data, size);
out[k++] = (unsigned char)(c >> 8);
out[k++] = (unsigned char)(c & 0xff);
} else {
out[k++] = (unsigned char)sum8(data, size);
}
return k;
}
/* a block sent until it's acknowledged */
static void send_block(dmc_xfer *x, int n, const unsigned char *data, int size,
int use_crc)
{
unsigned char bytes[1024 + 5];
int len = block_bytes(bytes, n, data, size, use_crc);
int errors = 0;
for (;;) {
xfer_write(x, bytes, len);
if (answer(x, n == 0, TIMEOUT) == ACK)
return;
if (++errors > MAX_ERRORS)
xfer_fail(x, "too many errors on the line");
xfer_error(x);
}
}
/* YMODEM-G: the receiver's CAN CAN, if it sent them (no wait) */
static void g_check(dmc_xfer *x)
{
while (xfer_available(x)) {
int c = xfer_read(x, 0);
if (c == CAN && xfer_read(x, 1000) == CAN)
xfer_cancelled(x, "cancelled by the receiver");
}
}
/* the open file's data in blocks of block_size (a short last one in 128,
padded with SUB), then EOT until acknowledged; g: the blocks with no
wait for an ACK (YMODEM-G) */
static void send_data(dmc_xfer *x, int block_size, int use_crc, int g)
{
unsigned char buf[1024];
int n = 1;
long long sent = 0;
for (;;) {
int len = 0;
while (len < block_size) {
int r = xfer_src_read(x, buf + len, block_size - len);
if (r <= 0)
break;
len += r;
}
if (!len)
break;
int size = len <= 128 ? 128 : block_size;
memset(buf + len, SUB, (size_t)(size - len));
if (g) {
unsigned char bytes[1024 + 5];
xfer_write(x, bytes, block_bytes(bytes, n, buf, size, 1));
g_check(x);
} else {
send_block(x, n, buf, size, use_crc);
}
sent += len;
n++;
xfer_bytes(x, sent);
if (len < block_size)
break;
}
/* the end: EOT until it's answered ACK (YMODEM answers the first NAK) */
for (int tries = 0;; tries++) {
xfer_put(x, EOT);
if (answer(x, 0, TIMEOUT) == ACK)
return;
if (tries >= MAX_ERRORS)
xfer_fail(x, "the end not acknowledged");
}
}
void xy_send_x(dmc_xfer *x, int one_k)
{
const struct xfer_file *f = &x->files[0];
int use_crc = wait_for_start(x, 0);
if (use_crc < 0)
xfer_fail(x, "the receiver didn't start");
xfer_file_start(x, f->name, f->size);
xfer_open(x, f);
send_data(x, one_k ? 1024 : 128, use_crc, 0);
xfer_close(x);
xfer_file_done(x);
}
void xy_send_y(dmc_xfer *x, int g)
{
unsigned char block0[1024];
for (int i = 0; i < x->nfiles; i++) {
const struct xfer_file *f = &x->files[i];
/* (asked with C: plain YMODEM, also for YMODEM-G) */
int start = wait_for_start(x, g);
if (start < 1)
xfer_fail(x, "the receiver didn't start");
int streaming = start == 2;
memset(block0, 0, sizeof(block0));
int nl = (int)strlen(f->name);
if (nl > 900)
nl = 900;
memcpy(block0, f->name, (size_t)nl);
char meta[64];
int ml = snprintf(meta, sizeof(meta), "%lld %llo 0",
f->size >= 0 ? f->size : 0LL,
(unsigned long long)(f->mtime > 0 ? f->mtime : 0));
memcpy(block0 + nl + 1, meta, (size_t)ml);
int size0 = nl + 1 + ml > 128 ? 1024 : 128;
if (streaming) {
unsigned char bytes[1024 + 5];
xfer_write(x, bytes, block_bytes(bytes, 0, block0, size0, 1));
} else {
send_block(x, 0, block0, size0, 1);
}
xfer_file_start(x, f->name, f->size);
if (wait_for_start(x, g) != (streaming ? 2 : 1))
xfer_fail(x, "the receiver didn't ask for the data");
xfer_open(x, f);
send_data(x, 1024, 1, streaming);
xfer_close(x);
xfer_file_done(x);
}
/* the batch over: an empty block 0 */
if (wait_for_start(x, g) < 1)
xfer_fail(x, "the receiver didn't ask for the end");
/* (rb exits as it takes it: its ACK can be lost with it) */
unsigned char empty[128], bytes[133];
memset(empty, 0, sizeof(empty));
int len = block_bytes(bytes, 0, empty, 128, 1);
for (int attempt = 0; attempt < 3; attempt++) {
xfer_write(x, bytes, len);
if (answer(x, 1, 2000) == ACK)
return;
}
}
-1149
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
-46
View File
@@ -1,46 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* zstd_codec.h - Zstandard (RFC 8878), whole frames, in plain C: the
* encoder makes one frame of a chunk (single segment, its
* content size and checksum in it, no dictionary), as
* ZMODEM with zstd sends a file (docs/zmodem-zstd.md of
* D-Modem); the decoder takes any frame up to its limit.
* A port of D-Modem's link/zstd_codec.cpp (and of the
* app's Zstd.kt): a hash chain over the chunk with a lazy
* match, the repeat offsets, literals raw, RLE or Huffman
* coded, each sequence table the predefined or a new one.
* Named so that it does not hide the system's <zstd.h>.
*/
#ifndef DMC_ZSTD_CODEC_H
#define DMC_ZSTD_CODEC_H
#include <stddef.h>
#include <stdint.h>
#define ZC_MAGIC 0xFD2FB528u
/* data[0..n) as one frame (malloc'd, its length in *out_n); NULL when
memory ran out */
unsigned char *zc_encode(const unsigned char *data, int n, int *out_n);
/* the content of the frame frame[0..n) (all of it, no more), malloc'd,
its length in *out_n (a frame of no content gives a block of 1 byte
that is not part of it); NULL if it is not a frame, has a dictionary,
a window or content over max, bad data or a bad checksum (why, if
not NULL, says which) */
unsigned char *zc_decode(const unsigned char *frame, int n, int max, int *out_n,
const char **why);
/* the length of the frame at the start of b[0..n) from its headers (RFC
8878 3.1.1.1 and 3.1.1.2): 0 while not all of it is there, -1 if it is
not a frame that ZMODEM with zstd takes (a frame of no more than max
bytes of content, without a dictionary, with its content size and
checksum) */
int zc_frame_len(const unsigned char *b, int n, int max);
/* XXH64 (seed 0), Zstandard's content checksum */
uint64_t zc_xxh64(const unsigned char *b, size_t n);
#endif
-14
View File
@@ -1,14 +0,0 @@
add_executable(dmodemctl_test dmodemctl_test.c)
target_link_libraries(dmodemctl_test PRIVATE dmodemctl)
target_include_directories(dmodemctl_test PRIVATE ../src)
add_test(NAME dmodemctl COMMAND dmodemctl_test ${CMAKE_CURRENT_SOURCE_DIR})
# the file transfers: both ways in memory, and against lrzsz and C-Kermit
# when they are installed (a pseudo-terminal: POSIX only)
if(UNIX)
add_executable(xfer_test xfer_test.c)
target_link_libraries(xfer_test PRIVATE dmodemctl)
target_include_directories(xfer_test PRIVATE ../src)
add_test(NAME xfer COMMAND xfer_test)
set_tests_properties(xfer PROPERTIES TIMEOUT 600)
endif()
-5
View File
@@ -1,5 +0,0 @@
AT#UD
DIAG <2A4D3263 0=10>
DIAG <2A4D3263 1=0>
DIAG <2A4D3263 60=1>
OK
File diff suppressed because it is too large. Load diff
-255
View File
@@ -1,255 +0,0 @@
AT!M
model 1 73
setting country pick B5 B5 +GCI=%s Line Country +GCI: the line's settings and tones
choice 02 algeria ALGERIA
choice 07 argentina ARGENTINA
choice 09 australia AUSTRALIA
choice 0A austria AUSTRIA
choice 0C bahrein BAHREIN
choice 0F belgium BELGIUM
choice 16 brazil BRAZIL
choice 1A brunei BRUNEI
choice 1B bulgaria BULGARIA
choice 20 canada CANADA
choice 25 chile CHILE
choice 26 china CHINA
choice 100 ctr21europe CTR21EUROPE
choice 2D cyprus CYPRUS
choice 2E czech-republic CZECH_REPUBLIC
choice 31 denmark DENMARK
choice 36 egypt EGYPT
choice 101 estonia ESTONIA
choice 3C finland FINLAND
choice 3D france FRANCE
choice 42 germany GERMANY
choice 46 greece GREECE
choice 50 hong-kong HONG_KONG
choice 51 hungary HUNGARY
choice 52 iceland ICELAND
choice 53 india INDIA
choice 54 indonesia INDONESIA
choice 57 ireland IRELAND
choice 58 israel ISRAEL
choice 59 italy ITALY
choice 00 japan JAPAN
choice 5E jordan JORDAN
choice 61 korea KOREA
choice 62 kuwait KUWAIT
choice 103 latvia LATVIA
choice 64 lebanon LEBANON
choice 104 lithuania LITHUANIA
choice 69 luxembourg LUXEMBOURG
choice 6C malaysia MALAYSIA
choice 70 malta MALTA
choice 73 mexico MEXICO
choice 77 morocco MOROCCO
choice 7B netherlands NETHERLANDS
choice 7E new-zealand NEW_ZEALAND
choice 82 norway NORWAY
choice 83 oman OMAN
choice 84 pakistan PAKISTAN
choice 88 peru PERU
choice 89 philippines PHILIPPINES
choice 8A poland POLAND
choice 8B portugal PORTUGAL
choice 8E romania ROMANIA
choice B8 russia RUSSIA
choice 98 saudiarabia SAUDIARABIA
choice 9C singapore SINGAPORE
choice C5 slovakia SLOVAKIA
choice C6 slovenia SLOVENIA
choice 9F southafrica SOUTHAFRICA
choice 107 southkorea SOUTHKOREA
choice A0 spain SPAIN
choice A1 srilanka SRILANKA
choice A5 sweden SWEDEN
choice A6 switzerland SWITZERLAND
choice 108 taiwan TAIWAN
choice A9 thailand THAILAND
choice AD tunisia TUNISIA
choice AE turkey TURKEY
choice B3 uae UAE
choice B4 uk UK
choice B7 uruguay URUGUAY
choice B5 usa USA
choice BC vietnam VIETNAM
setting dial-mode pick T T %s Line Dialling T tone, P pulse
choice T tone Tone
choice P pulse Pulse
setting pulse-ratio pick 0 0 &P%s Line Pulse make/break &P (S28): kept; the country sets the pulses
choice 0 0 &P0
choice 1 1 &P1
choice 2 2 &P2
choice 3 3 &P3
setting line-type pick 0 0 &L%s Line Line type &L (S47): a dialled line, or a leased one
choice 0 dialup Dial-up
choice 1 leased-2wire Leased 2-wire
choice 2 leased-4wire Leased 4-wire
setting call-progress pick 4 4 X%s Line Result codes and tones X (S56): CONNECT's rate, dial tone, busy
choice 0 basic X0 basic
choice 1 rate X1 rate
choice 2 dial-tone X2 dial tone
choice 3 busy X3 busy
choice 4 full X4 all
setting modulation pick 92 92 +MS=%s Modulation Modulation +MS: the highest modulation tried
choice 21 v21 V21
choice 22 v22 V22
choice 23 v23 V23
choice 26 v26 V26
choice 126 v26ter V26ter
choice 226 v26bis V26bis
choice 27 v27ter V27ter
choice 29 v29 V29
choice 229 v29fastpos V29FastPOS
choice 122 v22bis V22bis
choice 32 v32 V32
choice 132 v32bis V32bis
choice 232 v32terbo V32terbo
choice 168 hst HST
choice 128 vfc VFC
choice 61 v61 V61
choice 33 v33 V33
choice 34 v34 V34
choice 103 bell103 Bell103
choice 18 v18 V18
choice 45 baudot Baudot
choice 110 edt EDT
choice 118 dtmf DTMF
choice 121 v21text V21text
choice 123 v23text V23text
choice 203 bell103text Bell103text
choice 5 contactid ContactID
choice 12 sms SMS
choice 212 bell212 Bell212
choice 201 bell201 Bell201
choice 202 bell202 Bell202
choice 208 bell208 Bell208
choice 56 k56flex K56Flex
choice 90 v90 V90
choice 91 v91 V91
choice 92 v92 V92
choice 150 vcvm VCVM
choice 200 vwb VWB
choice 255 pep PEP
choice 64 clear CLEAR
setting automode pick 1 1 +MS=,%s Modulation Automode +MS, N: fall back to slower modulations
choice 0 off Off
choice 1 on On
setting min-rate number 300 300 300 56000 +MS=,,%s Modulation Lowest rate (bit/s) +MS: hang up rather than go below it
setting max-rate number 56000 56000 300 56000 +MS=,,,%s Modulation Highest rate (bit/s) +MS: the fastest the modem tries
setting error-control pick 3 3 \N%s Error control Error correction \N (S103): V.42, MNP or none
choice 0 normal Normal (none)
choice 1 direct Direct (none)
choice 2 reliable Reliable
choice 3 auto-reliable Auto-reliable
choice 4 lapm V.42 LAPM only
choice 5 mnp MNP only
setting compression pick 3 3 %%C%s Error control Compression %C (S104): needs error correction
choice 0 off None
choice 1 mnp5 MNP 5
choice 2 v42bis-v44 V.42bis or V.44
choice 3 auto Either
setting mnp-block pick 3 3 \A%s Error control MNP block size \A (S105): MNP's longest block
choice 0 64 64 octets
choice 1 128 128 octets
choice 2 192 192 octets
choice 3 256 256 octets
setting line-quality pick 0 0 %%E%s Error control Line quality monitor %E (S39): kept
choice 0 0 %E0
choice 1 1 %E1
choice 2 2 %E2
setting echo pick 1 1 E%s Terminal Command echo E (S13): the modem echoes what you type
choice 0 off Off
choice 1 on On
setting quiet pick 0 0 Q%s Terminal Result codes Q (S14): OK, CONNECT and the others shown or not
choice 0 shown Shown
choice 1 hidden Hidden
setting verbose pick 1 1 V%s Terminal Result code form V (S15): words or numbers
choice 0 numeric Numbers
choice 1 words Words
setting connect-lines number 0 0 0 7 &A%s Terminal Lines before CONNECT &A (S70): 1 modulation, 2 protocol, 4 rate
setting connect-protocol pick 0 0 \V%s Terminal Protocol in CONNECT \V (S106): CONNECT 33600/LAPM
choice 0 off Off
choice 1 on On
choice 2 on2 On (\V2)
setting connect-rate pick 0 0 &E%s Terminal CONNECT rate source &E (S71): kept
choice 0 0 &E0
choice 1 1 &E1
setting dcd pick 0 0 &C%s Terminal DCD &C (S60): kept
choice 0 always-on Always on
choice 1 carrier Follows carrier
setting flow-control pick 0 0 &H%s Terminal Flow control &H (S62): as #UD reports it
choice 0 none None
choice 1 rts-cts RTS/CTS
choice 2 xon-xoff XON/XOFF
choice 3 both Both
setting y number 0 0 0 3 Y%s Terminal Y setting Y (S161): kept
setting speaker pick 1 1 M%s Speaker Speaker M (S29)
choice 0 off Off
choice 1 until-connect On until CONNECT
choice 2 always Always on
choice 3 answer-only On after dialling until CONNECT
setting volume pick 3 3 L%s Speaker Speaker volume L (S30)
choice 0 lowest Lowest
choice 1 low Low
choice 2 medium Medium
choice 3 high High
setting mode pick 0 0 +FCLASS=%s Fax and voice Mode +FCLASS: data, fax or voice
choice 0 data Data
choice 1 fax1 Fax class 1
choice 1.0 fax1.0 Fax class 1.0
choice 8 voice Voice
setting caller-id pick 0 0 #CID=%s Fax and voice Caller ID #CID: shown after the first RING
choice 0 off Off
choice 1 formatted Formatted
choice 2 raw Unformatted
setting modem-on-hold pick 0 0 +PMH=%s Fax and voice V.92 modem-on-hold +PMH: granted or refused
choice 0 on Granted
choice 1 off Refused
setting modem-on-hold-time number 5 5 0 13 +PMHT=%s Fax and voice Modem-on-hold time code +PMHT: the longest hold granted (V.92's code)
setting auto-answer number 0 0 0 255 S0=%s Timers Rings before answering S0: 0 never answers by itself
setting dial-tone-wait number 2 2 0 255 S6=%s Timers Dial tone wait (s) S6: seconds to wait for a dial tone
setting carrier-wait number 60 60 0 255 S7=%s Timers Carrier wait (s) S7: seconds to wait for the other modem
setting comma-pause number 2 2 0 255 S8=%s Timers Comma pause (s) S8: a ',' in the number waits this long
setting carrier-detect-time number 6 6 0 255 S9=%s Timers Carrier detect (0.1 s) S9: the carrier must last this long
setting carrier-loss-time number 7 7 0 255 S10=%s Timers Carrier loss (0.1 s) S10: hang up after the carrier is gone this long
setting dtmf-duration number 100 100 0 255 S11=%s Timers DTMF tone length (ms) S11: each digit's tone and the gap after it
setting flash-time number 50 50 0 255 S24=%s Timers Hook flash (10 ms) S24: how long a hook flash lasts
setting answer-delay number 2 2 0 255 S92=%s Timers Answer delay (s) S92: from ATA to the answer tone
setting test-timer number 0 0 0 255 S18=%s Timers Test timer (s) S18: how long an AT&T test runs, 0 until AT&T0
setting simulated-carrier number 0 0 0 1 S48=%s Timers Simulated carrier (V.13) S48: 1 sends V.13's simulated carrier
setting fast-connect number 0 0 0 3 S49=%s Timers Fast connect (bits) S49: 1 the short V.22 handshake, 2 with HDLC flags
setting fast-answer-tone number 0 0 0 255 S50=%s Timers Fast answer tone (10 ms) S50: the fast connect answer tone, 0 for 400 ms
setting escape-char number 43 43 0 255 S2=%s Characters Escape character S2: the +++ escape's character (43 is '+')
setting escape-guard number 50 50 0 255 S12=%s Characters Escape guard time (20 ms) S12: the quiet before and after +++
setting cr-char number 13 13 0 127 S3=%s Characters Line end character S3: ends a command line (13 is CR)
setting lf-char number 10 10 0 127 S4=%s Characters Line feed character S4: follows S3 in responses (10 is LF)
setting bs-char number 8 8 0 127 S5=%s Characters Backspace character S5: erases a character (8 is BS)
setting ifc text 2,2 2,2 +IFC=%s Extended DTE flow control +IFC=(0-3),(0-2)
setting icf text 3,3 3,3 +ICF=%s Extended DTE character framing +ICF=(1-6),(0-3)
setting ipr text 0 0 +IPR=%s Extended DTE rate +IPR=(0,300,1200,2400,4800,9600,19200,38400,57600,115200,230400,460800,921600)
setting ilrr text 0 0 +ILRR=%s Extended Local rate reporting +ILRR=(0,1)
setting idsr text 0 0 +IDSR=%s Extended DSR control +IDSR=(0,1)
setting ilsd text 0 0 +ILSD=%s Extended Line signal detect +ILSD=(0,1)
setting mr text 0 0 +MR=%s Extended Modulation reporting +MR=(0,1)
setting er text 0 0 +ER=%s Extended Error control reporting +ER=(0,1)
setting dr text 0 0 +DR=%s Extended Compression reporting +DR=(0,1)
setting es text 3,0,2 3,0,2 +ES=%s Extended Error control (V.250) +ES=(0-4,6),(0-4),(0-6,8)
setting esa text 0,0,0,0,0,0,255,255 0,0,0,0,0,0,255,255 +ESA=%s Extended V.80 synchronous access +ESA=(0-2),(0,1),(0,1),(0),(0-2),(0),(0-255),(0-255)
setting itf text 383,128,0 383,128,0 +ITF=%s Extended V.80 transmit buffer +ITF=(1-4095),(0-4094),(0-500)
setting a8e text 1,1,0,0 1,1,0,0 +A8E=%s Extended V.8 and V.8 bis +A8E=(1),(1),(0),(0,1)
setting dsvd text 0 0 +DSVD=%s Extended DSVD (V.70) offered +DSVD=(0,1)
setting asvd text 0 0 +ASVD=%s Extended ASVD (V.61) offered +ASVD=(0,1)
setting ds text 3,0,2048,34 3,0,2048,34 +DS=%s Extended V.42bis compression +DS=(0-3),(0,1),(512-65535),(6-250)
setting ds44 text 3,0,0,4096,4096,255,255,12288,12288 3,0,0,4096,4096,255,255,12288,12288 +DS44=%s Extended V.44 compression +DS44=(0-3),(0,1),(0,1),(256-65535),(256-65535),(32-255),(32-255),(512-65535),(512-65535)
setting dsz text 1,1 1,1 +DSZ=%s Extended zstd compression +DSZ=(0,1),(0,1)
setting b2 text 0 0 +B2=%s Extended Clear channel link layer +B2=(0,5,7,9)
setting cbst text 0,0,0 0,0,0 +CBST=%s Extended Bearer service +CBST=(0,65,66,68,70,71,75,79,80,81,83),(0,1),(0,1)
setting crc text 0 0 +CRC=%s Extended Cellular result codes +CRC=(0,1)
setting pcw text 2 2 +PCW=%s Extended V.92 call waiting +PCW=(0-2)
setting pig text 1 1 +PIG=%s Extended V.92 PCM upstream +PIG=(0,1)
setting faa text 0 0 +FAA=%s Extended Adaptive answer +FAA=(0,1)
setting fpr text 0 0 +FPR=%s Extended Fax DTE rate +FPR=(0,1,2,4,8,10,18)
setting sec text 0 0 -SEC=%s Extended MNP 10EC -SEC=(0,1),(0-30)
setting cvm text 63,8000,0 63,8000,0 +CVM=%s Extended V.cvm +CVM=(0-63),(8000,16000),(0,1)
OK
-942
View File
@@ -1,942 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* xfer_test.c - the file transfers both ways, one transfer's line the
* other's: each protocol, each file as it was sent (and
* its time), on a clean line and on one that damages
* bytes; a cancel; what starts a transfer. With lrzsz's
* sz and rz and C-Kermit (when they are installed, or
* DMODEM_XFER_INTEROP=1 makes them needed), the same
* against them on a pseudo-terminal.
*/
#define _DEFAULT_SOURCE
#define _XOPEN_SOURCE 700
#define _DARWIN_C_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#include "dmodemctl.h"
#include "xfer.h"
#include "zstd_codec.h"
static int failures;
#define CHECK(c, ...) do { \
if (!(c)) { \
failures++; \
fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} \
} while (0)
#define MTIME 1700000000LL
static char tmp[512];
static void write_file(const char *path, const unsigned char *d, size_t n)
{
FILE *f = fopen(path, "wb");
fwrite(d, 1, n, f);
fclose(f);
struct utimbuf u = { (time_t)MTIME, (time_t)MTIME };
utime(path, &u);
}
static unsigned char *read_file(const char *path, size_t *n)
{
FILE *f = fopen(path, "rb");
if (!f) {
*n = 0;
return NULL;
}
fseek(f, 0, SEEK_END);
long l = ftell(f);
fseek(f, 0, SEEK_SET);
unsigned char *d = (unsigned char *)malloc((size_t)l + 1);
*n = fread(d, 1, (size_t)l, f);
fclose(f);
return d;
}
static long long mtime_of(const char *path)
{
struct stat sb;
return stat(path, &sb) == 0 ? (long long)sb.st_mtime : -1;
}
static void empty_dir(const char *dir)
{
char cmd[1024];
snprintf(cmd, sizeof(cmd), "rm -rf '%s' && mkdir -p '%s'", dir, dir);
if (system(cmd) != 0)
abort();
}
/* the two transfers' line, until both end: every noise-th byte from a
damaged (0 none) */
static long long line_bytes; /* what a sent in the last link2 */
static void link2(dmc_xfer *a, dmc_xfer *b, int noise)
{
char buf[4096];
line_bytes = 0;
long long count = 0, end = xfer_now() + 180000;
for (;;) {
dmc_xfer_status sa, sb;
dmc_xfer_get_status(a, &sa);
dmc_xfer_get_status(b, &sb);
if (!sa.running && !sb.running)
break;
if (xfer_now() > end) {
CHECK(0, "the transfer took too long");
dmc_xfer_cancel(a);
dmc_xfer_cancel(b);
}
int moved = 0, n;
while ((n = dmc_xfer_output(a, buf, sizeof(buf))) > 0) {
for (int i = 0; noise && i < n; i++)
if (++count % noise == 0)
buf[i] ^= 0x55;
dmc_xfer_feed(b, buf, n);
line_bytes += n;
moved = 1;
}
while ((n = dmc_xfer_output(b, buf, sizeof(buf))) > 0) {
dmc_xfer_feed(a, buf, n);
moved = 1;
}
if (!moved)
xfer_sleep(1);
}
}
static unsigned char big[40000], small[] = "hello, modem\n";
static void check_same(const char *path, const unsigned char *d, size_t n,
int prefix, const char *what)
{
size_t got;
unsigned char *g = read_file(path, &got);
CHECK(g != NULL, "%s: %s not there", what, path);
if (!g)
return;
if (prefix)
CHECK(got >= n && !memcmp(g, d, n), "%s: %s differs (%zu, %zu)",
what, path, got, n);
else
CHECK(got == n && !memcmp(g, d, n), "%s: %s differs (%zu, %zu)",
what, path, got, n);
free(g);
}
/* the protocol both ways, the files as they were */
static void both_ways(int p, int noise)
{
char src[600], dst[600], a[700], b[700];
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/data.bin", src);
snprintf(b, sizeof(b), "%s/hello.txt", src);
write_file(a, big, sizeof(big));
write_file(b, small, sizeof(small) - 1);
const char *paths[2] = { a, b };
dmc_xfer *r = dmc_xfer_receive(p, dst, "data.bin");
dmc_xfer *s = dmc_xfer_send(p, paths, 2);
link2(s, r, noise);
dmc_xfer_status ss, rs;
dmc_xfer_get_status(s, &ss);
dmc_xfer_get_status(r, &rs);
const char *what = dmc_xfer_label(p);
CHECK(!ss.result[0], "%s (noise %d): the sender: %s", what, noise, ss.result);
CHECK(!rs.result[0], "%s (noise %d): the receiver: %s", what, noise, rs.result);
int batch = dmc_xfer_batch(p);
int xmodem = p == DMC_XFER_XMODEM || p == DMC_XFER_XMODEM_1K;
char got[700];
snprintf(got, sizeof(got), "%s/data.bin", dst);
check_same(got, big, sizeof(big), xmodem, what);
if (batch) {
snprintf(got, sizeof(got), "%s/hello.txt", dst);
check_same(got, small, sizeof(small) - 1, 0, what);
CHECK(rs.files == 2, "%s: %d files", what, rs.files);
CHECK(dmc_xfer_received(r, 1) && !strcmp(dmc_xfer_received(r, 1), "hello.txt"),
"%s: the second name", what);
CHECK(mtime_of(got) == MTIME, "%s: the time %lld", what, mtime_of(got));
}
if (noise)
CHECK(rs.errors + ss.errors > 0, "%s: no errors on a noisy line", what);
dmc_xfer_free(s);
dmc_xfer_free(r);
}
/* YMODEM-G: an error ends it on both sides (no block again); a sender
asked with C does plain YMODEM */
static void ymodem_g(void)
{
char src[600], dst[600], a[700], got[700];
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/data.bin", src);
write_file(a, big, sizeof(big));
const char *paths[1] = { a };
dmc_xfer *r = dmc_xfer_receive(DMC_XFER_YMODEM_G, dst, NULL);
dmc_xfer *s = dmc_xfer_send(DMC_XFER_YMODEM_G, paths, 1);
link2(s, r, 3001);
dmc_xfer_status ss, rs;
dmc_xfer_get_status(s, &ss);
dmc_xfer_get_status(r, &rs);
CHECK(strstr(rs.result, "YMODEM-G") != NULL, "YMODEM-G noisy: the receiver: '%s'",
rs.result);
CHECK(ss.result[0], "YMODEM-G noisy: the sender went on");
snprintf(got, sizeof(got), "%s/data.bin", dst);
FILE *f = fopen(got, "rb");
CHECK(!f, "YMODEM-G noisy: the part of the file was kept");
if (f)
fclose(f);
dmc_xfer_free(s);
dmc_xfer_free(r);
empty_dir(dst);
r = dmc_xfer_receive(DMC_XFER_YMODEM, dst, NULL);
s = dmc_xfer_send(DMC_XFER_YMODEM_G, paths, 1);
link2(s, r, 0);
dmc_xfer_get_status(s, &ss);
dmc_xfer_get_status(r, &rs);
CHECK(!ss.result[0] && !rs.result[0], "YMODEM-G to YMODEM: '%s' '%s'",
ss.result, rs.result);
check_same(got, big, sizeof(big), 0, "YMODEM-G to YMODEM");
dmc_xfer_free(s);
dmc_xfer_free(r);
}
/* link2 with the receiver's skip once it has some bytes of the first file */
static void link2_skip(dmc_xfer *a, dmc_xfer *b)
{
char buf[4096];
int skipped = 0;
long long end = xfer_now() + 120000;
for (;;) {
dmc_xfer_status sa, sb;
dmc_xfer_get_status(a, &sa);
dmc_xfer_get_status(b, &sb);
if (!sa.running && !sb.running)
break;
if (xfer_now() > end) {
CHECK(0, "the skip: it took too long");
dmc_xfer_cancel(a);
dmc_xfer_cancel(b);
}
if (!skipped && sb.bytes > 8000 && !strcmp(sb.file, "data.bin")) {
dmc_xfer_skip(b);
skipped = 1;
}
int moved = 0, n;
/* (a slow line: 4 KB a turn) */
if ((n = dmc_xfer_output(a, buf, sizeof(buf))) > 0) {
dmc_xfer_feed(b, buf, n);
moved = 1;
}
while ((n = dmc_xfer_output(b, buf, sizeof(buf))) > 0) {
dmc_xfer_feed(a, buf, n);
moved = 1;
}
xfer_sleep(moved ? 1 : 2);
}
}
/* Skip File: the first file dropped, the second received */
static void skip_file(int p)
{
char src[600], dst[600], a[700], b[700], got[700];
const char *what = dmc_xfer_label(p);
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/data.bin", src);
snprintf(b, sizeof(b), "%s/hello.txt", src);
write_file(a, big, sizeof(big));
write_file(b, small, sizeof(small) - 1);
const char *paths[2] = { a, b };
dmc_xfer *r = dmc_xfer_receive(p, dst, NULL);
dmc_xfer *s = dmc_xfer_send(p, paths, 2);
link2_skip(s, r);
dmc_xfer_status ss, rs;
dmc_xfer_get_status(s, &ss);
dmc_xfer_get_status(r, &rs);
CHECK(!ss.result[0] && !rs.result[0], "%s skip: '%s' '%s'", what, ss.result,
rs.result);
snprintf(got, sizeof(got), "%s/data.bin", dst);
FILE *f = fopen(got, "rb");
CHECK(!f, "%s skip: the skipped file is there", what);
if (f)
fclose(f);
snprintf(got, sizeof(got), "%s/hello.txt", dst);
check_same(got, small, sizeof(small) - 1, 0, what);
CHECK(rs.files == 1, "%s skip: %d files", what, rs.files);
dmc_xfer_free(s);
dmc_xfer_free(r);
}
/* ZMODEM crash recovery: a part kept when the transfer stops, and
continued the next time */
static void resume(void)
{
char src[600], dst[600], a[700], got[700];
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/data.bin", src);
write_file(a, big, sizeof(big));
snprintf(got, sizeof(got), "%s/data.bin", dst);
const char *paths[1] = { a };
dmc_xfer_options o;
memset(&o, 0, sizeof(o));
o.resume = 1;
/* a part there: the receiver's option continues it */
write_file(got, big, 15000);
dmc_xfer *r = dmc_xfer_receive_opt(DMC_XFER_ZMODEM, dst, NULL, &o);
dmc_xfer *s = dmc_xfer_send(DMC_XFER_ZMODEM, paths, 1);
long long t0 = xfer_now();
link2(s, r, 0);
(void)t0;
dmc_xfer_status ss, rs;
dmc_xfer_get_status(s, &ss);
dmc_xfer_get_status(r, &rs);
CHECK(!ss.result[0] && !rs.result[0], "resume: '%s' '%s'", ss.result, rs.result);
check_same(got, big, sizeof(big), 0, "resume (the receiver's option)");
dmc_xfer_free(s);
dmc_xfer_free(r);
/* the same with the sender's ZCRECOV */
write_file(got, big, 20000);
r = dmc_xfer_receive(DMC_XFER_ZMODEM, dst, NULL);
s = dmc_xfer_send_opt(DMC_XFER_ZMODEM, paths, 1, &o);
link2(s, r, 0);
dmc_xfer_get_status(r, &rs);
CHECK(!rs.result[0], "resume (ZCRECOV): '%s'", rs.result);
check_same(got, big, sizeof(big), 0, "resume (the sender's ZCRECOV)");
dmc_xfer_free(s);
dmc_xfer_free(r);
/* there whole: skipped, and not made again as "data (2).bin" */
r = dmc_xfer_receive_opt(DMC_XFER_ZMODEM, dst, NULL, &o);
s = dmc_xfer_send(DMC_XFER_ZMODEM, paths, 1);
link2(s, r, 0);
dmc_xfer_get_status(r, &rs);
CHECK(!rs.result[0], "resume (whole): '%s'", rs.result);
char two[700];
snprintf(two, sizeof(two), "%s/data (2).bin", dst);
FILE *f = fopen(two, "rb");
CHECK(!f, "resume (whole): a second copy was made");
if (f)
fclose(f);
dmc_xfer_free(s);
dmc_xfer_free(r);
/* stopped in the middle: the part kept */
remove(got);
r = dmc_xfer_receive_opt(DMC_XFER_ZMODEM, dst, NULL, &o);
s = dmc_xfer_send(DMC_XFER_ZMODEM, paths, 1);
char buf[4096];
for (int turns = 0; turns < 20000; turns++) {
dmc_xfer_status st;
dmc_xfer_get_status(r, &st);
if (st.bytes > 10000)
break;
int n;
if ((n = dmc_xfer_output(s, buf, 1024)) > 0)
dmc_xfer_feed(r, buf, n);
while ((n = dmc_xfer_output(r, buf, sizeof(buf))) > 0)
dmc_xfer_feed(s, buf, n);
xfer_sleep(1);
}
dmc_xfer_cancel(r);
dmc_xfer_cancel(s);
link2(s, r, 0);
size_t n = 0;
unsigned char *part = read_file(got, &n);
CHECK(part && n > 0 && n < sizeof(big) && !memcmp(part, big, n),
"resume: the part was not kept (%zu bytes)", n);
free(part);
dmc_xfer_free(s);
dmc_xfer_free(r);
}
/* ------------------------------------------------------------------ */
/* ZMODEM with zstd */
static int have(const char *prog);
/* n bytes of text that compresses, as a BBS's text files do */
static unsigned char *text(size_t n, unsigned seed)
{
static const char *const words[] = {
"modem", "carrier", "the", "BBS", "file", "area", "sysop",
"message", "ZMODEM", "of", "and", "a", "upload", "download",
"baud", "line", "\r\n"
};
unsigned char *d = (unsigned char *)malloc(n + 16);
size_t at = 0;
unsigned r = seed * 2654435761u + 1;
while (at < n) {
r = r * 1103515245u + 12345u;
const char *w = words[(r >> 16) % (sizeof(words) / sizeof(words[0]))];
size_t l = strlen(w);
for (size_t i = 0; i < l && at < n; i++)
d[at++] = (unsigned char)w[i];
if (at < n)
d[at++] = ' ';
}
return d;
}
/* the codec: the specification's frame, there and back, against the
reference zstd (where it is installed) */
static void zstd_codec(void)
{
static const unsigned char vec[55] = {
0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x66, 0x55, 0x01, 0x00, 0x24, 0x02, 0x44, 0x2d, 0x4d,
0x6f, 0x64, 0x65, 0x6d, 0x20, 0x5a, 0x4d, 0x4f, 0x44, 0x45, 0x4d, 0x20, 0x7a, 0x73,
0x74, 0x64, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72,
0x2e, 0x0d, 0x0a, 0x01, 0x00, 0x8a, 0x82, 0xaa, 0x27, 0x32, 0x21, 0x69, 0x9d
};
const char *line = "D-Modem ZMODEM zstd test vector.\r\n";
char want[103];
snprintf(want, sizeof(want), "%s%s%s", line, line, line);
int n;
const char *why;
unsigned char *d = zc_decode(vec, 55, 1024, &n, &why);
CHECK(d && n == 102 && !memcmp(d, want, 102), "zstd: the vector: %s", why ? why : "differs");
free(d);
CHECK(zc_frame_len(vec, 55, 1024) == 55 && zc_frame_len(vec, 54, 1024) == 0,
"zstd: the vector's length");
unsigned char bad[55];
memcpy(bad, vec, 55);
bad[20] ^= 1;
d = zc_decode(bad, 55, 1024, &n, &why);
CHECK(!d, "zstd: a byte wrong, taken");
free(d);
d = zc_decode(vec, 55, 100, &n, &why);
CHECK(!d, "zstd: over the limit, taken");
free(d);
CHECK(zc_xxh64(NULL, 0) == 0xEF46DB3751D8E999ULL &&
zc_xxh64((const unsigned char *)"a", 1) == 0xD24EC4F1A98C6E5BULL &&
zc_xxh64((const unsigned char *)"Nobody inspects the spammish repetition", 39) ==
0xFBCEA83C8A378BF1ULL, "zstd: XXH64");
int ref = have("zstd");
size_t sizes[] = { 0, 1, 255, 256, 65535, 65791, 65792, 200000 };
for (size_t i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
for (int kind = 0; kind < 3; kind++) {
size_t sz = sizes[i];
unsigned char *t = kind == 0 ? text(sz, (unsigned)i) : (unsigned char *)malloc(sz + 1);
for (size_t k = 0; kind > 0 && k < sz; k++)
t[k] = kind == 1 ? big[k % sizeof(big)] : (unsigned char)(k / 1000);
int fn = 0, back = 0;
unsigned char *f = zc_encode(t, (int)sz, &fn);
d = f ? zc_decode(f, fn, 256 * 1024, &back, &why) : NULL;
CHECK(d && (size_t)back == sz && !memcmp(d, t, sz),
"zstd: %zu bytes (%d) there and back: %s", sz, kind, why ? why : "differs");
CHECK(f && zc_frame_len(f, fn, 256 * 1024) == fn, "zstd: %zu bytes: its length", sz);
if (kind == 0 && sz == 65535)
CHECK(fn * 3 < (int)sz, "zstd: 64 KB of text in %d bytes", fn);
/* the reference zstd: ours decoded, and its frame decoded */
if (sz > 0 && ref && f) {
char a[700], b[700], cmd[1500];
snprintf(a, sizeof(a), "%s/z.raw", tmp);
snprintf(b, sizeof(b), "%s/z.zst", tmp);
write_file(b, f, (size_t)fn);
snprintf(cmd, sizeof(cmd), "zstd -q -d -f -o '%s' '%s'", a, b);
CHECK(system(cmd) == 0, "zstd -d: our frame of %zu bytes", sz);
check_same(a, t, sz, 0, "zstd -d");
write_file(a, t, sz);
snprintf(cmd, sizeof(cmd), "zstd -q -19 --check -f -o '%s' '%s'", b, a);
CHECK(system(cmd) == 0, "zstd -19: %zu bytes", sz);
size_t rn;
unsigned char *r = read_file(b, &rn);
unsigned char *rd = r ? zc_decode(r, (int)rn, 1 << 23, &back, &why) : NULL;
CHECK(rd && (size_t)back == sz && !memcmp(rd, t, sz),
"zstd: the reference's frame of %zu bytes: %s", sz, why ? why : "differs");
free(r);
free(rd);
}
free(d);
free(f);
free(t);
}
}
if (ref)
printf("zstd: against the reference zstd\n");
}
/* one ZMODEM transfer of the files (paths) to dst with the two sides'
options: both ends' results checked */
static void zstd_link(const char *const *paths, int n, const char *dst,
const dmc_xfer_options *so, const dmc_xfer_options *ro,
int noise, const char *what)
{
dmc_xfer *r = dmc_xfer_receive_opt(DMC_XFER_ZMODEM, dst, NULL, ro);
dmc_xfer *s = dmc_xfer_send_opt(DMC_XFER_ZMODEM, paths, n, so);
link2(s, r, noise);
dmc_xfer_status ss, rs;
dmc_xfer_get_status(s, &ss);
dmc_xfer_get_status(r, &rs);
CHECK(!ss.result[0], "%s: the sender: %s", what, ss.result);
CHECK(!rs.result[0], "%s: the receiver: %s", what, rs.result);
if (noise)
CHECK(rs.errors + ss.errors > 0, "%s: no errors on a noisy line", what);
dmc_xfer_free(s);
dmc_xfer_free(r);
}
/* ZMODEM with zstd: smaller on the line, whole after errors, resumed,
plain when one side doesn't take it or the file is compressed */
static void zstd_transfers(void)
{
char src[600], dst[600], p[5][700], got[700];
const char *paths[5];
size_t sizes[5] = { 0, 1, 65536, 65537, 300001 };
unsigned char *d[5];
long long total = 0;
dmc_xfer_options on, off;
memset(&on, 0, sizeof(on));
memset(&off, 0, sizeof(off));
off.no_zstd = 1;
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
for (int i = 0; i < 5; i++) {
d[i] = text(sizes[i], (unsigned)i + 1);
snprintf(p[i], sizeof(p[i]), "%s/f%d.txt", src, i);
write_file(p[i], d[i], sizes[i]);
paths[i] = p[i];
total += (long long)sizes[i];
}
zstd_link(paths, 5, dst, &on, &on, 0, "zstd");
for (int i = 0; i < 5; i++) {
snprintf(got, sizeof(got), "%s/f%d.txt", dst, i);
check_same(got, d[i], sizes[i], 0, "zstd");
}
CHECK(line_bytes * 2 < total, "zstd: %lld bytes on the line for %lld", line_bytes, total);
printf("ZMODEM with zstd: %lld bytes on the line for %lld\n", line_bytes, total);
/* on a noisy line */
empty_dir(dst);
zstd_link(paths + 4, 1, dst, &on, &on, 3001, "zstd (noisy)");
snprintf(got, sizeof(got), "%s/f4.txt", dst);
check_same(got, d[4], sizes[4], 0, "zstd (noisy)");
/* zstd stopped on either side, or a compressed file: plain */
for (int k = 0; k < 3; k++) {
char zip[700];
const char *one[1] = { paths[4] };
empty_dir(dst);
if (k == 2) {
snprintf(zip, sizeof(zip), "%s/f4.zip", src);
write_file(zip, d[4], sizes[4]);
one[0] = zip;
}
zstd_link(one, 1, dst, k == 0 ? &off : &on, k == 1 ? &off : &on, 0, "zstd off");
snprintf(got, sizeof(got), "%s/f4.%s", dst, k == 2 ? "zip" : "txt");
check_same(got, d[4], sizes[4], 0, "zstd off");
CHECK(line_bytes >= (long long)sizes[4],
"zstd off (%d): %lld bytes on the line: compressed", k, line_bytes);
}
/* crash recovery with zstd: from the end of the part (fewer bytes on
the line than for the whole file) */
dmc_xfer_options res = on;
res.resume = 1;
empty_dir(dst);
zstd_link(paths + 4, 1, dst, &on, &on, 0, "zstd (whole)");
long long whole = line_bytes;
empty_dir(dst);
snprintf(got, sizeof(got), "%s/f4.txt", dst);
write_file(got, d[4], 123457);
zstd_link(paths + 4, 1, dst, &on, &res, 0, "zstd (resume)");
check_same(got, d[4], sizes[4], 0, "zstd (resume)");
CHECK(line_bytes * 4 < whole * 3,
"zstd (resume): %lld bytes on the line, %lld for all: not resumed", line_bytes, whole);
for (int i = 0; i < 5; i++)
free(d[i]);
}
/* plain text with the waits of ASCII Setup */
static void text_delays(void)
{
char src[600], dst[600], a[700], got[700];
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
static const unsigned char text[] = "one\r\ntwo\r\nthree\rfour\n";
snprintf(a, sizeof(a), "%s/t.txt", src);
write_file(a, text, sizeof(text) - 1);
const char *paths[1] = { a };
dmc_xfer_options o;
memset(&o, 0, sizeof(o));
o.line_delay_ms = 100;
o.char_delay_ms = 5;
xfer_text_quiet_ms = 600;
dmc_xfer *r = dmc_xfer_receive(DMC_XFER_TEXT, dst, "t.txt");
long long t0 = xfer_now();
dmc_xfer *s = dmc_xfer_send_opt(DMC_XFER_TEXT, paths, 1, &o);
for (;;) {
dmc_xfer_status st;
dmc_xfer_get_status(s, &st);
char buf[256];
int n;
while ((n = dmc_xfer_output(s, buf, sizeof(buf))) > 0)
dmc_xfer_feed(r, buf, n);
if (!st.running)
break;
xfer_sleep(1);
}
long long took = xfer_now() - t0;
/* 4 line ends and 21 characters */
CHECK(took >= 4 * 100 + 21 * 5, "text delays: %lld ms", took);
link2(s, r, 0);
snprintf(got, sizeof(got), "%s/t.txt", dst);
check_same(got, text, sizeof(text) - 1, 0, "text delays");
dmc_xfer_free(s);
dmc_xfer_free(r);
}
static void hex_both_ways(int p)
{
char src[600], dst[600], a[700], got[700];
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
/* (70000 bytes: past 64 KB, an extended address, S2 records) */
static unsigned char img[70000];
for (size_t i = 0; i < sizeof(img); i++)
img[i] = (unsigned char)(i * 7 + 3);
for (int as_records = 0; as_records < 2; as_records++) {
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/image.bin", src);
write_file(a, img, sizeof(img));
if (as_records) {
/* the records already: sent as they are */
char d2[600], rec[700];
snprintf(d2, sizeof(d2), "%s/rec", tmp);
empty_dir(d2);
const char *pa[1] = { a };
dmc_xfer *r = dmc_xfer_receive(DMC_XFER_TEXT, d2, "image.hex");
dmc_xfer *s = dmc_xfer_send(p, pa, 1);
xfer_text_quiet_ms = 300;
link2(s, r, 0);
dmc_xfer_free(s);
dmc_xfer_free(r);
snprintf(rec, sizeof(rec), "%s/image.hex", d2);
snprintf(a, sizeof(a), "%s", rec);
}
const char *paths[1] = { a };
dmc_xfer *r = dmc_xfer_receive(p, dst, "image.bin");
dmc_xfer *s = dmc_xfer_send(p, paths, 1);
link2(s, r, 0);
dmc_xfer_status rs;
dmc_xfer_get_status(r, &rs);
CHECK(!rs.result[0], "%s: %s", dmc_xfer_label(p), rs.result);
snprintf(got, sizeof(got), "%s/image.bin", dst);
check_same(got, img, sizeof(img), 0, dmc_xfer_label(p));
dmc_xfer_free(s);
dmc_xfer_free(r);
}
}
static void text_both_ways(void)
{
char src[600], dst[600], a[700], got[700];
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/note.txt", src);
write_file(a, big, 5000);
xfer_text_quiet_ms = 300;
const char *paths[1] = { a };
dmc_xfer *r = dmc_xfer_receive(DMC_XFER_TEXT, dst, "note.txt");
dmc_xfer *s = dmc_xfer_send(DMC_XFER_TEXT, paths, 1);
link2(s, r, 0);
snprintf(got, sizeof(got), "%s/note.txt", dst);
check_same(got, big, 5000, 0, "plain text");
dmc_xfer_free(s);
dmc_xfer_free(r);
/* a cancel keeps what came */
empty_dir(dst);
xfer_text_quiet_ms = 60000;
r = dmc_xfer_receive(DMC_XFER_TEXT, dst, "kept.txt");
dmc_xfer_feed(r, "some text", 9);
xfer_sleep(200);
dmc_xfer_cancel(r);
dmc_xfer_status rs;
do {
xfer_sleep(10);
dmc_xfer_get_status(r, &rs);
} while (rs.running);
CHECK(!rs.result[0], "plain text's cancel: %s", rs.result);
snprintf(got, sizeof(got), "%s/kept.txt", dst);
check_same(got, (const unsigned char *)"some text", 9, 0, "plain text's cancel");
dmc_xfer_free(r);
}
static void cancel(void)
{
char dst[600];
snprintf(dst, sizeof(dst), "%s/dst", tmp);
empty_dir(dst);
dmc_xfer *r = dmc_xfer_receive(DMC_XFER_ZMODEM, dst, NULL);
xfer_sleep(100);
dmc_xfer_cancel(r);
char buf[256];
int n, cans = 0;
dmc_xfer_status rs;
do {
xfer_sleep(10);
dmc_xfer_get_status(r, &rs);
while ((n = dmc_xfer_output(r, buf, sizeof(buf))) > 0)
for (int i = 0; i < n; i++)
cans += buf[i] == 0x18;
} while (rs.running);
CHECK(!strcmp(rs.result, "cancelled"), "cancel: %s", rs.result);
CHECK(cans >= 5, "cancel: %d CANs sent", cans);
dmc_xfer_free(r);
}
static void detect(void)
{
int at = -1;
const char sz[] = "rz waiting\r\n**\x18" "B00000000000000\r\x8a\x11";
CHECK(dmc_xfer_detect(sz, (int)sizeof(sz) - 1, &at) ==
DMC_XFER_DETECT_ZMODEM_SEND && at == 12, "sz %d", at);
const char rz[] = "**\x18" "B0100000023be50\r\x8a\x11";
CHECK(dmc_xfer_detect(rz, (int)sizeof(rz) - 1, &at) ==
DMC_XFER_DETECT_ZMODEM_RECEIVE && at == 0, "rz");
const char k[] = "x\x01" "1 S~/ @-#Y3~^>J)0___F\r";
CHECK(dmc_xfer_detect(k, (int)sizeof(k) - 1, &at) ==
DMC_XFER_DETECT_KERMIT_SEND && at == 1, "kermit");
CHECK(dmc_xfer_detect("hello", 5, &at) == DMC_XFER_DETECT_NONE, "none");
}
/* ------------------------------------------------------------------ */
/* lrzsz and C-Kermit, on a pseudo-terminal */
static int have(const char *prog)
{
char cmd[256];
snprintf(cmd, sizeof(cmd), "command -v %s >/dev/null 2>&1", prog);
return system(cmd) == 0;
}
/* cmd run in dir on a pseudo-terminal (raw), the transfer on its other
side: the command's exit status */
static int against(dmc_xfer *x, const char *dir, const char *cmd)
{
int m = posix_openpt(O_RDWR | O_NOCTTY);
if (m < 0 || grantpt(m) < 0 || unlockpt(m) < 0)
return -1;
const char *sname = ptsname(m);
pid_t pid = fork();
if (pid == 0) {
setsid();
int s = open(sname, O_RDWR);
char raw[700];
snprintf(raw, sizeof(raw), "stty raw -echo -ixon -ixoff <&%d; cd '%s' && exec %s",
s, dir, cmd);
dup2(s, 0);
dup2(s, 1);
int null = open("/dev/null", O_WRONLY);
dup2(null, 2);
execl("/bin/sh", "sh", "-c", raw, (char *)NULL);
_exit(127);
}
fcntl(m, F_SETFL, O_NONBLOCK);
char buf[4096];
long long end = xfer_now() + 120000;
int status = -1, done = 0;
for (;;) {
int moved = 0;
ssize_t n = read(m, buf, sizeof(buf));
if (n > 0) {
dmc_xfer_feed(x, buf, (int)n);
moved = 1;
}
int k;
while ((k = dmc_xfer_output(x, buf, sizeof(buf))) > 0) {
int off = 0;
while (off < k) {
ssize_t w = write(m, buf + off, (size_t)(k - off));
if (w > 0)
off += (int)w;
else if (errno == EAGAIN)
xfer_sleep(1);
else
break;
}
moved = 1;
}
if (!done && waitpid(pid, &status, WNOHANG) == pid)
done = 1;
dmc_xfer_status st;
dmc_xfer_get_status(x, &st);
if (!st.running && done)
break;
if (xfer_now() > end) {
kill(pid, 9);
dmc_xfer_cancel(x);
if (!done)
waitpid(pid, &status, 0);
done = 1;
}
if (!moved)
xfer_sleep(2);
}
close(m);
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
}
static void interop_one(int p, const char *send_cmd, const char *recv_cmd, int prefix)
{
char src[600], dst[600], a[700], b[700], got[700], cmd[1400];
const char *what = dmc_xfer_label(p);
snprintf(src, sizeof(src), "%s/src", tmp);
snprintf(dst, sizeof(dst), "%s/dst", tmp);
int batch = dmc_xfer_batch(p);
/* theirs sends, ours receives */
empty_dir(src);
empty_dir(dst);
snprintf(a, sizeof(a), "%s/data.bin", src);
snprintf(b, sizeof(b), "%s/hello.txt", src);
write_file(a, big, sizeof(big));
write_file(b, small, sizeof(small) - 1);
snprintf(cmd, sizeof(cmd), "%s data.bin%s", send_cmd, batch ? " hello.txt" : "");
dmc_xfer *r = dmc_xfer_receive(p, dst, "data.bin");
int rc = against(r, src, cmd);
dmc_xfer_status st;
dmc_xfer_get_status(r, &st);
CHECK(!st.result[0], "%s from %s: %s", what, send_cmd, st.result);
CHECK(rc == 0, "%s: %s exited %d", what, send_cmd, rc);
snprintf(got, sizeof(got), "%s/data.bin", dst);
check_same(got, big, sizeof(big), prefix, what);
if (batch) {
snprintf(got, sizeof(got), "%s/hello.txt", dst);
check_same(got, small, sizeof(small) - 1, 0, what);
CHECK(mtime_of(got) == MTIME, "%s from %s: the time %lld", what,
send_cmd, mtime_of(got));
}
dmc_xfer_free(r);
/* ours sends, theirs receives */
empty_dir(dst);
const char *paths[2] = { a, b };
dmc_xfer *s = dmc_xfer_send(p, paths, 2);
rc = against(s, dst, recv_cmd);
dmc_xfer_get_status(s, &st);
CHECK(!st.result[0], "%s to %s: %s", what, recv_cmd, st.result);
CHECK(rc == 0, "%s: %s exited %d", what, recv_cmd, rc);
snprintf(got, sizeof(got), "%s/data.bin", dst);
check_same(got, big, sizeof(big), prefix, what);
if (batch) {
snprintf(got, sizeof(got), "%s/hello.txt", dst);
check_same(got, small, sizeof(small) - 1, 0, what);
CHECK(mtime_of(got) == MTIME, "%s to %s: the time %lld", what,
recv_cmd, mtime_of(got));
}
dmc_xfer_free(s);
}
static void interop(void)
{
const char *want = getenv("DMODEM_XFER_INTEROP");
int need = want && !strcmp(want, "1");
if (have("sz") && have("rz")) {
interop_one(DMC_XFER_ZMODEM, "sz -b", "rz -b", 0);
interop_one(DMC_XFER_YMODEM, "sz --ymodem -b", "rz --ymodem -b", 0);
/* (sb streams when asked with G; rb asks with C: plain YMODEM) */
interop_one(DMC_XFER_YMODEM_G, "sz --ymodem -b", "rz --ymodem -b", 0);
interop_one(DMC_XFER_XMODEM, "sz --xmodem -b", "rz --xmodem -b data.bin", 1);
interop_one(DMC_XFER_XMODEM_1K, "sz --xmodem -k -b", "rz --xmodem -b data.bin", 1);
printf("interop: lrzsz\n");
} else {
CHECK(!need, "sz and rz are not installed");
}
if (have("kermit")) {
interop_one(DMC_XFER_KERMIT, "kermit -Y -i -s", "kermit -Y -i -r", 0);
printf("interop: C-Kermit\n");
} else {
CHECK(!need, "kermit is not installed");
}
}
int main(void)
{
snprintf(tmp, sizeof(tmp), "%s/dmodem-xfer-XXXXXX",
getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
if (!mkdtemp(tmp)) {
perror("mkdtemp");
return 1;
}
srand(7);
for (size_t i = 0; i < sizeof(big); i++)
big[i] = (unsigned char)rand();
int protocols[] = { DMC_XFER_ZMODEM, DMC_XFER_YMODEM, DMC_XFER_XMODEM,
DMC_XFER_XMODEM_1K, DMC_XFER_KERMIT };
both_ways(DMC_XFER_YMODEM_G, 0);
ymodem_g();
printf("YMODEM-G\n");
for (size_t i = 0; i < sizeof(protocols) / sizeof(protocols[0]); i++) {
both_ways(protocols[i], 0);
printf("%s: clean line\n", dmc_xfer_label(protocols[i]));
/* (Kermit's long packets: most would be damaged at 1 in 3001) */
both_ways(protocols[i], protocols[i] == DMC_XFER_KERMIT ? 7001 : 3001);
printf("%s: noisy line\n", dmc_xfer_label(protocols[i]));
}
hex_both_ways(DMC_XFER_INTEL_HEX);
hex_both_ways(DMC_XFER_SREC);
printf("hex records\n");
text_both_ways();
text_delays();
printf("plain text\n");
skip_file(DMC_XFER_ZMODEM);
skip_file(DMC_XFER_KERMIT);
printf("skip file\n");
resume();
printf("ZMODEM crash recovery\n");
zstd_codec();
printf("zstd\n");
zstd_transfers();
cancel();
detect();
interop();
char cmd[600];
snprintf(cmd, sizeof(cmd), "rm -rf '%s'", tmp);
if (system(cmd) != 0)
failures++;
if (failures)
fprintf(stderr, "%d failures\n", failures);
else
printf("all passed\n");
return failures ? 1 : 0;
}
-142
View File
@@ -1,142 +0,0 @@
# Documentation style: ASD-STE100 Simplified Technical English
All technical documentation in the D-Modem project uses ASD-STE100
Simplified Technical English (STE). This guide gives the rules that we use.
It applies to READMEs, the `docs/` folders, wikis, specifications, design
documents, protocol write-ups, CONTRIBUTING files (except legal text) and
technical notes in the project files.
The official source is the ASD-STE100 specification (Issue 9) and its
dictionary. If this guide and the specification are different, use the
specification. You can get the specification free of charge from
<https://www.asd-ste100.org>.
## 1. What STE does not change
Do not change these items. Copy them exactly:
- Code, commands, file names, paths, URLs, identifiers and configuration keys.
- AT commands, S-registers, result codes and protocol message names.
- Numbers, units, addresses, offsets and register values.
- Titles of standards (for example, ITU-T V.92) and quotations from them.
- Product names, company names and the names of people.
- Legal text: licenses, the contributor agreement, copyright and trademark
notices. Legal text keeps its legal wording.
- Text that we copied from a third party (for example, `ORIGINAL-readme.txt`
files, firmware release notes, test fixtures).
## 2. Words
1. Use approved words from the STE dictionary, with their approved meaning
only. For example, "close" means "to move to the closed position". It
does not mean "near".
2. Use technical names (Category: technical names). For example: modem,
handshake, carrier, codec, constellation, packet, socket, thread,
buffer, firmware, sample rate, call, line, PBX, trunk, server, client.
3. Use technical verbs (Category: technical verbs) for processes that STE
does not cover. This project uses these technical verbs: build, compile,
link, configure, install, uninstall, boot, flash, download, upload, dial,
log in, log out, debug, decode, encode, modulate, demodulate, train,
retrain, negotiate, sign, encrypt, decrypt, compress, decompress, parse,
render, cache, merge, commit, push, clone, emulate, probe.
4. Use one word for one thing. Do not change between synonyms. For example,
if you write "softmodem", do not write "software modem" in the next
paragraph.
5. Use these verb forms only: infinitive, imperative, simple present, simple
past, simple future, and the past participle as an adjective.
6. Do not use "-ing" forms of verbs, except in technical names (for example,
"ring signal", "echo canceller"). Write "the modem starts to train", not
"the modem is training".
7. Do not use phrasal verbs. Write "start", not "start up". Write "find",
not "find out".
8. Do not make noun clusters of more than three words. Use prepositions to
break up longer clusters. Write "the receive buffer of the V.34 data
pump", not "the V.34 data pump receive buffer".
9. Use articles ("the", "a") and demonstrative adjectives ("this", "these")
before nouns where possible.
10. Do not use slang, idioms, contractions ("can't", "it's") or Latin
abbreviations ("e.g.", "i.e.", "etc."). Write "for example", "that is",
"and other items".
### Common replacements
| Do not write | Write |
|---|---|
| utilize, make use of | use |
| ensure, make certain | make sure |
| require, need to | is necessary, must |
| should | must (a rule) or write what occurs (a fact) |
| allow, enable (a person) | let, make it possible |
| approximately, roughly | about |
| perform, carry out | do |
| obtain, fetch, grab | get |
| prior to | before |
| in order to | to |
| via | through |
| currently | now |
| additional | more |
| e.g., i.e., etc. | for example, that is, and other items |
| turn on / turn off (a setting) | enable / disable (technical verbs for software settings) |
| set up (verb) | configure, install |
| figure out, find out | find, calculate |
| it's, can't, don't | it is, cannot, do not |
## 3. Sentences
1. Write one topic in one sentence.
2. Procedural sentences (instructions): 20 words or fewer.
3. Descriptive sentences: 25 words or fewer.
4. Use the active voice. In descriptive text, you can use the passive voice
only when you do not know who or what does the action.
5. Do not use semicolons to join sentences. Write two sentences.
6. Use a colon before a list. Use a vertical list when there are more than
two items.
7. Use connecting words ("then", "but", "if", "because") to show how two
sentences are related.
## 4. Procedures
1. Write instructions in the imperative ("Install the package").
2. Write one instruction in one sentence. You can write two actions in one
sentence only when the reader does them at the same time.
3. Write each step as a numbered item.
4. If a condition applies, write the condition first: "If the build fails,
delete the `build/` folder."
5. Put a warning or a caution before the step that it applies to. Do not put
it at the end of the procedure.
6. Write the result of a step in a separate sentence after the step, if the
reader must know it.
## 5. Descriptive writing
1. Give the most important information first.
2. Write one topic in one paragraph.
3. Do not write more than six sentences in a paragraph.
4. Use headings to divide long text into short sections.
5. Use tables for data that has rows and columns.
## 6. Warnings and cautions
Use a warning for a risk to persons. Use a caution for a risk to equipment,
data or the telephone line. Start with a short title, then the instruction,
then the risk:
> **CAUTION: DO NOT CONNECT THE BOARD TO A LIVE LINE WITHOUT THE ISOLATION
> TRANSFORMER.** The line voltage can cause damage to the codec.
## 7. Examples
| Before | After (STE) |
|---|---|
| You'll need to make sure the PBX is set up before you dial out. | Configure the PBX before you dial. |
| The handshake is performed by the answering modem, which then starts sending ANSam. | The answering modem starts the handshake. Then it sends ANSam. |
| Turn it off if it's causing trouble. | If this feature causes problems, disable it. |
| `crypto/tls` can't take such a hello, and it can't be rewritten for it. | `crypto/tls` cannot accept this type of hello. Also, you cannot change `crypto/tls` to accept it. |
## 8. Check before you commit
- Are all sentences short (20 words for instructions, 25 for descriptions)?
- Is each instruction in the imperative, with one action?
- Is there a word with "-ing", a phrasal verb or a contraction?
- Are code, commands and identifiers exactly the same as before?
- Did you keep legal text and third-party text unchanged?
-157
View File
@@ -1,157 +0,0 @@
# Building
The app is one Win32 app (`windows/`). It builds for Windows, and for
Linux and macOS over the portable Win32 layer of clang-retro MFC
(`winport/`). The submodule `external/D-Modem` gives the built-in modem.
Refer to [The built-in modem](embedded-modem.md).
## Windows
We build the app for Windows with clang-retro. Get its toolchain
package (`clang-dos-linux-x86_64.tar.xz` or `clang-dos-windows-x86_64.zip`,
from the [nightly release](https://github.com/clang-retro/dos-sdk/releases/tag/nightly)).
Then set `CLANG_DOS` to the directory of the package. Each build needs the
submodule (`git submodule update --init`) for the built-in modem:
# Windows 95, 98, ME, NT 4.0 and later (no C runtime DLL), with the built-in modem
cmake -S . -B build/win9x -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake
cmake --build build/win9x
# Windows 98 SE, ME, 2000 and later, with the built-in modem
cmake -S . -B build/win98 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake \
-DCLANG_RETRO_CONFIG=win98
cmake --build build/win98
# Windows 7 and later, with the built-in modem
cmake -S . -B build/win7 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake \
-DCLANG_RETRO_CONFIG=win7
cmake --build build/win7
The app is in `windows/dmodem.exe` of the build directory. MSVC
(`cmake -S . -B build -A Win32`) and MinGW also build the same code.
## Linux and macOS
Get [clang-retro MFC](https://github.com/clang-retro/mfc),
clang and `llvm-rc` (on macOS, `brew install llvm`). For the built-in
modem, get the D-Modem submodule (`git submodule update --init`). On
Linux, also install `libusb-1.0-0-dev` and `libasound2-dev`. Then:
cmake -S . -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build --target dmodem-win32 && ./build/winport/dmodem-win32
On Linux, `cmake --install build` installs the app, its desktop entry,
its icon and the firmware of the MultiTech MT9234MU (`firmware/`).
On macOS, the app is for the architecture of the Mac. To build the app
for an Intel Mac on a Mac with Apple silicon, add
`-DCMAKE_OSX_ARCHITECTURES=x86_64` to the first command. Set one
architecture only. The app cannot be a universal binary.
## Mac OS X 10.4 and later (PowerPC and Intel)
The app for Mac OS X 10.4 (Tiger) and later builds on Linux. It uses the
Mac OS X 10.0-10.5 port of clang-retro MFC and the toolchain file
`cmake/macosx-legacy.cmake`. You need these items:
- clang of [clang-retro/llvm](https://github.com/clang-retro/llvm) (its
`llvm-prebuilt` release). The clang of the clang-dos package can be too
old: it must have emulated TLS for Mac OS X 10.4.
- The `macosx10.4` sysroot of [clang-retro/dos-sdk](https://github.com/clang-retro/dos-sdk):
`sh packaging/get-toolchain.sh -s macosx10.4 DIR`. It has libc++ and
the builtins, and the script also gets Apple's `MacOSX10.4u.sdk`.
Apple's license applies to the SDK.
- Apple's `ld64` and `ar` for PowerPC: `PREFIX=DIR sh scripts/build-cctools-ppc.sh`
in dos-sdk. This `ld64` also links for i386.
Build the app one time for each processor (`powerpc` and `i386`):
export MACOSX_LEGACY_LLVM=/path/to/llvm MACOSX_LEGACY_SYSROOT=/path/to/macosx10.4 \
MACOSX_LEGACY_CCTOOLS=/path/to/cctools-ppc
cmake -S . -B build/powerpc -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$PWD/cmake/macosx-legacy.cmake \
-DMACOSX_LEGACY_ARCH=powerpc -DCLANG_RETRO_MFC=/path/to/mfc -DDMODEM_GUI_WINPORT=ON
cmake --build build/powerpc --target dmodem-win32
Then join the two programs into one fat program:
$MACOSX_LEGACY_CCTOOLS/bin/powerpc-apple-darwin8-lipo -create \
build/powerpc/winport/dmodem-win32 build/i386/winport/dmodem-win32 -output dmodem-win32
`cmake/macosx-legacy/` has the fixes for headers of the 10.4 SDK
(`time.h`, `signal.h` and `net/if.h`). The built-in modem needs D-Modem
with the changes for 10.4 to 10.6 (`docs/macos-details.md` in D-Modem).
## Mac OS 9 (PowerPC)
The app for the classic Mac OS on PowerPC builds on Linux. It uses the
Toolbox backend of clang-retro MFC and the toolchain file
`cmake/macos9.cmake`. You need these items:
- clang of [clang-retro/llvm](https://github.com/clang-retro/llvm) (its
`llvm-prebuilt` release).
- A [clang-retro/mac-sdk](https://github.com/clang-retro/mac-sdk)
checkout with its PowerPC libraries in `lib/`. Build them with
`runtime/build.sh`, `runtime/build-libc.sh` (it needs a
[clang-retro/picolibc](https://github.com/clang-retro/picolibc)
checkout) and `runtime/build-libstdcxx.sh` (it needs the GCC 15.2.0
release and the libunwind of clang-retro/llvm). mac-sdk's
`docs/cxx.md` tells more.
Build the app:
export MACOS9_LLVM=/path/to/llvm MACOS9_SDK=/path/to/mac-sdk
cmake -S . -B build/os9 -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$PWD/cmake/macos9.cmake \
-DCLANG_RETRO_MFC=/path/to/mfc -DDMODEM_GUI_WINPORT=ON \
-DDMODEM_GUI_EMBED=ON -DDMODEM_GUI_SSH=OFF
cmake --build build/os9 --target dmodem-win32
The result is `build/os9/winport/dmodem-win32.bin`, an application in
MacBinary format. `mac-sdk/tools/macapp.py` links it. The memory
partition of the app is 16 MB (`MACOS9_APP_SIZE`, in KB).
These items are different on Mac OS 9:
- There is no SSH (`DMODEM_GUI_SSH=OFF`).
- There is no debug information. Clang cannot write DWARF into XCOFF
objects.
- `cmake/Platform/MacOS9.cmake` gives the CMake system `MacOS9`. The
built-in modem needs D-Modem with the changes for this system
(`docs/macos-details.md` in D-Modem).
## The library only
With no `DMODEM_GUI_WINPORT`, a build on Linux or macOS makes only
libdmodemctl, libdmodemssh and their tests. You do not need clang-retro
MFC for this build:
cmake -S . -B build && cmake --build build && ctest --test-dir build
## Notes
The first CMake build downloads libssh and mbedTLS for SSH. This always
occurs on Windows and macOS. Use `-DDMODEM_GUI_SSH=OFF` for a build with
no SSH. On Linux, it occurs if the libssh of the system
is older than 0.11.
The Settings page needs a dmodemd with AT!M (the main branch of D-Modem
since D-Modem/D-Modem#103). The other pages operate with all versions of
D-Modem 1.0.
## Updates from D-Modem
The workflow `.github/workflows/d-modem-bump.yml` keeps the submodule
`external/D-Modem` on the main branch of D-Modem. It starts when the main
branch of D-Modem changes, one time each day, or when you start it
manually. It opens a pull request that moves the submodule. Build
(`.github/workflows/build.yml`) builds and tests the app in that pull
request. The workflow merges the pull request when all checks pass. Then
Build runs on `main`, and the next nightly release has the new app. If a
check fails, the pull request stays open for a person. The workflow needs
a `DMODEM_BUMP_TOKEN` secret. The header of the workflow gives the
necessary permissions.
-597
View File
@@ -1,597 +0,0 @@
# Design
## One library, one Win32 app
The app is one Win32 app (`windows/`). The same source code builds for
Windows, and for Linux and macOS over the portable Win32 layer of
clang-retro MFC (refer to "The Windows app on Linux and macOS", below).
All the code that does not draw is in `core/`. `core/` is libdmodemctl, a
small C library with no I/O and no threads ("sans-I/O"). The app opens the
modem. Then it gives the bytes that it reads to `dmc_feed()`, writes the
data that `dmc_output()` gives it, and calls `dmc_poll()` from a 50 ms
timer. Thus the library is easy to call from C and C++. It is also easy to
test (`core/test`, which CI runs with ASan and UBSan).
| Part | What it does |
| --- | --- |
| `dmc_session` | The AT conversation: a queue of commands and their responses, the state of the call from the result codes (RING, CONNECT, NO CARRIER), caller ID, the escape (`+++` with its guard times) and the hang-up, and the byte stream for the terminal |
| `dmc_model` | The settings of the modem from AT!M, with the check of each setting and the command that sets it |
| `dmc_path` | The connection path at the top of the Settings page: the terminal, the modem, the line and what the line reaches. For each step, its role, name, state and setting, from the line settings and the state of the session |
| `dmc_diag` | The statistics of the last call from AT#UD, as labelled rows (with the V.58 code tables decoded) |
| `dmc_vt` | The terminal emulator of the D-Modem app (`shared/.../terminal` of D-Modem/app), ported to C: each type of terminal that it emulates (see below). The app draws it from its cells |
| `dmc_net` | Telnet (option negotiation, terminal type, window size) and rlogin (the handshake, and the window size on the urgent request of the server), for the Remote page |
| `dmc_daemon_*` | It reads the text that dmodemd prints when it starts: the device that it made, or its error |
## Where the settings come from
The core of dmodemd has one settings model (`Config::model`). This model
also controls its configurators (AT!CF, AT!CT, AT!C). AT!M prints that model
as tab-separated lines. Each line has the key of a setting, its kind (pick,
number or text), value, default, range, AT form, group, label and help, and
then each choice. The Settings page builds its controls from this output.
Thus, if a setting is added to the modem, it shows in the app without a
change here. The library checks a change and sends it as its AT command. The
app keeps the change when the modem says OK.
The modem keeps no stored profile. Thus the page shows the init string of
AT!R. Its **Keep** button saves the string in the line settings of the app.
The app sends the string each time that the modem opens.
## The pages
The app has seven pages:
| Page | Contents |
| --- | --- |
| Modem | The state ("Idle", "Dialling", "Online") and its detail (the CONNECT line, the caller), Dial, Answer, Hang Up, the line and the device, Start or Stop |
| Phone | The state of a voice call, Call and Answer, the keypad (DTMF), Mute and Listen. The answering machine (on or off, rings, the greeting) and its messages |
| Terminal | The AT console. The buttons **Full-screen setup** (AT!CF) and **Command-line setup** (AT!CT). The type of terminal |
| Remote | SSH, Telnet or rlogin. The server, its port (empty: the port of the protocol) and the user. The login method of SSH (keys and the agent, the agent only, a key file, the import of a PuTTY key). Connect. A separate terminal, with its type. The terminal sends its size to the server when the size changes |
| Settings | The connection path. Groups of settings as native controls, with the changed settings marked. Defaults (ATZ), the init string and Keep |
| Call Stats | The rows of AT#UD and the report of ATI11, refreshed after each call |
| Log | The text that dmodemd printed, and the command line that started it |
The terminal sends Backspace as BS (0x08), the S5 of the modem, because the
modem does not accept DEL. The colours are the colours of the brand:
background `#0a0f1c`, text `#e8f0ff`.
## The connection path
The top of the Settings page shows how a call is made, as the "Connection
Overview" of PCOMM draws its link: four steps joined by one line. Each step
has its role above its icon and its setting below.
| Line | Program | Modem (or Port) | Line (or Modem) | Reaches (or Line) |
| --- | --- | --- | --- | --- |
| SIP account | Terminal | D-Modem | SIP: the account, registered when the modem takes calls | The phone network, through the server |
| SIP, anonymous | Terminal | D-Modem | SIP: nothing registered | SIP addresses, dialled directly |
| USB modem | Terminal | D-Modem | The USB modem | Its phone line |
| Codec (Linux) | Terminal | D-Modem | The ALSA device | Its phone line |
| A modem that already runs | Terminal | Its device, TCP address or COM port | The modem | Its phone line |
When idle, each step shows the line settings. A step that is ready is in the
accent colour. A step that you must still set (no SIP account, no device) is
red and its line is dashed, and the text below says what to set. When the
modem starts, dials and is online, the steps light green as the call goes,
and the text below shows the CONNECT line. `dmc_path` of libdmodemctl has the
words. The app draws them in `pathview.cpp` (GDI, with the Wingdings of
Windows 95). The D-Modem app has the same picture at the top of its
Settings, with its own lines (Wi-Fi and Bluetooth to another phone, the
mobile calls of the phone, external modems).
## The terminals
The two terminals (the console of the modem and the terminal of the Remote
page) use `dmc_vt` of libdmodemctl. This is the emulator of the app in C,
with the 29 types of terminal (profiles) of the app. You select the type
next to each terminal, and the app keeps it with the settings of the page:
| Kind | What it is |
| --- | --- |
| xterm (the default) | A VT220 with colours (8, 16, 256, 24-bit), sixel, the mouse, bracketed paste, the alternate screen, titles, OSC 8 links and Tek mode |
| DEC VT52 to VT525 | The answers and sequences of each model: the sequences of the VT52, the levels of the VT100 to VT320, the sixel, ReGIS and Tek mode of the VT340, the rectangles, margins and pages of the VT420, the colours of the VT525. Soft fonts (DECDLD), user-defined keys, the printer port, the status line |
| ANSI-BBS, Avatar, RIPscrip, Amiga ANSI | The BBS terminal of a PC in code page 437 and the font of the VGA (the SyncTERM font switch, CSI SP D, with the fonts of the machines), ANSI music, iCE colours, doorway mode. The codes of Avatar. The graphics and mouse buttons of RIPscrip on 80x43. The Topaz and palette of the Amiga |
| Commodore 64, 128 (40 and 80 col.), Plus/4, VIC-20, PET (40 and 80) | PETSCII, and the screen, colours and ROM font of each machine |
| Atari 8-bit (and international), Atari ST (80 and 40 col.) | ATASCII. The TOS VT52 of the ST with its pens |
| Viewdata, Minitel | The 40x24 of Prestel with its mosaics. The videotex of the Minitel and its Téléinformatique (a VT100) |
| Tektronix 4014 | The storage tube, as a separate type |
The library is sans-I/O, as the remaining parts are. Bytes go in
(`dmc_vt_feed`) and answers come out (`dmc_vt_reply`). The library changes
each typed key or character into the bytes that the type of terminal sends
(`dmc_vt_key_mods`, `dmc_vt_char_bytes`: the PETSCII of a Commodore, the
ATASCII of an Atari). A view draws each cell (`dmc_vt_cell`) with these
items:
- Its character and resolved colours, and its attributes.
- The bitmap of the font of a machine (`dmc_vt_glyph_row`). These are the
SyncTERM copies of the ROMs, generated into `core/src/vt_data.c` by
`tools/gen_vt_data.py`.
- The tile of a picture (`dmc_vt_cell_image`: sixel, ReGIS, RIPscrip, the
Tektronix).
If the screen of a machine has its own size (40x25 for a C64), the library
requests that size (`dmc_vt_requested_cols`). The view stretches its cells
to fill the window, by whole pixels where they fit.
The view is `termview.cpp`. It draws with GDI, one row at a time, into a
DIB section (text by `ExtTextOutW`, glyphs and pictures by pixel). The
view copies the section to the window (or stretches it, for the double
width and height of DEC).
### Copy, capture and print
The terminal control (`termview.cpp`) keeps a selection. The
selection uses the rows of `dmc_vt_cell` (a row below 0 is in the
scrollback). The selection moves up with its text when new lines push the
text into the scrollback.
- Drag with the left mouse button to select. Double-click to select a word.
When the remote side uses the mouse, hold Shift.
- Copy (Ctrl+Insert, or the Edit menu, or the menu of the right mouse
button) puts the text on the clipboard. The text comes from
`dmc_vt_text_range`. The app removes the blanks at the end of each line.
The clipboard gets Unicode text and the text of the ANSI code page.
- Paste to Host (Shift+Insert) types the clipboard text.
`ascii.cpp` has the ASCII Setup dialog (Modem menu). `dmodem.ini` keeps
the settings in the `[ascii]` section: `send_lf`, `echo`, `line_delay`,
`char_delay`, `add_lf`, `seven_bit` and `wrap`. The app applies them to
the two terminals:
- `send_lf` sets Enter to CR LF (`dmc_vt_set_enter`).
- `echo` shows the characters that you type on the terminal. The app does
not show the escape sequences of the keys (for example, the arrow keys).
- `add_lf`, `seven_bit` and `wrap` go to `dmc_vt_set_ascii`. With
`DMC_VT_ASCII_ADD_LF`, the terminal adds an LF after each CR that it
receives. When an LF follows the CR, the terminal does not use that LF,
thus a CR LF does not give two lines. `DMC_VT_ASCII_7BIT` removes bit 8
of each byte. `DMC_VT_ASCII_NO_WRAP` stops the wrap at the right margin:
the terminal writes each new character in the last column.
`termset.cpp` has the Terminal Settings dialog (Modem menu). It applies
to the terminal of the page that shows: the Remote page's, else the
modem's. `dmodem.ini` keeps the settings in `[terminal]` (the modem) and
`[remote_terminal]` (Remote). `termview_set_options` applies them:
- `backspace`: 0 sends Ctrl+H, 1 sends Del, 2 sends Ctrl+H, Space,
Ctrl+H. The default of the modem is 0 (the configurator of the modem
uses Ctrl+H). The default of Remote is 1.
- `windows_keys`: Ctrl+C copies, Ctrl+V pastes, Ctrl+A selects all. The
arrow keys, Page Up and Page Down scroll the backscroll. The function
keys go to the window (F10 opens the menu). The terminal does not send
these keys.
- `backscroll`: the lines that the terminal keeps
(`dmc_vt_set_scrollback`). When the number is smaller, the terminal
keeps the newest lines.
- `font` and `font_size`: a fixed-pitch font. When the name is empty, the
terminal uses the font of the app.
- `cursor` (0 block, 1 underline) and `cursor_blink`. A DECSCUSR from the
remote side has priority.
- `telnet_id` (Remote only): the TERMINAL-TYPE that Telnet sends. When it
is empty, Telnet sends the name of the terminal type.
- `exit_on_disconnect` (modem only): the app closes when a call ends.
The status bar shows the connect timer during a call ("Online 0:01:05").
Send Break (Call menu, or Ctrl+Break in a terminal) sends a break. On a
COM port, the app holds the line at space for 250 ms (`SetCommBreak`). On
Telnet, the app sends IAC BRK (`dmc_net_break`). TCP to dmodemd, rlogin
and SSH cannot send a break, and the status bar tells you.
`calls.cpp` has the Call menu, as HyperTerminal has it:
- Call opens the Call dialog. A session is a name and a number (or a SIP
address). `dmodem.ini` keeps the sessions in the `[sessions]` section
(`count`, `name1`, `number1` ...). Save adds or changes a session, and
Delete removes it. Call dials the number (ATD) and shows the Terminal
page.
- Wait for a Call sends ATS0=1: the modem answers at the first ring. The
app sends ATS0=1 again each time the modem opens. When you clear the
check mark, the app sends ATS0=0.
- Disconnect hangs up the call (`dmc_hangup`), or closes the Remote
connection when the Remote page shows.
The Line Settings dialog has the settings of a COM port, as the Configure
dialog of HyperTerminal: bits per second (110 to 921,600), data bits (5 to
8), parity (none, odd, even, mark, space), stop bits (1, 1.5, 2) and flow
control (none, Xon/Xoff, hardware). `dmodem.ini` keeps them as `com-bps`,
`com-data-bits`, `com-parity`, `com-stop-bits` and `com-flow`. The default
is 115,200 bps, 8 data bits, no parity, 1 stop bit and hardware flow
control.
`capture.cpp` has the captures. Each capture is of one line (the modem or
the Remote login). The capture does not get the bytes of a file transfer.
- Capture Text writes the bytes from the line to a file, as they come
(with the escape sequences). The app adds the bytes to the end of a file
that exists, as HyperTerminal does. `dmodem.ini` keeps the folder in the
`[capture]` section.
- Capture to Printer keeps the text from the line. The app removes the
escape sequences and the control characters (but not tabs, line ends and
form feeds). When you stop the capture, the app prints the text on the
default printer.
- Print (Modem menu) prints the screen or the selection, with the print
dialog.
- When the remote side prints (`CSI 5 i`, `dmc_vt_printed`), the app prints
the text on the default printer after the remote side stops for 3
seconds. During Capture to Printer, this text goes into the capture.
The app prints with GDI: Courier New at 10 points, with margins of half an
inch. The app wraps long lines, and a form feed starts a new page.
## File transfers
The file transfer protocols are in libdmodemctl (`core/src/xfer*.c`). They
are a C port of the protocols of the D-Modem app (`ZModem.kt`,
`XYModem.kt`, `Kermit.kt`, `HexRecords.kt` and `TextTransfer.kt`). The
protocols are:
- ZMODEM: CRC-16 and CRC-32 headers, ZDLE escapes, streaming data (ZCRCG)
with a ZCRCQ each 16 KB, and recovery from errors with ZRPOS.
- ZMODEM crash recovery (`dmc_xfer_options.resume`, "ZMODEM with Crash
Recovery" in the dialogs). The receiver continues a part of a file that
is in the folder: it opens the file to add to it, and it sends ZRPOS with
the length of the part. The receiver also does this when the sender sets
ZF0 to ZCRECOV (`sz -r`). If the file is there whole, the receiver sends
ZSKIP. When a transfer stops, the receiver keeps the part that it
received. The sender with this option sets ZF0 to ZCRECOV.
- ZMODEM with zstd (the specification is `docs/zmodem-zstd.md` in the
D-Modem repository). The D-Modem BBS, GUI and app use this mode. The
receiver sets `CANZSTD` (0x40) in ZF1 of its ZRINIT. The sender sets
`ZTZSTD` (8) in ZF2 of the ZFILE for each file that it compresses. Then
the sender sends the file as independent zstd frames, one frame for each
chunk of 64 KB. After a ZRPOS, the chunk is half as large (minimum 1 KB).
After an ACK, the chunk is two times as large (maximum 64 KB). The
receiver writes only complete frames. All positions are file offsets,
thus ZRPOS and crash recovery operate as without zstd. The sender does
not compress a file of 0 bytes, a file with a compressed extension (for
example `.zip`, `.gz` or `.jpg`), or a file whose first 64 KB do not
become 5% smaller. When the other side does not use this mode, the
transfer is normal ZMODEM. To stop zstd, set `dmc_xfer_options.no_zstd`
(in the app: Transfer, ZMODEM Compression (zstd)).
`dmc_xfer_zstd` tells if the file now goes with zstd. The zstd encoder
and decoder are in `core/src/zstd_codec.c`. They are a C port of the
codec of the D-Modem app (`Zstd.kt`), and they do not use libzstd.
- YMODEM, XMODEM and XMODEM-1K.
- YMODEM-G: the receiver asks with G. The sender sends the blocks and does
not wait for an ACK. Use it only on a line that corrects its errors (V.42).
An error stops the transfer, because a block cannot come again. The
sender does plain YMODEM when the receiver asks with C (lrzsz's `rb`).
lrzsz's `sb` sends no empty block 0 at the end in YMODEM-G, thus the
receiver ends the batch when no block 0 comes after a file.
- Kermit: long packets, block checks 1 to 3, attribute packets,
repeat counts and 8-bit prefixes.
- Intel HEX and Motorola S-records: the app sends a file of records as it
is, and it encodes other files as records. When it receives, it decodes
the records to a binary image.
- Plain text: the app sends the bytes of the file as they are. With
`line_delay_ms` and `char_delay_ms`, the app waits after each line end
and after each character (as the ASCII Setup of HyperTerminal). When it
receives, it keeps the text until the line is quiet. A cancel keeps the
text that came.
`dmc_xfer_skip` skips the file that the app receives now. ZMODEM sends
ZSKIP. Kermit puts X in the ACK of a data packet, and the sender ends the
file with Z and D. The progress dialog has a Skip file button for these
two protocols.
Each transfer runs on its thread (CreateThread on Windows, pthreads on
other systems). The thread and the app use two queues with a lock:
1. The app gives the bytes from the line to `dmc_xfer_feed`.
2. The app gets the bytes for the line from `dmc_xfer_output`. The app
gets only as much as the line can send now. The queue holds 32 KB
maximum, thus the thread waits when the line is slow.
3. The notify function of `dmc_xfer_set_notify` tells the app when there
are bytes to send. The app posts `WM_APP_XFER` to the window.
4. `dmc_xfer_get_status` gives the file, the bytes, the size, the retries
and the result.
The protocol code reads files only through `xfer_src_read`, and writes
files only through `xfer_dst_write`. The positions in the protocols are
file offsets. When a transfer fails or you cancel it, the app deletes the
part of the file that it received (but not for plain text).
`dmc_xfer_cancel` sends the cancel sequence of the protocol: 10 CAN and
10 BS for ZMODEM, an E packet for Kermit.
`dmc_xfer_detect` finds the start of a transfer in the received data: the
ZRQINIT of sz, the ZRINIT of rz, and the Send-Init of kermit -s. When
Automatic Receive is on, the app starts a receive, or it opens the Send
File dialog for rz.
The app (`windows/src/xfer.cpp`) has these parts:
- The Transfer menu: Send File, Receive File, Automatic Receive and
Cancel Transfer. The Terminal page also has Send and Receive buttons.
- The Send File and Receive File dialogs, and a progress dialog as in
HyperTerminal. The progress dialog shows the file, the protocol, the
retries, the throughput, the time and the bytes.
- The transfer uses the line of the page that you see: the modem on the
Terminal page, or the login on the Remote page (`struct XferLine`).
- `dmodem.ini` keeps the folder, the protocols and Automatic Receive in
the `[transfer]` section. The default folder is `Received` in the data
folder of the app.
`core/test/xfer_test.c` tests each protocol on a clean line and on a line
with noise. It also does a test with `sz` and `rz` (lrzsz) and with
C-Kermit on a pty, when they are installed. Set `DMODEM_XFER_INTEROP=1` to
make these tests mandatory.
## How the app starts dmodemd
The app starts dmodemd with `CreateProcess`. The DTE of dmodemd is a TCP
socket (`--tcp 127.0.0.1:port`). The app keeps its settings in
`dmodem.ini`: `%APPDATA%\D-Modem\dmodem.ini` on Windows,
`~/.config/D-Modem/dmodem.ini` on Linux and
`~/Library/Application Support/D-Modem/dmodem.ini` on macOS.
The app gives the SIP account to dmodemd in its environment (`SIP_LOGIN`,
`SIP_T38`, `SIP_V152`, `SIP_V150`, `SIP_SRTP`). It gives the country, the
USB modem and the debug level as flags.
The app can also use a modem that already runs: a TCP address or a COM
port. On Linux and macOS, it can also be a device path (`/dev/ttyUSB0`,
`/dev/cu.usbmodem1`), or a COM port name that the layer changes to a
device (refer to "The Windows app on Linux and macOS", below).
The app does not start dmodemd by default. It runs the modem in a thread
(`libdmodem_embed`), and its DTE is a socket. Refer to
[The built-in modem](embedded-modem.md).
## Hardware modems: the MultiTech MT9234MU
The COM port line can also open a hardware modem. The app sends AT commands
to it and read its result codes, as they do with dmodemd. The Settings page
needs `AT!M`, thus it operates only with dmodemd.
The MultiTech MultiMobile MT9234MU (USB 06E0:F114) and the MT9234ZBA-USB
(06E0:F115, 06E0:0319) are V.92 data and fax modems. They have a TI TUSB3410
USB UART. The TUSB3410 has no firmware of its own. The host downloads the
firmware into the chip each time you connect the modem.
| | Linux | macOS | Windows |
| --- | --- | --- | --- |
| Driver | `ti_usb_3410_5052` (in the kernel) | we do not know a driver for the MT9234MU. The CDC-ACM models (MT9234MU-CDC) use the driver of the system | the driver of MultiTech |
| Firmware | `mts_mt9234mu.fw` in `/lib/firmware` | not applicable | the driver of MultiTech has it |
| The port | `/dev/ttyUSB0` | `/dev/cu.usbmodem*` (CDC-ACM models) | a COM port |
Linux does not include `mts_mt9234mu.fw` after June 2026. MultiTech gave no
license that lets other persons distribute it, thus linux-firmware removed
it. This repository includes the file, with a notice
(`firmware/README.md`). The AGPL-3.0 license does not apply to it.
`cmake --install` puts it in `share/dmodem-gui/firmware`, and
`-DDMODEM_GUI_INSTALL_FIRMWARE=ON` also puts it in `/lib/firmware`. Else,
copy it to `/lib/firmware` (for the MT9234ZBA-USB, as `mts_mt9234zba.fw`),
then disconnect the modem and connect it again.
### Look for a modem
The Line Settings dialog finds the modem (`windows/src/ports.cpp`). When
the dialog opens, it searches the ports. If it finds a modem on a port
that is not selected, it shows the modem below the settings of the serial
port. Click **Look for a modem** to search again. If the app finds a
modem, it selects "A modem on a serial port", the port of the modem and
hardware flow control (RTS/CTS). The modem uses `&K3` from the factory.
The Port box lists all the ports that the app found, with the modems
first. When you select a port, the dialog shows what is on it.
| | Where the app looks | What is a modem |
| --- | --- | --- |
| Windows | The modems that Windows knows: the Modem class in the registry (`AttachedTo`, and `FriendlyName` or `DriverDesc`), for Windows 95, 98 and ME and for NT. The MultiTech modems in `Enum\USB` (NT). The ports of `HARDWARE\DEVICEMAP\SERIALCOMM`. If that key has no ports, the app tries `COM1` to `COM16` | An installed modem, or a MultiTech MT9234MU or MT9234ZBA-USB |
| Linux | `/sys/class/tty`: each `ttyUSB` and `ttyACM`, with the maker and the product of its USB device | A MultiTech MT9234MU or MT9234ZBA-USB, or a USB device whose name has "modem" in it |
| macOS | Each `/dev/cu.*` device, but not the Bluetooth devices | A `cu.usbmodem` device (CDC-ACM, for example the MT9234MU-CDC) |
On Linux, if a MultiTech modem is connected but has no port, the dialog
tells you why. With no firmware (one USB configuration, the boot ROM of
the TUSB3410), it shows the command that copies the file. If the
firmware is there, it tells you to load the `ti_usb_3410_5052` driver.
Set the country of the line with `AT%T19,0,<code>` and `AT&F&W` in the
"Commands when the modem opens" field one time, or in the Terminal page.
`AT%T19,0,34` is the default (North America and Europe).
`ATI11` on these modems (and on other Agere modems) shows its report on two
pages. After each page, the modem waits for a key ("Press any key"). The
library sends a space when a command of the app gets this prompt, thus the
Call Stats page gets the full report. It does this for 8 pages at most. In
the Terminal page, you push the key.
We did not test this yet with a real MT9234MU.
## Remote logins
The Remote page logs in to a server, next to the modem, in a separate
terminal. Telnet and rlogin are a TCP connection that the app makes with
Winsock. The app uses `dmc_net` of libdmodemctl for the protocol (sans-I/O,
as the session). SSH is libdmodemssh (`ssh/`), the client of D-Modem on
libssh 0.11. The Android and iOS apps use the same engine. Thus SSH is the
same on all platforms, and you do not need to install anything:
- One thread for each connection calls `dmc_ssh_poll()` and gives each event
to the thread of the UI. The UI sends typed text, the window size and the
answers directly to the connection (it locks).
- The app checks the key of the host against `known_hosts` of OpenSSH. If
the key is known, the login continues. If the key is new, the app shows it
(its SHA256 fingerprint) and adds it if the user accepts it. If the key
changed, the app refuses it with a warning.
- The login uses the order of OpenSSH: first the agent and the keys of
`~/.ssh`, then keyboard-interactive or a password (three tries), in the
dialogs of the app. The app reads `~/.ssh/config` (host aliases, users,
ports).
- Alternatively, you can select with Login... next to the server one of
these: the keys of
the agent only, or a key file. The key file can be in the format of
OpenSSH, PEM or the `.ppk` of PuTTY (versions 2 and 3). `ssh/src/ppk.c`
reads `.ppk` files, with Argon2, the same with each libssh build. The app
asks for the passphrase in its dialog. You can also import a `.ppk`. The
app writes it to `.ssh` in the OpenSSH format with the same passphrase,
and selects it.
- On Linux and macOS, the agent is the socket of an ssh-agent
(`SSH_AUTH_SOCK`, or a socket that you give, as `IdentityAgent`). On
Windows, it is the Pageant of PuTTY (the app asks it by WM_COPYDATA, as the
tools of PuTTY do). If Pageant is not available, it is the agent of OpenSSH
(`\\.\pipe\openssh-ssh-agent`), or a named pipe that you give.
`ssh/src/agent.c` connects libssh to those two agents with a pair of
loopback sockets and a thread.
- Ed25519, ECDSA and RSA keys. A shell on a pty with TERM `xterm-256color`.
The app sends the size of the pty when it changes. The engine also has
commands, direct channels (`-L`, `-D`), remote listens (`-R`), agent
channels (`-A`), and it can make keys or encrypt them again. The mobile
apps use these functions.
If the system has libssh 0.11 or later (Linux), libssh and mbedTLS come from
the system. If not, the build makes them from their release tarballs, and
checks them by hash (`ssh/cmake/BundledLibssh.cmake`). This always occurs on
Windows and macOS. A build with no libssh (`-DDMODEM_GUI_SSH=OFF`) runs the
`ssh.exe` of Windows (Windows 10 1809 and later) in a pseudo console, if it
finds it.
The Windows 95 build also has libssh. libssh and mbedTLS use some functions
that Windows 95 does not have. Thus the build changes them as follows
(`ssh/cmake/PatchMbedtls.cmake` and `PatchLibssh.cmake`, only for targets
before Windows Vista):
| Function | Windows that have it | In the Windows 95 build |
| --- | --- | --- |
| `BCryptGenRandom` (mbedTLS, the random numbers) | Vista and later | `CryptGenRandom` of CryptoAPI, found at run time. CryptoAPI is in Windows 95 OSR2, 98, NT 4.0 and later, and Internet Explorer 3 and later installs it. If CryptoAPI is not there, SSH cannot connect. The other pages operate |
| `SHGetSpecialFolderPathA` (libssh, the home folder) | 98, 2000, and 95 and NT 4.0 with the shell of Internet Explorer 4 | found at run time, else `USERPROFILE` |
| `if_nametoindex` (libssh, IPv6 link-local addresses) | Vista and later | found at run time, else no interface names |
| `WSAStringToAddressA` (libssh, the address check) | 98, and 95 with Winsock 2 | found at run time, else IPv4 with `inet_addr` of Winsock 1.1 |
| `gai_strerrorA` of mingw-w64 (it calls `FormatMessageW`) | NT | `ssh/src/gai_strerror.c`, with `FormatMessageA` |
Thus the app imports only DLLs that each Windows 95 has, as before. libssh
uses Winsock 1.1 (`wsock32`) for its sockets. `getaddrinfo` is the
`WspiapiGetAddrInfo` of mingw-w64, which uses `gethostbyname` if Winsock 2
is not there.
| | How the app does it |
| --- | --- |
| Telnet and rlogin | Winsock 1.1, `WSAAsyncSelect` (FD_OOB for rlogin), on all Windows versions from 95 |
| SSH | libdmodemssh on a thread, posted events (`WM_APP_SSH`), the `.ssh` of the profile |
| Kept in | `dmodem.ini`, `[remote]` |
The TERM of SSH and the terminal of rlogin come from the type of terminal
(`xterm-256color`, `vt220`, `ansi`, `petscii` ...). The TERMINAL-TYPE of
Telnet is a separate value
(`XTERM-256COLOR`, `DEC-VT220`, `ANSI` ...: `dmc_vt_profile_term`,
`dmc_vt_profile_telnet`).
Telnet tells the server the terminal type and the window size (NAWS). It
sends a typed CR as CR NUL. rlogin sends the user as the local name and as
the remote name. Some servers accept only a client port below 1024 (classic
BSD `rlogind`). These servers do not accept an unprivileged app, but BBSes
and most rlogin services accept it. Backspace sends DEL, as a host expects
(the console of the modem sends BS).
## Voice calls and the answering machine
Voice uses the V.253 voice mode of dmodemd: `AT+FCLASS=8`, `AT+VSM=4` (G.711
μ-law at 8 kHz), then `ATD` or `AT+VLS=1`, and `AT+VTR` for the full-duplex
stream. libdmodemctl does all of this work. It does the DLE framing and its
events (hangup, busy, dial tone, digits, caller ID), μ-law, the pacing of
the stream by the clock that the app gives to `dmc_poll`, DTMF, and the
answering machine. The app only moves 8 kHz 16-bit samples between the
library and the sound card (`dmc_voice_read`, `dmc_voice_write`):
| | How the app does it |
| --- | --- |
| Sound | `waveOut` and `waveIn` with window callbacks (Windows 95 has them). On Linux and macOS, the layer supplies them |
| Settings | `dmodem.ini`, `[voice]` |
| Messages | `Voicemail` in the settings folder (for example `%APPDATA%\D-Modem\Voicemail`), or next to the exe |
| Greeting files beyond the library's | the ACM codecs: MP3 and compressed WAVs (GSM 6.10 and the other installed codecs) |
The answering machine is disabled until you enable it. When it is enabled,
it answers after the selected number of rings (4 by default). It plays the
greeting (or no greeting) and a beep. Then it records until one of these
conditions occurs: the caller hangs up, 7 s of silence, or 2 minutes. Each
message is a WAV file. Its name is its time and the number of the caller.
The app deletes a message that is shorter than one second.
You can record a greeting from the microphone, or select a sound file. The
app converts the file to 8 kHz mono. The library itself reads WAV (8 to
32-bit PCM, floats, A-law, μ-law, IMA and Microsoft ADPCM), AIFF and AIFF-C,
and Sun/NeXT `.au` (`dmc_audio_decode`). The app gives all other files to
the ACM codecs, as the table shows. Pick Up changes a message
into a call while the caller leaves it. Listen plays the message while the
caller leaves it. Messages stay on this computer.
## Windows 95 and later
The Windows app is plain Win32 in C++98. Thus one binary runs from
Windows 95 to Windows 11:
- ANSI APIs. The app converts the UTF-8 from the library with its own code
(9x has no `CP_UTF8`). The terminal draws with `ExtTextOutW`, which 9x has.
- The Windows 95 common controls (tabs, list views, the status bar),
Winsock 1.1 (`wsock32`, `WSAAsyncSelect`) and the 4.0 `OPENFILENAME`.
- No `SetHandleInformation` (NT only). The app uses `DuplicateHandle` to
make the pipe from dmodemd non-inheritable.
- clang-retro builds the app (`cmake/clang-retro.cmake`, a CMake toolchain
file), as CI does. Its toolchain package comes from the
`clang-retro/dos-sdk/.github/actions/setup-toolchain` action, or from
`packaging/get-toolchain.sh` in that repository. `CLANG_DOS` is the
directory of the package. `CLANG_RETRO_CONFIG` is the `--config` file:
- `win32-picolibc` (the default): Windows 95, 98, ME, NT 4.0 and later.
picolibc is the C library, and it is linked into the app. Thus the app
needs no `msvcrt.dll`, which some installations of Windows 95 do not
have. This build has libssh too (see "Remote logins", above).
- `win7`: Windows 7 and later. This is the minimum Windows version of
dmodemd too.
- CI examines the imports of the Windows 95 build with `check-imports.py`
of clang-retro, for Windows 9x and for NT 4.0. The build fails if the app
uses a function that these versions do not have. CI also runs the tests
of the two builds in Wine.
- picolibc has no `_snprintf`, `_stricmp` or `_strnicmp`. `app.h` gives
these names to `snprintf`, `strcasecmp` and `strncasecmp`.
- MinGW and MSVC also build the same code with CMake.
The app has the modem built in on each Windows (refer to
[The built-in modem](embedded-modem.md)). It can also use a COM port, or
connect to a dmodemd on another machine through TCP.
## The Windows app on Linux and macOS
The Windows app also builds for Linux and macOS. clang-retro MFC has a
portable Win32 layer (`port/`, `libwinport.a`). The layer supplies the
Win32 API on X11, Wayland and Cocoa: windows and controls, Winsock,
files, COM ports, processes and pipes, and sound (`waveOut`, `waveIn`
and ACM). The app links with this layer and not with Windows. Its source
code is the same as on Windows.
- Use `-DDMODEM_GUI_WINPORT=ON` and set `CLANG_RETRO_MFC` to a checkout of
clang-retro MFC. Use clang. `winport/CMakeLists.txt` builds
`libwinport.a` with the Makefile of MFC. It converts `app.rc` to C++
with `port/tools/res2cpp.py` (this needs `llvm-rc`). The app is
`winport/dmodem-win32` in the build directory. `windows/sources.cmake`
is the list of sources for the two builds.
- `DMODEM_WINPORT` is defined for this build. The app uses it in these
locations only:
- The settings file is in the `CSIDL_APPDATA` folder of the layer
(`~/.config/D-Modem` on Linux, `~/Library/Application Support/D-Modem`
on macOS). On Windows, the app uses `APPDATA`, because Windows 95 has
no `SHGetFolderPath`.
- The line is dmodemd by default. The layer tells the app that Windows
is version 5, and on Windows the app then uses a COM port by default.
- dmodemd is `dmodemd` next to the app, or else on the `PATH`. The app
starts dmodemd only when the built-in modem is off (`builtin=0`).
- With the D-Modem submodule, the app has the built-in modem
(`DMODEM_GUI_EMBED`), as the Windows app on Windows has it. The layer's
`SOCKET` is a POSIX file descriptor, so `WSAAsyncSelect` works with the
socket that `libdmodem_embed` gives. The data file of the line is
`dmodem0.data` in the settings folder.
- SSH uses `~/.ssh` and `/` in paths, because libssh uses POSIX paths
on these systems.
- The layer changes a COM port name to a device. On Linux, `COM1` is
`/dev/ttyS0`. On macOS, `COM1` is the first `/dev/cu.*` device (in
alphabetical order, with no Bluetooth devices). To use another device,
set the environment variable `WINPORT_COMn`. For example, with
`WINPORT_COM5=/dev/ttyUSB0`, `COM5` is `/dev/ttyUSB0`.
- CI builds the app on Linux, on macOS for arm64 and x86_64, and on Linux for Mac OS X 10.4 (PowerPC and i386, `cmake/macosx-legacy.cmake`) and for Mac OS 9 (PowerPC, `cmake/macos9.cmake`). On Linux, `winport/test/smoke.sh`
starts the app in Xvfb three times: with a TCP line, with a dmodemd
that the app starts (`winport/test/dmodemd`, a test dmodemd), and with
the built-in modem on a SIP line with no account. For the first two,
the test makes sure that the app stays up and sends AT commands to a
test modem. For the third, the test makes sure that the app stays up
and that the built-in modem writes its data file. On Linux and macOS,
CI also makes sure that the built-in modem is in the app.
-80
View File
@@ -1,80 +0,0 @@
# Download
The [nightly release](https://github.com/D-Modem/gui/releases/tag/nightly)
has the app from the newest build of `main`. A workflow
(`.github/workflows/nightly.yml`) replaces the release one time each day.
When `main` has no new commits, the release does not change.
!!! warning "These builds are not stable releases"
The files are not signed. Thus Windows SmartScreen and macOS Gatekeeper
can show a warning before the app starts.
## Select a file
| System | File | What it is |
| --- | --- | --- |
| Windows 95, 98, ME, NT 4.0 and later | [`dmodem-win9x.exe`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win9x.exe) | The app with the built-in modem. It needs no C runtime DLL. Windows 95 needs Winsock 2. |
| Windows 98 SE, ME, 2000 and later | [`dmodem-win98.exe`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win98.exe) | The app with the built-in modem, on `msvcrt.dll`. |
| Windows 7 and later | [`dmodem-win7.exe`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win7.exe) | The app with the built-in modem. |
| Linux, x86_64 (X11) | [`dmodem-win32-linux-x86_64.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-linux-x86_64.tar.gz) | The app on Linux, with the built-in modem. |
| macOS, arm64 (Apple silicon) | [`dmodem-win32-macos-arm64.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macos-arm64.tar.gz) | The app on macOS, with the built-in modem. |
| macOS, x86_64 (Intel Mac) | [`dmodem-win32-macos-x86_64.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macos-x86_64.tar.gz) | The app on macOS, with the built-in modem. |
| Mac OS X 10.4 and later, PowerPC and Intel | [`dmodem-win32-macosx10.4.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macosx10.4.tar.gz) | The app with the built-in modem. One program for PowerPC (G3, G4, G5) and Intel (i386). It is not tested on a Mac yet. |
| Mac OS 9, PowerPC | [`dmodem-win32-macos9.bin`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macos9.bin) | The app with the built-in modem, in MacBinary format. It is not tested on a Mac yet. |
| All | [`SHA256SUMS`](https://github.com/D-Modem/gui/releases/download/nightly/SHA256SUMS) | The SHA-256 of each file. |
If a file is not in the release, the newest build did not make it. The
notes of the release list the files that are not there.
## Check a file
1. Download the file and `SHA256SUMS` into the same directory.
2. Open a terminal in this directory.
3. Type `sha256sum --check --ignore-missing SHA256SUMS`.
The result for the file must be `OK`.
## Install on Windows
1. Download the `.exe` file for your version of Windows.
2. Double-click the file. The app does not need an installer.
3. If Windows SmartScreen shows a warning, click **More info**, then
click **Run anyway**.
## Install on macOS
1. Download `dmodem-win32-macos-arm64.tar.gz` for a Mac with Apple
silicon, or `dmodem-win32-macos-x86_64.tar.gz` for an Intel Mac.
2. Extract the file. In a terminal, type
`tar -xzf dmodem-win32-macos-arm64.tar.gz` (or the name of the x86_64
file).
3. Remove the quarantine attribute. Type
`xattr -d com.apple.quarantine dmodem-win32`. The app is not notarized.
4. Start the app. Type `./dmodem-win32`.
## Install on Mac OS X 10.4 to 10.6
1. Download `dmodem-win32-macosx10.4.tar.gz`. The file is for PowerPC
Macs and for Intel Macs.
2. Extract the file. In Terminal, type
`tar -xzf dmodem-win32-macosx10.4.tar.gz`.
3. Start the app. Type `./dmodem-win32`.
## Install on Mac OS 9
1. Download `dmodem-win32-macos9.bin`. The file is for PowerPC Macs.
2. Decode the file with StuffIt Expander. The file is in MacBinary
format.
3. Double-click the app. The app needs 16 MB of memory.
## Install on Linux
1. Install the libraries. On Ubuntu 24.04, type
`sudo apt install libx11-6 libusb-1.0-0 libasound2t64`.
2. Download `dmodem-win32-linux-x86_64.tar.gz`.
3. Extract the file. Type `tar -xzf dmodem-win32-linux-x86_64.tar.gz`.
4. Start the app. Type `./dmodem-win32`.
## Build the app
To build the app from the source code, refer to [Building](building.md).
-103
View File
@@ -1,103 +0,0 @@
# The built-in modem
The app has the D-Modem modem in it, on Windows (Windows 95 and later),
on Linux and on macOS. Thus, the app does not need a separate `dmodemd`.
## What it does
The app uses `libdmodem_embed`, the library of `dmodemd` in the D-Modem
repository ([docs/embed.md](https://github.com/D-Modem/D-Modem/blob/main/docs/embed.md)).
1. When you click **Start**, the app starts the modem in a thread of the
app.
2. The library gives the app a socket. This socket is the DTE of the modem.
The app uses the socket as it uses the pty of `dmodemd`.
3. When you click **Stop**, the app hangs up the call and stops the thread.
The built-in modem has these lines: a SIP account (or no account), a USB
modem, and a softmodem codec (ALSA, Linux only). For "A modem that already runs", the
app opens the device and starts no modem.
## Differences from dmodemd
- There is no pty and no `/dev/ttyDM0` link. Other programs cannot use the
built-in modem. To share the modem with other programs, start `dmodemd`.
- The app does not need root or a pty (Linux and macOS), or a firewall
exception for a TCP port (Windows).
- A USB modem needs a udev rule that lets the user open the device.
- A softmodem codec needs the user in the `audio` group.
- The modem keeps the measurements of the line in
`~/.config/D-Modem/dmodem0.data` (Linux),
`~/Library/Application Support/D-Modem/dmodem0.data` (macOS), or
`%APPDATA%\D-Modem\dmodem0.data` (Windows).
- The **Log** page shows the log of the modem.
## How to use dmodemd
The Line Settings dialog does not have this setting yet. Close the app,
and add this line to the `[line]` section of the settings file:
builtin=0
The settings file is `%APPDATA%\D-Modem\dmodem.ini` (Windows),
`~/.config/D-Modem/dmodem.ini` (Linux) or
`~/Library/Application Support/D-Modem/dmodem.ini` (macOS).
The app then starts `dmodemd` as before.
## How to build it
The D-Modem source is a git submodule in `external/D-Modem`. To get it:
git submodule update --init
If the submodule is there, CMake builds the built-in modem
(`DMODEM_GUI_EMBED`, on by default) for the app on Windows with the
clang-retro configurations `win32-picolibc` (the Windows 95 build),
`win98`, `winme`, `win7` and later, and for the app on Linux and macOS
(`DMODEM_GUI_WINPORT`). To build the app with no built-in
modem, use `-DDMODEM_GUI_EMBED=OFF`. For a USB line and an ALSA line, also
install `libusb-1.0-0-dev` and `libasound2-dev`.
The first build downloads libre and Mbed TLS for the SIP line of the modem.
## Licence
D-Modem and the GUI are both under the AGPL-3.0-only, or a commercial
licence from the D-Modem Authors. Thus the two combine under each licence.
The built-in modem links libre (BSD-3-Clause), Mbed TLS (Apache-2.0), and
on Linux the libusb and ALSA libraries of the system (LGPL-2.1). On
Windows and macOS, the build links libusb (LGPL-2.1) statically, as
`dmodemd` does.
## Status
| System | Status |
| --- | --- |
| Windows 98 SE and later | Done (`win98` build). It builds, and its imports agree with Windows 98 SE. It is not tested on Windows or Wine yet. |
| Windows 7 and later | Done (`win7` build). It builds. It is not tested on Windows or Wine yet. |
| Windows 95, NT 4.0 and later | Done (`win32-picolibc` build). It builds, and its imports agree with Windows 95 and NT 4.0. It is not tested on Windows or Wine yet. Refer to "Windows 95" below. |
| Linux | Done. CI builds it, checks that the library is in the app, and starts the built-in modem in Xvfb (`winport/test/smoke.sh`). |
| macOS | Done (arm64 and x86_64). CI builds it for each architecture, and checks that the library is in the app. It is not tested on a Mac yet. |
| Mac OS X 10.4 and later | Done (PowerPC and i386, one fat program). CI builds it on Linux, and checks that the library is in each part of the program. It is not tested on a Mac yet. |
| Mac OS 9 (PowerPC) | Done. CI builds it on Linux with the C and C++ libraries of clang-retro/mac-sdk. There are no ptys: the modem gives its DTE on a socket. It is not tested on a Mac yet. |
### Windows 95
The Windows 95 build of the app uses the clang-retro configuration
`win32-picolibc`. Its C library is picolibc and its C++ library is libc++.
Both are linked into the app, so the app does not need `msvcrt.dll`. The
modem (C++17) builds with this configuration. D-Modem changes some names
of libre and of its own Windows code for picolibc (refer to
"picolibc" in D-Modem's `docs/windows-details.md`).
- On Windows 95, the app needs Winsock 2 (`ws2_32.dll`). Install the
Windows Socket 2 Update of Microsoft. The SSH page needs it too.
- The modem does not need `iphlpapi.dll`, which Windows 95 does not have.
libre finds `GetAdaptersInfo()` at run time.
- The `win98` build does not operate on Windows NT 4.0: its libraries use
`_vsnprintf_s` of msvcrt.dll, which NT 4.0 does not have. Use the
`win32-picolibc` build on NT 4.0.
On Windows, the modem gives the app a socket on the loopback interface
(`127.0.0.1`), because Windows does not have `socketpair()`.
-17
View File
@@ -1,17 +0,0 @@
# Features
This page gives the details of the pages and menus of the app. The
[README](../README.md) gives a summary.
- **Remote**: log in to a server by SSH, Telnet or rlogin, in a separate terminal. SSH is built in, on libssh: it uses the keys, agent, config and known hosts of OpenSSH. It can use or import the `.ppk` keys of PuTTY. It uses Pageant on Windows, and an ssh-agent on Linux and macOS. On Windows 95, SSH needs CryptoAPI (Windows 95 OSR2, or Internet Explorer 3 or later)
- **Terminal types**: the two terminals use the emulator of the D-Modem app, ported to C:
xterm, the VT52 to VT525 of DEC, ANSI-BBS (with Avatar, RIPscrip and Amiga ANSI),
the PETSCII of the Commodores, the ATASCII of the Atari 8-bit and the ST, Viewdata,
the Minitel and the Tektronix 4014. They have sixel, ReGIS and Tektronix
graphics, and the font of each machine (the SyncTERM copies of their ROMs,
LGPL-2.0-or-later: `core/licenses/syncterm-fonts-LGPL-2.0.txt`)
- **File transfers**: send and receive files on the modem line or on a Telnet, rlogin or SSH login. The protocols are the same as the D-Modem app: ZMODEM (with Automatic Receive when the remote side starts sz, rz or kermit -s, with Crash Recovery, and with zstd compression to the D-Modem BBS and app), YMODEM, YMODEM-G, XMODEM, XMODEM-1K, Kermit, Intel HEX, Motorola S-records and plain text. Use the Transfer menu, or the Send and Receive buttons of the Terminal page
- **Copy and capture**: select text with the mouse (Shift and the mouse when the remote side uses the mouse), then copy it. Paste to Host, Select All, Capture Text (to a file), Capture to Printer, and Print (the screen or the selection). Text that the remote side sends to its printer port goes to the printer. Use the Edit and Transfer menus, or click the right mouse button on the terminal
- **ASCII Setup** (Modem menu): the same items as HyperTerminal. For the data that you send: Enter sends CR LF, the local echo, and the line delay and character delay of a text file. For the data that you receive: an LF after each CR, 7-bit ASCII, and the wrap of long lines. The settings apply to the modem terminal and to the Remote terminal
- **Terminal Settings** (Modem menu): the same items as HyperTerminal, for the modem terminal and for the Remote terminal. They are what Backspace sends (Ctrl+H, Del, or Ctrl+H, Space, Ctrl+H), the function, arrow and Ctrl keys as terminal keys or Windows keys, the backscroll buffer lines, the font, the cursor, the Telnet terminal ID, and Exit program upon disconnecting. The status bar shows the connect timer during a call
- **Call menu**: Call (sessions with a name and a number, as the connection files of HyperTerminal), Wait for a Call (ATS0=1), Disconnect, and Send Break (Ctrl+Break: a COM port or a Telnet connection). Line Settings has the COM port settings: bits per second, data bits, parity, stop bits and flow control. **Look for a modem** finds the modem and selects its port (refer to "Look for a modem" in [Design](design.md))
Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

-15
View File
@@ -1,15 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 500 500">
<!-- D-Modem's mark (D-Modem/brand, avatar/org-avatar.svg) on a desktop tile -->
<defs>
<linearGradient id="books" gradientUnits="userSpaceOnUse" x1="0" y1="81" x2="0" y2="419"><stop offset="0.0000" stop-color="#ff4d5e"/><stop offset="0.1667" stop-color="#ff4d5e"/><stop offset="0.1667" stop-color="#ff8a3d"/><stop offset="0.3333" stop-color="#ff8a3d"/><stop offset="0.3333" stop-color="#ffd23d"/><stop offset="0.5000" stop-color="#ffd23d"/><stop offset="0.5000" stop-color="#3ddc84"/><stop offset="0.6667" stop-color="#3ddc84"/><stop offset="0.6667" stop-color="#3d8bff"/><stop offset="0.8333" stop-color="#3d8bff"/><stop offset="0.8333" stop-color="#a66bff"/><stop offset="1.0000" stop-color="#a66bff"/></linearGradient>
<filter id="glow" x="-30%" y="-30%" width="160%" height="160%">
<feGaussianBlur stdDeviation="6" result="b"/>
<feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
</defs>
<rect x="10" y="10" width="480" height="480" rx="108" fill="#0a0f1c"/>
<g transform="translate(-15 0)">
<path d="M140 100 H240 A150 150 0 0 1 240 400 H140 Z" fill="none" stroke="url(#books)" stroke-width="38" stroke-linejoin="round" filter="url(#glow)"/>
<path d="M178.0,250.0 L178.8,246.3 L179.5,242.7 L180.3,239.1 L181.1,235.5 L181.8,232.0 L182.6,228.6 L183.4,225.2 L184.1,222.0 L184.9,218.9 L185.7,215.9 L186.4,213.1 L187.2,210.4 L188.0,207.9 L188.7,205.6 L189.5,203.4 L190.3,201.5 L191.0,199.8 L191.8,198.3 L192.6,197.0 L193.3,195.9 L194.1,195.1 L194.9,194.5 L195.6,194.1 L196.4,194.0 L197.2,194.1 L197.9,194.5 L198.7,195.1 L199.5,195.9 L200.2,197.0 L201.0,198.3 L201.8,199.8 L202.5,201.5 L203.3,203.4 L204.1,205.6 L204.8,207.9 L205.6,210.4 L206.4,213.1 L207.1,215.9 L207.9,218.9 L208.7,222.0 L209.4,225.2 L210.2,228.6 L211.0,232.0 L211.7,235.5 L212.5,239.1 L213.3,242.7 L214.0,246.3 L214.8,250.0 L215.6,253.7 L216.3,257.3 L217.1,260.9 L217.9,264.5 L218.6,268.0 L219.4,271.4 L220.2,274.8 L220.9,278.0 L221.7,281.1 L222.5,284.1 L223.2,286.9 L224.0,289.6 L224.8,292.1 L225.5,294.4 L226.3,296.6 L227.1,298.5 L227.8,300.2 L228.6,301.7 L229.4,303.0 L230.1,304.1 L230.9,304.9 L231.7,305.5 L232.4,305.9 L233.2,306.0 L234.0,305.9 L234.7,305.5 L235.5,304.9 L236.3,304.1 L237.0,303.0 L237.8,301.7 L238.6,300.2 L239.3,298.5 L240.1,296.6 L240.9,294.4 L241.6,292.1 L242.4,289.6 L243.2,286.9 L243.9,284.1 L244.7,281.1 L245.5,278.0 L246.2,274.8 L247.0,271.4 L247.8,268.0 L248.5,264.5 L249.3,260.9 L250.1,257.3 L250.8,253.7 L251.6,250.0 L252.4,246.3 L253.1,242.7 L253.9,239.1 L254.7,235.5 L255.4,232.0 L256.2,228.6 L257.0,225.2 L257.7,222.0 L258.5,218.9 L259.3,215.9 L260.0,213.1 L260.8,210.4 L261.6,207.9 L262.3,205.6 L263.1,203.4 L263.9,201.5 L264.6,199.8 L265.4,198.3 L266.2,197.0 L266.9,195.9 L267.7,195.1 L268.5,194.5 L269.2,194.1 L270.0,194.0 H288.4 V306.0 H325.2 V194.0 H362.0" fill="none" stroke="#e8f0ff" stroke-width="16" stroke-linecap="round" stroke-linejoin="round"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

-124
View File
@@ -1,124 +0,0 @@
---
title: D-Modem desktop app
hide:
- navigation
- toc
---
<div class="suite-hero" markdown>
<img src="images/dmodem.svg" alt="">
<div markdown>
# D-Modem desktop app
**D-Modem on the desktop: a V.92 modem in a window, from Windows 95 to
Windows 11, on macOS and on Linux.**
The app has the modem built in. You do not need modem hardware or a
separate `dmodemd`. Dial a BBS, a fax machine or an ISP from a SIP call,
a USB modem or a hardware modem.
[Download the nightly build](download.md){ .md-button .md-button--primary }
[Source on GitHub](https://github.com/D-Modem/gui){ .md-button }
</div>
</div>
<img src="images/windows-settings.png" width="49%" alt="The Settings page of the app"> <img src="images/windows-setup-screen.png" width="49%" alt="The Terminal of the app with the setup screen of the modem">
## What the app does
<div class="grid cards" markdown>
- **Modem**
---
The state of the call. Dial, answer and hang up. Select the line that
the modem uses: a SIP account, a USB modem, or a modem that already
runs.
- **Phone**
---
Voice calls through the sound card, with a keypad. An answering machine
can take messages on this computer. It is disabled by default.
- **Terminal**
---
The AT console and the setup screens of the modem (`AT!CF`, `AT!CT`).
The emulator has xterm, DEC VT52 to VT525, ANSI-BBS, PETSCII, ATASCII,
Viewdata, Minitel and Tektronix 4014.
- **Remote**
---
Log in to a server by SSH, Telnet or rlogin. SSH is built in. It uses
the keys and the agent of OpenSSH and PuTTY.
- **Settings**
---
Each setting of the modem as a native control, from `AT!M`. You do not
have to type AT commands.
- **Call Stats**
---
The rate, the modulation, the error control and the line figures of
the last call (`AT#UD`, `ATI11`).
</div>
[All the features](features.md){ .md-button }
<img src="images/windows-modem.png" width="49%" alt="The Modem page of the app"> <img src="images/windows-phone.png" width="49%" alt="The Phone page of the app as it takes a message">
## One Win32 app, one library
The app is plain Win32, built with
[clang-retro](https://clang-retro.github.io/). The same Win32 code also
runs on Linux and macOS, over the portable Win32 layer of
[clang-retro MFC](https://github.com/clang-retro/mfc). The app is a thin
shell over one small C library, libdmodemctl. Thus it operates in the
same way on each system.
| | Windows | macOS | Linux |
| --- | --- | --- | --- |
| Toolkit | Win32, C++ | Win32, over the Cocoa layer of clang-retro MFC | Win32, over the X11 and Wayland layer of clang-retro MFC |
| Runs on | Windows 95 and later | arm64 (Apple silicon) and x86_64 (Intel Mac). Also Mac OS X 10.4 and later on PowerPC and i386, and Mac OS 9 on PowerPC | x86_64 |
| Built-in modem | Yes | Yes | Yes |
Refer to [Design](design.md).
## Start here
- **Use the app:** [download the nightly build](download.md) for your
system.
- **Build the app:** refer to [Building](building.md).
- **Use the modem without dmodemd:** refer to
[The built-in modem](embedded-modem.md).
- **Learn how the app is built:** refer to [Design](design.md) and to
the API of [libdmodemctl](https://github.com/D-Modem/gui/blob/main/core/include/dmodemctl.h).
## Part of the D-Modem suite
The desktop app is one part of the [D-Modem suite](https://d-modem.github.io/).
The suite has the softmodem ([D-Modem](https://d-modem.github.io/D-Modem/)),
the [app for Android and iOS](https://d-modem.github.io/app/), the
[pico-serial boards](https://d-modem.github.io/hardware/), and the
servers that answer callers ([login](https://d-modem.github.io/login/) and
[bbs](https://d-modem.github.io/bbs/)).
## Licence
AGPL-3.0-only ([LICENSE](../LICENSE)), or a commercial licence from the
D-Modem Authors ([COMMERCIAL-LICENSE.md](../COMMERCIAL-LICENSE.md)).
Contributions come with a contributor agreement
([CONTRIBUTING.md](../CONTRIBUTING.md)).
-1
Submodule external/D-Modem deleted from 351268cd9c.
-32
View File
@@ -1,32 +0,0 @@
# The firmware of the MultiTech modems
| File | For | Size (octets) | SHA-1 | License | Source |
|---|---|---|---|---|---|
| mts_mt9234mu.fw | MultiTech MT9234MU and MT9234ZBA-USB (TI TUSB3410) | 13769 | `5537e93217c509129d5a870b9fe089cd58647070` | unknown | linux-firmware, before June 2026 (`WHENCE`: "Multi-Tech USB fax modems", "Licence: Unknown") |
The TUSB3410 of these modems has no firmware of its own. The
`ti_usb_3410_5052` driver of Linux downloads this file into the chip each
time you connect the modem. The driver looks for the file in
`/lib/firmware`. The MT9234ZBA-USB uses the name `mts_mt9234zba.fw` for the
same code.
To install it:
sudo cp firmware/mts_mt9234mu.fw /lib/firmware/
sudo cp firmware/mts_mt9234mu.fw /lib/firmware/mts_mt9234zba.fw
Then disconnect the modem and connect it again. `cmake --install` puts the
file in `share/dmodem-gui/firmware`. With `-DDMODEM_GUI_INSTALL_FIRMWARE=ON`,
it also puts the file in `/lib/firmware`.
Multi-Tech Systems, Inc. gave this file to the Linux kernel in 2010. The
file is TI's TUSB3410 UART firmware, compiled again by MultiTech with some
changes. The file has no copyright text and no license text. MultiTech did
not publish a license for it. In June 2026, linux-firmware removed it with
the other files that have an unknown license.
We include the file so that the modem operates without a search for it. The
AGPL-3.0 license of D-Modem and the commercial license do not apply to this
file. Multi-Tech Systems, Inc. and Texas Instruments keep their rights in it.
If you are the holder of these rights and you do not agree, tell us and we
will remove the file.
Binary file not shown.
-22
View File
@@ -1,22 +0,0 @@
INHERIT: .site/mkdocs-base.yml
# The gui site, https://d-modem.github.io/gui/: docs/ with brand's shared
# theme and workflow (brand's docs/sites.md). The site is built from a copy
# of docs/ (.site/docs). docs/index.md is the home page of the site, and the
# README stays the summary on GitHub.
site_name: D-Modem desktop app
site_description: D-Modem on the desktop, for Windows 95 to Windows 11, macOS and Linux
site_url: https://d-modem.github.io/gui/
repo_url: https://github.com/D-Modem/gui
repo_name: D-Modem/gui
docs_dir: .site/docs
extra:
repo: gui
nav:
- Home: index.md
- Download: download.md
- Features: features.md
- The built-in modem: embedded-modem.md
- Building: building.md
- Design: design.md
- "libdmodemctl API": https://github.com/D-Modem/gui/blob/main/core/include/dmodemctl.h
- Documentation style: STYLE.md
-52
View File
@@ -1,52 +0,0 @@
# libdmodemssh: D-Modem's SSH client (dmodemssh.h), on libssh 0.11.
# The system's libssh when it is 0.11 or later (and
# -DDMODEM_SSH_BUNDLED=OFF), else libssh and mbedTLS built here from
# their release tarballs: always for the app on Windows and macOS, which
# ships no libraries of the system's.
if(WIN32 OR APPLE)
set(_bundled ON)
else()
set(_bundled AUTO)
endif()
set(DMODEM_SSH_BUNDLED ${_bundled} CACHE STRING "Build libssh and mbedTLS from source (ON, OFF, AUTO: when the system's is older than 0.11)")
if(NOT DMODEM_SSH_BUNDLED STREQUAL "ON")
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(LIBSSH IMPORTED_TARGET libssh>=0.11)
endif()
endif()
if(LIBSSH_FOUND)
add_library(dmodem_libssh INTERFACE)
target_link_libraries(dmodem_libssh INTERFACE PkgConfig::LIBSSH)
elseif(DMODEM_SSH_BUNDLED STREQUAL "OFF")
message(FATAL_ERROR "libssh 0.11 or later not found (or -DDMODEM_SSH_BUNDLED=AUTO)")
else()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/BundledLibssh.cmake)
endif()
add_library(dmodemssh STATIC src/dmodemssh.c src/ppk.c src/agent.c)
# (the Windows 95 build, and the Windows 98 SE and ME builds of the app
# with the modem built in: a gai_strerrorA with no Unicode call)
if(CLANG_RETRO_CONFIG MATCHES "picolibc|^win98|^winme")
target_sources(dmodemssh PRIVATE src/gai_strerror.c)
endif()
target_include_directories(dmodemssh PUBLIC include)
target_link_libraries(dmodemssh PUBLIC dmodem_libssh)
if(WIN32)
target_link_libraries(dmodemssh PUBLIC ws2_32 user32 advapi32)
elseif(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(dmodemssh PUBLIC Threads::Threads)
endif()
if(MSVC)
target_compile_options(dmodemssh PRIVATE /W4 /wd4996)
else()
target_compile_options(dmodemssh PRIVATE -Wall -Wextra -Wshadow)
endif()
add_executable(dmodemssh_test test/dmodemssh_test.c)
target_link_libraries(dmodemssh_test PRIVATE dmodemssh)
# (Argon2 is tested too: ppk.h)
target_include_directories(dmodemssh_test PRIVATE src)
add_test(NAME dmodemssh COMMAND dmodemssh_test)
-131
View File
@@ -1,131 +0,0 @@
# libssh on mbedTLS, both static, built from their release tarballs
# (checked by hash), as the target dmodem_libssh.
include(FetchContent)
include(ExternalProject)
set(DMODEM_MBEDTLS_URL https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-3.6.7/mbedtls-3.6.7.tar.bz2)
set(DMODEM_MBEDTLS_SHA256 a7e8bcbec0e6f761b4af24f25677626b35f762f68eef79c08677a363212d11f6)
set(DMODEM_LIBSSH_URL https://www.libssh.org/files/0.11/libssh-0.11.3.tar.xz)
set(DMODEM_LIBSSH_SHA256 7d8a1361bb094ec3f511964e78a5a4dba689b5986e112afabe4f4d0d6c6125c3)
set(_prefix ${CMAKE_BINARY_DIR}/dmodem-libssh)
set(_args
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${_prefix}
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT})
# (a toolchain file names the compiler itself)
if(CMAKE_TOOLCHAIN_FILE)
list(APPEND _args -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
else()
list(APPEND _args -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER})
endif()
# (cmake/clang-retro.cmake)
if(CLANG_DOS)
list(APPEND _args -DCLANG_DOS=${CLANG_DOS} -DCLANG_RETRO_CONFIG=${CLANG_RETRO_CONFIG})
endif()
# (cmake/macosx-legacy.cmake)
if(MACOSX_LEGACY_TARGET)
foreach(_v MACOSX_LEGACY_ARCH MACOSX_LEGACY_LLVM MACOSX_LEGACY_SYSROOT
MACOSX_LEGACY_CCTOOLS CLANG_RETRO_MFC)
list(APPEND _args -D${_v}=${${_v}})
endforeach()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND _args -DCMAKE_SYSTEM_NAME=iOS)
endif()
if(ANDROID)
list(APPEND _args -DANDROID_ABI=${ANDROID_ABI} -DANDROID_PLATFORM=${ANDROID_PLATFORM})
endif()
if(CMAKE_MAKE_PROGRAM)
list(APPEND _args -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM})
endif()
string(REPLACE ";" "|" _archs "${CMAKE_OSX_ARCHITECTURES}")
list(TRANSFORM _args REPLACE "^-DCMAKE_OSX_ARCHITECTURES=.*" "-DCMAKE_OSX_ARCHITECTURES=${_archs}")
if(WIN32)
set(_mbed_libs mbedcrypto.lib mbedx509.lib mbedtls.lib everest.lib p256m.lib)
set(_ssh_lib ssh.lib)
if(MINGW)
set(_mbed_libs libmbedcrypto.a libmbedx509.a libmbedtls.a libeverest.a libp256m.a)
set(_ssh_lib libssh.a)
endif()
else()
set(_mbed_libs libmbedcrypto.a libmbedx509.a libmbedtls.a libeverest.a libp256m.a)
set(_ssh_lib libssh.a)
endif()
list(TRANSFORM _mbed_libs PREPEND ${_prefix}/lib/ OUTPUT_VARIABLE _mbed_paths)
ExternalProject_Add(dmodem_mbedtls
URL ${DMODEM_MBEDTLS_URL}
URL_HASH SHA256=${DMODEM_MBEDTLS_SHA256}
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/PatchMbedtls.cmake
LIST_SEPARATOR |
CMAKE_ARGS ${_args} -DENABLE_TESTING=OFF -DENABLE_PROGRAMS=OFF
-DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DMBEDTLS_FATAL_WARNINGS=OFF
BUILD_BYPRODUCTS ${_mbed_paths})
# libssh's sha1() and sha256() renamed: libre (in the modem built in,
# DMODEM_GUI_EMBED) has functions of the same names
set(_ssh_args)
set(_ssh_cflags "-Dsha1=dmodem_ssh_sha1 -Dsha256=dmodem_ssh_sha256")
# (Bionic has no S_IWRITE, the old name libssh uses)
if(ANDROID)
string(APPEND _ssh_cflags " -DS_IWRITE=S_IWUSR")
endif()
# clang-retro (cmake/clang-retro.cmake): its clang, newer than MinGW's
# GCC, makes an error of src/threads/mbedtls.c's casts of libssh's mutex
# callbacks. With picolibc (the Windows 95 build): strdup and
# explicit_bzero need _DEFAULT_SOURCE, and strerror_s needs
# __STDC_WANT_LIB_EXT1__; it has no <direct.h> (picolibc/direct.h here);
# its <io.h> and <termios.h> are not those that libssh expects on
# Windows, and its <arpa/inet.h> conflicts with <winsock2.h>, so libssh
# uses none of them.
if(CLANG_DOS)
string(APPEND _ssh_cflags " -Wno-error=incompatible-function-pointer-types")
if(CLANG_RETRO_CONFIG MATCHES "picolibc")
string(APPEND _ssh_cflags " -D_DEFAULT_SOURCE -D__STDC_WANT_LIB_EXT1__=1 -I${CMAKE_CURRENT_LIST_DIR}/picolibc")
list(APPEND _ssh_args -DHAVE_ARPA_INET_H= -DHAVE_IO_H= -DHAVE_TERMIOS_H=)
endif()
endif()
list(APPEND _ssh_args "-DCMAKE_C_FLAGS=${_ssh_cflags}")
# (WITH_SERVER: libssh runs a client's callbacks for the channels the
# server opens, the forwarded agent's, only when it's built with it)
ExternalProject_Add(dmodem_libssh_build
URL ${DMODEM_LIBSSH_URL}
URL_HASH SHA256=${DMODEM_LIBSSH_SHA256}
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
DEPENDS dmodem_mbedtls
PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/PatchLibssh.cmake
LIST_SEPARATOR |
CMAKE_ARGS ${_args} ${_ssh_args} -DBUILD_SHARED_LIBS=OFF
-DWITH_MBEDTLS=ON -DMBEDTLS_ROOT_DIR=${_prefix}
-DCMAKE_PREFIX_PATH=${_prefix} -DCMAKE_FIND_ROOT_PATH=${_prefix}
-DWITH_ZLIB=OFF -DWITH_GSSAPI=OFF -DWITH_SERVER=ON
-DWITH_EXAMPLES=OFF -DUNIT_TESTING=OFF -DCLIENT_TESTING=OFF
-DWITH_NACL=OFF -DWITH_SYMBOL_VERSIONING=OFF
BUILD_BYPRODUCTS ${_prefix}/lib/${_ssh_lib})
file(MAKE_DIRECTORY ${_prefix}/include)
add_library(dmodem_libssh INTERFACE)
add_dependencies(dmodem_libssh dmodem_libssh_build)
target_include_directories(dmodem_libssh INTERFACE ${_prefix}/include)
target_compile_definitions(dmodem_libssh INTERFACE LIBSSH_STATIC=1)
target_link_libraries(dmodem_libssh INTERFACE ${_prefix}/lib/${_ssh_lib} ${_mbed_paths})
if(WIN32)
target_link_libraries(dmodem_libssh INTERFACE ws2_32 iphlpapi bcrypt shell32 advapi32)
# (MinGW's libssh locks with winpthreads; clang-retro's sysroots have
# none, and there libssh locks with Win32's own)
if(MINGW AND NOT CLANG_DOS)
target_link_libraries(dmodem_libssh INTERFACE pthread)
endif()
elseif(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(dmodem_libssh INTERFACE Threads::Threads)
endif()
-152
View File
@@ -1,152 +0,0 @@
# libssh's remote listen on port 0 told the port the server picked from
# its own reply: libssh reads it from whatever packet came in last, which
# is often another one (its own "FIXME"), and then fails a listen that
# the server took. The reply's port kept in the session as it comes.
# Run in libssh's source tree by BundledLibssh.cmake.
# (a replace that must take: else this libssh isn't the one patched for)
function(dmodem_patch file from to)
file(READ ${file} _text)
string(FIND "${_text}" "${to}" _done)
if(_done GREATER -1)
return()
endif()
string(FIND "${_text}" "${from}" _at)
if(_at LESS 0)
message(FATAL_ERROR "PatchLibssh: ${file} isn't as expected")
endif()
string(REPLACE "${from}" "${to}" _text "${_text}")
file(WRITE ${file} "${_text}")
endfunction()
dmodem_patch(include/libssh/session.h
" enum ssh_channel_request_state_e global_req_state;"
" enum ssh_channel_request_state_e global_req_state;
/* D-Modem: bound port, from a global request's success */
int dmodem_bound_port;")
dmodem_patch(src/channels.c
" } else {
session->global_req_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
}"
" } else {
/* D-Modem: bound port */
uint32_t bound = 0;
session->global_req_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
session->dmodem_bound_port =
ssh_buffer_unpack(packet, \"d\", &bound) == SSH_OK ? (int)bound : 0;
}")
dmodem_patch(src/channels.c
" if (rc == SSH_OK && port == 0 && bound_port != NULL) {
rc = ssh_buffer_unpack(session->in_buffer, \"d\", bound_port);
if (rc != SSH_OK)
*bound_port = 0;
}"
" if (rc == SSH_OK && port == 0 && bound_port != NULL) {
/* D-Modem: bound port, as the success packet had it */
*bound_port = session->dmodem_bound_port;
}")
# Windows before Vista (the Windows 95 build of clang-retro): misc.c's
# SHGetSpecialFolderPathA (95 and NT 4.0 have it only with the shell of
# Internet Explorer 4), if_nametoindex (Vista) and WSAStringToAddressA
# (Winsock 2, which the first Windows 95 does not have) found at run
# time, so that the app also starts where they are not there.
dmodem_patch(src/misc.c
"#include <netioapi.h>
"
"#include <netioapi.h>
/* D-Modem: functions found at run time before Vista */
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
static FARPROC dmodem_proc(const char *dll, const char *name)
{
HMODULE lib = GetModuleHandleA(dll);
if (lib == NULL) {
lib = LoadLibraryA(dll);
}
return lib != NULL ? GetProcAddress(lib, name) : NULL;
}
/* (no SHGetSpecialFolderPathA: USERPROFILE, which NT 4.0 has) */
static BOOL dmodem_profile_dir(char *dir)
{
typedef BOOL (WINAPI *fn_t)(HWND, LPSTR, int, BOOL);
fn_t fn = (fn_t) (void (*)(void))
dmodem_proc(\"shell32.dll\", \"SHGetSpecialFolderPathA\");
const char *env;
if (fn != NULL && fn(NULL, dir, CSIDL_PROFILE, TRUE)) {
return TRUE;
}
env = getenv(\"USERPROFILE\");
if (env != NULL && *env != '\\0' && strlen(env) < PATH_MAX) {
strcpy(dir, env);
return TRUE;
}
return FALSE;
}
/* (no if_nametoindex: no interface names) */
static ULONG dmodem_if_nametoindex(const char *name)
{
typedef ULONG (WINAPI *fn_t)(PCSTR);
fn_t fn = (fn_t) (void (*)(void))
dmodem_proc(\"iphlpapi.dll\", \"if_nametoindex\");
return fn != NULL ? fn(name) : 0;
}
/* (no Winsock 2: IPv4 alone, by inet_addr of Winsock 1.1) */
static INT dmodem_WSAStringToAddressA(LPSTR str, INT family,
LPWSAPROTOCOL_INFOA info,
LPSOCKADDR addr, LPINT len)
{
typedef INT (WSAAPI *fn_t)(LPSTR, INT, LPWSAPROTOCOL_INFOA, LPSOCKADDR,
LPINT);
fn_t fn = (fn_t) (void (*)(void))
dmodem_proc(\"ws2_32.dll\", \"WSAStringToAddressA\");
struct sockaddr_in *sin = (struct sockaddr_in *) addr;
unsigned long a;
if (fn != NULL) {
return fn(str, family, info, addr, len);
}
if (family != AF_INET || *len < (INT) sizeof(*sin)) {
return SOCKET_ERROR;
}
a = inet_addr(str);
if (a == INADDR_NONE && strcmp(str, \"255.255.255.255\") != 0) {
return SOCKET_ERROR;
}
memset(sin, 0, sizeof(*sin));
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = a;
*len = sizeof(*sin);
return 0;
}
#else
#define dmodem_profile_dir(dir) SHGetSpecialFolderPathA(NULL, (dir), CSIDL_PROFILE, TRUE)
#define dmodem_if_nametoindex if_nametoindex
#define dmodem_WSAStringToAddressA WSAStringToAddressA
#endif
")
dmodem_patch(src/misc.c
" if (SHGetSpecialFolderPathA(NULL, tmp, CSIDL_PROFILE, TRUE)) {"
" if (dmodem_profile_dir(tmp)) {")
dmodem_patch(src/misc.c
"rc = if_nametoindex(network_interface + 1);"
"rc = dmodem_if_nametoindex(network_interface + 1);")
dmodem_patch(src/misc.c
"rc = WSAStringToAddressA((LPSTR) "
"rc = dmodem_WSAStringToAddressA((LPSTR) ")
# (the other ssh_is_ipaddr, for systems other than Windows, keeps its own)
dmodem_patch(src/misc.c
"#else /* _WIN32 */
"
"#else /* _WIN32 */
#define dmodem_if_nametoindex if_nametoindex /* D-Modem */
")
-106
View File
@@ -1,106 +0,0 @@
# mbedTLS's config with threading on, as libssh wants it: its own
# pthread mutexes, or (Windows) libssh's given through threading_alt.h.
# Run in mbedTLS's source tree by BundledLibssh.cmake.
set(_config include/mbedtls/mbedtls_config.h)
file(READ ${_config} _text)
if(NOT _text MATCHES "D-Modem: threading")
file(APPEND ${_config} "
/* D-Modem: threading, for libssh */
#define MBEDTLS_THREADING_C
#if defined(_WIN32)
#define MBEDTLS_THREADING_ALT
#else
#define MBEDTLS_THREADING_PTHREAD
#endif
")
endif()
file(WRITE include/mbedtls/threading_alt.h "/* D-Modem: libssh's mutexes (a pointer each) */
#ifndef DMODEM_THREADING_ALT_H
#define DMODEM_THREADING_ALT_H
typedef struct mbedtls_threading_mutex_t {
void *mutex;
} mbedtls_threading_mutex_t;
#endif
")
# Windows before Vista (the Windows 95 build of clang-retro): BCryptGenRandom
# is not there. The entropy comes from CryptGenRandom of CryptoAPI, found
# at run time, so that the app also starts on a Windows 95 without
# CryptoAPI (then SSH alone fails: no entropy source).
set(_poll library/entropy_poll.c)
file(READ ${_poll} _text)
if(NOT _text MATCHES "D-Modem: CryptGenRandom")
set(_old "#include <windows.h>\n#include <bcrypt.h>\n#include <intsafe.h>\n")
set(_new "#include <windows.h>\n
/* D-Modem: CryptGenRandom before Vista, found at run time */
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
#include <wincrypt.h>
typedef BOOL (WINAPI *dmodem_acquire_fn)(HCRYPTPROV *, LPCSTR, LPCSTR,
DWORD, DWORD);
typedef BOOL (WINAPI *dmodem_gen_random_fn)(HCRYPTPROV, DWORD, BYTE *);
typedef BOOL (WINAPI *dmodem_release_fn)(HCRYPTPROV, DWORD);
int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
size_t *olen)
{
HMODULE lib;
dmodem_acquire_fn acquire;
dmodem_gen_random_fn gen_random;
dmodem_release_fn release;
HCRYPTPROV prov;
BOOL ok;
((void) data);
*olen = 0;
lib = LoadLibraryA(\"advapi32.dll\");
if (lib == NULL) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
acquire = (dmodem_acquire_fn) (void (*)(void))
GetProcAddress(lib, \"CryptAcquireContextA\");
gen_random = (dmodem_gen_random_fn) (void (*)(void))
GetProcAddress(lib, \"CryptGenRandom\");
release = (dmodem_release_fn) (void (*)(void))
GetProcAddress(lib, \"CryptReleaseContext\");
if (acquire == NULL || gen_random == NULL || release == NULL ||
len > 0xffffffffu ||
!acquire(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
ok = gen_random(prov, (DWORD) len, output);
release(prov, 0);
if (!ok) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
*olen = len;
return 0;
}
#else /* D-Modem: BCryptGenRandom */
#include <bcrypt.h>
#include <intsafe.h>
")
string(FIND "${_text}" "${_old}" _at)
if(_at LESS 0)
message(FATAL_ERROR "PatchMbedtls: entropy_poll.c has changed")
endif()
string(REPLACE "${_old}" "${_new}" _text "${_text}")
string(REPLACE "#else /* _WIN32 && !EFIX64 && !EFI32 */"
"#endif /* D-Modem: BCryptGenRandom */\n#else /* _WIN32 && !EFIX64 && !EFI32 */"
_text "${_text}")
file(WRITE ${_poll} "${_text}")
endif()
# picolibc (the Windows 95 build): it has gmtime_r and not the gmtime_s of
# Microsoft, and memset_s only when <string.h> sees __STDC_WANT_LIB_EXT1__
set(_util library/platform_util.c)
file(READ ${_util} _text)
if(NOT _text MATCHES "__PICOLIBC__")
string(REPLACE "#if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME)\n"
"#if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME) && !defined(__PICOLIBC__)\n"
_text "${_text}")
string(REPLACE "#elif defined(__STDC_LIB_EXT1__) && !defined(__IAR_SYSTEMS_ICC__)\n"
"#elif defined(__STDC_LIB_EXT1__) && !defined(__IAR_SYSTEMS_ICC__) && !defined(__PICOLIBC__)\n"
_text "${_text}")
file(WRITE ${_util} "${_text}")
endif()
-18
View File
@@ -1,18 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* direct.h - for libssh on picolibc (the Windows 95 build of clang-retro),
* which has no <direct.h>: the names of Microsoft's C library
* that libssh's misc.c uses, as picolibc's POSIX functions.
*/
#ifndef DMODEM_PICOLIBC_DIRECT_H
#define DMODEM_PICOLIBC_DIRECT_H
#include <unistd.h>
#include <sys/stat.h>
#define _mkdir(path) mkdir((path), 0700)
#define _access access
#define _stat stat
#define _S_IFDIR S_IFDIR
#define _S_IWRITE S_IWUSR
#endif
-193
View File
@@ -1,193 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* dmodemssh.h - D-Modem's SSH client, on libssh: the one engine every
* app has (the desktops', iOS's, and Android's through JNI), so that
* each has the same SSH.
*
* A connection (dmc_ssh) is driven by one thread that calls
* dmc_ssh_poll() in a loop and acts on the events it hands back: the
* server's key to trust or not, a login method to choose, a
* keyboard-interactive round to answer, a channel's data. Every other
* call may come from any thread (a lock is taken): what is typed, a
* window's new size, the answers.
*
* What it has: host keys checked by the caller (and in OpenSSH's
* known_hosts when asked); logins by password, keyboard-interactive, a
* private key (OpenSSH's, PEM or PuTTY's .ppk), an agent (ssh-agent's
* socket; on Windows Pageant or OpenSSH's), or OpenSSH's own keys and
* agent at once (ssh's default); ~/.ssh/config when asked; Ed25519,
* ECDSA and RSA keys; a shell on a pty, a command, direct TCP channels
* (ssh -L and -D), remote listens (ssh -R) and the server's
* agent channels (ssh -A) handed to the caller as channels.
*
* This file and dmodemssh.c are the same in D-Modem/gui (ssh/) and
* D-Modem/app (native-ssh/): change both.
*/
#ifndef DMODEMSSH_H
#define DMODEMSSH_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct dmc_ssh dmc_ssh;
/* what dmc_ssh_poll() hands back */
enum {
DMC_SSH_EV_HOSTKEY = 1, /* the server's key: data is its OpenSSH line
("ssh-ed25519 AAAA..."), value a
DMC_SSH_HOST_*; answer dmc_ssh_trust() */
DMC_SSH_EV_AUTH, /* a login method wanted: value is the
DMC_SSH_AUTH_* the server takes, data why
the last failed ("" the first time);
answer one dmc_ssh_auth_*() */
DMC_SSH_EV_PROMPTS, /* the server's questions (keyboard-
interactive): value how many, data the
round's name; read them with
dmc_ssh_prompt(), answer each with
dmc_ssh_answer(), then dmc_ssh_answered() */
DMC_SSH_EV_READY, /* logged in: data the server's banner, if any */
DMC_SSH_EV_OPEN, /* a channel opened (value 1) or refused
(value 0, data why) */
DMC_SSH_EV_DATA, /* a channel's data (value 1: its stderr) */
DMC_SSH_EV_EOF, /* a channel's end of data */
DMC_SSH_EV_EXIT, /* a command's exit status (value), or the
signal that ended it (data) */
DMC_SSH_EV_CLOSE, /* a channel closed: its number is free */
DMC_SSH_EV_INCOMING, /* a channel the server opened, open now:
value DMC_SSH_IN_AGENT, or the remote
listen's port (data: who connected) */
DMC_SSH_EV_LISTEN, /* a remote listen (channel: its request's
number) answered: value the port bound,
-1 refused */
DMC_SSH_EV_CLOSED /* the connection over: data why (NULL when
dmc_ssh_disconnect() asked) */
};
typedef struct dmc_ssh_event {
int type;
int channel; /* the channel it's about (1 and up), or 0 */
int value;
const char *data; /* until the next dmc_ssh_poll() */
int len;
} dmc_ssh_event;
/* the server's key against OpenSSH's known_hosts (when the
"knownhosts" option was given) */
enum {
DMC_SSH_HOST_UNCHECKED = 0, DMC_SSH_HOST_KNOWN, DMC_SSH_HOST_NEW,
DMC_SSH_HOST_CHANGED, DMC_SSH_HOST_OTHER_TYPE
};
/* the login methods the server takes */
enum {
DMC_SSH_AUTH_PASSWORD = 1, DMC_SSH_AUTH_PUBLICKEY = 2,
DMC_SSH_AUTH_INTERACTIVE = 4
};
/* a server-opened channel that is the agent's (ssh -A) */
enum { DMC_SSH_IN_AGENT = -1 };
/* a connection to make to user@host:port (nothing done until polled) */
dmc_ssh *dmc_ssh_new(const char *host, int port, const char *user);
/* the connection dropped (if it's up) and freed */
void dmc_ssh_free(dmc_ssh *s);
/* an option, before the first poll: 0, or -1 if it's not one.
"config" OpenSSH's config read (a path; "" its own ~/.ssh/config)
"knownhosts" the host's key looked up there (a path; "" OpenSSH's)
"hostkeys" the host key algorithms, in order (a list with commas)
"timeout" seconds to connect in
"compression" "yes" or "no"
"agent" the agent logged in with: a socket (Linux, macOS; ""
SSH_AUTH_SOCK's); on Windows "pageant", a named pipe,
or "" for Pageant and else OpenSSH's */
int dmc_ssh_option(dmc_ssh *s, const char *name, const char *value);
/* the next event: 1 (in *ev), 0 when timeout_ms passed with none, -1
when the connection is over and its DMC_SSH_EV_CLOSED was handed back */
int dmc_ssh_poll(dmc_ssh *s, int timeout_ms, dmc_ssh_event *ev);
/* the connection closed by the user: a DMC_SSH_EV_CLOSED with NULL comes */
void dmc_ssh_disconnect(dmc_ssh *s);
/* the server's key: trusted (ok) or not; remember: added to known_hosts */
void dmc_ssh_trust(dmc_ssh *s, int ok, int remember);
/* a login tried (an answer to DMC_SSH_EV_AUTH) */
void dmc_ssh_auth_password(dmc_ssh *s, const char *password);
/* by a private key's text (OpenSSH's, PEM or PuTTY's .ppk): 0, or -1 when it can't be
read with that passphrase (nothing is tried: answer again) */
int dmc_ssh_auth_key(dmc_ssh *s, const char *key, const char *passphrase);
/* by the agent: the "agent" option's, else the system's (SSH_AUTH_SOCK;
on Windows Pageant, else OpenSSH's) */
void dmc_ssh_auth_agent(dmc_ssh *s);
/* whether that agent is there to answer (agent as the "agent" option):
1 or 0 */
int dmc_ssh_agent_reachable(const char *agent);
/* as OpenSSH's ssh does: the agent, then ~/.ssh's keys with no passphrase */
void dmc_ssh_auth_auto(dmc_ssh *s);
/* by the server's questions (keyboard-interactive) */
void dmc_ssh_auth_interactive(dmc_ssh *s);
/* no more tries: the connection closes, "not logged in" */
void dmc_ssh_auth_cancel(dmc_ssh *s);
/* a DMC_SSH_EV_PROMPTS round: its instruction, and question i (*echo:
whether the answer may be shown) */
const char *dmc_ssh_instruction(dmc_ssh *s);
const char *dmc_ssh_prompt(dmc_ssh *s, int i, int *echo);
void dmc_ssh_answer(dmc_ssh *s, int i, const char *answer);
void dmc_ssh_answered(dmc_ssh *s);
/* channels, once ready: each a number (1 and up), or -1; a
DMC_SSH_EV_OPEN tells whether it opened */
/* a shell on a pty of term in the given size; agent: ssh -A asked */
int dmc_ssh_shell(dmc_ssh *s, const char *term, int cols, int rows, int agent);
/* a command run, with no pty; agent: ssh -A asked */
int dmc_ssh_exec(dmc_ssh *s, const char *command, int agent);
/* a TCP connection made from the server to host:port (ssh -L, -D), for
a connection that came from from_host:from_port */
int dmc_ssh_direct(dmc_ssh *s, const char *host, int port,
const char *from_host, int from_port);
/* the server asked to listen on address:port (ssh -R; NULL: its
default, 0: a port it picks): a request's number, answered by a
DMC_SSH_EV_LISTEN; its connections come as DMC_SSH_EV_INCOMING */
int dmc_ssh_listen(dmc_ssh *s, const char *address, int port);
/* that listen stopped */
void dmc_ssh_unlisten(dmc_ssh *s, const char *address, int port);
/* data to a channel (kept until the server can take it): how many
bytes are still kept (0 when all went; len 0 asks), or -1 if the
channel isn't open */
int dmc_ssh_write(dmc_ssh *s, int channel, const char *data, int len);
/* the channel's end of data sent */
void dmc_ssh_eof(dmc_ssh *s, int channel);
/* the channel closed (a DMC_SSH_EV_CLOSE comes) */
void dmc_ssh_close(dmc_ssh *s, int channel);
/* a shell's pty resized */
void dmc_ssh_resize(dmc_ssh *s, int channel, int cols, int rows);
/* keys */
/* OpenSSH's SHA256 fingerprint of a key's OpenSSH line
("SHA256:..."), into buf: 0, or -1 if it isn't a key */
int dmc_ssh_fingerprint(const char *keyline, char *buf, int max);
/* a new key ("ed25519", "ecdsa" with bits 256, 384 or 521, "rsa" with
bits): its private text (OpenSSH's, encrypted with passphrase unless
it's NULL or "") and its public line, both to free with
dmc_ssh_free_string(): 0, or -1 */
int dmc_ssh_keygen(const char *type, int bits, const char *passphrase,
char **private_key, char **public_key);
/* a private key's public line: 0, or -1 if it can't be read with that
passphrase */
int dmc_ssh_key_public(const char *key, const char *passphrase,
char **public_key);
/* whether a private key's text (OpenSSH's, PEM or PuTTY's .ppk) needs a
passphrase: 1 or 0 */
int dmc_ssh_key_encrypted(const char *key);
/* a private key written again (OpenSSH's form) with a new passphrase
(NULL or "": none): 0, or -1 */
int dmc_ssh_key_export(const char *key, const char *passphrase,
const char *new_passphrase, char **out);
void dmc_ssh_free_string(char *str);
#ifdef __cplusplus
}
#endif
#endif
-409
View File
@@ -1,409 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* agent.c - the agent libdmodemssh logs in with: on Linux and macOS an
* ssh-agent's socket (SSH_AUTH_SOCK, or one given); on
* Windows PuTTY's Pageant or OpenSSH's own agent.
*
* libssh talks to an agent over a socket it is given, so on Windows a
* pair of connected sockets stands between it and the agent: a thread
* reads each of libssh's requests from its end and hands it on, to
* Pageant by its WM_COPYDATA (a shared memory mapping, as PuTTY's own
* tools ask it) or down OpenSSH's named pipe, and writes the answer
* back. The thread ends when libssh closes its end.
*
* This file and agent.h are the same in D-Modem/gui (ssh/) and
* D-Modem/app (native-ssh/): change both.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#else
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#endif
#include <libssh/libssh.h>
#include "agent.h"
#ifdef _WIN32
/* (picolibc, the C library of the Windows 95 build, has no _stricmp) */
#ifdef __PICOLIBC__
#include <strings.h>
#define _stricmp strcasecmp
#endif
/* Pageant's: its window, the WM_COPYDATA it answers, its longest message */
#define PAGEANT_ID 0x804e50baUL
#define AGENT_MAX 262144
/* OpenSSH's agent on Windows */
#define OPENSSH_PIPE "\\\\.\\pipe\\openssh-ssh-agent"
struct dmc_agent {
SOCKET sock; /* the thread's end */
HANDLE thread;
HANDLE pipe; /* OpenSSH's, or a pipe given; else Pageant */
};
/* a big-endian uint32 at b */
static unsigned long be32(const unsigned char *b)
{
return (unsigned long)b[0] << 24 | (unsigned long)b[1] << 16 |
(unsigned long)b[2] << 8 | b[3];
}
/* Pageant's window, if it's running */
static HWND pageant(void)
{
return FindWindowA("Pageant", "Pageant");
}
/* the user's SID (malloc'd), or NULL */
static PSID user_sid(void)
{
HANDLE tok;
DWORD n = 0;
TOKEN_USER *tu;
PSID sid = NULL;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tok))
return NULL;
GetTokenInformation(tok, TokenUser, NULL, 0, &n);
tu = n ? malloc(n) : NULL;
if (tu && GetTokenInformation(tok, TokenUser, tu, n, &n)) {
DWORD l = GetLengthSid(tu->User.Sid);
sid = malloc(l);
if (sid && !CopySid(l, sid, tu->User.Sid)) {
free(sid);
sid = NULL;
}
}
free(tu);
CloseHandle(tok);
return sid;
}
/* a request (its length first) asked of Pageant; the answer (its length
first) into rep, which holds AGENT_MAX: 0, or -1 */
static int pageant_query(const unsigned char *req, unsigned long len,
unsigned char *rep)
{
HWND w = pageant();
char name[64];
SECURITY_ATTRIBUTES sa, *psa = NULL;
PSECURITY_DESCRIPTOR sd = NULL;
PSID sid;
HANDLE fm;
unsigned char *p;
COPYDATASTRUCT cds;
int r = -1;
if (!w || len > AGENT_MAX)
return -1;
snprintf(name, sizeof name, "PageantRequest%08lx",
(unsigned long)GetCurrentThreadId());
/* (the mapping owned by the user: Pageant answers only its own) */
sid = user_sid();
if (sid) {
sd = LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (sd && InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION) &&
SetSecurityDescriptorOwner(sd, sid, FALSE)) {
sa.nLength = sizeof sa;
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = sd;
psa = &sa;
}
}
fm = CreateFileMappingA(INVALID_HANDLE_VALUE, psa, PAGE_READWRITE, 0,
AGENT_MAX, name);
if (fm) {
p = MapViewOfFile(fm, FILE_MAP_WRITE, 0, 0, 0);
if (p) {
memcpy(p, req, len);
cds.dwData = PAGEANT_ID;
cds.cbData = (DWORD)strlen(name) + 1;
cds.lpData = name;
if (SendMessageA(w, WM_COPYDATA, 0, (LPARAM)&cds) > 0) {
unsigned long n = be32(p);
if (n <= AGENT_MAX - 4) {
memcpy(rep, p, n + 4);
r = 0;
}
}
UnmapViewOfFile(p);
}
CloseHandle(fm);
}
if (sd)
LocalFree(sd);
free(sid);
return r;
}
/* n bytes read from the pipe: 0, or -1 */
static int pipe_read(HANDLE h, unsigned char *b, unsigned long n)
{
DWORD got;
while (n) {
if (!ReadFile(h, b, n, &got, NULL) || !got)
return -1;
b += got;
n -= got;
}
return 0;
}
/* a request asked down the agent's pipe; the answer into rep: 0, or -1 */
static int pipe_query(HANDLE h, const unsigned char *req, unsigned long len,
unsigned char *rep)
{
DWORD put;
unsigned long n;
while (len) {
if (!WriteFile(h, req, len, &put, NULL) || !put)
return -1;
req += put;
len -= put;
}
if (pipe_read(h, rep, 4))
return -1;
n = be32(rep);
if (n > AGENT_MAX - 4)
return -1;
return pipe_read(h, rep + 4, n);
}
/* n bytes from the socket: 0, or -1 at its end */
static int sock_read(SOCKET s, unsigned char *b, unsigned long n)
{
while (n) {
int got = recv(s, (char *)b, (int)n, 0);
if (got <= 0)
return -1;
b += got;
n -= (unsigned long)got;
}
return 0;
}
/* the thread: libssh's requests to the agent, its answers back */
static DWORD WINAPI bridge(void *p)
{
struct dmc_agent *a = p;
unsigned char *req = malloc(AGENT_MAX), *rep = malloc(AGENT_MAX);
static const unsigned char failure[5] = { 0, 0, 0, 1, 5 };
while (req && rep) {
unsigned long n;
const unsigned char *out = rep;
int r, outlen;
if (sock_read(a->sock, req, 4))
break;
n = be32(req);
if (n > AGENT_MAX - 4 || sock_read(a->sock, req + 4, n))
break;
r = a->pipe != INVALID_HANDLE_VALUE ?
pipe_query(a->pipe, req, n + 4, rep) :
pageant_query(req, n + 4, rep);
if (r) {
/* (SSH_AGENT_FAILURE: no agent, or it didn't answer) */
out = failure;
outlen = 5;
} else {
outlen = (int)be32(rep) + 4;
}
if (send(a->sock, (const char *)out, outlen, 0) != outlen)
break;
}
free(req);
free(rep);
closesocket(a->sock);
a->sock = INVALID_SOCKET;
return 0;
}
/* a pair of connected sockets, by the loopback: 0, or -1 */
static int sock_pair(SOCKET pair[2])
{
SOCKET l = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP), c, a;
struct sockaddr_in at, mine, peer;
int n = sizeof at;
if (l == INVALID_SOCKET)
return -1;
memset(&at, 0, sizeof at);
at.sin_family = AF_INET;
at.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if (bind(l, (struct sockaddr *)&at, sizeof at) || listen(l, 1) ||
getsockname(l, (struct sockaddr *)&at, &n)) {
closesocket(l);
return -1;
}
c = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (c == INVALID_SOCKET || connect(c, (struct sockaddr *)&at, sizeof at)) {
closesocket(l);
if (c != INVALID_SOCKET)
closesocket(c);
return -1;
}
n = sizeof peer;
a = accept(l, (struct sockaddr *)&peer, &n);
closesocket(l);
/* (only our own connection: the one from c's own port) */
n = sizeof mine;
if (a == INVALID_SOCKET || getsockname(c, (struct sockaddr *)&mine, &n) ||
peer.sin_port != mine.sin_port || peer.sin_addr.s_addr != mine.sin_addr.s_addr) {
if (a != INVALID_SOCKET)
closesocket(a);
closesocket(c);
return -1;
}
pair[0] = c;
pair[1] = a;
return 0;
}
/* a named pipe opened, or INVALID_HANDLE_VALUE */
static HANDLE pipe_open(const char *path)
{
return CreateFileA(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
}
/* the agent asked for: "" (Pageant, else OpenSSH's), "pageant", or a pipe */
static int which_pipe(const char *which)
{
return which && *which && _stricmp(which, "pageant") != 0;
}
/* whether the agent answers (see agent.h) */
int dmc_agent_reachable(const char *which)
{
HANDLE h;
if (!which_pipe(which) && pageant())
return 1;
if (which && !_stricmp(which, "pageant"))
return 0;
h = pipe_open(which_pipe(which) ? which : OPENSSH_PIPE);
if (h == INVALID_HANDLE_VALUE)
return 0;
CloseHandle(h);
return 1;
}
/* the session's agent set, before its login by the agent (see agent.h) */
int dmc_agent_attach(ssh_session ssh, const char *which, dmc_agent **out)
{
struct dmc_agent *a;
SOCKET pair[2];
HANDLE pipe = INVALID_HANDLE_VALUE;
DWORD id;
*out = NULL;
if (which_pipe(which)) {
pipe = pipe_open(which);
} else if (!pageant()) {
if (which && *which)
return -1;
pipe = pipe_open(OPENSSH_PIPE);
}
if (pipe == INVALID_HANDLE_VALUE && (which_pipe(which) || !pageant()))
return -1;
a = calloc(1, sizeof *a);
if (!a || sock_pair(pair)) {
free(a);
if (pipe != INVALID_HANDLE_VALUE)
CloseHandle(pipe);
return -1;
}
a->sock = pair[1];
a->pipe = pipe;
a->thread = CreateThread(NULL, 0, bridge, a, 0, &id);
if (!a->thread || ssh_set_agent_socket(ssh, pair[0]) != SSH_OK) {
closesocket(pair[0]);
if (a->thread) {
WaitForSingleObject(a->thread, INFINITE);
CloseHandle(a->thread);
} else {
closesocket(pair[1]);
}
if (pipe != INVALID_HANDLE_VALUE)
CloseHandle(pipe);
free(a);
return -1;
}
*out = a;
return 0;
}
/* what dmc_agent_attach() made, freed after its session */
void dmc_agent_detach(dmc_agent *a)
{
if (!a)
return;
/* (libssh closed its end with the session: the thread has ended or
ends now) */
WaitForSingleObject(a->thread, INFINITE);
CloseHandle(a->thread);
if (a->pipe != INVALID_HANDLE_VALUE)
CloseHandle(a->pipe);
free(a);
}
#else
/* whether the agent answers (see agent.h) */
int dmc_agent_reachable(const char *which)
{
const char *path = which && *which ? which : getenv("SSH_AUTH_SOCK");
char full[sizeof(((struct sockaddr_un *)0)->sun_path)];
struct sockaddr_un sun;
int fd, ok;
if (!path || !*path)
return 0;
/* (~ the home folder, as OpenSSH's IdentityAgent has it) */
if (path[0] == '~' && path[1] == '/' && getenv("HOME"))
snprintf(full, sizeof full, "%s%s", getenv("HOME"), path + 1);
else
snprintf(full, sizeof full, "%s", path);
memset(&sun, 0, sizeof sun);
sun.sun_family = AF_UNIX;
memcpy(sun.sun_path, full, sizeof sun.sun_path - 1);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
return 0;
ok = connect(fd, (struct sockaddr *)&sun, sizeof sun) == 0;
close(fd);
return ok;
}
/* the session's agent set, before its login by the agent (see agent.h) */
int dmc_agent_attach(ssh_session ssh, const char *which, dmc_agent **out)
{
*out = NULL;
/* (libssh connects to it itself; none given: SSH_AUTH_SOCK) */
if (which && *which)
return ssh_options_set(ssh, SSH_OPTIONS_IDENTITY_AGENT, which) == SSH_OK ? 0 : -1;
return 0;
}
/* what dmc_agent_attach() made, freed after its session */
void dmc_agent_detach(dmc_agent *a)
{
(void)a;
}
#endif
-30
View File
@@ -1,30 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* agent.h - the agent libdmodemssh logs in with (agent.c).
*
* This file and agent.c are the same in D-Modem/gui (ssh/) and
* D-Modem/app (native-ssh/): change both.
*/
#ifndef DMODEM_AGENT_H
#define DMODEM_AGENT_H
#include <libssh/libssh.h>
typedef struct dmc_agent dmc_agent;
/* whether the agent answers: which is its socket (Linux, macOS; NULL or
"": SSH_AUTH_SOCK's), or on Windows "pageant", a named pipe, or NULL
or "" for Pageant and else OpenSSH's agent */
int dmc_agent_reachable(const char *which);
/* the session's agent set to which (as above), before its login by the
agent: 0, or -1 when there's none; *out is freed by dmc_agent_detach()
once the session is */
int dmc_agent_attach(ssh_session ssh, const char *which, dmc_agent **out);
/* what dmc_agent_attach() made, freed after its session (NULL: none) */
void dmc_agent_detach(dmc_agent *a);
#endif
-1408
View File
File diff suppressed because it is too large. Load diff
-34
View File
@@ -1,34 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* gai_strerror.c - gai_strerrorA for the Windows 9x builds (clang-retro:
* picolibc, win98 and winme). The one of mingw-w64's libws2_32.a calls
* FormatMessageW, which Windows 9x has only as a stub.
* This one is linked before it (ssh/CMakeLists.txt) and
* calls FormatMessageA. (Only Windows: the macOS
* project compiles each file of ssh/src.)
*/
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
char *gai_strerrorA(int ecode)
{
/* (one buffer, as mingw-w64's: libssh copies the text at once) */
static char text[256];
DWORD n = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, (DWORD)ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
text, sizeof text, NULL);
if (n == 0)
snprintf(text, sizeof text, "name lookup error %d", ecode);
return text;
}
#else
typedef int dmodem_gai_strerror_unused; /* (ISO C: no empty file) */
#endif
-1169
View File
File diff suppressed because it is too large. Load diff
-38
View File
@@ -1,38 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* ppk.h - PuTTY's private key files (.ppk) read, for libdmodemssh.
*
* This file and ppk.c are the same in D-Modem/gui (ssh/) and D-Modem/app
* (native-ssh/): change both.
*/
#ifndef DMODEM_PPK_H
#define DMODEM_PPK_H
#include <stddef.h>
#include <stdint.h>
/* whether text is a .ppk (PuTTY-User-Key-File-...) */
int dmc_ppk_is(const char *text);
/* a .ppk (version 2 or 3) as OpenSSH's private key text, unencrypted
(malloc'd; wipe it before it's freed): 0; -1 it can't be read; -2 it
needs a passphrase, or the one given is wrong */
int dmc_ppk_to_openssh(const char *text, const char *passphrase, char **out);
/* whether a private key's text is encrypted (a passphrase needed):
PuTTY's .ppk, OpenSSH's own, or PEM's */
int dmc_key_text_encrypted(const char *text);
/* Argon2 (type 0 Argon2d, 1 Argon2i, 2 Argon2id; version 0x13) of pwd
and salt, with an optional secret and associated data, into out
(outlen bytes): 0, or -1 */
int dmc_argon2(int type, uint32_t mem_kib, uint32_t passes, uint32_t lanes,
const unsigned char *pwd, size_t pwdlen,
const unsigned char *salt, size_t saltlen,
const unsigned char *secret, size_t secretlen,
const unsigned char *ad, size_t adlen,
unsigned char *out, uint32_t outlen);
#endif
-643
View File
@@ -1,643 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* dmodemssh_test.c - libdmodemssh's tests: keys (always), and a login to
* a real sshd when DMODEM_SSH_TEST names one as host:port:user:password
* (a shell, a command, a direct channel and a remote listen on it).
* DMODEM_SSH_TEST_KEY, a private key's file that the user's
* authorized_keys has, adds a login by key.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#define closesocket close
#endif
#include "dmodemssh.h"
#include "ppk.h"
static int failures;
#define CHECK(c) do { if (!(c)) { \
fprintf(stderr, "%s:%d: failed: %s\n", __FILE__, __LINE__, #c); \
failures++; } } while (0)
/* a key made, read back, its fingerprint, and with a passphrase */
static void test_keys(void)
{
static const char *types[] = { "ed25519", "ecdsa", "rsa" };
static const int bits[] = { 0, 384, 2048 };
int i;
for (i = 0; i < 3; i++) {
char *priv = NULL, *pub = NULL, *pub2 = NULL, *enc = NULL;
char fp[128];
CHECK(dmc_ssh_keygen(types[i], bits[i], NULL, &priv, &pub) == 0);
if (!priv || !pub)
continue;
CHECK(strstr(priv, "BEGIN OPENSSH PRIVATE KEY") != NULL);
CHECK(dmc_ssh_key_public(priv, NULL, &pub2) == 0);
CHECK(pub2 && !strcmp(pub, pub2));
CHECK(dmc_ssh_fingerprint(pub, fp, sizeof fp) == 0);
CHECK(!strncmp(fp, "SHA256:", 7) && strlen(fp) == 50);
CHECK(dmc_ssh_key_encrypted(priv) == 0);
CHECK(dmc_ssh_key_export(priv, NULL, "sesame", &enc) == 0);
CHECK(enc && dmc_ssh_key_encrypted(enc) == 1);
dmc_ssh_free_string(pub2);
pub2 = NULL;
CHECK(enc && dmc_ssh_key_public(enc, "wrong", &pub2) < 0);
CHECK(enc && dmc_ssh_key_public(enc, "sesame", &pub2) == 0);
CHECK(pub2 && !strcmp(pub, pub2));
dmc_ssh_free_string(priv);
dmc_ssh_free_string(pub);
dmc_ssh_free_string(pub2);
dmc_ssh_free_string(enc);
}
{
char fp[128];
CHECK(dmc_ssh_fingerprint("ssh-ed25519 notbase64!", fp, sizeof fp) < 0);
}
}
/* PuTTY's keys (made by PuTTYgen 0.81, for these tests only): version 3
with Argon2id, version 2, and one with no passphrase */
static const char ppk_v3[] =
"PuTTY-User-Key-File-3: ssh-ed25519\n"
"Encryption: aes256-cbc\n"
"Comment: dmodem test\n"
"Public-Lines: 2\n"
"AAAAC3NzaC1lZDI1NTE5AAAAIGaq1WGILuZaAUWi0Oj7RUOfHb2IdFdPFkpBvgmT\n"
"FNDY\n"
"Key-Derivation: Argon2id\n"
"Argon2-Memory: 1024\n"
"Argon2-Passes: 2\n"
"Argon2-Parallelism: 1\n"
"Argon2-Salt: 33f9ba393a4951fb796e2fbc41661b75\n"
"Private-Lines: 1\n"
"hM2XhuziydvZHlIY7Kv3LLpDLxZpyZRk0FUEdY9QffTXspVHngnD3kDEYfdjBqsL\n"
"Private-MAC: 335d60073336e5ef6af9660f801a38edc92fc04f52d7042d9a598a180787d6b6\n";
static const char ppk_v3_pub[] =
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGaq1WGILuZaAUWi0Oj7RUOfHb2IdFdPFkpBvgmTFNDY";
static const char ppk_v2[] =
"PuTTY-User-Key-File-2: ecdsa-sha2-nistp256\n"
"Encryption: aes256-cbc\n"
"Comment: dmodem test\n"
"Public-Lines: 3\n"
"AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBP8cgz/JGtuf\n"
"pTcbwYWaC5rRxEtd94wTxyYeZmpibjtHZs0xe5R/U0/gsjoYAZBqLsVAuw/m7PEH\n"
"owsid94C7vQ=\n"
"Private-Lines: 1\n"
"tXUEPEl6phjZUecV/5HDrEjp64lDdujz0/2vShR6B1ayoimLGtze26jtLPWczTOn\n"
"Private-MAC: 9ef17c9fa24457b60b4cc20f2f8e07925a9ec090\n";
static const char ppk_v2_pub[] =
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBP8cgz/JGtufpTcbwYWaC5rRxEtd94wTxyYeZmpibjtHZs0xe5R/U0/gsjoYAZBqLsVAuw/m7PEHowsid94C7vQ=";
static const char ppk_plain[] =
"PuTTY-User-Key-File-3: ssh-ed25519\n"
"Encryption: none\n"
"Comment: dmodem test\n"
"Public-Lines: 2\n"
"AAAAC3NzaC1lZDI1NTE5AAAAIJuvvweC5NNfYlxOXbIN7mOvU3s9uMr4WbpWTlzY\n"
"bOOZ\n"
"Private-Lines: 1\n"
"AAAAID9RN2flxRLWco4mJwxMJJQUNSmAEZ4ltTevZi+TSuxO\n"
"Private-MAC: c31121241789d04ca3e7e68d528a5c46a4309276510c45cdc6b4e0f501746f2f\n";
static const char ppk_plain_pub[] =
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJuvvweC5NNfYlxOXbIN7mOvU3s9uMr4WbpWTlzYbOOZ";
/* Argon2d, Argon2i and Argon2id: RFC 9106's test vectors */
static void test_argon2(void)
{
static const char *want[3] = {
"512b391b6f1162975371d30919734294f868e3be3984f3c1a13a4db9fabe4acb",
"c814d9d1dc7f37aa13f0d77f2494bda1c8de6b016dd388d29952a4c4672b6ce8",
"0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659",
};
unsigned char pwd[32], salt[16], secret[8], ad[12], out[32];
char hex[65];
int t, i;
memset(pwd, 1, sizeof pwd);
memset(salt, 2, sizeof salt);
memset(secret, 3, sizeof secret);
memset(ad, 4, sizeof ad);
for (t = 0; t < 3; t++) {
CHECK(dmc_argon2(t, 32, 3, 4, pwd, sizeof pwd, salt, sizeof salt,
secret, sizeof secret, ad, sizeof ad, out, 32) == 0);
for (i = 0; i < 32; i++)
snprintf(hex + 2 * i, 3, "%02x", out[i]);
CHECK(!strcmp(hex, want[t]));
}
}
/* PuTTY's .ppk read: its public line, a wrong passphrase refused, and
OpenSSH's form written from it */
static void test_ppk(void)
{
static const struct { const char *ppk, *pub, *pass; } k[] = {
{ ppk_v3, ppk_v3_pub, "sesame" },
{ ppk_v2, ppk_v2_pub, "sesame" },
{ ppk_plain, ppk_plain_pub, NULL },
};
int i;
for (i = 0; i < 3; i++) {
char *pub = NULL, *out = NULL, *pub2 = NULL;
CHECK(dmc_ssh_key_encrypted(k[i].ppk) == (k[i].pass != NULL));
CHECK(dmc_ssh_key_public(k[i].ppk, k[i].pass, &pub) == 0);
CHECK(pub && !strcmp(pub, k[i].pub));
if (k[i].pass) {
char *no = NULL;
CHECK(dmc_ssh_key_public(k[i].ppk, "wrong", &no) < 0);
CHECK(dmc_ssh_key_public(k[i].ppk, NULL, &no) < 0);
}
CHECK(dmc_ssh_key_export(k[i].ppk, k[i].pass, "new", &out) == 0);
CHECK(out && strstr(out, "BEGIN OPENSSH PRIVATE KEY") != NULL);
CHECK(out && dmc_ssh_key_encrypted(out) == 1);
CHECK(out && dmc_ssh_key_public(out, "new", &pub2) == 0);
CHECK(pub2 && !strcmp(pub2, k[i].pub));
dmc_ssh_free_string(pub);
dmc_ssh_free_string(pub2);
dmc_ssh_free_string(out);
}
CHECK(dmc_ssh_key_encrypted("not a key") == 0);
}
static const char *host, *user, *password;
static int port;
/* the next event (10 s at most): its type, or 0 */
static int next(dmc_ssh *s, dmc_ssh_event *ev)
{
int r = dmc_ssh_poll(s, 10000, ev);
if (r <= 0) {
fprintf(stderr, "no event (%d)\n", r);
return 0;
}
return ev->type;
}
/* a connection logged in by password (a wrong one first): or NULL */
static dmc_ssh *logged_in(void)
{
dmc_ssh *s = dmc_ssh_new(host, port, user);
dmc_ssh_event ev;
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
CHECK(!strncmp(ev.data, "ssh-", 4) || !strncmp(ev.data, "ecdsa-", 6));
CHECK(ev.value == DMC_SSH_HOST_UNCHECKED);
dmc_ssh_trust(s, 1, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
CHECK(ev.value & DMC_SSH_AUTH_PASSWORD);
CHECK(!strcmp(ev.data, ""));
dmc_ssh_auth_password(s, "not it");
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
CHECK(!strcmp(ev.data, "The password was not accepted"));
dmc_ssh_auth_password(s, password);
if (next(s, &ev) != DMC_SSH_EV_READY) {
CHECK(!"logged in");
dmc_ssh_free(s);
return NULL;
}
return s;
}
/* a channel's output read until it closes: into out; its exit status */
static int drain(dmc_ssh *s, int ch, char *out, int max)
{
dmc_ssh_event ev;
int len = 0, status = -1000;
for (;;) {
int t = next(s, &ev);
if (!t || t == DMC_SSH_EV_CLOSED)
break;
if (ev.channel != ch)
continue;
if (t == DMC_SSH_EV_DATA && len + ev.len < max) {
memcpy(out + len, ev.data, (size_t)ev.len);
len += ev.len;
} else if (t == DMC_SSH_EV_EXIT) {
status = ev.value;
} else if (t == DMC_SSH_EV_CLOSE) {
break;
}
}
out[len] = 0;
return status;
}
/* a shell on a pty: its size, a command typed, its exit */
static void test_shell(dmc_ssh *s)
{
dmc_ssh_event ev;
char out[8192];
int ch = dmc_ssh_shell(s, "vt100", 100, 30, 0);
static const char typed[] = "stty size; echo $TERM; exit 3\n";
CHECK(ch > 0);
CHECK(next(s, &ev) == DMC_SSH_EV_OPEN && ev.channel == ch && ev.value == 1);
CHECK(dmc_ssh_write(s, ch, typed, (int)strlen(typed)) >= 0);
CHECK(drain(s, ch, out, sizeof out) == 3);
CHECK(strstr(out, "30 100") != NULL);
CHECK(strstr(out, "vt100") != NULL);
CHECK(dmc_ssh_write(s, ch, "x", 1) < 0);
}
/* a command: its output, stdin, and exit status */
static void test_exec(dmc_ssh *s)
{
dmc_ssh_event ev;
char out[8192];
int ch = dmc_ssh_exec(s, "tr a-z A-Z; exit 7", 0);
CHECK(ch > 0);
CHECK(next(s, &ev) == DMC_SSH_EV_OPEN && ev.value == 1);
CHECK(dmc_ssh_write(s, ch, "hello\n", 6) >= 0);
dmc_ssh_eof(s, ch);
CHECK(drain(s, ch, out, sizeof out) == 7);
CHECK(!strcmp(out, "HELLO\n"));
}
/* a direct channel to the sshd itself: its banner */
static void test_direct(dmc_ssh *s)
{
dmc_ssh_event ev;
int ch = dmc_ssh_direct(s, "127.0.0.1", port, "127.0.0.1", 40000);
int t;
CHECK(ch > 0);
CHECK(next(s, &ev) == DMC_SSH_EV_OPEN && ev.value == 1);
do {
t = next(s, &ev);
} while (t && t != DMC_SSH_EV_DATA);
CHECK(t == DMC_SSH_EV_DATA && !strncmp(ev.data, "SSH-2.0-", 8));
dmc_ssh_close(s, ch);
CHECK(next(s, &ev) == DMC_SSH_EV_CLOSE && ev.channel == ch);
}
/* a remote listen on a port the server picks, connected to from here */
static void test_listen(dmc_ssh *s)
{
dmc_ssh_event ev;
int id = dmc_ssh_listen(s, "127.0.0.1", 0), bound, ch, t;
struct sockaddr_in a;
int fd;
char b[16];
CHECK(id > 0);
CHECK(next(s, &ev) == DMC_SSH_EV_LISTEN && ev.channel == id);
bound = ev.value;
CHECK(bound > 0);
if (bound <= 0)
return;
fd = (int)socket(AF_INET, SOCK_STREAM, 0);
memset(&a, 0, sizeof a);
a.sin_family = AF_INET;
a.sin_port = htons((unsigned short)bound);
a.sin_addr.s_addr = htonl(0x7f000001);
CHECK(connect(fd, (struct sockaddr *)&a, sizeof a) == 0);
send(fd, "ping", 4, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_INCOMING && ev.value == bound);
ch = ev.channel;
do {
t = next(s, &ev);
} while (t && t != DMC_SSH_EV_DATA);
CHECK(t == DMC_SSH_EV_DATA && ev.channel == ch && ev.len == 4 &&
!memcmp(ev.data, "ping", 4));
CHECK(dmc_ssh_write(s, ch, "pong", 4) >= 0);
{
/* (the reply comes as the session is polled) */
int got = 0, i;
for (i = 0; i < 40 && got < 4; i++) {
dmc_ssh_poll(s, 50, &ev);
#ifdef _WIN32
{
u_long n = 0;
ioctlsocket(fd, FIONREAD, &n);
if (n >= 4)
got = recv(fd, b, 4, 0);
}
#else
got = (int)recv(fd, b, 4, MSG_DONTWAIT);
if (got < 0)
got = 0;
#endif
}
CHECK(got == 4 && !memcmp(b, "pong", 4));
}
closesocket(fd);
dmc_ssh_close(s, ch);
dmc_ssh_unlisten(s, "127.0.0.1", bound);
}
/* a login by a key in a file */
static void test_key_login(const char *file)
{
FILE *f = fopen(file, "rb");
char key[16384];
size_t n;
dmc_ssh *s;
dmc_ssh_event ev;
CHECK(f != NULL);
if (!f)
return;
n = fread(key, 1, sizeof key - 1, f);
key[n] = 0;
fclose(f);
s = dmc_ssh_new(host, port, user);
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
dmc_ssh_trust(s, 1, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH && (ev.value & DMC_SSH_AUTH_PUBLICKEY));
CHECK(dmc_ssh_auth_key(s, key, NULL) == 0);
CHECK(next(s, &ev) == DMC_SSH_EV_READY);
dmc_ssh_free(s);
}
/* a login by the agent named (a socket, or on Windows Pageant or a
pipe) */
static void test_agent_login(const char *agent)
{
dmc_ssh *s;
dmc_ssh_event ev;
CHECK(dmc_ssh_agent_reachable(agent) == 1);
s = dmc_ssh_new(host, port, user);
CHECK(dmc_ssh_option(s, "agent", agent) == 0);
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
dmc_ssh_trust(s, 1, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH && (ev.value & DMC_SSH_AUTH_PUBLICKEY));
dmc_ssh_auth_agent(s);
CHECK(next(s, &ev) == DMC_SSH_EV_READY);
dmc_ssh_free(s);
}
#ifdef _WIN32
/*
* A stand-in for Pageant: its window, answering by WM_COPYDATA as it
* does, with no keys (each request counted), so that the way to it is
* tested where PuTTY isn't.
*/
static int pageant_requests;
/* the stand-in's window: a request in the named mapping, answered there */
static LRESULT CALLBACK pageant_proc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_COPYDATA) {
COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lp;
HANDLE fm;
unsigned char *p;
if (cds->dwData != 0x804e50baUL)
return 0;
fm = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, (const char *)cds->lpData);
if (!fm)
return 0;
p = MapViewOfFile(fm, FILE_MAP_WRITE, 0, 0, 0);
if (p) {
pageant_requests++;
if (p[4] == 11) {
/* SSH2_AGENT_IDENTITIES_ANSWER, none */
static const unsigned char none[9] = { 0, 0, 0, 5, 12, 0, 0, 0, 0 };
memcpy(p, none, sizeof none);
} else {
/* SSH_AGENT_FAILURE */
static const unsigned char fail[5] = { 0, 0, 0, 1, 5 };
memcpy(p, fail, sizeof fail);
}
UnmapViewOfFile(p);
}
CloseHandle(fm);
return 1;
}
return DefWindowProcA(w, msg, wp, lp);
}
/* the stand-in's thread: its window and their messages */
static DWORD WINAPI pageant_run(void *ready)
{
WNDCLASSA wc;
MSG m;
memset(&wc, 0, sizeof wc);
wc.lpfnWndProc = pageant_proc;
wc.hInstance = GetModuleHandleA(NULL);
wc.lpszClassName = "Pageant";
RegisterClassA(&wc);
CreateWindowA("Pageant", "Pageant", 0, 0, 0, 0, 0, NULL, NULL, wc.hInstance, NULL);
SetEvent((HANDLE)ready);
while (GetMessageA(&m, NULL, 0, 0) > 0)
DispatchMessageA(&m);
return 0;
}
/* Pageant found, asked, and its "no keys" taken as a login refused */
static void test_pageant(void)
{
HANDLE ready = CreateEventA(NULL, TRUE, FALSE, NULL);
DWORD id;
dmc_ssh *s;
dmc_ssh_event ev;
if (FindWindowA("Pageant", "Pageant")) {
printf("Pageant is running: its stand-in not tested\n");
return;
}
CHECK(dmc_ssh_agent_reachable("pageant") == 0);
CreateThread(NULL, 0, pageant_run, ready, 0, &id);
WaitForSingleObject(ready, 5000);
if (!FindWindowA("Pageant", "Pageant")) {
printf("no window could be made: Pageant not tested\n");
return;
}
CHECK(dmc_ssh_agent_reachable("pageant") == 1);
CHECK(dmc_ssh_agent_reachable("") == 1);
if (!host)
return;
s = dmc_ssh_new(host, port, user);
CHECK(dmc_ssh_option(s, "agent", "pageant") == 0);
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
dmc_ssh_trust(s, 1, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
dmc_ssh_auth_agent(s);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
CHECK(pageant_requests >= 1);
dmc_ssh_free(s);
}
/* a stand-in for OpenSSH's agent on its named pipe: no keys, as above */
#define TEST_PIPE "\\\\.\\pipe\\dmodem-test-agent"
static int pipe_requests;
/* the pipe's one connection served, until it closes */
static DWORD WINAPI pipe_run(void *h)
{
unsigned char req[1024];
DWORD n;
if (!ConnectNamedPipe((HANDLE)h, NULL) && GetLastError() != ERROR_PIPE_CONNECTED)
return 0;
while (ReadFile((HANDLE)h, req, sizeof req, &n, NULL) && n >= 5) {
static const unsigned char none[9] = { 0, 0, 0, 5, 12, 0, 0, 0, 0 };
static const unsigned char fail[5] = { 0, 0, 0, 1, 5 };
pipe_requests++;
if (req[4] == 11)
WriteFile((HANDLE)h, none, sizeof none, &n, NULL);
else
WriteFile((HANDLE)h, fail, sizeof fail, &n, NULL);
}
CloseHandle((HANDLE)h);
return 0;
}
/* an agent on a named pipe found and asked */
static void test_agent_pipe(void)
{
HANDLE h;
DWORD id;
dmc_ssh *s;
dmc_ssh_event ev;
CHECK(dmc_ssh_agent_reachable(TEST_PIPE) == 0);
if (!host)
return;
h = CreateNamedPipeA(TEST_PIPE, PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1,
4096, 4096, 0, NULL);
CHECK(h != INVALID_HANDLE_VALUE);
if (h == INVALID_HANDLE_VALUE)
return;
CreateThread(NULL, 0, pipe_run, h, 0, &id);
s = dmc_ssh_new(host, port, user);
CHECK(dmc_ssh_option(s, "agent", TEST_PIPE) == 0);
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
dmc_ssh_trust(s, 1, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
dmc_ssh_auth_agent(s);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
CHECK(pipe_requests >= 1);
dmc_ssh_free(s);
}
#endif
/* the logins and channels against DMODEM_SSH_TEST's sshd */
static void test_live(const char *spec)
{
static char buf[512];
char *p[4];
int i;
dmc_ssh *s;
dmc_ssh_event ev;
/* (a key's file, OpenSSH's; a .ppk; an agent's socket) */
const char *key = getenv("DMODEM_SSH_TEST_KEY");
snprintf(buf, sizeof buf, "%s", spec);
p[0] = buf;
for (i = 1; i < 4; i++) {
p[i] = strchr(p[i - 1], ':');
if (!p[i]) {
fprintf(stderr, "DMODEM_SSH_TEST: host:port:user:password\n");
failures++;
return;
}
*p[i]++ = 0;
}
host = p[0];
port = atoi(p[1]);
user = p[2];
password = p[3];
s = logged_in();
if (!s)
return;
test_shell(s);
test_exec(s);
test_direct(s);
test_listen(s);
dmc_ssh_disconnect(s);
while (next(s, &ev) && ev.type != DMC_SSH_EV_CLOSED)
;
CHECK(ev.type == DMC_SSH_EV_CLOSED && ev.data == NULL);
CHECK(dmc_ssh_poll(s, 10, &ev) == -1);
dmc_ssh_free(s);
/* a refused key: the connection ends saying so */
s = dmc_ssh_new(host, port, user);
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
dmc_ssh_trust(s, 0, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_CLOSED);
CHECK(ev.data && !strcmp(ev.data, "the host's key was not accepted"));
dmc_ssh_free(s);
/* keyboard-interactive, when the server has it: the password asked */
s = dmc_ssh_new(host, port, user);
CHECK(next(s, &ev) == DMC_SSH_EV_HOSTKEY);
dmc_ssh_trust(s, 1, 0);
CHECK(next(s, &ev) == DMC_SSH_EV_AUTH);
if (ev.value & DMC_SSH_AUTH_INTERACTIVE) {
int echo = 1;
dmc_ssh_auth_interactive(s);
CHECK(next(s, &ev) == DMC_SSH_EV_PROMPTS && ev.value == 1);
CHECK(strstr(dmc_ssh_prompt(s, 0, &echo), "assword") != NULL);
CHECK(echo == 0);
dmc_ssh_answer(s, 0, password);
dmc_ssh_answered(s);
/* (some servers end with a round of no questions) */
while (next(s, &ev) == DMC_SSH_EV_PROMPTS && ev.value == 0)
dmc_ssh_answered(s);
CHECK(ev.type == DMC_SSH_EV_READY);
} else {
printf("no keyboard-interactive: not tested\n");
}
dmc_ssh_free(s);
if (key)
test_key_login(key);
if (getenv("DMODEM_SSH_TEST_PPK"))
test_key_login(getenv("DMODEM_SSH_TEST_PPK"));
if (getenv("DMODEM_SSH_TEST_AGENT"))
test_agent_login(getenv("DMODEM_SSH_TEST_AGENT"));
CHECK(dmc_ssh_agent_reachable("/nonexistent/agent.sock") == 0);
}
/* the key tests, then the live ones when DMODEM_SSH_TEST names a server */
int main(void)
{
const char *spec = getenv("DMODEM_SSH_TEST");
#ifdef _WIN32
WSADATA w;
WSAStartup(MAKEWORD(2, 2), &w);
#endif
test_keys();
test_argon2();
test_ppk();
if (spec)
test_live(spec);
else
printf("DMODEM_SSH_TEST is not set: no login tested\n");
#ifdef _WIN32
test_pageant();
test_agent_pipe();
#endif
if (failures) {
fprintf(stderr, "%d failed\n", failures);
return 1;
}
printf("ok\n");
return 0;
}
-140
View File
@@ -1,140 +0,0 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (C) 2026 D-Modem Authors
"""
Writes core/src/vt_data.c: the terminal emulator's data from the D-Modem
app's (D-Modem/app, shared/src/commonMain/kotlin/org/dmodem/app/terminal):
the home computers' character sets and Unscii's 8x8 and 8x16 glyphs
(LegacyCharsets.kt), the machines' character ROMs as SyncTERM draws them
(RomFonts.kt: Synchronet ciolib's, LGPL-2.0-or-later) and teletext's
mosaics (Mosaic.kt's, drawn the same way).
python3 tools/gen_vt_data.py APP_TERMINAL_DIR > core/src/vt_data.c
"""
import re
import sys
SETS = [
("C64_UPPER", "vt_set_c64_upper"), ("C64_LOWER", "vt_set_c64_lower"),
("VIC_UPPER", "vt_set_vic_upper"), ("VIC_LOWER", "vt_set_vic_lower"),
("PET_UPPER", "vt_set_pet_upper"), ("PET_LOWER", "vt_set_pet_lower"),
("ATARI_GRAPHICS", "vt_set_atari_graphics"),
("ATARI_INTERNATIONAL", "vt_set_atari_international"),
]
# RomFonts.kt's, in the order of vtint.h's ROM_* (SyncTERM's numbers)
ROMS = ["VGA", "VGA_THIN", "C64_UPPER", "C64_LOWER", "C128_UPPER",
"C128_LOWER", "ATARI", "POT_NOODLE", "MOSOUL", "MICROKNIGHT_PLUS",
"TOPAZ_PLUS", "MICROKNIGHT", "TOPAZ", "PRESTEL", "ATARI_ST",
"RIPTERM"]
def int_array(src, name):
m = re.search(r"val %s: IntArray = intArrayOf\((.*?)\)" % name, src, re.S)
v = [int(x, 16) for x in re.findall(r"0x([0-9A-Fa-f]+)", m.group(1))]
assert len(v) == 256, name
return v
def bitmap(src, name, height):
m = re.search(r"val %s: BitmapFont = BitmapFont.parse\(\s*%d,(.*?)\n \)" % (name, height), src, re.S)
body = "".join(re.findall(r'"([^"]*)"', m.group(1)))
out = []
for e in body.split(";"):
if not e:
continue
cp, rows = e.split(":")
out.append((int(cp, 16), [int(rows[2 * r:2 * r + 2], 16) for r in range(height)]))
out.sort()
return out
def rom(src, name):
m = re.search(r"val %s: RomFont = RomFont\((.*?)\n \)" % name, src, re.S)
sizes = {}
for h, body in re.findall(r"h(8|16) =\s*((?:\s*\"[0-9a-f]*\"\s*\+?)+)", m.group(1)):
hexs = "".join(re.findall(r'"([0-9a-f]*)"', body))
assert len(hexs) == 256 * int(h) * 2, (name, h)
sizes[int(h)] = bytes.fromhex(hexs)
return sizes
def mosaic():
out = []
for sep in (False, True):
for mask in range(1, 64):
rows = []
for y in range(9):
band = y // 3
r = 0
if not (sep and y % 3 == 2):
if mask & (1 << (band * 2)):
r |= 0b110000 if sep else 0b111000
if mask & (1 << (band * 2 + 1)):
r |= 0b000110 if sep else 0b000111
rows.append(r)
out.append((0xf1000 + mask + (0x40 if sep else 0), rows))
return out
def emit_bytes(name, data, static=True):
print("%sconst uint8_t %s[%d] = {" % ("static " if static else "", name, len(data)))
for k in range(0, len(data), 16):
print("\t" + ", ".join("0x%02x" % b for b in data[k:k + 16]) + ",")
print("};")
def emit_font(cname, font, w, h):
print("static const uint32_t %s_codes[%d] = {" % (cname, len(font)))
for k in range(0, len(font), 8):
print("\t" + ", ".join("0x%x" % cp for cp, _ in font[k:k + 8]) + ",")
print("};")
emit_bytes(cname + "_rows", [b for _, rows in font for b in rows])
print("const struct vt_font %s = { %d, %d, %d, %s_codes, %s_rows, NULL };\n"
% (cname, w, h, len(font), cname, cname))
def main():
d = sys.argv[1]
legacy = open(d + "/LegacyCharsets.kt", encoding="utf-8").read()
roms = open(sys.argv[2] if len(sys.argv) > 2 else d + "/RomFonts.kt", encoding="utf-8").read()
print("/*")
print(" * SPDX-License-Identifier: AGPL-3.0-only AND LGPL-2.0-or-later")
print(" * Generated by tools/gen_vt_data.py from the D-Modem app's")
print(" * LegacyCharsets.kt, RomFonts.kt and Mosaic.kt: don't edit by hand.")
print(" *")
print(" * The sets are Rebecca Bettencourt's Legacy Computing mappings; the")
print(" * 8x8 and 8x16 glyphs Unscii's (public domain); the character ROMs")
print(" * Synchronet ciolib's (src/conio/allfonts.c), LGPL-2.0-or-later,")
print(" * copyright Rob Swindell and its contributors")
print(" * (core/licenses/syncterm-fonts-LGPL-2.0.txt).")
print(" */")
print('#include "vtint.h"\n')
for kt, c in SETS:
v = int_array(legacy, kt)
print("const uint32_t %s[256] = {" % c)
for k in range(0, 256, 8):
print("\t" + ", ".join("0x%x" % x for x in v[k:k + 8]) + ",")
print("};\n")
emit_font("vt_font_8x8", bitmap(legacy, "GLYPHS", 8), 8, 8)
emit_font("vt_font_vga", bitmap(legacy, "VGA", 16), 8, 16)
emit_font("vt_font_mosaic", mosaic(), 6, 9)
names = []
for n in ROMS:
sizes = rom(roms, n)
r8 = r16 = "NULL"
if 8 in sizes:
r8 = "rom_%s_8" % n.lower()
emit_bytes(r8, sizes[8])
if 16 in sizes:
r16 = "rom_%s_16" % n.lower()
emit_bytes(r16, sizes[16])
names.append((r8, r16))
print()
print("const struct vt_rom vt_roms[ROM_COUNT] = {")
for r8, r16 in names:
print("\t{ %s, %s }," % (r8, r16))
print("};")
main()
-20
View File
@@ -1,20 +0,0 @@
// Renders assets/dmodem.svg (D-Modem/brand's mark, avatar/org-avatar.svg, on a tile) to the
// PNGs the app's icon is made from, with Playwright's Chromium:
// node tools/icons.js && python3 tools/icons.py
const { chromium } = require('playwright');
const fs = require('fs'), path = require('path');
const root = path.join(__dirname, '..');
const svg = fs.readFileSync(path.join(root, 'assets', 'dmodem.svg'), 'utf8');
const out = path.join(root, 'build', 'icons');
fs.mkdirSync(out, { recursive: true });
(async () => {
const browser = await chromium.launch();
for (const size of [16, 32, 48, 64, 128, 256, 512, 1024]) {
const page = await browser.newPage({ viewport: { width: size, height: size } });
const s = svg.replace(/width="\d+" height="\d+"/, `width="${size}" height="${size}"`);
await page.setContent(`<html><body style="margin:0;background:transparent">${s}</body></html>`);
await page.screenshot({ path: path.join(out, `${size}.png`), omitBackground: true });
await page.close();
}
await browser.close();
})();
-90
View File
@@ -1,90 +0,0 @@
#!/usr/bin/env python3
"""Makes the app's icon file from tools/icons.js's PNGs (build/icons):
windows/res/dmodem.ico 16, 32 and 48 in 256 colours (Windows 9x) and
in 32-bit colour with alpha (XP on), 256 as PNG
The .ico is written by hand: Windows 95 reads only BMP entries."""
import io
import os
import struct
from PIL import Image
ROOT = os.path.join(os.path.dirname(__file__), '..')
SRC = os.path.join(ROOT, 'build', 'icons')
def png(size):
return Image.open(os.path.join(SRC, f'{size}.png')).convert('RGBA')
def and_mask(img):
w, h = img.size
stride = ((w + 31) // 32) * 4
rows = []
for y in range(h - 1, -1, -1):
bits = bytearray(stride)
for x in range(w):
if img.getpixel((x, y))[3] < 128:
bits[x // 8] |= 0x80 >> (x % 8)
rows.append(bytes(bits))
return b''.join(rows)
def dib_32(img):
w, h = img.size
header = struct.pack('<IiiHHIIiiII', 40, w, h * 2, 1, 32, 0, 0, 0, 0, 0, 0)
px = bytearray()
for y in range(h - 1, -1, -1):
for x in range(w):
r, g, b, a = img.getpixel((x, y))
px += bytes((b, g, r, a))
return header + bytes(px) + and_mask(img)
def dib_8(img):
w, h = img.size
# 255 colours of the opaque pixels, on black where it is clear
flat = Image.new('RGB', img.size, (0, 0, 0))
flat.paste(img, mask=img.split()[3])
q = flat.quantize(colors=256, method=Image.Quantize.MEDIANCUT)
pal = q.getpalette()[:256 * 3]
pal += [0] * (256 * 3 - len(pal))
header = struct.pack('<IiiHHIIiiII', 40, w, h * 2, 1, 8, 0, 0, 0, 0, 256, 0)
table = bytearray()
for i in range(256):
r, g, b = pal[i * 3:i * 3 + 3]
table += bytes((b, g, r, 0))
stride = (w + 3) & ~3
px = bytearray()
for y in range(h - 1, -1, -1):
row = bytes(q.getpixel((x, y)) for x in range(w))
px += row + bytes(stride - w)
return header + bytes(table) + bytes(px) + and_mask(img)
def ico(path):
entries = []
for size in (16, 32, 48):
img = png(size)
entries.append((size, 8, 256, dib_8(img)))
for size in (16, 32, 48):
entries.append((size, 32, 0, dib_32(png(size))))
b = io.BytesIO()
png(256).save(b, 'PNG')
entries.append((256, 32, 0, b.getvalue()))
head = struct.pack('<HHH', 0, 1, len(entries))
offset = 6 + 16 * len(entries)
dirs, data = b'', b''
for size, bpp, colours, blob in entries:
dirs += struct.pack('<BBBBHHII', size % 256, size % 256,
colours % 256, 0, 1, bpp, len(blob), offset)
offset += len(blob)
data += blob
with open(path, 'wb') as f:
f.write(head + dirs + data)
if __name__ == '__main__':
ico(os.path.join(ROOT, 'windows', 'res', 'dmodem.ico'))
-34
View File
@@ -1,34 +0,0 @@
# The Windows app with MinGW, MSVC or clang-retro (the Windows 95 build:
# cmake/clang-retro.cmake). ANSI, for the same code to build with all.
enable_language(CXX)
enable_language(RC)
include(sources.cmake)
# (the target dmodem-app, its file dmodem.exe: D-Modem's libdmodem is
# the target dmodem, with the modem built in)
add_executable(dmodem-app WIN32 ${DMODEM_WIN_SOURCES} res/app.rc)
set_target_properties(dmodem-app PROPERTIES OUTPUT_NAME dmodem)
target_include_directories(dmodem-app PRIVATE src)
target_link_libraries(dmodem-app PRIVATE dmodemctl comctl32 wsock32 comdlg32 gdi32 winmm msacm32 shell32 advapi32)
# the Remote page's SSH: libdmodemssh (libssh, built in)
if(TARGET dmodemssh)
target_link_libraries(dmodem-app PRIVATE dmodemssh)
target_compile_definitions(dmodem-app PRIVATE DMODEM_HAVE_SSH)
endif()
if(MSVC)
target_compile_definitions(dmodem-app PRIVATE _CRT_SECURE_NO_WARNINGS)
# (a manifest of our own in app.rc)
target_link_options(dmodem-app PRIVATE /MANIFEST:NO)
else()
target_compile_options(dmodem-app PRIVATE -Wall -Wextra -Wno-unused-parameter)
target_link_options(dmodem-app PRIVATE -static)
endif()
# (picolibc starts main, unless the entry point is WinMain's)
if(CLANG_RETRO_CONFIG MATCHES "picolibc")
target_link_options(dmodem-app PRIVATE -Wl,-e,WinMainCRTStartup)
endif()
# the modem built in (libdmodem_embed, DMODEM_GUI_EMBED): Windows 98 SE
# and later
if(DMODEM_GUI_EMBED AND TARGET dmodem_embed)
target_link_libraries(dmodem-app PRIVATE dmodem_embed)
target_compile_definitions(dmodem-app PRIVATE DMODEM_GUI_EMBED)
endif()
-15
View File
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="DModem.Gui" type="win32"/>
<description>D-Modem</description>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
</assembly>
-345
View File
@@ -1,345 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* app.rc - the Windows app's icon, menu and dialogs (MS Shell Dlg: MS
* Sans Serif on Windows 9x, Tahoma or Segoe UI later)
*/
#include <windows.h>
#include "../src/resource.h"
IDI_APP ICON "dmodem.ico"
/* visual styles from Windows XP on (Windows 9x ignores it) */
1 24 "app.manifest"
IDR_MENU MENU
BEGIN
POPUP "&Modem"
BEGIN
MENUITEM "&Start or Stop", IDM_START
MENUITEM "&Line Settings...", IDM_LINE
MENUITEM "&ASCII Setup...", IDM_ASCII
MENUITEM "&Terminal Settings...", IDM_TERMSET
MENUITEM SEPARATOR
MENUITEM "&Print...", IDM_FPRINT
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_EXIT
END
POPUP "&Call"
BEGIN
MENUITEM "&Call...", IDM_CALL
MENUITEM "&Wait for a Call", IDM_WAITCALL
MENUITEM "&Disconnect", IDM_DISCONNECT
MENUITEM SEPARATOR
MENUITEM "Send &Break\tCtrl+Break", IDM_BREAK
END
POPUP "&Edit"
BEGIN
MENUITEM "&Copy\tCtrl+Insert", IDM_EDCOPY
MENUITEM "&Paste to Host\tShift+Insert", IDM_EDPASTE
MENUITEM SEPARATOR
MENUITEM "Select &All", IDM_SELALL
END
POPUP "&Transfer"
BEGIN
MENUITEM "&Send File...", IDM_SEND
MENUITEM "&Receive File...", IDM_RECEIVE
MENUITEM SEPARATOR
MENUITEM "&Automatic Receive (ZMODEM, Kermit)", IDM_AUTORECV
MENUITEM "ZMODEM Compression (&zstd)", IDM_XZSTD
MENUITEM SEPARATOR
MENUITEM "&Cancel Transfer", IDM_XCANCEL
MENUITEM SEPARATOR
MENUITEM "Capture &Text...", IDM_CAPTURE
MENUITEM "Capture Text: Pa&use", IDM_CAPPAUSE
MENUITEM "Capture Text: St&op", IDM_CAPSTOP
MENUITEM SEPARATOR
MENUITEM "Capture to &Printer", IDM_CAPPRINT
MENUITEM "Capture to Printer: Pau&se", IDM_PRNPAUSE
END
POPUP "&Help"
BEGIN
MENUITEM "&About D-Modem", IDM_ABOUT
END
END
IDD_LINE DIALOG 0, 0, 300, 332
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Line Settings"
FONT 8, "MS Shell Dlg"
BEGIN
AUTORADIOBUTTON "Start &dmodemd on this computer (Windows 7 or later)", IDC_L_DMODEMD, 8, 8, 284, 10, WS_GROUP | WS_TABSTOP
LTEXT "SIP &user:", -1, 20, 24, 60, 8
EDITTEXT IDC_L_USER, 84, 22, 120, 12, ES_AUTOHSCROLL
AUTOCHECKBOX "&No account", IDC_L_ANONYMOUS, 210, 23, 82, 10, WS_TABSTOP
LTEXT "&Password:", -1, 20, 40, 60, 8
EDITTEXT IDC_L_PASSWORD, 84, 38, 120, 12, ES_AUTOHSCROLL | ES_PASSWORD
LTEXT "Ser&ver:", -1, 20, 56, 60, 8
EDITTEXT IDC_L_SERVER, 84, 54, 208, 12, ES_AUTOHSCROLL
AUTOCHECKBOX "Take &calls (register with the server)", IDC_L_LISTEN, 20, 72, 200, 10, WS_TABSTOP
AUTOCHECKBOX "Fax over &T.38", IDC_L_T38, 20, 84, 120, 10, WS_TABSTOP
AUTOCHECKBOX "Mark calls as modem data (V.15&2)", IDC_L_V152, 140, 84, 152, 10, WS_TABSTOP
AUTOCHECKBOX "Modem relay (V.15&0.1)", IDC_L_V150, 20, 96, 120, 10, WS_TABSTOP
LTEXT "C&ountry:", -1, 20, 112, 60, 8
EDITTEXT IDC_L_COUNTRY, 84, 110, 80, 12, ES_AUTOHSCROLL
LTEXT "(empty for the USA)", -1, 170, 112, 120, 8
LTEXT "USB &modem:", -1, 20, 128, 60, 8
EDITTEXT IDC_L_USB, 84, 126, 80, 12, ES_AUTOHSCROLL
LTEXT "(auto, or empty for SIP)", -1, 170, 128, 120, 8
LTEXT "dmodemd.e&xe:", -1, 20, 144, 60, 8
EDITTEXT IDC_L_PATH, 84, 142, 152, 12, ES_AUTOHSCROLL
PUSHBUTTON "&Browse...", IDC_L_BROWSE, 240, 141, 52, 14
AUTORADIOBUTTON "dmodemd on &another computer, or as a service (TCP)", IDC_L_TCP, 8, 164, 284, 10, WS_TABSTOP
LTEXT "&Address:", -1, 20, 180, 60, 8
EDITTEXT IDC_L_ADDRESS, 84, 178, 120, 12, ES_AUTOHSCROLL
AUTORADIOBUTTON "A modem on a &serial port", IDC_L_COM, 8, 198, 284, 10, WS_TABSTOP
LTEXT "P&ort:", -1, 20, 214, 60, 8
COMBOBOX IDC_L_PORT, 84, 212, 80, 120, CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
LTEXT "Bits per s&econd:", -1, 172, 214, 58, 8
COMBOBOX IDC_L_BPS, 232, 212, 60, 160, CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
LTEXT "Data b&its:", -1, 20, 230, 60, 8
COMBOBOX IDC_L_DATA, 84, 228, 30, 80, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Parit&y:", -1, 120, 230, 28, 8
COMBOBOX IDC_L_PARITY, 150, 228, 50, 80, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Stop bi&ts:", -1, 206, 230, 40, 8
COMBOBOX IDC_L_STOP, 248, 228, 44, 80, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Flow control:", -1, 20, 246, 60, 8
COMBOBOX IDC_L_FLOW, 84, 244, 80, 80, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Look for a modem", IDC_L_FIND, 212, 243, 80, 14
LTEXT "", IDC_L_FOUND, 20, 260, 272, 16
LTEXT "Commands when the modem &opens:", -1, 8, 280, 140, 8
EDITTEXT IDC_L_INIT, 8, 290, 284, 12, ES_AUTOHSCROLL
DEFPUSHBUTTON "OK", IDOK, 186, 312, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 242, 312, 50, 14
END
IDD_SETTING DIALOG 0, 0, 240, 110
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Change Setting"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "", IDC_S_LABEL, 8, 8, 224, 8
LTEXT "", IDC_S_HELP, 8, 20, 224, 20
COMBOBOX IDC_S_LIST, 8, 44, 224, 140, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
EDITTEXT IDC_S_EDIT, 8, 44, 224, 12, ES_AUTOHSCROLL
LTEXT "", IDC_S_RANGE, 8, 62, 224, 8
LTEXT "", IDC_S_DEFAULT, 8, 74, 224, 8
DEFPUSHBUTTON "OK", IDOK, 126, 90, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 182, 90, 50, 14
END
/* the Remote page's SSH login: up to four questions, each answer shown
(IDC_A_E0 + i) or hidden (IDC_A_E0P + i) */
IDD_ASK DIALOG 0, 0, 260, 170
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Log In"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "", IDC_A_HEAD, 8, 8, 244, 10
LTEXT "", IDC_A_TEXT, 8, 20, 244, 24
LTEXT "", IDC_A_Q0, 8, 48, 90, 8
EDITTEXT IDC_A_E0, 100, 46, 152, 12, ES_AUTOHSCROLL
EDITTEXT IDC_A_E0P, 100, 46, 152, 12, ES_AUTOHSCROLL | ES_PASSWORD
LTEXT "", 964, 8, 66, 90, 8
EDITTEXT 968, 100, 64, 152, 12, ES_AUTOHSCROLL
EDITTEXT 972, 100, 64, 152, 12, ES_AUTOHSCROLL | ES_PASSWORD
LTEXT "", 965, 8, 84, 90, 8
EDITTEXT 969, 100, 82, 152, 12, ES_AUTOHSCROLL
EDITTEXT 973, 100, 82, 152, 12, ES_AUTOHSCROLL | ES_PASSWORD
LTEXT "", 966, 8, 102, 90, 8
EDITTEXT 970, 100, 100, 152, 12, ES_AUTOHSCROLL
EDITTEXT 974, 100, 100, 152, 12, ES_AUTOHSCROLL | ES_PASSWORD
DEFPUSHBUTTON "&Log In", IDOK, 146, 150, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 202, 150, 50, 14
END
/* the Remote page's SSH login: by OpenSSH's keys and the agent, the
agent alone, or a key file (and a PuTTY key's import) */
IDD_LOGIN DIALOG 0, 0, 260, 150
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "SSH Login"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Log in &with:", -1, 8, 10, 56, 8
COMBOBOX IDC_K_HOW, 66, 8, 186, 60, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Key file (OpenSSH's, PEM or PuTTY's .ppk):", -1, 8, 28, 244, 8
EDITTEXT IDC_K_KEY, 8, 40, 186, 12, ES_AUTOHSCROLL
PUSHBUTTON "&Browse...", IDC_K_BROWSE, 200, 39, 52, 14
PUSHBUTTON "&Import PuTTY Key...", IDC_K_IMPORT, 8, 58, 90, 14
LTEXT "&Agent (empty: Pageant, else OpenSSH's; or pageant, or a pipe):", -1, 8, 80, 244, 8
EDITTEXT IDC_K_AGENT, 8, 92, 244, 12, ES_AUTOHSCROLL
LTEXT "", IDC_K_STATE, 8, 108, 244, 8
DEFPUSHBUTTON "OK", IDOK, 146, 128, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 202, 128, 50, 14
END
/* the Transfer menu's Send File: the file (or files), the protocol, and
what to type at the remote first */
IDD_XSEND DIALOG 0, 0, 280, 132
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Send File"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "&Filename (ZMODEM, YMODEM, Kermit: more than one, with ; between):", -1, 8, 8, 264, 8
EDITTEXT IDC_F_FILE, 8, 20, 206, 12, ES_AUTOHSCROLL
PUSHBUTTON "&Browse...", IDC_F_BROWSE, 220, 19, 52, 14
LTEXT "&Protocol:", -1, 8, 42, 60, 8
COMBOBOX IDC_F_PROTO, 70, 40, 144, 140, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Type at the remote first:", -1, 8, 60, 90, 8
EDITTEXT IDC_F_COMMAND, 100, 58, 172, 12, ES_AUTOHSCROLL
LTEXT "", IDC_F_HINT, 8, 76, 264, 32
DEFPUSHBUTTON "&Send", IDOK, 166, 112, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 222, 112, 50, 14
END
/* the Transfer menu's Receive File: the folder, the protocol, a name for
the protocols that send none, and what to type at the remote first */
IDD_XRECV DIALOG 0, 0, 280, 150
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Receive File"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "&Place received files in this folder:", -1, 8, 8, 264, 8
EDITTEXT IDC_F_FILE, 8, 20, 206, 12, ES_AUTOHSCROLL
PUSHBUTTON "&Browse...", IDC_F_BROWSE, 220, 19, 52, 14
LTEXT "&Use receiving protocol:", -1, 8, 42, 90, 8
COMBOBOX IDC_F_PROTO, 100, 40, 114, 140, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "File &name:", IDC_F_NAMELABEL, 8, 60, 90, 8
EDITTEXT IDC_F_NAME, 100, 58, 172, 12, ES_AUTOHSCROLL
LTEXT "&Type at the remote first:", -1, 8, 78, 90, 8
EDITTEXT IDC_F_COMMAND, 100, 76, 172, 12, ES_AUTOHSCROLL
LTEXT "", IDC_F_HINT, 8, 94, 264, 32
DEFPUSHBUTTON "&Receive", IDOK, 166, 130, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 222, 130, 50, 14
END
/* the Call menu's Call: a session (a name and a number) chosen, saved or
deleted, and the number called */
IDD_CALL DIALOG 0, 0, 240, 90
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Call"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "&Session:", -1, 8, 10, 60, 8
COMBOBOX IDC_C_NAME, 70, 8, 162, 140, CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
LTEXT "&Phone number:", -1, 8, 28, 60, 8
EDITTEXT IDC_C_NUMBER, 70, 26, 162, 12, ES_AUTOHSCROLL
LTEXT "A number, or a SIP address (sip:user@host).", -1, 70, 42, 162, 8
PUSHBUTTON "Sa&ve", IDC_C_SAVE, 8, 68, 50, 14
PUSHBUTTON "&Delete", IDC_C_DELETE, 62, 68, 50, 14
DEFPUSHBUTTON "&Call", IDOK, 128, 68, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 182, 68, 50, 14
END
/* the Modem menu's Terminal Settings, as HyperTerminal has them, for the
terminal of the page shown (the Remote page's, else the modem's) */
IDD_TERMSET DIALOG 0, 0, 284, 232
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Terminal Settings"
FONT 8, "MS Shell Dlg"
BEGIN
GROUPBOX "&Backspace key sends", -1, 8, 6, 118, 50
AUTORADIOBUTTON "Ctrl+&H", IDC_T_BSH, 16, 18, 100, 10, WS_GROUP | WS_TABSTOP
AUTORADIOBUTTON "&Del", IDC_T_BSDEL, 16, 30, 100, 10
AUTORADIOBUTTON "Ctrl+H, &Space, Ctrl+H", IDC_T_BSHSH, 16, 42, 104, 10
GROUPBOX "Function, arrow, and ctrl keys act as", -1, 134, 6, 142, 50
AUTORADIOBUTTON "Te&rminal keys", IDC_T_TERMKEYS, 142, 18, 100, 10, WS_GROUP | WS_TABSTOP
AUTORADIOBUTTON "&Windows keys", IDC_T_WINKEYS, 142, 30, 100, 10
GROUPBOX "Cursor", -1, 8, 62, 118, 50
AUTORADIOBUTTON "Bl&ock", IDC_T_BLOCK, 16, 74, 100, 10, WS_GROUP | WS_TABSTOP
AUTORADIOBUTTON "&Underline", IDC_T_UNDERLINE, 16, 86, 100, 10
AUTOCHECKBOX "B&link", IDC_T_BLINK, 16, 98, 100, 10, WS_GROUP | WS_TABSTOP
GROUPBOX "Font", -1, 134, 62, 142, 50
LTEXT "&Name:", -1, 142, 76, 30, 8
EDITTEXT IDC_T_FONT, 176, 74, 92, 12, ES_AUTOHSCROLL
LTEXT "Si&ze:", -1, 142, 94, 30, 8
EDITTEXT IDC_T_FONTSIZE, 176, 92, 24, 12, ES_NUMBER
LTEXT "points", -1, 204, 94, 40, 8
LTEXT "Ba&ckscroll buffer lines:", -1, 8, 122, 110, 8
EDITTEXT IDC_T_BACKSCROLL, 120, 120, 44, 12, ES_NUMBER
LTEXT "Telnet terminal &ID:", IDC_T_TELNETLABEL, 8, 140, 110, 8
EDITTEXT IDC_T_TELNETID, 120, 138, 80, 12, ES_AUTOHSCROLL
AUTOCHECKBOX "E&xit program upon disconnecting", IDC_T_EXIT, 8, 158, 240, 10
LTEXT "An empty font name uses the font of the app. An empty Telnet terminal ID uses the terminal type.", -1, 8, 174, 268, 20
DEFPUSHBUTTON "OK", IDOK, 168, 210, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 226, 210, 50, 14
END
/* the Modem menu's ASCII Setup, as HyperTerminal has it */
IDD_ASCII DIALOG 0, 0, 220, 176
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "ASCII Setup"
FONT 8, "MS Shell Dlg"
BEGIN
GROUPBOX "ASCII Sending", -1, 8, 6, 204, 74
AUTOCHECKBOX "&Send line ends with line feeds", IDC_A_SENDLF, 16, 18, 188, 10
AUTOCHECKBOX "&Echo typed characters locally", IDC_A_ECHO, 16, 32, 188, 10
LTEXT "&Line delay:", -1, 16, 48, 70, 8
EDITTEXT IDC_A_LINEDELAY, 90, 46, 36, 12, ES_NUMBER
LTEXT "milliseconds.", -1, 130, 48, 70, 8
LTEXT "&Character delay:", -1, 16, 64, 70, 8
EDITTEXT IDC_A_CHARDELAY, 90, 62, 36, 12, ES_NUMBER
LTEXT "milliseconds.", -1, 130, 64, 70, 8
GROUPBOX "ASCII Receiving", -1, 8, 86, 204, 62
AUTOCHECKBOX "&Append line feeds to incoming line ends", IDC_A_ADDLF, 16, 98, 188, 10
AUTOCHECKBOX "&Force incoming data to 7-bit ASCII", IDC_A_7BIT, 16, 112, 188, 10
AUTOCHECKBOX "&Wrap lines that exceed terminal width", IDC_A_WRAP, 16, 126, 188, 10
DEFPUSHBUTTON "OK", IDOK, 104, 156, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 162, 156, 50, 14
END
/* a transfer as it goes (modeless) */
IDD_XFER DIALOG 0, 0, 260, 146
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE
CAPTION "File Transfer"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Sending:", IDC_X_VERB, 8, 8, 46, 8
LTEXT "", IDC_X_FILE, 56, 8, 196, 8, SS_NOPREFIX
LTEXT "Folder:", -1, 8, 20, 46, 8
LTEXT "", IDC_X_WHERE, 56, 20, 196, 8, SS_NOPREFIX
LTEXT "Protocol:", -1, 8, 34, 46, 8
LTEXT "", IDC_X_PROTO, 56, 34, 70, 8
LTEXT "Files:", -1, 132, 34, 46, 8
LTEXT "", IDC_X_FILES, 180, 34, 72, 8
LTEXT "Retries:", -1, 8, 46, 46, 8
LTEXT "", IDC_X_ERRORS, 56, 46, 70, 8
LTEXT "Throughput:", -1, 132, 46, 46, 8
LTEXT "", IDC_X_RATE, 180, 46, 72, 8
LTEXT "Elapsed:", -1, 8, 58, 46, 8
LTEXT "", IDC_X_ELAPSED, 56, 58, 70, 8
LTEXT "Remaining:", -1, 132, 58, 46, 8
LTEXT "", IDC_X_LEFT, 180, 58, 72, 8
LTEXT "", IDC_X_BAR, 8, 74, 244, 12
LTEXT "", IDC_X_BYTES, 8, 90, 244, 8
LTEXT "", IDC_X_RESULT, 8, 104, 244, 16, SS_NOPREFIX
PUSHBUTTON "&Skip file", IDC_X_SKIP, 90, 126, 50, 14
PUSHBUTTON "c&ps/bps", IDC_X_UNITS, 146, 126, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 202, 126, 50, 14
END
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x4
FILETYPE 0x1
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "D-Modem\0"
VALUE "FileDescription", "D-Modem\0"
VALUE "FileVersion", "1.0.0\0"
VALUE "LegalCopyright", "Copyright (C) 2026 D-Modem Authors. AGPL-3.0-only.\0"
VALUE "ProductName", "D-Modem\0"
VALUE "ProductVersion", "1.0.0\0"
VALUE "OriginalFilename", "dmodem.exe\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

-21
View File
@@ -1,21 +0,0 @@
# The sources of the Windows app, for windows/ and winport/ (the same
# app on Linux and macOS)
set(DMODEM_WIN_SOURCES
main.cpp
link.cpp
pages.cpp
term.cpp
settings.cpp
pathview.cpp
config.cpp
voice.cpp
audio.cpp
termview.cpp
remote.cpp
xfer.cpp
capture.cpp
ascii.cpp
termset.cpp
calls.cpp
ports.cpp)
list(TRANSFORM DMODEM_WIN_SOURCES PREPEND "${CMAKE_CURRENT_LIST_DIR}/src/")
Loaded 100 of 125 files, more files were not shown because too many files have changed in this diff. Show more