diff options
Diffstat (limited to 'lib/erl_docgen/priv/bin')
-rw-r--r-- | lib/erl_docgen/priv/bin/Makefile | 74 | ||||
-rwxr-xr-x | lib/erl_docgen/priv/bin/codeline_preprocessing.escript | 117 |
2 files changed, 191 insertions, 0 deletions
diff --git a/lib/erl_docgen/priv/bin/Makefile b/lib/erl_docgen/priv/bin/Makefile new file mode 100644 index 0000000000..bd59675003 --- /dev/null +++ b/lib/erl_docgen/priv/bin/Makefile @@ -0,0 +1,74 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../../vsn.mk +VSN=$(ERL_DOCGEN_VSN) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/erl_docgen-$(VSN) + + +# ---------------------------------------------------- +# Target Specs +# ---------------------------------------------------- + + +ESCRIPT_FILES= \ + codeline_preprocessing.escript + +# ---------------------------------------------------- +# FLAGS +# ---------------------------------------------------- + + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- +debug opt: + +docs: + +clean: + $(RM) $(TARGET_FILES) + + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + + +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/priv/bin + $(INSTALL_SCRIPT) $(ESCRIPT_FILES) $(RELSYSDIR)/priv/bin + +release_docs_spec: + + +release_tests_spec: + + diff --git a/lib/erl_docgen/priv/bin/codeline_preprocessing.escript b/lib/erl_docgen/priv/bin/codeline_preprocessing.escript new file mode 100755 index 0000000000..33a678d3a4 --- /dev/null +++ b/lib/erl_docgen/priv/bin/codeline_preprocessing.escript @@ -0,0 +1,117 @@ +#!/usr/bin/env escript +%% -*- erlang -*- +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%%---------------------------------------------------------------------- +%% File : codeline_preprocessing.escript +%% +%% Created : 10 Sep 2008 by Lars Thorsen +%%---------------------------------------------------------------------- + +%%====================================================================== +%% External functions +%%====================================================================== +%%---------------------------------------------------------------------- +%% Function: main/1 +%% Description: +%%---------------------------------------------------------------------- +main([InFile, OutFile]) -> + InDev = + case file:open(InFile, [read]) of + {ok,ID} -> + ID; + _ -> + halt(5) + end, + CPath=filename:dirname(InFile), + OutDev = + case file:open(OutFile, [write]) of + {ok,OD} -> + OD; + _ -> + halt(5) + end, + case re:compile("<codeinclude(?:\040|\t)*file=\"([^\"]*)\"(?:(?:(?:\040|\t)*tag=\"([^\"]*)\".*)|(?:.*))(?:/>|/codeinclude>)") of + {ok, Mp} -> + parse(InDev, OutDev, CPath, Mp); + _ -> + halt(2) + end; +main(_) -> + usage(). + + +%%---------------------------------------------------------------------- +%% Function: main/1 +%% Description: +%%---------------------------------------------------------------------- +usage() -> + io:format("usage: codeline_preprocessing <infile> <outfile>\n"), + halt(1). + + +%%====================================================================== +%% Internal functions +%%====================================================================== + +parse(InDev, OutDev, CPath, Mp) -> + case io:get_line(InDev, "") of + eof -> + file:close(OutDev), + file:close(InDev); + String -> + case re:run(String, Mp,[{capture, [1,2], list}]) of + {match,[File, []]} -> + case file:read_file(filename:join(CPath, File))of + {ok, Bin} -> + file:write(OutDev, "<code>\n<![CDATA[\n"), + file:write(OutDev, Bin), + file:write(OutDev, "]]></code>"); + _ -> + halt(3) + end; + {match,[File, Tag]} -> + String2 = get_code(filename:join(CPath, File), Tag), + file:write(OutDev, "<code>\n<![CDATA[\n"), + file:write(OutDev, String2), + file:write(OutDev, "]]></code>"); + _ -> + file:write(OutDev, String) + end, + parse(InDev, OutDev, CPath, Mp) + end. + +%%---------------------------------------------------------------------- +%% Function: get_code/2 +%% Description: +%%---------------------------------------------------------------------- +get_code(File, Tag) -> + case file:read_file(File) of + {ok, Bin} -> + case re:run(Bin,"^" ++ Tag ++ "\n((.|\n)*)\n" ++ + Tag ++ "\$",[global, multiline, {capture, [1], binary}]) of + {match,[[Match]]} -> + Match; + _ -> + halt(4) + end; + _ -> + halt(3) + end. + + + |