Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
A bit of clean up
Browse files Browse the repository at this point in the history
Rebarified build and fixed small bug with driver loading
  • Loading branch information
Kevin Smith committed Jun 11, 2010
1 parent c8a38f5 commit 6b4fb8e
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.beam
priv/*.so
priv/lib/*
c_src/*.o
20 changes: 10 additions & 10 deletions c_src/cecho.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -583,7 +583,7 @@ ErlDrvEntry driver_entry = {
ctrl,
NULL
};

// =============================================================================
// Erlang Driver Name
// =============================================================================
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ebin/cecho.app
Original file line number Diff line number Diff line change
@@ -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, []}}]}.
64 changes: 64 additions & 0 deletions include/cecho_commands.hrl
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 2 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{erl_opts, [debug_info, fail_on_warning]}.
{so_name, cecho.so}.
15 changes: 12 additions & 3 deletions src/cecho_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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").

0 comments on commit 6b4fb8e

Please sign in to comment.