CSC 209 Assignment 2, Summer 2020
1. centreWrite a standard unix filter, which processes its standard input if there are no filename arguments, or processes a sequence of one or more file names on the command-line.
The transformation on the data is that each line is centred: it is preceded in the output by the appropriate number of spaces so as to centre the line in a specified width.
Call your program "centre" (source code filename "centre.c"). The "centre" program takes two options:
- ?w specifies the width to be centred within, which is 80 characters by default. The ?w option takes an integer argument. You may limit this width (minimum or maximum) to avoid implementation difficulties, although the maximum must be at least 500. (Any specified value outside the minimum must result in an error message, not in incorrect behaviour.)
- ?c has an argument which is a single character; this character is used instead of space, on both sides of the input line, to achieve the desired width of each line. That is to say, "?c?'?'" is different from the default in that this puts spaces on the right side of the input line as well as the left; without ?c, the filler characters appear only on the left.
You must parse the command-line options with getopt() so as to accommodate all standard allowable command-line variations. There is an example getopt()-using program in the "Course notes" section of the CSC 209 web site, also linked to from the Q&A page.
When a file cannot be opened, you must call perror() properly to output a standard error message.
2. vcutWrite the?vcut?program, which is a vertical version of?cut.?vcut?takes a description similar to cut's ?c option argument, but instead of referring to characters horizontally within a line, it refers to line numbers (vertical).
For example, "vcut?8,1-4,9" takes lines 1, 2, 3, 4, 8, and 9 of the input (order on the command-line doesn't matter). The rest of the input is discarded.
北美代写essay,程序代写,Java代写代做,Java代考-焦点论文 The specification as to which lines are included is a mandatory first argument. The program processes the standard input if there are no further arguments, or it processes one or more file names if there are further arguments. You do not need to use getopt().
北美代写essay,程序代写,Java代写代做,Java代考-焦点论文 Please see some substantial guidance about a simplified way to parse and deal with the specification argument at?. That simpler algorithm limits line numbers in the specification to be less than 100, which is fine for this assignment.
3. "find ?name"Write a standard unix tool in C which is like "find ?name": it recursively traverses one or more directories, looking for a file with the exact specified name (not a substring). It outputs an appropriate path name for each match.
Call your program "findname". It will not take any command-line options, so you do not need to use getopt(). The first argument is the file name to look for, and subsequent arguments (of which there must be at least one) are directory names to search. Unlike the real?find, wildcard characters (glob notation) are not interpreted in the file name search argument.
The exit status should be 0, 1, or 2, with the same meanings as in?grep.
findname should?not?do a chdir() (which you might be tempted to do to avoid string processing). If it does a chdir(), your program will no longer always work with multiple directory arguments, since a chdir() in processing the first directory may invalidate the name of the specified second directory.
You may assume a maximum likely complete path name of, say, 2000 characters, so long as your program aborts with an error, rather than exceeding array bounds, should the situation turn out to be more complex than this.
You may not use ftw(), fts(), nftw(), or similar library functions (the point of this assignment question is to?implement?the filesystem-tree traversal).
Other notesPlease try sample implementations in /u/csc209h/summer/pub/a2 (compiled programs only, so that you can't see my sample solution source code before the due date!).
北美代写essay,程序代写,Java代写代做,Java代考-焦点论文 All of your programs must be in standard C. They must compile on the teach.cs linux machines with "gcc??Wall" with no errors or warning messages, and may not use linux-specific or GNU-specific features.
Pay attention to process exit statuses. Your programs must return exit status 0 or 1 as appropriate (or sometimes 2 in the case of findname).
Call your assignment files centre.c, vcut.c, and findname.c. Your files must have the correct names so as to be processed correctly by the grading software, and auxiliary files are not permitted. Submit with commands such as
submit ?c csc209h ?a a2 centre.c vcut.c findname.cand the other 'submit' commands are as in assignment one and the labs.
Please see the assignment Q&A web page at??for other reminders, and answers to common questions.
Remember:This assignment is due at the end of Friday, July 10, by midnight. Late assignments are not ordinarily accepted, and?always?require a written explanation. If you are not finished your assignment by the submission deadline, you should just submit what you have, for partial marks.
Despite the above, I'd like to be clear that if there?is北美代写essay,程序代写,Java代写代做,Java代考-焦点论文?a legitimate reason for lateness, please do submit your assignment late and send me that written explanation.
北美代写essay,程序代写,Java代写代做,Java代考-焦点论文 And above all: Do not commit an academic offence. Your work must be your own. Do not look at other students' assignments, and do not show your assignment (complete or partial) to other students. Collaborate with other students only on material which is not being submitted for course credit.