<commit_before>package org.basex.query.fs;

import static org.basex.Text.*;
import java.io.IOException;
import org.basex.io.PrintOutput;
import org.basex.util.GetOpts;
import org.basex.util.IntList;
import org.basex.util.Token;
import org.basex.util.TokenList;

/**
 * Performs a ls command.
 *
 * @author Workgroup DBIS, University of Konstanz 2005-08, ISC License
 * @author <NAME> - <EMAIL>
 */
public final class LS extends FSCmd {
  /** Also lists sub directories. */
  private boolean fRecursive;
  /** Lists files beginning with . */
  private boolean fListDot;
  /** Prints long version. */
  private boolean fPrintLong;
  /** Prints long version. */
  private boolean fSorted;
  /** Specified path. */
  private String path;

  @Override
  public void args(final String args, final int pos) throws FSException {
    // get all Options
    final GetOpts g = new GetOpts(args, "ahlRs", pos);
    while(g.more()) {
      final int ch = checkOpt(g);
      switch (ch) {
        case 'a':
          fListDot = true;
          break;
        case 'l':
          fPrintLong = true;
          break;
        case 'R':
          fRecursive = true;
          break;
        case 's':
          fSorted = true;
          break;  
      }
    }
    path = g.getPath();
  }

  @Override
  public void exec(final PrintOutput out) throws IOException {
    // if there is path expression set new pre value
    if(path != null) {
      curPre = checkPre(path, FSUtils.goToDir(data, curPre, path));
    }

    // go to work
    if(fRecursive) {
      lsRecursive(curPre, out);
    } else {
      print(FSUtils.getChildren(data, curPre), out);
    }
  }

  /**
   * Recursively lists sub directories encountered.
   *
   * @param pre Value of dir
   * @param out output stream
   * @throws IOException in case of problems with the PrintOutput
   */
  private void lsRecursive(final int pre, final PrintOutput out)
  throws IOException {

    final int[] contentDir = FSUtils.getChildren(data, pre);
    final int[] allDir = print(contentDir, out);

    for(final int dir : allDir) {
      if(!fListDot) {
        // don´t crawl dirs starting with ´.´
        if(Token.startsWith(FSUtils.getName(data, dir), '.')) continue;
      }
      out.print(NL);
      out.print(FSUtils.getPath(data, dir));
      out.print(NL);
      lsRecursive(dir, out);
    }
  }

  /**
   * Prints the result.
   * @param result - array to print
   * @param out output stream
   * @throws IOException in case of problems with the PrintOutput
   * @return list of directories found
   */
  private int[] print(final int[] result, final PrintOutput out)
    throws IOException {

    TokenList b = new TokenList();

    final IntList allDir = new IntList();
    for(final int j : result) {
      if(FSUtils.isDir(data, j)) allDir.add(j);
      final byte[] name = FSUtils.getName(data, j);
      // do not print files starting with .
      if(!fListDot && Token.startsWith(name, '.')) continue;

      if(fSorted)
        b.add(name);

      if(fPrintLong) {
        if(fSorted) error("", 102);
        
        final long size = FSUtils.getSize(data, j);
        final byte[] time = FSUtils.getMtime(data, j);
        final char file = FSUtils.isFile(data, j) ? 'f' : 'd';
        out.println(String.format("%-3s %-30s %10s %20s", file,
            Token.string(name), size, Token.string(time)));
      } else {
        if(!fSorted) {
          out.print(name);
          out.print("\t");
        }
      }
    }
    if(fSorted) {
      b.sort(true);
      for(final byte[] el : b.finish()) {
        out.print(el);
        out.print("\t");
      }
    }
    if(!fPrintLong) out.print(NL);
    return allDir.finish();
  }
}
<commit_msg>minor modification<commit_after>package org.basex.query.fs;

import static org.basex.Text.*;
import java.io.IOException;
import org.basex.io.PrintOutput;
import org.basex.util.GetOpts;
import org.basex.util.IntList;
import org.basex.util.Token;
import org.basex.util.TokenList;

/**
 * Performs a ls command.
 *
 * @author Workgroup DBIS, University of Konstanz 2005-08, ISC License
 * @author <NAME> - <EMAIL>
 */
public final class LS extends FSCmd {
  /** Also lists sub directories. */
  private boolean fRecursive;
  /** Lists files beginning with . */
  private boolean fListDot;
  /** Prints long version. */
  private boolean fPrintLong;
  /** Prints long version. */
  private boolean fSorted;
  /** Specified path. */
  private String path;

  @Override
  public void args(final String args, final int pos) throws FSException {
    // get all Options
    final GetOpts g = new GetOpts(args, "ahlRs", pos);
    while(g.more()) {
      final int ch = checkOpt(g);
      switch (ch) {
        case 'a':
          fListDot = true;
          break;
        case 'l':
          fPrintLong = true;
          break;
        case 'R':
          fRecursive = true;
          break;
        case 's':
          fSorted = true;
          break;  
      }
    }
    path = g.getPath();
  }

  @Override
  public void exec(final PrintOutput out) throws IOException {
    // if there is path expression set new pre value
    if(path != null) {
      curPre = checkPre(path, FSUtils.goToDir(data, curPre, path));
    }

    // go to work
    if(fRecursive) {
      lsRecursive(curPre, out);
    } else {
      print(FSUtils.getChildren(data, curPre), out);
    }
  }

  /**
   * Recursively lists sub directories encountered.
   *
   * @param pre Value of dir
   * @param out output stream
   * @throws IOException in case of problems with the PrintOutput
   */
  private void lsRecursive(final int pre, final PrintOutput out)
  throws IOException {

    final int[] contentDir = FSUtils.getChildren(data, pre);
    final int[] allDir = print(contentDir, out);

    for(final int dir : allDir) {
      if(!fListDot) {
        // don´t crawl dirs starting with ´.´
        if(Token.startsWith(FSUtils.getName(data, dir), '.')) continue;
      }
      out.print(NL);
      out.print(FSUtils.getPath(data, dir));
      out.print(NL);
      lsRecursive(dir, out);
    }
  }

  /**
   * Prints the result.
   * @param result - array to print
   * @param out output stream
   * @throws IOException in case of problems with the PrintOutput
   * @return list of directories found
   */
  private int[] print(final int[] result, final PrintOutput out)
    throws IOException {

    TokenList b = new TokenList();

    final IntList allDir = new IntList();
    for(final int j : result) {
      if(FSUtils.isDir(data, j)) allDir.add(j);
      final byte[] name = FSUtils.getName(data, j);
      // do not print files starting with .
      if(!fListDot && Token.startsWith(name, '.')) continue;

      if(fSorted)
        b.add(name);

      if(fPrintLong) {
        if(fSorted) error("", 102);
        
        final long size = FSUtils.getSize(data, j);
        final byte[] time = FSUtils.getMtime(data, j);
        final char file = FSUtils.isFile(data, j) ? 'f' : 'd';
        out.println(String.format("%-3s %-30s %10s %20s", file,
            Token.string(name), size, Token.string(time)));
      } else {
        if(!fSorted) {
          out.print(name);
          out.print("\t");
        }
      }
    }
    if(fSorted) {
      b.sort(false);
      for(final byte[] el : b.finish()) {
        out.print(el);
        out.print("\t");
      }
    }
    if(!fPrintLong) out.print(NL);
    return allDir.finish();
  }
}

{'fraction_non_alphanumeric': 0.12898003237992445, 'fraction_numerical': 0.004317323259579061, 'mean_word_length': 2.312332439678284, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2738274', 'n_tokens_mistral': 2443, 'n_tokens_neox': 2413, 'n_words': 661}