1 /***************************************************************************
2                           cabrillo.h  -  description
3                              -------------------
4     begin                : Thu Dec 5 2002
5     copyright            : (C) 2002 by ARRL
6     author               : Jon Bloom
7     email                : jbloom@arrl.org
8     revision             : $Id$
9  ***************************************************************************/
10 
11 #ifndef __CABRILLO_H
12 #define __CABRILLO_H
13 
14 #include "tqsllib.h"
15 
16 #undef CLIENT_STATIC
17 #ifndef LOTW_SERVER
18 #define CLIENT_STATIC static	///< Static linkage
19 #else
20 #define CLIENT_STATIC
21 #endif
22 
23 /*! \file */
24 
25 /** \defgroup Cabrillo Cabrillo API
26   *
27   * These functions and data structures provide a means of parsing a Cabrillo
28   * file into its component fields.
29   *
30   * For convenience, the returned fields are identified using field names
31   * from the \link ADIF ADIF \endlink specification.
32   */
33 /** @{ */
34 
35 #define TQSL_CABRILLO_MAX_FIELDS 12		///< Max field count
36 #define TQSL_CABRILLO_FIELD_NAME_LENGTH_MAX 64	///< Max field name length
37 #define TQSL_CABRILLO_FIELD_VALUE_LENGTH_MAX 40	///< Max field value length
38 
39 /// Cabrillo status values
40 typedef enum {
41 	TQSL_CABRILLO_NO_ERROR,
42 	TQSL_CABRILLO_EOF,
43 	TQSL_CABRILLO_NO_START_RECORD,
44 	TQSL_CABRILLO_NO_CONTEST_RECORD,
45 	TQSL_CABRILLO_UNKNOWN_CONTEST,
46 	TQSL_CABRILLO_BAD_FIELD_DATA,
47 	TQSL_CABRILLO_EOR,
48 } TQSL_CABRILLO_ERROR_TYPE;		///< Error type
49 
50 /*! \enum TQSL_CABRILLO_FREQ_TYPE
51  * Frequency type: HF, VHF, or UNKNOWN
52  */
53 typedef enum {
54 	TQSL_CABRILLO_HF,
55 	TQSL_CABRILLO_VHF,
56 	TQSL_CABRILLO_UNKNOWN,
57 } TQSL_CABRILLO_FREQ_TYPE;
58 
59 // Minimum field number for callsign and default field number
60 // For VHF, default should be 7.
61 #define TQSL_MIN_CABRILLO_MAP_FIELD 5	///< First possible call-worked field
62 #define TQSL_DEF_CABRILLO_MAP_FIELD 8	///< Default call-worked field
63 
64 /** Cabrillo field data:
65   *
66   * \li \c name - ADIF field name
67   * \li \c value - Field content
68   */
69 typedef struct {	///< Cabrillo field
70 	char name[TQSL_CABRILLO_FIELD_NAME_LENGTH_MAX +1];	///< Field name
71 	char value[TQSL_CABRILLO_FIELD_VALUE_LENGTH_MAX +1];	///< Field value
72 } tqsl_cabrilloField;
73 
74 typedef void * tQSL_Cabrillo;	///< Opaque cabrillo log type
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
80 /** Get the Cabrillo error message that corresponds to a particular error value */
81 DLLEXPORT const char* CALLCONVENTION tqsl_cabrilloGetError(TQSL_CABRILLO_ERROR_TYPE err);
82 
83 /** Initialize a Cabrillo file for reading */
84 DLLEXPORT int CALLCONVENTION tqsl_beginCabrillo(tQSL_Cabrillo *cabp, const char *filename);
85 
86 /** Get the Contest name as specified in the Cabrillo CONTEST line */
87 DLLEXPORT int CALLCONVENTION tqsl_getCabrilloContest(tQSL_Cabrillo cab, char *buf, int bufsiz);
88 
89 /** Get the Frequency type (HF or VHF) as determined by the contest */
90 DLLEXPORT int CALLCONVENTION tqsl_getCabrilloFreqType(tQSL_Cabrillo cab, TQSL_CABRILLO_FREQ_TYPE *type);
91 
92 /** Get the current line number (starting from 1) of the input file */
93 DLLEXPORT int CALLCONVENTION tqsl_getCabrilloLine(tQSL_Cabrillo cab, int *lineno);
94 
95 /** Get the text of the current Cabrillo record */
96 DLLEXPORT const char* CALLCONVENTION tqsl_getCabrilloRecordText(tQSL_Cabrillo cab);
97 
98 /** Get the next field of the Cabrillo record
99   *
100   * \c err is set to \c TQSL_CABRILLO_NO_ERROR or \c TQSL_CABRILLO_EOR (end-of-record)
101   * if \c field was populated with data. If \c err == \c TQSL_CABRILLO_EOR, this
102   * is the last field of the record.
103   *
104   * \c err == \c TQSL_CABRILLO_EOF when there is no more data available.
105   */
106 DLLEXPORT int CALLCONVENTION tqsl_getCabrilloField(tQSL_Cabrillo cab, tqsl_cabrilloField *field, TQSL_CABRILLO_ERROR_TYPE *err);
107 
108 /** Finish reading a Cabrillo file and release its resources */
109 DLLEXPORT int CALLCONVENTION tqsl_endCabrillo(tQSL_Cabrillo *cabp);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 /** @} */
116 
117 #endif // __CABRILLO_H
118