📄 dvdbookmarks.c
字号:
return -1; } if((cur = xmlNewChild(cur, NULL, "bookmark", NULL)) == NULL) { return -1; } else { xmlDocPtr navdoc = NULL; xmlNodePtr navnode, navcopy; if((navdoc = xmlParseDoc(navstate)) == NULL) { return -1; } if((navnode = xmlDocGetRootElement(navdoc)) == NULL) { return -1; } if((navcopy = xmlDocCopyNode(navnode, bm->doc, 1)) == NULL) { return -1; } xmlFreeDoc(navdoc); xmlAddChild(cur, navcopy); } if(usercomment) { if((xmlNewTextChild(cur, NULL, "usercomment", usercomment)) == NULL) { return -1; } } if(appname && appinfo) { if((cur = xmlNewTextChild(cur, NULL, "appinfo", appinfo)) == NULL) { return -1; } xmlNewProp(cur, "appname", appname); } return 0; }/** * Set the appinfo in a bookmark. * * @param bm Handle from DVDBookmarkOpen. * @param appname The name of your application here, you will * be able to supply application specific data in appinfo. * The appname "common" is used for standardized appinfo that all * players can read/use. * @param appinfo The appinfo data. * If there already is appinfo for the corresponding appname * it will be replaced. * If you pass NULL or a pointer to the empty string "" * the previous appinfo, if any, will be removed. * All char * should point to a nullterminated string. * * @return 0 on success, -1 on failure. */int DVDBookmarkSetAppInfo(DVDBookmark_t *bm, int nr, const char *appname, const char *appinfo){ xmlNodePtr cur; xmlNodePtr cur_bm; if(!bm || !appname) { return -1; } if((cur = xmlDocGetRootElement(bm->doc)) == NULL) { return -1; } cur_bm = get_bookmark(bm->doc, cur, nr); cur = cur_bm; if(cur == NULL) { return -1; } //if there is an appinfo with the same appname already remove it cur = cur->xmlChildrenNode; while(cur != NULL) { xmlNodePtr next = cur->next; if((!xmlStrcmp(cur->name, (const xmlChar *)"appinfo"))) { xmlChar *prop; if((prop = xmlGetProp(cur, "appname")) != NULL) { if(!xmlStrcmp(prop, (const xmlChar *)appname)) { xmlFree(prop); xmlUnlinkNode(cur); xmlFreeNode(cur); } else { xmlFree(prop); } } } cur = next; } cur = cur_bm; if(appinfo && (appinfo[0] != '\0')) { if((cur = xmlNewTextChild(cur, NULL, "appinfo", appinfo)) == NULL) { return -1; } xmlNewProp(cur, "appname", appname); } return 0; }/** * Set the usercomment in a bookmark. * * @param bm Handle from DVDBookmarkOpen. * @param usercomment The comment. * If there already is a usercomment, it will be replaced. * Setting it to NULL or the empty string "" will remove a previous comment. * All char * should point to a nullterminated string. * * @return 0 on success, -1 on failure. */int DVDBookmarkSetUserComment(DVDBookmark_t *bm, int nr, const char *usercomment){ xmlNodePtr cur; xmlNodePtr cur_bm; if(!bm) { return -1; } if((cur = xmlDocGetRootElement(bm->doc)) == NULL) { return -1; } cur_bm = get_bookmark(bm->doc, cur, nr); cur = cur_bm; if(cur == NULL) { return -1; } //if there is a usercomment already remove it cur = cur->xmlChildrenNode; while(cur != NULL) { xmlNodePtr next = cur->next; if((!xmlStrcmp(cur->name, (const xmlChar *)"usercomment"))) { xmlUnlinkNode(cur); xmlFreeNode(cur); } cur = next; } cur = cur_bm; if(usercomment && (usercomment[0] != '\0')) { if((cur = xmlNewTextChild(cur,NULL, "usercomment", usercomment)) == NULL) { return -1; } } return 0; }/** * Remove a bookmark for the current disc. * * @param bm Handle from DVDBookmarkOpen. * @param nr The specific bookmark in the list for this disc. * The nr is the same as in the DVDBookmarkGet function. * The numbering will change once you have removed a bookmark, the numbers * after the removed will decrease in value by one so there are no * gaps. * @return 0 on success, -1 on failure. */int DVDBookmarkRemove(DVDBookmark_t *bm, int nr){ xmlNodePtr cur; if(!bm || !(bm->doc) || (nr < 0)) { return -1; } if((cur = xmlDocGetRootElement(bm->doc)) == NULL) { return -1; } cur = get_bookmark(bm->doc, cur, nr); if(cur == NULL) { return -1; } xmlUnlinkNode(cur); xmlFreeNode(cur); return 0;}/** * Retrieve comment for the current disc. * * @param bm Handle from DVDBookmarkOpen. * @param disccomment This is where a pointer to the disccomment data * will be returned. It will be set if the call is succesfull otherwise * it will be undefined. You need to free() this when you are done with it. * In case nothing is returned it will be set to NULL; * @return 0 on success (though no data may be returned) -1 on failure */int DVDBookmarkGetDiscComment(DVDBookmark_t *bm, char **disccomment){ xmlNodePtr cur; xmlChar *data; if(!bm || !(bm->doc) || !disccomment) { return -1; } if((cur = xmlDocGetRootElement(bm->doc)) == NULL) { return -1; } cur = cur->xmlChildrenNode; while(cur != NULL) { if((!xmlStrcmp(cur->name, (const xmlChar *)"disccomment"))) { if(disccomment != NULL) { data = xmlNodeListGetString(bm->doc, cur->xmlChildrenNode, 1); if(data != NULL) { *disccomment = strdup(data); xmlFree(data); return 0; } } } cur = cur->next; } *disccomment = NULL; return 0;}/** * Set comment for the current disc. * * @param bm Handle from DVDBookmarkOpen. * @param disccomment The disc comment */int DVDBookmarkSetDiscComment(DVDBookmark_t *bm, const char *disccomment){ xmlNodePtr cur, docroot; if(!bm || !(bm->doc) || !disccomment) { return -1; } if((docroot = xmlDocGetRootElement(bm->doc)) == NULL) { return -1; } cur = docroot; cur = cur->xmlChildrenNode; while(cur != NULL) { xmlNodePtr next = cur->next; if((!xmlStrcmp(cur->name, (const xmlChar *)"disccomment"))) { xmlUnlinkNode(cur); xmlFreeNode(cur); } cur = next; } cur = docroot; cur = cur->xmlChildrenNode; if(cur != NULL) { xmlNodePtr newnode; if(((newnode = xmlNewTextChild(docroot, NULL, "disccomment", disccomment))) == NULL) { return -1; } xmlGetNodePath(xmlAddPrevSibling(cur, newnode)); } else { if((xmlNewTextChild(docroot, NULL, "disccomment", disccomment)) == NULL) { return -1; } } return 0;}/** * Save the bookmark list for the current disc to file. * If the list doesn't contain any entries the file will be removed. * * @param bm Handle from DVDBookmarkOpen. * @param compressed If 1 the output file will be compressed and not human * readable. If 0 it will be normal indented text. * 0 is recommended if not disk space is very limited. * DVDBookmarkOpen opens and reads both compressed and uncompressed files. * * @return 0 on success, -1 on failure. */int DVDBookmarkSave(DVDBookmark_t *bm, int compressed){ xmlNodePtr cur; int n; if(!bm || !(bm->filename) || !(bm->doc)) { return -1; } if(compressed) { xmlSetDocCompressMode(bm->doc, 9); } else { xmlSetDocCompressMode(bm->doc, 0); } if(xmlSaveFormatFile(bm->filename, bm->doc, 1) == -1) { return -1; } if((cur = xmlDocGetRootElement(bm->doc)) == NULL) { return -1; } n = 0; cur = cur->xmlChildrenNode; while(cur != NULL) { if((!xmlStrcmp(cur->name, (const xmlChar *)"bookmark"))) { n++; } cur = cur->next; } if(n == 0) { unlink(bm->filename); } return 0;}/** * Close and free memory used for holding the bookmark list. * @param bm The handle to be freed. It cannot be used again. */void DVDBookmarkClose(DVDBookmark_t *bm){ if(!bm) { return; } if(bm->filename) { free(bm->filename); bm->filename = NULL; } if(bm->doc) { xmlFreeDoc(bm->doc); bm->doc = NULL; } free(bm); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -