clinuxyacclexcall-graph

Is there any C library for drawing pictures and making .jpg files?


I think this question might look very stupid and unnecessary but I really couldn't figure out how to solve this problem.

I need to make a call graph as a result of using some test codes written in C.

I made lex file and yacc file to parse the syntax.

Now I can make an executable file to parse a file written in C language with .l and .y files.

But now I have to make a jpg file and text file as a result of the executable file with the input file

The jpg file and text file need to show the calling relationship of functions in the input(Call graph)

So suppose there are files

lex.l yacc.y test.c

I need to make an executable file.

lex lex.lcommand make lex.yy.c

yacc -d yacc.y command make y.tab.c and y.tab.h(header for the lex file)

now cc y.tab.c lex.yy.c cammand will make an executable file a.out

so I have to make a jpg file(.jpg) and text file(.txt) as a result of a.out < test.c command

I know how to make a text file using fprintf() function.

But the jpg file is something that I really can't figure out.

I can't use some other tools

I only can just type some C codes to the lex file and the yacc file

So I think I might use some C library for doing this

Is there any way that I can do this?

Thank you


Solution

  • I need to make a call graph as a result of using some test codes written in C.

    You could fork some other process doing the drawing and use inter-process communication facilities with it (and this is probably the simplest approach, since it conforms to the Unix philosophy). Consider running some GraphViz or maybe GnuPlot process. You need skills on Linux system programming (to use wisely several system calls, which are listed in syscalls(2)), so you should read ALP or something newer.

    so I have to make a jpg file(.jpg) and text file(.txt) as a result of a.out < test.c command

    Don't name your program a.out, in 2019 it is ridiculous. Learn how to invoke GCC. And learn to use the program arguments (you may want to use parsing program arguments facilities). You'll invoke your program as myprogram test.c but be aware that your shell (the one you'll use to run your program) will do globbing.

    And you could also make your program some GUI application (centered on some event loop provided by the toolkit), using some GUI toolkit like GTK or libSDL. If you just want to output some graphics, you might consider also libcairo.

    If you have web programming skills, you could consider using web technologies (such as SVG + HTML5 + Canvas); if you want to make your program some specialized web server (e.g. your user would browse some http://localhost:12345 URL), consider using an HTTP server library such as libonion.

    If you accept to produce some other kind of file having the drawing, consider emitting some SVG or PDF files. You'll find libraries for that too. BTW, SVG is a textual format that you could emit directly.

    At last, you can find many libraries processing JPEG files, such as libjpeg.

    PS. You really should find on the Web some small existing free software project (e.g. on github, gitlab, sourceforge, etc...) similar in spirit to your goals and study its source code for inspiration. By doing so, you'll learn a lot of practical things, and you'll save hours of work (because you apparently lack practical skills).

    BTW, if your goal is to find the call graph of some real-life C program, consider making some GCC plugin. I did that a few weeks ago (in about 800 lines of C++ code), for some uninteresting demo in relation with my Bismon research project. And if you do have to parse C code, you need to parse the preprocessed form of it. So run some cpp preprocessor to get that.