1. C-xrefactory Intro

This document is very much a work in progress.

1.1. What is C-xrefactory?

C-xrefactory is a development tool for C developers that allows browsing variables and functions, as well as refactoring, in C and Yacc code.

Here is a list of features

  • Full integration with Emacs

  • Browsing source code in C supporting multiple pre-processing passes

  • Designed to work with large projects (> millions of lines)

  • Fast update using only modified files

  • First tool to Cross Refactoring’s Rubicon as described by Martin Fowler

  • Safe refactorings to

    • rename variables, functions etc.

    • extract function/macro

    • delete, add, move parameters

  • Solid code completion

  • Search for symbols using wildcards

  • Find unused variables and functions, globally as well as locally

  • Auto-detection of project

  • Full undo in Emacs

1.2. About this document

This document is a Work In Progress, as most things in this project at this stage.

Things in this document might be out-dated, old, wrong or actually valid. Hopefully this will improve over time.

1.3. History

1.4. Installing

1.5. Usage

1.5.1. Emacs

1.5.2. Command line usage

Use case

Normally the c-xref program is controlled from an editor adapter. But sometimes running it from the command line, e.g. as part setting up a project, investigating problems with c-xref or as a part of the c-xrefactory test suite, can be useful.

Most options can be set in a configuration file to be effective for every execution of c-xref in a project.

Here follows a description of the various available command line options.

Command line options

There is a large number of command line options. Some of them might seem very obscure since they are only intended for use by the editor server protocol. Below is a list of all of them grouped after their usage (grouping and descriptions is a Work In Progress).

Operating modes
-refactory
-server

c-xrefactory can operate in three different modes:

  • xref - the cross-referencer (default)

  • server - editor server, started by editor adapters

  • refactory - refactoring editor, normally called by editor adapters

Cross-referencing options
-create

Overwrite any existing crossreference data with a completely new set.

-fastupdate
-fullupdate, -update

"Fast update" ignores updated header files. NOTE: This option might be removed in the future.

Selecting configuration information
-p <project>

c-xrefactory has project-based configurations. The -p selects which of the projects available in the selected configuration file (see -xrefrc option) that should be applied.

-stdop <file>

Read file as a configuration file containing options, as if it was included from the selected configuration file. This makes it possible to share certain configuration options between multiple configuration files/projects.

-xrefrc=<file>
-xrefrc <file>

Read the indicated file instead of the default ~/.c-xrefrc for configuration information.

Variables etc.
-set <variable> <value>

Set variable to 'value' in the same fashion as environment variables. Variables set in this way can be used in configuration files and queried using the command line option -get.

-get <variable>

Get the value of a previously set "environment variable". The value will be transfered over the edit server protocol as a PPC_SET_INFO record.

Character encoding etc.
-crconversion
-crlfconversion

Convert various line-ending conventions to LF.

-encoding=<encoding>

Consider source files to use the indicated text encoding (default, european, euc, sjis, utf, utf-8, utf-16, utf-16le, utf-16be).

Error reporting and output
-errors, -no-errors
-warnings
-infos
-debug
-trace

Select level of information to print.

-yydebug

Enable debugging of the C and Yacc parsers according to the Yacc manual.

-o <file>

Redirect all output to file rather than to standard output.

-log=<file>

Place all log output in file.

C specific options
-D<macro>[=<body>]

Define a preprocessor macro or variable with name macro in the same fashion as for the C/C++ pre-processor. This is typically used to set variables differently for different passes (see -pass).

-I <directory>

Look for included C header files also in directory. If used multiple times the order of search will be the same as the order of the occurence of the -I options.

-compiler <path>

Sets the path of the C compiler to use. c-xrefactory tries to setup pre-defined types, pre-processor variables, include paths etc. so that the parsing of the C source will be as close to what the compiler the project is using does. If the project is not using the default C compiler, cc, then this option allows c-xrefactory to inquire some compilers for their settings and apply them automatically.

-csuffixes=<suffixes>

This option indicates which file suffixes to consider being a C file. Multiple suffixes should be separated by :.

-strict

Reject keywords and types that are not part of the ANSI C standard, such as asm, _near and const.

Editor adapter/server configuration
-xrefactory-II

Applicable only to server mode. Will use a second generation protocol between the edit server and the editor adapter. Using the edit server/refactorer without activating -xrefactory-II is deprecated. Will be deprecated and removed in the future when legacy protocol is removed.

Miscellaneous
-about
-help
-version

Print short or long help text or version information.

Internal options
This should probably be in the design document instead.

The refactorer internally calls the main c-xref indexing function and controls it by passing "command line options". Here is a list of those "options", which shall not be used from the command line.

-exactpositionresolve

If a symbol is defined in multiple places, like it can be in C, using this flag will consider those instances different based on them being in different locations.

What you want or need is unfortunately depending on your situation. If you don’t use this option then navigation and refactorings will affect all occurrences.

One particular scenario is if you have mocked some functions (like with Cgreen) then you have at least two symbols with the same name and parameter lists. In this case you really want refactorings like renames and parameter changes to also affect the mocks, although they are not actually the "same" symbol. If -exactpositionresolve is used then the actual function and its mock version would be considered different symbols and a refactoring would only affect the selected one, leaving you to sync up the other manually.

As yet unsorted options
-addimportdefault
-browsedsym
-commentmovinglevel
-completeparenthesis
-completioncasesensitive
-completionoverloadwizdeep
-continuerefactoring
-displaynestedwithouters
-exit
-extractAddrParPrefix
-filescasesensitive
-filescaseunsensitive
-maxcompls
-mf
-movetargetfile
-no-autoupdatefromsrc
-no-includerefresh
-no-includerefs
-olallchecks
-olcheckaccess
-olchecklinkage
-olcheckversion
-olcomplback
-olcomplforward
-olcomplselect
-olcursor
-olcxargmanip
-olcxcbrowse
-olcxcgoto
-olcxcomplet
-olcxcplsearch
-olcxctinspectdef
-olcxencapsulate
-olcxencapsulatesc1
-olcxencapsulatesc2
-olcxextract
-olcxfilter
-olcxgetcurrentrefn
-olcxgetparamcoord
-olcxgetprojectname
-olcxgetrefactorings
-olcxgetsymboltype
-olcxgoto
-olcxgotocaller
-olcxgotocurrent
-olcxgotodef
-olcxgotoparname
-olcxintersection
-olcxlccursor
-olcxlist
-olcxlisttop
-olcxmaybethis
-olcxmctarget
-olcxmenuall
-olcxmenufilter
-olcxmenugo
-olcxmenuinspectdef
-olcxmenunone
-olcxmenuselect
-olcxmenusingleselect
-olcxmethodlines
-olcxmmtarget
-olcxmodified
-olcxnext
-olcxnotfqt
-olcxparnum
-olcxparnum2
-olcxpop
-olcxpoponly
-olcxprevious
-olcxprimarystart
-olcxpush
-olcxpushandcallmacro
-olcxpushfileunused
-olcxpushforlm
-olcxpushglobalunused
-olcxpushname
-olcxpushonly
-olcxpushspecialname
-olcxrename
-olcxrepush
-olcxsafetycheck
-olcxsafetycheckinit
-olcxsafetycheckmovedblock
-olcxsafetycheckmovedfile
-olcxsearch
-olcxsyntaxpass
-olcxtaggoto
-olcxtagsearch
-olcxtagsearchback
-olcxtagsearchforward
-olcxtagselect
-olcxtarget
-olcxtops
-olcxtoptype
-olcxunmodified
-olcxwindel
-olcxwindelfile
-olcxwindelwin
-olexaddress
-olexmacro
-olinelen
-olmanualresolve
-olmark
-olnodialog
-optinclude
-pass
-pause <n>

Will sleep n seconds before proceeding with next argument or processing. Useful when attaching a debugger to an edit server process.

-preload <file1> <file2>

Indicates that the current content of the editor copy of file1 is available in file2. If an editor has an edited, non-saved, buffer holding a relevant file1 it is supposed that the editor adaptor saves the content into a file and indicates this to the edit server using this option.

-prune
-refnum
-refs
-renameto
-resetIncludeDirs
-rfct-add-param
-rfct-add-to-imports
-rfct-del-param
-rfct-expand
-rfct-extract-macro
-rfct-extract-function
-rfct-move-param
-rfct-param1
-rfct-param2
-rfct-rename
-rlistwithoutsrc
-searchdef
-searchdefshortlist
-searchshortlist

…​

1.6. The configuration file

Appendix A: Release History

In this section only the introduction or changes of major user level features are listed, and thus only MINOR versions. For a detailed log of features, enhancements and bug fixes visit the projects repository on GitHub, https://github.com/thoni56/c-xrefactory.

A.1. 1.6.15

  • Add support for for-loop initializers in C

A.2. 1.6.13

  • Add support for C compound literals

A.3. 1.6.11

  • First version in github based of Sourceforge GPL’d source

A.4. 1.6.10

2. Acknowledgements

Thanks to

  • Marián Vittek, Bratislawa University, and his helpers that created this tool over many years.