forked from HeyuX10Automation/heyu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
5591 lines (4925 loc) · 183 KB
/
config.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*----------------------------------------------------------------------------+
| |
| HEYU Configuration |
| Copyright 2002,2003,2004-2008 Charles W. Sullivan |
| |
| |
| As used herein, HEYU is a trademark of Daniel B. Suthers. |
| X10, CM11A, and ActiveHome are trademarks of X-10 (USA) Inc. |
| The author is not affiliated with either entity. |
| |
| Charles W. Sullivan |
| Co-author and Maintainer |
| Greensboro, North Carolina |
| Email ID: cwsulliv01 |
| Email domain: -at- heyu -dot- org |
| |
+----------------------------------------------------------------------------*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include <ctype.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#include <time.h>
#include "x10.h"
#include "process.h"
#include "sun.h"
#include "x10state.h"
extern int line_no, verbose;
extern int i_am_relay, i_am_aux, i_am_state, i_am_monitor;
extern char heyu_path[PATH_LEN + 1];
extern char alt_path[PATH_LEN + 1];
extern char heyu_script[PATH_LEN + 1];
extern long std_tzone;
extern char default_housecode;
extern char heyu_config[PATH_LEN + 1];
extern int fetch_x10state ( void );
extern int fetch_x10state_old ( void );
extern struct x10global_st x10global;
char statefile[PATH_LEN + 1];
char enginelockfile[PATH_LEN + 1];
char auxfile[PATH_LEN + 1];
unsigned int transceive_list[16];
unsigned int ore_ignore[32];
int ore_ignore_size;
unsigned int sec_ignore[32];
int sec_ignore_size;
CONFIG config;
CONFIG *configp = NULL;
enum {
OldAlias, Alias, UserSyn, Launcher, Script, Scene, RFBursts,
/* Directives with multiple instances allowed */
/* must be before 'Separator'. */
Separator,
Tty, TtyAux, HouseCode, ForceAddr,
NewFormat, ScheduleFile, MaxPParms, RcsTemp, StatusTimeout,
SpfTimeout, DispExpMac, AckHails, Mode, ProgramDays,
AsIfDate, AsIfTime, CombineEvents, CompressMacros, FebKluge,
Latitude, Longitude, DawnOption, DuskOption, DawnSubstitute,
DuskSubstitute, MinDawn, MaxDawn, MinDusk, MaxDusk, CheckFiles,
ReportPath, ReplDelay, Ignored, ResvTimers, TrigTag, XrefApp,
MacTerm, AutoChain, ResOverlap, ModuleTypes, LaunchMode,
FunctionMode, LaunchSrc, DefaultModule, ScriptShell, ScriptMode,
LogDir, IsDarkOffset, EnvAliasPrefix, DevType, SunMode, Fix5A,
AutoFetch, PfailUpdate, BitDelay, DefRFBursts, BurstSpacing,
TimerTweak, RFPostDelay, RFFarbDelay, RFFarwDelay, DispRFX, LoopCount,
RestrictDims, StateFmt, /* StateDir, */PfailScript, CM11PostDelay,
StartEngine, IgnoreSilent, NoSwitch, RespoolPerms, SpoolMax,
CheckRILine, RIdisable, SendRetries, ScriptCtrl, Transceive, TransMissp,
RFForward, TransDim, StateCtrl, RFFuncMask, RingCtrl, AuxRepcounts,
AuxMincountRFX, HideUnchg, HideUnchgInactive, ShowChange, DispRFNoise, ArmMaxDelay, DispRawRF, ArmLogic,
InactiveTimeout, HeyuUmask, AutoWait, FullBright, EnginePoll,
RfxTscale, RfxVadscale, RfxBPscale, DispSubdir, RfxComDtrRts, RfxHiBaud,
RfxPowerScale, RfxWaterScale, RfxGasScale, RfxPulseScale, RfxComEnable, RfxComDisable,
LockupCheck, TailPath, RfxJam, DispDmxTemp, SecID16, SecIDPar, LogDateYr,
DmxTscale, OreTscale, OreBPscale, OreWgtscale, OreLowBatt, DispOreAll,
OreChgBitsT, OreChgBitsRH, OreChgBitsBP, OreChgBitsWgt, OreChgBitsDT,
OreDataEntry, OreDispChan, OreID16,
OreDispFcast, LogDateUnix, InactiveTimeoutOre, DispSensorIntv, DateFormat, LockTimeout,
CM11QueryDelay, ElsNumber, ElsVoltage, ElsChgBitsCurr, OreWindscale, OreWindSensorDir,
OreRainRatescale, OreRainTotscale, OreDispBatLvl, OreWindDirMode, OreDispCount,
OreDispBft, OreChgBitsWsp, OreChgBitsWavsp, OreChgBitsWdir, OreChgBitsRrate, OreChgBitsRtot,
OreChgBitsUV, ScanMode, RfxInline,
OwlVoltage, OwlCalibPower, OwlCalibEnergy, OwlChgBitsPower, OwlChgBitsEnergy, OwlDispCount,
ArmRemote, ActiveChange, InactiveHandling, ProcessXmit, ShowFlagsMode,
LaunchPathAppend, LaunchPathPrefix, FixStopStartError, TtyRFXmit, ChkSumTimeout
};
#define CSTP 1 /* Minimal config for stop command */
#define CCAL 2 /* Minimal config for syscheck command */
#define CMLT 4 /* Multiple instances allowed */
#define COVR 8 /* Allow override in sched file */
#define CHLP 16 /* Minimal config for help command */
#define CIGN 32 /* Ignored (usually obsolete) */
#define CHID 64 /* Don't display */
static struct conf {
char *name;
int mintoken;
int maxtoken;
unsigned char isparsed;
unsigned char override; /* Allow override in sched file */
unsigned int flags;
unsigned int switchval;
} command[] = {
{"(_alias_)", 3, 3, 0, 0, CMLT, OldAlias },
{"ALIAS", 3,16, 0, 0, CMLT, Alias },
{"LAUNCHER", 2,-1, 0, 0, CMLT, Launcher},
{"SCRIPT", 2,-1, 0, 0, CMLT, Script },
{"USERSYN", 2,-1, 0, 0, CMLT, UserSyn },
{"SCENE", 2,-1, 0, 0, CMLT, Scene },
{"SECTION", 1,-1, 0, 0, COVR|CMLT, IgnoreSilent},
/* Multiple instances OK for switchval above */
{"TTY", 2, 4, 0, 0, CSTP, Tty },
{"TTY_AUX", 3, 5, 0, 0, CSTP, TtyAux},
{"TTY_RFXMIT", 3, 3, 0, 0, CSTP, TtyRFXmit},
{"HOUSECODE", 2, 2, 0, 0, 0, HouseCode },
{"FORCE_ADDR", 2, 2, 0, 0, 0, ForceAddr },
{"NEWFORMAT", 1, 1, 0, 0, CIGN, Ignored },
{"MACROXREF", 2, 2, 0, 0, CIGN, Ignored },
{"SCHEDULE_FILE", 2, 2, 0, 0, 0, ScheduleFile },
{"MAX_PPARMS", 2, 2, 0, 0, 0, MaxPParms },
{"STATUS_TIMEOUT", 2, 2, 0, 0, 0, StatusTimeout },
{"SPF_TIMEOUT", 2, 2, 0, 0, 0, SpfTimeout },
{"RCS_TEMPERATURE", 2, 2, 0, 0, 0, RcsTemp },
{"RCS_DECODE", 2, 2, 0, 0, 0, RcsTemp },
{"DISPLAY_EXP_MACROS", 2, 2, 0, 0, CIGN, Ignored },
{"ACK_HAILS", 2, 2, 0, 0, 0, AckHails },
{"MODE", 2, 2, 0, 1, COVR, Mode },
{"PROGRAM_DAYS", 2, 2, 0, 1, COVR, ProgramDays },
{"ASIF_DATE", 2, 2, 0, 1, COVR, AsIfDate },
{"ASIF_TIME", 2, 2, 0, 1, COVR, AsIfTime },
{"COMBINE_EVENTS", 2, 2, 0, 1, COVR, CombineEvents },
{"COMPRESS_MACROS", 2, 2, 0, 1, COVR, CompressMacros },
{"FEB_KLUGE", 2, 2, 0, 1, COVR, FebKluge },
{"LATITUDE", 2, 2, 0, 1, COVR, Latitude },
{"LONGITUDE", 2, 2, 0, 1, COVR, Longitude },
{"DAWN_OPTION", 2, 2, 0, 1, COVR, DawnOption },
{"DUSK_OPTION", 2, 2, 0, 1, COVR, DuskOption },
{"DAWN_SUBSTITUTE", 2, 2, 0, 1, COVR|CIGN, Ignored },
{"DUSK_SUBSTITUTE", 2, 2, 0, 1, COVR|CIGN, Ignored },
{"MIN_DAWN", 2, 2, 0, 1, COVR, MinDawn },
{"MAX_DAWN", 2, 2, 0, 1, COVR, MaxDawn },
{"MIN_DUSK", 2, 2, 0, 1, COVR, MinDusk },
{"MAX_DUSK", 2, 2, 0, 1, COVR, MaxDusk },
{"WRITE_CHECK_FILES", 2, 2, 0, 1, COVR, CheckFiles },
{"REPORT_PATH", 2, 2, 0, 1, COVR, ReportPath },
{"REPL_DELAYED_MACROS", 2, 2, 0, 1, COVR, ReplDelay },
{"RESERVED_TIMERS", 2, 2, 0, 1, COVR|CHID, ResvTimers }, /* WIP */
{"TRIGGER_TAG", 2, 2, 0, 1, COVR|CIGN, Ignored },
{"XREF_APPEND", 2, 2, 0, 1, COVR|CIGN, Ignored },
{"MACTERM", 2, 2, 0, 1, COVR, MacTerm }, /* WIP */
{"RESOLVE_OVERLAP", 2, 2, 0, 1, COVR, ResOverlap },
{"DAWNDUSK_DEF", 2, 3, 0, 1, COVR, SunMode },
{"SCRIPT_MODE", 2, 2, 0, 0, 0, ScriptMode },
{"SCRIPT_SHELL", 2, 2, 0, 0, 0, ScriptShell },
{"LAUNCH_SOURCE", 2, 6, 0, 0, 0, LaunchSrc },
{"DEFAULT_MODULE", 2, 2, 0, 0, 0, DefaultModule },
{"LOG_DIR", 2, 3, 0, 0, 0, LogDir },
{"DISPLAY_SUBDIR", 2, 2, 0, 0, 0, DispSubdir },
{"ISDARK_OFFSET", 2, 2, 0, 0, 0, IsDarkOffset },
{"ENV_ALIAS_PREFIX", 2, 2, 0, 0, 0, EnvAliasPrefix },
{"FIX_5A", 2, 2, 0, 0, CHID, Fix5A },
{"AUTOFETCH", 2, 2, 0, 0, 0, AutoFetch },
{"POWERFAIL_UPDATE", 2, 2, 0, 0, 0, PfailUpdate },
{"CM17A_BIT_DELAY", 2, 2, 0, 0, 0, BitDelay },
{"DEF_RF_BURSTS", 2, 2, 0, 0, 0, DefRFBursts },
{"RF_BURSTS", 3,21, 0, 0, 0, RFBursts},
{"TIMER_LOOPCOUNT", 2, 2, 0, 0, 0, LoopCount },
{"RF_BURST_SPACING", 2, 2, 0, 0, 0, BurstSpacing },
{"RF_TIMER_TWEAK", 2, 2, 0, 0, 0, TimerTweak },
{"RF_POST_DELAY", 2, 2, 0, 0, 0, RFPostDelay },
{"RF_FARB_DELAY", 2, 2, 0, 0, 0, RFFarbDelay },
{"RF_FARW_DELAY", 2, 2, 0, 0, 0, RFFarwDelay },
{"DISPLAY_RF_XMIT", 2, 2, 0, 0, 0, DispRFX },
{"RESTRICT_DIMS", 2, 2, 0, 0, 0, RestrictDims },
{"STATE_FORMAT", 2, 2, 0, 0, 0, StateFmt },
{"RELAY_POWERFAIL_SCRIPT", 2,-1, 0, 0, CHID, PfailScript},
{"CM11_POST_DELAY", 2, 2, 0, 0, 0, CM11PostDelay},
{"START_ENGINE", 2, 2, 0, 0, 0, StartEngine},
{"RF_NOSWITCH", 2, 2, 0, 0, 0, NoSwitch},
{"RESPOOL_PERMISSIONS", 2, 2, 0, 0, CHID, RespoolPerms},
{"SPOOLFILE_MAX", 2, 2, 0, 0, 0, SpoolMax},
{"CHECK_RI_LINE", 2, 2, 0, 0, 0, CheckRILine},
{"RI_DISABLE", 2, 2, 0, 0, 0, RIdisable},
{"SEND_RETRIES", 2, 2, 0, 0, 0, SendRetries},
{"TRANSCEIVE", 2, 3, 0, 0, 0, Transceive},
{"TRANSCIEVE", 2, 3, 0, 0, CHID, TransMissp},
{"RFFORWARD", 2, 3, 0, 0, 0, RFForward},
{"TRANS_DIMLEVEL", 2, 2, 0, 0, 0, TransDim},
{"SCRIPT_CTRL", 2, 2, 0, 0, 0, ScriptCtrl},
{"STATE_CTRL", 2, 2, 0, 0, 0, StateCtrl},
{"RING_CTRL", 2, 2, 0, 0, 0, RingCtrl},
{"RF_FUNCMASK", 2,-1, 0, 0, 0, RFFuncMask},
{"AUX_REPCOUNTS", 4, 4, 0, 0, 0, AuxRepcounts},
{"AUX_MINCOUNT_RFX", 2, 2, 0, 0, 0, AuxMincountRFX},
{"HIDE_UNCHANGED", 2, 2, 0, 0, 0, HideUnchg},
{"HIDE_UNCHANGED_INACTIVE", 2, 2, 0, 0, 0, HideUnchgInactive},
{"SHOW_CHANGE", 2, 2, 0, 0, 0, ShowChange},
{"DISPLAY_RF_NOISE", 2, 2, 0, 0, 0, DispRFNoise},
{"ARM_MAX_DELAY", 2, 2, 0, 0, 0, ArmMaxDelay},
{"DISPLAY_RAW_RF", 2, 2, 0, 0, 0, DispRawRF},
{"ARM_LOGIC", 2, 2, 0, 0, 0, ArmLogic},
{"INACTIVE_TIMEOUT", 2, 2, 0, 0, 0, InactiveTimeout},
{"HEYU_UMASK", 2, 2, 0, 0, 0, HeyuUmask},
{"AUTO_WAIT", 2, 2, 0, 0, 0, AutoWait},
{"FULL_BRIGHT", 2, 2, 0, 0, 0, FullBright},
{"ENGINE_POLL", 2, 2, 0, 0, 0, EnginePoll},
{"DMX_TSCALE", 2, 3, 0, 0, 0, DmxTscale},
{"ORE_LOWBATTERY", 2, 2, 0, 0, 0, OreLowBatt},
{"ORE_TSCALE", 2, 3, 0, 0, 0, OreTscale},
{"ORE_BPSCALE", 3, 4, 0, 0, 0, OreBPscale},
{"ORE_WGTSCALE", 3, 3, 0, 0, 0, OreWgtscale},
{"ORE_WINDSCALE", 3, 3, 0, 0, 0, OreWindscale},
{"ORE_WINDSENSORDIR", 2, 2, 0, 0, 0, OreWindSensorDir},
{"ORE_WINDDIR_MODE", 2, 2, 0, 0, 0, OreWindDirMode},
{"ORE_RAINRATESCALE", 3, 3, 0, 0, 0, OreRainRatescale},
{"ORE_RAINTOTSCALE", 3, 3, 0, 0, 0, OreRainTotscale},
{"RFX_TSCALE", 2, 3, 0, 0, 0, RfxTscale},
{"RFX_VADSCALE", 3, 4, 0, 0, 0, RfxVadscale},
{"RFX_BPSCALE", 3, 4, 0, 0, 0, RfxBPscale},
{"RFXCOM_DTR_RTS", 2, 2, 0, 0, 0, RfxComDtrRts},
{"RFXCOM_HIBAUD", 2, 2, 0, 0, CHID, RfxHiBaud},
{"RFX_POWERSCALE", 3, 3, 0, 0, 0, RfxPowerScale},
{"RFX_WATERSCALE", 3, 3, 0, 0, 0, RfxWaterScale},
{"RFX_GASSCALE", 3, 3, 0, 0, 0, RfxGasScale},
{"RFX_PULSESCALE", 3, 3, 0, 0, 0, RfxPulseScale},
{"RFXCOM_ENABLE", 2, 4, 0, 0, 0, RfxComEnable},
{"RFXCOM_DISABLE", 2,16, 0, 0, 0, RfxComDisable},
{"LOCKUP_CHECK", 2, 2, 0, 0, CHID, LockupCheck},
{"TAILPATH", 2, 2, 0, 0, 0, TailPath},
{"SUPPRESS_RFXJAM", 2, 2, 0, 0, 0, RfxJam},
{"DISPLAY_DMXTEMP", 2, 2, 0, 0, 0, DispDmxTemp},
{"SECURID_16", 2, 2, 0, 0, 0, SecID16},
{"SECURID_PARITY", 2, 2, 0, 0, 0, SecIDPar},
{"LOGDATE_YEAR", 2, 2, 0, 0, 0, LogDateYr},
{"DISPLAY_ORE_ALL", 2, 2, 0, 0, 0, DispOreAll},
{"ORE_CHGBITS_T", 2, 2, 0, 0, 0, OreChgBitsT},
{"ORE_CHGBITS_RH", 2, 2, 0, 0, 0, OreChgBitsRH},
{"ORE_CHGBITS_BP", 2, 2, 0, 0, 0, OreChgBitsBP},
{"ORE_CHGBITS_WGT", 2, 2, 0, 0, 0, OreChgBitsWgt},
{"ORE_CHGBITS_DT", 2, 2, 0, 0, 0, OreChgBitsDT},
{"ORE_CHGBITS_WSP", 2, 2, 0, 0, CIGN, Ignored},
{"ORE_CHGBITS_WINDSP", 2, 2, 0, 0, 0, OreChgBitsWsp},
{"ORE_CHGBITS_WAVSP", 2, 2, 0, 0, CIGN, Ignored},
{"ORE_CHGBITS_WINDAVSP", 2, 2, 0, 0, 0, OreChgBitsWavsp},
{"ORE_CHGBITS_WDIR", 2, 2, 0, 0, CIGN, Ignored},
{"ORE_CHGBITS_WINDDIR", 2, 2, 0, 0, 0, OreChgBitsWdir},
{"ORE_CHGBITS_RRATE", 2, 2, 0, 0, CIGN, Ignored},
{"ORE_CHGBITS_RAINRATE", 2, 2, 0, 0, 0, OreChgBitsRrate},
{"ORE_CHGBITS_RTOT", 2, 2, 0, 0, CIGN, Ignored},
{"ORE_CHGBITS_RAINTOT", 2, 2, 0, 0, 0, OreChgBitsRtot},
{"ORE_CHGBITS_UV", 2, 2, 0, 0, 0, OreChgBitsUV},
{"ORE_DATA_ENTRY", 2, 2, 0, 0, 0, OreDataEntry},
{"ORE_DISPLAY_CHAN", 2, 2, 0, 0, 0, OreDispChan},
{"ORE_DISPLAY_BATLVL", 2, 2, 0, 0, 0, OreDispBatLvl},
{"ORE_DISPLAY_RAW", 2, 2, 0, 0, CIGN, Ignored},
{"ORE_DISPLAY_COUNT", 2, 2, 0, 0, 0, OreDispCount},
{"ORE_DISPLAY_BEAUFORT", 2, 2, 0, 0, 0, OreDispBft},
{"ORE_ID_16", 2, 2, 0, 0, 0, OreID16},
{"ORE_DISPLAY_FCAST", 2, 2, 0, 0, 0, OreDispFcast},
{"LOGDATE_UNIX", 2, 2, 0, 0, 0, LogDateUnix},
{"DISPLAY_SENSOR_INTV", 2, 2, 0, 0, 0, DispSensorIntv},
{"DATE_FORMAT", 2, 3, 0, 1, COVR, DateFormat},
{"LOCK_TIMEOUT", 2, 2, 0, 0, 0, LockTimeout},
{"CM11A_QUERY_DELAY", 2, 2, 0, 0, 0, CM11QueryDelay},
{"ELS_VOLTAGE", 2, 2, 0, 0, 0, ElsVoltage},
{"ELS_CHGBITS_CURR", 2, 2, 0, 0, 0, ElsChgBitsCurr},
{"LAUNCHER_SCANMODE", 2, 2, 0, 0, 0, ScanMode},
{"RFXMETER_SETUP_INLINE", 2, 2, 0, 0, 0, RfxInline},
{"OWL_VOLTAGE", 2, 2, 0, 0, 0, OwlVoltage},
{"OWL_CALIB_POWER", 2, 2, 0, 0, 0, OwlCalibPower},
{"OWL_CALIB_ENERGY", 2, 2, 0, 0, 0, OwlCalibEnergy},
{"OWL_CHGBITS_POWER", 2, 2, 0, 0, 0, OwlChgBitsPower},
{"OWL_CHGBITS_ENERGY", 2, 2, 0, 0, 0, OwlChgBitsEnergy},
{"OWL_DISPLAY_COUNT", 2, 2, 0, 0, 0, OwlDispCount},
{"ARM_REMOTE", 2, 2, 0, 0, 0, ArmRemote},
// {"ACTIVE_CHANGE", 2, 2, 0, 0, CIGN, Ignored},
{"INACTIVE_HANDLING", 2, 2, 0, 0, 0, InactiveHandling},
{"PROCESS_XMIT", 2, 2, 0, 0, 0, ProcessXmit},
{"SHOW_FLAGS_MODE", 2, 2, 0, 0, 0, ShowFlagsMode},
{"LAUNCHPATH_APPEND", 2, 2, 2, 0, 0, LaunchPathAppend},
{"LAUNCHPATH_PREFIX", 2, 2, 2, 0, 0, LaunchPathPrefix},
{"FIX_STOPSTART_ERROR", 2, 2, 0, 1, COVR, FixStopStartError},
// {"CHKSUM_TIMEOUT", 2, 2, 0, 0, 0, ChkSumTimeout},
#if 0
{"ELS_NUMBER", 2, 2, 0, 0, 0, ElsNumber},
#endif
#if 0
{"INACTIVE_TIMEOUT_ORE", 2, 2, 0, 0, 0, InactiveTimeoutOre}, /* WIP */
#endif
};
int ncommands = ( sizeof(command)/sizeof(struct conf) );
/* Dawn/Dusk options */
static struct ddopt {
char *label;
unsigned char value;
} dd_option[] = {
{"FIRST", FIRST },
{"EARLIEST", EARLIEST },
{"LATEST", LATEST },
{"AVERAGE", AVERAGE },
{"MEDIAN", MEDIAN },
};
int nddopt = ( sizeof(dd_option)/sizeof(struct ddopt) );
/* Launch source options - set default sources of signal */
/* permitted to launch a script. */
static struct lsopt {
char *label;
unsigned int value;
} ls_option[] = {
{"SNDC", SNDC }, /* Sent from command line */
{"SNDM", SNDM }, /* Sent from macro executed by Timer */
{"SNDT", SNDT }, /* Sent from macro executed by Trigger */
{"SNDP", SNDP }, /* Sent from a relay powerfail script */
{"SNDS", SNDS }, /* Sent from a script */
{"RCVI", RCVI }, /* Received from the interface */
{"RCVT", RCVT }, /* Trigger which executed a macro */
{"SNDA", SNDA }, /* Transceived by aux daemon */
{"RCVA", RCVA }, /* Received via sptty from aux daemon */
{"ANYSRC", LSALL }, /* Any of the above (SNDS and SNDP not included!) */
{"NOSRC", LSNONE }, /* No sources are the default */
};
int nlsopt = ( sizeof(ls_option)/sizeof(struct lsopt) );
/* CM17A function labels. Note: CONFIG.rf_bursts[] in */
/* process.h must be at least the size of nrflabels below */
static struct cm17a_label {
char *label;
unsigned char subcode;
} rf_label[] = {
{"falloff", 0 },
{"flightson", 1 },
{"fon", 2 },
{"foff", 3 },
{"fdim", 4 },
{"fbright", 5 },
{"flightsoff", 6 },
{"_", 7 },
{"_", 8 },
{"farb", 9 },
{"farw", 10 },
};
int nrflabels = ( sizeof(rf_label)/sizeof(struct cm17a_label) );
/*---------------------------------------------------------------------+
| Reset the isparsed flags in the conf struct array. |
+---------------------------------------------------------------------*/
void reset_isparsed_flags ( void )
{
int j;
for ( j = 0; j < ncommands; j++ )
command[j].isparsed = 0;
return;
}
/*---------------------------------------------------------------------+
| Return 1 if all valid characters within alias label, otherwise 0 |
+---------------------------------------------------------------------*/
int is_valid_alias_label ( char *label, char **sp )
{
*sp = label;
while ( **sp ) {
if ( isalnum((int)(**sp)) || strchr("-_.", **sp) ) {
(*sp)++;
continue;
}
return 0;
}
return 1;
}
/*---------------------------------------------------------------------+
| Initialize the CONFIG structure with default values. |
+---------------------------------------------------------------------*/
void initialize_config ( void )
{
char *sp1;
int j;
/* Load default configuration values */
configp->read_flag = 0;
configp->mode = DEF_MODE;
(void) strncpy2(configp->schedfile, DEF_SCHEDFILE, sizeof(config.schedfile) - 1);
configp->asif_date = -1;
configp->asif_time = -1;
configp->program_days_in = DEF_PROGRAM_DAYS;
configp->program_days = DEF_PROGRAM_DAYS;
configp->combine_events = DEF_COMBINE_EVENTS;
configp->compress_macros = DEF_COMPRESS_MACROS;
configp->feb_kluge = DEF_FEB_KLUGE;
configp->housecode = DEF_HOUSECODE;
configp->force_addr = DEF_FORCE_ADDR;
configp->loc_flag = 0;
configp->dawn_option = DEF_DAWN_OPTION;
configp->dusk_option = DEF_DUSK_OPTION;
configp->dawn_substitute = DEF_DAWN_SUBSTITUTE;
configp->dusk_substitute = DEF_DUSK_SUBSTITUTE;
configp->min_dawn = DEF_MIN_DAWN;
configp->max_dawn = DEF_MAX_DAWN;
configp->min_dusk = DEF_MIN_DUSK;
configp->max_dusk = DEF_MAX_DUSK;
strncpy2(configp->tty, DEF_TTY, sizeof(config.tty) - 1);
configp->ttyaux[0] = '\0';
#ifdef HAVE_FEATURE_RFXLAN
configp->auxhost[0] = '\0';
configp->auxport[0] = '\0';
#endif
configp->suffixaux[0] = '\0';
configp->auxdev = 0;
configp->newformat = 0;
configp->checkfiles = DEF_CHECK_FILES;
configp->repl_delay = DEF_REPL_DELAYED_MACROS;
configp->reserved_timers = DEF_RESERVED_TIMERS;
configp->alias_size = 0;
configp->aliasp = NULL;
configp->scenep = NULL;
configp->scriptp = NULL;
configp->launcherp = NULL;
configp->pfail_script = NULL;
configp->max_pparms = DEF_MAX_PPARMS;
configp->rcs_temperature = DEF_RCS_TEMPERATURE;
configp->trigger_tag = DEF_TRIGGER_TAG;
configp->display_offset = DEF_DISPLAY_OFFSET;
configp->xref_append = DEF_XREF_APPEND;
configp->ack_hails = DEF_ACK_HAILS;
configp->macterm = DEF_MACTERM;
configp->status_timeout = DEF_STATUS_TIMEOUT;
configp->spf_timeout = DEF_SPF_TIMEOUT;
configp->disp_exp_mac = DEF_DISPLAY_EXP_MACROS;
configp->module_types = DEF_MODULE_TYPES;
configp->launch_mode = DEF_LAUNCH_MODE;
configp->function_mode = DEF_FUNCTION_MODE;
configp->launch_source = DEF_LAUNCH_SOURCE;
configp->res_overlap = DEF_RES_OVERLAP;
configp->default_module = lookup_module_type(DEF_DEFAULT_MODULE);
configp->script_mode = DEF_SCRIPT_MODE;
if ( (sp1 = getenv("SHELL")) != NULL )
strncpy2(configp->script_shell, sp1, sizeof(config.script_shell) - 1);
else
strncpy2(configp->script_shell, "/bin/sh", sizeof(config.script_shell) - 1);
*configp->logfile = '\0';
configp->logcommon = NO;
configp->disp_subdir = NO_ANSWER;
configp->isdark_offset = DEF_ISDARK_OFFSET;
strncpy2(configp->env_alias_prefix, DEF_ENV_ALIAS_PREFIX, sizeof(config.env_alias_prefix) - 1);
configp->sunmode = DEF_SUNMODE;
configp->fix_5a = DEF_FIX_5A;
configp->cm11_post_delay = DEF_CM11_POST_DELAY;
configp->pfail_update = DEF_PFAIL_UPDATE;
configp->cm17a_bit_delay = DEF_CM17A_BIT_DELAY;
configp->rf_burst_spacing = DEF_RF_BURST_SPACING;
configp->rf_timer_tweak = DEF_RF_TIMER_TWEAK;
configp->rf_post_delay = DEF_RF_POST_DELAY;
configp->rf_farb_delay = DEF_RF_FARB_DELAY;
configp->rf_farw_delay = DEF_RF_FARW_DELAY;
configp->disp_rf_xmit = DEF_DISP_RF_XMIT;
configp->def_rf_bursts = DEF_RF_BURSTS;
for ( j = 0; j < nrflabels; j++ )
configp->rf_bursts[j] = DEF_RF_BURSTS;
configp->timer_loopcount = 0;
configp->restrict_dims = DEF_RESTRICT_DIMS;
configp->state_format = DEF_STATE_FORMAT;
configp->start_engine = DEF_START_ENGINE;
configp->rf_noswitch = DEF_RF_NOSWITCH;
configp->respool_perms = DEF_RESPOOL_PERMS;
configp->spool_max = DEF_SPOOLFILE_MAX;
configp->check_RI_line = DEF_CHECK_RI_LINE;
configp->send_retries = DEF_SEND_RETRIES;
configp->script_ctrl = DEF_SCRIPT_CTRL;
configp->transceive = DEF_TRANSCEIVE;
configp->rfforward = DEF_RFFORWARD;
configp->trans_dim = DEF_TRANS_DIMLEVEL;
configp->state_ctrl = DEF_STATE_CTRL;
configp->ring_ctrl = DEF_RING_CTRL;
configp->heyu_umask = DEF_HEYU_UMASK;
configp->log_umask = DEF_LOG_UMASK;
configp->rf_funcmask = DEF_RF_FUNCMASK;
configp->aux_repcounts[0] = 0; /* Value set at finalize_config() */
configp->aux_repcounts[1] = DEF_AUX_REPCOUNT;
configp->aux_repcounts[2] = DEF_AUX_MAXCOUNT;
configp->aux_repcounts[3] = DEF_AUX_FLOODREP;
configp->aux_mincount_rfx = 0; /* Value set at finalize_config() */
configp->hide_unchanged = DEF_HIDE_UNCHANGED;
configp->hide_unchanged_inactive = DEF_HIDE_UNCHANGED_INACTIVE;
configp->show_change = DEF_SHOW_CHANGE;
configp->disp_rf_noise = DEF_DISP_RF_NOISE;
configp->arm_max_delay = DEF_ARM_MAX_DELAY;
configp->disp_raw_rf = DEF_DISP_RAW_RF;
configp->arm_logic = DEF_ARM_LOGIC;
configp->inactive_timeout = DEF_INACTIVE_TIMEOUT;
configp->device_type = DEF_DEVICE_TYPE;
configp->auto_wait = DEF_AUTO_WAIT;
configp->full_bright = DEF_FULL_BRIGHT;
configp->engine_poll = DEF_ENGINE_POLL;
configp->dmx_tscale = DEF_DMX_TSCALE;
configp->dmx_toffset = DEF_DMX_TOFFSET;
configp->ore_lobat = DEF_ORE_LOWBATTERY;
configp->ore_tscale = DEF_ORE_TSCALE;
configp->ore_toffset = DEF_ORE_TOFFSET;
configp->ore_bpscale = DEF_ORE_BPSCALE;
configp->ore_bpoffset = DEF_ORE_BPOFFSET;
strncpy2(configp->ore_bpunits, DEF_ORE_BPUNITS, NAME_LEN - 1);
configp->ore_wgtscale = DEF_ORE_WGTSCALE;
strncpy2(configp->ore_wgtunits, DEF_ORE_WGTUNITS, NAME_LEN - 1);
configp->rfx_tscale = DEF_RFX_TSCALE;
configp->rfx_toffset = DEF_RFX_TOFFSET;
configp->rfx_vadscale = DEF_RFX_VADSCALE;
configp->rfx_vadoffset = DEF_RFX_VADOFFSET;
strncpy2(configp->rfx_vadunits, DEF_RFX_VADUNITS, NAME_LEN - 1);
configp->rfx_bpscale = DEF_RFX_BPSCALE;
configp->rfx_bpoffset = DEF_RFX_BPOFFSET;
strncpy2(configp->rfx_bpunits, DEF_RFX_BPUNITS, NAME_LEN - 1);
configp->rfxcom_dtr_rts = DEF_RFXCOM_DTR_RTS;
configp->rfxcom_hibaud = DEF_RFXCOM_HIBAUD;
configp->rfx_powerscale = DEF_RFX_POWERSCALE;
strncpy2(configp->rfx_powerunits, DEF_RFX_POWERUNITS, NAME_LEN - 1);
configp->rfx_waterscale = DEF_RFX_WATERSCALE;
strncpy2(configp->rfx_waterunits, DEF_RFX_WATERUNITS, NAME_LEN - 1);
configp->rfx_gasscale = DEF_RFX_GASSCALE;
strncpy2(configp->rfx_gasunits, DEF_RFX_GASUNITS, NAME_LEN - 1);
configp->rfx_pulsescale = DEF_RFX_PULSESCALE;
strncpy2(configp->rfx_pulseunits, DEF_RFX_PULSEUNITS, NAME_LEN - 1);
configp->rfxcom_enable = DEF_RFXCOM_ENABLE;
configp->rfxcom_disable = DEF_RFXCOM_DISABLE;
configp->lockup_check = DEF_LOCKUP_CHECK;
strncpy2(configp->tailpath, DEF_TAILPATH, sizeof(config.tailpath) - 1);
configp->suppress_rfxjam = DEF_SUPPRESS_RFXJAM;
configp->display_dmxtemp = DEF_DISPLAY_DMXTEMP;
configp->securid_16 = DEF_SECURID_16;
configp->securid_mask = DEF_SECURID_MASK;
configp->securid_parity = DEF_SECURID_PARITY;
configp->logdate_year = DEF_LOGDATE_YEAR;
configp->disp_ore_all = DEF_DISPLAY_ORE_ALL;
configp->ore_chgbits_t = DEF_ORE_CHGBITS_T;
configp->ore_chgbits_rh = DEF_ORE_CHGBITS_RH;
configp->ore_chgbits_bp = DEF_ORE_CHGBITS_BP;
configp->ore_chgbits_wgt = DEF_ORE_CHGBITS_WGT;
configp->ore_chgbits_dt = DEF_ORE_CHGBITS_DT;
configp->ore_chgbits_wsp = DEF_ORE_CHGBITS_WSP;
configp->ore_chgbits_wavsp = DEF_ORE_CHGBITS_WAVSP;
configp->ore_chgbits_wdir = DEF_ORE_CHGBITS_WDIR;
configp->ore_chgbits_rrate = DEF_ORE_CHGBITS_RRATE;
configp->ore_chgbits_rtot = DEF_ORE_CHGBITS_RTOT;
configp->ore_chgbits_uv = DEF_ORE_CHGBITS_UV;
configp->ore_data_entry = DEF_ORE_DATA_ENTRY;
configp->ore_display_chan = DEF_ORE_DISPLAY_CHAN;
configp->ore_display_batlvl = DEF_ORE_DISPLAY_BATLVL;
configp->ore_display_count = DEF_ORE_DISPLAY_COUNT;
configp->oreid_16 = DEF_OREID_16;
configp->ore_display_fcast = DEF_ORE_DISPLAY_FCAST;
configp->oreid_mask = DEF_OREID_MASK;
configp->logdate_unix = DEF_LOGDATE_UNIX;
configp->inactive_timeout_ore = DEF_INACTIVE_TIMEOUT_ORE;
configp->display_sensor_intv = DEF_DISPLAY_SENSOR_INTV;
configp->date_format = DEF_DATE_FORMAT;
configp->date_separator = DEF_DATE_SEPARATOR;
configp->lock_timeout = DEF_LOCK_TIMEOUT;
configp->cm11a_query_delay = DEF_CM11A_QUERY_DELAY;
configp->els_number = DEF_ELS_NUMBER;
configp->els_voltage = DEF_ELS_VOLTAGE;
configp->els_chgbits_curr = DEF_ELS_CHGBITS_CURR;
configp->ore_windscale = DEF_ORE_WINDSCALE;
strcpy(configp->ore_windunits, DEF_ORE_WINDUNITS);
configp->ore_windsensordir = DEF_ORE_WINDSENSORDIR;
configp->ore_winddir_mode = DEF_ORE_WINDDIR_MODE;
configp->ore_rainratescale = DEF_ORE_RAINRATESCALE;
strcpy(configp->ore_rainrateunits, DEF_ORE_RAINRATEUNITS);
configp->ore_raintotscale = DEF_ORE_RAINTOTSCALE;
strcpy(configp->ore_raintotunits, DEF_ORE_RAINTOTUNITS);
configp->scanmode = DEF_SCANMODE;
configp->rfx_inline = DEF_RFX_INLINE;
configp->owl_voltage = DEF_OWL_VOLTAGE;
configp->owl_calib_power = DEF_OWL_CALIB_POWER;
configp->owl_calib_energy = DEF_OWL_CALIB_ENERGY;
configp->owl_chgbits_power = DEF_OWL_CHGBITS_POWER;
configp->owl_chgbits_energy = DEF_OWL_CHGBITS_ENERGY;
configp->owl_display_count = DEF_OWL_DISPLAY_COUNT;
configp->arm_remote = DEF_ARM_REMOTE;
configp->active_change = DEF_ACTIVE_CHANGE;
configp->inactive_handling = DEF_INACTIVE_HANDLING;
configp->process_xmit = DEF_PROCESS_XMIT;
configp->show_flags_mode = DEF_SHOW_FLAGS_MODE;
configp->rfx_master = DEF_RFX_MASTER;
configp->rfx_slave = DEF_RFX_SLAVE;
strcpy(configp->launchpath_append, DEF_LAUNCHPATH_APPEND);
strcpy(configp->launchpath_prefix, DEF_LAUNCHPATH_PREFIX);
configp->fix_stopstart_error = DEF_FIX_STOPSTART_ERROR;
configp->ttyrfxmit[0] = '\0';
configp->rfxmit_freq = 0;
configp->chksum_timeout = DEF_CHKSUM_TIMEOUT;
return;
}
/*---------------------------------------------------------------------+
| Parse the users configuration file and save info in CONFIG struct |
| for only the minimal directives required for some specific commands.|
| E.g., the 'heyu stop' command needs only the TTY directive. |
+---------------------------------------------------------------------*/
int parse_minimal_config ( FILE *fd_conf, unsigned char mode, unsigned char source )
{
char buffer[LINE_LEN];
char *sp1;
int err, errors;
CONFIG configtmp;
configp = &configtmp;
/* Make sure the isparsed flags are reset in the command list */
reset_isparsed_flags();
/* Load some default configuration values */
initialize_config();
line_no = 0;
errors = 0;
while ( fgets(buffer, LINE_LEN, fd_conf) != NULL ) {
line_no++ ;
buffer[LINE_LEN - 1] = '\0';
/* Get rid of comments and blank lines */
if ( (sp1 = strchr(buffer, '#')) != NULL )
*sp1 = '\0';
(void) strtrim(buffer);
if ( buffer[0] == '\0' )
continue;
err = parse_config_tail(buffer, source);
if ( err || *error_message() != '\0' ) {
fprintf(stderr, "Config Line %02d: %s\n", line_no, error_message());
clear_error_message();
}
errors += err;
if ( errors > MAX_ERRORS )
return 1;
}
/* Determine and load the user's timezone */
get_std_timezone();
configp->tzone = std_tzone;
/* Determine if Daylight Time is ever in effect and if so, */
/* the minutes after midnight it goes into and out of effect. */
configp->isdst = get_dst_info(0);
/* Add configuration items from environment */
errors += environment_config();
errors += finalize_config(mode);
if ( *error_message() != '\0' ) {
fprintf(stderr, "%s\n", error_message());
clear_error_message();
}
/* Free the allocated memory in the original config structure */
free_all_arrays(&config);
/* Copy the temporary config into the global structure */
memcpy(&config, configp, sizeof(config));
configp = &config;
/* Done with config file */
line_no = 0;
return errors;
}
/*---------------------------------------------------------------------+
| Parse the users configuration file and save info in CONFIG struct. |
| First check to see if it's already been read. |
+---------------------------------------------------------------------*/
int parse_config ( FILE *fd_conf, unsigned char mode )
{
char buffer[LINE_LEN];
char *sp1;
int err, errors;
int j;
SCENE *scenep;
extern char *typename[];
CONFIG configtmp;
/* If the configuration file has already been read into memory, */
/* just return. */
if ( config.read_flag != 0 ) {
return 0;
}
configp = &configtmp;
/* Make sure the isparsed flags are reset in the command list */
reset_isparsed_flags();
/* Load some default configuration values */
initialize_config();
line_no = 0;
errors = 0;
while ( fgets(buffer, LINE_LEN, fd_conf) != NULL ) {
line_no++ ;
buffer[LINE_LEN - 1] = '\0';
/* Get rid of comments and blank lines */
if ( (sp1 = strchr(buffer, '#')) != NULL )
*sp1 = '\0';
(void) strtrim(buffer);
if ( buffer[0] == '\0' )
continue;
err = parse_config_tail(buffer, SRC_CONFIG);
if ( err || *error_message() != '\0') {
if ( !i_am_relay && !i_am_aux && !i_am_monitor )
fprintf(stderr, "Config Line %02d: %s\n", line_no, error_message());
clear_error_message();
}
errors += err;
if ( errors > MAX_ERRORS )
return 1;
}
/* Everything has now been read from the config file and stored */
/* Verify the syntax of user-defined scenes/usersyns */
scenep = configp->scenep;
j = 0;
while ( scenep && scenep[j].line_no > 0 ) {
if ( verify_scene(scenep[j].body) != 0 ) {
fprintf(stderr, "Config Line %02d: %s '%s': %s\n",
scenep[j].line_no, typename[scenep[j].type], scenep[j].label,
error_message());
clear_error_message();
if ( ++errors > MAX_ERRORS )
return errors;
}
else if ( *error_message() != '\0' ) {
/* Check warning messages */
fprintf(stderr, "Config Line %02d: %s '%s': %s\n",
scenep[j].line_no, typename[scenep[j].type], scenep[j].label,
error_message());
clear_error_message();
}
j++;
}
/* Configure module masks */
set_module_masks( configp->aliasp );
/* Use the Heyu path if the user hasn't provided an alternate */
if ( !(*alt_path) )
(void)strncpy2(alt_path, heyu_path, sizeof(alt_path) - 1);
/* Determine and load the user's timezone */
get_std_timezone();
configp->tzone = std_tzone;
/* Determine if Daylight Time is ever in effect and if so, */
/* the minutes after midnight it goes into and out of effect. */
configp->isdst = get_dst_info(0);
/* Add configuration items from environment */
errors += environment_config();
errors += finalize_config(mode);
if ( *error_message() != '\0' ) {
fprintf(stderr, "%s\n", error_message());
clear_error_message();
}
configp->read_flag = (errors == 0) ? 1 : 0;
if ( errors > 0 )
return errors;
/* Free the allocated memory in the original config structure */
free_all_arrays(&config);
/* Copy the temporary config into the global structure */
memcpy(&config, configp, sizeof(config));
configp = &config;
/* Done with config file */
line_no = 0;
return errors;
}
/*---------------------------------------------------------------------+
| Parse the config line in buffer. Argument 'source' can be |
| SRC_CONFIG if called from parse_config() or SRC_SCHED if called |
| from parse_sched(), for configuration items which may be overridden |
| in the latter. |
+---------------------------------------------------------------------*/
int parse_config_tail ( char *buffer, unsigned char source )
{
char errbuffer[80];
char searchstr[128];
char directive[128];
char label[(NAME_LEN + SCENE_LEN + MACRO_LEN + 1)];
char token[50];
char hc;
char *bufp, *sp;
int errors = 0;
int num, value, hour, minut, len, modtype;
long longvalue;
int bursts;
int j, k, commj, switchval;
int tokc;
char **tokv = NULL;
int perms;
double dblvalue;
extern struct rfx_disable_st rfx_disable[];
extern int nrfxdisable;
bufp = buffer;
get_token(directive, &bufp, " \t", sizeof(directive)/sizeof(char));
strtrim(bufp);
strncpy2(searchstr, directive, sizeof(searchstr) - 1);
strupper(searchstr);
/* Search list of configuration commands starting */
/* past "oldalias". */
commj = 0; switchval = OldAlias;
for ( j = 1; j < ncommands; j++ ) {
if ( !strcmp(searchstr, command[j].name) ) {
switchval = command[j].switchval;
commj = j;
break;
}
}
/* See if override in schedule file is permitted */
if ( (source == SRC_SCHED || source == SRC_ENVIRON) &&
(command[commj].flags & COVR) == 0 ) {
if ( commj )
sprintf(errbuffer, "Configuration directive %s not allowed here.",
command[commj].name);
else
sprintf(errbuffer, "Invalid configuration directive");
store_error_message(errbuffer);
return 1;
}
/* Minimal configurations for some commands */
if ( source == SRC_STOP && (command[commj].flags & CSTP) == 0 )
return 0;
if ( source == SRC_HELP && (command[commj].flags & CHLP) == 0 )
return 0;
if ( source == SRC_SYSCHECK && (command[commj].flags & CCAL) == 0 )
return 0;
/* If the directive has a fixed number of tokens (as denoted */
/* by maxtokens > 0) or _might_ be an old-style alias, */
/* tokenize the tail immediately. */
if ( commj == 0 || command[j].maxtoken > 0 ) {
tokenize(bufp, " \t", &tokc, &tokv);
}
else {
tokc = (*bufp == '\0') ? 0 : 1 ;
}
/* If not found in list and it doesn't have the correct */
/* number of items for an alias, reject it. */
if ( commj == 0 && tokc != 2 ) {
sprintf(errbuffer, "Invalid Directive '%s'", directive);
store_error_message(errbuffer);
return 1;
}
/* Unless allowed, check to see it's not a duplicate */
/* of an earlier directive. */
if ( command[commj].isparsed & source && (command[commj].flags & CMLT) == 0) {
sprintf(errbuffer,
"Directive '%s' appears more than once in the file", searchstr);
store_error_message(errbuffer);
return 1;
}
else {
command[commj].isparsed |= source;
}
/* Check that commands found on the list have the correct */
/* number of tokens on the line. */
if ( (tokc + 1) < command[commj].mintoken ) {
store_error_message("Too few items on line.");
return 1;
}
else if ( (command[commj].maxtoken != -1) && ((tokc + 1) > command[commj].maxtoken) ) {
store_error_message("Too many items on line.");
return 1;
}
errors = 0;
switch ( switchval ) {
case Ignored :
sprintf(errbuffer,
"Directive %s is obsolete and is being ignored.", searchstr);
store_error_message(errbuffer);
break;
case Mode :
(void) strupper(tokv[0]);
if ( !strcmp(tokv[0], "COMPATIBLE") )
configp->mode = COMPATIBLE;
else if ( !strcmp(tokv[0], "HEYU") )
configp->mode = HEYU_MODE;
else {
store_error_message("MODE must be COMPATIBLE or HEYU");
errors++;
}
break;
case OldAlias : /* Possible alias, else invalid command */
/* Check if it matches the form of an alias */
if ( tokc != 2 || strlen(tokv[0]) != 1 ||
(hc = toupper((int)(*tokv[0]))) < 'A' || hc > 'P' ) {
store_error_message("Invalid Directive.");
errors++;
break;
}
if ( !is_valid_alias_label(directive, &sp) ) {
sprintf(errbuffer, "Invalid character '%c' in alias label.", *sp);
store_error_message(errbuffer);
errors++;
break;
}
if ( strcmp(tokv[0], "macro") == 0 ) {
store_error_message("An alias label may not be the word \"macro\".");
errors++;
break;
}