diff --git a/src/genProto.erl b/src/genProto.erl index ff06092..388c4a1 100644 --- a/src/genProto.erl +++ b/src/genProto.erl @@ -11,7 +11,25 @@ ]). convertFile(File) -> - protoParse:parseFile(File). + erlang:erase(), + erlang:put(pd_errlist, []), + erlang:put(pd_handler, []), + case filename:extension(File) == ".mpdf" of + true -> + io:format("Convert proto msg file: ~s ~n", [File]), + BaseName = filename:basename(File, ".mpdf"), + [ModIndex, ModName] = re:split(BaseName, "_"), + Index = binary_to_integer(ModIndex), + erlang:put(pd_messageid, Index * ?MsgIdSegSize + 1), + erlang:put(pd_handler, [{Index, ModName} | erlang:get(pd_handler)]), + erlang:put(pd_errcodeid, Index * ?MsgIdSegSize + 1), + SProto = protoParse:parseFile(File), + ErrCode = erlang:get(pd_errlist), + Handler = erlang:get(pd_handler), + {SProto, Handler, ErrCode}; + _ -> + io:format("not proto msg file: ~s ~n", [File]) + end. convert([ProtoDir, HrlDir, ErlDir]) -> convertDir(atom_to_list(ProtoDir), atom_to_list(HrlDir), atom_to_list(ErlDir)). @@ -21,6 +39,7 @@ convertDir() -> convertDir(ProtoDir) -> convertDir(ProtoDir, "./", "./"). convertDir(ProtoDir, HrlDir, ErlDir) -> + erlang:erase(), erlang:put(pd_errlist, []), erlang:put(pd_handler, []), FunRead = diff --git a/src/protoParse.erl b/src/protoParse.erl index 16bd72f..e4361e5 100644 --- a/src/protoParse.erl +++ b/src/protoParse.erl @@ -56,7 +56,7 @@ parseParse(Input) when is_binary(Input) -> (p_seq([p_label('name', fun 'name'/2), fun 'blank0'/2, p_label('structural', fun 'structural'/2)]))(I, D) end, fun(Node, _Idx) -> - Name = binary_to_list(iolist_to_binary(proplists:get_value(name, Node))), + Name = iolist_to_binary(proplists:get_value(name, Node)), Structural = proplists:get_value(structural, Node), MsgId = erlang:get(pd_messageid), erlang:put(pd_messageid, MsgId + 1), @@ -80,8 +80,8 @@ parseParse(Input) when is_binary(Input) -> (p_seq([p_label('datatype', fun 'typename'/2), fun 'blanks'/2, p_label('name', fun 'name'/2), fun 'blank0'/2, p_string(<<";">>)]))(I, D) end, fun(Node, _Idx) -> - DataType = binary_to_list(iolist_to_binary(proplists:get_value(datatype, Node))), - Name = binary_to_list(iolist_to_binary(proplists:get_value(name, Node))), + DataType = iolist_to_binary(proplists:get_value(datatype, Node)), + Name = iolist_to_binary(proplists:get_value(name, Node)), {DataType, Name} end). @@ -124,10 +124,10 @@ parseParse(Input) when is_binary(Input) -> fun(Node, _Idx) -> ErrNameList = proplists:get_value('errname', Node), ErrCodeStrList = proplists:get_value('errcode_str', Node), - ErrName = binary_to_list(iolist_to_binary(ErrNameList)), - Desc = binary_to_list(iolist_to_binary(ErrCodeStrList)), + ErrName = iolist_to_binary(ErrNameList), + Desc = iolist_to_binary(ErrCodeStrList), ErrList = erlang:get(pd_errlist), - UpErrName = string:to_upper(ErrName), + UpErrName = toUpperStr(ErrName), case UpErrName =/= [] andalso lists:keyfind(UpErrName, 1, ErrList) == false of true -> ErrCodeId = erlang:get(pd_errcodeid), @@ -458,7 +458,7 @@ p_charclass(Class) -> {Head, Tail} = erlang:split_binary(Inp, Length), {Head, Tail, p_advance_index(Head, Index)}; _ -> - {fail, {expected, {character_class, binary_to_list(Class)}, Index}} + {fail, {expected, {character_class, Class}, Index}} end end. -endif. @@ -473,7 +473,7 @@ p_regexp(Regexp) -> {Head, Tail} = erlang:split_binary(Inp, Length), {Head, Tail, p_advance_index(Head, Index)}; _ -> - {fail, {expected, {regexp, binary_to_list(Regexp)}, Index}} + {fail, {expected, {regexp, Regexp}, Index}} end end. -endif. @@ -499,3 +499,26 @@ p_advance_index(MatchedInput, Index) when is_integer(MatchedInput) -> % single c $\n -> {{line, Line + 1}, {column, 1}}; _ -> {{line, Line}, {column, Col + 1}} end. + +toUpperStr(ListStr) when is_list(ListStr) -> + [ + begin + case C >= $a andalso C =< $z of + true -> + C - 32; + _ -> + C + end + end || C <- ListStr + ]; +toUpperStr(BinStr) when is_binary(BinStr) -> + << + begin + case C >= $a andalso C =< $z of + true -> + <<(C - 32)>>; + _ -> + <> + end + end || <> <= BinStr + >>. diff --git a/src/writeCs/gCsGen.erl b/src/writeCs/gCsGen.erl new file mode 100644 index 0000000..508bd43 --- /dev/null +++ b/src/writeCs/gCsGen.erl @@ -0,0 +1,8 @@ +-module(gCsGen). + +-export([ + genCs/4 +]). + +genCs(_SortedSProtoList, _SortedErrList, _HrlDir, _ErlDir) -> + ok.