summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
Diffstat (limited to 'osdep')
-rw-r--r--osdep/findfiles.c97
-rw-r--r--osdep/findfiles.h2
-rw-r--r--osdep/getch2-os2.c6
-rw-r--r--osdep/getch2-win.c6
-rw-r--r--osdep/getch2.c8
-rw-r--r--osdep/getch2.h3
-rw-r--r--osdep/mmap_anon.c2
-rw-r--r--osdep/mplayer.rc1
-rw-r--r--osdep/priority.c3
-rw-r--r--osdep/priority.h1
-rw-r--r--osdep/shmem.c2
-rw-r--r--osdep/timer-darwin.c18
-rw-r--r--osdep/timer-linux.c47
-rw-r--r--osdep/timer-win2.c14
-rw-r--r--osdep/timer.h9
15 files changed, 128 insertions, 91 deletions
diff --git a/osdep/findfiles.c b/osdep/findfiles.c
new file mode 100644
index 0000000000..879f6d5c98
--- /dev/null
+++ b/osdep/findfiles.c
@@ -0,0 +1,97 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer 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. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <dirent.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "talloc.h"
+
+#if defined(__MINGW32__) || defined(__CYGWIN__)
+static const char dir_separators[] = "/\\:";
+#else
+static const char dir_separators[] = "/";
+#endif
+
+char **find_files(const char *original_file, const char *suffix,
+ int *num_results_ptr)
+{
+ void *tmpmem = talloc_new(NULL);
+ char *fname = talloc_strdup(tmpmem, original_file);
+ char *basename = NULL;
+ char *next = fname;
+ while (1) {
+ next = strpbrk(next, dir_separators);
+ if (!next)
+ break;
+ basename = next++;
+ }
+ char *directory;
+ if (basename) {
+ directory = fname;
+ *basename++ = 0;
+ } else {
+ directory = ".";
+ basename = fname;
+ }
+
+
+ char **results = talloc_size(NULL, 0);
+ DIR *dp = opendir(directory);
+ struct dirent *ep;
+ char ***names_by_matchlen = talloc_array(tmpmem, char **,
+ strlen(basename) + 1);
+ memset(names_by_matchlen, 0, talloc_get_size(names_by_matchlen));
+ int num_results = 0;
+ while ((ep = readdir(dp))) {
+ int suffix_offset = strlen(ep->d_name) - strlen(suffix);
+ // name must end with suffix
+ if (suffix_offset < 0 || strcmp(ep->d_name + suffix_offset, suffix))
+ continue;
+ // don't list the original name
+ if (!strcmp(ep->d_name, basename))
+ continue;
+
+ char *name = talloc_asprintf(results, "%s/%s", directory, ep->d_name);
+ char *s1 = ep->d_name;
+ char *s2 = basename;
+ int matchlen = 0;
+ while (*s1 && *s1++ == *s2++)
+ matchlen++;
+ int oldcount = talloc_get_size(names_by_matchlen[matchlen]) /
+ sizeof(char **);
+ names_by_matchlen[matchlen] = talloc_realloc(names_by_matchlen,
+ names_by_matchlen[matchlen],
+ char *, oldcount + 1);
+ names_by_matchlen[matchlen][oldcount] = name;
+ num_results++;
+ }
+ closedir(dp);
+ results = talloc_realloc(NULL, results, char *, num_results);
+ char **resptr = results;
+ for (int i = strlen(basename); i >= 0; i--) {
+ char **p = names_by_matchlen[i];
+ for (int j = 0; j < talloc_get_size(p) / sizeof(char *); j++)
+ *resptr++ = p[j];
+ }
+ assert(resptr == results + num_results);
+ talloc_free(tmpmem);
+ *num_results_ptr = num_results;
+ return results;
+}
diff --git a/osdep/findfiles.h b/osdep/findfiles.h
new file mode 100644
index 0000000000..97443e7319
--- /dev/null
+++ b/osdep/findfiles.h
@@ -0,0 +1,2 @@
+char **find_files(const char *original_file, const char *suffix,
+ int *num_results_ptr);
diff --git a/osdep/getch2-os2.c b/osdep/getch2-os2.c
index 272d2d45e9..27ebfaa354 100644
--- a/osdep/getch2-os2.c
+++ b/osdep/getch2-os2.c
@@ -32,6 +32,7 @@
#include "keycodes.h"
#include "input/input.h"
#include "mp_fifo.h"
+#include "getch2.h"
#if defined(HAVE_LANGINFO) && defined(CONFIG_ICONV)
#include <locale.h>
@@ -164,13 +165,13 @@ static int getch2_internal( void )
return -1;
}
-void getch2( void )
+void getch2(struct mp_fifo *fifo)
{
int key;
key = getch2_internal();
if( key != -1 )
- mplayer_put_key( key );
+ mplayer_put_key(fifo, key);
}
void getch2_enable( void )
@@ -197,4 +198,3 @@ char *get_term_charset( void )
return charset;
}
#endif
-
diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c
index 3c428834ff..9dae9cd91d 100644
--- a/osdep/getch2-win.c
+++ b/osdep/getch2-win.c
@@ -30,6 +30,8 @@
#include "keycodes.h"
#include "input/input.h"
#include "mp_fifo.h"
+#include "getch2.h"
+
// HACK, stdin is used as something else below
#undef stdin
@@ -139,11 +141,11 @@ static int getch2_internal(void)
return -1;
}
-void getch2(void)
+void getch2(struct mp_fifo *fifo)
{
int r = getch2_internal();
if (r >= 0)
- mplayer_put_key(r);
+ mplayer_put_key(fifo, r);
}
void getch2_enable(void)
diff --git a/osdep/getch2.c b/osdep/getch2.c
index 4a591da2db..4aa09323eb 100644
--- a/osdep/getch2.c
+++ b/osdep/getch2.c
@@ -58,6 +58,7 @@
#include "mp_fifo.h"
#include "keycodes.h"
+#include "getch2.h"
#ifdef HAVE_TERMIOS
static struct termios tio_orig;
@@ -116,7 +117,7 @@ int load_termcap(char *termtype){
screen_height=tgetnum("li");
if(screen_width<1 || screen_width>255) screen_width=80;
if(screen_height<1 || screen_height>255) screen_height=24;
- erase_to_end_of_line= tgetstr("cd",&term_p);
+ erase_to_end_of_line= tgetstr("ce",&term_p);
termcap_add("kP",KEY_PGUP);
termcap_add("kN",KEY_PGDWN);
@@ -155,7 +156,7 @@ void get_screen_size(void){
#endif
}
-void getch2(void)
+void getch2(struct mp_fifo *fifo)
{
int retval = read(0, &getch2_buf[getch2_len], BUF_LEN-getch2_len);
if (retval < 1)
@@ -264,7 +265,7 @@ void getch2(void)
getch2_len -= len;
for (i = 0; i < getch2_len; i++)
getch2_buf[i] = getch2_buf[len+i];
- mplayer_put_key(code);
+ mplayer_put_key(fifo, code);
}
}
@@ -303,4 +304,3 @@ char* get_term_charset(void)
return charset;
}
#endif
-
diff --git a/osdep/getch2.h b/osdep/getch2.h
index f6f416b2a7..1156aedf7a 100644
--- a/osdep/getch2.h
+++ b/osdep/getch2.h
@@ -42,7 +42,8 @@ void getch2_enable(void);
void getch2_disable(void);
/* Read a character or a special key code (see keycodes.h) */
-void getch2(void);
+struct mp_fifo;
+void getch2(struct mp_fifo *fifo);
/* slave cmd function for Windows and OS/2 */
int mp_input_slave_cmd_func(int fd,char* dest,int size);
diff --git a/osdep/mmap_anon.c b/osdep/mmap_anon.c
index 727761cb6c..d5b3a3dd2f 100644
--- a/osdep/mmap_anon.c
+++ b/osdep/mmap_anon.c
@@ -27,6 +27,8 @@
#include <fcntl.h>
#include <sys/mman.h>
+#include "mmap_anon.h"
+
#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
#define MAP_ANONYMOUS MAP_ANON
#endif
diff --git a/osdep/mplayer.rc b/osdep/mplayer.rc
index 9014d37ca7..7e166b9c6f 100644
--- a/osdep/mplayer.rc
+++ b/osdep/mplayer.rc
@@ -51,4 +51,3 @@ FILETYPE VFT_APP
}
IDI_ICON1 ICON DISCARDABLE "etc/mplayer.ico"
-
diff --git a/osdep/priority.c b/osdep/priority.c
index 7a75153fa0..7a21868ddf 100644
--- a/osdep/priority.c
+++ b/osdep/priority.c
@@ -73,7 +73,7 @@ void set_priority(void)
if (strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
break;
}
- mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_SettingProcessPriority,
+ mp_tmsg(MSGT_CPLAYER, MSGL_STATUS, "Setting process priority: %s\n",
priority_presets_defs[i].name);
#ifdef __OS2__
@@ -86,4 +86,3 @@ void set_priority(void)
#endif
}
}
-
diff --git a/osdep/priority.h b/osdep/priority.h
index cb4bc56c3f..1a74f95665 100644
--- a/osdep/priority.h
+++ b/osdep/priority.h
@@ -28,4 +28,3 @@ extern char *proc_priority;
void set_priority(void);
#endif /* MPLAYER_PRIORITY_H */
-
diff --git a/osdep/shmem.c b/osdep/shmem.c
index 9788d02bc5..f1cec1be37 100644
--- a/osdep/shmem.c
+++ b/osdep/shmem.c
@@ -50,6 +50,8 @@
#include <sys/shm.h>
#endif
+#include "shmem.h"
+
#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
#define MAP_ANON MAP_ANONYMOUS
#endif
diff --git a/osdep/timer-darwin.c b/osdep/timer-darwin.c
index c292852c27..e0b4622c00 100644
--- a/osdep/timer-darwin.c
+++ b/osdep/timer-darwin.c
@@ -27,10 +27,9 @@
#include "timer.h"
/* global variables */
-static double relative_time;
static double timebase_ratio;
-const char *timer_name = "Darwin accurate";
+const char timer_name[] = "Darwin accurate";
@@ -63,19 +62,6 @@ unsigned int GetTimerMS(void)
return (unsigned int)(uint64_t)(mach_absolute_time() * timebase_ratio * 1e3);
}
-/* time spent between now and last call in seconds */
-float GetRelativeTime(void)
-{
- double last_time = relative_time;
-
- if (!relative_time)
- InitTimer();
-
- relative_time = mach_absolute_time() * timebase_ratio;
-
- return (float)(relative_time-last_time);
-}
-
/* initialize timer, must be called at least once at start */
void InitTimer(void)
{
@@ -84,8 +70,6 @@ void InitTimer(void)
mach_timebase_info(&timebase);
timebase_ratio = (double)timebase.numer / (double)timebase.denom
* (double)1e-9;
-
- relative_time = (double)(mach_absolute_time() * timebase_ratio);
}
#if 0
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c
index 8c1af557a0..073ca84182 100644
--- a/osdep/timer-linux.c
+++ b/osdep/timer-linux.c
@@ -27,8 +27,9 @@
#include <time.h>
#include <sys/time.h>
#include "config.h"
+#include "timer.h"
-const char *timer_name =
+const char timer_name[] =
#ifdef HAVE_NANOSLEEP
"nanosleep()";
#else
@@ -50,52 +51,20 @@ int usec_sleep(int usec_delay)
// Returns current time in microseconds
unsigned int GetTimer(void)
{
- struct timeval tv;
- //float s;
- gettimeofday(&tv,NULL);
- //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
- return tv.tv_sec * 1000000 + tv.tv_usec;
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return tv.tv_sec * 1000000 + tv.tv_usec;
}
// Returns current time in milliseconds
unsigned int GetTimerMS(void)
{
- struct timeval tv;
- //float s;
- gettimeofday(&tv,NULL);
- //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
- return tv.tv_sec * 1000 + tv.tv_usec / 1000;
-}
-
-static unsigned int RelativeTime = 0;
-
-// Returns time spent between now and last call in seconds
-float GetRelativeTime(void)
-{
- unsigned int t,r;
- t = GetTimer();
- //t *= 16; printf("time = %ud\n", t);
- r = t - RelativeTime;
- RelativeTime = t;
- return (float) r * 0.000001F;
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
// Initialize timer, must be called at least once at start
void InitTimer(void)
{
- GetRelativeTime();
}
-
-
-#if 0
-#include <stdio.h>
-int main(void)
-{
- float t = 0;
- InitTimer();
- while (1) {
- t += GetRelativeTime();
- printf("time = %10.6f\r", t);
- fflush(stdout); }
-}
-#endif
diff --git a/osdep/timer-win2.c b/osdep/timer-win2.c
index 100a3b6868..ac8eaa1bd6 100644
--- a/osdep/timer-win2.c
+++ b/osdep/timer-win2.c
@@ -22,7 +22,7 @@
#include <mmsystem.h>
#include "timer.h"
-const char *timer_name = "Windows native";
+const char timer_name[] = "Windows native";
// Returns current time in microseconds
unsigned int GetTimer(void)
@@ -45,18 +45,6 @@ int usec_sleep(int usec_delay){
return 0;
}
-static DWORD RelativeTime = 0;
-
-float GetRelativeTime(void)
-{
- DWORD t, r;
- t = GetTimer();
- r = t - RelativeTime;
- RelativeTime = t;
- return (float) r *0.000001F;
-}
-
void InitTimer(void)
{
- GetRelativeTime();
}
diff --git a/osdep/timer.h b/osdep/timer.h
index 2e4f2fc8fe..c3925041ca 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -19,19 +19,12 @@
#ifndef MPLAYER_TIMER_H
#define MPLAYER_TIMER_H
-extern const char *timer_name;
+extern const char timer_name[];
void InitTimer(void);
unsigned int GetTimer(void);
unsigned int GetTimerMS(void);
-//int uGetTimer(void);
-float GetRelativeTime(void);
int usec_sleep(int usec_delay);
-/* timer's callback handling */
-typedef void timer_callback( void );
-unsigned set_timer_callback(unsigned ms,timer_callback func);
-void restore_timer(void);
-
#endif /* MPLAYER_TIMER_H */