Skip to main content
留学咨询

辅导案例-CMSC 216

By May 15, 2020No Comments

CMSC 216 Project 3 Spring 2020 User Interface Due: Wed Mar 11 11:30pm / Sat Mar 14 11:30pm 1 Overview 1.1 user interface program For this project you write a text-based user interface to the document manager system you implemented in project 2. In addition, you will add some extra functionality to your system. There are two deadlines associated with the project: • Wed Mar 11 11:30pm: Your code must pass the first two public tests (public01, public02). That is the only requirement for this deadline. We will not grade the code for style. This first part is worth .5% of your course grade (NOT .5% of this project grade). You can submit late for this part. • Sat Mar 14 11:30pm: Final deadline for the project. You can submit late. Remember that you need to satisfy the good faith attempt for every project in order to pass the class (see syllabus). The good faith attempt information (requirements and deadline) for this project will be posted on the class web page later on. Make sure you read the class syllabus. Some students are not clear about the rules in this course. 2 Objectives To practice text parsing and file I/O. 2.1 Obtain the project files To obtain the project files, copy the folder project3 available in the 216 public directory to your 216 directory. The Makefile and document.h files for this project are different from the ones in project2. 2.2 Fixing problems with your project 2 code After the late deadline for project2, you can see the results for release/secret tests for project2 in the submit server. A TA during office hours (and only during office hours) can 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 that passing all the project2 tests does not mean that your code does not have bugs. In this project we will be testing your document functions again so it is in your best interest to test your code thoroughly. 3 Specification 3.1 Document manager update You need to add two functions to your document manager system. Remember to use the document.h file provided with this project (not the one from project 2). 1. int load_file(Document *doc, const char *filename) – This function is similar to load document, except that data is loaded from a file instead of from an array (in memory). By default the function adds a new paragraph. A blank line (line with only spaces as defined by isspace()) marks the the beginning of a new paragraph. The function returns FAILURE if doc is NULL, filename is NULL, opening the file failed, or the number of paragraphs would exceed MAX PARAGRAPHS; otherwise the function returns SUCCESS. If the number of paragraphs would exceed MAX PARAGRAPHS, the function adds paragraphs until the maximum limit is reached. Notice no error message is generated if the file cannot be opened. 1 2. int save_document(Document *doc, const char *filename) – This function prints the paragraphs associated with the specified document to the specified file (overwriting the file). Each paragraph is separated by a newline. The function returns FAILURE if doc is NULL, filename is NULL, or the file cannot be opened; otherwise the function returns SUCCESS. Notice no error message is generated if the file cannot be opened. 3.2 Method of operation Your 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_interface user_interface filename If the command line has more than one argument (excluding the executable name), the program prints the following usage message to standard error, and exits with exit code EX_USAGE 1. Usage: user_interface Usage: user_interface If there is no file specified when the program is started, the program reads its data from standard input. The program displays a prompt (represented by >) after which commands will be entered. If a file is named, 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 ”FILENAME cannot be opened.”, where FILENAME represents the file name. The program then exits with the exit code EX_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 put your program in a file named user_interface.c. This program will include document.h (the version provided for this project and not the one from project 2). 3.3 File format 3.3.1 Valid Lines An input file (or input coming from standard input) contains multiple lines with commands, and the com- mands are executed in the order they are encountered. No valid line can be more than 1024 characters (includ- ing the 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 characters 3. 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 lines add_paragraph_after 0 add_line_after 1 0 *first line of the document 1This and the other exit codes beginning with EX mentioned here are all obtained by including in your C program file. 2 add_line_after 1 1 *second line of the document # let’s print it print_document quit Valid commands must follow one of the formats specified in Section 3.4 below. 3.3.2 Invalid Lines/Commands If your program encounters an invalid line it should print the message ”Invalid Command” to the standard output. Make sure you print to the standard output and not to the standard error. An invalid line includes not only an invalid command, but a command without the expected values. For example, the add paragraph after command 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 Commands Unless output is associated with a command, the successful execution of a command will not generate any confirmation message (similar to successful execution of commands in Unix). If a command cannot be succes- fully executed (ie, returns FAILURE), 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 a command. A blank line (as defined above) and a comment will be ignored (no processing). When a comment or 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 also terminate when the end of file is seen. The commands quit or exit need not be present in a file. 1. add_paragraph_after PARAGRAPH_NUMBER Adds a paragraph to the document. The ”Invalid Command” message is generated when: a. PARAGRAPH NUMBER does not represent a number b. PARAGRAPH NUMBER is a negative value c. PARAGRAPH NUMBER is missing d. Additional information is provided after the PARAGRAPH NUMBER If the command cannot be successfully executed, the message ”add paragraph after failed” is generated. 2. add_line_after PARAGRAPH_NUMBER LINE_NUMBER * LINE Adds a line after the line with the specified line number. The line to add appears after the * character. The ”Invalid Command” message is generated when: a. PARAGRAPH NUMBER does not represent a number b. PARAGRAPH NUMBER is a negative value or 0 c. PARAGRAPH NUMBER is missing d. LINE NUMBER does not represent a number e. LINE NUMBER is a negative value f. LINE NUMBER is missing g. * is missing If the command cannot be successfully executed, the message ”add line after failed” is generated. 3 3. print_document Prints the document information (print docume
nt function output). The ”Invalid Command” message is generated if any data appears after print document. 4. quit Exits the user interface. The ”Invalid Command” message is generated if any data appears after quit. 5. exit Exits the user interface. The ”Invalid Command” message is generated if any data appears after exit. 6. append_line PARAGRAPH_NUMBER * LINE Appends a line to the specified paragraph. The line to add appears after the * character. The ”Invalid Command” message is generated if: a. PARAGRAPH NUMBER does not represent a number b. PARAGRAPH NUMBER is a negative value or 0 c. PARAGRAPH NUMBER is missing d. * is missing If the command cannot be successfully executed, the message ”append line failed” is generated. 7. remove_line PARAGRAPH_NUMBER LINE_NUMBER Removes the specified line from the paragraph. The ”Invalid Command” message is generated if: a. PARAGRAPH NUMBER does not represent a number b. PARAGRAPH NUMBER is a negative value or 0 c. PARAGRAPH NUMBER is missing d. LINE NUMBER does not represent a number e. LINE NUMBER is a negative value or 0 f. LINE NUMBER is missing g. Any data appears after the line number If the command cannot be successfully executed, the message ”remove line failed” is generated. 8. load_file FILENAME Loads the specified file into the current document. The ”Invalid Command” message will be generated if: a. FILENAME is missing b. Any data appears after FILENAME If the command cannot be successfully executed, the message ”load file failed” is generated. 9. replace_text “TARGET” “REPLACEMENT” Replaces the string ”TARGET” with ”REPLACEMENT”. The ”Invalid Command” message is generated if: a. Both ”TARGET” and ”REPLACEMENT” are missing b. Only ”TARGET” is provided For this command, assume that if ”TARGET” and ”REPLACEMENT” are present there is no additional data after ”REPLACEMENT”. If the command cannot be successfully executed, the message ”replace text failed” is generated. 4 10. highlight_text “TARGET” Highlights the string ”TARGET”. The ”Invalid Command” message is generated if ”TARGET” is miss- ing. For this command, assume that if ”TARGET” is present there is no additional data after it. Notice no fail message is associated with this command; either the text was highlighted or not. 11. remove_text “TARGET” Removes the string ”TARGET”. The ”Invalid Command” message is generated if ”TARGET” is missing. For this command, assume that if ”TARGET” is present there is no additional data after it. Notice no fail message is associated with this command; either a deletion takes place or not. 12. save_document FILENAME Saves the curent document to the specified file. The ”Invalid Command” message is generated if: a. FILENAME is missing. b. Any data appears after the filename. If the command cannot be successfully executed, the message ”save document failed” is generated. 13. reset_document Resets the curent document. The ”Invalid Command” message is generated if any data appears after reset document. Notice no fail message will be associated with reset document. 3.5 Important Points and Hints 1. Data should only be allocated statically. Do not use malloc(), etc. 2. Do not use perror to generate error messages; use fprintf and stderr instead. 3. IMPORTANT: Do not use memset, strtok, strtok r, memcpy in this project. 4. IMPORTANT. Do not use regular expressions for this project; if you do you will lose at least 30 points. Regular expressions can be used in the format string of a scanf statement in order to recognize string 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. Assume a filename does 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 is not removed (paragraph count stays the same). 9. The atoi function returns 0 when the provided string does not represent an integer. Keep this in mind if you use this function. 10. Remember that breaking down the desired computation into functions allows you to control the com- plexity of your code. Think of functions you can implement that would simplify your implementation and testing process. 5 4 Grading Criteria Your 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 grading For 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 UMD Directory 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 Submission You can submit your project by executing in your project directory the submit command. 6 Academic Integrity Please see the syllabus for project rules and academic integrity information. All programming assignments in this 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. 6

admin

Author admin

More posts by admin