FIT2100 Assign 01 2018 GUI shell

ÿþ FIT2100 Assignment #1 Building a Graphical Shell
with C Programming Semester 2 2018
Mr Daniel Kos
Admin Tutor, Faculty of IT. Email: © 2016-2018, Monash University
August 1, 2018
© 2016-2018, Faculty of IT, Monash University
----PAGE----
Revision Status
$Id: FIT2100-Assignment-01.tex, Version 1.0 2017/08/12 18:00 Jojo $
$Id: FIT2100-Assignment-01.tex, Version 2.0 2018/06/18 18:00 Daniel $
$Id: FIT2100-Assignment-01.tex, Version 2.4 2018/07/25 18:30 Daniel $
$Id: FIT2100-Assignment-01.tex, Version 2.5 2018/07/31 11:45 Jojo $
Based on command-line interface assignment prepared for FIT2100
in 2016-2017 by Dr Jojo Wong.
Adapted to graphical shell assignment by Daniel Kos.
© 2016-2018, Faculty of IT, Monash University
----PAGE----
CONTENTS 3
Contents
1 Introduction 4
2 Graphical Shell 4
2.1 Background ................................... 4 2.1.1 Objective................................. 5 2.1.2 Preparation................................ 5
2.2 Task1: BuildingtheEssentialProgramStructure . . . . . . . . . . . . . . . 6
2.3 Task2:GraphicalUserInterface......................... 9
2.4 Task3:AdvancedFileOperations........................ 10
2.4.1 OptionA:Fileproperties ........................ 12 2.4.2 OptionB:Cut,copy,paste ....................... 12 2.4.3 OptionC:Createandeditfiles ..................... 12
2.5 ImportantNotes ................................. 13
2.6 MarkingCriteria ................................. 13
3 Submission 13
3.1 Deliverables ................................... 14 3.2 AcademicIntegrity:PlagiarismandCollusion .................. 14
© 2016-2018, Faculty of IT, Monash University
----PAGE----
1 Introduction 4
1 Introduction
This assignment is due on 24th August 2018 (Friday) by 5:00pm. It is worth 15% of the total unit marks. A penalty of 5% per day will apply for late submission. Refer to the FIT2100 Unit Guide for the policy on extensions or special considerations.
Note that this is an individual assignment and must be your own work. Please pay attention to Section 3.2 of this document on the university policies for the Academic Integrity, Plagiarism and Collusion.
This first assignment consists of three main tasks and all three tasks should be submitted as three separate C programs with supporting documentation on usage. All the program files and any supporting documents should be compressed into one single .tar.gz file for submission. (The submission details are given in Section 3.)
Assessment: For the working program and code architecture components of your assignment 1 mark, the 3 tasks carry unequal weightage of marks with 35%, 40% and 25% respectively.
2 Graphical Shell
2.1 Background
You are currently getting familiar with the bash command line interface. Bash is an example of a shell utility. A shell is an important component in a typical computing environment, which allows the user to interact with various functions of the operating system.
Bash works by waiting for user input (in a loop), and responding to each command the user types into a TTY terminal by doing the action the user requests (then continuing to the next iteration of the loop, so the user can then input another command, repeating until the user decides to quit). However, learning to use a command-line interface can be frightening to people who aren t good with computers. Many operating systems such as Windows and macOS provide the user with a graphical shell so novice users can interact with files using a mouse. (Examples are Windows File Explorer and also the Finder in macOS.)
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.1 Background 5 2.1.1 Objective
The objective of this assignment is to implement a simplified version of a graphical shell like you might find in a popular operating system. This works on the same principles as a command-line shell, but allows the user to provide input in a graphical way by clicking file icons on the screen, browsing folders, etc.
Your shell shall be implemented on the Linux operating system in the C programming language, making use of external Linux utilities where specified, and producing output within the ioL graphical console environment.
2.1.2 Preparation
Throughout your degree up to now, whenever you have printed output from a program, the output was always displayed in a plain-text terminal window (technically known as a TTY). A standard TTY terminal is not ideal for building a lavish application. The output you print can only be displayed sequentially, line by line in plain text, and you can t display graphics or ask the user to click a button.
For Tasks 2 and 3, we will be replacing the traditional TTY with the ioL console system. You will compile your programs in the same way, but will run them inside a different environment.
Consider the line of C code below:
1 printf(”Hello <span italic=true {World!}>\n”);
If you run the program in the usual way (i.e. output is printed to a TTY terminal), the user will see everything you ve put in the quotation marks. But if you run your program inside an ioL console, the user will see the words  Hello World with the second word displayed in italic. This approach provides the ability to make your programs more intuitive for the user. (You will need to put:  iol --  in front of the command used to run your program, in order to make it run in the special environment, and the ioL console window will close automatically as soon as your program quits.)
To produce the graphical user interface in Tasks 2 and 3, you will need to print your program output according to the ioL markup syntax, including giving the user some way to provide input back to your program. ioL has special rules for how you need to print your output in order to make things show up the way you want. Your Linux virtual machine environment is already set up with the ioL console system needed to run these tasks.
© 2016-2018, Faculty of IT, Monash University

----PAGE----
2.2 Task 1: Building the Essential Program Structure 6
A getting-started tutorial is available online at:
http://doc.iol.science/getting-started/tutorial
You should go through the tutorial before you attempt Tasks 2 and 3 of this assignment.
2.2 Task 1: Building the Essential Program Structure
In the first task, you will implement a very rudimentary command-line interpreter running in a TTY terminal, taking command input from the terminal as typed by the user and printing output back to the terminal. (This is not a graphical shell yet, but once you have the essential program structure in place, you will turn it into a graphical shell in Task 2.)
For this task, you should name your main source file as task1shell12345678.c, where 12345678 is your Monash Student ID number.
Implement your terminal shell, task1shell, as follows:
1. When the user starts your shell, it should print the filenames of all the files in the current directory. Do not print hidden files. For each filename, also print whether it is a directory, executable program, or ordinary file.
2. Your shell should then wait for the user to input a command from the following table and behave accordingly.
3. After processing each command, the shell should allow the user to enter another com- mand, and repeat until the user decides to quit.
For this task, your program should implement the following commands:
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.2 Task 1: Building the Essential Program Structure 7
Command
d:<directory>
Description
Change the current working directory to <directory>, and re-print the files at the new directory location.
This command should also update the PWD environ- ment variable. It should also respond correctly if .. is specified as <directory>, by navigating to the parent of the current directory. If the user does not have permission to enter a directory, print an appro- priate error message.
Execute the specified <filename> by running the program in a new terminal window. Your program should run an instance of the xterm utility to create the new TTY terminal window. Your shell should not wait for the new process to finish, but should allow the user to continue entering commands while the new child process is running. If the file cannot be executed because the user does not have permission to do so, print an appropriate error message and do not open a new terminal window.
Display the contents of the text file <filename> in a new xterm terminal window, making use of the less utility. If the file size is larger than 500kb, do not allow the user to open the file; instead print an appropriate error message to inform the user that the file is too large to be viewed in this way. Your shell should not wait for the new process to finish, but should allow the user to continue entering commands while the file is being viewed in the other window.
Quit the shell.
x:<filename>
v:<filename>
Each command should print a reasonable error message if the operation could not be com- pleted, without terminating your program.
Error handling: You are required to validate against the possible error conditions mentioned above. You are not required to validate that the user has entered a valid command in this part, since the graphical user interface that you will build in Task 2 will shield your program
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.2 Task 1: Building the Essential Program Structure 8
from invalid inputs.
Robustness: Keep in mind that directory paths might contain spaces, and might be longer than you expect if the user wants to navigate to a path several folders deep. For the purposes of this assignment, you may assume that the number of characters in the user s paths/filenames will be fewer than PATH_MAX (this is a pre-defined constant in your C environment, but you will need to include <limits.h> in order to use it).
./task1shell Current directory: /home/me/FIT2100/ ***Directory listing follows***
File: FIT2100 is awesome.txt
File: MFW I get an HD.jpg Executable: task1shell
File: task1shell.c
Current directory: /home/me
***Directory listing follows***
Executable:
Directory:
Directory:
File:
Directory:
File:
Directory:
a.out
Documents
FIT2100
helloworld.c
Pictures
Reasons this unit is great.txt
Videos
v:Reasons this unit is great.txt
Error: Could not open text file. File size too large.
Figure 1: Sample output for Task 1, when the user runs the shell from within bash. The user s input is shown in bold.
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.3 Task 2: Graphical User Interface 9
2.3 Task 2: Graphical User Interface
By modifying your Task 1 shell, implement a new version, task2shell, to run within an ioL console instead of a TTY terminal.1
For this task, you should name your main source file as task2shell12345678.c, where 12345678 is your Monash Student ID number.
Your Task 1 implementation produces output intended for display on a plain-text TTY terminal. Modify the print statements in your implementation to mark-up your output in a graphical way as follows:
” Instead of printing the directory contents in plain text, use visual icons to indicate the file types.2 As in Task 1, the three different file types are directories, executable files, and ordinary files. The display should be updated whenever the user changes the current working directory.
” Add onclick= handlers3 to your program s output so that when the user clicks on the file icons, the appropriate command for that file is carried out by the shell. For example, when the user clicks on a directory named test, the console should input d:test back to your shell program, and your program should print new output to display the new directory contents on the screen. Similarly, when the user clicks on an executable file, a similar x:... instruction should be produced, and so on. All other files should be treated as text files.
” Error messages should be displayed on the screen in an appropriate way (for example, you might print a <box> element at the top of the window for error messages).
” The user should have a way to navigate to the parent folder.
” The user should be able to quit the program gracefully by closing the window.
1The user should be able to run your program by typing iol ./task2shell or something similar in order to get the correct graphical functionality.
2You can either use your own icon images, or make use of special font symbols defined in the Unicode character set for this task. For example, the character code (in hexadecimal) for an open folder symbol is x1F4C2, and can be printed as ”</#x1F4C2>”. A good resource for finding character codes for various symbols is https://www.fileformat.info/info/unicode/block/miscellaneous_symbols_and_pictographs/ list.htm
3 http://doc.iol.science/fields/reference/onclick
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.4 Task 3: Advanced File Operations 10
Go to parent directory Error: Could not open text file. File size too large. Current directory: =Ø /home/me
=Ø Documents =Ø FIT2100 =Ø Pictures =Ø Videos
=Ø a.out =Ø helloworld.c
=Ø Reasons this unit is great.txt
Figure 2: Sample output for Task 2, running through an iol console instance. This is just one idea  you may use your imagination to lay out your shell interface in any reasonable way you wish as long as you implement the requirements. The icons in this example are just special character symbols marked up in a large font size and different font colors.
2.4 Task 3: Advanced File Operations
In this task, you will add extra features to allow the user to carry out more advanced operations on each file. For this task, you may choose to make use of the oncontextclick= handler4 in your marked-up output so that the user can right-click a file to display buttons for additional commands.
For this task, you should name your main source file for your advanced implementation as task3shell12345678.c, where 12345678 is your Monash Student ID number.
4 http://doc.iol.science/fields/reference/oncontextclick
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.4 Task 3: Advanced File Operations 11
Go to parent directory a.out selected Cut Copy
Current directory: =Ø /home/me =Ø Documents
=Ø Pictures
=Ø Reasons this unit is great.txt =Ø helloworld.c
=Ø FIT2100 =Ø Videos =Ø a.out
Figure 3: One possible way to show the user extra file commands for Task 3. In this example, the user has right-clicked a.out. The program responds by making extra buttons visible at the top of the screen, and uses a status box to remind the user of which file they selected. If the user clicks a different file without choosing any of the copy/paste options, the operation will be cancelled. Your implementation might be very different, but try to find a way to make it reasonably user-friendly.
© 2016-2018, Faculty of IT, Monash University
----PAGE----
2.4 Task 3: Advanced File Operations 12 Choo