讲解:C:CIS2750 GEDCOM ParserR、R

代写实现一个GEDCOM文件格式的解析器。DescriptionIn this assignment, you need to implement a library to parse the GEDCOM files. The link to the format description is posted in the Assignment 1 description and in course notes. Make sure you understand the format before doing the assignment.Your assignment will be graded using an automated test harness, so you must follow all requirements exactly, or you will lose marks.According to the GEDCOM specification, a GEDCOM structure (which we will refer to as a GEDCOM object) contains:Exactly one header. The header must contain exactly one reference to a submitter record.1 or more records of different types. Exactly one trailer record (file terminator)The GEDCOM structure structure is represented by the GEDCOMobject type in GEDCOMparser.h.There are seven different record types. Some may appear multiple times in a GEDCOM file, while others may appear only once per file. For the purposes of this assignment, we will focus on four records:HeaderSubmitterFamilyrecordIndividualrecordThese records are represented by Header, Submitter, Family, and Individual types. All of them are also defined in GEDCOMparser.h.If your parser encounters any other record types, it should simply ignore those records.You’ll notice that each record has its own restrictions. Some are completely flexible, while others must include several parameters. Our types have the most relevant fields as struct members. Other fields will be saved as generic Field records in a list.Multi-line contentThe GEDCOM file consists of individual lines (gedcom_lines in the specification), which can indicate the start of a record, a field in a record, etc.. You’ll notice that long individual line (field) values can be broken into multiple lines using CONT/CONC tags.For example, the GEDCOM 5.5.1 format file contains the following address for the submitter record:0 @5@ SUBM 1 NAME Reldon /Poulson/ 1 ADDR 1900 43rd Street West 2 CONT Billings, MT 68051 1 PHON (406) 555-1232 You must store the complete value in the address field of the Submitter record. So for the above example, the Submitter record would be:- name = "Reldon Poulson" - address = "1900 43rd Street West\nBillings, MT 68051" You will also notice that the format is flexible when it comes to line terminators. Your parser must be able to handle them as specified in the GEDCOM documentation.Required FunctionsGEDCOM functions1GEDCOMerror createGEDCOM(char* fileName, GEDCOMobject** obj);This function does the parsing and allocates a GEDCOM object. It accepts a filename and an address of a GEDCOMobject pointer (i.e. a double pointer). If the file has been parsed successfully, the calendar object is allocated and the information is stored in it.The return type is an GEDCOMerror struct. The type field indicates the error type using the ErrorCode enum, while the line filed indicates the line in the file containing the error (if applicable).If createGEDCOM successfully creates a GEDCOM object, it returns GEDCOMerror with type OK and line -1. However, the parsing can fail for various reasons. In that case, the obj argument is set to NULL and the function returns a struct with the appropriate error code (type) and line number:INV_FILE is returned if there’s a problem with file argument - its null, it’s an empty string, file doesn’t exist or cannot be opened, file doesn’t have the .ged extension, etc. The line field must be -1. If the error is in the file contents, you must use an appropriate error code - see below.INV_GEDCOM is returned if the GEDCOM object itself is invalid. The line field must be -1. For example, you would return this code if:the file is missing the headerthe file is missing the closing tagthe file contains no recordsetc.If the error is in one of the records contained within the GEDCOM object, return a component- specific error code instead (see below).INV_HEADER is returned if the header is present, but is somehow invalid, e.g.Grammar error in header (line = first error that contains invalid grammar). This includes misspelled tags, invalid tags, tags with missing values, missing/incorrect numbers at the start of the line,etc.Header missing a reference to submitter record or any other required filed (line = last line of header)etc.INV_RECORD is returned if some record (other than header) is present, but is somehow invalid. In future assignments, we may expand this to include different error codes for different records - this is normal in iterative development. However, for now we will keep things simple. For example, you would return this code if the file has:Grammar error in record (line = first error that contains invalid grammar). This includes misspelled tags, invalid tags, tags with missing values, missing/incorrect numbers at the start of the line,etc.Record missing a required filed (line = last line of record)etc.OTHER_ERROR is returned if some other, non-GEDCOM error happens (e.g. malloc returns NULL).Note: it is possible that a record in a file is valid, but does not contain one or more fields that we have in our record structs. This is NOT an error. For example, an individual record may be missing the given name. If you encounter this, simply use the empty string as the value for that field. The returned error code should be OK. If a family is missing the husband, set the husband reference to NULL. The returned error code should be OK.If the missing field is actually a collection of things - e.g. children filed in the family record - initialize the list, but keep it empty. The returned error code should be OK.1char* printGEDCOM(const GEDCOMobject* obj);& This function returns a humanly readable string representation of the entire GEDCOM object. Sample output will be added to the assignment description. It must not modify the calendar object in any way. The function must allocate the string dynamically.1void deleteGEDCOM(GEDCOMobject* obj);& This function deallocates the object, including all of its records, lists, etc..1char* printError(GEDCOMerror err);& This function returns a string based on the GEDCOMerror value to make the output of your program easier to understand - i.e. “OK” if err.type is OK, “INV_FILE” or “invalid file” is INV_FILE was passed, &C代写:CIS2750 GEDCOM Parser帮做R编程作业、R课程设计代写留学生ldquo;invalid record (line 20)” if err.type=INV_RECORD and err.line = 20, etc.. The function must allocate the string dynamically.1234Individual* findPerson( const GEDCOMobject* failyRecord, bool (*compare)(const void* first, const void* second), const void* person);& This function is designed to find an individual in a GEDCOM object. We might wish to search by surname (list name), given name+surname, given name+surname+spouse’s name, etc.. The function should modify the GEDCOM object in any way. To allow for this customization, the function takes a custom comparator function and a custom search records. See the function description in GEDCOM parser.h for more details. Return a pointer to the record if found, NULL otherwise.1List getDescendants(const GEDCOMobject* failyRecord, const Individual* person);& This function returns a newly created List of Individual records of all descendants of a given individual. Make sure the list contains copies of the Individual records, rather than the references to actual records. This way, if the user clears the list, he or she does not blow away a portion of our GEDCOM object! Return an empty list of no descendants found.List helper functionsIn addition, you must provide implementations for delete/compare/print functions for every type that we store in a list, i.e.EventIndividualFamilyFieldThe headers for these functions are provided in GEDCOMobject.h. These functions are necessary for the test harness to work correctly.The the print… functions return a newly allocated string with a humanly readable representation of each record.The delete… functions free the records passed to them - freeField() frees a Field argument, freeFamily() - Family argument, etc..The compare… functions must return an int that indicates the relative ordering of the arguments, similar to strcmp():compareEvents() compared by event date. It returns -1 if first argument has an earlier date than second, 0 if dates are the same, 1 if first argument has a later date then second,. If one of the arguments is missing a date, perform lexicographical comparison using the type field.compareIndividuals() performs lexicographical comparison on concatenated givenName and surname fields. Use “,” to separate the fields when concatenating them. For example, if the first argument is the Individual record for Bugs Bunny and the second one is the Individual record for Elmer Fudd, we’re comparing “Bunny, Bugs” to “Fudd, Elmer”.compareFields() performs lexicographical comparison on concatenated tag and value fields, using “” (a single whitespace) as a separator. compareFamilies() compares by the number of family members. It returns -1 if first argument has fewer family members than second, 0 the number is the same, and 1 if first family has more members than second.Additional guidelines and requirementsWhile the above functions are required, you will need to write a number of helper functions. For example, it is strongly recommended that you write additional helpers functions for parsing the file - e.g. parsing each record type.All functions (required and not) must be in a file called GEDCOMparser.c. For your own test purposes, you will also want to code a main program in another .c file that calls your functions with a variety of test cases, but you won’t submit that program. Do not put your main() function in GEDCOMparser.c, or else the test program will fail due to multiple definitions of main(); you will lose marks for that.Applications will #include GEDCOMparser.h in their main program. A basic GEDCOMparser.h has been provided for you. You must customize the file header with your student name and number. However, do not change anything else, or else your utilities will not compile with the test program. Also, do not add any other functions, types, or headers. GEDCOMparser.h is the public “face” of our calendar API. All the helper functions are internal implementation details, and should not be visible to the end user.You are free to create your additional “helper functions” in GEDCOMparser.c, each with its proper function header, if you find some recurring processing steps that you would like to factor out into a single place. They must be in a separate header file, since they are internal to your implementation and not for public users of the utility package. You may put these functions in a separate file called GEDCOMutilities.cYour functions are supposed to be robust. They will be tested with various kinds of invalid data and must detect problems without crashing. However, be sure to follow the specification regarding return values. If your helper functions encounter a problem, they must free all memory and return the appropriate error value.Libraries are written with very specific requirements. They must have a clear public API, and they must communicate errors to the higher-level modules, which will then handle these errors. They should definitely not print their own error messages!Important pointsDo not put any internal helper function headers into GEDCOMparser.hDo not change the given typedefs or function prototypes GEDCOMparser.hDo not submit any main() functionsDo not exit the program from one of the parser functions if a problem is encountered, return an error value.Do not print anything to the command line.Do not assume that your pointers are valid. Always check for NULL pointers before dereferencing them.Submission structure.The submission must have the following directory structure:assign1/ contains the README file and the Makefileassign1/bin should be empty, but this is where the Makefile will place the static lib filesassign1/src contains GEDCOMparser.c, LinkedListAPI.c, and GEDCOMutilities.c (if you need it)assign1/include - contains GEDCOMparser.h, LinkedListAPI.h, and any additional header files that you might have.MakefileYou will need to provide a Makefile with the following functionality:make list creates a static library liblist.a in assign1/binmake tree creates a static library libtree.a in assign1/binmake parser creates a static library libparse.a in assign1/binmake or make all creates liblist.a, libtree.a, and libparse.a in assign1/bin - make clean removes all .o and .a filesEvaluationYour code must compile, run, and have all of the specified functionality implemented. Any compiler errors will result in the automatic grade of zero (0) for the assignment. Make sure you compile and run the assignment on the SoCS Linux server before submitting it - this is where it will be graded.Marks will be deducted for:Incorrect and missing functionalityDeviations from the requirementsRun-time errorsCompiler warningsMemory leaksBad / inconsistent indentationBad variable namesInsufficient commentsFailure to follow submission instructionsI will post a rough marking scheme with grade breakdowns later.SubmissionSubmit your files as a Zip archive using CourseLink. File name must be be A1FirstnameLastname.zip.Late submissions: see course outline for late submission policies.转自:http://ass.3daixie.com/2019011241150235.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,362评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,330评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,247评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,560评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,580评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,569评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,929评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,587评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,840评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,596评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,678评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,366评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,945评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,929评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,165评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,271评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,403评论 2 342

推荐阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 2,805评论 0 0
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,442评论 0 13
  • 1.高中老师管得很严, 有两名同学休息时间玩扑克, 老师把他们叫了去,一人发了一把剪子, 让他们剪碎了,越碎越好,...
    有为少年阅读 584评论 3 19
  • 昨晚做了一夜的梦,梦里的场景大体是这样的:“临近高考,我还在十分认真的复习着,希望能考个好成绩。可是,在考试的当...
    蜕变挣脱阅读 299评论 0 1
  • 好久没梦到他了,之前梦到他,都是不好的。但这次梦到他,醒来带着很幸福的感觉。这是一个幸福的梦,梦中他故意制造惊喜把...
    小雅的呢喃阅读 248评论 0 1