commit a543eed112b4167c410a2fb75d672df9df926a1a
parent 4384f09726a3178ee6c9c38d0c357068d66140a2
Author: lostd <lostd@2f30.org>
Date: Tue, 7 Oct 2014 14:32:03 +0000
Simplify associations and handle README files
Diffstat:
M | noice.c | | | 55 | +++++++++++++++++++++++-------------------------------- |
1 file changed, 23 insertions(+), 32 deletions(-)
diff --git a/noice.c b/noice.c
@@ -50,36 +50,34 @@ struct assoc {
char *ext; /* Extension */
char *bin; /* Program */
} assocs[] = {
- { "avi", "mplayer" },
- { "mp4", "mplayer" },
- { "mkv", "mplayer" },
- { "mp3", "mplayer" },
- { "ogg", "mplayer" },
- { "srt", "less" },
- { "txt", "less" },
+ { ".avi", "mplayer" },
+ { ".mp4", "mplayer" },
+ { ".mkv", "mplayer" },
+ { ".mp3", "mplayer" },
+ { ".ogg", "mplayer" },
+ { ".srt", "less" },
+ { ".txt", "less" },
+ { "README", "less" },
};
char *
-extension(char *file)
-{
- char *dot;
-
- dot = strrchr(file, '.');
- if (dot == NULL || dot == file)
- return NULL;
- else
- return dot + 1;
-}
-
-char *
-openwith(char *ext)
+openwith(char *file)
{
+ char *ext = NULL;
+ char *bin = NULL;
int i;
+ ext = strrchr(file, '.');
+ if (ext == NULL)
+ ext = file;
+ DPRINTF_S(ext);
+
for (i = 0; i < LEN(assocs); i++)
- if (strncmp(assocs[i].ext, ext, strlen(ext)) == 0)
- return assocs[i].bin;
- return NULL;
+ if (strncmp(assocs[i].ext, ext, strlen(ext) + 1) == 0)
+ bin = assocs[i].bin;
+ DPRINTF_S(bin);
+
+ return bin;
}
int
@@ -327,7 +325,7 @@ nochange:
if (ret == 3) {
char *name, *file = NULL;
char *newpath;
- char *ext, *bin;
+ char *bin;
pid_t pid;
/* Cannot descend in empty directories */
@@ -357,18 +355,11 @@ nochange:
DPRINTF_S(file);
/* Open with */
- ext = extension(name);
- if (ext == NULL) {
- printwarn("invalid extension\n");
- goto nochange;
- }
- bin = openwith(ext);
+ bin = openwith(name);
if (bin == NULL) {
printwarn("no association\n");
goto nochange;
}
- DPRINTF_S(ext);
- DPRINTF_S(bin);
exitcurses();