winport: use clang-retro MFC's new APIs and remove the stand-ins

The Win32 layer now has sound (waveOut, waveIn, ACM), COM ports, pipes
and CreateProcess with standard handles, the environment and user
calls, the commctrl helper macros, winsock.h, WinMain's declaration,
hit tests through HTTRANSPARENT, Wingdings, and SHGetFolderPath. So
winport/include and winport/src/stubs.cpp go, and so do the group box
and Wingdings workarounds in the app.

On Linux and macOS the app now starts dmodemd (next to it, or on the
PATH) by default, and keeps its settings in the layer's CSIDL_APPDATA.
The main window gives the focus back to the control that had it when a
dialog box closes (on Windows too: after the SSH login, keys now go to
the terminal). The smoke test also starts a test dmodemd through a pipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRRhKGCaYUyYtH7Boap
This commit is contained in:
Claude committed 2026-11-20 20:13:16 +00:00
1 parent b4ca7d5b4c
commit 12c578d77f
18 files changed
+121 -578

No files matched your search

+1 -1
View File
@@ -121,7 +121,7 @@ jobs:
path: build/win7/windows/dmodem.exe
# The Windows app for Linux and macOS (winport/), over the portable
# Win32 layer of clang-retro MFC. First pass: TCP and SSH only.
# Win32 layer of clang-retro MFC.
winport-linux:
name: Windows app on Linux (clang-retro MFC's Win32 layer)
runs-on: ubuntu-24.04
+1 -1
View File
@@ -25,7 +25,7 @@ libdmodemctl. Thus they operate in the same way.
- **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)
- **Windows 95 and later**: plain Win32, built with [clang-retro](https://clang-retro.github.io/). On Windows 9x, the app connects to a modem through TCP or a COM port
- **The Windows app on Linux and macOS** (first pass): the same Win32 code, built over the portable Win32 layer of [clang-retro MFC](https://github.com/clang-retro/mfc). At this time, it connects to a modem through TCP only, and the Phone page cannot play or record sound. Refer to "The Windows app on Linux and macOS" in [Design](docs/design.md)
- **The Windows app on Linux and macOS**: the same Win32 code, built over the portable Win32 layer of [clang-retro MFC](https://github.com/clang-retro/mfc). It starts dmodemd, or connects to a modem through TCP or a COM port. Refer to "The Windows app on Linux and macOS" in [Design](docs/design.md)
| | Windows | macOS | Linux |
| --- | --- | --- | --- |
+23 -33
View File
@@ -331,43 +331,33 @@ machine through TCP.
## The Windows app on Linux and macOS
The Windows app also builds for Linux and macOS. This is a first pass.
clang-retro MFC has a portable Win32 layer (`port/`, `libwinport.a`). The
layer supplies the Win32 API on X11, Wayland and Cocoa. The app links
with this layer and not with Windows. Its source code is the same as on
Windows.
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.
`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 `~/.config/D-Modem/dmodem.ini`.
- The line is TCP by default (`127.0.0.1:2323`, a dmodemd that runs).
The app does not start dmodemd on these systems yet.
- SSH uses `~/.ssh` and `/` in paths.
- The path view on the Settings page draws its pictures from Unicode
(DejaVu Sans), because these systems do not have Wingdings.
- The group boxes go under the other controls. The hit test of the
layer stops at a window that answers `HTTRANSPARENT`, and does not
try the windows under it. Windows tries them. Thus without this
change, a click on a control in a group box goes to the page.
- The layer does not have these functions yet. `winport/include` and
`winport/src/stubs.cpp` supply stand-ins for them:
| Function | The stand-in |
| --- | --- |
| `waveOut*`, `waveIn*` (`mmsystem.h`), `acm*` (`msacm.h`) | Returns `MMSYSERR_NODRIVER`. The Phone page cannot play or record. |
| `GetCommState`, `SetCommState`, `SetCommTimeouts` (COM ports) | Returns `FALSE` (`ERROR_NOT_SUPPORTED`). Do not use a COM port. |
| `CreatePipe`, `PeekNamedPipe` | Returns `FALSE`. The app cannot start dmodemd. |
| `GetEnvironmentStrings`, `GetUserName`, `Beep` | Uses `environ`, `$USER` and `MessageBeep`. |
| `ListView_*`, `TabCtrl_*` (`commctrl.h`), `winsock.h` | Macros and an include of `winsock2.h`. |
When the layer gets these functions, remove the stand-ins (and the
group box change). Each stand-in is in `winport/` only, or in a
`DMODEM_WINPORT` block.
- CI builds the app on Linux and macOS. On Linux, it starts the app in
Xvfb with `winport/test/smoke.sh`. The test makes sure that the app
stays up and sends AT commands to a test modem through TCP.
- 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`.
- SSH uses `~/.ssh` and `/` in paths, because libssh uses POSIX paths
on these systems.
- The layer changes a COM port name to a device: `COM1` is `/dev/ttyS0`.
- CI builds the app on Linux and macOS. On Linux, `winport/test/smoke.sh`
starts the app in Xvfb two times: with a TCP line, and with a dmodemd
that the app starts (`winport/test/dmodemd`, a test dmodemd). Each time,
the test makes sure that the app stays up and sends AT commands to a
test modem.
+4 -2
View File
@@ -45,14 +45,16 @@
#endif
/* the separator of paths that libssh and the C library see: Windows', or
POSIX on Linux and macOS (winport/); and the name of the folder that
holds .ssh */
POSIX on Linux and macOS (winport/); the name of the folder that holds
.ssh; and dmodemd's file name */
#ifdef DMODEM_WINPORT
#define DIR_SEP "/"
#define PROFILE_NAME "home folder"
#define DMODEMD_EXE "dmodemd"
#else
#define DIR_SEP "\\"
#define PROFILE_NAME "profile"
#define DMODEMD_EXE "dmodemd.exe"
#endif
/* (older headers, Open Watcom's among them, without the 64-bit names) */
+12 -8
View File
@@ -13,6 +13,9 @@
#include "app.h"
#include <commdlg.h>
#include "resource.h"
#ifdef DMODEM_WINPORT
#include <shlobj.h>
#endif
#ifndef OPENFILENAME_SIZE_VERSION_400
#define OPENFILENAME_SIZE_VERSION_400 76
@@ -22,11 +25,12 @@ void app_data_dir(char *out, int n)
{
char dir[MAX_PATH];
#ifdef DMODEM_WINPORT
/* (Linux and macOS, winport/: ~/.config/D-Modem) */
const char *home = getenv("HOME");
if (home && strlen(home) < sizeof(dir) - 20) {
_snprintf(dir, sizeof(dir), "%s/.config", home);
CreateDirectory(dir, NULL);
/* (Linux and macOS, winport/: the layer's CSIDL_APPDATA, ~/.config or
~/Library/Application Support; Windows 95 has no SHGetFolderPath,
so Windows uses APPDATA) */
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, 0, dir)) &&
strlen(dir) < sizeof(dir) - 10) {
strcat(dir, "/D-Modem");
CreateDirectory(dir, NULL);
_snprintf(out, n, "%s", dir);
@@ -92,10 +96,10 @@ void config_load(Config *c)
GetVersionEx(&v);
bool old = v.dwPlatformId != VER_PLATFORM_WIN32_NT || v.dwMajorVersion < 6;
#ifdef DMODEM_WINPORT
/* (Linux and macOS, winport/: no COM ports or dmodemd started by the
app yet, so a dmodemd that runs, through TCP) */
/* (Linux and macOS, winport/: dmodemd runs there, whatever Windows
version the layer reports) */
(void)old;
c->line = get_i(ini, "line", LINE_TCP);
c->line = get_i(ini, "line", LINE_DMODEMD);
#else
c->line = get_i(ini, "line", old ? LINE_COM : LINE_DMODEMD);
#endif
+12 -4
View File
@@ -175,7 +175,7 @@ static bool open_com(const char *name)
return true;
}
/* dmodemd.exe: the configured one, or next to this app */
/* dmodemd: the configured one, or next to this app */
static void dmodemd_path(char *out, int n)
{
if (app.cfg.dmodemd[0]) {
@@ -184,9 +184,17 @@ static void dmodemd_path(char *out, int n)
return;
}
GetModuleFileName(NULL, out, n);
char *slash = strrchr(out, '\\');
char *slash = strrchr(out, DIR_SEP[0]);
if (slash)
strcpy(slash + 1, "dmodemd.exe");
strcpy(slash + 1, DMODEMD_EXE);
#ifdef DMODEM_WINPORT
/* (Linux and macOS, winport/: else the one on the PATH) */
char found[MAX_PATH];
if (GetFileAttributes(out) == (DWORD)-1 &&
SearchPath(NULL, DMODEMD_EXE, NULL, sizeof(found), found, NULL))
_snprintf(out, n, "%s", found);
out[n - 1] = '\0';
#endif
}
/* an environment block: ours, and these */
@@ -234,7 +242,7 @@ static bool start_dmodemd()
dmodemd_path(exe, sizeof(exe));
if (GetFileAttributes(exe) == (DWORD)-1) {
char m[MAX_PATH + 64];
_snprintf(m, sizeof(m), "dmodemd.exe was not found (%s)", exe);
_snprintf(m, sizeof(m), DMODEMD_EXE " was not found (%s)", exe);
m[sizeof(m) - 1] = '\0';
app_message(m);
app_log(m);
+17 -21
View File
@@ -173,23 +173,6 @@ void app_event(const dmc_event *ev)
}
}
#ifdef DMODEM_WINPORT
/* (Linux and macOS, winport/: the layer's hit test stops at a group box,
which answers HTTRANSPARENT, and does not try the controls under it.
Windows tries them. Until the layer does too, put the group boxes
under the other controls.) */
static BOOL CALLBACK lower_group_box(HWND c, LPARAM lp)
{
char cls[16];
(void)lp;
if (GetClassName(c, cls, sizeof(cls)) && !lstrcmpi(cls, "BUTTON") &&
(GetWindowLong(c, GWL_STYLE) & BS_TYPEMASK) == BS_GROUPBOX)
SetWindowPos(c, HWND_BOTTOM, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
return TRUE;
}
#endif
static void show_page(int i)
{
for (int p = 0; p < PAGES; p++)
@@ -262,15 +245,28 @@ static LRESULT CALLBACK main_proc(HWND w, UINT m, WPARAM wp, LPARAM lp)
for (int p = 0; p < PAGES; p++)
SetWindowPos(app.pages[p], HWND_TOP, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
#ifdef DMODEM_WINPORT
for (int p = 0; p < PAGES; p++)
EnumChildWindows(app.pages[p], lower_group_box, 0);
#endif
show_page(PAGE_MODEM);
SetTimer(w, TIMER_PUMP, 50, NULL);
app_state();
return 0;
}
case WM_ACTIVATE: {
/* the control with the focus kept while another window (a
dialog box) is active, and given back after: the default
gives the focus to this window */
static HWND last_focus;
if (LOWORD(wp) == WA_INACTIVE) {
HWND f = GetFocus();
if (f && IsChild(w, f))
last_focus = f;
} else if (last_focus && IsWindow(last_focus) &&
IsWindowVisible(last_focus) &&
IsWindowEnabled(last_focus)) {
SetFocus(last_focus);
return 0;
}
break;
}
case WM_SIZE:
layout();
return 0;
-25
View File
@@ -53,21 +53,6 @@ static const char *mark(int kind, bool *wingdings)
}
}
#ifdef DMODEM_WINPORT
/* (Linux and macOS, winport/: no Wingdings there; the same pictures from
Unicode, in a font that the system has) */
static const wchar_t *mark_w(const char *m)
{
switch (m[0]) {
case ':': return L"\x2328"; /* a keyboard */
case ';': return L"\x25A3"; /* a box */
case ')': return L"\x260E"; /* a telephone */
case '*': return L"\x2709"; /* an envelope */
default: return L"\x260F"; /* a telephone, white */
}
}
#endif
static void line(HDC dc, int st, int x0, int x1, int y)
{
bool dashed = st == DMC_STEP_SETUP || st == DMC_STEP_OFF;
@@ -133,12 +118,6 @@ static void paint(HWND w)
RECT g = { cx - r, cy - r, cx + r, cy + r };
SelectObject(dc, wd ? glyph_font : app.font);
SetTextColor(dc, state_color(st));
#ifdef DMODEM_WINPORT
if (wd)
DrawTextW(dc, mark_w(m), -1, &g, DT_CENTER | DT_VCENTER |
DT_SINGLELINE | DT_NOPREFIX);
else
#endif
DrawText(dc, m, -1, &g, DT_CENTER | DT_VCENTER | DT_SINGLELINE |
DT_NOPREFIX);
RECT tt = { x, cy + r + 4, x + cw, cy + r + 4 + th };
@@ -185,12 +164,8 @@ HWND pathview_new(HWND parent)
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -20;
#ifdef DMODEM_WINPORT
strcpy(lf.lfFaceName, "DejaVu Sans");
#else
lf.lfCharSet = SYMBOL_CHARSET;
strcpy(lf.lfFaceName, "Wingdings");
#endif
glyph_font = CreateFontIndirect(&lf);
}
path = dmc_path_new();
+2 -13
View File
@@ -3,12 +3,6 @@
#
# cmake -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \
# -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
#
# This is a first pass. The layer does not have serial ports, pipes or
# audio (waveOut, waveIn and ACM) yet. The files in include/ and
# src/stubs.cpp supply stand-ins: these functions fail, so the app uses
# the TCP and SSH links only. When the layer gets these functions,
# remove the stand-ins.
enable_language(CXX)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -64,10 +58,7 @@ set(APP_RES_CPP "${CMAKE_CURRENT_BINARY_DIR}/app-res.cpp")
add_custom_command(OUTPUT "${APP_RES_CPP}"
COMMAND ${CMAKE_COMMAND} -E env RC=${DMODEM_LLVM_RC} CXX=${CMAKE_CXX_COMPILER}
${Python3_EXECUTABLE} "${CLANG_RETRO_MFC}/port/tools/res2cpp.py"
-I "${_win}/src" -I "${_win}/res" app.rc -o "${APP_RES_CPP}"
# (app.rc by a relative path: llvm-rc takes an absolute macOS path,
# /Users/..., for an option)
WORKING_DIRECTORY "${_win}/res"
-I "${_win}/src" -I "${_win}/res" "${_win}/res/app.rc" -o "${APP_RES_CPP}"
DEPENDS "${_win}/res/app.rc" "${_win}/res/app.manifest" "${_win}/res/dmodem.ico"
"${_win}/src/resource.h"
COMMENT "Converting app.rc to C++"
@@ -76,12 +67,10 @@ add_custom_command(OUTPUT "${APP_RES_CPP}"
include("${_win}/sources.cmake")
add_executable(dmodem-win32
${DMODEM_WIN_SOURCES}
src/stubs.cpp
"${APP_RES_CPP}")
set_target_properties(dmodem-win32 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
# Our stand-in headers come first, then the layer's headers.
target_include_directories(dmodem-win32 BEFORE PRIVATE
include "${CLANG_RETRO_MFC}/port/include" "${_win}/src" "${_win}/res")
"${CLANG_RETRO_MFC}/port/include" "${_win}/src" "${_win}/res")
target_compile_definitions(dmodem-win32 PRIVATE DMODEM_WINPORT)
target_compile_options(dmodem-win32 PRIVATE -Wall -Wno-unused-parameter)
target_link_libraries(dmodem-win32 PRIVATE dmodemctl winport)
-63
View File
@@ -1,63 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* commctrl.h - the common controls of the Win32 layer (clang-retro MFC's
* port/), with the helper macros of the SDK that the app
* uses and the layer does not have yet. (<objidl.h> first:
* the layer's commctrl.h needs LPSTREAM, which its
* <windows.h> gives only without WIN32_LEAN_AND_MEAN.)
*/
#ifndef DMODEM_WINPORT_COMMCTRL_H
#define DMODEM_WINPORT_COMMCTRL_H
#include <windows.h>
#include <objidl.h>
#include_next <commctrl.h>
#ifndef ListView_InsertColumn
#define ListView_InsertColumn(w, i, c) \
(int)SendMessage((w), LVM_INSERTCOLUMN, (WPARAM)(int)(i), (LPARAM)(c))
#endif
#ifndef ListView_InsertItem
#define ListView_InsertItem(w, item) \
(int)SendMessage((w), LVM_INSERTITEM, 0, (LPARAM)(item))
#endif
#ifndef ListView_GetItem
#define ListView_GetItem(w, item) \
(BOOL)SendMessage((w), LVM_GETITEM, 0, (LPARAM)(item))
#endif
#ifndef ListView_DeleteAllItems
#define ListView_DeleteAllItems(w) \
(BOOL)SendMessage((w), LVM_DELETEALLITEMS, 0, 0)
#endif
#ifndef ListView_GetNextItem
#define ListView_GetNextItem(w, i, flags) \
(int)SendMessage((w), LVM_GETNEXTITEM, (WPARAM)(int)(i), \
MAKELPARAM((flags), 0))
#endif
#ifndef ListView_SetExtendedListViewStyle
#define ListView_SetExtendedListViewStyle(w, ex) \
(DWORD)SendMessage((w), LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)(ex))
#endif
#ifndef ListView_SetItemText
#define ListView_SetItemText(w, i, sub, text) \
do { \
LV_ITEM lvi_; \
lvi_.iSubItem = (sub); \
lvi_.pszText = (text); \
SendMessage((w), LVM_SETITEMTEXT, (WPARAM)(i), \
(LPARAM)&lvi_); \
} while (0)
#endif
#ifndef TabCtrl_InsertItem
#define TabCtrl_InsertItem(w, i, item) \
(int)SendMessage((w), TCM_INSERTITEM, (WPARAM)(int)(i), (LPARAM)(item))
#endif
#ifndef TabCtrl_GetCurSel
#define TabCtrl_GetCurSel(w) (int)SendMessage((w), TCM_GETCURSEL, 0, 0)
#endif
#ifndef TabCtrl_AdjustRect
#define TabCtrl_AdjustRect(w, larger, rc) \
(void)SendMessage((w), TCM_ADJUSTRECT, (WPARAM)(BOOL)(larger), (LPARAM)(rc))
#endif
#endif
-26
View File
@@ -1,26 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* mmreg.h - the MP3 format of the ACM, as the app's audio.cpp names it
*/
#ifndef DMODEM_WINPORT_MMREG_H
#define DMODEM_WINPORT_MMREG_H
#include <mmsystem.h>
#define WAVE_FORMAT_MPEGLAYER3 0x0055
#define MPEGLAYER3_WFX_EXTRA_BYTES 12
#define MPEGLAYER3_ID_MPEG 1
#define MPEGLAYER3_FLAG_PADDING_OFF 0x00000002
#pragma pack(push, 1)
typedef struct mpeglayer3waveformat_tag {
WAVEFORMATEX wfx;
WORD wID;
DWORD fdwFlags;
WORD nBlockSize;
WORD nFramesPerBlock;
WORD nCodecDelay;
} MPEGLAYER3WAVEFORMAT, *LPMPEGLAYER3WAVEFORMAT;
#pragma pack(pop)
#endif
-77
View File
@@ -1,77 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* mmsystem.h - the part of the multimedia API that the app's sound
* (audio.cpp, voice.cpp) uses, which the Win32 layer does not
* have. First pass: the functions are in src/stubs.cpp and
* answer MMSYSERR_NODRIVER (no sound device).
*/
#ifndef DMODEM_WINPORT_MMSYSTEM_H
#define DMODEM_WINPORT_MMSYSTEM_H
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef UINT MMRESULT;
typedef struct dmodem_hwaveout *HWAVEOUT;
typedef struct dmodem_hwavein *HWAVEIN;
#define MMSYSERR_NOERROR 0
#define MMSYSERR_ERROR 1
#define MMSYSERR_BADDEVICEID 2
#define MMSYSERR_NODRIVER 6
#define WAVE_MAPPER ((UINT)-1)
#define CALLBACK_WINDOW 0x00010000L
#define MM_WOM_DONE 0x3BD
#define MM_WIM_DATA 0x3C0
#define WHDR_DONE 0x00000001
#define WHDR_PREPARED 0x00000002
#define WAVE_FORMAT_PCM 1
#pragma pack(push, 1)
typedef struct tWAVEFORMATEX {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX;
#pragma pack(pop)
typedef const WAVEFORMATEX *LPCWAVEFORMATEX;
typedef struct wavehdr_tag {
LPSTR lpData;
DWORD dwBufferLength;
DWORD dwBytesRecorded;
DWORD_PTR dwUser;
DWORD dwFlags;
DWORD dwLoops;
struct wavehdr_tag *lpNext;
DWORD_PTR reserved;
} WAVEHDR, *PWAVEHDR, *LPWAVEHDR;
MMRESULT WINAPI waveOutOpen(HWAVEOUT *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
DWORD_PTR, DWORD);
MMRESULT WINAPI waveOutClose(HWAVEOUT);
MMRESULT WINAPI waveOutPrepareHeader(HWAVEOUT, LPWAVEHDR, UINT);
MMRESULT WINAPI waveOutUnprepareHeader(HWAVEOUT, LPWAVEHDR, UINT);
MMRESULT WINAPI waveOutWrite(HWAVEOUT, LPWAVEHDR, UINT);
MMRESULT WINAPI waveOutReset(HWAVEOUT);
MMRESULT WINAPI waveInOpen(HWAVEIN *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
DWORD_PTR, DWORD);
MMRESULT WINAPI waveInClose(HWAVEIN);
MMRESULT WINAPI waveInPrepareHeader(HWAVEIN, LPWAVEHDR, UINT);
MMRESULT WINAPI waveInUnprepareHeader(HWAVEIN, LPWAVEHDR, UINT);
MMRESULT WINAPI waveInAddBuffer(HWAVEIN, LPWAVEHDR, UINT);
MMRESULT WINAPI waveInStart(HWAVEIN);
MMRESULT WINAPI waveInReset(HWAVEIN);
#ifdef __cplusplus
}
#endif
#endif
-62
View File
@@ -1,62 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* msacm.h - the Audio Compression Manager calls that the app's audio.cpp
* uses (greetings in MP3 and compressed WAVs). First pass: the
* functions are in src/stubs.cpp and answer MMSYSERR_NODRIVER,
* so the app reads only the files that libdmodemctl decodes.
*/
#ifndef DMODEM_WINPORT_MSACM_H
#define DMODEM_WINPORT_MSACM_H
#include <mmsystem.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct dmodem_hacmstream *HACMSTREAM;
typedef HACMSTREAM *LPHACMSTREAM;
typedef struct dmodem_hacmdriver *HACMDRIVER;
#define ACM_FORMATSUGGESTF_WFORMATTAG 0x00010000L
#define ACM_FORMATSUGGESTF_NCHANNELS 0x00020000L
#define ACM_FORMATSUGGESTF_NSAMPLESPERSEC 0x00040000L
#define ACM_FORMATSUGGESTF_WBITSPERSAMPLE 0x00080000L
#define ACM_STREAMOPENF_NONREALTIME 0x00000004L
#define ACM_STREAMSIZEF_SOURCE 0x00000000L
#define ACM_STREAMCONVERTF_BLOCKALIGN 0x00000004
#define ACM_STREAMCONVERTF_START 0x00000010
#define ACM_STREAMCONVERTF_END 0x00000020
typedef struct tACMSTREAMHEADER {
DWORD cbStruct;
DWORD fdwStatus;
DWORD_PTR dwUser;
LPBYTE pbSrc;
DWORD cbSrcLength;
DWORD cbSrcLengthUsed;
DWORD_PTR dwSrcUser;
LPBYTE pbDst;
DWORD cbDstLength;
DWORD cbDstLengthUsed;
DWORD_PTR dwDstUser;
DWORD dwReservedDriver[10];
} ACMSTREAMHEADER, *LPACMSTREAMHEADER;
MMRESULT WINAPI acmFormatSuggest(HACMDRIVER, LPWAVEFORMATEX, LPWAVEFORMATEX,
DWORD, DWORD);
MMRESULT WINAPI acmStreamOpen(LPHACMSTREAM, HACMDRIVER, LPWAVEFORMATEX,
LPWAVEFORMATEX, LPVOID, DWORD_PTR, DWORD_PTR,
DWORD);
MMRESULT WINAPI acmStreamClose(HACMSTREAM, DWORD);
MMRESULT WINAPI acmStreamSize(HACMSTREAM, DWORD, LPDWORD, DWORD);
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM, LPACMSTREAMHEADER, DWORD);
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM, LPACMSTREAMHEADER,
DWORD);
MMRESULT WINAPI acmStreamConvert(HACMSTREAM, LPACMSTREAMHEADER, DWORD);
#ifdef __cplusplus
}
#endif
#endif
-92
View File
@@ -1,92 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* windows.h - the Win32 layer of clang-retro MFC (port/), and the calls of
* the app that it does not have yet: serial ports, anonymous
* pipes, the environment block, the user name, Beep and
* the declaration of WinMain.
* First pass: src/stubs.cpp has them. The serial and pipe
* calls fail, so the app reaches a modem through TCP only.
*/
#ifndef DMODEM_WINPORT_WINDOWS_H
#define DMODEM_WINPORT_WINDOWS_H
#include_next <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
/* (the SDK's winbase.h declares it, with C linkage; the layer's crt0
calls it) */
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
/* serial ports */
#define CBR_115200 115200
#define NOPARITY 0
#define ONESTOPBIT 0
#define DTR_CONTROL_ENABLE 0x01
#define RTS_CONTROL_HANDSHAKE 0x02
typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD fBinary : 1;
DWORD fParity : 1;
DWORD fOutxCtsFlow : 1;
DWORD fOutxDsrFlow : 1;
DWORD fDtrControl : 2;
DWORD fDsrSensitivity : 1;
DWORD fTXContinueOnXoff : 1;
DWORD fOutX : 1;
DWORD fInX : 1;
DWORD fErrorChar : 1;
DWORD fNull : 1;
DWORD fRtsControl : 2;
DWORD fAbortOnError : 1;
DWORD fDummy2 : 17;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB, *LPDCB;
typedef struct _COMMTIMEOUTS {
DWORD ReadIntervalTimeout;
DWORD ReadTotalTimeoutMultiplier;
DWORD ReadTotalTimeoutConstant;
DWORD WriteTotalTimeoutMultiplier;
DWORD WriteTotalTimeoutConstant;
} COMMTIMEOUTS, *LPCOMMTIMEOUTS;
BOOL WINAPI GetCommState(HANDLE, LPDCB);
BOOL WINAPI SetCommState(HANDLE, LPDCB);
BOOL WINAPI SetCommTimeouts(HANDLE, LPCOMMTIMEOUTS);
/* anonymous pipes */
BOOL WINAPI CreatePipe(PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD);
BOOL WINAPI PeekNamedPipe(HANDLE, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD);
/* the environment, the user, the speaker */
LPSTR WINAPI dmodem_GetEnvironmentStringsA(void);
BOOL WINAPI dmodem_FreeEnvironmentStringsA(LPSTR);
#define GetEnvironmentStrings dmodem_GetEnvironmentStringsA
#define FreeEnvironmentStrings dmodem_FreeEnvironmentStringsA
BOOL WINAPI GetUserNameA(LPSTR, LPDWORD);
#ifndef UNICODE
#define GetUserName GetUserNameA
#endif
BOOL WINAPI Beep(DWORD, DWORD);
#ifdef __cplusplus
}
#endif
#endif
-3
View File
@@ -1,3 +0,0 @@
/* winsock.h - Winsock 1.1: the Win32 layer has the Winsock 2 header,
which has each function of 1.1 */
#include <winsock2.h>
-126
View File
@@ -1,126 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* stubs.cpp - the Win32 calls of the app that the Win32 layer of
* clang-retro MFC does not have yet (include/). First pass:
* the sound, ACM, serial and pipe calls fail, so the app
* operates through TCP (a dmodemd that already runs) and
* SSH, Telnet and rlogin. Remove each one when the layer
* has it.
*/
#include <windows.h>
#include <mmsystem.h>
#include <msacm.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
extern char **environ;
extern "C" {
/* sound: no device */
MMRESULT WINAPI waveOutOpen(HWAVEOUT *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
DWORD_PTR, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveOutClose(HWAVEOUT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveOutPrepareHeader(HWAVEOUT, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveOutUnprepareHeader(HWAVEOUT, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveOutWrite(HWAVEOUT, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveOutReset(HWAVEOUT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInOpen(HWAVEIN *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
DWORD_PTR, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInClose(HWAVEIN) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInPrepareHeader(HWAVEIN, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInUnprepareHeader(HWAVEIN, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInAddBuffer(HWAVEIN, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInStart(HWAVEIN) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI waveInReset(HWAVEIN) { return MMSYSERR_NODRIVER; }
/* ACM: no codecs */
MMRESULT WINAPI acmFormatSuggest(HACMDRIVER, LPWAVEFORMATEX, LPWAVEFORMATEX,
DWORD, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI acmStreamOpen(LPHACMSTREAM, HACMDRIVER, LPWAVEFORMATEX,
LPWAVEFORMATEX, LPVOID, DWORD_PTR, DWORD_PTR,
DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI acmStreamClose(HACMSTREAM, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI acmStreamSize(HACMSTREAM, DWORD, LPDWORD, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM, LPACMSTREAMHEADER, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM, LPACMSTREAMHEADER, DWORD) { return MMSYSERR_NODRIVER; }
MMRESULT WINAPI acmStreamConvert(HACMSTREAM, LPACMSTREAMHEADER, DWORD) { return MMSYSERR_NODRIVER; }
/* serial ports: none */
BOOL WINAPI GetCommState(HANDLE, LPDCB)
{
SetLastError(ERROR_NOT_SUPPORTED);
return FALSE;
}
BOOL WINAPI SetCommState(HANDLE, LPDCB)
{
SetLastError(ERROR_NOT_SUPPORTED);
return FALSE;
}
BOOL WINAPI SetCommTimeouts(HANDLE, LPCOMMTIMEOUTS)
{
SetLastError(ERROR_NOT_SUPPORTED);
return FALSE;
}
/* anonymous pipes: none (no dmodemd started by the app) */
BOOL WINAPI CreatePipe(PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD)
{
SetLastError(ERROR_NOT_SUPPORTED);
return FALSE;
}
BOOL WINAPI PeekNamedPipe(HANDLE, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD)
{
SetLastError(ERROR_NOT_SUPPORTED);
return FALSE;
}
/* the environment block of Windows (NAME=VALUE\0 ... \0) from environ */
LPSTR WINAPI dmodem_GetEnvironmentStringsA(void)
{
size_t n = 1;
for (char **e = environ; *e; e++)
n += strlen(*e) + 1;
char *block = (char *)malloc(n), *p = block;
if (!block)
return NULL;
for (char **e = environ; *e; e++) {
size_t l = strlen(*e) + 1;
memcpy(p, *e, l);
p += l;
}
*p = '\0';
return block;
}
BOOL WINAPI dmodem_FreeEnvironmentStringsA(LPSTR block)
{
free(block);
return TRUE;
}
BOOL WINAPI GetUserNameA(LPSTR name, LPDWORD n)
{
const char *u = getenv("USER");
if (!u)
u = getlogin();
if (!u || strlen(u) + 1 > *n) {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
strcpy(name, u);
*n = (DWORD)strlen(u) + 1;
return TRUE;
}
/* (no speaker: the terminal's bell is MessageBeep) */
BOOL WINAPI Beep(DWORD, DWORD)
{
MessageBeep(MB_OK);
return TRUE;
}
}
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
# A dmodemd for the smoke test: it takes --tcp HOST:PORT, says which
# port to use as dmodemd does, and starts the test modem on that port.
here=$(cd "$(dirname "$0")" && pwd)
port=$(echo "$*" | sed -n 's/.*--tcp [0-9.]*:\([0-9]*\).*/\1/p')
echo "test dmodemd: $*"
(sleep 1; echo "Use TCP 127.0.0.1:$port as the modem") &
exec python3 -u "$here/fake_modem.py" "$port" "$DMODEM_TEST_LOG"
+41 -21
View File
@@ -1,32 +1,52 @@
#!/bin/sh
# The smoke test of the Linux build (winport/): starts the app on an X
# display with an empty home folder, and makes sure that it stays up and
# sends its first AT commands to a test modem on the TCP port that it
# uses by default (127.0.0.1:2323).
# The smoke test of the Linux build (winport/). It starts the app on an
# X display, with an empty home folder, two times:
# 1. With a TCP line (127.0.0.1:2323) to a test modem.
# 2. With a dmodemd that the app starts: the test dmodemd in this
# folder, found on the PATH, through a pipe (CreatePipe,
# CreateProcess with STARTF_USESTDHANDLES and PeekNamedPipe).
# Each time, the app must stay up and send its first AT commands.
#
# DISPLAY=:99 winport/test/smoke.sh build/winport/dmodem-win32
set -eu
app=$1
here=$(cd "$(dirname "$0")" && pwd)
tmp=$(mktemp -d)
trap 'kill $modem $pid 2>/dev/null || true; rm -rf "$tmp"' EXIT
pid= modem=
trap 'kill $modem $pid 2>/dev/null || true; pkill -f "fake_modem.py .* $tmp/" 2>/dev/null || true; rm -rf "$tmp"' EXIT
python3 "$here/fake_modem.py" 2323 "$tmp/modem.log" &
# run NAME INI: starts the app with this settings file, and waits for AT
# commands in $tmp/NAME.log
run() {
name=$1
rm -rf "$tmp/home"
mkdir -p "$tmp/home/.config/D-Modem"
printf '%b' "$2" > "$tmp/home/.config/D-Modem/dmodem.ini"
HOME="$tmp/home" XDG_CONFIG_HOME= PATH="$here:$PATH" \
DMODEM_TEST_LOG="$tmp/$name.log" WINPORT_BACKEND=x11 "$app" &
pid=$!
i=0
while [ $i -lt 20 ]; do
sleep 1
kill -0 $pid 2>/dev/null || { echo "FAIL ($name): the app stopped"; exit 1; }
grep -q '^AT' "$tmp/$name.log" 2>/dev/null && break
i=$((i + 1))
done
grep -q '^AT' "$tmp/$name.log" 2>/dev/null ||
{ echo "FAIL ($name): no AT commands"; exit 1; }
sleep 2
kill -0 $pid 2>/dev/null || { echo "FAIL ($name): the app stopped"; exit 1; }
echo "$name: the modem got:"
cat "$tmp/$name.log"
kill $pid
wait $pid 2>/dev/null || true
pid=
}
python3 "$here/fake_modem.py" 2323 "$tmp/tcp.log" &
modem=$!
sleep 1
HOME="$tmp/home" WINPORT_BACKEND=x11 "$app" &
pid=$!
i=0
while [ $i -lt 20 ]; do
sleep 1
kill -0 $pid 2>/dev/null || { echo "FAIL: the app stopped"; exit 1; }
grep -q '^AT' "$tmp/modem.log" 2>/dev/null && break
i=$((i + 1))
done
grep -q '^AT' "$tmp/modem.log" || { echo "FAIL: no AT commands on the TCP port"; exit 1; }
sleep 2
kill -0 $pid 2>/dev/null || { echo "FAIL: the app stopped"; exit 1; }
echo "The modem got:"
cat "$tmp/modem.log"
run tcp '[line]\nline=1\ntcp=127.0.0.1:2323\n'
# (a USB modem: dmodemd needs no SIP account for it)
run dmodemd '[line]\nline=0\nusb=test0\n'
echo "PASS"