Lab 3 : Sort program

Similar documents
Lab 5 : WordAnalyzer class

Lab #1 Installing a System Due Friday, September 6, 2002

Bash Shell Programming Helps

COMP26120 Academic Session: Lab Exercise 2: Input/Output; Strings and Program Parameters; Error Handling

find starting-directory -name filename -user username

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

Introduction to the Shell

Output with printf Input. from a file from a command arguments from the command read

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

UNIX Kernel. UNIX History

Command-line interpreters

ADVANCED LINUX SYSTEM ADMINISTRATION

System Administration

A shell can be used in one of two ways:

5/20/2007. Touring Essential Programs

Lab #2 Physics 91SI Spring 2013

CSCI2467: Systems Programming Concepts

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

Module 8 Pipes, Redirection and REGEX

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Linux Command Line Interface. December 27, 2017

Introduction: What is Unix?

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

More Scripting Todd Kelley CST8207 Todd Kelley 1

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Essentials for Scientific Computing: Bash Shell Scripting Day 3

We first learn one useful option of gcc. Copy the following C source file to your

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Specification-Based Testing 1

Introduction to Linux

Files and Directories

CS354 gdb Tutorial Written by Chris Feilbach

CSE 374 Programming Concepts & Tools

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

CSCI 2132 Software Development. Lecture 7: Wildcards and Regular Expressions

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

Standard File Pointers

CSE 15L Final Summer 2011

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

UNIX Essentials Featuring Solaris 10 Op System

Week 2 Lecture 3. Unix

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

$Id: asg4-shell-tree.mm,v :36: $

Programming Assignment 5 (100 Points) START EARLY!

The Shell, System Calls, Processes, and Basic Inter-Process Communication

Lecture 7: file I/O, more Unix

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

Practical Session 0 Introduction to Linux

Getting your department account

LING 408/508: Computational Techniques for Linguists. Lecture 5

CSCI 2132 Software Development. Lecture 5: File Permissions

Mills HPC Tutorial Series. Linux Basics II

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

Basics. I think that the later is better.

ECE 364 Software Engineering Tools Lab. Lecture 2 Bash II

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Exploring UNIX: Session 5 (optional)

Sperimentazioni I LINUX commands tutorial - Part II

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

Virto Active Directory Service for SharePoint. Release Installation and User Guide

PROGRAMMING PROJECT ONE DEVELOPING A SHELL

Shell Control Structures

CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Introduction to UNIX Shell Exercises

Topic 2: More Shell Skills

Lab 4: Shell Scripting

Topic 2: More Shell Skills

Lec 1 add-on: Linux Intro

The input can also be taken from a file and similarly the output can be redirected to another file.

BIOS 546 Midterm March 26, Write the line of code that all Perl programs on biolinx must start with so they can be executed.

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Review of Fundamentals

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts

The UNIX Operating System. HORT Lecture 2 Instructor: Kranthi Varala

CHAPTER 2. Troubleshooting CGI Scripts

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Introduction to Linux Organizing Files

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

EECS2301. Lab 1 Winter 2016

Lab 2: Linux/Unix shell

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

HW 1: Shell. Contents CS 162. Due: September 18, Getting started 2. 2 Add support for cd and pwd 2. 3 Program execution 2. 4 Path resolution 3

Transcription:

Lab : Sort program Introduction Your pointy haired Dilbert manager decided to write a Sort program which you have now inherited. The Sort program intends to emulate the main functionality of the GNU sort program (sort lines from stdin or a into alphabetic/sorted order or reverse alphabetic/sorted order and display the sorted lines to stdout or a ). However, the version of the program given to you has some problems. It is your job to fix it so that it meets all the specifications below. In addition, you must keep an interactive Lab Notes log to show us along with demonstrating your Sort program works properly to get checked off at the end of the lab. In particular, there are 9 different/unique problems in the program. error occurs multiple times (same error in multiple locations) but only counts as of the 9 unique problems. These are all relatively minor or line programming fixes; do not redesign the program. Make sure the program compiles with no warnings! In particular take note of any "Note:" messages compiler. Make a new Lab-Sort directory in your cs5u account and copy all the from ~/../public/lab-sort/ to your new Lab-Sort directory. Program Specifications The Sort program should read lines of input from a single or stdin by default and write the lines sorted in alphabetic order to a or stdout by default. If the program is run with the command line argument "--help", it should print a usage message and exit. If no input is specified on the command line, it should read from stdin. If no output is specified on the command line, it should write to stdout. If the program is run with the command line argument "-" as the input name, it should read from stdin. If the program is run with the command line argument "-" as the output name, it should write to stdout. If the program is run with the "-r" command line argument, it should output the lines sorted in reverse order. If there is an error opening either the specified input or output, output an error message (see examples below) to stderr with the name of the program ("Sort: ") concatenated with the detailed message string of this exception (see the Javadocs for class Throwable/Exception), and then exit with exit status. (Exit status of 0 means success; an exit status of any non-zero value means failure.) Note: Catch the most specific exception type in this case, not a generic Exception. This is the only exception handling you need to do. Note: In all examples, the dollar sign is your prompt and user input is in bold. Assume there is one plain text in the current directory in. The in is available for you to you (you should have copied it along with the original broken Sort.java). To display the contents of the, you can run: cat in You first need to get your boss' program to compile! Remember - do not redesign the program no matter how badly you may want to. First understand what the program is trying to do by reading the source code. Sometimes compiler errors can be a bit misleading. You need to understand what the compiler thinks your code is trying to do and what you meant your code to do. Some of these compiler errors and warnings may be new to you. Most have to do with the use of the ArrayList type and generics. After trying to figure these out together, if you continue to have problems compiling the program without errors or warnings, ask for help from one of the CSE 5L staff.

Get the help message to print. Example Passing "--help" as a command line argument: $ java Sort --help Usage: java Sort [-r] [input [output]] Read input from standard input or a until the end of input is reached then print the input to standard output or a in sorted order. If the -r flag is present print the input in reverse sorted order. Using '-' for the input will read from standard input and for the output will print to standard output. Get the exception handling of bad input/output s working. Check that the error message is going to stderr and the program is exiting with exit status. Handle these with a single try-catch and a single method call to print the detail message string (hint: look at the javadocs for Throwable). How do you determine what single exception type to catch in the above examples? Remember - you are to catch the most specific type of exception that covers these errors. And how do you get the different/specific detailed message string from this exception object to output/print in a general way? If you cannot figure out how to determine this after trying, ask for help from one of the CSE 5L staff. Example Bad input name (catch exception; display that exception's error message; check exit status): $ java Sort xxx Sort: xxx (No such or directory) Example Bad output name (or some other name where you do not have permission): $ java Sort in /dev/mem Sort: /dev/mem (Permission denied) $ java Sort in /tmp Sort: /tmp (Is a directory) How do you test to make sure the error message is going to stderr? If you need help/hint, check how you tested this on the command line in Lab. We will ask you to demonstrate this. echo $? prints the exit status. The exit status of the previous cmd is stored in the special shell variable $? Now get this to work. Probably a few fixes need Example Sorting the contents of a to stdout: $ java Sort in in.

Example Sorting the contents of a to an output specified on the command line: $ java Sort in out $ cat out in. Example No command line arguments. Default input from stdin and default output going to stdout: $ java Sort $ <<<<<--- Note: Testing empty/no input $ touch in <<<<<--- Note: This create an empty $ java Sort in $ $ java Sort Hey! Things are looking. Now try the following. Example Using "-" as input to read from stdin and default output to stdout: $ java Sort - Oops. The program thinks the "-" is a command line option (or at least the beginning on a command line option) instead of the input. Where is the program trying to differentiate these?

Example Using "-" as input to read from stdin and "-" as output to write to stdout: $ java Sort - - Example Using "-" as input to read from stdin and specify an output : $ java Sort out $ cat out Test all of the above with the "-r" option to reverse the sort. Only showing a couple examples here. Example Sorting the contents of a in reverse order to stdout: $ java Sort r in in. $ java Sort -r - - Be sure to test the "-r" option with all variations/combinations of options from above.

One more Example Redirecting stdin and stdout: $ java Sort -r - - < in > out $ cat out in. < in redirects stdin in > out redirects stdout to the out Be sure to keep a running log (Lab Notes) of each observed bug, hypothesize what is wrong, how you fixed it, and how you tested the fix. Be sure to include erroneous hypotheses and non-fixes. Learning from mistakes is as important (if not more important). Get one of the CSE 5L staff to check you off for the lab. You will need to go through your log describing each bug interaction and demo your fixed version of Sort.