summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2008-10-05 15:11:52 (GMT)
committer Jaromil <jaromil@dyne.org>2008-10-05 15:11:52 (GMT)
commitd58f9438b198fb67b383db74e80ee244cc0ecf7f (patch)
treeb3ff3a863ececeeab7f5fc9dd1b6515625103e76
parent463a79aeeaf61bf774b5c216d4716b778af12b88 (diff)
fixes to build system to compile with gcc 4.3
-rw-r--r--Makefile3
-rw-r--r--cmdline.cpp4
-rw-r--r--jutils.cpp12
-rw-r--r--linklist.cpp2
-rw-r--r--linklist.h2
-rw-r--r--slw/Makefile5
-rw-r--r--slw/Makefile.am9
-rw-r--r--slw/jutils.cpp343
-rw-r--r--slw/jutils.h54
-rw-r--r--slw/linklist.cpp451
-rw-r--r--slw/linklist.h112
11 files changed, 17 insertions, 980 deletions
diff --git a/Makefile b/Makefile
index a40297e..37aa3b0 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,9 @@ CXXFLAGS = -Wall -ggdb -Islw -I. -I/usr/pkg/include -DHAVE_BSD
# Darwin/OSX flags: uncomment all below and comment the rest
# CPPFLAGS = -pipe -Wall -ggdb -I../slw -I. -I/sw/include -L/sw/lib -DHAVE_BSD
+# fix different paths for slang headers in various distros
+CXXFLAGS += -I/usr/include/slang
+
# flags to compile slang linking to dynamic system lib
LIBS = -lslang -lpthread slw/libslw.a
diff --git a/cmdline.cpp b/cmdline.cpp
index e1698ac..71b8939 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -363,13 +363,13 @@ int main(int argc, char** argv)
perror ("Couldn't install SIGINT handler"); exit(0); }
// if playing, load the recording
- if(operation == PLAY)
+ if(operation == PLAY) {
if( ! tbt.load( filename ) ) {
error("no entries found in file %s",filename);
exit(1);
} else
len = tbt.buffer->len();
-
+ }
if(console) { // initialize the s-lang console
diff --git a/jutils.cpp b/jutils.cpp
index 6da4c6f..b1d6449 100644
--- a/jutils.cpp
+++ b/jutils.cpp
@@ -26,7 +26,7 @@
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
-
+#include <errno.h>
#include <jutils.h>
#include <slw.h>
@@ -65,7 +65,7 @@ void set_status(SLangWidget *s) {
// console = c;
//}
-void notice(char *format, ...) {
+void notice(const char *format, ...) {
va_list arg;
va_start(arg, format);
@@ -79,7 +79,7 @@ void notice(char *format, ...) {
va_end(arg);
}
-void func(char *format, ...) {
+void func(const char *format, ...) {
if(verbosity>=FUNC) {
va_list arg;
va_start(arg, format);
@@ -95,7 +95,7 @@ void func(char *format, ...) {
}
}
-void error(char *format, ...) {
+void error(const char *format, ...) {
va_list arg;
va_start(arg, format);
@@ -109,7 +109,7 @@ void error(char *format, ...) {
va_end(arg);
}
-void act(char *format, ...) {
+void act(const char *format, ...) {
va_list arg;
va_start(arg, format);
@@ -123,7 +123,7 @@ void act(char *format, ...) {
va_end(arg);
}
-void warning(char *format, ...) {
+void warning(const char *format, ...) {
if(verbosity>=WARN) {
va_list arg;
va_start(arg, format);
diff --git a/linklist.cpp b/linklist.cpp
index 4dc54f3..6d86df2 100644
--- a/linklist.cpp
+++ b/linklist.cpp
@@ -311,7 +311,7 @@ Entry::~Entry() {
if(data) free(data);
}
-void Entry::set_name(char *nn) {
+void Entry::set_name(const char *nn) {
strncpy(name,nn,255);
}
diff --git a/linklist.h b/linklist.h
index ce9b279..a8ca3fc 100644
--- a/linklist.h
+++ b/linklist.h
@@ -85,7 +85,7 @@ class Entry {
Entry();
~Entry();
- void set_name(char *nn);
+ void set_name(const char *nn);
Entry *next;
Entry *prev;
diff --git a/slw/Makefile b/slw/Makefile
index dc49860..1a98b1d 100644
--- a/slw/Makefile
+++ b/slw/Makefile
@@ -17,6 +17,9 @@ CXXFLAGS = -pipe -Wall -ggdb -I.
# Darwin/OSX flags: uncomment all below and comment the rest
# CXXFLAGS = -pipe -Wall -ggdb -I. -I/sw/include -L/sw/lib
+# fix different paths for slang headers in various distros
+CXXFLAGS += -I/usr/include/slang -I..
+
# flags to compile slang linking to dynamic system lib
LIBS = -lslang
@@ -31,7 +34,7 @@ LIBS = -lslang
#CXXFLAGS = -Wall -ggdb -I. -I$(SLANGPATH)/src
#LIBS = $(SLANGPATH)/src/objs/libslang.a -ltermcap
-DEPS = slw_console.o slw.o slw_popup.o abs_text_console.o slw_text.o linklist.o jutils.o
+DEPS = slw_console.o slw.o slw_popup.o abs_text_console.o slw_text.o ../linklist.o ../jutils.o
# generic make rules
#%.o: %.cpp
diff --git a/slw/Makefile.am b/slw/Makefile.am
deleted file mode 100644
index 354a02b..0000000
--- a/slw/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-# s-lang widgets
-
-INCLUDES = -I$(top_srcdir)/src/include
-
-AUTOMAKE_OPTIONS = foreign
-
-noinst_LIBRARIES = libslw.a
-
-libslw_a_SOURCES = slw_console.cpp slw.cpp slw_popup.cpp abs_text_console.cpp slw_text.cpp
diff --git a/slw/jutils.cpp b/slw/jutils.cpp
deleted file mode 100644
index fe2bf2d..0000000
--- a/slw/jutils.cpp
+++ /dev/null
@@ -1,343 +0,0 @@
-/* FreeJ
- * (c) Copyright 2001 Denis Roio aka jaromil <jaromil@dyne.org>
- *
- * This source code is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * This source code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * Please refer to the GNU Public License for more details.
- *
- * You should have received a copy of the GNU Public License along with
- * this source code; if not, write to:
- * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- * this file includes a malloc wrapper, it acts very verbose when debug
- * mode allow it
- */
-
-#include <stdio.h>
-
-#ifdef linux
-/* we try to use the realtime linux clock on /dev/rtc */
-#include <linux/rtc.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/select.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#endif
-
-#include <iostream>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <time.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <jutils.h>
-
-#define MAX_DEBUG 2
-
-#define FUNC 2 /* se il debug level e' questo
- ci sono le funzioni chiamate */
-#define WARN 1 /* ... blkbblbl */
-
-char msg[255];
-
-static int verbosity;
-
-static char *osd_msg;
-
-void set_debug(int lev) {
- lev = lev<0 ? 0 : lev;
- lev = lev>MAX_DEBUG ? MAX_DEBUG : lev;
- verbosity = lev;
-}
-
-int get_debug() {
- return(verbosity);
-}
-
-void set_osd(char *st) {
- osd_msg = st;
- osd_msg[0] = '\0';
-}
-
-void show_osd() {
- strncpy(osd_msg,msg,49);
- osd_msg[50] = '\0';
-}
-
-void show_osd(char *format, ...) {
- va_list arg;
- va_start(arg, format);
-
- vsnprintf(osd_msg,49, format, arg);
- osd_msg[50] = '\0';
- va_end(arg);
-}
-
-
-void notice(char *format, ...) {
- va_list arg;
- va_start(arg, format);
-
- vsnprintf(msg, 254, format, arg);
- fprintf(stderr,"[*] %s\n",msg);
-
- va_end(arg);
-}
-
-void func(char *format, ...) {
- if(verbosity>=FUNC) {
- va_list arg;
- va_start(arg, format);
-
- vsnprintf(msg, 254, format, arg);
- fprintf(stderr,"[F] %s\n",msg);
-
- va_end(arg);
- }
-}
-
-void error(char *format, ...) {
- va_list arg;
- va_start(arg, format);
-
- vsnprintf(msg, 254, format, arg);
- fprintf(stderr,"[!] %s\n",msg);
-
- va_end(arg);
-}
-
-void act(char *format, ...) {
- va_list arg;
- va_start(arg, format);
-
- vsnprintf(msg, 254, format, arg);
- fprintf(stderr," . %s\n",msg);
-
- va_end(arg);
-}
-
-void warning(char *format, ...) {
- if(verbosity>=WARN) {
- va_list arg;
- va_start(arg, format);
-
- vsnprintf(msg, 254, format, arg);
- fprintf(stderr,"[W] %s\n",msg);
-
- va_end(arg);
- }
-}
-
-void *jalloc(void *point,size_t size) {
- if(point!=NULL)
- if(verbosity>0) warning("requested malloc on a non-NULL pointer");
-
- point = malloc(size);
-
- if(point==NULL) {
- error("cannot allocate %u bytes of memory",size);
- return(NULL);
- } else if(verbosity>=FUNC) {
- fprintf(stderr,"[M] allocated memory at %p sized %u bytes\n",point,(unsigned int)size);
- }
- return(point);
-}
-
-bool jfree(void *point) {
-
- if(point==NULL) {
- warning("requested free on a NULL pointer");
- return(false);
- }
-
- // if(verbosity>=FUNC)
- // fprintf(stderr,"[M] freeing memory at address %p\n",point);
-
- free(point);
- point = NULL;
- return(true);
-}
-
-/*
- * fastrand - fast fake random number generator
- * by Fukuchi Kentarou
- * Warning: The low-order bits of numbers generated by fastrand()
- * are bad as random numbers. For example, fastrand()%4
- * generates 1,2,3,0,1,2,3,0...
- * You should use high-order bits.
- *
- */
-
-static uint32_t randval;
-
-uint32_t fastrand()
-{
- // kentaro's original one:
- // return (randval=randval*1103515245+12345);
- //15:55 <salsaman2> mine uses two prime numbers and the cycling is much reduced
- //15:55 <salsaman2> return (randval=randval*1073741789+32749);
- return(randval = randval * 1073741789 + 32749 );
-}
-
-void fastsrand(uint32_t seed)
-{
- randval = seed;
-}
-
-#undef ARCH_X86
-double dtime() {
-#ifdef ARCH_X86
- double x;
- __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
- return x;
-#else
- struct timeval mytv;
- gettimeofday(&mytv,NULL);
- return((double)mytv.tv_sec+1.0e-6*(double)mytv.tv_usec);
-#endif
-}
-
-#ifdef linux
-#include <sched.h>
-/* sets the process to "policy" policy, if max=1 then set at max priority,
- else use min priority */
-
-bool set_rtpriority(bool max) {
- struct sched_param schp;
- // set the process to realtime privs
-
- memset(&schp, 0, sizeof(schp));
-
- if(max)
- schp.sched_priority = sched_get_priority_max(SCHED_RR);
- else
- schp.sched_priority = sched_get_priority_min(SCHED_RR);
-
- if (sched_setscheduler(0, SCHED_RR, &schp) != 0)
- return false;
- else
- return true;
-}
-#endif
-/* handle signals.
- * From the manpage:
- * nanosleep delays the execution of the program for at least
- * the time specified in *req. The function can return earlier
- * if a signal has been delivered to the process. In this case,
- * it returns -1, sets errno to EINTR, and writes the remaining
- * time into the structure pointed to by rem unless rem is
- * NULL. The value of *rem can then be used to call nanosleep
- * again and complete the specified pause.
- */
-void jsleep(int sec, long nsec) {
- struct timespec tmp_rem,*rem;
- rem = &tmp_rem;
- timespec timelap;
- timelap.tv_sec = sec;
- timelap.tv_nsec = nsec;
- while (nanosleep (&timelap, rem) == -1 && (errno == EINTR));
-}
-
-
-/* small RTC interface by jaromil
- all comes from the Linux Kernel Documentation */
-#ifdef linux
-/* better to use /dev/rtc */
-static int rtcfd = -1;
-static fd_set readfds;
-static timeval rtctv = { 0,0 };
-static unsigned long rtctime;
-int rtc_open() {
- int res;
- rtcfd = open("/dev/rtc",O_RDONLY);
- if(!rtcfd) {
- perror("/dev/rtc");
- return 0;
- }
- /* set the alarm event to 1 second */
- res = ioctl(rtcfd, RTC_UIE_ON, 0);
- if(res<0) {
- perror("rtc ioctl");
- return 0;
- }
- notice("realtime clock succesfully initialized");
- return 1;
-}
-/* tick returns 0 if 1 second didn't passed since last tick,
- positive number if 1 second passed */
-unsigned long rtc_tick() {
- FD_ZERO(&readfds);
- FD_SET(rtcfd,&readfds);
- if ( ! select(rtcfd+1,&readfds,NULL,NULL,&rtctv) )
- return 0; /* a second didn't passed yet */
- read(rtcfd,&rtctime,sizeof(unsigned long));
- return rtctime;
-}
-void rtc_freq_set(unsigned long freq) {
- int res;
-
- res = ioctl(rtcfd,RTC_IRQP_SET,freq);
- if(res<0) { perror("rtc freq set"); }
-
- res = ioctl(rtcfd,RTC_IRQP_READ,&freq);
- if(res<0) { perror("rtc freq read"); }
-
- act("realtime clock frequency set to %ld",freq);
-
- res = ioctl(rtcfd,RTC_PIE_ON,0);
- if(res<0) { perror("rtc freq on"); return; }
-
-}
-void rtc_freq_wait() {
- int res;
- res = read(rtcfd,&rtctime,sizeof(unsigned long));
- if(res < 0) {
- perror("read rtc frequency interrupt");
- return;
- }
-}
-void rtc_close() {
- if(rtcfd<=0) return;
- ioctl(rtcfd, RTC_UIE_OFF, 0);
- // ioctl(rtcfd,RTC_PIE_OFF,0);
- close(rtcfd);
-}
-#endif
-
-void *(* jmemcpy)(void *to, const void *from, size_t len) = memcpy;
-
-/*
- * memset(x,0,y) is a reasonably common thing to do, so we want to fill
- * things 32 bits at a time even when we don't know the size of the
- * area at compile-time..
- */
-void jmemset(void * s, unsigned long c ,size_t count)
-{
-#ifdef ARCH_X86
-int d0, d1;
-__asm__ __volatile__(
- "rep ; stosl\n\t"
- "testb $2,%b3\n\t"
- "je 1f\n\t"
- "stosw\n"
- "1:\ttestb $1,%b3\n\t"
- "je 2f\n\t"
- "stosb\n"
- "2:"
- : "=&c" (d0), "=&D" (d1)
- :"a" (c), "q" (count), "0" (count/4), "1" ((long) s)
- :"memory");
-#else
- memset(s,c,count);
-#endif
-}
diff --git a/slw/jutils.h b/slw/jutils.h
deleted file mode 100644
index 548882a..0000000
--- a/slw/jutils.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* FreeJ
- * (c) Copyright 2001 Denis Roio aka jaromil <jaromil@dyne.org>
- *
- * This source code is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * This source code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * Please refer to the GNU Public License for more details.
- *
- * You should have received a copy of the GNU Public License along with
- * this source code; if not, write to:
- * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __UTILS_H__
-#define __UTILS_H__
-
-#include <inttypes.h>
-#include <errno.h>
-
-extern char msg[255];
-
-extern void *(*jmemcpy)( void *to, const void *from, size_t len );
-void jmemset(void * s, unsigned long c ,size_t count);
-
-void set_debug(int lev);
-int get_debug();
-void set_osd(char *st);
-void show_osd();
-void show_osd(char *format, ...);
-void notice(char *format, ...);
-void func(char *format, ...);
-void error(char *format, ...);
-void act(char *format, ...);
-void warning(char *format, ...);
-void *jalloc(void *point,size_t size);
-bool jfree(void *point);
-uint32_t fastrand();
-void fastsrand(uint32_t seed);
-double dtime();
-bool set_rtpriority(bool max);
-void jsleep(int sec, long nsec);
-int rtc_open();
-unsigned long rtc_tick();
-void rtc_freq_set(unsigned long freq);
-void rtc_freq_wait();
-void rtc_close();
-#endif
-
-
diff --git a/slw/linklist.cpp b/slw/linklist.cpp
deleted file mode 100644
index 6da1a09..0000000
--- a/slw/linklist.cpp
+++ /dev/null
@@ -1,451 +0,0 @@
-/* C++ Linked list class, threadsafe (boolean is atom)
- *
- * (c) Copyright 2001-2004 Denis Roio aka jaromil <jaromil@dyne.org>
- *
- * This source code is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * This source code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * Please refer to the GNU Public License for more details.
- *
- * You should have received a copy of the GNU Public License along with
- * this source code; if not, write to:
- * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * "$Id: linklist.cpp 768 2006-10-03 17:25:14Z jaromil $"
- *
- -------------------------------------------------------------------------
- linked list container class
-
- NOTE: add and rem don't take care of deleting pointers
- that has to be done by the process that creates them and
- knows which inheriting class they are (delete is done in main)
-*/
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <jutils.h>
-#include <linklist.h>
-
-
-Linklist::Linklist() {
- length = 0;
- first = NULL;
- last = NULL;
-#ifdef THREADSAFE
- pthread_mutex_init(&mutex,NULL);
-#endif
-
-// unlock();
-}
-
-Linklist::~Linklist() {
- clear();
-}
-
-/* adds one element at the end of the list */
-void Linklist::append(Entry *addr) {
- Entry *ptr = NULL;
- if(addr->list) addr->rem();
-#ifdef THREADSAFE
- lock();
-#endif
-
- if(!last) { /* that's the first entry */
- last = addr;
- last->next = NULL;
- last->prev = NULL;
- first = last;
- } else { /* add the entry to the end */
- ptr = last;
- ptr->next = addr;
- addr->next = NULL;
- addr->prev = ptr;
- last = addr;
- }
- /* save the pointer to this list */
- addr->list = this;
- length++;
-#ifdef THREADSAFE
- unlock();
-#endif
-}
-
-void Linklist::prepend(Entry *addr) {
- Entry *ptr = NULL;
- if(addr->list) addr->rem();
-#ifdef THREADSAFE
- lock();
-#endif
-
- if(!first) { /* that's the first entry */
- first = addr;
- first->next = NULL;
- first->prev = NULL;
- last = first;
- } else { /* add an entry to the beginning */
- ptr = first;
- ptr->prev = addr;
- addr->next = ptr;
- addr->prev = NULL;
- first = addr;
- }
- addr->list = this;
- length++;
-#ifdef THREADSAFE
- unlock();
-#endif
-}
-
-
-// inserts an element after the given one
-void Linklist::insert_after(Entry *addr, Entry *pos) {
-
- // take it out from other lists
- if(addr->list) addr->rem();
-
-#ifdef THREADSAFE
- lock();
-#endif
- if(pos->next) {
- pos->next->prev = addr;
- addr->next = pos->next;
- } else last = addr; // it's the last
-
- addr->prev = pos;
- pos->next = addr;
-
- length++;
- addr->list = this;
-
-#ifdef THREADSAFE
- unlock();
-#endif
-}
-
-
-/* adds an element at the position specified
- if pos is out of bounds adds it at the beginning or the end
- the element occupying allready the position slides down
- THIS FUNCTION IS NOT YET RELIABLE
-*/
-void Linklist::insert(Entry *addr, int pos) {
- if(length<=pos) { /* adds it at the end */
- append(addr);
- return;
- } else if(pos<=1) {
- prepend(addr);
- return;
- }
-
- if(addr->list) addr->rem();
-
- Entry *ptr = pick(pos);
-
-#ifdef THREADSAFE
- lock();
-#endif
- ptr->prev->next = addr;
- addr->prev = ptr->prev;
-
- ptr->prev = addr;
- addr->next = ptr;
-
- length++;
- addr->list = this;
-#ifdef THREADSAFE
- unlock();
-#endif
-}
-
-/* clears the list
- i don't delete filters here because they have to be deleted
- from the procedure creating them. so this call simply discards
- the pointers stored into the linked list. OBJECTS ARE NOT FREED */
-void Linklist::clear() {
-#ifdef THREADSAFE
- lock();
-#endif
- sel(0);
- length = 0;
- first = NULL;
- last = NULL;
-#ifdef THREADSAFE
- unlock();
-#endif
-}
-
-/* takes one element from the list
- === STARTING FROM 1 ===
- returns NULL if called with pos=0 or pos>length
- returns Entry pointer otherwise
- this function is then overloading the operator[]
-*/
-Entry *Linklist::pick(int pos) {
- if(pos<1) {
- warning("linklist access at element 0 while first element is 1");
- return(NULL);
- }
- if(length<pos) {
- warning("linklist access out of boundary");
- return(NULL);
- }
- // shortcuts
- if(pos==1) return(first);
- if(pos==length) return(last);
-
- Entry *ptr = first;
- int c;
- for(c=1;c<pos;c++) ptr = ptr->next;
-
- return(ptr);
-}
-
-/* search the linklist for the entry matching *name
- returns the Entry* on success, NULL on failure */
-Entry *Linklist::search(char *name) {
- Entry *ptr = first;
- while(ptr) {
- if( strcasecmp(ptr->name,name)==0 ) break;
- ptr = ptr->next;
- }
- return(ptr);
-}
-/* searches all the linklist for entries starting with *needle
- returns a list of indexes where to reach the matches */
-int *Linklist::completion(char *needle) {
- int c;
- int found;
- int len = strlen(needle);
-
- /* cleanup */
- memset(compbuf,0,MAX_COMPLETION);
-
- /* check it */
- Entry *ptr = first;
- if(!ptr) return compbuf;
-
- for( found=0, c=1 ; ptr ; c++ , ptr=ptr->next ) {
- if(!len) { // 0 lenght needle: return the full list
- compbuf[found] = c;
- found++;
- } else if( strncasecmp(needle,ptr->name,len)==0 ) {
- compbuf[found] = c;
- found++;
- }
- }
-
- func("completion found %i hits",found);
- return compbuf;
-}
-
-
-/* this function is a wrapper around Entry::up()
- better to use that if you have a pointer to your Entry */
-bool Linklist::moveup(int pos) {
- Entry *p = pick(pos);
- if(!p) return(false);
- return( p->up() );
-}
-bool Linklist::movedown(int pos) {
- Entry *p = pick(pos);
- if(!p) return(false);
- return( p->down() );
-}
-bool Linklist::moveto(int num, int pos) {
- Entry
- *p = pick(num);
- if(!p) return(false);
- return( p->move(pos) );
-}
-/* removes one element from the list */
-void Linklist::rem(int pos) {
- Entry *ptr = pick(pos);
- if(ptr==NULL) return;
- ptr->rem();
-}
-
-/* selects ONLY ONE, deselects the others
- use Entry::sel() if you want to do multiple selects */
-void Linklist::sel(int pos) {
- int c;
- Entry *ptr = last;
-
- if(pos>length) return;
-
- for(c=length;c>0;c--) {
- if(c==pos) ptr->sel(true);
- else ptr->sel(false);
- ptr = ptr->prev;
- }
-}
-
-/* returns the last one selected
- this is supposed to be used with single selections */
-Entry *Linklist::selected() {
- int c;
- Entry *ptr = last;
- for(c=length;c>0;c--) {
- if(ptr->select) return ptr;
- ptr = ptr->prev;
- }
- return NULL;
-}
-
-Entry::Entry() {
- next = NULL;
- prev = NULL;
- list = NULL;
- data = NULL;
- select = false;
- strncpy(name,"noname",255);
-}
-
-Entry::~Entry() {
- rem();
- if(data) free(data);
-}
-
-void Entry::set_name(char *nn) {
- strncpy(name,nn,255);
-}
-
-bool Entry::up() {
- if(!prev || !list) return(false);
-#ifdef THREADSAFE
- list->lock();
-#endif
-
- Entry *tprev = prev,
- *tnext = next,
- *pp = prev->prev;
-
- if(!next)
- list->last = prev;
-
- if(tnext)
- tnext->prev = tprev;
-
- next = tprev;
- prev = pp;
- tprev->next = tnext;
- tprev->prev = this;
-
- if(pp)
- pp->next = this;
-
- if(!prev)
- list->first = this;
-
-#ifdef THREADSAFE
- list->unlock();
-#endif
- return(true);
-}
-
-bool Entry::down() {
- if(!next || !list) return(false);
-#ifdef THREADSAFE
- list->lock();
-#endif
-
- Entry *tprev = prev,
- *tnext = next,
- *nn = next->next;
-
- if(!prev)
- list->first = next;
-
- if(tprev)
- tprev->next = tnext;
-
- prev = tnext;
- next = nn;
- tnext->prev = tprev;
- tnext->next = this;
- if(nn)
- nn->prev = this;
-
- if(!next)
- list->last = this;
-
-#ifdef THREADSAFE
- list->unlock();
-#endif
- return(true);
-}
-
-bool Entry::move(int pos) {
- func("Entry::move(%i) - NEW LINKLIST MOVE, TRYING IT...");
- if(!list) return(false);
-#ifdef THREADSAFE
- list->lock();
-#endif
-
- Entry *tn, *tp;
-
- Entry *swapping = list->pick(pos);
- if(swapping == this) return(true);
- if(!swapping) return(false);
-
- tn = swapping->next;
- tp = swapping->prev;
-
- swapping->next = next;
- swapping->prev = prev;
- if(next) next->prev = swapping;
- else list->last = swapping;
- if(prev) prev->next = swapping;
- else list->first = swapping;
-
- next = tn;
- prev = tp;
- if(next) next->prev = this;
- else list->last = this;
- if(prev) prev->next = this;
- else list->first = this;
-
-#ifdef THREADSAFE
- list->unlock();
-#endif
- func("LINKLIST MOVE RETURNS SUCCESS");
-
- return(true);
-}
-
-void Entry::rem() {
- bool lastone = false;
- if(!list) return;
-#ifdef THREADSAFE
- list->lock();
-#endif
-
- if(next) { // if there is a next
- next->prev = prev; // link it to the previous
- next->select = select; // inherit selection
- } else {
- list->last = prev; // else just make it the last
- lastone = true;
- }
-
- if(prev) { // if there is a previous
- prev->next = next; // link it to the next
- if(lastone) prev->select = select;
- } else list->first = next; // else just make it a first
-
- list->length--;
-#ifdef THREADSAFE
- list->unlock();
-#endif
-
- list = NULL;
-}
-
-void Entry::sel(bool on) {
- select = on;
-}
diff --git a/slw/linklist.h b/slw/linklist.h
deleted file mode 100644
index 7ccdc78..0000000
--- a/slw/linklist.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/* C++ Linked list class, threadsafe (boolean is atom)
- *
- * (c) Copyright 2001-2006 Denis Rojo <jaromil@dyne.org>
- *
- * This source code is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * This source code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * Please refer to the GNU Public License for more details.
- *
- * You should have received a copy of the GNU Public License along with
- * this source code; if not, write to:
- * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __linklist_h__
-#define __linklist_h__
-
-
-// uncomment to have mutex locked operations
-// can be slow on OSX and adds dependency to pthreads
-#define THREADSAFE 1
-
-#ifdef THREADSAFE
-#include <pthread.h>
-#endif
-
-// maximum number of members returned by the completion
-#define MAX_COMPLETION 512
-
-class Entry;
-
-class Linklist {
- public:
- Linklist();
- virtual ~Linklist();
-
- Entry *begin() { return(first); };
- Entry *end() { return(last); };
- int len() { return(length); };
-
- void append(Entry *addr);
- void add(Entry *addr) { append(addr); }; /* lazy backward compatibility */
- void prepend(Entry *addr);
- void insert(Entry *addr, int pos);
- void insert_after(Entry *addr, Entry *pos);
- void rem(int pos);
- void sel(int pos);
- void clear();
- bool moveup(int pos);
- bool movedown(int pos);
- bool moveto(int num, int pos);
- Entry *pick(int pos);
- Entry *search(char *name);
- int *completion(char *needle);
-
- Entry *selected();
-
- Entry *operator[](int pos) { return pick(pos); };
-
- /* don't touch these directly */
- Entry *first;
- Entry *last;
- int length;
-
-#ifdef THREADSAFE
- void lock() { pthread_mutex_lock(&mutex); };
- void unlock() { pthread_mutex_unlock(&mutex); };
-#endif
-
- private:
-
-#ifdef THREADSAFE
- pthread_mutex_t mutex;
-#endif
-
- int compbuf[MAX_COMPLETION]; // maximum completion listsize allowed
-
-};
-
-class Entry {
- friend class Linklist;
-
- public:
- Entry();
- ~Entry();
-
- void set_name(char *nn);
-
- Entry *next;
- Entry *prev;
-
- Linklist *list;
-
- bool up();
- bool down();
- bool move(int pos);
- void rem();
- void sel(bool on);
-
- bool select;
-
- char name[256];
-
- void *data; ///< generic data pointer
-};
-
-#endif