Author Topic: Configuring Doxygen to draw a custom graph  (Read 2871 times)

0 Members and 1 Guest are viewing this topic.

Offline Phoenix

  • Frequent Contributor
  • **
  • Posts: 279
  • Country: au
Configuring Doxygen to draw a custom graph
« on: June 19, 2015, 09:30:36 pm »
Hi Guys,

I'm hoping someone here knows a bit about Doxygen. I've inhereted C code for a major project at work which has been commented using Doxygen style, and don't have contact with the old programmer. I have been able to generate most of the output using Doxygen with GraphViz and Dot properly installed and configured. I.e. I can produce the document pack with call/caller graphs etc. if ticked.

The problem I'm having is embedded in the code is are hand commented directed graphs of the state machines. I know these can be parsed by Doxygen/GraphViz/Dot but I don't know how to get Doxygen to recognise it (earlier version of the diagrams have "Created by Doxygen" written on them).

For example, the file "state_machine.c" would have near the top


//& subgraph cluster0 { node [style=filled]
//& color=midnightblue;


Throughout, the state functions are commented with:


//& state_init [style=bold,shape=box,peripheries=2,color=black,label="Initialise"]


And transistions are commented with:


//& state_init -> state_next_step [style=bold]


The end looks like:

//& ; fontsize=18;label="State Machine"; }

I can see these are Dot language and are always preceeded by //&. What I don't know is how to configure Doxygen to group together all of these comments and give them to Dot to produce a graph.

I'd be greatful if anyone could provide help, or direct me where to look in Doxygen's manual.

Cheers
 

Offline ale500

  • Frequent Contributor
  • **
  • Posts: 296
Re: Configuring Doxygen to draw a custom graph
« Reply #1 on: June 21, 2015, 10:11:04 pm »
After reading the dot user manual, I think that one possibility would be to grep all the commands and use them as input to dot, if the "header" so to say is not already there, you could add it, you will have to remove the comment marker '//&' too, so your input looks like:

Code: [Select]
digraph G {
 subgraph cluster0 { node [style=filled];
 color=midnightblue;
 state_init [style=bold,shape=box,peripheries=2,color=black,label="Initialise"];
 state_init -> state_next_step [style=bold];
 fontsize=18;label="State Machine"; }
}
 

Offline Phoenix

  • Frequent Contributor
  • **
  • Posts: 279
  • Country: au
Re: Configuring Doxygen to draw a custom graph
« Reply #2 on: June 24, 2015, 08:30:17 am »
Good idea.

I was thinking some sort out regular expression type thing to extract the diagram. I'll look into that a bit more. I don't care if it's external to doxygen.
 

Offline slateraptor

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: us
Re: Configuring Doxygen to draw a custom graph
« Reply #3 on: June 24, 2015, 05:43:21 pm »
To piggyback on ale500's suggestion, from command line $, try:

$ grep "^.*//&.*$" state_machine.c | sed s/"^.*\/\/& "//g

This regex extracts every line in state_machine.c which contains the //& token and pipes to stdout, then for each extracted line, sed will remove every character from beginning of line up to and including //& , passing the remainder to stdout. From your example code, return will look something like:

Code: [Select]
subgraph cluster0 { node [style=filled]
color=midnightblue;
state_init [style=bold,shape=box,peripheries=2,color=black,label="Initialise"]
state_init -> state_next_step [style=bold]
; fontsize=18;label="State Machine"; }

From this point, you can pipe/write to your heart's content.
 

Offline Phoenix

  • Frequent Contributor
  • **
  • Posts: 279
  • Country: au
Re: Configuring Doxygen to draw a custom graph
« Reply #4 on: June 24, 2015, 09:55:18 pm »
To piggyback on ale500's suggestion, from command line $, try:

$ grep "^.*//&.*$" state_machine.c | sed s/"^.*\/\/& "//g

This regex extracts every line in state_machine.c which contains the //& token and pipes to stdout, then for each extracted line, sed will remove every character from beginning of line up to and including //& , passing the remainder to stdout. From your example code, return will look something like:

Code: [Select]
subgraph cluster0 { node [style=filled]
color=midnightblue;
state_init [style=bold,shape=box,peripheries=2,color=black,label="Initialise"]
state_init -> state_next_step [style=bold]
; fontsize=18;label="State Machine"; }

From this point, you can pipe/write to your heart's content.

That sounds like just what I want, thanks guys. I played around with grep today and got up to  grep "^.*//&.*$" state_machine.c but didn't get into piping or sed. Shouldn't be too hard now I know where I'm going.
 

Offline Phoenix

  • Frequent Contributor
  • **
  • Posts: 279
  • Country: au
Re: Configuring Doxygen to draw a custom graph
« Reply #5 on: June 25, 2015, 05:35:59 pm »
Thanks guys, got my diagrams out with a batch file now (yeah, windows) :).
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 1687
  • Country: gb
Re: Configuring Doxygen to draw a custom graph
« Reply #6 on: June 25, 2015, 08:09:10 pm »
Not a solution in this case, but this Doxygen preprocessor looks like a much easier way to extract dot code for state machines.  The syntax is much more human friendly.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf