diff options
Diffstat (limited to 'ycurses/src')
38 files changed, 2235 insertions, 0 deletions
diff --git a/ycurses/src/Makefile.in b/ycurses/src/Makefile.in new file mode 100644 index 0000000..7723d45 --- /dev/null +++ b/ycurses/src/Makefile.in @@ -0,0 +1,21 @@ +SRCS=WILLBEADDEDBYCONFIGURE +OBJS=$(addprefix ../obj/,$(SRCS:.cpp=.o)) +CC=WILLBEADDEDBYCONFIGURE +LIBADD=`cat libs.add` +LDFLAGS=$(LIBADD) -lstdc++ +LDADD= +INCLUDES=`cat includes.add` +CFLAGS=-fno-inline -fno-default-inline -frepo +all: ycurses +$(SRCS): + $(CC) $(INCLUDES) $(CFLAGS) -c $*.cpp +infotext: + @echo Compiling base +ycurses: infotext $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) + @mv ycurses ../bin + @echo -n "Size of linked executable: " + @du -hc ../bin/ycurses | tail -n 1 +clean: + @echo Cleaning base obj + @if test -d ../obj; then rm -Rf ../obj; fi diff --git a/ycurses/src/configure b/ycurses/src/configure new file mode 100755 index 0000000..cb7c9ff --- /dev/null +++ b/ycurses/src/configure @@ -0,0 +1,330 @@ +#!/bin/sh + +# +# The ycurses Project (2003 - 2005) +# + +if ! ../scripts/checkperl.sh +then + exit 1 +fi + +if ! test -f ../g++.version +then + echo You need to run ./configure of the top level source dir first + exit 1 +fi + +perl -e ' + use strict; + $|=1; + + my %libadd; + my %incadd; + my $deepness = 500; + + my @headers = ( + "ncurses.h", + "menu.h", + "panel.h" + ); + + my @libs = ( + "libpanel.so", + "libmenu.so", + "libncurses.so" + ); + + my @headerpaths = ( + $ENV{HOME}."/include", + $ENV{HOME}."/usr/include", + "/include", + "/usr/include", + "/usr/local/include", + "/usr/lib/", + "/usr/pkg/include", + "/opt/include", + "/opt/local/include" + ); + + my @libpaths = ( + $ENV{HOME}."/lib", + $ENV{HOME}."/usr/lib", + "/lib", + "/usr/lib", + "/usr/local/lib", + "/usr/pkg/lib", + "/opt/lib", + "/opt/local/lib" + ); + + open FILE, "glob.h" or die "glob.h: $!\n"; + while(<FILE>) + { + if ( /\/\/#define DATABASE/ ) + { + remove_from_array("mysql/mysql.h",\@headers); + remove_from_array("libmysqlclient.so",\@libs); + } + + elsif ( /\/\/#define NCURSES/ ) + { + remove_from_array("ncurses.h",\@headers); + remove_from_array("libncurses.so",\@libs); + } + } + close FILE; + + if ( defined $ENV{YHTTPDHEADERPATHS} ) + { + map { print "Adding $_...\n"; + unshift @headerpaths, $_ } split /:/, $ENV{YHTTPDHEADERPATHS}; + } + + if ( defined $ENV{YHTTPDLIBPATHS} ) + { + map { print "Adding $_...\n"; + unshift @libpaths, $_ } split /:/, $ENV{YHTTPDLIBPATHS}; + } + + + print "Headers:\n"; + + my $testit = 0; + map { $incadd{&check($deepness, $_, @headerpaths)}++ } + @headers; + + $testit = 0; + print "Libraries:\n"; + map { $libadd{&check($deepness, $_, @libpaths)}++ } + @libs; + + my $incadd = &make_add("-I", \%incadd); + my $libadd = &make_add("-L", \%libadd); + + for ( @libs ) + { + $libadd .= "-l$_ " if s/^lib// and s/\.so$//; + } + + print "Incadd: $incadd\n"; + print "Libadd: $libadd\n"; + + `echo $incadd > includes.add`; + `echo $libadd > libs.add`; + + print "Creating new base Makefile...\n"; + unlink("Makefile") if -f "Makefile"; + unlink("../err") if -f "../err"; + open Fin, "Makefile.in" or die "Makefile.in: $!\n"; + open Fout, ">Makefile" or die "Makefile: $!\n"; + +# my $cpp = `echo *.cpp */*.cpp contrib/*/*.cpp | sort`; + my $cpp = `echo *.cpp */*.cpp | sort`; + my $compiler = `tail -n 1 ../g++.version`; + my $version = `tail -n 2 ../g++.version | head -n 1`; + my $uname = `uname -srm`; + my $compopt = join "; ", split /\n/, `cat ../g++.version`; + + chomp $uname; + chomp $compopt; + + print "Configuring for $uname...\n"; + chomp $cpp; + chomp $version; + + while (<Fin>) + { + s/^(CC=).*\n/$1$compiler/; + s/^(SRCS=).*/$1$cpp/; + s/ -frepo//; # unless $version =~ /3\.4/; + if ( $uname !~ /Linux/i ) { + print "Disabling -ldl flag...\n" if s/ -ldl//; + } + print Fout; + } + close Fin; + + my $args = join(" -",@ARGV); + $args = "-".$args unless $args eq ""; + + for my $cppfile (split / /, $cpp) + { + my $ofile = $cppfile; + $ofile =~ s/\.cpp/\.o/; + print Fout "../obj/$ofile: $cppfile\n"; + print Fout "\t\@if ! test -d `dirname ../obj/$ofile`; then mkdir -p `dirname ../obj/$ofile`; fi\n"; + my $class = $ofile; + $class =~ s/\.o//; + if ( $class =~ /contrib\/.+/ ) + { + my $dirname = `dirname $class`; + print Fout "\t\@echo -n \"Compiling contributed class $class \"\n"; + } + + else + { + print Fout "\t\@echo -n \"Compiling base class $class \"\n"; + } + + print Fout "\t\@\$(CC) \$(CFLAGS) \$(INCLUDES) $args -c -o ../obj/$ofile $cppfile\n"; + print Fout "\t\@du -hc ../obj/$ofile | tail -n 1 | sed s/total// | sed \"s/ //g\"\n"; + } + + close Fout; + + open F, "msgs.h" or die "msgs.h: $!\n"; + my @msgs = <F>; + close F; + unlink("msgs.h"); + open F, ">msgs.h" or die "msgs.h: $!\n"; + + for (@msgs) + { + s/(UNAME)(.+)$/UNAME "$uname"/; + s/(COMPOPT)(.+)$/COMPOPT "$compopt"/; + print F; + } + close F; + + if ( -d "mods" ) + { + chdir("mods"); + my $cflags = "-fno-inline -fno-default-inline"; + + $cflags .= " -nostdlib" if $uname =~ /FreeBSD/i && `uname -r` =~ /^4\./; + + system("echo $cflags > cflags.add"); + system("./configure"); + chdir(".."); + } + + sub remove_from_array + { + my $elem = shift; + my $array = shift; + + for ( my $i = 0; $i <= $#$array; ++$i ) + { + if ( $$array[$i] eq $elem ) + { + splice(@$array,$i,1); + last; + } + } # for + } + + sub check { + my $deep = shift; + + if ($deep == 0) { + print "Looking too deep! ($deepness)\n"; + exit(1); + } + + my $check = shift; + $testit = 1 if $check =~ s/::test:://; + + my $print = 1; + if ( $_[-1] eq "subsearch" ) { + $print = 0; + pop(@_); + } + + if ($print) + { + print "Checking for $check..."; + print "\n" if $testit; + } + + for (@_) + { + if ( -f "$_/$check" ) + { + if ($testit) + { + return $_ if test_include($_, $check); + return ""; + } + + else + { + print "OK\n"; + return "" if $_ eq "/usr/lib" or $_ eq "/usr/include"; + return $_; + } + } + } + + for (@_) + { + next unless -d $_; + opendir D, $_ or warn "$_: $!\n"; + my @dir = readdir(D); + closedir D; + + for my $dir ( @dir ) + { + next if $dir =~ /^\.+$/ or !-d "$_/$dir"; + my $path = &check($deep-1, $check, "$_/$dir", "subsearch"); + return $path if $path ne ""; + } + } + + if ($print) + { + print "NOT OK\n"; + print "Please make sure that you have the needed software installed!\n"; + print "If you have a special path for your includes then edit src/configure!\n"; + print "Or set the environment variables YHTTPDHEADERPATHS and YHTTPDLIBPATHS.\n"; + print " Example: setenv YHTTPDHEADERPATHS \"/your/header/includes:/a/includes\"\n"; + print "(The environment variables have to be seperated by an :)\n"; + print "PS: You may use the locate and/or find command to search for files.\n"; + exit(1); + } + + `touch ../err`; + return ""; + } + + sub make_add { + my $flag = shift; + my $add = shift; + my $ret = ""; + + for (reverse keys %$add) { + next unless /.+/; + $ret .= "$flag$_ "; + } + return $ret; + } + + sub test_include + { + my $shift = shift; + my $check = shift; + my $return = 0; + print "Testing $shift/$check..."; + + `echo "\#include \\"maps/hashmap.h\\"" > __test.cpp`; + `echo "int main(void){return 0;}" >> __test.cpp`; + my $cmd = "`tail -n 1 ../g++.version` -I$shift __test.cpp -o /dev/null 2>/dev/null"; + system $cmd; + + unless ($?) + { + print "OK\n"; + $return = 1; + } + + else + { + print "Not OK\n"; + } + + unlink "__test.cpp" if -f "__test.cpp"; + return $return; + } + + exit(0); +' `echo "$*" | sed "s/-//g"` diff --git a/ycurses/src/curses/attributes.cpp b/ycurses/src/curses/attributes.cpp new file mode 100644 index 0000000..b859da0 --- /dev/null +++ b/ycurses/src/curses/attributes.cpp @@ -0,0 +1,80 @@ +#ifndef ATTRIBUTES_CPP +#define ATTRIBUTES_CPP + +#include "attributes.h" + +attributes::attributes() +{ + init(); +} + +attributes::attributes(int i_attr) +{ + init(); + set(true, i_attr); +} + +attributes::attributes(color& r_color) +{ + init(); + set_color(r_color); +} + +void +attributes::init() +{ + p_color = 0; +} + +void +attributes::use_wattron(WINDOW* p_window) +{ + std::set<int>::iterator iter; + for (iter = set_attr.begin(); iter != set_attr.end(); ++iter) + wattron(p_window, *iter); + + if (p_color) + wattron(p_window, COLOR_PAIR(p_color->get_num())); +} + +void +attributes::use_wattroff(WINDOW* p_window) +{ + std::set<int>::iterator iter; + for (iter = set_attr.begin(); iter != set_attr.end(); ++iter) + wattroff(p_window, *iter); + + if (p_color) + wattroff(p_window, COLOR_PAIR(p_color->get_num())); +} + + +void +attributes::unset_all() +{ + set_attr.clear(); + p_color = 0; +} + +bool +attributes::get(int i_attr) +{ + return set_attr.find(i_attr) != set_attr.end(); +} + +void +attributes::set(bool b, int i_attr) +{ + if ((set_attr.find(i_attr) != set_attr.end() ) == b) + return; + + set_attr.insert(i_attr); +} + +void +attributes::set_color(color& r_color) +{ + this->p_color = &r_color; +} + +#endif diff --git a/ycurses/src/curses/attributes.h b/ycurses/src/curses/attributes.h new file mode 100644 index 0000000..2bc58d6 --- /dev/null +++ b/ycurses/src/curses/attributes.h @@ -0,0 +1,70 @@ +#ifndef ATTRIBUTES_H +#define ATTRIBUTES_H + +#include <set> +#include "incl.h" +#include "color.h" + +using namespace std; + +const int Normal = A_NORMAL; +const int Standout = A_STANDOUT; +const int Underline = A_UNDERLINE; +const int Reverse = A_REVERSE; +const int Blink = A_BLINK; +const int Dim = A_DIM; +const int Bold = A_BOLD; +const int Protect = A_PROTECT; +const int Invis = A_INVIS; +const int AltCharSet = A_ALTCHARSET; +const int CharText = A_CHARTEXT; + +class attributes +{ +private: + void init(); + set<int> set_attr; + bool get(int i_attr); + void set(bool b, int i_attr); + color* p_color; + + friend class window; + void use_wattron(WINDOW* p_window); + void use_wattroff(WINDOW* p_window); + +public: + attributes(); + attributes(int i_attr); + attributes(color& r_color); + + void set(int i_attr) { set(true, i_attr); } + void unset(int i_attr ) { set(false, i_attr); } + void unset_all(); + void set_color(color& r_color); + + void set_normal(bool b) { set(b, Normal); } + void set_standout(bool b) { set(b, Standout); } + void set_underline(bool b) { set(b, Underline); } + void set_reverse(bool b) { set(b, Reverse); } + void set_blink(bool b) { set(b, Blink); } + void set_dim(bool b) { set(b, Dim); } + void set_bold(bool b) { set(b, Bold); } + void set_protect(bool b) { set(b, Protect); } + void set_invisible(bool b) { set(b, Invis); } + void set_altcharset(bool b) { set(b, AltCharSet); } + void set_chartext(bool b) { set(b, CharText); } + + bool get_normal() { return get(Normal); } + bool get_standout() { return get(Standout); } + bool get_underline() { return get(Underline); } + bool get_reverse() { return get(Reverse); } + bool get_blink() { return get(Blink); } + bool get_dim() { return get(Dim); } + bool get_bold() { return get(Bold); } + bool get_protect() { return get(Protect); } + bool get_invisible() { return get(Invis); } + bool get_altcharset() { return get(AltCharSet); } + bool get_chartext() { return get(CharText); } +}; + +#endif diff --git a/ycurses/src/curses/color.cpp b/ycurses/src/curses/color.cpp new file mode 100644 index 0000000..190d343 --- /dev/null +++ b/ycurses/src/curses/color.cpp @@ -0,0 +1,54 @@ +#ifndef COLOR_CPP +#define COLOR_CPP + +#include "color.h" + +bool color::b_activated = false; +int color::i_pair_count = 0; + +color::color(short i, short j) + : i_foreground(i), i_background(j) +{ + init(); + + i_pair = ++i_pair_count; + + /* + * Simple color assignment. color pair 0 cannot + * be redefined. + */ + init_pair(i_pair, i_foreground, i_background); +} + +color::~color() +{ +} + +void +color::init() +{ + if ( !b_activated ) + { + if (has_colors()) + { + start_color(); + b_activated = true; + } + } +} + +void +color::enable() +{ + attron(COLOR_PAIR(i_pair)); +} + +void +color::disable() +{ + attroff(COLOR_PAIR(i_pair)); +} + + +#endif + diff --git a/ycurses/src/curses/color.h b/ycurses/src/curses/color.h new file mode 100644 index 0000000..a59727c --- /dev/null +++ b/ycurses/src/curses/color.h @@ -0,0 +1,39 @@ + +#ifndef COLOR_H +#define COLOR_H + +#include "incl.h" + +using namespace std; + +const short Red = COLOR_RED; +const short Green = COLOR_GREEN; +const short Yellow = COLOR_YELLOW; +const short Blue = COLOR_BLUE; +const short Cyan = COLOR_CYAN; +const short Magenta = COLOR_MAGENTA; +const short White = COLOR_WHITE; +const short Black = COLOR_BLACK; + +class color +{ + private: + void init(); + + static int i_pair_count; + short i_pair; + short i_foreground; + short i_background; + static bool b_activated; + + friend class curses; + + public: + color(short i, short j); + ~color(); + void enable(); + void disable(); + short get_num() { return i_pair; } +}; + +#endif diff --git a/ycurses/src/curses/coordinate.cpp b/ycurses/src/curses/coordinate.cpp new file mode 100644 index 0000000..efdf9e2 --- /dev/null +++ b/ycurses/src/curses/coordinate.cpp @@ -0,0 +1,134 @@ +#ifndef COORDONATE_CPP +#define COORDONATE_CPP + +#include "coordinate.h" + +coordinate::coordinate() +{ + y = x = 0; +} + +coordinate::coordinate(coordinate_type type, dummy_window& r_win) +{ + set(type, r_win); +} + +coordinate::coordinate(coordinate_type type) +{ + set(type); +} + +coordinate::coordinate(int y, int x) +{ + this->y = y; + this->x = x; +} + +coordinate& +coordinate::set(coordinate_type type, dummy_window& r_win) +{ + switch (type) + { + case Absolutecoord: + getyx(r_win.get_WINDOW(), y, x); + break; + + case Relativecoord: + getparyx(r_win.get_WINDOW(), y, x); + break; + + case Beginningcoord: + getbegyx(r_win.get_WINDOW(), y, x); + break; + + case windowSize: + getmaxyx(r_win.get_WINDOW(), y, x); + break; + + default: + set(type); + } + + return *this; +} + +coordinate& +coordinate::set(coordinate_type type) +{ + switch (type) + { + case TerminalSize: + y = COLS; + x = LINES; + break; + + case TerminalCenter: + y = static_cast<int>(COLS / 2); + x = static_cast<int>(LINES / 2); + break; + } + + return *this; +} + +coordinate& +coordinate::left() +{ + return left(1); +} + +coordinate& +coordinate::right() +{ + return right(1); +} + +coordinate& +coordinate::up() +{ + return up(1); +} + +coordinate& +coordinate::down() +{ + return down(1); +} + +coordinate& +coordinate::left(int i) +{ + x -= i; + return *this; +} + +coordinate& +coordinate::right(int i) +{ + x += i; + return *this; +} + +coordinate& +coordinate::up(int i) +{ + y -= i; + return *this; +} + +coordinate& +coordinate::down(int i) +{ + y += i; + return *this; +} + +coordinate& +coordinate::displace(int i_y, int i_x) +{ + y += i_y; + x += i_x; + return *this; +} + +#endif diff --git a/ycurses/src/curses/coordinate.h b/ycurses/src/curses/coordinate.h new file mode 100644 index 0000000..c17b36b --- /dev/null +++ b/ycurses/src/curses/coordinate.h @@ -0,0 +1,43 @@ +#ifndef COORDINATE_H +#define COORDINATE_H + +#include "incl.h" +#include "dummy.h" + +using namespace std; + +enum coordinate_type +{ + Absolutecoord, + Relativecoord, + Beginningcoord, + windowSize, + TerminalSize, + TerminalCenter +}; + + +struct coordinate +{ + int y, x; + + coordinate(); + coordinate(coordinate_type type, dummy_window& r_win); + coordinate(coordinate_type type); + coordinate(int y, int x); + + coordinate& set(coordinate_type type, dummy_window& r_win); + coordinate& set(coordinate_type type); + coordinate& left(); + coordinate& right(); + coordinate& up(); + coordinate& down(); + coordinate& left(int i); + coordinate& right(int i); + coordinate& up(int i); + coordinate& down(int i); + coordinate& displace(int i_y, int i_x); + +}; + +#endif diff --git a/ycurses/src/curses/coordinate.impl b/ycurses/src/curses/coordinate.impl new file mode 100644 index 0000000..8bdf17c --- /dev/null +++ b/ycurses/src/curses/coordinate.impl @@ -0,0 +1,17 @@ +template<class T> +coordinate +create_coordinate(dummy_window& d_window) +{ + coordinate coord; + T(d_window, coord.x, coord.y); + return coord; +} + +template<class T> +coordinate +create_coordinate() +{ + coordinate coord; + T(coord.x, coord.y); + return coord; +} diff --git a/ycurses/src/curses/curses.cpp b/ycurses/src/curses/curses.cpp new file mode 100644 index 0000000..3605e59 --- /dev/null +++ b/ycurses/src/curses/curses.cpp @@ -0,0 +1,86 @@ +#ifndef CURSES_CPP +#define CURSES_CPP + +#include "curses.h" + +int curses::i_self_counter = 0; + +curses::curses() +{ + if ( ++i_self_counter == 1 ) + { + initscr(); + raw(); + keypad(stdscr, TRUE); + noecho(); + } +} + +curses::~curses() +{ + if ( --i_self_counter == 0 ) + { +/* + Factory<attributes>::destroyAll(); + Factory<color>::destroyAll(); + Factory<window>::destroyAll(); + Factory<menu>::destroyAll(); + Factory<pwindow>::destroyAll(); + */ + clear(); + endwin(); + } +} + +void +curses::finish() +{ +} + +int +curses::get_char() +{ + return getch(); +} + +string +curses::get_string() +{ + char c[1024]; + getstr(c); + return string(c); +} + +void +curses::pause() +{ + getch(); +} + +void +curses::disable() +{ + refresh(); + def_prog_mode(); + endwin(); +} + +void +curses::enable() +{ + reset_prog_mode(); + refresh(); +} + +void +curses::clear() +{ + coordinate coord(LINES, COLS); + for ( int i = 0; i < coord.y; ++i ) + for ( int j = 0; j < coord.x; ++j ) + mvaddch(i, j, ' '); + + refresh(); +} + +#endif diff --git a/ycurses/src/curses/curses.h b/ycurses/src/curses/curses.h new file mode 100644 index 0000000..04ed707 --- /dev/null +++ b/ycurses/src/curses/curses.h @@ -0,0 +1,55 @@ +#ifndef CURSES_H +#define CURSES_H + +#include "attributes.h" +#include "incl.h" +#include "color.h" +#include "cursor.h" +#include "menu.h" +#include "pwindow.h" +#include "tool.h" +#include "window.h" +#include "coordinate.h" + +using namespace std; + +/* This class is representing the base of curses, it has to be instantiated + * in order to use curses. + */ +class curses +{ + private: + static int i_self_counter; + + public: + /* Initializes curses before its first use */ + curses(); + + /* Removes all curses elements, all objects (such as window, color etc) + * be finished as well! + */ + ~curses(); + + /* Waits for user intput and returns the ASCII code being typed */ + static int get_char(); + + /* Returns the string being typed until the first return */ + static string get_string(); + + /* Waits intil the user hits a key */ + static void pause(); + + static void disable(); + static void enable(); + + /* Removes all curses elements, all objects (such as window, color etc) will + * be finished as well! This method will be called by ~curses internally. + * You can also use this method instead of the destructor if you wanna use + * another shutdown routine like catching SIGINT first, deleting your own + * stuff, and then running curses::finish();! + */ + static void finish(); + static void clear(); +}; + +#endif diff --git a/ycurses/src/curses/cursor.cpp b/ycurses/src/curses/cursor.cpp new file mode 100644 index 0000000..eaa10a7 --- /dev/null +++ b/ycurses/src/curses/cursor.cpp @@ -0,0 +1,32 @@ +#ifndef CURSOR_CPP +#define CURSOR_CPP + +#include "cursor.h" + +cursor::cursor() +{ +} + +cursor::cursor(cursorType t) +{ + set(t); +} + +cursor::cursor(coordinate& r_coord) +{ + set(r_coord); +} + +void +cursor::set(cursorType t) +{ + curs_set(t); +} + +void +cursor::set(coordinate& r_coord) +{ + move(r_coord.y, r_coord.x); +} + +#endif diff --git a/ycurses/src/curses/cursor.h b/ycurses/src/curses/cursor.h new file mode 100644 index 0000000..504a44c --- /dev/null +++ b/ycurses/src/curses/cursor.h @@ -0,0 +1,30 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include "incl.h" +#include "coordinate.h" + +using namespace std; + +enum cursorType +{ + Invisible = 0, + Visible, |
