All pastes #750086 Raw Edit

Untitled

public text v1 · immutable
#750086 ·published 2007-10-26 06:37 UTC
rendered paste body
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.Formatter;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.regex.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Integer.*;
import static java.lang.String.*;
import static java.lang.System.*;

class edfile{

   public static void main (String[] args) {
      list<String> lines = new dllist<String> ();
      boolean eflag = false;
      int i;
      String argi;

// scanning operands and options
      if (args.length == 0) {
      auxlib.usage_exit ("[-e] [filename...]");
      }
//      lines.setposition (list.position.FIRST);
      for(i=0; i<args.length; i++){
      if (args[i].equals("-e")){
// what to do if reading from file:
         eflag = true;
         String fileopt;
         System.out.println("eflag changing to TRUE");
         try{
            Scanner scanf = new Scanner (new File(args[i+1]));
            System.out.println("scanf activated");
            while(scanf.hasNextLine()){
               System.out.print(auxlib.PROGNAME+": ");
               System.out.println(scanf.nextLine());
               fileopt=scanf.nextLine();
               switch(fileopt.charAt(0)){
                  case '#': System.out.println ("case # triggered"); break;
                  case '$': System.out.println ("case $ triggered"); break;
                  case '*': System.out.println ("case * triggered"); break;
                  case '.': System.out.println ("case . triggered"); break;
                  case '0': System.out.println ("case 0 triggered"); break;
                  case '<': System.out.println ("case < triggered"); break;
                  case '>': System.out.println ("case > triggered"); break;
                  case 'a': System.out.println ("case a triggered"); break;
                  case 'd': System.out.println ("case d triggered"); break;
                  case 'i': System.out.println ("case i triggered"); break;
                  case 'r': System.out.println ("case r triggered"); break;
                  case 'w': System.out.println ("case w triggered"); break;
                  default: System.out.println("invalid command: "+fileopt);
                           break;
               }
            }
         }catch(FileNotFoundException e){
            System.out.println(e.getMessage());
         }
      }
      }
// what to do to take commands if reading from command line:
      if (eflag == false){
         argi=args[0];
         printFile(argi);
//         System.out.println(auxlib.PROGNAME);
         Scanner sc = new Scanner (System.in);
         String opt;
         while(sc.hasNext()){
            System.out.print(auxlib.PROGNAME+": ");
            opt=sc.next();
            switch(opt.charAt(0)){
               case '#': System.out.println ("case # triggered");
                         break;
               case '$': System.out.println ("case $ triggered");
                         break;
               case '*': System.out.println ("case * triggered");
                         printFile(argi);
                         break;
               case '.': System.out.println ("case . triggered");
                         lines.getitem();
                         break;
               case '0': System.out.println ("case 0 triggered"); break;
               case '<': System.out.println ("case < triggered");
                         lines.setposition(list.position.PREVIOUS);
                         break;
               case '>': System.out.println ("case > triggered");
                         lines.setposition (list.position.FOLLOWING);
                         break;
               case 'a': System.out.println ("case a triggered"); break;
               case 'd': System.out.println ("case d triggered"); break;
               case 'i': System.out.println ("case i triggered"); break;
               case 'r': System.out.println ("case r triggered"); break;
               case 'w': System.out.println ("case w triggered"); break;
               default: System.out.println("invalid command: "+opt); break;
            }
         }

      }
   }


   static void printFile(String argi){
    //  int argi;
      try{
         Scanner filescan = new Scanner (new File (argi));
         while(filescan.hasNextLine()){
            System.out.print(auxlib.PROGNAME+": ");
            System.out.println(filescan.nextLine());
         }
      }catch(FileNotFoundException e){
         System.out.println(e.getMessage());
      }
   }



}