1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*
* title.c
*
* process titles into title/subtitle pairs for MODS
*
* Copyright (c) Chris Putnam 2004-2009
*
* Source code released under the GPL
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "newstr.h"
#include "fields.h"
#include "title.h"
#include "is_ws.h"
void
title_process( fields *info, char *tag, char *data, int level,
unsigned char nosplittitle )
{
newstr title, subtitle;
char *p, *q;
newstr_init( &title );
newstr_init( &subtitle );
if ( nosplittitle ) q = NULL;
else {
q = strstr( data, ": " );
if ( !q ) q = strstr( data, "? " );
}
if ( !q ) newstr_strcpy( &title, data );
else {
p = data;
while ( p!=q ) newstr_addchar( &title, *p++ );
if ( *q=='?' ) newstr_addchar( &title, '?' );
q++;
q = skip_ws( q );
while ( *q ) newstr_addchar( &subtitle, *q++ );
}
if ( strncasecmp( "SHORT", tag, 5 ) ) {
if ( title.len>0 )
fields_add( info, "TITLE", title.data, level );
if ( subtitle.len>0 )
fields_add( info, "SUBTITLE", subtitle.data, level );
} else {
if ( title.len>0 )
fields_add( info, "SHORTTITLE", title.data, level );
/* no SHORT-SUBTITLE! */
}
newstr_free( &subtitle );
newstr_free( &title );
}
|