Browse Prior Art Database

Create c/cpp files with functions aimed to print specific Data Structures given a file with those Data Structures

IP.com Disclosure Number: IPCOM000019888D
Original Publication Date: 2003-Oct-07
Included in the Prior Art Database: 2003-Oct-07
Document File: 4 page(s) / 53K

Publishing Venue

IBM

Abstract

The problem solved by this invention is almost a full automation of creating c/cpp functions used for printing Data Structures (hereafter denoted as DS) when such specific DSes are given. Almost every S/W project contains DSes. There is always a need for printing those DSes for debugging, information sharing, statistics, etc. Creating Print Functions (hereafter denoted as PFUNC) which are functions that receives a specific DS and print it, is usually done "by hand" and consumes both time and sometimes - especially when many DSes are involved or pointers/arrays are members of such DS - involves bugs. This "by hand" process can simply be automated in almost 100% and save both time and bugs.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 40% of the total text.

Page 1 of 4

  Create c/cpp files with functions aimed to print specific Data Structures given a file with those Data Structures

The problem solved by this invention is almost a full automation of creating c/cpp functions used for printing Data Structures (hereafter denoted as DS) when such specific DSes are given. Almost every S/W project contains DSes. There is always a need for printing those DSes for debugging, information sharing, statistics, etc. Creating Print Functions (hereafter denoted as PFUNC) which are functions that receives a specific DS and print it, is usually done "by hand" and consumes both time and sometimes - especially when many DSes are involved or pointers/arrays are members of such DS - involves bugs. This "by hand" process can simply be automated in almost 100% and save both time and bugs.

    The core idea is creating an application (named CPFS = Create Print FileS) which gets as input a c/cpp flag and a H file name with DSes (named IF = Input File), and creates a (c/cpp) Source file (named SPF = Source Print File) and a corresponding (h) Header file (named HPF = Header Print File) with PFUNCs - one for each DS found in the IF. This process is very fast and bug free and also creates a kind of standardization of the way you want your printings to be. It also allows you to make changes in the printing way (print the sizeof the DS in the PFUNC or not, etc.) and choose a bit different way and easily apply it to all the functions.

Interface - CPFS gets its input thru the command line:

The first input parameter is a c/cpp flag which indicates the programming language to use. The second input parameter is an IF name (e.g. "globals.h"). This is the file that contains the DSes you want to create PFUNCs for.

  Other optional input parameters can be given. Those are additional IF names. CPFS will create PFUNCs for all DSes found in those IFs and write them in the soon-to-be-created one SPF and one HPF. A possible command line can be:
cpfs -cpp globals.h structs1.h structs2.h

Flow

CPFS first writes some common lines to the new files (both SPF and HPF). Examples are comments with the file name, basic "include's" (to <stdio.h>, to the IF...), etc. A special #define is also written to the SPF. This is a #define to the "basic print function" that will be used. (e.g. - #define my_printf printf)

CPFS then starts reading lines from the IF searching for a basic type definition pattern ("basic type" = struct, union or enum). This searching - as well as any other pattern searching - is done by simple parsing algorithms.

Basic types Upon finding a basic type, CPFS creates a suitable function header for it and writes it to both SPF and HPF properly.

The 3 possible functions headers are:

For c file: printStructA(struct A * pStructIn, unsigned int nIdentIn = 0);


1.

Page 2 of 4

For cpp file: func_printStructA(struct A * pStructIn, unsigned int nIdentIn); and a Macro #define printStructA(p) func_printStructA(p, 0) This function gets a pointer to struct...