Ra
Size: a a a
Ra
Ra
Ra
ox
Ra
Ra
IL
IL

ox
const fs = require('fs')
function compile(inFile, outFile) {
const text = fs.readFileSync(inFile, 'utf-8')
let _id = 1
const getUID = () => `_UID_VAR_${ _id++ }`
let structCode = ''
const list = [...text.matchAll(/struct\s*([\w\d\_]+)\s+\{([^}]*)\}/g)]
.map(([, structName, body]) => {
let code_objCreate = ''
body = body
.split(';')
.map(s => s.replace(/[\r\n]*/g, ''))
.map(s => s.trim())
.filter(Boolean)
.map(s => s.split(/\s+/))
.map(([type, name]) => {
type = type.toLowerCase()
const m = name.match(/([^\[\]]+)\[\s*(\d+)\s*\]/)
if ( m )
return { node: "array", count: +m[2], type, name: m[1].trim() }
return { node: "simple", type, name }
})
.map(v => {
if ( !['byte', 'word', 'dword'].includes(v.type) )
throw new Error(`Invalid type ${ v.type }`)
v.codeSetData = ` DllStructSetData($struct, "${ v.name }", $obj.${ v.name })`
v.codeGetData = ` $obj.${ v.name } = DllStructGetData($struct, "${ v.name }")`
v.codeDeclare = ` "${ v.type } ${ v.name }${ v.node === 'array' ? `[${ v.count }]` : '' };"`
if ( v.node === 'array' ) {
const varName = getUID()
code_objCreate += ` Local $${ varName }[ ${ v.count } ] = [${ Array(v.count).fill(0).join(', ') }]\n`
code_objCreate += ` $obj.${ v.name } = $${ varName }\n`
} else {
code_objCreate += ` $obj.${ v.name } = 0\n`
}
return v
})
const code_structDeclare = `
global const $${ structName }__ = "" & _
${ body.map(v => v.codeDeclare).join(' & _\n') }
`
const code_objToStruct = `
Func ${ structName }__ObjToStruct($obj)
Local $struct = DllStructCreate($${ structName }__)
${ body.map(v => v.codeSetData).join('\n') }
return $struct
EndFunc
`
const code_structToObj = `
Func ${ structName }__structToObj(ByRef $obj, $struct)
${ body.map(v => v.codeGetData).join('\n') }
return $obj
EndFunc
`
code_objCreate = `
Func ${ structName }()
Local $obj = GetBaseObj()
$obj.__NAME__ = "${ structName }"
${ code_objCreate }
return $obj
EndFunc
`
const code = `;;;;;;;;;;;;;;;;;;;;;;;; ${ structName }\n` + code_structDeclare + code_objCreate + code_objToStruct + code_structToObj
return { structName, code, body }
})
.map(v => {
structCode += v.code
})
fs.writeFileSync(outFile, structCode)
//console.log( structCode )
return list
}
compile('Structures.h', './Structures2.au3')ox
;;;;;;;;;;;;;;;;;;;;;;;; ST_IDSECTOR
global const $ST_IDSECTOR__ = "" & _
"byte x;" & _
"word y;"
Func ST_IDSECTOR()
Local $obj = GetBaseObj()
$obj.__NAME__ = "ST_IDSECTOR"
$obj.x = 0
$obj.y = 0
return $obj
EndFunc
Func ST_IDSECTOR__ObjToStruct($obj)
Local $struct = DllStructCreate($ST_IDSECTOR__)
DllStructSetData($struct, "x", $obj.x)
DllStructSetData($struct, "y", $obj.y)
return $struct
EndFunc
Func ST_IDSECTOR__structToObj(ByRef $obj, $struct)
$obj.x = DllStructGetData($struct, "x")
$obj.y = DllStructGetData($struct, "y")
return $obj
EndFunc
Ra
Ra
ox
Func IsSmartEnabled($hDevice, $bDriveNumber = 0)
Local $cip = _SENDCMDINPARAMS()
$cip.cBufferSize = 0
$cip.irDriveRegs.bDriveNumber = $bDriveNumber
$cip.irDriveRegs.bFeaturesReg = $ENABLE_SMART
$cip.irDriveRegs.bSectorCountReg = 1
$cip.irDriveRegs.bSectorNumberReg = 1
$cip.irDriveRegs.bCylLowReg = $SMART_CYL_LOW
$cip.irDriveRegs.bCylHighReg = $SMART_CYL_HI
$cip.irDriveRegs.bDriveHeadReg = $DRIVE_HEAD_REG
$cip.irDriveRegs.bCommandReg = $SMART_CMD
return WinAPI_DeviceIoControl($hDevice, $SMART_SEND_DRIVE_COMMAND, ObjToStruct($cip), ObjToStruct(_SENDCMDOUTPARAMS()))
EndFunc
ox
Func GetBaseObj()
Local $obj[]
$obj.isResult = false
return $obj
EndFunc
Func ObjToStruct($obj)
return Call($obj.__NAME__ & "__objToStruct", $obj)
EndFunc
Func StructToObj(ByRef $obj, $struct, $isResult = false)
Call($obj.__NAME__ & "__structToObj", $obj, $struct)
$obj.isResult = $isResult
return $obj
EndFunc