1 /*
2  * Tlf - contest logging program for amateur radio operators
3  * Copyright (C) 2001-2002-2003 Rein Couperus <pa0rct@amsat.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 /* ------------------------------------------------------------
20  *        Write parameter file to disk
21  *
22  *--------------------------------------------------------------*/
23 
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 
30 #include "background_process.h"
31 #include "cw_utils.h"
32 #include "err_utils.h"
33 #include "globalvars.h"
34 #include "tlf.h"
35 #include "tlf_curses.h"
36 
37 /* write a .paras file */
writeparas_file(void)38 int writeparas_file(void) {
39 
40     extern char call[];
41     extern char message[][80];
42     extern const char headerline[];
43     extern char logfile[];
44     extern char whichcontest[];
45     extern int shortqsonr;
46     extern char para_word[];
47     extern int cluster;
48     extern int searchflg;
49     extern int demode;
50     extern int contest;
51     extern int announcefilter;
52     extern int showscore_flag;
53     extern int cqdelay;
54     extern int trxmode;
55 
56     FILE *fp;
57     int i;
58 
59     if (strlen(call) <= 3) {
60 	TLF_LOG_WARN("Cannot write parameters file: data corrupt... ");
61 	return (-1);
62     }
63 
64     if ((fp = fopen(".paras", "w")) == NULL) {
65 	TLF_LOG_ERR("writeparas.c: Error opening file.");
66     }
67     fputs("# Call  ----------------------------------\n", fp);
68     fputs(call, fp);
69     fputs("# Messages  F1...F12 ---------------------\n", fp);
70 
71     for (i = 0; i <= 13; i++) {
72 	if (i == 12)
73 	    fputs("# TU message S&P mode---------------------\n", fp);
74 	if (i == 13)
75 	    fputs("# TU  message CQ mode---------------------\n", fp);
76 	fputs(message[i], fp);
77     }
78 
79     fputs("# Digi Messages  F1...F12 ---------------------\n", fp);
80 
81     for (i = 0; i <= 13; i++) {
82 	if (i == 12)
83 	    fputs("# TU message S&P mode---------------------\n", fp);
84 	if (i == 13)
85 	    fputs("# TU  message CQ mode---------------------\n", fp);
86 	fputs(digi_message[i], fp);
87     }
88 
89     fputs("# Info for top status line----------------\n", fp);
90 
91     fputs(headerline, fp);
92 
93     fputs("# Logfile--------------------\n", fp);
94 
95     fputs(logfile, fp);
96     fputs("\n", fp);
97 
98     fputs("# Contest--------------------\n", fp);
99 
100     fputs(whichcontest, fp);
101     fputs("\n", fp);
102 
103     fputs("# Parameters--don't change----\n", fp);
104 
105     if (shortqsonr == 1)
106 	para_word[0] = 'S';	/* short */
107     else
108 	para_word[0] = 'L';	/* long  */
109 
110     if (cluster == 0)
111 	para_word[1] = 'O';	/* OFF */
112     else if (cluster == 1)
113 	para_word[1] = 'M';	/* MAP */
114     else if (cluster == 2)
115 	para_word[1] = 'S';	/* SPOTS  */
116     else if (cluster == 3)
117 	para_word[1] = 'A';	/* All  */
118 
119     if (searchflg == 1)
120 	para_word[2] = 'D';	/* DISPLAY */
121     else
122 	para_word[2] = 'N';	/* NO DISPLAY */
123 
124     if (demode == 1)
125 	para_word[3] = 'D';	/* DE mode on */
126     else
127 	para_word[3] = 'N';	/*  DE mode off */
128 
129     if (contest == 1)
130 	para_word[4] = 'C';	/* contest  mode */
131     else
132 	para_word[4] = 'G';	/* general qso mode */
133 
134     if (announcefilter == 1)
135 	para_word[5] = 'F';	/* filter  on  */
136     else
137 	para_word[5] = 'N';	/* off */
138 
139     if (showscore_flag == 0)
140 	para_word[6] = 'N';	/* No score window */
141     else
142 	para_word[6] = 'S';	/* show score window */
143 
144     para_word[7] = 48 + speed;
145 
146     if (cqdelay > 0 && cqdelay < 23)
147 	para_word[8] = 48 + cqdelay;
148 
149     if (trxmode == CWMODE)	/* use fifo for cw output */
150 	para_word[9] = 'C';
151     else
152 	para_word[9] = 'P';
153 
154     para_word[10] = '\n';
155     para_word[11] = '\0';
156 
157     fputs(para_word, fp);
158 
159     fclose(fp);
160 
161     return (0);
162 }
163 
164 
165 /* write .paras fiel with background thread stopped */
writeparas(void)166 int writeparas(void) {
167     int result;
168 
169     stop_background_process();
170     result = writeparas_file();
171     start_background_process();
172     return result;
173 }
174 
175