#!/usr/bin/lua

require "uci";
local x = uci.cursor()

local section
while true do
    local l = io.read()
    if l then
        l = string.gsub(l, ';.*', '');
        l = string.gsub(l, '#.*', '');
        l = string.gsub(l, '%s+$', '');
        l = string.gsub(l, '^%s+', '');

        if l ~= '' then
            local s = string.match(l, '%[([^%]]+)%]')
            if s then
                section = s
                x:set("keenfalcon", section, "section")
            else
                local k, v = string.match(l, '(%a[_%w]*)%s*=%s*(.+)')
                if section and k and v then
                    if section == "radio" and k == "power_index" then
                    	x:set("keenfalcon", "88XXau", "rtw_tx_pwr_idx_override", v)
                    else 
                    	x:set("keenfalcon", section, k, v)
                    end
                end
            end
        end
    else
        break
    end
end

x:commit("keenfalcon")
