Question

Description: You will develop a small "text-based shell utility" ("ts") for Unix (or similar OS). A...

Description: You will develop a small "text-based shell utility" ("ts") for Unix (or similar OS). A common complaint of the most-used UNIX (text) shells (Bourne, Korn, C) is that it is difficult to remember (long) file names, and type "long" command names. A "menu" type shell allows a user to "pick" an item (file or command)from a "menu".

You will display a simple menu, the following is a suggestion (you may change format):

Current Working Dir: /home/os.progs/Me It is now: 8 September 2019, 3:59 PM

Files: 0. ts.c 1. a.out 2. ts.txt 3. assignment1 4. program2.c

Directories: 0. .. 1. my_dir

Operation: D Display E Edit R Run C Change Directory S Sort Directory listing M Move to Directory R Remove File Q Quit

You will read a single key "command" entered by the user, then a file or directory number or partial file name with “completion” and ts will output some system information on the terminal, or run a program (by means of systems calls). The commands you will implement: Edit – opens a text editor with a file. Run - runs an executable program. You should handle parameters. Change – changes working directory. Sort – sorts listing by either size or date (prompt user) You will need to implement: Prev, Next, and Operations need to be merged (menu fits on one screen). Store names in an array, Only one pass through directory. Add a menu using terminal codes or curses (ncurses). (First use initscr(), then move(), printw(), refresh(), getch(), and endwin() )

If the "ts" program has an argument, use it as the directory starting point (working dir), like: "./ts /bin". You should provide a reasonable user interface. (See below) You may write this in ADA, Assembler, C, C++ or Java.(Others with permission) You should target ts to Unix, MacOS, (or similar), or discuss alternatives with instructor. Constraints: How many files and directories can you handle (max 1024) How long is a file name (max 2048 characters, really: limits.h, NAME_MAX) Bonus: Show additional file information (date, size, read/execute) Use file name completion as well as a number. Create/use a pull-down menu. Please, Submit ONLY to Canvas. All work must be your own, you may reference web sites, books, or my code but You MUST site the references.
You must submit this lab, working (or partially) by the due date. You may (optionally) demonstrate this lab, working (or partially) to the GTA before the due date. Your program should be well commented and documented, make sure the first few lines of your program contain your name, this course number, and the lab number. Your comments should reflect your design and issues in your implementation. You should address error conditions: what if an illegal command is entered or misspelled, what if a path can not be reached, or an "executable file" is not executable.

Homework Answers

Answer #1

#include <sys/types.h>

#include <stdlib.h>

#include <stdio.h>

#include <unistd.h>

#include <dirent.h>

#include <string.h>

#include <time.h>

#include <curses.h>

int main(void) {  pid_t child;     DIR * d;     struct dirent * de;

int i, c, k;

char s[256], cmd[256]; time_t t;

while (1) {       t = time( NULL );

printf( “Time: %s\n”, ctime( &t ));

getcwd(s, 200);      /* why 200? What if bigger? Check for errors? */       printf( “\nCurrent Directory: %s \n”, s);

d = opendir( “.” );            /* errors? More below */         c = 0;

while ((de = readdir(d))){           if ((de->d_type) & DT_DIR)

printf( ” ( %d Directory: %s ) \n”, c++, de->d_name);

}       closedir( d );       d = opendir( “.” );       c = 0;

while ((de = readdir(d))){

if (((de->d_type) & DT_REG))                                            printf( ” ( %d File: %s ) \n”, c++, de->d_name);           if ( ( c % 8 ) == 0 ) {

printf( “Hit N for Next\n” );    /* What if only subdirs? */              k = getchar( );   }

}       closedir( d );

printf( “—————————————–\n” );       c = getchar( ); getchar( );       switch (c) {

case ‘q’: exit(0); /* quit */         case ‘e’: printf( “Edit what?:” );                   scanf( “%s”, s );                   strcpy( cmd, “pico “);                   strcat( cmd, s );

system( cmd );    /*this is bad, should use fork() then execv() or execl() */                   break;

case ‘r’: printf( “Run what?:” );                   scanf( “%s”, cmd );                   system( cmd );                   break;

case ‘c’: printf( “Change To?:” );                   scanf( “%s”, cmd );

chdir( cmd );   /* what can go wrong ? */                   break;

}

}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a shell program named HELOO (this should be done linux) Your program should set permissions...
Write a shell program named HELOO (this should be done linux) Your program should set permissions for a file named A1testFile so that the current premissions remain, except execute permissions are REMOVED for everyone, including owner. Your must accomplish this with a single chmod command. A1testFile should be specified as a relative path name to a file in the current directory (the directory the user is in when they run your program). Your program should not display any error messages,...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and the output in a word document and submit it. Part1: 1. Log in to Linux using your user account name and password. 2. If you logged in using a graphical login screen, open a terminal window by clicking on the icon in the lower left corner of the desktop to open the main menu, then selecting System Tools, then Terminal. A terminal window opens....
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
I need to create a UNIX program for this assignment In this assignment, you are to...
I need to create a UNIX program for this assignment In this assignment, you are to create an "archive" utility. It is a simple way to have some version control. You've created software projects before that change and grow over time. You might have several different copies of it (let's assume that it's all in one file). Perhaps before making major changes, you make a back-up copy, in case you later decide to revert to the earlier version. The idea...
You are to create a hard link to one of your existing files on someone else's...
You are to create a hard link to one of your existing files on someone else's directory (or vice versa). In other words, you know that you can link a file within your own directories, but you can also have a link to one of your files on other areas of the unix system as long as you have permissions to write to that directory (in this case, your partner). Create a subdirectory called temp where you can place this...
I cannot upload the needed text files to this question for your benefit of double checking...
I cannot upload the needed text files to this question for your benefit of double checking your solution, but I need help on this multi part question. Thanks! Write a Python program that will open the ‘steam.csv’ file. Your program should load the data as col- umns corresponding to the variable names located in the first row (You can hard code this – i.e open the file and use the names in the first row as variable names). You should...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text editor of your choice). This program will “explode” a String into an array of characters (char[]), and then print out the array. The String comes from the first command-line argument. Example output with the command-line argument foo is below: f o o --------------------------------------------------------------------- public class StringExplode { // TODO - write your code below this comment. // You will need to write a method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT