[SOLVED] CSE344 Homework 1-File I/O

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon hw1-ybkzeq.zip (423.7 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

File I/O

The goal is to develop a simple text editor accomplishing a common task: string replacement. It must support the following:

a) ./hw1 ‘/str1/str2/‘ inputFilePath
This will replace all occurrences of str1 with str2 in the file inputFilePath (relative or absolute)

b) ./hw1 ‘/str1/str2/i‘ inputFilePath
This will perform the same as before, but will be case insensitive.

c) ./hw1 ‘/str1/str2/i;/str3/str4/‘ inputFilePath It must be able to support multiple replacement operations.

d) ./hw1 ‘/[zs]tr1/str2/‘ inputFilePath
It must support multiple character matching; e.g. this will match both ztr1 and str1

e) ./hw1 ‘/^str1/str2/‘ inputFilePath
It must support matching at line starts; e.g. this will only match lines starting with str1

f) ./hw1 ‘/str1$/str2/‘ inputFilePath
It must support matching at line ends; e.g. this will only match lines ending with str1

g) ./hw1 ‘/st*r1/str2/‘ inputFilePath
It must support zero or more repetitions of characters; e.g. this will match sr1, str1, sttr1, sttttr1, etc

And of course it must support arbitrary combinations of the above;
e.g. ./hw1 ‘/^Window[sz]*/Linux/i;/close[dD]$/open/‘ inputFilePath

Assume that the user will try to match/replace only letters and digits, but no symbols or space. Hence you will not need escape characters.

Output

The output will be written to the input file. If you need temporary files, you must use mkstemp().

Is this all?
No. The program might be executed as multiple instances with different replacement commands, on the same file. This will result in multiple processes manipulating the same input file with potentially wrong results.

Imagine for instance one process replacing str1 with str2, and another replacing str2 with str3 at the same time. Depending on which process writes/reads what, the end result might vary. You cannot stop the user from invoking your program multiple times, so instead you must protect file access (via the locks seen during our lectures) by making sure than no second instance of the program runs on the same file, before the first one has finished its task with it.

For all file I/O operations, use the low-level system calls presented during our lecture and not C library functions. Make sure you control each system call’s return value and print informative

March 10th, 2022

messages via perror/strerror in case of errors. Make sure you print your program’s usage in case the commandline arguments are wrong.

Evaluation

This is an all or nothing homework, make it work!

Rules:

1) Compilation error: grade set to 1; if the error is resolved during the demo, then evaluation continues.
2) Compilation warning (with respect to the -Wall flag); -1 for every warning until 10. -20 points if there are more than 10 warnings; no chance of correction at demo.
3) No makefile: -30
4) No pdf report submitted (or submitted but insufficient, e.g. 3 lines of text with no design explanation, etc): -20. Other file formats are not admissible.
5) If the required command line arguments are missing/invalid, your program must print usage information and exit. Otherwise: -10
6) The program crashes or doesn’t produce expected output with normal input: -100
7) The program doesn’t satisfy a requirement: -100
8) Presence of memory leak (regardless of amount – checked with valgrind) -30
9) Late submissions will not be accepted
10) In case of an arbitrary error, exit by printing to stderr a nicely formatted informative message. Otherwise: -10

Is my homework submission valid?

If it works with the case (a), it will be considered valid.

  • hw1-ybkzeq.zip