--=== Version 0.1 ===-- function main() filename = ""; input_ok = false; cprintf(cli.yellow,"Starting Main Function \n") repeat cprintf(cli.lightgreen,"\n Enter Waypoint filename to renumber WITHOUT path and extension (.xml)\n") cprintf(cli.lightgreen," This script creates a renumbered copy.\n") cprintf(cli.lightgreen," Enter X to eXit\n") cprintf(cli.lightgreen," > ") keyboardBufferClear(); -- clear keyboard buffer filename = io.stdin:read(); if (string.lower(filename) == "x" ) then error("Exit.", 0); else -- filname == nil, filename == "" or not existing is checked in Renumber() input_ok = true; end; until input_ok; Renumber(filename) -- Place the name of your file in here end function Renumber(waypt_file) cprintf(cli.yellow,"Starting Renumber Function \n") if (waypt_file == nil) or (waypt_file == "") then cprintf(cli.red,"No file name. Usage Renumber(\"YourWaypointFile\")\nDo not enter the path or extension.\nThis script creates a renumbered copy.\n\n"); return false else local filenameIn = getExecutionPath() .. "/waypoints/" .. waypt_file .. ".xml"; local filenameOut = getExecutionPath() .. "/waypoints/" .. waypt_file .. "_renum.xml"; local fileIn, err = io.open(filenameIn, "r"); local fileOut, err = io.open(filenameOut, "w+"); local newNumString = ""; local padding = ""; local startVal1 = 0; local startVal2 = 0; local endVal1 = 0; local endVal2 = 0; local line = ""; local lineNumber = 1; local replCount = 0; if fileIn and fileOut then for line in fileIn:lines() do startVal1, endVal1 = string.find(line, "", 1, true); newNumString = ""; line = string.sub(line, 1, startVal1-1) .. newNumString .. string.sub(line, endVal2 + 1, -1) lineNumber = lineNumber + 1; end fileOut:write(line .. "\n"); end else cprintf(cli.red,"Couldn't open/create the files. Usage Renumber(\"YourWaypointFile\")\nDo not the path or extension.\nThis script creates a renumbered copy.\n\n"); return false end fileIn:close(); fileOut:close(); cprintf(cli.green,"Done. New file is " .. waypt_file .. "_renum.xml\n"); return true; end; end startMacro(main,true);