Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A bit of clean up

Rebarified build and fixed small bug with driver loading
  • Loading branch information...
commit 6b4fb8ed4ab543373335acb6263ec73d81c33ebd 1 parent c8a38f5
@kevsmith kevsmith authored
View
4 .gitignore
@@ -0,0 +1,4 @@
+*.beam
+priv/*.so
+priv/lib/*
+c_src/*.o
View
20 c_src/cecho.c
@@ -1,9 +1,9 @@
// Copyright (c) 2010, Mazen Harake
// All rights reserved.
-//
+//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
-//
+//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
@@ -12,7 +12,7 @@
// * Neither the name of the <ORGANIZATION> nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
-//
+//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -23,7 +23,7 @@
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.x
+// POSSIBILITY OF SUCH DAMAGE.x
// Includes
#include <stdlib.h>
@@ -122,7 +122,7 @@ static void init_getch_loop(ErlDrvData drvstate, char *buf, int buflen) {
driver_async(st->drv_port, NULL, loop_getch, (void *)st, NULL);
}
-static int ctrl(ErlDrvData drvstate, unsigned int command, char *args,
+static int ctrl(ErlDrvData drvstate, unsigned int command, char *args,
int argslen, char **rbuf, int rbuflen) {
state *st = (state *)drvstate;
init_state(st, args, argslen);
@@ -167,7 +167,7 @@ static int ctrl(ErlDrvData drvstate, unsigned int command, char *args,
case KEYPAD: do_keypad(st); break;
default: break;
}
-
+
int rlen = st->eixb.index;
ErlDrvBinary *response = driver_alloc_binary(rlen);
memcpy(response->orig_bytes, st->eixb.buff, rlen);
@@ -289,7 +289,7 @@ void do_wattron(state *st) {
int arity;
long slot, attrs;
ei_decode_tuple_header(st->args, &(st->index), &arity);
- ei_decode_long(st->args, &(st->index), &slot);
+ ei_decode_long(st->args, &(st->index), &slot);
ei_decode_long(st->args, &(st->index), &attrs);
encode_ok_reply(st, wattron(st->win[slot], (int)attrs));
}
@@ -342,7 +342,7 @@ void do_mvaddstr(state *st) {
ei_decode_string(st->args, &(st->index), str);
encode_ok_reply(st, mvaddnstr((int)y, (int)x, str, (int)strlen));
}
-
+
void do_newwin(state *st) {
int slot = findfreewindowslot(st);
if (slot > 0) {
@@ -409,7 +409,7 @@ void do_mvwaddstr(state *st) {
int arity;
long slot, y, x, strlen;
ei_decode_tuple_header(st->args, &(st->index), &arity);
- ei_decode_long(st->args, &(st->index), &slot);
+ ei_decode_long(st->args, &(st->index), &slot);
ei_decode_long(st->args, &(st->index), &y);
ei_decode_long(st->args, &(st->index), &x);
ei_decode_long(st->args, &(st->index), &strlen);
@@ -583,7 +583,7 @@ ErlDrvEntry driver_entry = {
ctrl,
NULL
};
-
+
// =============================================================================
// Erlang Driver Name
// =============================================================================
View
0  include/cecho.h → c_src/cecho.h
File renamed without changes
View
0  include/cecho_commands.h → c_src/cecho_commands.h
File renamed without changes
View
2  ebin/cecho.app
@@ -1,6 +1,6 @@
{application, cecho,
[{description, "An ncurses library for Erlang"},
{version, "0.0.1"},
- {modules, [cecho, cecho_srv]},
+ {modules, [cecho, cecho_srv, cecho_example]},
{env, []},
{mod, {cecho, []}}]}.
View
64 include/cecho_commands.hrl
@@ -0,0 +1,64 @@
+%% Copyright (c) 2010, Mazen Harake
+%% All rights reserved.
+%%
+%% Redistribution and use in source and binary forms, with or without
+%% modification, are permitted provided that the following conditions are met:
+%%
+%% * Redistributions of source code must retain the above copyright notice,
+%% this list of conditions and the following disclaimer.
+%% * Redistributions in binary form must reproduce the above copyright
+%% notice, this list of conditions and the following disclaimer in the
+%% documentation and/or other materials provided with the distribution.
+%% * Neither the name of the <ORGANIZATION> nor the names of its
+%% contributors may be used to endorse or promote products derived from
+%% this software without specific prior written permission.
+%%
+%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+%% POSSIBILITY OF SUCH DAMAGE.
+
+-define(ENDWIN, 0).
+-define(INITSCR, 1).
+-define(REFRESH, 2).
+-define(CBREAK, 3).
+-define(NOCBREAK, 4).
+-define(ECHO, 5).
+-define(NOECHO, 6).
+-define(ADDCH, 7).
+-define(ADDSTR, 8).
+-define(MOVE, 9).
+-define(GETYX, 10).
+-define(GETMAXYX, 11).
+-define(CURS_SET, 12).
+-define(ERASE, 13).
+-define(HAS_COLORS, 14).
+-define(START_COLOR, 15).
+-define(INIT_PAIR, 16).
+-define(WATTRON, 17).
+-define(WATTROFF, 18).
+-define(NL, 19).
+-define(NONL, 20).
+-define(SCROLLOK, 21).
+-define(MVADDCH, 22).
+-define(MVADDSTR, 23).
+-define(NEWWIN, 24).
+-define(DELWIN, 25).
+-define(WMOVE, 26).
+-define(WADDSTR, 27).
+-define(WADDCH, 28).
+-define(MVWADDSTR, 29).
+-define(MVWADDCH, 30).
+-define(WREFRESH, 31).
+-define(WHLINE, 32).
+-define(WVLINE, 33).
+-define(WBORDER, 34).
+-define(BOX, 35).
+-define(KEYPAD, 36).
View
2  rebar.config
@@ -0,0 +1,2 @@
+{erl_opts, [debug_info, fail_on_warning]}.
+{so_name, cecho.so}.
View
15 src/cecho_srv.erl
@@ -27,8 +27,8 @@
-module(cecho_srv).
-behaviour(gen_server).
--include("include/cecho.hrl").
--include("include/cecho_commands.hrl").
+-include("cecho.hrl").
+-include("cecho_commands.hrl").
%% Behaviour Callbacks
-export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,
@@ -57,7 +57,7 @@ getch() ->
%% =============================================================================
init(no_args) ->
process_flag(trap_exit, true),
- case erl_ddll:load(code:priv_dir(cecho)++"/lib","cecho") of
+ case load_driver() of
ok ->
Port = erlang:open_port({spawn, "cecho"}, [binary]),
ok = do_call(Port, ?INITSCR),
@@ -104,3 +104,12 @@ do_call(Port, Cmd) ->
do_call(Port, Cmd, Args) ->
binary_to_term(erlang:port_control(Port, Cmd, term_to_binary(Args))).
+
+load_driver() ->
+ Dir = case code:priv_dir(cecho) of
+ {error, bad_name} ->
+ filename:dirname(code:which(?MODULE)) ++ "/../priv";
+ D ->
+ D
+ end,
+ erl_ddll:load(Dir, "cecho").
Please sign in to comment.
Something went wrong with that request. Please try again.