|
@@ -4,10 +4,12 @@
|
|
|
|
|
|
do(FileName) ->
|
|
|
{#xmlElement{content=[#xmlElement{content=Head}, BodyTree | _]}, _} = xmerl_scan:file(FileName),
|
|
|
- FN = hd( string:split(FileName, ".", leading) ),
|
|
|
- write2new(FN, lists:reverse( show(BodyTree, false, false,
|
|
|
- [ [".TH ", FN, " 1 \"n2o 4.5.0\" \"Synrc Research Center\" \"", head(Head, ""), "\"", "\n",
|
|
|
- ".SH NAME", "\n", "UNKNOWN", "\n"] ]) ) ), ok.
|
|
|
+ FN = string:join(lists:reverse(tl(lists:reverse(string:tokens(FileName,".")))),"."),
|
|
|
+ Groff = "groff/"++FN,
|
|
|
+ filelib:ensure_dir(filename:dirname(Groff)++"/"),
|
|
|
+ write2new(Groff, lists:reverse( show(BodyTree, false, false,
|
|
|
+ [ [".TH ", FN, " 1 \"",FN,"\" \"Synrc Research Center\" \"", head(Head, ""), "\"", "\n",
|
|
|
+ ".SH NAME", "\n", FN, "\n"] ]))), ok.
|
|
|
|
|
|
show(#xmlElement{name=section,content=C},false,_,RA) -> S = check(C, false), child(C,S,[also(S)|RA]);
|
|
|
show(#xmlElement{content=C},false,_,RA) -> child(C,false,RA);
|
|
@@ -15,9 +17,9 @@ show(#xmlElement{name=h3,content=C},{true,S2},_,RA) -> child(C,{true,S2},[".SH "
|
|
|
show(#xmlElement{name=a,content=[#xmlText{value=V}|_]},{true, last},_,RA) ->
|
|
|
[["\\fB\\fI", V,"(1)","\\fR\\&\\fR\\&",", "]|RA];
|
|
|
show(#xmlElement{name=a,content=[#xmlText{value=V}|CM]},S,false,RA) ->
|
|
|
- child(CM, S, [["\\fI", V, "\\fR\\& "]|RA]);
|
|
|
+ child(CM, S, [["\\fI",V,"\\fR\\& "]|RA]);
|
|
|
show(#xmlElement{name=a,content=[#xmlText{value=V}|CM]},S,true,RA) ->
|
|
|
- child(CM, S, [["\\fI", V, "\\fR\\&"]|RA]);
|
|
|
+ child(CM, S, [["\\fI",V,"\\fR\\&"]|RA]);
|
|
|
show(#xmlElement{name=code,content=[#xmlText{value=V} | CM]},{true,S2},_,RA) ->
|
|
|
child(CM, {true, S2}, [[".nf","\n",ltrim(V),".fi","\n"]|RA]);
|
|
|
show(#xmlElement{name=p,content=C}, {true, S2}, _, RA) -> child(C,{true,S2}, ["\n",".LP"|RA]);
|
|
@@ -26,14 +28,14 @@ show(#xmlElement{name=_, content=C}, S, _, RA) -> child(C,S,RA);
|
|
|
show(_,false,_,RA) -> RA;
|
|
|
show(_,{true,last},_,RA) -> RA;
|
|
|
show(#xmlText{value=V},_S,_,RA) ->
|
|
|
- G = (hd(V) == 10) andalso (string:trim(tl(V)) == ""),
|
|
|
+ G = (hd(V) == 10) andalso (mad_man:trim(tl(V)) == ""),
|
|
|
if G -> RA; true -> [ltrim(V) | RA] end;
|
|
|
show(_,_,_,RA) -> RA.
|
|
|
|
|
|
check([#xmlElement{name=h3,content=C}|_], false) -> check(C, {true, h3});
|
|
|
check([#xmlElement{name=p,content=C}|_], false) -> check(C, {true, p});
|
|
|
check([#xmlText{value=V}|MoreNodes], false) ->
|
|
|
- G = (hd(V) == 10) andalso (string:trim(tl(V)) == ""),
|
|
|
+ G = (hd(V) == 10) andalso (mad_man:trim(tl(V)) == ""),
|
|
|
if G -> check(MoreNodes, false); true -> {true, other} end;
|
|
|
check([], {true, h3}) -> {true, other};
|
|
|
check([#xmlText{value=_V} | _], {true, h3}) -> {true, usual};
|
|
@@ -54,16 +56,16 @@ child([Node | MoreNodes], S, RA) ->
|
|
|
pt({true,last},_,_) -> false;
|
|
|
pt(_,_,[]) -> false;
|
|
|
pt(_,#xmlElement{name=a},[#xmlText{value=V}|_])->
|
|
|
- V2=string:trim(V),if V2 =/= "",hd(V2)==46->true;true->false end;
|
|
|
+ V2=mad_man:trim(V),if V2 =/= "",hd(V2)==46->true;true->false end;
|
|
|
pt(_,_,_) -> false.
|
|
|
|
|
|
also({true, last}) -> ["\n", ".SH ALSO", "\n"];
|
|
|
also(_) -> "".
|
|
|
|
|
|
ltrim(V) ->
|
|
|
- [ [ string:trim(V2, both), "\n"]
|
|
|
- || V2 <- string:split(V, "\n", all),
|
|
|
- string:trim(V2, both) =/= ""].
|
|
|
+ [ [ mad_man:trim(V2), "\n"]
|
|
|
+ || V2 <- string:tokens(V, "\n"),
|
|
|
+ mad_man:trim(V2) =/= ""].
|
|
|
|
|
|
head([], A) -> A;
|
|
|
head([#xmlElement{name=title, content=[#xmlText{value=V} | _]} | _], _) -> V;
|
|
@@ -72,5 +74,5 @@ head([_|T], A) -> head(T, A).
|
|
|
write2new(F, S) ->
|
|
|
file:write_file(F ++ ".1",
|
|
|
io_lib:fwrite("~s", [
|
|
|
- string:trim(
|
|
|
- unicode:characters_to_binary(S,utf8),trailing,", ")]),[append]).
|
|
|
+ mad_man:trim(
|
|
|
+ unicode:characters_to_binary(S,utf8))]), [append]).
|