* Fixed bug in "fortune" that would let it crash if you'd point it to an empty

directory.
* Moved fortune files to "data/system/data" in the repository, and /system/data/
  in the file system.
* Got teapot.data location wrong in the repository.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33982 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-11-10 13:09:32 +00:00
parent 0491552bc3
commit c6106a595d
27 changed files with 15 additions and 13 deletions
+5 -8
View File
@@ -403,16 +403,13 @@ AddFilesToHaikuImage system etc vim : <etc>vimrc ;
local dataFiles = teapot.data ; local dataFiles = teapot.data ;
dataFiles = $(dataFiles:G=data) ; dataFiles = $(dataFiles:G=data) ;
SEARCH on $(dataFiles) = [ FDirName $(HAIKU_TOP) data ] ; SEARCH on $(dataFiles) = [ FDirName $(HAIKU_TOP) data system data ] ;
AddFilesToHaikuImage system data : $(dataFiles) ; AddFilesToHaikuImage system data : $(dataFiles) ;
local fortuneFiles = Art Computers Education Food Fortunes Goedel Haiku local fortuneFiles = [ Glob $(HAIKU_TOP)/data/system/data/fortunes
Humorists Kids Law "Linux cookies" Love Magic Medicine Miscellaneous : [a-zA-Z0-9]* ] ;
News "One Liners" "OS Fortunes" Pets Platitudes Riddles "Songs & Poems" fortuneFiles = $(fortuneFiles:G=data!fortunes) ;
Sports "Tech Support Excuses" ; AddFilesToHaikuImage system data fortunes : $(fortuneFiles) ;
fortuneFiles = $(fortuneFiles:G=etc!fortunes) ;
SEARCH on $(fortuneFiles) = [ FDirName $(HAIKU_TOP) data etc fortunes ] ;
AddFilesToHaikuImage system etc fortunes : $(fortuneFiles) ;
local fontDir = [ FDirName $(HAIKU_TOP) data system data fonts ] ; local fontDir = [ FDirName $(HAIKU_TOP) data system data fonts ] ;
local psFonts = [ Glob $(fontDir)/psfonts : *.afm *.pfb ] ; local psFonts = [ Glob $(fontDir)/psfonts : *.afm *.pfb ] ;
+10 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008, Haiku. All rights reserved. * Copyright 2002-2009, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -13,12 +13,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <FindDirectory.h>
#include <OS.h> #include <OS.h>
#define FORTUNES "/etc/fortunes"
static int static int
choose_file(const char *path) choose_file(const char *path)
{ {
@@ -39,6 +37,9 @@ choose_file(const char *path)
count++; count++;
} }
if (count == 0)
return -1;
// choose and open entry // choose and open entry
chosen = rand() % count; chosen = rand() % count;
@@ -75,7 +76,8 @@ choose_file(const char *path)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *file = FORTUNES; char path[PATH_MAX] = {'\0'};
const char *file = path;
int fd; int fd;
char *buffer; char *buffer;
unsigned start, i; unsigned start, i;
@@ -87,6 +89,9 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
// if there are arguments, choose one randomly // if there are arguments, choose one randomly
file = argv[1 + (rand() % (argc - 1))]; file = argv[1 + (rand() % (argc - 1))];
} else if (find_directory(B_SYSTEM_DATA_DIRECTORY, -1, false, path,
sizeof(path)) == B_OK) {
strlcat(path, "/fortunes", sizeof(path));
} }
fd = open(file, O_RDONLY, 0); fd = open(file, O_RDONLY, 0);