ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs FixCRLF.java
Date Sun, 13 Feb 2000 21:44:01 GMT
rubys       00/02/13 13:44:01

  Modified:    src/main/org/apache/tools/ant/taskdefs FixCRLF.java
  Log:
  remove debugging code
  
  Revision  Changes    Path
  1.4       +116 -121  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FixCRLF.java	2000/02/13 18:20:00	1.3
  +++ FixCRLF.java	2000/02/13 21:44:00	1.4
  @@ -232,136 +232,131 @@
           DirectoryScanner ds = super.getDirectoryScanner(srcDir);
           String[] files = ds.getIncludedFiles();
   
  -        try {
  -            for (int i = 0; i < files.length; i++) {
  -                File srcFile = new File(srcDir, files[i]);
  -
  -                // read the contents of the file
  -                int count = (int)srcFile.length();
  -                byte indata[] = new byte[count];
  -                try {
  -                    FileInputStream inStream = new FileInputStream(srcFile);
  -                    inStream.read(indata);
  -                    inStream.close();
  -                } catch (IOException e) {
  -                    throw new BuildException(e);
  -                }
  -
  -                // count the number of cr, lf,  and tab characters
  -                int cr = 0;
  -                int lf = 0;
  -                int tab = 0;
  -
  -                for (int k=0; k<count; k++) {
  -                    byte c = indata[k];
  -                    if (c == '\r') cr++;
  -                    if (c == '\n') lf++;
  -                    if (c == '\t') tab++;
  -                }
  +        for (int i = 0; i < files.length; i++) {
  +            File srcFile = new File(srcDir, files[i]);
   
  -                // check for trailing eof
  -                boolean eof = ((count>0) && (indata[count-1] == 0x1A));
  -
  -                // log stats (before fixes)
  -                project.log(srcFile + ": size=" + count + " cr=" + cr +
  -                            " lf=" + lf + " tab=" + tab + " eof=" + eof,
  -                            "fixcrlf", project.MSG_VERBOSE);
  -
  -                // determine the output buffer size (slightly pessimisticly)
  -                int outsize = count;
  -                if (addcr  !=  0) outsize-=cr;
  -                if (addcr  == +1) outsize+=lf;
  -                if (addtab == -1) outsize+=tab*7;
  -                if (ctrlz  == +1) outsize+=1;
  -
  -                // copy the data
  -                byte outdata[] = new byte[outsize];
  -                int o = 0;    // output offset
  -                int line = o; // beginning of line
  -                int col = 0;  // desired column
  -
  -                for (int k=0; k<count; k++) {
  -                    switch (indata[k]) {
  -                        case ' ':
  -                            // advance column
  -                            if (addtab == 0) outdata[o++]=(byte)' ';
  +            // read the contents of the file
  +            int count = (int)srcFile.length();
  +            byte indata[] = new byte[count];
  +            try {
  +                FileInputStream inStream = new FileInputStream(srcFile);
  +                inStream.read(indata);
  +                inStream.close();
  +            } catch (IOException e) {
  +                throw new BuildException(e);
  +            }
  +
  +            // count the number of cr, lf,  and tab characters
  +            int cr = 0;
  +            int lf = 0;
  +            int tab = 0;
  +
  +            for (int k=0; k<count; k++) {
  +                byte c = indata[k];
  +                if (c == '\r') cr++;
  +                if (c == '\n') lf++;
  +                if (c == '\t') tab++;
  +            }
  +
  +            // check for trailing eof
  +            boolean eof = ((count>0) && (indata[count-1] == 0x1A));
  +
  +            // log stats (before fixes)
  +            project.log(srcFile + ": size=" + count + " cr=" + cr +
  +                        " lf=" + lf + " tab=" + tab + " eof=" + eof,
  +                        "fixcrlf", project.MSG_VERBOSE);
  +
  +            // determine the output buffer size (slightly pessimisticly)
  +            int outsize = count;
  +            if (addcr  !=  0) outsize-=cr;
  +            if (addcr  == +1) outsize+=lf;
  +            if (addtab == -1) outsize+=tab*7;
  +            if (ctrlz  == +1) outsize+=1;
  +
  +            // copy the data
  +            byte outdata[] = new byte[outsize];
  +            int o = 0;    // output offset
  +            int line = o; // beginning of line
  +            int col = 0;  // desired column
  +
  +            for (int k=0; k<count; k++) {
  +                switch (indata[k]) {
  +                    case ' ':
  +                        // advance column
  +                        if (addtab == 0) outdata[o++]=(byte)' ';
  +                        col++;
  +                        break;
  +
  +                    case '\t':
  +                        if (addtab == 0) {
  +                            // treat like any other character
  +                            outdata[o++]=(byte)'\t';
  +                            col++;
  +                        } else {
  +                            // advance column to next tab stop
  +                            col = (col|7)+1;
  +                        }
  +                        break;
  +
  +                    case '\r':
  +                        if (addcr == 0) {
  +                            // treat like any other character
  +                            outdata[o++]=(byte)'\r';
                               col++;
  -                            break;
  +                        }
  +                        break;
   
  -                        case '\t':
  -                            if (addtab == 0) {
  -                                // treat like any other character
  +                    case '\n':
  +                        // start a new line (optional CR followed by LF)
  +                        if (addcr == +1) outdata[o++]=(byte)'\r';
  +                        outdata[o++]=(byte)'\n';
  +                        line=o;
  +                        col=0;
  +                        break;
  +
  +                    default:
  +                        // add tabs if two or more spaces are required
  +                        if (addtab>0 && o+1<line+col) {
  +                            // determine logical column
  +                            int diff=o-line;
  +
  +                            // add tabs until this column would be passed
  +                            // note: the start of line is adjusted to match
  +                            while ((diff|7)<col) {
                                   outdata[o++]=(byte)'\t';
  -                                col++;
  -                            } else {
  -                                // advance column to next tab stop
  -                                col = (col|7)+1;
  -                            }
  -                            break;
  -
  -                        case '\r':
  -                            if (addcr == 0) {
  -                                // treat like any other character
  -                                outdata[o++]=(byte)'\r';
  -                                col++;
  -                            }
  -                            break;
  -
  -                        case '\n':
  -                            // start a new line (optional CR followed by LF)
  -                            if (addcr == +1) outdata[o++]=(byte)'\r';
  -                            outdata[o++]=(byte)'\n';
  -                            line=o;
  -                            col=0;
  -                            break;
  -
  -                        default:
  -                            // add tabs if two or more spaces are required
  -                            if (addtab>0 && o+1<line+col) {
  -                                // determine logical column
  -                                int diff=o-line;
  -
  -                                // add tabs until this column would be passed
  -                                // note: the start of line is adjusted to match
  -                                while ((diff|7)<col) {
  -                                    outdata[o++]=(byte)'\t';
  -                                    line-=7-(diff&7);
  -                                    diff=o-line;
  -                                };
  +                                line-=7-(diff&7);
  +                                diff=o-line;
                               };
  +                        };
   
  -                            // space out to desired column
  -                            while (o<line+col) outdata[o++]=(byte)' ';
  +                        // space out to desired column
  +                        while (o<line+col) outdata[o++]=(byte)' ';
   
  -                            // append desired character
  -                            outdata[o++]=indata[k];
  -                            col++;
  -                    }
  -                }
  -
  -                // add or remove an eof character as required
  -                if (ctrlz == +1) {
  -                    if (outdata[o-1]!=0x1A) outdata[o++]=0x1A;
  -                } else if (ctrlz == -1) {
  -                    if (o>2 && outdata[o-1]==0x0A && outdata[o-2]==0x1A)
o--;
  -                    if (o>1 && outdata[o-1]==0x1A) o--;
  +                        // append desired character
  +                        outdata[o++]=indata[k];
  +                        col++;
                   }
  +            }
   
  -                // output the data
  -                try {
  -                    File destFile = srcFile;
  -                    if (destDir != null) destFile = new File(destDir, files[i]);
  -                    FileOutputStream outStream = new FileOutputStream(destFile);
  -                    outStream.write(outdata,0,o);
  -                    outStream.close();
  -                } catch (IOException e) {
  -                    throw new BuildException(e);
  -                }
  +            // add or remove an eof character as required
  +            if (ctrlz == +1) {
  +                if (outdata[o-1]!=0x1A) outdata[o++]=0x1A;
  +            } else if (ctrlz == -1) {
  +                if (o>2 && outdata[o-1]==0x0A && outdata[o-2]==0x1A)
o--;
  +                if (o>1 && outdata[o-1]==0x1A) o--;
  +            }
  +
  +            // output the data
  +            try {
  +                File destFile = srcFile;
  +                if (destDir != null) destFile = new File(destDir, files[i]);
  +                FileOutputStream outStream = new FileOutputStream(destFile);
  +                outStream.write(outdata,0,o);
  +                outStream.close();
  +            } catch (IOException e) {
  +                throw new BuildException(e);
  +            }
   
  -            } /* end for */
  -        } catch (Exception e) {
  -            e.printStackTrace();
  -            throw new BuildException(e);
  -        }
  +        } /* end for */
       }
   }
  
  
  

Mime
View raw message