summaryrefslogtreecommitdiff
path: root/support/texlab/crates/bibutils_sys/src/title.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
committerNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
commitb8d4bb76703bcb15578e2b23c5d256532180b894 (patch)
treebedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/crates/bibutils_sys/src/title.c
parent02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff)
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/crates/bibutils_sys/src/title.c')
-rw-r--r--support/texlab/crates/bibutils_sys/src/title.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/support/texlab/crates/bibutils_sys/src/title.c b/support/texlab/crates/bibutils_sys/src/title.c
new file mode 100644
index 0000000000..6b2981442d
--- /dev/null
+++ b/support/texlab/crates/bibutils_sys/src/title.c
@@ -0,0 +1,100 @@
+/*
+ * title.c
+ *
+ * process titles into title/subtitle pairs for MODS
+ *
+ * Copyright (c) Chris Putnam 2004-2019
+ *
+ * Source code released under the GPL version 2
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "str.h"
+#include "fields.h"
+#include "title.h"
+#include "is_ws.h"
+#include "msvc_fix.h"
+
+int
+title_process( fields *info, const char *tag, const char *value, int level, unsigned char nosplittitle )
+{
+ str title, subtitle;
+ const char *p, *q;
+ int status;
+
+ str_init( &title );
+ str_init( &subtitle );
+
+ if ( nosplittitle ) q = NULL;
+ else {
+ q = strstr( value, ": " );
+ if ( !q ) q = strstr( value, "? " );
+ }
+
+ if ( !q ) str_strcpyc( &title, value );
+ else {
+ p = value;
+ while ( p!=q ) str_addchar( &title, *p++ );
+ if ( *q=='?' ) str_addchar( &title, '?' );
+ q++;
+ q = skip_ws( q );
+ while ( *q ) str_addchar( &subtitle, *q++ );
+ }
+
+ if ( strncasecmp( "SHORT", tag, 5 ) ) {
+ if ( str_has_value( &title ) ) {
+ status = fields_add( info, "TITLE", str_cstr( &title ), level );
+ if ( status!=FIELDS_OK ) return 0;
+ }
+ if ( str_has_value( &subtitle ) ) {
+ status = fields_add( info, "SUBTITLE", str_cstr( &subtitle ), level );
+ if ( status!=FIELDS_OK ) return 0;
+ }
+ } else {
+ if ( str_has_value( &title ) ) {
+ status = fields_add( info, "SHORTTITLE", str_cstr( &title ), level );
+ if ( status!=FIELDS_OK ) return 0;
+ }
+ /* no SHORT-SUBTITLE! */
+ }
+
+ str_free( &subtitle );
+ str_free( &title );
+
+ return 1;
+}
+
+/* title_combine()
+ *
+ * Combine a main title and a subtitle into a full title.
+ *
+ * Example:
+ * Main title = "A Clearing in the Distance"
+ * Subtitle = "The Biography of Frederick Law Olmstead"
+ * Full title = "A Clearing in the Distance: The Biography of Frederick Law Olmstead"
+ * Example:
+ * Main title = "What Makes a Good Team Player?"
+ * Subtitle = "Personality and Team Effectiveness"
+ * Full title = "What Makes a Good Team Player? Personality and Team Effectiveness"
+ */
+void
+title_combine( str *fullttl, str *mainttl, str *subttl )
+{
+ str_empty( fullttl );
+
+ if ( !mainttl ) return;
+
+ str_strcpy( fullttl, mainttl );
+
+ if ( subttl ) {
+ if ( str_has_value( mainttl ) ) {
+ if ( mainttl->data[ mainttl->len - 1 ] != '?' && mainttl->data[ mainttl->len - 1] != ':' )
+ str_strcatc( fullttl, ": " );
+ else
+ str_strcatc( fullttl, " " );
+ }
+ str_strcat( fullttl, subttl );
+ }
+}