p1_logger-1.0.0/0000755000232200023220000000000012642726530013744 5ustar debalancedebalancep1_logger-1.0.0/rebar.config0000644000232200023220000000017612642726530016232 0ustar debalancedebalance{erl_opts, [debug_info, {i, "include"}]}. %% Local Variables: %% mode: erlang %% End: %% vim: set filetype=erlang tabstop=8: p1_logger-1.0.0/include/0000755000232200023220000000000012642726530015367 5ustar debalancedebalancep1_logger-1.0.0/include/p1_logger.hrl0000644000232200023220000000263312642726530017761 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% %%% p1_logger, Copyright (C) 2002-2015 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as %%% published by the Free Software Foundation; either version 2 of the %%% License, or (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program; if not, write to the Free Software %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA %%% 02111-1307 USA %%% %%%---------------------------------------------------------------------- -define(PRINT(Format, Args), io:format(Format, Args)). -define(DEBUG(Format, Args), p1_logger:debug_msg(?MODULE, ?LINE, Format, Args)). -define(INFO_MSG(Format, Args), p1_logger:info_msg(?MODULE, ?LINE, Format, Args)). -define(WARNING_MSG(Format, Args), p1_logger:warning_msg(?MODULE, ?LINE, Format, Args)). -define(ERROR_MSG(Format, Args), p1_logger:error_msg(?MODULE, ?LINE, Format, Args)). -define(CRITICAL_MSG(Format, Args), p1_logger:critical_msg(?MODULE, ?LINE, Format, Args)). p1_logger-1.0.0/src/0000755000232200023220000000000012642726530014533 5ustar debalancedebalancep1_logger-1.0.0/src/p1_logger_sup.erl0000644000232200023220000000416612642726530020014 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : p1_logger_sup.erl %%% Author : Evgeniy Khramtsov %%% Purpose : logger supervisor %%% Created : 15 May 2013 by Evgeniy Khramtsov %%% %%% %%% p1_logger, Copyright (C) 2002-2015 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as %%% published by the Free Software Foundation; either version 2 of the %%% License, or (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program; if not, write to the Free Software %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA %%% 02111-1307 USA %%% %%%---------------------------------------------------------------------- -module(p1_logger_sup). -behaviour(supervisor). %% API -export([start_link/0]). %% Supervisor callbacks -export([init/1]). -define(SERVER, ?MODULE). %%%=================================================================== %%% API functions %%%=================================================================== %%-------------------------------------------------------------------- %% @doc %% Starts the supervisor %% %% @spec start_link() -> {ok, Pid} | ignore | {error, Error} %% @end %%-------------------------------------------------------------------- start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). %%%=================================================================== %%% Supervisor callbacks %%%=================================================================== init([]) -> {ok, {{one_for_one, 10, 1}, []}}. %%%=================================================================== %%% Internal functions %%%=================================================================== p1_logger-1.0.0/src/p1_loglevel.erl0000644000232200023220000001637612642726530017465 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : p1_loglevel.erl %%% Author : Mickael Remond %%% Purpose : Loglevel switcher. %%% Be careful: you should not have any p1_logger module %%% as p1_loglevel switcher is compiling and loading %%% dynamically a "virtual" p1_logger module (Described %%% in a string at the end of this module). %%% Created : 29 Nov 2006 by Mickael Remond %%% %%% %%% p1_logger, Copyright (C) 2002-2015 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as %%% published by the Free Software Foundation; either version 2 of the %%% License, or (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program; if not, write to the Free Software %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA %%% 02111-1307 USA %%% %%%---------------------------------------------------------------------- -module(p1_loglevel). -author('mickael.remond@process-one.net'). -export([set/1, get/0, set_custom/2, clear_custom/0, clear_custom/1]). -include("p1_logger.hrl"). -define(LOGMODULE, "error_logger"). %% Error levels: -record(p1_loglevel, {ordinal, name, description, function = no_log, event_type = no_log, msg_prefix = no_log}). -define(LOG_LEVELS, [#p1_loglevel{ordinal = 0, name = no_log, description = "No log"}, #p1_loglevel{ordinal = 1, name = critical, description = "Critical", function = critical_msg, event_type = error, msg_prefix = "C"}, #p1_loglevel{ordinal = 2, name = error, description = "Error", function = error_msg, event_type = error, msg_prefix = "E"}, #p1_loglevel{ordinal = 3, name = warning, description = "Warning", function = warning_msg, event_type = warning_msg, msg_prefix = "W"}, #p1_loglevel{ordinal = 4, name = info, description = "Info", function = info_msg, event_type = info_msg, msg_prefix = "I"}, #p1_loglevel{ordinal = 5, name = debug, description = "Debug", function = debug_msg, event_type = info_msg, msg_prefix = "D"}]). %% @type level() = integer() | atom(). %% @spec () -> {DefaultLevelOrdinal::integer(), [{Module::atom(), LevelOrdinal::integer()}]} %% @doc Get the default and all custom levels get() -> {DefaultLevel, _CustomLevels} = p1_logger:get(), case lists:keysearch(DefaultLevel, #p1_loglevel.ordinal, ?LOG_LEVELS) of {value, Result = #p1_loglevel{}} -> {Result#p1_loglevel.ordinal, Result#p1_loglevel.name, Result#p1_loglevel.description}; _ -> erlang:error({no_such_loglevel, DefaultLevel}) end. %% @spec (DefaultLevel::level() | {DefaultLevel::level(), [{Module::atom(), Level::level()}]}) -> %% {module, p1_logger} %% @doc Set the default and all custom levels set(DefaultLevel) when is_atom(DefaultLevel) orelse is_integer(DefaultLevel) -> set({DefaultLevel, []}); set({DefaultLevel, CustomLevels}) when is_list(CustomLevels) -> DefaultInt = level_to_integer(DefaultLevel), CustomInts = [level_to_integer(C) || C <- CustomLevels], Loglevel = {DefaultInt, CustomInts}, try {Mod,Code} = dynamic_compile:from_string(p1_logger_src(Loglevel)), code:load_binary(Mod, ?LOGMODULE ++ ".erl", Code) catch Type:Error -> error_logger:error_msg("Error compiling p1_logger (~p): ~p~n", [Type, Error]) end; set(_) -> exit("Invalid p1_loglevel format"). %% @spec (Module::atom(), CustomLevel::level()) -> ok %% @doc Set a custom level set_custom(Module, Level) -> {DefaultLevel, CustomLevels} = p1_logger:get(), case lists:keysearch(Module, 1, CustomLevels) of {value, {Module, Level}} -> ok; {value, _} -> set({DefaultLevel, lists:keyreplace(Module, 1, CustomLevels, {Module, Level})}); _ -> set({DefaultLevel, [{Module, Level} | CustomLevels]}) end. %% @spec () -> ok %% @doc Clear all custom levels clear_custom() -> {DefaultLevel, _CustomLevels} = p1_logger:get(), set({DefaultLevel, []}). %% @spec (Module::atom()) -> ok %% @doc Clear a custom level clear_custom(Module) -> {DefaultLevel, CustomLevels} = p1_logger:get(), case lists:keysearch(Module, 1, CustomLevels) of {value, _} -> set({DefaultLevel, lists:keydelete(Module, 1, CustomLevels)}); _ -> ok end. level_to_integer(Level) when is_integer(Level) -> Level; level_to_integer({Module, Level}) -> {Module, level_to_integer(Level)}; level_to_integer(Level) -> case lists:keysearch(Level, #p1_loglevel.name, ?LOG_LEVELS) of {value, #p1_loglevel{ordinal = Int}} -> Int; _ -> erlang:error({no_such_loglevel, Level}) end. %% -------------------------------------------------------------- %% Code of the p1_logger, dynamically compiled and loaded %% This allows to dynamically change log level while keeping a %% very efficient code. p1_logger_src(Loglevel) -> lists:flatten([header_src(), get_src(Loglevel), [log_src(Loglevel, LevelSpec) || LevelSpec <- ?LOG_LEVELS], notify_src()]). header_src() -> "-module(p1_logger). -author('mickael.remond@process-one.net'). -export([debug_msg/4, info_msg/4, warning_msg/4, error_msg/4, critical_msg/4, get/0]). ". get_src(Loglevel) -> io_lib:format("get() -> ~w. ", [Loglevel]). log_src(_Loglevel, #p1_loglevel{function = no_log}) -> []; log_src({DefaultLevel, [{Module, Level} | Tail]}, Spec = #p1_loglevel{ordinal = MinLevel}) when Level < MinLevel andalso MinLevel =< DefaultLevel -> [atom_to_list(Spec#p1_loglevel.function), "(", atom_to_list(Module), ", _, _, _) -> ok; ", log_src({DefaultLevel, Tail}, Spec)]; log_src({DefaultLevel, [{Module, Level} | Tail]}, Spec = #p1_loglevel{ordinal = MinLevel}) when DefaultLevel < MinLevel andalso MinLevel =< Level -> [atom_to_list(Spec#p1_loglevel.function), "(", atom_to_list(Module), " = Module, Line, Format, Args) ->", log_notify_src(Spec), "; ", log_src({DefaultLevel, Tail}, Spec)]; log_src({DefaultLevel, [_Head | Tail]}, Spec = #p1_loglevel{}) -> log_src({DefaultLevel, Tail}, Spec); log_src({DefaultLevel, []}, Spec = #p1_loglevel{ordinal = MinLevel}) when DefaultLevel < MinLevel -> [atom_to_list(Spec#p1_loglevel.function), "(_, _, _, _) -> ok. "]; log_src({_DefaultLevel, []}, Spec = #p1_loglevel{}) -> [atom_to_list(Spec#p1_loglevel.function), "(Module, Line, Format, Args) ->", log_notify_src(Spec), ". "]. log_notify_src(Spec = #p1_loglevel{}) -> ["notify(", atom_to_list(Spec#p1_loglevel.event_type), ", \"", Spec#p1_loglevel.msg_prefix, "(~p:~p:~p) : \"++Format++\"~n\", [self(), Module, Line | Args])"]. notify_src() -> %% Distribute the message to the Erlang error p1_logger "notify(Type, Format, Args) -> LoggerMsg = {Type, group_leader(), {self(), Format, Args}}, gen_event:notify(error_logger, LoggerMsg). ". p1_logger-1.0.0/src/p1_logger.app.src0000644000232200023220000000116512642726530017705 0ustar debalancedebalance%%%------------------------------------------------------------------- %%% @author Evgeniy Khramtsov %%% @copyright (C) 2013, Evgeniy Khramtsov %%% @doc %%% %%% @end %%% Created : 4 Apr 2013 by Evgeniy Khramtsov %%%------------------------------------------------------------------- {application, p1_logger, [{description, "P1 Logger"}, {vsn, "1.0.0"}, {modules, []}, {registered, []}, {applications, [kernel, stdlib]}, {mod, {p1_logger_app,[]}}]}. %% Local Variables: %% mode: erlang %% End: %% vim: set filetype=erlang tabstop=8: p1_logger-1.0.0/src/p1_logger.erl0000644000232200023220000000434112642726530017120 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : p1_logger.erl %%% Author : Evgeniy Khramtsov %%% Purpose : logger wrapper %%% Created : 10 Jul 2012 by Evgeniy Khramtsov %%% %%% %%% p1_logger, Copyright (C) 2002-2015 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as %%% published by the Free Software Foundation; either version 2 of the %%% License, or (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program; if not, write to the Free Software %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA %%% 02111-1307 USA %%% %%%---------------------------------------------------------------------- -module(p1_logger). -compile({no_auto_import, [{get, 0}]}). %% API -export([debug_msg/4, info_msg/4, warning_msg/4, error_msg/4, critical_msg/4, get/0]). %%%=================================================================== %%% API %%%=================================================================== -spec debug_msg(atom(), pos_integer(), string(), list()) -> ok. -spec info_msg(atom(), pos_integer(), string(), list()) -> ok. -spec warning_msg(atom(), pos_integer(), string(), list()) -> ok. -spec error_msg(atom(), pos_integer(), string(), list()) -> ok. -spec critical_msg(atom(), pos_integer(), string(), list()) -> ok. -spec get() -> {non_neg_integer(), [{atom(), non_neg_integer()}]}. debug_msg(_Mod, _Line, _Format, _Args) -> ok. info_msg(_Mod, _Line, _Format, _Args) -> ok. warning_msg(_Mod, _Line, _Format, _Args) -> ok. error_msg(_Mod, _Line, _Format, _Args) -> ok. critical_msg(_Mod, _Line, _Format, _Args) -> ok. get() -> {0, [{foo, 0}]}. %%%=================================================================== %%% Internal functions %%%=================================================================== p1_logger-1.0.0/src/dynamic_compile.erl0000644000232200023220000003304612642726530020401 0ustar debalancedebalance%% Copyright (c) 2007 %% Mats Cronqvist %% Chris Newcombe %% Jacob Vorreuter %% %% Permission is hereby granted, free of charge, to any person %% obtaining a copy of this software and associated documentation %% files (the "Software"), to deal in the Software without %% restriction, including without limitation the rights to use, %% copy, modify, merge, publish, distribute, sublicense, and/or sell %% copies of the Software, and to permit persons to whom the %% Software is furnished to do so, subject to the following %% conditions: %% %% The above copyright notice and this permission notice shall be %% included in all copies or substantial portions of the Software. %% %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR %% OTHER DEALINGS IN THE SOFTWARE. %%%------------------------------------------------------------------- %%% File : dynamic_compile.erl %%% Description : %%% Authors : Mats Cronqvist %%% Chris Newcombe %%% Jacob Vorreuter %%% TODO : %%% - add support for limit include-file depth (and prevent circular references) %%% prevent circular macro expansion set FILE correctly when -module() is found %%% -include_lib support $ENVVAR in include filenames %%% substitute-stringize (??MACRO) %%% -undef/-ifdef/-ifndef/-else/-endif %%% -file(File, Line) %%%------------------------------------------------------------------- -module(dynamic_compile). %% API -export([from_string/1, from_string/2]). -import(lists, [reverse/1, keyreplace/4]). %%==================================================================== %% API %%==================================================================== %%-------------------------------------------------------------------- %% Function: %% Description: %% Returns a binary that can be used with %% code:load_binary(Module, ModuleFilenameForInternalRecords, Binary). %%-------------------------------------------------------------------- from_string(CodeStr) -> from_string(CodeStr, []). % takes Options as for compile:forms/2 from_string(CodeStr, CompileFormsOptions) -> %% Initialise the macro dictionary with the default predefined macros, %% (adapted from epp.erl:predef_macros/1 Filename = "compiled_from_string", %%Machine = list_to_atom(erlang:system_info(machine)), Ms0 = dict:new(), % Ms1 = dict:store('FILE', {[], "compiled_from_string"}, Ms0), % Ms2 = dict:store('LINE', {[], 1}, Ms1), % actually we might add special code for this % Ms3 = dict:store('MODULE', {[], undefined}, Ms2), % Ms4 = dict:store('MODULE_STRING', {[], undefined}, Ms3), % Ms5 = dict:store('MACHINE', {[], Machine}, Ms4), % InitMD = dict:store(Machine, {[], true}, Ms5), InitMD = Ms0, %% From the docs for compile:forms: %% When encountering an -include or -include_dir directive, the compiler searches for header files in the following directories: %% 1. ".", the current working directory of the file server; %% 2. the base name of the compiled file; %% 3. the directories specified using the i option. The directory specified last is searched first. %% In this case, #2 is meaningless. IncludeSearchPath = ["." | reverse([Dir || {i, Dir} <- CompileFormsOptions])], {RevForms, _OutMacroDict} = scan_and_parse(CodeStr, Filename, 1, [], InitMD, IncludeSearchPath), Forms = reverse(RevForms), %% note: 'binary' is forced as an implicit option, whether it is provided or not. case compile:forms(Forms, CompileFormsOptions) of {ok, ModuleName, CompiledCodeBinary} when is_binary(CompiledCodeBinary) -> {ModuleName, CompiledCodeBinary}; {ok, ModuleName, CompiledCodeBinary, []} when is_binary(CompiledCodeBinary) -> % empty warnings list {ModuleName, CompiledCodeBinary}; {ok, _ModuleName, _CompiledCodeBinary, Warnings} -> throw({?MODULE, warnings, Warnings}); Other -> throw({?MODULE, compile_forms, Other}) end. %%==================================================================== %% Internal functions %%==================================================================== %%% Code from Mats Cronqvist %%% See http://www.erlang.org/pipermail/erlang-questions/2007-March/025507.html %%%## 'scan_and_parse' %%% %%% basically we call the OTP scanner and parser (erl_scan and %%% erl_parse) line-by-line, but check each scanned line for (or %%% definitions of) macros before parsing. %% returns {ReverseForms, FinalMacroDict} scan_and_parse([], _CurrFilename, _CurrLine, RevForms, MacroDict, _IncludeSearchPath) -> {RevForms, MacroDict}; scan_and_parse(RemainingText, CurrFilename, CurrLine, RevForms, MacroDict, IncludeSearchPath) -> case scanner(RemainingText, CurrLine, MacroDict) of {tokens, NLine, NRemainingText, Toks} -> {ok, Form} = erl_parse:parse_form(Toks), scan_and_parse(NRemainingText, CurrFilename, NLine, [Form | RevForms], MacroDict, IncludeSearchPath); {macro, NLine, NRemainingText, NMacroDict} -> scan_and_parse(NRemainingText, CurrFilename, NLine, RevForms,NMacroDict, IncludeSearchPath); {include, NLine, NRemainingText, IncludeFilename} -> IncludeFileRemainingTextents = read_include_file(IncludeFilename, IncludeSearchPath), %%io:format("include file ~p contents: ~n~p~nRemainingText = ~p~n", [IncludeFilename,IncludeFileRemainingTextents, RemainingText]), %% Modify the FILE macro to reflect the filename %%IncludeMacroDict = dict:store('FILE', {[],IncludeFilename}, MacroDict), IncludeMacroDict = MacroDict, %% Process the header file (inc. any nested header files) {RevIncludeForms, IncludedMacroDict} = scan_and_parse(IncludeFileRemainingTextents, IncludeFilename, 1, [], IncludeMacroDict, IncludeSearchPath), %io:format("include file results = ~p~n", [R]), %% Restore the FILE macro in the NEW MacroDict (so we keep any macros defined in the header file) %%NMacroDict = dict:store('FILE', {[],CurrFilename}, IncludedMacroDict), NMacroDict = IncludedMacroDict, %% Continue with the original file scan_and_parse(NRemainingText, CurrFilename, NLine, RevIncludeForms ++ RevForms, NMacroDict, IncludeSearchPath); done -> scan_and_parse([], CurrFilename, CurrLine, RevForms, MacroDict, IncludeSearchPath) end. scanner(Text, Line, MacroDict) -> case erl_scan:tokens([],Text,Line) of {done, {ok,Toks,NLine}, LeftOverChars} -> case pre_proc(Toks, MacroDict) of {tokens, NToks} -> {tokens, NLine, LeftOverChars, NToks}; {macro, NMacroDict} -> {macro, NLine, LeftOverChars, NMacroDict}; {include, Filename} -> {include, NLine, LeftOverChars, Filename} end; {more, _Continuation} -> %% This is supposed to mean "term is not yet complete" (i.e. a '.' has %% not been reached yet). %% However, for some bizarre reason we also get this if there is a comment after the final '.' in a file. %% So we check to see if Text only consists of comments. case is_only_comments(Text) of true -> done; false -> throw({incomplete_term, Text, Line}) end end. is_only_comments(Text) -> is_only_comments(Text, not_in_comment). is_only_comments([], _) -> true; is_only_comments([$ |T], not_in_comment) -> is_only_comments(T, not_in_comment); % skipping whitspace outside of comment is_only_comments([$\t |T], not_in_comment) -> is_only_comments(T, not_in_comment); % skipping whitspace outside of comment is_only_comments([$\n |T], not_in_comment) -> is_only_comments(T, not_in_comment); % skipping whitspace outside of comment is_only_comments([$% |T], not_in_comment) -> is_only_comments(T, in_comment); % found start of a comment is_only_comments(_, not_in_comment) -> false; % found any significant char NOT in a comment is_only_comments([$\n |T], in_comment) -> is_only_comments(T, not_in_comment); % found end of a comment is_only_comments([_ |T], in_comment) -> is_only_comments(T, in_comment). % skipping over in-comment chars %%%## 'pre-proc' %%% %%% have to implement a subset of the pre-processor, since epp insists %%% on running on a file. %%% only handles 2 cases; %% -define(MACRO, something). %% -define(MACRO(VAR1,VARN),{stuff,VAR1,more,stuff,VARN,extra,stuff}). pre_proc([{'-',_},{atom,_,define},{'(',_},{_,_,Name}|DefToks],MacroDict) -> false = dict:is_key(Name, MacroDict), case DefToks of [{',',_} | Macro] -> {macro, dict:store(Name, {[], macro_body_def(Macro, [])}, MacroDict)}; [{'(',_} | Macro] -> {macro, dict:store(Name, macro_params_body_def(Macro, []), MacroDict)} end; pre_proc([{'-',_}, {atom,_,include}, {'(',_}, {string,_,Filename}, {')',_}, {dot,_}], _MacroDict) -> {include, Filename}; pre_proc(Toks,MacroDict) -> {tokens, subst_macros(Toks, MacroDict)}. macro_params_body_def([{')',_},{',',_} | Toks], RevParams) -> {reverse(RevParams), macro_body_def(Toks, [])}; macro_params_body_def([{var,_,Param} | Toks], RevParams) -> macro_params_body_def(Toks, [Param | RevParams]); macro_params_body_def([{',',_}, {var,_,Param} | Toks], RevParams) -> macro_params_body_def(Toks, [Param | RevParams]). macro_body_def([{')',_}, {dot,_}], RevMacroBodyToks) -> reverse(RevMacroBodyToks); macro_body_def([Tok|Toks], RevMacroBodyToks) -> macro_body_def(Toks, [Tok | RevMacroBodyToks]). subst_macros(Toks, MacroDict) -> reverse(subst_macros_rev(Toks, MacroDict, [])). %% returns a reversed list of tokes subst_macros_rev([{'?',_}, {_,LineNum,'LINE'} | Toks], MacroDict, RevOutToks) -> %% special-case for ?LINE, to avoid creating a new MacroDict for every line in the source file subst_macros_rev(Toks, MacroDict, [{integer,LineNum,LineNum}] ++ RevOutToks); subst_macros_rev([{'?',_}, {_,_,Name}, {'(',_} = Paren | Toks], MacroDict, RevOutToks) -> case dict:fetch(Name, MacroDict) of {[], MacroValue} -> %% This macro does not have any vars, so ignore the fact that the invocation is followed by "(...stuff" %% Recursively expand any macro calls inside this macro's value %% TODO: avoid infinite expansion due to circular references (even indirect ones) RevExpandedOtherMacrosToks = subst_macros_rev(MacroValue, MacroDict, []), subst_macros_rev([Paren|Toks], MacroDict, RevExpandedOtherMacrosToks ++ RevOutToks); ParamsAndBody -> %% This macro does have vars. %% Collect all of the passe arguments, in an ordered list {NToks, Arguments} = subst_macros_get_args(Toks, []), %% Expand the varibles ExpandedParamsToks = subst_macros_subst_args_for_vars(ParamsAndBody, Arguments), %% Recursively expand any macro calls inside this macro's value %% TODO: avoid infinite expansion due to circular references (even indirect ones) RevExpandedOtherMacrosToks = subst_macros_rev(ExpandedParamsToks, MacroDict, []), subst_macros_rev(NToks, MacroDict, RevExpandedOtherMacrosToks ++ RevOutToks) end; subst_macros_rev([{'?',_}, {_,_,Name} | Toks], MacroDict, RevOutToks) -> %% This macro invocation does not have arguments. %% Therefore the definition should not have parameters {[], MacroValue} = dict:fetch(Name, MacroDict), %% Recursively expand any macro calls inside this macro's value %% TODO: avoid infinite expansion due to circular references (even indirect ones) RevExpandedOtherMacrosToks = subst_macros_rev(MacroValue, MacroDict, []), subst_macros_rev(Toks, MacroDict, RevExpandedOtherMacrosToks ++ RevOutToks); subst_macros_rev([Tok|Toks], MacroDict, RevOutToks) -> subst_macros_rev(Toks, MacroDict, [Tok|RevOutToks]); subst_macros_rev([], _MacroDict, RevOutToks) -> RevOutToks. subst_macros_get_args([{')',_} | Toks], RevArgs) -> {Toks, reverse(RevArgs)}; subst_macros_get_args([{',',_}, {var,_,ArgName} | Toks], RevArgs) -> subst_macros_get_args(Toks, [ArgName| RevArgs]); subst_macros_get_args([{var,_,ArgName} | Toks], RevArgs) -> subst_macros_get_args(Toks, [ArgName | RevArgs]). subst_macros_subst_args_for_vars({[], BodyToks}, []) -> BodyToks; subst_macros_subst_args_for_vars({[Param | Params], BodyToks}, [Arg|Args]) -> NBodyToks = keyreplace(Param, 3, BodyToks, {var,1,Arg}), subst_macros_subst_args_for_vars({Params, NBodyToks}, Args). read_include_file(Filename, IncludeSearchPath) -> case file:path_open(IncludeSearchPath, Filename, [read, raw, binary]) of {ok, IoDevice, FullName} -> {ok, Data} = file:read(IoDevice, filelib:file_size(FullName)), file:close(IoDevice), binary_to_list(Data); {error, Reason} -> throw({failed_to_read_include_file, Reason, Filename, IncludeSearchPath}) end.p1_logger-1.0.0/src/p1_logger_h.erl0000644000232200023220000002002012642726530017417 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : p1_logger_h.erl %%% Author : Alexey Shchepin %%% Purpose : Manage Erlang logging. %%% Created : 23 Oct 2003 by Alexey Shchepin %%% %%% %%% p1_logger, Copyright (C) 2002-2015 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as %%% published by the Free Software Foundation; either version 2 of the %%% License, or (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program; if not, write to the Free Software %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA %%% 02111-1307 USA %%% %%%---------------------------------------------------------------------- -module(p1_logger_h). -author('alexey@process-one.net'). -behaviour(gen_event). %% gen_event callbacks -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3, reopen_log/0, rotate_log/1]). -record(state, {fd, file}). %%%---------------------------------------------------------------------- %%% Callback functions from gen_event %%%---------------------------------------------------------------------- %%---------------------------------------------------------------------- %% Func: init/1 %% Returns: {ok, State} | %% Other %%---------------------------------------------------------------------- init(File) -> case file:open(File, [append, raw]) of {ok, Fd} -> {ok, #state{fd = Fd, file = File}}; Error -> Error end. %%---------------------------------------------------------------------- %% Func: handle_event/2 %% Returns: {ok, State} | %% {swap_handler, Args1, State1, Mod2, Args2} | %% remove_handler %%---------------------------------------------------------------------- handle_event(Event, State) -> write_event(State#state.fd, {erlang:localtime(), Event}), {ok, State}. %%---------------------------------------------------------------------- %% Func: handle_call/2 %% Returns: {ok, Reply, State} | %% {swap_handler, Reply, Args1, State1, Mod2, Args2} | %% {remove_handler, Reply} %%---------------------------------------------------------------------- handle_call(_Request, State) -> Reply = ok, {ok, Reply, State}. %%---------------------------------------------------------------------- %% Func: handle_info/2 %% Returns: {ok, State} | %% {swap_handler, Args1, State1, Mod2, Args2} | %% remove_handler %%---------------------------------------------------------------------- handle_info({'EXIT', _Fd, _Reason}, _State) -> remove_handler; handle_info({emulator, _GL, reopen}, State) -> file:close(State#state.fd), rotate_log(State#state.file), case file:open(State#state.file, [append, raw]) of {ok, Fd} -> {ok, State#state{fd = Fd}}; Error -> Error end; handle_info({emulator, GL, Chars}, State) -> write_event(State#state.fd, {erlang:localtime(), {emulator, GL, Chars}}), {ok, State}; handle_info(_Info, State) -> {ok, State}. %%---------------------------------------------------------------------- %% Func: terminate/2 %% Purpose: Shutdown the server %% Returns: any %%---------------------------------------------------------------------- terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. reopen_log() -> error_logger ! {emulator, noproc, reopen}. %%%---------------------------------------------------------------------- %%% Internal functions %%%---------------------------------------------------------------------- % Copied from erlang_logger_file_h.erl write_event(Fd, {Time, {error, _GL, {Pid, Format, Args}}}) -> T = write_time(Time), case catch io_lib:format(add_node(Format,Pid), Args) of S when is_list(S) -> file:write(Fd, io_lib:format(T ++ S, [])); _ -> F = add_node("ERROR: ~p - ~p~n", Pid), file:write(Fd, io_lib:format(T ++ F, [Format,Args])) end; write_event(Fd, {Time, {emulator, _GL, Chars}}) -> T = write_time(Time), case catch io_lib:format(Chars, []) of S when is_list(S) -> file:write(Fd, io_lib:format(T ++ S, [])); _ -> file:write(Fd, io_lib:format(T ++ "ERROR: ~p ~n", [Chars])) end; write_event(Fd, {Time, {info, _GL, {Pid, Info, _}}}) -> T = write_time(Time), file:write(Fd, io_lib:format(T ++ add_node("~p~n",Pid), [Info])); write_event(Fd, {Time, {error_report, _GL, {Pid, std_error, Rep}}}) -> T = write_time(Time), S = format_report(Rep), file:write(Fd, io_lib:format(T ++ S ++ add_node("", Pid), [])); write_event(Fd, {Time, {info_report, _GL, {Pid, std_info, Rep}}}) -> T = write_time(Time, "INFO REPORT"), S = format_report(Rep), file:write(Fd, io_lib:format(T ++ S ++ add_node("", Pid), [])); write_event(Fd, {Time, {info_msg, _GL, {Pid, Format, Args}}}) -> T = write_time(Time, "INFO REPORT"), case catch io_lib:format(add_node(Format,Pid), Args) of S when is_list(S) -> file:write(Fd, io_lib:format(T ++ S, [])); _ -> F = add_node("ERROR: ~p - ~p~n", Pid), file:write(Fd, io_lib:format(T ++ F, [Format,Args])) end; write_event(Fd, {Time, {warning_report, _GL, {Pid, std_warning, Rep}}}) -> T = write_time(Time, "WARNING REPORT"), S = format_report(Rep), file:write(Fd, io_lib:format(T ++ S ++ add_node("", Pid), [])); write_event(Fd, {Time, {warning_msg, _GL, {Pid, Format, Args}}}) -> T = write_time(Time, "WARNING REPORT"), case catch io_lib:format(add_node(Format,Pid), Args) of S when is_list(S) -> file:write(Fd, io_lib:format(T ++ S, [])); _ -> F = add_node("ERROR: ~p - ~p~n", Pid), file:write(Fd, io_lib:format(T ++ F, [Format,Args])) end; write_event(_, _) -> ok. format_report(Rep) when is_list(Rep) -> case string_p(Rep) of true -> io_lib:format("~s~n",[Rep]); _ -> format_rep(Rep) end; format_report(Rep) -> io_lib:format("~p~n",[Rep]). format_rep([{Tag,Data}|Rep]) -> io_lib:format(" ~p: ~p~n",[Tag,Data]) ++ format_rep(Rep); format_rep([Other|Rep]) -> io_lib:format(" ~p~n",[Other]) ++ format_rep(Rep); format_rep(_) -> []. add_node(X, Pid) when is_atom(X) -> add_node(atom_to_list(X), Pid); add_node(X, Pid) when node(Pid) /= node() -> lists:concat([X,"** at node ",node(Pid)," **~n"]); add_node(X, _) -> X. string_p([]) -> false; string_p(Term) -> string_p1(Term). string_p1([H|T]) when is_integer(H), H >= $\s, H < 255 -> string_p1(T); string_p1([$\n|T]) -> string_p1(T); string_p1([$\r|T]) -> string_p1(T); string_p1([$\t|T]) -> string_p1(T); string_p1([$\v|T]) -> string_p1(T); string_p1([$\b|T]) -> string_p1(T); string_p1([$\f|T]) -> string_p1(T); string_p1([$\e|T]) -> string_p1(T); string_p1([H|T]) when is_list(H) -> case string_p1(H) of true -> string_p1(T); _ -> false end; string_p1([]) -> true; string_p1(_) -> false. write_time(Time) -> write_time(Time, "ERROR REPORT"). write_time({{Y,Mo,D},{H,Mi,S}}, Type) -> io_lib:format("~n=~s==== ~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w ===~n", [Type, Y, Mo, D, H, Mi, S]). %% @doc Rename the log file if exists, by adding suffix ".0". %% This is needed in systems when the file must be closed before rotation (Windows). %% On most Unix-like system, the file can be renamed from the command line and %% the log can directly be reopened. %% @spec (Filename::string()) -> ok rotate_log(Filename) -> case file:read_file_info(Filename) of {ok, _FileInfo} -> file:rename(Filename, [Filename, ".0"]), ok; {error, _Reason} -> ok end. p1_logger-1.0.0/src/p1_logger_app.erl0000644000232200023220000000403012642726530017753 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : p1_logger_app.erl %%% Author : Evgeniy Khramtsov %%% Purpose : logger application %%% Created : 15 May 2013 by Evgeniy Khramtsov %%% %%% %%% p1_logger, Copyright (C) 2002-2015 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as %%% published by the Free Software Foundation; either version 2 of the %%% License, or (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program; if not, write to the Free Software %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA %%% 02111-1307 USA %%% %%%---------------------------------------------------------------------- -module(p1_logger_app). -behaviour(application). %% Application callbacks -export([start/2, stop/1]). %%%=================================================================== %%% Application callbacks %%%=================================================================== start(_StartType, _StartArgs) -> p1_logger_sup:start_link(). %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called whenever an application has stopped. It %% is intended to be the opposite of Module:start/2 and should do %% any necessary cleaning up. The return value is ignored. %% %% @spec stop(State) -> void() %% @end %%-------------------------------------------------------------------- stop(_State) -> ok. %%%=================================================================== %%% Internal functions %%%=================================================================== p1_logger-1.0.0/Makefile0000644000232200023220000000010612642726530015401 0ustar debalancedebalanceall: src src: rebar compile clean: rebar clean .PHONY: clean src p1_logger-1.0.0/COPYING0000644000232200023220000004325412642726530015007 0ustar debalancedebalance GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License.