Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan9 port of PDCurses #93

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Build instructions are in the README.md file for each platform:

- [DOS]
- [OS/2]
- [Plan9]
- [SDL 1.x]
- [SDL 2.x]
- [Windows]
Expand Down
31 changes: 31 additions & 0 deletions demos/mkfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
APE=/sys/src/ape
<$APE/config

TARG=\
firework\
ozdemo\
ptest\
rain\
testcurs\
tuidemo\
worm\
xmas\

HFILES=\
/sys/include/ape/curses.h\
/sys/include/ape/panel.h\

UPDATE=\
mkfile\
$HFILES\
${OFILES:%.$O=%.c}\
/$objtype/ape/lib/libcurses.a

</sys/src/cmd/mkmany

CFLAGS= -c -D_POSIX_SOURCE -D_BSD_EXTENSION #-DPDCDEBUG

$O.tuidemo:V: tui.$O tuidemo.$O
$LD -o $target $prereq

$O.out: /$objtype/lib/ape/libcurses.a
32 changes: 32 additions & 0 deletions plan9/README.Plan9
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
This is William McBrine PDCurses 3.4
ported and repackaged for Plan 9.

Federico G. Benavento
January 2008
benavento@gmail.com

Jens Staal
July 2015


Copyright (c) 2007 Federico G. Benavento

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

35 changes: 35 additions & 0 deletions plan9/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PDCurses for Plan9
==================

This directory contains PDCurses source code files specific to Plan9.


Building
--------

- cd to the plan9 sub directory

- Build it:

mk
mk install

- Optionally, you can cross compile by setting the variable $objtype,
for example:

objtype=amd64 mk

Distribution Status
-------------------

See README.Plan9 for the copyright notice of Federico G. Benavento with
a permissive license.


Acknowledgements
----------------

Federico G. Benavento made the original port to PDCurses 3.0
<https://comp.os.plan9.narkive.com/YWgPwjjW/9fans-i-did-it-curses-port>

Jens Staal updated it
11 changes: 11 additions & 0 deletions plan9/header.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- curses.h 2020-06-04 13:06:57.089157964 +0200
+++ curses.ape 2020-06-05 11:17:57.562007451 +0200
@@ -27,6 +27,8 @@

**man-end****************************************************************/

+#pragma lib "/$M/lib/ape/libcurses.a"
+
#define PDCURSES 1
#define PDC_BUILD 3905
#define PDC_VER_MAJOR 3
103 changes: 103 additions & 0 deletions plan9/mkfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
</$objtype/mkfile

LIB=libcurses.a

OFILES=\
# pdcurses \
addch.$O\
addchstr.$O\
addstr.$O\
attr.$O\
beep.$O\
bkgd.$O\
border.$O\
clear.$O\
color.$O\
debug.$O\
delch.$O\
deleteln.$O\
getch.$O\
getstr.$O\
getyx.$O\
inch.$O\
inchstr.$O\
initscr.$O\
inopts.$O\
insch.$O\
insstr.$O\
instr.$O\
kernel.$O\
keyname.$O\
mouse.$O\
move.$O\
outopts.$O\
overlay.$O\
pad.$O\
panel.$O\
printw.$O\
refresh.$O\
scanw.$O\
scr_dump.$O\
scroll.$O\
slk.$O\
termattr.$O\
touch.$O\
util.$O\
window.$O\
# plan9 \
pdcclip.$O\
pdcdisp.$O\
pdcgetsc.$O\
pdckbd.$O\
pdcscrn.$O\
pdcsetsc.$O\
pdcutil.$O\
pdcplan9.$O\

HFILES=\
/sys/include/ape/curses.h\
/sys/include/ape/panel.h\

UPDATE=\
mkfile\
$HFILES\
${OFILES:%.$O=%.c}\
${LIB:/$objtype/%=/386/%}\

</sys/src/cmd/mksyslib

CC=pcc
LD=pcc
CFLAGS= -c -I. -I.. -D_POSIX_SOURCE -D_BSD_EXTENSION -D_C99_SNPRINTF_EXTENSION \
-DHAVE_VSNPRINTF

%.$O: ../pdcurses/%.c
$CC $CFLAGS ../pdcurses/$stem.c

%.$O: %.c
$CC $CFLAGS $stem.c


install:V:
cp libcurses.a /$objtype/lib/ape/libcurses.a
cp ../curses.h /sys/include/ape/curses.h
ape/patch /sys/include/ape/curses.h <header.patch
cp ../panel.h /sys/include/ape/panel.h

demos:V:
@{
cd ../demos
mk all
}

clean:V:
@{
cd ../demos
mk clean
}
rm -f *.[$OS]

nuke:V:
rm -f $LIB
rm -f /$objtype/lib/ape/libcurses.a
rm -f $HFILES
67 changes: 67 additions & 0 deletions plan9/pdcclip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <stdlib.h>
#include <string.h>
#include <curspriv.h>
#include "pdcplan9.h"


static char *clip = NULL;

int PDC_getclipboard(char **sp, long *np)
{
long n;

PDC_LOG(("PDC_getclipboard() - called\n"));
if (!clip)
return PDC_CLIP_EMPTY;

n = strlen(clip);
if ((*sp = malloc(n + 1)) == NULL)
return PDC_CLIP_MEMORY_ERROR;

memmove(*sp, clip, n);
*np = n;

return PDC_CLIP_SUCCESS;
}


int PDC_setclipboard(const char *s, long n)
{
PDC_LOG(("PDC_setclipboard() - called\n"));
if (clip)
{
free(clip);
clip = NULL;
}
if (s)
{
if ((clip = malloc(n + 1)) == NULL)
return PDC_CLIP_MEMORY_ERROR;
memmove(clip, s, n);
clip[n] = 0;
}

return PDC_CLIP_SUCCESS;
}


int PDC_freeclipboard(char *s)
{
PDC_LOG(("PDC_freeclipboard() - called\n"));
free(s);

return PDC_CLIP_SUCCESS;
}


int PDC_clearclipboard(void)
{
PDC_LOG(("PDC_clearclipboard() - called\n"));
if (clip)
{
free(clip);
clip = NULL;
}

return PDC_CLIP_SUCCESS;
}
65 changes: 65 additions & 0 deletions plan9/pdcdisp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <curspriv.h>
#include "pdcplan9.h"

#ifdef CHTYPE_LONG
# define A(x) ((chtype)x | A_ALTCHARSET)
chtype acs_map[128] = {
A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9),
A(10), A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18),
A(19), A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27),
A(28), A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*',

0x2192, 0x2190, 0x2191, 0x2193,

'/',

0x2588,

'1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',

0x25c6, 0x2592,

'b', 'c', 'd', 'e',

0x00ba, 0x00b1, 0x0023, 0x0023, 0x2518, 0x2510, 0x250c, 0x2514,
0x253c, 'o',
'p', 0x2500, 'r', 's', 0x2524, 0x251c, 0x2534, 0x252c, 0x2502,
0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x2022,

A(127)
};

# undef A
#endif


void PDC_gotoyx(int y, int x)
{
chtype *ch;

PDC_LOG(("PDC_gotoyx() - called: y %d x %d\n", y, x));
p9setcur(SP->cursrow, SP->curscol, y, x, SP->visibility);
}


void PDC_transform_line(int y, int x, int len, const chtype * srcp)
{
int i;

PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno));
for (i = 0; i < len; i++)
{
p9putc(y, x + i, srcp[i]);
}
}

void PDC_doupdate(void)
{
p9napms(1);
}


28 changes: 28 additions & 0 deletions plan9/pdcgetsc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <curspriv.h>
#include "pdcplan9.h"

int PDC_get_columns(void)
{
int i;

i = p9getcols();
PDC_LOG(("PDC_get_columns() returns: %d\n", i));
return i;
}


int PDC_get_cursor_mode(void)
{
PDC_LOG(("PDC_get_cursor_mode() - called\n"));
return 0;
}


int PDC_get_rows(void)
{
int i;

i = p9getrows();
PDC_LOG(("PDC_get_rows() - returns: %d\n", i));
return i;
}
Loading