收录日期:2020/06/02 03:21:29 时间:2015-11-27 11:40:15 标签:c,eclipse-cdt,c-preprocessor

I'm using Eclipse CDT for a C project with custom makefiles, and I want to use the inactive code highlighting as proposed in the answers to question 739230. The automatic discovery of active/defined symbols does not work for my makefiles. Instead I have created a text file for each build target listing the active symbols.

So my questions are:

  1. How do I load these settings into a the project without going through the GUI (folder properties -> Paths and Symbols -> Symbols)?
  2. And how do I choose which configuration/build target the symbols are added to?

Directly editing the the .cproject file and adding lines like this works:

<listOptionValue builtIn="false" value="HIRES_OUTPUT"/>

But only if I go through the GUI to create the first key for each build target. I would prefer to create the build target and import the symbols in one operation.

Writing an Eclipse plugin from scratch seems like overkill for this task.

Any ideas for a smarter way to do this?

The Import/Export Wizard can handle Symbol Definitions. Use File->Import and choose C/C++ Project Settings.

The XML format needed by the Import Wizard can be created from the text file of active symbols with a small throw-away script.

I used the following python script:

#
#   	Tool to import a list of defined symbols into Eclipse IDE for code highlighting.
#
#   	Takes a _cdef.txt file (generated during library build) and converts to an XML file
#   	suitable for import into Eclipse
#   	Use stdin and stdout for input and output.

import sys
import string

header = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<cdtprojectproperties>'
,
'<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.Macros">',
'<language name="holder for library settings">',
'',
'</language>',
'<language name="GNU C++">',
'',
'</language>',
'<language name="GNU C">',
''
]

sys.stdout.write (string.join(header, '\n'))


text=sys.stdin.readlines()
tokens = string.split(string.strip(text[0]),',')
for curtok in tokens:
    lines = ['<macro>',
    '<name>' + string.strip(curtok) + '</name><value></value>',
    '</macro>', '']
    sys.stdout.write(string.join(lines, '\n'))

footer = [
'',
'</language>',
'<language name="Assembly">',
'',
'</language>',
'</section>',
'</cdtprojectproperties>',
'']
sys.stdout.write (string.join(footer, '\n'))

The input to the script is a text file with the comma-separated active symbols, all on the first line.