Good day fellow hackers,

Over the years I've wondered why we at suckless are still using such
slow and antiquated languages like C and Bash instead of advanced and
really fast ones like Java or C#.
To adress this problem, I'm currently working on porting sbase to Java
to bring more performance into this piece of software and make it suck
less and more memory-efficient.
Using Java, I found many ways to improve the echo-command. For
instance, using a LinkedList of LinkedLists of Characters allows easy
storage of parameters and easy access through LinkedList- and
LinkedList<LinkedList>-Iterators.
A StringBuffer is used to store the output.
--
Longer code usually is safer, because there are more ways to do it
right.
--
As of now, I only ported the echo-command into echo.java. More will
come.
Please let me know what you think about this great advancement.

Happy hacking!

Cheers

FRIGN

PS: compile with "javac echo.java" and execute with "java echo".

-- 
FRIGN <d...@frign.de>
/*        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
 *                    Version 2, December 2004 
 *
 * Copyright (C) 2004 Sam Hocevar <s...@hocevar.net> 
 *
 * Everyone is permitted to copy and distribute verbatim or modified 
 * copies of this license document, and changing it is allowed as long 
 * as the name is changed. 
 *
 *            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
 *   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 
 *
 *  0. You just DO WHAT THE FUCK YOU WANT TO.
 */

import java.util.LinkedList;
import java.util.Iterator;

public class echo {
       static void usage(){
              System.err.print("usage: echo [-n] text\n");
       }
	
       public static void main(String[] args) {
              String nflag = "n flag is not set";
	      int i,m;
              LinkedList<LinkedList<Character>> arguments = new LinkedList<LinkedList<Character>>();
              LinkedList<Character> string;
	      Character character;

	      for(i=0; i < args.length; ++i){
	             string = new LinkedList<Character>();
                     for(m=0; m < args[i].length(); ++m){
		            character = new Character(args[i].charAt(m));
                            string.add(character);
		     }
                     arguments.add(string);
	      }

	      Iterator<LinkedList<Character>> arg_iterator = arguments.iterator();
             
              if(!arguments.isEmpty() && arguments.getFirst().getFirst().charValue() == '-'){
                     if(arguments.getFirst().getLast().charValue() == 'n'){
                            nflag = "n flag is now set";
			    arg_iterator.next();
                     } else {
                            usage();
                     }
              }

	      StringBuffer buffer = new StringBuffer("");
              Iterator<Character> char_iterator;
              
	      for(; arg_iterator.hasNext();){
	             char_iterator = arg_iterator.next().iterator();
                     for(; char_iterator.hasNext();){
                            buffer.append(char_iterator.next());
		     }
		     buffer.append(' ');
              }
	      buffer.setLength(buffer.length()-1);

              if(!nflag.equals("n flag is now set")){
                     buffer.append('\n');
              }
              
	      System.out.print(buffer);
       }
}

Reply via email to