HaikuPorts
  • Login
  • Preferences
  • Help/Guide
  • Wiki
  • Timeline
  • Roadmap
  • View Tickets
  • Search
  • Port Log
  • Blog

Context Navigation

  • ← Previous Change
  • Wiki History
  • Next Change →

Changes between Initial Version and Version 1 of FindDirectory


Ignore:
Timestamp:
12/04/09 07:06:26 (6 years ago)
Author:
mmadia
Comment:

copied content from SandBox

Legend:

Unmodified
Added
Removed
Modified
  • FindDirectory

    v1 v1  
     1= Finding a Directory's Path = 
     2When referencing paths, it is best to use Haiku's Find Directory functionality. The system defines numerous key directories in the [http://dev.haiku-os.org/browser/haiku/trunk/headers/os/storage/FindDirectory.h os/storage/FindDirectory.h] header. In addition to C/C++, a command line utility `finddir` can be used with the same variable names. 
     3 
     4== Terminal == 
     5{{{ 
     6export USER_SETTINGS_DIRECTORY=`/bin/finddir B_USER_SETTINGS_DIRECTORY` 
     7}}} 
     8To test this, try {{{ finddir B_USER_SETTINGS_DIRECTORY }}} 
     9 
     10== Shell Script == 
     11{{{ 
     12APPS_DIR=`finddir B_APPS_DIRECTORY` 
     13echo ${APPS_DIR} 
     14}}} 
     15 
     16== Makefile == 
     17# Assuming the makefile sets  
     18{{{ 
     19APPS_DIR:=$(shell finddir B_APPS_DIRECTORY) 
     20}}} 
     21 
     22== C == 
     23{{{ 
     24#!rst 
     25diff -urN tuxpaint-0.9.21/src/fonts.c tuxpaint-0.9.21-haiku/src/fonts.c 
     26--- tuxpaint-0.9.21/src/fonts.c 2009-06-06 18:22:00.000000000 +0000 
     27+++ tuxpaint-0.9.21-haiku/src/fonts.c   2009-10-07 07:39:18.000000000 +0000 
     28@@ -67,6 +67,11 @@ 
     29 #include "win32_print.h" 
     30 #endif 
     31  
     32+#ifdef __HAIKU__ 
     33+#include <FindDirectory.h> 
     34+#include <fs_info.h> 
     35+#endif 
     36+ 
     37 #ifdef __APPLE__ 
     38 #include "wrapperdata.h" 
     39 extern WrapperData macosx; 
     40@@ -699,6 +704,14 @@ 
     41     loadfonts(screen, "/boot/home/config/font/ttffonts"); 
     42     loadfonts(screen, "/usr/share/fonts"); 
     43     loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); 
     44+#elif defined(__HAIKU__) 
     45+       dev_t volume = dev_for_path("/boot"); 
     46+       char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; 
     47+       status_t result; 
     48+    result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); 
     49+       loadfonts(screen, buffer); 
     50+    result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); 
     51+       loadfonts(screen, buffer); 
     52 #elif defined(__APPLE__) 
     53     loadfonts(screen, "/System/Library/Fonts"); 
     54     loadfonts(screen, "/Library/Fonts"); 
     55}}} 
     56 
     57== C++ == 
     58{{{ 
     59#!cpp 
     60// Note: This is untested! 
     61 
     62#ifdef __HAIKU__ 
     63#include <FindDirectory.h> 
     64#include <fs_info.h> 
     65#endif 
     66         
     67// ... 
     68 
     69BPath dir; 
     70result = find_directory(B_SYSTEM_FONTS_DIRECTORY, &dir); 
     71loadfonts(screen, dir.Path()); 
     72result = find_directory(B_COMMON_FONTS_DIRECTORY, &dir); 
     73loadfonts(screen, dir.Path()); 
     74}}} 
     75 
     76== Python ==  
     77{{{ 
     78#!python 
     79#!/bin/env python 
     80 
     81import commands 
     82 
     83# Creating a utility function 
     84def FindDirectory(aDir): 
     85        result = commands.getoutput('finddir %s' % aDir) 
     86        return result 
     87         
     88 
     89if __name__ == "__main__": 
     90        # Using the utility function ... 
     91        B_APPS_DIRECTORY = FindDirectory('B_APPS_DIRECTORY') 
     92        print 'Using utility function:' 
     93        print B_APPS_DIRECTORY 
     94 
     95        # Set a baloney value, to display functionality 
     96        B_APPS_DIRECTORY='Some Text to display the value being set properly' 
     97        print 'After setting a baloney value:' 
     98        print B_APPS_DIRECTORY 
     99  
     100        # As a one liner ... 
     101        B_APPS_DIRECTORY = commands.getoutput('finddir B_APPS_DIRECTORY') 
     102        print 'Using a one liner:' 
     103        print B_APPS_DIRECTORY 
     104}}} 

Trac Powered

Powered by Trac 0.13dev-r10686
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/