const char * fs_mimetype_get_file_extension_from_filename(const char *filename) { int err; unsigned int i, cnt, len; char buff[1024], **tab = NULL; if (filename == NULL || strlen(filename) == 0 || strlen(filename) > 1024) return (ERR_PARAM); if ((err = str_strip(filename, " \t\n\r", (char *)&buff)) != ERR_OK) return (err); if ((err = str_split(filename, ".", &cnt, &tab)) != ERR_OK) return (err); if (cnt > 1) { len = strlen(tab[cnt -1]); strncpy(&buff, (const char *)tab[cnt -1], len + 1); buff[len] = '\0'; } else *buff = '\0'; strs_free(tab); return ((const char *)buff); }
/* <Pagination> * <MedlinePgn>12111-6</MedlinePgn> * </Pagination> */ static int medin_pagination( xml *node, fields *info ) { int i, fstatus, status; str sp, ep; char *p, *pp; if ( xml_tag_matches( node, "MedlinePgn" ) && node->value.len ) { strs_init( &sp, &ep, NULL ); p = str_cpytodelim( &sp, xml_value_cstr( node ), "-", 1 ); if ( str_memerr( &sp ) ) return BIBL_ERR_MEMERR; if ( str_has_value( &sp ) ) { fstatus = fields_add( info, "PAGES:START", str_cstr( &sp ), 1 ); if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR; } (void) str_cpytodelim( &ep, p, "", 0 ); if ( str_memerr( &ep ) ) return BIBL_ERR_MEMERR; if ( str_has_value( &ep ) ) { if ( sp.len > ep.len ) { for ( i=sp.len-ep.len; i<sp.len; ++i ) sp.data[i] = ep.data[i-sp.len+ep.len]; pp = sp.data; } else pp = ep.data; fstatus = fields_add( info, "PAGES:STOP", pp, 1 ); if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR; } strs_free( &sp, &ep, NULL ); } if ( node->down ) { status = medin_pagination( node->down, info ); if ( status!=BIBL_OK ) return status; } if ( node->next ) { status = medin_pagination( node->next, info ); if ( status!=BIBL_OK ) return status; } return BIBL_OK; }