// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com) // All rights reserved. // SET command functions: SET EXACT, SET SOFTSEEK, SET DELETED, SET EXCLUSIVE, // SET(_SET_xxx, lValue) pattern. // Harbour: src/rtl/set.c — 47+ settings in HB_SET_ENUM. package hbrtl import ( "five/hbrt" "sync" ) // SET indices (Harbour HB_SET_ENUM compatible) const ( SetExact = 1 SetFixed = 2 SetDecimals = 3 SetDateFmt = 4 SetEpoch = 5 SetPath = 6 SetDefault = 7 SetDeleted = 8 SetExclusive = 11 SetSoftSeek = 12 SetUnique = 13 SetCancel = 14 SetConfirm = 15 SetConsole = 16 SetAlternate = 17 SetDevice = 18 SetPrinter = 19 SetBell = 20 SetEscape = 21 SetInsert = 22 SetExit = 23 SetIntensity = 24 SetScoreB = 25 SetColorIdx = 26 SetCursorIdx = 27 SetWrap = 28 SetMessage = 29 ) var ( settings = map[int]hbrt.Value{ SetExact: hbrt.MakeBool(false), SetFixed: hbrt.MakeBool(false), SetDecimals: hbrt.MakeInt(2), SetDeleted: hbrt.MakeBool(false), SetExclusive: hbrt.MakeBool(true), SetSoftSeek: hbrt.MakeBool(false), SetUnique: hbrt.MakeBool(false), SetCancel: hbrt.MakeBool(true), SetConfirm: hbrt.MakeBool(false), SetConsole: hbrt.MakeBool(true), SetBell: hbrt.MakeBool(false), SetEscape: hbrt.MakeBool(true), SetInsert: hbrt.MakeBool(false), SetExit: hbrt.MakeBool(false), SetIntensity: hbrt.MakeBool(true), SetWrap: hbrt.MakeBool(false), } setMu sync.Mutex ) // SET(nSpecifier [, xNewValue]) → xOldValue // Generic SET function matching Harbour's Set() function. func SetFunc(t *hbrt.Thread) { nParams := t.ParamCount() t.Frame(nParams, 0) defer t.EndProc() nSet := t.Local(1).AsInt() setMu.Lock() defer setMu.Unlock() old, exists := settings[nSet] if !exists { old = hbrt.MakeNil() } if nParams >= 2 && !t.Local(2).IsNil() { settings[nSet] = t.Local(2) } t.RetVal(old) } // GetSetting returns a SET value (called internally). func GetSetting(nSet int) hbrt.Value { setMu.Lock() defer setMu.Unlock() v, ok := settings[nSet] if !ok { return hbrt.MakeNil() } return v } // GetSetDeleted returns SET DELETED state. func GetSetDeleted() bool { return GetSetting(SetDeleted).AsBool() } // GetSetExact returns SET EXACT state. func GetSetExact() bool { return GetSetting(SetExact).AsBool() } // GetSetSoftSeek returns SET SOFTSEEK state. func GetSetSoftSeek() bool { return GetSetting(SetSoftSeek).AsBool() }