require "ctx_config" -- pripoji subor require "ctx_typography" function Write_to(file,str) if str~=nil then file:write(str) end end -- writes string to the file function New_stack() return {""} -- starts with an empty string end function Init(file_name) ctx_line=1 if context_mode then ctx_char_number=-5 else ctx_char_number=-3 end is_over = false braces_reading=0 buffer = New_stack() file = assert(io.open(file_name, "r","nepodarilo sa najst subor vstupu")) file2 = assert(io.open([[ctx_checked_]]..file_name,"w")) io.input(file) end function Add_string (stack, s) if s~=nil and stack~=nil then table.insert(stack, s) -- push 's' into the the stack end end function Concat_buffer(stack) if stack~=nil then concatenated_word=table.concat(stack) return concatenated_word end end function Number_in_set(t,val) for k,v in pairs(t) do if v == val then return k end end end function Change_setting(char,array,number) str=char char=Read_char(1) if char~=nil then str=str..char end if char=="+" then array[number]=true elseif char=="-" then array[number]=false end return str end function Read_char(amount) local next_char=io.read(amount) if next_char=="\n" then ctx_line=ctx_line+1 ctx_char_number=-1 end if is_over==false then ctx_char_number=ctx_char_number+1 if next_char~=nil then if next_char:byte()==195 or next_char:byte()==196 or next_char:byte()==197 or next_char=="" then ctx_char_number=ctx_char_number-1 elseif next_char:byte()==226 then ctx_char_number=ctx_char_number-2 end end if braces_reading>0 then if next_char~=nil then if next_char=="{" then closing_braces=closing_braces+1 end if next_char=="}" then closing_braces=closing_braces-1 end if closing_braces==0 then is_over=true end return (next_char) else is_over=true end elseif next_char~=nil then return (next_char) else is_over=true end end end -- nacita znak a skontroluje ci nie je prazdny function Read_keyword() local next_char=Read_char(1) local key_word_buffer=New_stack() if next_char==[[%]] or next_char==[[,]] then ctx_char=next_char return next_char end while (string.byte(next_char)>96 and string.byte(next_char)<123) or (string.byte(next_char)>64 and string.byte(next_char)<91) --or (string.byte(next_char)>47 and string.byte(next_char)<58) --klucove slovo neobsahuje cisla do Add_string(key_word_buffer,next_char) next_char=Read_char(1) end key_word=Concat_buffer(key_word_buffer) Write_to(file2,key_word) ctx_char=next_char return key_word end -- nacita klucove slovo function Fill (list) local set = {} for _, l in ipairs(list) do set[l] = true end return set end -- naplnenie poli function Union(t1,t2) for i=1,#t2 do t1[#t1+1] = t2[i] end return t1 end -- spoji dve tabulky function Read_spaces() if ctx_char~=nil and ctx_char~="" then while ctx_char==" " or ctx_char:byte()==9 or ctx_char=="~" do Write_to(file2,ctx_char) ctx_char=Read_char(1) if ctx_char==nil or ctx_char =="" then break end end end end -- cita znaky az kym nenajde znak rôzny od medzery function Read_brackets(max_brackets) local current_brackets=0 local next_line=0 while current_brackets#original_file_lines then old_stop=#original_file_lines end for j=old_start,old_stop do Write_to(file3,"OLD "..j..". "..original_file_lines[j].."\n") end count=1 file4:seek("set") for new_line in file4:lines() do if count==ctx_mistakes[l-1][1] then Write_to(file3,"NEW "..new_line.."\n") end count=count+1 end Write_to(file3,"----------------------------------------------------------".."\n") end end file:close() file3:close() file4:close() end function Main() local dont_run=false if arg[1]~=nil then Init(arg[1]) input_file=arg[1] elseif input_file~="" and input_file~=nil then Init(input_file) else --error("No input file chosen, set it in ctx_config or as parameter in command line",0) print("No input file chosen, set it in ctx_config or as parameter in command line") dont_run=true end if not dont_run then if context_mode then Find_starttext() Process_context() else txt_buffer={} char=file:read(1) while char~=nil do Add_string(txt_buffer,char) char=file:read(1) end Write_to(file2,Concat_buffer(Ctx_detect_mistakes(ctx_settings, txt_buffer, 1, 0))) end file2:close() Create_recommendations() if (#ctx_mistakes-1)==1 then return ("Done, found "..(#ctx_mistakes-1).." mistake") elseif (#ctx_mistakes-1)==0 then return ("No mistakes found! Well done") else return ("Done, found "..(#ctx_mistakes-1).." mistakes") end end end print(Main())