Fix INCREDIBLY stupid Windows bug (files named "con.*" are illegal!)

This commit is contained in:
Craig Everett 2020-01-23 23:37:14 +09:00
parent b60a0e182f
commit 96b6027942
11 changed files with 58 additions and 45 deletions

View File

@ -90,8 +90,10 @@ initialize(P = #project{type = lib, id = none}) ->
initialize(P = #project{id = none}) ->
ID = {_, Name, _} = ask_package_id(),
initialize(P#project{id = ID, appmod = Name});
initialize(P = #project{prefix = none}) ->
initialize(P#project{prefix = ask_prefix()});
initialize(P = #project{type = app, id = {_, Name, _}, prefix = none}) ->
initialize(P#project{prefix = ask_prefix(Name)});
initialize(P = #project{type = gui, id = {_, Name, _}, prefix = none}) ->
initialize(P#project{prefix = ask_prefix(Name)});
initialize(P = #project{type = app, appmod = none}) ->
initialize(P#project{appmod = ask_appmod()});
initialize(P = #project{type = cli, appmod = none}) ->
@ -1199,8 +1201,10 @@ create(P = #project{type = lib, id = none}) ->
create(P = #project{id = none}) ->
ID = {_, AppMod, _} = ask_package_id(),
create(P#project{id = ID, appmod = AppMod});
create(P = #project{prefix = none}) ->
create(P#project{prefix = ask_prefix()});
create(P = #project{type = app, id = {_, Name, _}, prefix = none}) ->
create(P#project{prefix = ask_prefix(Name)});
create(P = #project{type = gui, id = {_, Name, _}, prefix = none}) ->
create(P#project{prefix = ask_prefix(Name)});
create(P = #project{type = app, appmod = none}) ->
create(P#project{appmod = ask_appmod()});
create(P = #project{type = gui, appmod = none}) ->
@ -1733,20 +1737,29 @@ ask_package_id3(Realm, Name) ->
end.
-spec ask_prefix() -> string().
-spec ask_prefix(zx:name()) -> string().
%% @private
%% Get a valid module prefix to use as a namespace for new modules.
ask_prefix() ->
ask_prefix(Name) ->
Default =
case string:split(Name, "_", all) of
Name -> Name;
Parts -> lists:reverse(lists:map(fun erlang:hd/1, Parts))
end,
Instructions =
"~nPICKING A PREFIX~n"
"Most projects use a prefix with a trailing underscore to namespace their "
"modules. For example, example_server uses the module prefix \"es_\" "
"internally.~n"
"This is optional.~n",
case zx_tty:get_input(Instructions, [], "[ENTER] to leave blank") of
"projects use a prefix with a trailing underscore as module namespaces.~n"
"Names are usually either the project name (if it is short), or an "
"abbreviation of the project name.~n"
"For example, example_server uses the module prefix \"es\", so many files "
"in the project are named things like \"es_client\".~n"
"Enter the prefix you would like to use below (or enter for the generated "
"default).~n",
ok = io:format(Instructions),
case zx_tty:get_input("[\"~ts\"]", [Default]) of
"" ->
"";
Default;
String ->
case zx_lib:valid_lower0_9(String) of
true ->
@ -1754,7 +1767,7 @@ ask_prefix() ->
false ->
Message = "The string \"~ts\" isn't valid. Try \"[a-z0-9_]*\".~n",
ok = io:format(Message, [String]),
ask_prefix()
ask_prefix(Name)
end
end.

View File

@ -64,7 +64,7 @@ start(PortNum) ->
%% See: http://erlang.org/doc/apps/kernel/application.html
start(normal, _Args) ->
*PREFIX*sup:start_link().
*PREFIX*_sup:start_link().
-spec stop(term()) -> ok.

View File

@ -13,7 +13,7 @@
%%% http://erlang.org/doc/design_principles/spec_proc.html
%%% @end
-module(*PREFIX*client).
-module(*PREFIX*_client).
-vsn("〘*VERSION*〙").
*AUTHOR*
*COPYRIGHT*

View File

@ -9,7 +9,7 @@
%%% OTP should take care of for us.
%%% @end
-module(*PREFIX*client_man).
-module(*PREFIX*_client_man).
-vsn("〘*VERSION*〙").
-behavior(gen_server).
*AUTHOR*

View File

@ -13,7 +13,7 @@
%%% http://erlang.org/doc/design_principles/sup_princ.html#id79244
%%% @end
-module(*PREFIX*client_sup).
-module(*PREFIX*_client_sup).
-vsn("〘*VERSION*〙").
-behaviour(supervisor).
*AUTHOR*
@ -35,8 +35,8 @@
| {shutdown, term()}
| term().
%% @private
%% Spawns the first listener at the request of the *PREFIX*client_man when es:listen/1
%% is called, or the next listener at the request of the currently listening *PREFIX*client
%% Spawns the first listener at the request of the *PREFIX*_client_man when es:listen/1
%% is called, or the next listener at the request of the currently listening *PREFIX*_client
%% when a connection is made.
%%
%% Error conditions, supervision strategies and other important issues are
@ -61,10 +61,10 @@ start_link() ->
init(none) ->
RestartStrategy = {simple_one_for_one, 1, 60},
Client = {*PREFIX*client,
{*PREFIX*client, start_link, []},
Client = {*PREFIX*_client,
{*PREFIX*_client, start_link, []},
temporary,
brutal_kill,
worker,
[*PREFIX*client]},
[*PREFIX*_client]},
{ok, {RestartStrategy, [Client]}}.

View File

@ -3,12 +3,12 @@
%%%
%%% This is the service-level supervisor of the system. It is the parent of both the
%%% client connection handlers and the client manager (which manages the client
%%% connection handlers). This is the child of *PREFIX*sup.
%%% connection handlers). This is the child of *PREFIX*_sup.
%%%
%%% See: http://erlang.org/doc/apps/kernel/application.html
%%% @end
-module(*PREFIX*clients).
-module(*PREFIX*_clients).
-vsn("〘*VERSION*〙").
-behavior(supervisor).
*AUTHOR*
@ -32,17 +32,17 @@ start_link() ->
init(none) ->
RestartStrategy = {rest_for_one, 1, 60},
ClientSup = {*PREFIX*client_sup,
{*PREFIX*client_sup, start_link, []},
ClientSup = {*PREFIX*_client_sup,
{*PREFIX*_client_sup, start_link, []},
permanent,
5000,
supervisor,
[*PREFIX*client_sup]},
ClientMan = {*PREFIX*client_man,
{*PREFIX*client_man, start_link, []},
[*PREFIX*_client_sup]},
ClientMan = {*PREFIX*_client_man,
{*PREFIX*_client_man, start_link, []},
permanent,
5000,
worker,
[*PREFIX*client_man]},
[*PREFIX*_client_man]},
Children = [ClientSup, ClientMan],
{ok, {RestartStrategy, Children}}.

View File

@ -11,7 +11,7 @@
%%% See: http://zxq9.com/archives/1311
%%% @end
-module(*PREFIX*sup).
-module(*PREFIX*_sup).
-vsn("〘*VERSION*〙").
-behaviour(supervisor).
*AUTHOR*
@ -36,11 +36,11 @@ start_link() ->
init([]) ->
RestartStrategy = {one_for_one, 1, 60},
Clients = {*PREFIX*clients,
{*PREFIX*clients, start_link, []},
Clients = {*PREFIX*_clients,
{*PREFIX*_clients, start_link, []},
permanent,
5000,
supervisor,
[*PREFIX*clients]},
[*PREFIX*_clients]},
Children = [Clients],
{ok, {RestartStrategy, Children}}.

View File

@ -28,7 +28,7 @@
%% See: http://erlang.org/doc/apps/kernel/application.html
start(normal, _Args) ->
*PREFIX*sup:start_link().
*PREFIX*_sup:start_link().
-spec stop(term()) -> ok.

View File

@ -4,7 +4,7 @@
%%% This process is a in charge of maintaining the program's state.
%%% @end
-module(*PREFIX*con).
-module(*PREFIX*_con).
-vsn("〘*VERSION*〙").
*AUTHOR*
*COPYRIGHT*
@ -46,7 +46,7 @@ stop() ->
| {shutdown, term()}
| term().
%% @private
%% Called by *PREFIX*sup.
%% Called by *PREFIX*_sup.
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, none, []).
@ -56,11 +56,11 @@ start_link() ->
init(none) ->
ok = log(info, "Starting"),
Window = *PREFIX*gui:start_link("Hello, WX!"),
Window = *PREFIX*_gui:start_link("Hello, WX!"),
ok = log(info, "Window: ~p", [Window]),
State = #s{window = Window},
ArgV = zx_daemon:argv(),
ok = *PREFIX*gui:show(ArgV),
ok = *PREFIX*_gui:show(ArgV),
{ok, State}.

View File

@ -6,7 +6,7 @@
%%% Reference: http://erlang.org/doc/man/wx_object.html
%%% @end
-module(*PREFIX*gui).
-module(*PREFIX*_gui).
-vsn("〘*VERSION*〙").
*AUTHOR*
*COPYRIGHT*
@ -113,7 +113,7 @@ handle_info(Unexpected, State) ->
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2
handle_event(#wx{event = #wxClose{}}, State = #s{frame = Frame}) ->
ok = *PREFIX*con:stop(),
ok = *PREFIX*_con:stop(),
ok = wxWindow:destroy(Frame),
{noreply, State};
handle_event(Event, State) ->

View File

@ -11,7 +11,7 @@
%%% See: http://zxq9.com/archives/1311
%%% @end
-module(*PREFIX*sup).
-module(*PREFIX*_sup).
-vsn("〘*VERSION*〙").
-behaviour(supervisor).
*AUTHOR*
@ -36,11 +36,11 @@ start_link() ->
init([]) ->
RestartStrategy = {one_for_one, 0, 60},
Clients = {*PREFIX*con,
{*PREFIX*con, start_link, []},
Clients = {*PREFIX*_con,
{*PREFIX*_con, start_link, []},
permanent,
5000,
worker,
[*PREFIX*con]},
[*PREFIX*_con]},
Children = [Clients],
{ok, {RestartStrategy, Children}}.