Changeset 67:108d123238c0

Show
Ignore:
Timestamp:
07/03/08 07:40:31 (6 months ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
branch:
default
Message:

Changes to work with tango r3700 (post 0.99.6).

Changes to logging.
Replaced many uses of PathView? with FilePath?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mde/font/font.d

    r64 r67  
    6868            FT_Int maj, min, patch; 
    6969            FT_Library_Version (library, &maj, &min, &patch); 
    70             if (maj != 2 || min != 3) { 
    71                 char[128] tmp; 
    72                 logger.warn (logger.format (tmp, "Using an untested FreeType version: {}.{}.{}", maj, min, patch)); 
    73             } 
     70            if (maj != 2 || min != 3) 
     71                logger.warn ("Using an untested FreeType version: {}.{}.{}", maj, min, patch); 
    7472             
    7573            // Set LCD filtering method if LCD rendering is enabled. 
  • mde/gl/draw.d

    r63 r67  
    4343    GLenum err = glGetError(); 
    4444    while (err != GL_NO_ERROR) { 
    45         char[128] tmp; 
    46         logger.error (logger.format (tmp, "GL error: {}", err)); 
     45        logger.error ("GL error: {}", err); 
    4746        err = glGetError(); 
    4847    } 
  • mde/input/Config.d

    r63 r67  
    169169         
    170170        debug (MDE_CONFIG_DUMP) { 
    171             char tmp[128] = void; 
    172             logger.trace (logger.format (tmp, "Loaded {} config sections.", configs.length)); 
     171            logger.trace ("Loaded {} config sections.", configs.length); 
    173172            foreach (id, cfg; configs) { 
    174173                logger.trace ("Section " ~ id ~ 
  • mde/input/joystick.d

    r31 r67  
    3838void openJoysticks () { 
    3939    joysticks = new SDL_Joystick*[SDL_NumJoysticks ()]; 
    40     char tmp[128] = void; 
    4140     
    4241    for (int i = 0; i < joysticks.length; ++i) { 
    4342        if ((joysticks[i] = SDL_JoystickOpen (i)) is null) {    // null on failure 
    44             logger.error (logger.format (tmp, "Unable to open joystick {} via SDL", i)); 
     43            logger.error ("Unable to open joystick {} via SDL", i); 
    4544        } 
    4645    } 
    4746     
    48     logger.info (logger.format (tmp, "Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length)); 
     47    logger.info ("Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length); 
    4948} 
    5049 
  • mde/lookup/Options.d

    r64 r67  
    136136        */ 
    137137        private const fileName = "options"; 
    138         private const MT_LOAD_EXC = "Loading options aborted:"; 
    139138        void load () { 
    140139        // Check it exists (if not it should still be created on exit). 
     
    153152                reader.read; 
    154153            } catch (MTException e) { 
    155                 logger.fatal (MT_LOAD_EXC); 
     154                logger.fatal ("Loading options aborted:"); 
    156155                logger.fatal (e.msg); 
    157156                throw new optionsLoadException ("Mergetag exception (see above message)"); 
     
    177176            } catch (MTException e) { 
    178177                // Log a message and continue, overwriting the file: 
    179                 logger.error (MT_LOAD_EXC); 
     178                logger.error ("Loading options aborted:"); 
    180179                logger.error (e.msg); 
    181180            } 
  • mde/mergetag/Reader.d

    r47 r67  
    2929 
    3030// tango imports 
     31import tango.io.FilePath; 
    3132import tango.io.UnicodeFile; 
    3233import Util = tango.text.Util; 
    3334import ConvInt = tango.text.convert.Integer; 
    34 import tango.util.collection.model.View : View; 
     35//import tango.util.collection.model.View : View; 
    3536import tango.util.collection.HashSet : HashSet; 
    3637import tango.util.log.Log : Log, Logger; 
     
    5455* 
    5556*/ 
    56 IReader makeReader (PathView path, DataSet ds = null, bool rdHeader = false) { 
     57IReader makeReader (FilePath path, DataSet ds = null, bool rdHeader = false) { 
    5758    if      (path.ext == "mtb") return new MTBReader (path, ds, rdHeader); 
    5859    else if (path.ext == "mtt") return new MTTReader (path, ds, rdHeader); 
     
    6465 * Tries adding both ".mtt" and ".mtb" extensions, returning whichever exists (the most recently 
    6566 * modified if both exist), or returns null if neither exist. */ 
    66 PathView findFile (char[] path) { 
     67FilePath findFile (char[] path) { 
    6768    if (path is null) return null; 
    6869     
     
    214215    } 
    215216    /** ditto */ 
    216     public this (PathView path, DataSet ds = null, bool rdHeader = false) { 
     217    public this (FilePath path, DataSet ds = null, bool rdHeader = false) { 
    217218        // Create a dataset or use an existing one 
    218219        if (ds !is null) _dataset = ds; 
  • mde/mergetag/Writer.d

    r26 r67  
    9191 *  MTFileFormatException if unable to determine writing format or use requested format. 
    9292 */ 
    93 IWriter makeWriter (char[] path, DataSet dataset = null, WriterMethod method = WriterMethod.FromExtension) { 
     93//FIXME: separate functions for separate functionality, like in Reader? 
     94IWriter makeWriter (char[] path, DataSet dataset = null, 
     95                    WriterMethod method = WriterMethod.FromExtension) { 
    9496    if (method == WriterMethod.FromExtension) { 
    95         PathView fpath = new FilePath (path); 
    96          
    97         if (fpath.ext == "mtt") return new MTTWriter (fpath, dataset); 
    98         else if (fpath.ext == "mtb") return new MTBWriter (fpath, dataset); 
     97        if (path.length > 4 && path[$-4..$] == ".mtt") 
     98            return new MTTWriter (path, dataset); 
     99        else if (path.length > 4 && path[$-4..$] == ".mtb") 
     100            return new MTBWriter (path, dataset); 
    99101        else { 
    100102            logger.error ("Unable to determine writing format: text or binary"); 
     
    144146    DataSet _dataset; 
    145147     
    146     PathView _path; 
     148    char[] _path; 
    147149//END DATA 
    148150     
     
    153155    * 
    154156    * Params: 
    155     * path = The name or FilePath of the file to open. 
     157    * path = The name of the file to open. 
    156158    *     Standard extensions are .mtt and .mtb for text and binary files respectively. 
    157159    * dataset_ = If null create a new DataSet, else use existing DataSet *dataset_ and merge read 
     
    159161    */ 
    160162    public this (char[] path, DataSet ds = null) { 
    161         this (new FilePath (path), ds); 
    162     } 
    163     /** ditto */ 
    164     public this (PathView path, DataSet ds = null) { 
    165163        _path = path; 
    166164        _dataset = ds; 
     
    236234class MTBWriter : IWriter { 
    237235    public this (char[] path, DataSet ds = null) { 
    238         this (new FilePath (path), ds); 
    239     } 
    240     public this (PathView path, DataSet ds = null) { 
    241236        throw new MTNotImplementedException; 
    242237         
  • mde/setup/Init.d

    r64 r67  
    3838import TimeStamp = tango.text.convert.TimeStamp, tango.time.WallClock;  // output date in log file 
    3939import tango.util.Arguments; 
    40 import tango.util.log.Log : Log, Logger; 
    41 import tango.util.log.ConsoleAppender : ConsoleAppender; 
    42  
    43 //version = SwitchAppender; 
    44 version (SwitchAppender) {  // My own variation, currently just a test 
    45     import tango.util.log.SwitchingFileAppender : SwitchingFileAppender; 
    46 } else { 
    47     import tango.util.log.RollingFileAppender : RollingFileAppender; 
    48 
     40import tango.util.log.Log : Log, Logger, Level; 
     41import tango.util.log.AppendConsole; 
     42import tango.util.log.AppendFiles; 
    4943 
    5044// Derelict imports 
     
    6357static this() 
    6458{ 
    65     Logger root = Log.getRootLogger()
     59    Logger root = Log.root
    6660    // Set the level here, but set it again once options have been loaded: 
    67     debug root.setLevel(root.Level.Trace); 
    68     else root.setLevel(root.Level.Info); 
     61    debug root.level(Logger.Trace); 
     62    else root.level(Logger.Info); 
    6963    // Temporarily log to the console (until we've found paths and loaded options): 
    70     root.addAppender(new ConsoleAppender); 
     64    root.add(new AppendConsole); 
    7165} 
    7266static ~this() 
     
    168162             
    169163        // Where logging is done to is determined at compile-time, currently just via static ifs. 
    170             root = Log.getRootLogger()
    171         root.clearAppenders;  // we may no longer want to log to the console 
     164            root = Log.root
     165        root.clear;           // we may no longer want to log to the console 
    172166         
    173167            // Now re-set the logging level, using the value from the config file: 
    174             root.setLevel (cast(Log.Level) (miscOpts.logOptions & LOG.LEVEL), true); 
     168            root.level (cast(Level) (miscOpts.logOptions & LOG.LEVEL), true); 
    175169             
    176170            // Log to a file (first appender so root seperator messages don't show on console): 
    177171            if (miscOpts.logOptions & LOG.ROLLFILE) { 
    178                 version (SwitchAppender) { 
    179                     root.addAppender (new SwitchingFileAppender (paths.logDir~"/log-.txt", 5)); 
    180                 } else { 
    181172                // Use 2 log files with a maximum size of 1 MB: 
    182                     root.addAppender (new RollingFileAppender (paths.logDir~"/log-.txt", 2, 1024*1024)); 
    183                     root.info (""); // some kind of separation between runs 
    184                     root.info (""); 
    185                 } 
     173                root.add (new AppendFiles (paths.logDir~"/log-.txt", 2, 1024*1024)); 
     174                root.info (""); // some kind of separation between runs 
     175                root.info (""); 
    186176            } else if (!(miscOpts.logOptions & LOG.CONSOLE)) { 
    187177                // make sure at least one logger is enabled 
     
    189179            } 
    190180            if (miscOpts.logOptions & LOG.CONSOLE) {    // Log to the console 
    191                 root.addAppender(new ConsoleAppender); 
     181                root.add(new AppendConsole); 
    192182            } 
    193183            logger.info ("Starting mde [no version] on " ~ TimeStamp.toString(WallClock.now)); 
     
    195185            // Presumably it was only adding a file appender which failed; set up a new console 
    196186            // logger and if that fails let the exception kill the program. 
    197             root.clearAppenders
    198             root.addAppender (new ConsoleAppender); 
     187            root.clear
     188            root.add (new AppendConsole); 
    199189            logger.warn ("Exception while setting up the logger; logging to the console instead."); 
    200190        } 
  • mde/setup/paths.d

    r63 r67  
    2727*/ 
    2828/* Implementation note: 
    29 * All paths are stored internally as strings, rather than as an instance of FilePath/PathView once 
     29* All paths are stored internally as strings, rather than as an instance of FilePath/FilePath once 
    3030* the FilePath has served its immediate purpose, since it's more convenient and creating new 
    3131* FilePaths for adjusted paths should be no slower than mutating existing ones. */ 
     
    7272    IReader makeMTReader (char[] file, PRIORITY readOrder, DataSet ds = null, bool rdHeader = false) 
    7373    { 
    74         PathView[] files = getFiles (file, readOrder); 
     74        FilePath[] files = getFiles (file, readOrder); 
    7575        if (files is null) 
    7676            throw new MTFileIOException ("Unable to find the file: "~file~"[.mtt|mtb]"); 
     
    9696    char[] getFileName (char[] file, PRIORITY readOrder) 
    9797    { 
    98         PathView[] files = getFiles (file, readOrder); 
     98        FilePath[] files = getFiles (file, readOrder); 
    9999        if (files is null) 
    100100            return "no file found"; 
     
    125125     
    126126private: 
    127     PathView[] getFiles (char[] filename, PRIORITY readOrder) 
     127    FilePath[] getFiles (char[] filename, PRIORITY readOrder) 
    128128    in { 
    129129        assert (readOrder == PRIORITY.LOW_HIGH || 
     
    131131                readOrder == PRIORITY.HIGH_ONLY ); 
    132132    } body { 
    133         PathView[] ret; 
     133        FilePath[] ret; 
    134134        if (readOrder == PRIORITY.LOW_HIGH) { 
    135135            for (size_t i = 0; i < pathsLen; ++i) { 
    136                 PathView file = findFile (paths[i]~filename); 
     136                FilePath file = findFile (paths[i]~filename); 
    137137                if (file !is null) 
    138138                    ret ~= file; 
     
    140140        } else { 
    141141            for (int i = pathsLen - 1; i >= 0; --i) { 
    142                 PathView file = findFile (paths[i]~filename); 
     142                FilePath file = findFile (paths[i]~filename); 
    143143                if (file !is null) { 
    144144                    ret ~= file; 
     
    209209        // Base paths: 
    210210        // Static data (must exist): 
    211         PathView staticPath = 
     211        FilePath staticPath = 
    212212                findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data"); 
    213213        // Config (can just use defaults if necessary, so long as we can save afterwards): 
    214         PathView userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); 
     214        FilePath userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); 
    215215         
    216216        // Static data paths: 
     
    237237         
    238238        // Base paths: 
    239         PathView installPath = findPath (false, base); 
    240         PathView staticPath = findPath (false, installPath.append("data").toString); 
    241         PathView userPath = findPath (true, installPath.append("user").toString);   // FIXME: see above 
     239        FilePath installPath = findPath (false, base); 
     240        FilePath staticPath = findPath (false, installPath.append("data").toString); 
     241        FilePath userPath = findPath (true, installPath.append("user").toString);   // FIXME: see above 
    242242         
    243243        // Static data paths: 
     
    278278     * If none are valid and create is true, will try creating each in turn. 
    279279     * If still none are valid, throws. */ 
    280     PathView findPath (bool create, char[][] paths ...) { 
     280    FilePath findPath (bool create, char[][] paths ...) { 
    281281        FilePath[] fps; 
    282282        fps.length = paths.length; 
     
    306306    class mdeReader : IReader 
    307307    { 
    308         private this (PathView[] files, DataSet ds, bool rdHeader) 
     308        private this (FilePath[] files, DataSet ds, bool rdHeader) 
    309309        in { 
    310310            assert (files !is null, "mdeReader.this: files is null"); 
  • mde/setup/sdl.d

    r64 r67  
    9494        // Print a load of info: 
    9595        logger.info ("Available video modes:"); 
    96         char[128] tmp; 
    9796        SDL_Rect** modes = SDL_ListModes (null, SDL_FULLSCREEN); 
    9897        if (modes is null) logger.info ("None!"); 
     
    10099        else { 
    101100            for (uint i = 0; modes[i] !is null; ++i) { 
    102                 logger.info (logger.format (tmp, "\t{}x{}", modes[i].w, modes[i].h)); 
     101                logger.info ("\t{}x{}", modes[i].w, modes[i].h); 
    103102            } 
    104103        } 
     
    108107            logger.info ("Video info:"); 
    109108            logger.info ("Hardware surface support: "~ (vi.flags & SDL_HWSURFACE ? "yes" : "no")); 
    110             logger.info (logger.format (tmp, "Video memory: {}", vi.video_mem)); 
     109            logger.info ("Video memory: {}", vi.video_mem); 
    111110     
    112111            if (vi.vfmt !is null) { 
    113112                logger.info ("Best video mode:"); 
    114                 logger.info (logger.format (tmp, "Bits per pixel: {}", vi.vfmt.BitsPerPixel)); 
     113                logger.info ("Bits per pixel: {}", vi.vfmt.BitsPerPixel); 
    115114            } 
    116115        } 
  • util/mtcp.d

    r47 r67  
    3030 
    3131// Logger, used by mergetag: 
    32 import tango.util.log.Log : Log, Logger; 
    33 import tango.util.log.ConsoleAppender : ConsoleAppender; 
    34 static this() { 
    35     Logger root = Log.getRootLogger(); 
    36     root.addAppender(new ConsoleAppender); 
    37 
     32import tango.util.log.Config; 
    3833 
    3934int main (char[][] args)