Last active
August 29, 2015 14:01
-
-
Save runcom/4ad8adbecea8a5897c8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- | |
% ex: ts=4 sw=4 et | |
-export([main/1]). | |
create_xml_snippet(L) -> | |
PlaceHolders = [ | |
"@ind_clifor@", | |
"@cod_clifor@", | |
"@ind_gest_ivacassa@", | |
"@cod_contropartita@", | |
"@cod_agenzia1@", | |
"@cod_banca1@", | |
"@cod_iva@", | |
"@flg_addebito_spese@", | |
"@flg_addebito_bollo@", | |
"@cod_pag@", | |
"@sig_bban1@", | |
"@sig_ccbanc1@", | |
"@sig_iban1@", | |
"@cod_piacont@", | |
"@cod_perc@", | |
"@ind_tipo_perc@", | |
"@cod_caurit@", | |
"@cod_tributo@", | |
"@cod_iva@", | |
"@cod_caupag@" | |
], | |
Snippet = "<CLIFOR TipoOperazione=\"UpdateInsert\">" ++ | |
"<CO_CLIFOR>" ++ | |
"<datarow>" ++ | |
"<ind_clifor>@ind_clifor@</ind_clifor>" ++ | |
"<cod_clifor>@cod_clifor@</cod_clifor>" ++ | |
"<ind_gest_ivacassa>@ind_gest_ivacassa@</ind_gest_ivacassa>" ++ | |
"<cod_contropartita>@cod_contropartita@</cod_contropartita>" ++ | |
"<cod_agenzia1>@cod_agenzia1@</cod_agenzia1>" ++ | |
"<cod_banca1>@cod_banca1@</cod_banca1>" ++ | |
"<cod_iva>@cod_iva@</cod_iva>" ++ | |
"<flg_addebito_spese>@flg_addebito_spese@</flg_addebito_spese>" ++ | |
"<flg_addebito_bollo>@flg_addebito_bollo@</flg_addebito_bollo>" ++ | |
"<cod_pag>@cod_pag@</cod_pag>" ++ | |
"<sig_bban1>@sig_bban1@</sig_bban1>" ++ | |
"<sig_ccbanc1>@sig_ccbanc1@</sig_ccbanc1>" ++ | |
"<sig_iban1>@sig_iban1@</sig_iban1>" ++ | |
"</datarow>" ++ | |
"<CO_CLIFOR_PIACONT>" ++ | |
"<datarow><cod_piacont>@cod_piacont@</cod_piacont><flg_default>1</flg_default></datarow>" ++ | |
"</CO_CLIFOR_PIACONT>" ++ | |
"</CO_CLIFOR>" ++ | |
"</CLIFOR>" ++ | |
"<PERCIPIENTE TipoOperazione=\"UpdateInsert\">" ++ | |
"<RI_PERC>" ++ | |
"<datarow>" ++ | |
"<cod_perc>@cod_perc@</cod_perc>" ++ | |
"<ind_tipo_perc>@ind_tipo_perc@</ind_tipo_perc>" ++ | |
"<cod_caurit>@cod_caurit@</cod_caurit>" ++ | |
"<cod_tributo>@cod_tributo@</cod_tributo>" ++ | |
"<cod_iva>@cod_iva@</cod_iva>" ++ | |
"<cod_caupag>@cod_caupag@</cod_caupag>" ++ | |
"</datarow>" ++ | |
"</RI_PERC>" ++ | |
"</PERCIPIENTE>", | |
Tokens = string:tokens(L, "|\n"), | |
replace_placeholder(Snippet, PlaceHolders, Tokens). | |
replace_placeholder(Snippet, [], []) -> | |
file:write_file("output.txt", Snippet, [append]), | |
ok; | |
replace_placeholder(Snippet, PlaceHolders, Tokens) -> | |
[Ph|T] = PlaceHolders, | |
[H|T1] = Tokens, | |
Snip = re:replace(Snippet, Ph, H, [{return, list}]), | |
replace_placeholder(Snip, T, T1). | |
get_all_lines(Device) -> | |
case io:get_line(Device, "") of | |
eof -> []; | |
Line -> | |
ok = create_xml_snippet(Line), | |
get_all_lines(Device) | |
end. | |
readlines(FileName) -> | |
{ok, Device} = file:open(FileName, [read]), | |
try get_all_lines(Device) | |
after file:close(Device) | |
end. | |
main(DbInputFile) -> | |
file:write_file("output.txt", ""), | |
readlines(DbInputFile), | |
io:format("Fatto!~n", []). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment