1 /*
2 *   Copyright (c) 2016, Red Hat, Inc.
3 *   Copyright (c) 2016, Masatake YAMATO
4 *
5 *   This source code is released for free distribution under the terms of the
6 *   GNU General Public License version 2 or (at your option) any later version.
7 *
8 */
9 #ifndef CTAGS_MAIN_WRITER_PRIVATE_H
10 #define CTAGS_MAIN_WRITER_PRIVATE_H
11 
12 #include "general.h"  /* must always come first */
13 #include "mio.h"
14 #include "options_p.h"
15 #include "types.h"
16 
17 /* Other than writeEntry can be NULL.
18    The value returned from preWriteEntry is passed to writeEntry,
19    and postWriteEntry. If a resource is allocated in
20    preWriteEntry, postWriteEntry should free it. */
21 
22 typedef enum eWriterType {
23 	WRITER_DEFAULT,
24 	WRITER_U_CTAGS = WRITER_DEFAULT,
25 	WRITER_E_CTAGS,
26 	WRITER_ETAGS,
27 	WRITER_XREF,
28 	WRITER_JSON,
29 	WRITER_CUSTOM,
30 	WRITER_COUNT,
31 } writerType;
32 
33 struct sTagWriter;
34 typedef struct sTagWriter tagWriter;
35 struct sTagWriter {
36 	int (* writeEntry) (tagWriter *writer, MIO * mio, const tagEntryInfo *const tag,
37 						void *clientData);
38 	int (* writePtagEntry) (tagWriter *writer, MIO * mio, const ptagDesc *desc,
39 							const char *const fileName,
40 							const char *const pattern,
41 							const char *const parserName,
42 							void *clientData);
43 	bool printPtagByDefault;
44 	void * (* preWriteEntry) (tagWriter *writer, MIO * mio,
45 							  void *clientData);
46 
47 	/* Returning TRUE means the output file may be shrunk.
48 	   In such case the callee may do truncate output file. */
49 	bool (* postWriteEntry)  (tagWriter *writer, MIO * mio, const char* filename,
50 							  void *clientData);
51 	void (* rescanFailedEntry) (tagWriter *writer, unsigned long validTagNum,
52 								void *clientData);
53 	bool (* treatFieldAsFixed) (int fieldType);
54 
55 	void (* checkOptions) (tagWriter *writer);
56 
57 #ifdef WIN32
58 	enum filenameSepOp (* overrideFilenameSeparator) (enum filenameSepOp currentSetting);
59 #endif	/* WIN32 */
60 
61 	const char *defaultFileName;
62 
63 	/* The value returned from preWriteEntry is stored `private' field.
64 	   The value must be released in postWriteEntry. */
65 	void *private;
66 	writerType type;
67 	/* The value passed as the second argument for writerSetup iss
68 	 * stored here. Unlink `private' field, ctags does nothing more. */
69 	void *clientData;
70 };
71 
72 /* customWriter is used only if otype is WRITER_CUSTOM */
73 extern void setTagWriter (writerType otype, tagWriter *customWriter);
74 extern void writerSetup  (MIO *mio, void *clientData);
75 extern bool writerTeardown (MIO *mio, const char *filename);
76 
77 int writerWriteTag (MIO * mio, const tagEntryInfo *const tag);
78 int writerWritePtag (MIO * mio,
79 					 const ptagDesc *desc,
80 					 const char *const fileName,
81 					 const char *const pattern,
82 					 const char *const parserName);
83 
84 void writerRescanFailed (unsigned long validTagNum);
85 
86 extern const char *outputDefaultFileName (void);
87 
88 extern size_t truncateTagLineAfterTag (char *const line, const char *const token,
89 			     const bool discardNewline);
90 extern void abort_if_ferror(MIO *const fp);
91 
92 extern bool ptagMakeJsonOutputVersion (ptagDesc *desc, langType language CTAGS_ATTR_UNUSED, const void *data CTAGS_ATTR_UNUSED);
93 extern bool ptagMakeCtagsOutputMode (ptagDesc *desc, langType language CTAGS_ATTR_UNUSED, const void *data CTAGS_ATTR_UNUSED);
94 extern bool ptagMakeCtagsOutputFilesep (ptagDesc *desc, langType language CTAGS_ATTR_UNUSED, const void *data);
95 extern bool ptagMakeCtagsOutputExcmd (ptagDesc *desc, langType language CTAGS_ATTR_UNUSED, const void *data);
96 
97 extern bool writerCanPrintPtag (void);
98 extern bool writerDoesTreatFieldAsFixed (int fieldType);
99 
100 extern void writerCheckOptions (void);
101 extern bool writerPrintPtagByDefault (void);
102 
103 #ifdef WIN32
104 extern enum filenameSepOp getFilenameSeparator (enum filenameSepOp currentSetting);
105 #endif	/* WIN32 */
106 #endif	/* CTAGS_MAIN_WRITER_PRIVATE_H */
107