5

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?

Community
  • 1
  • 1
Jakob Buron
  • 1,196
  • 11
  • 19

2 Answers2

3

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.

Jakob Buron
  • 1,196
  • 11
  • 19
0

Another way is to use project settings XML and add all the required macros there. You can generate a base XML file by

Right Click on Project -> Go to properties -> C/C++ General -> Path and Symbol and in Symbol tab, add some pre-processor for GNU C or GNU C++ and export these settings as the file using "Export Setting" link at bottom of the window. Then manually edit XML file for new macros and import using "import settings" button in above option.

Use saved file as the template for all other projects and import it once at the time of project creation.

Mukul
  • 11
  • 2