require"ctx_config" function Write_to(where,what) if what~=nil then where:write(what) end end if context_mode then file_rec = assert(io.open([[recommendations.tex]], "r","Recommendations file not found!")) else file_rec = assert(io.open([[recommendations.txt]], "r","Recommendations file not found!")) end local input_file_name=file_rec:read() local file_output = assert(io.open([[ctx_checked_]]..input_file_name,"w")) local file_input = assert(io.open(input_file_name, "r","Input file "..input_file_name.." not found!")) local line=file_rec:read() local def,def2,def3={},{},{} local warning_done=false while line~=nil do if string.sub(line,2,9)=="WARNING!" or string.sub(line,1,8)=="WARNING!" then if warning_done then error("New line not found") end if line:sub(1,1)=="-" then table.insert(def,0) elseif line:sub(1,1)=="+" then table.insert(def,1) elseif do_offered_corrections then table.insert(def,1) elseif not do_offered_corrections then table.insert(def,0) end local j=1 local str_line="" while line:sub(j,j)~=nil do if line:sub(j,j):byte()<58 and line:sub(j,j):byte()>47 then str_line=str_line..line:sub(j,j) j=j+1 while line:sub(j,j):byte()<58 and line:sub(j,j):byte()>47 do str_line=str_line..line:sub(j,j) j=j+1 end table.insert(def2,tonumber(str_line)) break end j=j+1 if line:sub(j,j)==nil then error("Couldn't find the line number to correction") end end warning_done=true elseif line:sub(1,3)=="NEW" and warning_done then warning_done=false table.insert(def3,line:sub(5,#line)) end line=file_rec:read() end local output_line=file_input:read() local line_number=1 local changes=0 while output_line~=nil do is_in_corrections=false for i=1,#def2 do if line_number==def2[i] then is_in_corrections=true array_value=i end end if is_in_corrections and def[array_value]==1 then Write_to(file_output,def3[array_value].."\n") changes=changes+1 else Write_to(file_output,output_line.."\n") end line_number=line_number+1 output_line=file_input:read() end if changes==0 then print("No changes") elseif changes==1 then print("Done, "..changes.." line corrected") else print("Done, "..changes.." lines corrected") end