1 /*
2    Copyright (c) 2000-2002 Perry Rapp
3    "The MIT license"
4    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 */
8 /*==============================================================
9  * dispfmt.c -- Code to reformat dates & places for user preferences
10  *  (for use in reports and/or GUI)
11  *============================================================*/
12 
13 #include "llstdlib.h"
14 #include "gedcom.h"
15 #include "lloptions.h"
16 #include "date.h"
17 
18 /*********************************************
19  * global/exported variables
20  *********************************************/
21 
22 struct tag_rfmt disp_long_rfmt; /* reformatting used for display long forms */
23 struct tag_rfmt disp_shrt_rfmt; /* reformatting used for display short forms */
24 
25 
26 /*********************************************
27  * local function prototypes
28  *********************************************/
29 
30 /* alphabetical */
31 static STRING disp_long_format_date(STRING date);
32 static STRING disp_shrt_format_date(STRING date);
33 static STRING disp_shrt_format_plac(STRING plac);
34 
35 /*********************************************
36  * local function definitions
37  * body of module
38  *********************************************/
39 
40 /*===============================================
41  * init_disp_reformat -- Initialize reformatting for display
42  * Set up format descriptions for both long & short display forms
43  * Created: 2001/07/12 (Perry Rapp)
44  *=============================================*/
45 void
init_disp_reformat(void)46 init_disp_reformat (void)
47 {
48 	/* Set up long formats */
49 	memset(&disp_long_rfmt, 0, sizeof(disp_long_rfmt));
50 	disp_long_rfmt.rfmt_date = &disp_long_format_date;
51 	disp_long_rfmt.rfmt_plac = 0; /* use place as is */
52 	disp_long_rfmt.combopic = "%1, %2";
53 	/* Set up short formats */
54 	memset(&disp_shrt_rfmt, 0, sizeof(disp_shrt_rfmt));
55 	disp_shrt_rfmt.rfmt_date = &disp_shrt_format_date;
56 	disp_shrt_rfmt.rfmt_plac = &disp_shrt_format_plac;
57 	disp_shrt_rfmt.combopic = "%1, %2";
58 }
59 /*===========================================================
60  * disp_long_format_date -- Convert date according to options
61  *=========================================================*/
62 static STRING
disp_long_format_date(STRING date)63 disp_long_format_date (STRING date)
64 {
65 	INT dfmt=0,mfmt=0,yfmt=0,sfmt=0,efmt=0, cmplx;
66 	INT n;
67 	STRING fmts, pic;
68 
69 	if (!date) return NULL;
70 
71 	n = 0;
72 	fmts = getlloptstr("LongDisplayDate", NULL);
73 	if (fmts) {
74 		/* try to use user-specified format */
75 		n = sscanf(fmts, "%ld,%ld,%ld,%ld,%ld,%ld"
76 			, &dfmt, &mfmt, &yfmt, &sfmt, &efmt, &cmplx);
77 	}
78 	if (n != 6) {
79 		dfmt=mfmt=yfmt=sfmt=efmt=cmplx=0;
80 		sfmt=14; /* GEDCOM as is */
81 	}
82 
83 	pic = getlloptstr("LongDisplayDatePic", NULL);
84 	if (pic && pic[0])
85 		set_date_pic(pic);
86 
87 	return do_format_date(date, dfmt, mfmt, yfmt, sfmt, efmt, cmplx);
88 }
89 /*===============================================================
90  * disp_shrt_format_date -- short form of date for display
91  *  This is used for dates in option strings, and in single-line
92  *  descriptions of people (ie, in event summaries).
93  * Created: 2001/10/29 (Perry Rapp)
94  *=============================================================*/
95 static STRING
disp_shrt_format_date(STRING date)96 disp_shrt_format_date (STRING date)
97 {
98 	INT dfmt=0,mfmt=0,yfmt=0,sfmt=0,efmt=0, cmplx;
99 	INT n;
100 	STRING fmts, pic;
101 
102 	if (!date) return NULL;
103 
104 	n = 0;
105 	fmts = getlloptstr("ShortDisplayDate", NULL);
106 	if (fmts) {
107 		/* try to use user-specified format */
108 		n = sscanf(fmts, "%ld,%ld,%ld,%ld,%ld,%ld"
109 			, &dfmt, &mfmt, &yfmt, &sfmt, &efmt, &cmplx);
110 	}
111 	if (n != 6) {
112 		dfmt=mfmt=yfmt=sfmt=cmplx=0;
113 		sfmt=12; /* old style short form -- year only */
114 	}
115 
116 	pic = getlloptstr("ShortDisplayDatePic", NULL);
117 	if (pic && pic[0])
118 		set_date_pic(pic);
119 
120 	return do_format_date(date, dfmt, mfmt, yfmt, sfmt, efmt, cmplx);
121 }
122 /*================================================================
123  * disp_shrt_format_plac -- short form of place for display
124  *  This is used for places in single-line descriptions of people
125  *  (ie, in event summaries).
126  * Created: 2001/10/29 (Perry Rapp)
127  *==============================================================*/
128 static STRING
disp_shrt_format_plac(STRING plac)129 disp_shrt_format_plac (STRING plac)
130 {
131 	if (!plac) return NULL;
132 	return shorten_plac(plac);
133 }
134