Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 211 additions & 12 deletions Source/robohdrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* robohdrs
* DESCRIPTION
* Standalone program to insert ROBODoc headers to source code files.
* This program processes one source file at the time. Existing
* ROBODoc headers, if any, are not checked for. Beware since this
* may result in double headers. Current working directory should
* be the same as where the source file is located.
* This program processes one source file at the time. Current working
* directory should be the same as where the source file is located.
* USES
* Exuberant Ctags 5.3.1 or newer required
* USAGE
Expand Down Expand Up @@ -148,6 +146,19 @@ static short srcEnd = SRC_E_C;

/********** srcSta */

/****v* ROBOhdrs/stdin_cp
* NAME
* srcSta
* SEE ALSO
* src_constants
* SOURCE
*/

static int stdin_cp;
static int stdout_cp;

/********** srcSta */

typedef struct _ctag_t
{
void *prev;
Expand Down Expand Up @@ -184,6 +195,29 @@ ctags_t;
static ctags_t myctags;

/********** myctags */

/****v* ROBOhdrs/checkctags
* NAME
* myctags
* SYNOPSIS
* static ctags_t checkctags;
* SOURCE
*/
static ctags_t checkctags;

/********** checkctags */

/****v* ROBOhdrs/checkctagsptr
* NAME
* checkctagsptr
* SYNOPSIS
* static ctags_t *checkctagsptr;
* SOURCE
*/
static ctags_t *checkctagsptr;

/********** ctags */

/****v* ROBOhdrs/ctags
* NAME
* ctags
Expand Down Expand Up @@ -476,8 +510,22 @@ typeOk( char *t )
static void
initMe( void )
{
stdin_cp = dup(0);
stdout_cp = dup(1);

ctags = &myctags;
checkctagsptr = &checkctags;
memset( ctags, 0, sizeof( ctags_t ) );
memset( checkctagsptr, 0, sizeof( ctags_t ) );

if ( !checkctagsptr->ctag )
{
/* empty list */
checkctagsptr->ctag = ( ctag_t * ) malloc( sizeof( ctag_t ) );
assert( checkctagsptr->ctag );
memset( checkctagsptr->ctag, 0, sizeof( ctag_t ) );
}

projName[0] = '\0';
ctagsBin[0] = '\0';
vcTag[0] = '\0';
Expand Down Expand Up @@ -597,13 +645,55 @@ parseCtagsX( FILE * fp )
tagsParsed++;
}
} /* end while() */

fclose( fp );

dup2(stdin_cp, 0);
dup2(stdout_cp, 1);

return tagsParsed;
}

/********** parseCtagsX */

/****f* ROBOhdrs/doNanoExec
* NAME
* doNanoExec
* SYNOPSIS
* static void doNanoExec( char * buffer)
* SOURCE
*/
static void
doNanoExec( char *buffer )
{
int vipe_fd[2], echo_fd[2], vipe_pid, echo_pid;
FILE *incoming = NULL;
char *vipe_cmd = "vipe";
char *echo_cmd = "echo";

*buffer = '\0';

FILE *pipe_fp;

if(( pipe_fp = popen("export EDITOR=nano;echo prova | vipe", "r") ) == NULL)
{
perror("popen");
exit(1);
}

char buf[MAXLINE + 1];

while ( fgets( buf, MAXLINE, pipe_fp ) != NULL )
{
sprintf( buffer, "%s%s %s", buffer,remark_markers[srcRem], buf );
//strcat( buffer, buf);
}

pclose( pipe_fp );
}

/********** doCtagsExec */

/****f* ROBOhdrs/roboFileHeader
* NAME
* roboFileHeader
Expand All @@ -628,13 +718,42 @@ roboFileHeader( FILE * fp, char *proj, char *fname )
fprintf( fp, "%s %s\n", s, vcTag );
}
fprintf( fp, "%s DESCRIPTION\n", s );

char input[1024];
doNanoExec( input );

fprintf( fp, "%s", input );

fprintf( fp, "%s*******%s\n", s,
( end_remark_markers[srcEnd] ? end_remark_markers[srcEnd] :
"" ) );
}

/********** roboFileHeader */

/****f* ROBOhdrs/roboFileHeaderCheck
* NAME
* roboFileHeaderCheck
* FUNCTION
* Check if source file header has been write.
* SYNOPSIS
* static void roboFileHeaderCheck( char *proj, char *fname )
* SOURCE
*/
static int
roboFileHeaderCheck( char *proj, char *fname, char *line )
{
char *s;
char buf[ MAXLINE ];

s = remark_markers[srcRem];
sprintf( buf, "%sh* %s/%s\n", header_markers[srcSta],
( proj[0] ? proj : fname ), fname );

return strcmp(buf, line);
}

/********** roboFileHeaderCheck */

/****f* ROBOhdrs/roboHeader
* NAME
* roboHeader
Expand Down Expand Up @@ -705,6 +824,75 @@ roboHeader( FILE * fp, char *fname, char *name, char *type, char *decl )

/********** roboHeader */

/****f* ROBOhdrs/roboHeaderCheck
* NAME
* roboHeaderCheck
* SYNOPSIS
* static void roboHeaderCheck( char * line, ctags_t *ctags )
* SOURCE
*/
static int
roboHeaderCheck( char * line, ctag_t *ctags )
{
char fname[MAXNAME];
char type[MAXNAME];
char typechar;
char *name;

int ret = 0;

/* type is 2 char long due to the optional prefix "i" */
ret = sscanf(line, "/***%2s* %s\n", type, fname);

if(ret >= 2)
{
name = strstr(fname, "/");
if( name != NULL )
{
*name = '\0';
name++;

/* if no "i" option */
if( type[0] == '*' )
{
type[0] = type[1];
type[1] = '\0';
typechar = type[0];
}
else
typechar = type[1];

switch(typechar)
{
case 'f':
strcpy(type, "function");
break;

case 'v':
strcpy(type, "variable");
break;

case 's':
strcpy(type, "struct");
break;

case 'm':
strcpy(type, "macro");
break;
}

strncpy( ctags->type, type, MAXNAME );
strncpy( ctags->fname, fname, MAXNAME );
strncpy( ctags->name, name, MAXNAME );
}

return 0;
}
return 1;
}

/********** roboHeaderCheck */

/****f* ROBOhdrs/insertSrcEnd
* NAME
* insertSrcEnd
Expand Down Expand Up @@ -735,6 +923,7 @@ insertHeaders( ctags_t * e, char *project, char *dstpath, char *srcpath )
{
FILE *ifp, *ofp;
ctag_t *ctag = e->ctag;
ctag_t *ctagcheck = checkctagsptr->ctag;
int lnum = 0, funcline = 0;
char buf[MAXLINE], *funcname = 0;

Expand All @@ -746,14 +935,19 @@ insertHeaders( ctags_t * e, char *project, char *dstpath, char *srcpath )
assert( ofp = fopen( dstpath, "w" ) );
assert( ifp = fopen( srcpath, "r" ) );

/* include file header only if project name is defined */
if ( project )
{
roboFileHeader( ofp, project, dstpath );
}

while ( fgets( buf, MAXLINE, ifp ) != NULL )
{
/* include file header only if project name is defined */
/* include file header only if project header hasn't been write yet */
if ( project && (lnum == 0) )
{
if(roboFileHeaderCheck( project, dstpath, buf))
roboFileHeader( ofp, project, dstpath );
}

roboHeaderCheck( buf, ctagcheck );

lnum++;
while ( ctag->prev )
{
Expand All @@ -771,8 +965,13 @@ insertHeaders( ctags_t * e, char *project, char *dstpath, char *srcpath )
{
if ( typeOk( ctag->type ) )
{
roboHeader( ofp, ctag->fname, ctag->name, ctag->type,
ctag->decl );
if( strncmp(ctagcheck->fname, ctag->fname, MAXNAME) ||
strncmp(ctagcheck->name, ctag->name, MAXNAME ) ||
strncmp(ctagcheck->type, ctag->type, MAXNAME ) )
{
roboHeader( ofp, ctag->fname, ctag->name, ctag->type,
ctag->decl );
}
funcline = lnum;
funcname = ctag->name;
}
Expand Down