Changeset 268


Ignore:
Timestamp:
11/17/02 15:32:42 (21 years ago)
Author:
piso
Message:

Support --time-style=iso and --time-style=long-iso ls options (fixes bug 638385).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/Directory.java

    r157 r268  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: Directory.java,v 1.5 2002-10-17 14:12:36 piso Exp $
     5 * $Id: Directory.java,v 1.6 2002-11-17 15:32:42 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    5757    private int numMarked = 0;
    5858
    59     // The offset on the line where the filename starts.
    60     private int nameOffset = -1;
    61 
    6259    private DirectoryHistory history = new DirectoryHistory();
    6360
    64     static private RE nativeMoveToFilenameRegExp;
    65     static private RE internalMoveToFilenameRegExp;
     61    private static RE nativeMoveToFilenameRegExp;
     62    private static RE internalMoveToFilenameRegExp;
    6663
    6764    private long totalSize;
     
    9794            RESyntax syntax = new RESyntax(RESyntax.RE_SYNTAX_PERL5);
    9895            syntax.set(RESyntax.RE_CHAR_CLASSES);
    99             nativeMoveToFilenameRegExp = new RE("[0-9]+" + s + monthAndDay +
    100                 s + timeOrYear + s, 0, syntax);
     96
     97            String normal = "[0-9]+" + s + monthAndDay + s + timeOrYear + s;
     98
     99            // --time-style=long-iso
     100            // -rw-r--r--    1 peter    peter         147 2002-11-13 13:10 notes
     101            // --time-style=iso
     102            // -rw-r--r--    1 peter    peter       69016 11-16 18:29 Directory.java
     103            // -rw-r--r--    1 peter    peter       13274 2001-09-08  thinbox.tar.gz
     104            String iso = "[0-9]+" + s + "[0-9\\-]+" + s + "(" + HHMM + ")? *";
     105
     106            nativeMoveToFilenameRegExp =
     107                new RE("(" + normal + ")|(" + iso + ")", 0, syntax);
    101108            internalMoveToFilenameRegExp = new RE(":[0-5][0-9]" + s);
    102109        }
    103         catch (REException e) {}
     110        catch (REException e) {
     111            Log.error(e);
     112        }
    104113    }
    105114
     
    578587                else if (sortBy == SORT_BY_SIZE)
    579588                    flags = "-laS";
     589                String extraOptions =
     590                    getStringProperty(Property.LS_EXTRA_OPTIONS);
     591                if (extraOptions != null) {
     592                    flags += " ";
     593                    flags += extraOptions;
     594                    Log.debug("Directory.loadInternal flags = " + flags);
     595                }
    580596                BufferedReader reader = null;
    581597                if (getListing() != null) {
     
    668684            try {
    669685                addEntriesToBuffer();
    670                 setNameOffset(); // We may have changed formats.
    671686                if (totalSize != 0) {
     687                    int end;
     688                    if (usingNativeFormat) {
     689                        end = getFileSizeEndOffset();
     690                        if (end <= 0)
     691                            end = 45;
     692                    } else {
     693                        int nameOffset = getNameOffset();
     694                        end = nameOffset - 19;
     695                        if (end <= 0)
     696                            end = 13;
     697                    }
    672698                    String s = String.valueOf(totalSize);
    673                     int end =
    674                         usingNativeFormat ? nameOffset - 14 : nameOffset - 19;
    675699                    int begin = end - s.length();
     700                    if (begin < 0)
     701                        begin = 0;
    676702                    FastStringBuffer sb =  new FastStringBuffer(80);
    677703                    sb.append(Utilities.spaces(begin));
     
    18511877    {
    18521878        if (line != null) {
    1853             try {
    1854                 REMatch match;
    1855                 if (usingNativeFormat)
    1856                     match = nativeMoveToFilenameRegExp.getMatch(line.getText());
    1857                 else
    1858                     match = internalMoveToFilenameRegExp.getMatch(line.getText());
    1859                 if (match != null)
    1860                     return match.getEndIndex();
    1861             }
    1862             catch (Exception e) {
    1863                 Log.error(e);
    1864             }
     1879            REMatch match;
     1880            if (usingNativeFormat)
     1881                match = nativeMoveToFilenameRegExp.getMatch(line.getText());
     1882            else
     1883                match = internalMoveToFilenameRegExp.getMatch(line.getText());
     1884            if (match != null)
     1885                return match.getEndIndex();
    18651886        }
    18661887        return 0;
    18671888    }
    18681889
    1869     private void setNameOffset()
    1870     {
    1871         nameOffset = 0;
     1890    private int getNameOffset()
     1891    {
     1892        return getNameOffset(getFirstLine());
     1893    }
     1894
     1895    private int getFileSizeEndOffset()
     1896    {
    18721897        Line line = getFirstLine();
    18731898        if (line != null) {
    1874             try {
    1875                 REMatch match;
    1876                 if (usingNativeFormat)
    1877                     match = nativeMoveToFilenameRegExp.getMatch(line.getText());
    1878                 else
    1879                     match = internalMoveToFilenameRegExp.getMatch(line.getText());
    1880                 if (match != null)
    1881                     nameOffset = match.getEndIndex();
    1882             }
    1883             catch (Exception e) {
    1884                 Log.error(e);
    1885             }
    1886         }
     1899            final String text = line.getText();
     1900            REMatch match;
     1901            if (usingNativeFormat)
     1902                match = nativeMoveToFilenameRegExp.getMatch(text);
     1903            else
     1904                match = internalMoveToFilenameRegExp.getMatch(text);
     1905            if (match != null) {
     1906                int start = match.getStartIndex();
     1907                // The file size is followed by a single space.
     1908                return text.indexOf(' ', start);
     1909            }
     1910        }
     1911        return -1; // Error!
    18871912    }
    18881913
Note: See TracChangeset for help on using the changeset viewer.