Configuring Doxygen to draw a custom graph - Page 1
Forum section: electronics / general

author: Phoenix
author_rank: Frequent Contributor
timestamp: June 19, 2015, 11:30:36 am
content: 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

author: ale500
author_rank: Frequent Contributor
timestamp: June 21, 2015, 12:11:04 pm
content: 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: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"; }}

author: Phoenix
author_rank: Frequent Contributor
timestamp: June 23, 2015, 10:30:17 pm
content: 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.

author: slateraptor
author_rank: Frequent Contributor
timestamp: June 24, 2015, 07:43:21 am
content: To piggyback on ale500's suggestion, from command line$, try:$ grep "^.*//&.*$" state_machine.c | sed s/"^.*\/\/& "//gThis 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: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.

author: Phoenix
author_rank: Frequent Contributor
timestamp: June 24, 2015, 11:55:18 am
content: Quote from: slateraptor on June 24, 2015, 07:43:21 amThat 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.

author: Phoenix
author_rank: Frequent Contributor
timestamp: June 25, 2015, 07:35:59 am
content: Thanks guys, got my diagrams out with a batch file now (yeah, windows).

author: mikerj
author_rank: Super Contributor
timestamp: June 25, 2015, 10:09:10 am
content: Not a solution in this case, but thisDoxygen preprocessorlooks like a much easier way to extract dot code for state machines. The syntax is much more human friendly.