CMSC 216 Project #3 Spring 2019User Interface Due: Mon, Mar 11 / Thu, Mar 14, 2019, 11:30PM1 Overview1.1 user interface programFor this project you will write a text-based user interface to the document manager system you implementedin project #2. In addition, you will add some extra functionality to your system. There are two deadlinesassociated with the project. Those deadlines are:Mon, Mar 11, 11:30PM - Your code must pass the first two public tests (public01, public02). That is theonly requirement for this deadline. We will not grade the code for style. This first part is worth .5% ofyour course grade (NOT .5% of this project grade). Notice you can still submit late for this part.Thu, Mar 14, 11:30PM - Final deadline for the project. Notice you can still submit late (as usual).Remember that you need to satisfy the good faith attempt for every project in order to pass the class (seesyllabus). The good faith attempt information for this project (e.g., requirements and deadline) will be postedon the class web page later on.Make sure you read the class syllabus. Some students are not clear about the rules associated with this course.2 ObjectivesTo practice text parsing and file I/O.2.1 Obtain the project filesTo obtain the project files copy the folder project3 available in the 216 public directory to your 216 directory.Keep in mind that the Makefile and document.h files for this project are different from the ones used inproject2.2.2 Fixing problems with your project #2 codeAfter the late deadline for project2 you will be able to see results for release/secret tests in the submit server. ATA during office hours (and only during office hours) will be able to show you any test and why the test failed(if that is the case). You are responsible for fixing your code before submitting this project. Keep in mind thatif you passed all the project2 tests that does not mean you don’t have bugs. In this project we will be testingyour document functions again so it is in your best interest to test your code thoroughly.3 Specification3.1 Document manager updateYou need to add two functions to your document manager system. Remember to use the provided document.hfile (not the one from project #2).1. int load_file(Document *doc, const char *filename) - This function is similar to load document,except data will will be loaded from a file instead of using an array. By default a paragraph will beadded and any blank lines (line with only spaces as defined by isspace()) will mark the beginning ofa new paragraph. The function will fail and return FAILURE if doc is NULL, filename is NULL, or ifopening the file failed; otherwise the function will return SUCCESS. Notice no error message will begenerated if the file cannot be opened.12. int save_document(Document *doc, const char *filename) - This function will print the paragraphsassociated with a document to the specified file (overwriting the file). Each paragraph will be separatedby a newline. The function will fail and return FAILURE if doc is NULL, filename is NULL, or thefile cannot be opened; otherwise the function will return SUCCESS. Notice no error message will begenerated if the file cannot be opened.3.2 Method of operationYour program will be in a file named user_interface.c. A user calls your program in one of two ways(assuming the executable is named user interface):user_interfaceuser_interface filenameThe program should have zero or one arguments (in addition to the executable name) on the command line;if there are more the program prints the following usage message to standard error, and exits with exit codeEX_USAGE 1.Usage: user_interfaceUsage: user_interface <filename>If there is no file specified when the program is started, the program should read its data from standard input.The program will display a prompt (represented by >) after which commands will be entered. If a file isnamed, however, the program reads its data from that file; in this case no prompt will be used.In case of an error opening the file your program should print (to standard error) the message ”FILENAMEcannot be opened.” where FILENAME represents the file name. The program will then exit with the exit codeEX_OSERR.Upon starting execution your program should initialize a single document with the name ”main document”,and perform operations on that document as instructed by the commands the program reads.Make sure you name the file with your program user interface.c. This program will include document.h (theversion provided for this project and not the one from proect #2).3.3 File format3.3.1 Valid LinesAn input file (or input coming from standard input) contains multiple lines with commands, and the commandsare executed in the order they are encountered. No valid line can be more than 1024 characters (includingthe newline character). A valid line takes one of three forms:1. a comment, where the first non-whitespace character is a hash symbol (‘#’)2. a command, where the line is composed of one or more strings of non-whitespace characters3. a blank line, where the line contains 1 or more spaces (as defined by the isspace() function in ctype.h)For example, the following file contains valid lines:# creating a paragraph and inserting some linesadd_paragraph_after 0add_line_after 1 0 *first line of the document1This and the other exit codes beginning with EX mentioned here are all obtained by including <sysexits.h> in your C programfile.2add_line_after 1 1 *second line of the document# let's print itprint_documentquitValid commands must follow one of the formats specified in Section 3.4 below.3.3.2 Invalid Lines/CommandsIf your program encounters an invalid line it should print the message ”Invalid Command” to the standardoutput. Make sure you print to the standard output and not to the standard error. An invalid line includes notonly an invalid command, but a command without the expected values. For example, the add paragraph aftercommand requires an integer. If the value provided is not an integer the command will be considered invalid.Notice the program will not end when an invalid command is provided.3.4 CommandsUnless output is associated with a command the successful execution of a command will not generate any con-firmation message (similar to successful execution of commands in Unix). If a command cannot be succesfullyexecuted the message ”COMMAND NAME failed”, where COMMAND NAME represents the command,should be printed to standard output (and not to the standard error).Any number of spaces can appear between the different elements of a command, and before and after acommand. A blank line (as defined above) and a comment will be ignored (no processing). When a commentor blank line is provided, and standard input is being used, a new prompt will be generated.The quit and exit commands will end/terminate the command processor. The command processor will alsoterminate when end of file is seen. The commands quit or exit need not be present in a file.1. add_paragraph_after PARAGRAPH_NUMBERThis command will add a paragraph to the document. The ”Invalid Command” message will be generatedwhen:a. PARAGRAPH NUMBER does not represent a numberb. PARAGRAPH NUMBER is a negative valuec. PARAGRAPH NUMBER is missingd. Additional information is provided after the PARAGRAPH NUMBERIf the command cannot be successfully executed the message ”add paragraph after failed” will be generated.2. add_line_after PARAGRAPH_NUMBER LINE_NUMBER * LINEThis command will add a line after the line with the specified line number. The line to add will appearafter the * character. The ”Invalid Command” message will be generated when:a. PARAGRAPH NUMBER does not represent a numberb. PARAGRAPH NUMBER is a negative value or 0c. PARAGRAPH NUMBER is missingd. LINE NUMBER does not represent a numbere. LINE NUMBER is a negative valuef. LINE NUMBER is missingg. * is missing3If the command cannot be successfully executed the message ”add line after failed” will be generated.3. print_documentThis command will print the document information (print document function output). The ”InvalidCommand” message will be generated if any data appears after print document.4. quitThis command will exit the user interface. The ”Invalid Command” message will be generated whenany data appears after quit.5. exitThis command will exit the user interface. The ”Invalid Command” message will be generated whenany data appears after exit.6. append_line PARAGRAPH_NUMBER * LINEThis command will append a line to the specified paragraph. The line to add will appear after the *character. The ”Invalid Command” message will be generated when:a. PARAGRAPH NUMBER does not represent a numberb. PARAGRAPH NUMBER is a negative value or 0c. PARAGRAPH NUMBER is missingd. * is missingIf the command cannot be successfully executed the message ”append line failed” will be generated.7. remove_line PARAGRAPH_NUMBER LINE_NUMBERThis command will remove the specified line from the paragraph. The ”Invalid Command” messagewill be generated when:a. PARAGRAPH NUMBER does not represent a numberb. PARAGRAPH NUMBER is a negative value or 0c. PARAGRAPH NUMBER is missingd. LINE NUMBER does not represent a numbere. LINE NUMBER is a negative value or 0f. LINE NUMBER is missingg. Any data appears after the line numberIf the command cannot be successfully executed the message ”remove line failed” will be generated.8. load_file FILENAMEThis command will load the specified file into the current document. The ”Invalid Command” messagewill be generated when:a. FILENAME is missingb. Any data appears after FILENAMEIf the command cannot be successfully executed the message ”load file failed” will be generated.9. replace_text "TARGET" "REPLACEMENT"This command will replace the string ”TARGET” with ”REPLACEMENT”. The ”Invalid Command”message will be generated when:a. Both ”TARGET” and ”REPLACEMENT” are missing4b. Only ”TARGET” is providedFor this command you can assume that if ”TARGET” and ”REPLACEMENT” are present there is noadditional data after ”REPLACEMENT”.If the command cannot be successfully executed the message ”replace text failed” will be generated.10. highlight_text "TARGET"This command will highlight the string ”TARGET”. The ”Invalid Command” message will be generatedwhen ”TARGET” is missing.For this command you can assume that if ”TARGET” is present there is no additional data after it. Noticeno fail message is associated with this command; either the text was highlighted or not.11. remove_text "TARGET"This command will remove the string ”TARGET”. The ”Invalid Command” message will be generatedwhen ”TARGET” is missing.For this command you can assume that if ”TARGET” is present there is no additional data after it. Noticeno fail message is associated with this command; either a deletion took place or not.12. save_document FILENAMEThis command will save the curent document to the specified file. The ”Invalid Command” messagewill be generated when:a. FILENAME is missing.b. Any data appears after the filename.If the command cannot be successfully executed the message ”save document failed” will be generated.13. reset_documentThis command will reset the curent document. The ”Invalid Command” message will be generatedwhen any data appears after reset document. Notice no fail message will be associated with reset document.3.5 Important Points and Hints1. Data should only be allocated statically. You may not use malloc() etc.2. Do not use perror to generate error messages; use fprintf and stderr instead.3. IMPORTANT: You may not use memset, strtok, strtok r, memcpy in this project.4. IMPORTANT. You may not use regular expressions for this project; if you do you will lose at least 30points. Regular expressions can be used in the format string of a scanf statement in order to recognizestring patterns. The following are characters typically associated with regular expressions:[,],*,^,-,$,?See your lab TA or instructor if you have doubts as to what represents a regular expression.5. Do not include .c files using #include.6. You can assume a filename will not exceed 80 characters.7. If you remove a line that line should not be printed (no blank line for it).8. If you remove all the lines from a paragraph, the paragraph will not be removed (paragraph count willstay the same).54 Grading CriteriaYour project grade will be determined with the following weights:Results of public tests 20%Results of release tests 45%Results of secret tests 25%Code style grading 10%4.1 Style gradingFor this project, your code is expected to conform to the following style guidelines:Your code must have a comment at the beginning with your name, university ID number, and UMDDirectory ID (i.e., your username on Grace).Do not use global variables.Feel free to use helper functions for this project; just make sure to define them as static.Follow the C style guidelines available at:http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/5 SubmissionYou can submit your project by executing in your project directory the submit command.6 Academic IntegrityPlease see the syllabus for project rules and academic integrity information. All programming assignments inthis course are to be written individually (unless explicitly indicated otherwise in a written project handout).Cooperation between students is a violation of the Code of Academic Integrity.
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
微信:codinghelp