unsupported
      	ˆ¾‘äÇò 8à%­6ãauïçÈƒh¹Ç¿Ä      	unsupported
  6   ˆl–ßi~”Ji?u8 q‘\d
bÑ¿�þB g£‘çG+/3üÿÉƒh¹ÈÀÅ      unsupported
  M   ˆl–ßi~”ªC]Šq@‚ãm\mµ1hß�þY,„YÆ‹!�nBùÊ„€|_Éa–ßi~”Ji?u8 q \ÊbÑ¿Ç >Ü    #!/usr/bin/env escript
%% -*- erlang -*-
%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 2008-2022. All Rights Reserved.
%% 
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% 
%% %CopyrightEnd%
%%
%% SNMP MIB compiler frontend
%% 

-mode(compile).

-include_lib("kernel/include/file.hrl").
-include_lib("snmp/include/snmp_types.hrl").


-record(state, 
        {
	 version = "5.13.3", 
         mfv, 
         file, % .mib or .bin depending on which are compiled
         outdir = "./",
         db = volatile,
	 include_dirs = ["./"],
         include_lib_dirs = [],
	 deprecated         = false,
	 group_check        = true,
	 description        = false,
	 reference          = false,
	 imports            = false,
	 module_identity    = false,
	 module_compliance  = false, 
	 agent_capabilities = false,
	 module,
	 no_defaults        = false,
	 relaxed_row_name_assign_check = false,
	 %% The default verbosity (silence) will be filled in 
	 %% during argument processing.
	 verbosity, 
	 warnings           = false,
	 warnings_as_errors = false
        }).


%% ------------------------------------------------------------------------
%% Valid arguments: 
%% --o Dir [defaults to "./"]
%% --i Dir [defaults to "./"]
%% --il Dir
%% --sgc
%% --db DB [defaults to volatile]
%% --dep
%% --desc
%% --ref
%% --imp
%% --mi
%% --mc
%% --ac
%% --mod Mod
%% --nd
%% --rrnac
%% --version
%% --verbosity V
%% --warnings | --W
%% --Werror | --wae | --warnings_as_errors
main(Args) when is_list(Args) ->
    case (catch process_args(Args)) of
	ok ->
	    usage();
        {ok, State} when is_record(State, state) ->
	    compile(State);
        {ok, Str} when is_list(Str) ->
            io:format("~s~n~n", [Str]),
            halt(1);
        {error, ReasonStr} ->
            usage(ReasonStr)
    end;
main(_) ->
    usage().

compile(State) ->
    %% io:format("snmpc: ~p~n", [State]),
    case mk_file(State) of
	{mib, File} ->
	    Options = mk_mib_options(State),
	    case mib2bin(File, Options) of
		{ok, _BinFileName} ->
		    ok;
		{error, Reason} ->
		    io:format("ERROR: Failed compiling mib: "
			      "~n   ~p~n", [Reason]),
		    halt(1)
	    end;
	{bin, File} ->
	    Options = mk_hrl_options(State),
	    case bin2hrl(File, Options) of
		ok ->
		    ok;
		{error, Reason} ->
		    io:format("ERROR: Failed generating hrl from mib: "
			      "~n   ~p~n", [Reason]),
		    halt(1)
	    end
    end.

mib2bin(MibFileName, Options) ->
    snmpc:compile(MibFileName, Options).

bin2hrl(BinFileName, {OutDir, Verbosity}) ->
    MibName = filename:basename(BinFileName), 
    BinFile = BinFileName ++ ".bin",
    HrlFile = filename:join(OutDir, MibName) ++ ".hrl",
    put(verbosity, Verbosity),
    snmpc_mib_to_hrl:convert(BinFile, HrlFile, MibName).
	    

mk_file(#state{file = MIB}) ->
    DirName  = filename:dirname(MIB),
    case filename:extension(MIB) of
	".mib" ->
	    BaseName = filename:basename(MIB, ".mib"),
	    {mib, filename:join(DirName, BaseName)};
	".bin"  ->
	    BaseName = filename:basename(MIB, ".bin"),
	    {bin, filename:join(DirName, BaseName)};
	BadExt ->
	    e(lists:flatten(io_lib:format("Unsupported file type: ~s", [BadExt])))
    end.

mk_mib_options(#state{outdir             = OutDir, 
		      db                 = DB,
		      include_dirs       = IDs,
		      include_lib_dirs   = ILD