From 96b6027942ec0a332ba881181a06f28f3bae004d Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Thu, 23 Jan 2020 23:37:14 +0900 Subject: [PATCH] Fix INCREDIBLY stupid Windows bug (files named "con.*" are illegal!) --- zomp/lib/otpr/zx/0.9.1/src/zx_local.erl | 39 ++++++++++++------- .../0.9.1/templates/example_server/appmod.erl | 2 +- .../src/{client.erl => _client.erl} | 2 +- .../src/{client_man.erl => _client_man.erl} | 2 +- .../src/{client_sup.erl => _client_sup.erl} | 12 +++--- .../src/{clients.erl => _clients.erl} | 16 ++++---- .../example_server/src/{sup.erl => _sup.erl} | 8 ++-- .../zx/0.9.1/templates/hellowx/appmod.erl | 2 +- .../hellowx/src/{con.erl => _con.erl} | 8 ++-- .../hellowx/src/{gui.erl => _gui.erl} | 4 +- .../hellowx/src/{sup.erl => _sup.erl} | 8 ++-- 11 files changed, 58 insertions(+), 45 deletions(-) rename zomp/lib/otpr/zx/0.9.1/templates/example_server/src/{client.erl => _client.erl} (99%) rename zomp/lib/otpr/zx/0.9.1/templates/example_server/src/{client_man.erl => _client_man.erl} (99%) rename zomp/lib/otpr/zx/0.9.1/templates/example_server/src/{client_sup.erl => _client_sup.erl} (89%) rename zomp/lib/otpr/zx/0.9.1/templates/example_server/src/{clients.erl => _clients.erl} (71%) rename zomp/lib/otpr/zx/0.9.1/templates/example_server/src/{sup.erl => _sup.erl} (87%) rename zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/{con.erl => _con.erl} (94%) rename zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/{gui.erl => _gui.erl} (98%) rename zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/{sup.erl => _sup.erl} (87%) diff --git a/zomp/lib/otpr/zx/0.9.1/src/zx_local.erl b/zomp/lib/otpr/zx/0.9.1/src/zx_local.erl index 8334d58..d894d34 100644 --- a/zomp/lib/otpr/zx/0.9.1/src/zx_local.erl +++ b/zomp/lib/otpr/zx/0.9.1/src/zx_local.erl @@ -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. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/example_server/appmod.erl b/zomp/lib/otpr/zx/0.9.1/templates/example_server/appmod.erl index a0c918f..3ef9837 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/example_server/appmod.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/example_server/appmod.erl @@ -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. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client.erl b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client.erl similarity index 99% rename from zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client.erl rename to zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client.erl index bde7321..b77edda 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client.erl @@ -13,7 +13,7 @@ %%% http://erlang.org/doc/design_principles/spec_proc.html %%% @end --module(〘*PREFIX*〙client). +-module(〘*PREFIX*〙_client). -vsn("〘*VERSION*〙"). 〘*AUTHOR*〙 〘*COPYRIGHT*〙 diff --git a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client_man.erl b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client_man.erl similarity index 99% rename from zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client_man.erl rename to zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client_man.erl index 420fbc4..d3e77d5 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client_man.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client_man.erl @@ -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*〙 diff --git a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client_sup.erl b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client_sup.erl similarity index 89% rename from zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client_sup.erl rename to zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client_sup.erl index b407cc6..9ae5656 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/client_sup.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_client_sup.erl @@ -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]}}. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/clients.erl b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_clients.erl similarity index 71% rename from zomp/lib/otpr/zx/0.9.1/templates/example_server/src/clients.erl rename to zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_clients.erl index 7a5eb7a..720eb18 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/clients.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_clients.erl @@ -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}}. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/sup.erl b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_sup.erl similarity index 87% rename from zomp/lib/otpr/zx/0.9.1/templates/example_server/src/sup.erl rename to zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_sup.erl index 6f66605..a259823 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/sup.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/example_server/src/_sup.erl @@ -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}}. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/appmod.erl b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/appmod.erl index 0ef8d38..e3b2f0b 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/appmod.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/appmod.erl @@ -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. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/con.erl b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_con.erl similarity index 94% rename from zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/con.erl rename to zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_con.erl index 3e1639a..0ca0a1e 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/con.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_con.erl @@ -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}. diff --git a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/gui.erl b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_gui.erl similarity index 98% rename from zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/gui.erl rename to zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_gui.erl index fe69dc0..83c8f47 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/gui.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_gui.erl @@ -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) -> diff --git a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/sup.erl b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_sup.erl similarity index 87% rename from zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/sup.erl rename to zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_sup.erl index 8ae27b1..246d1e3 100644 --- a/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/sup.erl +++ b/zomp/lib/otpr/zx/0.9.1/templates/hellowx/src/_sup.erl @@ -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}}.