// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later // Package ocrconfirm runs only in the short-lived confirmation helper. package ocrconfirm /* #cgo pkg-config: gtk+-3.0 #include int cthulhu_ocr_confirm(const char *word); */ import "C" import ( "bytes" "io" "unicode/utf8" "unsafe" ) func Run(input io.Reader, output io.Writer) error { data, err := io.ReadAll(io.LimitReader(input, 4097)) if err != nil || len(data) == 0 || len(data) > 4096 || !utf8.Valid(data) || bytes.IndexByte(data, 0) >= 0 { return io.ErrUnexpectedEOF } word := C.CString(string(data)) defer C.free(unsafe.Pointer(word)) if C.cthulhu_ocr_confirm(word) == 1 { _, err = io.WriteString(output, "yes\n") } else { _, err = io.WriteString(output, "cancel\n") } return err }